aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/stable/sysfs-driver-ib_srp25
-rw-r--r--Documentation/arm64/legacy_instructions.txt45
-rw-r--r--Documentation/block/biodoc.txt4
-rw-r--r--Documentation/device-mapper/cache-policies.txt24
-rw-r--r--Documentation/devicetree/bindings/ata/sata_rcar.txt6
-rw-r--r--Documentation/devicetree/bindings/hwmon/ltc2978.txt39
-rw-r--r--Documentation/devicetree/bindings/interrupt-controller/interrupts.txt4
-rw-r--r--Documentation/devicetree/bindings/mfd/atmel-hlcdc.txt51
-rw-r--r--Documentation/devicetree/bindings/mfd/max77686.txt6
-rw-r--r--Documentation/devicetree/bindings/mfd/max77693.txt21
-rw-r--r--Documentation/devicetree/bindings/mfd/s2mps11.txt22
-rw-r--r--Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt4
-rw-r--r--Documentation/devicetree/bindings/mmc/img-dw-mshc.txt29
-rw-r--r--Documentation/devicetree/bindings/mmc/sdhci-pxa.txt7
-rw-r--r--Documentation/devicetree/bindings/nios2/nios2.txt62
-rw-r--r--Documentation/devicetree/bindings/nios2/timer.txt19
-rw-r--r--Documentation/devicetree/bindings/pci/pci.txt11
-rw-r--r--Documentation/devicetree/bindings/pinctrl/img,tz1090-pdc-pinctrl.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/img,tz1090-pinctrl.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/lantiq,falcon-pinumx.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/lantiq,xway-pinumx.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/nvidia,tegra20-pinmux.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/pinctrl-sirf.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/pinctrl_spear.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/qcom,apq8064-pinctrl.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/qcom,apq8084-pinctrl.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/qcom,ipq8064-pinctrl.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/qcom,msm8960-pinctrl.txt2
-rw-r--r--Documentation/devicetree/bindings/pinctrl/qcom,msm8974-pinctrl.txt2
-rw-r--r--Documentation/devicetree/bindings/power/power-controller.txt18
-rw-r--r--Documentation/devicetree/bindings/regulator/act8865-regulator.txt4
-rw-r--r--Documentation/devicetree/bindings/regulator/max77802.txt35
-rw-r--r--Documentation/devicetree/bindings/regulator/regulator.txt22
-rw-r--r--Documentation/devicetree/bindings/regulator/sky81452-regulator.txt10
-rw-r--r--Documentation/devicetree/bindings/thermal/rcar-thermal.txt5
-rw-r--r--Documentation/devicetree/bindings/vendor-prefixes.txt5
-rw-r--r--Documentation/filesystems/overlayfs.txt2
-rw-r--r--Documentation/hwmon/lm755
-rw-r--r--Documentation/hwmon/lm9523415
-rw-r--r--Documentation/hwmon/lm9524514
-rw-r--r--Documentation/hwmon/nct677514
-rw-r--r--Documentation/hwmon/nct780232
-rw-r--r--Documentation/hwmon/tmp4018
-rw-r--r--Documentation/input/elantech.txt81
-rw-r--r--Documentation/kernel-parameters.txt2
-rw-r--r--Documentation/networking/ip-sysctl.txt14
-rw-r--r--Documentation/networking/timestamping.txt2
-rw-r--r--Documentation/nios2/README23
-rw-r--r--Documentation/scsi/libsas.txt82
-rw-r--r--Documentation/scsi/scsi_mid_low_api.txt66
-rw-r--r--Documentation/scsi/st.txt8
-rw-r--r--Documentation/scsi/wd719x.txt21
-rw-r--r--Documentation/video4linux/vivid.txt12
-rw-r--r--MAINTAINERS165
-rw-r--r--Makefile7
-rw-r--r--arch/arm/Kconfig7
-rw-r--r--arch/arm/Kconfig.debug2
-rw-r--r--arch/arm/Makefile8
-rw-r--r--arch/arm/boot/compressed/head.S20
-rw-r--r--arch/arm/boot/dts/Makefile27
-rw-r--r--arch/arm/boot/dts/am335x-evm.dts2
-rw-r--r--arch/arm/boot/dts/am437x-gp-evm.dts4
-rw-r--r--arch/arm/boot/dts/am437x-sk-evm.dts4
-rw-r--r--arch/arm/boot/dts/am43x-epos-evm.dts4
-rw-r--r--arch/arm/boot/dts/emev2-kzm9d.dts63
-rw-r--r--arch/arm/boot/dts/emev2.dtsi12
-rw-r--r--arch/arm/boot/dts/exynos5250-snow.dts4
-rw-r--r--arch/arm/boot/dts/exynos5250.dtsi2
-rw-r--r--arch/arm/boot/dts/imx6qdl-gw52xx.dtsi1
-rw-r--r--arch/arm/boot/dts/imx6qdl-gw53xx.dtsi1
-rw-r--r--arch/arm/boot/dts/imx6qdl-gw54xx.dtsi2
-rw-r--r--arch/arm/boot/dts/imx6qdl-rex.dtsi1
-rw-r--r--arch/arm/boot/dts/imx6qdl-sabresd.dtsi8
-rw-r--r--arch/arm/boot/dts/omap3-evm-common.dtsi21
-rw-r--r--arch/arm/boot/dts/omap3-ldp.dts23
-rw-r--r--arch/arm/boot/dts/omap3.dtsi2
-rw-r--r--arch/arm/boot/dts/r7s72100-genmai.dts3
-rw-r--r--arch/arm/boot/dts/r7s72100.dtsi202
-rw-r--r--arch/arm/boot/dts/r8a73a4-ape6evm-reference.dts3
-rw-r--r--arch/arm/boot/dts/r8a73a4.dtsi232
-rw-r--r--arch/arm/boot/dts/r8a7740-armadillo800eva.dts1
-rw-r--r--arch/arm/boot/dts/r8a7740.dtsi2
-rw-r--r--arch/arm/boot/dts/r8a7778-bockw-reference.dts3
-rw-r--r--arch/arm/boot/dts/r8a7779-marzen.dts84
-rw-r--r--arch/arm/boot/dts/r8a7779.dtsi24
-rw-r--r--arch/arm/boot/dts/r8a7790-lager.dts54
-rw-r--r--arch/arm/boot/dts/r8a7790.dtsi94
-rw-r--r--arch/arm/boot/dts/r8a7791-henninger.dts1
-rw-r--r--arch/arm/boot/dts/r8a7791-koelsch.dts19
-rw-r--r--arch/arm/boot/dts/r8a7791.dtsi69
-rw-r--r--arch/arm/boot/dts/r8a7794-alt.dts1
-rw-r--r--arch/arm/boot/dts/r8a77xx-aa104xd12-panel.dtsi41
-rw-r--r--arch/arm/boot/dts/sama5d31.dtsi2
-rw-r--r--arch/arm/boot/dts/sama5d33.dtsi2
-rw-r--r--arch/arm/boot/dts/sama5d34.dtsi2
-rw-r--r--arch/arm/boot/dts/sama5d35.dtsi2
-rw-r--r--arch/arm/boot/dts/sama5d36.dtsi2
-rw-r--r--arch/arm/boot/dts/sama5d3xcm.dtsi2
-rw-r--r--arch/arm/boot/dts/sh73a0-kzm9g-reference.dts1
-rw-r--r--arch/arm/boot/dts/sun6i-a31.dtsi4
-rw-r--r--arch/arm/boot/dts/tegra114-dalmore.dts1
-rw-r--r--arch/arm/boot/dts/tegra114-roth.dts9
-rw-r--r--arch/arm/boot/dts/tegra114-tn7.dts5
-rw-r--r--arch/arm/boot/dts/tegra114.dtsi7
-rw-r--r--arch/arm/boot/dts/tegra124-jetson-tk1.dts1
-rw-r--r--arch/arm/boot/dts/tegra124-nyan-big.dts1
-rw-r--r--arch/arm/boot/dts/tegra124-venice2.dts1
-rw-r--r--arch/arm/boot/dts/tegra124.dtsi8
-rw-r--r--arch/arm/boot/dts/tegra20-harmony.dts1
-rw-r--r--arch/arm/boot/dts/tegra20-iris-512.dts5
-rw-r--r--arch/arm/boot/dts/tegra20-medcom-wide.dts4
-rw-r--r--arch/arm/boot/dts/tegra20-paz00.dts2
-rw-r--r--arch/arm/boot/dts/tegra20-seaboard.dts1
-rw-r--r--arch/arm/boot/dts/tegra20-tamonten.dtsi1
-rw-r--r--arch/arm/boot/dts/tegra20-trimslice.dts1
-rw-r--r--arch/arm/boot/dts/tegra20-ventana.dts1
-rw-r--r--arch/arm/boot/dts/tegra20-whistler.dts1
-rw-r--r--arch/arm/boot/dts/tegra20.dtsi8
-rw-r--r--arch/arm/boot/dts/tegra30-apalis-eval.dts4
-rw-r--r--arch/arm/boot/dts/tegra30-beaver.dts1
-rw-r--r--arch/arm/boot/dts/tegra30-cardhu.dtsi2
-rw-r--r--arch/arm/boot/dts/tegra30-colibri-eval-v3.dts3
-rw-r--r--arch/arm/boot/dts/tegra30.dtsi8
-rw-r--r--arch/arm/boot/dts/vf610-cosmic.dts19
-rw-r--r--arch/arm/boot/dts/zynq-parallella.dts4
-rw-r--r--arch/arm/common/edma.c9
-rw-r--r--arch/arm/configs/at91rm9200_defconfig161
-rw-r--r--arch/arm/configs/at91sam9260_9g20_defconfig145
-rw-r--r--arch/arm/configs/at91sam9261_9g10_defconfig147
-rw-r--r--arch/arm/configs/at91sam9263_defconfig151
-rw-r--r--arch/arm/configs/at91sam9g45_defconfig175
-rw-r--r--arch/arm/configs/at91sam9rl_defconfig92
-rw-r--r--arch/arm/configs/at91x40_defconfig48
-rw-r--r--arch/arm/configs/exynos_defconfig2
-rw-r--r--arch/arm/configs/koelsch_defconfig113
-rw-r--r--arch/arm/configs/multi_v7_defconfig3
-rw-r--r--arch/arm/configs/omap2plus_defconfig4
-rw-r--r--arch/arm/configs/sama5_defconfig1
-rw-r--r--arch/arm/configs/shmobile_defconfig1
-rw-r--r--arch/arm/configs/socfpga_defconfig71
-rw-r--r--arch/arm/include/asm/thread_info.h11
-rw-r--r--arch/arm/kernel/traps.c31
-rw-r--r--arch/arm/kvm/mmu.c10
-rw-r--r--arch/arm/mach-at91/Kconfig72
-rw-r--r--arch/arm/mach-at91/Kconfig.non_dt344
-rw-r--r--arch/arm/mach-at91/Makefile67
-rw-r--r--arch/arm/mach-at91/Makefile.boot6
-rw-r--r--arch/arm/mach-at91/at91_aic.h99
-rw-r--r--arch/arm/mach-at91/at91_tc.h146
-rw-r--r--arch/arm/mach-at91/at91rm9200.c341
-rw-r--r--arch/arm/mach-at91/at91rm9200_devices.c1212
-rw-r--r--arch/arm/mach-at91/at91rm9200_time.c23
-rw-r--r--arch/arm/mach-at91/at91sam9260.c397
-rw-r--r--arch/arm/mach-at91/at91sam9260_devices.c1364
-rw-r--r--arch/arm/mach-at91/at91sam9261.c375
-rw-r--r--arch/arm/mach-at91/at91sam9261_devices.c1098
-rw-r--r--arch/arm/mach-at91/at91sam9263.c399
-rw-r--r--arch/arm/mach-at91/at91sam9263_devices.c1538
-rw-r--r--arch/arm/mach-at91/at91sam9g45.c456
-rw-r--r--arch/arm/mach-at91/at91sam9g45_devices.c1915
-rw-r--r--arch/arm/mach-at91/at91sam9n12.c213
-rw-r--r--arch/arm/mach-at91/at91sam9rl.c378
-rw-r--r--arch/arm/mach-at91/at91sam9rl_devices.c1260
-rw-r--r--arch/arm/mach-at91/at91sam9x5.c311
-rw-r--r--arch/arm/mach-at91/at91x40.c93
-rw-r--r--arch/arm/mach-at91/at91x40_time.c85
-rw-r--r--arch/arm/mach-at91/board-1arm.c99
-rw-r--r--arch/arm/mach-at91/board-afeb-9260v1.c223
-rw-r--r--arch/arm/mach-at91/board-cam60.c199
-rw-r--r--arch/arm/mach-at91/board-carmeva.c167
-rw-r--r--arch/arm/mach-at91/board-cpu9krea.c386
-rw-r--r--arch/arm/mach-at91/board-cpuat91.c189
-rw-r--r--arch/arm/mach-at91/board-csb337.c260
-rw-r--r--arch/arm/mach-at91/board-csb637.c142
-rw-r--r--arch/arm/mach-at91/board-dt-rm9200.c3
-rw-r--r--arch/arm/mach-at91/board-dt-sam9.c2
-rw-r--r--arch/arm/mach-at91/board-dt-sama5.c1
-rw-r--r--arch/arm/mach-at91/board-eb01.c52
-rw-r--r--arch/arm/mach-at91/board-eb9200.c126
-rw-r--r--arch/arm/mach-at91/board-ecbat91.c191
-rw-r--r--arch/arm/mach-at91/board-eco920.c160
-rw-r--r--arch/arm/mach-at91/board-flexibity.c171
-rw-r--r--arch/arm/mach-at91/board-gsia18s.c585
-rw-r--r--arch/arm/mach-at91/board-kafa.c113
-rw-r--r--arch/arm/mach-at91/board-kb9202.c159
-rw-r--r--arch/arm/mach-at91/board-pcontrol-g20.c228
-rw-r--r--arch/arm/mach-at91/board-picotux200.c129
-rw-r--r--arch/arm/mach-at91/board-rm9200ek.c196
-rw-r--r--arch/arm/mach-at91/board-sam9-l9260.c230
-rw-r--r--arch/arm/mach-at91/board-sam9260ek.c354
-rw-r--r--arch/arm/mach-at91/board-sam9261ek.c623
-rw-r--r--arch/arm/mach-at91/board-sam9263ek.c493
-rw-r--r--arch/arm/mach-at91/board-sam9g20ek.c429
-rw-r--r--arch/arm/mach-at91/board-sam9m10g45ek.c527
-rw-r--r--arch/arm/mach-at91/board-sam9rlek.c333
-rw-r--r--arch/arm/mach-at91/board-snapper9260.c191
-rw-r--r--arch/arm/mach-at91/board-stamp9g20.c294
-rw-r--r--arch/arm/mach-at91/board-yl-9200.c597
-rw-r--r--arch/arm/mach-at91/board.h127
-rw-r--r--arch/arm/mach-at91/clock.c977
-rw-r--r--arch/arm/mach-at91/clock.h49
-rw-r--r--arch/arm/mach-at91/generic.h53
-rw-r--r--arch/arm/mach-at91/gpio.c982
-rw-r--r--arch/arm/mach-at91/gpio.h214
-rw-r--r--arch/arm/mach-at91/gsia18s.h33
-rw-r--r--arch/arm/mach-at91/include/mach/at91_dbgu.h3
-rw-r--r--arch/arm/mach-at91/include/mach/at91_ramc.h6
-rw-r--r--arch/arm/mach-at91/include/mach/at91x40.h60
-rw-r--r--arch/arm/mach-at91/include/mach/cpu.h1
-rw-r--r--arch/arm/mach-at91/include/mach/hardware.h10
-rw-r--r--arch/arm/mach-at91/include/mach/uncompress.h7
-rw-r--r--arch/arm/mach-at91/irq.c296
-rw-r--r--arch/arm/mach-at91/leds.c56
-rw-r--r--arch/arm/mach-at91/pm.c33
-rw-r--r--arch/arm/mach-at91/pm.h1
-rw-r--r--arch/arm/mach-at91/setup.c67
-rw-r--r--arch/arm/mach-at91/soc.h6
-rw-r--r--arch/arm/mach-at91/stamp9g20.h7
-rw-r--r--arch/arm/mach-davinci/board-da830-evm.c89
-rw-r--r--arch/arm/mach-davinci/board-da850-evm.c9
-rw-r--r--arch/arm/mach-davinci/board-dm644x-evm.c10
-rw-r--r--arch/arm/mach-davinci/board-mityomapl138.c45
-rw-r--r--arch/arm/mach-davinci/board-neuros-osd2.c5
-rw-r--r--arch/arm/mach-davinci/clock.c2
-rw-r--r--arch/arm/mach-davinci/mux.c15
-rw-r--r--arch/arm/mach-davinci/time.c13
-rw-r--r--arch/arm/mach-ep93xx/dma.c12
-rw-r--r--arch/arm/mach-exynos/exynos.c50
-rw-r--r--arch/arm/mach-exynos/include/mach/map.h23
-rw-r--r--arch/arm/mach-imx/clk-imx6q.c2
-rw-r--r--arch/arm/mach-imx/clk-pllv3.c7
-rw-r--r--arch/arm/mach-imx/common.h5
-rw-r--r--arch/arm/mach-imx/gpc.c42
-rw-r--r--arch/arm/mach-imx/imx25-dt.c9
-rw-r--r--arch/arm/mach-imx/imx27-dt.c3
-rw-r--r--arch/arm/mach-imx/imx31-dt.c9
-rw-r--r--arch/arm/mach-imx/imx35-dt.c10
-rw-r--r--arch/arm/mach-imx/iomux-imx31.c8
-rw-r--r--arch/arm/mach-imx/iomux-mx3.h2
-rw-r--r--arch/arm/mach-imx/mach-imx50.c9
-rw-r--r--arch/arm/mach-imx/mach-imx51.c2
-rw-r--r--arch/arm/mach-imx/mach-imx53.c2
-rw-r--r--arch/arm/mach-imx/mach-imx6q.c3
-rw-r--r--arch/arm/mach-imx/mach-imx6sl.c4
-rw-r--r--arch/arm/mach-imx/mach-imx6sx.c4
-rw-r--r--arch/arm/mach-imx/mach-vf610.c10
-rw-r--r--arch/arm/mach-imx/pm-imx6.c5
-rw-r--r--arch/arm/mach-imx/system.c15
-rw-r--r--arch/arm/mach-ixp4xx/include/mach/io.h4
-rw-r--r--arch/arm/mach-omap2/board-n8x0.c2
-rw-r--r--arch/arm/mach-omap2/board-rx51-peripherals.c4
-rw-r--r--arch/arm/mach-omap2/devices.c36
-rw-r--r--arch/arm/mach-omap2/gpmc.c2
-rw-r--r--arch/arm/mach-omap2/hsmmc.c158
-rw-r--r--arch/arm/mach-omap2/hsmmc.h9
-rw-r--r--arch/arm/mach-omap2/mmc.h10
-rw-r--r--arch/arm/mach-omap2/omap4-common.c1
-rw-r--r--arch/arm/mach-omap2/omap_device.c4
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_2430_data.c4
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_33xx_43xx_ipblock_data.c8
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_33xx_data.c1
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_3xxx_data.c8
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_44xx_data.c4
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_54xx_data.c4
-rw-r--r--arch/arm/mach-omap2/omap_hwmod_7xx_data.c4
-rw-r--r--arch/arm/mach-omap2/omap_phy_internal.c8
-rw-r--r--arch/arm/mach-omap2/serial.c3
-rw-r--r--arch/arm/mach-pxa/include/mach/addr-map.h5
-rw-r--r--arch/arm/mach-shmobile/Kconfig20
-rw-r--r--arch/arm/mach-shmobile/Makefile5
-rw-r--r--arch/arm/mach-shmobile/Makefile.boot1
-rw-r--r--arch/arm/mach-shmobile/board-ape6evm-reference.c4
-rw-r--r--arch/arm/mach-shmobile/board-ape6evm.c4
-rw-r--r--arch/arm/mach-shmobile/board-armadillo800eva.c45
-rw-r--r--arch/arm/mach-shmobile/board-bockw-reference.c4
-rw-r--r--arch/arm/mach-shmobile/board-bockw.c4
-rw-r--r--arch/arm/mach-shmobile/board-koelsch-reference.c117
-rw-r--r--arch/arm/mach-shmobile/board-koelsch.c527
-rw-r--r--arch/arm/mach-shmobile/board-kzm9g-reference.c4
-rw-r--r--arch/arm/mach-shmobile/board-kzm9g.c4
-rw-r--r--arch/arm/mach-shmobile/board-lager-reference.c84
-rw-r--r--arch/arm/mach-shmobile/board-lager.c4
-rw-r--r--arch/arm/mach-shmobile/board-mackerel.c4
-rw-r--r--arch/arm/mach-shmobile/board-marzen-reference.c5
-rw-r--r--arch/arm/mach-shmobile/board-marzen.c4
-rw-r--r--arch/arm/mach-shmobile/clock-r8a73a4.c4
-rw-r--r--arch/arm/mach-shmobile/clock-r8a7740.c13
-rw-r--r--arch/arm/mach-shmobile/clock-r8a7778.c4
-rw-r--r--arch/arm/mach-shmobile/clock-r8a7779.c4
-rw-r--r--arch/arm/mach-shmobile/clock-r8a7790.c6
-rw-r--r--arch/arm/mach-shmobile/clock-r8a7791.c342
-rw-r--r--arch/arm/mach-shmobile/clock-sh7372.c4
-rw-r--r--arch/arm/mach-shmobile/clock-sh73a0.c4
-rw-r--r--arch/arm/mach-shmobile/clock.c36
-rw-r--r--arch/arm/mach-shmobile/clock.h14
-rw-r--r--arch/arm/mach-shmobile/console.c4
-rw-r--r--arch/arm/mach-shmobile/headsmp-scu.S5
-rw-r--r--arch/arm/mach-shmobile/intc-sh7372.c4
-rw-r--r--arch/arm/mach-shmobile/intc-sh73a0.c4
-rw-r--r--arch/arm/mach-shmobile/r8a7740.h4
-rw-r--r--arch/arm/mach-shmobile/r8a7778.h5
-rw-r--r--arch/arm/mach-shmobile/r8a7791.h3
-rw-r--r--arch/arm/mach-shmobile/setup-emev2.c4
-rw-r--r--arch/arm/mach-shmobile/setup-r7s72100.c4
-rw-r--r--arch/arm/mach-shmobile/setup-r8a73a4.c4
-rw-r--r--arch/arm/mach-shmobile/setup-r8a7740.c4
-rw-r--r--arch/arm/mach-shmobile/setup-r8a7778.c11
-rw-r--r--arch/arm/mach-shmobile/setup-r8a7779.c10
-rw-r--r--arch/arm/mach-shmobile/setup-r8a7790.c4
-rw-r--r--arch/arm/mach-shmobile/setup-r8a7791.c185
-rw-r--r--arch/arm/mach-shmobile/setup-rcar-gen2.c4
-rw-r--r--arch/arm/mach-shmobile/setup-sh7372.c6
-rw-r--r--arch/arm/mach-shmobile/setup-sh73a0.c35
-rw-r--r--arch/arm/mach-shmobile/sh73a0.h1
-rw-r--r--arch/arm/mach-shmobile/sleep-sh7372.S5
-rw-r--r--arch/arm/mach-shmobile/smp-emev2.c4
-rw-r--r--arch/arm/mach-shmobile/smp-r8a7779.c4
-rw-r--r--arch/arm/mach-shmobile/smp-sh73a0.c4
-rw-r--r--arch/arm/mach-shmobile/timer.c5
-rw-r--r--arch/arm/mach-tegra/irq.c22
-rw-r--r--arch/arm/mach-tegra/reset-handler.S1
-rw-r--r--arch/arm/mach-vexpress/Kconfig4
-rw-r--r--arch/arm/mach-vexpress/Makefile3
-rw-r--r--arch/arm/mach-vexpress/core.h7
-rw-r--r--arch/arm/mach-vexpress/ct-ca9x4.c212
-rw-r--r--arch/arm/mach-vexpress/include/mach/ct-ca9x4.h47
-rw-r--r--arch/arm/mach-vexpress/include/mach/hardware.h1
-rw-r--r--arch/arm/mach-vexpress/include/mach/irqs.h6
-rw-r--r--arch/arm/mach-vexpress/include/mach/motherboard.h88
-rw-r--r--arch/arm/mach-vexpress/platsmp.c42
-rw-r--r--arch/arm/mach-vexpress/v2m.c374
-rw-r--r--arch/arm/mach-zynq/Makefile2
-rw-r--r--arch/arm/mach-zynq/common.h1
-rw-r--r--arch/arm/mach-zynq/hotplug.c14
-rw-r--r--arch/arm/mm/Kconfig1
-rw-r--r--arch/arm/mm/proc-v7.S2
-rw-r--r--arch/arm/mm/proc-xscale.S4
-rw-r--r--arch/arm/plat-samsung/include/plat/map-s5p.h21
-rw-r--r--arch/arm/plat-versatile/Kconfig2
-rw-r--r--arch/arm64/Kconfig187
-rw-r--r--arch/arm64/Kconfig.debug12
-rw-r--r--arch/arm64/Makefile10
-rw-r--r--arch/arm64/boot/dts/Makefile15
-rw-r--r--arch/arm64/boot/dts/apm/Makefile5
-rw-r--r--arch/arm64/boot/dts/apm/apm-mustang.dts (renamed from arch/arm64/boot/dts/apm-mustang.dts)0
-rw-r--r--arch/arm64/boot/dts/apm/apm-storm.dtsi (renamed from arch/arm64/boot/dts/apm-storm.dtsi)10
-rw-r--r--arch/arm64/boot/dts/arm/Makefile6
-rw-r--r--arch/arm64/boot/dts/arm/foundation-v8.dts (renamed from arch/arm64/boot/dts/foundation-v8.dts)0
-rw-r--r--arch/arm64/boot/dts/arm/rtsm_ve-aemv8a.dts (renamed from arch/arm64/boot/dts/rtsm_ve-aemv8a.dts)0
-rw-r--r--arch/arm64/boot/dts/arm/rtsm_ve-motherboard.dtsi (renamed from arch/arm64/boot/dts/rtsm_ve-motherboard.dtsi)0
-rw-r--r--arch/arm64/boot/dts/cavium/Makefile5
-rw-r--r--arch/arm64/boot/dts/cavium/thunder-88xx.dts (renamed from arch/arm64/boot/dts/thunder-88xx.dts)0
-rw-r--r--arch/arm64/boot/dts/cavium/thunder-88xx.dtsi (renamed from arch/arm64/boot/dts/thunder-88xx.dtsi)0
-rw-r--r--arch/arm64/configs/defconfig26
-rw-r--r--arch/arm64/crypto/Kconfig5
-rw-r--r--arch/arm64/crypto/aes-ce-ccm-glue.c4
-rw-r--r--arch/arm64/crypto/aes-ce-cipher.c112
-rw-r--r--arch/arm64/crypto/aes-ce-setkey.h5
-rw-r--r--arch/arm64/crypto/aes-glue.c18
-rw-r--r--arch/arm64/include/asm/alternative-asm.h29
-rw-r--r--arch/arm64/include/asm/alternative.h44
-rw-r--r--arch/arm64/include/asm/cache.h2
-rw-r--r--arch/arm64/include/asm/cacheflush.h2
-rw-r--r--arch/arm64/include/asm/cmpxchg.h73
-rw-r--r--arch/arm64/include/asm/compat.h7
-rw-r--r--arch/arm64/include/asm/cpu.h2
-rw-r--r--arch/arm64/include/asm/cpufeature.h29
-rw-r--r--arch/arm64/include/asm/cputype.h5
-rw-r--r--arch/arm64/include/asm/dmi.h31
-rw-r--r--arch/arm64/include/asm/fixmap.h8
-rw-r--r--arch/arm64/include/asm/hwcap.h1
-rw-r--r--arch/arm64/include/asm/insn.h10
-rw-r--r--arch/arm64/include/asm/io.h23
-rw-r--r--arch/arm64/include/asm/irq.h3
-rw-r--r--arch/arm64/include/asm/kvm_arm.h21
-rw-r--r--arch/arm64/include/asm/memory.h2
-rw-r--r--arch/arm64/include/asm/opcodes.h1
-rw-r--r--arch/arm64/include/asm/percpu.h215
-rw-r--r--arch/arm64/include/asm/pgalloc.h8
-rw-r--r--arch/arm64/include/asm/seccomp.h25
-rw-r--r--arch/arm64/include/asm/tlb.h67
-rw-r--r--arch/arm64/include/asm/traps.h16
-rw-r--r--arch/arm64/include/asm/unistd.h3
-rw-r--r--arch/arm64/include/asm/unistd32.h5
-rw-r--r--arch/arm64/kernel/Makefile7
-rw-r--r--arch/arm64/kernel/alternative.c85
-rw-r--r--arch/arm64/kernel/armv8_deprecated.c553
-rw-r--r--arch/arm64/kernel/cpu_errata.c111
-rw-r--r--arch/arm64/kernel/cpuinfo.c23
-rw-r--r--arch/arm64/kernel/efi-entry.S30
-rw-r--r--arch/arm64/kernel/efi.c37
-rw-r--r--arch/arm64/kernel/entry-ftrace.S21
-rw-r--r--arch/arm64/kernel/entry.S138
-rw-r--r--arch/arm64/kernel/head.S434
-rw-r--r--arch/arm64/kernel/insn.c31
-rw-r--r--arch/arm64/kernel/io.c66
-rw-r--r--arch/arm64/kernel/irq.c2
-rw-r--r--arch/arm64/kernel/jump_label.c23
-rw-r--r--arch/arm64/kernel/module.c18
-rw-r--r--arch/arm64/kernel/perf_event.c10
-rw-r--r--arch/arm64/kernel/psci.c2
-rw-r--r--arch/arm64/kernel/ptrace.c40
-rw-r--r--arch/arm64/kernel/setup.c108
-rw-r--r--arch/arm64/kernel/signal32.c6
-rw-r--r--arch/arm64/kernel/sleep.S36
-rw-r--r--arch/arm64/kernel/smp.c2
-rw-r--r--arch/arm64/kernel/suspend.c4
-rw-r--r--arch/arm64/kernel/sys_compat.c49
-rw-r--r--arch/arm64/kernel/topology.c7
-rw-r--r--arch/arm64/kernel/trace-events-emulation.h35
-rw-r--r--arch/arm64/kernel/traps.c66
-rw-r--r--arch/arm64/kernel/vmlinux.lds.S33
-rw-r--r--arch/arm64/kvm/hyp.S4
-rw-r--r--arch/arm64/kvm/sys_regs.c9
-rw-r--r--arch/arm64/lib/clear_user.S2
-rw-r--r--arch/arm64/mm/Makefile1
-rw-r--r--arch/arm64/mm/cache.S10
-rw-r--r--arch/arm64/mm/dump.c332
-rw-r--r--arch/arm64/mm/fault.c2
-rw-r--r--arch/arm64/mm/init.c2
-rw-r--r--arch/arm64/mm/ioremap.c93
-rw-r--r--arch/arm64/mm/mm.h1
-rw-r--r--arch/arm64/mm/mmap.c12
-rw-r--r--arch/arm64/mm/mmu.c96
-rw-r--r--arch/arm64/mm/pgd.c4
-rw-r--r--arch/arm64/net/bpf_jit_comp.c13
-rw-r--r--arch/avr32/mach-at32ap/at32ap700x.c2
-rw-r--r--arch/avr32/mach-at32ap/include/mach/atmel-mci.h17
-rw-r--r--arch/ia64/kvm/kvm-ia64.c2
-rw-r--r--arch/m68k/atari/config.c27
-rw-r--r--arch/m68k/atari/stdma.c61
-rw-r--r--arch/m68k/include/asm/atari_stdma.h4
-rw-r--r--arch/m68k/include/asm/macintosh.h4
-rw-r--r--arch/m68k/include/asm/unistd.h2
-rw-r--r--arch/m68k/include/uapi/asm/unistd.h1
-rw-r--r--arch/m68k/kernel/syscalltable.S1
-rw-r--r--arch/m68k/mac/config.c146
-rw-r--r--arch/m68k/mm/init.c1
-rw-r--r--arch/m68k/sun3/config.c60
-rw-r--r--arch/microblaze/include/asm/tlb.h3
-rw-r--r--arch/mips/Kconfig14
-rw-r--r--arch/mips/Makefile9
-rw-r--r--arch/mips/cavium-octeon/octeon-irq.c2
-rw-r--r--arch/mips/include/asm/asmmacro-32.h6
-rw-r--r--arch/mips/include/asm/asmmacro.h18
-rw-r--r--arch/mips/include/asm/fpregdef.h14
-rw-r--r--arch/mips/include/asm/fpu.h4
-rw-r--r--arch/mips/include/asm/jump_label.h8
-rw-r--r--arch/mips/include/asm/mach-loongson/cpu-feature-overrides.h2
-rw-r--r--arch/mips/include/asm/mipsregs.h13
-rw-r--r--arch/mips/include/asm/r4kcache.h4
-rw-r--r--arch/mips/include/asm/uaccess.h18
-rw-r--r--arch/mips/include/uapi/asm/unistd.h15
-rw-r--r--arch/mips/kernel/bmips_vec.S3
-rw-r--r--arch/mips/kernel/branch.c8
-rw-r--r--arch/mips/kernel/cps-vec.S2
-rw-r--r--arch/mips/kernel/cpu-probe.c40
-rw-r--r--arch/mips/kernel/genex.S1
-rw-r--r--arch/mips/kernel/jump_label.c42
-rw-r--r--arch/mips/kernel/r2300_fpu.S6
-rw-r--r--arch/mips/kernel/r2300_switch.S5
-rw-r--r--arch/mips/kernel/r4k_fpu.S27
-rw-r--r--arch/mips/kernel/r4k_switch.S15
-rw-r--r--arch/mips/kernel/r6000_fpu.S5
-rw-r--r--arch/mips/kernel/rtlx.c4
-rw-r--r--arch/mips/kernel/scall32-o32.S1
-rw-r--r--arch/mips/kernel/scall64-64.S1
-rw-r--r--arch/mips/kernel/scall64-n32.S1
-rw-r--r--arch/mips/kernel/scall64-o32.S1
-rw-r--r--arch/mips/kernel/setup.c7
-rw-r--r--arch/mips/kernel/signal.c8
-rw-r--r--arch/mips/lib/memcpy.S1
-rw-r--r--arch/mips/lib/r3k_dump_tlb.c4
-rw-r--r--arch/mips/lib/strnlen_user.S6
-rw-r--r--arch/mips/loongson/common/Makefile3
-rw-r--r--arch/mips/loongson/loongson-3/numa.c1
-rw-r--r--arch/mips/math-emu/cp1emu.c6
-rw-r--r--arch/mips/mm/tlb-r4k.c4
-rw-r--r--arch/mips/mm/tlbex.c10
-rw-r--r--arch/mips/mti-sead3/sead3-leds.c8
-rw-r--r--arch/mips/netlogic/xlp/Makefile12
-rw-r--r--arch/mips/oprofile/backtrace.c2
-rw-r--r--arch/mips/pci/msi-xlp.c4
-rw-r--r--arch/mips/sgi-ip27/ip27-memory.c1
-rw-r--r--arch/nios2/Kconfig206
-rw-r--r--arch/nios2/Kconfig.debug17
-rw-r--r--arch/nios2/Makefile73
-rw-r--r--arch/nios2/boot/Makefile52
-rw-r--r--arch/nios2/boot/dts/3c120_devboard.dts164
-rw-r--r--arch/nios2/boot/install.sh52
-rw-r--r--arch/nios2/boot/linked_dtb.S19
-rw-r--r--arch/nios2/configs/3c120_defconfig77
-rw-r--r--arch/nios2/include/asm/Kbuild66
-rw-r--r--arch/nios2/include/asm/asm-macros.h309
-rw-r--r--arch/nios2/include/asm/asm-offsets.h20
-rw-r--r--arch/nios2/include/asm/cache.h36
-rw-r--r--arch/nios2/include/asm/cacheflush.h52
-rw-r--r--arch/nios2/include/asm/checksum.h78
-rw-r--r--arch/nios2/include/asm/cmpxchg.h61
-rw-r--r--arch/nios2/include/asm/cpuinfo.h57
-rw-r--r--arch/nios2/include/asm/delay.h21
-rw-r--r--arch/nios2/include/asm/dma-mapping.h140
-rw-r--r--arch/nios2/include/asm/elf.h101
-rw-r--r--arch/nios2/include/asm/entry.h120
-rw-r--r--arch/nios2/include/asm/io.h61
-rw-r--r--arch/nios2/include/asm/irq.h28
-rw-r--r--arch/nios2/include/asm/irqflags.h72
-rw-r--r--arch/nios2/include/asm/linkage.h25
-rw-r--r--arch/nios2/include/asm/mmu.h16
-rw-r--r--arch/nios2/include/asm/mmu_context.h66
-rw-r--r--arch/nios2/include/asm/mutex.h1
-rw-r--r--arch/nios2/include/asm/page.h109
-rw-r--r--arch/nios2/include/asm/pgalloc.h86
-rw-r--r--arch/nios2/include/asm/pgtable-bits.h35
-rw-r--r--arch/nios2/include/asm/pgtable.h310
-rw-r--r--arch/nios2/include/asm/processor.h103
-rw-r--r--arch/nios2/include/asm/ptrace.h33
-rw-r--r--arch/nios2/include/asm/registers.h71
-rw-r--r--arch/nios2/include/asm/setup.h38
-rw-r--r--arch/nios2/include/asm/signal.h22
-rw-r--r--arch/nios2/include/asm/string.h24
-rw-r--r--arch/nios2/include/asm/switch_to.h31
-rw-r--r--arch/nios2/include/asm/syscall.h138
-rw-r--r--arch/nios2/include/asm/syscalls.h25
-rw-r--r--arch/nios2/include/asm/thread_info.h120
-rw-r--r--arch/nios2/include/asm/timex.h24
-rw-r--r--arch/nios2/include/asm/tlb.h34
-rw-r--r--arch/nios2/include/asm/tlbflush.h46
-rw-r--r--arch/nios2/include/asm/traps.h19
-rw-r--r--arch/nios2/include/asm/uaccess.h231
-rw-r--r--arch/nios2/include/asm/ucontext.h32
-rw-r--r--arch/nios2/include/uapi/asm/Kbuild4
-rw-r--r--arch/nios2/include/uapi/asm/byteorder.h22
-rw-r--r--arch/nios2/include/uapi/asm/elf.h67
-rw-r--r--arch/nios2/include/uapi/asm/ptrace.h120
-rw-r--r--arch/nios2/include/uapi/asm/sigcontext.h28
-rw-r--r--arch/nios2/include/uapi/asm/signal.h23
-rw-r--r--arch/nios2/include/uapi/asm/swab.h37
-rw-r--r--arch/nios2/include/uapi/asm/unistd.h25
-rw-r--r--arch/nios2/kernel/Makefile24
-rw-r--r--arch/nios2/kernel/asm-offsets.c87
-rw-r--r--arch/nios2/kernel/cpuinfo.c197
-rw-r--r--arch/nios2/kernel/entry.S555
-rw-r--r--arch/nios2/kernel/head.S175
-rw-r--r--arch/nios2/kernel/insnemu.S592
-rw-r--r--arch/nios2/kernel/irq.c93
-rw-r--r--arch/nios2/kernel/misaligned.c256
-rw-r--r--arch/nios2/kernel/module.c138
-rw-r--r--arch/nios2/kernel/nios2_ksyms.c33
-rw-r--r--arch/nios2/kernel/process.c258
-rw-r--r--arch/nios2/kernel/prom.c65
-rw-r--r--arch/nios2/kernel/ptrace.c166
-rw-r--r--arch/nios2/kernel/setup.c218
-rw-r--r--arch/nios2/kernel/signal.c323
-rw-r--r--arch/nios2/kernel/sys_nios2.c53
-rw-r--r--arch/nios2/kernel/syscall_table.c29
-rw-r--r--arch/nios2/kernel/time.c308
-rw-r--r--arch/nios2/kernel/traps.c185
-rw-r--r--arch/nios2/kernel/vmlinux.lds.S75
-rw-r--r--arch/nios2/lib/Makefile8
-rw-r--r--arch/nios2/lib/delay.c52
-rw-r--r--arch/nios2/lib/memcpy.c202
-rw-r--r--arch/nios2/lib/memmove.c82
-rw-r--r--arch/nios2/lib/memset.c81
-rw-r--r--arch/nios2/mm/Makefile14
-rw-r--r--arch/nios2/mm/cacheflush.c271
-rw-r--r--arch/nios2/mm/dma-mapping.c186
-rw-r--r--arch/nios2/mm/extable.c25
-rw-r--r--arch/nios2/mm/fault.c251
-rw-r--r--arch/nios2/mm/init.c142
-rw-r--r--arch/nios2/mm/ioremap.c187
-rw-r--r--arch/nios2/mm/mmu_context.c116
-rw-r--r--arch/nios2/mm/pgtable.c74
-rw-r--r--arch/nios2/mm/tlb.c275
-rw-r--r--arch/nios2/mm/uaccess.c163
-rw-r--r--arch/nios2/platform/Kconfig.platform129
-rw-r--r--arch/nios2/platform/Makefile1
-rw-r--r--arch/nios2/platform/platform.c46
-rw-r--r--arch/parisc/include/asm/uaccess.h19
-rw-r--r--arch/parisc/include/uapi/asm/bitsperlong.h8
-rw-r--r--arch/parisc/include/uapi/asm/msgbuf.h8
-rw-r--r--arch/parisc/include/uapi/asm/sembuf.h6
-rw-r--r--arch/parisc/include/uapi/asm/shmbuf.h35
-rw-r--r--arch/parisc/include/uapi/asm/signal.h2
-rw-r--r--arch/parisc/include/uapi/asm/unistd.h3
-rw-r--r--arch/parisc/kernel/syscall_table.S9
-rw-r--r--arch/powerpc/include/asm/fadump.h52
-rw-r--r--arch/powerpc/include/asm/pci-bridge.h2
-rw-r--r--arch/powerpc/include/asm/pgalloc.h3
-rw-r--r--arch/powerpc/include/asm/tlb.h1
-rw-r--r--arch/powerpc/kernel/eeh_sysfs.c2
-rw-r--r--arch/powerpc/kernel/entry_64.S6
-rw-r--r--arch/powerpc/kernel/fadump.c114
-rw-r--r--arch/powerpc/kernel/pci_64.c10
-rw-r--r--arch/powerpc/kernel/vdso32/getcpu.S4
-rw-r--r--arch/powerpc/mm/hugetlbpage.c2
-rw-r--r--arch/powerpc/mm/init_32.c2
-rw-r--r--arch/powerpc/platforms/powernv/opal-hmi.c2
-rw-r--r--arch/powerpc/platforms/powernv/opal-lpc.c59
-rw-r--r--arch/powerpc/platforms/powernv/opal-sensor.c20
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c5
-rw-r--r--arch/powerpc/platforms/powernv/pci.c3
-rw-r--r--arch/powerpc/platforms/pseries/dlpar.c4
-rw-r--r--arch/powerpc/platforms/pseries/lpar.c14
-rw-r--r--arch/powerpc/platforms/pseries/msi.c2
-rw-r--r--arch/powerpc/sysdev/fsl_msi.c2
-rw-r--r--arch/powerpc/xmon/xmon.c6
-rw-r--r--arch/s390/configs/default_defconfig36
-rw-r--r--arch/s390/configs/gcov_defconfig25
-rw-r--r--arch/s390/configs/performance_defconfig30
-rw-r--r--arch/s390/configs/zfcpdump_defconfig10
-rw-r--r--arch/s390/defconfig5
-rw-r--r--arch/s390/kernel/ftrace.c2
-rw-r--r--arch/s390/kernel/nmi.c8
-rw-r--r--arch/s390/kernel/vdso32/clock_gettime.S12
-rw-r--r--arch/s390/kernel/vdso32/gettimeofday.S14
-rw-r--r--arch/s390/kernel/vdso64/clock_gettime.S13
-rw-r--r--arch/s390/kernel/vdso64/gettimeofday.S6
-rw-r--r--arch/s390/kernel/vtime.c4
-rw-r--r--arch/sparc/include/asm/atomic_32.h2
-rw-r--r--arch/sparc/include/asm/cmpxchg_32.h12
-rw-r--r--arch/sparc/include/asm/dma-mapping.h8
-rw-r--r--arch/sparc/include/uapi/asm/swab.h12
-rw-r--r--arch/sparc/kernel/pci_schizo.c6
-rw-r--r--arch/sparc/kernel/smp_64.c4
-rw-r--r--arch/sparc/lib/atomic32.c27
-rw-r--r--arch/x86/Kconfig2
-rw-r--r--arch/x86/boot/compressed/Makefile4
-rw-r--r--arch/x86/boot/compressed/head_32.S5
-rw-r--r--arch/x86/boot/compressed/head_64.S5
-rw-r--r--arch/x86/boot/compressed/misc.c13
-rw-r--r--arch/x86/boot/compressed/mkpiggy.c9
-rw-r--r--arch/x86/include/asm/page_32_types.h1
-rw-r--r--arch/x86/include/asm/page_64_types.h11
-rw-r--r--arch/x86/include/asm/smp.h1
-rw-r--r--arch/x86/include/asm/thread_info.h2
-rw-r--r--arch/x86/include/asm/traps.h1
-rw-r--r--arch/x86/kernel/amd_nb.c2
-rw-r--r--arch/x86/kernel/cpu/common.c2
-rw-r--r--arch/x86/kernel/cpu/microcode/amd_early.c33
-rw-r--r--arch/x86/kernel/cpu/microcode/core.c10
-rw-r--r--arch/x86/kernel/cpu/microcode/core_early.c2
-rw-r--r--arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c49
-rw-r--r--arch/x86/kernel/dumpstack_64.c1
-rw-r--r--arch/x86/kernel/entry_64.S81
-rw-r--r--arch/x86/kernel/ptrace.c2
-rw-r--r--arch/x86/kernel/smpboot.c15
-rw-r--r--arch/x86/kernel/traps.c71
-rw-r--r--arch/x86/kvm/emulate.c8
-rw-r--r--arch/x86/kvm/mmu.c6
-rw-r--r--arch/x86/lib/csum-wrappers_64.c5
-rw-r--r--arch/x86/mm/init_64.c11
-rw-r--r--arch/x86/tools/calc_run_size.pl39
-rw-r--r--arch/x86/xen/smp.c3
-rw-r--r--arch/xtensa/Kconfig4
-rw-r--r--arch/xtensa/boot/dts/lx200mx.dts16
-rw-r--r--arch/xtensa/configs/generic_kc705_defconfig131
-rw-r--r--arch/xtensa/configs/smp_lx200_defconfig135
-rw-r--r--arch/xtensa/include/asm/pgtable.h2
-rw-r--r--arch/xtensa/include/uapi/asm/unistd.h12
-rw-r--r--block/bio-integrity.c13
-rw-r--r--block/blk-core.c4
-rw-r--r--block/blk-merge.c19
-rw-r--r--block/blk-mq-tag.c28
-rw-r--r--block/blk-mq.c43
-rw-r--r--block/ioprio.c14
-rw-r--r--block/scsi_ioctl.c10
-rw-r--r--drivers/acpi/blacklist.c8
-rw-r--r--drivers/acpi/device_pm.c2
-rw-r--r--drivers/acpi/video.c3
-rw-r--r--drivers/ata/ahci.c32
-rw-r--r--drivers/ata/libahci.c78
-rw-r--r--drivers/ata/libata-scsi.c19
-rw-r--r--drivers/ata/sata_fsl.c2
-rw-r--r--drivers/ata/sata_nv.c2
-rw-r--r--drivers/ata/sata_rcar.c15
-rw-r--r--drivers/atm/solos-pci.c2
-rw-r--r--drivers/base/Kconfig19
-rw-r--r--drivers/base/core.c4
-rw-r--r--drivers/base/power/domain.c42
-rw-r--r--drivers/base/regmap/Kconfig5
-rw-r--r--drivers/base/regmap/Makefile1
-rw-r--r--drivers/base/regmap/regcache-flat.c2
-rw-r--r--drivers/base/regmap/regcache-lzo.c2
-rw-r--r--drivers/base/regmap/regcache-rbtree.c4
-rw-r--r--drivers/base/regmap/regcache.c63
-rw-r--r--drivers/base/regmap/regmap-ac97.c114
-rw-r--r--drivers/block/nvme-scsi.c4
-rw-r--r--drivers/block/rbd.c35
-rw-r--r--drivers/block/zram/zram_drv.c3
-rw-r--r--drivers/bus/omap_l3_smx.c26
-rw-r--r--drivers/char/hw_random/pseries-rng.c11
-rw-r--r--drivers/char/virtio_console.c4
-rw-r--r--drivers/clk/at91/clk-usb.c35
-rw-r--r--drivers/clk/clk-divider.c18
-rw-r--r--drivers/clk/clk-s2mps11.c24
-rw-r--r--drivers/clk/pxa/clk-pxa27x.c4
-rw-r--r--drivers/clk/qcom/mmcc-apq8084.c2
-rw-r--r--drivers/clk/rockchip/clk.c4
-rw-r--r--drivers/clk/versatile/Makefile1
-rw-r--r--drivers/clk/versatile/clk-vexpress-osc.c7
-rw-r--r--drivers/clk/versatile/clk-vexpress.c86
-rw-r--r--drivers/clocksource/sun4i_timer.c12
-rw-r--r--drivers/clocksource/timer-atmel-pit.c32
-rw-r--r--drivers/cpufreq/cpufreq-dt.c4
-rw-r--r--drivers/cpufreq/cpufreq.c3
-rw-r--r--drivers/crypto/caam/key_gen.c29
-rw-r--r--drivers/crypto/qat/qat_common/adf_accel_devices.h3
-rw-r--r--drivers/crypto/qat/qat_common/adf_transport.c12
-rw-r--r--drivers/crypto/qat/qat_common/qat_algs.c7
-rw-r--r--drivers/crypto/qat/qat_common/qat_crypto.c8
-rw-r--r--drivers/crypto/qat/qat_dh895xcc/adf_admin.c2
-rw-r--r--drivers/crypto/qat/qat_dh895xcc/adf_drv.c32
-rw-r--r--drivers/crypto/qat/qat_dh895xcc/adf_isr.c2
-rw-r--r--drivers/dma/edma.c40
-rw-r--r--drivers/dma/pl330.c23
-rw-r--r--drivers/dma/sun6i-dma.c61
-rw-r--r--drivers/edac/Kconfig16
-rw-r--r--drivers/edac/Makefile2
-rw-r--r--drivers/edac/amd64_edac.c260
-rw-r--r--drivers/edac/amd64_edac.h15
-rw-r--r--drivers/edac/edac_mc.c40
-rw-r--r--drivers/edac/edac_pci_sysfs.c5
-rw-r--r--drivers/edac/ghes_edac.c4
-rw-r--r--drivers/edac/i3000_edac.c3
-rw-r--r--drivers/edac/i3200_edac.c3
-rw-r--r--drivers/edac/i82443bxgx_edac.c3
-rw-r--r--drivers/edac/mce_amd.c47
-rw-r--r--drivers/edac/mce_amd_inj.c293
-rw-r--r--drivers/edac/mv64x60_edac.c8
-rw-r--r--drivers/edac/ppc4xx_edac.c4
-rw-r--r--drivers/edac/x38_edac.c3
-rw-r--r--drivers/firewire/core-cdev.c3
-rw-r--r--drivers/firmware/dmi_scan.c79
-rw-r--r--drivers/firmware/efi/efi.c4
-rw-r--r--drivers/firmware/efi/libstub/arm-stub.c11
-rw-r--r--drivers/gpio/Kconfig12
-rw-r--r--drivers/gpio/Makefile1
-rw-r--r--drivers/gpio/gpio-dln2.c553
-rw-r--r--drivers/gpio/gpio-tc3589x.c2
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_drv.c49
-rw-r--r--drivers/gpu/drm/exynos/exynos_drm_g2d.c9
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c10
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c10
-rw-r--r--drivers/gpu/drm/i915/i915_gem_gtt.c16
-rw-r--r--drivers/gpu/drm/i915/i915_gem_tiling.c19
-rw-r--r--drivers/gpu/drm/i915/intel_display.c6
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c1
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c22
-rw-r--r--drivers/gpu/drm/i915/intel_panel.c17
-rw-r--r--drivers/gpu/drm/i915/intel_pm.c5
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/device/nvc0.c1
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/fifo/nv04.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/fifo/nvc0.c4
-rw-r--r--drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c2
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/fb/gk20a.c16
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drm.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fence.c92
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_fence.h4
-rw-r--r--drivers/gpu/drm/nouveau/nv50_display.c25
-rw-r--r--drivers/gpu/drm/radeon/atom.c11
-rw-r--r--drivers/gpu/drm/radeon/atom.h2
-rw-r--r--drivers/gpu/drm/radeon/atombios_dp.c4
-rw-r--r--drivers/gpu/drm/radeon/atombios_i2c.c4
-rw-r--r--drivers/gpu/drm/radeon/cik.c7
-rw-r--r--drivers/gpu/drm/radeon/cik_sdma.c21
-rw-r--r--drivers/gpu/drm/radeon/evergreen.c4
-rw-r--r--drivers/gpu/drm/radeon/r100.c3
-rw-r--r--drivers/gpu/drm/radeon/r600_dma.c20
-rw-r--r--drivers/gpu/drm/radeon/r600_dpm.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_connectors.c19
-rw-r--r--drivers/gpu/drm/radeon/radeon_cs.c17
-rw-r--r--drivers/gpu/drm/radeon/radeon_device.c1
-rw-r--r--drivers/gpu/drm/radeon/radeon_encoders.c3
-rw-r--r--drivers/gpu/drm/radeon/radeon_irq_kms.c10
-rw-r--r--drivers/gpu/drm/radeon/radeon_kms.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_object.c7
-rw-r--r--drivers/gpu/drm/radeon/rs600.c3
-rw-r--r--drivers/gpu/drm/radeon/rs690.c3
-rw-r--r--drivers/gpu/drm/radeon/rv515.c3
-rw-r--r--drivers/gpu/drm/radeon/si.c3
-rw-r--r--drivers/gpu/drm/tegra/dc.c9
-rw-r--r--drivers/hid/hid-core.c1
-rw-r--r--drivers/hid/hid-ids.h1
-rw-r--r--drivers/hid/hid-sensor-hub.c8
-rw-r--r--drivers/hid/usbhid/hid-quirks.c1
-rw-r--r--drivers/hwmon/Kconfig28
-rw-r--r--drivers/hwmon/Makefile1
-rw-r--r--drivers/hwmon/fam15h_power.c2
-rw-r--r--drivers/hwmon/g762.c6
-rw-r--r--drivers/hwmon/gpio-fan.c18
-rw-r--r--drivers/hwmon/ibmpowernv.c76
-rw-r--r--drivers/hwmon/iio_hwmon.c7
-rw-r--r--drivers/hwmon/ina2xx.c26
-rw-r--r--drivers/hwmon/lm75.c12
-rw-r--r--drivers/hwmon/lm95234.c91
-rw-r--r--drivers/hwmon/lm95245.c41
-rw-r--r--drivers/hwmon/nct6775.c77
-rw-r--r--drivers/hwmon/nct7802.c860
-rw-r--r--drivers/hwmon/pmbus/Kconfig11
-rw-r--r--drivers/hwmon/pmbus/ltc2978.c39
-rw-r--r--drivers/hwmon/pmbus/pmbus.h30
-rw-r--r--drivers/hwmon/pmbus/pmbus_core.c118
-rw-r--r--drivers/hwmon/pwm-fan.c13
-rw-r--r--drivers/hwmon/tmp401.c42
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c5
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c5
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c5
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.h7
-rw-r--r--drivers/i2c/busses/Kconfig10
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c4
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c4
-rw-r--r--drivers/i2c/busses/i2c-amd756-s4882.c4
-rw-r--r--drivers/i2c/busses/i2c-amd756.c4
-rw-r--r--drivers/i2c/busses/i2c-at91.c2
-rw-r--r--drivers/i2c/busses/i2c-au1550.c4
-rw-r--r--drivers/i2c/busses/i2c-cadence.c11
-rw-r--r--drivers/i2c/busses/i2c-cpm.c4
-rw-r--r--drivers/i2c/busses/i2c-davinci.c12
-rw-r--r--drivers/i2c/busses/i2c-designware-core.c6
-rw-r--r--drivers/i2c/busses/i2c-designware-core.h4
-rw-r--r--drivers/i2c/busses/i2c-designware-pcidrv.c4
-rw-r--r--drivers/i2c/busses/i2c-designware-platdrv.c4
-rw-r--r--drivers/i2c/busses/i2c-dln2.c262
-rw-r--r--drivers/i2c/busses/i2c-eg20t.c4
-rw-r--r--drivers/i2c/busses/i2c-elektor.c6
-rw-r--r--drivers/i2c/busses/i2c-hydra.c4
-rw-r--r--drivers/i2c/busses/i2c-i801.c4
-rw-r--r--drivers/i2c/busses/i2c-imx.c5
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.h6
-rw-r--r--drivers/i2c/busses/i2c-isch.c4
-rw-r--r--drivers/i2c/busses/i2c-ismt.c4
-rw-r--r--drivers/i2c/busses/i2c-nforce2-s4985.c4
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c4
-rw-r--r--drivers/i2c/busses/i2c-omap.c14
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c4
-rw-r--r--drivers/i2c/busses/i2c-parport.c4
-rw-r--r--drivers/i2c/busses/i2c-parport.h4
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c4
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c4
-rw-r--r--drivers/i2c/busses/i2c-piix4.c4
-rw-r--r--drivers/i2c/busses/i2c-pmcmsp.c4
-rw-r--r--drivers/i2c/busses/i2c-powermac.c4
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c4
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c4
-rw-r--r--drivers/i2c/busses/i2c-sibyte.c4
-rw-r--r--drivers/i2c/busses/i2c-simtec.c4
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c4
-rw-r--r--drivers/i2c/busses/i2c-sis630.c4
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c4
-rw-r--r--drivers/i2c/busses/i2c-taos-evm.c4
-rw-r--r--drivers/i2c/busses/i2c-via.c4
-rw-r--r--drivers/i2c/busses/i2c-viapro.c4
-rw-r--r--drivers/i2c/busses/i2c-xiic.c4
-rw-r--r--drivers/i2c/busses/scx200_acb.c4
-rw-r--r--drivers/i2c/i2c-boardinfo.c5
-rw-r--r--drivers/i2c/i2c-core.c10
-rw-r--r--drivers/i2c/i2c-core.h5
-rw-r--r--drivers/i2c/i2c-dev.c5
-rw-r--r--drivers/i2c/i2c-smbus.c5
-rw-r--r--drivers/i2c/i2c-stub.c4
-rw-r--r--drivers/iio/accel/bmc150-accel.c40
-rw-r--r--drivers/iio/accel/kxcjk-1013.c4
-rw-r--r--drivers/iio/adc/Kconfig8
-rw-r--r--drivers/iio/adc/Makefile1
-rw-r--r--drivers/iio/adc/axp288_adc.c261
-rw-r--r--drivers/iio/adc/men_z188_adc.c1
-rw-r--r--drivers/iio/gyro/bmg160.c53
-rw-r--r--drivers/iio/light/tsl4531.c7
-rw-r--r--drivers/iio/proximity/as3935.c2
-rw-r--r--drivers/infiniband/ulp/iser/iscsi_iser.c3
-rw-r--r--drivers/infiniband/ulp/isert/ib_isert.c44
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c1100
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.h75
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c8
-rw-r--r--drivers/input/evdev.c2
-rw-r--r--drivers/input/joystick/xpad.c16
-rw-r--r--drivers/input/misc/twl4030-pwrbutton.c1
-rw-r--r--drivers/input/mouse/alps.c28
-rw-r--r--drivers/input/mouse/elantech.c64
-rw-r--r--drivers/input/mouse/synaptics.c9
-rw-r--r--drivers/irqchip/irq-armada-370-xp.c23
-rw-r--r--drivers/irqchip/irq-atmel-aic-common.c6
-rw-r--r--drivers/irqchip/irq-bcm7120-l2.c4
-rw-r--r--drivers/irqchip/irq-brcmstb-l2.c4
-rw-r--r--drivers/md/dm-bio-prison.c186
-rw-r--r--drivers/md/dm-bio-prison.h28
-rw-r--r--drivers/md/dm-bufio.c238
-rw-r--r--drivers/md/dm-cache-block-types.h11
-rw-r--r--drivers/md/dm-cache-metadata.c34
-rw-r--r--drivers/md/dm-cache-metadata.h6
-rw-r--r--drivers/md/dm-cache-policy-mq.c82
-rw-r--r--drivers/md/dm-cache-target.c378
-rw-r--r--drivers/md/dm-crypt.c2
-rw-r--r--drivers/md/dm-ioctl.c5
-rw-r--r--drivers/md/dm-raid.c17
-rw-r--r--drivers/md/dm-stats.c2
-rw-r--r--drivers/md/dm-stripe.c4
-rw-r--r--drivers/md/dm-table.c36
-rw-r--r--drivers/md/dm-thin-metadata.c35
-rw-r--r--drivers/md/dm-thin-metadata.h9
-rw-r--r--drivers/md/dm-thin.c766
-rw-r--r--drivers/md/dm.c273
-rw-r--r--drivers/md/dm.h10
-rw-r--r--drivers/md/md.c4
-rw-r--r--drivers/md/persistent-data/dm-array.c4
-rw-r--r--drivers/md/persistent-data/dm-btree-internal.h6
-rw-r--r--drivers/md/persistent-data/dm-btree-spine.c2
-rw-r--r--drivers/md/persistent-data/dm-btree.c24
-rw-r--r--drivers/md/persistent-data/dm-space-map-metadata.c8
-rw-r--r--drivers/md/persistent-data/dm-transaction-manager.c77
-rw-r--r--drivers/md/persistent-data/dm-transaction-manager.h7
-rw-r--r--drivers/media/dvb-core/dvb_frontend.c6
-rw-r--r--drivers/media/dvb-frontends/ds3000.c7
-rw-r--r--drivers/media/dvb-frontends/sp2.c4
-rw-r--r--drivers/media/dvb-frontends/tc90522.c18
-rw-r--r--drivers/media/i2c/smiapp/smiapp-core.c2
-rw-r--r--drivers/media/pci/cx23885/cx23885-core.c6
-rw-r--r--drivers/media/pci/solo6x10/solo6x10-core.c10
-rw-r--r--drivers/media/platform/vivid/vivid-core.c11
-rw-r--r--drivers/media/rc/imon.c3
-rw-r--r--drivers/media/rc/ir-hix5hd2.c2
-rw-r--r--drivers/media/rc/ir-rc5-decoder.c2
-rw-r--r--drivers/media/rc/ir-rc6-decoder.c2
-rw-r--r--drivers/media/rc/rc-ir-raw.c1
-rw-r--r--drivers/media/rc/rc-main.c2
-rw-r--r--drivers/media/usb/s2255/s2255drv.c2
-rw-r--r--drivers/message/fusion/mptsas.c1
-rw-r--r--drivers/message/fusion/mptscsih.c22
-rw-r--r--drivers/message/fusion/mptscsih.h3
-rw-r--r--drivers/mfd/Kconfig25
-rw-r--r--drivers/mfd/Makefile4
-rw-r--r--drivers/mfd/ab8500-sysctrl.c57
-rw-r--r--drivers/mfd/arizona-spi.c2
-rw-r--r--drivers/mfd/atmel-hlcdc.c122
-rw-r--r--drivers/mfd/axp20x.c361
-rw-r--r--drivers/mfd/da9063-core.c4
-rw-r--r--drivers/mfd/db8500-prcmu.c22
-rw-r--r--drivers/mfd/dln2.c781
-rw-r--r--drivers/mfd/lpc_sch.c6
-rw-r--r--drivers/mfd/max14577.c2
-rw-r--r--drivers/mfd/max77693.c45
-rw-r--r--drivers/mfd/mfd-core.c8
-rw-r--r--drivers/mfd/rts5227.c6
-rw-r--r--drivers/mfd/rts5249.c4
-rw-r--r--drivers/mfd/rtsx_gops.c37
-rw-r--r--drivers/mfd/rtsx_pcr.c2
-rw-r--r--drivers/mfd/rtsx_pcr.h3
-rw-r--r--drivers/mfd/rtsx_usb.c4
-rw-r--r--drivers/mfd/sec-core.c39
-rw-r--r--drivers/mfd/sec-irq.c23
-rw-r--r--drivers/mfd/stmpe.h2
-rw-r--r--drivers/mfd/syscon.c96
-rw-r--r--drivers/mfd/t7l66xb.c14
-rw-r--r--drivers/mfd/tc3589x.c9
-rw-r--r--drivers/mfd/tc6387xb.c10
-rw-r--r--drivers/mfd/tc6393xb.c23
-rw-r--r--drivers/mfd/tps65090.c62
-rw-r--r--drivers/mfd/tps65217.c2
-rw-r--r--drivers/mfd/twl4030-power.c55
-rw-r--r--drivers/mfd/viperboard.c4
-rw-r--r--drivers/mfd/wm5102-tables.c6
-rw-r--r--drivers/mfd/wm5110-tables.c20
-rw-r--r--drivers/mfd/wm8350-core.c2
-rw-r--r--drivers/mfd/wm8997-tables.c6
-rw-r--r--drivers/misc/Kconfig2
-rw-r--r--drivers/misc/eeprom/eeprom_93cx6.c62
-rw-r--r--drivers/misc/enclosure.c44
-rw-r--r--drivers/misc/vexpress-syscfg.c60
-rw-r--r--drivers/mmc/card/block.c83
-rw-r--r--drivers/mmc/card/mmc_test.c28
-rw-r--r--drivers/mmc/card/queue.c16
-rw-r--r--drivers/mmc/core/bus.c55
-rw-r--r--drivers/mmc/core/core.c111
-rw-r--r--drivers/mmc/core/core.h1
-rw-r--r--drivers/mmc/core/debugfs.c9
-rw-r--r--drivers/mmc/core/host.c21
-rw-r--r--drivers/mmc/core/mmc.c184
-rw-r--r--drivers/mmc/core/mmc_ops.c130
-rw-r--r--drivers/mmc/core/mmc_ops.h2
-rw-r--r--drivers/mmc/core/sdio.c10
-rw-r--r--drivers/mmc/core/sdio_bus.c16
-rw-r--r--drivers/mmc/host/Kconfig7
-rw-r--r--drivers/mmc/host/Makefile1
-rw-r--r--drivers/mmc/host/atmel-mci.c207
-rw-r--r--drivers/mmc/host/dw_mmc-exynos.c91
-rw-r--r--drivers/mmc/host/dw_mmc-pltfm.c6
-rw-r--r--drivers/mmc/host/dw_mmc-rockchip.c13
-rw-r--r--drivers/mmc/host/dw_mmc.c346
-rw-r--r--drivers/mmc/host/dw_mmc.h15
-rw-r--r--drivers/mmc/host/mmci.c7
-rw-r--r--drivers/mmc/host/msm_sdcc.c6
-rw-r--r--drivers/mmc/host/mvsdio.c7
-rw-r--r--drivers/mmc/host/mxcmmc.c25
-rw-r--r--drivers/mmc/host/mxs-mmc.c26
-rw-r--r--drivers/mmc/host/omap_hsmmc.c286
-rw-r--r--drivers/mmc/host/sdhci-acpi.c52
-rw-r--r--drivers/mmc/host/sdhci-esdhc-imx.c78
-rw-r--r--drivers/mmc/host/sdhci-msm.c50
-rw-r--r--drivers/mmc/host/sdhci-of-arasan.c5
-rw-r--r--drivers/mmc/host/sdhci-pci-o2micro.c2
-rw-r--r--drivers/mmc/host/sdhci-pci.c56
-rw-r--r--drivers/mmc/host/sdhci-pxav2.c15
-rw-r--r--drivers/mmc/host/sdhci-pxav3.c60
-rw-r--r--drivers/mmc/host/sdhci-s3c.c8
-rw-r--r--drivers/mmc/host/sdhci.c273
-rw-r--r--drivers/mmc/host/sdhci.h45
-rw-r--r--drivers/mmc/host/sunxi-mmc.c1
-rw-r--r--drivers/mmc/host/toshsd.c717
-rw-r--r--drivers/mmc/host/toshsd.h176
-rw-r--r--drivers/net/bonding/bond_main.c3
-rw-r--r--drivers/net/bonding/bond_netlink.c7
-rw-r--r--drivers/net/can/dev.c4
-rw-r--r--drivers/net/can/m_can/Kconfig1
-rw-r--r--drivers/net/can/m_can/m_can.c219
-rw-r--r--drivers/net/can/rcar_can.c1
-rw-r--r--drivers/net/can/sja1000/kvaser_pci.c5
-rw-r--r--drivers/net/can/usb/ems_usb.c3
-rw-r--r--drivers/net/can/usb/esd_usb2.c3
-rw-r--r--drivers/net/can/usb/gs_usb.c1
-rw-r--r--drivers/net/can/xilinx_can.c4
-rw-r--r--drivers/net/dsa/bcm_sf2.c58
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_hw.c18
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_hw.h4
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_main.c11
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_main.h5
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_sgmac.c7
-rw-r--r--drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c7
-rw-r--r--drivers/net/ethernet/broadcom/bcmsysport.c13
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmgenet.c11
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmgenet.h3
-rw-r--r--drivers/net/ethernet/broadcom/genet/bcmmii.c9
-rw-r--r--drivers/net/ethernet/broadcom/tg3.c3
-rw-r--r--drivers/net/ethernet/cadence/Kconfig2
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c33
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c8
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/sge.c30
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/t4_hw.c51
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/t4_regs.h10
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4vf/adapter.h8
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4vf/sge.c136
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4vf/t4vf_common.h2
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c28
-rw-r--r--drivers/net/ethernet/cisco/enic/enic_main.c20
-rw-r--r--drivers/net/ethernet/emulex/benet/be_main.c11
-rw-r--r--drivers/net/ethernet/freescale/fec_main.c39
-rw-r--r--drivers/net/ethernet/intel/igb/igb_main.c23
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c17
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c4
-rw-r--r--drivers/net/ethernet/marvell/mv643xx_eth.c18
-rw-r--r--drivers/net/ethernet/marvell/mvpp2.c27
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_netdev.c35
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/resource_tracker.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/eq.c7
-rw-r--r--drivers/net/ethernet/mellanox/mlx5/core/main.c4
-rw-r--r--drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c3
-rw-r--r--drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c6
-rw-r--r--drivers/net/ethernet/qualcomm/Kconfig3
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.c96
-rw-r--r--drivers/net/ethernet/renesas/sh_eth.h5
-rw-r--r--drivers/net/ethernet/sfc/ef10.c3
-rw-r--r--drivers/net/ethernet/smsc/smc91x.c20
-rw-r--r--drivers/net/ethernet/smsc/smsc911x.c61
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_main.c52
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c27
-rw-r--r--drivers/net/ethernet/sun/sunhme.c62
-rw-r--r--drivers/net/ethernet/ti/cpsw.c6
-rw-r--r--drivers/net/ethernet/ti/cpsw_ale.c1
-rw-r--r--drivers/net/ethernet/ti/cpts.c2
-rw-r--r--drivers/net/ieee802154/fakehard.c13
-rw-r--r--drivers/net/macvtap.c2
-rw-r--r--drivers/net/phy/dp83640.c4
-rw-r--r--drivers/net/phy/phy.c36
-rw-r--r--drivers/net/ppp/ppp_generic.c40
-rw-r--r--drivers/net/ppp/pptp.c4
-rw-r--r--drivers/net/tun.c28
-rw-r--r--drivers/net/usb/asix_devices.c14
-rw-r--r--drivers/net/usb/qmi_wwan.c1
-rw-r--r--drivers/net/virtio_net.c37
-rw-r--r--drivers/net/vxlan.c41
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c13
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c13
-rw-r--r--drivers/net/wireless/ath/ath9k/main.c9
-rw-r--r--drivers/net/wireless/b43/phy_common.c4
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/of.c4
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/pcie.c2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/usb.c6
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-fw.h2
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/fw.c10
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mac80211.c13
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/mvm.h1
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/ops.c12
-rw-r--r--drivers/net/wireless/iwlwifi/mvm/scan.c20
-rw-r--r--drivers/net/wireless/iwlwifi/pcie/trans.c7
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c4
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00queue.c50
-rw-r--r--drivers/net/wireless/rtlwifi/pci.c39
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192se/hw.c7
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192se/phy.c2
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192se/sw.c16
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8821ae/hw.c5
-rw-r--r--drivers/net/xen-netback/xenbus.c15
-rw-r--r--drivers/net/xen-netfront.c5
-rw-r--r--drivers/nubus/nubus.c4
-rw-r--r--drivers/of/address.c19
-rw-r--r--drivers/of/base.c88
-rw-r--r--drivers/of/dynamic.c2
-rw-r--r--drivers/of/fdt.c4
-rw-r--r--drivers/of/selftest.c77
-rw-r--r--drivers/of/testcase-data/tests-phandle.dtsi2
-rw-r--r--drivers/pci/access.c2
-rw-r--r--drivers/pci/host/pci-tegra.c28
-rw-r--r--drivers/pci/host/pci-xgene.c7
-rw-r--r--drivers/pci/msi.c26
-rw-r--r--drivers/pci/pci.h2
-rw-r--r--drivers/pci/probe.c30
-rw-r--r--drivers/phy/phy-omap-usb2.c6
-rw-r--r--drivers/pinctrl/pinctrl-baytrail.c8
-rw-r--r--drivers/platform/x86/Kconfig1
-rw-r--r--drivers/platform/x86/acer-wmi.c11
-rw-r--r--drivers/platform/x86/asus-nb-wmi.c9
-rw-r--r--drivers/platform/x86/hp_accel.c44
-rw-r--r--drivers/platform/x86/ideapad-laptop.c7
-rw-r--r--drivers/platform/x86/samsung-laptop.c10
-rw-r--r--drivers/platform/x86/toshiba_acpi.c6
-rw-r--r--drivers/power/ab8500_fg.c17
-rw-r--r--drivers/power/bq2415x_charger.c23
-rw-r--r--drivers/power/charger-manager.c164
-rw-r--r--drivers/power/power_supply_core.c3
-rw-r--r--drivers/power/reset/at91-reset.c4
-rw-r--r--drivers/regulator/88pm8607.c3
-rw-r--r--drivers/regulator/Kconfig20
-rw-r--r--drivers/regulator/Makefile1
-rw-r--r--drivers/regulator/act8865-regulator.c31
-rw-r--r--drivers/regulator/anatop-regulator.c18
-rw-r--r--drivers/regulator/arizona-ldo1.c10
-rw-r--r--drivers/regulator/arizona-micsupp.c8
-rw-r--r--drivers/regulator/core.c23
-rw-r--r--drivers/regulator/da9052-regulator.c3
-rw-r--r--drivers/regulator/da9063-regulator.c19
-rw-r--r--drivers/regulator/da9210-regulator.c2
-rw-r--r--drivers/regulator/dummy.c2
-rw-r--r--drivers/regulator/fan53555.c17
-rw-r--r--drivers/regulator/fixed.c24
-rw-r--r--drivers/regulator/gpio-regulator.c115
-rw-r--r--drivers/regulator/max1586.c2
-rw-r--r--drivers/regulator/max77686.c172
-rw-r--r--drivers/regulator/max77693.c4
-rw-r--r--drivers/regulator/max77802.c254
-rw-r--r--drivers/regulator/max8660.c2
-rw-r--r--drivers/regulator/max8952.c4
-rw-r--r--drivers/regulator/max8973-regulator.c3
-rw-r--r--drivers/regulator/max8997.c3
-rw-r--r--drivers/regulator/max8998.c5
-rw-r--r--drivers/regulator/mc13xxx-regulator-core.c3
-rw-r--r--drivers/regulator/of_regulator.c90
-rw-r--r--drivers/regulator/pwm-regulator.c3
-rw-r--r--drivers/regulator/qcom_rpm-regulator.c28
-rw-r--r--drivers/regulator/rk808-regulator.c57
-rw-r--r--drivers/regulator/rn5t618-regulator.c51
-rw-r--r--drivers/regulator/rt5033-regulator.c123
-rw-r--r--drivers/regulator/s2mpa01.c4
-rw-r--r--drivers/regulator/s2mps11.c105
-rw-r--r--drivers/regulator/s5m8767.c4
-rw-r--r--drivers/regulator/sky81452-regulator.c46
-rw-r--r--drivers/regulator/stw481x-vmmc.c3
-rw-r--r--drivers/regulator/ti-abb-regulator.c3
-rw-r--r--drivers/regulator/tps51632-regulator.c43
-rw-r--r--drivers/regulator/tps62360-regulator.c31
-rw-r--r--drivers/regulator/tps65090-regulator.c4
-rw-r--r--drivers/regulator/tps65218-regulator.c3
-rw-r--r--drivers/regulator/twl-regulator.c3
-rw-r--r--drivers/regulator/vexpress.c3
-rw-r--r--drivers/regulator/wm8994-regulator.c6
-rw-r--r--drivers/rtc/Kconfig6
-rw-r--r--drivers/s390/kvm/virtio_ccw.c1
-rw-r--r--drivers/s390/scsi/zfcp_aux.c6
-rw-r--r--drivers/s390/scsi/zfcp_ccw.c32
-rw-r--r--drivers/s390/scsi/zfcp_def.h3
-rw-r--r--drivers/s390/scsi/zfcp_erp.c7
-rw-r--r--drivers/s390/scsi/zfcp_ext.h1
-rw-r--r--drivers/s390/scsi/zfcp_fc.c52
-rw-r--r--drivers/s390/scsi/zfcp_fc.h14
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c3
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c26
-rw-r--r--drivers/s390/scsi/zfcp_sysfs.c66
-rw-r--r--drivers/scsi/3w-9xxx.c15
-rw-r--r--drivers/scsi/3w-sas.c15
-rw-r--r--drivers/scsi/3w-xxxx.c15
-rw-r--r--drivers/scsi/53c700.c51
-rw-r--r--drivers/scsi/BusLogic.c4
-rw-r--r--drivers/scsi/Kconfig18
-rw-r--r--drivers/scsi/Makefile3
-rw-r--r--drivers/scsi/NCR5380.c310
-rw-r--r--drivers/scsi/NCR5380.h78
-rw-r--r--drivers/scsi/aacraid/aachba.c4
-rw-r--r--drivers/scsi/aacraid/linit.c20
-rw-r--r--drivers/scsi/advansys.c11
-rw-r--r--drivers/scsi/aha152x.c994
-rw-r--r--drivers/scsi/aha1740.c2
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c19
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.c23
-rw-r--r--drivers/scsi/aic94xx/aic94xx.h2
-rw-r--r--drivers/scsi/aic94xx/aic94xx_hwi.c3
-rw-r--r--drivers/scsi/aic94xx/aic94xx_init.c13
-rw-r--r--drivers/scsi/aic94xx/aic94xx_task.c13
-rw-r--r--drivers/scsi/am53c974.c586
-rw-r--r--drivers/scsi/arcmsr/arcmsr_hba.c9
-rw-r--r--drivers/scsi/arm/acornscsi.c12
-rw-r--r--drivers/scsi/arm/cumana_1.c18
-rw-r--r--drivers/scsi/arm/fas216.c39
-rw-r--r--drivers/scsi/arm/oak.c23
-rw-r--r--drivers/scsi/atari_NCR5380.c986
-rw-r--r--drivers/scsi/atari_scsi.c673
-rw-r--r--drivers/scsi/atari_scsi.h60
-rw-r--r--drivers/scsi/be2iscsi/be_main.c4
-rw-r--r--drivers/scsi/bfa/bfad_debugfs.c30
-rw-r--r--drivers/scsi/bfa/bfad_im.c18
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_els.c2
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_fcoe.c16
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_io.c37
-rw-r--r--drivers/scsi/bnx2i/bnx2i_iscsi.c3
-rw-r--r--drivers/scsi/ch.c36
-rw-r--r--drivers/scsi/constants.c599
-rw-r--r--drivers/scsi/csiostor/csio_scsi.c37
-rw-r--r--drivers/scsi/cxgbi/cxgb3i/cxgb3i.c3
-rw-r--r--drivers/scsi/cxgbi/cxgb4i/cxgb4i.c20
-rw-r--r--drivers/scsi/cxgbi/libcxgbi.c20
-rw-r--r--drivers/scsi/device_handler/scsi_dh.c55
-rw-r--r--drivers/scsi/device_handler/scsi_dh_alua.c89
-rw-r--r--drivers/scsi/device_handler/scsi_dh_emc.c86
-rw-r--r--drivers/scsi/device_handler/scsi_dh_hp_sw.c81
-rw-r--r--drivers/scsi/device_handler/scsi_dh_rdac.c82
-rw-r--r--drivers/scsi/dmx3191d.c31
-rw-r--r--drivers/scsi/dpt_i2o.c4
-rw-r--r--drivers/scsi/dtc.c85
-rw-r--r--drivers/scsi/dtc.h26
-rw-r--r--drivers/scsi/eata.c8
-rw-r--r--drivers/scsi/esas2r/esas2r.h5
-rw-r--r--drivers/scsi/esas2r/esas2r_ioctl.c22
-rw-r--r--drivers/scsi/esas2r/esas2r_main.c64
-rw-r--r--drivers/scsi/esp_scsi.c428
-rw-r--r--drivers/scsi/esp_scsi.h22
-rw-r--r--drivers/scsi/fcoe/fcoe.c6
-rw-r--r--drivers/scsi/fnic/fnic.h2
-rw-r--r--drivers/scsi/fnic/fnic_fcs.c5
-rw-r--r--drivers/scsi/fnic/fnic_main.c23
-rw-r--r--drivers/scsi/fnic/fnic_scsi.c43
-rw-r--r--drivers/scsi/fnic/fnic_trace.c4
-rw-r--r--drivers/scsi/g_NCR5380.c224
-rw-r--r--drivers/scsi/g_NCR5380.h26
-rw-r--r--drivers/scsi/gdth.c5
-rw-r--r--drivers/scsi/hosts.c5
-rw-r--r--drivers/scsi/hpsa.c509
-rw-r--r--drivers/scsi/hpsa.h33
-rw-r--r--drivers/scsi/hpsa_cmd.h34
-rw-r--r--drivers/scsi/hptiop.c8
-rw-r--r--drivers/scsi/ibmvscsi/ibmvfc.c58
-rw-r--r--drivers/scsi/ibmvscsi/ibmvscsi.c11
-rw-r--r--drivers/scsi/ipr.c175
-rw-r--r--drivers/scsi/ipr.h2
-rw-r--r--drivers/scsi/ips.c2
-rw-r--r--drivers/scsi/isci/init.c4
-rw-r--r--drivers/scsi/isci/task.c147
-rw-r--r--drivers/scsi/isci/task.h1
-rw-r--r--drivers/scsi/iscsi_tcp.c3
-rw-r--r--drivers/scsi/libfc/fc_fcp.c52
-rw-r--r--drivers/scsi/libiscsi.c19
-rw-r--r--drivers/scsi/libsas/sas_ata.c9
-rw-r--r--drivers/scsi/libsas/sas_expander.c2
-rw-r--r--drivers/scsi/libsas/sas_init.c21
-rw-r--r--drivers/scsi/libsas/sas_internal.h2
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c223
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c158
-rw-r--r--drivers/scsi/mac_scsi.c552
-rw-r--r--drivers/scsi/mac_scsi.h74
-rw-r--r--drivers/scsi/megaraid.c8
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c23
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h23
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_base.c166
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_fp.c33
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_fusion.c112
-rw-r--r--drivers/scsi/megaraid/megaraid_sas_fusion.h18
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_scsih.c82
-rw-r--r--drivers/scsi/mpt3sas/mpt3sas_scsih.c84
-rw-r--r--drivers/scsi/mvsas/mv_init.c24
-rw-r--r--drivers/scsi/mvsas/mv_sas.c109
-rw-r--r--drivers/scsi/mvsas/mv_sas.h10
-rw-r--r--drivers/scsi/ncr53c8xx.c5
-rw-r--r--drivers/scsi/osd/osd_uld.c2
-rw-r--r--drivers/scsi/osst.c29
-rw-r--r--drivers/scsi/pas16.c106
-rw-r--r--drivers/scsi/pas16.h21
-rw-r--r--drivers/scsi/pm8001/pm8001_init.c4
-rw-r--r--drivers/scsi/pm8001/pm8001_sas.c22
-rw-r--r--drivers/scsi/pm8001/pm8001_sas.h3
-rw-r--r--drivers/scsi/pmcraid.c94
-rw-r--r--drivers/scsi/ps3rom.c4
-rw-r--r--drivers/scsi/qla1280.c5
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h2
-rw-r--r--drivers/scsi/qla2xxx/qla_iocb.c92
-rw-r--r--drivers/scsi/qla2xxx/qla_mr.c13
-rw-r--r--drivers/scsi/qla2xxx/qla_nx2.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c83
-rw-r--r--drivers/scsi/qla4xxx/ql4_iocb.c10
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c35
-rw-r--r--drivers/scsi/scsi.c211
-rw-r--r--drivers/scsi/scsi_debug.c1995
-rw-r--r--drivers/scsi/scsi_devinfo.c1
-rw-r--r--drivers/scsi/scsi_error.c231
-rw-r--r--drivers/scsi/scsi_ioctl.c74
-rw-r--r--drivers/scsi/scsi_lib.c165
-rw-r--r--drivers/scsi/scsi_logging.h1
-rw-r--r--drivers/scsi/scsi_priv.h2
-rw-r--r--drivers/scsi/scsi_scan.c27
-rw-r--r--drivers/scsi/scsi_sysfs.c18
-rw-r--r--drivers/scsi/scsi_trace.c2
-rw-r--r--drivers/scsi/scsi_transport_spi.c23
-rw-r--r--drivers/scsi/scsicam.c4
-rw-r--r--drivers/scsi/sd.c114
-rw-r--r--drivers/scsi/sd.h6
-rw-r--r--drivers/scsi/ses.c2
-rw-r--r--drivers/scsi/sg.c62
-rw-r--r--drivers/scsi/sr.c19
-rw-r--r--drivers/scsi/sr.h3
-rw-r--r--drivers/scsi/sr_ioctl.c10
-rw-r--r--drivers/scsi/st.c47
-rw-r--r--drivers/scsi/stex.c30
-rw-r--r--drivers/scsi/storvsc_drv.c6
-rw-r--r--drivers/scsi/sun3_NCR5380.c2933
-rw-r--r--drivers/scsi/sun3_scsi.c512
-rw-r--r--drivers/scsi/sun3_scsi.h84
-rw-r--r--drivers/scsi/sym53c8xx_2/sym_glue.c4
-rw-r--r--drivers/scsi/t128.c83
-rw-r--r--drivers/scsi/t128.h23
-rw-r--r--drivers/scsi/tmscsim.c2620
-rw-r--r--drivers/scsi/tmscsim.h551
-rw-r--r--drivers/scsi/u14-34f.c10
-rw-r--r--drivers/scsi/ufs/ufshcd-pltfrm.c15
-rw-r--r--drivers/scsi/ufs/ufshcd.c143
-rw-r--r--drivers/scsi/ufs/ufshcd.h2
-rw-r--r--drivers/scsi/virtio_scsi.c40
-rw-r--r--drivers/scsi/vmw_pvscsi.c32
-rw-r--r--drivers/scsi/wd7000.c1
-rw-r--r--drivers/scsi/wd719x.c996
-rw-r--r--drivers/scsi/wd719x.h249
-rw-r--r--drivers/soc/versatile/soc-realview.c1
-rw-r--r--drivers/spi/spi-dw.c6
-rw-r--r--drivers/spi/spi-fsl-dspi.c4
-rw-r--r--drivers/spi/spi-pxa2xx.c7
-rw-r--r--drivers/spi/spi-sirf.c4
-rw-r--r--drivers/spi/spi.c6
-rw-r--r--drivers/staging/iio/meter/ade7758.h1
-rw-r--r--drivers/staging/iio/meter/ade7758_core.c57
-rw-r--r--drivers/staging/iio/meter/ade7758_ring.c5
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_cmd.c22
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_mlme_ext.c12
-rw-r--r--drivers/staging/rtl8188eu/core/rtw_wlan_util.c2
-rw-r--r--drivers/staging/rtl8188eu/os_dep/usb_intf.c1
-rw-r--r--drivers/target/iscsi/iscsi_target.c2
-rw-r--r--drivers/target/loopback/tcm_loop.c75
-rw-r--r--drivers/target/target_core_alua.c2
-rw-r--r--drivers/target/target_core_pr.c11
-rw-r--r--drivers/target/target_core_sbc.c2
-rw-r--r--drivers/target/target_core_transport.c2
-rw-r--r--drivers/thermal/cpu_cooling.c37
-rw-r--r--drivers/thermal/imx_thermal.c45
-rw-r--r--drivers/thermal/int340x_thermal/int3403_thermal.c8
-rw-r--r--drivers/thermal/of-thermal.c40
-rw-r--r--drivers/thermal/samsung/exynos_thermal_common.c9
-rw-r--r--drivers/thermal/samsung/exynos_thermal_common.h2
-rw-r--r--drivers/thermal/samsung/exynos_tmu.c170
-rw-r--r--drivers/thermal/samsung/exynos_tmu.h89
-rw-r--r--drivers/thermal/samsung/exynos_tmu_data.c105
-rw-r--r--drivers/thermal/samsung/exynos_tmu_data.h55
-rw-r--r--drivers/thermal/st/st_thermal.c3
-rw-r--r--drivers/thermal/thermal_core.c3
-rw-r--r--drivers/tty/n_tty.c9
-rw-r--r--drivers/tty/serial/8250/8250_mtk.c2
-rw-r--r--drivers/tty/serial/of_serial.c29
-rw-r--r--drivers/tty/serial/serial_core.c2
-rw-r--r--drivers/tty/tty_io.c15
-rw-r--r--drivers/tty/vt/consolemap.c7
-rw-r--r--drivers/usb/class/cdc-acm.c25
-rw-r--r--drivers/usb/class/cdc-acm.h2
-rw-r--r--drivers/usb/core/hcd.c2
-rw-r--r--drivers/usb/core/hub.c10
-rw-r--r--drivers/usb/core/quirks.c9
-rw-r--r--drivers/usb/dwc2/gadget.c2
-rw-r--r--drivers/usb/dwc3/ep0.c8
-rw-r--r--drivers/usb/gadget/legacy/tcm_usb_gadget.c2
-rw-r--r--drivers/usb/host/Kconfig4
-rw-r--r--drivers/usb/host/hwa-hc.c2
-rw-r--r--drivers/usb/host/xhci-hub.c5
-rw-r--r--drivers/usb/host/xhci-pci.c20
-rw-r--r--drivers/usb/host/xhci-plat.c10
-rw-r--r--drivers/usb/host/xhci-ring.c43
-rw-r--r--drivers/usb/host/xhci.c107
-rw-r--r--drivers/usb/host/xhci.h2
-rw-r--r--drivers/usb/serial/cp210x.c1
-rw-r--r--drivers/usb/serial/ftdi_sio.c33
-rw-r--r--drivers/usb/serial/ftdi_sio_ids.h39
-rw-r--r--drivers/usb/serial/keyspan.c97
-rw-r--r--drivers/usb/serial/kobil_sct.c5
-rw-r--r--drivers/usb/serial/opticon.c2
-rw-r--r--drivers/usb/serial/ssu100.c11
-rw-r--r--drivers/usb/storage/debug.c10
-rw-r--r--drivers/usb/storage/initializers.c4
-rw-r--r--drivers/usb/storage/realtek_cr.c2
-rw-r--r--drivers/usb/storage/transport.c26
-rw-r--r--drivers/usb/storage/uas.c7
-rw-r--r--drivers/usb/storage/unusual_uas.h35
-rw-r--r--drivers/vhost/scsi.c24
-rw-r--r--drivers/video/backlight/Kconfig1
-rw-r--r--drivers/video/fbdev/Kconfig17
-rw-r--r--drivers/watchdog/Kconfig4
-rw-r--r--drivers/watchdog/s3c2410_wdt.c2
-rw-r--r--drivers/xen/efi.c1
-rw-r--r--drivers/xen/xen-scsiback.c4
-rw-r--r--fs/Makefile2
-rw-r--r--fs/aio.c21
-rw-r--r--fs/btrfs/compression.c33
-rw-r--r--fs/btrfs/compression.h4
-rw-r--r--fs/btrfs/ctree.c14
-rw-r--r--fs/btrfs/file-item.c2
-rw-r--r--fs/btrfs/locking.c24
-rw-r--r--fs/btrfs/locking.h2
-rw-r--r--fs/btrfs/lzo.c15
-rw-r--r--fs/btrfs/zlib.c20
-rw-r--r--fs/ceph/caps.c2
-rw-r--r--fs/dcache.c1
-rw-r--r--fs/fat/namei_vfat.c20
-rw-r--r--fs/isofs/inode.c42
-rw-r--r--fs/jbd2/journal.c5
-rw-r--r--fs/nfs/blocklayout/blocklayout.c2
-rw-r--r--fs/nfs/blocklayout/rpc_pipefs.c14
-rw-r--r--fs/nfs/delegation.c25
-rw-r--r--fs/nfs/delegation.h1
-rw-r--r--fs/nfs/dir.c1
-rw-r--r--fs/nfs/direct.c1
-rw-r--r--fs/nfs/filelayout/filelayout.c3
-rw-r--r--fs/nfs/inode.c2
-rw-r--r--fs/nfs/netns.h1
-rw-r--r--fs/nfs/nfs4proc.c95
-rw-r--r--fs/nfs/write.c2
-rw-r--r--fs/nfsd/nfs4callback.c8
-rw-r--r--fs/nfsd/nfsd.h9
-rw-r--r--fs/notify/fsnotify.c36
-rw-r--r--fs/notify/fsnotify.h4
-rw-r--r--fs/notify/inode_mark.c8
-rw-r--r--fs/notify/mark.c36
-rw-r--r--fs/notify/vfsmount_mark.c8
-rw-r--r--fs/ocfs2/cluster/tcp.c2
-rw-r--r--fs/overlayfs/Kconfig2
-rw-r--r--fs/overlayfs/Makefile4
-rw-r--r--fs/overlayfs/dir.c31
-rw-r--r--fs/overlayfs/inode.c27
-rw-r--r--fs/overlayfs/readdir.c41
-rw-r--r--fs/overlayfs/super.c61
-rw-r--r--fs/xfs/xfs_bmap_util.c72
-rw-r--r--fs/xfs/xfs_itable.c250
-rw-r--r--fs/xfs/xfs_itable.h16
-rw-r--r--include/asm-generic/futex.h114
-rw-r--r--include/asm-generic/seccomp.h30
-rw-r--r--include/asm-generic/tlb.h57
-rw-r--r--include/dt-bindings/clock/qcom,mmcc-apq8084.h2
-rw-r--r--include/dt-bindings/pinctrl/dra.h4
-rw-r--r--include/dt-bindings/regulator/maxim,max77802.h18
-rw-r--r--include/linux/atmel-mci.h2
-rw-r--r--include/linux/bitops.h7
-rw-r--r--include/linux/blk-mq.h17
-rw-r--r--include/linux/blkdev.h1
-rw-r--r--include/linux/bootmem.h1
-rw-r--r--include/linux/can/dev.h6
-rw-r--r--include/linux/clk-provider.h1
-rw-r--r--include/linux/cma.h8
-rw-r--r--include/linux/device-mapper.h2
-rw-r--r--include/linux/edac.h4
-rw-r--r--include/linux/eeprom_93cx6.h4
-rw-r--r--include/linux/efi.h6
-rw-r--r--include/linux/i2c/pmbus.h4
-rw-r--r--include/linux/iio/events.h2
-rw-r--r--include/linux/inetdevice.h2
-rw-r--r--include/linux/kernel_stat.h5
-rw-r--r--include/linux/kvm_host.h2
-rw-r--r--include/linux/libata.h4
-rw-r--r--include/linux/mfd/abx500/ab8500-sysctrl.h1
-rw-r--r--include/linux/mfd/arizona/registers.h50
-rw-r--r--include/linux/mfd/atmel-hlcdc.h85
-rw-r--r--include/linux/mfd/axp20x.h59
-rw-r--r--include/linux/mfd/core.h7
-rw-r--r--include/linux/mfd/dln2.h103
-rw-r--r--include/linux/mfd/max77686.h7
-rw-r--r--include/linux/mfd/max77693-private.h8
-rw-r--r--include/linux/mfd/rtsx_pci.h37
-rw-r--r--include/linux/mfd/samsung/core.h2
-rw-r--r--include/linux/mfd/samsung/s2mps13.h186
-rw-r--r--include/linux/mfd/tc3589x.h8
-rw-r--r--include/linux/mmc/card.h23
-rw-r--r--include/linux/mmc/core.h3
-rw-r--r--include/linux/mmc/dw_mmc.h7
-rw-r--r--include/linux/mmc/host.h1
-rw-r--r--include/linux/mmc/mmc.h3
-rw-r--r--include/linux/mmc/sdhci.h18
-rw-r--r--include/linux/mmc/sdio_func.h2
-rw-r--r--include/linux/mmzone.h9
-rw-r--r--include/linux/nfs_xdr.h11
-rw-r--r--include/linux/of.h95
-rw-r--r--include/linux/page-isolation.h8
-rw-r--r--include/linux/pci-acpi.h7
-rw-r--r--include/linux/pci.h1
-rw-r--r--include/linux/pci_ids.h2
-rw-r--r--include/linux/percpu-refcount.h8
-rw-r--r--include/linux/platform_data/hsmmc-omap.h90
-rw-r--r--include/linux/platform_data/mmc-atmel-mci.h (renamed from arch/arm/mach-at91/include/mach/atmel-mci.h)13
-rw-r--r--include/linux/platform_data/mmc-omap.h27
-rw-r--r--include/linux/platform_data/pxa_sdhci.h5
-rw-r--r--include/linux/platform_data/serial-omap.h3
-rw-r--r--include/linux/pm_domain.h8
-rw-r--r--include/linux/power/charger-manager.h3
-rw-r--r--include/linux/power_supply.h6
-rw-r--r--include/linux/regmap.h7
-rw-r--r--include/linux/regulator/consumer.h6
-rw-r--r--include/linux/regulator/driver.h8
-rw-r--r--include/linux/regulator/of_regulator.h9
-rw-r--r--include/linux/ring_buffer.h2
-rw-r--r--include/linux/socket.h2
-rw-r--r--include/linux/vexpress.h19
-rw-r--r--include/net/9p/transport.h1
-rw-r--r--include/net/inet_common.h2
-rw-r--r--include/net/netfilter/nf_tables.h2
-rw-r--r--include/net/udp_tunnel.h9
-rw-r--r--include/net/vxlan.h18
-rw-r--r--include/scsi/libfc.h2
-rw-r--r--include/scsi/libiscsi.h2
-rw-r--r--include/scsi/libsas.h17
-rw-r--r--include/scsi/scsi.h12
-rw-r--r--include/scsi/scsi_cmnd.h6
-rw-r--r--include/scsi/scsi_dbg.h28
-rw-r--r--include/scsi/scsi_device.h21
-rw-r--r--include/scsi/scsi_driver.h1
-rw-r--r--include/scsi/scsi_eh.h24
-rw-r--r--include/scsi/scsi_host.h39
-rw-r--r--include/scsi/scsi_ioctl.h4
-rw-r--r--include/scsi/scsi_tcq.h87
-rw-r--r--include/scsi/scsi_transport_spi.h1
-rw-r--r--include/scsi/sg.h5
-rw-r--r--include/soc/at91/at91rm9200_sdramc.h (renamed from arch/arm/mach-at91/include/mach/at91rm9200_sdramc.h)0
-rw-r--r--include/soc/at91/at91sam9_ddrsdr.h (renamed from arch/arm/mach-at91/include/mach/at91sam9_ddrsdr.h)0
-rw-r--r--include/soc/at91/at91sam9_sdramc.h (renamed from arch/arm/mach-at91/include/mach/at91sam9_sdramc.h)0
-rw-r--r--include/sound/pcm.h2
-rw-r--r--include/sound/soc-dpcm.h2
-rw-r--r--include/trace/events/scsi.h2
-rw-r--r--include/trace/events/target.h2
-rw-r--r--include/uapi/linux/Kbuild4
-rw-r--r--include/uapi/linux/dm-ioctl.h9
-rw-r--r--include/uapi/linux/elf-em.h1
-rw-r--r--include/uapi/linux/elf.h1
-rw-r--r--include/uapi/linux/if_bridge.h1
-rw-r--r--include/uapi/sound/asound.h4
-rw-r--r--init/main.c2
-rw-r--r--ipc/sem.c15
-rw-r--r--kernel/audit.c2
-rw-r--r--kernel/audit_tree.c1
-rw-r--r--kernel/events/core.c8
-rw-r--r--kernel/events/uprobes.c1
-rw-r--r--kernel/panic.c1
-rw-r--r--kernel/power/suspend.c4
-rw-r--r--kernel/sched/core.c71
-rw-r--r--kernel/sched/deadline.c2
-rw-r--r--kernel/sched/fair.c14
-rw-r--r--kernel/sched/idle_task.c5
-rw-r--r--kernel/sched/rt.c2
-rw-r--r--kernel/sched/sched.h2
-rw-r--r--kernel/sched/stop_task.c5
-rw-r--r--kernel/time/posix-cpu-timers.c2
-rw-r--r--kernel/trace/ring_buffer.c81
-rw-r--r--kernel/trace/trace.c33
-rw-r--r--lib/Makefile4
-rw-r--r--lib/genalloc.c1
-rw-r--r--lib/rhashtable.c10
-rw-r--r--lib/show_mem.c2
-rw-r--r--mm/bootmem.c9
-rw-r--r--mm/cma.c68
-rw-r--r--mm/compaction.c18
-rw-r--r--mm/frontswap.c4
-rw-r--r--mm/internal.h25
-rw-r--r--mm/iov_iter.c4
-rw-r--r--mm/memory.c56
-rw-r--r--mm/memory_hotplug.c26
-rw-r--r--mm/mmap.c10
-rw-r--r--mm/nobootmem.c8
-rw-r--r--mm/page_alloc.c68
-rw-r--r--mm/page_isolation.c43
-rw-r--r--mm/rmap.c6
-rw-r--r--mm/slab.c2
-rw-r--r--mm/slab_common.c4
-rw-r--r--mm/truncate.c6
-rw-r--r--mm/vmpressure.c8
-rw-r--r--net/bridge/br_multicast.c3
-rw-r--r--net/bridge/br_netlink.c1
-rw-r--r--net/bridge/netfilter/nft_reject_bridge.c1
-rw-r--r--net/ceph/auth_x.c25
-rw-r--r--net/ceph/crypto.c169
-rw-r--r--net/ceph/messenger.c10
-rw-r--r--net/ceph/osd_client.c7
-rw-r--r--net/core/rtnetlink.c24
-rw-r--r--net/core/skbuff.c23
-rw-r--r--net/dcb/dcbnl.c36
-rw-r--r--net/dsa/slave.c7
-rw-r--r--net/ipv4/af_inet.c11
-rw-r--r--net/ipv4/fib_rules.c4
-rw-r--r--net/ipv4/fou.c2
-rw-r--r--net/ipv4/geneve.c3
-rw-r--r--net/ipv4/igmp.c11
-rw-r--r--net/ipv4/ip_sockglue.c2
-rw-r--r--net/ipv4/ip_vti.c1
-rw-r--r--net/ipv4/netfilter/nft_masq_ipv4.c1
-rw-r--r--net/ipv4/ping.c14
-rw-r--r--net/ipv4/tcp.c2
-rw-r--r--net/ipv4/tcp_input.c64
-rw-r--r--net/ipv4/tcp_ipv4.c5
-rw-r--r--net/ipv6/ip6_gre.c9
-rw-r--r--net/ipv6/ip6_offload.c3
-rw-r--r--net/ipv6/ip6_tunnel.c10
-rw-r--r--net/ipv6/ip6_udp_tunnel.c4
-rw-r--r--net/ipv6/ip6_vti.c22
-rw-r--r--net/ipv6/ip6mr.c4
-rw-r--r--net/ipv6/mcast.c9
-rw-r--r--net/ipv6/netfilter/nft_masq_ipv6.c1
-rw-r--r--net/ipv6/sit.c15
-rw-r--r--net/ipv6/tcp_ipv6.c5
-rw-r--r--net/ipx/af_ipx.c6
-rw-r--r--net/mac80211/aes_ccm.c3
-rw-r--r--net/mac80211/ibss.c2
-rw-r--r--net/mac80211/ieee80211_i.h3
-rw-r--r--net/mac80211/iface.c18
-rw-r--r--net/mac80211/mesh.c2
-rw-r--r--net/mac80211/mlme.c5
-rw-r--r--net/mac80211/rc80211_minstrel_ht.c15
-rw-r--r--net/mac80211/rx.c14
-rw-r--r--net/mac80211/spectmgmt.c18
-rw-r--r--net/netfilter/ipset/ip_set_core.c6
-rw-r--r--net/netfilter/ipvs/ip_vs_xmit.c2
-rw-r--r--net/netfilter/nf_tables_api.c24
-rw-r--r--net/netfilter/nfnetlink.c12
-rw-r--r--net/netfilter/nft_compat.c40
-rw-r--r--net/netlink/af_netlink.c5
-rw-r--r--net/openvswitch/actions.c10
-rw-r--r--net/openvswitch/datapath.c14
-rw-r--r--net/openvswitch/flow_netlink.c9
-rw-r--r--net/packet/af_packet.c2
-rw-r--r--net/sctp/auth.c2
-rw-r--r--net/sctp/sm_make_chunk.c3
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c35
-rw-r--r--net/sunrpc/svcsock.c27
-rw-r--r--scripts/Kbuild.include6
-rw-r--r--scripts/Makefile.dtbinst51
-rw-r--r--scripts/Makefile.lib12
-rw-r--r--security/keys/internal.h1
-rw-r--r--security/keys/keyctl.c56
-rw-r--r--security/keys/keyring.c10
-rw-r--r--security/keys/request_key.c2
-rw-r--r--security/keys/request_key_auth.c1
-rw-r--r--security/selinux/hooks.c7
-rw-r--r--sound/core/pcm.c2
-rw-r--r--sound/core/pcm_misc.c8
-rw-r--r--sound/pci/hda/hda_intel.c28
-rw-r--r--sound/pci/hda/hda_priv.h1
-rw-r--r--sound/pci/hda/patch_conexant.c31
-rw-r--r--sound/pci/hda/patch_realtek.c228
-rw-r--r--sound/soc/codecs/cs42l51-i2c.c1
-rw-r--r--sound/soc/codecs/cs42l51.c4
-rw-r--r--sound/soc/codecs/cs42l51.h1
-rw-r--r--sound/soc/codecs/es8328-i2c.c2
-rw-r--r--sound/soc/codecs/max98090.c6
-rw-r--r--sound/soc/codecs/rt5645.c2
-rw-r--r--sound/soc/codecs/rt5670.c36
-rw-r--r--sound/soc/codecs/sgtl5000.c3
-rw-r--r--sound/soc/codecs/sgtl5000.h2
-rw-r--r--sound/soc/codecs/wm_adsp.c1
-rw-r--r--sound/soc/fsl/fsl_asrc.c26
-rw-r--r--sound/soc/rockchip/rockchip_i2s.c4
-rw-r--r--sound/soc/samsung/snow.c1
-rw-r--r--sound/soc/sh/fsi.c3
-rw-r--r--sound/soc/sh/rcar/core.c3
-rw-r--r--sound/soc/soc-core.c2
-rw-r--r--sound/soc/soc-pcm.c72
-rw-r--r--sound/usb/card.c9
-rw-r--r--sound/usb/mixer.c7
-rw-r--r--sound/usb/mixer_quirks.c10
-rw-r--r--sound/usb/quirks.c18
-rw-r--r--tools/lib/traceevent/plugin_scsi.c9
-rwxr-xr-xtools/testing/selftests/ftrace/ftracetest2
-rw-r--r--tools/testing/selftests/net/psock_fanout.c2
-rw-r--r--virt/kvm/arm/vgic.c8
-rw-r--r--virt/kvm/kvm_main.c16
1699 files changed, 40547 insertions, 50008 deletions
diff --git a/Documentation/ABI/stable/sysfs-driver-ib_srp b/Documentation/ABI/stable/sysfs-driver-ib_srp
index b9688de8455b..7049a2b50359 100644
--- a/Documentation/ABI/stable/sysfs-driver-ib_srp
+++ b/Documentation/ABI/stable/sysfs-driver-ib_srp
@@ -55,12 +55,12 @@ Description: Interface for making ib_srp connect to a new target.
55 only safe with partial memory descriptor list support enabled 55 only safe with partial memory descriptor list support enabled
56 (allow_ext_sg=1). 56 (allow_ext_sg=1).
57 * comp_vector, a number in the range 0..n-1 specifying the 57 * comp_vector, a number in the range 0..n-1 specifying the
58 MSI-X completion vector. Some HCA's allocate multiple (n) 58 MSI-X completion vector of the first RDMA channel. Some
59 MSI-X vectors per HCA port. If the IRQ affinity masks of 59 HCA's allocate multiple (n) MSI-X vectors per HCA port. If
60 these interrupts have been configured such that each MSI-X 60 the IRQ affinity masks of these interrupts have been
61 interrupt is handled by a different CPU then the comp_vector 61 configured such that each MSI-X interrupt is handled by a
62 parameter can be used to spread the SRP completion workload 62 different CPU then the comp_vector parameter can be used to
63 over multiple CPU's. 63 spread the SRP completion workload over multiple CPU's.
64 * tl_retry_count, a number in the range 2..7 specifying the 64 * tl_retry_count, a number in the range 2..7 specifying the
65 IB RC retry count. 65 IB RC retry count.
66 * queue_size, the maximum number of commands that the 66 * queue_size, the maximum number of commands that the
@@ -88,6 +88,13 @@ Description: Whether ib_srp is allowed to include a partial memory
88 descriptor list in an SRP_CMD when communicating with an SRP 88 descriptor list in an SRP_CMD when communicating with an SRP
89 target. 89 target.
90 90
91What: /sys/class/scsi_host/host<n>/ch_count
92Date: April 1, 2015
93KernelVersion: 3.19
94Contact: linux-rdma@vger.kernel.org
95Description: Number of RDMA channels used for communication with the SRP
96 target.
97
91What: /sys/class/scsi_host/host<n>/cmd_sg_entries 98What: /sys/class/scsi_host/host<n>/cmd_sg_entries
92Date: May 19, 2011 99Date: May 19, 2011
93KernelVersion: 2.6.39 100KernelVersion: 2.6.39
@@ -95,6 +102,12 @@ Contact: linux-rdma@vger.kernel.org
95Description: Maximum number of data buffer descriptors that may be sent to 102Description: Maximum number of data buffer descriptors that may be sent to
96 the target in a single SRP_CMD request. 103 the target in a single SRP_CMD request.
97 104
105What: /sys/class/scsi_host/host<n>/comp_vector
106Date: September 2, 2013
107KernelVersion: 3.11
108Contact: linux-rdma@vger.kernel.org
109Description: Completion vector used for the first RDMA channel.
110
98What: /sys/class/scsi_host/host<n>/dgid 111What: /sys/class/scsi_host/host<n>/dgid
99Date: June 17, 2006 112Date: June 17, 2006
100KernelVersion: 2.6.17 113KernelVersion: 2.6.17
diff --git a/Documentation/arm64/legacy_instructions.txt b/Documentation/arm64/legacy_instructions.txt
new file mode 100644
index 000000000000..a3b3da2ec6ed
--- /dev/null
+++ b/Documentation/arm64/legacy_instructions.txt
@@ -0,0 +1,45 @@
1The arm64 port of the Linux kernel provides infrastructure to support
2emulation of instructions which have been deprecated, or obsoleted in
3the architecture. The infrastructure code uses undefined instruction
4hooks to support emulation. Where available it also allows turning on
5the instruction execution in hardware.
6
7The emulation mode can be controlled by writing to sysctl nodes
8(/proc/sys/abi). The following explains the different execution
9behaviours and the corresponding values of the sysctl nodes -
10
11* Undef
12 Value: 0
13 Generates undefined instruction abort. Default for instructions that
14 have been obsoleted in the architecture, e.g., SWP
15
16* Emulate
17 Value: 1
18 Uses software emulation. To aid migration of software, in this mode
19 usage of emulated instruction is traced as well as rate limited
20 warnings are issued. This is the default for deprecated
21 instructions, .e.g., CP15 barriers
22
23* Hardware Execution
24 Value: 2
25 Although marked as deprecated, some implementations may support the
26 enabling/disabling of hardware support for the execution of these
27 instructions. Using hardware execution generally provides better
28 performance, but at the loss of ability to gather runtime statistics
29 about the use of the deprecated instructions.
30
31The default mode depends on the status of the instruction in the
32architecture. Deprecated instructions should default to emulation
33while obsolete instructions must be undefined by default.
34
35Supported legacy instructions
36-----------------------------
37* SWP{B}
38Node: /proc/sys/abi/swp
39Status: Obsolete
40Default: Undef (0)
41
42* CP15 Barriers
43Node: /proc/sys/abi/cp15_barrier
44Status: Deprecated
45Default: Emulate (1)
diff --git a/Documentation/block/biodoc.txt b/Documentation/block/biodoc.txt
index 2101e718670d..6b972b287795 100644
--- a/Documentation/block/biodoc.txt
+++ b/Documentation/block/biodoc.txt
@@ -827,10 +827,6 @@ but in the event of any barrier requests in the tag queue we need to ensure
827that requests are restarted in the order they were queue. This may happen 827that requests are restarted in the order they were queue. This may happen
828if the driver needs to use blk_queue_invalidate_tags(). 828if the driver needs to use blk_queue_invalidate_tags().
829 829
830Tagging also defines a new request flag, REQ_QUEUED. This is set whenever
831a request is currently tagged. You should not use this flag directly,
832blk_rq_tagged(rq) is the portable way to do so.
833
8343.3 I/O Submission 8303.3 I/O Submission
835 831
836The routine submit_bio() is used to submit a single io. Higher level i/o 832The routine submit_bio() is used to submit a single io. Higher level i/o
diff --git a/Documentation/device-mapper/cache-policies.txt b/Documentation/device-mapper/cache-policies.txt
index 66c2774c0c64..0d124a971801 100644
--- a/Documentation/device-mapper/cache-policies.txt
+++ b/Documentation/device-mapper/cache-policies.txt
@@ -47,20 +47,26 @@ Message and constructor argument pairs are:
47 'discard_promote_adjustment <value>' 47 'discard_promote_adjustment <value>'
48 48
49The sequential threshold indicates the number of contiguous I/Os 49The sequential threshold indicates the number of contiguous I/Os
50required before a stream is treated as sequential. The random threshold 50required before a stream is treated as sequential. Once a stream is
51considered sequential it will bypass the cache. The random threshold
51is the number of intervening non-contiguous I/Os that must be seen 52is the number of intervening non-contiguous I/Os that must be seen
52before the stream is treated as random again. 53before the stream is treated as random again.
53 54
54The sequential and random thresholds default to 512 and 4 respectively. 55The sequential and random thresholds default to 512 and 4 respectively.
55 56
56Large, sequential ios are probably better left on the origin device 57Large, sequential I/Os are probably better left on the origin device
57since spindles tend to have good bandwidth. The io_tracker counts 58since spindles tend to have good sequential I/O bandwidth. The
58contiguous I/Os to try to spot when the io is in one of these sequential 59io_tracker counts contiguous I/Os to try to spot when the I/O is in one
59modes. 60of these sequential modes. But there are use-cases for wanting to
60 61promote sequential blocks to the cache (e.g. fast application startup).
61Internally the mq policy maintains a promotion threshold variable. If 62If sequential threshold is set to 0 the sequential I/O detection is
62the hit count of a block not in the cache goes above this threshold it 63disabled and sequential I/O will no longer implicitly bypass the cache.
63gets promoted to the cache. The read, write and discard promote adjustment 64Setting the random threshold to 0 does _not_ disable the random I/O
65stream detection.
66
67Internally the mq policy determines a promotion threshold. If the hit
68count of a block not in the cache goes above this threshold it gets
69promoted to the cache. The read, write and discard promote adjustment
64tunables allow you to tweak the promotion threshold by adding a small 70tunables allow you to tweak the promotion threshold by adding a small
65value based on the io type. They default to 4, 8 and 1 respectively. 71value based on the io type. They default to 4, 8 and 1 respectively.
66If you're trying to quickly warm a new cache device you may wish to 72If you're trying to quickly warm a new cache device you may wish to
diff --git a/Documentation/devicetree/bindings/ata/sata_rcar.txt b/Documentation/devicetree/bindings/ata/sata_rcar.txt
index 1e6111333fa8..80ae87a0784b 100644
--- a/Documentation/devicetree/bindings/ata/sata_rcar.txt
+++ b/Documentation/devicetree/bindings/ata/sata_rcar.txt
@@ -3,8 +3,10 @@
3Required properties: 3Required properties:
4- compatible : should contain one of the following: 4- compatible : should contain one of the following:
5 - "renesas,sata-r8a7779" for R-Car H1 5 - "renesas,sata-r8a7779" for R-Car H1
6 - "renesas,sata-r8a7790" for R-Car H2 6 - "renesas,sata-r8a7790-es1" for R-Car H2 ES1
7 - "renesas,sata-r8a7791" for R-Car M2 7 - "renesas,sata-r8a7790" for R-Car H2 other than ES1
8 - "renesas,sata-r8a7791" for R-Car M2-W
9 - "renesas,sata-r8a7793" for R-Car M2-N
8- reg : address and length of the SATA registers; 10- reg : address and length of the SATA registers;
9- interrupts : must consist of one interrupt specifier. 11- interrupts : must consist of one interrupt specifier.
10 12
diff --git a/Documentation/devicetree/bindings/hwmon/ltc2978.txt b/Documentation/devicetree/bindings/hwmon/ltc2978.txt
new file mode 100644
index 000000000000..ed2f09dc2483
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/ltc2978.txt
@@ -0,0 +1,39 @@
1ltc2978
2
3Required properties:
4- compatible: should contain one of:
5 * "lltc,ltc2974"
6 * "lltc,ltc2977"
7 * "lltc,ltc2978"
8 * "lltc,ltc3880"
9 * "lltc,ltc3883"
10 * "lltc,ltm4676"
11- reg: I2C slave address
12
13Optional properties:
14- regulators: A node that houses a sub-node for each regulator controlled by
15 the device. Each sub-node is identified using the node's name, with valid
16 values listed below. The content of each sub-node is defined by the
17 standard binding for regulators; see regulator.txt.
18
19Valid names of regulators depend on number of supplies supported per device:
20 * ltc2974 : vout0 - vout3
21 * ltc2977 : vout0 - vout7
22 * ltc2978 : vout0 - vout7
23 * ltc3880 : vout0 - vout1
24 * ltc3883 : vout0
25 * ltm4676 : vout0 - vout1
26
27Example:
28ltc2978@5e {
29 compatible = "lltc,ltc2978";
30 reg = <0x5e>;
31 regulators {
32 vout0 {
33 regulator-name = "FPGA-2.5V";
34 };
35 vout2 {
36 regulator-name = "FPGA-1.5V";
37 };
38 };
39};
diff --git a/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt b/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
index ce6a1a072028..8a3c40829899 100644
--- a/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
+++ b/Documentation/devicetree/bindings/interrupt-controller/interrupts.txt
@@ -30,10 +30,6 @@ should only be used when a device has multiple interrupt parents.
30 Example: 30 Example:
31 interrupts-extended = <&intc1 5 1>, <&intc2 1 0>; 31 interrupts-extended = <&intc1 5 1>, <&intc2 1 0>;
32 32
33A device node may contain either "interrupts" or "interrupts-extended", but not
34both. If both properties are present, then the operating system should log an
35error and use only the data in "interrupts".
36
372) Interrupt controller nodes 332) Interrupt controller nodes
38----------------------------- 34-----------------------------
39 35
diff --git a/Documentation/devicetree/bindings/mfd/atmel-hlcdc.txt b/Documentation/devicetree/bindings/mfd/atmel-hlcdc.txt
new file mode 100644
index 000000000000..f64de95a8e8b
--- /dev/null
+++ b/Documentation/devicetree/bindings/mfd/atmel-hlcdc.txt
@@ -0,0 +1,51 @@
1Device-Tree bindings for Atmel's HLCDC (High LCD Controller) MFD driver
2
3Required properties:
4 - compatible: value should be one of the following:
5 "atmel,sama5d3-hlcdc"
6 - reg: base address and size of the HLCDC device registers.
7 - clock-names: the name of the 3 clocks requested by the HLCDC device.
8 Should contain "periph_clk", "sys_clk" and "slow_clk".
9 - clocks: should contain the 3 clocks requested by the HLCDC device.
10 - interrupts: should contain the description of the HLCDC interrupt line
11
12The HLCDC IP exposes two subdevices:
13 - a PWM chip: see ../pwm/atmel-hlcdc-pwm.txt
14 - a Display Controller: see ../drm/atmel-hlcdc-dc.txt
15
16Example:
17
18 hlcdc: hlcdc@f0030000 {
19 compatible = "atmel,sama5d3-hlcdc";
20 reg = <0xf0030000 0x2000>;
21 clocks = <&lcdc_clk>, <&lcdck>, <&clk32k>;
22 clock-names = "periph_clk","sys_clk", "slow_clk";
23 interrupts = <36 IRQ_TYPE_LEVEL_HIGH 0>;
24 status = "disabled";
25
26 hlcdc-display-controller {
27 compatible = "atmel,hlcdc-display-controller";
28 pinctrl-names = "default";
29 pinctrl-0 = <&pinctrl_lcd_base &pinctrl_lcd_rgb888>;
30 #address-cells = <1>;
31 #size-cells = <0>;
32
33 port@0 {
34 #address-cells = <1>;
35 #size-cells = <0>;
36 reg = <0>;
37
38 hlcdc_panel_output: endpoint@0 {
39 reg = <0>;
40 remote-endpoint = <&panel_input>;
41 };
42 };
43 };
44
45 hlcdc_pwm: hlcdc-pwm {
46 compatible = "atmel,hlcdc-pwm";
47 pinctrl-names = "default";
48 pinctrl-0 = <&pinctrl_lcd_pwm>;
49 #pwm-cells = <3>;
50 };
51 };
diff --git a/Documentation/devicetree/bindings/mfd/max77686.txt b/Documentation/devicetree/bindings/mfd/max77686.txt
index 678f3cf0b8f0..75fdfaf41831 100644
--- a/Documentation/devicetree/bindings/mfd/max77686.txt
+++ b/Documentation/devicetree/bindings/mfd/max77686.txt
@@ -34,6 +34,12 @@ to get matched with their hardware counterparts as follow:
34 -BUCKn : for BUCKs, where n can lie in range 1 to 9. 34 -BUCKn : for BUCKs, where n can lie in range 1 to 9.
35 example: BUCK1, BUCK5, BUCK9. 35 example: BUCK1, BUCK5, BUCK9.
36 36
37 Regulators which can be turned off during system suspend:
38 -LDOn : 2, 6-8, 10-12, 14-16,
39 -BUCKn : 1-4.
40 Use standard regulator bindings for it ('regulator-off-in-suspend').
41
42
37Example: 43Example:
38 44
39 max77686@09 { 45 max77686@09 {
diff --git a/Documentation/devicetree/bindings/mfd/max77693.txt b/Documentation/devicetree/bindings/mfd/max77693.txt
index 11921cc417bf..01e9f30fe678 100644
--- a/Documentation/devicetree/bindings/mfd/max77693.txt
+++ b/Documentation/devicetree/bindings/mfd/max77693.txt
@@ -27,6 +27,20 @@ Optional properties:
27 27
28 [*] refer Documentation/devicetree/bindings/regulator/regulator.txt 28 [*] refer Documentation/devicetree/bindings/regulator/regulator.txt
29 29
30- haptic : The MAX77693 haptic device utilises a PWM controlled motor to provide
31 users with tactile feedback. PWM period and duty-cycle are varied in
32 order to provide the approprite level of feedback.
33
34 Required properties:
35 - compatible : Must be "maxim,max77693-hpatic"
36 - haptic-supply : power supply for the haptic motor
37 [*] refer Documentation/devicetree/bindings/regulator/regulator.txt
38 - pwms : phandle to the physical PWM(Pulse Width Modulation) device.
39 PWM properties should be named "pwms". And number of cell is different
40 for each pwm device.
41 To get more informations, please refer to documentaion.
42 [*] refer Documentation/devicetree/bindings/pwm/pwm.txt
43
30Example: 44Example:
31 max77693@66 { 45 max77693@66 {
32 compatible = "maxim,max77693"; 46 compatible = "maxim,max77693";
@@ -52,4 +66,11 @@ Example:
52 regulator-boot-on; 66 regulator-boot-on;
53 }; 67 };
54 }; 68 };
69
70 haptic {
71 compatible = "maxim,max77693-haptic";
72 haptic-supply = <&haptic_supply>;
73 pwms = <&pwm 0 40000 0>;
74 pwm-names = "haptic";
75 };
55 }; 76 };
diff --git a/Documentation/devicetree/bindings/mfd/s2mps11.txt b/Documentation/devicetree/bindings/mfd/s2mps11.txt
index 0e4026a6cbbf..57a045016fca 100644
--- a/Documentation/devicetree/bindings/mfd/s2mps11.txt
+++ b/Documentation/devicetree/bindings/mfd/s2mps11.txt
@@ -1,5 +1,5 @@
1 1
2* Samsung S2MPS11, S2MPS14 and S2MPU02 Voltage and Current Regulator 2* Samsung S2MPS11, S2MPS13, S2MPS14 and S2MPU02 Voltage and Current Regulator
3 3
4The Samsung S2MPS11 is a multi-function device which includes voltage and 4The Samsung S2MPS11 is a multi-function device which includes voltage and
5current regulators, RTC, charger controller and other sub-blocks. It is 5current regulators, RTC, charger controller and other sub-blocks. It is
@@ -7,8 +7,8 @@ interfaced to the host controller using an I2C interface. Each sub-block is
7addressed by the host system using different I2C slave addresses. 7addressed by the host system using different I2C slave addresses.
8 8
9Required properties: 9Required properties:
10- compatible: Should be "samsung,s2mps11-pmic" or "samsung,s2mps14-pmic" 10- compatible: Should be "samsung,s2mps11-pmic" or "samsung,s2mps13-pmic"
11 or "samsung,s2mpu02-pmic". 11 or "samsung,s2mps14-pmic" or "samsung,s2mpu02-pmic".
12- reg: Specifies the I2C slave address of the pmic block. It should be 0x66. 12- reg: Specifies the I2C slave address of the pmic block. It should be 0x66.
13 13
14Optional properties: 14Optional properties:
@@ -17,8 +17,8 @@ Optional properties:
17- interrupts: Interrupt specifiers for interrupt sources. 17- interrupts: Interrupt specifiers for interrupt sources.
18 18
19Optional nodes: 19Optional nodes:
20- clocks: s2mps11 and s5m8767 provide three(AP/CP/BT) buffered 32.768 KHz 20- clocks: s2mps11, s2mps13 and s5m8767 provide three(AP/CP/BT) buffered 32.768
21 outputs, so to register these as clocks with common clock framework 21 KHz outputs, so to register these as clocks with common clock framework
22 instantiate a sub-node named "clocks". It uses the common clock binding 22 instantiate a sub-node named "clocks". It uses the common clock binding
23 documented in : 23 documented in :
24 [Documentation/devicetree/bindings/clock/clock-bindings.txt] 24 [Documentation/devicetree/bindings/clock/clock-bindings.txt]
@@ -30,12 +30,12 @@ Optional nodes:
30 the clock which they consume. 30 the clock which they consume.
31 Clock ID Devices 31 Clock ID Devices
32 ---------------------------------------------------------- 32 ----------------------------------------------------------
33 32KhzAP 0 S2MPS11, S2MPS14, S5M8767 33 32KhzAP 0 S2MPS11, S2MPS13, S2MPS14, S5M8767
34 32KhzCP 1 S2MPS11, S5M8767 34 32KhzCP 1 S2MPS11, S2MPS13, S5M8767
35 32KhzBT 2 S2MPS11, S2MPS14, S5M8767 35 32KhzBT 2 S2MPS11, S2MPS13, S2MPS14, S5M8767
36 36
37 - compatible: Should be one of: "samsung,s2mps11-clk", "samsung,s2mps14-clk", 37 - compatible: Should be one of: "samsung,s2mps11-clk", "samsung,s2mps13-clk",
38 "samsung,s5m8767-clk" 38 "samsung,s2mps14-clk", "samsung,s5m8767-clk"
39 39
40- regulators: The regulators of s2mps11 that have to be instantiated should be 40- regulators: The regulators of s2mps11 that have to be instantiated should be
41included in a sub-node named 'regulators'. Regulator nodes included in this 41included in a sub-node named 'regulators'. Regulator nodes included in this
@@ -81,12 +81,14 @@ as per the datasheet of s2mps11.
81 - LDOn 81 - LDOn
82 - valid values for n are: 82 - valid values for n are:
83 - S2MPS11: 1 to 38 83 - S2MPS11: 1 to 38
84 - S2MPS13: 1 to 40
84 - S2MPS14: 1 to 25 85 - S2MPS14: 1 to 25
85 - S2MPU02: 1 to 28 86 - S2MPU02: 1 to 28
86 - Example: LDO1, LDO2, LDO28 87 - Example: LDO1, LDO2, LDO28
87 - BUCKn 88 - BUCKn
88 - valid values for n are: 89 - valid values for n are:
89 - S2MPS11: 1 to 10 90 - S2MPS11: 1 to 10
91 - S2MPS13: 1 to 10
90 - S2MPS14: 1 to 5 92 - S2MPS14: 1 to 5
91 - S2MPU02: 1 to 7 93 - S2MPU02: 1 to 7
92 - Example: BUCK1, BUCK2, BUCK9 94 - Example: BUCK1, BUCK2, BUCK9
diff --git a/Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt b/Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt
index 6cd3525d0e09..ee4fc0576c7d 100644
--- a/Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt
+++ b/Documentation/devicetree/bindings/mmc/exynos-dw-mshc.txt
@@ -18,6 +18,10 @@ Required Properties:
18 specific extensions. 18 specific extensions.
19 - "samsung,exynos5420-dw-mshc": for controllers with Samsung Exynos5420 19 - "samsung,exynos5420-dw-mshc": for controllers with Samsung Exynos5420
20 specific extensions. 20 specific extensions.
21 - "samsung,exynos7-dw-mshc": for controllers with Samsung Exynos7
22 specific extensions.
23 - "samsung,exynos7-dw-mshc-smu": for controllers with Samsung Exynos7
24 specific extensions having an SMU.
21 25
22* samsung,dw-mshc-ciu-div: Specifies the divider value for the card interface 26* samsung,dw-mshc-ciu-div: Specifies the divider value for the card interface
23 unit (ciu) clock. This property is applicable only for Exynos5 SoC's and 27 unit (ciu) clock. This property is applicable only for Exynos5 SoC's and
diff --git a/Documentation/devicetree/bindings/mmc/img-dw-mshc.txt b/Documentation/devicetree/bindings/mmc/img-dw-mshc.txt
new file mode 100644
index 000000000000..85de99fcaa2f
--- /dev/null
+++ b/Documentation/devicetree/bindings/mmc/img-dw-mshc.txt
@@ -0,0 +1,29 @@
1* Imagination specific extensions to the Synopsys Designware Mobile Storage
2 Host Controller
3
4The Synopsys designware mobile storage host controller is used to interface
5a SoC with storage medium such as eMMC or SD/MMC cards. This file documents
6differences between the core Synopsys dw mshc controller properties described
7by synopsys-dw-mshc.txt and the properties used by the Imagination specific
8extensions to the Synopsys Designware Mobile Storage Host Controller.
9
10Required Properties:
11
12* compatible: should be
13 - "img,pistachio-dw-mshc": for Pistachio SoCs
14
15Example:
16
17 mmc@18142000 {
18 compatible = "img,pistachio-dw-mshc";
19 reg = <0x18142000 0x400>;
20 interrupts = <GIC_SHARED 39 IRQ_TYPE_LEVEL_HIGH>;
21
22 clocks = <&system_clk>, <&sdhost_clk>;
23 clock-names = "biu", "ciu";
24
25 fifo-depth = <0x20>;
26 bus-width = <4>;
27 num-slots = <1>;
28 disable-wp;
29 };
diff --git a/Documentation/devicetree/bindings/mmc/sdhci-pxa.txt b/Documentation/devicetree/bindings/mmc/sdhci-pxa.txt
index 86223c3eda90..4dd6deb90719 100644
--- a/Documentation/devicetree/bindings/mmc/sdhci-pxa.txt
+++ b/Documentation/devicetree/bindings/mmc/sdhci-pxa.txt
@@ -12,6 +12,10 @@ Required properties:
12 * for "marvell,armada-380-sdhci", two register areas. The first one 12 * for "marvell,armada-380-sdhci", two register areas. The first one
13 for the SDHCI registers themselves, and the second one for the 13 for the SDHCI registers themselves, and the second one for the
14 AXI/Mbus bridge registers of the SDHCI unit. 14 AXI/Mbus bridge registers of the SDHCI unit.
15- clocks: Array of clocks required for SDHCI; requires at least one for
16 I/O clock.
17- clock-names: Array of names corresponding to clocks property; shall be
18 "io" for I/O clock and "core" for optional core clock.
15 19
16Optional properties: 20Optional properties:
17- mrvl,clk-delay-cycles: Specify a number of cycles to delay for tuning. 21- mrvl,clk-delay-cycles: Specify a number of cycles to delay for tuning.
@@ -23,6 +27,8 @@ sdhci@d4280800 {
23 reg = <0xd4280800 0x800>; 27 reg = <0xd4280800 0x800>;
24 bus-width = <8>; 28 bus-width = <8>;
25 interrupts = <27>; 29 interrupts = <27>;
30 clocks = <&chip CLKID_SDIO1XIN>, <&chip CLKID_SDIO1>;
31 clock-names = "io", "core";
26 non-removable; 32 non-removable;
27 mrvl,clk-delay-cycles = <31>; 33 mrvl,clk-delay-cycles = <31>;
28}; 34};
@@ -32,5 +38,6 @@ sdhci@d8000 {
32 reg = <0xd8000 0x1000>, <0xdc000 0x100>; 38 reg = <0xd8000 0x1000>, <0xdc000 0x100>;
33 interrupts = <0 25 0x4>; 39 interrupts = <0 25 0x4>;
34 clocks = <&gateclk 17>; 40 clocks = <&gateclk 17>;
41 clock-names = "io";
35 mrvl,clk-delay-cycles = <0x1F>; 42 mrvl,clk-delay-cycles = <0x1F>;
36}; 43};
diff --git a/Documentation/devicetree/bindings/nios2/nios2.txt b/Documentation/devicetree/bindings/nios2/nios2.txt
new file mode 100644
index 000000000000..d6d0a94cb3bb
--- /dev/null
+++ b/Documentation/devicetree/bindings/nios2/nios2.txt
@@ -0,0 +1,62 @@
1* Nios II Processor Binding
2
3This binding specifies what properties available in the device tree
4representation of a Nios II Processor Core.
5
6Users can use sopc2dts tool for generating device tree sources (dts) from a
7Qsys system. See more detail in: http://www.alterawiki.com/wiki/Sopc2dts
8
9Required properties:
10
11- compatible: Compatible property value should be "altr,nios2-1.0".
12- reg: Contains CPU index.
13- interrupt-controller: Specifies that the node is an interrupt controller
14- #interrupt-cells: Specifies the number of cells needed to encode an
15 interrupt source, should be 1.
16- clock-frequency: Contains the clock frequency for CPU, in Hz.
17- dcache-line-size: Contains data cache line size.
18- icache-line-size: Contains instruction line size.
19- dcache-size: Contains data cache size.
20- icache-size: Contains instruction cache size.
21- altr,pid-num-bits: Specifies the number of bits to use to represent the process
22 identifier (PID).
23- altr,tlb-num-ways: Specifies the number of set-associativity ways in the TLB.
24- altr,tlb-num-entries: Specifies the number of entries in the TLB.
25- altr,tlb-ptr-sz: Specifies size of TLB pointer.
26- altr,has-mul: Specifies CPU hardware multipy support, should be 1.
27- altr,has-mmu: Specifies CPU support MMU support, should be 1.
28- altr,has-initda: Specifies CPU support initda instruction, should be 1.
29- altr,reset-addr: Specifies CPU reset address
30- altr,fast-tlb-miss-addr: Specifies CPU fast TLB miss exception address
31- altr,exception-addr: Specifies CPU exception address
32
33Optional properties:
34- altr,has-div: Specifies CPU hardware divide support
35- altr,implementation: Nios II core implementation, this should be "fast";
36
37Example:
38
39cpu@0x0 {
40 device_type = "cpu";
41 compatible = "altr,nios2-1.0";
42 reg = <0>;
43 interrupt-controller;
44 #interrupt-cells = <1>;
45 clock-frequency = <125000000>;
46 dcache-line-size = <32>;
47 icache-line-size = <32>;
48 dcache-size = <32768>;
49 icache-size = <32768>;
50 altr,implementation = "fast";
51 altr,pid-num-bits = <8>;
52 altr,tlb-num-ways = <16>;
53 altr,tlb-num-entries = <128>;
54 altr,tlb-ptr-sz = <7>;
55 altr,has-div = <1>;
56 altr,has-mul = <1>;
57 altr,reset-addr = <0xc2800000>;
58 altr,fast-tlb-miss-addr = <0xc7fff400>;
59 altr,exception-addr = <0xd0000020>;
60 altr,has-initda = <1>;
61 altr,has-mmu = <1>;
62};
diff --git a/Documentation/devicetree/bindings/nios2/timer.txt b/Documentation/devicetree/bindings/nios2/timer.txt
new file mode 100644
index 000000000000..904a5846d7ac
--- /dev/null
+++ b/Documentation/devicetree/bindings/nios2/timer.txt
@@ -0,0 +1,19 @@
1Altera Timer
2
3Required properties:
4
5- compatible : should be "altr,timer-1.0"
6- reg : Specifies base physical address and size of the registers.
7- interrupt-parent: phandle of the interrupt controller
8- interrupts : Should contain the timer interrupt number
9- clock-frequency : The frequency of the clock that drives the counter, in Hz.
10
11Example:
12
13timer {
14 compatible = "altr,timer-1.0";
15 reg = <0x00400000 0x00000020>;
16 interrupt-parent = <&cpu>;
17 interrupts = <11>;
18 clock-frequency = <125000000>;
19};
diff --git a/Documentation/devicetree/bindings/pci/pci.txt b/Documentation/devicetree/bindings/pci/pci.txt
index 41aeed38926d..f8fbe9af7b2f 100644
--- a/Documentation/devicetree/bindings/pci/pci.txt
+++ b/Documentation/devicetree/bindings/pci/pci.txt
@@ -7,3 +7,14 @@ And for the interrupt mapping part:
7 7
8Open Firmware Recommended Practice: Interrupt Mapping 8Open Firmware Recommended Practice: Interrupt Mapping
9http://www.openfirmware.org/1275/practice/imap/imap0_9d.pdf 9http://www.openfirmware.org/1275/practice/imap/imap0_9d.pdf
10
11Additionally to the properties specified in the above standards a host bridge
12driver implementation may support the following properties:
13
14- linux,pci-domain:
15 If present this property assigns a fixed PCI domain number to a host bridge,
16 otherwise an unstable (across boots) unique number will be assigned.
17 It is required to either not set this property at all or set it for all
18 host bridges in the system, otherwise potentially conflicting domain numbers
19 may be assigned to root buses behind different host bridges. The domain
20 number for each host bridge in the system must be unique.
diff --git a/Documentation/devicetree/bindings/pinctrl/img,tz1090-pdc-pinctrl.txt b/Documentation/devicetree/bindings/pinctrl/img,tz1090-pdc-pinctrl.txt
index a186181c402b..51b943cc9770 100644
--- a/Documentation/devicetree/bindings/pinctrl/img,tz1090-pdc-pinctrl.txt
+++ b/Documentation/devicetree/bindings/pinctrl/img,tz1090-pdc-pinctrl.txt
@@ -9,7 +9,7 @@ Please refer to pinctrl-bindings.txt in this directory for details of the
9common pinctrl bindings used by client devices, including the meaning of the 9common pinctrl bindings used by client devices, including the meaning of the
10phrase "pin configuration node". 10phrase "pin configuration node".
11 11
12TZ1090-PDC's pin configuration nodes act as a container for an abitrary number 12TZ1090-PDC's pin configuration nodes act as a container for an arbitrary number
13of subnodes. Each of these subnodes represents some desired configuration for a 13of subnodes. Each of these subnodes represents some desired configuration for a
14pin, a group, or a list of pins or groups. This configuration can include the 14pin, a group, or a list of pins or groups. This configuration can include the
15mux function to select on those pin(s)/group(s), and various pin configuration 15mux function to select on those pin(s)/group(s), and various pin configuration
diff --git a/Documentation/devicetree/bindings/pinctrl/img,tz1090-pinctrl.txt b/Documentation/devicetree/bindings/pinctrl/img,tz1090-pinctrl.txt
index 4b27c99f7f9d..49d0e6050940 100644
--- a/Documentation/devicetree/bindings/pinctrl/img,tz1090-pinctrl.txt
+++ b/Documentation/devicetree/bindings/pinctrl/img,tz1090-pinctrl.txt
@@ -9,7 +9,7 @@ Please refer to pinctrl-bindings.txt in this directory for details of the
9common pinctrl bindings used by client devices, including the meaning of the 9common pinctrl bindings used by client devices, including the meaning of the
10phrase "pin configuration node". 10phrase "pin configuration node".
11 11
12TZ1090's pin configuration nodes act as a container for an abitrary number of 12TZ1090's pin configuration nodes act as a container for an arbitrary number of
13subnodes. Each of these subnodes represents some desired configuration for a 13subnodes. Each of these subnodes represents some desired configuration for a
14pin, a group, or a list of pins or groups. This configuration can include the 14pin, a group, or a list of pins or groups. This configuration can include the
15mux function to select on those pin(s)/group(s), and various pin configuration 15mux function to select on those pin(s)/group(s), and various pin configuration
diff --git a/Documentation/devicetree/bindings/pinctrl/lantiq,falcon-pinumx.txt b/Documentation/devicetree/bindings/pinctrl/lantiq,falcon-pinumx.txt
index daa768956069..ac4da9fe07bd 100644
--- a/Documentation/devicetree/bindings/pinctrl/lantiq,falcon-pinumx.txt
+++ b/Documentation/devicetree/bindings/pinctrl/lantiq,falcon-pinumx.txt
@@ -9,7 +9,7 @@ Please refer to pinctrl-bindings.txt in this directory for details of the
9common pinctrl bindings used by client devices, including the meaning of the 9common pinctrl bindings used by client devices, including the meaning of the
10phrase "pin configuration node". 10phrase "pin configuration node".
11 11
12Lantiq's pin configuration nodes act as a container for an abitrary number of 12Lantiq's pin configuration nodes act as a container for an arbitrary number of
13subnodes. Each of these subnodes represents some desired configuration for a 13subnodes. Each of these subnodes represents some desired configuration for a
14pin, a group, or a list of pins or groups. This configuration can include the 14pin, a group, or a list of pins or groups. This configuration can include the
15mux function to select on those group(s), and two pin configuration parameters: 15mux function to select on those group(s), and two pin configuration parameters:
diff --git a/Documentation/devicetree/bindings/pinctrl/lantiq,xway-pinumx.txt b/Documentation/devicetree/bindings/pinctrl/lantiq,xway-pinumx.txt
index b5469db1d7ad..e89b4677567d 100644
--- a/Documentation/devicetree/bindings/pinctrl/lantiq,xway-pinumx.txt
+++ b/Documentation/devicetree/bindings/pinctrl/lantiq,xway-pinumx.txt
@@ -9,7 +9,7 @@ Please refer to pinctrl-bindings.txt in this directory for details of the
9common pinctrl bindings used by client devices, including the meaning of the 9common pinctrl bindings used by client devices, including the meaning of the
10phrase "pin configuration node". 10phrase "pin configuration node".
11 11
12Lantiq's pin configuration nodes act as a container for an abitrary number of 12Lantiq's pin configuration nodes act as a container for an arbitrary number of
13subnodes. Each of these subnodes represents some desired configuration for a 13subnodes. Each of these subnodes represents some desired configuration for a
14pin, a group, or a list of pins or groups. This configuration can include the 14pin, a group, or a list of pins or groups. This configuration can include the
15mux function to select on those group(s), and two pin configuration parameters: 15mux function to select on those group(s), and two pin configuration parameters:
diff --git a/Documentation/devicetree/bindings/pinctrl/nvidia,tegra20-pinmux.txt b/Documentation/devicetree/bindings/pinctrl/nvidia,tegra20-pinmux.txt
index 61e73cde9ae9..3c8ce28baad6 100644
--- a/Documentation/devicetree/bindings/pinctrl/nvidia,tegra20-pinmux.txt
+++ b/Documentation/devicetree/bindings/pinctrl/nvidia,tegra20-pinmux.txt
@@ -9,7 +9,7 @@ Please refer to pinctrl-bindings.txt in this directory for details of the
9common pinctrl bindings used by client devices, including the meaning of the 9common pinctrl bindings used by client devices, including the meaning of the
10phrase "pin configuration node". 10phrase "pin configuration node".
11 11
12Tegra's pin configuration nodes act as a container for an abitrary number of 12Tegra's pin configuration nodes act as a container for an arbitrary number of
13subnodes. Each of these subnodes represents some desired configuration for a 13subnodes. Each of these subnodes represents some desired configuration for a
14pin, a group, or a list of pins or groups. This configuration can include the 14pin, a group, or a list of pins or groups. This configuration can include the
15mux function to select on those pin(s)/group(s), and various pin configuration 15mux function to select on those pin(s)/group(s), and various pin configuration
diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl-sirf.txt b/Documentation/devicetree/bindings/pinctrl/pinctrl-sirf.txt
index c596a6ad3285..5f55be59d914 100644
--- a/Documentation/devicetree/bindings/pinctrl/pinctrl-sirf.txt
+++ b/Documentation/devicetree/bindings/pinctrl/pinctrl-sirf.txt
@@ -13,7 +13,7 @@ Optional properties:
13Please refer to pinctrl-bindings.txt in this directory for details of the common 13Please refer to pinctrl-bindings.txt in this directory for details of the common
14pinctrl bindings used by client devices. 14pinctrl bindings used by client devices.
15 15
16SiRFprimaII's pinmux nodes act as a container for an abitrary number of subnodes. 16SiRFprimaII's pinmux nodes act as a container for an arbitrary number of subnodes.
17Each of these subnodes represents some desired configuration for a group of pins. 17Each of these subnodes represents some desired configuration for a group of pins.
18 18
19Required subnode-properties: 19Required subnode-properties:
diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl_spear.txt b/Documentation/devicetree/bindings/pinctrl/pinctrl_spear.txt
index b4480d5c3aca..458615596946 100644
--- a/Documentation/devicetree/bindings/pinctrl/pinctrl_spear.txt
+++ b/Documentation/devicetree/bindings/pinctrl/pinctrl_spear.txt
@@ -32,7 +32,7 @@ Required properties:
32Please refer to pinctrl-bindings.txt in this directory for details of the common 32Please refer to pinctrl-bindings.txt in this directory for details of the common
33pinctrl bindings used by client devices. 33pinctrl bindings used by client devices.
34 34
35SPEAr's pinmux nodes act as a container for an abitrary number of subnodes. Each 35SPEAr's pinmux nodes act as a container for an arbitrary number of subnodes. Each
36of these subnodes represents muxing for a pin, a group, or a list of pins or 36of these subnodes represents muxing for a pin, a group, or a list of pins or
37groups. 37groups.
38 38
diff --git a/Documentation/devicetree/bindings/pinctrl/qcom,apq8064-pinctrl.txt b/Documentation/devicetree/bindings/pinctrl/qcom,apq8064-pinctrl.txt
index 2fb90b37aa09..a7bde64798c7 100644
--- a/Documentation/devicetree/bindings/pinctrl/qcom,apq8064-pinctrl.txt
+++ b/Documentation/devicetree/bindings/pinctrl/qcom,apq8064-pinctrl.txt
@@ -18,7 +18,7 @@ Please refer to pinctrl-bindings.txt in this directory for details of the
18common pinctrl bindings used by client devices, including the meaning of the 18common pinctrl bindings used by client devices, including the meaning of the
19phrase "pin configuration node". 19phrase "pin configuration node".
20 20
21Qualcomm's pin configuration nodes act as a container for an abitrary number of 21Qualcomm's pin configuration nodes act as a container for an arbitrary number of
22subnodes. Each of these subnodes represents some desired configuration for a 22subnodes. Each of these subnodes represents some desired configuration for a
23pin, a group, or a list of pins or groups. This configuration can include the 23pin, a group, or a list of pins or groups. This configuration can include the
24mux function to select on those pin(s)/group(s), and various pin configuration 24mux function to select on those pin(s)/group(s), and various pin configuration
diff --git a/Documentation/devicetree/bindings/pinctrl/qcom,apq8084-pinctrl.txt b/Documentation/devicetree/bindings/pinctrl/qcom,apq8084-pinctrl.txt
index ffafa1990a30..c4ea61ac56f2 100644
--- a/Documentation/devicetree/bindings/pinctrl/qcom,apq8084-pinctrl.txt
+++ b/Documentation/devicetree/bindings/pinctrl/qcom,apq8084-pinctrl.txt
@@ -47,7 +47,7 @@ Please refer to pinctrl-bindings.txt in this directory for details of the
47common pinctrl bindings used by client devices, including the meaning of the 47common pinctrl bindings used by client devices, including the meaning of the
48phrase "pin configuration node". 48phrase "pin configuration node".
49 49
50The pin configuration nodes act as a container for an abitrary number of 50The pin configuration nodes act as a container for an arbitrary number of
51subnodes. Each of these subnodes represents some desired configuration for a 51subnodes. Each of these subnodes represents some desired configuration for a
52pin, a group, or a list of pins or groups. This configuration can include the 52pin, a group, or a list of pins or groups. This configuration can include the
53mux function to select on those pin(s)/group(s), and various pin configuration 53mux function to select on those pin(s)/group(s), and various pin configuration
diff --git a/Documentation/devicetree/bindings/pinctrl/qcom,ipq8064-pinctrl.txt b/Documentation/devicetree/bindings/pinctrl/qcom,ipq8064-pinctrl.txt
index e33e4dcdce79..6e88e91feb11 100644
--- a/Documentation/devicetree/bindings/pinctrl/qcom,ipq8064-pinctrl.txt
+++ b/Documentation/devicetree/bindings/pinctrl/qcom,ipq8064-pinctrl.txt
@@ -18,7 +18,7 @@ Please refer to pinctrl-bindings.txt in this directory for details of the
18common pinctrl bindings used by client devices, including the meaning of the 18common pinctrl bindings used by client devices, including the meaning of the
19phrase "pin configuration node". 19phrase "pin configuration node".
20 20
21Qualcomm's pin configuration nodes act as a container for an abitrary number of 21Qualcomm's pin configuration nodes act as a container for an arbitrary number of
22subnodes. Each of these subnodes represents some desired configuration for a 22subnodes. Each of these subnodes represents some desired configuration for a
23pin, a group, or a list of pins or groups. This configuration can include the 23pin, a group, or a list of pins or groups. This configuration can include the
24mux function to select on those pin(s)/group(s), and various pin configuration 24mux function to select on those pin(s)/group(s), and various pin configuration
diff --git a/Documentation/devicetree/bindings/pinctrl/qcom,msm8960-pinctrl.txt b/Documentation/devicetree/bindings/pinctrl/qcom,msm8960-pinctrl.txt
index 93b7de91b9f6..eb8d8aa41f20 100644
--- a/Documentation/devicetree/bindings/pinctrl/qcom,msm8960-pinctrl.txt
+++ b/Documentation/devicetree/bindings/pinctrl/qcom,msm8960-pinctrl.txt
@@ -47,7 +47,7 @@ Please refer to pinctrl-bindings.txt in this directory for details of the
47common pinctrl bindings used by client devices, including the meaning of the 47common pinctrl bindings used by client devices, including the meaning of the
48phrase "pin configuration node". 48phrase "pin configuration node".
49 49
50The pin configuration nodes act as a container for an abitrary number of 50The pin configuration nodes act as a container for an arbitrary number of
51subnodes. Each of these subnodes represents some desired configuration for a 51subnodes. Each of these subnodes represents some desired configuration for a
52pin, a group, or a list of pins or groups. This configuration can include the 52pin, a group, or a list of pins or groups. This configuration can include the
53mux function to select on those pin(s)/group(s), and various pin configuration 53mux function to select on those pin(s)/group(s), and various pin configuration
diff --git a/Documentation/devicetree/bindings/pinctrl/qcom,msm8974-pinctrl.txt b/Documentation/devicetree/bindings/pinctrl/qcom,msm8974-pinctrl.txt
index d2ea80dc43eb..e4d6a9d20f7d 100644
--- a/Documentation/devicetree/bindings/pinctrl/qcom,msm8974-pinctrl.txt
+++ b/Documentation/devicetree/bindings/pinctrl/qcom,msm8974-pinctrl.txt
@@ -18,7 +18,7 @@ Please refer to pinctrl-bindings.txt in this directory for details of the
18common pinctrl bindings used by client devices, including the meaning of the 18common pinctrl bindings used by client devices, including the meaning of the
19phrase "pin configuration node". 19phrase "pin configuration node".
20 20
21Qualcomm's pin configuration nodes act as a container for an abitrary number of 21Qualcomm's pin configuration nodes act as a container for an arbitrary number of
22subnodes. Each of these subnodes represents some desired configuration for a 22subnodes. Each of these subnodes represents some desired configuration for a
23pin, a group, or a list of pins or groups. This configuration can include the 23pin, a group, or a list of pins or groups. This configuration can include the
24mux function to select on those pin(s)/group(s), and various pin configuration 24mux function to select on those pin(s)/group(s), and various pin configuration
diff --git a/Documentation/devicetree/bindings/power/power-controller.txt b/Documentation/devicetree/bindings/power/power-controller.txt
new file mode 100644
index 000000000000..4f7a3bc9c407
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/power-controller.txt
@@ -0,0 +1,18 @@
1* Generic system power control capability
2
3Power-management integrated circuits or miscellaneous hardware components are
4sometimes able to control the system power. The device driver associated with these
5components might need to define this capability, which tells the kernel that
6it can be used to switch off the system. The corresponding device must have the
7standard property "system-power-controller" in its device node. This property
8marks the device as able to control the system power. In order to test if this
9property is found programmatically, use the helper function
10"of_device_is_system_power_controller" from of.h .
11
12Example:
13
14act8846: act8846@5 {
15 compatible = "active-semi,act8846";
16 status = "okay";
17 system-power-controller;
18}
diff --git a/Documentation/devicetree/bindings/regulator/act8865-regulator.txt b/Documentation/devicetree/bindings/regulator/act8865-regulator.txt
index 865614b34d6f..dad6358074ac 100644
--- a/Documentation/devicetree/bindings/regulator/act8865-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/act8865-regulator.txt
@@ -5,6 +5,10 @@ Required properties:
5- compatible: "active-semi,act8846" or "active-semi,act8865" 5- compatible: "active-semi,act8846" or "active-semi,act8865"
6- reg: I2C slave address 6- reg: I2C slave address
7 7
8Optional properties:
9- system-power-controller: Telling whether or not this pmic is controlling
10 the system power. See Documentation/devicetree/bindings/power/power-controller.txt .
11
8Any standard regulator properties can be used to configure the single regulator. 12Any standard regulator properties can be used to configure the single regulator.
9 13
10The valid names for regulators are: 14The valid names for regulators are:
diff --git a/Documentation/devicetree/bindings/regulator/max77802.txt b/Documentation/devicetree/bindings/regulator/max77802.txt
index 5aeaffc0f1f0..79e5476444f7 100644
--- a/Documentation/devicetree/bindings/regulator/max77802.txt
+++ b/Documentation/devicetree/bindings/regulator/max77802.txt
@@ -25,6 +25,29 @@ with their hardware counterparts as follow. The valid names are:
25 example: LDO1, LDO2, LDO35. 25 example: LDO1, LDO2, LDO35.
26 -BUCKn : for BUCKs, where n can lie in range 1 to 10. 26 -BUCKn : for BUCKs, where n can lie in range 1 to 10.
27 example: BUCK1, BUCK5, BUCK10. 27 example: BUCK1, BUCK5, BUCK10.
28
29The max77802 regulator supports two different operating modes: Normal and Low
30Power Mode. Some regulators support the modes to be changed at startup or by
31the consumers during normal operation while others only support to change the
32mode during system suspend. The standard regulator suspend states binding can
33be used to configure the regulator operating mode.
34
35The regulators that support the standard "regulator-initial-mode" property,
36changing their mode during normal operation are: LDOs 1, 3, 20 and 21.
37
38The possible values for "regulator-initial-mode" and "regulator-mode" are:
39 1: Normal regulator voltage output mode.
40 3: Low Power which reduces the quiescent current down to only 1uA
41
42The list of valid modes are defined in the dt-bindings/clock/maxim,max77802.h
43header and can be included by device tree source files.
44
45The standard "regulator-mode" property can only be used for regulators that
46support changing their mode to Low Power Mode during suspend. These regulators
47are: BUCKs 2-4 and LDOs 1-35. Also, it only takes effect if the regulator has
48been enabled for the given suspend state using "regulator-on-in-suspend" and
49has not been disabled for that state using "regulator-off-in-suspend".
50
28Example: 51Example:
29 52
30 max77802@09 { 53 max77802@09 {
@@ -36,11 +59,23 @@ Example:
36 #size-cells = <0>; 59 #size-cells = <0>;
37 60
38 regulators { 61 regulators {
62 ldo1_reg: LDO1 {
63 regulator-name = "vdd_1v0";
64 regulator-min-microvolt = <1000000>;
65 regulator-max-microvolt = <1000000>;
66 regulator-always-on;
67 regulator-initial-mode = <MAX77802_OPMODE_LP>;
68 };
69
39 ldo11_reg: LDO11 { 70 ldo11_reg: LDO11 {
40 regulator-name = "vdd_ldo11"; 71 regulator-name = "vdd_ldo11";
41 regulator-min-microvolt = <1900000>; 72 regulator-min-microvolt = <1900000>;
42 regulator-max-microvolt = <1900000>; 73 regulator-max-microvolt = <1900000>;
43 regulator-always-on; 74 regulator-always-on;
75 regulator-state-mem {
76 regulator-on-in-suspend;
77 regulator-mode = <MAX77802_OPMODE_LP>;
78 };
44 }; 79 };
45 80
46 buck1_reg: BUCK1 { 81 buck1_reg: BUCK1 {
diff --git a/Documentation/devicetree/bindings/regulator/regulator.txt b/Documentation/devicetree/bindings/regulator/regulator.txt
index 86074334e342..abb26b58c83e 100644
--- a/Documentation/devicetree/bindings/regulator/regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/regulator.txt
@@ -19,6 +19,24 @@ Optional properties:
19 design requires. This property describes the total system ramp time 19 design requires. This property describes the total system ramp time
20 required due to the combination of internal ramping of the regulator itself, 20 required due to the combination of internal ramping of the regulator itself,
21 and board design issues such as trace capacitance and load on the supply. 21 and board design issues such as trace capacitance and load on the supply.
22- regulator-state-mem sub-root node for Suspend-to-RAM mode
23 : suspend to memory, the device goes to sleep, but all data stored in memory,
24 only some external interrupt can wake the device.
25- regulator-state-disk sub-root node for Suspend-to-DISK mode
26 : suspend to disk, this state operates similarly to Suspend-to-RAM,
27 but includes a final step of writing memory contents to disk.
28- regulator-state-[mem/disk] node has following common properties:
29 - regulator-on-in-suspend: regulator should be on in suspend state.
30 - regulator-off-in-suspend: regulator should be off in suspend state.
31 - regulator-suspend-microvolt: regulator should be set to this voltage
32 in suspend.
33 - regulator-mode: operating mode in the given suspend state.
34 The set of possible operating modes depends on the capabilities of
35 every hardware so the valid modes are documented on each regulator
36 device tree binding document.
37- regulator-initial-mode: initial operating mode. The set of possible operating
38 modes depends on the capabilities of every hardware so each device binding
39 documentation explains which values the regulator supports.
22 40
23Deprecated properties: 41Deprecated properties:
24- regulator-compatible: If a regulator chip contains multiple 42- regulator-compatible: If a regulator chip contains multiple
@@ -34,6 +52,10 @@ Example:
34 regulator-max-microvolt = <2500000>; 52 regulator-max-microvolt = <2500000>;
35 regulator-always-on; 53 regulator-always-on;
36 vin-supply = <&vin>; 54 vin-supply = <&vin>;
55
56 regulator-state-mem {
57 regulator-on-in-suspend;
58 };
37 }; 59 };
38 60
39Regulator Consumers: 61Regulator Consumers:
diff --git a/Documentation/devicetree/bindings/regulator/sky81452-regulator.txt b/Documentation/devicetree/bindings/regulator/sky81452-regulator.txt
index 882455e9b36d..f9acbc1f3c6b 100644
--- a/Documentation/devicetree/bindings/regulator/sky81452-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/sky81452-regulator.txt
@@ -1,6 +1,7 @@
1SKY81452 voltage regulator 1SKY81452 voltage regulator
2 2
3Required properties: 3Required properties:
4- regulator node named lout.
4- any required generic properties defined in regulator.txt 5- any required generic properties defined in regulator.txt
5 6
6Optional properties: 7Optional properties:
@@ -9,8 +10,9 @@ Optional properties:
9Example: 10Example:
10 11
11 regulator { 12 regulator {
12 /* generic regulator properties */ 13 lout {
13 regulator-name = "touch_en"; 14 regulator-name = "sky81452-lout";
14 regulator-min-microvolt = <4500000>; 15 regulator-min-microvolt = <4500000>;
15 regulator-max-microvolt = <8000000>; 16 regulator-max-microvolt = <8000000>;
17 };
16 }; 18 };
diff --git a/Documentation/devicetree/bindings/thermal/rcar-thermal.txt b/Documentation/devicetree/bindings/thermal/rcar-thermal.txt
index 0ef00be44b01..43404b197933 100644
--- a/Documentation/devicetree/bindings/thermal/rcar-thermal.txt
+++ b/Documentation/devicetree/bindings/thermal/rcar-thermal.txt
@@ -7,7 +7,10 @@ Required properties:
7 - "renesas,thermal-r8a73a4" (R-Mobile AP6) 7 - "renesas,thermal-r8a73a4" (R-Mobile AP6)
8 - "renesas,thermal-r8a7779" (R-Car H1) 8 - "renesas,thermal-r8a7779" (R-Car H1)
9 - "renesas,thermal-r8a7790" (R-Car H2) 9 - "renesas,thermal-r8a7790" (R-Car H2)
10 - "renesas,thermal-r8a7791" (R-Car M2) 10 - "renesas,thermal-r8a7791" (R-Car M2-W)
11 - "renesas,thermal-r8a7792" (R-Car V2H)
12 - "renesas,thermal-r8a7793" (R-Car M2-N)
13 - "renesas,thermal-r8a7794" (R-Car E2)
11- reg : Address range of the thermal registers. 14- reg : Address range of the thermal registers.
12 The 1st reg will be recognized as common register 15 The 1st reg will be recognized as common register
13 if it has "interrupts". 16 if it has "interrupts".
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 3da78a14e6c7..ecaf2035c2fe 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -34,6 +34,7 @@ chipidea Chipidea, Inc
34chrp Common Hardware Reference Platform 34chrp Common Hardware Reference Platform
35chunghwa Chunghwa Picture Tubes Ltd. 35chunghwa Chunghwa Picture Tubes Ltd.
36cirrus Cirrus Logic, Inc. 36cirrus Cirrus Logic, Inc.
37cnm Chips&Media, Inc.
37cortina Cortina Systems, Inc. 38cortina Cortina Systems, Inc.
38crystalfontz Crystalfontz America, Inc. 39crystalfontz Crystalfontz America, Inc.
39dallas Maxim Integrated Products (formerly Dallas Semiconductor) 40dallas Maxim Integrated Products (formerly Dallas Semiconductor)
@@ -93,6 +94,7 @@ mediatek MediaTek Inc.
93merrii Merrii Technology Co., Ltd. 94merrii Merrii Technology Co., Ltd.
94micrel Micrel Inc. 95micrel Micrel Inc.
95microchip Microchip Technology Inc. 96microchip Microchip Technology Inc.
97micron Micron Technology Inc.
96mitsubishi Mitsubishi Electric Corporation 98mitsubishi Mitsubishi Electric Corporation
97mosaixtech Mosaix Technologies, Inc. 99mosaixtech Mosaix Technologies, Inc.
98moxa Moxa 100moxa Moxa
@@ -128,6 +130,7 @@ renesas Renesas Electronics Corporation
128ricoh Ricoh Co. Ltd. 130ricoh Ricoh Co. Ltd.
129rockchip Fuzhou Rockchip Electronics Co., Ltd 131rockchip Fuzhou Rockchip Electronics Co., Ltd
130samsung Samsung Semiconductor 132samsung Samsung Semiconductor
133sandisk Sandisk Corporation
131sbs Smart Battery System 134sbs Smart Battery System
132schindler Schindler 135schindler Schindler
133seagate Seagate Technology PLC 136seagate Seagate Technology PLC
@@ -139,7 +142,7 @@ silergy Silergy Corp.
139sirf SiRF Technology, Inc. 142sirf SiRF Technology, Inc.
140sitronix Sitronix Technology Corporation 143sitronix Sitronix Technology Corporation
141smsc Standard Microsystems Corporation 144smsc Standard Microsystems Corporation
142snps Synopsys, Inc. 145snps Synopsys, Inc.
143solidrun SolidRun 146solidrun SolidRun
144sony Sony Corporation 147sony Sony Corporation
145spansion Spansion Inc. 148spansion Spansion Inc.
diff --git a/Documentation/filesystems/overlayfs.txt b/Documentation/filesystems/overlayfs.txt
index 530850a72735..a27c950ece61 100644
--- a/Documentation/filesystems/overlayfs.txt
+++ b/Documentation/filesystems/overlayfs.txt
@@ -64,7 +64,7 @@ is formed.
64At mount time, the two directories given as mount options "lowerdir" and 64At mount time, the two directories given as mount options "lowerdir" and
65"upperdir" are combined into a merged directory: 65"upperdir" are combined into a merged directory:
66 66
67 mount -t overlayfs overlayfs -olowerdir=/lower,upperdir=/upper,\ 67 mount -t overlay overlay -olowerdir=/lower,upperdir=/upper,\
68workdir=/work /merged 68workdir=/work /merged
69 69
70The "workdir" needs to be an empty directory on the same filesystem 70The "workdir" needs to be an empty directory on the same filesystem
diff --git a/Documentation/hwmon/lm75 b/Documentation/hwmon/lm75
index c6a5ff1b4641..67691a0aa41d 100644
--- a/Documentation/hwmon/lm75
+++ b/Documentation/hwmon/lm75
@@ -53,6 +53,11 @@ Supported chips:
53 http://www.ti.com/product/tmp75 53 http://www.ti.com/product/tmp75
54 http://www.ti.com/product/tmp175 54 http://www.ti.com/product/tmp175
55 http://www.ti.com/product/tmp275 55 http://www.ti.com/product/tmp275
56 * NXP LM75B
57 Prefix: 'lm75b'
58 Addresses scanned: none
59 Datasheet: Publicly available at the NXP website
60 http://www.nxp.com/documents/data_sheet/LM75B.pdf
56 61
57Author: Frodo Looijaard <frodol@dds.nl> 62Author: Frodo Looijaard <frodol@dds.nl>
58 63
diff --git a/Documentation/hwmon/lm95234 b/Documentation/hwmon/lm95234
index a0e95ddfd372..32b777ef224c 100644
--- a/Documentation/hwmon/lm95234
+++ b/Documentation/hwmon/lm95234
@@ -2,6 +2,10 @@ Kernel driver lm95234
2===================== 2=====================
3 3
4Supported chips: 4Supported chips:
5 * National Semiconductor / Texas Instruments LM95233
6 Addresses scanned: I2C 0x18, 0x2a, 0x2b
7 Datasheet: Publicly available at the Texas Instruments website
8 http://www.ti.com/product/lm95233
5 * National Semiconductor / Texas Instruments LM95234 9 * National Semiconductor / Texas Instruments LM95234
6 Addresses scanned: I2C 0x18, 0x4d, 0x4e 10 Addresses scanned: I2C 0x18, 0x4d, 0x4e
7 Datasheet: Publicly available at the Texas Instruments website 11 Datasheet: Publicly available at the Texas Instruments website
@@ -13,11 +17,12 @@ Author: Guenter Roeck <linux@roeck-us.net>
13Description 17Description
14----------- 18-----------
15 19
16LM95234 is an 11-bit digital temperature sensor with a 2-wire System Management 20LM95233 and LM95234 are 11-bit digital temperature sensors with a 2-wire
17Bus (SMBus) interface and TrueTherm technology that can very accurately monitor 21System Management Bus (SMBus) interface and TrueTherm technology
18the temperature of four remote diodes as well as its own temperature. 22that can very accurately monitor the temperature of two (LM95233)
19The four remote diodes can be external devices such as microprocessors, 23or four (LM95234) remote diodes as well as its own temperature.
20graphics processors or diode-connected 2N3904s. The LM95234's TruTherm 24The remote diodes can be external devices such as microprocessors,
25graphics processors or diode-connected 2N3904s. The chip's TruTherm
21beta compensation technology allows sensing of 90 nm or 65 nm process 26beta compensation technology allows sensing of 90 nm or 65 nm process
22thermal diodes accurately. 27thermal diodes accurately.
23 28
diff --git a/Documentation/hwmon/lm95245 b/Documentation/hwmon/lm95245
index 77eaf2812d25..d755901f58c4 100644
--- a/Documentation/hwmon/lm95245
+++ b/Documentation/hwmon/lm95245
@@ -2,10 +2,14 @@ Kernel driver lm95245
2================== 2==================
3 3
4Supported chips: 4Supported chips:
5 * National Semiconductor LM95245 5 * TI LM95235
6 Addresses scanned: I2C 0x18, 0x29, 0x4c
7 Datasheet: Publicly available at the TI website
8 http://www.ti.com/lit/ds/symlink/lm95235.pdf
9 * TI / National Semiconductor LM95245
6 Addresses scanned: I2C 0x18, 0x19, 0x29, 0x4c, 0x4d 10 Addresses scanned: I2C 0x18, 0x19, 0x29, 0x4c, 0x4d
7 Datasheet: Publicly available at the National Semiconductor website 11 Datasheet: Publicly available at the TI website
8 http://www.national.com/mpf/LM/LM95245.html 12 http://www.ti.com/lit/ds/symlink/lm95245.pdf
9 13
10 14
11Author: Alexander Stein <alexander.stein@systec-electronic.com> 15Author: Alexander Stein <alexander.stein@systec-electronic.com>
@@ -13,10 +17,10 @@ Author: Alexander Stein <alexander.stein@systec-electronic.com>
13Description 17Description
14----------- 18-----------
15 19
16The LM95245 is an 11-bit digital temperature sensor with a 2-wire System 20LM95235 and LM95245 are 11-bit digital temperature sensors with a 2-wire System
17Management Bus (SMBus) interface and TruTherm technology that can monitor 21Management Bus (SMBus) interface and TruTherm technology that can monitor
18the temperature of a remote diode as well as its own temperature. 22the temperature of a remote diode as well as its own temperature.
19The LM95245 can be used to very accurately monitor the temperature of 23The chips can be used to very accurately monitor the temperature of
20external devices such as microprocessors. 24external devices such as microprocessors.
21 25
22All temperature values are given in millidegrees Celsius. Local temperature 26All temperature values are given in millidegrees Celsius. Local temperature
diff --git a/Documentation/hwmon/nct6775 b/Documentation/hwmon/nct6775
index 4e9ef60e8c6c..f0dd3d2fec96 100644
--- a/Documentation/hwmon/nct6775
+++ b/Documentation/hwmon/nct6775
@@ -8,11 +8,15 @@ Kernel driver NCT6775
8===================== 8=====================
9 9
10Supported chips: 10Supported chips:
11 * Nuvoton NCT6102D/NCT6104D/NCT6106D
12 Prefix: 'nct6106'
13 Addresses scanned: ISA address retrieved from Super I/O registers
14 Datasheet: Available from the Nuvoton web site
11 * Nuvoton NCT5572D/NCT6771F/NCT6772F/NCT6775F/W83677HG-I 15 * Nuvoton NCT5572D/NCT6771F/NCT6772F/NCT6775F/W83677HG-I
12 Prefix: 'nct6775' 16 Prefix: 'nct6775'
13 Addresses scanned: ISA address retrieved from Super I/O registers 17 Addresses scanned: ISA address retrieved from Super I/O registers
14 Datasheet: Available from Nuvoton upon request 18 Datasheet: Available from Nuvoton upon request
15 * Nuvoton NCT5577D/NCT6776D/NCT6776F 19 * Nuvoton NCT5573D/NCT5577D/NCT6776D/NCT6776F
16 Prefix: 'nct6776' 20 Prefix: 'nct6776'
17 Addresses scanned: ISA address retrieved from Super I/O registers 21 Addresses scanned: ISA address retrieved from Super I/O registers
18 Datasheet: Available from Nuvoton upon request 22 Datasheet: Available from Nuvoton upon request
@@ -20,6 +24,14 @@ Supported chips:
20 Prefix: 'nct6779' 24 Prefix: 'nct6779'
21 Addresses scanned: ISA address retrieved from Super I/O registers 25 Addresses scanned: ISA address retrieved from Super I/O registers
22 Datasheet: Available from Nuvoton upon request 26 Datasheet: Available from Nuvoton upon request
27 * Nuvoton NCT6791D
28 Prefix: 'nct6791'
29 Addresses scanned: ISA address retrieved from Super I/O registers
30 Datasheet: Available from Nuvoton upon request
31 * Nuvoton NCT6792D
32 Prefix: 'nct6792'
33 Addresses scanned: ISA address retrieved from Super I/O registers
34 Datasheet: Available from Nuvoton upon request
23 35
24Authors: 36Authors:
25 Guenter Roeck <linux@roeck-us.net> 37 Guenter Roeck <linux@roeck-us.net>
diff --git a/Documentation/hwmon/nct7802 b/Documentation/hwmon/nct7802
new file mode 100644
index 000000000000..2e00f5e344bc
--- /dev/null
+++ b/Documentation/hwmon/nct7802
@@ -0,0 +1,32 @@
1Kernel driver nct7802
2=====================
3
4Supported chips:
5 * Nuvoton NCT7802Y
6 Prefix: 'nct7802'
7 Addresses scanned: I2C 0x28..0x2f
8 Datasheet: Available from Nuvoton web site
9
10Authors:
11 Guenter Roeck <linux@roeck-us.net>
12
13Description
14-----------
15
16This driver implements support for the Nuvoton NCT7802Y hardware monitoring
17chip. NCT7802Y supports 6 temperature sensors, 5 voltage sensors, and 3 fan
18speed sensors.
19
20The chip also supports intelligent fan speed control. This functionality is
21not currently supported by the driver.
22
23Tested Boards and BIOS Versions
24-------------------------------
25
26The driver has been reported to work with the following boards and
27BIOS versions.
28
29Board BIOS version
30---------------------------------------------------------------
31Kontron COMe-bSC2 CHR2E934.001.GGO
32Kontron COMe-bIP2 CCR2E212
diff --git a/Documentation/hwmon/tmp401 b/Documentation/hwmon/tmp401
index f91e3fa7e5ec..8eb88e974055 100644
--- a/Documentation/hwmon/tmp401
+++ b/Documentation/hwmon/tmp401
@@ -18,6 +18,10 @@ Supported chips:
18 Prefix: 'tmp432' 18 Prefix: 'tmp432'
19 Addresses scanned: I2C 0x4c, 0x4d 19 Addresses scanned: I2C 0x4c, 0x4d
20 Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp432.html 20 Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp432.html
21 * Texas Instruments TMP435
22 Prefix: 'tmp435'
23 Addresses scanned: I2C 0x37, 0x48 - 0x4f
24 Datasheet: http://focus.ti.com/docs/prod/folders/print/tmp435.html
21 25
22Authors: 26Authors:
23 Hans de Goede <hdegoede@redhat.com> 27 Hans de Goede <hdegoede@redhat.com>
@@ -27,8 +31,8 @@ Description
27----------- 31-----------
28 32
29This driver implements support for Texas Instruments TMP401, TMP411, 33This driver implements support for Texas Instruments TMP401, TMP411,
30TMP431, and TMP432 chips. These chips implement one or two remote and 34TMP431, TMP432 and TMP435 chips. These chips implement one or two remote
31one local temperature sensors. Temperature is measured in degrees 35and one local temperature sensors. Temperature is measured in degrees
32Celsius. Resolution of the remote sensor is 0.0625 degree. Local 36Celsius. Resolution of the remote sensor is 0.0625 degree. Local
33sensor resolution can be set to 0.5, 0.25, 0.125 or 0.0625 degree (not 37sensor resolution can be set to 0.5, 0.25, 0.125 or 0.0625 degree (not
34supported by the driver so far, so using the default resolution of 0.5 38supported by the driver so far, so using the default resolution of 0.5
diff --git a/Documentation/input/elantech.txt b/Documentation/input/elantech.txt
index e1ae127ed099..1ec0db7879d3 100644
--- a/Documentation/input/elantech.txt
+++ b/Documentation/input/elantech.txt
@@ -38,22 +38,38 @@ Contents
38 7.2.1 Status packet 38 7.2.1 Status packet
39 7.2.2 Head packet 39 7.2.2 Head packet
40 7.2.3 Motion packet 40 7.2.3 Motion packet
41 8. Trackpoint (for Hardware version 3 and 4)
42 8.1 Registers
43 8.2 Native relative mode 6 byte packet format
44 8.2.1 Status Packet
41 45
42 46
43 47
441. Introduction 481. Introduction
45 ~~~~~~~~~~~~ 49 ~~~~~~~~~~~~
46 50
47Currently the Linux Elantech touchpad driver is aware of two different 51Currently the Linux Elantech touchpad driver is aware of four different
48hardware versions unimaginatively called version 1 and version 2. Version 1 52hardware versions unimaginatively called version 1,version 2, version 3
49is found in "older" laptops and uses 4 bytes per packet. Version 2 seems to 53and version 4. Version 1 is found in "older" laptops and uses 4 bytes per
50be introduced with the EeePC and uses 6 bytes per packet, and provides 54packet. Version 2 seems to be introduced with the EeePC and uses 6 bytes
51additional features such as position of two fingers, and width of the touch. 55per packet, and provides additional features such as position of two fingers,
56and width of the touch. Hardware version 3 uses 6 bytes per packet (and
57for 2 fingers the concatenation of two 6 bytes packets) and allows tracking
58of up to 3 fingers. Hardware version 4 uses 6 bytes per packet, and can
59combine a status packet with multiple head or motion packets. Hardware version
604 allows tracking up to 5 fingers.
61
62Some Hardware version 3 and version 4 also have a trackpoint which uses a
63separate packet format. It is also 6 bytes per packet.
52 64
53The driver tries to support both hardware versions and should be compatible 65The driver tries to support both hardware versions and should be compatible
54with the Xorg Synaptics touchpad driver and its graphical configuration 66with the Xorg Synaptics touchpad driver and its graphical configuration
55utilities. 67utilities.
56 68
69Note that a mouse button is also associated with either the touchpad or the
70trackpoint when a trackpoint is available. Disabling the Touchpad in xorg
71(TouchPadOff=0) will also disable the buttons associated with the touchpad.
72
57Additionally the operation of the touchpad can be altered by adjusting the 73Additionally the operation of the touchpad can be altered by adjusting the
58contents of some of its internal registers. These registers are represented 74contents of some of its internal registers. These registers are represented
59by the driver as sysfs entries under /sys/bus/serio/drivers/psmouse/serio? 75by the driver as sysfs entries under /sys/bus/serio/drivers/psmouse/serio?
@@ -78,7 +94,7 @@ completeness sake.
782. Extra knobs 942. Extra knobs
79 ~~~~~~~~~~~ 95 ~~~~~~~~~~~
80 96
81Currently the Linux Elantech touchpad driver provides two extra knobs under 97Currently the Linux Elantech touchpad driver provides three extra knobs under
82/sys/bus/serio/drivers/psmouse/serio? for the user. 98/sys/bus/serio/drivers/psmouse/serio? for the user.
83 99
84* debug 100* debug
@@ -112,6 +128,20 @@ Currently the Linux Elantech touchpad driver provides two extra knobs under
112 data consistency checking can be done. For now checking is disabled by 128 data consistency checking can be done. For now checking is disabled by
113 default. Currently even turning it on will do nothing. 129 default. Currently even turning it on will do nothing.
114 130
131* crc_enabled
132
133 Sets crc_enabled to 0/1. The name "crc_enabled" is the official name of
134 this integrity check, even though it is not an actual cyclic redundancy
135 check.
136
137 Depending on the state of crc_enabled, certain basic data integrity
138 verification is done by the driver on hardware version 3 and 4. The
139 driver will reject any packet that appears corrupted. Using this knob,
140 The state of crc_enabled can be altered with this knob.
141
142 Reading the crc_enabled value will show the active value. Echoing
143 "0" or "1" to this file will set the state to "0" or "1".
144
115///////////////////////////////////////////////////////////////////////////// 145/////////////////////////////////////////////////////////////////////////////
116 146
1173. Differentiating hardware versions 1473. Differentiating hardware versions
@@ -746,3 +776,42 @@ byte 5:
746 776
747 byte 0 ~ 2 for one finger 777 byte 0 ~ 2 for one finger
748 byte 3 ~ 5 for another 778 byte 3 ~ 5 for another
779
780
7818. Trackpoint (for Hardware version 3 and 4)
782 =========================================
7838.1 Registers
784 ~~~~~~~~~
785No special registers have been identified.
786
7878.2 Native relative mode 6 byte packet format
788 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7898.2.1 Status Packet
790 ~~~~~~~~~~~~~
791
792byte 0:
793 bit 7 6 5 4 3 2 1 0
794 0 0 sx sy 0 M R L
795byte 1:
796 bit 7 6 5 4 3 2 1 0
797 ~sx 0 0 0 0 0 0 0
798byte 2:
799 bit 7 6 5 4 3 2 1 0
800 ~sy 0 0 0 0 0 0 0
801byte 3:
802 bit 7 6 5 4 3 2 1 0
803 0 0 ~sy ~sx 0 1 1 0
804byte 4:
805 bit 7 6 5 4 3 2 1 0
806 x7 x6 x5 x4 x3 x2 x1 x0
807byte 5:
808 bit 7 6 5 4 3 2 1 0
809 y7 y6 y5 y4 y3 y2 y1 y0
810
811
812 x and y are written in two's complement spread
813 over 9 bits with sx/sy the relative top bit and
814 x7..x0 and y7..y0 the lower bits.
815 ~sx is the inverse of sx, ~sy is the inverse of sy.
816 The sign of y is opposite to what the input driver
817 expects for a relative movement
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 4c81a860cc2b..479f33204a37 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -3621,7 +3621,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
3621 3621
3622 usb-storage.delay_use= 3622 usb-storage.delay_use=
3623 [UMS] The delay in seconds before a new device is 3623 [UMS] The delay in seconds before a new device is
3624 scanned for Logical Units (default 5). 3624 scanned for Logical Units (default 1).
3625 3625
3626 usb-storage.quirks= 3626 usb-storage.quirks=
3627 [UMS] A list of quirks entries to supplement or 3627 [UMS] A list of quirks entries to supplement or
diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
index 0307e2875f21..a476b08a43e0 100644
--- a/Documentation/networking/ip-sysctl.txt
+++ b/Documentation/networking/ip-sysctl.txt
@@ -56,6 +56,13 @@ ip_forward_use_pmtu - BOOLEAN
56 0 - disabled 56 0 - disabled
57 1 - enabled 57 1 - enabled
58 58
59fwmark_reflect - BOOLEAN
60 Controls the fwmark of kernel-generated IPv4 reply packets that are not
61 associated with a socket for example, TCP RSTs or ICMP echo replies).
62 If unset, these packets have a fwmark of zero. If set, they have the
63 fwmark of the packet they are replying to.
64 Default: 0
65
59route/max_size - INTEGER 66route/max_size - INTEGER
60 Maximum number of routes allowed in the kernel. Increase 67 Maximum number of routes allowed in the kernel. Increase
61 this when using large numbers of interfaces and/or routes. 68 this when using large numbers of interfaces and/or routes.
@@ -1201,6 +1208,13 @@ conf/all/forwarding - BOOLEAN
1201proxy_ndp - BOOLEAN 1208proxy_ndp - BOOLEAN
1202 Do proxy ndp. 1209 Do proxy ndp.
1203 1210
1211fwmark_reflect - BOOLEAN
1212 Controls the fwmark of kernel-generated IPv6 reply packets that are not
1213 associated with a socket for example, TCP RSTs or ICMPv6 echo replies).
1214 If unset, these packets have a fwmark of zero. If set, they have the
1215 fwmark of the packet they are replying to.
1216 Default: 0
1217
1204conf/interface/*: 1218conf/interface/*:
1205 Change special settings per interface. 1219 Change special settings per interface.
1206 1220
diff --git a/Documentation/networking/timestamping.txt b/Documentation/networking/timestamping.txt
index 412f45ca2d73..1d6d02d6ba52 100644
--- a/Documentation/networking/timestamping.txt
+++ b/Documentation/networking/timestamping.txt
@@ -136,7 +136,7 @@ SOF_TIMESTAMPING_OPT_ID:
136 136
137 This option is implemented only for transmit timestamps. There, the 137 This option is implemented only for transmit timestamps. There, the
138 timestamp is always looped along with a struct sock_extended_err. 138 timestamp is always looped along with a struct sock_extended_err.
139 The option modifies field ee_info to pass an id that is unique 139 The option modifies field ee_data to pass an id that is unique
140 among all possibly concurrently outstanding timestamp requests for 140 among all possibly concurrently outstanding timestamp requests for
141 that socket. In practice, it is a monotonically increasing u32 141 that socket. In practice, it is a monotonically increasing u32
142 (that wraps). 142 (that wraps).
diff --git a/Documentation/nios2/README b/Documentation/nios2/README
new file mode 100644
index 000000000000..054a67d55563
--- /dev/null
+++ b/Documentation/nios2/README
@@ -0,0 +1,23 @@
1Linux on the Nios II architecture
2=================================
3
4This is a port of Linux to Nios II (nios2) processor.
5
6In order to compile for Nios II, you need a version of GCC with support for the generic
7system call ABI. Please see this link for more information on how compiling and booting
8software for the Nios II platform:
9http://www.rocketboards.org/foswiki/Documentation/NiosIILinuxUserManual
10
11For reference, please see the following link:
12http://www.altera.com/literature/lit-nio2.jsp
13
14What is Nios II?
15================
16Nios II is a 32-bit embedded-processor architecture designed specifically for the
17Altera family of FPGAs. In order to support Linux, Nios II needs to be configured
18with MMU and hardware multiplier enabled.
19
20Nios II ABI
21===========
22Please refer to chapter "Application Binary Interface" in Nios II Processor Reference
23Handbook.
diff --git a/Documentation/scsi/libsas.txt b/Documentation/scsi/libsas.txt
index 3cc9c7843e15..8cac6492aade 100644
--- a/Documentation/scsi/libsas.txt
+++ b/Documentation/scsi/libsas.txt
@@ -226,9 +226,6 @@ static int register_sas_ha(struct my_sas_ha *my_ha)
226 my_ha->sas_ha.lldd_dev_found = my_dev_found; 226 my_ha->sas_ha.lldd_dev_found = my_dev_found;
227 my_ha->sas_ha.lldd_dev_gone = my_dev_gone; 227 my_ha->sas_ha.lldd_dev_gone = my_dev_gone;
228 228
229 my_ha->sas_ha.lldd_max_execute_num = lldd_max_execute_num; (1)
230
231 my_ha->sas_ha.lldd_queue_size = ha_can_queue;
232 my_ha->sas_ha.lldd_execute_task = my_execute_task; 229 my_ha->sas_ha.lldd_execute_task = my_execute_task;
233 230
234 my_ha->sas_ha.lldd_abort_task = my_abort_task; 231 my_ha->sas_ha.lldd_abort_task = my_abort_task;
@@ -247,28 +244,6 @@ static int register_sas_ha(struct my_sas_ha *my_ha)
247 return sas_register_ha(&my_ha->sas_ha); 244 return sas_register_ha(&my_ha->sas_ha);
248} 245}
249 246
250(1) This is normally a LLDD parameter, something of the
251lines of a task collector. What it tells the SAS Layer is
252whether the SAS layer should run in Direct Mode (default:
253value 0 or 1) or Task Collector Mode (value greater than 1).
254
255In Direct Mode, the SAS Layer calls Execute Task as soon as
256it has a command to send to the SDS, _and_ this is a single
257command, i.e. not linked.
258
259Some hardware (e.g. aic94xx) has the capability to DMA more
260than one task at a time (interrupt) from host memory. Task
261Collector Mode is an optional feature for HAs which support
262this in their hardware. (Again, it is completely optional
263even if your hardware supports it.)
264
265In Task Collector Mode, the SAS Layer would do _natural_
266coalescing of tasks and at the appropriate moment it would
267call your driver to DMA more than one task in a single HA
268interrupt. DMBS may want to use this by insmod/modprobe
269setting the lldd_max_execute_num to something greater than
2701.
271
272(2) SAS 1.1 does not define I_T Nexus Reset TMF. 247(2) SAS 1.1 does not define I_T Nexus Reset TMF.
273 248
274Events 249Events
@@ -325,71 +300,22 @@ PHYE_SPINUP_HOLD -- SATA is present, COMWAKE not sent.
325 300
326The Execute Command SCSI RPC: 301The Execute Command SCSI RPC:
327 302
328 int (*lldd_execute_task)(struct sas_task *, int num, 303 int (*lldd_execute_task)(struct sas_task *, gfp_t gfp_flags);
329 unsigned long gfp_flags);
330 304
331Used to queue a task to the SAS LLDD. @task is the tasks to 305Used to queue a task to the SAS LLDD. @task is the task to be executed.
332be executed. @num should be the number of tasks being 306@gfp_mask is the gfp_mask defining the context of the caller.
333queued at this function call (they are linked listed via
334task::list), @gfp_mask should be the gfp_mask defining the
335context of the caller.
336 307
337This function should implement the Execute Command SCSI RPC, 308This function should implement the Execute Command SCSI RPC,
338or if you're sending a SCSI Task as linked commands, you
339should also use this function.
340 309
341That is, when lldd_execute_task() is called, the command(s) 310That is, when lldd_execute_task() is called, the command
342go out on the transport *immediately*. There is *no* 311go out on the transport *immediately*. There is *no*
343queuing of any sort and at any level in a SAS LLDD. 312queuing of any sort and at any level in a SAS LLDD.
344 313
345The use of task::list is two-fold, one for linked commands,
346the other discussed below.
347
348It is possible to queue up more than one task at a time, by
349initializing the list element of struct sas_task, and
350passing the number of tasks enlisted in this manner in num.
351
352Returns: -SAS_QUEUE_FULL, -ENOMEM, nothing was queued; 314Returns: -SAS_QUEUE_FULL, -ENOMEM, nothing was queued;
353 0, the task(s) were queued. 315 0, the task(s) were queued.
354 316
355If you want to pass num > 1, then either
356A) you're the only caller of this function and keep track
357 of what you've queued to the LLDD, or
358B) you know what you're doing and have a strategy of
359 retrying.
360
361As opposed to queuing one task at a time (function call),
362batch queuing of tasks, by having num > 1, greatly
363simplifies LLDD code, sequencer code, and _hardware design_,
364and has some performance advantages in certain situations
365(DBMS).
366
367The LLDD advertises if it can take more than one command at
368a time at lldd_execute_task(), by setting the
369lldd_max_execute_num parameter (controlled by "collector"
370module parameter in aic94xx SAS LLDD).
371
372You should leave this to the default 1, unless you know what
373you're doing.
374
375This is a function of the LLDD, to which the SAS layer can
376cater to.
377
378int lldd_queue_size
379 The host adapter's queue size. This is the maximum
380number of commands the lldd can have pending to domain
381devices on behalf of all upper layers submitting through
382lldd_execute_task().
383
384You really want to set this to something (much) larger than
3851.
386
387This _really_ has absolutely nothing to do with queuing.
388There is no queuing in SAS LLDDs.
389
390struct sas_task { 317struct sas_task {
391 dev -- the device this task is destined to 318 dev -- the device this task is destined to
392 list -- must be initialized (INIT_LIST_HEAD)
393 task_proto -- _one_ of enum sas_proto 319 task_proto -- _one_ of enum sas_proto
394 scatter -- pointer to scatter gather list array 320 scatter -- pointer to scatter gather list array
395 num_scatter -- number of elements in scatter 321 num_scatter -- number of elements in scatter
diff --git a/Documentation/scsi/scsi_mid_low_api.txt b/Documentation/scsi/scsi_mid_low_api.txt
index d6a9bdeee7f2..731bc4f4c5e6 100644
--- a/Documentation/scsi/scsi_mid_low_api.txt
+++ b/Documentation/scsi/scsi_mid_low_api.txt
@@ -149,7 +149,7 @@ scsi_add_host() ---->
149scsi_scan_host() -------+ 149scsi_scan_host() -------+
150 | 150 |
151 slave_alloc() 151 slave_alloc()
152 slave_configure() --> scsi_adjust_queue_depth() 152 slave_configure() --> scsi_change_queue_depth()
153 | 153 |
154 slave_alloc() 154 slave_alloc()
155 slave_configure() 155 slave_configure()
@@ -159,7 +159,7 @@ scsi_scan_host() -------+
159------------------------------------------------------------ 159------------------------------------------------------------
160 160
161If the LLD wants to adjust the default queue settings, it can invoke 161If the LLD wants to adjust the default queue settings, it can invoke
162scsi_adjust_queue_depth() in its slave_configure() routine. 162scsi_change_queue_depth() in its slave_configure() routine.
163 163
164*** For scsi devices that the mid level tries to scan but do not 164*** For scsi devices that the mid level tries to scan but do not
165 respond, a slave_alloc(), slave_destroy() pair is called. 165 respond, a slave_alloc(), slave_destroy() pair is called.
@@ -203,7 +203,7 @@ LLD mid level LLD
203scsi_add_device() ------+ 203scsi_add_device() ------+
204 | 204 |
205 slave_alloc() 205 slave_alloc()
206 slave_configure() [--> scsi_adjust_queue_depth()] 206 slave_configure() [--> scsi_change_queue_depth()]
207------------------------------------------------------------ 207------------------------------------------------------------
208 208
209In a similar fashion, an LLD may become aware that a SCSI device has been 209In a similar fashion, an LLD may become aware that a SCSI device has been
@@ -261,7 +261,7 @@ init_this_scsi_driver() ----+
261 | scsi_register() 261 | scsi_register()
262 | 262 |
263 slave_alloc() 263 slave_alloc()
264 slave_configure() --> scsi_adjust_queue_depth() 264 slave_configure() --> scsi_change_queue_depth()
265 slave_alloc() *** 265 slave_alloc() ***
266 slave_destroy() *** 266 slave_destroy() ***
267 | 267 |
@@ -271,9 +271,9 @@ init_this_scsi_driver() ----+
271 slave_destroy() *** 271 slave_destroy() ***
272------------------------------------------------------------ 272------------------------------------------------------------
273 273
274The mid level invokes scsi_adjust_queue_depth() with tagged queuing off and 274The mid level invokes scsi_change_queue_depth() with "cmd_per_lun" for that
275"cmd_per_lun" for that host as the queue length. These settings can be 275host as the queue length. These settings can be overridden by a
276overridden by a slave_configure() supplied by the LLD. 276slave_configure() supplied by the LLD.
277 277
278*** For scsi devices that the mid level tries to scan but do not 278*** For scsi devices that the mid level tries to scan but do not
279 respond, a slave_alloc(), slave_destroy() pair is called. 279 respond, a slave_alloc(), slave_destroy() pair is called.
@@ -366,13 +366,11 @@ is initialized. The functions below are listed alphabetically and their
366names all start with "scsi_". 366names all start with "scsi_".
367 367
368Summary: 368Summary:
369 scsi_activate_tcq - turn on tag command queueing
370 scsi_add_device - creates new scsi device (lu) instance 369 scsi_add_device - creates new scsi device (lu) instance
371 scsi_add_host - perform sysfs registration and set up transport class 370 scsi_add_host - perform sysfs registration and set up transport class
372 scsi_adjust_queue_depth - change the queue depth on a SCSI device 371 scsi_change_queue_depth - change the queue depth on a SCSI device
373 scsi_bios_ptable - return copy of block device's partition table 372 scsi_bios_ptable - return copy of block device's partition table
374 scsi_block_requests - prevent further commands being queued to given host 373 scsi_block_requests - prevent further commands being queued to given host
375 scsi_deactivate_tcq - turn off tag command queueing
376 scsi_host_alloc - return a new scsi_host instance whose refcount==1 374 scsi_host_alloc - return a new scsi_host instance whose refcount==1
377 scsi_host_get - increments Scsi_Host instance's refcount 375 scsi_host_get - increments Scsi_Host instance's refcount
378 scsi_host_put - decrements Scsi_Host instance's refcount (free if 0) 376 scsi_host_put - decrements Scsi_Host instance's refcount (free if 0)
@@ -390,24 +388,6 @@ Summary:
390Details: 388Details:
391 389
392/** 390/**
393 * scsi_activate_tcq - turn on tag command queueing ("ordered" task attribute)
394 * @sdev: device to turn on TCQ for
395 * @depth: queue depth
396 *
397 * Returns nothing
398 *
399 * Might block: no
400 *
401 * Notes: Eventually, it is hoped depth would be the maximum depth
402 * the device could cope with and the real queue depth
403 * would be adjustable from 0 to depth.
404 *
405 * Defined (inline) in: include/scsi/scsi_tcq.h
406 **/
407void scsi_activate_tcq(struct scsi_device *sdev, int depth)
408
409
410/**
411 * scsi_add_device - creates new scsi device (lu) instance 391 * scsi_add_device - creates new scsi device (lu) instance
412 * @shost: pointer to scsi host instance 392 * @shost: pointer to scsi host instance
413 * @channel: channel number (rarely other than 0) 393 * @channel: channel number (rarely other than 0)
@@ -456,11 +436,8 @@ int scsi_add_host(struct Scsi_Host *shost, struct device * dev)
456 436
457 437
458/** 438/**
459 * scsi_adjust_queue_depth - allow LLD to change queue depth on a SCSI device 439 * scsi_change_queue_depth - allow LLD to change queue depth on a SCSI device
460 * @sdev: pointer to SCSI device to change queue depth on 440 * @sdev: pointer to SCSI device to change queue depth on
461 * @tagged: 0 - no tagged queuing
462 * MSG_SIMPLE_TAG - simple tagged queuing
463 * MSG_ORDERED_TAG - ordered tagged queuing
464 * @tags Number of tags allowed if tagged queuing enabled, 441 * @tags Number of tags allowed if tagged queuing enabled,
465 * or number of commands the LLD can queue up 442 * or number of commands the LLD can queue up
466 * in non-tagged mode (as per cmd_per_lun). 443 * in non-tagged mode (as per cmd_per_lun).
@@ -471,15 +448,12 @@ int scsi_add_host(struct Scsi_Host *shost, struct device * dev)
471 * 448 *
472 * Notes: Can be invoked any time on a SCSI device controlled by this 449 * Notes: Can be invoked any time on a SCSI device controlled by this
473 * LLD. [Specifically during and after slave_configure() and prior to 450 * LLD. [Specifically during and after slave_configure() and prior to
474 * slave_destroy().] Can safely be invoked from interrupt code. Actual 451 * slave_destroy().] Can safely be invoked from interrupt code.
475 * queue depth change may be delayed until the next command is being
476 * processed. See also scsi_activate_tcq() and scsi_deactivate_tcq().
477 * 452 *
478 * Defined in: drivers/scsi/scsi.c [see source code for more notes] 453 * Defined in: drivers/scsi/scsi.c [see source code for more notes]
479 * 454 *
480 **/ 455 **/
481void scsi_adjust_queue_depth(struct scsi_device * sdev, int tagged, 456int scsi_change_queue_depth(struct scsi_device *sdev, int tags)
482 int tags)
483 457
484 458
485/** 459/**
@@ -515,20 +489,6 @@ void scsi_block_requests(struct Scsi_Host * shost)
515 489
516 490
517/** 491/**
518 * scsi_deactivate_tcq - turn off tag command queueing
519 * @sdev: device to turn off TCQ for
520 * @depth: queue depth (stored in sdev)
521 *
522 * Returns nothing
523 *
524 * Might block: no
525 *
526 * Defined (inline) in: include/scsi/scsi_tcq.h
527 **/
528void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)
529
530
531/**
532 * scsi_host_alloc - create a scsi host adapter instance and perform basic 492 * scsi_host_alloc - create a scsi host adapter instance and perform basic
533 * initialization. 493 * initialization.
534 * @sht: pointer to scsi host template 494 * @sht: pointer to scsi host template
@@ -1254,7 +1214,7 @@ of interest:
1254 for disk firmware uploads. 1214 for disk firmware uploads.
1255 cmd_per_lun - maximum number of commands that can be queued on devices 1215 cmd_per_lun - maximum number of commands that can be queued on devices
1256 controlled by the host. Overridden by LLD calls to 1216 controlled by the host. Overridden by LLD calls to
1257 scsi_adjust_queue_depth(). 1217 scsi_change_queue_depth().
1258 unchecked_isa_dma - 1=>only use bottom 16 MB of ram (ISA DMA addressing 1218 unchecked_isa_dma - 1=>only use bottom 16 MB of ram (ISA DMA addressing
1259 restriction), 0=>can use full 32 bit (or better) DMA 1219 restriction), 0=>can use full 32 bit (or better) DMA
1260 address space 1220 address space
@@ -1294,7 +1254,7 @@ struct scsi_cmnd
1294Instances of this structure convey SCSI commands to the LLD and responses 1254Instances of this structure convey SCSI commands to the LLD and responses
1295back to the mid level. The SCSI mid level will ensure that no more SCSI 1255back to the mid level. The SCSI mid level will ensure that no more SCSI
1296commands become queued against the LLD than are indicated by 1256commands become queued against the LLD than are indicated by
1297scsi_adjust_queue_depth() (or struct Scsi_Host::cmd_per_lun). There will 1257scsi_change_queue_depth() (or struct Scsi_Host::cmd_per_lun). There will
1298be at least one instance of struct scsi_cmnd available for each SCSI device. 1258be at least one instance of struct scsi_cmnd available for each SCSI device.
1299Members of interest: 1259Members of interest:
1300 cmnd - array containing SCSI command 1260 cmnd - array containing SCSI command
diff --git a/Documentation/scsi/st.txt b/Documentation/scsi/st.txt
index f346abbdd6ff..0d5bdb153d3b 100644
--- a/Documentation/scsi/st.txt
+++ b/Documentation/scsi/st.txt
@@ -506,9 +506,11 @@ user does not request data that far.)
506 506
507DEBUGGING HINTS 507DEBUGGING HINTS
508 508
509To enable debugging messages, edit st.c and #define DEBUG 1. As seen 509Debugging code is now compiled in by default but debugging is turned off
510above, debugging can be switched off with an ioctl if debugging is 510with the kernel module parameter debug_flag defaulting to 0. Debugging
511compiled into the driver. The debugging output is not voluminous. 511can still be switched on and off with an ioctl. To enable debug at
512module load time add debug_flag=1 to the module load options, the
513debugging output is not voluminous.
512 514
513If the tape seems to hang, I would be very interested to hear where 515If the tape seems to hang, I would be very interested to hear where
514the driver is waiting. With the command 'ps -l' you can see the state 516the driver is waiting. With the command 'ps -l' you can see the state
diff --git a/Documentation/scsi/wd719x.txt b/Documentation/scsi/wd719x.txt
new file mode 100644
index 000000000000..0816b0220238
--- /dev/null
+++ b/Documentation/scsi/wd719x.txt
@@ -0,0 +1,21 @@
1Driver for Western Digital WD7193, WD7197 and WD7296 SCSI cards
2---------------------------------------------------------------
3
4The card requires firmware that can be cut out of the Windows NT driver that
5can be downloaded from WD at:
6http://support.wdc.com/product/download.asp?groupid=801&sid=27&lang=en
7
8There is no license anywhere in the file or on the page - so the firmware
9probably cannot be added to linux-firmware.
10
11This script downloads and extracts the firmware, creating wd719x-risc.bin and
12d719x-wcs.bin files. Put them in /lib/firmware/.
13
14#!/bin/sh
15wget http://support.wdc.com/download/archive/pciscsi.exe
16lha xi pciscsi.exe pci-scsi.exe
17lha xi pci-scsi.exe nt/wd7296a.sys
18rm pci-scsi.exe
19dd if=wd7296a.sys of=wd719x-risc.bin bs=1 skip=5760 count=14336
20dd if=wd7296a.sys of=wd719x-wcs.bin bs=1 skip=20096 count=514
21rm wd7296a.sys
diff --git a/Documentation/video4linux/vivid.txt b/Documentation/video4linux/vivid.txt
index eeb11a28e4fc..e5a940e3d304 100644
--- a/Documentation/video4linux/vivid.txt
+++ b/Documentation/video4linux/vivid.txt
@@ -221,12 +221,11 @@ ccs_out_mode: specify the allowed video output crop/compose/scaling combination
221 key, not quality. 221 key, not quality.
222 222
223multiplanar: select whether each device instance supports multi-planar formats, 223multiplanar: select whether each device instance supports multi-planar formats,
224 and thus the V4L2 multi-planar API. By default the first device instance 224 and thus the V4L2 multi-planar API. By default device instances are
225 is single-planar, the second multi-planar, and it keeps alternating. 225 single-planar.
226 226
227 This module option can override that for each instance. Values are: 227 This module option can override that for each instance. Values are:
228 228
229 0: use alternating single and multi-planar devices.
230 1: this is a single-planar instance. 229 1: this is a single-planar instance.
231 2: this is a multi-planar instance. 230 2: this is a multi-planar instance.
232 231
@@ -975,9 +974,8 @@ is set, then the alpha component is only used for the color red and set to
9750 otherwise. 9740 otherwise.
976 975
977The driver has to be configured to support the multiplanar formats. By default 976The driver has to be configured to support the multiplanar formats. By default
978the first driver instance is single-planar, the second is multi-planar, and it 977the driver instances are single-planar. This can be changed by setting the
979keeps alternating. This can be changed by setting the multiplanar module option, 978multiplanar module option, see section 1 for more details on that option.
980see section 1 for more details on that option.
981 979
982If the driver instance is using the multiplanar formats/API, then the first 980If the driver instance is using the multiplanar formats/API, then the first
983single planar format (YUYV) and the multiplanar NV16M and NV61M formats the 981single planar format (YUYV) and the multiplanar NV16M and NV61M formats the
@@ -1021,7 +1019,7 @@ the output overlay for the video output, turn on video looping and capture
1021to see the blended framebuffer overlay that's being written to by the second 1019to see the blended framebuffer overlay that's being written to by the second
1022instance. This setup would require the following commands: 1020instance. This setup would require the following commands:
1023 1021
1024 $ sudo modprobe vivid n_devs=2 node_types=0x10101,0x1 multiplanar=1,1 1022 $ sudo modprobe vivid n_devs=2 node_types=0x10101,0x1
1025 $ v4l2-ctl -d1 --find-fb 1023 $ v4l2-ctl -d1 --find-fb
1026 /dev/fb1 is the framebuffer associated with base address 0x12800000 1024 /dev/fb1 is the framebuffer associated with base address 0x12800000
1027 $ sudo v4l2-ctl -d2 --set-fbuf fb=1 1025 $ sudo v4l2-ctl -d2 --set-fbuf fb=1
diff --git a/MAINTAINERS b/MAINTAINERS
index 617ed6a03341..e3a96e42193c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -861,6 +861,7 @@ W: http://maxim.org.za/at91_26.html
861W: http://www.linux4sam.org 861W: http://www.linux4sam.org
862S: Supported 862S: Supported
863F: arch/arm/mach-at91/ 863F: arch/arm/mach-at91/
864F: include/soc/at91/
864F: arch/arm/boot/dts/at91*.dts 865F: arch/arm/boot/dts/at91*.dts
865F: arch/arm/boot/dts/at91*.dtsi 866F: arch/arm/boot/dts/at91*.dtsi
866F: arch/arm/boot/dts/sama*.dts 867F: arch/arm/boot/dts/sama*.dts
@@ -1308,30 +1309,22 @@ F: drivers/*/*rockchip*
1308F: drivers/*/*/*rockchip* 1309F: drivers/*/*/*rockchip*
1309F: sound/soc/rockchip/ 1310F: sound/soc/rockchip/
1310 1311
1311ARM/SAMSUNG ARM ARCHITECTURES 1312ARM/SAMSUNG EXYNOS ARM ARCHITECTURES
1312M: Ben Dooks <ben-linux@fluff.org> 1313M: Kukjin Kim <kgene@kernel.org>
1313M: Kukjin Kim <kgene.kim@samsung.com>
1314L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1314L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1315L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers) 1315L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
1316W: http://www.fluff.org/ben/linux/
1317S: Maintained 1316S: Maintained
1318F: arch/arm/boot/dts/s3c* 1317F: arch/arm/boot/dts/s3c*
1319F: arch/arm/boot/dts/exynos* 1318F: arch/arm/boot/dts/exynos*
1320F: arch/arm/plat-samsung/ 1319F: arch/arm/plat-samsung/
1321F: arch/arm/mach-s3c24*/ 1320F: arch/arm/mach-s3c24*/
1322F: arch/arm/mach-s3c64xx/ 1321F: arch/arm/mach-s3c64xx/
1322F: arch/arm/mach-s5p*/
1323F: arch/arm/mach-exynos*/
1323F: drivers/*/*s3c2410* 1324F: drivers/*/*s3c2410*
1324F: drivers/*/*/*s3c2410* 1325F: drivers/*/*/*s3c2410*
1325F: drivers/spi/spi-s3c* 1326F: drivers/spi/spi-s3c*
1326F: sound/soc/samsung/* 1327F: sound/soc/samsung/*
1327
1328ARM/S5P EXYNOS ARM ARCHITECTURES
1329M: Kukjin Kim <kgene.kim@samsung.com>
1330L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1331L: linux-samsung-soc@vger.kernel.org (moderated for non-subscribers)
1332S: Maintained
1333F: arch/arm/mach-s5p*/
1334F: arch/arm/mach-exynos*/
1335N: exynos 1328N: exynos
1336 1329
1337ARM/SAMSUNG MOBILE MACHINE SUPPORT 1330ARM/SAMSUNG MOBILE MACHINE SUPPORT
@@ -1381,7 +1374,6 @@ F: arch/arm/boot/dts/sh*
1381F: arch/arm/configs/ape6evm_defconfig 1374F: arch/arm/configs/ape6evm_defconfig
1382F: arch/arm/configs/armadillo800eva_defconfig 1375F: arch/arm/configs/armadillo800eva_defconfig
1383F: arch/arm/configs/bockw_defconfig 1376F: arch/arm/configs/bockw_defconfig
1384F: arch/arm/configs/koelsch_defconfig
1385F: arch/arm/configs/kzm9g_defconfig 1377F: arch/arm/configs/kzm9g_defconfig
1386F: arch/arm/configs/lager_defconfig 1378F: arch/arm/configs/lager_defconfig
1387F: arch/arm/configs/mackerel_defconfig 1379F: arch/arm/configs/mackerel_defconfig
@@ -1431,6 +1423,7 @@ F: drivers/tty/serial/st-asc.c
1431F: drivers/usb/dwc3/dwc3-st.c 1423F: drivers/usb/dwc3/dwc3-st.c
1432F: drivers/usb/host/ehci-st.c 1424F: drivers/usb/host/ehci-st.c
1433F: drivers/usb/host/ohci-st.c 1425F: drivers/usb/host/ohci-st.c
1426F: drivers/ata/ahci_st.c
1434 1427
1435ARM/TECHNOLOGIC SYSTEMS TS7250 MACHINE SUPPORT 1428ARM/TECHNOLOGIC SYSTEMS TS7250 MACHINE SUPPORT
1436M: Lennert Buytenhek <kernel@wantstofly.org> 1429M: Lennert Buytenhek <kernel@wantstofly.org>
@@ -1504,6 +1497,19 @@ S: Maintained
1504F: drivers/clk/ux500/ 1497F: drivers/clk/ux500/
1505F: include/linux/platform_data/clk-ux500.h 1498F: include/linux/platform_data/clk-ux500.h
1506 1499
1500ARM/VERSATILE EXPRESS PLATFORM
1501M: Liviu Dudau <liviu.dudau@arm.com>
1502M: Sudeep Holla <sudeep.holla@arm.com>
1503M: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
1504L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1505S: Maintained
1506F: arch/arm/boot/dts/vexpress*
1507F: arch/arm/mach-vexpress/
1508F: */*/vexpress*
1509F: */*/*/vexpress*
1510F: drivers/clk/versatile/clk-vexpress-osc.c
1511F: drivers/clocksource/versatile.c
1512
1507ARM/VFP SUPPORT 1513ARM/VFP SUPPORT
1508M: Russell King <linux@arm.linux.org.uk> 1514M: Russell King <linux@arm.linux.org.uk>
1509L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1515L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
@@ -1544,6 +1550,7 @@ F: arch/arm/mach-pxa/include/mach/z2.h
1544 1550
1545ARM/ZYNQ ARCHITECTURE 1551ARM/ZYNQ ARCHITECTURE
1546M: Michal Simek <michal.simek@xilinx.com> 1552M: Michal Simek <michal.simek@xilinx.com>
1553R: Sören Brinkmann <soren.brinkmann@xilinx.com>
1547L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 1554L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
1548W: http://wiki.xilinx.com 1555W: http://wiki.xilinx.com
1549T: git git://git.xilinx.com/linux-xlnx.git 1556T: git git://git.xilinx.com/linux-xlnx.git
@@ -1828,7 +1835,7 @@ F: include/net/ax25.h
1828F: net/ax25/ 1835F: net/ax25/
1829 1836
1830AZ6007 DVB DRIVER 1837AZ6007 DVB DRIVER
1831M: Mauro Carvalho Chehab <m.chehab@samsung.com> 1838M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
1832L: linux-media@vger.kernel.org 1839L: linux-media@vger.kernel.org
1833W: http://linuxtv.org 1840W: http://linuxtv.org
1834T: git git://linuxtv.org/media_tree.git 1841T: git git://linuxtv.org/media_tree.git
@@ -2072,8 +2079,9 @@ F: drivers/clocksource/bcm_kona_timer.c
2072 2079
2073BROADCOM BCM2835 ARM ARCHITECTURE 2080BROADCOM BCM2835 ARM ARCHITECTURE
2074M: Stephen Warren <swarren@wwwdotorg.org> 2081M: Stephen Warren <swarren@wwwdotorg.org>
2082M: Lee Jones <lee@kernel.org>
2075L: linux-rpi-kernel@lists.infradead.org (moderated for non-subscribers) 2083L: linux-rpi-kernel@lists.infradead.org (moderated for non-subscribers)
2076T: git git://git.kernel.org/pub/scm/linux/kernel/git/swarren/linux-rpi.git 2084T: git git://git.kernel.org/pub/scm/linux/kernel/git/rpi/linux-rpi.git
2077S: Maintained 2085S: Maintained
2078N: bcm2835 2086N: bcm2835
2079 2087
@@ -2096,10 +2104,13 @@ F: arch/arm/include/debug/bcm63xx.S
2096BROADCOM BCM7XXX ARM ARCHITECTURE 2104BROADCOM BCM7XXX ARM ARCHITECTURE
2097M: Marc Carino <marc.ceeeee@gmail.com> 2105M: Marc Carino <marc.ceeeee@gmail.com>
2098M: Brian Norris <computersforpeace@gmail.com> 2106M: Brian Norris <computersforpeace@gmail.com>
2107M: Gregory Fong <gregory.0xf0@gmail.com>
2108M: Florian Fainelli <f.fainelli@gmail.com>
2099L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) 2109L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
2100S: Maintained 2110S: Maintained
2101F: arch/arm/mach-bcm/*brcmstb* 2111F: arch/arm/mach-bcm/*brcmstb*
2102F: arch/arm/boot/dts/bcm7*.dts* 2112F: arch/arm/boot/dts/bcm7*.dts*
2113F: drivers/bus/brcmstb_gisb.c
2103 2114
2104BROADCOM TG3 GIGABIT ETHERNET DRIVER 2115BROADCOM TG3 GIGABIT ETHERNET DRIVER
2105M: Prashant Sreedharan <prashant@broadcom.com> 2116M: Prashant Sreedharan <prashant@broadcom.com>
@@ -2130,6 +2141,20 @@ L: linux-scsi@vger.kernel.org
2130S: Supported 2141S: Supported
2131F: drivers/scsi/bnx2i/ 2142F: drivers/scsi/bnx2i/
2132 2143
2144BROADCOM CYGNUS/IPROC ARM ARCHITECTURE
2145M: Ray Jui <rjui@broadcom.com>
2146M: Scott Branden <sbranden@broadcom.com>
2147L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
2148L: bcm-kernel-feedback-list@broadcom.com
2149T: git git://git.github.com/brcm/linux.git
2150S: Maintained
2151N: iproc
2152N: cygnus
2153N: bcm9113*
2154N: bcm9583*
2155N: bcm583*
2156N: bcm113*
2157
2133BROADCOM KONA GPIO DRIVER 2158BROADCOM KONA GPIO DRIVER
2134M: Ray Jui <rjui@broadcom.com> 2159M: Ray Jui <rjui@broadcom.com>
2135L: bcm-kernel-feedback-list@broadcom.com 2160L: bcm-kernel-feedback-list@broadcom.com
@@ -2197,7 +2222,7 @@ F: Documentation/filesystems/btrfs.txt
2197F: fs/btrfs/ 2222F: fs/btrfs/
2198 2223
2199BTTV VIDEO4LINUX DRIVER 2224BTTV VIDEO4LINUX DRIVER
2200M: Mauro Carvalho Chehab <m.chehab@samsung.com> 2225M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2201L: linux-media@vger.kernel.org 2226L: linux-media@vger.kernel.org
2202W: http://linuxtv.org 2227W: http://linuxtv.org
2203T: git git://linuxtv.org/media_tree.git 2228T: git git://linuxtv.org/media_tree.git
@@ -2718,7 +2743,7 @@ F: drivers/media/common/cx2341x*
2718F: include/media/cx2341x* 2743F: include/media/cx2341x*
2719 2744
2720CX88 VIDEO4LINUX DRIVER 2745CX88 VIDEO4LINUX DRIVER
2721M: Mauro Carvalho Chehab <m.chehab@samsung.com> 2746M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
2722L: linux-media@vger.kernel.org 2747L: linux-media@vger.kernel.org
2723W: http://linuxtv.org 2748W: http://linuxtv.org
2724T: git git://linuxtv.org/media_tree.git 2749T: git git://linuxtv.org/media_tree.git
@@ -2743,6 +2768,13 @@ W: http://www.chelsio.com
2743S: Supported 2768S: Supported
2744F: drivers/net/ethernet/chelsio/cxgb3/ 2769F: drivers/net/ethernet/chelsio/cxgb3/
2745 2770
2771CXGB3 ISCSI DRIVER (CXGB3I)
2772M: Karen Xie <kxie@chelsio.com>
2773L: linux-scsi@vger.kernel.org
2774W: http://www.chelsio.com
2775S: Supported
2776F: drivers/scsi/cxgbi/cxgb3i
2777
2746CXGB3 IWARP RNIC DRIVER (IW_CXGB3) 2778CXGB3 IWARP RNIC DRIVER (IW_CXGB3)
2747M: Steve Wise <swise@chelsio.com> 2779M: Steve Wise <swise@chelsio.com>
2748L: linux-rdma@vger.kernel.org 2780L: linux-rdma@vger.kernel.org
@@ -2757,6 +2789,13 @@ W: http://www.chelsio.com
2757S: Supported 2789S: Supported
2758F: drivers/net/ethernet/chelsio/cxgb4/ 2790F: drivers/net/ethernet/chelsio/cxgb4/
2759 2791
2792CXGB4 ISCSI DRIVER (CXGB4I)
2793M: Karen Xie <kxie@chelsio.com>
2794L: linux-scsi@vger.kernel.org
2795W: http://www.chelsio.com
2796S: Supported
2797F: drivers/scsi/cxgbi/cxgb4i
2798
2760CXGB4 IWARP RNIC DRIVER (IW_CXGB4) 2799CXGB4 IWARP RNIC DRIVER (IW_CXGB4)
2761M: Steve Wise <swise@chelsio.com> 2800M: Steve Wise <swise@chelsio.com>
2762L: linux-rdma@vger.kernel.org 2801L: linux-rdma@vger.kernel.org
@@ -2847,11 +2886,10 @@ F: Documentation/networking/dmfe.txt
2847F: drivers/net/ethernet/dec/tulip/dmfe.c 2886F: drivers/net/ethernet/dec/tulip/dmfe.c
2848 2887
2849DC390/AM53C974 SCSI driver 2888DC390/AM53C974 SCSI driver
2850M: Kurt Garloff <garloff@suse.de> 2889M: Hannes Reinecke <hare@suse.de>
2851W: http://www.garloff.de/kurt/linux/dc390/ 2890L: linux-scsi@vger.kernel.org
2852M: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
2853S: Maintained 2891S: Maintained
2854F: drivers/scsi/tmscsim.* 2892F: drivers/scsi/am53c974.c
2855 2893
2856DC395x SCSI driver 2894DC395x SCSI driver
2857M: Oliver Neukum <oliver@neukum.org> 2895M: Oliver Neukum <oliver@neukum.org>
@@ -3387,7 +3425,7 @@ F: fs/ecryptfs/
3387EDAC-CORE 3425EDAC-CORE
3388M: Doug Thompson <dougthompson@xmission.com> 3426M: Doug Thompson <dougthompson@xmission.com>
3389M: Borislav Petkov <bp@alien8.de> 3427M: Borislav Petkov <bp@alien8.de>
3390M: Mauro Carvalho Chehab <m.chehab@samsung.com> 3428M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3391L: linux-edac@vger.kernel.org 3429L: linux-edac@vger.kernel.org
3392W: bluesmoke.sourceforge.net 3430W: bluesmoke.sourceforge.net
3393S: Supported 3431S: Supported
@@ -3436,7 +3474,7 @@ S: Maintained
3436F: drivers/edac/e7xxx_edac.c 3474F: drivers/edac/e7xxx_edac.c
3437 3475
3438EDAC-GHES 3476EDAC-GHES
3439M: Mauro Carvalho Chehab <m.chehab@samsung.com> 3477M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3440L: linux-edac@vger.kernel.org 3478L: linux-edac@vger.kernel.org
3441W: bluesmoke.sourceforge.net 3479W: bluesmoke.sourceforge.net
3442S: Maintained 3480S: Maintained
@@ -3464,21 +3502,21 @@ S: Maintained
3464F: drivers/edac/i5000_edac.c 3502F: drivers/edac/i5000_edac.c
3465 3503
3466EDAC-I5400 3504EDAC-I5400
3467M: Mauro Carvalho Chehab <m.chehab@samsung.com> 3505M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3468L: linux-edac@vger.kernel.org 3506L: linux-edac@vger.kernel.org
3469W: bluesmoke.sourceforge.net 3507W: bluesmoke.sourceforge.net
3470S: Maintained 3508S: Maintained
3471F: drivers/edac/i5400_edac.c 3509F: drivers/edac/i5400_edac.c
3472 3510
3473EDAC-I7300 3511EDAC-I7300
3474M: Mauro Carvalho Chehab <m.chehab@samsung.com> 3512M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3475L: linux-edac@vger.kernel.org 3513L: linux-edac@vger.kernel.org
3476W: bluesmoke.sourceforge.net 3514W: bluesmoke.sourceforge.net
3477S: Maintained 3515S: Maintained
3478F: drivers/edac/i7300_edac.c 3516F: drivers/edac/i7300_edac.c
3479 3517
3480EDAC-I7CORE 3518EDAC-I7CORE
3481M: Mauro Carvalho Chehab <m.chehab@samsung.com> 3519M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3482L: linux-edac@vger.kernel.org 3520L: linux-edac@vger.kernel.org
3483W: bluesmoke.sourceforge.net 3521W: bluesmoke.sourceforge.net
3484S: Maintained 3522S: Maintained
@@ -3521,7 +3559,7 @@ S: Maintained
3521F: drivers/edac/r82600_edac.c 3559F: drivers/edac/r82600_edac.c
3522 3560
3523EDAC-SBRIDGE 3561EDAC-SBRIDGE
3524M: Mauro Carvalho Chehab <m.chehab@samsung.com> 3562M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3525L: linux-edac@vger.kernel.org 3563L: linux-edac@vger.kernel.org
3526W: bluesmoke.sourceforge.net 3564W: bluesmoke.sourceforge.net
3527S: Maintained 3565S: Maintained
@@ -3581,7 +3619,7 @@ S: Maintained
3581F: drivers/net/ethernet/ibm/ehea/ 3619F: drivers/net/ethernet/ibm/ehea/
3582 3620
3583EM28XX VIDEO4LINUX DRIVER 3621EM28XX VIDEO4LINUX DRIVER
3584M: Mauro Carvalho Chehab <m.chehab@samsung.com> 3622M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
3585L: linux-media@vger.kernel.org 3623L: linux-media@vger.kernel.org
3586W: http://linuxtv.org 3624W: http://linuxtv.org
3587T: git git://linuxtv.org/media_tree.git 3625T: git git://linuxtv.org/media_tree.git
@@ -4715,6 +4753,7 @@ L: linux-iio@vger.kernel.org
4715S: Maintained 4753S: Maintained
4716F: drivers/iio/ 4754F: drivers/iio/
4717F: drivers/staging/iio/ 4755F: drivers/staging/iio/
4756F: include/linux/iio/
4718 4757
4719IKANOS/ADI EAGLE ADSL USB DRIVER 4758IKANOS/ADI EAGLE ADSL USB DRIVER
4720M: Matthieu Castet <castet.matthieu@free.fr> 4759M: Matthieu Castet <castet.matthieu@free.fr>
@@ -5946,7 +5985,7 @@ S: Maintained
5946F: drivers/media/radio/radio-maxiradio* 5985F: drivers/media/radio/radio-maxiradio*
5947 5986
5948MEDIA INPUT INFRASTRUCTURE (V4L/DVB) 5987MEDIA INPUT INFRASTRUCTURE (V4L/DVB)
5949M: Mauro Carvalho Chehab <m.chehab@samsung.com> 5988M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
5950P: LinuxTV.org Project 5989P: LinuxTV.org Project
5951L: linux-media@vger.kernel.org 5990L: linux-media@vger.kernel.org
5952W: http://linuxtv.org 5991W: http://linuxtv.org
@@ -5975,10 +6014,13 @@ W: http://linuxtv.org
5975S: Odd Fixes 6014S: Odd Fixes
5976F: drivers/media/parport/pms* 6015F: drivers/media/parport/pms*
5977 6016
5978MEGARAID SCSI DRIVERS 6017MEGARAID SCSI/SAS DRIVERS
5979M: Neela Syam Kolli <megaraidlinux@lsi.com> 6018M: Kashyap Desai <kashyap.desai@avagotech.com>
6019M: Sumit Saxena <sumit.saxena@avagotech.com>
6020M: Uday Lingala <uday.lingala@avagotech.com>
6021L: megaraidlinux.pdl@avagotech.com
5980L: linux-scsi@vger.kernel.org 6022L: linux-scsi@vger.kernel.org
5981W: http://megaraid.lsilogic.com 6023W: http://www.lsi.com
5982S: Maintained 6024S: Maintained
5983F: Documentation/scsi/megaraid.txt 6025F: Documentation/scsi/megaraid.txt
5984F: drivers/scsi/megaraid.* 6026F: drivers/scsi/megaraid.*
@@ -6289,7 +6331,6 @@ F: drivers/scsi/g_NCR5380.*
6289F: drivers/scsi/g_NCR5380_mmio.c 6331F: drivers/scsi/g_NCR5380_mmio.c
6290F: drivers/scsi/mac_scsi.* 6332F: drivers/scsi/mac_scsi.*
6291F: drivers/scsi/pas16.* 6333F: drivers/scsi/pas16.*
6292F: drivers/scsi/sun3_NCR5380.c
6293F: drivers/scsi/sun3_scsi.* 6334F: drivers/scsi/sun3_scsi.*
6294F: drivers/scsi/sun3_scsi_vme.c 6335F: drivers/scsi/sun3_scsi_vme.c
6295F: drivers/scsi/t128.* 6336F: drivers/scsi/t128.*
@@ -6545,6 +6586,13 @@ S: Maintained
6545F: Documentation/scsi/NinjaSCSI.txt 6586F: Documentation/scsi/NinjaSCSI.txt
6546F: drivers/scsi/nsp32* 6587F: drivers/scsi/nsp32*
6547 6588
6589NIOS2 ARCHITECTURE
6590M: Ley Foon Tan <lftan@altera.com>
6591L: nios2-dev@lists.rocketboards.org (moderated for non-subscribers)
6592T: git git://git.rocketboards.org/linux-socfpga.git
6593S: Maintained
6594F: arch/nios2/
6595
6548NTB DRIVER 6596NTB DRIVER
6549M: Jon Mason <jdmason@kudzu.us> 6597M: Jon Mason <jdmason@kudzu.us>
6550M: Dave Jiang <dave.jiang@intel.com> 6598M: Dave Jiang <dave.jiang@intel.com>
@@ -6595,6 +6643,23 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/tmlind/linux-omap.git
6595S: Maintained 6643S: Maintained
6596F: arch/arm/*omap*/ 6644F: arch/arm/*omap*/
6597F: drivers/i2c/busses/i2c-omap.c 6645F: drivers/i2c/busses/i2c-omap.c
6646F: drivers/irqchip/irq-omap-intc.c
6647F: drivers/mfd/*omap*.c
6648F: drivers/mfd/menelaus.c
6649F: drivers/mfd/palmas.c
6650F: drivers/mfd/tps65217.c
6651F: drivers/mfd/tps65218.c
6652F: drivers/mfd/tps65910.c
6653F: drivers/mfd/twl-core.[ch]
6654F: drivers/mfd/twl4030*.c
6655F: drivers/mfd/twl6030*.c
6656F: drivers/mfd/twl6040*.c
6657F: drivers/regulator/palmas-regulator*.c
6658F: drivers/regulator/pbias-regulator.c
6659F: drivers/regulator/tps65217-regulator.c
6660F: drivers/regulator/tps65218-regulator.c
6661F: drivers/regulator/tps65910-regulator.c
6662F: drivers/regulator/twl-regulator.c
6598F: include/linux/i2c-omap.h 6663F: include/linux/i2c-omap.h
6599 6664
6600OMAP DEVICE TREE SUPPORT 6665OMAP DEVICE TREE SUPPORT
@@ -6605,6 +6670,9 @@ L: devicetree@vger.kernel.org
6605S: Maintained 6670S: Maintained
6606F: arch/arm/boot/dts/*omap* 6671F: arch/arm/boot/dts/*omap*
6607F: arch/arm/boot/dts/*am3* 6672F: arch/arm/boot/dts/*am3*
6673F: arch/arm/boot/dts/*am4*
6674F: arch/arm/boot/dts/*am5*
6675F: arch/arm/boot/dts/*dra7*
6608 6676
6609OMAP CLOCK FRAMEWORK SUPPORT 6677OMAP CLOCK FRAMEWORK SUPPORT
6610M: Paul Walmsley <paul@pwsan.com> 6678M: Paul Walmsley <paul@pwsan.com>
@@ -6852,11 +6920,12 @@ F: drivers/scsi/osd/
6852F: include/scsi/osd_* 6920F: include/scsi/osd_*
6853F: fs/exofs/ 6921F: fs/exofs/
6854 6922
6855OVERLAYFS FILESYSTEM 6923OVERLAY FILESYSTEM
6856M: Miklos Szeredi <miklos@szeredi.hu> 6924M: Miklos Szeredi <miklos@szeredi.hu>
6857L: linux-fsdevel@vger.kernel.org 6925L: linux-unionfs@vger.kernel.org
6926T: git git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git
6858S: Supported 6927S: Supported
6859F: fs/overlayfs/* 6928F: fs/overlayfs/
6860F: Documentation/filesystems/overlayfs.txt 6929F: Documentation/filesystems/overlayfs.txt
6861 6930
6862P54 WIRELESS DRIVER 6931P54 WIRELESS DRIVER
@@ -7180,6 +7249,7 @@ F: drivers/crypto/picoxcell*
7180 7249
7181PIN CONTROL SUBSYSTEM 7250PIN CONTROL SUBSYSTEM
7182M: Linus Walleij <linus.walleij@linaro.org> 7251M: Linus Walleij <linus.walleij@linaro.org>
7252L: linux-gpio@vger.kernel.org
7183S: Maintained 7253S: Maintained
7184F: drivers/pinctrl/ 7254F: drivers/pinctrl/
7185F: include/linux/pinctrl/ 7255F: include/linux/pinctrl/
@@ -7975,7 +8045,7 @@ S: Odd Fixes
7975F: drivers/media/i2c/saa6588* 8045F: drivers/media/i2c/saa6588*
7976 8046
7977SAA7134 VIDEO4LINUX DRIVER 8047SAA7134 VIDEO4LINUX DRIVER
7978M: Mauro Carvalho Chehab <m.chehab@samsung.com> 8048M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
7979L: linux-media@vger.kernel.org 8049L: linux-media@vger.kernel.org
7980W: http://linuxtv.org 8050W: http://linuxtv.org
7981T: git git://linuxtv.org/media_tree.git 8051T: git git://linuxtv.org/media_tree.git
@@ -8433,7 +8503,7 @@ S: Maintained
8433F: drivers/media/radio/si4713/radio-usb-si4713.c 8503F: drivers/media/radio/si4713/radio-usb-si4713.c
8434 8504
8435SIANO DVB DRIVER 8505SIANO DVB DRIVER
8436M: Mauro Carvalho Chehab <m.chehab@samsung.com> 8506M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
8437L: linux-media@vger.kernel.org 8507L: linux-media@vger.kernel.org
8438W: http://linuxtv.org 8508W: http://linuxtv.org
8439T: git git://linuxtv.org/media_tree.git 8509T: git git://linuxtv.org/media_tree.git
@@ -8484,7 +8554,6 @@ F: arch/arm/mach-s3c24xx/bast-irq.c
8484TI DAVINCI MACHINE SUPPORT 8554TI DAVINCI MACHINE SUPPORT
8485M: Sekhar Nori <nsekhar@ti.com> 8555M: Sekhar Nori <nsekhar@ti.com>
8486M: Kevin Hilman <khilman@deeprootsystems.com> 8556M: Kevin Hilman <khilman@deeprootsystems.com>
8487L: davinci-linux-open-source@linux.davincidsp.com (moderated for non-subscribers)
8488T: git git://gitorious.org/linux-davinci/linux-davinci.git 8557T: git git://gitorious.org/linux-davinci/linux-davinci.git
8489Q: http://patchwork.kernel.org/project/linux-davinci/list/ 8558Q: http://patchwork.kernel.org/project/linux-davinci/list/
8490S: Supported 8559S: Supported
@@ -8494,7 +8563,6 @@ F: drivers/i2c/busses/i2c-davinci.c
8494TI DAVINCI SERIES MEDIA DRIVER 8563TI DAVINCI SERIES MEDIA DRIVER
8495M: Lad, Prabhakar <prabhakar.csengg@gmail.com> 8564M: Lad, Prabhakar <prabhakar.csengg@gmail.com>
8496L: linux-media@vger.kernel.org 8565L: linux-media@vger.kernel.org
8497L: davinci-linux-open-source@linux.davincidsp.com (moderated for non-subscribers)
8498W: http://linuxtv.org/ 8566W: http://linuxtv.org/
8499Q: http://patchwork.linuxtv.org/project/linux-media/list/ 8567Q: http://patchwork.linuxtv.org/project/linux-media/list/
8500T: git git://linuxtv.org/mhadli/v4l-dvb-davinci_devices.git 8568T: git git://linuxtv.org/mhadli/v4l-dvb-davinci_devices.git
@@ -8646,7 +8714,9 @@ S: Maintained
8646F: drivers/leds/leds-net48xx.c 8714F: drivers/leds/leds-net48xx.c
8647 8715
8648SOFTLOGIC 6x10 MPEG CODEC 8716SOFTLOGIC 6x10 MPEG CODEC
8649M: Ismael Luceno <ismael.luceno@corp.bluecherry.net> 8717M: Bluecherry Maintainers <maintainers@bluecherrydvr.com>
8718M: Andrey Utkin <andrey.utkin@corp.bluecherry.net>
8719M: Andrey Utkin <andrey.krieger.utkin@gmail.com>
8650L: linux-media@vger.kernel.org 8720L: linux-media@vger.kernel.org
8651S: Supported 8721S: Supported
8652F: drivers/media/pci/solo6x10/ 8722F: drivers/media/pci/solo6x10/
@@ -9120,7 +9190,7 @@ S: Maintained
9120F: drivers/media/i2c/tda9840* 9190F: drivers/media/i2c/tda9840*
9121 9191
9122TEA5761 TUNER DRIVER 9192TEA5761 TUNER DRIVER
9123M: Mauro Carvalho Chehab <m.chehab@samsung.com> 9193M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
9124L: linux-media@vger.kernel.org 9194L: linux-media@vger.kernel.org
9125W: http://linuxtv.org 9195W: http://linuxtv.org
9126T: git git://linuxtv.org/media_tree.git 9196T: git git://linuxtv.org/media_tree.git
@@ -9128,7 +9198,7 @@ S: Odd fixes
9128F: drivers/media/tuners/tea5761.* 9198F: drivers/media/tuners/tea5761.*
9129 9199
9130TEA5767 TUNER DRIVER 9200TEA5767 TUNER DRIVER
9131M: Mauro Carvalho Chehab <m.chehab@samsung.com> 9201M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
9132L: linux-media@vger.kernel.org 9202L: linux-media@vger.kernel.org
9133W: http://linuxtv.org 9203W: http://linuxtv.org
9134T: git git://linuxtv.org/media_tree.git 9204T: git git://linuxtv.org/media_tree.git
@@ -9440,7 +9510,7 @@ F: include/linux/shmem_fs.h
9440F: mm/shmem.c 9510F: mm/shmem.c
9441 9511
9442TM6000 VIDEO4LINUX DRIVER 9512TM6000 VIDEO4LINUX DRIVER
9443M: Mauro Carvalho Chehab <m.chehab@samsung.com> 9513M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
9444L: linux-media@vger.kernel.org 9514L: linux-media@vger.kernel.org
9445W: http://linuxtv.org 9515W: http://linuxtv.org
9446T: git git://linuxtv.org/media_tree.git 9516T: git git://linuxtv.org/media_tree.git
@@ -9704,11 +9774,6 @@ S: Maintained
9704F: Documentation/hid/hiddev.txt 9774F: Documentation/hid/hiddev.txt
9705F: drivers/hid/usbhid/ 9775F: drivers/hid/usbhid/
9706 9776
9707USB/IP DRIVERS
9708L: linux-usb@vger.kernel.org
9709S: Orphan
9710F: drivers/staging/usbip/
9711
9712USB ISP116X DRIVER 9777USB ISP116X DRIVER
9713M: Olav Kongas <ok@artecdesign.ee> 9778M: Olav Kongas <ok@artecdesign.ee>
9714L: linux-usb@vger.kernel.org 9779L: linux-usb@vger.kernel.org
@@ -10266,7 +10331,7 @@ S: Maintained
10266F: arch/x86/kernel/cpu/mcheck/* 10331F: arch/x86/kernel/cpu/mcheck/*
10267 10332
10268XC2028/3028 TUNER DRIVER 10333XC2028/3028 TUNER DRIVER
10269M: Mauro Carvalho Chehab <m.chehab@samsung.com> 10334M: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
10270L: linux-media@vger.kernel.org 10335L: linux-media@vger.kernel.org
10271W: http://linuxtv.org 10336W: http://linuxtv.org
10272T: git git://linuxtv.org/media_tree.git 10337T: git git://linuxtv.org/media_tree.git
diff --git a/Makefile b/Makefile
index ffc1ce2b0345..fd80c6e9bc23 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
1VERSION = 3 1VERSION = 3
2PATCHLEVEL = 18 2PATCHLEVEL = 18
3SUBLEVEL = 0 3SUBLEVEL = 0
4EXTRAVERSION = -rc3 4EXTRAVERSION =
5NAME = Diseased Newt 5NAME = Diseased Newt
6 6
7# *DOCUMENTATION* 7# *DOCUMENTATION*
@@ -297,7 +297,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
297 297
298HOSTCC = gcc 298HOSTCC = gcc
299HOSTCXX = g++ 299HOSTCXX = g++
300HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer 300HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
301HOSTCXXFLAGS = -O2 301HOSTCXXFLAGS = -O2
302 302
303ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1) 303ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
@@ -401,7 +401,8 @@ KBUILD_CPPFLAGS := -D__KERNEL__
401KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ 401KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
402 -fno-strict-aliasing -fno-common \ 402 -fno-strict-aliasing -fno-common \
403 -Werror-implicit-function-declaration \ 403 -Werror-implicit-function-declaration \
404 -Wno-format-security 404 -Wno-format-security \
405 -std=gnu89
405 406
406KBUILD_AFLAGS_KERNEL := 407KBUILD_AFLAGS_KERNEL :=
407KBUILD_CFLAGS_KERNEL := 408KBUILD_CFLAGS_KERNEL :=
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index b9bde0c337b1..8db9dc07f8ac 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -332,6 +332,7 @@ config ARCH_REALVIEW
332 select ICST 332 select ICST
333 select NEED_MACH_MEMORY_H 333 select NEED_MACH_MEMORY_H
334 select PLAT_VERSATILE 334 select PLAT_VERSATILE
335 select PLAT_VERSATILE_SCHED_CLOCK
335 help 336 help
336 This enables support for ARM Ltd RealView boards. 337 This enables support for ARM Ltd RealView boards.
337 338
@@ -347,6 +348,7 @@ config ARCH_VERSATILE
347 select ICST 348 select ICST
348 select PLAT_VERSATILE 349 select PLAT_VERSATILE
349 select PLAT_VERSATILE_CLOCK 350 select PLAT_VERSATILE_CLOCK
351 select PLAT_VERSATILE_SCHED_CLOCK
350 select VERSATILE_FPGA_IRQ 352 select VERSATILE_FPGA_IRQ
351 help 353 help
352 This enables support for ARM Ltd Versatile board. 354 This enables support for ARM Ltd Versatile board.
@@ -358,10 +360,11 @@ config ARCH_AT91
358 select IRQ_DOMAIN 360 select IRQ_DOMAIN
359 select NEED_MACH_IO_H if PCCARD 361 select NEED_MACH_IO_H if PCCARD
360 select PINCTRL 362 select PINCTRL
361 select PINCTRL_AT91 if USE_OF 363 select PINCTRL_AT91
364 select USE_OF
362 help 365 help
363 This enables support for systems based on Atmel 366 This enables support for systems based on Atmel
364 AT91RM9200 and AT91SAM9* processors. 367 AT91RM9200, AT91SAM9 and SAMA5 processors.
365 368
366config ARCH_CLPS711X 369config ARCH_CLPS711X
367 bool "Cirrus Logic CLPS711x/EP721x/EP731x-based" 370 bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
diff --git a/arch/arm/Kconfig.debug b/arch/arm/Kconfig.debug
index 66ebfb88c505..f9295a4e1036 100644
--- a/arch/arm/Kconfig.debug
+++ b/arch/arm/Kconfig.debug
@@ -1339,7 +1339,7 @@ config DEBUG_UART_VIRT
1339 default 0xf1c28000 if DEBUG_SUNXI_UART0 1339 default 0xf1c28000 if DEBUG_SUNXI_UART0
1340 default 0xf1c28400 if DEBUG_SUNXI_UART1 1340 default 0xf1c28400 if DEBUG_SUNXI_UART1
1341 default 0xf1f02800 if DEBUG_SUNXI_R_UART 1341 default 0xf1f02800 if DEBUG_SUNXI_R_UART
1342 default 0xf2100000 if DEBUG_PXA_UART1 1342 default 0xf6200000 if DEBUG_PXA_UART1
1343 default 0xf4090000 if ARCH_LPC32XX 1343 default 0xf4090000 if ARCH_LPC32XX
1344 default 0xf4200000 if ARCH_GEMINI 1344 default 0xf4200000 if ARCH_GEMINI
1345 default 0xf7000000 if DEBUG_SUN9I_UART0 1345 default 0xf7000000 if DEBUG_SUN9I_UART0
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 034a94904d69..c1785eec2cf7 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -312,8 +312,12 @@ $(INSTALL_TARGETS):
312 $(Q)$(MAKE) $(build)=$(boot)/dts MACHINE=$(MACHINE) $(boot)/dts/$@ 312 $(Q)$(MAKE) $(build)=$(boot)/dts MACHINE=$(MACHINE) $(boot)/dts/$@
313 313
314PHONY += dtbs dtbs_install 314PHONY += dtbs dtbs_install
315dtbs dtbs_install: prepare scripts 315
316 $(Q)$(MAKE) $(build)=$(boot)/dts MACHINE=$(MACHINE) $@ 316dtbs: prepare scripts
317 $(Q)$(MAKE) $(build)=$(boot)/dts
318
319dtbs_install:
320 $(Q)$(MAKE) $(dtbinst)=$(boot)/dts
317 321
318# We use MRPROPER_FILES and CLEAN_FILES now 322# We use MRPROPER_FILES and CLEAN_FILES now
319archclean: 323archclean:
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 413fd94b5301..68be9017593d 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -397,8 +397,7 @@ dtb_check_done:
397 add sp, sp, r6 397 add sp, sp, r6
398#endif 398#endif
399 399
400 tst r4, #1 400 bl cache_clean_flush
401 bleq cache_clean_flush
402 401
403 adr r0, BSYM(restart) 402 adr r0, BSYM(restart)
404 add r0, r0, r6 403 add r0, r0, r6
@@ -1047,6 +1046,8 @@ cache_clean_flush:
1047 b call_cache_fn 1046 b call_cache_fn
1048 1047
1049__armv4_mpu_cache_flush: 1048__armv4_mpu_cache_flush:
1049 tst r4, #1
1050 movne pc, lr
1050 mov r2, #1 1051 mov r2, #1
1051 mov r3, #0 1052 mov r3, #0
1052 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache 1053 mcr p15, 0, ip, c7, c6, 0 @ invalidate D cache
@@ -1064,6 +1065,8 @@ __armv4_mpu_cache_flush:
1064 mov pc, lr 1065 mov pc, lr
1065 1066
1066__fa526_cache_flush: 1067__fa526_cache_flush:
1068 tst r4, #1
1069 movne pc, lr
1067 mov r1, #0 1070 mov r1, #0
1068 mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache 1071 mcr p15, 0, r1, c7, c14, 0 @ clean and invalidate D cache
1069 mcr p15, 0, r1, c7, c5, 0 @ flush I cache 1072 mcr p15, 0, r1, c7, c5, 0 @ flush I cache
@@ -1072,13 +1075,16 @@ __fa526_cache_flush:
1072 1075
1073__armv6_mmu_cache_flush: 1076__armv6_mmu_cache_flush:
1074 mov r1, #0 1077 mov r1, #0
1075 mcr p15, 0, r1, c7, c14, 0 @ clean+invalidate D 1078 tst r4, #1
1079 mcreq p15, 0, r1, c7, c14, 0 @ clean+invalidate D
1076 mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB 1080 mcr p15, 0, r1, c7, c5, 0 @ invalidate I+BTB
1077 mcr p15, 0, r1, c7, c15, 0 @ clean+invalidate unified 1081 mcreq p15, 0, r1, c7, c15, 0 @ clean+invalidate unified
1078 mcr p15, 0, r1, c7, c10, 4 @ drain WB 1082 mcr p15, 0, r1, c7, c10, 4 @ drain WB
1079 mov pc, lr 1083 mov pc, lr
1080 1084
1081__armv7_mmu_cache_flush: 1085__armv7_mmu_cache_flush:
1086 tst r4, #1
1087 bne iflush
1082 mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1 1088 mrc p15, 0, r10, c0, c1, 5 @ read ID_MMFR1
1083 tst r10, #0xf << 16 @ hierarchical cache (ARMv7) 1089 tst r10, #0xf << 16 @ hierarchical cache (ARMv7)
1084 mov r10, #0 1090 mov r10, #0
@@ -1139,6 +1145,8 @@ iflush:
1139 mov pc, lr 1145 mov pc, lr
1140 1146
1141__armv5tej_mmu_cache_flush: 1147__armv5tej_mmu_cache_flush:
1148 tst r4, #1
1149 movne pc, lr
11421: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache 11501: mrc p15, 0, r15, c7, c14, 3 @ test,clean,invalidate D cache
1143 bne 1b 1151 bne 1b
1144 mcr p15, 0, r0, c7, c5, 0 @ flush I cache 1152 mcr p15, 0, r0, c7, c5, 0 @ flush I cache
@@ -1146,6 +1154,8 @@ __armv5tej_mmu_cache_flush:
1146 mov pc, lr 1154 mov pc, lr
1147 1155
1148__armv4_mmu_cache_flush: 1156__armv4_mmu_cache_flush:
1157 tst r4, #1
1158 movne pc, lr
1149 mov r2, #64*1024 @ default: 32K dcache size (*2) 1159 mov r2, #64*1024 @ default: 32K dcache size (*2)
1150 mov r11, #32 @ default: 32 byte line size 1160 mov r11, #32 @ default: 32 byte line size
1151 mrc p15, 0, r3, c0, c0, 1 @ read cache type 1161 mrc p15, 0, r3, c0, c0, 1 @ read cache type
@@ -1179,6 +1189,8 @@ no_cache_id:
1179 1189
1180__armv3_mmu_cache_flush: 1190__armv3_mmu_cache_flush:
1181__armv3_mpu_cache_flush: 1191__armv3_mpu_cache_flush:
1192 tst r4, #1
1193 movne pc, lr
1182 mov r1, #0 1194 mov r1, #0
1183 mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3 1195 mcr p15, 0, r1, c7, c0, 0 @ invalidate whole cache v3
1184 mov pc, lr 1196 mov pc, lr
diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index 38c89cafa1ab..fe92f5df9d3c 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -376,25 +376,24 @@ dtb-$(CONFIG_ARCH_S5PV210) += s5pv210-aquila.dtb \
376 s5pv210-smdkc110.dtb \ 376 s5pv210-smdkc110.dtb \
377 s5pv210-smdkv210.dtb \ 377 s5pv210-smdkv210.dtb \
378 s5pv210-torbreck.dtb 378 s5pv210-torbreck.dtb
379dtb-$(CONFIG_ARCH_SHMOBILE_LEGACY) += r7s72100-genmai.dtb \ 379dtb-$(CONFIG_ARCH_SHMOBILE_LEGACY) += \
380 r8a73a4-ape6evm.dtb \
381 r8a73a4-ape6evm-reference.dtb \
380 r8a7740-armadillo800eva.dtb \ 382 r8a7740-armadillo800eva.dtb \
381 r8a7778-bockw.dtb \ 383 r8a7778-bockw.dtb \
382 r8a7778-bockw-reference.dtb \ 384 r8a7778-bockw-reference.dtb \
383 r8a7779-marzen.dtb \ 385 r8a7779-marzen.dtb \
384 r8a7791-koelsch.dtb \
385 r8a7790-lager.dtb \ 386 r8a7790-lager.dtb \
387 sh7372-mackerel.dtb \
386 sh73a0-kzm9g.dtb \ 388 sh73a0-kzm9g.dtb \
387 sh73a0-kzm9g-reference.dtb \ 389 sh73a0-kzm9g-reference.dtb
388 r8a73a4-ape6evm.dtb \
389 r8a73a4-ape6evm-reference.dtb \
390 sh7372-mackerel.dtb
391dtb-$(CONFIG_ARCH_SHMOBILE_MULTI) += emev2-kzm9d.dtb \ 390dtb-$(CONFIG_ARCH_SHMOBILE_MULTI) += emev2-kzm9d.dtb \
392 r7s72100-genmai.dtb \ 391 r7s72100-genmai.dtb \
393 r8a7740-armadillo800eva.dtb \ 392 r8a7740-armadillo800eva.dtb \
393 r8a7779-marzen.dtb \
394 r8a7790-lager.dtb \
394 r8a7791-henninger.dtb \ 395 r8a7791-henninger.dtb \
395 r8a7791-koelsch.dtb \ 396 r8a7791-koelsch.dtb \
396 r8a7790-lager.dtb \
397 r8a7779-marzen.dtb \
398 r8a7794-alt.dtb 397 r8a7794-alt.dtb
399dtb-$(CONFIG_ARCH_SOCFPGA) += socfpga_arria5_socdk.dtb \ 398dtb-$(CONFIG_ARCH_SOCFPGA) += socfpga_arria5_socdk.dtb \
400 socfpga_cyclone5_socdk.dtb \ 399 socfpga_cyclone5_socdk.dtb \
@@ -517,15 +516,7 @@ dtb-$(CONFIG_MACH_DOVE) += dove-cm-a510.dtb \
517 dove-dove-db.dtb 516 dove-dove-db.dtb
518dtb-$(CONFIG_ARCH_MEDIATEK) += mt6589-aquaris5.dtb 517dtb-$(CONFIG_ARCH_MEDIATEK) += mt6589-aquaris5.dtb
519 518
520targets += dtbs dtbs_install
521targets += $(dtb-y)
522endif 519endif
523 520
524# *.dtb used to be generated in the directory above. Clean out the 521always := $(dtb-y)
525# old build results so people don't accidentally use them. 522clean-files := *.dtb
526dtbs: $(addprefix $(obj)/, $(dtb-y))
527 $(Q)rm -f $(obj)/../*.dtb
528
529clean-files := *.dtb
530
531dtbs_install: $(addsuffix _dtbinst_, $(dtb-y))
diff --git a/arch/arm/boot/dts/am335x-evm.dts b/arch/arm/boot/dts/am335x-evm.dts
index e2156a583de7..c4b968f0feb5 100644
--- a/arch/arm/boot/dts/am335x-evm.dts
+++ b/arch/arm/boot/dts/am335x-evm.dts
@@ -489,7 +489,7 @@
489 reg = <0x00060000 0x00020000>; 489 reg = <0x00060000 0x00020000>;
490 }; 490 };
491 partition@4 { 491 partition@4 {
492 label = "NAND.u-boot-spl"; 492 label = "NAND.u-boot-spl-os";
493 reg = <0x00080000 0x00040000>; 493 reg = <0x00080000 0x00040000>;
494 }; 494 };
495 partition@5 { 495 partition@5 {
diff --git a/arch/arm/boot/dts/am437x-gp-evm.dts b/arch/arm/boot/dts/am437x-gp-evm.dts
index e7ac47fa6615..a521ac0a7d5a 100644
--- a/arch/arm/boot/dts/am437x-gp-evm.dts
+++ b/arch/arm/boot/dts/am437x-gp-evm.dts
@@ -291,8 +291,8 @@
291 dcdc3: regulator-dcdc3 { 291 dcdc3: regulator-dcdc3 {
292 compatible = "ti,tps65218-dcdc3"; 292 compatible = "ti,tps65218-dcdc3";
293 regulator-name = "vdcdc3"; 293 regulator-name = "vdcdc3";
294 regulator-min-microvolt = <1350000>; 294 regulator-min-microvolt = <1500000>;
295 regulator-max-microvolt = <1350000>; 295 regulator-max-microvolt = <1500000>;
296 regulator-boot-on; 296 regulator-boot-on;
297 regulator-always-on; 297 regulator-always-on;
298 }; 298 };
diff --git a/arch/arm/boot/dts/am437x-sk-evm.dts b/arch/arm/boot/dts/am437x-sk-evm.dts
index 859ff3d620ee..87aa4f3b8b3d 100644
--- a/arch/arm/boot/dts/am437x-sk-evm.dts
+++ b/arch/arm/boot/dts/am437x-sk-evm.dts
@@ -363,8 +363,8 @@
363 dcdc3: regulator-dcdc3 { 363 dcdc3: regulator-dcdc3 {
364 compatible = "ti,tps65218-dcdc3"; 364 compatible = "ti,tps65218-dcdc3";
365 regulator-name = "vdds_ddr"; 365 regulator-name = "vdds_ddr";
366 regulator-min-microvolt = <1350000>; 366 regulator-min-microvolt = <1500000>;
367 regulator-max-microvolt = <1350000>; 367 regulator-max-microvolt = <1500000>;
368 regulator-boot-on; 368 regulator-boot-on;
369 regulator-always-on; 369 regulator-always-on;
370 }; 370 };
diff --git a/arch/arm/boot/dts/am43x-epos-evm.dts b/arch/arm/boot/dts/am43x-epos-evm.dts
index ac3e4859935f..f7e9bba10bd6 100644
--- a/arch/arm/boot/dts/am43x-epos-evm.dts
+++ b/arch/arm/boot/dts/am43x-epos-evm.dts
@@ -358,8 +358,8 @@
358 dcdc3: regulator-dcdc3 { 358 dcdc3: regulator-dcdc3 {
359 compatible = "ti,tps65218-dcdc3"; 359 compatible = "ti,tps65218-dcdc3";
360 regulator-name = "vdcdc3"; 360 regulator-name = "vdcdc3";
361 regulator-min-microvolt = <1350000>; 361 regulator-min-microvolt = <1500000>;
362 regulator-max-microvolt = <1350000>; 362 regulator-max-microvolt = <1500000>;
363 regulator-boot-on; 363 regulator-boot-on;
364 regulator-always-on; 364 regulator-always-on;
365 }; 365 };
diff --git a/arch/arm/boot/dts/emev2-kzm9d.dts b/arch/arm/boot/dts/emev2-kzm9d.dts
index 50ccd151091e..667d323e80a3 100644
--- a/arch/arm/boot/dts/emev2-kzm9d.dts
+++ b/arch/arm/boot/dts/emev2-kzm9d.dts
@@ -25,37 +25,7 @@
25 25
26 chosen { 26 chosen {
27 bootargs = "console=ttyS1,115200n81 ignore_loglevel root=/dev/nfs ip=dhcp"; 27 bootargs = "console=ttyS1,115200n81 ignore_loglevel root=/dev/nfs ip=dhcp";
28 }; 28 stdout-path = &uart1;
29
30 reg_1p8v: regulator@0 {
31 compatible = "regulator-fixed";
32 regulator-name = "fixed-1.8V";
33 regulator-min-microvolt = <1800000>;
34 regulator-max-microvolt = <1800000>;
35 regulator-always-on;
36 regulator-boot-on;
37 };
38
39 reg_3p3v: regulator@1 {
40 compatible = "regulator-fixed";
41 regulator-name = "fixed-3.3V";
42 regulator-min-microvolt = <3300000>;
43 regulator-max-microvolt = <3300000>;
44 regulator-always-on;
45 regulator-boot-on;
46 };
47
48 lan9220@20000000 {
49 compatible = "smsc,lan9220", "smsc,lan9115";
50 reg = <0x20000000 0x10000>;
51 phy-mode = "mii";
52 interrupt-parent = <&gpio0>;
53 interrupts = <1 IRQ_TYPE_EDGE_RISING>;
54 reg-io-width = <4>;
55 smsc,irq-active-high;
56 smsc,irq-push-pull;
57 vddvario-supply = <&reg_1p8v>;
58 vdd33a-supply = <&reg_3p3v>;
59 }; 29 };
60 30
61 gpio_keys { 31 gpio_keys {
@@ -92,4 +62,35 @@
92 gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>; 62 gpios = <&gpio0 17 GPIO_ACTIVE_HIGH>;
93 }; 63 };
94 }; 64 };
65
66 reg_1p8v: regulator@0 {
67 compatible = "regulator-fixed";
68 regulator-name = "fixed-1.8V";
69 regulator-min-microvolt = <1800000>;
70 regulator-max-microvolt = <1800000>;
71 regulator-always-on;
72 regulator-boot-on;
73 };
74
75 reg_3p3v: regulator@1 {
76 compatible = "regulator-fixed";
77 regulator-name = "fixed-3.3V";
78 regulator-min-microvolt = <3300000>;
79 regulator-max-microvolt = <3300000>;
80 regulator-always-on;
81 regulator-boot-on;
82 };
83
84 lan9220@20000000 {
85 compatible = "smsc,lan9220", "smsc,lan9115";
86 reg = <0x20000000 0x10000>;
87 phy-mode = "mii";
88 interrupt-parent = <&gpio0>;
89 interrupts = <1 IRQ_TYPE_EDGE_RISING>;
90 reg-io-width = <4>;
91 smsc,irq-active-high;
92 smsc,irq-push-pull;
93 vddvario-supply = <&reg_1p8v>;
94 vdd33a-supply = <&reg_3p3v>;
95 };
95}; 96};
diff --git a/arch/arm/boot/dts/emev2.dtsi b/arch/arm/boot/dts/emev2.dtsi
index 00eeed3721b6..cc7bfe0ba40a 100644
--- a/arch/arm/boot/dts/emev2.dtsi
+++ b/arch/arm/boot/dts/emev2.dtsi
@@ -55,7 +55,7 @@
55 <0 121 IRQ_TYPE_LEVEL_HIGH>; 55 <0 121 IRQ_TYPE_LEVEL_HIGH>;
56 }; 56 };
57 57
58 smu@e0110000 { 58 clocks@e0110000 {
59 compatible = "renesas,emev2-smu"; 59 compatible = "renesas,emev2-smu";
60 reg = <0xe0110000 0x10000>; 60 reg = <0xe0110000 0x10000>;
61 #address-cells = <2>; 61 #address-cells = <2>;
@@ -129,7 +129,7 @@
129 }; 129 };
130 }; 130 };
131 131
132 sti@e0180000 { 132 timer@e0180000 {
133 compatible = "renesas,em-sti"; 133 compatible = "renesas,em-sti";
134 reg = <0xe0180000 0x54>; 134 reg = <0xe0180000 0x54>;
135 interrupts = <0 125 IRQ_TYPE_LEVEL_HIGH>; 135 interrupts = <0 125 IRQ_TYPE_LEVEL_HIGH>;
@@ -137,7 +137,7 @@
137 clock-names = "sclk"; 137 clock-names = "sclk";
138 }; 138 };
139 139
140 uart@e1020000 { 140 uart0: serial@e1020000 {
141 compatible = "renesas,em-uart"; 141 compatible = "renesas,em-uart";
142 reg = <0xe1020000 0x38>; 142 reg = <0xe1020000 0x38>;
143 interrupts = <0 8 IRQ_TYPE_LEVEL_HIGH>; 143 interrupts = <0 8 IRQ_TYPE_LEVEL_HIGH>;
@@ -145,7 +145,7 @@
145 clock-names = "sclk"; 145 clock-names = "sclk";
146 }; 146 };
147 147
148 uart@e1030000 { 148 uart1: serial@e1030000 {
149 compatible = "renesas,em-uart"; 149 compatible = "renesas,em-uart";
150 reg = <0xe1030000 0x38>; 150 reg = <0xe1030000 0x38>;
151 interrupts = <0 9 IRQ_TYPE_LEVEL_HIGH>; 151 interrupts = <0 9 IRQ_TYPE_LEVEL_HIGH>;
@@ -153,7 +153,7 @@
153 clock-names = "sclk"; 153 clock-names = "sclk";
154 }; 154 };
155 155
156 uart@e1040000 { 156 uart2: serial@e1040000 {
157 compatible = "renesas,em-uart"; 157 compatible = "renesas,em-uart";
158 reg = <0xe1040000 0x38>; 158 reg = <0xe1040000 0x38>;
159 interrupts = <0 10 IRQ_TYPE_LEVEL_HIGH>; 159 interrupts = <0 10 IRQ_TYPE_LEVEL_HIGH>;
@@ -161,7 +161,7 @@
161 clock-names = "sclk"; 161 clock-names = "sclk";
162 }; 162 };
163 163
164 uart@e1050000 { 164 uart3: serial@e1050000 {
165 compatible = "renesas,em-uart"; 165 compatible = "renesas,em-uart";
166 reg = <0xe1050000 0x38>; 166 reg = <0xe1050000 0x38>;
167 interrupts = <0 11 IRQ_TYPE_LEVEL_HIGH>; 167 interrupts = <0 11 IRQ_TYPE_LEVEL_HIGH>;
diff --git a/arch/arm/boot/dts/exynos5250-snow.dts b/arch/arm/boot/dts/exynos5250-snow.dts
index e51fcef884a4..60429ad1c5d8 100644
--- a/arch/arm/boot/dts/exynos5250-snow.dts
+++ b/arch/arm/boot/dts/exynos5250-snow.dts
@@ -624,4 +624,8 @@
624 num-cs = <1>; 624 num-cs = <1>;
625}; 625};
626 626
627&usbdrd_dwc3 {
628 dr_mode = "host";
629};
630
627#include "cros-ec-keyboard.dtsi" 631#include "cros-ec-keyboard.dtsi"
diff --git a/arch/arm/boot/dts/exynos5250.dtsi b/arch/arm/boot/dts/exynos5250.dtsi
index f21b9aa00fbb..d55c1a2eb798 100644
--- a/arch/arm/boot/dts/exynos5250.dtsi
+++ b/arch/arm/boot/dts/exynos5250.dtsi
@@ -555,7 +555,7 @@
555 #size-cells = <1>; 555 #size-cells = <1>;
556 ranges; 556 ranges;
557 557
558 dwc3 { 558 usbdrd_dwc3: dwc3 {
559 compatible = "synopsys,dwc3"; 559 compatible = "synopsys,dwc3";
560 reg = <0x12000000 0x10000>; 560 reg = <0x12000000 0x10000>;
561 interrupts = <0 72 0>; 561 interrupts = <0 72 0>;
diff --git a/arch/arm/boot/dts/imx6qdl-gw52xx.dtsi b/arch/arm/boot/dts/imx6qdl-gw52xx.dtsi
index d3c0bf5c84e3..b5756c21ea1d 100644
--- a/arch/arm/boot/dts/imx6qdl-gw52xx.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-gw52xx.dtsi
@@ -282,7 +282,6 @@
282}; 282};
283 283
284&ssi1 { 284&ssi1 {
285 fsl,mode = "i2s-slave";
286 status = "okay"; 285 status = "okay";
287}; 286};
288 287
diff --git a/arch/arm/boot/dts/imx6qdl-gw53xx.dtsi b/arch/arm/boot/dts/imx6qdl-gw53xx.dtsi
index cade1bdc97e9..86f03c1b147c 100644
--- a/arch/arm/boot/dts/imx6qdl-gw53xx.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-gw53xx.dtsi
@@ -287,7 +287,6 @@
287}; 287};
288 288
289&ssi1 { 289&ssi1 {
290 fsl,mode = "i2s-slave";
291 status = "okay"; 290 status = "okay";
292}; 291};
293 292
diff --git a/arch/arm/boot/dts/imx6qdl-gw54xx.dtsi b/arch/arm/boot/dts/imx6qdl-gw54xx.dtsi
index cf13239a1619..4a8d97f47759 100644
--- a/arch/arm/boot/dts/imx6qdl-gw54xx.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-gw54xx.dtsi
@@ -376,12 +376,10 @@
376}; 376};
377 377
378&ssi1 { 378&ssi1 {
379 fsl,mode = "i2s-slave";
380 status = "okay"; 379 status = "okay";
381}; 380};
382 381
383&ssi2 { 382&ssi2 {
384 fsl,mode = "i2s-slave";
385 status = "okay"; 383 status = "okay";
386}; 384};
387 385
diff --git a/arch/arm/boot/dts/imx6qdl-rex.dtsi b/arch/arm/boot/dts/imx6qdl-rex.dtsi
index df7bcf86c156..488a640796ac 100644
--- a/arch/arm/boot/dts/imx6qdl-rex.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-rex.dtsi
@@ -308,7 +308,6 @@
308}; 308};
309 309
310&ssi1 { 310&ssi1 {
311 fsl,mode = "i2s-slave";
312 status = "okay"; 311 status = "okay";
313}; 312};
314 313
diff --git a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
index baf2f00d519a..5db4a2417d94 100644
--- a/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-sabresd.dtsi
@@ -107,10 +107,8 @@
107 "Headphone Jack", "HPOUTR", 107 "Headphone Jack", "HPOUTR",
108 "Ext Spk", "SPKOUTL", 108 "Ext Spk", "SPKOUTL",
109 "Ext Spk", "SPKOUTR", 109 "Ext Spk", "SPKOUTR",
110 "MICBIAS", "AMIC", 110 "AMIC", "MICBIAS",
111 "IN3R", "MICBIAS", 111 "IN3R", "AMIC";
112 "DMIC", "MICBIAS",
113 "DMICDAT", "DMIC";
114 mux-int-port = <2>; 112 mux-int-port = <2>;
115 mux-ext-port = <3>; 113 mux-ext-port = <3>;
116 }; 114 };
@@ -179,7 +177,7 @@
179 codec: wm8962@1a { 177 codec: wm8962@1a {
180 compatible = "wlf,wm8962"; 178 compatible = "wlf,wm8962";
181 reg = <0x1a>; 179 reg = <0x1a>;
182 clocks = <&clks 201>; 180 clocks = <&clks IMX6QDL_CLK_CKO>;
183 DCVDD-supply = <&reg_audio>; 181 DCVDD-supply = <&reg_audio>;
184 DBVDD-supply = <&reg_audio>; 182 DBVDD-supply = <&reg_audio>;
185 AVDD-supply = <&reg_audio>; 183 AVDD-supply = <&reg_audio>;
diff --git a/arch/arm/boot/dts/omap3-evm-common.dtsi b/arch/arm/boot/dts/omap3-evm-common.dtsi
index c8747c7f1cc8..127f3e7c10c4 100644
--- a/arch/arm/boot/dts/omap3-evm-common.dtsi
+++ b/arch/arm/boot/dts/omap3-evm-common.dtsi
@@ -2,6 +2,7 @@
2 * Common support for omap3 EVM boards 2 * Common support for omap3 EVM boards
3 */ 3 */
4 4
5#include <dt-bindings/input/input.h>
5#include "omap-gpmc-smsc911x.dtsi" 6#include "omap-gpmc-smsc911x.dtsi"
6 7
7/ { 8/ {
@@ -111,6 +112,26 @@
111 ti,use-leds; 112 ti,use-leds;
112}; 113};
113 114
115&twl_keypad {
116 linux,keymap = <
117 MATRIX_KEY(2, 2, KEY_1)
118 MATRIX_KEY(1, 1, KEY_2)
119 MATRIX_KEY(0, 0, KEY_3)
120 MATRIX_KEY(3, 2, KEY_4)
121 MATRIX_KEY(2, 1, KEY_5)
122 MATRIX_KEY(1, 0, KEY_6)
123 MATRIX_KEY(1, 3, KEY_7)
124 MATRIX_KEY(3, 1, KEY_8)
125 MATRIX_KEY(2, 0, KEY_9)
126 MATRIX_KEY(2, 3, KEY_KPASTERISK)
127 MATRIX_KEY(0, 2, KEY_0)
128 MATRIX_KEY(3, 0, KEY_KPDOT)
129 /* s4 not wired */
130 MATRIX_KEY(1, 2, KEY_BACKSPACE)
131 MATRIX_KEY(0, 1, KEY_ENTER)
132 >;
133};
134
114&usb_otg_hs { 135&usb_otg_hs {
115 interface-type = <0>; 136 interface-type = <0>;
116 usb-phy = <&usb2_phy>; 137 usb-phy = <&usb2_phy>;
diff --git a/arch/arm/boot/dts/omap3-ldp.dts b/arch/arm/boot/dts/omap3-ldp.dts
index 72dca0b7904d..77fee3fb7515 100644
--- a/arch/arm/boot/dts/omap3-ldp.dts
+++ b/arch/arm/boot/dts/omap3-ldp.dts
@@ -7,6 +7,7 @@
7 */ 7 */
8/dts-v1/; 8/dts-v1/;
9 9
10#include <dt-bindings/input/input.h>
10#include "omap34xx.dtsi" 11#include "omap34xx.dtsi"
11#include "omap-gpmc-smsc911x.dtsi" 12#include "omap-gpmc-smsc911x.dtsi"
12 13
@@ -141,7 +142,7 @@
141 }; 142 };
142 partition@2000000 { 143 partition@2000000 {
143 label = "Filesystem"; 144 label = "Filesystem";
144 reg = <0x2000000 0xe000000>; 145 reg = <0x2000000 0x6000000>;
145 }; 146 };
146 }; 147 };
147 148
@@ -263,6 +264,26 @@
263 }; 264 };
264}; 265};
265 266
267&twl_keypad {
268 linux,keymap = <MATRIX_KEY(0, 0, KEY_1)
269 MATRIX_KEY(0, 1, KEY_2)
270 MATRIX_KEY(0, 2, KEY_3)
271 MATRIX_KEY(1, 0, KEY_4)
272 MATRIX_KEY(1, 1, KEY_5)
273 MATRIX_KEY(1, 2, KEY_6)
274 MATRIX_KEY(1, 3, KEY_F5)
275 MATRIX_KEY(2, 0, KEY_7)
276 MATRIX_KEY(2, 1, KEY_8)
277 MATRIX_KEY(2, 2, KEY_9)
278 MATRIX_KEY(2, 3, KEY_F6)
279 MATRIX_KEY(3, 0, KEY_F7)
280 MATRIX_KEY(3, 1, KEY_0)
281 MATRIX_KEY(3, 2, KEY_F8)
282 MATRIX_KEY(5, 4, KEY_RESERVED)
283 MATRIX_KEY(4, 4, KEY_VOLUMEUP)
284 MATRIX_KEY(5, 5, KEY_VOLUMEDOWN)>;
285};
286
266&uart3 { 287&uart3 {
267 interrupts-extended = <&intc 74 &omap3_pmx_core OMAP3_UART3_RX>; 288 interrupts-extended = <&intc 74 &omap3_pmx_core OMAP3_UART3_RX>;
268}; 289};
diff --git a/arch/arm/boot/dts/omap3.dtsi b/arch/arm/boot/dts/omap3.dtsi
index d0e884d3a737..e602e75ce5b7 100644
--- a/arch/arm/boot/dts/omap3.dtsi
+++ b/arch/arm/boot/dts/omap3.dtsi
@@ -79,7 +79,7 @@
79 * hierarchy. 79 * hierarchy.
80 */ 80 */
81 ocp { 81 ocp {
82 compatible = "simple-bus"; 82 compatible = "ti,omap3-l3-smx", "simple-bus";
83 reg = <0x68000000 0x10000>; 83 reg = <0x68000000 0x10000>;
84 interrupts = <9 10>; 84 interrupts = <9 10>;
85 #address-cells = <1>; 85 #address-cells = <1>;
diff --git a/arch/arm/boot/dts/r7s72100-genmai.dts b/arch/arm/boot/dts/r7s72100-genmai.dts
index a3ed23c0a8f5..1518c5bcca33 100644
--- a/arch/arm/boot/dts/r7s72100-genmai.dts
+++ b/arch/arm/boot/dts/r7s72100-genmai.dts
@@ -21,7 +21,8 @@
21 }; 21 };
22 22
23 chosen { 23 chosen {
24 bootargs = "console=ttySC2,115200 ignore_loglevel rw root=/dev/nfs ip=dhcp"; 24 bootargs = "ignore_loglevel rw root=/dev/nfs ip=dhcp";
25 stdout-path = &scif2;
25 }; 26 };
26 27
27 memory { 28 memory {
diff --git a/arch/arm/boot/dts/r7s72100.dtsi b/arch/arm/boot/dts/r7s72100.dtsi
index 801a556e264b..277e73c110e5 100644
--- a/arch/arm/boot/dts/r7s72100.dtsi
+++ b/arch/arm/boot/dts/r7s72100.dtsi
@@ -52,16 +52,6 @@
52 clock-output-names = "usb_x1"; 52 clock-output-names = "usb_x1";
53 }; 53 };
54 54
55 /* Special CPG clocks */
56 cpg_clocks: cpg_clocks@fcfe0000 {
57 #clock-cells = <1>;
58 compatible = "renesas,r7s72100-cpg-clocks",
59 "renesas,rz-cpg-clocks";
60 reg = <0xfcfe0000 0x18>;
61 clocks = <&extal_clk>, <&usb_x1_clk>;
62 clock-output-names = "pll", "i", "g";
63 };
64
65 /* Fixed factor clocks */ 55 /* Fixed factor clocks */
66 b_clk: b_clk { 56 b_clk: b_clk {
67 #clock-cells = <0>; 57 #clock-cells = <0>;
@@ -88,6 +78,16 @@
88 clock-output-names = "p0"; 78 clock-output-names = "p0";
89 }; 79 };
90 80
81 /* Special CPG clocks */
82 cpg_clocks: cpg_clocks@fcfe0000 {
83 #clock-cells = <1>;
84 compatible = "renesas,r7s72100-cpg-clocks",
85 "renesas,rz-cpg-clocks";
86 reg = <0xfcfe0000 0x18>;
87 clocks = <&extal_clk>, <&usb_x1_clk>;
88 clock-output-names = "pll", "i", "g";
89 };
90
91 /* MSTP clocks */ 91 /* MSTP clocks */
92 mstp3_clks: mstp3_clks@fcfe0420 { 92 mstp3_clks: mstp3_clks@fcfe0420 {
93 #clock-cells = <1>; 93 #clock-cells = <1>;
@@ -148,97 +148,6 @@
148 }; 148 };
149 }; 149 };
150 150
151 gic: interrupt-controller@e8201000 {
152 compatible = "arm,cortex-a9-gic";
153 #interrupt-cells = <3>;
154 #address-cells = <0>;
155 interrupt-controller;
156 reg = <0xe8201000 0x1000>,
157 <0xe8202000 0x1000>;
158 };
159
160 i2c0: i2c@fcfee000 {
161 #address-cells = <1>;
162 #size-cells = <0>;
163 compatible = "renesas,riic-r7s72100", "renesas,riic-rz";
164 reg = <0xfcfee000 0x44>;
165 interrupts = <0 157 IRQ_TYPE_LEVEL_HIGH>,
166 <0 158 IRQ_TYPE_EDGE_RISING>,
167 <0 159 IRQ_TYPE_EDGE_RISING>,
168 <0 160 IRQ_TYPE_LEVEL_HIGH>,
169 <0 161 IRQ_TYPE_LEVEL_HIGH>,
170 <0 162 IRQ_TYPE_LEVEL_HIGH>,
171 <0 163 IRQ_TYPE_LEVEL_HIGH>,
172 <0 164 IRQ_TYPE_LEVEL_HIGH>;
173 clocks = <&mstp9_clks R7S72100_CLK_I2C0>;
174 clock-frequency = <100000>;
175 status = "disabled";
176 };
177
178 i2c1: i2c@fcfee400 {
179 #address-cells = <1>;
180 #size-cells = <0>;
181 compatible = "renesas,riic-r7s72100", "renesas,riic-rz";
182 reg = <0xfcfee400 0x44>;
183 interrupts = <0 165 IRQ_TYPE_LEVEL_HIGH>,
184 <0 166 IRQ_TYPE_EDGE_RISING>,
185 <0 167 IRQ_TYPE_EDGE_RISING>,
186 <0 168 IRQ_TYPE_LEVEL_HIGH>,
187 <0 169 IRQ_TYPE_LEVEL_HIGH>,
188 <0 170 IRQ_TYPE_LEVEL_HIGH>,
189 <0 171 IRQ_TYPE_LEVEL_HIGH>,
190 <0 172 IRQ_TYPE_LEVEL_HIGH>;
191 clocks = <&mstp9_clks R7S72100_CLK_I2C1>;
192 clock-frequency = <100000>;
193 status = "disabled";
194 };
195
196 i2c2: i2c@fcfee800 {
197 #address-cells = <1>;
198 #size-cells = <0>;
199 compatible = "renesas,riic-r7s72100", "renesas,riic-rz";
200 reg = <0xfcfee800 0x44>;
201 interrupts = <0 173 IRQ_TYPE_LEVEL_HIGH>,
202 <0 174 IRQ_TYPE_EDGE_RISING>,
203 <0 175 IRQ_TYPE_EDGE_RISING>,
204 <0 176 IRQ_TYPE_LEVEL_HIGH>,
205 <0 177 IRQ_TYPE_LEVEL_HIGH>,
206 <0 178 IRQ_TYPE_LEVEL_HIGH>,
207 <0 179 IRQ_TYPE_LEVEL_HIGH>,
208 <0 180 IRQ_TYPE_LEVEL_HIGH>;
209 clocks = <&mstp9_clks R7S72100_CLK_I2C2>;
210 clock-frequency = <100000>;
211 status = "disabled";
212 };
213
214 i2c3: i2c@fcfeec00 {
215 #address-cells = <1>;
216 #size-cells = <0>;
217 compatible = "renesas,riic-r7s72100", "renesas,riic-rz";
218 reg = <0xfcfeec00 0x44>;
219 interrupts = <0 181 IRQ_TYPE_LEVEL_HIGH>,
220 <0 182 IRQ_TYPE_EDGE_RISING>,
221 <0 183 IRQ_TYPE_EDGE_RISING>,
222 <0 184 IRQ_TYPE_LEVEL_HIGH>,
223 <0 185 IRQ_TYPE_LEVEL_HIGH>,
224 <0 186 IRQ_TYPE_LEVEL_HIGH>,
225 <0 187 IRQ_TYPE_LEVEL_HIGH>,
226 <0 188 IRQ_TYPE_LEVEL_HIGH>;
227 clocks = <&mstp9_clks R7S72100_CLK_I2C3>;
228 clock-frequency = <100000>;
229 status = "disabled";
230 };
231
232 mtu2: timer@fcff0000 {
233 compatible = "renesas,mtu2-r7s72100", "renesas,mtu2";
234 reg = <0xfcff0000 0x400>;
235 interrupts = <0 107 IRQ_TYPE_LEVEL_HIGH>;
236 interrupt-names = "tgi0a";
237 clocks = <&mstp3_clks R7S72100_CLK_MTU2>;
238 clock-names = "fck";
239 status = "disabled";
240 };
241
242 scif0: serial@e8007000 { 151 scif0: serial@e8007000 {
243 compatible = "renesas,scif-r7s72100", "renesas,scif"; 152 compatible = "renesas,scif-r7s72100", "renesas,scif";
244 reg = <0xe8007000 64>; 153 reg = <0xe8007000 64>;
@@ -404,4 +313,95 @@
404 #size-cells = <0>; 313 #size-cells = <0>;
405 status = "disabled"; 314 status = "disabled";
406 }; 315 };
316
317 gic: interrupt-controller@e8201000 {
318 compatible = "arm,cortex-a9-gic";
319 #interrupt-cells = <3>;
320 #address-cells = <0>;
321 interrupt-controller;
322 reg = <0xe8201000 0x1000>,
323 <0xe8202000 0x1000>;
324 };
325
326 i2c0: i2c@fcfee000 {
327 #address-cells = <1>;
328 #size-cells = <0>;
329 compatible = "renesas,riic-r7s72100", "renesas,riic-rz";
330 reg = <0xfcfee000 0x44>;
331 interrupts = <0 157 IRQ_TYPE_LEVEL_HIGH>,
332 <0 158 IRQ_TYPE_EDGE_RISING>,
333 <0 159 IRQ_TYPE_EDGE_RISING>,
334 <0 160 IRQ_TYPE_LEVEL_HIGH>,
335 <0 161 IRQ_TYPE_LEVEL_HIGH>,
336 <0 162 IRQ_TYPE_LEVEL_HIGH>,
337 <0 163 IRQ_TYPE_LEVEL_HIGH>,
338 <0 164 IRQ_TYPE_LEVEL_HIGH>;
339 clocks = <&mstp9_clks R7S72100_CLK_I2C0>;
340 clock-frequency = <100000>;
341 status = "disabled";
342 };
343
344 i2c1: i2c@fcfee400 {
345 #address-cells = <1>;
346 #size-cells = <0>;
347 compatible = "renesas,riic-r7s72100", "renesas,riic-rz";
348 reg = <0xfcfee400 0x44>;
349 interrupts = <0 165 IRQ_TYPE_LEVEL_HIGH>,
350 <0 166 IRQ_TYPE_EDGE_RISING>,
351 <0 167 IRQ_TYPE_EDGE_RISING>,
352 <0 168 IRQ_TYPE_LEVEL_HIGH>,
353 <0 169 IRQ_TYPE_LEVEL_HIGH>,
354 <0 170 IRQ_TYPE_LEVEL_HIGH>,
355 <0 171 IRQ_TYPE_LEVEL_HIGH>,
356 <0 172 IRQ_TYPE_LEVEL_HIGH>;
357 clocks = <&mstp9_clks R7S72100_CLK_I2C1>;
358 clock-frequency = <100000>;
359 status = "disabled";
360 };
361
362 i2c2: i2c@fcfee800 {
363 #address-cells = <1>;
364 #size-cells = <0>;
365 compatible = "renesas,riic-r7s72100", "renesas,riic-rz";
366 reg = <0xfcfee800 0x44>;
367 interrupts = <0 173 IRQ_TYPE_LEVEL_HIGH>,
368 <0 174 IRQ_TYPE_EDGE_RISING>,
369 <0 175 IRQ_TYPE_EDGE_RISING>,
370 <0 176 IRQ_TYPE_LEVEL_HIGH>,
371 <0 177 IRQ_TYPE_LEVEL_HIGH>,
372 <0 178 IRQ_TYPE_LEVEL_HIGH>,
373 <0 179 IRQ_TYPE_LEVEL_HIGH>,
374 <0 180 IRQ_TYPE_LEVEL_HIGH>;
375 clocks = <&mstp9_clks R7S72100_CLK_I2C2>;
376 clock-frequency = <100000>;
377 status = "disabled";
378 };
379
380 i2c3: i2c@fcfeec00 {
381 #address-cells = <1>;
382 #size-cells = <0>;
383 compatible = "renesas,riic-r7s72100", "renesas,riic-rz";
384 reg = <0xfcfeec00 0x44>;
385 interrupts = <0 181 IRQ_TYPE_LEVEL_HIGH>,
386 <0 182 IRQ_TYPE_EDGE_RISING>,
387 <0 183 IRQ_TYPE_EDGE_RISING>,
388 <0 184 IRQ_TYPE_LEVEL_HIGH>,
389 <0 185 IRQ_TYPE_LEVEL_HIGH>,
390 <0 186 IRQ_TYPE_LEVEL_HIGH>,
391 <0 187 IRQ_TYPE_LEVEL_HIGH>,
392 <0 188 IRQ_TYPE_LEVEL_HIGH>;
393 clocks = <&mstp9_clks R7S72100_CLK_I2C3>;
394 clock-frequency = <100000>;
395 status = "disabled";
396 };
397
398 mtu2: timer@fcff0000 {
399 compatible = "renesas,mtu2-r7s72100", "renesas,mtu2";
400 reg = <0xfcff0000 0x400>;
401 interrupts = <0 107 IRQ_TYPE_LEVEL_HIGH>;
402 interrupt-names = "tgi0a";
403 clocks = <&mstp3_clks R7S72100_CLK_MTU2>;
404 clock-names = "fck";
405 status = "disabled";
406 };
407}; 407};
diff --git a/arch/arm/boot/dts/r8a73a4-ape6evm-reference.dts b/arch/arm/boot/dts/r8a73a4-ape6evm-reference.dts
index a860f32bca27..2bcf69124a6a 100644
--- a/arch/arm/boot/dts/r8a73a4-ape6evm-reference.dts
+++ b/arch/arm/boot/dts/r8a73a4-ape6evm-reference.dts
@@ -21,7 +21,8 @@
21 }; 21 };
22 22
23 chosen { 23 chosen {
24 bootargs = "console=ttySC0,115200 ignore_loglevel rw"; 24 bootargs = "ignore_loglevel rw";
25 stdout-path = &scifa0;
25 }; 26 };
26 27
27 memory@40000000 { 28 memory@40000000 {
diff --git a/arch/arm/boot/dts/r8a73a4.dtsi b/arch/arm/boot/dts/r8a73a4.dtsi
index ef152e384822..c17afef92e8d 100644
--- a/arch/arm/boot/dts/r8a73a4.dtsi
+++ b/arch/arm/boot/dts/r8a73a4.dtsi
@@ -30,18 +30,6 @@
30 }; 30 };
31 }; 31 };
32 32
33 gic: interrupt-controller@f1001000 {
34 compatible = "arm,cortex-a15-gic";
35 #interrupt-cells = <3>;
36 #address-cells = <0>;
37 interrupt-controller;
38 reg = <0 0xf1001000 0 0x1000>,
39 <0 0xf1002000 0 0x1000>,
40 <0 0xf1004000 0 0x2000>,
41 <0 0xf1006000 0 0x2000>;
42 interrupts = <1 9 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_HIGH)>;
43 };
44
45 timer { 33 timer {
46 compatible = "arm,armv7-timer"; 34 compatible = "arm,armv7-timer";
47 interrupts = <1 13 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>, 35 interrupts = <1 13 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>,
@@ -50,6 +38,80 @@
50 <1 10 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>; 38 <1 10 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>;
51 }; 39 };
52 40
41 dmac: dma-multiplexer {
42 compatible = "renesas,shdma-mux";
43 #dma-cells = <1>;
44 dma-channels = <20>;
45 dma-requests = <256>;
46 #address-cells = <2>;
47 #size-cells = <2>;
48 ranges;
49
50 dma0: dma-controller@e6700020 {
51 compatible = "renesas,shdma-r8a73a4";
52 reg = <0 0xe6700020 0 0x89e0>;
53 interrupts = <0 220 IRQ_TYPE_LEVEL_HIGH
54 0 200 IRQ_TYPE_LEVEL_HIGH
55 0 201 IRQ_TYPE_LEVEL_HIGH
56 0 202 IRQ_TYPE_LEVEL_HIGH
57 0 203 IRQ_TYPE_LEVEL_HIGH
58 0 204 IRQ_TYPE_LEVEL_HIGH
59 0 205 IRQ_TYPE_LEVEL_HIGH
60 0 206 IRQ_TYPE_LEVEL_HIGH
61 0 207 IRQ_TYPE_LEVEL_HIGH
62 0 208 IRQ_TYPE_LEVEL_HIGH
63 0 209 IRQ_TYPE_LEVEL_HIGH
64 0 210 IRQ_TYPE_LEVEL_HIGH
65 0 211 IRQ_TYPE_LEVEL_HIGH
66 0 212 IRQ_TYPE_LEVEL_HIGH
67 0 213 IRQ_TYPE_LEVEL_HIGH
68 0 214 IRQ_TYPE_LEVEL_HIGH
69 0 215 IRQ_TYPE_LEVEL_HIGH
70 0 216 IRQ_TYPE_LEVEL_HIGH
71 0 217 IRQ_TYPE_LEVEL_HIGH
72 0 218 IRQ_TYPE_LEVEL_HIGH
73 0 219 IRQ_TYPE_LEVEL_HIGH>;
74 interrupt-names = "error",
75 "ch0", "ch1", "ch2", "ch3",
76 "ch4", "ch5", "ch6", "ch7",
77 "ch8", "ch9", "ch10", "ch11",
78 "ch12", "ch13", "ch14", "ch15",
79 "ch16", "ch17", "ch18", "ch19";
80 };
81 };
82
83 pfc: pfc@e6050000 {
84 compatible = "renesas,pfc-r8a73a4";
85 reg = <0 0xe6050000 0 0x9000>;
86 gpio-controller;
87 #gpio-cells = <2>;
88 interrupts-extended =
89 <&irqc0 0 0>, <&irqc0 1 0>, <&irqc0 2 0>, <&irqc0 3 0>,
90 <&irqc0 4 0>, <&irqc0 5 0>, <&irqc0 6 0>, <&irqc0 7 0>,
91 <&irqc0 8 0>, <&irqc0 9 0>, <&irqc0 10 0>, <&irqc0 11 0>,
92 <&irqc0 12 0>, <&irqc0 13 0>, <&irqc0 14 0>, <&irqc0 15 0>,
93 <&irqc0 16 0>, <&irqc0 17 0>, <&irqc0 18 0>, <&irqc0 19 0>,
94 <&irqc0 20 0>, <&irqc0 21 0>, <&irqc0 22 0>, <&irqc0 23 0>,
95 <&irqc0 24 0>, <&irqc0 25 0>, <&irqc0 26 0>, <&irqc0 27 0>,
96 <&irqc0 28 0>, <&irqc0 29 0>, <&irqc0 30 0>, <&irqc0 31 0>,
97 <&irqc1 0 0>, <&irqc1 1 0>, <&irqc1 2 0>, <&irqc1 3 0>,
98 <&irqc1 4 0>, <&irqc1 5 0>, <&irqc1 6 0>, <&irqc1 7 0>,
99 <&irqc1 8 0>, <&irqc1 9 0>, <&irqc1 10 0>, <&irqc1 11 0>,
100 <&irqc1 12 0>, <&irqc1 13 0>, <&irqc1 14 0>, <&irqc1 15 0>,
101 <&irqc1 16 0>, <&irqc1 17 0>, <&irqc1 18 0>, <&irqc1 19 0>,
102 <&irqc1 20 0>, <&irqc1 21 0>, <&irqc1 22 0>, <&irqc1 23 0>,
103 <&irqc1 24 0>, <&irqc1 25 0>;
104 };
105
106 i2c5: i2c@e60b0000 {
107 #address-cells = <1>;
108 #size-cells = <0>;
109 compatible = "renesas,rmobile-iic";
110 reg = <0 0xe60b0000 0 0x428>;
111 interrupts = <0 179 IRQ_TYPE_LEVEL_HIGH>;
112 status = "disabled";
113 };
114
53 irqc0: interrupt-controller@e61c0000 { 115 irqc0: interrupt-controller@e61c0000 {
54 compatible = "renesas,irqc-r8a73a4", "renesas,irqc"; 116 compatible = "renesas,irqc-r8a73a4", "renesas,irqc";
55 #interrupt-cells = <2>; 117 #interrupt-cells = <2>;
@@ -122,48 +184,6 @@
122 <0 57 IRQ_TYPE_LEVEL_HIGH>; 184 <0 57 IRQ_TYPE_LEVEL_HIGH>;
123 }; 185 };
124 186
125 dmac: dma-multiplexer@0 {
126 compatible = "renesas,shdma-mux";
127 #dma-cells = <1>;
128 dma-channels = <20>;
129 dma-requests = <256>;
130 #address-cells = <2>;
131 #size-cells = <2>;
132 ranges;
133
134 dma0: dma-controller@e6700020 {
135 compatible = "renesas,shdma-r8a73a4";
136 reg = <0 0xe6700020 0 0x89e0>;
137 interrupts = <0 220 IRQ_TYPE_LEVEL_HIGH
138 0 200 IRQ_TYPE_LEVEL_HIGH
139 0 201 IRQ_TYPE_LEVEL_HIGH
140 0 202 IRQ_TYPE_LEVEL_HIGH
141 0 203 IRQ_TYPE_LEVEL_HIGH
142 0 204 IRQ_TYPE_LEVEL_HIGH
143 0 205 IRQ_TYPE_LEVEL_HIGH
144 0 206 IRQ_TYPE_LEVEL_HIGH
145 0 207 IRQ_TYPE_LEVEL_HIGH
146 0 208 IRQ_TYPE_LEVEL_HIGH
147 0 209 IRQ_TYPE_LEVEL_HIGH
148 0 210 IRQ_TYPE_LEVEL_HIGH
149 0 211 IRQ_TYPE_LEVEL_HIGH
150 0 212 IRQ_TYPE_LEVEL_HIGH
151 0 213 IRQ_TYPE_LEVEL_HIGH
152 0 214 IRQ_TYPE_LEVEL_HIGH
153 0 215 IRQ_TYPE_LEVEL_HIGH
154 0 216 IRQ_TYPE_LEVEL_HIGH
155 0 217 IRQ_TYPE_LEVEL_HIGH
156 0 218 IRQ_TYPE_LEVEL_HIGH
157 0 219 IRQ_TYPE_LEVEL_HIGH>;
158 interrupt-names = "error",
159 "ch0", "ch1", "ch2", "ch3",
160 "ch4", "ch5", "ch6", "ch7",
161 "ch8", "ch9", "ch10", "ch11",
162 "ch12", "ch13", "ch14", "ch15",
163 "ch16", "ch17", "ch18", "ch19";
164 };
165 };
166
167 thermal@e61f0000 { 187 thermal@e61f0000 {
168 compatible = "renesas,thermal-r8a73a4", "renesas,rcar-thermal"; 188 compatible = "renesas,thermal-r8a73a4", "renesas,rcar-thermal";
169 reg = <0 0xe61f0000 0 0x14>, <0 0xe61f0100 0 0x38>, 189 reg = <0 0xe61f0000 0 0x14>, <0 0xe61f0100 0 0x38>,
@@ -216,15 +236,6 @@
216 status = "disabled"; 236 status = "disabled";
217 }; 237 };
218 238
219 i2c5: i2c@e60b0000 {
220 #address-cells = <1>;
221 #size-cells = <0>;
222 compatible = "renesas,rmobile-iic";
223 reg = <0 0xe60b0000 0 0x428>;
224 interrupts = <0 179 IRQ_TYPE_LEVEL_HIGH>;
225 status = "disabled";
226 };
227
228 i2c6: i2c@e6550000 { 239 i2c6: i2c@e6550000 {
229 #address-cells = <1>; 240 #address-cells = <1>;
230 #size-cells = <0>; 241 #size-cells = <0>;
@@ -252,20 +263,6 @@
252 status = "disabled"; 263 status = "disabled";
253 }; 264 };
254 265
255 scifa0: serial@e6c40000 {
256 compatible = "renesas,scifa-r8a73a4", "renesas,scifa";
257 reg = <0 0xe6c40000 0 0x100>;
258 interrupts = <0 144 IRQ_TYPE_LEVEL_HIGH>;
259 status = "disabled";
260 };
261
262 scifa1: serial@e6c50000 {
263 compatible = "renesas,scifa-r8a73a4", "renesas,scifa";
264 reg = <0 0xe6c50000 0 0x100>;
265 interrupts = <0 145 IRQ_TYPE_LEVEL_HIGH>;
266 status = "disabled";
267 };
268
269 scifb2: serial@e6c20000 { 266 scifb2: serial@e6c20000 {
270 compatible = "renesas,scifb-r8a73a4", "renesas,scifb"; 267 compatible = "renesas,scifb-r8a73a4", "renesas,scifb";
271 reg = <0 0xe6c20000 0 0x100>; 268 reg = <0 0xe6c20000 0 0x100>;
@@ -280,6 +277,20 @@
280 status = "disabled"; 277 status = "disabled";
281 }; 278 };
282 279
280 scifa0: serial@e6c40000 {
281 compatible = "renesas,scifa-r8a73a4", "renesas,scifa";
282 reg = <0 0xe6c40000 0 0x100>;
283 interrupts = <0 144 IRQ_TYPE_LEVEL_HIGH>;
284 status = "disabled";
285 };
286
287 scifa1: serial@e6c50000 {
288 compatible = "renesas,scifa-r8a73a4", "renesas,scifa";
289 reg = <0 0xe6c50000 0 0x100>;
290 interrupts = <0 145 IRQ_TYPE_LEVEL_HIGH>;
291 status = "disabled";
292 };
293
283 scifb4: serial@e6ce0000 { 294 scifb4: serial@e6ce0000 {
284 compatible = "renesas,scifb-r8a73a4", "renesas,scifb"; 295 compatible = "renesas,scifb-r8a73a4", "renesas,scifb";
285 reg = <0 0xe6ce0000 0 0x100>; 296 reg = <0 0xe6ce0000 0 0x100>;
@@ -294,45 +305,6 @@
294 status = "disabled"; 305 status = "disabled";
295 }; 306 };
296 307
297 mmcif0: mmc@ee200000 {
298 compatible = "renesas,sh-mmcif";
299 reg = <0 0xee200000 0 0x80>;
300 interrupts = <0 169 IRQ_TYPE_LEVEL_HIGH>;
301 reg-io-width = <4>;
302 status = "disabled";
303 };
304
305 mmcif1: mmc@ee220000 {
306 compatible = "renesas,sh-mmcif";
307 reg = <0 0xee220000 0 0x80>;
308 interrupts = <0 170 IRQ_TYPE_LEVEL_HIGH>;
309 reg-io-width = <4>;
310 status = "disabled";
311 };
312
313 pfc: pfc@e6050000 {
314 compatible = "renesas,pfc-r8a73a4";
315 reg = <0 0xe6050000 0 0x9000>;
316 gpio-controller;
317 #gpio-cells = <2>;
318 interrupts-extended =
319 <&irqc0 0 0>, <&irqc0 1 0>, <&irqc0 2 0>, <&irqc0 3 0>,
320 <&irqc0 4 0>, <&irqc0 5 0>, <&irqc0 6 0>, <&irqc0 7 0>,
321 <&irqc0 8 0>, <&irqc0 9 0>, <&irqc0 10 0>, <&irqc0 11 0>,
322 <&irqc0 12 0>, <&irqc0 13 0>, <&irqc0 14 0>, <&irqc0 15 0>,
323 <&irqc0 16 0>, <&irqc0 17 0>, <&irqc0 18 0>, <&irqc0 19 0>,
324 <&irqc0 20 0>, <&irqc0 21 0>, <&irqc0 22 0>, <&irqc0 23 0>,
325 <&irqc0 24 0>, <&irqc0 25 0>, <&irqc0 26 0>, <&irqc0 27 0>,
326 <&irqc0 28 0>, <&irqc0 29 0>, <&irqc0 30 0>, <&irqc0 31 0>,
327 <&irqc1 0 0>, <&irqc1 1 0>, <&irqc1 2 0>, <&irqc1 3 0>,
328 <&irqc1 4 0>, <&irqc1 5 0>, <&irqc1 6 0>, <&irqc1 7 0>,
329 <&irqc1 8 0>, <&irqc1 9 0>, <&irqc1 10 0>, <&irqc1 11 0>,
330 <&irqc1 12 0>, <&irqc1 13 0>, <&irqc1 14 0>, <&irqc1 15 0>,
331 <&irqc1 16 0>, <&irqc1 17 0>, <&irqc1 18 0>, <&irqc1 19 0>,
332 <&irqc1 20 0>, <&irqc1 21 0>, <&irqc1 22 0>, <&irqc1 23 0>,
333 <&irqc1 24 0>, <&irqc1 25 0>;
334 };
335
336 sdhi0: sd@ee100000 { 308 sdhi0: sd@ee100000 {
337 compatible = "renesas,sdhi-r8a73a4"; 309 compatible = "renesas,sdhi-r8a73a4";
338 reg = <0 0xee100000 0 0x100>; 310 reg = <0 0xee100000 0 0x100>;
@@ -356,4 +328,32 @@
356 cap-sd-highspeed; 328 cap-sd-highspeed;
357 status = "disabled"; 329 status = "disabled";
358 }; 330 };
331
332 mmcif0: mmc@ee200000 {
333 compatible = "renesas,sh-mmcif";
334 reg = <0 0xee200000 0 0x80>;
335 interrupts = <0 169 IRQ_TYPE_LEVEL_HIGH>;
336 reg-io-width = <4>;
337 status = "disabled";
338 };
339
340 mmcif1: mmc@ee220000 {
341 compatible = "renesas,sh-mmcif";
342 reg = <0 0xee220000 0 0x80>;
343 interrupts = <0 170 IRQ_TYPE_LEVEL_HIGH>;
344 reg-io-width = <4>;
345 status = "disabled";
346 };
347
348 gic: interrupt-controller@f1001000 {
349 compatible = "arm,cortex-a15-gic";
350 #interrupt-cells = <3>;
351 #address-cells = <0>;
352 interrupt-controller;
353 reg = <0 0xf1001000 0 0x1000>,
354 <0 0xf1002000 0 0x1000>,
355 <0 0xf1004000 0 0x2000>,
356 <0 0xf1006000 0 0x2000>;
357 interrupts = <1 9 (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_HIGH)>;
358 };
359}; 359};
diff --git a/arch/arm/boot/dts/r8a7740-armadillo800eva.dts b/arch/arm/boot/dts/r8a7740-armadillo800eva.dts
index effb7b46f131..2703428557fc 100644
--- a/arch/arm/boot/dts/r8a7740-armadillo800eva.dts
+++ b/arch/arm/boot/dts/r8a7740-armadillo800eva.dts
@@ -25,6 +25,7 @@
25 25
26 chosen { 26 chosen {
27 bootargs = "console=tty0 console=ttySC1,115200 earlyprintk=sh-sci.1,115200 ignore_loglevel root=/dev/nfs ip=dhcp rw"; 27 bootargs = "console=tty0 console=ttySC1,115200 earlyprintk=sh-sci.1,115200 ignore_loglevel root=/dev/nfs ip=dhcp rw";
28 stdout-path = &scifa1;
28 }; 29 };
29 30
30 memory { 31 memory {
diff --git a/arch/arm/boot/dts/r8a7740.dtsi b/arch/arm/boot/dts/r8a7740.dtsi
index d46c213a17ad..eed697a6bd6b 100644
--- a/arch/arm/boot/dts/r8a7740.dtsi
+++ b/arch/arm/boot/dts/r8a7740.dtsi
@@ -433,7 +433,7 @@
433 clocks = <&cpg_clocks R8A7740_CLK_S>, 433 clocks = <&cpg_clocks R8A7740_CLK_S>,
434 <&cpg_clocks R8A7740_CLK_S>, <&sub_clk>, 434 <&cpg_clocks R8A7740_CLK_S>, <&sub_clk>,
435 <&cpg_clocks R8A7740_CLK_B>, 435 <&cpg_clocks R8A7740_CLK_B>,
436 <&sub_clk>, <&sub_clk>, 436 <&cpg_clocks R8A7740_CLK_HPP>, <&sub_clk>,
437 <&cpg_clocks R8A7740_CLK_B>; 437 <&cpg_clocks R8A7740_CLK_B>;
438 #clock-cells = <1>; 438 #clock-cells = <1>;
439 renesas,clock-indices = < 439 renesas,clock-indices = <
diff --git a/arch/arm/boot/dts/r8a7778-bockw-reference.dts b/arch/arm/boot/dts/r8a7778-bockw-reference.dts
index 3342c74c5de8..fba294905ff4 100644
--- a/arch/arm/boot/dts/r8a7778-bockw-reference.dts
+++ b/arch/arm/boot/dts/r8a7778-bockw-reference.dts
@@ -28,7 +28,8 @@
28 }; 28 };
29 29
30 chosen { 30 chosen {
31 bootargs = "console=ttySC0,115200 ignore_loglevel root=/dev/nfs ip=dhcp rw"; 31 bootargs = "ignore_loglevel root=/dev/nfs ip=dhcp rw";
32 stdout-path = &scif0;
32 }; 33 };
33 34
34 memory { 35 memory {
diff --git a/arch/arm/boot/dts/r8a7779-marzen.dts b/arch/arm/boot/dts/r8a7779-marzen.dts
index c160404e4d40..e83d40e24bcd 100644
--- a/arch/arm/boot/dts/r8a7779-marzen.dts
+++ b/arch/arm/boot/dts/r8a7779-marzen.dts
@@ -25,6 +25,7 @@
25 25
26 chosen { 26 chosen {
27 bootargs = "console=ttySC2,115200 ignore_loglevel root=/dev/nfs ip=on"; 27 bootargs = "console=ttySC2,115200 ignore_loglevel root=/dev/nfs ip=on";
28 stdout-path = &scif2;
28 }; 29 };
29 30
30 memory { 31 memory {
@@ -68,6 +69,78 @@
68 gpios = <&gpio4 31 GPIO_ACTIVE_HIGH>; 69 gpios = <&gpio4 31 GPIO_ACTIVE_HIGH>;
69 }; 70 };
70 }; 71 };
72
73 vga-encoder {
74 compatible = "adi,adv7123";
75
76 ports {
77 #address-cells = <1>;
78 #size-cells = <0>;
79
80 port@0 {
81 reg = <0>;
82 vga_enc_in: endpoint {
83 remote-endpoint = <&du_out_rgb0>;
84 };
85 };
86 port@1 {
87 reg = <1>;
88 vga_enc_out: endpoint {
89 remote-endpoint = <&vga_in>;
90 };
91 };
92 };
93 };
94
95 vga {
96 compatible = "vga-connector";
97
98 port {
99 vga_in: endpoint {
100 remote-endpoint = <&vga_enc_out>;
101 };
102 };
103 };
104
105 lvds-encoder {
106 compatible = "thine,thc63lvdm83d";
107
108 ports {
109 #address-cells = <1>;
110 #size-cells = <0>;
111
112 port@0 {
113 reg = <0>;
114 lvds_enc_in: endpoint {
115 remote-endpoint = <&du_out_rgb1>;
116 };
117 };
118 port@1 {
119 reg = <1>;
120 lvds_connector: endpoint {
121 };
122 };
123 };
124 };
125};
126
127&du {
128 pinctrl-0 = <&du_pins>;
129 pinctrl-names = "default";
130 status = "okay";
131
132 ports {
133 port@0 {
134 endpoint {
135 remote-endpoint = <&vga_enc_in>;
136 };
137 };
138 port@1 {
139 endpoint {
140 remote-endpoint = <&lvds_enc_in>;
141 };
142 };
143 };
71}; 144};
72 145
73&irqpin0 { 146&irqpin0 {
@@ -83,6 +156,17 @@
83}; 156};
84 157
85&pfc { 158&pfc {
159 du_pins: du {
160 du0 {
161 renesas,groups = "du0_rgb888", "du0_sync_1", "du0_clk_out_0";
162 renesas,function = "du0";
163 };
164 du1 {
165 renesas,groups = "du1_rgb666", "du1_sync_1", "du1_clk_out";
166 renesas,function = "du1";
167 };
168 };
169
86 lan0_pins: lan0 { 170 lan0_pins: lan0 {
87 intc { 171 intc {
88 renesas,groups = "intc_irq1_b"; 172 renesas,groups = "intc_irq1_b";
diff --git a/arch/arm/boot/dts/r8a7779.dtsi b/arch/arm/boot/dts/r8a7779.dtsi
index 7cfba9aa1b41..fda814ed191d 100644
--- a/arch/arm/boot/dts/r8a7779.dtsi
+++ b/arch/arm/boot/dts/r8a7779.dtsi
@@ -379,6 +379,30 @@
379 status = "disabled"; 379 status = "disabled";
380 }; 380 };
381 381
382 du: display@fff80000 {
383 compatible = "renesas,du-r8a7779";
384 reg = <0 0xfff80000 0 0x40000>;
385 interrupts = <0 31 IRQ_TYPE_LEVEL_HIGH>;
386 clocks = <&mstp1_clks R8A7779_CLK_DU>;
387 status = "disabled";
388
389 ports {
390 #address-cells = <1>;
391 #size-cells = <0>;
392
393 port@0 {
394 reg = <0>;
395 du_out_rgb0: endpoint {
396 };
397 };
398 port@1 {
399 reg = <1>;
400 du_out_rgb1: endpoint {
401 };
402 };
403 };
404 };
405
382 clocks { 406 clocks {
383 #address-cells = <1>; 407 #address-cells = <1>;
384 #size-cells = <1>; 408 #size-cells = <1>;
diff --git a/arch/arm/boot/dts/r8a7790-lager.dts b/arch/arm/boot/dts/r8a7790-lager.dts
index 69098b906b39..acab2e153382 100644
--- a/arch/arm/boot/dts/r8a7790-lager.dts
+++ b/arch/arm/boot/dts/r8a7790-lager.dts
@@ -25,6 +25,7 @@
25 25
26 chosen { 26 chosen {
27 bootargs = "console=ttySC6,115200 ignore_loglevel rw root=/dev/nfs ip=dhcp"; 27 bootargs = "console=ttySC6,115200 ignore_loglevel rw root=/dev/nfs ip=dhcp";
28 stdout-path = &scifa0;
28 }; 29 };
29 30
30 memory@40000000 { 31 memory@40000000 {
@@ -144,6 +145,56 @@
144 states = <3300000 1 145 states = <3300000 1
145 1800000 0>; 146 1800000 0>;
146 }; 147 };
148
149 vga-encoder {
150 compatible = "adi,adv7123";
151
152 ports {
153 #address-cells = <1>;
154 #size-cells = <0>;
155
156 port@0 {
157 reg = <0>;
158 adv7123_in: endpoint {
159 remote-endpoint = <&du_out_rgb>;
160 };
161 };
162 port@1 {
163 reg = <1>;
164 adv7123_out: endpoint {
165 remote-endpoint = <&vga_in>;
166 };
167 };
168 };
169 };
170
171 vga {
172 compatible = "vga-connector";
173
174 port {
175 vga_in: endpoint {
176 remote-endpoint = <&adv7123_out>;
177 };
178 };
179 };
180};
181
182&du {
183 pinctrl-0 = <&du_pins>;
184 pinctrl-names = "default";
185 status = "okay";
186
187 ports {
188 port@0 {
189 endpoint {
190 remote-endpoint = <&adv7123_in>;
191 };
192 };
193 port@2 {
194 lvds_connector: endpoint {
195 };
196 };
197 };
147}; 198};
148 199
149&extal_clk { 200&extal_clk {
@@ -151,9 +202,6 @@
151}; 202};
152 203
153&pfc { 204&pfc {
154 pinctrl-0 = <&du_pins>;
155 pinctrl-names = "default";
156
157 du_pins: du { 205 du_pins: du {
158 renesas,groups = "du_rgb666", "du_sync_1", "du_clk_out_0"; 206 renesas,groups = "du_rgb666", "du_sync_1", "du_clk_out_0";
159 renesas,function = "du"; 207 renesas,function = "du";
diff --git a/arch/arm/boot/dts/r8a7790.dtsi b/arch/arm/boot/dts/r8a7790.dtsi
index d0e17733dc1a..0c20c90d8c06 100644
--- a/arch/arm/boot/dts/r8a7790.dtsi
+++ b/arch/arm/boot/dts/r8a7790.dtsi
@@ -600,6 +600,96 @@
600 status = "disabled"; 600 status = "disabled";
601 }; 601 };
602 602
603 vsp1@fe920000 {
604 compatible = "renesas,vsp1";
605 reg = <0 0xfe920000 0 0x8000>;
606 interrupts = <0 266 IRQ_TYPE_LEVEL_HIGH>;
607 clocks = <&mstp1_clks R8A7790_CLK_VSP1_R>;
608
609 renesas,has-sru;
610 renesas,#rpf = <5>;
611 renesas,#uds = <1>;
612 renesas,#wpf = <4>;
613 };
614
615 vsp1@fe928000 {
616 compatible = "renesas,vsp1";
617 reg = <0 0xfe928000 0 0x8000>;
618 interrupts = <0 267 IRQ_TYPE_LEVEL_HIGH>;
619 clocks = <&mstp1_clks R8A7790_CLK_VSP1_S>;
620
621 renesas,has-lut;
622 renesas,has-sru;
623 renesas,#rpf = <5>;
624 renesas,#uds = <3>;
625 renesas,#wpf = <4>;
626 };
627
628 vsp1@fe930000 {
629 compatible = "renesas,vsp1";
630 reg = <0 0xfe930000 0 0x8000>;
631 interrupts = <0 246 IRQ_TYPE_LEVEL_HIGH>;
632 clocks = <&mstp1_clks R8A7790_CLK_VSP1_DU0>;
633
634 renesas,has-lif;
635 renesas,has-lut;
636 renesas,#rpf = <4>;
637 renesas,#uds = <1>;
638 renesas,#wpf = <4>;
639 };
640
641 vsp1@fe938000 {
642 compatible = "renesas,vsp1";
643 reg = <0 0xfe938000 0 0x8000>;
644 interrupts = <0 247 IRQ_TYPE_LEVEL_HIGH>;
645 clocks = <&mstp1_clks R8A7790_CLK_VSP1_DU1>;
646
647 renesas,has-lif;
648 renesas,has-lut;
649 renesas,#rpf = <4>;
650 renesas,#uds = <1>;
651 renesas,#wpf = <4>;
652 };
653
654 du: display@feb00000 {
655 compatible = "renesas,du-r8a7790";
656 reg = <0 0xfeb00000 0 0x70000>,
657 <0 0xfeb90000 0 0x1c>,
658 <0 0xfeb94000 0 0x1c>;
659 reg-names = "du", "lvds.0", "lvds.1";
660 interrupts = <0 256 IRQ_TYPE_LEVEL_HIGH>,
661 <0 268 IRQ_TYPE_LEVEL_HIGH>,
662 <0 269 IRQ_TYPE_LEVEL_HIGH>;
663 clocks = <&mstp7_clks R8A7790_CLK_DU0>,
664 <&mstp7_clks R8A7790_CLK_DU1>,
665 <&mstp7_clks R8A7790_CLK_DU2>,
666 <&mstp7_clks R8A7790_CLK_LVDS0>,
667 <&mstp7_clks R8A7790_CLK_LVDS1>;
668 clock-names = "du.0", "du.1", "du.2", "lvds.0", "lvds.1";
669 status = "disabled";
670
671 ports {
672 #address-cells = <1>;
673 #size-cells = <0>;
674
675 port@0 {
676 reg = <0>;
677 du_out_rgb: endpoint {
678 };
679 };
680 port@1 {
681 reg = <1>;
682 du_out_lvds0: endpoint {
683 };
684 };
685 port@2 {
686 reg = <2>;
687 du_out_lvds1: endpoint {
688 };
689 };
690 };
691 };
692
603 clocks { 693 clocks {
604 #address-cells = <2>; 694 #address-cells = <2>;
605 #size-cells = <2>; 695 #size-cells = <2>;
@@ -666,9 +756,9 @@
666 #clock-cells = <0>; 756 #clock-cells = <0>;
667 clock-output-names = "sd2"; 757 clock-output-names = "sd2";
668 }; 758 };
669 sd3_clk: sd3_clk@e615007c { 759 sd3_clk: sd3_clk@e615026c {
670 compatible = "renesas,r8a7790-div6-clock", "renesas,cpg-div6-clock"; 760 compatible = "renesas,r8a7790-div6-clock", "renesas,cpg-div6-clock";
671 reg = <0 0xe615007c 0 4>; 761 reg = <0 0xe615026c 0 4>;
672 clocks = <&pll1_div2_clk>; 762 clocks = <&pll1_div2_clk>;
673 #clock-cells = <0>; 763 #clock-cells = <0>;
674 clock-output-names = "sd3"; 764 clock-output-names = "sd3";
diff --git a/arch/arm/boot/dts/r8a7791-henninger.dts b/arch/arm/boot/dts/r8a7791-henninger.dts
index f1b56de10205..0868899882e3 100644
--- a/arch/arm/boot/dts/r8a7791-henninger.dts
+++ b/arch/arm/boot/dts/r8a7791-henninger.dts
@@ -23,6 +23,7 @@
23 23
24 chosen { 24 chosen {
25 bootargs = "console=ttySC0,38400 ignore_loglevel rw root=/dev/nfs ip=dhcp"; 25 bootargs = "console=ttySC0,38400 ignore_loglevel rw root=/dev/nfs ip=dhcp";
26 stdout-path = &scif0;
26 }; 27 };
27 28
28 memory@40000000 { 29 memory@40000000 {
diff --git a/arch/arm/boot/dts/r8a7791-koelsch.dts b/arch/arm/boot/dts/r8a7791-koelsch.dts
index 07550e775e80..924183817b02 100644
--- a/arch/arm/boot/dts/r8a7791-koelsch.dts
+++ b/arch/arm/boot/dts/r8a7791-koelsch.dts
@@ -25,7 +25,8 @@
25 }; 25 };
26 26
27 chosen { 27 chosen {
28 bootargs = "console=ttySC6,115200 ignore_loglevel rw root=/dev/nfs ip=dhcp"; 28 bootargs = "ignore_loglevel rw root=/dev/nfs ip=dhcp";
29 stdout-path = &scif0;
29 }; 30 };
30 31
31 memory@40000000 { 32 memory@40000000 {
@@ -211,14 +212,24 @@
211 }; 212 };
212}; 213};
213 214
215&du {
216 pinctrl-0 = <&du_pins>;
217 pinctrl-names = "default";
218 status = "okay";
219
220 ports {
221 port@1 {
222 lvds_connector: endpoint {
223 };
224 };
225 };
226};
227
214&extal_clk { 228&extal_clk {
215 clock-frequency = <20000000>; 229 clock-frequency = <20000000>;
216}; 230};
217 231
218&pfc { 232&pfc {
219 pinctrl-0 = <&du_pins>;
220 pinctrl-names = "default";
221
222 i2c2_pins: i2c2 { 233 i2c2_pins: i2c2 {
223 renesas,groups = "i2c2"; 234 renesas,groups = "i2c2";
224 renesas,function = "i2c2"; 235 renesas,function = "i2c2";
diff --git a/arch/arm/boot/dts/r8a7791.dtsi b/arch/arm/boot/dts/r8a7791.dtsi
index e06c11fa8698..e4a7170f368b 100644
--- a/arch/arm/boot/dts/r8a7791.dtsi
+++ b/arch/arm/boot/dts/r8a7791.dtsi
@@ -637,6 +637,75 @@
637 status = "disabled"; 637 status = "disabled";
638 }; 638 };
639 639
640 vsp1@fe928000 {
641 compatible = "renesas,vsp1";
642 reg = <0 0xfe928000 0 0x8000>;
643 interrupts = <0 267 IRQ_TYPE_LEVEL_HIGH>;
644 clocks = <&mstp1_clks R8A7791_CLK_VSP1_S>;
645
646 renesas,has-lut;
647 renesas,has-sru;
648 renesas,#rpf = <5>;
649 renesas,#uds = <3>;
650 renesas,#wpf = <4>;
651 };
652
653 vsp1@fe930000 {
654 compatible = "renesas,vsp1";
655 reg = <0 0xfe930000 0 0x8000>;
656 interrupts = <0 246 IRQ_TYPE_LEVEL_HIGH>;
657 clocks = <&mstp1_clks R8A7791_CLK_VSP1_DU0>;
658
659 renesas,has-lif;
660 renesas,has-lut;
661 renesas,#rpf = <4>;
662 renesas,#uds = <1>;
663 renesas,#wpf = <4>;
664 };
665
666 vsp1@fe938000 {
667 compatible = "renesas,vsp1";
668 reg = <0 0xfe938000 0 0x8000>;
669 interrupts = <0 247 IRQ_TYPE_LEVEL_HIGH>;
670 clocks = <&mstp1_clks R8A7791_CLK_VSP1_DU1>;
671
672 renesas,has-lif;
673 renesas,has-lut;
674 renesas,#rpf = <4>;
675 renesas,#uds = <1>;
676 renesas,#wpf = <4>;
677 };
678
679 du: display@feb00000 {
680 compatible = "renesas,du-r8a7791";
681 reg = <0 0xfeb00000 0 0x40000>,
682 <0 0xfeb90000 0 0x1c>;
683 reg-names = "du", "lvds.0";
684 interrupts = <0 256 IRQ_TYPE_LEVEL_HIGH>,
685 <0 268 IRQ_TYPE_LEVEL_HIGH>;
686 clocks = <&mstp7_clks R8A7791_CLK_DU0>,
687 <&mstp7_clks R8A7791_CLK_DU1>,
688 <&mstp7_clks R8A7791_CLK_LVDS0>;
689 clock-names = "du.0", "du.1", "lvds.0";
690 status = "disabled";
691
692 ports {
693 #address-cells = <1>;
694 #size-cells = <0>;
695
696 port@0 {
697 reg = <0>;
698 du_out_rgb: endpoint {
699 };
700 };
701 port@1 {
702 reg = <1>;
703 du_out_lvds0: endpoint {
704 };
705 };
706 };
707 };
708
640 clocks { 709 clocks {
641 #address-cells = <2>; 710 #address-cells = <2>;
642 #size-cells = <2>; 711 #size-cells = <2>;
diff --git a/arch/arm/boot/dts/r8a7794-alt.dts b/arch/arm/boot/dts/r8a7794-alt.dts
index 79d06ef017a0..8aec51268b7d 100644
--- a/arch/arm/boot/dts/r8a7794-alt.dts
+++ b/arch/arm/boot/dts/r8a7794-alt.dts
@@ -21,6 +21,7 @@
21 21
22 chosen { 22 chosen {
23 bootargs = "console=ttySC0,38400 ignore_loglevel rw root=/dev/nfs ip=dhcp"; 23 bootargs = "console=ttySC0,38400 ignore_loglevel rw root=/dev/nfs ip=dhcp";
24 stdout-path = &scif2;
24 }; 25 };
25 26
26 memory@40000000 { 27 memory@40000000 {
diff --git a/arch/arm/boot/dts/r8a77xx-aa104xd12-panel.dtsi b/arch/arm/boot/dts/r8a77xx-aa104xd12-panel.dtsi
new file mode 100644
index 000000000000..65cb50f0c29f
--- /dev/null
+++ b/arch/arm/boot/dts/r8a77xx-aa104xd12-panel.dtsi
@@ -0,0 +1,41 @@
1/*
2 * Common file for the AA104XD12 panel connected to Renesas R-Car boards
3 *
4 * Copyright (C) 2014 Renesas Electronics Corp.
5 *
6 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of any
8 * kind, whether express or implied.
9 */
10
11/ {
12 panel {
13 compatible = "mitsubishi,aa104xd12", "panel-dpi";
14
15 width-mm = <210>;
16 height-mm = <158>;
17
18 panel-timing {
19 /* 1024x768 @65Hz */
20 clock-frequency = <65000000>;
21 hactive = <1024>;
22 vactive = <768>;
23 hsync-len = <136>;
24 hfront-porch = <20>;
25 hback-porch = <160>;
26 vfront-porch = <3>;
27 vback-porch = <29>;
28 vsync-len = <6>;
29 };
30
31 port {
32 panel_in: endpoint {
33 remote-endpoint = <&lvds_connector>;
34 };
35 };
36 };
37};
38
39&lvds_connector {
40 remote-endpoint = <&panel_in>;
41};
diff --git a/arch/arm/boot/dts/sama5d31.dtsi b/arch/arm/boot/dts/sama5d31.dtsi
index 7997dc9863ed..883878b32971 100644
--- a/arch/arm/boot/dts/sama5d31.dtsi
+++ b/arch/arm/boot/dts/sama5d31.dtsi
@@ -12,5 +12,5 @@
12#include "sama5d3_uart.dtsi" 12#include "sama5d3_uart.dtsi"
13 13
14/ { 14/ {
15 compatible = "atmel,samad31", "atmel,sama5d3", "atmel,sama5"; 15 compatible = "atmel,sama5d31", "atmel,sama5d3", "atmel,sama5";
16}; 16};
diff --git a/arch/arm/boot/dts/sama5d33.dtsi b/arch/arm/boot/dts/sama5d33.dtsi
index 39f832253caf..4b4434aca351 100644
--- a/arch/arm/boot/dts/sama5d33.dtsi
+++ b/arch/arm/boot/dts/sama5d33.dtsi
@@ -10,5 +10,5 @@
10#include "sama5d3_gmac.dtsi" 10#include "sama5d3_gmac.dtsi"
11 11
12/ { 12/ {
13 compatible = "atmel,samad33", "atmel,sama5d3", "atmel,sama5"; 13 compatible = "atmel,sama5d33", "atmel,sama5d3", "atmel,sama5";
14}; 14};
diff --git a/arch/arm/boot/dts/sama5d34.dtsi b/arch/arm/boot/dts/sama5d34.dtsi
index 89cda2c0da39..aa01573fdee9 100644
--- a/arch/arm/boot/dts/sama5d34.dtsi
+++ b/arch/arm/boot/dts/sama5d34.dtsi
@@ -12,5 +12,5 @@
12#include "sama5d3_mci2.dtsi" 12#include "sama5d3_mci2.dtsi"
13 13
14/ { 14/ {
15 compatible = "atmel,samad34", "atmel,sama5d3", "atmel,sama5"; 15 compatible = "atmel,sama5d34", "atmel,sama5d3", "atmel,sama5";
16}; 16};
diff --git a/arch/arm/boot/dts/sama5d35.dtsi b/arch/arm/boot/dts/sama5d35.dtsi
index d20cd71b5f0e..16c39f4c96a4 100644
--- a/arch/arm/boot/dts/sama5d35.dtsi
+++ b/arch/arm/boot/dts/sama5d35.dtsi
@@ -14,5 +14,5 @@
14#include "sama5d3_tcb1.dtsi" 14#include "sama5d3_tcb1.dtsi"
15 15
16/ { 16/ {
17 compatible = "atmel,samad35", "atmel,sama5d3", "atmel,sama5"; 17 compatible = "atmel,sama5d35", "atmel,sama5d3", "atmel,sama5";
18}; 18};
diff --git a/arch/arm/boot/dts/sama5d36.dtsi b/arch/arm/boot/dts/sama5d36.dtsi
index db58cad6acd3..e85139ef40af 100644
--- a/arch/arm/boot/dts/sama5d36.dtsi
+++ b/arch/arm/boot/dts/sama5d36.dtsi
@@ -16,5 +16,5 @@
16#include "sama5d3_uart.dtsi" 16#include "sama5d3_uart.dtsi"
17 17
18/ { 18/ {
19 compatible = "atmel,samad36", "atmel,sama5d3", "atmel,sama5"; 19 compatible = "atmel,sama5d36", "atmel,sama5d3", "atmel,sama5";
20}; 20};
diff --git a/arch/arm/boot/dts/sama5d3xcm.dtsi b/arch/arm/boot/dts/sama5d3xcm.dtsi
index 962dc28dc37b..cfcd200b0c17 100644
--- a/arch/arm/boot/dts/sama5d3xcm.dtsi
+++ b/arch/arm/boot/dts/sama5d3xcm.dtsi
@@ -8,7 +8,7 @@
8 */ 8 */
9 9
10/ { 10/ {
11 compatible = "atmel,samad3xcm", "atmel,sama5d3", "atmel,sama5"; 11 compatible = "atmel,sama5d3xcm", "atmel,sama5d3", "atmel,sama5";
12 12
13 chosen { 13 chosen {
14 bootargs = "console=ttyS0,115200 rootfstype=ubifs ubi.mtd=5 root=ubi0:rootfs"; 14 bootargs = "console=ttyS0,115200 rootfstype=ubifs ubi.mtd=5 root=ubi0:rootfs";
diff --git a/arch/arm/boot/dts/sh73a0-kzm9g-reference.dts b/arch/arm/boot/dts/sh73a0-kzm9g-reference.dts
index 30ef97e99dc5..0dac0e66ccad 100644
--- a/arch/arm/boot/dts/sh73a0-kzm9g-reference.dts
+++ b/arch/arm/boot/dts/sh73a0-kzm9g-reference.dts
@@ -40,6 +40,7 @@
40 40
41 chosen { 41 chosen {
42 bootargs = "console=tty0 console=ttySC4,115200 root=/dev/nfs ip=dhcp ignore_loglevel rw"; 42 bootargs = "console=tty0 console=ttySC4,115200 root=/dev/nfs ip=dhcp ignore_loglevel rw";
43 stdout-path = &scifa4;
43 }; 44 };
44 45
45 memory { 46 memory {
diff --git a/arch/arm/boot/dts/sun6i-a31.dtsi b/arch/arm/boot/dts/sun6i-a31.dtsi
index 543f895d18d3..2e652e2339e9 100644
--- a/arch/arm/boot/dts/sun6i-a31.dtsi
+++ b/arch/arm/boot/dts/sun6i-a31.dtsi
@@ -361,6 +361,10 @@
361 clocks = <&ahb1_gates 6>; 361 clocks = <&ahb1_gates 6>;
362 resets = <&ahb1_rst 6>; 362 resets = <&ahb1_rst 6>;
363 #dma-cells = <1>; 363 #dma-cells = <1>;
364
365 /* DMA controller requires AHB1 clocked from PLL6 */
366 assigned-clocks = <&ahb1_mux>;
367 assigned-clock-parents = <&pll6>;
364 }; 368 };
365 369
366 mmc0: mmc@01c0f000 { 370 mmc0: mmc@01c0f000 {
diff --git a/arch/arm/boot/dts/tegra114-dalmore.dts b/arch/arm/boot/dts/tegra114-dalmore.dts
index 5c21d216515a..8b7aa0dcdc6e 100644
--- a/arch/arm/boot/dts/tegra114-dalmore.dts
+++ b/arch/arm/boot/dts/tegra114-dalmore.dts
@@ -15,6 +15,7 @@
15 aliases { 15 aliases {
16 rtc0 = "/i2c@7000d000/tps65913@58"; 16 rtc0 = "/i2c@7000d000/tps65913@58";
17 rtc1 = "/rtc@7000e000"; 17 rtc1 = "/rtc@7000e000";
18 serial0 = &uartd;
18 }; 19 };
19 20
20 memory { 21 memory {
diff --git a/arch/arm/boot/dts/tegra114-roth.dts b/arch/arm/boot/dts/tegra114-roth.dts
index c7c6825f11fb..38acf78d7815 100644
--- a/arch/arm/boot/dts/tegra114-roth.dts
+++ b/arch/arm/boot/dts/tegra114-roth.dts
@@ -15,6 +15,10 @@
15 linux,initrd-end = <0x82800000>; 15 linux,initrd-end = <0x82800000>;
16 }; 16 };
17 17
18 aliases {
19 serial0 = &uartd;
20 };
21
18 firmware { 22 firmware {
19 trusted-foundations { 23 trusted-foundations {
20 compatible = "tlm,trusted-foundations"; 24 compatible = "tlm,trusted-foundations";
@@ -916,8 +920,6 @@
916 regulator-name = "vddio-sdmmc3"; 920 regulator-name = "vddio-sdmmc3";
917 regulator-min-microvolt = <1800000>; 921 regulator-min-microvolt = <1800000>;
918 regulator-max-microvolt = <3300000>; 922 regulator-max-microvolt = <3300000>;
919 regulator-always-on;
920 regulator-boot-on;
921 }; 923 };
922 924
923 ldousb { 925 ldousb {
@@ -962,7 +964,7 @@
962 sdhci@78000400 { 964 sdhci@78000400 {
963 status = "okay"; 965 status = "okay";
964 bus-width = <4>; 966 bus-width = <4>;
965 vmmc-supply = <&vddio_sdmmc3>; 967 vqmmc-supply = <&vddio_sdmmc3>;
966 cd-gpios = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_LOW>; 968 cd-gpios = <&gpio TEGRA_GPIO(V, 2) GPIO_ACTIVE_LOW>;
967 power-gpios = <&gpio TEGRA_GPIO(H, 0) GPIO_ACTIVE_HIGH>; 969 power-gpios = <&gpio TEGRA_GPIO(H, 0) GPIO_ACTIVE_HIGH>;
968 }; 970 };
@@ -971,7 +973,6 @@
971 sdhci@78000600 { 973 sdhci@78000600 {
972 status = "okay"; 974 status = "okay";
973 bus-width = <8>; 975 bus-width = <8>;
974 vmmc-supply = <&vdd_1v8>;
975 non-removable; 976 non-removable;
976 }; 977 };
977 978
diff --git a/arch/arm/boot/dts/tegra114-tn7.dts b/arch/arm/boot/dts/tegra114-tn7.dts
index 963662145635..f91c2c9b2f94 100644
--- a/arch/arm/boot/dts/tegra114-tn7.dts
+++ b/arch/arm/boot/dts/tegra114-tn7.dts
@@ -15,6 +15,10 @@
15 linux,initrd-end = <0x82800000>; 15 linux,initrd-end = <0x82800000>;
16 }; 16 };
17 17
18 aliases {
19 serial0 = &uartd;
20 };
21
18 firmware { 22 firmware {
19 trusted-foundations { 23 trusted-foundations {
20 compatible = "tlm,trusted-foundations"; 24 compatible = "tlm,trusted-foundations";
@@ -240,7 +244,6 @@
240 sdhci@78000600 { 244 sdhci@78000600 {
241 status = "okay"; 245 status = "okay";
242 bus-width = <8>; 246 bus-width = <8>;
243 vmmc-supply = <&vdd_1v8>;
244 non-removable; 247 non-removable;
245 }; 248 };
246 249
diff --git a/arch/arm/boot/dts/tegra114.dtsi b/arch/arm/boot/dts/tegra114.dtsi
index 2ca9c1807f72..222f3b3f4dd5 100644
--- a/arch/arm/boot/dts/tegra114.dtsi
+++ b/arch/arm/boot/dts/tegra114.dtsi
@@ -9,13 +9,6 @@
9 compatible = "nvidia,tegra114"; 9 compatible = "nvidia,tegra114";
10 interrupt-parent = <&gic>; 10 interrupt-parent = <&gic>;
11 11
12 aliases {
13 serial0 = &uarta;
14 serial1 = &uartb;
15 serial2 = &uartc;
16 serial3 = &uartd;
17 };
18
19 host1x@50000000 { 12 host1x@50000000 {
20 compatible = "nvidia,tegra114-host1x", "simple-bus"; 13 compatible = "nvidia,tegra114-host1x", "simple-bus";
21 reg = <0x50000000 0x00028000>; 14 reg = <0x50000000 0x00028000>;
diff --git a/arch/arm/boot/dts/tegra124-jetson-tk1.dts b/arch/arm/boot/dts/tegra124-jetson-tk1.dts
index 029c9a021541..51b373ff1065 100644
--- a/arch/arm/boot/dts/tegra124-jetson-tk1.dts
+++ b/arch/arm/boot/dts/tegra124-jetson-tk1.dts
@@ -10,6 +10,7 @@
10 aliases { 10 aliases {
11 rtc0 = "/i2c@0,7000d000/pmic@40"; 11 rtc0 = "/i2c@0,7000d000/pmic@40";
12 rtc1 = "/rtc@0,7000e000"; 12 rtc1 = "/rtc@0,7000e000";
13 serial0 = &uartd;
13 }; 14 };
14 15
15 memory { 16 memory {
diff --git a/arch/arm/boot/dts/tegra124-nyan-big.dts b/arch/arm/boot/dts/tegra124-nyan-big.dts
index 7d0784ce4c74..53181d310247 100644
--- a/arch/arm/boot/dts/tegra124-nyan-big.dts
+++ b/arch/arm/boot/dts/tegra124-nyan-big.dts
@@ -10,6 +10,7 @@
10 aliases { 10 aliases {
11 rtc0 = "/i2c@0,7000d000/pmic@40"; 11 rtc0 = "/i2c@0,7000d000/pmic@40";
12 rtc1 = "/rtc@0,7000e000"; 12 rtc1 = "/rtc@0,7000e000";
13 serial0 = &uarta;
13 }; 14 };
14 15
15 memory { 16 memory {
diff --git a/arch/arm/boot/dts/tegra124-venice2.dts b/arch/arm/boot/dts/tegra124-venice2.dts
index 13008858e967..5c3f7813360d 100644
--- a/arch/arm/boot/dts/tegra124-venice2.dts
+++ b/arch/arm/boot/dts/tegra124-venice2.dts
@@ -10,6 +10,7 @@
10 aliases { 10 aliases {
11 rtc0 = "/i2c@0,7000d000/pmic@40"; 11 rtc0 = "/i2c@0,7000d000/pmic@40";
12 rtc1 = "/rtc@0,7000e000"; 12 rtc1 = "/rtc@0,7000e000";
13 serial0 = &uarta;
13 }; 14 };
14 15
15 memory { 16 memory {
diff --git a/arch/arm/boot/dts/tegra124.dtsi b/arch/arm/boot/dts/tegra124.dtsi
index 478c555ebd96..df2b06b29985 100644
--- a/arch/arm/boot/dts/tegra124.dtsi
+++ b/arch/arm/boot/dts/tegra124.dtsi
@@ -286,7 +286,7 @@
286 * the APB DMA based serial driver, the comptible is 286 * the APB DMA based serial driver, the comptible is
287 * "nvidia,tegra124-hsuart", "nvidia,tegra30-hsuart". 287 * "nvidia,tegra124-hsuart", "nvidia,tegra30-hsuart".
288 */ 288 */
289 serial@0,70006000 { 289 uarta: serial@0,70006000 {
290 compatible = "nvidia,tegra124-uart", "nvidia,tegra20-uart"; 290 compatible = "nvidia,tegra124-uart", "nvidia,tegra20-uart";
291 reg = <0x0 0x70006000 0x0 0x40>; 291 reg = <0x0 0x70006000 0x0 0x40>;
292 reg-shift = <2>; 292 reg-shift = <2>;
@@ -299,7 +299,7 @@
299 status = "disabled"; 299 status = "disabled";
300 }; 300 };
301 301
302 serial@0,70006040 { 302 uartb: serial@0,70006040 {
303 compatible = "nvidia,tegra124-uart", "nvidia,tegra20-uart"; 303 compatible = "nvidia,tegra124-uart", "nvidia,tegra20-uart";
304 reg = <0x0 0x70006040 0x0 0x40>; 304 reg = <0x0 0x70006040 0x0 0x40>;
305 reg-shift = <2>; 305 reg-shift = <2>;
@@ -312,7 +312,7 @@
312 status = "disabled"; 312 status = "disabled";
313 }; 313 };
314 314
315 serial@0,70006200 { 315 uartc: serial@0,70006200 {
316 compatible = "nvidia,tegra124-uart", "nvidia,tegra20-uart"; 316 compatible = "nvidia,tegra124-uart", "nvidia,tegra20-uart";
317 reg = <0x0 0x70006200 0x0 0x40>; 317 reg = <0x0 0x70006200 0x0 0x40>;
318 reg-shift = <2>; 318 reg-shift = <2>;
@@ -325,7 +325,7 @@
325 status = "disabled"; 325 status = "disabled";
326 }; 326 };
327 327
328 serial@0,70006300 { 328 uartd: serial@0,70006300 {
329 compatible = "nvidia,tegra124-uart", "nvidia,tegra20-uart"; 329 compatible = "nvidia,tegra124-uart", "nvidia,tegra20-uart";
330 reg = <0x0 0x70006300 0x0 0x40>; 330 reg = <0x0 0x70006300 0x0 0x40>;
331 reg-shift = <2>; 331 reg-shift = <2>;
diff --git a/arch/arm/boot/dts/tegra20-harmony.dts b/arch/arm/boot/dts/tegra20-harmony.dts
index a37279af687c..b926a07b9443 100644
--- a/arch/arm/boot/dts/tegra20-harmony.dts
+++ b/arch/arm/boot/dts/tegra20-harmony.dts
@@ -10,6 +10,7 @@
10 aliases { 10 aliases {
11 rtc0 = "/i2c@7000d000/tps6586x@34"; 11 rtc0 = "/i2c@7000d000/tps6586x@34";
12 rtc1 = "/rtc@7000e000"; 12 rtc1 = "/rtc@7000e000";
13 serial0 = &uartd;
13 }; 14 };
14 15
15 memory { 16 memory {
diff --git a/arch/arm/boot/dts/tegra20-iris-512.dts b/arch/arm/boot/dts/tegra20-iris-512.dts
index 8cfb83f42e1f..1dd7d7bfdfcc 100644
--- a/arch/arm/boot/dts/tegra20-iris-512.dts
+++ b/arch/arm/boot/dts/tegra20-iris-512.dts
@@ -6,6 +6,11 @@
6 model = "Toradex Colibri T20 512MB on Iris"; 6 model = "Toradex Colibri T20 512MB on Iris";
7 compatible = "toradex,iris", "toradex,colibri_t20-512", "nvidia,tegra20"; 7 compatible = "toradex,iris", "toradex,colibri_t20-512", "nvidia,tegra20";
8 8
9 aliases {
10 serial0 = &uarta;
11 serial1 = &uartd;
12 };
13
9 host1x@50000000 { 14 host1x@50000000 {
10 hdmi@54280000 { 15 hdmi@54280000 {
11 status = "okay"; 16 status = "okay";
diff --git a/arch/arm/boot/dts/tegra20-medcom-wide.dts b/arch/arm/boot/dts/tegra20-medcom-wide.dts
index 1b7c56b33aca..9b87526ab0b7 100644
--- a/arch/arm/boot/dts/tegra20-medcom-wide.dts
+++ b/arch/arm/boot/dts/tegra20-medcom-wide.dts
@@ -6,6 +6,10 @@
6 model = "Avionic Design Medcom-Wide board"; 6 model = "Avionic Design Medcom-Wide board";
7 compatible = "ad,medcom-wide", "ad,tamonten", "nvidia,tegra20"; 7 compatible = "ad,medcom-wide", "ad,tamonten", "nvidia,tegra20";
8 8
9 aliases {
10 serial0 = &uartd;
11 };
12
9 pwm@7000a000 { 13 pwm@7000a000 {
10 status = "okay"; 14 status = "okay";
11 }; 15 };
diff --git a/arch/arm/boot/dts/tegra20-paz00.dts b/arch/arm/boot/dts/tegra20-paz00.dts
index d4438e30de45..ed7e1009326c 100644
--- a/arch/arm/boot/dts/tegra20-paz00.dts
+++ b/arch/arm/boot/dts/tegra20-paz00.dts
@@ -10,6 +10,8 @@
10 aliases { 10 aliases {
11 rtc0 = "/i2c@7000d000/tps6586x@34"; 11 rtc0 = "/i2c@7000d000/tps6586x@34";
12 rtc1 = "/rtc@7000e000"; 12 rtc1 = "/rtc@7000e000";
13 serial0 = &uarta;
14 serial1 = &uartc;
13 }; 15 };
14 16
15 memory { 17 memory {
diff --git a/arch/arm/boot/dts/tegra20-seaboard.dts b/arch/arm/boot/dts/tegra20-seaboard.dts
index a1d4bf9895d7..ea282c7c0ca5 100644
--- a/arch/arm/boot/dts/tegra20-seaboard.dts
+++ b/arch/arm/boot/dts/tegra20-seaboard.dts
@@ -10,6 +10,7 @@
10 aliases { 10 aliases {
11 rtc0 = "/i2c@7000d000/tps6586x@34"; 11 rtc0 = "/i2c@7000d000/tps6586x@34";
12 rtc1 = "/rtc@7000e000"; 12 rtc1 = "/rtc@7000e000";
13 serial0 = &uartd;
13 }; 14 };
14 15
15 memory { 16 memory {
diff --git a/arch/arm/boot/dts/tegra20-tamonten.dtsi b/arch/arm/boot/dts/tegra20-tamonten.dtsi
index 80e7d386ce34..13d4e6185275 100644
--- a/arch/arm/boot/dts/tegra20-tamonten.dtsi
+++ b/arch/arm/boot/dts/tegra20-tamonten.dtsi
@@ -7,6 +7,7 @@
7 aliases { 7 aliases {
8 rtc0 = "/i2c@7000d000/tps6586x@34"; 8 rtc0 = "/i2c@7000d000/tps6586x@34";
9 rtc1 = "/rtc@7000e000"; 9 rtc1 = "/rtc@7000e000";
10 serial0 = &uartd;
10 }; 11 };
11 12
12 memory { 13 memory {
diff --git a/arch/arm/boot/dts/tegra20-trimslice.dts b/arch/arm/boot/dts/tegra20-trimslice.dts
index 5ad87979ab13..d99af4ef9c64 100644
--- a/arch/arm/boot/dts/tegra20-trimslice.dts
+++ b/arch/arm/boot/dts/tegra20-trimslice.dts
@@ -10,6 +10,7 @@
10 aliases { 10 aliases {
11 rtc0 = "/i2c@7000c500/rtc@56"; 11 rtc0 = "/i2c@7000c500/rtc@56";
12 rtc1 = "/rtc@7000e000"; 12 rtc1 = "/rtc@7000e000";
13 serial0 = &uarta;
13 }; 14 };
14 15
15 memory { 16 memory {
diff --git a/arch/arm/boot/dts/tegra20-ventana.dts b/arch/arm/boot/dts/tegra20-ventana.dts
index ca8484cccddc..04c58e9ca490 100644
--- a/arch/arm/boot/dts/tegra20-ventana.dts
+++ b/arch/arm/boot/dts/tegra20-ventana.dts
@@ -10,6 +10,7 @@
10 aliases { 10 aliases {
11 rtc0 = "/i2c@7000d000/tps6586x@34"; 11 rtc0 = "/i2c@7000d000/tps6586x@34";
12 rtc1 = "/rtc@7000e000"; 12 rtc1 = "/rtc@7000e000";
13 serial0 = &uartd;
13 }; 14 };
14 15
15 memory { 16 memory {
diff --git a/arch/arm/boot/dts/tegra20-whistler.dts b/arch/arm/boot/dts/tegra20-whistler.dts
index 1843725785c9..340d81108df1 100644
--- a/arch/arm/boot/dts/tegra20-whistler.dts
+++ b/arch/arm/boot/dts/tegra20-whistler.dts
@@ -10,6 +10,7 @@
10 aliases { 10 aliases {
11 rtc0 = "/i2c@7000d000/max8907@3c"; 11 rtc0 = "/i2c@7000d000/max8907@3c";
12 rtc1 = "/rtc@7000e000"; 12 rtc1 = "/rtc@7000e000";
13 serial0 = &uarta;
13 }; 14 };
14 15
15 memory { 16 memory {
diff --git a/arch/arm/boot/dts/tegra20.dtsi b/arch/arm/boot/dts/tegra20.dtsi
index 3b374c49d04d..8acf5d85c99d 100644
--- a/arch/arm/boot/dts/tegra20.dtsi
+++ b/arch/arm/boot/dts/tegra20.dtsi
@@ -9,14 +9,6 @@
9 compatible = "nvidia,tegra20"; 9 compatible = "nvidia,tegra20";
10 interrupt-parent = <&intc>; 10 interrupt-parent = <&intc>;
11 11
12 aliases {
13 serial0 = &uarta;
14 serial1 = &uartb;
15 serial2 = &uartc;
16 serial3 = &uartd;
17 serial4 = &uarte;
18 };
19
20 host1x@50000000 { 12 host1x@50000000 {
21 compatible = "nvidia,tegra20-host1x", "simple-bus"; 13 compatible = "nvidia,tegra20-host1x", "simple-bus";
22 reg = <0x50000000 0x00024000>; 14 reg = <0x50000000 0x00024000>;
diff --git a/arch/arm/boot/dts/tegra30-apalis-eval.dts b/arch/arm/boot/dts/tegra30-apalis-eval.dts
index 45d40f024585..6236bdecb48b 100644
--- a/arch/arm/boot/dts/tegra30-apalis-eval.dts
+++ b/arch/arm/boot/dts/tegra30-apalis-eval.dts
@@ -11,6 +11,10 @@
11 rtc0 = "/i2c@7000c000/rtc@68"; 11 rtc0 = "/i2c@7000c000/rtc@68";
12 rtc1 = "/i2c@7000d000/tps65911@2d"; 12 rtc1 = "/i2c@7000d000/tps65911@2d";
13 rtc2 = "/rtc@7000e000"; 13 rtc2 = "/rtc@7000e000";
14 serial0 = &uarta;
15 serial1 = &uartb;
16 serial2 = &uartc;
17 serial3 = &uartd;
14 }; 18 };
15 19
16 pcie-controller@00003000 { 20 pcie-controller@00003000 {
diff --git a/arch/arm/boot/dts/tegra30-beaver.dts b/arch/arm/boot/dts/tegra30-beaver.dts
index cee8f2246fdb..6b157eeabcc5 100644
--- a/arch/arm/boot/dts/tegra30-beaver.dts
+++ b/arch/arm/boot/dts/tegra30-beaver.dts
@@ -9,6 +9,7 @@
9 aliases { 9 aliases {
10 rtc0 = "/i2c@7000d000/tps65911@2d"; 10 rtc0 = "/i2c@7000d000/tps65911@2d";
11 rtc1 = "/rtc@7000e000"; 11 rtc1 = "/rtc@7000e000";
12 serial0 = &uarta;
12 }; 13 };
13 14
14 memory { 15 memory {
diff --git a/arch/arm/boot/dts/tegra30-cardhu.dtsi b/arch/arm/boot/dts/tegra30-cardhu.dtsi
index 206379546244..a1b682ea01bd 100644
--- a/arch/arm/boot/dts/tegra30-cardhu.dtsi
+++ b/arch/arm/boot/dts/tegra30-cardhu.dtsi
@@ -30,6 +30,8 @@
30 aliases { 30 aliases {
31 rtc0 = "/i2c@7000d000/tps65911@2d"; 31 rtc0 = "/i2c@7000d000/tps65911@2d";
32 rtc1 = "/rtc@7000e000"; 32 rtc1 = "/rtc@7000e000";
33 serial0 = &uarta;
34 serial1 = &uartc;
33 }; 35 };
34 36
35 memory { 37 memory {
diff --git a/arch/arm/boot/dts/tegra30-colibri-eval-v3.dts b/arch/arm/boot/dts/tegra30-colibri-eval-v3.dts
index 7793abd5bef1..4d3ddc585641 100644
--- a/arch/arm/boot/dts/tegra30-colibri-eval-v3.dts
+++ b/arch/arm/boot/dts/tegra30-colibri-eval-v3.dts
@@ -10,6 +10,9 @@
10 rtc0 = "/i2c@7000c000/rtc@68"; 10 rtc0 = "/i2c@7000c000/rtc@68";
11 rtc1 = "/i2c@7000d000/tps65911@2d"; 11 rtc1 = "/i2c@7000d000/tps65911@2d";
12 rtc2 = "/rtc@7000e000"; 12 rtc2 = "/rtc@7000e000";
13 serial0 = &uarta;
14 serial1 = &uartb;
15 serial2 = &uartd;
13 }; 16 };
14 17
15 host1x@50000000 { 18 host1x@50000000 {
diff --git a/arch/arm/boot/dts/tegra30.dtsi b/arch/arm/boot/dts/tegra30.dtsi
index aa6ccea13d30..b270b9e3d455 100644
--- a/arch/arm/boot/dts/tegra30.dtsi
+++ b/arch/arm/boot/dts/tegra30.dtsi
@@ -9,14 +9,6 @@
9 compatible = "nvidia,tegra30"; 9 compatible = "nvidia,tegra30";
10 interrupt-parent = <&intc>; 10 interrupt-parent = <&intc>;
11 11
12 aliases {
13 serial0 = &uarta;
14 serial1 = &uartb;
15 serial2 = &uartc;
16 serial3 = &uartd;
17 serial4 = &uarte;
18 };
19
20 pcie-controller@00003000 { 12 pcie-controller@00003000 {
21 compatible = "nvidia,tegra30-pcie"; 13 compatible = "nvidia,tegra30-pcie";
22 device_type = "pci"; 14 device_type = "pci";
diff --git a/arch/arm/boot/dts/vf610-cosmic.dts b/arch/arm/boot/dts/vf610-cosmic.dts
index 3fd1b74e1216..de1b453c2932 100644
--- a/arch/arm/boot/dts/vf610-cosmic.dts
+++ b/arch/arm/boot/dts/vf610-cosmic.dts
@@ -33,6 +33,13 @@
33 33
34}; 34};
35 35
36&esdhc1 {
37 pinctrl-names = "default";
38 pinctrl-0 = <&pinctrl_esdhc1>;
39 bus-width = <4>;
40 status = "okay";
41};
42
36&fec1 { 43&fec1 {
37 phy-mode = "rmii"; 44 phy-mode = "rmii";
38 pinctrl-names = "default"; 45 pinctrl-names = "default";
@@ -42,6 +49,18 @@
42 49
43&iomuxc { 50&iomuxc {
44 vf610-cosmic { 51 vf610-cosmic {
52 pinctrl_esdhc1: esdhc1grp {
53 fsl,pins = <
54 VF610_PAD_PTA24__ESDHC1_CLK 0x31ef
55 VF610_PAD_PTA25__ESDHC1_CMD 0x31ef
56 VF610_PAD_PTA26__ESDHC1_DAT0 0x31ef
57 VF610_PAD_PTA27__ESDHC1_DAT1 0x31ef
58 VF610_PAD_PTA28__ESDHC1_DATA2 0x31ef
59 VF610_PAD_PTA29__ESDHC1_DAT3 0x31ef
60 VF610_PAD_PTB28__GPIO_98 0x219d
61 >;
62 };
63
45 pinctrl_fec1: fec1grp { 64 pinctrl_fec1: fec1grp {
46 fsl,pins = < 65 fsl,pins = <
47 VF610_PAD_PTC9__ENET_RMII1_MDC 0x30d2 66 VF610_PAD_PTC9__ENET_RMII1_MDC 0x30d2
diff --git a/arch/arm/boot/dts/zynq-parallella.dts b/arch/arm/boot/dts/zynq-parallella.dts
index e1f51ca127fe..0429bbd89fba 100644
--- a/arch/arm/boot/dts/zynq-parallella.dts
+++ b/arch/arm/boot/dts/zynq-parallella.dts
@@ -34,6 +34,10 @@
34 }; 34 };
35}; 35};
36 36
37&clkc {
38 fclk-enable = <0xf>;
39};
40
37&gem0 { 41&gem0 {
38 status = "okay"; 42 status = "okay";
39 phy-mode = "rgmii-id"; 43 phy-mode = "rgmii-id";
diff --git a/arch/arm/common/edma.c b/arch/arm/common/edma.c
index d86771abbf57..72041f002b7e 100644
--- a/arch/arm/common/edma.c
+++ b/arch/arm/common/edma.c
@@ -26,6 +26,7 @@
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/edma.h> 28#include <linux/edma.h>
29#include <linux/dma-mapping.h>
29#include <linux/of_address.h> 30#include <linux/of_address.h>
30#include <linux/of_device.h> 31#include <linux/of_device.h>
31#include <linux/of_dma.h> 32#include <linux/of_dma.h>
@@ -1623,6 +1624,11 @@ static int edma_probe(struct platform_device *pdev)
1623 struct device_node *node = pdev->dev.of_node; 1624 struct device_node *node = pdev->dev.of_node;
1624 struct device *dev = &pdev->dev; 1625 struct device *dev = &pdev->dev;
1625 int ret; 1626 int ret;
1627 struct platform_device_info edma_dev_info = {
1628 .name = "edma-dma-engine",
1629 .dma_mask = DMA_BIT_MASK(32),
1630 .parent = &pdev->dev,
1631 };
1626 1632
1627 if (node) { 1633 if (node) {
1628 /* Check if this is a second instance registered */ 1634 /* Check if this is a second instance registered */
@@ -1793,6 +1799,9 @@ static int edma_probe(struct platform_device *pdev)
1793 edma_write_array(j, EDMA_QRAE, i, 0x0); 1799 edma_write_array(j, EDMA_QRAE, i, 0x0);
1794 } 1800 }
1795 arch_num_cc++; 1801 arch_num_cc++;
1802
1803 edma_dev_info.id = j;
1804 platform_device_register_full(&edma_dev_info);
1796 } 1805 }
1797 1806
1798 return 0; 1807 return 0;
diff --git a/arch/arm/configs/at91rm9200_defconfig b/arch/arm/configs/at91rm9200_defconfig
deleted file mode 100644
index bf057719dab0..000000000000
--- a/arch/arm/configs/at91rm9200_defconfig
+++ /dev/null
@@ -1,161 +0,0 @@
1# CONFIG_LOCALVERSION_AUTO is not set
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y
4CONFIG_NO_HZ=y
5CONFIG_HIGH_RES_TIMERS=y
6CONFIG_IKCONFIG=y
7CONFIG_IKCONFIG_PROC=y
8CONFIG_LOG_BUF_SHIFT=14
9CONFIG_USER_NS=y
10CONFIG_BLK_DEV_INITRD=y
11CONFIG_MODULES=y
12CONFIG_MODULE_FORCE_LOAD=y
13CONFIG_MODULE_UNLOAD=y
14CONFIG_MODVERSIONS=y
15CONFIG_MODULE_SRCVERSION_ALL=y
16# CONFIG_BLK_DEV_BSG is not set
17# CONFIG_IOSCHED_CFQ is not set
18CONFIG_ARCH_AT91=y
19CONFIG_ARCH_AT91RM9200=y
20CONFIG_MACH_ONEARM=y
21CONFIG_MACH_AT91RM9200EK=y
22CONFIG_MACH_CSB337=y
23CONFIG_MACH_CSB637=y
24CONFIG_MACH_CARMEVA=y
25CONFIG_MACH_ATEB9200=y
26CONFIG_MACH_KB9200=y
27CONFIG_MACH_PICOTUX2XX=y
28CONFIG_MACH_KAFA=y
29CONFIG_MACH_ECBAT91=y
30CONFIG_MACH_YL9200=y
31CONFIG_MACH_CPUAT91=y
32CONFIG_MACH_ECO920=y
33CONFIG_MTD_AT91_DATAFLASH_CARD=y
34CONFIG_AT91_TIMER_HZ=100
35# CONFIG_ARM_THUMB is not set
36CONFIG_PCCARD=y
37CONFIG_AT91_CF=y
38CONFIG_AEABI=y
39# CONFIG_COMPACTION is not set
40CONFIG_ZBOOT_ROM_TEXT=0x10000000
41CONFIG_ZBOOT_ROM_BSS=0x20040000
42CONFIG_KEXEC=y
43CONFIG_AUTO_ZRELADDR=y
44CONFIG_FPE_NWFPE=y
45CONFIG_BINFMT_MISC=y
46CONFIG_NET=y
47CONFIG_PACKET=y
48CONFIG_UNIX=y
49CONFIG_INET=y
50CONFIG_IP_MULTICAST=y
51CONFIG_IP_PNP=y
52CONFIG_IP_PNP_DHCP=y
53CONFIG_IP_PNP_BOOTP=y
54# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
55# CONFIG_INET_XFRM_MODE_TUNNEL is not set
56# CONFIG_INET_XFRM_MODE_BEET is not set
57# CONFIG_INET_DIAG is not set
58CONFIG_IPV6=y
59CONFIG_IPV6_PRIVACY=y
60CONFIG_IPV6_ROUTER_PREF=y
61CONFIG_IPV6_ROUTE_INFO=y
62CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
63CONFIG_DEVTMPFS=y
64CONFIG_DEVTMPFS_MOUNT=y
65# CONFIG_STANDALONE is not set
66# CONFIG_PREVENT_FIRMWARE_BUILD is not set
67CONFIG_MTD=y
68CONFIG_MTD_CMDLINE_PARTS=y
69CONFIG_MTD_CHAR=y
70CONFIG_MTD_BLOCK=y
71CONFIG_MTD_CFI=y
72CONFIG_MTD_JEDECPROBE=y
73CONFIG_MTD_CFI_INTELEXT=y
74CONFIG_MTD_CFI_AMDSTD=y
75CONFIG_MTD_COMPLEX_MAPPINGS=y
76CONFIG_MTD_PHYSMAP=y
77CONFIG_MTD_PLATRAM=y
78CONFIG_MTD_DATAFLASH=y
79CONFIG_MTD_NAND=y
80CONFIG_MTD_NAND_ATMEL=y
81CONFIG_MTD_NAND_PLATFORM=y
82CONFIG_MTD_UBI=y
83CONFIG_MTD_UBI_GLUEBI=y
84CONFIG_BLK_DEV_LOOP=y
85CONFIG_BLK_DEV_RAM=y
86CONFIG_BLK_DEV_RAM_SIZE=8192
87CONFIG_NETDEVICES=y
88CONFIG_MII=y
89CONFIG_ARM_AT91_ETHER=y
90CONFIG_DAVICOM_PHY=y
91CONFIG_SMSC_PHY=y
92CONFIG_MICREL_PHY=y
93# CONFIG_WLAN is not set
94# CONFIG_INPUT_MOUSEDEV is not set
95CONFIG_INPUT_EVDEV=y
96CONFIG_KEYBOARD_GPIO=y
97# CONFIG_INPUT_MOUSE is not set
98CONFIG_INPUT_TOUCHSCREEN=y
99# CONFIG_LEGACY_PTYS is not set
100CONFIG_SERIAL_ATMEL=y
101CONFIG_SERIAL_ATMEL_CONSOLE=y
102CONFIG_HW_RANDOM=y
103CONFIG_I2C=y
104CONFIG_I2C_CHARDEV=y
105CONFIG_I2C_GPIO=y
106CONFIG_SPI=y
107CONFIG_SPI_ATMEL=y
108CONFIG_GPIO_SYSFS=y
109# CONFIG_HWMON is not set
110CONFIG_WATCHDOG=y
111CONFIG_WATCHDOG_NOWAYOUT=y
112CONFIG_AT91RM9200_WATCHDOG=y
113CONFIG_FB=y
114CONFIG_FB_MODE_HELPERS=y
115CONFIG_FB_TILEBLITTING=y
116CONFIG_FB_S1D13XXX=y
117CONFIG_BACKLIGHT_LCD_SUPPORT=y
118CONFIG_LCD_CLASS_DEVICE=y
119CONFIG_BACKLIGHT_CLASS_DEVICE=y
120# CONFIG_BACKLIGHT_GENERIC is not set
121CONFIG_FRAMEBUFFER_CONSOLE=y
122CONFIG_FONTS=y
123CONFIG_LOGO=y
124CONFIG_USB=y
125CONFIG_USB_OHCI_HCD=y
126CONFIG_USB_GADGET=y
127CONFIG_USB_AT91=y
128CONFIG_USB_G_SERIAL=y
129CONFIG_MMC=y
130CONFIG_MMC_ATMELMCI=y
131CONFIG_NEW_LEDS=y
132CONFIG_LEDS_CLASS=y
133CONFIG_LEDS_GPIO=y
134CONFIG_LEDS_TRIGGERS=y
135CONFIG_LEDS_TRIGGER_TIMER=y
136CONFIG_LEDS_TRIGGER_HEARTBEAT=y
137CONFIG_LEDS_TRIGGER_GPIO=y
138CONFIG_RTC_CLASS=y
139CONFIG_RTC_DRV_AT91RM9200=y
140CONFIG_EXT4_FS=y
141CONFIG_AUTOFS4_FS=y
142CONFIG_VFAT_FS=y
143CONFIG_TMPFS=y
144CONFIG_UBIFS_FS=y
145CONFIG_UBIFS_FS_ADVANCED_COMPR=y
146CONFIG_NFS_FS=y
147CONFIG_ROOT_NFS=y
148CONFIG_NLS_CODEPAGE_437=y
149CONFIG_NLS_CODEPAGE_850=y
150CONFIG_NLS_ISO8859_1=y
151CONFIG_NLS_UTF8=y
152CONFIG_MAGIC_SYSRQ=y
153CONFIG_DEBUG_FS=y
154CONFIG_DEBUG_KERNEL=y
155# CONFIG_FTRACE is not set
156CONFIG_DEBUG_USER=y
157CONFIG_DEBUG_LL=y
158CONFIG_EARLY_PRINTK=y
159CONFIG_CRYPTO_PCBC=y
160CONFIG_CRYPTO_SHA1=y
161CONFIG_XZ_DEC_ARMTHUMB=y
diff --git a/arch/arm/configs/at91sam9260_9g20_defconfig b/arch/arm/configs/at91sam9260_9g20_defconfig
deleted file mode 100644
index 3ada05d639ad..000000000000
--- a/arch/arm/configs/at91sam9260_9g20_defconfig
+++ /dev/null
@@ -1,145 +0,0 @@
1# CONFIG_LOCALVERSION_AUTO is not set
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y
4CONFIG_LOG_BUF_SHIFT=14
5CONFIG_BLK_DEV_INITRD=y
6CONFIG_EMBEDDED=y
7CONFIG_SLAB=y
8CONFIG_MODULES=y
9CONFIG_MODULE_UNLOAD=y
10# CONFIG_BLK_DEV_BSG is not set
11# CONFIG_IOSCHED_DEADLINE is not set
12# CONFIG_IOSCHED_CFQ is not set
13CONFIG_ARCH_AT91=y
14CONFIG_ARCH_AT91SAM9260=y
15CONFIG_MACH_AT91SAM9260EK=y
16CONFIG_MACH_CAM60=y
17CONFIG_MACH_SAM9_L9260=y
18CONFIG_MACH_AFEB9260=y
19CONFIG_MACH_CPU9260=y
20CONFIG_MACH_FLEXIBITY=y
21CONFIG_MACH_AT91SAM9G20EK=y
22CONFIG_MACH_AT91SAM9G20EK_2MMC=y
23CONFIG_MACH_CPU9G20=y
24CONFIG_MACH_ACMENETUSFOXG20=y
25CONFIG_MACH_PORTUXG20=y
26CONFIG_MACH_STAMP9G20=y
27CONFIG_MACH_PCONTROL_G20=y
28CONFIG_MACH_GSIA18S=y
29CONFIG_MACH_SNAPPER_9260=y
30CONFIG_MACH_AT91SAM9_DT=y
31CONFIG_AT91_SLOW_CLOCK=y
32# CONFIG_ARM_THUMB is not set
33CONFIG_AEABI=y
34CONFIG_ZBOOT_ROM_TEXT=0x0
35CONFIG_ZBOOT_ROM_BSS=0x0
36CONFIG_ARM_APPENDED_DTB=y
37CONFIG_ARM_ATAG_DTB_COMPAT=y
38CONFIG_CMDLINE="mem=64M console=ttyS0,115200 initrd=0x21100000,3145728 root=/dev/ram0 rw"
39CONFIG_AUTO_ZRELADDR=y
40CONFIG_NET=y
41CONFIG_PACKET=y
42CONFIG_UNIX=y
43CONFIG_INET=y
44CONFIG_IP_PNP=y
45CONFIG_IP_PNP_DHCP=y
46CONFIG_IP_PNP_BOOTP=y
47# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
48# CONFIG_INET_XFRM_MODE_TUNNEL is not set
49# CONFIG_INET_XFRM_MODE_BEET is not set
50# CONFIG_INET_LRO is not set
51# CONFIG_IPV6 is not set
52CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
53CONFIG_DEVTMPFS=y
54CONFIG_DEVTMPFS_MOUNT=y
55CONFIG_MTD=y
56CONFIG_MTD_CMDLINE_PARTS=y
57CONFIG_MTD_BLOCK=y
58CONFIG_MTD_DATAFLASH=y
59CONFIG_MTD_NAND=y
60CONFIG_MTD_NAND_ATMEL=y
61CONFIG_MTD_UBI=y
62CONFIG_BLK_DEV_LOOP=y
63CONFIG_BLK_DEV_RAM=y
64CONFIG_BLK_DEV_RAM_SIZE=8192
65CONFIG_EEPROM_AT25=y
66CONFIG_SCSI=y
67CONFIG_BLK_DEV_SD=y
68# CONFIG_SCSI_LOWLEVEL is not set
69CONFIG_NETDEVICES=y
70CONFIG_MACB=y
71# CONFIG_NET_VENDOR_BROADCOM is not set
72# CONFIG_NET_VENDOR_FARADAY is not set
73# CONFIG_NET_VENDOR_INTEL is not set
74# CONFIG_NET_VENDOR_MARVELL is not set
75# CONFIG_NET_VENDOR_MICREL is not set
76# CONFIG_NET_VENDOR_MICROCHIP is not set
77# CONFIG_NET_VENDOR_NATSEMI is not set
78# CONFIG_NET_VENDOR_SEEQ is not set
79# CONFIG_NET_VENDOR_SMSC is not set
80# CONFIG_NET_VENDOR_STMICRO is not set
81CONFIG_SMSC_PHY=y
82# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
83CONFIG_KEYBOARD_GPIO=y
84# CONFIG_INPUT_MOUSE is not set
85CONFIG_SERIAL_ATMEL=y
86CONFIG_SERIAL_ATMEL_CONSOLE=y
87CONFIG_HW_RANDOM=y
88CONFIG_I2C=y
89CONFIG_I2C_CHARDEV=y
90CONFIG_I2C_GPIO=y
91CONFIG_SPI=y
92CONFIG_SPI_ATMEL=y
93CONFIG_SPI_SPIDEV=y
94CONFIG_GPIO_SYSFS=y
95CONFIG_POWER_SUPPLY=y
96CONFIG_POWER_RESET=y
97# CONFIG_HWMON is not set
98CONFIG_WATCHDOG=y
99CONFIG_WATCHDOG_NOWAYOUT=y
100CONFIG_AT91SAM9X_WATCHDOG=y
101CONFIG_SOUND=y
102CONFIG_SND=y
103CONFIG_SND_SEQUENCER=y
104CONFIG_SND_MIXER_OSS=y
105CONFIG_SND_PCM_OSS=y
106CONFIG_SND_SEQUENCER_OSS=y
107# CONFIG_SND_VERBOSE_PROCFS is not set
108CONFIG_USB=y
109CONFIG_USB_MON=y
110CONFIG_USB_OHCI_HCD=y
111CONFIG_USB_STORAGE=y
112CONFIG_USB_GADGET=y
113CONFIG_USB_AT91=y
114CONFIG_USB_G_SERIAL=y
115CONFIG_MMC=y
116CONFIG_MMC_ATMELMCI=y
117CONFIG_MMC_SPI=y
118CONFIG_NEW_LEDS=y
119CONFIG_LEDS_CLASS=y
120CONFIG_LEDS_GPIO=y
121CONFIG_LEDS_TRIGGERS=y
122CONFIG_LEDS_TRIGGER_TIMER=y
123CONFIG_LEDS_TRIGGER_HEARTBEAT=y
124CONFIG_RTC_CLASS=y
125CONFIG_RTC_DRV_RV3029C2=y
126CONFIG_RTC_DRV_AT91SAM9=y
127CONFIG_IIO=y
128CONFIG_AT91_ADC=y
129CONFIG_EXT4_FS=y
130CONFIG_VFAT_FS=y
131CONFIG_TMPFS=y
132CONFIG_UBIFS_FS=y
133CONFIG_UBIFS_FS_ADVANCED_COMPR=y
134CONFIG_NFS_FS=y
135CONFIG_ROOT_NFS=y
136CONFIG_NLS_CODEPAGE_437=y
137CONFIG_NLS_CODEPAGE_850=y
138CONFIG_NLS_ISO8859_1=y
139CONFIG_NLS_ISO8859_15=y
140CONFIG_NLS_UTF8=y
141CONFIG_DEBUG_INFO=y
142# CONFIG_ENABLE_WARN_DEPRECATED is not set
143# CONFIG_FTRACE is not set
144CONFIG_DEBUG_LL=y
145CONFIG_EARLY_PRINTK=y
diff --git a/arch/arm/configs/at91sam9261_9g10_defconfig b/arch/arm/configs/at91sam9261_9g10_defconfig
deleted file mode 100644
index 0c505d801e25..000000000000
--- a/arch/arm/configs/at91sam9261_9g10_defconfig
+++ /dev/null
@@ -1,147 +0,0 @@
1# CONFIG_LOCALVERSION_AUTO is not set
2CONFIG_KERNEL_LZMA=y
3# CONFIG_SWAP is not set
4CONFIG_SYSVIPC=y
5CONFIG_IKCONFIG=y
6CONFIG_IKCONFIG_PROC=y
7CONFIG_LOG_BUF_SHIFT=14
8CONFIG_NAMESPACES=y
9CONFIG_EMBEDDED=y
10CONFIG_SLAB=y
11CONFIG_MODULES=y
12CONFIG_MODULE_UNLOAD=y
13# CONFIG_BLK_DEV_BSG is not set
14# CONFIG_IOSCHED_DEADLINE is not set
15# CONFIG_IOSCHED_CFQ is not set
16CONFIG_ARCH_AT91=y
17CONFIG_ARCH_AT91SAM9261=y
18CONFIG_MACH_AT91SAM9261EK=y
19CONFIG_MACH_AT91SAM9G10EK=y
20# CONFIG_ARM_THUMB is not set
21CONFIG_AEABI=y
22CONFIG_ZBOOT_ROM_TEXT=0x0
23CONFIG_ZBOOT_ROM_BSS=0x0
24CONFIG_CMDLINE="mem=64M console=ttyS0,115200 initrd=0x21100000,3145728 root=/dev/ram0 rw"
25CONFIG_AUTO_ZRELADDR=y
26CONFIG_VFP=y
27# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
28CONFIG_NET=y
29CONFIG_PACKET=y
30CONFIG_UNIX=y
31CONFIG_INET=y
32CONFIG_IP_MULTICAST=y
33CONFIG_IP_PNP=y
34CONFIG_IP_PNP_DHCP=y
35CONFIG_IP_PNP_BOOTP=y
36# CONFIG_INET_LRO is not set
37# CONFIG_IPV6 is not set
38CONFIG_CFG80211=y
39CONFIG_MAC80211=y
40CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
41CONFIG_DEVTMPFS=y
42CONFIG_DEVTMPFS_MOUNT=y
43CONFIG_MTD=y
44CONFIG_MTD_CMDLINE_PARTS=y
45CONFIG_MTD_BLOCK=y
46CONFIG_MTD_NAND=y
47CONFIG_MTD_NAND_ATMEL=y
48CONFIG_MTD_UBI=y
49CONFIG_MTD_UBI_GLUEBI=y
50CONFIG_BLK_DEV_RAM=y
51CONFIG_BLK_DEV_RAM_SIZE=8192
52CONFIG_ATMEL_TCLIB=y
53CONFIG_ATMEL_SSC=y
54CONFIG_SCSI=y
55CONFIG_BLK_DEV_SD=y
56CONFIG_NETDEVICES=y
57CONFIG_DM9000=y
58CONFIG_USB_ZD1201=m
59CONFIG_RTL8187=m
60CONFIG_LIBERTAS=m
61CONFIG_LIBERTAS_USB=m
62CONFIG_LIBERTAS_SDIO=m
63CONFIG_LIBERTAS_SPI=m
64CONFIG_RT2X00=m
65CONFIG_RT2500USB=m
66CONFIG_RT73USB=m
67CONFIG_ZD1211RW=m
68CONFIG_INPUT_POLLDEV=m
69# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
70CONFIG_INPUT_MOUSEDEV_SCREEN_X=240
71CONFIG_INPUT_MOUSEDEV_SCREEN_Y=320
72CONFIG_INPUT_EVDEV=y
73# CONFIG_KEYBOARD_ATKBD is not set
74CONFIG_KEYBOARD_GPIO=y
75# CONFIG_INPUT_MOUSE is not set
76CONFIG_INPUT_TOUCHSCREEN=y
77CONFIG_TOUCHSCREEN_ADS7846=y
78CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
79CONFIG_SERIAL_ATMEL=y
80CONFIG_SERIAL_ATMEL_CONSOLE=y
81CONFIG_HW_RANDOM=y
82CONFIG_I2C=y
83CONFIG_I2C_CHARDEV=y
84CONFIG_I2C_GPIO=y
85CONFIG_SPI=y
86CONFIG_SPI_ATMEL=y
87CONFIG_POWER_SUPPLY=y
88CONFIG_POWER_RESET=y
89# CONFIG_HWMON is not set
90CONFIG_WATCHDOG=y
91CONFIG_WATCHDOG_NOWAYOUT=y
92CONFIG_AT91SAM9X_WATCHDOG=y
93CONFIG_FB=y
94CONFIG_FB_ATMEL=y
95CONFIG_BACKLIGHT_LCD_SUPPORT=y
96# CONFIG_LCD_CLASS_DEVICE is not set
97CONFIG_BACKLIGHT_CLASS_DEVICE=y
98CONFIG_BACKLIGHT_ATMEL_LCDC=y
99# CONFIG_BACKLIGHT_GENERIC is not set
100CONFIG_FRAMEBUFFER_CONSOLE=y
101CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
102CONFIG_LOGO=y
103CONFIG_SOUND=y
104CONFIG_SND=y
105CONFIG_SND_SEQUENCER=y
106CONFIG_SND_MIXER_OSS=y
107CONFIG_SND_PCM_OSS=y
108# CONFIG_SND_SUPPORT_OLD_API is not set
109# CONFIG_SND_VERBOSE_PROCFS is not set
110# CONFIG_SND_DRIVERS is not set
111# CONFIG_SND_ARM is not set
112CONFIG_SND_AT73C213=y
113CONFIG_SND_USB_AUDIO=m
114# CONFIG_USB_HID is not set
115CONFIG_USB=y
116CONFIG_USB_OHCI_HCD=y
117CONFIG_USB_STORAGE=y
118CONFIG_USB_GADGET=y
119CONFIG_USB_AT91=y
120CONFIG_USB_G_SERIAL=y
121CONFIG_MMC=y
122CONFIG_MMC_ATMELMCI=m
123CONFIG_NEW_LEDS=y
124CONFIG_LEDS_CLASS=y
125CONFIG_LEDS_GPIO=y
126CONFIG_LEDS_TRIGGERS=y
127CONFIG_LEDS_TRIGGER_TIMER=y
128CONFIG_LEDS_TRIGGER_HEARTBEAT=y
129CONFIG_LEDS_TRIGGER_GPIO=y
130CONFIG_RTC_CLASS=y
131CONFIG_RTC_DRV_AT91SAM9=y
132CONFIG_MSDOS_FS=y
133CONFIG_VFAT_FS=y
134CONFIG_TMPFS=y
135CONFIG_UBIFS_FS=y
136CONFIG_UBIFS_FS_ADVANCED_COMPR=y
137CONFIG_SQUASHFS=y
138CONFIG_SQUASHFS_LZO=y
139CONFIG_SQUASHFS_XZ=y
140CONFIG_NFS_FS=y
141CONFIG_ROOT_NFS=y
142CONFIG_NLS_CODEPAGE_437=y
143CONFIG_NLS_CODEPAGE_850=y
144CONFIG_NLS_ISO8859_1=y
145CONFIG_NLS_ISO8859_15=y
146CONFIG_NLS_UTF8=y
147CONFIG_CRC_CCITT=m
diff --git a/arch/arm/configs/at91sam9263_defconfig b/arch/arm/configs/at91sam9263_defconfig
deleted file mode 100644
index 8b671c977b81..000000000000
--- a/arch/arm/configs/at91sam9263_defconfig
+++ /dev/null
@@ -1,151 +0,0 @@
1# CONFIG_LOCALVERSION_AUTO is not set
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y
4CONFIG_IKCONFIG=y
5CONFIG_IKCONFIG_PROC=y
6CONFIG_LOG_BUF_SHIFT=14
7CONFIG_NAMESPACES=y
8CONFIG_EMBEDDED=y
9CONFIG_SLAB=y
10CONFIG_MODULES=y
11CONFIG_MODULE_UNLOAD=y
12# CONFIG_BLK_DEV_BSG is not set
13# CONFIG_IOSCHED_DEADLINE is not set
14# CONFIG_IOSCHED_CFQ is not set
15CONFIG_ARCH_AT91=y
16CONFIG_ARCH_AT91SAM9263=y
17CONFIG_MACH_AT91SAM9263EK=y
18CONFIG_MTD_AT91_DATAFLASH_CARD=y
19# CONFIG_ARM_THUMB is not set
20CONFIG_AEABI=y
21CONFIG_ZBOOT_ROM_TEXT=0x0
22CONFIG_ZBOOT_ROM_BSS=0x0
23CONFIG_CMDLINE="mem=64M console=ttyS0,115200 initrd=0x21100000,3145728 root=/dev/ram0 rw"
24CONFIG_AUTO_ZRELADDR=y
25CONFIG_NET=y
26CONFIG_PACKET=y
27CONFIG_UNIX=y
28CONFIG_NET_KEY=y
29CONFIG_INET=y
30CONFIG_IP_MULTICAST=y
31CONFIG_IP_ADVANCED_ROUTER=y
32CONFIG_IP_ROUTE_VERBOSE=y
33CONFIG_IP_PNP=y
34CONFIG_IP_PNP_DHCP=y
35CONFIG_IP_PNP_BOOTP=y
36CONFIG_IP_PNP_RARP=y
37CONFIG_NET_IPIP=y
38CONFIG_IP_MROUTE=y
39CONFIG_IP_PIMSM_V1=y
40CONFIG_IP_PIMSM_V2=y
41# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
42# CONFIG_INET_XFRM_MODE_TUNNEL is not set
43# CONFIG_INET_XFRM_MODE_BEET is not set
44# CONFIG_INET_LRO is not set
45# CONFIG_INET_DIAG is not set
46CONFIG_IPV6=y
47# CONFIG_WIRELESS is not set
48CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
49CONFIG_DEVTMPFS=y
50CONFIG_DEVTMPFS_MOUNT=y
51CONFIG_MTD=y
52CONFIG_MTD_CMDLINE_PARTS=y
53CONFIG_MTD_BLOCK=y
54CONFIG_NFTL=y
55CONFIG_NFTL_RW=y
56CONFIG_MTD_DATAFLASH=y
57CONFIG_MTD_BLOCK2MTD=y
58CONFIG_MTD_NAND=y
59CONFIG_MTD_NAND_ATMEL=y
60CONFIG_MTD_UBI=y
61CONFIG_MTD_UBI_GLUEBI=y
62CONFIG_BLK_DEV_LOOP=y
63CONFIG_BLK_DEV_RAM=y
64CONFIG_BLK_DEV_RAM_SIZE=8192
65CONFIG_ATMEL_TCLIB=y
66CONFIG_SCSI=y
67CONFIG_BLK_DEV_SD=y
68CONFIG_NETDEVICES=y
69CONFIG_MACB=y
70CONFIG_SMSC_PHY=y
71# CONFIG_WLAN is not set
72CONFIG_INPUT_POLLDEV=m
73# CONFIG_INPUT_MOUSEDEV is not set
74CONFIG_INPUT_EVDEV=y
75# CONFIG_KEYBOARD_ATKBD is not set
76CONFIG_KEYBOARD_GPIO=y
77# CONFIG_INPUT_MOUSE is not set
78CONFIG_INPUT_TOUCHSCREEN=y
79CONFIG_TOUCHSCREEN_ADS7846=y
80# CONFIG_LEGACY_PTYS is not set
81CONFIG_SERIAL_ATMEL=y
82CONFIG_SERIAL_ATMEL_CONSOLE=y
83CONFIG_HW_RANDOM=y
84CONFIG_I2C=y
85CONFIG_I2C_CHARDEV=y
86CONFIG_I2C_GPIO=y
87CONFIG_SPI=y
88CONFIG_SPI_ATMEL=y
89CONFIG_GPIO_SYSFS=y
90CONFIG_POWER_SUPPLY=y
91CONFIG_POWER_RESET=y
92# CONFIG_HWMON is not set
93CONFIG_WATCHDOG=y
94CONFIG_WATCHDOG_NOWAYOUT=y
95CONFIG_AT91SAM9X_WATCHDOG=y
96CONFIG_FB=y
97CONFIG_FB_ATMEL=y
98CONFIG_BACKLIGHT_LCD_SUPPORT=y
99CONFIG_LCD_CLASS_DEVICE=y
100CONFIG_BACKLIGHT_CLASS_DEVICE=y
101CONFIG_FRAMEBUFFER_CONSOLE=y
102CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
103CONFIG_LOGO=y
104CONFIG_SOUND=y
105CONFIG_SND=y
106CONFIG_SND_SEQUENCER=y
107CONFIG_SND_MIXER_OSS=y
108CONFIG_SND_PCM_OSS=y
109# CONFIG_SND_SUPPORT_OLD_API is not set
110# CONFIG_SND_VERBOSE_PROCFS is not set
111# CONFIG_SND_DRIVERS is not set
112# CONFIG_SND_ARM is not set
113CONFIG_SND_ATMEL_AC97C=y
114# CONFIG_SND_SPI is not set
115CONFIG_SND_USB_AUDIO=m
116CONFIG_USB=y
117CONFIG_USB_MON=y
118CONFIG_USB_OHCI_HCD=y
119CONFIG_USB_STORAGE=y
120CONFIG_USB_GADGET=y
121CONFIG_USB_ATMEL_USBA=y
122CONFIG_USB_G_SERIAL=y
123CONFIG_MMC=y
124CONFIG_SDIO_UART=m
125CONFIG_MMC_ATMELMCI=m
126CONFIG_NEW_LEDS=y
127CONFIG_LEDS_CLASS=y
128CONFIG_LEDS_GPIO=y
129CONFIG_LEDS_PWM=y
130CONFIG_LEDS_TRIGGERS=y
131CONFIG_LEDS_TRIGGER_HEARTBEAT=y
132CONFIG_RTC_CLASS=y
133CONFIG_RTC_DRV_AT91SAM9=y
134CONFIG_PWM=y
135CONFIG_PWM_ATMEL=y
136CONFIG_EXT4_FS=y
137CONFIG_VFAT_FS=y
138CONFIG_TMPFS=y
139CONFIG_UBIFS_FS=y
140CONFIG_UBIFS_FS_ADVANCED_COMPR=y
141CONFIG_NFS_FS=y
142CONFIG_NFS_V3_ACL=y
143CONFIG_NFS_V4=y
144CONFIG_ROOT_NFS=y
145CONFIG_NLS_CODEPAGE_437=y
146CONFIG_NLS_CODEPAGE_850=y
147CONFIG_NLS_ISO8859_1=y
148CONFIG_NLS_UTF8=y
149CONFIG_DEBUG_USER=y
150CONFIG_XZ_DEC=y
151CONFIG_FONTS=y
diff --git a/arch/arm/configs/at91sam9g45_defconfig b/arch/arm/configs/at91sam9g45_defconfig
deleted file mode 100644
index f66d1a1b64bf..000000000000
--- a/arch/arm/configs/at91sam9g45_defconfig
+++ /dev/null
@@ -1,175 +0,0 @@
1# CONFIG_LOCALVERSION_AUTO is not set
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y
4CONFIG_LOG_BUF_SHIFT=14
5CONFIG_SYSFS_DEPRECATED=y
6CONFIG_SYSFS_DEPRECATED_V2=y
7CONFIG_BLK_DEV_INITRD=y
8CONFIG_CC_OPTIMIZE_FOR_SIZE=y
9CONFIG_EMBEDDED=y
10CONFIG_SLAB=y
11CONFIG_MODULES=y
12CONFIG_MODULE_UNLOAD=y
13# CONFIG_LBDAF is not set
14# CONFIG_BLK_DEV_BSG is not set
15# CONFIG_IOSCHED_DEADLINE is not set
16# CONFIG_IOSCHED_CFQ is not set
17CONFIG_ARCH_AT91=y
18CONFIG_ARCH_AT91SAM9G45=y
19CONFIG_MACH_AT91SAM9M10G45EK=y
20CONFIG_MACH_AT91SAM9_DT=y
21CONFIG_AT91_SLOW_CLOCK=y
22CONFIG_AEABI=y
23CONFIG_UACCESS_WITH_MEMCPY=y
24CONFIG_ZBOOT_ROM_TEXT=0x0
25CONFIG_ZBOOT_ROM_BSS=0x0
26CONFIG_CMDLINE="mem=128M console=ttyS0,115200 initrd=0x71100000,25165824 root=/dev/ram0 rw"
27CONFIG_AUTO_ZRELADDR=y
28# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
29CONFIG_NET=y
30CONFIG_PACKET=y
31CONFIG_UNIX=y
32CONFIG_INET=y
33CONFIG_IP_MULTICAST=y
34CONFIG_IP_PNP=y
35CONFIG_IP_PNP_DHCP=y
36CONFIG_IP_PNP_BOOTP=y
37# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
38# CONFIG_INET_XFRM_MODE_TUNNEL is not set
39# CONFIG_INET_XFRM_MODE_BEET is not set
40# CONFIG_INET_DIAG is not set
41CONFIG_IPV6=y
42# CONFIG_INET6_XFRM_MODE_TRANSPORT is not set
43# CONFIG_INET6_XFRM_MODE_TUNNEL is not set
44# CONFIG_INET6_XFRM_MODE_BEET is not set
45CONFIG_IPV6_SIT_6RD=y
46CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
47CONFIG_DEVTMPFS=y
48CONFIG_DEVTMPFS_MOUNT=y
49# CONFIG_STANDALONE is not set
50# CONFIG_PREVENT_FIRMWARE_BUILD is not set
51CONFIG_MTD=y
52CONFIG_MTD_CMDLINE_PARTS=y
53CONFIG_MTD_BLOCK=y
54CONFIG_MTD_DATAFLASH=y
55CONFIG_MTD_NAND=y
56CONFIG_MTD_NAND_ATMEL=y
57CONFIG_MTD_UBI=y
58CONFIG_MTD_UBI_GLUEBI=y
59CONFIG_BLK_DEV_LOOP=y
60CONFIG_BLK_DEV_RAM=y
61CONFIG_BLK_DEV_RAM_COUNT=4
62CONFIG_BLK_DEV_RAM_SIZE=8192
63CONFIG_ATMEL_TCLIB=y
64CONFIG_ATMEL_SSC=y
65CONFIG_SCSI=y
66CONFIG_BLK_DEV_SD=y
67# CONFIG_SCSI_LOWLEVEL is not set
68CONFIG_NETDEVICES=y
69CONFIG_MACB=y
70CONFIG_DAVICOM_PHY=y
71# CONFIG_INPUT_MOUSEDEV is not set
72CONFIG_INPUT_JOYDEV=y
73CONFIG_INPUT_EVDEV=y
74# CONFIG_KEYBOARD_ATKBD is not set
75CONFIG_KEYBOARD_QT1070=y
76CONFIG_KEYBOARD_QT2160=y
77CONFIG_KEYBOARD_GPIO=y
78# CONFIG_INPUT_MOUSE is not set
79CONFIG_INPUT_TOUCHSCREEN=y
80CONFIG_TOUCHSCREEN_ATMEL_MXT=m
81# CONFIG_SERIO is not set
82# CONFIG_LEGACY_PTYS is not set
83CONFIG_SERIAL_ATMEL=y
84CONFIG_SERIAL_ATMEL_CONSOLE=y
85CONFIG_HW_RANDOM=y
86CONFIG_I2C=y
87CONFIG_I2C_CHARDEV=y
88CONFIG_I2C_GPIO=y
89CONFIG_SPI=y
90CONFIG_SPI_ATMEL=y
91CONFIG_POWER_SUPPLY=y
92CONFIG_POWER_RESET=y
93# CONFIG_HWMON is not set
94CONFIG_WATCHDOG=y
95CONFIG_WATCHDOG_NOWAYOUT=y
96CONFIG_AT91SAM9X_WATCHDOG=y
97CONFIG_FB=y
98CONFIG_FB_ATMEL=y
99CONFIG_BACKLIGHT_LCD_SUPPORT=y
100CONFIG_LCD_CLASS_DEVICE=y
101CONFIG_BACKLIGHT_CLASS_DEVICE=y
102CONFIG_BACKLIGHT_ATMEL_LCDC=y
103# CONFIG_BACKLIGHT_GENERIC is not set
104CONFIG_BACKLIGHT_PWM=y
105CONFIG_FRAMEBUFFER_CONSOLE=y
106CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y
107CONFIG_LOGO=y
108CONFIG_SOUND=y
109CONFIG_SND=y
110CONFIG_SND_SEQUENCER=y
111CONFIG_SND_MIXER_OSS=y
112CONFIG_SND_PCM_OSS=y
113# CONFIG_SND_SUPPORT_OLD_API is not set
114# CONFIG_SND_VERBOSE_PROCFS is not set
115# CONFIG_SND_DRIVERS is not set
116# CONFIG_SND_ARM is not set
117CONFIG_SND_ATMEL_AC97C=y
118# CONFIG_SND_SPI is not set
119# CONFIG_SND_USB is not set
120# CONFIG_USB_HID is not set
121CONFIG_USB=y
122CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
123CONFIG_USB_EHCI_HCD=y
124CONFIG_USB_OHCI_HCD=y
125CONFIG_USB_ACM=y
126CONFIG_USB_STORAGE=y
127CONFIG_USB_GADGET=y
128CONFIG_USB_ATMEL_USBA=y
129CONFIG_USB_G_MULTI=y
130CONFIG_USB_G_MULTI_CDC=y
131CONFIG_MMC=y
132# CONFIG_MMC_BLOCK_BOUNCE is not set
133CONFIG_MMC_ATMELMCI=y
134CONFIG_NEW_LEDS=y
135CONFIG_LEDS_CLASS=y
136CONFIG_LEDS_GPIO=y
137CONFIG_LEDS_PWM=y
138CONFIG_LEDS_TRIGGERS=y
139CONFIG_LEDS_TRIGGER_TIMER=y
140CONFIG_LEDS_TRIGGER_HEARTBEAT=y
141CONFIG_LEDS_TRIGGER_GPIO=y
142CONFIG_RTC_CLASS=y
143CONFIG_RTC_DRV_AT91RM9200=y
144CONFIG_DMADEVICES=y
145CONFIG_AT_HDMAC=y
146CONFIG_DMATEST=m
147# CONFIG_IOMMU_SUPPORT is not set
148CONFIG_IIO=y
149CONFIG_AT91_ADC=y
150CONFIG_PWM=y
151CONFIG_PWM_ATMEL=y
152CONFIG_EXT4_FS=y
153CONFIG_FANOTIFY=y
154CONFIG_VFAT_FS=y
155CONFIG_TMPFS=y
156CONFIG_UBIFS_FS=y
157CONFIG_UBIFS_FS_ADVANCED_COMPR=y
158CONFIG_NFS_FS=y
159CONFIG_ROOT_NFS=y
160CONFIG_NLS_CODEPAGE_437=y
161CONFIG_NLS_CODEPAGE_850=y
162CONFIG_NLS_ISO8859_1=y
163CONFIG_STRIP_ASM_SYMS=y
164CONFIG_DEBUG_MEMORY_INIT=y
165# CONFIG_SCHED_DEBUG is not set
166# CONFIG_FTRACE is not set
167CONFIG_DEBUG_USER=y
168CONFIG_DEBUG_LL=y
169CONFIG_EARLY_PRINTK=y
170CONFIG_CRYPTO_ECB=y
171# CONFIG_CRYPTO_ANSI_CPRNG is not set
172CONFIG_CRYPTO_USER_API_HASH=m
173CONFIG_CRYPTO_USER_API_SKCIPHER=m
174# CONFIG_CRYPTO_HW is not set
175CONFIG_FONTS=y
diff --git a/arch/arm/configs/at91sam9rl_defconfig b/arch/arm/configs/at91sam9rl_defconfig
deleted file mode 100644
index 4c26d344ae88..000000000000
--- a/arch/arm/configs/at91sam9rl_defconfig
+++ /dev/null
@@ -1,92 +0,0 @@
1# CONFIG_LOCALVERSION_AUTO is not set
2# CONFIG_SWAP is not set
3CONFIG_SYSVIPC=y
4CONFIG_LOG_BUF_SHIFT=14
5CONFIG_BLK_DEV_INITRD=y
6CONFIG_EMBEDDED=y
7CONFIG_SLAB=y
8CONFIG_MODULES=y
9CONFIG_MODULE_UNLOAD=y
10# CONFIG_BLK_DEV_BSG is not set
11# CONFIG_IOSCHED_DEADLINE is not set
12# CONFIG_IOSCHED_CFQ is not set
13CONFIG_ARCH_AT91=y
14CONFIG_ARCH_AT91SAM9RL=y
15CONFIG_MACH_AT91SAM9RLEK=y
16# CONFIG_ARM_THUMB is not set
17CONFIG_AEABI=y
18CONFIG_ZBOOT_ROM_TEXT=0x0
19CONFIG_ZBOOT_ROM_BSS=0x0
20CONFIG_CMDLINE="mem=64M console=ttyS0,115200 initrd=0x21100000,17105363 root=/dev/ram0 rw"
21CONFIG_AUTO_ZRELADDR=y
22CONFIG_NET=y
23CONFIG_UNIX=y
24CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
25CONFIG_DEVTMPFS=y
26CONFIG_DEVTMPFS_MOUNT=y
27CONFIG_MTD=y
28CONFIG_MTD_CMDLINE_PARTS=y
29CONFIG_MTD_BLOCK=y
30CONFIG_MTD_DATAFLASH=y
31CONFIG_MTD_NAND=y
32CONFIG_MTD_NAND_ATMEL=y
33CONFIG_MTD_UBI=y
34CONFIG_BLK_DEV_LOOP=y
35CONFIG_BLK_DEV_RAM=y
36CONFIG_BLK_DEV_RAM_COUNT=4
37CONFIG_BLK_DEV_RAM_SIZE=24576
38CONFIG_SCSI=y
39CONFIG_BLK_DEV_SD=y
40# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
41CONFIG_INPUT_MOUSEDEV_SCREEN_X=320
42CONFIG_INPUT_MOUSEDEV_SCREEN_Y=240
43CONFIG_INPUT_EVDEV=y
44# CONFIG_INPUT_KEYBOARD is not set
45# CONFIG_INPUT_MOUSE is not set
46CONFIG_INPUT_TOUCHSCREEN=y
47# CONFIG_SERIO is not set
48CONFIG_SERIAL_ATMEL=y
49CONFIG_SERIAL_ATMEL_CONSOLE=y
50# CONFIG_HW_RANDOM is not set
51CONFIG_I2C=y
52CONFIG_I2C_CHARDEV=y
53CONFIG_I2C_GPIO=y
54CONFIG_SPI=y
55CONFIG_SPI_ATMEL=y
56CONFIG_POWER_SUPPLY=y
57CONFIG_POWER_RESET=y
58# CONFIG_HWMON is not set
59CONFIG_WATCHDOG=y
60CONFIG_WATCHDOG_NOWAYOUT=y
61CONFIG_AT91SAM9X_WATCHDOG=y
62CONFIG_FB=y
63CONFIG_FB_ATMEL=y
64CONFIG_USB_GADGET=y
65CONFIG_USB_ATMEL_USBA=y
66CONFIG_MMC=y
67CONFIG_MMC_ATMELMCI=m
68CONFIG_NEW_LEDS=y
69CONFIG_LEDS_CLASS=y
70CONFIG_LEDS_GPIO=y
71CONFIG_LEDS_PWM=y
72CONFIG_LEDS_TRIGGERS=y
73CONFIG_LEDS_TRIGGER_HEARTBEAT=y
74CONFIG_RTC_CLASS=y
75CONFIG_RTC_DRV_AT91SAM9=y
76CONFIG_IIO=y
77CONFIG_AT91_ADC=y
78CONFIG_PWM=y
79CONFIG_PWM_ATMEL=y
80CONFIG_EXT4_FS=y
81CONFIG_VFAT_FS=y
82CONFIG_TMPFS=y
83CONFIG_UBIFS_FS=y
84CONFIG_CRAMFS=y
85CONFIG_NLS_CODEPAGE_437=y
86CONFIG_NLS_CODEPAGE_850=y
87CONFIG_NLS_ISO8859_1=y
88CONFIG_NLS_ISO8859_15=y
89CONFIG_NLS_UTF8=y
90CONFIG_DEBUG_INFO=y
91CONFIG_DEBUG_USER=y
92CONFIG_DEBUG_LL=y
diff --git a/arch/arm/configs/at91x40_defconfig b/arch/arm/configs/at91x40_defconfig
deleted file mode 100644
index c55e9212fcbb..000000000000
--- a/arch/arm/configs/at91x40_defconfig
+++ /dev/null
@@ -1,48 +0,0 @@
1CONFIG_EXPERIMENTAL=y
2CONFIG_LOG_BUF_SHIFT=14
3CONFIG_EMBEDDED=y
4# CONFIG_HOTPLUG is not set
5# CONFIG_ELF_CORE is not set
6# CONFIG_FUTEX is not set
7# CONFIG_TIMERFD is not set
8# CONFIG_VM_EVENT_COUNTERS is not set
9# CONFIG_COMPAT_BRK is not set
10CONFIG_SLAB=y
11# CONFIG_LBDAF is not set
12# CONFIG_BLK_DEV_BSG is not set
13# CONFIG_IOSCHED_DEADLINE is not set
14# CONFIG_IOSCHED_CFQ is not set
15# CONFIG_MMU is not set
16CONFIG_ARCH_AT91=y
17CONFIG_ARCH_AT91X40=y
18CONFIG_MACH_AT91EB01=y
19CONFIG_AT91_EARLY_USART0=y
20CONFIG_CPU_ARM7TDMI=y
21CONFIG_SET_MEM_PARAM=y
22CONFIG_DRAM_BASE=0x01000000
23CONFIG_DRAM_SIZE=0x00400000
24CONFIG_FLASH_MEM_BASE=0x01400000
25CONFIG_PROCESSOR_ID=0x14000040
26CONFIG_ZBOOT_ROM_TEXT=0x0
27CONFIG_ZBOOT_ROM_BSS=0x0
28CONFIG_BINFMT_FLAT=y
29# CONFIG_SUSPEND is not set
30# CONFIG_FW_LOADER is not set
31CONFIG_MTD=y
32CONFIG_MTD_PARTITIONS=y
33CONFIG_MTD_CHAR=y
34CONFIG_MTD_BLOCK=y
35CONFIG_MTD_RAM=y
36CONFIG_MTD_ROM=y
37CONFIG_BLK_DEV_RAM=y
38# CONFIG_INPUT is not set
39# CONFIG_SERIO is not set
40# CONFIG_VT is not set
41# CONFIG_DEVKMEM is not set
42# CONFIG_HW_RANDOM is not set
43# CONFIG_HWMON is not set
44# CONFIG_USB_SUPPORT is not set
45CONFIG_EXT2_FS=y
46# CONFIG_DNOTIFY is not set
47CONFIG_ROMFS_FS=y
48# CONFIG_ENABLE_MUST_CHECK is not set
diff --git a/arch/arm/configs/exynos_defconfig b/arch/arm/configs/exynos_defconfig
index 72058b8a6f4d..e21ef830a483 100644
--- a/arch/arm/configs/exynos_defconfig
+++ b/arch/arm/configs/exynos_defconfig
@@ -142,11 +142,13 @@ CONFIG_MMC_DW_IDMAC=y
142CONFIG_MMC_DW_EXYNOS=y 142CONFIG_MMC_DW_EXYNOS=y
143CONFIG_RTC_CLASS=y 143CONFIG_RTC_CLASS=y
144CONFIG_RTC_DRV_MAX77686=y 144CONFIG_RTC_DRV_MAX77686=y
145CONFIG_RTC_DRV_MAX77802=y
145CONFIG_RTC_DRV_S5M=y 146CONFIG_RTC_DRV_S5M=y
146CONFIG_RTC_DRV_S3C=y 147CONFIG_RTC_DRV_S3C=y
147CONFIG_DMADEVICES=y 148CONFIG_DMADEVICES=y
148CONFIG_PL330_DMA=y 149CONFIG_PL330_DMA=y
149CONFIG_COMMON_CLK_MAX77686=y 150CONFIG_COMMON_CLK_MAX77686=y
151CONFIG_COMMON_CLK_MAX77802=y
150CONFIG_COMMON_CLK_S2MPS11=y 152CONFIG_COMMON_CLK_S2MPS11=y
151CONFIG_EXYNOS_IOMMU=y 153CONFIG_EXYNOS_IOMMU=y
152CONFIG_IIO=y 154CONFIG_IIO=y
diff --git a/arch/arm/configs/koelsch_defconfig b/arch/arm/configs/koelsch_defconfig
deleted file mode 100644
index b33d19b7f134..000000000000
--- a/arch/arm/configs/koelsch_defconfig
+++ /dev/null
@@ -1,113 +0,0 @@
1CONFIG_SYSVIPC=y
2CONFIG_NO_HZ=y
3CONFIG_IKCONFIG=y
4CONFIG_IKCONFIG_PROC=y
5CONFIG_LOG_BUF_SHIFT=16
6CONFIG_CC_OPTIMIZE_FOR_SIZE=y
7CONFIG_SYSCTL_SYSCALL=y
8CONFIG_EMBEDDED=y
9CONFIG_PERF_EVENTS=y
10CONFIG_SLAB=y
11CONFIG_ARCH_SHMOBILE_LEGACY=y
12CONFIG_ARCH_R8A7791=y
13CONFIG_MACH_KOELSCH=y
14# CONFIG_SWP_EMULATE is not set
15CONFIG_CPU_BPREDICT_DISABLE=y
16CONFIG_PL310_ERRATA_588369=y
17CONFIG_ARM_ERRATA_754322=y
18CONFIG_PCI=y
19CONFIG_PCI_RCAR_GEN2=y
20CONFIG_PCI_RCAR_GEN2_PCIE=y
21CONFIG_SMP=y
22CONFIG_SCHED_MC=y
23CONFIG_NR_CPUS=8
24CONFIG_AEABI=y
25CONFIG_ZBOOT_ROM_TEXT=0x0
26CONFIG_ZBOOT_ROM_BSS=0x0
27CONFIG_ARM_APPENDED_DTB=y
28CONFIG_KEXEC=y
29CONFIG_AUTO_ZRELADDR=y
30CONFIG_VFP=y
31CONFIG_NEON=y
32# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
33CONFIG_PM_RUNTIME=y
34CONFIG_NET=y
35CONFIG_PACKET=y
36CONFIG_UNIX=y
37CONFIG_INET=y
38CONFIG_IP_PNP=y
39CONFIG_IP_PNP_DHCP=y
40CONFIG_DEVTMPFS=y
41CONFIG_DEVTMPFS_MOUNT=y
42CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
43CONFIG_BLK_DEV_SD=y
44CONFIG_ATA=y
45CONFIG_SATA_RCAR=y
46CONFIG_MTD=y
47CONFIG_MTD_M25P80=y
48CONFIG_MTD_SPI_NOR=y
49CONFIG_EEPROM_AT24=y
50CONFIG_NETDEVICES=y
51# CONFIG_NET_VENDOR_ARC is not set
52# CONFIG_NET_CADENCE is not set
53# CONFIG_NET_VENDOR_BROADCOM is not set
54# CONFIG_NET_VENDOR_CIRRUS is not set
55# CONFIG_NET_VENDOR_FARADAY is not set
56# CONFIG_NET_VENDOR_INTEL is not set
57# CONFIG_NET_VENDOR_MARVELL is not set
58# CONFIG_NET_VENDOR_MICREL is not set
59# CONFIG_NET_VENDOR_NATSEMI is not set
60CONFIG_SH_ETH=y
61# CONFIG_NET_VENDOR_SEEQ is not set
62# CONFIG_NET_VENDOR_SMSC is not set
63# CONFIG_NET_VENDOR_STMICRO is not set
64# CONFIG_NET_VENDOR_VIA is not set
65# CONFIG_NET_VENDOR_WIZNET is not set
66# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
67CONFIG_KEYBOARD_GPIO=y
68# CONFIG_INPUT_MOUSE is not set
69# CONFIG_LEGACY_PTYS is not set
70CONFIG_SERIAL_SH_SCI=y
71CONFIG_SERIAL_SH_SCI_NR_UARTS=20
72CONFIG_SERIAL_SH_SCI_CONSOLE=y
73CONFIG_I2C=y
74CONFIG_I2C_MUX=y
75CONFIG_I2C_SH_MOBILE=y
76CONFIG_I2C_RCAR=y
77CONFIG_SPI=y
78CONFIG_SPI_RSPI=y
79CONFIG_SPI_SH_MSIOF=y
80CONFIG_GPIOLIB=y
81CONFIG_GPIO_RCAR=y
82# CONFIG_HWMON is not set
83CONFIG_THERMAL=y
84CONFIG_RCAR_THERMAL=y
85CONFIG_REGULATOR=y
86CONFIG_REGULATOR_FIXED_VOLTAGE=y
87CONFIG_REGULATOR_DA9210=y
88CONFIG_REGULATOR_GPIO=y
89CONFIG_MEDIA_SUPPORT=y
90CONFIG_MEDIA_CAMERA_SUPPORT=y
91CONFIG_V4L_PLATFORM_DRIVERS=y
92CONFIG_SOC_CAMERA=y
93CONFIG_SOC_CAMERA_PLATFORM=y
94CONFIG_VIDEO_RCAR_VIN=y
95# CONFIG_MEDIA_SUBDRV_AUTOSELECT is not set
96CONFIG_VIDEO_ADV7180=y
97# CONFIG_HID is not set
98# CONFIG_USB_SUPPORT is not set
99CONFIG_MMC=y
100CONFIG_MMC_SDHI=y
101CONFIG_NEW_LEDS=y
102CONFIG_LEDS_CLASS=y
103CONFIG_LEDS_GPIO=y
104# CONFIG_IOMMU_SUPPORT is not set
105# CONFIG_DNOTIFY is not set
106CONFIG_TMPFS=y
107CONFIG_CONFIGFS_FS=y
108# CONFIG_MISC_FILESYSTEMS is not set
109CONFIG_NFS_FS=y
110CONFIG_ROOT_NFS=y
111# CONFIG_ENABLE_WARN_DEPRECATED is not set
112# CONFIG_ENABLE_MUST_CHECK is not set
113# CONFIG_ARM_UNWIND is not set
diff --git a/arch/arm/configs/multi_v7_defconfig b/arch/arm/configs/multi_v7_defconfig
index f1dc7fc668f3..9d7a32f93fcf 100644
--- a/arch/arm/configs/multi_v7_defconfig
+++ b/arch/arm/configs/multi_v7_defconfig
@@ -217,6 +217,7 @@ CONFIG_I2C_CADENCE=y
217CONFIG_I2C_DESIGNWARE_PLATFORM=y 217CONFIG_I2C_DESIGNWARE_PLATFORM=y
218CONFIG_I2C_EXYNOS5=y 218CONFIG_I2C_EXYNOS5=y
219CONFIG_I2C_MV64XXX=y 219CONFIG_I2C_MV64XXX=y
220CONFIG_I2C_S3C2410=y
220CONFIG_I2C_SIRF=y 221CONFIG_I2C_SIRF=y
221CONFIG_I2C_TEGRA=y 222CONFIG_I2C_TEGRA=y
222CONFIG_I2C_ST=y 223CONFIG_I2C_ST=y
@@ -235,6 +236,7 @@ CONFIG_SPI_TEGRA20_SLINK=y
235CONFIG_SPI_XILINX=y 236CONFIG_SPI_XILINX=y
236CONFIG_PINCTRL_AS3722=y 237CONFIG_PINCTRL_AS3722=y
237CONFIG_PINCTRL_PALMAS=y 238CONFIG_PINCTRL_PALMAS=y
239CONFIG_PINCTRL_APQ8084=y
238CONFIG_GPIO_SYSFS=y 240CONFIG_GPIO_SYSFS=y
239CONFIG_GPIO_GENERIC_PLATFORM=y 241CONFIG_GPIO_GENERIC_PLATFORM=y
240CONFIG_GPIO_DWAPB=y 242CONFIG_GPIO_DWAPB=y
@@ -411,6 +413,7 @@ CONFIG_NVEC_POWER=y
411CONFIG_NVEC_PAZ00=y 413CONFIG_NVEC_PAZ00=y
412CONFIG_QCOM_GSBI=y 414CONFIG_QCOM_GSBI=y
413CONFIG_COMMON_CLK_QCOM=y 415CONFIG_COMMON_CLK_QCOM=y
416CONFIG_APQ_MMCC_8084=y
414CONFIG_MSM_GCC_8660=y 417CONFIG_MSM_GCC_8660=y
415CONFIG_MSM_MMCC_8960=y 418CONFIG_MSM_MMCC_8960=y
416CONFIG_MSM_MMCC_8974=y 419CONFIG_MSM_MMCC_8974=y
diff --git a/arch/arm/configs/omap2plus_defconfig b/arch/arm/configs/omap2plus_defconfig
index 16e719c268dd..b3f86670d2eb 100644
--- a/arch/arm/configs/omap2plus_defconfig
+++ b/arch/arm/configs/omap2plus_defconfig
@@ -86,7 +86,6 @@ CONFIG_IP_PNP_DHCP=y
86CONFIG_IP_PNP_BOOTP=y 86CONFIG_IP_PNP_BOOTP=y
87CONFIG_IP_PNP_RARP=y 87CONFIG_IP_PNP_RARP=y
88# CONFIG_INET_LRO is not set 88# CONFIG_INET_LRO is not set
89CONFIG_IPV6=y
90CONFIG_NETFILTER=y 89CONFIG_NETFILTER=y
91CONFIG_CAN=m 90CONFIG_CAN=m
92CONFIG_CAN_C_CAN=m 91CONFIG_CAN_C_CAN=m
@@ -112,6 +111,7 @@ CONFIG_MTD_OOPS=y
112CONFIG_MTD_CFI=y 111CONFIG_MTD_CFI=y
113CONFIG_MTD_CFI_INTELEXT=y 112CONFIG_MTD_CFI_INTELEXT=y
114CONFIG_MTD_NAND=y 113CONFIG_MTD_NAND=y
114CONFIG_MTD_NAND_ECC_BCH=y
115CONFIG_MTD_NAND_OMAP2=y 115CONFIG_MTD_NAND_OMAP2=y
116CONFIG_MTD_ONENAND=y 116CONFIG_MTD_ONENAND=y
117CONFIG_MTD_ONENAND_VERIFY_WRITE=y 117CONFIG_MTD_ONENAND_VERIFY_WRITE=y
@@ -317,7 +317,7 @@ CONFIG_EXT4_FS=y
317CONFIG_FANOTIFY=y 317CONFIG_FANOTIFY=y
318CONFIG_QUOTA=y 318CONFIG_QUOTA=y
319CONFIG_QFMT_V2=y 319CONFIG_QFMT_V2=y
320CONFIG_AUTOFS4_FS=y 320CONFIG_AUTOFS4_FS=m
321CONFIG_MSDOS_FS=y 321CONFIG_MSDOS_FS=y
322CONFIG_VFAT_FS=y 322CONFIG_VFAT_FS=y
323CONFIG_TMPFS=y 323CONFIG_TMPFS=y
diff --git a/arch/arm/configs/sama5_defconfig b/arch/arm/configs/sama5_defconfig
index c9089c927daf..299ca18bbd75 100644
--- a/arch/arm/configs/sama5_defconfig
+++ b/arch/arm/configs/sama5_defconfig
@@ -20,7 +20,6 @@ CONFIG_ARCH_AT91=y
20CONFIG_SOC_SAM_V7=y 20CONFIG_SOC_SAM_V7=y
21CONFIG_SOC_SAMA5D3=y 21CONFIG_SOC_SAMA5D3=y
22CONFIG_SOC_SAMA5D4=y 22CONFIG_SOC_SAMA5D4=y
23CONFIG_MACH_SAMA5_DT=y
24CONFIG_AEABI=y 23CONFIG_AEABI=y
25CONFIG_UACCESS_WITH_MEMCPY=y 24CONFIG_UACCESS_WITH_MEMCPY=y
26CONFIG_ZBOOT_ROM_TEXT=0x0 25CONFIG_ZBOOT_ROM_TEXT=0x0
diff --git a/arch/arm/configs/shmobile_defconfig b/arch/arm/configs/shmobile_defconfig
index d7346ad51043..c8201a93b54d 100644
--- a/arch/arm/configs/shmobile_defconfig
+++ b/arch/arm/configs/shmobile_defconfig
@@ -17,7 +17,6 @@ CONFIG_ARCH_R8A7779=y
17CONFIG_ARCH_R8A7790=y 17CONFIG_ARCH_R8A7790=y
18CONFIG_ARCH_R8A7791=y 18CONFIG_ARCH_R8A7791=y
19CONFIG_ARCH_R8A7794=y 19CONFIG_ARCH_R8A7794=y
20CONFIG_MACH_KOELSCH=y
21CONFIG_MACH_LAGER=y 20CONFIG_MACH_LAGER=y
22CONFIG_MACH_MARZEN=y 21CONFIG_MACH_MARZEN=y
23# CONFIG_SWP_EMULATE is not set 22# CONFIG_SWP_EMULATE is not set
diff --git a/arch/arm/configs/socfpga_defconfig b/arch/arm/configs/socfpga_defconfig
index d7a5855a5db8..a2956c3112f1 100644
--- a/arch/arm/configs/socfpga_defconfig
+++ b/arch/arm/configs/socfpga_defconfig
@@ -1,5 +1,6 @@
1CONFIG_EXPERIMENTAL=y
2CONFIG_SYSVIPC=y 1CONFIG_SYSVIPC=y
2CONFIG_FHANDLE=y
3CONFIG_HIGH_RES_TIMERS=y
3CONFIG_IKCONFIG=y 4CONFIG_IKCONFIG=y
4CONFIG_IKCONFIG_PROC=y 5CONFIG_IKCONFIG_PROC=y
5CONFIG_LOG_BUF_SHIFT=14 6CONFIG_LOG_BUF_SHIFT=14
@@ -11,23 +12,17 @@ CONFIG_PROFILING=y
11CONFIG_OPROFILE=y 12CONFIG_OPROFILE=y
12CONFIG_MODULES=y 13CONFIG_MODULES=y
13CONFIG_MODULE_UNLOAD=y 14CONFIG_MODULE_UNLOAD=y
14CONFIG_HOTPLUG=y
15# CONFIG_LBDAF is not set 15# CONFIG_LBDAF is not set
16# CONFIG_BLK_DEV_BSG is not set 16# CONFIG_BLK_DEV_BSG is not set
17# CONFIG_IOSCHED_DEADLINE is not set 17# CONFIG_IOSCHED_DEADLINE is not set
18# CONFIG_IOSCHED_CFQ is not set 18# CONFIG_IOSCHED_CFQ is not set
19CONFIG_ARCH_SOCFPGA=y 19CONFIG_ARCH_SOCFPGA=y
20CONFIG_MACH_SOCFPGA_CYCLONE5=y
21CONFIG_ARM_THUMBEE=y 20CONFIG_ARM_THUMBEE=y
22# CONFIG_ARCH_VEXPRESS_CORTEX_A5_A9_ERRATA is not set
23# CONFIG_CACHE_L2X0 is not set
24CONFIG_HIGH_RES_TIMERS=y
25CONFIG_SMP=y 21CONFIG_SMP=y
26CONFIG_NR_CPUS=2 22CONFIG_NR_CPUS=2
27CONFIG_AEABI=y 23CONFIG_AEABI=y
28CONFIG_ZBOOT_ROM_TEXT=0x0 24CONFIG_ZBOOT_ROM_TEXT=0x0
29CONFIG_ZBOOT_ROM_BSS=0x0 25CONFIG_ZBOOT_ROM_BSS=0x0
30CONFIG_CMDLINE=""
31CONFIG_VFP=y 26CONFIG_VFP=y
32CONFIG_NEON=y 27CONFIG_NEON=y
33CONFIG_NET=y 28CONFIG_NET=y
@@ -41,38 +36,30 @@ CONFIG_IP_PNP=y
41CONFIG_IP_PNP_DHCP=y 36CONFIG_IP_PNP_DHCP=y
42CONFIG_IP_PNP_BOOTP=y 37CONFIG_IP_PNP_BOOTP=y
43CONFIG_IP_PNP_RARP=y 38CONFIG_IP_PNP_RARP=y
39CONFIG_IPV6=y
40CONFIG_NETWORK_PHY_TIMESTAMPING=y
41CONFIG_VLAN_8021Q=y
42CONFIG_VLAN_8021Q_GVRP=y
44CONFIG_CAN=y 43CONFIG_CAN=y
45CONFIG_CAN_RAW=y
46CONFIG_CAN_BCM=y
47CONFIG_CAN_GW=y
48CONFIG_CAN_DEV=y
49CONFIG_CAN_CALC_BITTIMING=y
50CONFIG_CAN_C_CAN=y 44CONFIG_CAN_C_CAN=y
51CONFIG_CAN_C_CAN_PLATFORM=y 45CONFIG_CAN_C_CAN_PLATFORM=y
52CONFIG_CAN_DEBUG_DEVICES=y 46CONFIG_CAN_DEBUG_DEVICES=y
53CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 47CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
54CONFIG_DEVTMPFS=y 48CONFIG_DEVTMPFS=y
55CONFIG_PROC_DEVICETREE=y 49CONFIG_DEVTMPFS_MOUNT=y
56CONFIG_BLK_DEV_RAM=y 50CONFIG_BLK_DEV_RAM=y
57CONFIG_BLK_DEV_RAM_COUNT=2 51CONFIG_BLK_DEV_RAM_COUNT=2
58CONFIG_BLK_DEV_RAM_SIZE=8192 52CONFIG_BLK_DEV_RAM_SIZE=8192
53CONFIG_SRAM=y
59CONFIG_SCSI=y 54CONFIG_SCSI=y
60# CONFIG_SCSI_PROC_FS is not set 55# CONFIG_SCSI_PROC_FS is not set
61CONFIG_BLK_DEV_SD=y 56CONFIG_BLK_DEV_SD=y
62# CONFIG_SCSI_LOWLEVEL is not set 57# CONFIG_SCSI_LOWLEVEL is not set
63CONFIG_NETDEVICES=y 58CONFIG_NETDEVICES=y
64CONFIG_STMMAC_ETH=y 59CONFIG_STMMAC_ETH=y
60CONFIG_DWMAC_SOCFPGA=y
65CONFIG_MICREL_PHY=y 61CONFIG_MICREL_PHY=y
66# CONFIG_STMMAC_PHY_ID_ZERO_WORKAROUND is not set
67CONFIG_INPUT_EVDEV=y 62CONFIG_INPUT_EVDEV=y
68CONFIG_DWMAC_SOCFPGA=y
69CONFIG_PPS=y
70CONFIG_NETWORK_PHY_TIMESTAMPING=y
71CONFIG_PTP_1588_CLOCK=y
72CONFIG_VLAN_8021Q=y
73CONFIG_VLAN_8021Q_GVRP=y
74CONFIG_GARP=y
75CONFIG_IPV6=y
76# CONFIG_SERIO_SERPORT is not set 63# CONFIG_SERIO_SERPORT is not set
77CONFIG_SERIO_AMBAKMI=y 64CONFIG_SERIO_AMBAKMI=y
78CONFIG_LEGACY_PTY_COUNT=16 65CONFIG_LEGACY_PTY_COUNT=16
@@ -81,45 +68,43 @@ CONFIG_SERIAL_8250_CONSOLE=y
81CONFIG_SERIAL_8250_NR_UARTS=2 68CONFIG_SERIAL_8250_NR_UARTS=2
82CONFIG_SERIAL_8250_RUNTIME_UARTS=2 69CONFIG_SERIAL_8250_RUNTIME_UARTS=2
83CONFIG_SERIAL_8250_DW=y 70CONFIG_SERIAL_8250_DW=y
71CONFIG_I2C=y
72CONFIG_I2C_CHARDEV=y
73CONFIG_I2C_DESIGNWARE_PLATFORM=y
84CONFIG_GPIOLIB=y 74CONFIG_GPIOLIB=y
85CONFIG_GPIO_SYSFS=y 75CONFIG_GPIO_SYSFS=y
86CONFIG_GPIO_DWAPB=y 76CONFIG_GPIO_DWAPB=y
87# CONFIG_RTC_HCTOSYS is not set 77CONFIG_PMBUS=y
78CONFIG_SENSORS_LTC2978=y
79CONFIG_SENSORS_LTC2978_REGULATOR=y
88CONFIG_WATCHDOG=y 80CONFIG_WATCHDOG=y
89CONFIG_DW_WATCHDOG=y 81CONFIG_DW_WATCHDOG=y
82CONFIG_REGULATOR=y
83CONFIG_REGULATOR_FIXED_VOLTAGE=y
84CONFIG_USB=y
85CONFIG_USB_DWC2=y
86CONFIG_USB_DWC2_HOST=y
87CONFIG_MMC=y
88CONFIG_MMC_DW=y
90CONFIG_EXT2_FS=y 89CONFIG_EXT2_FS=y
91CONFIG_EXT2_FS_XATTR=y 90CONFIG_EXT2_FS_XATTR=y
92CONFIG_EXT2_FS_POSIX_ACL=y 91CONFIG_EXT2_FS_POSIX_ACL=y
93CONFIG_EXT3_FS=y 92CONFIG_EXT3_FS=y
94CONFIG_NFS_FS=y 93CONFIG_EXT4_FS=y
95CONFIG_ROOT_NFS=y
96# CONFIG_DNOTIFY is not set
97# CONFIG_INOTIFY_USER is not set
98CONFIG_FHANDLE=y
99CONFIG_VFAT_FS=y 94CONFIG_VFAT_FS=y
100CONFIG_NTFS_FS=y 95CONFIG_NTFS_FS=y
101CONFIG_NTFS_RW=y 96CONFIG_NTFS_RW=y
102CONFIG_TMPFS=y 97CONFIG_TMPFS=y
103CONFIG_JFFS2_FS=y 98CONFIG_CONFIGFS_FS=y
99CONFIG_NFS_FS=y
100CONFIG_ROOT_NFS=y
104CONFIG_NLS_CODEPAGE_437=y 101CONFIG_NLS_CODEPAGE_437=y
105CONFIG_NLS_ISO8859_1=y 102CONFIG_NLS_ISO8859_1=y
103CONFIG_PRINTK_TIME=y
104CONFIG_DEBUG_INFO=y
106CONFIG_MAGIC_SYSRQ=y 105CONFIG_MAGIC_SYSRQ=y
107CONFIG_DETECT_HUNG_TASK=y 106CONFIG_DETECT_HUNG_TASK=y
108# CONFIG_SCHED_DEBUG is not set 107# CONFIG_SCHED_DEBUG is not set
109CONFIG_DEBUG_INFO=y
110CONFIG_ENABLE_DEFAULT_TRACERS=y 108CONFIG_ENABLE_DEFAULT_TRACERS=y
111CONFIG_DEBUG_USER=y 109CONFIG_DEBUG_USER=y
112CONFIG_XZ_DEC=y 110CONFIG_XZ_DEC=y
113CONFIG_I2C=y
114CONFIG_I2C_DESIGNWARE_CORE=y
115CONFIG_I2C_DESIGNWARE_PLATFORM=y
116CONFIG_I2C_CHARDEV=y
117CONFIG_MMC=y
118CONFIG_MMC_DW=y
119CONFIG_PM=y
120CONFIG_SUSPEND=y
121CONFIG_MMC_UNSAFE_RESUME=y
122CONFIG_USB=y
123CONFIG_USB_DWC2=y
124CONFIG_USB_DWC2_HOST=y
125CONFIG_USB_DWC2_PLATFORM=y
diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index fc44d3761f9e..ce73ab635414 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -44,16 +44,6 @@ struct cpu_context_save {
44 __u32 extra[2]; /* Xscale 'acc' register, etc */ 44 __u32 extra[2]; /* Xscale 'acc' register, etc */
45}; 45};
46 46
47struct arm_restart_block {
48 union {
49 /* For user cache flushing */
50 struct {
51 unsigned long start;
52 unsigned long end;
53 } cache;
54 };
55};
56
57/* 47/*
58 * low level task data that entry.S needs immediate access to. 48 * low level task data that entry.S needs immediate access to.
59 * __switch_to() assumes cpu_context follows immediately after cpu_domain. 49 * __switch_to() assumes cpu_context follows immediately after cpu_domain.
@@ -79,7 +69,6 @@ struct thread_info {
79 unsigned long thumbee_state; /* ThumbEE Handler Base register */ 69 unsigned long thumbee_state; /* ThumbEE Handler Base register */
80#endif 70#endif
81 struct restart_block restart_block; 71 struct restart_block restart_block;
82 struct arm_restart_block arm_restart_block;
83}; 72};
84 73
85#define INIT_THREAD_INFO(tsk) \ 74#define INIT_THREAD_INFO(tsk) \
diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index 0c8b10801d36..9f5d81881eb6 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -533,8 +533,6 @@ static int bad_syscall(int n, struct pt_regs *regs)
533 return regs->ARM_r0; 533 return regs->ARM_r0;
534} 534}
535 535
536static long do_cache_op_restart(struct restart_block *);
537
538static inline int 536static inline int
539__do_cache_op(unsigned long start, unsigned long end) 537__do_cache_op(unsigned long start, unsigned long end)
540{ 538{
@@ -543,24 +541,8 @@ __do_cache_op(unsigned long start, unsigned long end)
543 do { 541 do {
544 unsigned long chunk = min(PAGE_SIZE, end - start); 542 unsigned long chunk = min(PAGE_SIZE, end - start);
545 543
546 if (signal_pending(current)) { 544 if (fatal_signal_pending(current))
547 struct thread_info *ti = current_thread_info(); 545 return 0;
548
549 ti->restart_block = (struct restart_block) {
550 .fn = do_cache_op_restart,
551 };
552
553 ti->arm_restart_block = (struct arm_restart_block) {
554 {
555 .cache = {
556 .start = start,
557 .end = end,
558 },
559 },
560 };
561
562 return -ERESTART_RESTARTBLOCK;
563 }
564 546
565 ret = flush_cache_user_range(start, start + chunk); 547 ret = flush_cache_user_range(start, start + chunk);
566 if (ret) 548 if (ret)
@@ -573,15 +555,6 @@ __do_cache_op(unsigned long start, unsigned long end)
573 return 0; 555 return 0;
574} 556}
575 557
576static long do_cache_op_restart(struct restart_block *unused)
577{
578 struct arm_restart_block *restart_block;
579
580 restart_block = &current_thread_info()->arm_restart_block;
581 return __do_cache_op(restart_block->cache.start,
582 restart_block->cache.end);
583}
584
585static inline int 558static inline int
586do_cache_op(unsigned long start, unsigned long end, int flags) 559do_cache_op(unsigned long start, unsigned long end, int flags)
587{ 560{
diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c
index 57a403a5c22b..8664ff17cbbe 100644
--- a/arch/arm/kvm/mmu.c
+++ b/arch/arm/kvm/mmu.c
@@ -197,7 +197,8 @@ static void unmap_range(struct kvm *kvm, pgd_t *pgdp,
197 pgd = pgdp + pgd_index(addr); 197 pgd = pgdp + pgd_index(addr);
198 do { 198 do {
199 next = kvm_pgd_addr_end(addr, end); 199 next = kvm_pgd_addr_end(addr, end);
200 unmap_puds(kvm, pgd, addr, next); 200 if (!pgd_none(*pgd))
201 unmap_puds(kvm, pgd, addr, next);
201 } while (pgd++, addr = next, addr != end); 202 } while (pgd++, addr = next, addr != end);
202} 203}
203 204
@@ -834,6 +835,11 @@ static bool kvm_is_write_fault(struct kvm_vcpu *vcpu)
834 return kvm_vcpu_dabt_iswrite(vcpu); 835 return kvm_vcpu_dabt_iswrite(vcpu);
835} 836}
836 837
838static bool kvm_is_device_pfn(unsigned long pfn)
839{
840 return !pfn_valid(pfn);
841}
842
837static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, 843static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
838 struct kvm_memory_slot *memslot, unsigned long hva, 844 struct kvm_memory_slot *memslot, unsigned long hva,
839 unsigned long fault_status) 845 unsigned long fault_status)
@@ -904,7 +910,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
904 if (is_error_pfn(pfn)) 910 if (is_error_pfn(pfn))
905 return -EFAULT; 911 return -EFAULT;
906 912
907 if (kvm_is_mmio_pfn(pfn)) 913 if (kvm_is_device_pfn(pfn))
908 mem_type = PAGE_S2_DEVICE; 914 mem_type = PAGE_S2_DEVICE;
909 915
910 spin_lock(&kvm->mmu_lock); 916 spin_lock(&kvm->mmu_lock);
diff --git a/arch/arm/mach-at91/Kconfig b/arch/arm/mach-at91/Kconfig
index 0e6d548b70d9..2395c68b3e32 100644
--- a/arch/arm/mach-at91/Kconfig
+++ b/arch/arm/mach-at91/Kconfig
@@ -15,27 +15,10 @@ config HAVE_AT91_DBGU1
15config HAVE_AT91_DBGU2 15config HAVE_AT91_DBGU2
16 bool 16 bool
17 17
18config AT91_USE_OLD_CLK
19 bool
20
21config AT91_PMC_UNIT
22 bool
23 default !ARCH_AT91X40
24
25config COMMON_CLK_AT91 18config COMMON_CLK_AT91
26 bool 19 bool
27 default AT91_PMC_UNIT && USE_OF && !AT91_USE_OLD_CLK
28 select COMMON_CLK 20 select COMMON_CLK
29 21
30config OLD_CLK_AT91
31 bool
32 default AT91_PMC_UNIT && AT91_USE_OLD_CLK
33
34config OLD_IRQ_AT91
35 bool
36 select MULTI_IRQ_HANDLER
37 select SPARSE_IRQ
38
39config HAVE_AT91_SMD 22config HAVE_AT91_SMD
40 bool 23 bool
41 24
@@ -44,20 +27,22 @@ config HAVE_AT91_H32MX
44 27
45config SOC_AT91SAM9 28config SOC_AT91SAM9
46 bool 29 bool
47 select ATMEL_AIC_IRQ if !OLD_IRQ_AT91 30 select ATMEL_AIC_IRQ
31 select COMMON_CLK_AT91
48 select CPU_ARM926T 32 select CPU_ARM926T
49 select GENERIC_CLOCKEVENTS 33 select GENERIC_CLOCKEVENTS
50 select MEMORY if USE_OF 34 select MEMORY
51 select ATMEL_SDRAMC if USE_OF 35 select ATMEL_SDRAMC
52 36
53config SOC_SAMA5 37config SOC_SAMA5
54 bool 38 bool
55 select ATMEL_AIC5_IRQ 39 select ATMEL_AIC5_IRQ
40 select COMMON_CLK_AT91
56 select CPU_V7 41 select CPU_V7
57 select GENERIC_CLOCKEVENTS 42 select GENERIC_CLOCKEVENTS
58 select USE_OF
59 select MEMORY 43 select MEMORY
60 select ATMEL_SDRAMC 44 select ATMEL_SDRAMC
45 select PHYLIB if NETDEVICES
61 46
62menu "Atmel AT91 System-on-Chip" 47menu "Atmel AT91 System-on-Chip"
63 48
@@ -65,16 +50,6 @@ choice
65 50
66 prompt "Core type" 51 prompt "Core type"
67 52
68config ARCH_AT91X40
69 bool "ARM7 AT91X40"
70 depends on !MMU
71 select CPU_ARM7TDMI
72 select ARCH_USES_GETTIMEOFFSET
73 select OLD_IRQ_AT91
74
75 help
76 Select this if you are using one of Atmel's AT91X40 SoC.
77
78config SOC_SAM_V4_V5 53config SOC_SAM_V4_V5
79 bool "ARM9 AT91SAM9/AT91RM9200" 54 bool "ARM9 AT91SAM9/AT91RM9200"
80 help 55 help
@@ -122,7 +97,8 @@ endif
122if SOC_SAM_V4_V5 97if SOC_SAM_V4_V5
123config SOC_AT91RM9200 98config SOC_AT91RM9200
124 bool "AT91RM9200" 99 bool "AT91RM9200"
125 select ATMEL_AIC_IRQ if !OLD_IRQ_AT91 100 select ATMEL_AIC_IRQ
101 select COMMON_CLK_AT91
126 select CPU_ARM920T 102 select CPU_ARM920T
127 select GENERIC_CLOCKEVENTS 103 select GENERIC_CLOCKEVENTS
128 select HAVE_AT91_DBGU0 104 select HAVE_AT91_DBGU0
@@ -198,37 +174,11 @@ config SOC_AT91SAM9N12
198# ---------------------------------------------------------- 174# ----------------------------------------------------------
199endif # SOC_SAM_V4_V5 175endif # SOC_SAM_V4_V5
200 176
201
202if SOC_SAM_V4_V5 || ARCH_AT91X40
203source arch/arm/mach-at91/Kconfig.non_dt
204endif
205
206comment "Generic Board Type"
207
208config MACH_AT91RM9200_DT 177config MACH_AT91RM9200_DT
209 bool "Atmel AT91RM9200 Evaluation Kits with device-tree support" 178 def_bool SOC_AT91RM9200
210 depends on SOC_AT91RM9200
211 select USE_OF
212 help
213 Select this if you want to experiment device-tree with
214 an Atmel RM9200 Evaluation Kit.
215 179
216config MACH_AT91SAM9_DT 180config MACH_AT91SAM9_DT
217 bool "Atmel AT91SAM Evaluation Kits with device-tree support" 181 def_bool SOC_AT91SAM9
218 depends on SOC_AT91SAM9
219 select USE_OF
220 help
221 Select this if you want to experiment device-tree with
222 an Atmel Evaluation Kit.
223
224config MACH_SAMA5_DT
225 bool "Atmel SAMA5 Evaluation Kits with device-tree support"
226 depends on SOC_SAMA5
227 select USE_OF
228 select PHYLIB if NETDEVICES
229 help
230 Select this if you want to experiment device-tree with
231 an Atmel Evaluation Kit.
232 182
233# ---------------------------------------------------------- 183# ----------------------------------------------------------
234 184
@@ -251,7 +201,7 @@ config AT91_TIMER_HZ
251 int "Kernel HZ (jiffies per second)" 201 int "Kernel HZ (jiffies per second)"
252 range 32 1024 202 range 32 1024
253 depends on ARCH_AT91 203 depends on ARCH_AT91
254 default "128" if ARCH_AT91RM9200 204 default "128" if SOC_AT91RM9200
255 default "100" 205 default "100"
256 help 206 help
257 On AT91rm9200 chips where you're using a system clock derived 207 On AT91rm9200 chips where you're using a system clock derived
diff --git a/arch/arm/mach-at91/Kconfig.non_dt b/arch/arm/mach-at91/Kconfig.non_dt
deleted file mode 100644
index d8e88219edb4..000000000000
--- a/arch/arm/mach-at91/Kconfig.non_dt
+++ /dev/null
@@ -1,344 +0,0 @@
1menu "Atmel Non-DT world"
2
3config HAVE_AT91_DATAFLASH_CARD
4 bool
5
6choice
7 prompt "Atmel AT91 Processor Devices for non DT boards"
8 depends on !ARCH_AT91X40
9
10config ARCH_AT91_NONE
11 bool "None"
12
13config ARCH_AT91RM9200
14 bool "AT91RM9200"
15 select SOC_AT91RM9200
16 select AT91_USE_OLD_CLK
17 select OLD_IRQ_AT91
18
19config ARCH_AT91SAM9260
20 bool "AT91SAM9260 or AT91SAM9XE or AT91SAM9G20"
21 select SOC_AT91SAM9260
22 select AT91_USE_OLD_CLK
23 select OLD_IRQ_AT91
24
25config ARCH_AT91SAM9261
26 bool "AT91SAM9261 or AT91SAM9G10"
27 select SOC_AT91SAM9261
28 select AT91_USE_OLD_CLK
29 select OLD_IRQ_AT91
30
31config ARCH_AT91SAM9263
32 bool "AT91SAM9263"
33 select SOC_AT91SAM9263
34 select AT91_USE_OLD_CLK
35 select OLD_IRQ_AT91
36
37config ARCH_AT91SAM9RL
38 bool "AT91SAM9RL"
39 select SOC_AT91SAM9RL
40 select AT91_USE_OLD_CLK
41 select OLD_IRQ_AT91
42
43config ARCH_AT91SAM9G45
44 bool "AT91SAM9G45"
45 select SOC_AT91SAM9G45
46 select AT91_USE_OLD_CLK
47 select OLD_IRQ_AT91
48
49endchoice
50
51config ARCH_AT91SAM9G20
52 bool
53 select ARCH_AT91SAM9260
54
55config ARCH_AT91SAM9G10
56 bool
57 select ARCH_AT91SAM9261
58
59# ----------------------------------------------------------
60
61if ARCH_AT91RM9200
62
63comment "AT91RM9200 Board Type"
64
65config MACH_ONEARM
66 bool "Ajeco 1ARM Single Board Computer"
67 help
68 Select this if you are using Ajeco's 1ARM Single Board Computer.
69 <http://www.ajeco.fi/>
70
71config MACH_AT91RM9200EK
72 bool "Atmel AT91RM9200-EK Evaluation Kit"
73 select HAVE_AT91_DATAFLASH_CARD
74 help
75 Select this if you are using Atmel's AT91RM9200-EK Evaluation Kit.
76 <http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3507>
77
78config MACH_CSB337
79 bool "Cogent CSB337"
80 help
81 Select this if you are using Cogent's CSB337 board.
82 <http://www.cogcomp.com/csb_csb337.htm>
83
84config MACH_CSB637
85 bool "Cogent CSB637"
86 help
87 Select this if you are using Cogent's CSB637 board.
88 <http://www.cogcomp.com/csb_csb637.htm>
89
90config MACH_CARMEVA
91 bool "Conitec ARM&EVA"
92 help
93 Select this if you are using Conitec's AT91RM9200-MCU-Module.
94 <http://www.conitec.net/english/linuxboard.php>
95
96config MACH_ATEB9200
97 bool "Embest ATEB9200"
98 help
99 Select this if you are using Embest's ATEB9200 board.
100 <http://www.embedinfo.com/english/product/ATEB9200.asp>
101
102config MACH_KB9200
103 bool "KwikByte KB920x"
104 help
105 Select this if you are using KwikByte's KB920x board.
106 <http://www.kwikbyte.com/KB9202.html>
107
108config MACH_PICOTUX2XX
109 bool "picotux 200"
110 help
111 Select this if you are using a picotux 200.
112 <http://www.picotux.com/>
113
114config MACH_KAFA
115 bool "Sperry-Sun KAFA board"
116 help
117 Select this if you are using Sperry-Sun's KAFA board.
118
119config MACH_ECBAT91
120 bool "emQbit ECB_AT91 SBC"
121 select HAVE_AT91_DATAFLASH_CARD
122 help
123 Select this if you are using emQbit's ECB_AT91 board.
124 <http://wiki.emqbit.com/free-ecb-at91>
125
126config MACH_YL9200
127 bool "ucDragon YL-9200"
128 help
129 Select this if you are using the ucDragon YL-9200 board.
130
131config MACH_CPUAT91
132 bool "Eukrea CPUAT91"
133 help
134 Select this if you are using the Eukrea Electromatique's
135 CPUAT91 board <http://www.eukrea.com/>.
136
137config MACH_ECO920
138 bool "eco920"
139 help
140 Select this if you are using the eco920 board
141endif
142
143# ----------------------------------------------------------
144
145if ARCH_AT91SAM9260
146
147comment "AT91SAM9260 Variants"
148
149comment "AT91SAM9260 / AT91SAM9XE Board Type"
150
151config MACH_AT91SAM9260EK
152 bool "Atmel AT91SAM9260-EK / AT91SAM9XE Evaluation Kit"
153 select HAVE_AT91_DATAFLASH_CARD
154 help
155 Select this if you are using Atmel's AT91SAM9260-EK or AT91SAM9XE Evaluation Kit
156 <http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3933>
157
158config MACH_CAM60
159 bool "KwikByte KB9260 (CAM60) board"
160 help
161 Select this if you are using KwikByte's KB9260 (CAM60) board based on the Atmel AT91SAM9260.
162 <http://www.kwikbyte.com/KB9260.html>
163
164config MACH_SAM9_L9260
165 bool "Olimex SAM9-L9260 board"
166 select HAVE_AT91_DATAFLASH_CARD
167 help
168 Select this if you are using Olimex's SAM9-L9260 board based on the Atmel AT91SAM9260.
169 <http://www.olimex.com/dev/sam9-L9260.html>
170
171config MACH_AFEB9260
172 bool "Custom afeb9260 board v1"
173 help
174 Select this if you are using custom afeb9260 board based on
175 open hardware design. Select this for revision 1 of the board.
176 <svn://194.85.238.22/home/users/george/svn/arm9eb>
177 <http://groups.google.com/group/arm9fpga-evolution-board>
178
179config MACH_CPU9260
180 bool "Eukrea CPU9260 board"
181 help
182 Select this if you are using a Eukrea Electromatique's
183 CPU9260 Board <http://www.eukrea.com/>
184
185config MACH_FLEXIBITY
186 bool "Flexibity Connect board"
187 help
188 Select this if you are using Flexibity Connect board
189 <http://www.flexibity.com>
190
191comment "AT91SAM9G20 Board Type"
192
193config MACH_AT91SAM9G20EK
194 bool "Atmel AT91SAM9G20-EK Evaluation Kit"
195 select HAVE_AT91_DATAFLASH_CARD
196 help
197 Select this if you are using Atmel's AT91SAM9G20-EK Evaluation Kit
198 that embeds only one SD/MMC slot.
199
200config MACH_AT91SAM9G20EK_2MMC
201 depends on MACH_AT91SAM9G20EK
202 bool "Atmel AT91SAM9G20-EK Evaluation Kit with 2 SD/MMC Slots"
203 help
204 Select this if you are using an Atmel AT91SAM9G20-EK Evaluation Kit
205 with 2 SD/MMC Slots. This is the case for AT91SAM9G20-EK rev. C and
206 onwards.
207 <http://www.atmel.com/tools/SAM9G20-EK.aspx>
208
209config MACH_CPU9G20
210 bool "Eukrea CPU9G20 board"
211 help
212 Select this if you are using a Eukrea Electromatique's
213 CPU9G20 Board <http://www.eukrea.com/>
214
215config MACH_PORTUXG20
216 bool "taskit PortuxG20"
217 help
218 Select this if you are using taskit's PortuxG20.
219 <http://www.taskit.de/en/>
220
221config MACH_STAMP9G20
222 bool "taskit Stamp9G20 CPU module"
223 help
224 Select this if you are using taskit's Stamp9G20 CPU module on its
225 evaluation board.
226 <http://www.taskit.de/en/>
227
228config MACH_PCONTROL_G20
229 bool "PControl G20 CPU module"
230 help
231 Select this if you are using taskit's Stamp9G20 CPU module on this
232 carrier board, being the decentralized unit of a building automation
233 system; featuring nvram, eth-switch, iso-rs485, display, io
234
235config MACH_GSIA18S
236 bool "GS_IA18_S board"
237 help
238 This enables support for the GS_IA18_S board
239 produced by GeoSIG Ltd company. This is an internet accelerograph.
240 <http://www.geosig.com>
241
242config MACH_SNAPPER_9260
243 bool "Bluewater Systems Snapper 9260/9G20 module"
244 help
245 Select this if you are using the Bluewater Systems Snapper 9260 or
246 Snapper 9G20 modules.
247 <http://www.bluewatersys.com/>
248endif
249
250# ----------------------------------------------------------
251
252if ARCH_AT91SAM9261
253
254comment "AT91SAM9261 Board Type"
255
256config MACH_AT91SAM9261EK
257 bool "Atmel AT91SAM9261-EK Evaluation Kit"
258 select HAVE_AT91_DATAFLASH_CARD
259 help
260 Select this if you are using Atmel's AT91SAM9261-EK Evaluation Kit.
261 <http://www.atmel.com/dyn/products/tools_card.asp?tool_id=3820>
262
263comment "AT91SAM9G10 Board Type"
264
265config MACH_AT91SAM9G10EK
266 bool "Atmel AT91SAM9G10-EK Evaluation Kit"
267 select HAVE_AT91_DATAFLASH_CARD
268 help
269 Select this if you are using Atmel's AT91SAM9G10-EK Evaluation Kit.
270 <http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4588>
271
272endif
273
274# ----------------------------------------------------------
275
276if ARCH_AT91SAM9263
277
278comment "AT91SAM9263 Board Type"
279
280config MACH_AT91SAM9263EK
281 bool "Atmel AT91SAM9263-EK Evaluation Kit"
282 select HAVE_AT91_DATAFLASH_CARD
283 help
284 Select this if you are using Atmel's AT91SAM9263-EK Evaluation Kit.
285 <http://www.atmel.com/dyn/products/tools_card.asp?tool_id=4057>
286
287endif
288
289# ----------------------------------------------------------
290
291if ARCH_AT91SAM9RL
292
293comment "AT91SAM9RL Board Type"
294
295config MACH_AT91SAM9RLEK
296 bool "Atmel AT91SAM9RL-EK Evaluation Kit"
297 help
298 Select this if you are using Atmel's AT91SAM9RL-EK Evaluation Kit.
299
300endif
301
302# ----------------------------------------------------------
303
304if ARCH_AT91SAM9G45
305
306comment "AT91SAM9G45 Board Type"
307
308config MACH_AT91SAM9M10G45EK
309 bool "Atmel AT91SAM9M10G45-EK Evaluation Kits"
310 help
311 Select this if you are using Atmel's AT91SAM9M10G45-EK Evaluation Kit.
312 Those boards can be populated with any SoC of AT91SAM9G45 or AT91SAM9M10
313 families: AT91SAM9G45, AT91SAM9G46, AT91SAM9M10 and AT91SAM9M11.
314 <http://www.atmel.com/tools/SAM9M10-G45-EK.aspx>
315
316endif
317
318# ----------------------------------------------------------
319
320if ARCH_AT91X40
321
322comment "AT91X40 Board Type"
323
324config MACH_AT91EB01
325 bool "Atmel AT91EB01 Evaluation Kit"
326 help
327 Select this if you are using Atmel's AT91EB01 Evaluation Kit.
328 It is also a popular target for simulators such as GDB's
329 ARM simulator (commonly known as the ARMulator) and the
330 Skyeye simulator.
331
332endif
333
334# ----------------------------------------------------------
335
336comment "AT91 Board Options"
337
338config MTD_AT91_DATAFLASH_CARD
339 bool "Enable DataFlash Card support"
340 depends on HAVE_AT91_DATAFLASH_CARD
341 help
342 Enable support for the DataFlash card.
343
344endmenu
diff --git a/arch/arm/mach-at91/Makefile b/arch/arm/mach-at91/Makefile
index 1b9ae0257a6e..7b6424d40764 100644
--- a/arch/arm/mach-at91/Makefile
+++ b/arch/arm/mach-at91/Makefile
@@ -2,10 +2,8 @@
2# Makefile for the linux kernel. 2# Makefile for the linux kernel.
3# 3#
4 4
5obj-y := gpio.o setup.o sysirq_mask.o 5obj-y := setup.o sysirq_mask.o
6 6
7obj-$(CONFIG_OLD_IRQ_AT91) += irq.o
8obj-$(CONFIG_OLD_CLK_AT91) += clock.o
9obj-$(CONFIG_SOC_AT91SAM9) += sam9_smc.o 7obj-$(CONFIG_SOC_AT91SAM9) += sam9_smc.o
10 8
11# CPU-specific support 9# CPU-specific support
@@ -20,73 +18,12 @@ obj-$(CONFIG_SOC_AT91SAM9RL) += at91sam9rl.o
20obj-$(CONFIG_SOC_SAMA5D3) += sama5d3.o 18obj-$(CONFIG_SOC_SAMA5D3) += sama5d3.o
21obj-$(CONFIG_SOC_SAMA5D4) += sama5d4.o 19obj-$(CONFIG_SOC_SAMA5D4) += sama5d4.o
22 20
23obj-$(CONFIG_ARCH_AT91RM9200) += at91rm9200_devices.o
24obj-$(CONFIG_ARCH_AT91SAM9260) += at91sam9260_devices.o
25obj-$(CONFIG_ARCH_AT91SAM9261) += at91sam9261_devices.o
26obj-$(CONFIG_ARCH_AT91SAM9263) += at91sam9263_devices.o
27obj-$(CONFIG_ARCH_AT91SAM9RL) += at91sam9rl_devices.o
28obj-$(CONFIG_ARCH_AT91SAM9G45) += at91sam9g45_devices.o
29obj-$(CONFIG_ARCH_AT91X40) += at91x40.o at91x40_time.o
30
31# AT91RM9200 board-specific support
32obj-$(CONFIG_MACH_ONEARM) += board-1arm.o
33obj-$(CONFIG_MACH_AT91RM9200EK) += board-rm9200ek.o
34obj-$(CONFIG_MACH_CSB337) += board-csb337.o
35obj-$(CONFIG_MACH_CSB637) += board-csb637.o
36obj-$(CONFIG_MACH_CARMEVA) += board-carmeva.o
37obj-$(CONFIG_MACH_KB9200) += board-kb9202.o
38obj-$(CONFIG_MACH_ATEB9200) += board-eb9200.o
39obj-$(CONFIG_MACH_KAFA) += board-kafa.o
40obj-$(CONFIG_MACH_PICOTUX2XX) += board-picotux200.o
41obj-$(CONFIG_MACH_ECBAT91) += board-ecbat91.o
42obj-$(CONFIG_MACH_YL9200) += board-yl-9200.o
43obj-$(CONFIG_MACH_CPUAT91) += board-cpuat91.o
44obj-$(CONFIG_MACH_ECO920) += board-eco920.o
45
46# AT91SAM9260 board-specific support
47obj-$(CONFIG_MACH_AT91SAM9260EK) += board-sam9260ek.o
48obj-$(CONFIG_MACH_CAM60) += board-cam60.o
49obj-$(CONFIG_MACH_SAM9_L9260) += board-sam9-l9260.o
50obj-$(CONFIG_MACH_AFEB9260) += board-afeb-9260v1.o
51obj-$(CONFIG_MACH_CPU9260) += board-cpu9krea.o
52obj-$(CONFIG_MACH_FLEXIBITY) += board-flexibity.o
53
54# AT91SAM9261 board-specific support
55obj-$(CONFIG_MACH_AT91SAM9261EK) += board-sam9261ek.o
56obj-$(CONFIG_MACH_AT91SAM9G10EK) += board-sam9261ek.o
57
58# AT91SAM9263 board-specific support
59obj-$(CONFIG_MACH_AT91SAM9263EK) += board-sam9263ek.o
60
61# AT91SAM9RL board-specific support
62obj-$(CONFIG_MACH_AT91SAM9RLEK) += board-sam9rlek.o
63
64# AT91SAM9G20 board-specific support
65obj-$(CONFIG_MACH_AT91SAM9G20EK) += board-sam9g20ek.o
66obj-$(CONFIG_MACH_CPU9G20) += board-cpu9krea.o
67obj-$(CONFIG_MACH_STAMP9G20) += board-stamp9g20.o
68obj-$(CONFIG_MACH_PORTUXG20) += board-stamp9g20.o
69obj-$(CONFIG_MACH_PCONTROL_G20) += board-pcontrol-g20.o board-stamp9g20.o
70obj-$(CONFIG_MACH_GSIA18S) += board-gsia18s.o board-stamp9g20.o
71
72# AT91SAM9260/AT91SAM9G20 board-specific support
73obj-$(CONFIG_MACH_SNAPPER_9260) += board-snapper9260.o
74
75# AT91SAM9G45 board-specific support
76obj-$(CONFIG_MACH_AT91SAM9M10G45EK) += board-sam9m10g45ek.o
77
78# AT91SAM board with device-tree 21# AT91SAM board with device-tree
79obj-$(CONFIG_MACH_AT91RM9200_DT) += board-dt-rm9200.o 22obj-$(CONFIG_MACH_AT91RM9200_DT) += board-dt-rm9200.o
80obj-$(CONFIG_MACH_AT91SAM9_DT) += board-dt-sam9.o 23obj-$(CONFIG_MACH_AT91SAM9_DT) += board-dt-sam9.o
81 24
82# SAMA5 board with device-tree 25# SAMA5 board with device-tree
83obj-$(CONFIG_MACH_SAMA5_DT) += board-dt-sama5.o 26obj-$(CONFIG_SOC_SAMA5) += board-dt-sama5.o
84
85# AT91X40 board-specific support
86obj-$(CONFIG_MACH_AT91EB01) += board-eb01.o
87
88# Drivers
89obj-y += leds.o
90 27
91# Power Management 28# Power Management
92obj-$(CONFIG_PM) += pm.o 29obj-$(CONFIG_PM) += pm.o
diff --git a/arch/arm/mach-at91/Makefile.boot b/arch/arm/mach-at91/Makefile.boot
index 5309f9b6aabc..29ed0fa374ca 100644
--- a/arch/arm/mach-at91/Makefile.boot
+++ b/arch/arm/mach-at91/Makefile.boot
@@ -3,12 +3,6 @@
3# PARAMS_PHYS must be within 4MB of ZRELADDR 3# PARAMS_PHYS must be within 4MB of ZRELADDR
4# INITRD_PHYS must be in RAM 4# INITRD_PHYS must be in RAM
5 5
6ifeq ($(CONFIG_ARCH_AT91SAM9G45),y)
7 zreladdr-y += 0x70008000
8params_phys-y := 0x70000100
9initrd_phys-y := 0x70410000
10else
11 zreladdr-y += 0x20008000 6 zreladdr-y += 0x20008000
12params_phys-y := 0x20000100 7params_phys-y := 0x20000100
13initrd_phys-y := 0x20410000 8initrd_phys-y := 0x20410000
14endif
diff --git a/arch/arm/mach-at91/at91_aic.h b/arch/arm/mach-at91/at91_aic.h
deleted file mode 100644
index eaea66197fa1..000000000000
--- a/arch/arm/mach-at91/at91_aic.h
+++ /dev/null
@@ -1,99 +0,0 @@
1/*
2 * arch/arm/mach-at91/include/mach/at91_aic.h
3 *
4 * Copyright (C) 2005 Ivan Kokshaysky
5 * Copyright (C) SAN People
6 *
7 * Advanced Interrupt Controller (AIC) - System peripherals registers.
8 * Based on AT91RM9200 datasheet revision E.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 */
15
16#ifndef AT91_AIC_H
17#define AT91_AIC_H
18
19#ifndef __ASSEMBLY__
20extern void __iomem *at91_aic_base;
21
22#define at91_aic_read(field) \
23 __raw_readl(at91_aic_base + field)
24
25#define at91_aic_write(field, value) \
26 __raw_writel(value, at91_aic_base + field)
27#else
28.extern at91_aic_base
29#endif
30
31/* Number of irq lines managed by AIC */
32#define NR_AIC_IRQS 32
33#define NR_AIC5_IRQS 128
34
35#define AT91_AIC5_SSR 0x0 /* Source Select Register [AIC5] */
36#define AT91_AIC5_INTSEL_MSK (0x7f << 0) /* Interrupt Line Selection Mask */
37
38#define AT91_AIC_IRQ_MIN_PRIORITY 0
39#define AT91_AIC_IRQ_MAX_PRIORITY 7
40
41#define AT91_AIC_SMR(n) ((n) * 4) /* Source Mode Registers 0-31 */
42#define AT91_AIC5_SMR 0x4 /* Source Mode Register [AIC5] */
43#define AT91_AIC_PRIOR (7 << 0) /* Priority Level */
44#define AT91_AIC_SRCTYPE (3 << 5) /* Interrupt Source Type */
45#define AT91_AIC_SRCTYPE_LOW (0 << 5)
46#define AT91_AIC_SRCTYPE_FALLING (1 << 5)
47#define AT91_AIC_SRCTYPE_HIGH (2 << 5)
48#define AT91_AIC_SRCTYPE_RISING (3 << 5)
49
50#define AT91_AIC_SVR(n) (0x80 + ((n) * 4)) /* Source Vector Registers 0-31 */
51#define AT91_AIC5_SVR 0x8 /* Source Vector Register [AIC5] */
52#define AT91_AIC_IVR 0x100 /* Interrupt Vector Register */
53#define AT91_AIC5_IVR 0x10 /* Interrupt Vector Register [AIC5] */
54#define AT91_AIC_FVR 0x104 /* Fast Interrupt Vector Register */
55#define AT91_AIC5_FVR 0x14 /* Fast Interrupt Vector Register [AIC5] */
56#define AT91_AIC_ISR 0x108 /* Interrupt Status Register */
57#define AT91_AIC5_ISR 0x18 /* Interrupt Status Register [AIC5] */
58#define AT91_AIC_IRQID (0x1f << 0) /* Current Interrupt Identifier */
59
60#define AT91_AIC_IPR 0x10c /* Interrupt Pending Register */
61#define AT91_AIC5_IPR0 0x20 /* Interrupt Pending Register 0 [AIC5] */
62#define AT91_AIC5_IPR1 0x24 /* Interrupt Pending Register 1 [AIC5] */
63#define AT91_AIC5_IPR2 0x28 /* Interrupt Pending Register 2 [AIC5] */
64#define AT91_AIC5_IPR3 0x2c /* Interrupt Pending Register 3 [AIC5] */
65#define AT91_AIC_IMR 0x110 /* Interrupt Mask Register */
66#define AT91_AIC5_IMR 0x30 /* Interrupt Mask Register [AIC5] */
67#define AT91_AIC_CISR 0x114 /* Core Interrupt Status Register */
68#define AT91_AIC5_CISR 0x34 /* Core Interrupt Status Register [AIC5] */
69#define AT91_AIC_NFIQ (1 << 0) /* nFIQ Status */
70#define AT91_AIC_NIRQ (1 << 1) /* nIRQ Status */
71
72#define AT91_AIC_IECR 0x120 /* Interrupt Enable Command Register */
73#define AT91_AIC5_IECR 0x40 /* Interrupt Enable Command Register [AIC5] */
74#define AT91_AIC_IDCR 0x124 /* Interrupt Disable Command Register */
75#define AT91_AIC5_IDCR 0x44 /* Interrupt Disable Command Register [AIC5] */
76#define AT91_AIC_ICCR 0x128 /* Interrupt Clear Command Register */
77#define AT91_AIC5_ICCR 0x48 /* Interrupt Clear Command Register [AIC5] */
78#define AT91_AIC_ISCR 0x12c /* Interrupt Set Command Register */
79#define AT91_AIC5_ISCR 0x4c /* Interrupt Set Command Register [AIC5] */
80#define AT91_AIC_EOICR 0x130 /* End of Interrupt Command Register */
81#define AT91_AIC5_EOICR 0x38 /* End of Interrupt Command Register [AIC5] */
82#define AT91_AIC_SPU 0x134 /* Spurious Interrupt Vector Register */
83#define AT91_AIC5_SPU 0x3c /* Spurious Interrupt Vector Register [AIC5] */
84#define AT91_AIC_DCR 0x138 /* Debug Control Register */
85#define AT91_AIC5_DCR 0x6c /* Debug Control Register [AIC5] */
86#define AT91_AIC_DCR_PROT (1 << 0) /* Protection Mode */
87#define AT91_AIC_DCR_GMSK (1 << 1) /* General Mask */
88
89#define AT91_AIC_FFER 0x140 /* Fast Forcing Enable Register [SAM9 only] */
90#define AT91_AIC5_FFER 0x50 /* Fast Forcing Enable Register [AIC5] */
91#define AT91_AIC_FFDR 0x144 /* Fast Forcing Disable Register [SAM9 only] */
92#define AT91_AIC5_FFDR 0x54 /* Fast Forcing Disable Register [AIC5] */
93#define AT91_AIC_FFSR 0x148 /* Fast Forcing Status Register [SAM9 only] */
94#define AT91_AIC5_FFSR 0x58 /* Fast Forcing Status Register [AIC5] */
95
96void at91_aic_handle_irq(struct pt_regs *regs);
97void at91_aic5_handle_irq(struct pt_regs *regs);
98
99#endif
diff --git a/arch/arm/mach-at91/at91_tc.h b/arch/arm/mach-at91/at91_tc.h
deleted file mode 100644
index 46a317fd7164..000000000000
--- a/arch/arm/mach-at91/at91_tc.h
+++ /dev/null
@@ -1,146 +0,0 @@
1/*
2 * arch/arm/mach-at91/include/mach/at91_tc.h
3 *
4 * Copyright (C) SAN People
5 *
6 * Timer/Counter Unit (TC) registers.
7 * Based on AT91RM9200 datasheet revision E.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 */
14
15#ifndef AT91_TC_H
16#define AT91_TC_H
17
18#define AT91_TC_BCR 0xc0 /* TC Block Control Register */
19#define AT91_TC_SYNC (1 << 0) /* Synchro Command */
20
21#define AT91_TC_BMR 0xc4 /* TC Block Mode Register */
22#define AT91_TC_TC0XC0S (3 << 0) /* External Clock Signal 0 Selection */
23#define AT91_TC_TC0XC0S_TCLK0 (0 << 0)
24#define AT91_TC_TC0XC0S_NONE (1 << 0)
25#define AT91_TC_TC0XC0S_TIOA1 (2 << 0)
26#define AT91_TC_TC0XC0S_TIOA2 (3 << 0)
27#define AT91_TC_TC1XC1S (3 << 2) /* External Clock Signal 1 Selection */
28#define AT91_TC_TC1XC1S_TCLK1 (0 << 2)
29#define AT91_TC_TC1XC1S_NONE (1 << 2)
30#define AT91_TC_TC1XC1S_TIOA0 (2 << 2)
31#define AT91_TC_TC1XC1S_TIOA2 (3 << 2)
32#define AT91_TC_TC2XC2S (3 << 4) /* External Clock Signal 2 Selection */
33#define AT91_TC_TC2XC2S_TCLK2 (0 << 4)
34#define AT91_TC_TC2XC2S_NONE (1 << 4)
35#define AT91_TC_TC2XC2S_TIOA0 (2 << 4)
36#define AT91_TC_TC2XC2S_TIOA1 (3 << 4)
37
38
39#define AT91_TC_CCR 0x00 /* Channel Control Register */
40#define AT91_TC_CLKEN (1 << 0) /* Counter Clock Enable Command */
41#define AT91_TC_CLKDIS (1 << 1) /* Counter CLock Disable Command */
42#define AT91_TC_SWTRG (1 << 2) /* Software Trigger Command */
43
44#define AT91_TC_CMR 0x04 /* Channel Mode Register */
45#define AT91_TC_TCCLKS (7 << 0) /* Capture/Waveform Mode: Clock Selection */
46#define AT91_TC_TIMER_CLOCK1 (0 << 0)
47#define AT91_TC_TIMER_CLOCK2 (1 << 0)
48#define AT91_TC_TIMER_CLOCK3 (2 << 0)
49#define AT91_TC_TIMER_CLOCK4 (3 << 0)
50#define AT91_TC_TIMER_CLOCK5 (4 << 0)
51#define AT91_TC_XC0 (5 << 0)
52#define AT91_TC_XC1 (6 << 0)
53#define AT91_TC_XC2 (7 << 0)
54#define AT91_TC_CLKI (1 << 3) /* Capture/Waveform Mode: Clock Invert */
55#define AT91_TC_BURST (3 << 4) /* Capture/Waveform Mode: Burst Signal Selection */
56#define AT91_TC_LDBSTOP (1 << 6) /* Capture Mode: Counter Clock Stopped with TB Loading */
57#define AT91_TC_LDBDIS (1 << 7) /* Capture Mode: Counter Clock Disable with RB Loading */
58#define AT91_TC_ETRGEDG (3 << 8) /* Capture Mode: External Trigger Edge Selection */
59#define AT91_TC_ABETRG (1 << 10) /* Capture Mode: TIOA or TIOB External Trigger Selection */
60#define AT91_TC_CPCTRG (1 << 14) /* Capture Mode: RC Compare Trigger Enable */
61#define AT91_TC_WAVE (1 << 15) /* Capture/Waveform mode */
62#define AT91_TC_LDRA (3 << 16) /* Capture Mode: RA Loading Selection */
63#define AT91_TC_LDRB (3 << 18) /* Capture Mode: RB Loading Selection */
64
65#define AT91_TC_CPCSTOP (1 << 6) /* Waveform Mode: Counter Clock Stopped with RC Compare */
66#define AT91_TC_CPCDIS (1 << 7) /* Waveform Mode: Counter Clock Disable with RC Compare */
67#define AT91_TC_EEVTEDG (3 << 8) /* Waveform Mode: External Event Edge Selection */
68#define AT91_TC_EEVTEDG_NONE (0 << 8)
69#define AT91_TC_EEVTEDG_RISING (1 << 8)
70#define AT91_TC_EEVTEDG_FALLING (2 << 8)
71#define AT91_TC_EEVTEDG_BOTH (3 << 8)
72#define AT91_TC_EEVT (3 << 10) /* Waveform Mode: External Event Selection */
73#define AT91_TC_EEVT_TIOB (0 << 10)
74#define AT91_TC_EEVT_XC0 (1 << 10)
75#define AT91_TC_EEVT_XC1 (2 << 10)
76#define AT91_TC_EEVT_XC2 (3 << 10)
77#define AT91_TC_ENETRG (1 << 12) /* Waveform Mode: External Event Trigger Enable */
78#define AT91_TC_WAVESEL (3 << 13) /* Waveform Mode: Waveform Selection */
79#define AT91_TC_WAVESEL_UP (0 << 13)
80#define AT91_TC_WAVESEL_UP_AUTO (2 << 13)
81#define AT91_TC_WAVESEL_UPDOWN (1 << 13)
82#define AT91_TC_WAVESEL_UPDOWN_AUTO (3 << 13)
83#define AT91_TC_ACPA (3 << 16) /* Waveform Mode: RA Compare Effect on TIOA */
84#define AT91_TC_ACPA_NONE (0 << 16)
85#define AT91_TC_ACPA_SET (1 << 16)
86#define AT91_TC_ACPA_CLEAR (2 << 16)
87#define AT91_TC_ACPA_TOGGLE (3 << 16)
88#define AT91_TC_ACPC (3 << 18) /* Waveform Mode: RC Compre Effect on TIOA */
89#define AT91_TC_ACPC_NONE (0 << 18)
90#define AT91_TC_ACPC_SET (1 << 18)
91#define AT91_TC_ACPC_CLEAR (2 << 18)
92#define AT91_TC_ACPC_TOGGLE (3 << 18)
93#define AT91_TC_AEEVT (3 << 20) /* Waveform Mode: External Event Effect on TIOA */
94#define AT91_TC_AEEVT_NONE (0 << 20)
95#define AT91_TC_AEEVT_SET (1 << 20)
96#define AT91_TC_AEEVT_CLEAR (2 << 20)
97#define AT91_TC_AEEVT_TOGGLE (3 << 20)
98#define AT91_TC_ASWTRG (3 << 22) /* Waveform Mode: Software Trigger Effect on TIOA */
99#define AT91_TC_ASWTRG_NONE (0 << 22)
100#define AT91_TC_ASWTRG_SET (1 << 22)
101#define AT91_TC_ASWTRG_CLEAR (2 << 22)
102#define AT91_TC_ASWTRG_TOGGLE (3 << 22)
103#define AT91_TC_BCPB (3 << 24) /* Waveform Mode: RB Compare Effect on TIOB */
104#define AT91_TC_BCPB_NONE (0 << 24)
105#define AT91_TC_BCPB_SET (1 << 24)
106#define AT91_TC_BCPB_CLEAR (2 << 24)
107#define AT91_TC_BCPB_TOGGLE (3 << 24)
108#define AT91_TC_BCPC (3 << 26) /* Waveform Mode: RC Compare Effect on TIOB */
109#define AT91_TC_BCPC_NONE (0 << 26)
110#define AT91_TC_BCPC_SET (1 << 26)
111#define AT91_TC_BCPC_CLEAR (2 << 26)
112#define AT91_TC_BCPC_TOGGLE (3 << 26)
113#define AT91_TC_BEEVT (3 << 28) /* Waveform Mode: External Event Effect on TIOB */
114#define AT91_TC_BEEVT_NONE (0 << 28)
115#define AT91_TC_BEEVT_SET (1 << 28)
116#define AT91_TC_BEEVT_CLEAR (2 << 28)
117#define AT91_TC_BEEVT_TOGGLE (3 << 28)
118#define AT91_TC_BSWTRG (3 << 30) /* Waveform Mode: Software Trigger Effect on TIOB */
119#define AT91_TC_BSWTRG_NONE (0 << 30)
120#define AT91_TC_BSWTRG_SET (1 << 30)
121#define AT91_TC_BSWTRG_CLEAR (2 << 30)
122#define AT91_TC_BSWTRG_TOGGLE (3 << 30)
123
124#define AT91_TC_CV 0x10 /* Counter Value */
125#define AT91_TC_RA 0x14 /* Register A */
126#define AT91_TC_RB 0x18 /* Register B */
127#define AT91_TC_RC 0x1c /* Register C */
128
129#define AT91_TC_SR 0x20 /* Status Register */
130#define AT91_TC_COVFS (1 << 0) /* Counter Overflow Status */
131#define AT91_TC_LOVRS (1 << 1) /* Load Overrun Status */
132#define AT91_TC_CPAS (1 << 2) /* RA Compare Status */
133#define AT91_TC_CPBS (1 << 3) /* RB Compare Status */
134#define AT91_TC_CPCS (1 << 4) /* RC Compare Status */
135#define AT91_TC_LDRAS (1 << 5) /* RA Loading Status */
136#define AT91_TC_LDRBS (1 << 6) /* RB Loading Status */
137#define AT91_TC_ETRGS (1 << 7) /* External Trigger Status */
138#define AT91_TC_CLKSTA (1 << 16) /* Clock Enabling Status */
139#define AT91_TC_MTIOA (1 << 17) /* TIOA Mirror */
140#define AT91_TC_MTIOB (1 << 18) /* TIOB Mirror */
141
142#define AT91_TC_IER 0x24 /* Interrupt Enable Register */
143#define AT91_TC_IDR 0x28 /* Interrupt Disable Register */
144#define AT91_TC_IMR 0x2c /* Interrupt Mask Register */
145
146#endif
diff --git a/arch/arm/mach-at91/at91rm9200.c b/arch/arm/mach-at91/at91rm9200.c
index 038702ee8bc6..b52916947535 100644
--- a/arch/arm/mach-at91/at91rm9200.c
+++ b/arch/arm/mach-at91/at91rm9200.c
@@ -11,296 +11,15 @@
11 */ 11 */
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/reboot.h>
15#include <linux/clk/at91_pmc.h> 14#include <linux/clk/at91_pmc.h>
16 15
17#include <asm/irq.h>
18#include <asm/mach/arch.h>
19#include <asm/mach/map.h> 16#include <asm/mach/map.h>
20#include <asm/system_misc.h> 17#include <asm/system_misc.h>
21#include <mach/at91rm9200.h>
22#include <mach/at91_st.h> 18#include <mach/at91_st.h>
23#include <mach/cpu.h>
24#include <mach/hardware.h> 19#include <mach/hardware.h>
25 20
26#include "at91_aic.h"
27#include "soc.h" 21#include "soc.h"
28#include "generic.h" 22#include "generic.h"
29#include "sam9_smc.h"
30#include "pm.h"
31
32#if defined(CONFIG_OLD_CLK_AT91)
33#include "clock.h"
34/* --------------------------------------------------------------------
35 * Clocks
36 * -------------------------------------------------------------------- */
37
38/*
39 * The peripheral clocks.
40 */
41static struct clk udc_clk = {
42 .name = "udc_clk",
43 .pmc_mask = 1 << AT91RM9200_ID_UDP,
44 .type = CLK_TYPE_PERIPHERAL,
45};
46static struct clk ohci_clk = {
47 .name = "ohci_clk",
48 .pmc_mask = 1 << AT91RM9200_ID_UHP,
49 .type = CLK_TYPE_PERIPHERAL,
50};
51static struct clk ether_clk = {
52 .name = "ether_clk",
53 .pmc_mask = 1 << AT91RM9200_ID_EMAC,
54 .type = CLK_TYPE_PERIPHERAL,
55};
56static struct clk mmc_clk = {
57 .name = "mci_clk",
58 .pmc_mask = 1 << AT91RM9200_ID_MCI,
59 .type = CLK_TYPE_PERIPHERAL,
60};
61static struct clk twi_clk = {
62 .name = "twi_clk",
63 .pmc_mask = 1 << AT91RM9200_ID_TWI,
64 .type = CLK_TYPE_PERIPHERAL,
65};
66static struct clk usart0_clk = {
67 .name = "usart0_clk",
68 .pmc_mask = 1 << AT91RM9200_ID_US0,
69 .type = CLK_TYPE_PERIPHERAL,
70};
71static struct clk usart1_clk = {
72 .name = "usart1_clk",
73 .pmc_mask = 1 << AT91RM9200_ID_US1,
74 .type = CLK_TYPE_PERIPHERAL,
75};
76static struct clk usart2_clk = {
77 .name = "usart2_clk",
78 .pmc_mask = 1 << AT91RM9200_ID_US2,
79 .type = CLK_TYPE_PERIPHERAL,
80};
81static struct clk usart3_clk = {
82 .name = "usart3_clk",
83 .pmc_mask = 1 << AT91RM9200_ID_US3,
84 .type = CLK_TYPE_PERIPHERAL,
85};
86static struct clk spi_clk = {
87 .name = "spi_clk",
88 .pmc_mask = 1 << AT91RM9200_ID_SPI,
89 .type = CLK_TYPE_PERIPHERAL,
90};
91static struct clk pioA_clk = {
92 .name = "pioA_clk",
93 .pmc_mask = 1 << AT91RM9200_ID_PIOA,
94 .type = CLK_TYPE_PERIPHERAL,
95};
96static struct clk pioB_clk = {
97 .name = "pioB_clk",
98 .pmc_mask = 1 << AT91RM9200_ID_PIOB,
99 .type = CLK_TYPE_PERIPHERAL,
100};
101static struct clk pioC_clk = {
102 .name = "pioC_clk",
103 .pmc_mask = 1 << AT91RM9200_ID_PIOC,
104 .type = CLK_TYPE_PERIPHERAL,
105};
106static struct clk pioD_clk = {
107 .name = "pioD_clk",
108 .pmc_mask = 1 << AT91RM9200_ID_PIOD,
109 .type = CLK_TYPE_PERIPHERAL,
110};
111static struct clk ssc0_clk = {
112 .name = "ssc0_clk",
113 .pmc_mask = 1 << AT91RM9200_ID_SSC0,
114 .type = CLK_TYPE_PERIPHERAL,
115};
116static struct clk ssc1_clk = {
117 .name = "ssc1_clk",
118 .pmc_mask = 1 << AT91RM9200_ID_SSC1,
119 .type = CLK_TYPE_PERIPHERAL,
120};
121static struct clk ssc2_clk = {
122 .name = "ssc2_clk",
123 .pmc_mask = 1 << AT91RM9200_ID_SSC2,
124 .type = CLK_TYPE_PERIPHERAL,
125};
126static struct clk tc0_clk = {
127 .name = "tc0_clk",
128 .pmc_mask = 1 << AT91RM9200_ID_TC0,
129 .type = CLK_TYPE_PERIPHERAL,
130};
131static struct clk tc1_clk = {
132 .name = "tc1_clk",
133 .pmc_mask = 1 << AT91RM9200_ID_TC1,
134 .type = CLK_TYPE_PERIPHERAL,
135};
136static struct clk tc2_clk = {
137 .name = "tc2_clk",
138 .pmc_mask = 1 << AT91RM9200_ID_TC2,
139 .type = CLK_TYPE_PERIPHERAL,
140};
141static struct clk tc3_clk = {
142 .name = "tc3_clk",
143 .pmc_mask = 1 << AT91RM9200_ID_TC3,
144 .type = CLK_TYPE_PERIPHERAL,
145};
146static struct clk tc4_clk = {
147 .name = "tc4_clk",
148 .pmc_mask = 1 << AT91RM9200_ID_TC4,
149 .type = CLK_TYPE_PERIPHERAL,
150};
151static struct clk tc5_clk = {
152 .name = "tc5_clk",
153 .pmc_mask = 1 << AT91RM9200_ID_TC5,
154 .type = CLK_TYPE_PERIPHERAL,
155};
156
157static struct clk *periph_clocks[] __initdata = {
158 &pioA_clk,
159 &pioB_clk,
160 &pioC_clk,
161 &pioD_clk,
162 &usart0_clk,
163 &usart1_clk,
164 &usart2_clk,
165 &usart3_clk,
166 &mmc_clk,
167 &udc_clk,
168 &twi_clk,
169 &spi_clk,
170 &ssc0_clk,
171 &ssc1_clk,
172 &ssc2_clk,
173 &tc0_clk,
174 &tc1_clk,
175 &tc2_clk,
176 &tc3_clk,
177 &tc4_clk,
178 &tc5_clk,
179 &ohci_clk,
180 &ether_clk,
181 // irq0 .. irq6
182};
183
184static struct clk_lookup periph_clocks_lookups[] = {
185 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),
186 CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),
187 CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),
188 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.1", &tc3_clk),
189 CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.1", &tc4_clk),
190 CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.1", &tc5_clk),
191 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.0", &ssc0_clk),
192 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.1", &ssc1_clk),
193 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.2", &ssc2_clk),
194 CLKDEV_CON_DEV_ID("pclk", "fffd0000.ssc", &ssc0_clk),
195 CLKDEV_CON_DEV_ID("pclk", "fffd4000.ssc", &ssc1_clk),
196 CLKDEV_CON_DEV_ID("pclk", "fffd8000.ssc", &ssc2_clk),
197 CLKDEV_CON_DEV_ID(NULL, "i2c-at91rm9200.0", &twi_clk),
198 /* fake hclk clock */
199 CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
200 CLKDEV_CON_ID("pioA", &pioA_clk),
201 CLKDEV_CON_ID("pioB", &pioB_clk),
202 CLKDEV_CON_ID("pioC", &pioC_clk),
203 CLKDEV_CON_ID("pioD", &pioD_clk),
204 /* usart lookup table for DT entries */
205 CLKDEV_CON_DEV_ID("usart", "fffff200.serial", &mck),
206 CLKDEV_CON_DEV_ID("usart", "fffc0000.serial", &usart0_clk),
207 CLKDEV_CON_DEV_ID("usart", "fffc4000.serial", &usart1_clk),
208 CLKDEV_CON_DEV_ID("usart", "fffc8000.serial", &usart2_clk),
209 CLKDEV_CON_DEV_ID("usart", "fffcc000.serial", &usart3_clk),
210 /* tc lookup table for DT entries */
211 CLKDEV_CON_DEV_ID("t0_clk", "fffa0000.timer", &tc0_clk),
212 CLKDEV_CON_DEV_ID("t1_clk", "fffa0000.timer", &tc1_clk),
213 CLKDEV_CON_DEV_ID("t2_clk", "fffa0000.timer", &tc2_clk),
214 CLKDEV_CON_DEV_ID("t0_clk", "fffa4000.timer", &tc3_clk),
215 CLKDEV_CON_DEV_ID("t1_clk", "fffa4000.timer", &tc4_clk),
216 CLKDEV_CON_DEV_ID("t2_clk", "fffa4000.timer", &tc5_clk),
217 CLKDEV_CON_DEV_ID("mci_clk", "fffb4000.mmc", &mmc_clk),
218 CLKDEV_CON_DEV_ID("emac_clk", "fffbc000.ethernet", &ether_clk),
219 CLKDEV_CON_DEV_ID(NULL, "fffb8000.i2c", &twi_clk),
220 CLKDEV_CON_DEV_ID("hclk", "300000.ohci", &ohci_clk),
221 CLKDEV_CON_DEV_ID(NULL, "fffff400.gpio", &pioA_clk),
222 CLKDEV_CON_DEV_ID(NULL, "fffff600.gpio", &pioB_clk),
223 CLKDEV_CON_DEV_ID(NULL, "fffff800.gpio", &pioC_clk),
224 CLKDEV_CON_DEV_ID(NULL, "fffffa00.gpio", &pioD_clk),
225};
226
227static struct clk_lookup usart_clocks_lookups[] = {
228 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
229 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
230 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
231 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
232 CLKDEV_CON_DEV_ID("usart", "atmel_usart.4", &usart3_clk),
233};
234
235/*
236 * The four programmable clocks.
237 * You must configure pin multiplexing to bring these signals out.
238 */
239static struct clk pck0 = {
240 .name = "pck0",
241 .pmc_mask = AT91_PMC_PCK0,
242 .type = CLK_TYPE_PROGRAMMABLE,
243 .id = 0,
244};
245static struct clk pck1 = {
246 .name = "pck1",
247 .pmc_mask = AT91_PMC_PCK1,
248 .type = CLK_TYPE_PROGRAMMABLE,
249 .id = 1,
250};
251static struct clk pck2 = {
252 .name = "pck2",
253 .pmc_mask = AT91_PMC_PCK2,
254 .type = CLK_TYPE_PROGRAMMABLE,
255 .id = 2,
256};
257static struct clk pck3 = {
258 .name = "pck3",
259 .pmc_mask = AT91_PMC_PCK3,
260 .type = CLK_TYPE_PROGRAMMABLE,
261 .id = 3,
262};
263
264static void __init at91rm9200_register_clocks(void)
265{
266 int i;
267
268 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
269 clk_register(periph_clocks[i]);
270
271 clkdev_add_table(periph_clocks_lookups,
272 ARRAY_SIZE(periph_clocks_lookups));
273 clkdev_add_table(usart_clocks_lookups,
274 ARRAY_SIZE(usart_clocks_lookups));
275
276 clk_register(&pck0);
277 clk_register(&pck1);
278 clk_register(&pck2);
279 clk_register(&pck3);
280}
281#else
282#define at91rm9200_register_clocks NULL
283#endif
284
285/* --------------------------------------------------------------------
286 * GPIO
287 * -------------------------------------------------------------------- */
288
289static struct at91_gpio_bank at91rm9200_gpio[] __initdata = {
290 {
291 .id = AT91RM9200_ID_PIOA,
292 .regbase = AT91RM9200_BASE_PIOA,
293 }, {
294 .id = AT91RM9200_ID_PIOB,
295 .regbase = AT91RM9200_BASE_PIOB,
296 }, {
297 .id = AT91RM9200_ID_PIOC,
298 .regbase = AT91RM9200_BASE_PIOC,
299 }, {
300 .id = AT91RM9200_ID_PIOD,
301 .regbase = AT91RM9200_BASE_PIOD,
302 }
303};
304 23
305static void at91rm9200_idle(void) 24static void at91rm9200_idle(void)
306{ 25{
@@ -329,74 +48,14 @@ static void __init at91rm9200_map_io(void)
329 at91_init_sram(0, AT91RM9200_SRAM_BASE, AT91RM9200_SRAM_SIZE); 48 at91_init_sram(0, AT91RM9200_SRAM_BASE, AT91RM9200_SRAM_SIZE);
330} 49}
331 50
332static void __init at91rm9200_ioremap_registers(void)
333{
334 at91rm9200_ioremap_st(AT91RM9200_BASE_ST);
335 at91_ioremap_ramc(0, AT91RM9200_BASE_MC, 256);
336 at91_pm_set_standby(at91rm9200_standby);
337}
338
339static void __init at91rm9200_initialize(void) 51static void __init at91rm9200_initialize(void)
340{ 52{
341 arm_pm_idle = at91rm9200_idle; 53 arm_pm_idle = at91rm9200_idle;
342 arm_pm_restart = at91rm9200_restart; 54 arm_pm_restart = at91rm9200_restart;
343
344 /* Initialize GPIO subsystem */
345 at91_gpio_init(at91rm9200_gpio,
346 cpu_is_at91rm9200_bga() ? AT91RM9200_BGA : AT91RM9200_PQFP);
347} 55}
348 56
349 57
350/* --------------------------------------------------------------------
351 * Interrupt initialization
352 * -------------------------------------------------------------------- */
353
354/*
355 * The default interrupt priority levels (0 = lowest, 7 = highest).
356 */
357static unsigned int at91rm9200_default_irq_priority[NR_AIC_IRQS] __initdata = {
358 7, /* Advanced Interrupt Controller (FIQ) */
359 7, /* System Peripherals */
360 1, /* Parallel IO Controller A */
361 1, /* Parallel IO Controller B */
362 1, /* Parallel IO Controller C */
363 1, /* Parallel IO Controller D */
364 5, /* USART 0 */
365 5, /* USART 1 */
366 5, /* USART 2 */
367 5, /* USART 3 */
368 0, /* Multimedia Card Interface */
369 2, /* USB Device Port */
370 6, /* Two-Wire Interface */
371 5, /* Serial Peripheral Interface */
372 4, /* Serial Synchronous Controller 0 */
373 4, /* Serial Synchronous Controller 1 */
374 4, /* Serial Synchronous Controller 2 */
375 0, /* Timer Counter 0 */
376 0, /* Timer Counter 1 */
377 0, /* Timer Counter 2 */
378 0, /* Timer Counter 3 */
379 0, /* Timer Counter 4 */
380 0, /* Timer Counter 5 */
381 2, /* USB Host port */
382 3, /* Ethernet MAC */
383 0, /* Advanced Interrupt Controller (IRQ0) */
384 0, /* Advanced Interrupt Controller (IRQ1) */
385 0, /* Advanced Interrupt Controller (IRQ2) */
386 0, /* Advanced Interrupt Controller (IRQ3) */
387 0, /* Advanced Interrupt Controller (IRQ4) */
388 0, /* Advanced Interrupt Controller (IRQ5) */
389 0 /* Advanced Interrupt Controller (IRQ6) */
390};
391
392AT91_SOC_START(at91rm9200) 58AT91_SOC_START(at91rm9200)
393 .map_io = at91rm9200_map_io, 59 .map_io = at91rm9200_map_io,
394 .default_irq_priority = at91rm9200_default_irq_priority,
395 .extern_irq = (1 << AT91RM9200_ID_IRQ0) | (1 << AT91RM9200_ID_IRQ1)
396 | (1 << AT91RM9200_ID_IRQ2) | (1 << AT91RM9200_ID_IRQ3)
397 | (1 << AT91RM9200_ID_IRQ4) | (1 << AT91RM9200_ID_IRQ5)
398 | (1 << AT91RM9200_ID_IRQ6),
399 .ioremap_registers = at91rm9200_ioremap_registers,
400 .register_clocks = at91rm9200_register_clocks,
401 .init = at91rm9200_initialize, 60 .init = at91rm9200_initialize,
402AT91_SOC_END 61AT91_SOC_END
diff --git a/arch/arm/mach-at91/at91rm9200_devices.c b/arch/arm/mach-at91/at91rm9200_devices.c
deleted file mode 100644
index 74f1eaf97801..000000000000
--- a/arch/arm/mach-at91/at91rm9200_devices.c
+++ /dev/null
@@ -1,1212 +0,0 @@
1/*
2 * arch/arm/mach-at91/at91rm9200_devices.c
3 *
4 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
5 * Copyright (C) 2005 David Brownell
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 */
13#include <asm/mach/arch.h>
14#include <asm/mach/map.h>
15
16#include <linux/dma-mapping.h>
17#include <linux/gpio.h>
18#include <linux/gpio/machine.h>
19#include <linux/platform_device.h>
20#include <linux/i2c-gpio.h>
21
22#include <mach/at91rm9200.h>
23#include <mach/at91rm9200_mc.h>
24#include <mach/at91_ramc.h>
25#include <mach/hardware.h>
26
27#include "board.h"
28#include "generic.h"
29#include "gpio.h"
30
31
32/* --------------------------------------------------------------------
33 * USB Host
34 * -------------------------------------------------------------------- */
35
36#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
37static u64 ohci_dmamask = DMA_BIT_MASK(32);
38static struct at91_usbh_data usbh_data;
39
40static struct resource usbh_resources[] = {
41 [0] = {
42 .start = AT91RM9200_UHP_BASE,
43 .end = AT91RM9200_UHP_BASE + SZ_1M - 1,
44 .flags = IORESOURCE_MEM,
45 },
46 [1] = {
47 .start = NR_IRQS_LEGACY + AT91RM9200_ID_UHP,
48 .end = NR_IRQS_LEGACY + AT91RM9200_ID_UHP,
49 .flags = IORESOURCE_IRQ,
50 },
51};
52
53static struct platform_device at91rm9200_usbh_device = {
54 .name = "at91_ohci",
55 .id = -1,
56 .dev = {
57 .dma_mask = &ohci_dmamask,
58 .coherent_dma_mask = DMA_BIT_MASK(32),
59 .platform_data = &usbh_data,
60 },
61 .resource = usbh_resources,
62 .num_resources = ARRAY_SIZE(usbh_resources),
63};
64
65void __init at91_add_device_usbh(struct at91_usbh_data *data)
66{
67 int i;
68
69 if (!data)
70 return;
71
72 /* Enable overcurrent notification */
73 for (i = 0; i < data->ports; i++) {
74 if (gpio_is_valid(data->overcurrent_pin[i]))
75 at91_set_gpio_input(data->overcurrent_pin[i], 1);
76 }
77
78 usbh_data = *data;
79 platform_device_register(&at91rm9200_usbh_device);
80}
81#else
82void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
83#endif
84
85
86/* --------------------------------------------------------------------
87 * USB Device (Gadget)
88 * -------------------------------------------------------------------- */
89
90#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
91static struct at91_udc_data udc_data;
92
93static struct resource udc_resources[] = {
94 [0] = {
95 .start = AT91RM9200_BASE_UDP,
96 .end = AT91RM9200_BASE_UDP + SZ_16K - 1,
97 .flags = IORESOURCE_MEM,
98 },
99 [1] = {
100 .start = NR_IRQS_LEGACY + AT91RM9200_ID_UDP,
101 .end = NR_IRQS_LEGACY + AT91RM9200_ID_UDP,
102 .flags = IORESOURCE_IRQ,
103 },
104};
105
106static struct platform_device at91rm9200_udc_device = {
107 .name = "at91_udc",
108 .id = -1,
109 .dev = {
110 .platform_data = &udc_data,
111 },
112 .resource = udc_resources,
113 .num_resources = ARRAY_SIZE(udc_resources),
114};
115
116void __init at91_add_device_udc(struct at91_udc_data *data)
117{
118 if (!data)
119 return;
120
121 if (gpio_is_valid(data->vbus_pin)) {
122 at91_set_gpio_input(data->vbus_pin, 0);
123 at91_set_deglitch(data->vbus_pin, 1);
124 }
125 if (gpio_is_valid(data->pullup_pin))
126 at91_set_gpio_output(data->pullup_pin, 0);
127
128 udc_data = *data;
129 platform_device_register(&at91rm9200_udc_device);
130}
131#else
132void __init at91_add_device_udc(struct at91_udc_data *data) {}
133#endif
134
135
136/* --------------------------------------------------------------------
137 * Ethernet
138 * -------------------------------------------------------------------- */
139
140#if defined(CONFIG_ARM_AT91_ETHER) || defined(CONFIG_ARM_AT91_ETHER_MODULE)
141static u64 eth_dmamask = DMA_BIT_MASK(32);
142static struct macb_platform_data eth_data;
143
144static struct resource eth_resources[] = {
145 [0] = {
146 .start = AT91RM9200_BASE_EMAC,
147 .end = AT91RM9200_BASE_EMAC + SZ_16K - 1,
148 .flags = IORESOURCE_MEM,
149 },
150 [1] = {
151 .start = NR_IRQS_LEGACY + AT91RM9200_ID_EMAC,
152 .end = NR_IRQS_LEGACY + AT91RM9200_ID_EMAC,
153 .flags = IORESOURCE_IRQ,
154 },
155};
156
157static struct platform_device at91rm9200_eth_device = {
158 .name = "at91_ether",
159 .id = -1,
160 .dev = {
161 .dma_mask = &eth_dmamask,
162 .coherent_dma_mask = DMA_BIT_MASK(32),
163 .platform_data = &eth_data,
164 },
165 .resource = eth_resources,
166 .num_resources = ARRAY_SIZE(eth_resources),
167};
168
169void __init at91_add_device_eth(struct macb_platform_data *data)
170{
171 if (!data)
172 return;
173
174 if (gpio_is_valid(data->phy_irq_pin)) {
175 at91_set_gpio_input(data->phy_irq_pin, 0);
176 at91_set_deglitch(data->phy_irq_pin, 1);
177 }
178
179 /* Pins used for MII and RMII */
180 at91_set_A_periph(AT91_PIN_PA16, 0); /* EMDIO */
181 at91_set_A_periph(AT91_PIN_PA15, 0); /* EMDC */
182 at91_set_A_periph(AT91_PIN_PA14, 0); /* ERXER */
183 at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
184 at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
185 at91_set_A_periph(AT91_PIN_PA11, 0); /* ECRS_ECRSDV */
186 at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX1 */
187 at91_set_A_periph(AT91_PIN_PA9, 0); /* ETX0 */
188 at91_set_A_periph(AT91_PIN_PA8, 0); /* ETXEN */
189 at91_set_A_periph(AT91_PIN_PA7, 0); /* ETXCK_EREFCK */
190
191 if (!data->is_rmii) {
192 at91_set_B_periph(AT91_PIN_PB19, 0); /* ERXCK */
193 at91_set_B_periph(AT91_PIN_PB18, 0); /* ECOL */
194 at91_set_B_periph(AT91_PIN_PB17, 0); /* ERXDV */
195 at91_set_B_periph(AT91_PIN_PB16, 0); /* ERX3 */
196 at91_set_B_periph(AT91_PIN_PB15, 0); /* ERX2 */
197 at91_set_B_periph(AT91_PIN_PB14, 0); /* ETXER */
198 at91_set_B_periph(AT91_PIN_PB13, 0); /* ETX3 */
199 at91_set_B_periph(AT91_PIN_PB12, 0); /* ETX2 */
200 }
201
202 eth_data = *data;
203 platform_device_register(&at91rm9200_eth_device);
204}
205#else
206void __init at91_add_device_eth(struct macb_platform_data *data) {}
207#endif
208
209
210/* --------------------------------------------------------------------
211 * Compact Flash / PCMCIA
212 * -------------------------------------------------------------------- */
213
214#if defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
215static struct at91_cf_data cf_data;
216
217#define CF_BASE AT91_CHIPSELECT_4
218
219static struct resource cf_resources[] = {
220 [0] = {
221 .start = CF_BASE,
222 /* ties up CS4, CS5 and CS6 */
223 .end = CF_BASE + (0x30000000 - 1),
224 .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
225 },
226};
227
228static struct platform_device at91rm9200_cf_device = {
229 .name = "at91_cf",
230 .id = -1,
231 .dev = {
232 .platform_data = &cf_data,
233 },
234 .resource = cf_resources,
235 .num_resources = ARRAY_SIZE(cf_resources),
236};
237
238void __init at91_add_device_cf(struct at91_cf_data *data)
239{
240 unsigned int csa;
241
242 if (!data)
243 return;
244
245 data->chipselect = 4; /* can only use EBI ChipSelect 4 */
246
247 /* CF takes over CS4, CS5, CS6 */
248 csa = at91_ramc_read(0, AT91_EBI_CSA);
249 at91_ramc_write(0, AT91_EBI_CSA, csa | AT91_EBI_CS4A_SMC_COMPACTFLASH);
250
251 /*
252 * Static memory controller timing adjustments.
253 * REVISIT: these timings are in terms of MCK cycles, so
254 * when MCK changes (cpufreq etc) so must these values...
255 */
256 at91_ramc_write(0, AT91_SMC_CSR(4),
257 AT91_SMC_ACSS_STD
258 | AT91_SMC_DBW_16
259 | AT91_SMC_BAT
260 | AT91_SMC_WSEN
261 | AT91_SMC_NWS_(32) /* wait states */
262 | AT91_SMC_RWSETUP_(6) /* setup time */
263 | AT91_SMC_RWHOLD_(4) /* hold time */
264 );
265
266 /* input/irq */
267 if (gpio_is_valid(data->irq_pin)) {
268 at91_set_gpio_input(data->irq_pin, 1);
269 at91_set_deglitch(data->irq_pin, 1);
270 }
271 at91_set_gpio_input(data->det_pin, 1);
272 at91_set_deglitch(data->det_pin, 1);
273
274 /* outputs, initially off */
275 if (gpio_is_valid(data->vcc_pin))
276 at91_set_gpio_output(data->vcc_pin, 0);
277 at91_set_gpio_output(data->rst_pin, 0);
278
279 /* force poweron defaults for these pins ... */
280 at91_set_A_periph(AT91_PIN_PC9, 0); /* A25/CFRNW */
281 at91_set_A_periph(AT91_PIN_PC10, 0); /* NCS4/CFCS */
282 at91_set_A_periph(AT91_PIN_PC11, 0); /* NCS5/CFCE1 */
283 at91_set_A_periph(AT91_PIN_PC12, 0); /* NCS6/CFCE2 */
284
285 /* nWAIT is _not_ a default setting */
286 at91_set_A_periph(AT91_PIN_PC6, 1); /* nWAIT */
287
288 cf_data = *data;
289 platform_device_register(&at91rm9200_cf_device);
290}
291#else
292void __init at91_add_device_cf(struct at91_cf_data *data) {}
293#endif
294
295
296/* --------------------------------------------------------------------
297 * MMC / SD
298 * -------------------------------------------------------------------- */
299
300#if IS_ENABLED(CONFIG_MMC_ATMELMCI)
301static u64 mmc_dmamask = DMA_BIT_MASK(32);
302static struct mci_platform_data mmc_data;
303
304static struct resource mmc_resources[] = {
305 [0] = {
306 .start = AT91RM9200_BASE_MCI,
307 .end = AT91RM9200_BASE_MCI + SZ_16K - 1,
308 .flags = IORESOURCE_MEM,
309 },
310 [1] = {
311 .start = NR_IRQS_LEGACY + AT91RM9200_ID_MCI,
312 .end = NR_IRQS_LEGACY + AT91RM9200_ID_MCI,
313 .flags = IORESOURCE_IRQ,
314 },
315};
316
317static struct platform_device at91rm9200_mmc_device = {
318 .name = "atmel_mci",
319 .id = -1,
320 .dev = {
321 .dma_mask = &mmc_dmamask,
322 .coherent_dma_mask = DMA_BIT_MASK(32),
323 .platform_data = &mmc_data,
324 },
325 .resource = mmc_resources,
326 .num_resources = ARRAY_SIZE(mmc_resources),
327};
328
329void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
330{
331 unsigned int i;
332 unsigned int slot_count = 0;
333
334 if (!data)
335 return;
336
337 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
338
339 if (!data->slot[i].bus_width)
340 continue;
341
342 /* input/irq */
343 if (gpio_is_valid(data->slot[i].detect_pin)) {
344 at91_set_gpio_input(data->slot[i].detect_pin, 1);
345 at91_set_deglitch(data->slot[i].detect_pin, 1);
346 }
347 if (gpio_is_valid(data->slot[i].wp_pin))
348 at91_set_gpio_input(data->slot[i].wp_pin, 1);
349
350 switch (i) {
351 case 0: /* slot A */
352 /* CMD */
353 at91_set_A_periph(AT91_PIN_PA28, 1);
354 /* DAT0, maybe DAT1..DAT3 */
355 at91_set_A_periph(AT91_PIN_PA29, 1);
356 if (data->slot[i].bus_width == 4) {
357 at91_set_B_periph(AT91_PIN_PB3, 1);
358 at91_set_B_periph(AT91_PIN_PB4, 1);
359 at91_set_B_periph(AT91_PIN_PB5, 1);
360 }
361 slot_count++;
362 break;
363 case 1: /* slot B */
364 /* CMD */
365 at91_set_B_periph(AT91_PIN_PA8, 1);
366 /* DAT0, maybe DAT1..DAT3 */
367 at91_set_B_periph(AT91_PIN_PA9, 1);
368 if (data->slot[i].bus_width == 4) {
369 at91_set_B_periph(AT91_PIN_PA10, 1);
370 at91_set_B_periph(AT91_PIN_PA11, 1);
371 at91_set_B_periph(AT91_PIN_PA12, 1);
372 }
373 slot_count++;
374 break;
375 default:
376 printk(KERN_ERR
377 "AT91: SD/MMC slot %d not available\n", i);
378 break;
379 }
380 if (slot_count) {
381 /* CLK */
382 at91_set_A_periph(AT91_PIN_PA27, 0);
383
384 mmc_data = *data;
385 platform_device_register(&at91rm9200_mmc_device);
386 }
387 }
388
389}
390#else
391void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
392#endif
393
394
395/* --------------------------------------------------------------------
396 * NAND / SmartMedia
397 * -------------------------------------------------------------------- */
398
399#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
400static struct atmel_nand_data nand_data;
401
402#define NAND_BASE AT91_CHIPSELECT_3
403
404static struct resource nand_resources[] = {
405 {
406 .start = NAND_BASE,
407 .end = NAND_BASE + SZ_256M - 1,
408 .flags = IORESOURCE_MEM,
409 }
410};
411
412static struct platform_device at91rm9200_nand_device = {
413 .name = "atmel_nand",
414 .id = -1,
415 .dev = {
416 .platform_data = &nand_data,
417 },
418 .resource = nand_resources,
419 .num_resources = ARRAY_SIZE(nand_resources),
420};
421
422void __init at91_add_device_nand(struct atmel_nand_data *data)
423{
424 unsigned int csa;
425
426 if (!data)
427 return;
428
429 /* enable the address range of CS3 */
430 csa = at91_ramc_read(0, AT91_EBI_CSA);
431 at91_ramc_write(0, AT91_EBI_CSA, csa | AT91_EBI_CS3A_SMC_SMARTMEDIA);
432
433 /* set the bus interface characteristics */
434 at91_ramc_write(0, AT91_SMC_CSR(3), AT91_SMC_ACSS_STD | AT91_SMC_DBW_8 | AT91_SMC_WSEN
435 | AT91_SMC_NWS_(5)
436 | AT91_SMC_TDF_(1)
437 | AT91_SMC_RWSETUP_(0) /* tDS Data Set up Time 30 - ns */
438 | AT91_SMC_RWHOLD_(1) /* tDH Data Hold Time 20 - ns */
439 );
440
441 /* enable pin */
442 if (gpio_is_valid(data->enable_pin))
443 at91_set_gpio_output(data->enable_pin, 1);
444
445 /* ready/busy pin */
446 if (gpio_is_valid(data->rdy_pin))
447 at91_set_gpio_input(data->rdy_pin, 1);
448
449 /* card detect pin */
450 if (gpio_is_valid(data->det_pin))
451 at91_set_gpio_input(data->det_pin, 1);
452
453 at91_set_A_periph(AT91_PIN_PC1, 0); /* SMOE */
454 at91_set_A_periph(AT91_PIN_PC3, 0); /* SMWE */
455
456 nand_data = *data;
457 platform_device_register(&at91rm9200_nand_device);
458}
459#else
460void __init at91_add_device_nand(struct atmel_nand_data *data) {}
461#endif
462
463
464/* --------------------------------------------------------------------
465 * TWI (i2c)
466 * -------------------------------------------------------------------- */
467
468/*
469 * Prefer the GPIO code since the TWI controller isn't robust
470 * (gets overruns and underruns under load) and can only issue
471 * repeated STARTs in one scenario (the driver doesn't yet handle them).
472 */
473#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
474
475static struct i2c_gpio_platform_data pdata = {
476 .sda_pin = AT91_PIN_PA25,
477 .sda_is_open_drain = 1,
478 .scl_pin = AT91_PIN_PA26,
479 .scl_is_open_drain = 1,
480 .udelay = 2, /* ~100 kHz */
481};
482
483static struct platform_device at91rm9200_twi_device = {
484 .name = "i2c-gpio",
485 .id = 0,
486 .dev.platform_data = &pdata,
487};
488
489void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
490{
491 at91_set_GPIO_periph(AT91_PIN_PA25, 1); /* TWD (SDA) */
492 at91_set_multi_drive(AT91_PIN_PA25, 1);
493
494 at91_set_GPIO_periph(AT91_PIN_PA26, 1); /* TWCK (SCL) */
495 at91_set_multi_drive(AT91_PIN_PA26, 1);
496
497 i2c_register_board_info(0, devices, nr_devices);
498 platform_device_register(&at91rm9200_twi_device);
499}
500
501#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
502
503static struct resource twi_resources[] = {
504 [0] = {
505 .start = AT91RM9200_BASE_TWI,
506 .end = AT91RM9200_BASE_TWI + SZ_16K - 1,
507 .flags = IORESOURCE_MEM,
508 },
509 [1] = {
510 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TWI,
511 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TWI,
512 .flags = IORESOURCE_IRQ,
513 },
514};
515
516static struct platform_device at91rm9200_twi_device = {
517 .name = "i2c-at91rm9200",
518 .id = 0,
519 .resource = twi_resources,
520 .num_resources = ARRAY_SIZE(twi_resources),
521};
522
523void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
524{
525 /* pins used for TWI interface */
526 at91_set_A_periph(AT91_PIN_PA25, 0); /* TWD */
527 at91_set_multi_drive(AT91_PIN_PA25, 1);
528
529 at91_set_A_periph(AT91_PIN_PA26, 0); /* TWCK */
530 at91_set_multi_drive(AT91_PIN_PA26, 1);
531
532 i2c_register_board_info(0, devices, nr_devices);
533 platform_device_register(&at91rm9200_twi_device);
534}
535#else
536void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
537#endif
538
539
540/* --------------------------------------------------------------------
541 * SPI
542 * -------------------------------------------------------------------- */
543
544#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
545static u64 spi_dmamask = DMA_BIT_MASK(32);
546
547static struct resource spi_resources[] = {
548 [0] = {
549 .start = AT91RM9200_BASE_SPI,
550 .end = AT91RM9200_BASE_SPI + SZ_16K - 1,
551 .flags = IORESOURCE_MEM,
552 },
553 [1] = {
554 .start = NR_IRQS_LEGACY + AT91RM9200_ID_SPI,
555 .end = NR_IRQS_LEGACY + AT91RM9200_ID_SPI,
556 .flags = IORESOURCE_IRQ,
557 },
558};
559
560static struct platform_device at91rm9200_spi_device = {
561 .name = "atmel_spi",
562 .id = 0,
563 .dev = {
564 .dma_mask = &spi_dmamask,
565 .coherent_dma_mask = DMA_BIT_MASK(32),
566 },
567 .resource = spi_resources,
568 .num_resources = ARRAY_SIZE(spi_resources),
569};
570
571static const unsigned spi_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
572
573void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
574{
575 int i;
576 unsigned long cs_pin;
577
578 at91_set_A_periph(AT91_PIN_PA0, 0); /* MISO */
579 at91_set_A_periph(AT91_PIN_PA1, 0); /* MOSI */
580 at91_set_A_periph(AT91_PIN_PA2, 0); /* SPCK */
581
582 /* Enable SPI chip-selects */
583 for (i = 0; i < nr_devices; i++) {
584 if (devices[i].controller_data)
585 cs_pin = (unsigned long) devices[i].controller_data;
586 else
587 cs_pin = spi_standard_cs[devices[i].chip_select];
588
589 if (devices[i].chip_select == 0) /* for CS0 errata */
590 at91_set_A_periph(cs_pin, 0);
591 else
592 at91_set_gpio_output(cs_pin, 1);
593
594
595 /* pass chip-select pin to driver */
596 devices[i].controller_data = (void *) cs_pin;
597 }
598
599 spi_register_board_info(devices, nr_devices);
600 platform_device_register(&at91rm9200_spi_device);
601}
602#else
603void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
604#endif
605
606
607/* --------------------------------------------------------------------
608 * Timer/Counter blocks
609 * -------------------------------------------------------------------- */
610
611#ifdef CONFIG_ATMEL_TCLIB
612
613static struct resource tcb0_resources[] = {
614 [0] = {
615 .start = AT91RM9200_BASE_TCB0,
616 .end = AT91RM9200_BASE_TCB0 + SZ_16K - 1,
617 .flags = IORESOURCE_MEM,
618 },
619 [1] = {
620 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC0,
621 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC0,
622 .flags = IORESOURCE_IRQ,
623 },
624 [2] = {
625 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC1,
626 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC1,
627 .flags = IORESOURCE_IRQ,
628 },
629 [3] = {
630 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC2,
631 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC2,
632 .flags = IORESOURCE_IRQ,
633 },
634};
635
636static struct platform_device at91rm9200_tcb0_device = {
637 .name = "atmel_tcb",
638 .id = 0,
639 .resource = tcb0_resources,
640 .num_resources = ARRAY_SIZE(tcb0_resources),
641};
642
643static struct resource tcb1_resources[] = {
644 [0] = {
645 .start = AT91RM9200_BASE_TCB1,
646 .end = AT91RM9200_BASE_TCB1 + SZ_16K - 1,
647 .flags = IORESOURCE_MEM,
648 },
649 [1] = {
650 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC3,
651 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC3,
652 .flags = IORESOURCE_IRQ,
653 },
654 [2] = {
655 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC4,
656 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC4,
657 .flags = IORESOURCE_IRQ,
658 },
659 [3] = {
660 .start = NR_IRQS_LEGACY + AT91RM9200_ID_TC5,
661 .end = NR_IRQS_LEGACY + AT91RM9200_ID_TC5,
662 .flags = IORESOURCE_IRQ,
663 },
664};
665
666static struct platform_device at91rm9200_tcb1_device = {
667 .name = "atmel_tcb",
668 .id = 1,
669 .resource = tcb1_resources,
670 .num_resources = ARRAY_SIZE(tcb1_resources),
671};
672
673static void __init at91_add_device_tc(void)
674{
675 platform_device_register(&at91rm9200_tcb0_device);
676 platform_device_register(&at91rm9200_tcb1_device);
677}
678#else
679static void __init at91_add_device_tc(void) { }
680#endif
681
682
683/* --------------------------------------------------------------------
684 * RTC
685 * -------------------------------------------------------------------- */
686
687#if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
688static struct resource rtc_resources[] = {
689 [0] = {
690 .start = AT91RM9200_BASE_RTC,
691 .end = AT91RM9200_BASE_RTC + SZ_256 - 1,
692 .flags = IORESOURCE_MEM,
693 },
694 [1] = {
695 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
696 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
697 .flags = IORESOURCE_IRQ,
698 },
699};
700
701static struct platform_device at91rm9200_rtc_device = {
702 .name = "at91_rtc",
703 .id = -1,
704 .resource = rtc_resources,
705 .num_resources = ARRAY_SIZE(rtc_resources),
706};
707
708static void __init at91_add_device_rtc(void)
709{
710 platform_device_register(&at91rm9200_rtc_device);
711}
712#else
713static void __init at91_add_device_rtc(void) {}
714#endif
715
716
717/* --------------------------------------------------------------------
718 * Watchdog
719 * -------------------------------------------------------------------- */
720
721#if defined(CONFIG_AT91RM9200_WATCHDOG) || defined(CONFIG_AT91RM9200_WATCHDOG_MODULE)
722static struct platform_device at91rm9200_wdt_device = {
723 .name = "at91_wdt",
724 .id = -1,
725 .num_resources = 0,
726};
727
728static void __init at91_add_device_watchdog(void)
729{
730 platform_device_register(&at91rm9200_wdt_device);
731}
732#else
733static void __init at91_add_device_watchdog(void) {}
734#endif
735
736
737/* --------------------------------------------------------------------
738 * SSC -- Synchronous Serial Controller
739 * -------------------------------------------------------------------- */
740
741#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
742static u64 ssc0_dmamask = DMA_BIT_MASK(32);
743
744static struct resource ssc0_resources[] = {
745 [0] = {
746 .start = AT91RM9200_BASE_SSC0,
747 .end = AT91RM9200_BASE_SSC0 + SZ_16K - 1,
748 .flags = IORESOURCE_MEM,
749 },
750 [1] = {
751 .start = NR_IRQS_LEGACY + AT91RM9200_ID_SSC0,
752 .end = NR_IRQS_LEGACY + AT91RM9200_ID_SSC0,
753 .flags = IORESOURCE_IRQ,
754 },
755};
756
757static struct platform_device at91rm9200_ssc0_device = {
758 .name = "at91rm9200_ssc",
759 .id = 0,
760 .dev = {
761 .dma_mask = &ssc0_dmamask,
762 .coherent_dma_mask = DMA_BIT_MASK(32),
763 },
764 .resource = ssc0_resources,
765 .num_resources = ARRAY_SIZE(ssc0_resources),
766};
767
768static inline void configure_ssc0_pins(unsigned pins)
769{
770 if (pins & ATMEL_SSC_TF)
771 at91_set_A_periph(AT91_PIN_PB0, 1);
772 if (pins & ATMEL_SSC_TK)
773 at91_set_A_periph(AT91_PIN_PB1, 1);
774 if (pins & ATMEL_SSC_TD)
775 at91_set_A_periph(AT91_PIN_PB2, 1);
776 if (pins & ATMEL_SSC_RD)
777 at91_set_A_periph(AT91_PIN_PB3, 1);
778 if (pins & ATMEL_SSC_RK)
779 at91_set_A_periph(AT91_PIN_PB4, 1);
780 if (pins & ATMEL_SSC_RF)
781 at91_set_A_periph(AT91_PIN_PB5, 1);
782}
783
784static u64 ssc1_dmamask = DMA_BIT_MASK(32);
785
786static struct resource ssc1_resources[] = {
787 [0] = {
788 .start = AT91RM9200_BASE_SSC1,
789 .end = AT91RM9200_BASE_SSC1 + SZ_16K - 1,
790 .flags = IORESOURCE_MEM,
791 },
792 [1] = {
793 .start = NR_IRQS_LEGACY + AT91RM9200_ID_SSC1,
794 .end = NR_IRQS_LEGACY + AT91RM9200_ID_SSC1,
795 .flags = IORESOURCE_IRQ,
796 },
797};
798
799static struct platform_device at91rm9200_ssc1_device = {
800 .name = "at91rm9200_ssc",
801 .id = 1,
802 .dev = {
803 .dma_mask = &ssc1_dmamask,
804 .coherent_dma_mask = DMA_BIT_MASK(32),
805 },
806 .resource = ssc1_resources,
807 .num_resources = ARRAY_SIZE(ssc1_resources),
808};
809
810static inline void configure_ssc1_pins(unsigned pins)
811{
812 if (pins & ATMEL_SSC_TF)
813 at91_set_A_periph(AT91_PIN_PB6, 1);
814 if (pins & ATMEL_SSC_TK)
815 at91_set_A_periph(AT91_PIN_PB7, 1);
816 if (pins & ATMEL_SSC_TD)
817 at91_set_A_periph(AT91_PIN_PB8, 1);
818 if (pins & ATMEL_SSC_RD)
819 at91_set_A_periph(AT91_PIN_PB9, 1);
820 if (pins & ATMEL_SSC_RK)
821 at91_set_A_periph(AT91_PIN_PB10, 1);
822 if (pins & ATMEL_SSC_RF)
823 at91_set_A_periph(AT91_PIN_PB11, 1);
824}
825
826static u64 ssc2_dmamask = DMA_BIT_MASK(32);
827
828static struct resource ssc2_resources[] = {
829 [0] = {
830 .start = AT91RM9200_BASE_SSC2,
831 .end = AT91RM9200_BASE_SSC2 + SZ_16K - 1,
832 .flags = IORESOURCE_MEM,
833 },
834 [1] = {
835 .start = NR_IRQS_LEGACY + AT91RM9200_ID_SSC2,
836 .end = NR_IRQS_LEGACY + AT91RM9200_ID_SSC2,
837 .flags = IORESOURCE_IRQ,
838 },
839};
840
841static struct platform_device at91rm9200_ssc2_device = {
842 .name = "at91rm9200_ssc",
843 .id = 2,
844 .dev = {
845 .dma_mask = &ssc2_dmamask,
846 .coherent_dma_mask = DMA_BIT_MASK(32),
847 },
848 .resource = ssc2_resources,
849 .num_resources = ARRAY_SIZE(ssc2_resources),
850};
851
852static inline void configure_ssc2_pins(unsigned pins)
853{
854 if (pins & ATMEL_SSC_TF)
855 at91_set_A_periph(AT91_PIN_PB12, 1);
856 if (pins & ATMEL_SSC_TK)
857 at91_set_A_periph(AT91_PIN_PB13, 1);
858 if (pins & ATMEL_SSC_TD)
859 at91_set_A_periph(AT91_PIN_PB14, 1);
860 if (pins & ATMEL_SSC_RD)
861 at91_set_A_periph(AT91_PIN_PB15, 1);
862 if (pins & ATMEL_SSC_RK)
863 at91_set_A_periph(AT91_PIN_PB16, 1);
864 if (pins & ATMEL_SSC_RF)
865 at91_set_A_periph(AT91_PIN_PB17, 1);
866}
867
868/*
869 * SSC controllers are accessed through library code, instead of any
870 * kind of all-singing/all-dancing driver. For example one could be
871 * used by a particular I2S audio codec's driver, while another one
872 * on the same system might be used by a custom data capture driver.
873 */
874void __init at91_add_device_ssc(unsigned id, unsigned pins)
875{
876 struct platform_device *pdev;
877
878 /*
879 * NOTE: caller is responsible for passing information matching
880 * "pins" to whatever will be using each particular controller.
881 */
882 switch (id) {
883 case AT91RM9200_ID_SSC0:
884 pdev = &at91rm9200_ssc0_device;
885 configure_ssc0_pins(pins);
886 break;
887 case AT91RM9200_ID_SSC1:
888 pdev = &at91rm9200_ssc1_device;
889 configure_ssc1_pins(pins);
890 break;
891 case AT91RM9200_ID_SSC2:
892 pdev = &at91rm9200_ssc2_device;
893 configure_ssc2_pins(pins);
894 break;
895 default:
896 return;
897 }
898
899 platform_device_register(pdev);
900}
901
902#else
903void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
904#endif
905
906
907/* --------------------------------------------------------------------
908 * UART
909 * -------------------------------------------------------------------- */
910
911#if defined(CONFIG_SERIAL_ATMEL)
912static struct resource dbgu_resources[] = {
913 [0] = {
914 .start = AT91RM9200_BASE_DBGU,
915 .end = AT91RM9200_BASE_DBGU + SZ_512 - 1,
916 .flags = IORESOURCE_MEM,
917 },
918 [1] = {
919 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
920 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
921 .flags = IORESOURCE_IRQ,
922 },
923};
924
925static struct atmel_uart_data dbgu_data = {
926 .use_dma_tx = 0,
927 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
928};
929
930static u64 dbgu_dmamask = DMA_BIT_MASK(32);
931
932static struct platform_device at91rm9200_dbgu_device = {
933 .name = "atmel_usart",
934 .id = 0,
935 .dev = {
936 .dma_mask = &dbgu_dmamask,
937 .coherent_dma_mask = DMA_BIT_MASK(32),
938 .platform_data = &dbgu_data,
939 },
940 .resource = dbgu_resources,
941 .num_resources = ARRAY_SIZE(dbgu_resources),
942};
943
944static inline void configure_dbgu_pins(void)
945{
946 at91_set_A_periph(AT91_PIN_PA30, 0); /* DRXD */
947 at91_set_A_periph(AT91_PIN_PA31, 1); /* DTXD */
948}
949
950static struct resource uart0_resources[] = {
951 [0] = {
952 .start = AT91RM9200_BASE_US0,
953 .end = AT91RM9200_BASE_US0 + SZ_16K - 1,
954 .flags = IORESOURCE_MEM,
955 },
956 [1] = {
957 .start = NR_IRQS_LEGACY + AT91RM9200_ID_US0,
958 .end = NR_IRQS_LEGACY + AT91RM9200_ID_US0,
959 .flags = IORESOURCE_IRQ,
960 },
961};
962
963static struct atmel_uart_data uart0_data = {
964 .use_dma_tx = 1,
965 .use_dma_rx = 1,
966};
967
968static struct gpiod_lookup_table uart0_gpios_table = {
969 .dev_id = "atmel_usart",
970 .table = {
971 GPIO_LOOKUP("pioA", 21, "rts", GPIO_ACTIVE_LOW),
972 { },
973 },
974};
975
976static u64 uart0_dmamask = DMA_BIT_MASK(32);
977
978static struct platform_device at91rm9200_uart0_device = {
979 .name = "atmel_usart",
980 .id = 1,
981 .dev = {
982 .dma_mask = &uart0_dmamask,
983 .coherent_dma_mask = DMA_BIT_MASK(32),
984 .platform_data = &uart0_data,
985 },
986 .resource = uart0_resources,
987 .num_resources = ARRAY_SIZE(uart0_resources),
988};
989
990static inline void configure_usart0_pins(unsigned pins)
991{
992 at91_set_A_periph(AT91_PIN_PA17, 1); /* TXD0 */
993 at91_set_A_periph(AT91_PIN_PA18, 0); /* RXD0 */
994
995 if (pins & ATMEL_UART_CTS)
996 at91_set_A_periph(AT91_PIN_PA20, 0); /* CTS0 */
997
998 if (pins & ATMEL_UART_RTS) {
999 /*
1000 * AT91RM9200 Errata #39 - RTS0 is not internally connected to PA21.
1001 * We need to drive the pin manually. The serial driver will driver
1002 * this to high when initializing.
1003 */
1004 gpiod_add_lookup_table(&uart0_gpios_table);
1005 }
1006}
1007
1008static struct resource uart1_resources[] = {
1009 [0] = {
1010 .start = AT91RM9200_BASE_US1,
1011 .end = AT91RM9200_BASE_US1 + SZ_16K - 1,
1012 .flags = IORESOURCE_MEM,
1013 },
1014 [1] = {
1015 .start = NR_IRQS_LEGACY + AT91RM9200_ID_US1,
1016 .end = NR_IRQS_LEGACY + AT91RM9200_ID_US1,
1017 .flags = IORESOURCE_IRQ,
1018 },
1019};
1020
1021static struct atmel_uart_data uart1_data = {
1022 .use_dma_tx = 1,
1023 .use_dma_rx = 1,
1024};
1025
1026static u64 uart1_dmamask = DMA_BIT_MASK(32);
1027
1028static struct platform_device at91rm9200_uart1_device = {
1029 .name = "atmel_usart",
1030 .id = 2,
1031 .dev = {
1032 .dma_mask = &uart1_dmamask,
1033 .coherent_dma_mask = DMA_BIT_MASK(32),
1034 .platform_data = &uart1_data,
1035 },
1036 .resource = uart1_resources,
1037 .num_resources = ARRAY_SIZE(uart1_resources),
1038};
1039
1040static inline void configure_usart1_pins(unsigned pins)
1041{
1042 at91_set_A_periph(AT91_PIN_PB20, 1); /* TXD1 */
1043 at91_set_A_periph(AT91_PIN_PB21, 0); /* RXD1 */
1044
1045 if (pins & ATMEL_UART_RI)
1046 at91_set_A_periph(AT91_PIN_PB18, 0); /* RI1 */
1047 if (pins & ATMEL_UART_DTR)
1048 at91_set_A_periph(AT91_PIN_PB19, 0); /* DTR1 */
1049 if (pins & ATMEL_UART_DCD)
1050 at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD1 */
1051 if (pins & ATMEL_UART_CTS)
1052 at91_set_A_periph(AT91_PIN_PB24, 0); /* CTS1 */
1053 if (pins & ATMEL_UART_DSR)
1054 at91_set_A_periph(AT91_PIN_PB25, 0); /* DSR1 */
1055 if (pins & ATMEL_UART_RTS)
1056 at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS1 */
1057}
1058
1059static struct resource uart2_resources[] = {
1060 [0] = {
1061 .start = AT91RM9200_BASE_US2,
1062 .end = AT91RM9200_BASE_US2 + SZ_16K - 1,
1063 .flags = IORESOURCE_MEM,
1064 },
1065 [1] = {
1066 .start = NR_IRQS_LEGACY + AT91RM9200_ID_US2,
1067 .end = NR_IRQS_LEGACY + AT91RM9200_ID_US2,
1068 .flags = IORESOURCE_IRQ,
1069 },
1070};
1071
1072static struct atmel_uart_data uart2_data = {
1073 .use_dma_tx = 1,
1074 .use_dma_rx = 1,
1075};
1076
1077static u64 uart2_dmamask = DMA_BIT_MASK(32);
1078
1079static struct platform_device at91rm9200_uart2_device = {
1080 .name = "atmel_usart",
1081 .id = 3,
1082 .dev = {
1083 .dma_mask = &uart2_dmamask,
1084 .coherent_dma_mask = DMA_BIT_MASK(32),
1085 .platform_data = &uart2_data,
1086 },
1087 .resource = uart2_resources,
1088 .num_resources = ARRAY_SIZE(uart2_resources),
1089};
1090
1091static inline void configure_usart2_pins(unsigned pins)
1092{
1093 at91_set_A_periph(AT91_PIN_PA22, 0); /* RXD2 */
1094 at91_set_A_periph(AT91_PIN_PA23, 1); /* TXD2 */
1095
1096 if (pins & ATMEL_UART_CTS)
1097 at91_set_B_periph(AT91_PIN_PA30, 0); /* CTS2 */
1098 if (pins & ATMEL_UART_RTS)
1099 at91_set_B_periph(AT91_PIN_PA31, 0); /* RTS2 */
1100}
1101
1102static struct resource uart3_resources[] = {
1103 [0] = {
1104 .start = AT91RM9200_BASE_US3,
1105 .end = AT91RM9200_BASE_US3 + SZ_16K - 1,
1106 .flags = IORESOURCE_MEM,
1107 },
1108 [1] = {
1109 .start = NR_IRQS_LEGACY + AT91RM9200_ID_US3,
1110 .end = NR_IRQS_LEGACY + AT91RM9200_ID_US3,
1111 .flags = IORESOURCE_IRQ,
1112 },
1113};
1114
1115static struct atmel_uart_data uart3_data = {
1116 .use_dma_tx = 1,
1117 .use_dma_rx = 1,
1118};
1119
1120static u64 uart3_dmamask = DMA_BIT_MASK(32);
1121
1122static struct platform_device at91rm9200_uart3_device = {
1123 .name = "atmel_usart",
1124 .id = 4,
1125 .dev = {
1126 .dma_mask = &uart3_dmamask,
1127 .coherent_dma_mask = DMA_BIT_MASK(32),
1128 .platform_data = &uart3_data,
1129 },
1130 .resource = uart3_resources,
1131 .num_resources = ARRAY_SIZE(uart3_resources),
1132};
1133
1134static inline void configure_usart3_pins(unsigned pins)
1135{
1136 at91_set_B_periph(AT91_PIN_PA5, 1); /* TXD3 */
1137 at91_set_B_periph(AT91_PIN_PA6, 0); /* RXD3 */
1138
1139 if (pins & ATMEL_UART_CTS)
1140 at91_set_B_periph(AT91_PIN_PB1, 0); /* CTS3 */
1141 if (pins & ATMEL_UART_RTS)
1142 at91_set_B_periph(AT91_PIN_PB0, 0); /* RTS3 */
1143}
1144
1145static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
1146
1147void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1148{
1149 struct platform_device *pdev;
1150 struct atmel_uart_data *pdata;
1151
1152 switch (id) {
1153 case 0: /* DBGU */
1154 pdev = &at91rm9200_dbgu_device;
1155 configure_dbgu_pins();
1156 break;
1157 case AT91RM9200_ID_US0:
1158 pdev = &at91rm9200_uart0_device;
1159 configure_usart0_pins(pins);
1160 break;
1161 case AT91RM9200_ID_US1:
1162 pdev = &at91rm9200_uart1_device;
1163 configure_usart1_pins(pins);
1164 break;
1165 case AT91RM9200_ID_US2:
1166 pdev = &at91rm9200_uart2_device;
1167 configure_usart2_pins(pins);
1168 break;
1169 case AT91RM9200_ID_US3:
1170 pdev = &at91rm9200_uart3_device;
1171 configure_usart3_pins(pins);
1172 break;
1173 default:
1174 return;
1175 }
1176 pdata = pdev->dev.platform_data;
1177 pdata->num = portnr; /* update to mapped ID */
1178
1179 if (portnr < ATMEL_MAX_UART)
1180 at91_uarts[portnr] = pdev;
1181}
1182
1183void __init at91_add_device_serial(void)
1184{
1185 int i;
1186
1187 for (i = 0; i < ATMEL_MAX_UART; i++) {
1188 if (at91_uarts[i])
1189 platform_device_register(at91_uarts[i]);
1190 }
1191}
1192#else
1193void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1194void __init at91_add_device_serial(void) {}
1195#endif
1196
1197
1198/* -------------------------------------------------------------------- */
1199
1200/*
1201 * These devices are always present and don't need any board-specific
1202 * setup.
1203 */
1204static int __init at91_add_standard_devices(void)
1205{
1206 at91_add_device_rtc();
1207 at91_add_device_watchdog();
1208 at91_add_device_tc();
1209 return 0;
1210}
1211
1212arch_initcall(at91_add_standard_devices);
diff --git a/arch/arm/mach-at91/at91rm9200_time.c b/arch/arm/mach-at91/at91rm9200_time.c
index 7fd13aef9827..51761f8927b7 100644
--- a/arch/arm/mach-at91/at91rm9200_time.c
+++ b/arch/arm/mach-at91/at91rm9200_time.c
@@ -183,7 +183,6 @@ static struct clock_event_device clkevt = {
183void __iomem *at91_st_base; 183void __iomem *at91_st_base;
184EXPORT_SYMBOL_GPL(at91_st_base); 184EXPORT_SYMBOL_GPL(at91_st_base);
185 185
186#ifdef CONFIG_OF
187static struct of_device_id at91rm9200_st_timer_ids[] = { 186static struct of_device_id at91rm9200_st_timer_ids[] = {
188 { .compatible = "atmel,at91rm9200-st" }, 187 { .compatible = "atmel,at91rm9200-st" },
189 { /* sentinel */ } 188 { /* sentinel */ }
@@ -219,28 +218,6 @@ node_err:
219err: 218err:
220 return -EINVAL; 219 return -EINVAL;
221} 220}
222#else
223static int __init of_at91rm9200_st_init(void)
224{
225 return -EINVAL;
226}
227#endif
228
229void __init at91rm9200_ioremap_st(u32 addr)
230{
231#ifdef CONFIG_OF
232 struct device_node *np;
233
234 np = of_find_matching_node(NULL, at91rm9200_st_timer_ids);
235 if (np) {
236 of_node_put(np);
237 return;
238 }
239#endif
240 at91_st_base = ioremap(addr, 256);
241 if (!at91_st_base)
242 panic("Impossible to ioremap ST\n");
243}
244 221
245/* 222/*
246 * ST (system timer) module supports both clockevents and clocksource. 223 * ST (system timer) module supports both clockevents and clocksource.
diff --git a/arch/arm/mach-at91/at91sam9260.c b/arch/arm/mach-at91/at91sam9260.c
index aab1f969a7c3..78137c24d90b 100644
--- a/arch/arm/mach-at91/at91sam9260.c
+++ b/arch/arm/mach-at91/at91sam9260.c
@@ -10,305 +10,13 @@
10 * 10 *
11 */ 11 */
12 12
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/clk/at91_pmc.h>
16
17#include <asm/proc-fns.h>
18#include <asm/irq.h>
19#include <asm/mach/arch.h>
20#include <asm/mach/map.h>
21#include <asm/system_misc.h> 13#include <asm/system_misc.h>
22#include <mach/cpu.h> 14#include <mach/cpu.h>
23#include <mach/at91_dbgu.h> 15#include <mach/at91_dbgu.h>
24#include <mach/at91sam9260.h>
25#include <mach/hardware.h> 16#include <mach/hardware.h>
26 17
27#include "at91_aic.h"
28#include "soc.h" 18#include "soc.h"
29#include "generic.h" 19#include "generic.h"
30#include "sam9_smc.h"
31#include "pm.h"
32
33#if defined(CONFIG_OLD_CLK_AT91)
34#include "clock.h"
35/* --------------------------------------------------------------------
36 * Clocks
37 * -------------------------------------------------------------------- */
38
39/*
40 * The peripheral clocks.
41 */
42static struct clk pioA_clk = {
43 .name = "pioA_clk",
44 .pmc_mask = 1 << AT91SAM9260_ID_PIOA,
45 .type = CLK_TYPE_PERIPHERAL,
46};
47static struct clk pioB_clk = {
48 .name = "pioB_clk",
49 .pmc_mask = 1 << AT91SAM9260_ID_PIOB,
50 .type = CLK_TYPE_PERIPHERAL,
51};
52static struct clk pioC_clk = {
53 .name = "pioC_clk",
54 .pmc_mask = 1 << AT91SAM9260_ID_PIOC,
55 .type = CLK_TYPE_PERIPHERAL,
56};
57static struct clk adc_clk = {
58 .name = "adc_clk",
59 .pmc_mask = 1 << AT91SAM9260_ID_ADC,
60 .type = CLK_TYPE_PERIPHERAL,
61};
62
63static struct clk adc_op_clk = {
64 .name = "adc_op_clk",
65 .type = CLK_TYPE_PERIPHERAL,
66 .rate_hz = 5000000,
67};
68
69static struct clk usart0_clk = {
70 .name = "usart0_clk",
71 .pmc_mask = 1 << AT91SAM9260_ID_US0,
72 .type = CLK_TYPE_PERIPHERAL,
73};
74static struct clk usart1_clk = {
75 .name = "usart1_clk",
76 .pmc_mask = 1 << AT91SAM9260_ID_US1,
77 .type = CLK_TYPE_PERIPHERAL,
78};
79static struct clk usart2_clk = {
80 .name = "usart2_clk",
81 .pmc_mask = 1 << AT91SAM9260_ID_US2,
82 .type = CLK_TYPE_PERIPHERAL,
83};
84static struct clk mmc_clk = {
85 .name = "mci_clk",
86 .pmc_mask = 1 << AT91SAM9260_ID_MCI,
87 .type = CLK_TYPE_PERIPHERAL,
88};
89static struct clk udc_clk = {
90 .name = "udc_clk",
91 .pmc_mask = 1 << AT91SAM9260_ID_UDP,
92 .type = CLK_TYPE_PERIPHERAL,
93};
94static struct clk twi_clk = {
95 .name = "twi_clk",
96 .pmc_mask = 1 << AT91SAM9260_ID_TWI,
97 .type = CLK_TYPE_PERIPHERAL,
98};
99static struct clk spi0_clk = {
100 .name = "spi0_clk",
101 .pmc_mask = 1 << AT91SAM9260_ID_SPI0,
102 .type = CLK_TYPE_PERIPHERAL,
103};
104static struct clk spi1_clk = {
105 .name = "spi1_clk",
106 .pmc_mask = 1 << AT91SAM9260_ID_SPI1,
107 .type = CLK_TYPE_PERIPHERAL,
108};
109static struct clk ssc_clk = {
110 .name = "ssc_clk",
111 .pmc_mask = 1 << AT91SAM9260_ID_SSC,
112 .type = CLK_TYPE_PERIPHERAL,
113};
114static struct clk tc0_clk = {
115 .name = "tc0_clk",
116 .pmc_mask = 1 << AT91SAM9260_ID_TC0,
117 .type = CLK_TYPE_PERIPHERAL,
118};
119static struct clk tc1_clk = {
120 .name = "tc1_clk",
121 .pmc_mask = 1 << AT91SAM9260_ID_TC1,
122 .type = CLK_TYPE_PERIPHERAL,
123};
124static struct clk tc2_clk = {
125 .name = "tc2_clk",
126 .pmc_mask = 1 << AT91SAM9260_ID_TC2,
127 .type = CLK_TYPE_PERIPHERAL,
128};
129static struct clk ohci_clk = {
130 .name = "ohci_clk",
131 .pmc_mask = 1 << AT91SAM9260_ID_UHP,
132 .type = CLK_TYPE_PERIPHERAL,
133};
134static struct clk macb_clk = {
135 .name = "pclk",
136 .pmc_mask = 1 << AT91SAM9260_ID_EMAC,
137 .type = CLK_TYPE_PERIPHERAL,
138};
139static struct clk isi_clk = {
140 .name = "isi_clk",
141 .pmc_mask = 1 << AT91SAM9260_ID_ISI,
142 .type = CLK_TYPE_PERIPHERAL,
143};
144static struct clk usart3_clk = {
145 .name = "usart3_clk",
146 .pmc_mask = 1 << AT91SAM9260_ID_US3,
147 .type = CLK_TYPE_PERIPHERAL,
148};
149static struct clk usart4_clk = {
150 .name = "usart4_clk",
151 .pmc_mask = 1 << AT91SAM9260_ID_US4,
152 .type = CLK_TYPE_PERIPHERAL,
153};
154static struct clk usart5_clk = {
155 .name = "usart5_clk",
156 .pmc_mask = 1 << AT91SAM9260_ID_US5,
157 .type = CLK_TYPE_PERIPHERAL,
158};
159static struct clk tc3_clk = {
160 .name = "tc3_clk",
161 .pmc_mask = 1 << AT91SAM9260_ID_TC3,
162 .type = CLK_TYPE_PERIPHERAL,
163};
164static struct clk tc4_clk = {
165 .name = "tc4_clk",
166 .pmc_mask = 1 << AT91SAM9260_ID_TC4,
167 .type = CLK_TYPE_PERIPHERAL,
168};
169static struct clk tc5_clk = {
170 .name = "tc5_clk",
171 .pmc_mask = 1 << AT91SAM9260_ID_TC5,
172 .type = CLK_TYPE_PERIPHERAL,
173};
174
175static struct clk *periph_clocks[] __initdata = {
176 &pioA_clk,
177 &pioB_clk,
178 &pioC_clk,
179 &adc_clk,
180 &adc_op_clk,
181 &usart0_clk,
182 &usart1_clk,
183 &usart2_clk,
184 &mmc_clk,
185 &udc_clk,
186 &twi_clk,
187 &spi0_clk,
188 &spi1_clk,
189 &ssc_clk,
190 &tc0_clk,
191 &tc1_clk,
192 &tc2_clk,
193 &ohci_clk,
194 &macb_clk,
195 &isi_clk,
196 &usart3_clk,
197 &usart4_clk,
198 &usart5_clk,
199 &tc3_clk,
200 &tc4_clk,
201 &tc5_clk,
202 // irq0 .. irq2
203};
204
205static struct clk_lookup periph_clocks_lookups[] = {
206 /* One additional fake clock for macb_hclk */
207 CLKDEV_CON_ID("hclk", &macb_clk),
208 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
209 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
210 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),
211 CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),
212 CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),
213 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.1", &tc3_clk),
214 CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.1", &tc4_clk),
215 CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.1", &tc5_clk),
216 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.0", &ssc_clk),
217 CLKDEV_CON_DEV_ID("pclk", "fffbc000.ssc", &ssc_clk),
218 CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9260.0", &twi_clk),
219 CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9g20.0", &twi_clk),
220 /* more usart lookup table for DT entries */
221 CLKDEV_CON_DEV_ID("usart", "fffff200.serial", &mck),
222 CLKDEV_CON_DEV_ID("usart", "fffb0000.serial", &usart0_clk),
223 CLKDEV_CON_DEV_ID("usart", "fffb4000.serial", &usart1_clk),
224 CLKDEV_CON_DEV_ID("usart", "fffb8000.serial", &usart2_clk),
225 CLKDEV_CON_DEV_ID("usart", "fffd0000.serial", &usart3_clk),
226 CLKDEV_CON_DEV_ID("usart", "fffd4000.serial", &usart4_clk),
227 CLKDEV_CON_DEV_ID("usart", "fffd8000.serial", &usart5_clk),
228 CLKDEV_CON_DEV_ID(NULL, "fffac000.i2c", &twi_clk),
229 /* more tc lookup table for DT entries */
230 CLKDEV_CON_DEV_ID("t0_clk", "fffa0000.timer", &tc0_clk),
231 CLKDEV_CON_DEV_ID("t1_clk", "fffa0000.timer", &tc1_clk),
232 CLKDEV_CON_DEV_ID("t2_clk", "fffa0000.timer", &tc2_clk),
233 CLKDEV_CON_DEV_ID("t0_clk", "fffdc000.timer", &tc3_clk),
234 CLKDEV_CON_DEV_ID("t1_clk", "fffdc000.timer", &tc4_clk),
235 CLKDEV_CON_DEV_ID("t2_clk", "fffdc000.timer", &tc5_clk),
236 CLKDEV_CON_DEV_ID("hclk", "500000.ohci", &ohci_clk),
237 CLKDEV_CON_DEV_ID("mci_clk", "fffa8000.mmc", &mmc_clk),
238 CLKDEV_CON_DEV_ID("spi_clk", "fffc8000.spi", &spi0_clk),
239 CLKDEV_CON_DEV_ID("spi_clk", "fffcc000.spi", &spi1_clk),
240 /* fake hclk clock */
241 CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
242 CLKDEV_CON_ID("pioA", &pioA_clk),
243 CLKDEV_CON_ID("pioB", &pioB_clk),
244 CLKDEV_CON_ID("pioC", &pioC_clk),
245 CLKDEV_CON_DEV_ID(NULL, "fffff400.gpio", &pioA_clk),
246 CLKDEV_CON_DEV_ID(NULL, "fffff600.gpio", &pioB_clk),
247 CLKDEV_CON_DEV_ID(NULL, "fffff800.gpio", &pioC_clk),
248};
249
250static struct clk_lookup usart_clocks_lookups[] = {
251 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
252 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
253 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
254 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
255 CLKDEV_CON_DEV_ID("usart", "atmel_usart.4", &usart3_clk),
256 CLKDEV_CON_DEV_ID("usart", "atmel_usart.5", &usart4_clk),
257 CLKDEV_CON_DEV_ID("usart", "atmel_usart.6", &usart5_clk),
258};
259
260/*
261 * The two programmable clocks.
262 * You must configure pin multiplexing to bring these signals out.
263 */
264static struct clk pck0 = {
265 .name = "pck0",
266 .pmc_mask = AT91_PMC_PCK0,
267 .type = CLK_TYPE_PROGRAMMABLE,
268 .id = 0,
269};
270static struct clk pck1 = {
271 .name = "pck1",
272 .pmc_mask = AT91_PMC_PCK1,
273 .type = CLK_TYPE_PROGRAMMABLE,
274 .id = 1,
275};
276
277static void __init at91sam9260_register_clocks(void)
278{
279 int i;
280
281 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
282 clk_register(periph_clocks[i]);
283
284 clkdev_add_table(periph_clocks_lookups,
285 ARRAY_SIZE(periph_clocks_lookups));
286 clkdev_add_table(usart_clocks_lookups,
287 ARRAY_SIZE(usart_clocks_lookups));
288
289 clk_register(&pck0);
290 clk_register(&pck1);
291}
292#else
293#define at91sam9260_register_clocks NULL
294#endif
295
296/* --------------------------------------------------------------------
297 * GPIO
298 * -------------------------------------------------------------------- */
299
300static struct at91_gpio_bank at91sam9260_gpio[] __initdata = {
301 {
302 .id = AT91SAM9260_ID_PIOA,
303 .regbase = AT91SAM9260_BASE_PIOA,
304 }, {
305 .id = AT91SAM9260_ID_PIOB,
306 .regbase = AT91SAM9260_BASE_PIOB,
307 }, {
308 .id = AT91SAM9260_ID_PIOC,
309 .regbase = AT91SAM9260_BASE_PIOC,
310 }
311};
312 20
313/* -------------------------------------------------------------------- 21/* --------------------------------------------------------------------
314 * AT91SAM9260 processor initialization 22 * AT91SAM9260 processor initialization
@@ -340,119 +48,14 @@ static void __init at91sam9260_map_io(void)
340 at91_init_sram(0, AT91SAM9260_SRAM_BASE, AT91SAM9260_SRAM_SIZE); 48 at91_init_sram(0, AT91SAM9260_SRAM_BASE, AT91SAM9260_SRAM_SIZE);
341} 49}
342 50
343static void __init at91sam9260_ioremap_registers(void)
344{
345 at91_ioremap_ramc(0, AT91SAM9260_BASE_SDRAMC, 512);
346 at91sam926x_ioremap_pit(AT91SAM9260_BASE_PIT);
347 at91sam9_ioremap_smc(0, AT91SAM9260_BASE_SMC);
348 at91_ioremap_matrix(AT91SAM9260_BASE_MATRIX);
349 at91_pm_set_standby(at91sam9_sdram_standby);
350}
351
352static void __init at91sam9260_initialize(void) 51static void __init at91sam9260_initialize(void)
353{ 52{
354 arm_pm_idle = at91sam9_idle; 53 arm_pm_idle = at91sam9_idle;
355 54
356 at91_sysirq_mask_rtt(AT91SAM9260_BASE_RTT); 55 at91_sysirq_mask_rtt(AT91SAM9260_BASE_RTT);
357
358 /* Register GPIO subsystem */
359 at91_gpio_init(at91sam9260_gpio, 3);
360}
361
362static struct resource rstc_resources[] = {
363 [0] = {
364 .start = AT91SAM9260_BASE_RSTC,
365 .end = AT91SAM9260_BASE_RSTC + SZ_16 - 1,
366 .flags = IORESOURCE_MEM,
367 },
368 [1] = {
369 .start = AT91SAM9260_BASE_SDRAMC,
370 .end = AT91SAM9260_BASE_SDRAMC + SZ_512 - 1,
371 .flags = IORESOURCE_MEM,
372 },
373};
374
375static struct platform_device rstc_device = {
376 .name = "at91-sam9260-reset",
377 .resource = rstc_resources,
378 .num_resources = ARRAY_SIZE(rstc_resources),
379};
380
381static struct resource shdwc_resources[] = {
382 [0] = {
383 .start = AT91SAM9260_BASE_SHDWC,
384 .end = AT91SAM9260_BASE_SHDWC + SZ_16 - 1,
385 .flags = IORESOURCE_MEM,
386 },
387};
388
389static struct platform_device shdwc_device = {
390 .name = "at91-poweroff",
391 .resource = shdwc_resources,
392 .num_resources = ARRAY_SIZE(shdwc_resources),
393};
394
395static void __init at91sam9260_register_devices(void)
396{
397 platform_device_register(&rstc_device);
398 platform_device_register(&shdwc_device);
399}
400
401/* --------------------------------------------------------------------
402 * Interrupt initialization
403 * -------------------------------------------------------------------- */
404
405/*
406 * The default interrupt priority levels (0 = lowest, 7 = highest).
407 */
408static unsigned int at91sam9260_default_irq_priority[NR_AIC_IRQS] __initdata = {
409 7, /* Advanced Interrupt Controller */
410 7, /* System Peripherals */
411 1, /* Parallel IO Controller A */
412 1, /* Parallel IO Controller B */
413 1, /* Parallel IO Controller C */
414 0, /* Analog-to-Digital Converter */
415 5, /* USART 0 */
416 5, /* USART 1 */
417 5, /* USART 2 */
418 0, /* Multimedia Card Interface */
419 2, /* USB Device Port */
420 6, /* Two-Wire Interface */
421 5, /* Serial Peripheral Interface 0 */
422 5, /* Serial Peripheral Interface 1 */
423 5, /* Serial Synchronous Controller */
424 0,
425 0,
426 0, /* Timer Counter 0 */
427 0, /* Timer Counter 1 */
428 0, /* Timer Counter 2 */
429 2, /* USB Host port */
430 3, /* Ethernet */
431 0, /* Image Sensor Interface */
432 5, /* USART 3 */
433 5, /* USART 4 */
434 5, /* USART 5 */
435 0, /* Timer Counter 3 */
436 0, /* Timer Counter 4 */
437 0, /* Timer Counter 5 */
438 0, /* Advanced Interrupt Controller */
439 0, /* Advanced Interrupt Controller */
440 0, /* Advanced Interrupt Controller */
441};
442
443static void __init at91sam9260_init_time(void)
444{
445 at91sam926x_pit_init(NR_IRQS_LEGACY + AT91_ID_SYS);
446} 56}
447 57
448AT91_SOC_START(at91sam9260) 58AT91_SOC_START(at91sam9260)
449 .map_io = at91sam9260_map_io, 59 .map_io = at91sam9260_map_io,
450 .default_irq_priority = at91sam9260_default_irq_priority,
451 .extern_irq = (1 << AT91SAM9260_ID_IRQ0) | (1 << AT91SAM9260_ID_IRQ1)
452 | (1 << AT91SAM9260_ID_IRQ2),
453 .ioremap_registers = at91sam9260_ioremap_registers,
454 .register_clocks = at91sam9260_register_clocks,
455 .register_devices = at91sam9260_register_devices,
456 .init = at91sam9260_initialize, 60 .init = at91sam9260_initialize,
457 .init_time = at91sam9260_init_time,
458AT91_SOC_END 61AT91_SOC_END
diff --git a/arch/arm/mach-at91/at91sam9260_devices.c b/arch/arm/mach-at91/at91sam9260_devices.c
deleted file mode 100644
index ef88e0fe4e80..000000000000
--- a/arch/arm/mach-at91/at91sam9260_devices.c
+++ /dev/null
@@ -1,1364 +0,0 @@
1/*
2 * arch/arm/mach-at91/at91sam9260_devices.c
3 *
4 * Copyright (C) 2006 Atmel
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12#include <asm/mach/arch.h>
13#include <asm/mach/map.h>
14
15#include <linux/dma-mapping.h>
16#include <linux/gpio.h>
17#include <linux/platform_device.h>
18#include <linux/i2c-gpio.h>
19
20#include <linux/platform_data/at91_adc.h>
21
22#include <mach/cpu.h>
23#include <mach/at91sam9260.h>
24#include <mach/at91sam9260_matrix.h>
25#include <mach/at91_matrix.h>
26#include <mach/at91sam9_smc.h>
27#include <mach/hardware.h>
28
29#include "board.h"
30#include "generic.h"
31#include "gpio.h"
32
33/* --------------------------------------------------------------------
34 * USB Host
35 * -------------------------------------------------------------------- */
36
37#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
38static u64 ohci_dmamask = DMA_BIT_MASK(32);
39static struct at91_usbh_data usbh_data;
40
41static struct resource usbh_resources[] = {
42 [0] = {
43 .start = AT91SAM9260_UHP_BASE,
44 .end = AT91SAM9260_UHP_BASE + SZ_1M - 1,
45 .flags = IORESOURCE_MEM,
46 },
47 [1] = {
48 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_UHP,
49 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_UHP,
50 .flags = IORESOURCE_IRQ,
51 },
52};
53
54static struct platform_device at91_usbh_device = {
55 .name = "at91_ohci",
56 .id = -1,
57 .dev = {
58 .dma_mask = &ohci_dmamask,
59 .coherent_dma_mask = DMA_BIT_MASK(32),
60 .platform_data = &usbh_data,
61 },
62 .resource = usbh_resources,
63 .num_resources = ARRAY_SIZE(usbh_resources),
64};
65
66void __init at91_add_device_usbh(struct at91_usbh_data *data)
67{
68 int i;
69
70 if (!data)
71 return;
72
73 /* Enable overcurrent notification */
74 for (i = 0; i < data->ports; i++) {
75 if (gpio_is_valid(data->overcurrent_pin[i]))
76 at91_set_gpio_input(data->overcurrent_pin[i], 1);
77 }
78
79 usbh_data = *data;
80 platform_device_register(&at91_usbh_device);
81}
82#else
83void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
84#endif
85
86
87/* --------------------------------------------------------------------
88 * USB Device (Gadget)
89 * -------------------------------------------------------------------- */
90
91#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
92static struct at91_udc_data udc_data;
93
94static struct resource udc_resources[] = {
95 [0] = {
96 .start = AT91SAM9260_BASE_UDP,
97 .end = AT91SAM9260_BASE_UDP + SZ_16K - 1,
98 .flags = IORESOURCE_MEM,
99 },
100 [1] = {
101 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_UDP,
102 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_UDP,
103 .flags = IORESOURCE_IRQ,
104 },
105};
106
107static struct platform_device at91_udc_device = {
108 .name = "at91_udc",
109 .id = -1,
110 .dev = {
111 .platform_data = &udc_data,
112 },
113 .resource = udc_resources,
114 .num_resources = ARRAY_SIZE(udc_resources),
115};
116
117void __init at91_add_device_udc(struct at91_udc_data *data)
118{
119 if (!data)
120 return;
121
122 if (gpio_is_valid(data->vbus_pin)) {
123 at91_set_gpio_input(data->vbus_pin, 0);
124 at91_set_deglitch(data->vbus_pin, 1);
125 }
126
127 /* Pullup pin is handled internally by USB device peripheral */
128
129 udc_data = *data;
130 platform_device_register(&at91_udc_device);
131}
132#else
133void __init at91_add_device_udc(struct at91_udc_data *data) {}
134#endif
135
136
137/* --------------------------------------------------------------------
138 * Ethernet
139 * -------------------------------------------------------------------- */
140
141#if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
142static u64 eth_dmamask = DMA_BIT_MASK(32);
143static struct macb_platform_data eth_data;
144
145static struct resource eth_resources[] = {
146 [0] = {
147 .start = AT91SAM9260_BASE_EMAC,
148 .end = AT91SAM9260_BASE_EMAC + SZ_16K - 1,
149 .flags = IORESOURCE_MEM,
150 },
151 [1] = {
152 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_EMAC,
153 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_EMAC,
154 .flags = IORESOURCE_IRQ,
155 },
156};
157
158static struct platform_device at91sam9260_eth_device = {
159 .name = "macb",
160 .id = -1,
161 .dev = {
162 .dma_mask = &eth_dmamask,
163 .coherent_dma_mask = DMA_BIT_MASK(32),
164 .platform_data = &eth_data,
165 },
166 .resource = eth_resources,
167 .num_resources = ARRAY_SIZE(eth_resources),
168};
169
170void __init at91_add_device_eth(struct macb_platform_data *data)
171{
172 if (!data)
173 return;
174
175 if (gpio_is_valid(data->phy_irq_pin)) {
176 at91_set_gpio_input(data->phy_irq_pin, 0);
177 at91_set_deglitch(data->phy_irq_pin, 1);
178 }
179
180 /* Pins used for MII and RMII */
181 at91_set_A_periph(AT91_PIN_PA19, 0); /* ETXCK_EREFCK */
182 at91_set_A_periph(AT91_PIN_PA17, 0); /* ERXDV */
183 at91_set_A_periph(AT91_PIN_PA14, 0); /* ERX0 */
184 at91_set_A_periph(AT91_PIN_PA15, 0); /* ERX1 */
185 at91_set_A_periph(AT91_PIN_PA18, 0); /* ERXER */
186 at91_set_A_periph(AT91_PIN_PA16, 0); /* ETXEN */
187 at91_set_A_periph(AT91_PIN_PA12, 0); /* ETX0 */
188 at91_set_A_periph(AT91_PIN_PA13, 0); /* ETX1 */
189 at91_set_A_periph(AT91_PIN_PA21, 0); /* EMDIO */
190 at91_set_A_periph(AT91_PIN_PA20, 0); /* EMDC */
191
192 if (!data->is_rmii) {
193 at91_set_B_periph(AT91_PIN_PA28, 0); /* ECRS */
194 at91_set_B_periph(AT91_PIN_PA29, 0); /* ECOL */
195 at91_set_B_periph(AT91_PIN_PA25, 0); /* ERX2 */
196 at91_set_B_periph(AT91_PIN_PA26, 0); /* ERX3 */
197 at91_set_B_periph(AT91_PIN_PA27, 0); /* ERXCK */
198 at91_set_B_periph(AT91_PIN_PA23, 0); /* ETX2 */
199 at91_set_B_periph(AT91_PIN_PA24, 0); /* ETX3 */
200 at91_set_B_periph(AT91_PIN_PA22, 0); /* ETXER */
201 }
202
203 eth_data = *data;
204 platform_device_register(&at91sam9260_eth_device);
205}
206#else
207void __init at91_add_device_eth(struct macb_platform_data *data) {}
208#endif
209
210
211/* --------------------------------------------------------------------
212 * MMC / SD Slot for Atmel MCI Driver
213 * -------------------------------------------------------------------- */
214
215#if IS_ENABLED(CONFIG_MMC_ATMELMCI)
216static u64 mmc_dmamask = DMA_BIT_MASK(32);
217static struct mci_platform_data mmc_data;
218
219static struct resource mmc_resources[] = {
220 [0] = {
221 .start = AT91SAM9260_BASE_MCI,
222 .end = AT91SAM9260_BASE_MCI + SZ_16K - 1,
223 .flags = IORESOURCE_MEM,
224 },
225 [1] = {
226 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
227 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_MCI,
228 .flags = IORESOURCE_IRQ,
229 },
230};
231
232static struct platform_device at91sam9260_mmc_device = {
233 .name = "atmel_mci",
234 .id = -1,
235 .dev = {
236 .dma_mask = &mmc_dmamask,
237 .coherent_dma_mask = DMA_BIT_MASK(32),
238 .platform_data = &mmc_data,
239 },
240 .resource = mmc_resources,
241 .num_resources = ARRAY_SIZE(mmc_resources),
242};
243
244void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
245{
246 unsigned int i;
247 unsigned int slot_count = 0;
248
249 if (!data)
250 return;
251
252 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
253 if (data->slot[i].bus_width) {
254 /* input/irq */
255 if (gpio_is_valid(data->slot[i].detect_pin)) {
256 at91_set_gpio_input(data->slot[i].detect_pin, 1);
257 at91_set_deglitch(data->slot[i].detect_pin, 1);
258 }
259 if (gpio_is_valid(data->slot[i].wp_pin))
260 at91_set_gpio_input(data->slot[i].wp_pin, 1);
261
262 switch (i) {
263 case 0:
264 /* CMD */
265 at91_set_A_periph(AT91_PIN_PA7, 1);
266 /* DAT0, maybe DAT1..DAT3 */
267 at91_set_A_periph(AT91_PIN_PA6, 1);
268 if (data->slot[i].bus_width == 4) {
269 at91_set_A_periph(AT91_PIN_PA9, 1);
270 at91_set_A_periph(AT91_PIN_PA10, 1);
271 at91_set_A_periph(AT91_PIN_PA11, 1);
272 }
273 slot_count++;
274 break;
275 case 1:
276 /* CMD */
277 at91_set_B_periph(AT91_PIN_PA1, 1);
278 /* DAT0, maybe DAT1..DAT3 */
279 at91_set_B_periph(AT91_PIN_PA0, 1);
280 if (data->slot[i].bus_width == 4) {
281 at91_set_B_periph(AT91_PIN_PA5, 1);
282 at91_set_B_periph(AT91_PIN_PA4, 1);
283 at91_set_B_periph(AT91_PIN_PA3, 1);
284 }
285 slot_count++;
286 break;
287 default:
288 printk(KERN_ERR
289 "AT91: SD/MMC slot %d not available\n", i);
290 break;
291 }
292 }
293 }
294
295 if (slot_count) {
296 /* CLK */
297 at91_set_A_periph(AT91_PIN_PA8, 0);
298
299 mmc_data = *data;
300 platform_device_register(&at91sam9260_mmc_device);
301 }
302}
303#else
304void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
305#endif
306
307
308/* --------------------------------------------------------------------
309 * NAND / SmartMedia
310 * -------------------------------------------------------------------- */
311
312#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
313static struct atmel_nand_data nand_data;
314
315#define NAND_BASE AT91_CHIPSELECT_3
316
317static struct resource nand_resources[] = {
318 [0] = {
319 .start = NAND_BASE,
320 .end = NAND_BASE + SZ_256M - 1,
321 .flags = IORESOURCE_MEM,
322 },
323 [1] = {
324 .start = AT91SAM9260_BASE_ECC,
325 .end = AT91SAM9260_BASE_ECC + SZ_512 - 1,
326 .flags = IORESOURCE_MEM,
327 }
328};
329
330static struct platform_device at91sam9260_nand_device = {
331 .name = "atmel_nand",
332 .id = -1,
333 .dev = {
334 .platform_data = &nand_data,
335 },
336 .resource = nand_resources,
337 .num_resources = ARRAY_SIZE(nand_resources),
338};
339
340void __init at91_add_device_nand(struct atmel_nand_data *data)
341{
342 unsigned long csa;
343
344 if (!data)
345 return;
346
347 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
348 at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
349
350 /* enable pin */
351 if (gpio_is_valid(data->enable_pin))
352 at91_set_gpio_output(data->enable_pin, 1);
353
354 /* ready/busy pin */
355 if (gpio_is_valid(data->rdy_pin))
356 at91_set_gpio_input(data->rdy_pin, 1);
357
358 /* card detect pin */
359 if (gpio_is_valid(data->det_pin))
360 at91_set_gpio_input(data->det_pin, 1);
361
362 nand_data = *data;
363 platform_device_register(&at91sam9260_nand_device);
364}
365#else
366void __init at91_add_device_nand(struct atmel_nand_data *data) {}
367#endif
368
369
370/* --------------------------------------------------------------------
371 * TWI (i2c)
372 * -------------------------------------------------------------------- */
373
374/*
375 * Prefer the GPIO code since the TWI controller isn't robust
376 * (gets overruns and underruns under load) and can only issue
377 * repeated STARTs in one scenario (the driver doesn't yet handle them).
378 */
379
380#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
381
382static struct i2c_gpio_platform_data pdata = {
383 .sda_pin = AT91_PIN_PA23,
384 .sda_is_open_drain = 1,
385 .scl_pin = AT91_PIN_PA24,
386 .scl_is_open_drain = 1,
387 .udelay = 2, /* ~100 kHz */
388};
389
390static struct platform_device at91sam9260_twi_device = {
391 .name = "i2c-gpio",
392 .id = 0,
393 .dev.platform_data = &pdata,
394};
395
396void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
397{
398 at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
399 at91_set_multi_drive(AT91_PIN_PA23, 1);
400
401 at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
402 at91_set_multi_drive(AT91_PIN_PA24, 1);
403
404 i2c_register_board_info(0, devices, nr_devices);
405 platform_device_register(&at91sam9260_twi_device);
406}
407
408#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
409
410static struct resource twi_resources[] = {
411 [0] = {
412 .start = AT91SAM9260_BASE_TWI,
413 .end = AT91SAM9260_BASE_TWI + SZ_16K - 1,
414 .flags = IORESOURCE_MEM,
415 },
416 [1] = {
417 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
418 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TWI,
419 .flags = IORESOURCE_IRQ,
420 },
421};
422
423static struct platform_device at91sam9260_twi_device = {
424 .id = 0,
425 .resource = twi_resources,
426 .num_resources = ARRAY_SIZE(twi_resources),
427};
428
429void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
430{
431 /* IP version is not the same on 9260 and g20 */
432 if (cpu_is_at91sam9g20()) {
433 at91sam9260_twi_device.name = "i2c-at91sam9g20";
434 } else {
435 at91sam9260_twi_device.name = "i2c-at91sam9260";
436 }
437
438 /* pins used for TWI interface */
439 at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
440 at91_set_multi_drive(AT91_PIN_PA23, 1);
441
442 at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
443 at91_set_multi_drive(AT91_PIN_PA24, 1);
444
445 i2c_register_board_info(0, devices, nr_devices);
446 platform_device_register(&at91sam9260_twi_device);
447}
448#else
449void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
450#endif
451
452
453/* --------------------------------------------------------------------
454 * SPI
455 * -------------------------------------------------------------------- */
456
457#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
458static u64 spi_dmamask = DMA_BIT_MASK(32);
459
460static struct resource spi0_resources[] = {
461 [0] = {
462 .start = AT91SAM9260_BASE_SPI0,
463 .end = AT91SAM9260_BASE_SPI0 + SZ_16K - 1,
464 .flags = IORESOURCE_MEM,
465 },
466 [1] = {
467 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
468 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI0,
469 .flags = IORESOURCE_IRQ,
470 },
471};
472
473static struct platform_device at91sam9260_spi0_device = {
474 .name = "atmel_spi",
475 .id = 0,
476 .dev = {
477 .dma_mask = &spi_dmamask,
478 .coherent_dma_mask = DMA_BIT_MASK(32),
479 },
480 .resource = spi0_resources,
481 .num_resources = ARRAY_SIZE(spi0_resources),
482};
483
484static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PC11, AT91_PIN_PC16, AT91_PIN_PC17 };
485
486static struct resource spi1_resources[] = {
487 [0] = {
488 .start = AT91SAM9260_BASE_SPI1,
489 .end = AT91SAM9260_BASE_SPI1 + SZ_16K - 1,
490 .flags = IORESOURCE_MEM,
491 },
492 [1] = {
493 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
494 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SPI1,
495 .flags = IORESOURCE_IRQ,
496 },
497};
498
499static struct platform_device at91sam9260_spi1_device = {
500 .name = "atmel_spi",
501 .id = 1,
502 .dev = {
503 .dma_mask = &spi_dmamask,
504 .coherent_dma_mask = DMA_BIT_MASK(32),
505 },
506 .resource = spi1_resources,
507 .num_resources = ARRAY_SIZE(spi1_resources),
508};
509
510static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PC5, AT91_PIN_PC4, AT91_PIN_PC3 };
511
512void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
513{
514 int i;
515 unsigned long cs_pin;
516 short enable_spi0 = 0;
517 short enable_spi1 = 0;
518
519 /* Choose SPI chip-selects */
520 for (i = 0; i < nr_devices; i++) {
521 if (devices[i].controller_data)
522 cs_pin = (unsigned long) devices[i].controller_data;
523 else if (devices[i].bus_num == 0)
524 cs_pin = spi0_standard_cs[devices[i].chip_select];
525 else
526 cs_pin = spi1_standard_cs[devices[i].chip_select];
527
528 if (!gpio_is_valid(cs_pin))
529 continue;
530
531 if (devices[i].bus_num == 0)
532 enable_spi0 = 1;
533 else
534 enable_spi1 = 1;
535
536 /* enable chip-select pin */
537 at91_set_gpio_output(cs_pin, 1);
538
539 /* pass chip-select pin to driver */
540 devices[i].controller_data = (void *) cs_pin;
541 }
542
543 spi_register_board_info(devices, nr_devices);
544
545 /* Configure SPI bus(es) */
546 if (enable_spi0) {
547 at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
548 at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
549 at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI1_SPCK */
550
551 platform_device_register(&at91sam9260_spi0_device);
552 }
553 if (enable_spi1) {
554 at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI1_MISO */
555 at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI1_MOSI */
556 at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI1_SPCK */
557
558 platform_device_register(&at91sam9260_spi1_device);
559 }
560}
561#else
562void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
563#endif
564
565
566/* --------------------------------------------------------------------
567 * Timer/Counter blocks
568 * -------------------------------------------------------------------- */
569
570#ifdef CONFIG_ATMEL_TCLIB
571
572static struct resource tcb0_resources[] = {
573 [0] = {
574 .start = AT91SAM9260_BASE_TCB0,
575 .end = AT91SAM9260_BASE_TCB0 + SZ_256 - 1,
576 .flags = IORESOURCE_MEM,
577 },
578 [1] = {
579 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
580 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC0,
581 .flags = IORESOURCE_IRQ,
582 },
583 [2] = {
584 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
585 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC1,
586 .flags = IORESOURCE_IRQ,
587 },
588 [3] = {
589 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
590 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC2,
591 .flags = IORESOURCE_IRQ,
592 },
593};
594
595static struct platform_device at91sam9260_tcb0_device = {
596 .name = "atmel_tcb",
597 .id = 0,
598 .resource = tcb0_resources,
599 .num_resources = ARRAY_SIZE(tcb0_resources),
600};
601
602static struct resource tcb1_resources[] = {
603 [0] = {
604 .start = AT91SAM9260_BASE_TCB1,
605 .end = AT91SAM9260_BASE_TCB1 + SZ_256 - 1,
606 .flags = IORESOURCE_MEM,
607 },
608 [1] = {
609 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
610 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC3,
611 .flags = IORESOURCE_IRQ,
612 },
613 [2] = {
614 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
615 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC4,
616 .flags = IORESOURCE_IRQ,
617 },
618 [3] = {
619 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
620 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_TC5,
621 .flags = IORESOURCE_IRQ,
622 },
623};
624
625static struct platform_device at91sam9260_tcb1_device = {
626 .name = "atmel_tcb",
627 .id = 1,
628 .resource = tcb1_resources,
629 .num_resources = ARRAY_SIZE(tcb1_resources),
630};
631
632static void __init at91_add_device_tc(void)
633{
634 platform_device_register(&at91sam9260_tcb0_device);
635 platform_device_register(&at91sam9260_tcb1_device);
636}
637#else
638static void __init at91_add_device_tc(void) { }
639#endif
640
641
642/* --------------------------------------------------------------------
643 * RTT
644 * -------------------------------------------------------------------- */
645
646static struct resource rtt_resources[] = {
647 {
648 .start = AT91SAM9260_BASE_RTT,
649 .end = AT91SAM9260_BASE_RTT + SZ_16 - 1,
650 .flags = IORESOURCE_MEM,
651 }, {
652 .flags = IORESOURCE_MEM,
653 }, {
654 .flags = IORESOURCE_IRQ,
655 },
656};
657
658static struct platform_device at91sam9260_rtt_device = {
659 .name = "at91_rtt",
660 .id = 0,
661 .resource = rtt_resources,
662};
663
664
665#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
666static void __init at91_add_device_rtt_rtc(void)
667{
668 at91sam9260_rtt_device.name = "rtc-at91sam9";
669 /*
670 * The second resource is needed:
671 * GPBR will serve as the storage for RTC time offset
672 */
673 at91sam9260_rtt_device.num_resources = 3;
674 rtt_resources[1].start = AT91SAM9260_BASE_GPBR +
675 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
676 rtt_resources[1].end = rtt_resources[1].start + 3;
677 rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
678 rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
679}
680#else
681static void __init at91_add_device_rtt_rtc(void)
682{
683 /* Only one resource is needed: RTT not used as RTC */
684 at91sam9260_rtt_device.num_resources = 1;
685}
686#endif
687
688static void __init at91_add_device_rtt(void)
689{
690 at91_add_device_rtt_rtc();
691 platform_device_register(&at91sam9260_rtt_device);
692}
693
694
695/* --------------------------------------------------------------------
696 * Watchdog
697 * -------------------------------------------------------------------- */
698
699#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
700static struct resource wdt_resources[] = {
701 {
702 .start = AT91SAM9260_BASE_WDT,
703 .end = AT91SAM9260_BASE_WDT + SZ_16 - 1,
704 .flags = IORESOURCE_MEM,
705 }
706};
707
708static struct platform_device at91sam9260_wdt_device = {
709 .name = "at91_wdt",
710 .id = -1,
711 .resource = wdt_resources,
712 .num_resources = ARRAY_SIZE(wdt_resources),
713};
714
715static void __init at91_add_device_watchdog(void)
716{
717 platform_device_register(&at91sam9260_wdt_device);
718}
719#else
720static void __init at91_add_device_watchdog(void) {}
721#endif
722
723
724/* --------------------------------------------------------------------
725 * SSC -- Synchronous Serial Controller
726 * -------------------------------------------------------------------- */
727
728#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
729static u64 ssc_dmamask = DMA_BIT_MASK(32);
730
731static struct resource ssc_resources[] = {
732 [0] = {
733 .start = AT91SAM9260_BASE_SSC,
734 .end = AT91SAM9260_BASE_SSC + SZ_16K - 1,
735 .flags = IORESOURCE_MEM,
736 },
737 [1] = {
738 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
739 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_SSC,
740 .flags = IORESOURCE_IRQ,
741 },
742};
743
744static struct platform_device at91sam9260_ssc_device = {
745 .name = "at91rm9200_ssc",
746 .id = 0,
747 .dev = {
748 .dma_mask = &ssc_dmamask,
749 .coherent_dma_mask = DMA_BIT_MASK(32),
750 },
751 .resource = ssc_resources,
752 .num_resources = ARRAY_SIZE(ssc_resources),
753};
754
755static inline void configure_ssc_pins(unsigned pins)
756{
757 if (pins & ATMEL_SSC_TF)
758 at91_set_A_periph(AT91_PIN_PB17, 1);
759 if (pins & ATMEL_SSC_TK)
760 at91_set_A_periph(AT91_PIN_PB16, 1);
761 if (pins & ATMEL_SSC_TD)
762 at91_set_A_periph(AT91_PIN_PB18, 1);
763 if (pins & ATMEL_SSC_RD)
764 at91_set_A_periph(AT91_PIN_PB19, 1);
765 if (pins & ATMEL_SSC_RK)
766 at91_set_A_periph(AT91_PIN_PB20, 1);
767 if (pins & ATMEL_SSC_RF)
768 at91_set_A_periph(AT91_PIN_PB21, 1);
769}
770
771/*
772 * SSC controllers are accessed through library code, instead of any
773 * kind of all-singing/all-dancing driver. For example one could be
774 * used by a particular I2S audio codec's driver, while another one
775 * on the same system might be used by a custom data capture driver.
776 */
777void __init at91_add_device_ssc(unsigned id, unsigned pins)
778{
779 struct platform_device *pdev;
780
781 /*
782 * NOTE: caller is responsible for passing information matching
783 * "pins" to whatever will be using each particular controller.
784 */
785 switch (id) {
786 case AT91SAM9260_ID_SSC:
787 pdev = &at91sam9260_ssc_device;
788 configure_ssc_pins(pins);
789 break;
790 default:
791 return;
792 }
793
794 platform_device_register(pdev);
795}
796
797#else
798void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
799#endif
800
801
802/* --------------------------------------------------------------------
803 * UART
804 * -------------------------------------------------------------------- */
805#if defined(CONFIG_SERIAL_ATMEL)
806static struct resource dbgu_resources[] = {
807 [0] = {
808 .start = AT91SAM9260_BASE_DBGU,
809 .end = AT91SAM9260_BASE_DBGU + SZ_512 - 1,
810 .flags = IORESOURCE_MEM,
811 },
812 [1] = {
813 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
814 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
815 .flags = IORESOURCE_IRQ,
816 },
817};
818
819static struct atmel_uart_data dbgu_data = {
820 .use_dma_tx = 0,
821 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
822};
823
824static u64 dbgu_dmamask = DMA_BIT_MASK(32);
825
826static struct platform_device at91sam9260_dbgu_device = {
827 .name = "atmel_usart",
828 .id = 0,
829 .dev = {
830 .dma_mask = &dbgu_dmamask,
831 .coherent_dma_mask = DMA_BIT_MASK(32),
832 .platform_data = &dbgu_data,
833 },
834 .resource = dbgu_resources,
835 .num_resources = ARRAY_SIZE(dbgu_resources),
836};
837
838static inline void configure_dbgu_pins(void)
839{
840 at91_set_A_periph(AT91_PIN_PB14, 0); /* DRXD */
841 at91_set_A_periph(AT91_PIN_PB15, 1); /* DTXD */
842}
843
844static struct resource uart0_resources[] = {
845 [0] = {
846 .start = AT91SAM9260_BASE_US0,
847 .end = AT91SAM9260_BASE_US0 + SZ_16K - 1,
848 .flags = IORESOURCE_MEM,
849 },
850 [1] = {
851 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
852 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US0,
853 .flags = IORESOURCE_IRQ,
854 },
855};
856
857static struct atmel_uart_data uart0_data = {
858 .use_dma_tx = 1,
859 .use_dma_rx = 1,
860};
861
862static u64 uart0_dmamask = DMA_BIT_MASK(32);
863
864static struct platform_device at91sam9260_uart0_device = {
865 .name = "atmel_usart",
866 .id = 1,
867 .dev = {
868 .dma_mask = &uart0_dmamask,
869 .coherent_dma_mask = DMA_BIT_MASK(32),
870 .platform_data = &uart0_data,
871 },
872 .resource = uart0_resources,
873 .num_resources = ARRAY_SIZE(uart0_resources),
874};
875
876static inline void configure_usart0_pins(unsigned pins)
877{
878 at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD0 */
879 at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD0 */
880
881 if (pins & ATMEL_UART_RTS)
882 at91_set_A_periph(AT91_PIN_PB26, 0); /* RTS0 */
883 if (pins & ATMEL_UART_CTS)
884 at91_set_A_periph(AT91_PIN_PB27, 0); /* CTS0 */
885 if (pins & ATMEL_UART_DTR)
886 at91_set_A_periph(AT91_PIN_PB24, 0); /* DTR0 */
887 if (pins & ATMEL_UART_DSR)
888 at91_set_A_periph(AT91_PIN_PB22, 0); /* DSR0 */
889 if (pins & ATMEL_UART_DCD)
890 at91_set_A_periph(AT91_PIN_PB23, 0); /* DCD0 */
891 if (pins & ATMEL_UART_RI)
892 at91_set_A_periph(AT91_PIN_PB25, 0); /* RI0 */
893}
894
895static struct resource uart1_resources[] = {
896 [0] = {
897 .start = AT91SAM9260_BASE_US1,
898 .end = AT91SAM9260_BASE_US1 + SZ_16K - 1,
899 .flags = IORESOURCE_MEM,
900 },
901 [1] = {
902 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
903 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US1,
904 .flags = IORESOURCE_IRQ,
905 },
906};
907
908static struct atmel_uart_data uart1_data = {
909 .use_dma_tx = 1,
910 .use_dma_rx = 1,
911};
912
913static u64 uart1_dmamask = DMA_BIT_MASK(32);
914
915static struct platform_device at91sam9260_uart1_device = {
916 .name = "atmel_usart",
917 .id = 2,
918 .dev = {
919 .dma_mask = &uart1_dmamask,
920 .coherent_dma_mask = DMA_BIT_MASK(32),
921 .platform_data = &uart1_data,
922 },
923 .resource = uart1_resources,
924 .num_resources = ARRAY_SIZE(uart1_resources),
925};
926
927static inline void configure_usart1_pins(unsigned pins)
928{
929 at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD1 */
930 at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD1 */
931
932 if (pins & ATMEL_UART_RTS)
933 at91_set_A_periph(AT91_PIN_PB28, 0); /* RTS1 */
934 if (pins & ATMEL_UART_CTS)
935 at91_set_A_periph(AT91_PIN_PB29, 0); /* CTS1 */
936}
937
938static struct resource uart2_resources[] = {
939 [0] = {
940 .start = AT91SAM9260_BASE_US2,
941 .end = AT91SAM9260_BASE_US2 + SZ_16K - 1,
942 .flags = IORESOURCE_MEM,
943 },
944 [1] = {
945 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
946 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US2,
947 .flags = IORESOURCE_IRQ,
948 },
949};
950
951static struct atmel_uart_data uart2_data = {
952 .use_dma_tx = 1,
953 .use_dma_rx = 1,
954};
955
956static u64 uart2_dmamask = DMA_BIT_MASK(32);
957
958static struct platform_device at91sam9260_uart2_device = {
959 .name = "atmel_usart",
960 .id = 3,
961 .dev = {
962 .dma_mask = &uart2_dmamask,
963 .coherent_dma_mask = DMA_BIT_MASK(32),
964 .platform_data = &uart2_data,
965 },
966 .resource = uart2_resources,
967 .num_resources = ARRAY_SIZE(uart2_resources),
968};
969
970static inline void configure_usart2_pins(unsigned pins)
971{
972 at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD2 */
973 at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD2 */
974
975 if (pins & ATMEL_UART_RTS)
976 at91_set_A_periph(AT91_PIN_PA4, 0); /* RTS2 */
977 if (pins & ATMEL_UART_CTS)
978 at91_set_A_periph(AT91_PIN_PA5, 0); /* CTS2 */
979}
980
981static struct resource uart3_resources[] = {
982 [0] = {
983 .start = AT91SAM9260_BASE_US3,
984 .end = AT91SAM9260_BASE_US3 + SZ_16K - 1,
985 .flags = IORESOURCE_MEM,
986 },
987 [1] = {
988 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
989 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US3,
990 .flags = IORESOURCE_IRQ,
991 },
992};
993
994static struct atmel_uart_data uart3_data = {
995 .use_dma_tx = 1,
996 .use_dma_rx = 1,
997};
998
999static u64 uart3_dmamask = DMA_BIT_MASK(32);
1000
1001static struct platform_device at91sam9260_uart3_device = {
1002 .name = "atmel_usart",
1003 .id = 4,
1004 .dev = {
1005 .dma_mask = &uart3_dmamask,
1006 .coherent_dma_mask = DMA_BIT_MASK(32),
1007 .platform_data = &uart3_data,
1008 },
1009 .resource = uart3_resources,
1010 .num_resources = ARRAY_SIZE(uart3_resources),
1011};
1012
1013static inline void configure_usart3_pins(unsigned pins)
1014{
1015 at91_set_A_periph(AT91_PIN_PB10, 1); /* TXD3 */
1016 at91_set_A_periph(AT91_PIN_PB11, 0); /* RXD3 */
1017
1018 if (pins & ATMEL_UART_RTS)
1019 at91_set_B_periph(AT91_PIN_PC8, 0); /* RTS3 */
1020 if (pins & ATMEL_UART_CTS)
1021 at91_set_B_periph(AT91_PIN_PC10, 0); /* CTS3 */
1022}
1023
1024static struct resource uart4_resources[] = {
1025 [0] = {
1026 .start = AT91SAM9260_BASE_US4,
1027 .end = AT91SAM9260_BASE_US4 + SZ_16K - 1,
1028 .flags = IORESOURCE_MEM,
1029 },
1030 [1] = {
1031 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
1032 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US4,
1033 .flags = IORESOURCE_IRQ,
1034 },
1035};
1036
1037static struct atmel_uart_data uart4_data = {
1038 .use_dma_tx = 1,
1039 .use_dma_rx = 1,
1040};
1041
1042static u64 uart4_dmamask = DMA_BIT_MASK(32);
1043
1044static struct platform_device at91sam9260_uart4_device = {
1045 .name = "atmel_usart",
1046 .id = 5,
1047 .dev = {
1048 .dma_mask = &uart4_dmamask,
1049 .coherent_dma_mask = DMA_BIT_MASK(32),
1050 .platform_data = &uart4_data,
1051 },
1052 .resource = uart4_resources,
1053 .num_resources = ARRAY_SIZE(uart4_resources),
1054};
1055
1056static inline void configure_usart4_pins(void)
1057{
1058 at91_set_B_periph(AT91_PIN_PA31, 1); /* TXD4 */
1059 at91_set_B_periph(AT91_PIN_PA30, 0); /* RXD4 */
1060}
1061
1062static struct resource uart5_resources[] = {
1063 [0] = {
1064 .start = AT91SAM9260_BASE_US5,
1065 .end = AT91SAM9260_BASE_US5 + SZ_16K - 1,
1066 .flags = IORESOURCE_MEM,
1067 },
1068 [1] = {
1069 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
1070 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_US5,
1071 .flags = IORESOURCE_IRQ,
1072 },
1073};
1074
1075static struct atmel_uart_data uart5_data = {
1076 .use_dma_tx = 1,
1077 .use_dma_rx = 1,
1078};
1079
1080static u64 uart5_dmamask = DMA_BIT_MASK(32);
1081
1082static struct platform_device at91sam9260_uart5_device = {
1083 .name = "atmel_usart",
1084 .id = 6,
1085 .dev = {
1086 .dma_mask = &uart5_dmamask,
1087 .coherent_dma_mask = DMA_BIT_MASK(32),
1088 .platform_data = &uart5_data,
1089 },
1090 .resource = uart5_resources,
1091 .num_resources = ARRAY_SIZE(uart5_resources),
1092};
1093
1094static inline void configure_usart5_pins(void)
1095{
1096 at91_set_A_periph(AT91_PIN_PB12, 1); /* TXD5 */
1097 at91_set_A_periph(AT91_PIN_PB13, 0); /* RXD5 */
1098}
1099
1100static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
1101
1102void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1103{
1104 struct platform_device *pdev;
1105 struct atmel_uart_data *pdata;
1106
1107 switch (id) {
1108 case 0: /* DBGU */
1109 pdev = &at91sam9260_dbgu_device;
1110 configure_dbgu_pins();
1111 break;
1112 case AT91SAM9260_ID_US0:
1113 pdev = &at91sam9260_uart0_device;
1114 configure_usart0_pins(pins);
1115 break;
1116 case AT91SAM9260_ID_US1:
1117 pdev = &at91sam9260_uart1_device;
1118 configure_usart1_pins(pins);
1119 break;
1120 case AT91SAM9260_ID_US2:
1121 pdev = &at91sam9260_uart2_device;
1122 configure_usart2_pins(pins);
1123 break;
1124 case AT91SAM9260_ID_US3:
1125 pdev = &at91sam9260_uart3_device;
1126 configure_usart3_pins(pins);
1127 break;
1128 case AT91SAM9260_ID_US4:
1129 pdev = &at91sam9260_uart4_device;
1130 configure_usart4_pins();
1131 break;
1132 case AT91SAM9260_ID_US5:
1133 pdev = &at91sam9260_uart5_device;
1134 configure_usart5_pins();
1135 break;
1136 default:
1137 return;
1138 }
1139 pdata = pdev->dev.platform_data;
1140 pdata->num = portnr; /* update to mapped ID */
1141
1142 if (portnr < ATMEL_MAX_UART)
1143 at91_uarts[portnr] = pdev;
1144}
1145
1146void __init at91_add_device_serial(void)
1147{
1148 int i;
1149
1150 for (i = 0; i < ATMEL_MAX_UART; i++) {
1151 if (at91_uarts[i])
1152 platform_device_register(at91_uarts[i]);
1153 }
1154}
1155#else
1156void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1157void __init at91_add_device_serial(void) {}
1158#endif
1159
1160/* --------------------------------------------------------------------
1161 * CF/IDE
1162 * -------------------------------------------------------------------- */
1163
1164#if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
1165 defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
1166
1167static struct at91_cf_data cf0_data;
1168
1169static struct resource cf0_resources[] = {
1170 [0] = {
1171 .start = AT91_CHIPSELECT_4,
1172 .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
1173 .flags = IORESOURCE_MEM,
1174 }
1175};
1176
1177static struct platform_device cf0_device = {
1178 .id = 0,
1179 .dev = {
1180 .platform_data = &cf0_data,
1181 },
1182 .resource = cf0_resources,
1183 .num_resources = ARRAY_SIZE(cf0_resources),
1184};
1185
1186static struct at91_cf_data cf1_data;
1187
1188static struct resource cf1_resources[] = {
1189 [0] = {
1190 .start = AT91_CHIPSELECT_5,
1191 .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
1192 .flags = IORESOURCE_MEM,
1193 }
1194};
1195
1196static struct platform_device cf1_device = {
1197 .id = 1,
1198 .dev = {
1199 .platform_data = &cf1_data,
1200 },
1201 .resource = cf1_resources,
1202 .num_resources = ARRAY_SIZE(cf1_resources),
1203};
1204
1205void __init at91_add_device_cf(struct at91_cf_data *data)
1206{
1207 struct platform_device *pdev;
1208 unsigned long csa;
1209
1210 if (!data)
1211 return;
1212
1213 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
1214
1215 switch (data->chipselect) {
1216 case 4:
1217 at91_set_multi_drive(AT91_PIN_PC8, 0);
1218 at91_set_A_periph(AT91_PIN_PC8, 0);
1219 csa |= AT91_MATRIX_CS4A_SMC_CF1;
1220 cf0_data = *data;
1221 pdev = &cf0_device;
1222 break;
1223 case 5:
1224 at91_set_multi_drive(AT91_PIN_PC9, 0);
1225 at91_set_A_periph(AT91_PIN_PC9, 0);
1226 csa |= AT91_MATRIX_CS5A_SMC_CF2;
1227 cf1_data = *data;
1228 pdev = &cf1_device;
1229 break;
1230 default:
1231 printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
1232 data->chipselect);
1233 return;
1234 }
1235
1236 at91_matrix_write(AT91_MATRIX_EBICSA, csa);
1237
1238 if (gpio_is_valid(data->rst_pin)) {
1239 at91_set_multi_drive(data->rst_pin, 0);
1240 at91_set_gpio_output(data->rst_pin, 1);
1241 }
1242
1243 if (gpio_is_valid(data->irq_pin)) {
1244 at91_set_gpio_input(data->irq_pin, 0);
1245 at91_set_deglitch(data->irq_pin, 1);
1246 }
1247
1248 if (gpio_is_valid(data->det_pin)) {
1249 at91_set_gpio_input(data->det_pin, 0);
1250 at91_set_deglitch(data->det_pin, 1);
1251 }
1252
1253 at91_set_B_periph(AT91_PIN_PC6, 0); /* CFCE1 */
1254 at91_set_B_periph(AT91_PIN_PC7, 0); /* CFCE2 */
1255 at91_set_A_periph(AT91_PIN_PC10, 0); /* CFRNW */
1256 at91_set_A_periph(AT91_PIN_PC15, 1); /* NWAIT */
1257
1258 if (IS_ENABLED(CONFIG_PATA_AT91) && (data->flags & AT91_CF_TRUE_IDE))
1259 pdev->name = "pata_at91";
1260 else
1261 pdev->name = "at91_cf";
1262
1263 platform_device_register(pdev);
1264}
1265
1266#else
1267void __init at91_add_device_cf(struct at91_cf_data * data) {}
1268#endif
1269
1270/* --------------------------------------------------------------------
1271 * ADCs
1272 * -------------------------------------------------------------------- */
1273
1274#if IS_ENABLED(CONFIG_AT91_ADC)
1275static struct at91_adc_data adc_data;
1276
1277static struct resource adc_resources[] = {
1278 [0] = {
1279 .start = AT91SAM9260_BASE_ADC,
1280 .end = AT91SAM9260_BASE_ADC + SZ_16K - 1,
1281 .flags = IORESOURCE_MEM,
1282 },
1283 [1] = {
1284 .start = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
1285 .end = NR_IRQS_LEGACY + AT91SAM9260_ID_ADC,
1286 .flags = IORESOURCE_IRQ,
1287 },
1288};
1289
1290static struct platform_device at91_adc_device = {
1291 .name = "at91sam9260-adc",
1292 .id = -1,
1293 .dev = {
1294 .platform_data = &adc_data,
1295 },
1296 .resource = adc_resources,
1297 .num_resources = ARRAY_SIZE(adc_resources),
1298};
1299
1300static struct at91_adc_trigger at91_adc_triggers[] = {
1301 [0] = {
1302 .name = "timer-counter-0",
1303 .value = 0x1,
1304 },
1305 [1] = {
1306 .name = "timer-counter-1",
1307 .value = 0x3,
1308 },
1309 [2] = {
1310 .name = "timer-counter-2",
1311 .value = 0x5,
1312 },
1313 [3] = {
1314 .name = "external",
1315 .value = 0xd,
1316 .is_external = true,
1317 },
1318};
1319
1320void __init at91_add_device_adc(struct at91_adc_data *data)
1321{
1322 if (!data)
1323 return;
1324
1325 if (test_bit(0, &data->channels_used))
1326 at91_set_A_periph(AT91_PIN_PC0, 0);
1327 if (test_bit(1, &data->channels_used))
1328 at91_set_A_periph(AT91_PIN_PC1, 0);
1329 if (test_bit(2, &data->channels_used))
1330 at91_set_A_periph(AT91_PIN_PC2, 0);
1331 if (test_bit(3, &data->channels_used))
1332 at91_set_A_periph(AT91_PIN_PC3, 0);
1333
1334 if (data->use_external_triggers)
1335 at91_set_A_periph(AT91_PIN_PA22, 0);
1336
1337 data->startup_time = 10;
1338 data->trigger_number = 4;
1339 data->trigger_list = at91_adc_triggers;
1340
1341 adc_data = *data;
1342 platform_device_register(&at91_adc_device);
1343}
1344#else
1345void __init at91_add_device_adc(struct at91_adc_data *data) {}
1346#endif
1347
1348/* -------------------------------------------------------------------- */
1349/*
1350 * These devices are always present and don't need any board-specific
1351 * setup.
1352 */
1353static int __init at91_add_standard_devices(void)
1354{
1355 if (of_have_populated_dt())
1356 return 0;
1357
1358 at91_add_device_rtt();
1359 at91_add_device_watchdog();
1360 at91_add_device_tc();
1361 return 0;
1362}
1363
1364arch_initcall(at91_add_standard_devices);
diff --git a/arch/arm/mach-at91/at91sam9261.c b/arch/arm/mach-at91/at91sam9261.c
index a8bd35963332..d29953ecb0c4 100644
--- a/arch/arm/mach-at91/at91sam9261.c
+++ b/arch/arm/mach-at91/at91sam9261.c
@@ -10,282 +10,12 @@
10 * 10 *
11 */ 11 */
12 12
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/clk/at91_pmc.h>
16
17#include <asm/proc-fns.h>
18#include <asm/irq.h>
19#include <asm/mach/arch.h>
20#include <asm/mach/map.h>
21#include <asm/system_misc.h> 13#include <asm/system_misc.h>
22#include <mach/cpu.h> 14#include <mach/cpu.h>
23#include <mach/at91sam9261.h>
24#include <mach/hardware.h> 15#include <mach/hardware.h>
25 16
26#include "at91_aic.h"
27#include "soc.h" 17#include "soc.h"
28#include "generic.h" 18#include "generic.h"
29#include "sam9_smc.h"
30#include "pm.h"
31
32#if defined(CONFIG_OLD_CLK_AT91)
33#include "clock.h"
34
35/* --------------------------------------------------------------------
36 * Clocks
37 * -------------------------------------------------------------------- */
38
39/*
40 * The peripheral clocks.
41 */
42static struct clk pioA_clk = {
43 .name = "pioA_clk",
44 .pmc_mask = 1 << AT91SAM9261_ID_PIOA,
45 .type = CLK_TYPE_PERIPHERAL,
46};
47static struct clk pioB_clk = {
48 .name = "pioB_clk",
49 .pmc_mask = 1 << AT91SAM9261_ID_PIOB,
50 .type = CLK_TYPE_PERIPHERAL,
51};
52static struct clk pioC_clk = {
53 .name = "pioC_clk",
54 .pmc_mask = 1 << AT91SAM9261_ID_PIOC,
55 .type = CLK_TYPE_PERIPHERAL,
56};
57static struct clk usart0_clk = {
58 .name = "usart0_clk",
59 .pmc_mask = 1 << AT91SAM9261_ID_US0,
60 .type = CLK_TYPE_PERIPHERAL,
61};
62static struct clk usart1_clk = {
63 .name = "usart1_clk",
64 .pmc_mask = 1 << AT91SAM9261_ID_US1,
65 .type = CLK_TYPE_PERIPHERAL,
66};
67static struct clk usart2_clk = {
68 .name = "usart2_clk",
69 .pmc_mask = 1 << AT91SAM9261_ID_US2,
70 .type = CLK_TYPE_PERIPHERAL,
71};
72static struct clk mmc_clk = {
73 .name = "mci_clk",
74 .pmc_mask = 1 << AT91SAM9261_ID_MCI,
75 .type = CLK_TYPE_PERIPHERAL,
76};
77static struct clk udc_clk = {
78 .name = "udc_clk",
79 .pmc_mask = 1 << AT91SAM9261_ID_UDP,
80 .type = CLK_TYPE_PERIPHERAL,
81};
82static struct clk twi_clk = {
83 .name = "twi_clk",
84 .pmc_mask = 1 << AT91SAM9261_ID_TWI,
85 .type = CLK_TYPE_PERIPHERAL,
86};
87static struct clk spi0_clk = {
88 .name = "spi0_clk",
89 .pmc_mask = 1 << AT91SAM9261_ID_SPI0,
90 .type = CLK_TYPE_PERIPHERAL,
91};
92static struct clk spi1_clk = {
93 .name = "spi1_clk",
94 .pmc_mask = 1 << AT91SAM9261_ID_SPI1,
95 .type = CLK_TYPE_PERIPHERAL,
96};
97static struct clk ssc0_clk = {
98 .name = "ssc0_clk",
99 .pmc_mask = 1 << AT91SAM9261_ID_SSC0,
100 .type = CLK_TYPE_PERIPHERAL,
101};
102static struct clk ssc1_clk = {
103 .name = "ssc1_clk",
104 .pmc_mask = 1 << AT91SAM9261_ID_SSC1,
105 .type = CLK_TYPE_PERIPHERAL,
106};
107static struct clk ssc2_clk = {
108 .name = "ssc2_clk",
109 .pmc_mask = 1 << AT91SAM9261_ID_SSC2,
110 .type = CLK_TYPE_PERIPHERAL,
111};
112static struct clk tc0_clk = {
113 .name = "tc0_clk",
114 .pmc_mask = 1 << AT91SAM9261_ID_TC0,
115 .type = CLK_TYPE_PERIPHERAL,
116};
117static struct clk tc1_clk = {
118 .name = "tc1_clk",
119 .pmc_mask = 1 << AT91SAM9261_ID_TC1,
120 .type = CLK_TYPE_PERIPHERAL,
121};
122static struct clk tc2_clk = {
123 .name = "tc2_clk",
124 .pmc_mask = 1 << AT91SAM9261_ID_TC2,
125 .type = CLK_TYPE_PERIPHERAL,
126};
127static struct clk ohci_clk = {
128 .name = "ohci_clk",
129 .pmc_mask = 1 << AT91SAM9261_ID_UHP,
130 .type = CLK_TYPE_PERIPHERAL,
131};
132static struct clk lcdc_clk = {
133 .name = "lcdc_clk",
134 .pmc_mask = 1 << AT91SAM9261_ID_LCDC,
135 .type = CLK_TYPE_PERIPHERAL,
136};
137
138/* HClocks */
139static struct clk hck0 = {
140 .name = "hck0",
141 .pmc_mask = AT91_PMC_HCK0,
142 .type = CLK_TYPE_SYSTEM,
143 .id = 0,
144};
145static struct clk hck1 = {
146 .name = "hck1",
147 .pmc_mask = AT91_PMC_HCK1,
148 .type = CLK_TYPE_SYSTEM,
149 .id = 1,
150};
151
152static struct clk *periph_clocks[] __initdata = {
153 &pioA_clk,
154 &pioB_clk,
155 &pioC_clk,
156 &usart0_clk,
157 &usart1_clk,
158 &usart2_clk,
159 &mmc_clk,
160 &udc_clk,
161 &twi_clk,
162 &spi0_clk,
163 &spi1_clk,
164 &ssc0_clk,
165 &ssc1_clk,
166 &ssc2_clk,
167 &tc0_clk,
168 &tc1_clk,
169 &tc2_clk,
170 &ohci_clk,
171 &lcdc_clk,
172 // irq0 .. irq2
173};
174
175static struct clk_lookup periph_clocks_lookups[] = {
176 CLKDEV_CON_DEV_ID("hclk", "at91sam9261-lcdfb.0", &hck1),
177 CLKDEV_CON_DEV_ID("hclk", "at91sam9g10-lcdfb.0", &hck1),
178 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
179 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
180 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),
181 CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),
182 CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),
183 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.0", &ssc0_clk),
184 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.1", &ssc1_clk),
185 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.2", &ssc2_clk),
186 CLKDEV_CON_DEV_ID("pclk", "fffbc000.ssc", &ssc0_clk),
187 CLKDEV_CON_DEV_ID("pclk", "fffc0000.ssc", &ssc1_clk),
188 CLKDEV_CON_DEV_ID("pclk", "fffc4000.ssc", &ssc2_clk),
189 CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &hck0),
190 CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9261.0", &twi_clk),
191 CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9g10.0", &twi_clk),
192 CLKDEV_CON_ID("pioA", &pioA_clk),
193 CLKDEV_CON_ID("pioB", &pioB_clk),
194 CLKDEV_CON_ID("pioC", &pioC_clk),
195 /* more lookup table for DT entries */
196 CLKDEV_CON_DEV_ID("usart", "fffff200.serial", &mck),
197 CLKDEV_CON_DEV_ID("usart", "fffb0000.serial", &usart0_clk),
198 CLKDEV_CON_DEV_ID("usart", "ffffb400.serial", &usart1_clk),
199 CLKDEV_CON_DEV_ID("usart", "fff94000.serial", &usart2_clk),
200 CLKDEV_CON_DEV_ID("t0_clk", "fffa0000.timer", &tc0_clk),
201 CLKDEV_CON_DEV_ID("t1_clk", "fffa0000.timer", &tc1_clk),
202 CLKDEV_CON_DEV_ID("t2_clk", "fffa0000.timer", &tc2_clk),
203 CLKDEV_CON_DEV_ID("hclk", "500000.ohci", &hck0),
204 CLKDEV_CON_DEV_ID("hclk", "600000.fb", &hck1),
205 CLKDEV_CON_DEV_ID("spi_clk", "fffc8000.spi", &spi0_clk),
206 CLKDEV_CON_DEV_ID("spi_clk", "fffcc000.spi", &spi1_clk),
207 CLKDEV_CON_DEV_ID("mci_clk", "fffa8000.mmc", &mmc_clk),
208 CLKDEV_CON_DEV_ID(NULL, "fffac000.i2c", &twi_clk),
209 CLKDEV_CON_DEV_ID(NULL, "fffff400.gpio", &pioA_clk),
210 CLKDEV_CON_DEV_ID(NULL, "fffff600.gpio", &pioB_clk),
211 CLKDEV_CON_DEV_ID(NULL, "fffff800.gpio", &pioC_clk),
212};
213
214static struct clk_lookup usart_clocks_lookups[] = {
215 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
216 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
217 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
218 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
219};
220
221/*
222 * The four programmable clocks.
223 * You must configure pin multiplexing to bring these signals out.
224 */
225static struct clk pck0 = {
226 .name = "pck0",
227 .pmc_mask = AT91_PMC_PCK0,
228 .type = CLK_TYPE_PROGRAMMABLE,
229 .id = 0,
230};
231static struct clk pck1 = {
232 .name = "pck1",
233 .pmc_mask = AT91_PMC_PCK1,
234 .type = CLK_TYPE_PROGRAMMABLE,
235 .id = 1,
236};
237static struct clk pck2 = {
238 .name = "pck2",
239 .pmc_mask = AT91_PMC_PCK2,
240 .type = CLK_TYPE_PROGRAMMABLE,
241 .id = 2,
242};
243static struct clk pck3 = {
244 .name = "pck3",
245 .pmc_mask = AT91_PMC_PCK3,
246 .type = CLK_TYPE_PROGRAMMABLE,
247 .id = 3,
248};
249
250static void __init at91sam9261_register_clocks(void)
251{
252 int i;
253
254 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
255 clk_register(periph_clocks[i]);
256
257 clkdev_add_table(periph_clocks_lookups,
258 ARRAY_SIZE(periph_clocks_lookups));
259 clkdev_add_table(usart_clocks_lookups,
260 ARRAY_SIZE(usart_clocks_lookups));
261
262 clk_register(&pck0);
263 clk_register(&pck1);
264 clk_register(&pck2);
265 clk_register(&pck3);
266
267 clk_register(&hck0);
268 clk_register(&hck1);
269}
270#else
271#define at91sam9261_register_clocks NULL
272#endif
273/* --------------------------------------------------------------------
274 * GPIO
275 * -------------------------------------------------------------------- */
276
277static struct at91_gpio_bank at91sam9261_gpio[] __initdata = {
278 {
279 .id = AT91SAM9261_ID_PIOA,
280 .regbase = AT91SAM9261_BASE_PIOA,
281 }, {
282 .id = AT91SAM9261_ID_PIOB,
283 .regbase = AT91SAM9261_BASE_PIOB,
284 }, {
285 .id = AT91SAM9261_ID_PIOC,
286 .regbase = AT91SAM9261_BASE_PIOC,
287 }
288};
289 19
290/* -------------------------------------------------------------------- 20/* --------------------------------------------------------------------
291 * AT91SAM9261 processor initialization 21 * AT91SAM9261 processor initialization
@@ -299,119 +29,14 @@ static void __init at91sam9261_map_io(void)
299 at91_init_sram(0, AT91SAM9261_SRAM_BASE, AT91SAM9261_SRAM_SIZE); 29 at91_init_sram(0, AT91SAM9261_SRAM_BASE, AT91SAM9261_SRAM_SIZE);
300} 30}
301 31
302static void __init at91sam9261_ioremap_registers(void)
303{
304 at91_ioremap_ramc(0, AT91SAM9261_BASE_SDRAMC, 512);
305 at91sam926x_ioremap_pit(AT91SAM9261_BASE_PIT);
306 at91sam9_ioremap_smc(0, AT91SAM9261_BASE_SMC);
307 at91_ioremap_matrix(AT91SAM9261_BASE_MATRIX);
308 at91_pm_set_standby(at91sam9_sdram_standby);
309}
310
311static void __init at91sam9261_initialize(void) 32static void __init at91sam9261_initialize(void)
312{ 33{
313 arm_pm_idle = at91sam9_idle; 34 arm_pm_idle = at91sam9_idle;
314 35
315 at91_sysirq_mask_rtt(AT91SAM9261_BASE_RTT); 36 at91_sysirq_mask_rtt(AT91SAM9261_BASE_RTT);
316
317 /* Register GPIO subsystem */
318 at91_gpio_init(at91sam9261_gpio, 3);
319}
320
321static struct resource rstc_resources[] = {
322 [0] = {
323 .start = AT91SAM9261_BASE_RSTC,
324 .end = AT91SAM9261_BASE_RSTC + SZ_16 - 1,
325 .flags = IORESOURCE_MEM,
326 },
327 [1] = {
328 .start = AT91SAM9261_BASE_SDRAMC,
329 .end = AT91SAM9261_BASE_SDRAMC + SZ_512 - 1,
330 .flags = IORESOURCE_MEM,
331 },
332};
333
334static struct platform_device rstc_device = {
335 .name = "at91-sam9260-reset",
336 .resource = rstc_resources,
337 .num_resources = ARRAY_SIZE(rstc_resources),
338};
339
340static struct resource shdwc_resources[] = {
341 [0] = {
342 .start = AT91SAM9261_BASE_SHDWC,
343 .end = AT91SAM9261_BASE_SHDWC + SZ_16 - 1,
344 .flags = IORESOURCE_MEM,
345 },
346};
347
348static struct platform_device shdwc_device = {
349 .name = "at91-poweroff",
350 .resource = shdwc_resources,
351 .num_resources = ARRAY_SIZE(shdwc_resources),
352};
353
354static void __init at91sam9261_register_devices(void)
355{
356 platform_device_register(&rstc_device);
357 platform_device_register(&shdwc_device);
358}
359
360/* --------------------------------------------------------------------
361 * Interrupt initialization
362 * -------------------------------------------------------------------- */
363
364/*
365 * The default interrupt priority levels (0 = lowest, 7 = highest).
366 */
367static unsigned int at91sam9261_default_irq_priority[NR_AIC_IRQS] __initdata = {
368 7, /* Advanced Interrupt Controller */
369 7, /* System Peripherals */
370 1, /* Parallel IO Controller A */
371 1, /* Parallel IO Controller B */
372 1, /* Parallel IO Controller C */
373 0,
374 5, /* USART 0 */
375 5, /* USART 1 */
376 5, /* USART 2 */
377 0, /* Multimedia Card Interface */
378 2, /* USB Device Port */
379 6, /* Two-Wire Interface */
380 5, /* Serial Peripheral Interface 0 */
381 5, /* Serial Peripheral Interface 1 */
382 4, /* Serial Synchronous Controller 0 */
383 4, /* Serial Synchronous Controller 1 */
384 4, /* Serial Synchronous Controller 2 */
385 0, /* Timer Counter 0 */
386 0, /* Timer Counter 1 */
387 0, /* Timer Counter 2 */
388 2, /* USB Host port */
389 3, /* LCD Controller */
390 0,
391 0,
392 0,
393 0,
394 0,
395 0,
396 0,
397 0, /* Advanced Interrupt Controller */
398 0, /* Advanced Interrupt Controller */
399 0, /* Advanced Interrupt Controller */
400};
401
402static void __init at91sam9261_init_time(void)
403{
404 at91sam926x_pit_init(NR_IRQS_LEGACY + AT91_ID_SYS);
405} 37}
406 38
407AT91_SOC_START(at91sam9261) 39AT91_SOC_START(at91sam9261)
408 .map_io = at91sam9261_map_io, 40 .map_io = at91sam9261_map_io,
409 .default_irq_priority = at91sam9261_default_irq_priority,
410 .extern_irq = (1 << AT91SAM9261_ID_IRQ0) | (1 << AT91SAM9261_ID_IRQ1)
411 | (1 << AT91SAM9261_ID_IRQ2),
412 .ioremap_registers = at91sam9261_ioremap_registers,
413 .register_clocks = at91sam9261_register_clocks,
414 .register_devices = at91sam9261_register_devices,
415 .init = at91sam9261_initialize, 41 .init = at91sam9261_initialize,
416 .init_time = at91sam9261_init_time,
417AT91_SOC_END 42AT91_SOC_END
diff --git a/arch/arm/mach-at91/at91sam9261_devices.c b/arch/arm/mach-at91/at91sam9261_devices.c
deleted file mode 100644
index 29baacb5c359..000000000000
--- a/arch/arm/mach-at91/at91sam9261_devices.c
+++ /dev/null
@@ -1,1098 +0,0 @@
1/*
2 * arch/arm/mach-at91/at91sam9261_devices.c
3 *
4 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
5 * Copyright (C) 2005 David Brownell
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 */
13#include <asm/mach/arch.h>
14#include <asm/mach/map.h>
15
16#include <linux/dma-mapping.h>
17#include <linux/gpio.h>
18#include <linux/platform_device.h>
19#include <linux/i2c-gpio.h>
20
21#include <linux/fb.h>
22#include <video/atmel_lcdc.h>
23
24#include <mach/at91sam9261.h>
25#include <mach/at91sam9261_matrix.h>
26#include <mach/at91_matrix.h>
27#include <mach/at91sam9_smc.h>
28#include <mach/hardware.h>
29
30#include "board.h"
31#include "generic.h"
32#include "gpio.h"
33
34/* --------------------------------------------------------------------
35 * USB Host
36 * -------------------------------------------------------------------- */
37
38#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
39static u64 ohci_dmamask = DMA_BIT_MASK(32);
40static struct at91_usbh_data usbh_data;
41
42static struct resource usbh_resources[] = {
43 [0] = {
44 .start = AT91SAM9261_UHP_BASE,
45 .end = AT91SAM9261_UHP_BASE + SZ_1M - 1,
46 .flags = IORESOURCE_MEM,
47 },
48 [1] = {
49 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_UHP,
50 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_UHP,
51 .flags = IORESOURCE_IRQ,
52 },
53};
54
55static struct platform_device at91sam9261_usbh_device = {
56 .name = "at91_ohci",
57 .id = -1,
58 .dev = {
59 .dma_mask = &ohci_dmamask,
60 .coherent_dma_mask = DMA_BIT_MASK(32),
61 .platform_data = &usbh_data,
62 },
63 .resource = usbh_resources,
64 .num_resources = ARRAY_SIZE(usbh_resources),
65};
66
67void __init at91_add_device_usbh(struct at91_usbh_data *data)
68{
69 int i;
70
71 if (!data)
72 return;
73
74 /* Enable overcurrent notification */
75 for (i = 0; i < data->ports; i++) {
76 if (gpio_is_valid(data->overcurrent_pin[i]))
77 at91_set_gpio_input(data->overcurrent_pin[i], 1);
78 }
79
80 usbh_data = *data;
81 platform_device_register(&at91sam9261_usbh_device);
82}
83#else
84void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
85#endif
86
87
88/* --------------------------------------------------------------------
89 * USB Device (Gadget)
90 * -------------------------------------------------------------------- */
91
92#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
93static struct at91_udc_data udc_data;
94
95static struct resource udc_resources[] = {
96 [0] = {
97 .start = AT91SAM9261_BASE_UDP,
98 .end = AT91SAM9261_BASE_UDP + SZ_16K - 1,
99 .flags = IORESOURCE_MEM,
100 },
101 [1] = {
102 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_UDP,
103 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_UDP,
104 .flags = IORESOURCE_IRQ,
105 },
106};
107
108static struct platform_device at91sam9261_udc_device = {
109 .name = "at91_udc",
110 .id = -1,
111 .dev = {
112 .platform_data = &udc_data,
113 },
114 .resource = udc_resources,
115 .num_resources = ARRAY_SIZE(udc_resources),
116};
117
118void __init at91_add_device_udc(struct at91_udc_data *data)
119{
120 if (!data)
121 return;
122
123 if (gpio_is_valid(data->vbus_pin)) {
124 at91_set_gpio_input(data->vbus_pin, 0);
125 at91_set_deglitch(data->vbus_pin, 1);
126 }
127
128 /* Pullup pin is handled internally by USB device peripheral */
129
130 udc_data = *data;
131 platform_device_register(&at91sam9261_udc_device);
132}
133#else
134void __init at91_add_device_udc(struct at91_udc_data *data) {}
135#endif
136
137/* --------------------------------------------------------------------
138 * MMC / SD
139 * -------------------------------------------------------------------- */
140
141#if IS_ENABLED(CONFIG_MMC_ATMELMCI)
142static u64 mmc_dmamask = DMA_BIT_MASK(32);
143static struct mci_platform_data mmc_data;
144
145static struct resource mmc_resources[] = {
146 [0] = {
147 .start = AT91SAM9261_BASE_MCI,
148 .end = AT91SAM9261_BASE_MCI + SZ_16K - 1,
149 .flags = IORESOURCE_MEM,
150 },
151 [1] = {
152 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_MCI,
153 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_MCI,
154 .flags = IORESOURCE_IRQ,
155 },
156};
157
158static struct platform_device at91sam9261_mmc_device = {
159 .name = "atmel_mci",
160 .id = -1,
161 .dev = {
162 .dma_mask = &mmc_dmamask,
163 .coherent_dma_mask = DMA_BIT_MASK(32),
164 .platform_data = &mmc_data,
165 },
166 .resource = mmc_resources,
167 .num_resources = ARRAY_SIZE(mmc_resources),
168};
169
170void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
171{
172 if (!data)
173 return;
174
175 if (data->slot[0].bus_width) {
176 /* input/irq */
177 if (gpio_is_valid(data->slot[0].detect_pin)) {
178 at91_set_gpio_input(data->slot[0].detect_pin, 1);
179 at91_set_deglitch(data->slot[0].detect_pin, 1);
180 }
181 if (gpio_is_valid(data->slot[0].wp_pin))
182 at91_set_gpio_input(data->slot[0].wp_pin, 1);
183
184 /* CLK */
185 at91_set_B_periph(AT91_PIN_PA2, 0);
186
187 /* CMD */
188 at91_set_B_periph(AT91_PIN_PA1, 1);
189
190 /* DAT0, maybe DAT1..DAT3 */
191 at91_set_B_periph(AT91_PIN_PA0, 1);
192 if (data->slot[0].bus_width == 4) {
193 at91_set_B_periph(AT91_PIN_PA4, 1);
194 at91_set_B_periph(AT91_PIN_PA5, 1);
195 at91_set_B_periph(AT91_PIN_PA6, 1);
196 }
197
198 mmc_data = *data;
199 platform_device_register(&at91sam9261_mmc_device);
200 }
201}
202#else
203void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
204#endif
205
206
207/* --------------------------------------------------------------------
208 * NAND / SmartMedia
209 * -------------------------------------------------------------------- */
210
211#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
212static struct atmel_nand_data nand_data;
213
214#define NAND_BASE AT91_CHIPSELECT_3
215
216static struct resource nand_resources[] = {
217 {
218 .start = NAND_BASE,
219 .end = NAND_BASE + SZ_256M - 1,
220 .flags = IORESOURCE_MEM,
221 }
222};
223
224static struct platform_device atmel_nand_device = {
225 .name = "atmel_nand",
226 .id = -1,
227 .dev = {
228 .platform_data = &nand_data,
229 },
230 .resource = nand_resources,
231 .num_resources = ARRAY_SIZE(nand_resources),
232};
233
234void __init at91_add_device_nand(struct atmel_nand_data *data)
235{
236 unsigned long csa;
237
238 if (!data)
239 return;
240
241 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
242 at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
243
244 /* enable pin */
245 if (gpio_is_valid(data->enable_pin))
246 at91_set_gpio_output(data->enable_pin, 1);
247
248 /* ready/busy pin */
249 if (gpio_is_valid(data->rdy_pin))
250 at91_set_gpio_input(data->rdy_pin, 1);
251
252 /* card detect pin */
253 if (gpio_is_valid(data->det_pin))
254 at91_set_gpio_input(data->det_pin, 1);
255
256 at91_set_A_periph(AT91_PIN_PC0, 0); /* NANDOE */
257 at91_set_A_periph(AT91_PIN_PC1, 0); /* NANDWE */
258
259 nand_data = *data;
260 platform_device_register(&atmel_nand_device);
261}
262
263#else
264void __init at91_add_device_nand(struct atmel_nand_data *data) {}
265#endif
266
267
268/* --------------------------------------------------------------------
269 * TWI (i2c)
270 * -------------------------------------------------------------------- */
271
272/*
273 * Prefer the GPIO code since the TWI controller isn't robust
274 * (gets overruns and underruns under load) and can only issue
275 * repeated STARTs in one scenario (the driver doesn't yet handle them).
276 */
277#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
278
279static struct i2c_gpio_platform_data pdata = {
280 .sda_pin = AT91_PIN_PA7,
281 .sda_is_open_drain = 1,
282 .scl_pin = AT91_PIN_PA8,
283 .scl_is_open_drain = 1,
284 .udelay = 2, /* ~100 kHz */
285};
286
287static struct platform_device at91sam9261_twi_device = {
288 .name = "i2c-gpio",
289 .id = 0,
290 .dev.platform_data = &pdata,
291};
292
293void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
294{
295 at91_set_GPIO_periph(AT91_PIN_PA7, 1); /* TWD (SDA) */
296 at91_set_multi_drive(AT91_PIN_PA7, 1);
297
298 at91_set_GPIO_periph(AT91_PIN_PA8, 1); /* TWCK (SCL) */
299 at91_set_multi_drive(AT91_PIN_PA8, 1);
300
301 i2c_register_board_info(0, devices, nr_devices);
302 platform_device_register(&at91sam9261_twi_device);
303}
304
305#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
306
307static struct resource twi_resources[] = {
308 [0] = {
309 .start = AT91SAM9261_BASE_TWI,
310 .end = AT91SAM9261_BASE_TWI + SZ_16K - 1,
311 .flags = IORESOURCE_MEM,
312 },
313 [1] = {
314 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_TWI,
315 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_TWI,
316 .flags = IORESOURCE_IRQ,
317 },
318};
319
320static struct platform_device at91sam9261_twi_device = {
321 .id = 0,
322 .resource = twi_resources,
323 .num_resources = ARRAY_SIZE(twi_resources),
324};
325
326void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
327{
328 /* IP version is not the same on 9261 and g10 */
329 if (cpu_is_at91sam9g10()) {
330 at91sam9261_twi_device.name = "i2c-at91sam9g10";
331 /* I2C PIO must not be configured as open-drain on this chip */
332 } else {
333 at91sam9261_twi_device.name = "i2c-at91sam9261";
334 at91_set_multi_drive(AT91_PIN_PA7, 1);
335 at91_set_multi_drive(AT91_PIN_PA8, 1);
336 }
337
338 /* pins used for TWI interface */
339 at91_set_A_periph(AT91_PIN_PA7, 0); /* TWD */
340 at91_set_A_periph(AT91_PIN_PA8, 0); /* TWCK */
341
342 i2c_register_board_info(0, devices, nr_devices);
343 platform_device_register(&at91sam9261_twi_device);
344}
345#else
346void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
347#endif
348
349
350/* --------------------------------------------------------------------
351 * SPI
352 * -------------------------------------------------------------------- */
353
354#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
355static u64 spi_dmamask = DMA_BIT_MASK(32);
356
357static struct resource spi0_resources[] = {
358 [0] = {
359 .start = AT91SAM9261_BASE_SPI0,
360 .end = AT91SAM9261_BASE_SPI0 + SZ_16K - 1,
361 .flags = IORESOURCE_MEM,
362 },
363 [1] = {
364 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_SPI0,
365 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_SPI0,
366 .flags = IORESOURCE_IRQ,
367 },
368};
369
370static struct platform_device at91sam9261_spi0_device = {
371 .name = "atmel_spi",
372 .id = 0,
373 .dev = {
374 .dma_mask = &spi_dmamask,
375 .coherent_dma_mask = DMA_BIT_MASK(32),
376 },
377 .resource = spi0_resources,
378 .num_resources = ARRAY_SIZE(spi0_resources),
379};
380
381static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PA5, AT91_PIN_PA6 };
382
383static struct resource spi1_resources[] = {
384 [0] = {
385 .start = AT91SAM9261_BASE_SPI1,
386 .end = AT91SAM9261_BASE_SPI1 + SZ_16K - 1,
387 .flags = IORESOURCE_MEM,
388 },
389 [1] = {
390 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_SPI1,
391 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_SPI1,
392 .flags = IORESOURCE_IRQ,
393 },
394};
395
396static struct platform_device at91sam9261_spi1_device = {
397 .name = "atmel_spi",
398 .id = 1,
399 .dev = {
400 .dma_mask = &spi_dmamask,
401 .coherent_dma_mask = DMA_BIT_MASK(32),
402 },
403 .resource = spi1_resources,
404 .num_resources = ARRAY_SIZE(spi1_resources),
405};
406
407static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB28, AT91_PIN_PA24, AT91_PIN_PA25, AT91_PIN_PA26 };
408
409void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
410{
411 int i;
412 unsigned long cs_pin;
413 short enable_spi0 = 0;
414 short enable_spi1 = 0;
415
416 /* Choose SPI chip-selects */
417 for (i = 0; i < nr_devices; i++) {
418 if (devices[i].controller_data)
419 cs_pin = (unsigned long) devices[i].controller_data;
420 else if (devices[i].bus_num == 0)
421 cs_pin = spi0_standard_cs[devices[i].chip_select];
422 else
423 cs_pin = spi1_standard_cs[devices[i].chip_select];
424
425 if (!gpio_is_valid(cs_pin))
426 continue;
427
428 if (devices[i].bus_num == 0)
429 enable_spi0 = 1;
430 else
431 enable_spi1 = 1;
432
433 /* enable chip-select pin */
434 at91_set_gpio_output(cs_pin, 1);
435
436 /* pass chip-select pin to driver */
437 devices[i].controller_data = (void *) cs_pin;
438 }
439
440 spi_register_board_info(devices, nr_devices);
441
442 /* Configure SPI bus(es) */
443 if (enable_spi0) {
444 at91_set_A_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
445 at91_set_A_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
446 at91_set_A_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
447
448 platform_device_register(&at91sam9261_spi0_device);
449 }
450 if (enable_spi1) {
451 at91_set_A_periph(AT91_PIN_PB30, 0); /* SPI1_MISO */
452 at91_set_A_periph(AT91_PIN_PB31, 0); /* SPI1_MOSI */
453 at91_set_A_periph(AT91_PIN_PB29, 0); /* SPI1_SPCK */
454
455 platform_device_register(&at91sam9261_spi1_device);
456 }
457}
458#else
459void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
460#endif
461
462
463/* --------------------------------------------------------------------
464 * LCD Controller
465 * -------------------------------------------------------------------- */
466
467#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
468static u64 lcdc_dmamask = DMA_BIT_MASK(32);
469static struct atmel_lcdfb_pdata lcdc_data;
470
471static struct resource lcdc_resources[] = {
472 [0] = {
473 .start = AT91SAM9261_LCDC_BASE,
474 .end = AT91SAM9261_LCDC_BASE + SZ_4K - 1,
475 .flags = IORESOURCE_MEM,
476 },
477 [1] = {
478 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_LCDC,
479 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_LCDC,
480 .flags = IORESOURCE_IRQ,
481 },
482#if defined(CONFIG_FB_INTSRAM)
483 [2] = {
484 .start = AT91SAM9261_SRAM_BASE,
485 .end = AT91SAM9261_SRAM_BASE + AT91SAM9261_SRAM_SIZE - 1,
486 .flags = IORESOURCE_MEM,
487 },
488#endif
489};
490
491static struct platform_device at91_lcdc_device = {
492 .id = 0,
493 .dev = {
494 .dma_mask = &lcdc_dmamask,
495 .coherent_dma_mask = DMA_BIT_MASK(32),
496 .platform_data = &lcdc_data,
497 },
498 .resource = lcdc_resources,
499 .num_resources = ARRAY_SIZE(lcdc_resources),
500};
501
502void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data)
503{
504 if (!data) {
505 return;
506 }
507
508 if (cpu_is_at91sam9g10())
509 at91_lcdc_device.name = "at91sam9g10-lcdfb";
510 else
511 at91_lcdc_device.name = "at91sam9261-lcdfb";
512
513#if defined(CONFIG_FB_ATMEL_STN)
514 at91_set_A_periph(AT91_PIN_PB0, 0); /* LCDVSYNC */
515 at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
516 at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
517 at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
518 at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
519 at91_set_A_periph(AT91_PIN_PB5, 0); /* LCDD0 */
520 at91_set_A_periph(AT91_PIN_PB6, 0); /* LCDD1 */
521 at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
522 at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
523#else
524 at91_set_A_periph(AT91_PIN_PB1, 0); /* LCDHSYNC */
525 at91_set_A_periph(AT91_PIN_PB2, 0); /* LCDDOTCK */
526 at91_set_A_periph(AT91_PIN_PB3, 0); /* LCDDEN */
527 at91_set_A_periph(AT91_PIN_PB4, 0); /* LCDCC */
528 at91_set_A_periph(AT91_PIN_PB7, 0); /* LCDD2 */
529 at91_set_A_periph(AT91_PIN_PB8, 0); /* LCDD3 */
530 at91_set_A_periph(AT91_PIN_PB9, 0); /* LCDD4 */
531 at91_set_A_periph(AT91_PIN_PB10, 0); /* LCDD5 */
532 at91_set_A_periph(AT91_PIN_PB11, 0); /* LCDD6 */
533 at91_set_A_periph(AT91_PIN_PB12, 0); /* LCDD7 */
534 at91_set_A_periph(AT91_PIN_PB15, 0); /* LCDD10 */
535 at91_set_A_periph(AT91_PIN_PB16, 0); /* LCDD11 */
536 at91_set_A_periph(AT91_PIN_PB17, 0); /* LCDD12 */
537 at91_set_A_periph(AT91_PIN_PB18, 0); /* LCDD13 */
538 at91_set_A_periph(AT91_PIN_PB19, 0); /* LCDD14 */
539 at91_set_A_periph(AT91_PIN_PB20, 0); /* LCDD15 */
540 at91_set_B_periph(AT91_PIN_PB23, 0); /* LCDD18 */
541 at91_set_B_periph(AT91_PIN_PB24, 0); /* LCDD19 */
542 at91_set_B_periph(AT91_PIN_PB25, 0); /* LCDD20 */
543 at91_set_B_periph(AT91_PIN_PB26, 0); /* LCDD21 */
544 at91_set_B_periph(AT91_PIN_PB27, 0); /* LCDD22 */
545 at91_set_B_periph(AT91_PIN_PB28, 0); /* LCDD23 */
546#endif
547
548 if (ARRAY_SIZE(lcdc_resources) > 2) {
549 void __iomem *fb;
550 struct resource *fb_res = &lcdc_resources[2];
551 size_t fb_len = resource_size(fb_res);
552
553 fb = ioremap(fb_res->start, fb_len);
554 if (fb) {
555 memset(fb, 0, fb_len);
556 iounmap(fb);
557 }
558 }
559 lcdc_data = *data;
560 platform_device_register(&at91_lcdc_device);
561}
562#else
563void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data) {}
564#endif
565
566
567/* --------------------------------------------------------------------
568 * Timer/Counter block
569 * -------------------------------------------------------------------- */
570
571#ifdef CONFIG_ATMEL_TCLIB
572
573static struct resource tcb_resources[] = {
574 [0] = {
575 .start = AT91SAM9261_BASE_TCB0,
576 .end = AT91SAM9261_BASE_TCB0 + SZ_16K - 1,
577 .flags = IORESOURCE_MEM,
578 },
579 [1] = {
580 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_TC0,
581 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_TC0,
582 .flags = IORESOURCE_IRQ,
583 },
584 [2] = {
585 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_TC1,
586 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_TC1,
587 .flags = IORESOURCE_IRQ,
588 },
589 [3] = {
590 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_TC2,
591 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_TC2,
592 .flags = IORESOURCE_IRQ,
593 },
594};
595
596static struct platform_device at91sam9261_tcb_device = {
597 .name = "atmel_tcb",
598 .id = 0,
599 .resource = tcb_resources,
600 .num_resources = ARRAY_SIZE(tcb_resources),
601};
602
603static void __init at91_add_device_tc(void)
604{
605 platform_device_register(&at91sam9261_tcb_device);
606}
607#else
608static void __init at91_add_device_tc(void) { }
609#endif
610
611
612/* --------------------------------------------------------------------
613 * RTT
614 * -------------------------------------------------------------------- */
615
616static struct resource rtt_resources[] = {
617 {
618 .start = AT91SAM9261_BASE_RTT,
619 .end = AT91SAM9261_BASE_RTT + SZ_16 - 1,
620 .flags = IORESOURCE_MEM,
621 }, {
622 .flags = IORESOURCE_MEM,
623 }, {
624 .flags = IORESOURCE_IRQ,
625 }
626};
627
628static struct platform_device at91sam9261_rtt_device = {
629 .name = "at91_rtt",
630 .id = 0,
631 .resource = rtt_resources,
632};
633
634#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
635static void __init at91_add_device_rtt_rtc(void)
636{
637 at91sam9261_rtt_device.name = "rtc-at91sam9";
638 /*
639 * The second resource is needed:
640 * GPBR will serve as the storage for RTC time offset
641 */
642 at91sam9261_rtt_device.num_resources = 3;
643 rtt_resources[1].start = AT91SAM9261_BASE_GPBR +
644 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
645 rtt_resources[1].end = rtt_resources[1].start + 3;
646 rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
647 rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
648}
649#else
650static void __init at91_add_device_rtt_rtc(void)
651{
652 /* Only one resource is needed: RTT not used as RTC */
653 at91sam9261_rtt_device.num_resources = 1;
654}
655#endif
656
657static void __init at91_add_device_rtt(void)
658{
659 at91_add_device_rtt_rtc();
660 platform_device_register(&at91sam9261_rtt_device);
661}
662
663
664/* --------------------------------------------------------------------
665 * Watchdog
666 * -------------------------------------------------------------------- */
667
668#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
669static struct resource wdt_resources[] = {
670 {
671 .start = AT91SAM9261_BASE_WDT,
672 .end = AT91SAM9261_BASE_WDT + SZ_16 - 1,
673 .flags = IORESOURCE_MEM,
674 }
675};
676
677static struct platform_device at91sam9261_wdt_device = {
678 .name = "at91_wdt",
679 .id = -1,
680 .resource = wdt_resources,
681 .num_resources = ARRAY_SIZE(wdt_resources),
682};
683
684static void __init at91_add_device_watchdog(void)
685{
686 platform_device_register(&at91sam9261_wdt_device);
687}
688#else
689static void __init at91_add_device_watchdog(void) {}
690#endif
691
692
693/* --------------------------------------------------------------------
694 * SSC -- Synchronous Serial Controller
695 * -------------------------------------------------------------------- */
696
697#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
698static u64 ssc0_dmamask = DMA_BIT_MASK(32);
699
700static struct resource ssc0_resources[] = {
701 [0] = {
702 .start = AT91SAM9261_BASE_SSC0,
703 .end = AT91SAM9261_BASE_SSC0 + SZ_16K - 1,
704 .flags = IORESOURCE_MEM,
705 },
706 [1] = {
707 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC0,
708 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC0,
709 .flags = IORESOURCE_IRQ,
710 },
711};
712
713static struct platform_device at91sam9261_ssc0_device = {
714 .name = "at91rm9200_ssc",
715 .id = 0,
716 .dev = {
717 .dma_mask = &ssc0_dmamask,
718 .coherent_dma_mask = DMA_BIT_MASK(32),
719 },
720 .resource = ssc0_resources,
721 .num_resources = ARRAY_SIZE(ssc0_resources),
722};
723
724static inline void configure_ssc0_pins(unsigned pins)
725{
726 if (pins & ATMEL_SSC_TF)
727 at91_set_A_periph(AT91_PIN_PB21, 1);
728 if (pins & ATMEL_SSC_TK)
729 at91_set_A_periph(AT91_PIN_PB22, 1);
730 if (pins & ATMEL_SSC_TD)
731 at91_set_A_periph(AT91_PIN_PB23, 1);
732 if (pins & ATMEL_SSC_RD)
733 at91_set_A_periph(AT91_PIN_PB24, 1);
734 if (pins & ATMEL_SSC_RK)
735 at91_set_A_periph(AT91_PIN_PB25, 1);
736 if (pins & ATMEL_SSC_RF)
737 at91_set_A_periph(AT91_PIN_PB26, 1);
738}
739
740static u64 ssc1_dmamask = DMA_BIT_MASK(32);
741
742static struct resource ssc1_resources[] = {
743 [0] = {
744 .start = AT91SAM9261_BASE_SSC1,
745 .end = AT91SAM9261_BASE_SSC1 + SZ_16K - 1,
746 .flags = IORESOURCE_MEM,
747 },
748 [1] = {
749 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC1,
750 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC1,
751 .flags = IORESOURCE_IRQ,
752 },
753};
754
755static struct platform_device at91sam9261_ssc1_device = {
756 .name = "at91rm9200_ssc",
757 .id = 1,
758 .dev = {
759 .dma_mask = &ssc1_dmamask,
760 .coherent_dma_mask = DMA_BIT_MASK(32),
761 },
762 .resource = ssc1_resources,
763 .num_resources = ARRAY_SIZE(ssc1_resources),
764};
765
766static inline void configure_ssc1_pins(unsigned pins)
767{
768 if (pins & ATMEL_SSC_TF)
769 at91_set_B_periph(AT91_PIN_PA17, 1);
770 if (pins & ATMEL_SSC_TK)
771 at91_set_B_periph(AT91_PIN_PA18, 1);
772 if (pins & ATMEL_SSC_TD)
773 at91_set_B_periph(AT91_PIN_PA19, 1);
774 if (pins & ATMEL_SSC_RD)
775 at91_set_B_periph(AT91_PIN_PA20, 1);
776 if (pins & ATMEL_SSC_RK)
777 at91_set_B_periph(AT91_PIN_PA21, 1);
778 if (pins & ATMEL_SSC_RF)
779 at91_set_B_periph(AT91_PIN_PA22, 1);
780}
781
782static u64 ssc2_dmamask = DMA_BIT_MASK(32);
783
784static struct resource ssc2_resources[] = {
785 [0] = {
786 .start = AT91SAM9261_BASE_SSC2,
787 .end = AT91SAM9261_BASE_SSC2 + SZ_16K - 1,
788 .flags = IORESOURCE_MEM,
789 },
790 [1] = {
791 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC2,
792 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_SSC2,
793 .flags = IORESOURCE_IRQ,
794 },
795};
796
797static struct platform_device at91sam9261_ssc2_device = {
798 .name = "at91rm9200_ssc",
799 .id = 2,
800 .dev = {
801 .dma_mask = &ssc2_dmamask,
802 .coherent_dma_mask = DMA_BIT_MASK(32),
803 },
804 .resource = ssc2_resources,
805 .num_resources = ARRAY_SIZE(ssc2_resources),
806};
807
808static inline void configure_ssc2_pins(unsigned pins)
809{
810 if (pins & ATMEL_SSC_TF)
811 at91_set_B_periph(AT91_PIN_PC25, 1);
812 if (pins & ATMEL_SSC_TK)
813 at91_set_B_periph(AT91_PIN_PC26, 1);
814 if (pins & ATMEL_SSC_TD)
815 at91_set_B_periph(AT91_PIN_PC27, 1);
816 if (pins & ATMEL_SSC_RD)
817 at91_set_B_periph(AT91_PIN_PC28, 1);
818 if (pins & ATMEL_SSC_RK)
819 at91_set_B_periph(AT91_PIN_PC29, 1);
820 if (pins & ATMEL_SSC_RF)
821 at91_set_B_periph(AT91_PIN_PC30, 1);
822}
823
824/*
825 * SSC controllers are accessed through library code, instead of any
826 * kind of all-singing/all-dancing driver. For example one could be
827 * used by a particular I2S audio codec's driver, while another one
828 * on the same system might be used by a custom data capture driver.
829 */
830void __init at91_add_device_ssc(unsigned id, unsigned pins)
831{
832 struct platform_device *pdev;
833
834 /*
835 * NOTE: caller is responsible for passing information matching
836 * "pins" to whatever will be using each particular controller.
837 */
838 switch (id) {
839 case AT91SAM9261_ID_SSC0:
840 pdev = &at91sam9261_ssc0_device;
841 configure_ssc0_pins(pins);
842 break;
843 case AT91SAM9261_ID_SSC1:
844 pdev = &at91sam9261_ssc1_device;
845 configure_ssc1_pins(pins);
846 break;
847 case AT91SAM9261_ID_SSC2:
848 pdev = &at91sam9261_ssc2_device;
849 configure_ssc2_pins(pins);
850 break;
851 default:
852 return;
853 }
854
855 platform_device_register(pdev);
856}
857
858#else
859void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
860#endif
861
862
863/* --------------------------------------------------------------------
864 * UART
865 * -------------------------------------------------------------------- */
866
867#if defined(CONFIG_SERIAL_ATMEL)
868static struct resource dbgu_resources[] = {
869 [0] = {
870 .start = AT91SAM9261_BASE_DBGU,
871 .end = AT91SAM9261_BASE_DBGU + SZ_512 - 1,
872 .flags = IORESOURCE_MEM,
873 },
874 [1] = {
875 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
876 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
877 .flags = IORESOURCE_IRQ,
878 },
879};
880
881static struct atmel_uart_data dbgu_data = {
882 .use_dma_tx = 0,
883 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
884};
885
886static u64 dbgu_dmamask = DMA_BIT_MASK(32);
887
888static struct platform_device at91sam9261_dbgu_device = {
889 .name = "atmel_usart",
890 .id = 0,
891 .dev = {
892 .dma_mask = &dbgu_dmamask,
893 .coherent_dma_mask = DMA_BIT_MASK(32),
894 .platform_data = &dbgu_data,
895 },
896 .resource = dbgu_resources,
897 .num_resources = ARRAY_SIZE(dbgu_resources),
898};
899
900static inline void configure_dbgu_pins(void)
901{
902 at91_set_A_periph(AT91_PIN_PA9, 0); /* DRXD */
903 at91_set_A_periph(AT91_PIN_PA10, 1); /* DTXD */
904}
905
906static struct resource uart0_resources[] = {
907 [0] = {
908 .start = AT91SAM9261_BASE_US0,
909 .end = AT91SAM9261_BASE_US0 + SZ_16K - 1,
910 .flags = IORESOURCE_MEM,
911 },
912 [1] = {
913 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_US0,
914 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_US0,
915 .flags = IORESOURCE_IRQ,
916 },
917};
918
919static struct atmel_uart_data uart0_data = {
920 .use_dma_tx = 1,
921 .use_dma_rx = 1,
922};
923
924static u64 uart0_dmamask = DMA_BIT_MASK(32);
925
926static struct platform_device at91sam9261_uart0_device = {
927 .name = "atmel_usart",
928 .id = 1,
929 .dev = {
930 .dma_mask = &uart0_dmamask,
931 .coherent_dma_mask = DMA_BIT_MASK(32),
932 .platform_data = &uart0_data,
933 },
934 .resource = uart0_resources,
935 .num_resources = ARRAY_SIZE(uart0_resources),
936};
937
938static inline void configure_usart0_pins(unsigned pins)
939{
940 at91_set_A_periph(AT91_PIN_PC8, 1); /* TXD0 */
941 at91_set_A_periph(AT91_PIN_PC9, 0); /* RXD0 */
942
943 if (pins & ATMEL_UART_RTS)
944 at91_set_A_periph(AT91_PIN_PC10, 0); /* RTS0 */
945 if (pins & ATMEL_UART_CTS)
946 at91_set_A_periph(AT91_PIN_PC11, 0); /* CTS0 */
947}
948
949static struct resource uart1_resources[] = {
950 [0] = {
951 .start = AT91SAM9261_BASE_US1,
952 .end = AT91SAM9261_BASE_US1 + SZ_16K - 1,
953 .flags = IORESOURCE_MEM,
954 },
955 [1] = {
956 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_US1,
957 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_US1,
958 .flags = IORESOURCE_IRQ,
959 },
960};
961
962static struct atmel_uart_data uart1_data = {
963 .use_dma_tx = 1,
964 .use_dma_rx = 1,
965};
966
967static u64 uart1_dmamask = DMA_BIT_MASK(32);
968
969static struct platform_device at91sam9261_uart1_device = {
970 .name = "atmel_usart",
971 .id = 2,
972 .dev = {
973 .dma_mask = &uart1_dmamask,
974 .coherent_dma_mask = DMA_BIT_MASK(32),
975 .platform_data = &uart1_data,
976 },
977 .resource = uart1_resources,
978 .num_resources = ARRAY_SIZE(uart1_resources),
979};
980
981static inline void configure_usart1_pins(unsigned pins)
982{
983 at91_set_A_periph(AT91_PIN_PC12, 1); /* TXD1 */
984 at91_set_A_periph(AT91_PIN_PC13, 0); /* RXD1 */
985
986 if (pins & ATMEL_UART_RTS)
987 at91_set_B_periph(AT91_PIN_PA12, 0); /* RTS1 */
988 if (pins & ATMEL_UART_CTS)
989 at91_set_B_periph(AT91_PIN_PA13, 0); /* CTS1 */
990}
991
992static struct resource uart2_resources[] = {
993 [0] = {
994 .start = AT91SAM9261_BASE_US2,
995 .end = AT91SAM9261_BASE_US2 + SZ_16K - 1,
996 .flags = IORESOURCE_MEM,
997 },
998 [1] = {
999 .start = NR_IRQS_LEGACY + AT91SAM9261_ID_US2,
1000 .end = NR_IRQS_LEGACY + AT91SAM9261_ID_US2,
1001 .flags = IORESOURCE_IRQ,
1002 },
1003};
1004
1005static struct atmel_uart_data uart2_data = {
1006 .use_dma_tx = 1,
1007 .use_dma_rx = 1,
1008};
1009
1010static u64 uart2_dmamask = DMA_BIT_MASK(32);
1011
1012static struct platform_device at91sam9261_uart2_device = {
1013 .name = "atmel_usart",
1014 .id = 3,
1015 .dev = {
1016 .dma_mask = &uart2_dmamask,
1017 .coherent_dma_mask = DMA_BIT_MASK(32),
1018 .platform_data = &uart2_data,
1019 },
1020 .resource = uart2_resources,
1021 .num_resources = ARRAY_SIZE(uart2_resources),
1022};
1023
1024static inline void configure_usart2_pins(unsigned pins)
1025{
1026 at91_set_A_periph(AT91_PIN_PC15, 0); /* RXD2 */
1027 at91_set_A_periph(AT91_PIN_PC14, 1); /* TXD2 */
1028
1029 if (pins & ATMEL_UART_RTS)
1030 at91_set_B_periph(AT91_PIN_PA15, 0); /* RTS2*/
1031 if (pins & ATMEL_UART_CTS)
1032 at91_set_B_periph(AT91_PIN_PA16, 0); /* CTS2 */
1033}
1034
1035static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
1036
1037void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1038{
1039 struct platform_device *pdev;
1040 struct atmel_uart_data *pdata;
1041
1042 switch (id) {
1043 case 0: /* DBGU */
1044 pdev = &at91sam9261_dbgu_device;
1045 configure_dbgu_pins();
1046 break;
1047 case AT91SAM9261_ID_US0:
1048 pdev = &at91sam9261_uart0_device;
1049 configure_usart0_pins(pins);
1050 break;
1051 case AT91SAM9261_ID_US1:
1052 pdev = &at91sam9261_uart1_device;
1053 configure_usart1_pins(pins);
1054 break;
1055 case AT91SAM9261_ID_US2:
1056 pdev = &at91sam9261_uart2_device;
1057 configure_usart2_pins(pins);
1058 break;
1059 default:
1060 return;
1061 }
1062 pdata = pdev->dev.platform_data;
1063 pdata->num = portnr; /* update to mapped ID */
1064
1065 if (portnr < ATMEL_MAX_UART)
1066 at91_uarts[portnr] = pdev;
1067}
1068
1069void __init at91_add_device_serial(void)
1070{
1071 int i;
1072
1073 for (i = 0; i < ATMEL_MAX_UART; i++) {
1074 if (at91_uarts[i])
1075 platform_device_register(at91_uarts[i]);
1076 }
1077}
1078#else
1079void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1080void __init at91_add_device_serial(void) {}
1081#endif
1082
1083
1084/* -------------------------------------------------------------------- */
1085
1086/*
1087 * These devices are always present and don't need any board-specific
1088 * setup.
1089 */
1090static int __init at91_add_standard_devices(void)
1091{
1092 at91_add_device_rtt();
1093 at91_add_device_watchdog();
1094 at91_add_device_tc();
1095 return 0;
1096}
1097
1098arch_initcall(at91_add_standard_devices);
diff --git a/arch/arm/mach-at91/at91sam9263.c b/arch/arm/mach-at91/at91sam9263.c
index fbff228cc63e..e7ad14864083 100644
--- a/arch/arm/mach-at91/at91sam9263.c
+++ b/arch/arm/mach-at91/at91sam9263.c
@@ -10,304 +10,11 @@
10 * 10 *
11 */ 11 */
12 12
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/clk/at91_pmc.h>
16
17#include <asm/proc-fns.h>
18#include <asm/irq.h>
19#include <asm/mach/arch.h>
20#include <asm/mach/map.h>
21#include <asm/system_misc.h> 13#include <asm/system_misc.h>
22#include <mach/at91sam9263.h>
23#include <mach/hardware.h> 14#include <mach/hardware.h>
24 15
25#include "at91_aic.h"
26#include "soc.h" 16#include "soc.h"
27#include "generic.h" 17#include "generic.h"
28#include "sam9_smc.h"
29#include "pm.h"
30
31#if defined(CONFIG_OLD_CLK_AT91)
32#include "clock.h"
33/* --------------------------------------------------------------------
34 * Clocks
35 * -------------------------------------------------------------------- */
36
37/*
38 * The peripheral clocks.
39 */
40static struct clk pioA_clk = {
41 .name = "pioA_clk",
42 .pmc_mask = 1 << AT91SAM9263_ID_PIOA,
43 .type = CLK_TYPE_PERIPHERAL,
44};
45static struct clk pioB_clk = {
46 .name = "pioB_clk",
47 .pmc_mask = 1 << AT91SAM9263_ID_PIOB,
48 .type = CLK_TYPE_PERIPHERAL,
49};
50static struct clk pioCDE_clk = {
51 .name = "pioCDE_clk",
52 .pmc_mask = 1 << AT91SAM9263_ID_PIOCDE,
53 .type = CLK_TYPE_PERIPHERAL,
54};
55static struct clk usart0_clk = {
56 .name = "usart0_clk",
57 .pmc_mask = 1 << AT91SAM9263_ID_US0,
58 .type = CLK_TYPE_PERIPHERAL,
59};
60static struct clk usart1_clk = {
61 .name = "usart1_clk",
62 .pmc_mask = 1 << AT91SAM9263_ID_US1,
63 .type = CLK_TYPE_PERIPHERAL,
64};
65static struct clk usart2_clk = {
66 .name = "usart2_clk",
67 .pmc_mask = 1 << AT91SAM9263_ID_US2,
68 .type = CLK_TYPE_PERIPHERAL,
69};
70static struct clk mmc0_clk = {
71 .name = "mci0_clk",
72 .pmc_mask = 1 << AT91SAM9263_ID_MCI0,
73 .type = CLK_TYPE_PERIPHERAL,
74};
75static struct clk mmc1_clk = {
76 .name = "mci1_clk",
77 .pmc_mask = 1 << AT91SAM9263_ID_MCI1,
78 .type = CLK_TYPE_PERIPHERAL,
79};
80static struct clk can_clk = {
81 .name = "can_clk",
82 .pmc_mask = 1 << AT91SAM9263_ID_CAN,
83 .type = CLK_TYPE_PERIPHERAL,
84};
85static struct clk twi_clk = {
86 .name = "twi_clk",
87 .pmc_mask = 1 << AT91SAM9263_ID_TWI,
88 .type = CLK_TYPE_PERIPHERAL,
89};
90static struct clk spi0_clk = {
91 .name = "spi0_clk",
92 .pmc_mask = 1 << AT91SAM9263_ID_SPI0,
93 .type = CLK_TYPE_PERIPHERAL,
94};
95static struct clk spi1_clk = {
96 .name = "spi1_clk",
97 .pmc_mask = 1 << AT91SAM9263_ID_SPI1,
98 .type = CLK_TYPE_PERIPHERAL,
99};
100static struct clk ssc0_clk = {
101 .name = "ssc0_clk",
102 .pmc_mask = 1 << AT91SAM9263_ID_SSC0,
103 .type = CLK_TYPE_PERIPHERAL,
104};
105static struct clk ssc1_clk = {
106 .name = "ssc1_clk",
107 .pmc_mask = 1 << AT91SAM9263_ID_SSC1,
108 .type = CLK_TYPE_PERIPHERAL,
109};
110static struct clk ac97_clk = {
111 .name = "ac97_clk",
112 .pmc_mask = 1 << AT91SAM9263_ID_AC97C,
113 .type = CLK_TYPE_PERIPHERAL,
114};
115static struct clk tcb_clk = {
116 .name = "tcb_clk",
117 .pmc_mask = 1 << AT91SAM9263_ID_TCB,
118 .type = CLK_TYPE_PERIPHERAL,
119};
120static struct clk pwm_clk = {
121 .name = "pwm_clk",
122 .pmc_mask = 1 << AT91SAM9263_ID_PWMC,
123 .type = CLK_TYPE_PERIPHERAL,
124};
125static struct clk macb_clk = {
126 .name = "pclk",
127 .pmc_mask = 1 << AT91SAM9263_ID_EMAC,
128 .type = CLK_TYPE_PERIPHERAL,
129};
130static struct clk dma_clk = {
131 .name = "dma_clk",
132 .pmc_mask = 1 << AT91SAM9263_ID_DMA,
133 .type = CLK_TYPE_PERIPHERAL,
134};
135static struct clk twodge_clk = {
136 .name = "2dge_clk",
137 .pmc_mask = 1 << AT91SAM9263_ID_2DGE,
138 .type = CLK_TYPE_PERIPHERAL,
139};
140static struct clk udc_clk = {
141 .name = "udc_clk",
142 .pmc_mask = 1 << AT91SAM9263_ID_UDP,
143 .type = CLK_TYPE_PERIPHERAL,
144};
145static struct clk isi_clk = {
146 .name = "isi_clk",
147 .pmc_mask = 1 << AT91SAM9263_ID_ISI,
148 .type = CLK_TYPE_PERIPHERAL,
149};
150static struct clk lcdc_clk = {
151 .name = "lcdc_clk",
152 .pmc_mask = 1 << AT91SAM9263_ID_LCDC,
153 .type = CLK_TYPE_PERIPHERAL,
154};
155static struct clk ohci_clk = {
156 .name = "ohci_clk",
157 .pmc_mask = 1 << AT91SAM9263_ID_UHP,
158 .type = CLK_TYPE_PERIPHERAL,
159};
160
161static struct clk *periph_clocks[] __initdata = {
162 &pioA_clk,
163 &pioB_clk,
164 &pioCDE_clk,
165 &usart0_clk,
166 &usart1_clk,
167 &usart2_clk,
168 &mmc0_clk,
169 &mmc1_clk,
170 &can_clk,
171 &twi_clk,
172 &spi0_clk,
173 &spi1_clk,
174 &ssc0_clk,
175 &ssc1_clk,
176 &ac97_clk,
177 &tcb_clk,
178 &pwm_clk,
179 &macb_clk,
180 &twodge_clk,
181 &udc_clk,
182 &isi_clk,
183 &lcdc_clk,
184 &dma_clk,
185 &ohci_clk,
186 // irq0 .. irq1
187};
188
189static struct clk_lookup periph_clocks_lookups[] = {
190 /* One additional fake clock for macb_hclk */
191 CLKDEV_CON_ID("hclk", &macb_clk),
192 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.0", &ssc0_clk),
193 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.1", &ssc1_clk),
194 CLKDEV_CON_DEV_ID("pclk", "fff98000.ssc", &ssc0_clk),
195 CLKDEV_CON_DEV_ID("pclk", "fff9c000.ssc", &ssc1_clk),
196 CLKDEV_CON_DEV_ID("hclk", "at91sam9263-lcdfb.0", &lcdc_clk),
197 CLKDEV_CON_DEV_ID("mci_clk", "atmel_mci.0", &mmc0_clk),
198 CLKDEV_CON_DEV_ID("mci_clk", "atmel_mci.1", &mmc1_clk),
199 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
200 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
201 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb_clk),
202 CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9260.0", &twi_clk),
203 CLKDEV_CON_DEV_ID(NULL, "at91sam9rl-pwm", &pwm_clk),
204 /* fake hclk clock */
205 CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &ohci_clk),
206 CLKDEV_CON_ID("pioA", &pioA_clk),
207 CLKDEV_CON_ID("pioB", &pioB_clk),
208 CLKDEV_CON_ID("pioC", &pioCDE_clk),
209 CLKDEV_CON_ID("pioD", &pioCDE_clk),
210 CLKDEV_CON_ID("pioE", &pioCDE_clk),
211 /* more usart lookup table for DT entries */
212 CLKDEV_CON_DEV_ID("usart", "ffffee00.serial", &mck),
213 CLKDEV_CON_DEV_ID("usart", "fff8c000.serial", &usart0_clk),
214 CLKDEV_CON_DEV_ID("usart", "fff90000.serial", &usart1_clk),
215 CLKDEV_CON_DEV_ID("usart", "fff94000.serial", &usart2_clk),
216 /* more tc lookup table for DT entries */
217 CLKDEV_CON_DEV_ID("t0_clk", "fff7c000.timer", &tcb_clk),
218 CLKDEV_CON_DEV_ID("hclk", "a00000.ohci", &ohci_clk),
219 CLKDEV_CON_DEV_ID("spi_clk", "fffa4000.spi", &spi0_clk),
220 CLKDEV_CON_DEV_ID("spi_clk", "fffa8000.spi", &spi1_clk),
221 CLKDEV_CON_DEV_ID("mci_clk", "fff80000.mmc", &mmc0_clk),
222 CLKDEV_CON_DEV_ID("mci_clk", "fff84000.mmc", &mmc1_clk),
223 CLKDEV_CON_DEV_ID(NULL, "fff88000.i2c", &twi_clk),
224 CLKDEV_CON_DEV_ID(NULL, "fffff200.gpio", &pioA_clk),
225 CLKDEV_CON_DEV_ID(NULL, "fffff400.gpio", &pioB_clk),
226 CLKDEV_CON_DEV_ID(NULL, "fffff600.gpio", &pioCDE_clk),
227 CLKDEV_CON_DEV_ID(NULL, "fffff800.gpio", &pioCDE_clk),
228 CLKDEV_CON_DEV_ID(NULL, "fffffa00.gpio", &pioCDE_clk),
229 CLKDEV_CON_DEV_ID(NULL, "fffb8000.pwm", &pwm_clk),
230};
231
232static struct clk_lookup usart_clocks_lookups[] = {
233 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
234 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
235 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
236 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
237};
238
239/*
240 * The four programmable clocks.
241 * You must configure pin multiplexing to bring these signals out.
242 */
243static struct clk pck0 = {
244 .name = "pck0",
245 .pmc_mask = AT91_PMC_PCK0,
246 .type = CLK_TYPE_PROGRAMMABLE,
247 .id = 0,
248};
249static struct clk pck1 = {
250 .name = "pck1",
251 .pmc_mask = AT91_PMC_PCK1,
252 .type = CLK_TYPE_PROGRAMMABLE,
253 .id = 1,
254};
255static struct clk pck2 = {
256 .name = "pck2",
257 .pmc_mask = AT91_PMC_PCK2,
258 .type = CLK_TYPE_PROGRAMMABLE,
259 .id = 2,
260};
261static struct clk pck3 = {
262 .name = "pck3",
263 .pmc_mask = AT91_PMC_PCK3,
264 .type = CLK_TYPE_PROGRAMMABLE,
265 .id = 3,
266};
267
268static void __init at91sam9263_register_clocks(void)
269{
270 int i;
271
272 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
273 clk_register(periph_clocks[i]);
274
275 clkdev_add_table(periph_clocks_lookups,
276 ARRAY_SIZE(periph_clocks_lookups));
277 clkdev_add_table(usart_clocks_lookups,
278 ARRAY_SIZE(usart_clocks_lookups));
279
280 clk_register(&pck0);
281 clk_register(&pck1);
282 clk_register(&pck2);
283 clk_register(&pck3);
284}
285#else
286#define at91sam9263_register_clocks NULL
287#endif
288
289/* --------------------------------------------------------------------
290 * GPIO
291 * -------------------------------------------------------------------- */
292
293static struct at91_gpio_bank at91sam9263_gpio[] __initdata = {
294 {
295 .id = AT91SAM9263_ID_PIOA,
296 .regbase = AT91SAM9263_BASE_PIOA,
297 }, {
298 .id = AT91SAM9263_ID_PIOB,
299 .regbase = AT91SAM9263_BASE_PIOB,
300 }, {
301 .id = AT91SAM9263_ID_PIOCDE,
302 .regbase = AT91SAM9263_BASE_PIOC,
303 }, {
304 .id = AT91SAM9263_ID_PIOCDE,
305 .regbase = AT91SAM9263_BASE_PIOD,
306 }, {
307 .id = AT91SAM9263_ID_PIOCDE,
308 .regbase = AT91SAM9263_BASE_PIOE,
309 }
310};
311 18
312/* -------------------------------------------------------------------- 19/* --------------------------------------------------------------------
313 * AT91SAM9263 processor initialization 20 * AT91SAM9263 processor initialization
@@ -319,121 +26,15 @@ static void __init at91sam9263_map_io(void)
319 at91_init_sram(1, AT91SAM9263_SRAM1_BASE, AT91SAM9263_SRAM1_SIZE); 26 at91_init_sram(1, AT91SAM9263_SRAM1_BASE, AT91SAM9263_SRAM1_SIZE);
320} 27}
321 28
322static void __init at91sam9263_ioremap_registers(void)
323{
324 at91_ioremap_ramc(0, AT91SAM9263_BASE_SDRAMC0, 512);
325 at91_ioremap_ramc(1, AT91SAM9263_BASE_SDRAMC1, 512);
326 at91sam926x_ioremap_pit(AT91SAM9263_BASE_PIT);
327 at91sam9_ioremap_smc(0, AT91SAM9263_BASE_SMC0);
328 at91sam9_ioremap_smc(1, AT91SAM9263_BASE_SMC1);
329 at91_ioremap_matrix(AT91SAM9263_BASE_MATRIX);
330 at91_pm_set_standby(at91sam9_sdram_standby);
331}
332
333static void __init at91sam9263_initialize(void) 29static void __init at91sam9263_initialize(void)
334{ 30{
335 arm_pm_idle = at91sam9_idle; 31 arm_pm_idle = at91sam9_idle;
336 32
337 at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT0); 33 at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT0);
338 at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT1); 34 at91_sysirq_mask_rtt(AT91SAM9263_BASE_RTT1);
339
340 /* Register GPIO subsystem */
341 at91_gpio_init(at91sam9263_gpio, 5);
342}
343
344static struct resource rstc_resources[] = {
345 [0] = {
346 .start = AT91SAM9263_BASE_RSTC,
347 .end = AT91SAM9263_BASE_RSTC + SZ_16 - 1,
348 .flags = IORESOURCE_MEM,
349 },
350 [1] = {
351 .start = AT91SAM9263_BASE_SDRAMC0,
352 .end = AT91SAM9263_BASE_SDRAMC0 + SZ_512 - 1,
353 .flags = IORESOURCE_MEM,
354 },
355};
356
357static struct platform_device rstc_device = {
358 .name = "at91-sam9260-reset",
359 .resource = rstc_resources,
360 .num_resources = ARRAY_SIZE(rstc_resources),
361};
362
363static struct resource shdwc_resources[] = {
364 [0] = {
365 .start = AT91SAM9263_BASE_SHDWC,
366 .end = AT91SAM9263_BASE_SHDWC + SZ_16 - 1,
367 .flags = IORESOURCE_MEM,
368 },
369};
370
371static struct platform_device shdwc_device = {
372 .name = "at91-poweroff",
373 .resource = shdwc_resources,
374 .num_resources = ARRAY_SIZE(shdwc_resources),
375};
376
377static void __init at91sam9263_register_devices(void)
378{
379 platform_device_register(&rstc_device);
380 platform_device_register(&shdwc_device);
381}
382
383/* --------------------------------------------------------------------
384 * Interrupt initialization
385 * -------------------------------------------------------------------- */
386
387/*
388 * The default interrupt priority levels (0 = lowest, 7 = highest).
389 */
390static unsigned int at91sam9263_default_irq_priority[NR_AIC_IRQS] __initdata = {
391 7, /* Advanced Interrupt Controller (FIQ) */
392 7, /* System Peripherals */
393 1, /* Parallel IO Controller A */
394 1, /* Parallel IO Controller B */
395 1, /* Parallel IO Controller C, D and E */
396 0,
397 0,
398 5, /* USART 0 */
399 5, /* USART 1 */
400 5, /* USART 2 */
401 0, /* Multimedia Card Interface 0 */
402 0, /* Multimedia Card Interface 1 */
403 3, /* CAN */
404 6, /* Two-Wire Interface */
405 5, /* Serial Peripheral Interface 0 */
406 5, /* Serial Peripheral Interface 1 */
407 4, /* Serial Synchronous Controller 0 */
408 4, /* Serial Synchronous Controller 1 */
409 5, /* AC97 Controller */
410 0, /* Timer Counter 0, 1 and 2 */
411 0, /* Pulse Width Modulation Controller */
412 3, /* Ethernet */
413 0,
414 0, /* 2D Graphic Engine */
415 2, /* USB Device Port */
416 0, /* Image Sensor Interface */
417 3, /* LDC Controller */
418 0, /* DMA Controller */
419 0,
420 2, /* USB Host port */
421 0, /* Advanced Interrupt Controller (IRQ0) */
422 0, /* Advanced Interrupt Controller (IRQ1) */
423};
424
425static void __init at91sam9263_init_time(void)
426{
427 at91sam926x_pit_init(NR_IRQS_LEGACY + AT91_ID_SYS);
428} 35}
429 36
430AT91_SOC_START(at91sam9263) 37AT91_SOC_START(at91sam9263)
431 .map_io = at91sam9263_map_io, 38 .map_io = at91sam9263_map_io,
432 .default_irq_priority = at91sam9263_default_irq_priority,
433 .extern_irq = (1 << AT91SAM9263_ID_IRQ0) | (1 << AT91SAM9263_ID_IRQ1),
434 .ioremap_registers = at91sam9263_ioremap_registers,
435 .register_clocks = at91sam9263_register_clocks,
436 .register_devices = at91sam9263_register_devices,
437 .init = at91sam9263_initialize, 39 .init = at91sam9263_initialize,
438 .init_time = at91sam9263_init_time,
439AT91_SOC_END 40AT91_SOC_END
diff --git a/arch/arm/mach-at91/at91sam9263_devices.c b/arch/arm/mach-at91/at91sam9263_devices.c
deleted file mode 100644
index cef0e2f57068..000000000000
--- a/arch/arm/mach-at91/at91sam9263_devices.c
+++ /dev/null
@@ -1,1538 +0,0 @@
1/*
2 * arch/arm/mach-at91/at91sam9263_devices.c
3 *
4 * Copyright (C) 2007 Atmel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12#include <asm/mach/arch.h>
13#include <asm/mach/map.h>
14
15#include <linux/dma-mapping.h>
16#include <linux/gpio.h>
17#include <linux/platform_device.h>
18#include <linux/i2c-gpio.h>
19
20#include <linux/fb.h>
21#include <video/atmel_lcdc.h>
22
23#include <mach/at91sam9263.h>
24#include <mach/at91sam9263_matrix.h>
25#include <mach/at91_matrix.h>
26#include <mach/at91sam9_smc.h>
27#include <mach/hardware.h>
28
29#include "board.h"
30#include "generic.h"
31#include "gpio.h"
32
33
34/* --------------------------------------------------------------------
35 * USB Host
36 * -------------------------------------------------------------------- */
37
38#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
39static u64 ohci_dmamask = DMA_BIT_MASK(32);
40static struct at91_usbh_data usbh_data;
41
42static struct resource usbh_resources[] = {
43 [0] = {
44 .start = AT91SAM9263_UHP_BASE,
45 .end = AT91SAM9263_UHP_BASE + SZ_1M - 1,
46 .flags = IORESOURCE_MEM,
47 },
48 [1] = {
49 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_UHP,
50 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_UHP,
51 .flags = IORESOURCE_IRQ,
52 },
53};
54
55static struct platform_device at91_usbh_device = {
56 .name = "at91_ohci",
57 .id = -1,
58 .dev = {
59 .dma_mask = &ohci_dmamask,
60 .coherent_dma_mask = DMA_BIT_MASK(32),
61 .platform_data = &usbh_data,
62 },
63 .resource = usbh_resources,
64 .num_resources = ARRAY_SIZE(usbh_resources),
65};
66
67void __init at91_add_device_usbh(struct at91_usbh_data *data)
68{
69 int i;
70
71 if (!data)
72 return;
73
74 /* Enable VBus control for UHP ports */
75 for (i = 0; i < data->ports; i++) {
76 if (gpio_is_valid(data->vbus_pin[i]))
77 at91_set_gpio_output(data->vbus_pin[i],
78 data->vbus_pin_active_low[i]);
79 }
80
81 /* Enable overcurrent notification */
82 for (i = 0; i < data->ports; i++) {
83 if (gpio_is_valid(data->overcurrent_pin[i]))
84 at91_set_gpio_input(data->overcurrent_pin[i], 1);
85 }
86
87 usbh_data = *data;
88 platform_device_register(&at91_usbh_device);
89}
90#else
91void __init at91_add_device_usbh(struct at91_usbh_data *data) {}
92#endif
93
94
95/* --------------------------------------------------------------------
96 * USB Device (Gadget)
97 * -------------------------------------------------------------------- */
98
99#if defined(CONFIG_USB_AT91) || defined(CONFIG_USB_AT91_MODULE)
100static struct at91_udc_data udc_data;
101
102static struct resource udc_resources[] = {
103 [0] = {
104 .start = AT91SAM9263_BASE_UDP,
105 .end = AT91SAM9263_BASE_UDP + SZ_16K - 1,
106 .flags = IORESOURCE_MEM,
107 },
108 [1] = {
109 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_UDP,
110 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_UDP,
111 .flags = IORESOURCE_IRQ,
112 },
113};
114
115static struct platform_device at91_udc_device = {
116 .name = "at91_udc",
117 .id = -1,
118 .dev = {
119 .platform_data = &udc_data,
120 },
121 .resource = udc_resources,
122 .num_resources = ARRAY_SIZE(udc_resources),
123};
124
125void __init at91_add_device_udc(struct at91_udc_data *data)
126{
127 if (!data)
128 return;
129
130 if (gpio_is_valid(data->vbus_pin)) {
131 at91_set_gpio_input(data->vbus_pin, 0);
132 at91_set_deglitch(data->vbus_pin, 1);
133 }
134
135 /* Pullup pin is handled internally by USB device peripheral */
136
137 udc_data = *data;
138 platform_device_register(&at91_udc_device);
139}
140#else
141void __init at91_add_device_udc(struct at91_udc_data *data) {}
142#endif
143
144
145/* --------------------------------------------------------------------
146 * Ethernet
147 * -------------------------------------------------------------------- */
148
149#if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
150static u64 eth_dmamask = DMA_BIT_MASK(32);
151static struct macb_platform_data eth_data;
152
153static struct resource eth_resources[] = {
154 [0] = {
155 .start = AT91SAM9263_BASE_EMAC,
156 .end = AT91SAM9263_BASE_EMAC + SZ_16K - 1,
157 .flags = IORESOURCE_MEM,
158 },
159 [1] = {
160 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_EMAC,
161 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_EMAC,
162 .flags = IORESOURCE_IRQ,
163 },
164};
165
166static struct platform_device at91sam9263_eth_device = {
167 .name = "macb",
168 .id = -1,
169 .dev = {
170 .dma_mask = &eth_dmamask,
171 .coherent_dma_mask = DMA_BIT_MASK(32),
172 .platform_data = &eth_data,
173 },
174 .resource = eth_resources,
175 .num_resources = ARRAY_SIZE(eth_resources),
176};
177
178void __init at91_add_device_eth(struct macb_platform_data *data)
179{
180 if (!data)
181 return;
182
183 if (gpio_is_valid(data->phy_irq_pin)) {
184 at91_set_gpio_input(data->phy_irq_pin, 0);
185 at91_set_deglitch(data->phy_irq_pin, 1);
186 }
187
188 /* Pins used for MII and RMII */
189 at91_set_A_periph(AT91_PIN_PE21, 0); /* ETXCK_EREFCK */
190 at91_set_B_periph(AT91_PIN_PC25, 0); /* ERXDV */
191 at91_set_A_periph(AT91_PIN_PE25, 0); /* ERX0 */
192 at91_set_A_periph(AT91_PIN_PE26, 0); /* ERX1 */
193 at91_set_A_periph(AT91_PIN_PE27, 0); /* ERXER */
194 at91_set_A_periph(AT91_PIN_PE28, 0); /* ETXEN */
195 at91_set_A_periph(AT91_PIN_PE23, 0); /* ETX0 */
196 at91_set_A_periph(AT91_PIN_PE24, 0); /* ETX1 */
197 at91_set_A_periph(AT91_PIN_PE30, 0); /* EMDIO */
198 at91_set_A_periph(AT91_PIN_PE29, 0); /* EMDC */
199
200 if (!data->is_rmii) {
201 at91_set_A_periph(AT91_PIN_PE22, 0); /* ECRS */
202 at91_set_B_periph(AT91_PIN_PC26, 0); /* ECOL */
203 at91_set_B_periph(AT91_PIN_PC22, 0); /* ERX2 */
204 at91_set_B_periph(AT91_PIN_PC23, 0); /* ERX3 */
205 at91_set_B_periph(AT91_PIN_PC27, 0); /* ERXCK */
206 at91_set_B_periph(AT91_PIN_PC20, 0); /* ETX2 */
207 at91_set_B_periph(AT91_PIN_PC21, 0); /* ETX3 */
208 at91_set_B_periph(AT91_PIN_PC24, 0); /* ETXER */
209 }
210
211 eth_data = *data;
212 platform_device_register(&at91sam9263_eth_device);
213}
214#else
215void __init at91_add_device_eth(struct macb_platform_data *data) {}
216#endif
217
218
219/* --------------------------------------------------------------------
220 * MMC / SD
221 * -------------------------------------------------------------------- */
222
223#if IS_ENABLED(CONFIG_MMC_ATMELMCI)
224static u64 mmc_dmamask = DMA_BIT_MASK(32);
225static struct mci_platform_data mmc0_data, mmc1_data;
226
227static struct resource mmc0_resources[] = {
228 [0] = {
229 .start = AT91SAM9263_BASE_MCI0,
230 .end = AT91SAM9263_BASE_MCI0 + SZ_16K - 1,
231 .flags = IORESOURCE_MEM,
232 },
233 [1] = {
234 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_MCI0,
235 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_MCI0,
236 .flags = IORESOURCE_IRQ,
237 },
238};
239
240static struct platform_device at91sam9263_mmc0_device = {
241 .name = "atmel_mci",
242 .id = 0,
243 .dev = {
244 .dma_mask = &mmc_dmamask,
245 .coherent_dma_mask = DMA_BIT_MASK(32),
246 .platform_data = &mmc0_data,
247 },
248 .resource = mmc0_resources,
249 .num_resources = ARRAY_SIZE(mmc0_resources),
250};
251
252static struct resource mmc1_resources[] = {
253 [0] = {
254 .start = AT91SAM9263_BASE_MCI1,
255 .end = AT91SAM9263_BASE_MCI1 + SZ_16K - 1,
256 .flags = IORESOURCE_MEM,
257 },
258 [1] = {
259 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_MCI1,
260 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_MCI1,
261 .flags = IORESOURCE_IRQ,
262 },
263};
264
265static struct platform_device at91sam9263_mmc1_device = {
266 .name = "atmel_mci",
267 .id = 1,
268 .dev = {
269 .dma_mask = &mmc_dmamask,
270 .coherent_dma_mask = DMA_BIT_MASK(32),
271 .platform_data = &mmc1_data,
272 },
273 .resource = mmc1_resources,
274 .num_resources = ARRAY_SIZE(mmc1_resources),
275};
276
277void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
278{
279 unsigned int i;
280 unsigned int slot_count = 0;
281
282 if (!data)
283 return;
284
285 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
286
287 if (!data->slot[i].bus_width)
288 continue;
289
290 /* input/irq */
291 if (gpio_is_valid(data->slot[i].detect_pin)) {
292 at91_set_gpio_input(data->slot[i].detect_pin,
293 1);
294 at91_set_deglitch(data->slot[i].detect_pin,
295 1);
296 }
297 if (gpio_is_valid(data->slot[i].wp_pin))
298 at91_set_gpio_input(data->slot[i].wp_pin, 1);
299
300 if (mmc_id == 0) { /* MCI0 */
301 switch (i) {
302 case 0: /* slot A */
303 /* CMD */
304 at91_set_A_periph(AT91_PIN_PA1, 1);
305 /* DAT0, maybe DAT1..DAT3 */
306 at91_set_A_periph(AT91_PIN_PA0, 1);
307 if (data->slot[i].bus_width == 4) {
308 at91_set_A_periph(AT91_PIN_PA3, 1);
309 at91_set_A_periph(AT91_PIN_PA4, 1);
310 at91_set_A_periph(AT91_PIN_PA5, 1);
311 }
312 slot_count++;
313 break;
314 case 1: /* slot B */
315 /* CMD */
316 at91_set_A_periph(AT91_PIN_PA16, 1);
317 /* DAT0, maybe DAT1..DAT3 */
318 at91_set_A_periph(AT91_PIN_PA17, 1);
319 if (data->slot[i].bus_width == 4) {
320 at91_set_A_periph(AT91_PIN_PA18, 1);
321 at91_set_A_periph(AT91_PIN_PA19, 1);
322 at91_set_A_periph(AT91_PIN_PA20, 1);
323 }
324 slot_count++;
325 break;
326 default:
327 printk(KERN_ERR
328 "AT91: SD/MMC slot %d not available\n", i);
329 break;
330 }
331 if (slot_count) {
332 /* CLK */
333 at91_set_A_periph(AT91_PIN_PA12, 0);
334
335 mmc0_data = *data;
336 platform_device_register(&at91sam9263_mmc0_device);
337 }
338 } else if (mmc_id == 1) { /* MCI1 */
339 switch (i) {
340 case 0: /* slot A */
341 /* CMD */
342 at91_set_A_periph(AT91_PIN_PA7, 1);
343 /* DAT0, maybe DAT1..DAT3 */
344 at91_set_A_periph(AT91_PIN_PA8, 1);
345 if (data->slot[i].bus_width == 4) {
346 at91_set_A_periph(AT91_PIN_PA9, 1);
347 at91_set_A_periph(AT91_PIN_PA10, 1);
348 at91_set_A_periph(AT91_PIN_PA11, 1);
349 }
350 slot_count++;
351 break;
352 case 1: /* slot B */
353 /* CMD */
354 at91_set_A_periph(AT91_PIN_PA21, 1);
355 /* DAT0, maybe DAT1..DAT3 */
356 at91_set_A_periph(AT91_PIN_PA22, 1);
357 if (data->slot[i].bus_width == 4) {
358 at91_set_A_periph(AT91_PIN_PA23, 1);
359 at91_set_A_periph(AT91_PIN_PA24, 1);
360 at91_set_A_periph(AT91_PIN_PA25, 1);
361 }
362 slot_count++;
363 break;
364 default:
365 printk(KERN_ERR
366 "AT91: SD/MMC slot %d not available\n", i);
367 break;
368 }
369 if (slot_count) {
370 /* CLK */
371 at91_set_A_periph(AT91_PIN_PA6, 0);
372
373 mmc1_data = *data;
374 platform_device_register(&at91sam9263_mmc1_device);
375 }
376 }
377 }
378}
379#else
380void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
381#endif
382
383/* --------------------------------------------------------------------
384 * Compact Flash (PCMCIA or IDE)
385 * -------------------------------------------------------------------- */
386
387#if defined(CONFIG_PATA_AT91) || defined(CONFIG_PATA_AT91_MODULE) || \
388 defined(CONFIG_AT91_CF) || defined(CONFIG_AT91_CF_MODULE)
389
390static struct at91_cf_data cf0_data;
391
392static struct resource cf0_resources[] = {
393 [0] = {
394 .start = AT91_CHIPSELECT_4,
395 .end = AT91_CHIPSELECT_4 + SZ_256M - 1,
396 .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
397 }
398};
399
400static struct platform_device cf0_device = {
401 .id = 0,
402 .dev = {
403 .platform_data = &cf0_data,
404 },
405 .resource = cf0_resources,
406 .num_resources = ARRAY_SIZE(cf0_resources),
407};
408
409static struct at91_cf_data cf1_data;
410
411static struct resource cf1_resources[] = {
412 [0] = {
413 .start = AT91_CHIPSELECT_5,
414 .end = AT91_CHIPSELECT_5 + SZ_256M - 1,
415 .flags = IORESOURCE_MEM | IORESOURCE_MEM_8AND16BIT,
416 }
417};
418
419static struct platform_device cf1_device = {
420 .id = 1,
421 .dev = {
422 .platform_data = &cf1_data,
423 },
424 .resource = cf1_resources,
425 .num_resources = ARRAY_SIZE(cf1_resources),
426};
427
428void __init at91_add_device_cf(struct at91_cf_data *data)
429{
430 unsigned long ebi0_csa;
431 struct platform_device *pdev;
432
433 if (!data)
434 return;
435
436 /*
437 * assign CS4 or CS5 to SMC with Compact Flash logic support,
438 * we assume SMC timings are configured by board code,
439 * except True IDE where timings are controlled by driver
440 */
441 ebi0_csa = at91_matrix_read(AT91_MATRIX_EBI0CSA);
442 switch (data->chipselect) {
443 case 4:
444 at91_set_A_periph(AT91_PIN_PD6, 0); /* EBI0_NCS4/CFCS0 */
445 ebi0_csa |= AT91_MATRIX_EBI0_CS4A_SMC_CF1;
446 cf0_data = *data;
447 pdev = &cf0_device;
448 break;
449 case 5:
450 at91_set_A_periph(AT91_PIN_PD7, 0); /* EBI0_NCS5/CFCS1 */
451 ebi0_csa |= AT91_MATRIX_EBI0_CS5A_SMC_CF2;
452 cf1_data = *data;
453 pdev = &cf1_device;
454 break;
455 default:
456 printk(KERN_ERR "AT91 CF: bad chip-select requested (%u)\n",
457 data->chipselect);
458 return;
459 }
460 at91_matrix_write(AT91_MATRIX_EBI0CSA, ebi0_csa);
461
462 if (gpio_is_valid(data->det_pin)) {
463 at91_set_gpio_input(data->det_pin, 1);
464 at91_set_deglitch(data->det_pin, 1);
465 }
466
467 if (gpio_is_valid(data->irq_pin)) {
468 at91_set_gpio_input(data->irq_pin, 1);
469 at91_set_deglitch(data->irq_pin, 1);
470 }
471
472 if (gpio_is_valid(data->vcc_pin))
473 /* initially off */
474 at91_set_gpio_output(data->vcc_pin, 0);
475
476 /* enable EBI controlled pins */
477 at91_set_A_periph(AT91_PIN_PD5, 1); /* NWAIT */
478 at91_set_A_periph(AT91_PIN_PD8, 0); /* CFCE1 */
479 at91_set_A_periph(AT91_PIN_PD9, 0); /* CFCE2 */
480 at91_set_A_periph(AT91_PIN_PD14, 0); /* CFNRW */
481
482 pdev->name = (data->flags & AT91_CF_TRUE_IDE) ? "pata_at91" : "at91_cf";
483 platform_device_register(pdev);
484}
485#else
486void __init at91_add_device_cf(struct at91_cf_data *data) {}
487#endif
488
489/* --------------------------------------------------------------------
490 * NAND / SmartMedia
491 * -------------------------------------------------------------------- */
492
493#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
494static struct atmel_nand_data nand_data;
495
496#define NAND_BASE AT91_CHIPSELECT_3
497
498static struct resource nand_resources[] = {
499 [0] = {
500 .start = NAND_BASE,
501 .end = NAND_BASE + SZ_256M - 1,
502 .flags = IORESOURCE_MEM,
503 },
504 [1] = {
505 .start = AT91SAM9263_BASE_ECC0,
506 .end = AT91SAM9263_BASE_ECC0 + SZ_512 - 1,
507 .flags = IORESOURCE_MEM,
508 }
509};
510
511static struct platform_device at91sam9263_nand_device = {
512 .name = "atmel_nand",
513 .id = -1,
514 .dev = {
515 .platform_data = &nand_data,
516 },
517 .resource = nand_resources,
518 .num_resources = ARRAY_SIZE(nand_resources),
519};
520
521void __init at91_add_device_nand(struct atmel_nand_data *data)
522{
523 unsigned long csa;
524
525 if (!data)
526 return;
527
528 csa = at91_matrix_read(AT91_MATRIX_EBI0CSA);
529 at91_matrix_write(AT91_MATRIX_EBI0CSA, csa | AT91_MATRIX_EBI0_CS3A_SMC_SMARTMEDIA);
530
531 /* enable pin */
532 if (gpio_is_valid(data->enable_pin))
533 at91_set_gpio_output(data->enable_pin, 1);
534
535 /* ready/busy pin */
536 if (gpio_is_valid(data->rdy_pin))
537 at91_set_gpio_input(data->rdy_pin, 1);
538
539 /* card detect pin */
540 if (gpio_is_valid(data->det_pin))
541 at91_set_gpio_input(data->det_pin, 1);
542
543 nand_data = *data;
544 platform_device_register(&at91sam9263_nand_device);
545}
546#else
547void __init at91_add_device_nand(struct atmel_nand_data *data) {}
548#endif
549
550
551/* --------------------------------------------------------------------
552 * TWI (i2c)
553 * -------------------------------------------------------------------- */
554
555/*
556 * Prefer the GPIO code since the TWI controller isn't robust
557 * (gets overruns and underruns under load) and can only issue
558 * repeated STARTs in one scenario (the driver doesn't yet handle them).
559 */
560#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
561
562static struct i2c_gpio_platform_data pdata = {
563 .sda_pin = AT91_PIN_PB4,
564 .sda_is_open_drain = 1,
565 .scl_pin = AT91_PIN_PB5,
566 .scl_is_open_drain = 1,
567 .udelay = 2, /* ~100 kHz */
568};
569
570static struct platform_device at91sam9263_twi_device = {
571 .name = "i2c-gpio",
572 .id = 0,
573 .dev.platform_data = &pdata,
574};
575
576void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
577{
578 at91_set_GPIO_periph(AT91_PIN_PB4, 1); /* TWD (SDA) */
579 at91_set_multi_drive(AT91_PIN_PB4, 1);
580
581 at91_set_GPIO_periph(AT91_PIN_PB5, 1); /* TWCK (SCL) */
582 at91_set_multi_drive(AT91_PIN_PB5, 1);
583
584 i2c_register_board_info(0, devices, nr_devices);
585 platform_device_register(&at91sam9263_twi_device);
586}
587
588#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
589
590static struct resource twi_resources[] = {
591 [0] = {
592 .start = AT91SAM9263_BASE_TWI,
593 .end = AT91SAM9263_BASE_TWI + SZ_16K - 1,
594 .flags = IORESOURCE_MEM,
595 },
596 [1] = {
597 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_TWI,
598 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_TWI,
599 .flags = IORESOURCE_IRQ,
600 },
601};
602
603static struct platform_device at91sam9263_twi_device = {
604 .name = "i2c-at91sam9260",
605 .id = 0,
606 .resource = twi_resources,
607 .num_resources = ARRAY_SIZE(twi_resources),
608};
609
610void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
611{
612 /* pins used for TWI interface */
613 at91_set_A_periph(AT91_PIN_PB4, 0); /* TWD */
614 at91_set_multi_drive(AT91_PIN_PB4, 1);
615
616 at91_set_A_periph(AT91_PIN_PB5, 0); /* TWCK */
617 at91_set_multi_drive(AT91_PIN_PB5, 1);
618
619 i2c_register_board_info(0, devices, nr_devices);
620 platform_device_register(&at91sam9263_twi_device);
621}
622#else
623void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
624#endif
625
626
627/* --------------------------------------------------------------------
628 * SPI
629 * -------------------------------------------------------------------- */
630
631#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
632static u64 spi_dmamask = DMA_BIT_MASK(32);
633
634static struct resource spi0_resources[] = {
635 [0] = {
636 .start = AT91SAM9263_BASE_SPI0,
637 .end = AT91SAM9263_BASE_SPI0 + SZ_16K - 1,
638 .flags = IORESOURCE_MEM,
639 },
640 [1] = {
641 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_SPI0,
642 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_SPI0,
643 .flags = IORESOURCE_IRQ,
644 },
645};
646
647static struct platform_device at91sam9263_spi0_device = {
648 .name = "atmel_spi",
649 .id = 0,
650 .dev = {
651 .dma_mask = &spi_dmamask,
652 .coherent_dma_mask = DMA_BIT_MASK(32),
653 },
654 .resource = spi0_resources,
655 .num_resources = ARRAY_SIZE(spi0_resources),
656};
657
658static const unsigned spi0_standard_cs[4] = { AT91_PIN_PA5, AT91_PIN_PA3, AT91_PIN_PA4, AT91_PIN_PB11 };
659
660static struct resource spi1_resources[] = {
661 [0] = {
662 .start = AT91SAM9263_BASE_SPI1,
663 .end = AT91SAM9263_BASE_SPI1 + SZ_16K - 1,
664 .flags = IORESOURCE_MEM,
665 },
666 [1] = {
667 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_SPI1,
668 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_SPI1,
669 .flags = IORESOURCE_IRQ,
670 },
671};
672
673static struct platform_device at91sam9263_spi1_device = {
674 .name = "atmel_spi",
675 .id = 1,
676 .dev = {
677 .dma_mask = &spi_dmamask,
678 .coherent_dma_mask = DMA_BIT_MASK(32),
679 },
680 .resource = spi1_resources,
681 .num_resources = ARRAY_SIZE(spi1_resources),
682};
683
684static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB15, AT91_PIN_PB16, AT91_PIN_PB17, AT91_PIN_PB18 };
685
686void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
687{
688 int i;
689 unsigned long cs_pin;
690 short enable_spi0 = 0;
691 short enable_spi1 = 0;
692
693 /* Choose SPI chip-selects */
694 for (i = 0; i < nr_devices; i++) {
695 if (devices[i].controller_data)
696 cs_pin = (unsigned long) devices[i].controller_data;
697 else if (devices[i].bus_num == 0)
698 cs_pin = spi0_standard_cs[devices[i].chip_select];
699 else
700 cs_pin = spi1_standard_cs[devices[i].chip_select];
701
702 if (!gpio_is_valid(cs_pin))
703 continue;
704
705 if (devices[i].bus_num == 0)
706 enable_spi0 = 1;
707 else
708 enable_spi1 = 1;
709
710 /* enable chip-select pin */
711 at91_set_gpio_output(cs_pin, 1);
712
713 /* pass chip-select pin to driver */
714 devices[i].controller_data = (void *) cs_pin;
715 }
716
717 spi_register_board_info(devices, nr_devices);
718
719 /* Configure SPI bus(es) */
720 if (enable_spi0) {
721 at91_set_B_periph(AT91_PIN_PA0, 0); /* SPI0_MISO */
722 at91_set_B_periph(AT91_PIN_PA1, 0); /* SPI0_MOSI */
723 at91_set_B_periph(AT91_PIN_PA2, 0); /* SPI0_SPCK */
724
725 platform_device_register(&at91sam9263_spi0_device);
726 }
727 if (enable_spi1) {
728 at91_set_A_periph(AT91_PIN_PB12, 0); /* SPI1_MISO */
729 at91_set_A_periph(AT91_PIN_PB13, 0); /* SPI1_MOSI */
730 at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_SPCK */
731
732 platform_device_register(&at91sam9263_spi1_device);
733 }
734}
735#else
736void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
737#endif
738
739
740/* --------------------------------------------------------------------
741 * AC97
742 * -------------------------------------------------------------------- */
743
744#if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
745static u64 ac97_dmamask = DMA_BIT_MASK(32);
746static struct ac97c_platform_data ac97_data;
747
748static struct resource ac97_resources[] = {
749 [0] = {
750 .start = AT91SAM9263_BASE_AC97C,
751 .end = AT91SAM9263_BASE_AC97C + SZ_16K - 1,
752 .flags = IORESOURCE_MEM,
753 },
754 [1] = {
755 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_AC97C,
756 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_AC97C,
757 .flags = IORESOURCE_IRQ,
758 },
759};
760
761static struct platform_device at91sam9263_ac97_device = {
762 .name = "atmel_ac97c",
763 .id = 0,
764 .dev = {
765 .dma_mask = &ac97_dmamask,
766 .coherent_dma_mask = DMA_BIT_MASK(32),
767 .platform_data = &ac97_data,
768 },
769 .resource = ac97_resources,
770 .num_resources = ARRAY_SIZE(ac97_resources),
771};
772
773void __init at91_add_device_ac97(struct ac97c_platform_data *data)
774{
775 if (!data)
776 return;
777
778 at91_set_A_periph(AT91_PIN_PB0, 0); /* AC97FS */
779 at91_set_A_periph(AT91_PIN_PB1, 0); /* AC97CK */
780 at91_set_A_periph(AT91_PIN_PB2, 0); /* AC97TX */
781 at91_set_A_periph(AT91_PIN_PB3, 0); /* AC97RX */
782
783 /* reset */
784 if (gpio_is_valid(data->reset_pin))
785 at91_set_gpio_output(data->reset_pin, 0);
786
787 ac97_data = *data;
788 platform_device_register(&at91sam9263_ac97_device);
789}
790#else
791void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
792#endif
793
794/* --------------------------------------------------------------------
795 * CAN Controller
796 * -------------------------------------------------------------------- */
797
798#if defined(CONFIG_CAN_AT91) || defined(CONFIG_CAN_AT91_MODULE)
799static struct resource can_resources[] = {
800 [0] = {
801 .start = AT91SAM9263_BASE_CAN,
802 .end = AT91SAM9263_BASE_CAN + SZ_16K - 1,
803 .flags = IORESOURCE_MEM,
804 },
805 [1] = {
806 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_CAN,
807 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_CAN,
808 .flags = IORESOURCE_IRQ,
809 },
810};
811
812static struct platform_device at91sam9263_can_device = {
813 .name = "at91_can",
814 .id = -1,
815 .resource = can_resources,
816 .num_resources = ARRAY_SIZE(can_resources),
817};
818
819void __init at91_add_device_can(struct at91_can_data *data)
820{
821 at91_set_A_periph(AT91_PIN_PA13, 0); /* CANTX */
822 at91_set_A_periph(AT91_PIN_PA14, 0); /* CANRX */
823 at91sam9263_can_device.dev.platform_data = data;
824
825 platform_device_register(&at91sam9263_can_device);
826}
827#else
828void __init at91_add_device_can(struct at91_can_data *data) {}
829#endif
830
831/* --------------------------------------------------------------------
832 * LCD Controller
833 * -------------------------------------------------------------------- */
834
835#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
836static u64 lcdc_dmamask = DMA_BIT_MASK(32);
837static struct atmel_lcdfb_pdata lcdc_data;
838
839static struct resource lcdc_resources[] = {
840 [0] = {
841 .start = AT91SAM9263_LCDC_BASE,
842 .end = AT91SAM9263_LCDC_BASE + SZ_4K - 1,
843 .flags = IORESOURCE_MEM,
844 },
845 [1] = {
846 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_LCDC,
847 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_LCDC,
848 .flags = IORESOURCE_IRQ,
849 },
850};
851
852static struct platform_device at91_lcdc_device = {
853 .name = "at91sam9263-lcdfb",
854 .id = 0,
855 .dev = {
856 .dma_mask = &lcdc_dmamask,
857 .coherent_dma_mask = DMA_BIT_MASK(32),
858 .platform_data = &lcdc_data,
859 },
860 .resource = lcdc_resources,
861 .num_resources = ARRAY_SIZE(lcdc_resources),
862};
863
864void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data)
865{
866 if (!data)
867 return;
868
869 at91_set_A_periph(AT91_PIN_PC1, 0); /* LCDHSYNC */
870 at91_set_A_periph(AT91_PIN_PC2, 0); /* LCDDOTCK */
871 at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDDEN */
872 at91_set_B_periph(AT91_PIN_PB9, 0); /* LCDCC */
873 at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDD2 */
874 at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDD3 */
875 at91_set_A_periph(AT91_PIN_PC8, 0); /* LCDD4 */
876 at91_set_A_periph(AT91_PIN_PC9, 0); /* LCDD5 */
877 at91_set_A_periph(AT91_PIN_PC10, 0); /* LCDD6 */
878 at91_set_A_periph(AT91_PIN_PC11, 0); /* LCDD7 */
879 at91_set_A_periph(AT91_PIN_PC14, 0); /* LCDD10 */
880 at91_set_A_periph(AT91_PIN_PC15, 0); /* LCDD11 */
881 at91_set_A_periph(AT91_PIN_PC16, 0); /* LCDD12 */
882 at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD13 */
883 at91_set_A_periph(AT91_PIN_PC18, 0); /* LCDD14 */
884 at91_set_A_periph(AT91_PIN_PC19, 0); /* LCDD15 */
885 at91_set_A_periph(AT91_PIN_PC22, 0); /* LCDD18 */
886 at91_set_A_periph(AT91_PIN_PC23, 0); /* LCDD19 */
887 at91_set_A_periph(AT91_PIN_PC24, 0); /* LCDD20 */
888 at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD21 */
889 at91_set_A_periph(AT91_PIN_PC26, 0); /* LCDD22 */
890 at91_set_A_periph(AT91_PIN_PC27, 0); /* LCDD23 */
891
892 lcdc_data = *data;
893 platform_device_register(&at91_lcdc_device);
894}
895#else
896void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data) {}
897#endif
898
899
900/* --------------------------------------------------------------------
901 * Image Sensor Interface
902 * -------------------------------------------------------------------- */
903
904#if defined(CONFIG_VIDEO_AT91_ISI) || defined(CONFIG_VIDEO_AT91_ISI_MODULE)
905
906struct resource isi_resources[] = {
907 [0] = {
908 .start = AT91SAM9263_BASE_ISI,
909 .end = AT91SAM9263_BASE_ISI + SZ_16K - 1,
910 .flags = IORESOURCE_MEM,
911 },
912 [1] = {
913 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_ISI,
914 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_ISI,
915 .flags = IORESOURCE_IRQ,
916 },
917};
918
919static struct platform_device at91sam9263_isi_device = {
920 .name = "at91_isi",
921 .id = -1,
922 .resource = isi_resources,
923 .num_resources = ARRAY_SIZE(isi_resources),
924};
925
926void __init at91_add_device_isi(struct isi_platform_data *data,
927 bool use_pck_as_mck)
928{
929 at91_set_A_periph(AT91_PIN_PE0, 0); /* ISI_D0 */
930 at91_set_A_periph(AT91_PIN_PE1, 0); /* ISI_D1 */
931 at91_set_A_periph(AT91_PIN_PE2, 0); /* ISI_D2 */
932 at91_set_A_periph(AT91_PIN_PE3, 0); /* ISI_D3 */
933 at91_set_A_periph(AT91_PIN_PE4, 0); /* ISI_D4 */
934 at91_set_A_periph(AT91_PIN_PE5, 0); /* ISI_D5 */
935 at91_set_A_periph(AT91_PIN_PE6, 0); /* ISI_D6 */
936 at91_set_A_periph(AT91_PIN_PE7, 0); /* ISI_D7 */
937 at91_set_A_periph(AT91_PIN_PE8, 0); /* ISI_PCK */
938 at91_set_A_periph(AT91_PIN_PE9, 0); /* ISI_HSYNC */
939 at91_set_A_periph(AT91_PIN_PE10, 0); /* ISI_VSYNC */
940 at91_set_B_periph(AT91_PIN_PE12, 0); /* ISI_PD8 */
941 at91_set_B_periph(AT91_PIN_PE13, 0); /* ISI_PD9 */
942 at91_set_B_periph(AT91_PIN_PE14, 0); /* ISI_PD10 */
943 at91_set_B_periph(AT91_PIN_PE15, 0); /* ISI_PD11 */
944
945 if (use_pck_as_mck) {
946 at91_set_B_periph(AT91_PIN_PE11, 0); /* ISI_MCK (PCK3) */
947
948 /* TODO: register the PCK for ISI_MCK and set its parent */
949 }
950}
951#else
952void __init at91_add_device_isi(struct isi_platform_data *data,
953 bool use_pck_as_mck) {}
954#endif
955
956
957/* --------------------------------------------------------------------
958 * Timer/Counter block
959 * -------------------------------------------------------------------- */
960
961#ifdef CONFIG_ATMEL_TCLIB
962
963static struct resource tcb_resources[] = {
964 [0] = {
965 .start = AT91SAM9263_BASE_TCB0,
966 .end = AT91SAM9263_BASE_TCB0 + SZ_16K - 1,
967 .flags = IORESOURCE_MEM,
968 },
969 [1] = {
970 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_TCB,
971 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_TCB,
972 .flags = IORESOURCE_IRQ,
973 },
974};
975
976static struct platform_device at91sam9263_tcb_device = {
977 .name = "atmel_tcb",
978 .id = 0,
979 .resource = tcb_resources,
980 .num_resources = ARRAY_SIZE(tcb_resources),
981};
982
983#if defined(CONFIG_OF)
984static struct of_device_id tcb_ids[] = {
985 { .compatible = "atmel,at91rm9200-tcb" },
986 { /*sentinel*/ }
987};
988#endif
989
990static void __init at91_add_device_tc(void)
991{
992#if defined(CONFIG_OF)
993 struct device_node *np;
994
995 np = of_find_matching_node(NULL, tcb_ids);
996 if (np) {
997 of_node_put(np);
998 return;
999 }
1000#endif
1001
1002 platform_device_register(&at91sam9263_tcb_device);
1003}
1004#else
1005static void __init at91_add_device_tc(void) { }
1006#endif
1007
1008
1009/* --------------------------------------------------------------------
1010 * RTT
1011 * -------------------------------------------------------------------- */
1012
1013static struct resource rtt0_resources[] = {
1014 {
1015 .start = AT91SAM9263_BASE_RTT0,
1016 .end = AT91SAM9263_BASE_RTT0 + SZ_16 - 1,
1017 .flags = IORESOURCE_MEM,
1018 }, {
1019 .flags = IORESOURCE_MEM,
1020 }, {
1021 .flags = IORESOURCE_IRQ,
1022 }
1023};
1024
1025static struct platform_device at91sam9263_rtt0_device = {
1026 .name = "at91_rtt",
1027 .id = 0,
1028 .resource = rtt0_resources,
1029};
1030
1031static struct resource rtt1_resources[] = {
1032 {
1033 .start = AT91SAM9263_BASE_RTT1,
1034 .end = AT91SAM9263_BASE_RTT1 + SZ_16 - 1,
1035 .flags = IORESOURCE_MEM,
1036 }, {
1037 .flags = IORESOURCE_MEM,
1038 }, {
1039 .flags = IORESOURCE_IRQ,
1040 }
1041};
1042
1043static struct platform_device at91sam9263_rtt1_device = {
1044 .name = "at91_rtt",
1045 .id = 1,
1046 .resource = rtt1_resources,
1047};
1048
1049#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
1050static void __init at91_add_device_rtt_rtc(void)
1051{
1052 struct platform_device *pdev;
1053 struct resource *r;
1054
1055 switch (CONFIG_RTC_DRV_AT91SAM9_RTT) {
1056 case 0:
1057 /*
1058 * The second resource is needed only for the chosen RTT:
1059 * GPBR will serve as the storage for RTC time offset
1060 */
1061 at91sam9263_rtt0_device.num_resources = 3;
1062 at91sam9263_rtt1_device.num_resources = 1;
1063 pdev = &at91sam9263_rtt0_device;
1064 r = rtt0_resources;
1065 break;
1066 case 1:
1067 at91sam9263_rtt0_device.num_resources = 1;
1068 at91sam9263_rtt1_device.num_resources = 3;
1069 pdev = &at91sam9263_rtt1_device;
1070 r = rtt1_resources;
1071 break;
1072 default:
1073 pr_err("at91sam9263: only supports 2 RTT (%d)\n",
1074 CONFIG_RTC_DRV_AT91SAM9_RTT);
1075 return;
1076 }
1077
1078 pdev->name = "rtc-at91sam9";
1079 r[1].start = AT91SAM9263_BASE_GPBR + 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
1080 r[1].end = r[1].start + 3;
1081 r[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
1082 r[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
1083}
1084#else
1085static void __init at91_add_device_rtt_rtc(void)
1086{
1087 /* Only one resource is needed: RTT not used as RTC */
1088 at91sam9263_rtt0_device.num_resources = 1;
1089 at91sam9263_rtt1_device.num_resources = 1;
1090}
1091#endif
1092
1093static void __init at91_add_device_rtt(void)
1094{
1095 at91_add_device_rtt_rtc();
1096 platform_device_register(&at91sam9263_rtt0_device);
1097 platform_device_register(&at91sam9263_rtt1_device);
1098}
1099
1100
1101/* --------------------------------------------------------------------
1102 * Watchdog
1103 * -------------------------------------------------------------------- */
1104
1105#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
1106static struct resource wdt_resources[] = {
1107 {
1108 .start = AT91SAM9263_BASE_WDT,
1109 .end = AT91SAM9263_BASE_WDT + SZ_16 - 1,
1110 .flags = IORESOURCE_MEM,
1111 }
1112};
1113
1114static struct platform_device at91sam9263_wdt_device = {
1115 .name = "at91_wdt",
1116 .id = -1,
1117 .resource = wdt_resources,
1118 .num_resources = ARRAY_SIZE(wdt_resources),
1119};
1120
1121static void __init at91_add_device_watchdog(void)
1122{
1123 platform_device_register(&at91sam9263_wdt_device);
1124}
1125#else
1126static void __init at91_add_device_watchdog(void) {}
1127#endif
1128
1129
1130/* --------------------------------------------------------------------
1131 * PWM
1132 * --------------------------------------------------------------------*/
1133
1134#if IS_ENABLED(CONFIG_PWM_ATMEL)
1135static struct resource pwm_resources[] = {
1136 [0] = {
1137 .start = AT91SAM9263_BASE_PWMC,
1138 .end = AT91SAM9263_BASE_PWMC + SZ_16K - 1,
1139 .flags = IORESOURCE_MEM,
1140 },
1141 [1] = {
1142 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_PWMC,
1143 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_PWMC,
1144 .flags = IORESOURCE_IRQ,
1145 },
1146};
1147
1148static struct platform_device at91sam9263_pwm0_device = {
1149 .name = "at91sam9rl-pwm",
1150 .id = -1,
1151 .resource = pwm_resources,
1152 .num_resources = ARRAY_SIZE(pwm_resources),
1153};
1154
1155void __init at91_add_device_pwm(u32 mask)
1156{
1157 if (mask & (1 << AT91_PWM0))
1158 at91_set_B_periph(AT91_PIN_PB7, 1); /* enable PWM0 */
1159
1160 if (mask & (1 << AT91_PWM1))
1161 at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM1 */
1162
1163 if (mask & (1 << AT91_PWM2))
1164 at91_set_B_periph(AT91_PIN_PC29, 1); /* enable PWM2 */
1165
1166 if (mask & (1 << AT91_PWM3))
1167 at91_set_B_periph(AT91_PIN_PB29, 1); /* enable PWM3 */
1168
1169 platform_device_register(&at91sam9263_pwm0_device);
1170}
1171#else
1172void __init at91_add_device_pwm(u32 mask) {}
1173#endif
1174
1175
1176/* --------------------------------------------------------------------
1177 * SSC -- Synchronous Serial Controller
1178 * -------------------------------------------------------------------- */
1179
1180#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
1181static u64 ssc0_dmamask = DMA_BIT_MASK(32);
1182
1183static struct resource ssc0_resources[] = {
1184 [0] = {
1185 .start = AT91SAM9263_BASE_SSC0,
1186 .end = AT91SAM9263_BASE_SSC0 + SZ_16K - 1,
1187 .flags = IORESOURCE_MEM,
1188 },
1189 [1] = {
1190 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_SSC0,
1191 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_SSC0,
1192 .flags = IORESOURCE_IRQ,
1193 },
1194};
1195
1196static struct platform_device at91sam9263_ssc0_device = {
1197 .name = "at91rm9200_ssc",
1198 .id = 0,
1199 .dev = {
1200 .dma_mask = &ssc0_dmamask,
1201 .coherent_dma_mask = DMA_BIT_MASK(32),
1202 },
1203 .resource = ssc0_resources,
1204 .num_resources = ARRAY_SIZE(ssc0_resources),
1205};
1206
1207static inline void configure_ssc0_pins(unsigned pins)
1208{
1209 if (pins & ATMEL_SSC_TF)
1210 at91_set_B_periph(AT91_PIN_PB0, 1);
1211 if (pins & ATMEL_SSC_TK)
1212 at91_set_B_periph(AT91_PIN_PB1, 1);
1213 if (pins & ATMEL_SSC_TD)
1214 at91_set_B_periph(AT91_PIN_PB2, 1);
1215 if (pins & ATMEL_SSC_RD)
1216 at91_set_B_periph(AT91_PIN_PB3, 1);
1217 if (pins & ATMEL_SSC_RK)
1218 at91_set_B_periph(AT91_PIN_PB4, 1);
1219 if (pins & ATMEL_SSC_RF)
1220 at91_set_B_periph(AT91_PIN_PB5, 1);
1221}
1222
1223static u64 ssc1_dmamask = DMA_BIT_MASK(32);
1224
1225static struct resource ssc1_resources[] = {
1226 [0] = {
1227 .start = AT91SAM9263_BASE_SSC1,
1228 .end = AT91SAM9263_BASE_SSC1 + SZ_16K - 1,
1229 .flags = IORESOURCE_MEM,
1230 },
1231 [1] = {
1232 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_SSC1,
1233 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_SSC1,
1234 .flags = IORESOURCE_IRQ,
1235 },
1236};
1237
1238static struct platform_device at91sam9263_ssc1_device = {
1239 .name = "at91rm9200_ssc",
1240 .id = 1,
1241 .dev = {
1242 .dma_mask = &ssc1_dmamask,
1243 .coherent_dma_mask = DMA_BIT_MASK(32),
1244 },
1245 .resource = ssc1_resources,
1246 .num_resources = ARRAY_SIZE(ssc1_resources),
1247};
1248
1249static inline void configure_ssc1_pins(unsigned pins)
1250{
1251 if (pins & ATMEL_SSC_TF)
1252 at91_set_A_periph(AT91_PIN_PB6, 1);
1253 if (pins & ATMEL_SSC_TK)
1254 at91_set_A_periph(AT91_PIN_PB7, 1);
1255 if (pins & ATMEL_SSC_TD)
1256 at91_set_A_periph(AT91_PIN_PB8, 1);
1257 if (pins & ATMEL_SSC_RD)
1258 at91_set_A_periph(AT91_PIN_PB9, 1);
1259 if (pins & ATMEL_SSC_RK)
1260 at91_set_A_periph(AT91_PIN_PB10, 1);
1261 if (pins & ATMEL_SSC_RF)
1262 at91_set_A_periph(AT91_PIN_PB11, 1);
1263}
1264
1265/*
1266 * SSC controllers are accessed through library code, instead of any
1267 * kind of all-singing/all-dancing driver. For example one could be
1268 * used by a particular I2S audio codec's driver, while another one
1269 * on the same system might be used by a custom data capture driver.
1270 */
1271void __init at91_add_device_ssc(unsigned id, unsigned pins)
1272{
1273 struct platform_device *pdev;
1274
1275 /*
1276 * NOTE: caller is responsible for passing information matching
1277 * "pins" to whatever will be using each particular controller.
1278 */
1279 switch (id) {
1280 case AT91SAM9263_ID_SSC0:
1281 pdev = &at91sam9263_ssc0_device;
1282 configure_ssc0_pins(pins);
1283 break;
1284 case AT91SAM9263_ID_SSC1:
1285 pdev = &at91sam9263_ssc1_device;
1286 configure_ssc1_pins(pins);
1287 break;
1288 default:
1289 return;
1290 }
1291
1292 platform_device_register(pdev);
1293}
1294
1295#else
1296void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
1297#endif
1298
1299
1300/* --------------------------------------------------------------------
1301 * UART
1302 * -------------------------------------------------------------------- */
1303
1304#if defined(CONFIG_SERIAL_ATMEL)
1305
1306static struct resource dbgu_resources[] = {
1307 [0] = {
1308 .start = AT91SAM9263_BASE_DBGU,
1309 .end = AT91SAM9263_BASE_DBGU + SZ_512 - 1,
1310 .flags = IORESOURCE_MEM,
1311 },
1312 [1] = {
1313 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
1314 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
1315 .flags = IORESOURCE_IRQ,
1316 },
1317};
1318
1319static struct atmel_uart_data dbgu_data = {
1320 .use_dma_tx = 0,
1321 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
1322};
1323
1324static u64 dbgu_dmamask = DMA_BIT_MASK(32);
1325
1326static struct platform_device at91sam9263_dbgu_device = {
1327 .name = "atmel_usart",
1328 .id = 0,
1329 .dev = {
1330 .dma_mask = &dbgu_dmamask,
1331 .coherent_dma_mask = DMA_BIT_MASK(32),
1332 .platform_data = &dbgu_data,
1333 },
1334 .resource = dbgu_resources,
1335 .num_resources = ARRAY_SIZE(dbgu_resources),
1336};
1337
1338static inline void configure_dbgu_pins(void)
1339{
1340 at91_set_A_periph(AT91_PIN_PC30, 0); /* DRXD */
1341 at91_set_A_periph(AT91_PIN_PC31, 1); /* DTXD */
1342}
1343
1344static struct resource uart0_resources[] = {
1345 [0] = {
1346 .start = AT91SAM9263_BASE_US0,
1347 .end = AT91SAM9263_BASE_US0 + SZ_16K - 1,
1348 .flags = IORESOURCE_MEM,
1349 },
1350 [1] = {
1351 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_US0,
1352 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_US0,
1353 .flags = IORESOURCE_IRQ,
1354 },
1355};
1356
1357static struct atmel_uart_data uart0_data = {
1358 .use_dma_tx = 1,
1359 .use_dma_rx = 1,
1360};
1361
1362static u64 uart0_dmamask = DMA_BIT_MASK(32);
1363
1364static struct platform_device at91sam9263_uart0_device = {
1365 .name = "atmel_usart",
1366 .id = 1,
1367 .dev = {
1368 .dma_mask = &uart0_dmamask,
1369 .coherent_dma_mask = DMA_BIT_MASK(32),
1370 .platform_data = &uart0_data,
1371 },
1372 .resource = uart0_resources,
1373 .num_resources = ARRAY_SIZE(uart0_resources),
1374};
1375
1376static inline void configure_usart0_pins(unsigned pins)
1377{
1378 at91_set_A_periph(AT91_PIN_PA26, 1); /* TXD0 */
1379 at91_set_A_periph(AT91_PIN_PA27, 0); /* RXD0 */
1380
1381 if (pins & ATMEL_UART_RTS)
1382 at91_set_A_periph(AT91_PIN_PA28, 0); /* RTS0 */
1383 if (pins & ATMEL_UART_CTS)
1384 at91_set_A_periph(AT91_PIN_PA29, 0); /* CTS0 */
1385}
1386
1387static struct resource uart1_resources[] = {
1388 [0] = {
1389 .start = AT91SAM9263_BASE_US1,
1390 .end = AT91SAM9263_BASE_US1 + SZ_16K - 1,
1391 .flags = IORESOURCE_MEM,
1392 },
1393 [1] = {
1394 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_US1,
1395 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_US1,
1396 .flags = IORESOURCE_IRQ,
1397 },
1398};
1399
1400static struct atmel_uart_data uart1_data = {
1401 .use_dma_tx = 1,
1402 .use_dma_rx = 1,
1403};
1404
1405static u64 uart1_dmamask = DMA_BIT_MASK(32);
1406
1407static struct platform_device at91sam9263_uart1_device = {
1408 .name = "atmel_usart",
1409 .id = 2,
1410 .dev = {
1411 .dma_mask = &uart1_dmamask,
1412 .coherent_dma_mask = DMA_BIT_MASK(32),
1413 .platform_data = &uart1_data,
1414 },
1415 .resource = uart1_resources,
1416 .num_resources = ARRAY_SIZE(uart1_resources),
1417};
1418
1419static inline void configure_usart1_pins(unsigned pins)
1420{
1421 at91_set_A_periph(AT91_PIN_PD0, 1); /* TXD1 */
1422 at91_set_A_periph(AT91_PIN_PD1, 0); /* RXD1 */
1423
1424 if (pins & ATMEL_UART_RTS)
1425 at91_set_B_periph(AT91_PIN_PD7, 0); /* RTS1 */
1426 if (pins & ATMEL_UART_CTS)
1427 at91_set_B_periph(AT91_PIN_PD8, 0); /* CTS1 */
1428}
1429
1430static struct resource uart2_resources[] = {
1431 [0] = {
1432 .start = AT91SAM9263_BASE_US2,
1433 .end = AT91SAM9263_BASE_US2 + SZ_16K - 1,
1434 .flags = IORESOURCE_MEM,
1435 },
1436 [1] = {
1437 .start = NR_IRQS_LEGACY + AT91SAM9263_ID_US2,
1438 .end = NR_IRQS_LEGACY + AT91SAM9263_ID_US2,
1439 .flags = IORESOURCE_IRQ,
1440 },
1441};
1442
1443static struct atmel_uart_data uart2_data = {
1444 .use_dma_tx = 1,
1445 .use_dma_rx = 1,
1446};
1447
1448static u64 uart2_dmamask = DMA_BIT_MASK(32);
1449
1450static struct platform_device at91sam9263_uart2_device = {
1451 .name = "atmel_usart",
1452 .id = 3,
1453 .dev = {
1454 .dma_mask = &uart2_dmamask,
1455 .coherent_dma_mask = DMA_BIT_MASK(32),
1456 .platform_data = &uart2_data,
1457 },
1458 .resource = uart2_resources,
1459 .num_resources = ARRAY_SIZE(uart2_resources),
1460};
1461
1462static inline void configure_usart2_pins(unsigned pins)
1463{
1464 at91_set_A_periph(AT91_PIN_PD2, 1); /* TXD2 */
1465 at91_set_A_periph(AT91_PIN_PD3, 0); /* RXD2 */
1466
1467 if (pins & ATMEL_UART_RTS)
1468 at91_set_B_periph(AT91_PIN_PD5, 0); /* RTS2 */
1469 if (pins & ATMEL_UART_CTS)
1470 at91_set_B_periph(AT91_PIN_PD6, 0); /* CTS2 */
1471}
1472
1473static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
1474
1475void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1476{
1477 struct platform_device *pdev;
1478 struct atmel_uart_data *pdata;
1479
1480 switch (id) {
1481 case 0: /* DBGU */
1482 pdev = &at91sam9263_dbgu_device;
1483 configure_dbgu_pins();
1484 break;
1485 case AT91SAM9263_ID_US0:
1486 pdev = &at91sam9263_uart0_device;
1487 configure_usart0_pins(pins);
1488 break;
1489 case AT91SAM9263_ID_US1:
1490 pdev = &at91sam9263_uart1_device;
1491 configure_usart1_pins(pins);
1492 break;
1493 case AT91SAM9263_ID_US2:
1494 pdev = &at91sam9263_uart2_device;
1495 configure_usart2_pins(pins);
1496 break;
1497 default:
1498 return;
1499 }
1500 pdata = pdev->dev.platform_data;
1501 pdata->num = portnr; /* update to mapped ID */
1502
1503 if (portnr < ATMEL_MAX_UART)
1504 at91_uarts[portnr] = pdev;
1505}
1506
1507void __init at91_add_device_serial(void)
1508{
1509 int i;
1510
1511 for (i = 0; i < ATMEL_MAX_UART; i++) {
1512 if (at91_uarts[i])
1513 platform_device_register(at91_uarts[i]);
1514 }
1515}
1516#else
1517void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1518void __init at91_add_device_serial(void) {}
1519#endif
1520
1521
1522/* -------------------------------------------------------------------- */
1523/*
1524 * These devices are always present and don't need any board-specific
1525 * setup.
1526 */
1527static int __init at91_add_standard_devices(void)
1528{
1529 if (of_have_populated_dt())
1530 return 0;
1531
1532 at91_add_device_rtt();
1533 at91_add_device_watchdog();
1534 at91_add_device_tc();
1535 return 0;
1536}
1537
1538arch_initcall(at91_add_standard_devices);
diff --git a/arch/arm/mach-at91/at91sam9g45.c b/arch/arm/mach-at91/at91sam9g45.c
index 405427ec05f8..b6117bea9a6f 100644
--- a/arch/arm/mach-at91/at91sam9g45.c
+++ b/arch/arm/mach-at91/at91sam9g45.c
@@ -10,356 +10,12 @@
10 * 10 *
11 */ 11 */
12 12
13#include <linux/module.h>
14#include <linux/dma-mapping.h>
15#include <linux/clk/at91_pmc.h>
16#include <linux/platform_device.h>
17
18#include <asm/irq.h>
19#include <asm/mach/arch.h>
20#include <asm/mach/map.h>
21#include <asm/system_misc.h> 13#include <asm/system_misc.h>
22#include <mach/at91sam9g45.h> 14#include <asm/irq.h>
23#include <mach/cpu.h>
24#include <mach/hardware.h> 15#include <mach/hardware.h>
25 16
26#include "at91_aic.h"
27#include "soc.h" 17#include "soc.h"
28#include "generic.h" 18#include "generic.h"
29#include "sam9_smc.h"
30#include "pm.h"
31
32#if defined(CONFIG_OLD_CLK_AT91)
33#include "clock.h"
34/* --------------------------------------------------------------------
35 * Clocks
36 * -------------------------------------------------------------------- */
37
38/*
39 * The peripheral clocks.
40 */
41static struct clk pioA_clk = {
42 .name = "pioA_clk",
43 .pmc_mask = 1 << AT91SAM9G45_ID_PIOA,
44 .type = CLK_TYPE_PERIPHERAL,
45};
46static struct clk pioB_clk = {
47 .name = "pioB_clk",
48 .pmc_mask = 1 << AT91SAM9G45_ID_PIOB,
49 .type = CLK_TYPE_PERIPHERAL,
50};
51static struct clk pioC_clk = {
52 .name = "pioC_clk",
53 .pmc_mask = 1 << AT91SAM9G45_ID_PIOC,
54 .type = CLK_TYPE_PERIPHERAL,
55};
56static struct clk pioDE_clk = {
57 .name = "pioDE_clk",
58 .pmc_mask = 1 << AT91SAM9G45_ID_PIODE,
59 .type = CLK_TYPE_PERIPHERAL,
60};
61static struct clk trng_clk = {
62 .name = "trng_clk",
63 .pmc_mask = 1 << AT91SAM9G45_ID_TRNG,
64 .type = CLK_TYPE_PERIPHERAL,
65};
66static struct clk usart0_clk = {
67 .name = "usart0_clk",
68 .pmc_mask = 1 << AT91SAM9G45_ID_US0,
69 .type = CLK_TYPE_PERIPHERAL,
70};
71static struct clk usart1_clk = {
72 .name = "usart1_clk",
73 .pmc_mask = 1 << AT91SAM9G45_ID_US1,
74 .type = CLK_TYPE_PERIPHERAL,
75};
76static struct clk usart2_clk = {
77 .name = "usart2_clk",
78 .pmc_mask = 1 << AT91SAM9G45_ID_US2,
79 .type = CLK_TYPE_PERIPHERAL,
80};
81static struct clk usart3_clk = {
82 .name = "usart3_clk",
83 .pmc_mask = 1 << AT91SAM9G45_ID_US3,
84 .type = CLK_TYPE_PERIPHERAL,
85};
86static struct clk mmc0_clk = {
87 .name = "mci0_clk",
88 .pmc_mask = 1 << AT91SAM9G45_ID_MCI0,
89 .type = CLK_TYPE_PERIPHERAL,
90};
91static struct clk twi0_clk = {
92 .name = "twi0_clk",
93 .pmc_mask = 1 << AT91SAM9G45_ID_TWI0,
94 .type = CLK_TYPE_PERIPHERAL,
95};
96static struct clk twi1_clk = {
97 .name = "twi1_clk",
98 .pmc_mask = 1 << AT91SAM9G45_ID_TWI1,
99 .type = CLK_TYPE_PERIPHERAL,
100};
101static struct clk spi0_clk = {
102 .name = "spi0_clk",
103 .pmc_mask = 1 << AT91SAM9G45_ID_SPI0,
104 .type = CLK_TYPE_PERIPHERAL,
105};
106static struct clk spi1_clk = {
107 .name = "spi1_clk",
108 .pmc_mask = 1 << AT91SAM9G45_ID_SPI1,
109 .type = CLK_TYPE_PERIPHERAL,
110};
111static struct clk ssc0_clk = {
112 .name = "ssc0_clk",
113 .pmc_mask = 1 << AT91SAM9G45_ID_SSC0,
114 .type = CLK_TYPE_PERIPHERAL,
115};
116static struct clk ssc1_clk = {
117 .name = "ssc1_clk",
118 .pmc_mask = 1 << AT91SAM9G45_ID_SSC1,
119 .type = CLK_TYPE_PERIPHERAL,
120};
121static struct clk tcb0_clk = {
122 .name = "tcb0_clk",
123 .pmc_mask = 1 << AT91SAM9G45_ID_TCB,
124 .type = CLK_TYPE_PERIPHERAL,
125};
126static struct clk pwm_clk = {
127 .name = "pwm_clk",
128 .pmc_mask = 1 << AT91SAM9G45_ID_PWMC,
129 .type = CLK_TYPE_PERIPHERAL,
130};
131static struct clk tsc_clk = {
132 .name = "tsc_clk",
133 .pmc_mask = 1 << AT91SAM9G45_ID_TSC,
134 .type = CLK_TYPE_PERIPHERAL,
135};
136static struct clk dma_clk = {
137 .name = "dma_clk",
138 .pmc_mask = 1 << AT91SAM9G45_ID_DMA,
139 .type = CLK_TYPE_PERIPHERAL,
140};
141static struct clk uhphs_clk = {
142 .name = "uhphs_clk",
143 .pmc_mask = 1 << AT91SAM9G45_ID_UHPHS,
144 .type = CLK_TYPE_PERIPHERAL,
145};
146static struct clk lcdc_clk = {
147 .name = "lcdc_clk",
148 .pmc_mask = 1 << AT91SAM9G45_ID_LCDC,
149 .type = CLK_TYPE_PERIPHERAL,
150};
151static struct clk ac97_clk = {
152 .name = "ac97_clk",
153 .pmc_mask = 1 << AT91SAM9G45_ID_AC97C,
154 .type = CLK_TYPE_PERIPHERAL,
155};
156static struct clk macb_clk = {
157 .name = "pclk",
158 .pmc_mask = 1 << AT91SAM9G45_ID_EMAC,
159 .type = CLK_TYPE_PERIPHERAL,
160};
161static struct clk isi_clk = {
162 .name = "isi_clk",
163 .pmc_mask = 1 << AT91SAM9G45_ID_ISI,
164 .type = CLK_TYPE_PERIPHERAL,
165};
166static struct clk udphs_clk = {
167 .name = "udphs_clk",
168 .pmc_mask = 1 << AT91SAM9G45_ID_UDPHS,
169 .type = CLK_TYPE_PERIPHERAL,
170};
171static struct clk mmc1_clk = {
172 .name = "mci1_clk",
173 .pmc_mask = 1 << AT91SAM9G45_ID_MCI1,
174 .type = CLK_TYPE_PERIPHERAL,
175};
176
177/* Video decoder clock - Only for sam9m10/sam9m11 */
178static struct clk vdec_clk = {
179 .name = "vdec_clk",
180 .pmc_mask = 1 << AT91SAM9G45_ID_VDEC,
181 .type = CLK_TYPE_PERIPHERAL,
182};
183
184static struct clk adc_op_clk = {
185 .name = "adc_op_clk",
186 .type = CLK_TYPE_PERIPHERAL,
187 .rate_hz = 300000,
188};
189
190/* AES/TDES/SHA clock - Only for sam9m11/sam9g56 */
191static struct clk aestdessha_clk = {
192 .name = "aestdessha_clk",
193 .pmc_mask = 1 << AT91SAM9G45_ID_AESTDESSHA,
194 .type = CLK_TYPE_PERIPHERAL,
195};
196
197static struct clk *periph_clocks[] __initdata = {
198 &pioA_clk,
199 &pioB_clk,
200 &pioC_clk,
201 &pioDE_clk,
202 &trng_clk,
203 &usart0_clk,
204 &usart1_clk,
205 &usart2_clk,
206 &usart3_clk,
207 &mmc0_clk,
208 &twi0_clk,
209 &twi1_clk,
210 &spi0_clk,
211 &spi1_clk,
212 &ssc0_clk,
213 &ssc1_clk,
214 &tcb0_clk,
215 &pwm_clk,
216 &tsc_clk,
217 &dma_clk,
218 &uhphs_clk,
219 &lcdc_clk,
220 &ac97_clk,
221 &macb_clk,
222 &isi_clk,
223 &udphs_clk,
224 &mmc1_clk,
225 &adc_op_clk,
226 &aestdessha_clk,
227 // irq0
228};
229
230static struct clk_lookup periph_clocks_lookups[] = {
231 /* One additional fake clock for macb_hclk */
232 CLKDEV_CON_ID("hclk", &macb_clk),
233 /* One additional fake clock for ohci */
234 CLKDEV_CON_ID("ohci_clk", &uhphs_clk),
235 CLKDEV_CON_DEV_ID("hclk", "at91sam9g45-lcdfb.0", &lcdc_clk),
236 CLKDEV_CON_DEV_ID("hclk", "at91sam9g45es-lcdfb.0", &lcdc_clk),
237 CLKDEV_CON_DEV_ID("ehci_clk", "atmel-ehci", &uhphs_clk),
238 CLKDEV_CON_DEV_ID("hclk", "atmel_usba_udc", &utmi_clk),
239 CLKDEV_CON_DEV_ID("pclk", "atmel_usba_udc", &udphs_clk),
240 CLKDEV_CON_DEV_ID("mci_clk", "atmel_mci.0", &mmc0_clk),
241 CLKDEV_CON_DEV_ID("mci_clk", "atmel_mci.1", &mmc1_clk),
242 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.0", &spi0_clk),
243 CLKDEV_CON_DEV_ID("spi_clk", "atmel_spi.1", &spi1_clk),
244 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tcb0_clk),
245 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.1", &tcb0_clk),
246 CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9g10.0", &twi0_clk),
247 CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9g10.1", &twi1_clk),
248 CLKDEV_CON_DEV_ID("pclk", "at91sam9g45_ssc.0", &ssc0_clk),
249 CLKDEV_CON_DEV_ID("pclk", "at91sam9g45_ssc.1", &ssc1_clk),
250 CLKDEV_CON_DEV_ID("pclk", "fff9c000.ssc", &ssc0_clk),
251 CLKDEV_CON_DEV_ID("pclk", "fffa0000.ssc", &ssc1_clk),
252 CLKDEV_CON_DEV_ID(NULL, "atmel-trng", &trng_clk),
253 CLKDEV_CON_DEV_ID(NULL, "atmel_sha", &aestdessha_clk),
254 CLKDEV_CON_DEV_ID(NULL, "atmel_tdes", &aestdessha_clk),
255 CLKDEV_CON_DEV_ID(NULL, "atmel_aes", &aestdessha_clk),
256 CLKDEV_CON_DEV_ID(NULL, "at91sam9rl-pwm", &pwm_clk),
257 /* more usart lookup table for DT entries */
258 CLKDEV_CON_DEV_ID("usart", "ffffee00.serial", &mck),
259 CLKDEV_CON_DEV_ID("usart", "fff8c000.serial", &usart0_clk),
260 CLKDEV_CON_DEV_ID("usart", "fff90000.serial", &usart1_clk),
261 CLKDEV_CON_DEV_ID("usart", "fff94000.serial", &usart2_clk),
262 CLKDEV_CON_DEV_ID("usart", "fff98000.serial", &usart3_clk),
263 /* more tc lookup table for DT entries */
264 CLKDEV_CON_DEV_ID("t0_clk", "fff7c000.timer", &tcb0_clk),
265 CLKDEV_CON_DEV_ID("t0_clk", "fffd4000.timer", &tcb0_clk),
266 CLKDEV_CON_DEV_ID("hclk", "700000.ohci", &uhphs_clk),
267 CLKDEV_CON_DEV_ID("ehci_clk", "800000.ehci", &uhphs_clk),
268 CLKDEV_CON_DEV_ID("mci_clk", "fff80000.mmc", &mmc0_clk),
269 CLKDEV_CON_DEV_ID("mci_clk", "fffd0000.mmc", &mmc1_clk),
270 CLKDEV_CON_DEV_ID(NULL, "fff84000.i2c", &twi0_clk),
271 CLKDEV_CON_DEV_ID(NULL, "fff88000.i2c", &twi1_clk),
272 CLKDEV_CON_DEV_ID("spi_clk", "fffa4000.spi", &spi0_clk),
273 CLKDEV_CON_DEV_ID("spi_clk", "fffa8000.spi", &spi1_clk),
274 CLKDEV_CON_DEV_ID("hclk", "600000.gadget", &utmi_clk),
275 CLKDEV_CON_DEV_ID("pclk", "600000.gadget", &udphs_clk),
276 /* fake hclk clock */
277 CLKDEV_CON_DEV_ID("hclk", "at91_ohci", &uhphs_clk),
278 CLKDEV_CON_DEV_ID(NULL, "fffff200.gpio", &pioA_clk),
279 CLKDEV_CON_DEV_ID(NULL, "fffff400.gpio", &pioB_clk),
280 CLKDEV_CON_DEV_ID(NULL, "fffff600.gpio", &pioC_clk),
281 CLKDEV_CON_DEV_ID(NULL, "fffff800.gpio", &pioDE_clk),
282 CLKDEV_CON_DEV_ID(NULL, "fffffa00.gpio", &pioDE_clk),
283
284 CLKDEV_CON_ID("pioA", &pioA_clk),
285 CLKDEV_CON_ID("pioB", &pioB_clk),
286 CLKDEV_CON_ID("pioC", &pioC_clk),
287 CLKDEV_CON_ID("pioD", &pioDE_clk),
288 CLKDEV_CON_ID("pioE", &pioDE_clk),
289 /* Fake adc clock */
290 CLKDEV_CON_ID("adc_clk", &tsc_clk),
291 CLKDEV_CON_DEV_ID(NULL, "fffb8000.pwm", &pwm_clk),
292};
293
294static struct clk_lookup usart_clocks_lookups[] = {
295 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
296 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
297 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
298 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
299 CLKDEV_CON_DEV_ID("usart", "atmel_usart.4", &usart3_clk),
300};
301
302/*
303 * The two programmable clocks.
304 * You must configure pin multiplexing to bring these signals out.
305 */
306static struct clk pck0 = {
307 .name = "pck0",
308 .pmc_mask = AT91_PMC_PCK0,
309 .type = CLK_TYPE_PROGRAMMABLE,
310 .id = 0,
311};
312static struct clk pck1 = {
313 .name = "pck1",
314 .pmc_mask = AT91_PMC_PCK1,
315 .type = CLK_TYPE_PROGRAMMABLE,
316 .id = 1,
317};
318
319static void __init at91sam9g45_register_clocks(void)
320{
321 int i;
322
323 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
324 clk_register(periph_clocks[i]);
325
326 clkdev_add_table(periph_clocks_lookups,
327 ARRAY_SIZE(periph_clocks_lookups));
328 clkdev_add_table(usart_clocks_lookups,
329 ARRAY_SIZE(usart_clocks_lookups));
330
331 if (cpu_is_at91sam9m10() || cpu_is_at91sam9m11())
332 clk_register(&vdec_clk);
333
334 clk_register(&pck0);
335 clk_register(&pck1);
336}
337#else
338#define at91sam9g45_register_clocks NULL
339#endif
340
341/* --------------------------------------------------------------------
342 * GPIO
343 * -------------------------------------------------------------------- */
344
345static struct at91_gpio_bank at91sam9g45_gpio[] __initdata = {
346 {
347 .id = AT91SAM9G45_ID_PIOA,
348 .regbase = AT91SAM9G45_BASE_PIOA,
349 }, {
350 .id = AT91SAM9G45_ID_PIOB,
351 .regbase = AT91SAM9G45_BASE_PIOB,
352 }, {
353 .id = AT91SAM9G45_ID_PIOC,
354 .regbase = AT91SAM9G45_BASE_PIOC,
355 }, {
356 .id = AT91SAM9G45_ID_PIODE,
357 .regbase = AT91SAM9G45_BASE_PIOD,
358 }, {
359 .id = AT91SAM9G45_ID_PIODE,
360 .regbase = AT91SAM9G45_BASE_PIOE,
361 }
362};
363 19
364/* -------------------------------------------------------------------- 20/* --------------------------------------------------------------------
365 * AT91SAM9G45 processor initialization 21 * AT91SAM9G45 processor initialization
@@ -370,125 +26,15 @@ static void __init at91sam9g45_map_io(void)
370 at91_init_sram(0, AT91SAM9G45_SRAM_BASE, AT91SAM9G45_SRAM_SIZE); 26 at91_init_sram(0, AT91SAM9G45_SRAM_BASE, AT91SAM9G45_SRAM_SIZE);
371} 27}
372 28
373static void __init at91sam9g45_ioremap_registers(void)
374{
375 at91_ioremap_ramc(0, AT91SAM9G45_BASE_DDRSDRC1, 512);
376 at91_ioremap_ramc(1, AT91SAM9G45_BASE_DDRSDRC0, 512);
377 at91sam926x_ioremap_pit(AT91SAM9G45_BASE_PIT);
378 at91sam9_ioremap_smc(0, AT91SAM9G45_BASE_SMC);
379 at91_ioremap_matrix(AT91SAM9G45_BASE_MATRIX);
380 at91_pm_set_standby(at91_ddr_standby);
381}
382
383static void __init at91sam9g45_initialize(void) 29static void __init at91sam9g45_initialize(void)
384{ 30{
385 arm_pm_idle = at91sam9_idle; 31 arm_pm_idle = at91sam9_idle;
386 32
387 at91_sysirq_mask_rtc(AT91SAM9G45_BASE_RTC); 33 at91_sysirq_mask_rtc(AT91SAM9G45_BASE_RTC);
388 at91_sysirq_mask_rtt(AT91SAM9G45_BASE_RTT); 34 at91_sysirq_mask_rtt(AT91SAM9G45_BASE_RTT);
389
390 /* Register GPIO subsystem */
391 at91_gpio_init(at91sam9g45_gpio, 5);
392}
393
394static struct resource rstc_resources[] = {
395 [0] = {
396 .start = AT91SAM9G45_BASE_RSTC,
397 .end = AT91SAM9G45_BASE_RSTC + SZ_16 - 1,
398 .flags = IORESOURCE_MEM,
399 },
400 [1] = {
401 .start = AT91SAM9G45_BASE_DDRSDRC1,
402 .end = AT91SAM9G45_BASE_DDRSDRC1 + SZ_512 - 1,
403 .flags = IORESOURCE_MEM,
404 },
405 [2] = {
406 .start = AT91SAM9G45_BASE_DDRSDRC0,
407 .end = AT91SAM9G45_BASE_DDRSDRC0 + SZ_512 - 1,
408 .flags = IORESOURCE_MEM,
409 },
410};
411
412static struct platform_device rstc_device = {
413 .name = "at91-sam9g45-reset",
414 .resource = rstc_resources,
415 .num_resources = ARRAY_SIZE(rstc_resources),
416};
417
418static struct resource shdwc_resources[] = {
419 [0] = {
420 .start = AT91SAM9G45_BASE_SHDWC,
421 .end = AT91SAM9G45_BASE_SHDWC + SZ_16 - 1,
422 .flags = IORESOURCE_MEM,
423 },
424};
425
426static struct platform_device shdwc_device = {
427 .name = "at91-poweroff",
428 .resource = shdwc_resources,
429 .num_resources = ARRAY_SIZE(shdwc_resources),
430};
431
432static void __init at91sam9g45_register_devices(void)
433{
434 platform_device_register(&rstc_device);
435 platform_device_register(&shdwc_device);
436}
437
438/* --------------------------------------------------------------------
439 * Interrupt initialization
440 * -------------------------------------------------------------------- */
441
442/*
443 * The default interrupt priority levels (0 = lowest, 7 = highest).
444 */
445static unsigned int at91sam9g45_default_irq_priority[NR_AIC_IRQS] __initdata = {
446 7, /* Advanced Interrupt Controller (FIQ) */
447 7, /* System Peripherals */
448 1, /* Parallel IO Controller A */
449 1, /* Parallel IO Controller B */
450 1, /* Parallel IO Controller C */
451 1, /* Parallel IO Controller D and E */
452 0,
453 5, /* USART 0 */
454 5, /* USART 1 */
455 5, /* USART 2 */
456 5, /* USART 3 */
457 0, /* Multimedia Card Interface 0 */
458 6, /* Two-Wire Interface 0 */
459 6, /* Two-Wire Interface 1 */
460 5, /* Serial Peripheral Interface 0 */
461 5, /* Serial Peripheral Interface 1 */
462 4, /* Serial Synchronous Controller 0 */
463 4, /* Serial Synchronous Controller 1 */
464 0, /* Timer Counter 0, 1, 2, 3, 4 and 5 */
465 0, /* Pulse Width Modulation Controller */
466 0, /* Touch Screen Controller */
467 0, /* DMA Controller */
468 2, /* USB Host High Speed port */
469 3, /* LDC Controller */
470 5, /* AC97 Controller */
471 3, /* Ethernet */
472 0, /* Image Sensor Interface */
473 2, /* USB Device High speed port */
474 0, /* AESTDESSHA Crypto HW Accelerators */
475 0, /* Multimedia Card Interface 1 */
476 0,
477 0, /* Advanced Interrupt Controller (IRQ0) */
478};
479
480static void __init at91sam9g45_init_time(void)
481{
482 at91sam926x_pit_init(NR_IRQS_LEGACY + AT91_ID_SYS);
483} 35}
484 36
485AT91_SOC_START(at91sam9g45) 37AT91_SOC_START(at91sam9g45)
486 .map_io = at91sam9g45_map_io, 38 .map_io = at91sam9g45_map_io,
487 .default_irq_priority = at91sam9g45_default_irq_priority,
488 .extern_irq = (1 << AT91SAM9G45_ID_IRQ0),
489 .ioremap_registers = at91sam9g45_ioremap_registers,
490 .register_clocks = at91sam9g45_register_clocks,
491 .register_devices = at91sam9g45_register_devices,
492 .init = at91sam9g45_initialize, 39 .init = at91sam9g45_initialize,
493 .init_time = at91sam9g45_init_time,
494AT91_SOC_END 40AT91_SOC_END
diff --git a/arch/arm/mach-at91/at91sam9g45_devices.c b/arch/arm/mach-at91/at91sam9g45_devices.c
deleted file mode 100644
index 21ab782cc8e9..000000000000
--- a/arch/arm/mach-at91/at91sam9g45_devices.c
+++ /dev/null
@@ -1,1915 +0,0 @@
1/*
2 * On-Chip devices setup code for the AT91SAM9G45 family
3 *
4 * Copyright (C) 2009 Atmel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12#include <asm/mach/arch.h>
13#include <asm/mach/map.h>
14
15#include <linux/dma-mapping.h>
16#include <linux/gpio.h>
17#include <linux/clk.h>
18#include <linux/platform_device.h>
19#include <linux/i2c-gpio.h>
20#include <linux/atmel-mci.h>
21#include <linux/platform_data/crypto-atmel.h>
22
23#include <linux/platform_data/at91_adc.h>
24
25#include <linux/fb.h>
26#include <video/atmel_lcdc.h>
27
28#include <mach/at91sam9g45.h>
29#include <mach/at91sam9g45_matrix.h>
30#include <mach/at91_matrix.h>
31#include <mach/at91sam9_smc.h>
32#include <linux/platform_data/dma-atmel.h>
33#include <mach/atmel-mci.h>
34#include <mach/hardware.h>
35
36#include <media/atmel-isi.h>
37
38#include "board.h"
39#include "generic.h"
40#include "clock.h"
41#include "gpio.h"
42
43
44/* --------------------------------------------------------------------
45 * HDMAC - AHB DMA Controller
46 * -------------------------------------------------------------------- */
47
48#if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
49static u64 hdmac_dmamask = DMA_BIT_MASK(32);
50
51static struct resource hdmac_resources[] = {
52 [0] = {
53 .start = AT91SAM9G45_BASE_DMA,
54 .end = AT91SAM9G45_BASE_DMA + SZ_512 - 1,
55 .flags = IORESOURCE_MEM,
56 },
57 [1] = {
58 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_DMA,
59 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_DMA,
60 .flags = IORESOURCE_IRQ,
61 },
62};
63
64static struct platform_device at_hdmac_device = {
65 .name = "at91sam9g45_dma",
66 .id = -1,
67 .dev = {
68 .dma_mask = &hdmac_dmamask,
69 .coherent_dma_mask = DMA_BIT_MASK(32),
70 },
71 .resource = hdmac_resources,
72 .num_resources = ARRAY_SIZE(hdmac_resources),
73};
74
75void __init at91_add_device_hdmac(void)
76{
77 platform_device_register(&at_hdmac_device);
78}
79#else
80void __init at91_add_device_hdmac(void) {}
81#endif
82
83
84/* --------------------------------------------------------------------
85 * USB Host (OHCI)
86 * -------------------------------------------------------------------- */
87
88#if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
89static u64 ohci_dmamask = DMA_BIT_MASK(32);
90static struct at91_usbh_data usbh_ohci_data;
91
92static struct resource usbh_ohci_resources[] = {
93 [0] = {
94 .start = AT91SAM9G45_OHCI_BASE,
95 .end = AT91SAM9G45_OHCI_BASE + SZ_1M - 1,
96 .flags = IORESOURCE_MEM,
97 },
98 [1] = {
99 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_UHPHS,
100 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_UHPHS,
101 .flags = IORESOURCE_IRQ,
102 },
103};
104
105static struct platform_device at91_usbh_ohci_device = {
106 .name = "at91_ohci",
107 .id = -1,
108 .dev = {
109 .dma_mask = &ohci_dmamask,
110 .coherent_dma_mask = DMA_BIT_MASK(32),
111 .platform_data = &usbh_ohci_data,
112 },
113 .resource = usbh_ohci_resources,
114 .num_resources = ARRAY_SIZE(usbh_ohci_resources),
115};
116
117void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data)
118{
119 int i;
120
121 if (!data)
122 return;
123
124 /* Enable VBus control for UHP ports */
125 for (i = 0; i < data->ports; i++) {
126 if (gpio_is_valid(data->vbus_pin[i]))
127 at91_set_gpio_output(data->vbus_pin[i],
128 data->vbus_pin_active_low[i]);
129 }
130
131 /* Enable overcurrent notification */
132 for (i = 0; i < data->ports; i++) {
133 if (gpio_is_valid(data->overcurrent_pin[i]))
134 at91_set_gpio_input(data->overcurrent_pin[i], 1);
135 }
136
137 usbh_ohci_data = *data;
138 platform_device_register(&at91_usbh_ohci_device);
139}
140#else
141void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data) {}
142#endif
143
144
145/* --------------------------------------------------------------------
146 * USB Host HS (EHCI)
147 * Needs an OHCI host for low and full speed management
148 * -------------------------------------------------------------------- */
149
150#if defined(CONFIG_USB_EHCI_HCD) || defined(CONFIG_USB_EHCI_HCD_MODULE)
151static u64 ehci_dmamask = DMA_BIT_MASK(32);
152static struct at91_usbh_data usbh_ehci_data;
153
154static struct resource usbh_ehci_resources[] = {
155 [0] = {
156 .start = AT91SAM9G45_EHCI_BASE,
157 .end = AT91SAM9G45_EHCI_BASE + SZ_1M - 1,
158 .flags = IORESOURCE_MEM,
159 },
160 [1] = {
161 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_UHPHS,
162 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_UHPHS,
163 .flags = IORESOURCE_IRQ,
164 },
165};
166
167static struct platform_device at91_usbh_ehci_device = {
168 .name = "atmel-ehci",
169 .id = -1,
170 .dev = {
171 .dma_mask = &ehci_dmamask,
172 .coherent_dma_mask = DMA_BIT_MASK(32),
173 .platform_data = &usbh_ehci_data,
174 },
175 .resource = usbh_ehci_resources,
176 .num_resources = ARRAY_SIZE(usbh_ehci_resources),
177};
178
179void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data)
180{
181 int i;
182
183 if (!data)
184 return;
185
186 /* Enable VBus control for UHP ports */
187 for (i = 0; i < data->ports; i++) {
188 if (gpio_is_valid(data->vbus_pin[i]))
189 at91_set_gpio_output(data->vbus_pin[i],
190 data->vbus_pin_active_low[i]);
191 }
192
193 usbh_ehci_data = *data;
194 platform_device_register(&at91_usbh_ehci_device);
195}
196#else
197void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data) {}
198#endif
199
200
201/* --------------------------------------------------------------------
202 * USB HS Device (Gadget)
203 * -------------------------------------------------------------------- */
204
205#if defined(CONFIG_USB_ATMEL_USBA) || defined(CONFIG_USB_ATMEL_USBA_MODULE)
206static struct resource usba_udc_resources[] = {
207 [0] = {
208 .start = AT91SAM9G45_UDPHS_FIFO,
209 .end = AT91SAM9G45_UDPHS_FIFO + SZ_512K - 1,
210 .flags = IORESOURCE_MEM,
211 },
212 [1] = {
213 .start = AT91SAM9G45_BASE_UDPHS,
214 .end = AT91SAM9G45_BASE_UDPHS + SZ_1K - 1,
215 .flags = IORESOURCE_MEM,
216 },
217 [2] = {
218 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_UDPHS,
219 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_UDPHS,
220 .flags = IORESOURCE_IRQ,
221 },
222};
223
224#define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
225 [idx] = { \
226 .name = nam, \
227 .index = idx, \
228 .fifo_size = maxpkt, \
229 .nr_banks = maxbk, \
230 .can_dma = dma, \
231 .can_isoc = isoc, \
232 }
233
234static struct usba_ep_data usba_udc_ep[] __initdata = {
235 EP("ep0", 0, 64, 1, 0, 0),
236 EP("ep1", 1, 1024, 2, 1, 1),
237 EP("ep2", 2, 1024, 2, 1, 1),
238 EP("ep3", 3, 1024, 3, 1, 0),
239 EP("ep4", 4, 1024, 3, 1, 0),
240 EP("ep5", 5, 1024, 3, 1, 1),
241 EP("ep6", 6, 1024, 3, 1, 1),
242};
243
244#undef EP
245
246/*
247 * pdata doesn't have room for any endpoints, so we need to
248 * append room for the ones we need right after it.
249 */
250static struct {
251 struct usba_platform_data pdata;
252 struct usba_ep_data ep[7];
253} usba_udc_data;
254
255static struct platform_device at91_usba_udc_device = {
256 .name = "atmel_usba_udc",
257 .id = -1,
258 .dev = {
259 .platform_data = &usba_udc_data.pdata,
260 },
261 .resource = usba_udc_resources,
262 .num_resources = ARRAY_SIZE(usba_udc_resources),
263};
264
265void __init at91_add_device_usba(struct usba_platform_data *data)
266{
267 usba_udc_data.pdata.vbus_pin = -EINVAL;
268 usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
269 memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));
270
271 if (data && gpio_is_valid(data->vbus_pin)) {
272 at91_set_gpio_input(data->vbus_pin, 0);
273 at91_set_deglitch(data->vbus_pin, 1);
274 usba_udc_data.pdata.vbus_pin = data->vbus_pin;
275 }
276
277 /* Pullup pin is handled internally by USB device peripheral */
278
279 platform_device_register(&at91_usba_udc_device);
280}
281#else
282void __init at91_add_device_usba(struct usba_platform_data *data) {}
283#endif
284
285
286/* --------------------------------------------------------------------
287 * Ethernet
288 * -------------------------------------------------------------------- */
289
290#if defined(CONFIG_MACB) || defined(CONFIG_MACB_MODULE)
291static u64 eth_dmamask = DMA_BIT_MASK(32);
292static struct macb_platform_data eth_data;
293
294static struct resource eth_resources[] = {
295 [0] = {
296 .start = AT91SAM9G45_BASE_EMAC,
297 .end = AT91SAM9G45_BASE_EMAC + SZ_16K - 1,
298 .flags = IORESOURCE_MEM,
299 },
300 [1] = {
301 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_EMAC,
302 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_EMAC,
303 .flags = IORESOURCE_IRQ,
304 },
305};
306
307static struct platform_device at91sam9g45_eth_device = {
308 .name = "macb",
309 .id = -1,
310 .dev = {
311 .dma_mask = &eth_dmamask,
312 .coherent_dma_mask = DMA_BIT_MASK(32),
313 .platform_data = &eth_data,
314 },
315 .resource = eth_resources,
316 .num_resources = ARRAY_SIZE(eth_resources),
317};
318
319void __init at91_add_device_eth(struct macb_platform_data *data)
320{
321 if (!data)
322 return;
323
324 if (gpio_is_valid(data->phy_irq_pin)) {
325 at91_set_gpio_input(data->phy_irq_pin, 0);
326 at91_set_deglitch(data->phy_irq_pin, 1);
327 }
328
329 /* Pins used for MII and RMII */
330 at91_set_A_periph(AT91_PIN_PA17, 0); /* ETXCK_EREFCK */
331 at91_set_A_periph(AT91_PIN_PA15, 0); /* ERXDV */
332 at91_set_A_periph(AT91_PIN_PA12, 0); /* ERX0 */
333 at91_set_A_periph(AT91_PIN_PA13, 0); /* ERX1 */
334 at91_set_A_periph(AT91_PIN_PA16, 0); /* ERXER */
335 at91_set_A_periph(AT91_PIN_PA14, 0); /* ETXEN */
336 at91_set_A_periph(AT91_PIN_PA10, 0); /* ETX0 */
337 at91_set_A_periph(AT91_PIN_PA11, 0); /* ETX1 */
338 at91_set_A_periph(AT91_PIN_PA19, 0); /* EMDIO */
339 at91_set_A_periph(AT91_PIN_PA18, 0); /* EMDC */
340
341 if (!data->is_rmii) {
342 at91_set_B_periph(AT91_PIN_PA29, 0); /* ECRS */
343 at91_set_B_periph(AT91_PIN_PA30, 0); /* ECOL */
344 at91_set_B_periph(AT91_PIN_PA8, 0); /* ERX2 */
345 at91_set_B_periph(AT91_PIN_PA9, 0); /* ERX3 */
346 at91_set_B_periph(AT91_PIN_PA28, 0); /* ERXCK */
347 at91_set_B_periph(AT91_PIN_PA6, 0); /* ETX2 */
348 at91_set_B_periph(AT91_PIN_PA7, 0); /* ETX3 */
349 at91_set_B_periph(AT91_PIN_PA27, 0); /* ETXER */
350 }
351
352 eth_data = *data;
353 platform_device_register(&at91sam9g45_eth_device);
354}
355#else
356void __init at91_add_device_eth(struct macb_platform_data *data) {}
357#endif
358
359
360/* --------------------------------------------------------------------
361 * MMC / SD
362 * -------------------------------------------------------------------- */
363
364#if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
365static u64 mmc_dmamask = DMA_BIT_MASK(32);
366static struct mci_platform_data mmc0_data, mmc1_data;
367
368static struct resource mmc0_resources[] = {
369 [0] = {
370 .start = AT91SAM9G45_BASE_MCI0,
371 .end = AT91SAM9G45_BASE_MCI0 + SZ_16K - 1,
372 .flags = IORESOURCE_MEM,
373 },
374 [1] = {
375 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_MCI0,
376 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_MCI0,
377 .flags = IORESOURCE_IRQ,
378 },
379};
380
381static struct platform_device at91sam9g45_mmc0_device = {
382 .name = "atmel_mci",
383 .id = 0,
384 .dev = {
385 .dma_mask = &mmc_dmamask,
386 .coherent_dma_mask = DMA_BIT_MASK(32),
387 .platform_data = &mmc0_data,
388 },
389 .resource = mmc0_resources,
390 .num_resources = ARRAY_SIZE(mmc0_resources),
391};
392
393static struct resource mmc1_resources[] = {
394 [0] = {
395 .start = AT91SAM9G45_BASE_MCI1,
396 .end = AT91SAM9G45_BASE_MCI1 + SZ_16K - 1,
397 .flags = IORESOURCE_MEM,
398 },
399 [1] = {
400 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_MCI1,
401 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_MCI1,
402 .flags = IORESOURCE_IRQ,
403 },
404};
405
406static struct platform_device at91sam9g45_mmc1_device = {
407 .name = "atmel_mci",
408 .id = 1,
409 .dev = {
410 .dma_mask = &mmc_dmamask,
411 .coherent_dma_mask = DMA_BIT_MASK(32),
412 .platform_data = &mmc1_data,
413 },
414 .resource = mmc1_resources,
415 .num_resources = ARRAY_SIZE(mmc1_resources),
416};
417
418/* Consider only one slot : slot 0 */
419void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
420{
421
422 if (!data)
423 return;
424
425 /* Must have at least one usable slot */
426 if (!data->slot[0].bus_width)
427 return;
428
429#if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
430 {
431 struct at_dma_slave *atslave;
432 struct mci_dma_data *alt_atslave;
433
434 alt_atslave = kzalloc(sizeof(struct mci_dma_data), GFP_KERNEL);
435 atslave = &alt_atslave->sdata;
436
437 /* DMA slave channel configuration */
438 atslave->dma_dev = &at_hdmac_device.dev;
439 atslave->cfg = ATC_FIFOCFG_HALFFIFO
440 | ATC_SRC_H2SEL_HW | ATC_DST_H2SEL_HW;
441 if (mmc_id == 0) /* MCI0 */
442 atslave->cfg |= ATC_SRC_PER(AT_DMA_ID_MCI0)
443 | ATC_DST_PER(AT_DMA_ID_MCI0);
444
445 else /* MCI1 */
446 atslave->cfg |= ATC_SRC_PER(AT_DMA_ID_MCI1)
447 | ATC_DST_PER(AT_DMA_ID_MCI1);
448
449 data->dma_slave = alt_atslave;
450 }
451#endif
452
453
454 /* input/irq */
455 if (gpio_is_valid(data->slot[0].detect_pin)) {
456 at91_set_gpio_input(data->slot[0].detect_pin, 1);
457 at91_set_deglitch(data->slot[0].detect_pin, 1);
458 }
459 if (gpio_is_valid(data->slot[0].wp_pin))
460 at91_set_gpio_input(data->slot[0].wp_pin, 1);
461
462 if (mmc_id == 0) { /* MCI0 */
463
464 /* CLK */
465 at91_set_A_periph(AT91_PIN_PA0, 0);
466
467 /* CMD */
468 at91_set_A_periph(AT91_PIN_PA1, 1);
469
470 /* DAT0, maybe DAT1..DAT3 and maybe DAT4..DAT7 */
471 at91_set_A_periph(AT91_PIN_PA2, 1);
472 if (data->slot[0].bus_width == 4) {
473 at91_set_A_periph(AT91_PIN_PA3, 1);
474 at91_set_A_periph(AT91_PIN_PA4, 1);
475 at91_set_A_periph(AT91_PIN_PA5, 1);
476 if (data->slot[0].bus_width == 8) {
477 at91_set_A_periph(AT91_PIN_PA6, 1);
478 at91_set_A_periph(AT91_PIN_PA7, 1);
479 at91_set_A_periph(AT91_PIN_PA8, 1);
480 at91_set_A_periph(AT91_PIN_PA9, 1);
481 }
482 }
483
484 mmc0_data = *data;
485 platform_device_register(&at91sam9g45_mmc0_device);
486
487 } else { /* MCI1 */
488
489 /* CLK */
490 at91_set_A_periph(AT91_PIN_PA31, 0);
491
492 /* CMD */
493 at91_set_A_periph(AT91_PIN_PA22, 1);
494
495 /* DAT0, maybe DAT1..DAT3 and maybe DAT4..DAT7 */
496 at91_set_A_periph(AT91_PIN_PA23, 1);
497 if (data->slot[0].bus_width == 4) {
498 at91_set_A_periph(AT91_PIN_PA24, 1);
499 at91_set_A_periph(AT91_PIN_PA25, 1);
500 at91_set_A_periph(AT91_PIN_PA26, 1);
501 if (data->slot[0].bus_width == 8) {
502 at91_set_A_periph(AT91_PIN_PA27, 1);
503 at91_set_A_periph(AT91_PIN_PA28, 1);
504 at91_set_A_periph(AT91_PIN_PA29, 1);
505 at91_set_A_periph(AT91_PIN_PA30, 1);
506 }
507 }
508
509 mmc1_data = *data;
510 platform_device_register(&at91sam9g45_mmc1_device);
511
512 }
513}
514#else
515void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
516#endif
517
518
519/* --------------------------------------------------------------------
520 * NAND / SmartMedia
521 * -------------------------------------------------------------------- */
522
523#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
524static struct atmel_nand_data nand_data;
525
526#define NAND_BASE AT91_CHIPSELECT_3
527
528static struct resource nand_resources[] = {
529 [0] = {
530 .start = NAND_BASE,
531 .end = NAND_BASE + SZ_256M - 1,
532 .flags = IORESOURCE_MEM,
533 },
534 [1] = {
535 .start = AT91SAM9G45_BASE_ECC,
536 .end = AT91SAM9G45_BASE_ECC + SZ_512 - 1,
537 .flags = IORESOURCE_MEM,
538 }
539};
540
541static struct platform_device at91sam9g45_nand_device = {
542 .name = "atmel_nand",
543 .id = -1,
544 .dev = {
545 .platform_data = &nand_data,
546 },
547 .resource = nand_resources,
548 .num_resources = ARRAY_SIZE(nand_resources),
549};
550
551void __init at91_add_device_nand(struct atmel_nand_data *data)
552{
553 unsigned long csa;
554
555 if (!data)
556 return;
557
558 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
559 at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
560
561 /* enable pin */
562 if (gpio_is_valid(data->enable_pin))
563 at91_set_gpio_output(data->enable_pin, 1);
564
565 /* ready/busy pin */
566 if (gpio_is_valid(data->rdy_pin))
567 at91_set_gpio_input(data->rdy_pin, 1);
568
569 /* card detect pin */
570 if (gpio_is_valid(data->det_pin))
571 at91_set_gpio_input(data->det_pin, 1);
572
573 nand_data = *data;
574 platform_device_register(&at91sam9g45_nand_device);
575}
576#else
577void __init at91_add_device_nand(struct atmel_nand_data *data) {}
578#endif
579
580
581/* --------------------------------------------------------------------
582 * TWI (i2c)
583 * -------------------------------------------------------------------- */
584
585/*
586 * Prefer the GPIO code since the TWI controller isn't robust
587 * (gets overruns and underruns under load) and can only issue
588 * repeated STARTs in one scenario (the driver doesn't yet handle them).
589 */
590#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
591static struct i2c_gpio_platform_data pdata_i2c0 = {
592 .sda_pin = AT91_PIN_PA20,
593 .sda_is_open_drain = 1,
594 .scl_pin = AT91_PIN_PA21,
595 .scl_is_open_drain = 1,
596 .udelay = 5, /* ~100 kHz */
597};
598
599static struct platform_device at91sam9g45_twi0_device = {
600 .name = "i2c-gpio",
601 .id = 0,
602 .dev.platform_data = &pdata_i2c0,
603};
604
605static struct i2c_gpio_platform_data pdata_i2c1 = {
606 .sda_pin = AT91_PIN_PB10,
607 .sda_is_open_drain = 1,
608 .scl_pin = AT91_PIN_PB11,
609 .scl_is_open_drain = 1,
610 .udelay = 5, /* ~100 kHz */
611};
612
613static struct platform_device at91sam9g45_twi1_device = {
614 .name = "i2c-gpio",
615 .id = 1,
616 .dev.platform_data = &pdata_i2c1,
617};
618
619void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
620{
621 i2c_register_board_info(i2c_id, devices, nr_devices);
622
623 if (i2c_id == 0) {
624 at91_set_GPIO_periph(AT91_PIN_PA20, 1); /* TWD (SDA) */
625 at91_set_multi_drive(AT91_PIN_PA20, 1);
626
627 at91_set_GPIO_periph(AT91_PIN_PA21, 1); /* TWCK (SCL) */
628 at91_set_multi_drive(AT91_PIN_PA21, 1);
629
630 platform_device_register(&at91sam9g45_twi0_device);
631 } else {
632 at91_set_GPIO_periph(AT91_PIN_PB10, 1); /* TWD (SDA) */
633 at91_set_multi_drive(AT91_PIN_PB10, 1);
634
635 at91_set_GPIO_periph(AT91_PIN_PB11, 1); /* TWCK (SCL) */
636 at91_set_multi_drive(AT91_PIN_PB11, 1);
637
638 platform_device_register(&at91sam9g45_twi1_device);
639 }
640}
641
642#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
643static struct resource twi0_resources[] = {
644 [0] = {
645 .start = AT91SAM9G45_BASE_TWI0,
646 .end = AT91SAM9G45_BASE_TWI0 + SZ_16K - 1,
647 .flags = IORESOURCE_MEM,
648 },
649 [1] = {
650 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_TWI0,
651 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_TWI0,
652 .flags = IORESOURCE_IRQ,
653 },
654};
655
656static struct platform_device at91sam9g45_twi0_device = {
657 .name = "i2c-at91sam9g10",
658 .id = 0,
659 .resource = twi0_resources,
660 .num_resources = ARRAY_SIZE(twi0_resources),
661};
662
663static struct resource twi1_resources[] = {
664 [0] = {
665 .start = AT91SAM9G45_BASE_TWI1,
666 .end = AT91SAM9G45_BASE_TWI1 + SZ_16K - 1,
667 .flags = IORESOURCE_MEM,
668 },
669 [1] = {
670 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_TWI1,
671 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_TWI1,
672 .flags = IORESOURCE_IRQ,
673 },
674};
675
676static struct platform_device at91sam9g45_twi1_device = {
677 .name = "i2c-at91sam9g10",
678 .id = 1,
679 .resource = twi1_resources,
680 .num_resources = ARRAY_SIZE(twi1_resources),
681};
682
683void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices)
684{
685 i2c_register_board_info(i2c_id, devices, nr_devices);
686
687 /* pins used for TWI interface */
688 if (i2c_id == 0) {
689 at91_set_A_periph(AT91_PIN_PA20, 0); /* TWD */
690 at91_set_A_periph(AT91_PIN_PA21, 0); /* TWCK */
691
692 platform_device_register(&at91sam9g45_twi0_device);
693 } else {
694 at91_set_A_periph(AT91_PIN_PB10, 0); /* TWD */
695 at91_set_A_periph(AT91_PIN_PB11, 0); /* TWCK */
696
697 platform_device_register(&at91sam9g45_twi1_device);
698 }
699}
700#else
701void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices) {}
702#endif
703
704
705/* --------------------------------------------------------------------
706 * SPI
707 * -------------------------------------------------------------------- */
708
709#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
710static u64 spi_dmamask = DMA_BIT_MASK(32);
711
712static struct resource spi0_resources[] = {
713 [0] = {
714 .start = AT91SAM9G45_BASE_SPI0,
715 .end = AT91SAM9G45_BASE_SPI0 + SZ_16K - 1,
716 .flags = IORESOURCE_MEM,
717 },
718 [1] = {
719 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_SPI0,
720 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_SPI0,
721 .flags = IORESOURCE_IRQ,
722 },
723};
724
725static struct platform_device at91sam9g45_spi0_device = {
726 .name = "atmel_spi",
727 .id = 0,
728 .dev = {
729 .dma_mask = &spi_dmamask,
730 .coherent_dma_mask = DMA_BIT_MASK(32),
731 },
732 .resource = spi0_resources,
733 .num_resources = ARRAY_SIZE(spi0_resources),
734};
735
736static const unsigned spi0_standard_cs[4] = { AT91_PIN_PB3, AT91_PIN_PB18, AT91_PIN_PB19, AT91_PIN_PD27 };
737
738static struct resource spi1_resources[] = {
739 [0] = {
740 .start = AT91SAM9G45_BASE_SPI1,
741 .end = AT91SAM9G45_BASE_SPI1 + SZ_16K - 1,
742 .flags = IORESOURCE_MEM,
743 },
744 [1] = {
745 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_SPI1,
746 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_SPI1,
747 .flags = IORESOURCE_IRQ,
748 },
749};
750
751static struct platform_device at91sam9g45_spi1_device = {
752 .name = "atmel_spi",
753 .id = 1,
754 .dev = {
755 .dma_mask = &spi_dmamask,
756 .coherent_dma_mask = DMA_BIT_MASK(32),
757 },
758 .resource = spi1_resources,
759 .num_resources = ARRAY_SIZE(spi1_resources),
760};
761
762static const unsigned spi1_standard_cs[4] = { AT91_PIN_PB17, AT91_PIN_PD28, AT91_PIN_PD18, AT91_PIN_PD19 };
763
764void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
765{
766 int i;
767 unsigned long cs_pin;
768 short enable_spi0 = 0;
769 short enable_spi1 = 0;
770
771 /* Choose SPI chip-selects */
772 for (i = 0; i < nr_devices; i++) {
773 if (devices[i].controller_data)
774 cs_pin = (unsigned long) devices[i].controller_data;
775 else if (devices[i].bus_num == 0)
776 cs_pin = spi0_standard_cs[devices[i].chip_select];
777 else
778 cs_pin = spi1_standard_cs[devices[i].chip_select];
779
780 if (!gpio_is_valid(cs_pin))
781 continue;
782
783 if (devices[i].bus_num == 0)
784 enable_spi0 = 1;
785 else
786 enable_spi1 = 1;
787
788 /* enable chip-select pin */
789 at91_set_gpio_output(cs_pin, 1);
790
791 /* pass chip-select pin to driver */
792 devices[i].controller_data = (void *) cs_pin;
793 }
794
795 spi_register_board_info(devices, nr_devices);
796
797 /* Configure SPI bus(es) */
798 if (enable_spi0) {
799 at91_set_A_periph(AT91_PIN_PB0, 0); /* SPI0_MISO */
800 at91_set_A_periph(AT91_PIN_PB1, 0); /* SPI0_MOSI */
801 at91_set_A_periph(AT91_PIN_PB2, 0); /* SPI0_SPCK */
802
803 platform_device_register(&at91sam9g45_spi0_device);
804 }
805 if (enable_spi1) {
806 at91_set_A_periph(AT91_PIN_PB14, 0); /* SPI1_MISO */
807 at91_set_A_periph(AT91_PIN_PB15, 0); /* SPI1_MOSI */
808 at91_set_A_periph(AT91_PIN_PB16, 0); /* SPI1_SPCK */
809
810 platform_device_register(&at91sam9g45_spi1_device);
811 }
812}
813#else
814void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
815#endif
816
817
818/* --------------------------------------------------------------------
819 * AC97
820 * -------------------------------------------------------------------- */
821
822#if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
823static u64 ac97_dmamask = DMA_BIT_MASK(32);
824static struct ac97c_platform_data ac97_data;
825
826static struct resource ac97_resources[] = {
827 [0] = {
828 .start = AT91SAM9G45_BASE_AC97C,
829 .end = AT91SAM9G45_BASE_AC97C + SZ_16K - 1,
830 .flags = IORESOURCE_MEM,
831 },
832 [1] = {
833 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_AC97C,
834 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_AC97C,
835 .flags = IORESOURCE_IRQ,
836 },
837};
838
839static struct platform_device at91sam9g45_ac97_device = {
840 .name = "atmel_ac97c",
841 .id = 0,
842 .dev = {
843 .dma_mask = &ac97_dmamask,
844 .coherent_dma_mask = DMA_BIT_MASK(32),
845 .platform_data = &ac97_data,
846 },
847 .resource = ac97_resources,
848 .num_resources = ARRAY_SIZE(ac97_resources),
849};
850
851void __init at91_add_device_ac97(struct ac97c_platform_data *data)
852{
853 if (!data)
854 return;
855
856 at91_set_A_periph(AT91_PIN_PD8, 0); /* AC97FS */
857 at91_set_A_periph(AT91_PIN_PD9, 0); /* AC97CK */
858 at91_set_A_periph(AT91_PIN_PD7, 0); /* AC97TX */
859 at91_set_A_periph(AT91_PIN_PD6, 0); /* AC97RX */
860
861 /* reset */
862 if (gpio_is_valid(data->reset_pin))
863 at91_set_gpio_output(data->reset_pin, 0);
864
865 ac97_data = *data;
866 platform_device_register(&at91sam9g45_ac97_device);
867}
868#else
869void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
870#endif
871
872/* --------------------------------------------------------------------
873 * Image Sensor Interface
874 * -------------------------------------------------------------------- */
875#if defined(CONFIG_VIDEO_ATMEL_ISI) || defined(CONFIG_VIDEO_ATMEL_ISI_MODULE)
876static u64 isi_dmamask = DMA_BIT_MASK(32);
877static struct isi_platform_data isi_data;
878
879struct resource isi_resources[] = {
880 [0] = {
881 .start = AT91SAM9G45_BASE_ISI,
882 .end = AT91SAM9G45_BASE_ISI + SZ_16K - 1,
883 .flags = IORESOURCE_MEM,
884 },
885 [1] = {
886 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_ISI,
887 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_ISI,
888 .flags = IORESOURCE_IRQ,
889 },
890};
891
892static struct platform_device at91sam9g45_isi_device = {
893 .name = "atmel_isi",
894 .id = 0,
895 .dev = {
896 .dma_mask = &isi_dmamask,
897 .coherent_dma_mask = DMA_BIT_MASK(32),
898 .platform_data = &isi_data,
899 },
900 .resource = isi_resources,
901 .num_resources = ARRAY_SIZE(isi_resources),
902};
903
904static struct clk_lookup isi_mck_lookups[] = {
905 CLKDEV_CON_DEV_ID("isi_mck", "atmel_isi.0", NULL),
906};
907
908void __init at91_add_device_isi(struct isi_platform_data *data,
909 bool use_pck_as_mck)
910{
911 struct clk *pck;
912 struct clk *parent;
913
914 if (!data)
915 return;
916 isi_data = *data;
917
918 at91_set_A_periph(AT91_PIN_PB20, 0); /* ISI_D0 */
919 at91_set_A_periph(AT91_PIN_PB21, 0); /* ISI_D1 */
920 at91_set_A_periph(AT91_PIN_PB22, 0); /* ISI_D2 */
921 at91_set_A_periph(AT91_PIN_PB23, 0); /* ISI_D3 */
922 at91_set_A_periph(AT91_PIN_PB24, 0); /* ISI_D4 */
923 at91_set_A_periph(AT91_PIN_PB25, 0); /* ISI_D5 */
924 at91_set_A_periph(AT91_PIN_PB26, 0); /* ISI_D6 */
925 at91_set_A_periph(AT91_PIN_PB27, 0); /* ISI_D7 */
926 at91_set_A_periph(AT91_PIN_PB28, 0); /* ISI_PCK */
927 at91_set_A_periph(AT91_PIN_PB30, 0); /* ISI_HSYNC */
928 at91_set_A_periph(AT91_PIN_PB29, 0); /* ISI_VSYNC */
929 at91_set_B_periph(AT91_PIN_PB8, 0); /* ISI_PD8 */
930 at91_set_B_periph(AT91_PIN_PB9, 0); /* ISI_PD9 */
931 at91_set_B_periph(AT91_PIN_PB10, 0); /* ISI_PD10 */
932 at91_set_B_periph(AT91_PIN_PB11, 0); /* ISI_PD11 */
933
934 platform_device_register(&at91sam9g45_isi_device);
935
936 if (use_pck_as_mck) {
937 at91_set_B_periph(AT91_PIN_PB31, 0); /* ISI_MCK (PCK1) */
938
939 pck = clk_get(NULL, "pck1");
940 parent = clk_get(NULL, "plla");
941
942 BUG_ON(IS_ERR(pck) || IS_ERR(parent));
943
944 if (clk_set_parent(pck, parent)) {
945 pr_err("Failed to set PCK's parent\n");
946 } else {
947 /* Register PCK as ISI_MCK */
948 isi_mck_lookups[0].clk = pck;
949 clkdev_add_table(isi_mck_lookups,
950 ARRAY_SIZE(isi_mck_lookups));
951 }
952
953 clk_put(pck);
954 clk_put(parent);
955 }
956}
957#else
958void __init at91_add_device_isi(struct isi_platform_data *data,
959 bool use_pck_as_mck) {}
960#endif
961
962
963/* --------------------------------------------------------------------
964 * LCD Controller
965 * -------------------------------------------------------------------- */
966
967#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
968static u64 lcdc_dmamask = DMA_BIT_MASK(32);
969static struct atmel_lcdfb_pdata lcdc_data;
970
971static struct resource lcdc_resources[] = {
972 [0] = {
973 .start = AT91SAM9G45_LCDC_BASE,
974 .end = AT91SAM9G45_LCDC_BASE + SZ_4K - 1,
975 .flags = IORESOURCE_MEM,
976 },
977 [1] = {
978 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_LCDC,
979 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_LCDC,
980 .flags = IORESOURCE_IRQ,
981 },
982};
983
984static struct platform_device at91_lcdc_device = {
985 .id = 0,
986 .dev = {
987 .dma_mask = &lcdc_dmamask,
988 .coherent_dma_mask = DMA_BIT_MASK(32),
989 .platform_data = &lcdc_data,
990 },
991 .resource = lcdc_resources,
992 .num_resources = ARRAY_SIZE(lcdc_resources),
993};
994
995void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data)
996{
997 if (!data)
998 return;
999
1000 if (cpu_is_at91sam9g45es())
1001 at91_lcdc_device.name = "at91sam9g45es-lcdfb";
1002 else
1003 at91_lcdc_device.name = "at91sam9g45-lcdfb";
1004
1005 at91_set_A_periph(AT91_PIN_PE0, 0); /* LCDDPWR */
1006
1007 at91_set_A_periph(AT91_PIN_PE2, 0); /* LCDCC */
1008 at91_set_A_periph(AT91_PIN_PE3, 0); /* LCDVSYNC */
1009 at91_set_A_periph(AT91_PIN_PE4, 0); /* LCDHSYNC */
1010 at91_set_A_periph(AT91_PIN_PE5, 0); /* LCDDOTCK */
1011 at91_set_A_periph(AT91_PIN_PE6, 0); /* LCDDEN */
1012 at91_set_A_periph(AT91_PIN_PE7, 0); /* LCDD0 */
1013 at91_set_A_periph(AT91_PIN_PE8, 0); /* LCDD1 */
1014 at91_set_A_periph(AT91_PIN_PE9, 0); /* LCDD2 */
1015 at91_set_A_periph(AT91_PIN_PE10, 0); /* LCDD3 */
1016 at91_set_A_periph(AT91_PIN_PE11, 0); /* LCDD4 */
1017 at91_set_A_periph(AT91_PIN_PE12, 0); /* LCDD5 */
1018 at91_set_A_periph(AT91_PIN_PE13, 0); /* LCDD6 */
1019 at91_set_A_periph(AT91_PIN_PE14, 0); /* LCDD7 */
1020 at91_set_A_periph(AT91_PIN_PE15, 0); /* LCDD8 */
1021 at91_set_A_periph(AT91_PIN_PE16, 0); /* LCDD9 */
1022 at91_set_A_periph(AT91_PIN_PE17, 0); /* LCDD10 */
1023 at91_set_A_periph(AT91_PIN_PE18, 0); /* LCDD11 */
1024 at91_set_A_periph(AT91_PIN_PE19, 0); /* LCDD12 */
1025 at91_set_A_periph(AT91_PIN_PE20, 0); /* LCDD13 */
1026 at91_set_A_periph(AT91_PIN_PE21, 0); /* LCDD14 */
1027 at91_set_A_periph(AT91_PIN_PE22, 0); /* LCDD15 */
1028 at91_set_A_periph(AT91_PIN_PE23, 0); /* LCDD16 */
1029 at91_set_A_periph(AT91_PIN_PE24, 0); /* LCDD17 */
1030 at91_set_A_periph(AT91_PIN_PE25, 0); /* LCDD18 */
1031 at91_set_A_periph(AT91_PIN_PE26, 0); /* LCDD19 */
1032 at91_set_A_periph(AT91_PIN_PE27, 0); /* LCDD20 */
1033 at91_set_A_periph(AT91_PIN_PE28, 0); /* LCDD21 */
1034 at91_set_A_periph(AT91_PIN_PE29, 0); /* LCDD22 */
1035 at91_set_A_periph(AT91_PIN_PE30, 0); /* LCDD23 */
1036
1037 lcdc_data = *data;
1038 platform_device_register(&at91_lcdc_device);
1039}
1040#else
1041void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data) {}
1042#endif
1043
1044
1045/* --------------------------------------------------------------------
1046 * Timer/Counter block
1047 * -------------------------------------------------------------------- */
1048
1049#ifdef CONFIG_ATMEL_TCLIB
1050static struct resource tcb0_resources[] = {
1051 [0] = {
1052 .start = AT91SAM9G45_BASE_TCB0,
1053 .end = AT91SAM9G45_BASE_TCB0 + SZ_256 - 1,
1054 .flags = IORESOURCE_MEM,
1055 },
1056 [1] = {
1057 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_TCB,
1058 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_TCB,
1059 .flags = IORESOURCE_IRQ,
1060 },
1061};
1062
1063static struct platform_device at91sam9g45_tcb0_device = {
1064 .name = "atmel_tcb",
1065 .id = 0,
1066 .resource = tcb0_resources,
1067 .num_resources = ARRAY_SIZE(tcb0_resources),
1068};
1069
1070/* TCB1 begins with TC3 */
1071static struct resource tcb1_resources[] = {
1072 [0] = {
1073 .start = AT91SAM9G45_BASE_TCB1,
1074 .end = AT91SAM9G45_BASE_TCB1 + SZ_256 - 1,
1075 .flags = IORESOURCE_MEM,
1076 },
1077 [1] = {
1078 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_TCB,
1079 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_TCB,
1080 .flags = IORESOURCE_IRQ,
1081 },
1082};
1083
1084static struct platform_device at91sam9g45_tcb1_device = {
1085 .name = "atmel_tcb",
1086 .id = 1,
1087 .resource = tcb1_resources,
1088 .num_resources = ARRAY_SIZE(tcb1_resources),
1089};
1090
1091static void __init at91_add_device_tc(void)
1092{
1093 platform_device_register(&at91sam9g45_tcb0_device);
1094 platform_device_register(&at91sam9g45_tcb1_device);
1095}
1096#else
1097static void __init at91_add_device_tc(void) { }
1098#endif
1099
1100
1101/* --------------------------------------------------------------------
1102 * RTC
1103 * -------------------------------------------------------------------- */
1104
1105#if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
1106static struct resource rtc_resources[] = {
1107 [0] = {
1108 .start = AT91SAM9G45_BASE_RTC,
1109 .end = AT91SAM9G45_BASE_RTC + SZ_256 - 1,
1110 .flags = IORESOURCE_MEM,
1111 },
1112 [1] = {
1113 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
1114 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
1115 .flags = IORESOURCE_IRQ,
1116 },
1117};
1118
1119static struct platform_device at91sam9g45_rtc_device = {
1120 .name = "at91_rtc",
1121 .id = -1,
1122 .resource = rtc_resources,
1123 .num_resources = ARRAY_SIZE(rtc_resources),
1124};
1125
1126static void __init at91_add_device_rtc(void)
1127{
1128 platform_device_register(&at91sam9g45_rtc_device);
1129}
1130#else
1131static void __init at91_add_device_rtc(void) {}
1132#endif
1133
1134
1135/* --------------------------------------------------------------------
1136 * ADC and touchscreen
1137 * -------------------------------------------------------------------- */
1138
1139#if IS_ENABLED(CONFIG_AT91_ADC)
1140static struct at91_adc_data adc_data;
1141
1142static struct resource adc_resources[] = {
1143 [0] = {
1144 .start = AT91SAM9G45_BASE_TSC,
1145 .end = AT91SAM9G45_BASE_TSC + SZ_16K - 1,
1146 .flags = IORESOURCE_MEM,
1147 },
1148 [1] = {
1149 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_TSC,
1150 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_TSC,
1151 .flags = IORESOURCE_IRQ,
1152 }
1153};
1154
1155static struct platform_device at91_adc_device = {
1156 .name = "at91sam9g45-adc",
1157 .id = -1,
1158 .dev = {
1159 .platform_data = &adc_data,
1160 },
1161 .resource = adc_resources,
1162 .num_resources = ARRAY_SIZE(adc_resources),
1163};
1164
1165static struct at91_adc_trigger at91_adc_triggers[] = {
1166 [0] = {
1167 .name = "external-rising",
1168 .value = 1,
1169 .is_external = true,
1170 },
1171 [1] = {
1172 .name = "external-falling",
1173 .value = 2,
1174 .is_external = true,
1175 },
1176 [2] = {
1177 .name = "external-any",
1178 .value = 3,
1179 .is_external = true,
1180 },
1181 [3] = {
1182 .name = "continuous",
1183 .value = 6,
1184 .is_external = false,
1185 },
1186};
1187
1188void __init at91_add_device_adc(struct at91_adc_data *data)
1189{
1190 if (!data)
1191 return;
1192
1193 if (test_bit(0, &data->channels_used))
1194 at91_set_gpio_input(AT91_PIN_PD20, 0);
1195 if (test_bit(1, &data->channels_used))
1196 at91_set_gpio_input(AT91_PIN_PD21, 0);
1197 if (test_bit(2, &data->channels_used))
1198 at91_set_gpio_input(AT91_PIN_PD22, 0);
1199 if (test_bit(3, &data->channels_used))
1200 at91_set_gpio_input(AT91_PIN_PD23, 0);
1201 if (test_bit(4, &data->channels_used))
1202 at91_set_gpio_input(AT91_PIN_PD24, 0);
1203 if (test_bit(5, &data->channels_used))
1204 at91_set_gpio_input(AT91_PIN_PD25, 0);
1205 if (test_bit(6, &data->channels_used))
1206 at91_set_gpio_input(AT91_PIN_PD26, 0);
1207 if (test_bit(7, &data->channels_used))
1208 at91_set_gpio_input(AT91_PIN_PD27, 0);
1209
1210 if (data->use_external_triggers)
1211 at91_set_A_periph(AT91_PIN_PD28, 0);
1212
1213 data->startup_time = 40;
1214 data->trigger_number = 4;
1215 data->trigger_list = at91_adc_triggers;
1216
1217 adc_data = *data;
1218 platform_device_register(&at91_adc_device);
1219}
1220#else
1221void __init at91_add_device_adc(struct at91_adc_data *data) {}
1222#endif
1223
1224/* --------------------------------------------------------------------
1225 * RTT
1226 * -------------------------------------------------------------------- */
1227
1228static struct resource rtt_resources[] = {
1229 {
1230 .start = AT91SAM9G45_BASE_RTT,
1231 .end = AT91SAM9G45_BASE_RTT + SZ_16 - 1,
1232 .flags = IORESOURCE_MEM,
1233 }, {
1234 .flags = IORESOURCE_MEM,
1235 }, {
1236 .flags = IORESOURCE_IRQ,
1237 }
1238};
1239
1240static struct platform_device at91sam9g45_rtt_device = {
1241 .name = "at91_rtt",
1242 .id = 0,
1243 .resource = rtt_resources,
1244};
1245
1246#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
1247static void __init at91_add_device_rtt_rtc(void)
1248{
1249 at91sam9g45_rtt_device.name = "rtc-at91sam9";
1250 /*
1251 * The second resource is needed:
1252 * GPBR will serve as the storage for RTC time offset
1253 */
1254 at91sam9g45_rtt_device.num_resources = 3;
1255 rtt_resources[1].start = AT91SAM9G45_BASE_GPBR +
1256 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
1257 rtt_resources[1].end = rtt_resources[1].start + 3;
1258 rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
1259 rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
1260}
1261#else
1262static void __init at91_add_device_rtt_rtc(void)
1263{
1264 /* Only one resource is needed: RTT not used as RTC */
1265 at91sam9g45_rtt_device.num_resources = 1;
1266}
1267#endif
1268
1269static void __init at91_add_device_rtt(void)
1270{
1271 at91_add_device_rtt_rtc();
1272 platform_device_register(&at91sam9g45_rtt_device);
1273}
1274
1275
1276/* --------------------------------------------------------------------
1277 * TRNG
1278 * -------------------------------------------------------------------- */
1279
1280#if defined(CONFIG_HW_RANDOM_ATMEL) || defined(CONFIG_HW_RANDOM_ATMEL_MODULE)
1281static struct resource trng_resources[] = {
1282 {
1283 .start = AT91SAM9G45_BASE_TRNG,
1284 .end = AT91SAM9G45_BASE_TRNG + SZ_16K - 1,
1285 .flags = IORESOURCE_MEM,
1286 },
1287};
1288
1289static struct platform_device at91sam9g45_trng_device = {
1290 .name = "atmel-trng",
1291 .id = -1,
1292 .resource = trng_resources,
1293 .num_resources = ARRAY_SIZE(trng_resources),
1294};
1295
1296static void __init at91_add_device_trng(void)
1297{
1298 platform_device_register(&at91sam9g45_trng_device);
1299}
1300#else
1301static void __init at91_add_device_trng(void) {}
1302#endif
1303
1304/* --------------------------------------------------------------------
1305 * Watchdog
1306 * -------------------------------------------------------------------- */
1307
1308#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
1309static struct resource wdt_resources[] = {
1310 {
1311 .start = AT91SAM9G45_BASE_WDT,
1312 .end = AT91SAM9G45_BASE_WDT + SZ_16 - 1,
1313 .flags = IORESOURCE_MEM,
1314 }
1315};
1316
1317static struct platform_device at91sam9g45_wdt_device = {
1318 .name = "at91_wdt",
1319 .id = -1,
1320 .resource = wdt_resources,
1321 .num_resources = ARRAY_SIZE(wdt_resources),
1322};
1323
1324static void __init at91_add_device_watchdog(void)
1325{
1326 platform_device_register(&at91sam9g45_wdt_device);
1327}
1328#else
1329static void __init at91_add_device_watchdog(void) {}
1330#endif
1331
1332
1333/* --------------------------------------------------------------------
1334 * PWM
1335 * --------------------------------------------------------------------*/
1336
1337#if IS_ENABLED(CONFIG_PWM_ATMEL)
1338static struct resource pwm_resources[] = {
1339 [0] = {
1340 .start = AT91SAM9G45_BASE_PWMC,
1341 .end = AT91SAM9G45_BASE_PWMC + SZ_16K - 1,
1342 .flags = IORESOURCE_MEM,
1343 },
1344 [1] = {
1345 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_PWMC,
1346 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_PWMC,
1347 .flags = IORESOURCE_IRQ,
1348 },
1349};
1350
1351static struct platform_device at91sam9g45_pwm0_device = {
1352 .name = "at91sam9rl-pwm",
1353 .id = -1,
1354 .resource = pwm_resources,
1355 .num_resources = ARRAY_SIZE(pwm_resources),
1356};
1357
1358void __init at91_add_device_pwm(u32 mask)
1359{
1360 if (mask & (1 << AT91_PWM0))
1361 at91_set_B_periph(AT91_PIN_PD24, 1); /* enable PWM0 */
1362
1363 if (mask & (1 << AT91_PWM1))
1364 at91_set_B_periph(AT91_PIN_PD31, 1); /* enable PWM1 */
1365
1366 if (mask & (1 << AT91_PWM2))
1367 at91_set_B_periph(AT91_PIN_PD26, 1); /* enable PWM2 */
1368
1369 if (mask & (1 << AT91_PWM3))
1370 at91_set_B_periph(AT91_PIN_PD0, 1); /* enable PWM3 */
1371
1372 platform_device_register(&at91sam9g45_pwm0_device);
1373}
1374#else
1375void __init at91_add_device_pwm(u32 mask) {}
1376#endif
1377
1378
1379/* --------------------------------------------------------------------
1380 * SSC -- Synchronous Serial Controller
1381 * -------------------------------------------------------------------- */
1382
1383#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
1384static u64 ssc0_dmamask = DMA_BIT_MASK(32);
1385
1386static struct resource ssc0_resources[] = {
1387 [0] = {
1388 .start = AT91SAM9G45_BASE_SSC0,
1389 .end = AT91SAM9G45_BASE_SSC0 + SZ_16K - 1,
1390 .flags = IORESOURCE_MEM,
1391 },
1392 [1] = {
1393 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_SSC0,
1394 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_SSC0,
1395 .flags = IORESOURCE_IRQ,
1396 },
1397};
1398
1399static struct platform_device at91sam9g45_ssc0_device = {
1400 .name = "at91sam9g45_ssc",
1401 .id = 0,
1402 .dev = {
1403 .dma_mask = &ssc0_dmamask,
1404 .coherent_dma_mask = DMA_BIT_MASK(32),
1405 },
1406 .resource = ssc0_resources,
1407 .num_resources = ARRAY_SIZE(ssc0_resources),
1408};
1409
1410static inline void configure_ssc0_pins(unsigned pins)
1411{
1412 if (pins & ATMEL_SSC_TF)
1413 at91_set_A_periph(AT91_PIN_PD1, 1);
1414 if (pins & ATMEL_SSC_TK)
1415 at91_set_A_periph(AT91_PIN_PD0, 1);
1416 if (pins & ATMEL_SSC_TD)
1417 at91_set_A_periph(AT91_PIN_PD2, 1);
1418 if (pins & ATMEL_SSC_RD)
1419 at91_set_A_periph(AT91_PIN_PD3, 1);
1420 if (pins & ATMEL_SSC_RK)
1421 at91_set_A_periph(AT91_PIN_PD4, 1);
1422 if (pins & ATMEL_SSC_RF)
1423 at91_set_A_periph(AT91_PIN_PD5, 1);
1424}
1425
1426static u64 ssc1_dmamask = DMA_BIT_MASK(32);
1427
1428static struct resource ssc1_resources[] = {
1429 [0] = {
1430 .start = AT91SAM9G45_BASE_SSC1,
1431 .end = AT91SAM9G45_BASE_SSC1 + SZ_16K - 1,
1432 .flags = IORESOURCE_MEM,
1433 },
1434 [1] = {
1435 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_SSC1,
1436 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_SSC1,
1437 .flags = IORESOURCE_IRQ,
1438 },
1439};
1440
1441static struct platform_device at91sam9g45_ssc1_device = {
1442 .name = "at91sam9g45_ssc",
1443 .id = 1,
1444 .dev = {
1445 .dma_mask = &ssc1_dmamask,
1446 .coherent_dma_mask = DMA_BIT_MASK(32),
1447 },
1448 .resource = ssc1_resources,
1449 .num_resources = ARRAY_SIZE(ssc1_resources),
1450};
1451
1452static inline void configure_ssc1_pins(unsigned pins)
1453{
1454 if (pins & ATMEL_SSC_TF)
1455 at91_set_A_periph(AT91_PIN_PD14, 1);
1456 if (pins & ATMEL_SSC_TK)
1457 at91_set_A_periph(AT91_PIN_PD12, 1);
1458 if (pins & ATMEL_SSC_TD)
1459 at91_set_A_periph(AT91_PIN_PD10, 1);
1460 if (pins & ATMEL_SSC_RD)
1461 at91_set_A_periph(AT91_PIN_PD11, 1);
1462 if (pins & ATMEL_SSC_RK)
1463 at91_set_A_periph(AT91_PIN_PD13, 1);
1464 if (pins & ATMEL_SSC_RF)
1465 at91_set_A_periph(AT91_PIN_PD15, 1);
1466}
1467
1468/*
1469 * SSC controllers are accessed through library code, instead of any
1470 * kind of all-singing/all-dancing driver. For example one could be
1471 * used by a particular I2S audio codec's driver, while another one
1472 * on the same system might be used by a custom data capture driver.
1473 */
1474void __init at91_add_device_ssc(unsigned id, unsigned pins)
1475{
1476 struct platform_device *pdev;
1477
1478 /*
1479 * NOTE: caller is responsible for passing information matching
1480 * "pins" to whatever will be using each particular controller.
1481 */
1482 switch (id) {
1483 case AT91SAM9G45_ID_SSC0:
1484 pdev = &at91sam9g45_ssc0_device;
1485 configure_ssc0_pins(pins);
1486 break;
1487 case AT91SAM9G45_ID_SSC1:
1488 pdev = &at91sam9g45_ssc1_device;
1489 configure_ssc1_pins(pins);
1490 break;
1491 default:
1492 return;
1493 }
1494
1495 platform_device_register(pdev);
1496}
1497
1498#else
1499void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
1500#endif
1501
1502
1503/* --------------------------------------------------------------------
1504 * UART
1505 * -------------------------------------------------------------------- */
1506
1507#if defined(CONFIG_SERIAL_ATMEL)
1508static struct resource dbgu_resources[] = {
1509 [0] = {
1510 .start = AT91SAM9G45_BASE_DBGU,
1511 .end = AT91SAM9G45_BASE_DBGU + SZ_512 - 1,
1512 .flags = IORESOURCE_MEM,
1513 },
1514 [1] = {
1515 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
1516 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
1517 .flags = IORESOURCE_IRQ,
1518 },
1519};
1520
1521static struct atmel_uart_data dbgu_data = {
1522 .use_dma_tx = 0,
1523 .use_dma_rx = 0,
1524};
1525
1526static u64 dbgu_dmamask = DMA_BIT_MASK(32);
1527
1528static struct platform_device at91sam9g45_dbgu_device = {
1529 .name = "atmel_usart",
1530 .id = 0,
1531 .dev = {
1532 .dma_mask = &dbgu_dmamask,
1533 .coherent_dma_mask = DMA_BIT_MASK(32),
1534 .platform_data = &dbgu_data,
1535 },
1536 .resource = dbgu_resources,
1537 .num_resources = ARRAY_SIZE(dbgu_resources),
1538};
1539
1540static inline void configure_dbgu_pins(void)
1541{
1542 at91_set_A_periph(AT91_PIN_PB12, 0); /* DRXD */
1543 at91_set_A_periph(AT91_PIN_PB13, 1); /* DTXD */
1544}
1545
1546static struct resource uart0_resources[] = {
1547 [0] = {
1548 .start = AT91SAM9G45_BASE_US0,
1549 .end = AT91SAM9G45_BASE_US0 + SZ_16K - 1,
1550 .flags = IORESOURCE_MEM,
1551 },
1552 [1] = {
1553 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_US0,
1554 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_US0,
1555 .flags = IORESOURCE_IRQ,
1556 },
1557};
1558
1559static struct atmel_uart_data uart0_data = {
1560 .use_dma_tx = 1,
1561 .use_dma_rx = 1,
1562};
1563
1564static u64 uart0_dmamask = DMA_BIT_MASK(32);
1565
1566static struct platform_device at91sam9g45_uart0_device = {
1567 .name = "atmel_usart",
1568 .id = 1,
1569 .dev = {
1570 .dma_mask = &uart0_dmamask,
1571 .coherent_dma_mask = DMA_BIT_MASK(32),
1572 .platform_data = &uart0_data,
1573 },
1574 .resource = uart0_resources,
1575 .num_resources = ARRAY_SIZE(uart0_resources),
1576};
1577
1578static inline void configure_usart0_pins(unsigned pins)
1579{
1580 at91_set_A_periph(AT91_PIN_PB19, 1); /* TXD0 */
1581 at91_set_A_periph(AT91_PIN_PB18, 0); /* RXD0 */
1582
1583 if (pins & ATMEL_UART_RTS)
1584 at91_set_B_periph(AT91_PIN_PB17, 0); /* RTS0 */
1585 if (pins & ATMEL_UART_CTS)
1586 at91_set_B_periph(AT91_PIN_PB15, 0); /* CTS0 */
1587}
1588
1589static struct resource uart1_resources[] = {
1590 [0] = {
1591 .start = AT91SAM9G45_BASE_US1,
1592 .end = AT91SAM9G45_BASE_US1 + SZ_16K - 1,
1593 .flags = IORESOURCE_MEM,
1594 },
1595 [1] = {
1596 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_US1,
1597 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_US1,
1598 .flags = IORESOURCE_IRQ,
1599 },
1600};
1601
1602static struct atmel_uart_data uart1_data = {
1603 .use_dma_tx = 1,
1604 .use_dma_rx = 1,
1605};
1606
1607static u64 uart1_dmamask = DMA_BIT_MASK(32);
1608
1609static struct platform_device at91sam9g45_uart1_device = {
1610 .name = "atmel_usart",
1611 .id = 2,
1612 .dev = {
1613 .dma_mask = &uart1_dmamask,
1614 .coherent_dma_mask = DMA_BIT_MASK(32),
1615 .platform_data = &uart1_data,
1616 },
1617 .resource = uart1_resources,
1618 .num_resources = ARRAY_SIZE(uart1_resources),
1619};
1620
1621static inline void configure_usart1_pins(unsigned pins)
1622{
1623 at91_set_A_periph(AT91_PIN_PB4, 1); /* TXD1 */
1624 at91_set_A_periph(AT91_PIN_PB5, 0); /* RXD1 */
1625
1626 if (pins & ATMEL_UART_RTS)
1627 at91_set_A_periph(AT91_PIN_PD16, 0); /* RTS1 */
1628 if (pins & ATMEL_UART_CTS)
1629 at91_set_A_periph(AT91_PIN_PD17, 0); /* CTS1 */
1630}
1631
1632static struct resource uart2_resources[] = {
1633 [0] = {
1634 .start = AT91SAM9G45_BASE_US2,
1635 .end = AT91SAM9G45_BASE_US2 + SZ_16K - 1,
1636 .flags = IORESOURCE_MEM,
1637 },
1638 [1] = {
1639 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_US2,
1640 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_US2,
1641 .flags = IORESOURCE_IRQ,
1642 },
1643};
1644
1645static struct atmel_uart_data uart2_data = {
1646 .use_dma_tx = 1,
1647 .use_dma_rx = 1,
1648};
1649
1650static u64 uart2_dmamask = DMA_BIT_MASK(32);
1651
1652static struct platform_device at91sam9g45_uart2_device = {
1653 .name = "atmel_usart",
1654 .id = 3,
1655 .dev = {
1656 .dma_mask = &uart2_dmamask,
1657 .coherent_dma_mask = DMA_BIT_MASK(32),
1658 .platform_data = &uart2_data,
1659 },
1660 .resource = uart2_resources,
1661 .num_resources = ARRAY_SIZE(uart2_resources),
1662};
1663
1664static inline void configure_usart2_pins(unsigned pins)
1665{
1666 at91_set_A_periph(AT91_PIN_PB6, 1); /* TXD2 */
1667 at91_set_A_periph(AT91_PIN_PB7, 0); /* RXD2 */
1668
1669 if (pins & ATMEL_UART_RTS)
1670 at91_set_B_periph(AT91_PIN_PC9, 0); /* RTS2 */
1671 if (pins & ATMEL_UART_CTS)
1672 at91_set_B_periph(AT91_PIN_PC11, 0); /* CTS2 */
1673}
1674
1675static struct resource uart3_resources[] = {
1676 [0] = {
1677 .start = AT91SAM9G45_BASE_US3,
1678 .end = AT91SAM9G45_BASE_US3 + SZ_16K - 1,
1679 .flags = IORESOURCE_MEM,
1680 },
1681 [1] = {
1682 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_US3,
1683 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_US3,
1684 .flags = IORESOURCE_IRQ,
1685 },
1686};
1687
1688static struct atmel_uart_data uart3_data = {
1689 .use_dma_tx = 1,
1690 .use_dma_rx = 1,
1691};
1692
1693static u64 uart3_dmamask = DMA_BIT_MASK(32);
1694
1695static struct platform_device at91sam9g45_uart3_device = {
1696 .name = "atmel_usart",
1697 .id = 4,
1698 .dev = {
1699 .dma_mask = &uart3_dmamask,
1700 .coherent_dma_mask = DMA_BIT_MASK(32),
1701 .platform_data = &uart3_data,
1702 },
1703 .resource = uart3_resources,
1704 .num_resources = ARRAY_SIZE(uart3_resources),
1705};
1706
1707static inline void configure_usart3_pins(unsigned pins)
1708{
1709 at91_set_A_periph(AT91_PIN_PB8, 1); /* TXD3 */
1710 at91_set_A_periph(AT91_PIN_PB9, 0); /* RXD3 */
1711
1712 if (pins & ATMEL_UART_RTS)
1713 at91_set_B_periph(AT91_PIN_PA23, 0); /* RTS3 */
1714 if (pins & ATMEL_UART_CTS)
1715 at91_set_B_periph(AT91_PIN_PA24, 0); /* CTS3 */
1716}
1717
1718static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
1719
1720void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1721{
1722 struct platform_device *pdev;
1723 struct atmel_uart_data *pdata;
1724
1725 switch (id) {
1726 case 0: /* DBGU */
1727 pdev = &at91sam9g45_dbgu_device;
1728 configure_dbgu_pins();
1729 break;
1730 case AT91SAM9G45_ID_US0:
1731 pdev = &at91sam9g45_uart0_device;
1732 configure_usart0_pins(pins);
1733 break;
1734 case AT91SAM9G45_ID_US1:
1735 pdev = &at91sam9g45_uart1_device;
1736 configure_usart1_pins(pins);
1737 break;
1738 case AT91SAM9G45_ID_US2:
1739 pdev = &at91sam9g45_uart2_device;
1740 configure_usart2_pins(pins);
1741 break;
1742 case AT91SAM9G45_ID_US3:
1743 pdev = &at91sam9g45_uart3_device;
1744 configure_usart3_pins(pins);
1745 break;
1746 default:
1747 return;
1748 }
1749 pdata = pdev->dev.platform_data;
1750 pdata->num = portnr; /* update to mapped ID */
1751
1752 if (portnr < ATMEL_MAX_UART)
1753 at91_uarts[portnr] = pdev;
1754}
1755
1756void __init at91_add_device_serial(void)
1757{
1758 int i;
1759
1760 for (i = 0; i < ATMEL_MAX_UART; i++) {
1761 if (at91_uarts[i])
1762 platform_device_register(at91_uarts[i]);
1763 }
1764}
1765#else
1766void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1767void __init at91_add_device_serial(void) {}
1768#endif
1769
1770/* --------------------------------------------------------------------
1771 * SHA1/SHA256
1772 * -------------------------------------------------------------------- */
1773
1774#if defined(CONFIG_CRYPTO_DEV_ATMEL_SHA) || defined(CONFIG_CRYPTO_DEV_ATMEL_SHA_MODULE)
1775static struct resource sha_resources[] = {
1776 {
1777 .start = AT91SAM9G45_BASE_SHA,
1778 .end = AT91SAM9G45_BASE_SHA + SZ_16K - 1,
1779 .flags = IORESOURCE_MEM,
1780 },
1781 [1] = {
1782 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
1783 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
1784 .flags = IORESOURCE_IRQ,
1785 },
1786};
1787
1788static struct platform_device at91sam9g45_sha_device = {
1789 .name = "atmel_sha",
1790 .id = -1,
1791 .resource = sha_resources,
1792 .num_resources = ARRAY_SIZE(sha_resources),
1793};
1794
1795static void __init at91_add_device_sha(void)
1796{
1797 platform_device_register(&at91sam9g45_sha_device);
1798}
1799#else
1800static void __init at91_add_device_sha(void) {}
1801#endif
1802
1803/* --------------------------------------------------------------------
1804 * DES/TDES
1805 * -------------------------------------------------------------------- */
1806
1807#if defined(CONFIG_CRYPTO_DEV_ATMEL_TDES) || defined(CONFIG_CRYPTO_DEV_ATMEL_TDES_MODULE)
1808static struct resource tdes_resources[] = {
1809 [0] = {
1810 .start = AT91SAM9G45_BASE_TDES,
1811 .end = AT91SAM9G45_BASE_TDES + SZ_16K - 1,
1812 .flags = IORESOURCE_MEM,
1813 },
1814 [1] = {
1815 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
1816 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
1817 .flags = IORESOURCE_IRQ,
1818 },
1819};
1820
1821static struct platform_device at91sam9g45_tdes_device = {
1822 .name = "atmel_tdes",
1823 .id = -1,
1824 .resource = tdes_resources,
1825 .num_resources = ARRAY_SIZE(tdes_resources),
1826};
1827
1828static void __init at91_add_device_tdes(void)
1829{
1830 platform_device_register(&at91sam9g45_tdes_device);
1831}
1832#else
1833static void __init at91_add_device_tdes(void) {}
1834#endif
1835
1836/* --------------------------------------------------------------------
1837 * AES
1838 * -------------------------------------------------------------------- */
1839
1840#if defined(CONFIG_CRYPTO_DEV_ATMEL_AES) || defined(CONFIG_CRYPTO_DEV_ATMEL_AES_MODULE)
1841static struct crypto_platform_data aes_data;
1842static struct crypto_dma_data alt_atslave;
1843static u64 aes_dmamask = DMA_BIT_MASK(32);
1844
1845static struct resource aes_resources[] = {
1846 [0] = {
1847 .start = AT91SAM9G45_BASE_AES,
1848 .end = AT91SAM9G45_BASE_AES + SZ_16K - 1,
1849 .flags = IORESOURCE_MEM,
1850 },
1851 [1] = {
1852 .start = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
1853 .end = NR_IRQS_LEGACY + AT91SAM9G45_ID_AESTDESSHA,
1854 .flags = IORESOURCE_IRQ,
1855 },
1856};
1857
1858static struct platform_device at91sam9g45_aes_device = {
1859 .name = "atmel_aes",
1860 .id = -1,
1861 .dev = {
1862 .dma_mask = &aes_dmamask,
1863 .coherent_dma_mask = DMA_BIT_MASK(32),
1864 .platform_data = &aes_data,
1865 },
1866 .resource = aes_resources,
1867 .num_resources = ARRAY_SIZE(aes_resources),
1868};
1869
1870static void __init at91_add_device_aes(void)
1871{
1872 struct at_dma_slave *atslave;
1873
1874 /* DMA TX slave channel configuration */
1875 atslave = &alt_atslave.txdata;
1876 atslave->dma_dev = &at_hdmac_device.dev;
1877 atslave->cfg = ATC_FIFOCFG_ENOUGHSPACE | ATC_SRC_H2SEL_HW |
1878 ATC_SRC_PER(AT_DMA_ID_AES_RX);
1879
1880 /* DMA RX slave channel configuration */
1881 atslave = &alt_atslave.rxdata;
1882 atslave->dma_dev = &at_hdmac_device.dev;
1883 atslave->cfg = ATC_FIFOCFG_ENOUGHSPACE | ATC_DST_H2SEL_HW |
1884 ATC_DST_PER(AT_DMA_ID_AES_TX);
1885
1886 aes_data.dma_slave = &alt_atslave;
1887 platform_device_register(&at91sam9g45_aes_device);
1888}
1889#else
1890static void __init at91_add_device_aes(void) {}
1891#endif
1892
1893/* -------------------------------------------------------------------- */
1894/*
1895 * These devices are always present and don't need any board-specific
1896 * setup.
1897 */
1898static int __init at91_add_standard_devices(void)
1899{
1900 if (of_have_populated_dt())
1901 return 0;
1902
1903 at91_add_device_hdmac();
1904 at91_add_device_rtc();
1905 at91_add_device_rtt();
1906 at91_add_device_trng();
1907 at91_add_device_watchdog();
1908 at91_add_device_tc();
1909 at91_add_device_sha();
1910 at91_add_device_tdes();
1911 at91_add_device_aes();
1912 return 0;
1913}
1914
1915arch_initcall(at91_add_standard_devices);
diff --git a/arch/arm/mach-at91/at91sam9n12.c b/arch/arm/mach-at91/at91sam9n12.c
index c8988fe5ff70..dee569b1987e 100644
--- a/arch/arm/mach-at91/at91sam9n12.c
+++ b/arch/arm/mach-at91/at91sam9n12.c
@@ -6,219 +6,11 @@
6 * Licensed under GPLv2 or later. 6 * Licensed under GPLv2 or later.
7 */ 7 */
8 8
9#include <linux/module.h> 9#include <asm/system_misc.h>
10#include <linux/dma-mapping.h> 10#include <mach/hardware.h>
11#include <linux/clk/at91_pmc.h>
12 11
13#include <asm/irq.h>
14#include <asm/mach/arch.h>
15#include <asm/mach/map.h>
16#include <mach/at91sam9n12.h>
17#include <mach/cpu.h>
18
19#include "board.h"
20#include "soc.h" 12#include "soc.h"
21#include "generic.h" 13#include "generic.h"
22#include "sam9_smc.h"
23
24#if defined(CONFIG_OLD_CLK_AT91)
25#include "clock.h"
26/* --------------------------------------------------------------------
27 * Clocks
28 * -------------------------------------------------------------------- */
29
30/*
31 * The peripheral clocks.
32 */
33static struct clk pioAB_clk = {
34 .name = "pioAB_clk",
35 .pmc_mask = 1 << AT91SAM9N12_ID_PIOAB,
36 .type = CLK_TYPE_PERIPHERAL,
37};
38static struct clk pioCD_clk = {
39 .name = "pioCD_clk",
40 .pmc_mask = 1 << AT91SAM9N12_ID_PIOCD,
41 .type = CLK_TYPE_PERIPHERAL,
42};
43static struct clk usart0_clk = {
44 .name = "usart0_clk",
45 .pmc_mask = 1 << AT91SAM9N12_ID_USART0,
46 .type = CLK_TYPE_PERIPHERAL,
47};
48static struct clk usart1_clk = {
49 .name = "usart1_clk",
50 .pmc_mask = 1 << AT91SAM9N12_ID_USART1,
51 .type = CLK_TYPE_PERIPHERAL,
52};
53static struct clk usart2_clk = {
54 .name = "usart2_clk",
55 .pmc_mask = 1 << AT91SAM9N12_ID_USART2,
56 .type = CLK_TYPE_PERIPHERAL,
57};
58static struct clk usart3_clk = {
59 .name = "usart3_clk",
60 .pmc_mask = 1 << AT91SAM9N12_ID_USART3,
61 .type = CLK_TYPE_PERIPHERAL,
62};
63static struct clk twi0_clk = {
64 .name = "twi0_clk",
65 .pmc_mask = 1 << AT91SAM9N12_ID_TWI0,
66 .type = CLK_TYPE_PERIPHERAL,
67};
68static struct clk twi1_clk = {
69 .name = "twi1_clk",
70 .pmc_mask = 1 << AT91SAM9N12_ID_TWI1,
71 .type = CLK_TYPE_PERIPHERAL,
72};
73static struct clk mmc_clk = {
74 .name = "mci_clk",
75 .pmc_mask = 1 << AT91SAM9N12_ID_MCI,
76 .type = CLK_TYPE_PERIPHERAL,
77};
78static struct clk spi0_clk = {
79 .name = "spi0_clk",
80 .pmc_mask = 1 << AT91SAM9N12_ID_SPI0,
81 .type = CLK_TYPE_PERIPHERAL,
82};
83static struct clk spi1_clk = {
84 .name = "spi1_clk",
85 .pmc_mask = 1 << AT91SAM9N12_ID_SPI1,
86 .type = CLK_TYPE_PERIPHERAL,
87};
88static struct clk uart0_clk = {
89 .name = "uart0_clk",
90 .pmc_mask = 1 << AT91SAM9N12_ID_UART0,
91 .type = CLK_TYPE_PERIPHERAL,
92};
93static struct clk uart1_clk = {
94 .name = "uart1_clk",
95 .pmc_mask = 1 << AT91SAM9N12_ID_UART1,
96 .type = CLK_TYPE_PERIPHERAL,
97};
98static struct clk tcb_clk = {
99 .name = "tcb_clk",
100 .pmc_mask = 1 << AT91SAM9N12_ID_TCB,
101 .type = CLK_TYPE_PERIPHERAL,
102};
103static struct clk pwm_clk = {
104 .name = "pwm_clk",
105 .pmc_mask = 1 << AT91SAM9N12_ID_PWM,
106 .type = CLK_TYPE_PERIPHERAL,
107};
108static struct clk adc_clk = {
109 .name = "adc_clk",
110 .pmc_mask = 1 << AT91SAM9N12_ID_ADC,
111 .type = CLK_TYPE_PERIPHERAL,
112};
113static struct clk dma_clk = {
114 .name = "dma_clk",
115 .pmc_mask = 1 << AT91SAM9N12_ID_DMA,
116 .type = CLK_TYPE_PERIPHERAL,
117};
118static struct clk uhp_clk = {
119 .name = "uhp",
120 .pmc_mask = 1 << AT91SAM9N12_ID_UHP,
121 .type = CLK_TYPE_PERIPHERAL,
122};
123static struct clk udp_clk = {
124 .name = "udp_clk",
125 .pmc_mask = 1 << AT91SAM9N12_ID_UDP,
126 .type = CLK_TYPE_PERIPHERAL,
127};
128static struct clk lcdc_clk = {
129 .name = "lcdc_clk",
130 .pmc_mask = 1 << AT91SAM9N12_ID_LCDC,
131 .type = CLK_TYPE_PERIPHERAL,
132};
133static struct clk ssc_clk = {
134 .name = "ssc_clk",
135 .pmc_mask = 1 << AT91SAM9N12_ID_SSC,
136 .type = CLK_TYPE_PERIPHERAL,
137};
138
139static struct clk *periph_clocks[] __initdata = {
140 &pioAB_clk,
141 &pioCD_clk,
142 &usart0_clk,
143 &usart1_clk,
144 &usart2_clk,
145 &usart3_clk,
146 &twi0_clk,
147 &twi1_clk,
148 &mmc_clk,
149 &spi0_clk,
150 &spi1_clk,
151 &lcdc_clk,
152 &uart0_clk,
153 &uart1_clk,
154 &tcb_clk,
155 &pwm_clk,
156 &adc_clk,
157 &dma_clk,
158 &uhp_clk,
159 &udp_clk,
160 &ssc_clk,
161};
162
163static struct clk_lookup periph_clocks_lookups[] = {
164 /* lookup table for DT entries */
165 CLKDEV_CON_DEV_ID("usart", "fffff200.serial", &mck),
166 CLKDEV_CON_DEV_ID("usart", "f801c000.serial", &usart0_clk),
167 CLKDEV_CON_DEV_ID("usart", "f8020000.serial", &usart1_clk),
168 CLKDEV_CON_DEV_ID("usart", "f8024000.serial", &usart2_clk),
169 CLKDEV_CON_DEV_ID("usart", "f8028000.serial", &usart3_clk),
170 CLKDEV_CON_DEV_ID("t0_clk", "f8008000.timer", &tcb_clk),
171 CLKDEV_CON_DEV_ID("t0_clk", "f800c000.timer", &tcb_clk),
172 CLKDEV_CON_DEV_ID("mci_clk", "f0008000.mmc", &mmc_clk),
173 CLKDEV_CON_DEV_ID(NULL, "f0010000.ssc", &ssc_clk),
174 CLKDEV_CON_DEV_ID("dma_clk", "ffffec00.dma-controller", &dma_clk),
175 CLKDEV_CON_DEV_ID(NULL, "f8010000.i2c", &twi0_clk),
176 CLKDEV_CON_DEV_ID(NULL, "f8014000.i2c", &twi1_clk),
177 CLKDEV_CON_DEV_ID("spi_clk", "f0000000.spi", &spi0_clk),
178 CLKDEV_CON_DEV_ID("spi_clk", "f0004000.spi", &spi1_clk),
179 CLKDEV_CON_DEV_ID(NULL, "fffff400.gpio", &pioAB_clk),
180 CLKDEV_CON_DEV_ID(NULL, "fffff600.gpio", &pioAB_clk),
181 CLKDEV_CON_DEV_ID(NULL, "fffff800.gpio", &pioCD_clk),
182 CLKDEV_CON_DEV_ID(NULL, "fffffa00.gpio", &pioCD_clk),
183 /* additional fake clock for macb_hclk */
184 CLKDEV_CON_DEV_ID("hclk", "500000.ohci", &uhp_clk),
185 CLKDEV_CON_DEV_ID("ohci_clk", "500000.ohci", &uhp_clk),
186 CLKDEV_CON_DEV_ID(NULL, "f8034000.pwm", &pwm_clk),
187};
188
189/*
190 * The two programmable clocks.
191 * You must configure pin multiplexing to bring these signals out.
192 */
193static struct clk pck0 = {
194 .name = "pck0",
195 .pmc_mask = AT91_PMC_PCK0,
196 .type = CLK_TYPE_PROGRAMMABLE,
197 .id = 0,
198};
199static struct clk pck1 = {
200 .name = "pck1",
201 .pmc_mask = AT91_PMC_PCK1,
202 .type = CLK_TYPE_PROGRAMMABLE,
203 .id = 1,
204};
205
206static void __init at91sam9n12_register_clocks(void)
207{
208 int i;
209
210 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
211 clk_register(periph_clocks[i]);
212 clk_register(&pck0);
213 clk_register(&pck1);
214
215 clkdev_add_table(periph_clocks_lookups,
216 ARRAY_SIZE(periph_clocks_lookups));
217
218}
219#else
220#define at91sam9n12_register_clocks NULL
221#endif
222 14
223/* -------------------------------------------------------------------- 15/* --------------------------------------------------------------------
224 * AT91SAM9N12 processor initialization 16 * AT91SAM9N12 processor initialization
@@ -236,6 +28,5 @@ static void __init at91sam9n12_initialize(void)
236 28
237AT91_SOC_START(at91sam9n12) 29AT91_SOC_START(at91sam9n12)
238 .map_io = at91sam9n12_map_io, 30 .map_io = at91sam9n12_map_io,
239 .register_clocks = at91sam9n12_register_clocks,
240 .init = at91sam9n12_initialize, 31 .init = at91sam9n12_initialize,
241AT91_SOC_END 32AT91_SOC_END
diff --git a/arch/arm/mach-at91/at91sam9rl.c b/arch/arm/mach-at91/at91sam9rl.c
index f553e4ea034b..f25b9aec9c50 100644
--- a/arch/arm/mach-at91/at91sam9rl.c
+++ b/arch/arm/mach-at91/at91sam9rl.c
@@ -9,284 +9,14 @@
9 * more details. 9 * more details.
10 */ 10 */
11 11
12#include <linux/module.h>
13#include <linux/platform_device.h>
14#include <linux/clk/at91_pmc.h>
15
16#include <asm/proc-fns.h>
17#include <asm/irq.h>
18#include <asm/mach/arch.h>
19#include <asm/mach/map.h>
20#include <asm/system_misc.h> 12#include <asm/system_misc.h>
13#include <asm/irq.h>
21#include <mach/cpu.h> 14#include <mach/cpu.h>
22#include <mach/at91_dbgu.h> 15#include <mach/at91_dbgu.h>
23#include <mach/at91sam9rl.h>
24#include <mach/hardware.h> 16#include <mach/hardware.h>
25 17
26#include "at91_aic.h"
27#include "soc.h" 18#include "soc.h"
28#include "generic.h" 19#include "generic.h"
29#include "sam9_smc.h"
30#include "pm.h"
31
32/* --------------------------------------------------------------------
33 * Clocks
34 * -------------------------------------------------------------------- */
35#if defined(CONFIG_OLD_CLK_AT91)
36#include "clock.h"
37
38/*
39 * The peripheral clocks.
40 */
41static struct clk pioA_clk = {
42 .name = "pioA_clk",
43 .pmc_mask = 1 << AT91SAM9RL_ID_PIOA,
44 .type = CLK_TYPE_PERIPHERAL,
45};
46static struct clk pioB_clk = {
47 .name = "pioB_clk",
48 .pmc_mask = 1 << AT91SAM9RL_ID_PIOB,
49 .type = CLK_TYPE_PERIPHERAL,
50};
51static struct clk pioC_clk = {
52 .name = "pioC_clk",
53 .pmc_mask = 1 << AT91SAM9RL_ID_PIOC,
54 .type = CLK_TYPE_PERIPHERAL,
55};
56static struct clk pioD_clk = {
57 .name = "pioD_clk",
58 .pmc_mask = 1 << AT91SAM9RL_ID_PIOD,
59 .type = CLK_TYPE_PERIPHERAL,
60};
61static struct clk usart0_clk = {
62 .name = "usart0_clk",
63 .pmc_mask = 1 << AT91SAM9RL_ID_US0,
64 .type = CLK_TYPE_PERIPHERAL,
65};
66static struct clk usart1_clk = {
67 .name = "usart1_clk",
68 .pmc_mask = 1 << AT91SAM9RL_ID_US1,
69 .type = CLK_TYPE_PERIPHERAL,
70};
71static struct clk usart2_clk = {
72 .name = "usart2_clk",
73 .pmc_mask = 1 << AT91SAM9RL_ID_US2,
74 .type = CLK_TYPE_PERIPHERAL,
75};
76static struct clk usart3_clk = {
77 .name = "usart3_clk",
78 .pmc_mask = 1 << AT91SAM9RL_ID_US3,
79 .type = CLK_TYPE_PERIPHERAL,
80};
81static struct clk mmc_clk = {
82 .name = "mci_clk",
83 .pmc_mask = 1 << AT91SAM9RL_ID_MCI,
84 .type = CLK_TYPE_PERIPHERAL,
85};
86static struct clk twi0_clk = {
87 .name = "twi0_clk",
88 .pmc_mask = 1 << AT91SAM9RL_ID_TWI0,
89 .type = CLK_TYPE_PERIPHERAL,
90};
91static struct clk twi1_clk = {
92 .name = "twi1_clk",
93 .pmc_mask = 1 << AT91SAM9RL_ID_TWI1,
94 .type = CLK_TYPE_PERIPHERAL,
95};
96static struct clk spi_clk = {
97 .name = "spi_clk",
98 .pmc_mask = 1 << AT91SAM9RL_ID_SPI,
99 .type = CLK_TYPE_PERIPHERAL,
100};
101static struct clk ssc0_clk = {
102 .name = "ssc0_clk",
103 .pmc_mask = 1 << AT91SAM9RL_ID_SSC0,
104 .type = CLK_TYPE_PERIPHERAL,
105};
106static struct clk ssc1_clk = {
107 .name = "ssc1_clk",
108 .pmc_mask = 1 << AT91SAM9RL_ID_SSC1,
109 .type = CLK_TYPE_PERIPHERAL,
110};
111static struct clk tc0_clk = {
112 .name = "tc0_clk",
113 .pmc_mask = 1 << AT91SAM9RL_ID_TC0,
114 .type = CLK_TYPE_PERIPHERAL,
115};
116static struct clk tc1_clk = {
117 .name = "tc1_clk",
118 .pmc_mask = 1 << AT91SAM9RL_ID_TC1,
119 .type = CLK_TYPE_PERIPHERAL,
120};
121static struct clk tc2_clk = {
122 .name = "tc2_clk",
123 .pmc_mask = 1 << AT91SAM9RL_ID_TC2,
124 .type = CLK_TYPE_PERIPHERAL,
125};
126static struct clk pwm_clk = {
127 .name = "pwm_clk",
128 .pmc_mask = 1 << AT91SAM9RL_ID_PWMC,
129 .type = CLK_TYPE_PERIPHERAL,
130};
131static struct clk tsc_clk = {
132 .name = "tsc_clk",
133 .pmc_mask = 1 << AT91SAM9RL_ID_TSC,
134 .type = CLK_TYPE_PERIPHERAL,
135};
136static struct clk dma_clk = {
137 .name = "dma_clk",
138 .pmc_mask = 1 << AT91SAM9RL_ID_DMA,
139 .type = CLK_TYPE_PERIPHERAL,
140};
141static struct clk udphs_clk = {
142 .name = "udphs_clk",
143 .pmc_mask = 1 << AT91SAM9RL_ID_UDPHS,
144 .type = CLK_TYPE_PERIPHERAL,
145};
146static struct clk lcdc_clk = {
147 .name = "lcdc_clk",
148 .pmc_mask = 1 << AT91SAM9RL_ID_LCDC,
149 .type = CLK_TYPE_PERIPHERAL,
150};
151static struct clk ac97_clk = {
152 .name = "ac97_clk",
153 .pmc_mask = 1 << AT91SAM9RL_ID_AC97C,
154 .type = CLK_TYPE_PERIPHERAL,
155};
156static struct clk adc_op_clk = {
157 .name = "adc_op_clk",
158 .type = CLK_TYPE_PERIPHERAL,
159 .rate_hz = 1000000,
160};
161
162static struct clk *periph_clocks[] __initdata = {
163 &pioA_clk,
164 &pioB_clk,
165 &pioC_clk,
166 &pioD_clk,
167 &usart0_clk,
168 &usart1_clk,
169 &usart2_clk,
170 &usart3_clk,
171 &mmc_clk,
172 &twi0_clk,
173 &twi1_clk,
174 &spi_clk,
175 &ssc0_clk,
176 &ssc1_clk,
177 &tc0_clk,
178 &tc1_clk,
179 &tc2_clk,
180 &pwm_clk,
181 &tsc_clk,
182 &dma_clk,
183 &udphs_clk,
184 &lcdc_clk,
185 &ac97_clk,
186 &adc_op_clk,
187 // irq0
188};
189
190static struct clk_lookup periph_clocks_lookups[] = {
191 CLKDEV_CON_DEV_ID("hclk", "at91sam9rl-lcdfb.0", &lcdc_clk),
192 CLKDEV_CON_DEV_ID("hclk", "atmel_usba_udc", &utmi_clk),
193 CLKDEV_CON_DEV_ID("pclk", "atmel_usba_udc", &udphs_clk),
194 CLKDEV_CON_DEV_ID("t0_clk", "atmel_tcb.0", &tc0_clk),
195 CLKDEV_CON_DEV_ID("t1_clk", "atmel_tcb.0", &tc1_clk),
196 CLKDEV_CON_DEV_ID("t2_clk", "atmel_tcb.0", &tc2_clk),
197 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.0", &ssc0_clk),
198 CLKDEV_CON_DEV_ID("pclk", "at91rm9200_ssc.1", &ssc1_clk),
199 CLKDEV_CON_DEV_ID("pclk", "fffc0000.ssc", &ssc0_clk),
200 CLKDEV_CON_DEV_ID("pclk", "fffc4000.ssc", &ssc1_clk),
201 CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9g20.0", &twi0_clk),
202 CLKDEV_CON_DEV_ID(NULL, "i2c-at91sam9g20.1", &twi1_clk),
203 CLKDEV_CON_DEV_ID(NULL, "at91sam9rl-pwm", &pwm_clk),
204 CLKDEV_CON_ID("pioA", &pioA_clk),
205 CLKDEV_CON_ID("pioB", &pioB_clk),
206 CLKDEV_CON_ID("pioC", &pioC_clk),
207 CLKDEV_CON_ID("pioD", &pioD_clk),
208 /* more lookup table for DT entries */
209 CLKDEV_CON_DEV_ID("usart", "fffff200.serial", &mck),
210 CLKDEV_CON_DEV_ID("usart", "fffb0000.serial", &usart0_clk),
211 CLKDEV_CON_DEV_ID("usart", "ffffb400.serial", &usart1_clk),
212 CLKDEV_CON_DEV_ID("usart", "ffffb800.serial", &usart2_clk),
213 CLKDEV_CON_DEV_ID("usart", "ffffbc00.serial", &usart3_clk),
214 CLKDEV_CON_DEV_ID("t0_clk", "fffa0000.timer", &tc0_clk),
215 CLKDEV_CON_DEV_ID("t1_clk", "fffa0000.timer", &tc1_clk),
216 CLKDEV_CON_DEV_ID("t2_clk", "fffa0000.timer", &tc2_clk),
217 CLKDEV_CON_DEV_ID("mci_clk", "fffa4000.mmc", &mmc_clk),
218 CLKDEV_CON_DEV_ID(NULL, "fffa8000.i2c", &twi0_clk),
219 CLKDEV_CON_DEV_ID(NULL, "fffac000.i2c", &twi1_clk),
220 CLKDEV_CON_DEV_ID(NULL, "fffc8000.pwm", &pwm_clk),
221 CLKDEV_CON_DEV_ID(NULL, "ffffc800.pwm", &pwm_clk),
222 CLKDEV_CON_DEV_ID(NULL, "fffff400.gpio", &pioA_clk),
223 CLKDEV_CON_DEV_ID(NULL, "fffff600.gpio", &pioB_clk),
224 CLKDEV_CON_DEV_ID(NULL, "fffff800.gpio", &pioC_clk),
225 CLKDEV_CON_DEV_ID(NULL, "fffffa00.gpio", &pioD_clk),
226 CLKDEV_CON_ID("adc_clk", &tsc_clk),
227};
228
229static struct clk_lookup usart_clocks_lookups[] = {
230 CLKDEV_CON_DEV_ID("usart", "atmel_usart.0", &mck),
231 CLKDEV_CON_DEV_ID("usart", "atmel_usart.1", &usart0_clk),
232 CLKDEV_CON_DEV_ID("usart", "atmel_usart.2", &usart1_clk),
233 CLKDEV_CON_DEV_ID("usart", "atmel_usart.3", &usart2_clk),
234 CLKDEV_CON_DEV_ID("usart", "atmel_usart.4", &usart3_clk),
235};
236
237/*
238 * The two programmable clocks.
239 * You must configure pin multiplexing to bring these signals out.
240 */
241static struct clk pck0 = {
242 .name = "pck0",
243 .pmc_mask = AT91_PMC_PCK0,
244 .type = CLK_TYPE_PROGRAMMABLE,
245 .id = 0,
246};
247static struct clk pck1 = {
248 .name = "pck1",
249 .pmc_mask = AT91_PMC_PCK1,
250 .type = CLK_TYPE_PROGRAMMABLE,
251 .id = 1,
252};
253
254static void __init at91sam9rl_register_clocks(void)
255{
256 int i;
257
258 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
259 clk_register(periph_clocks[i]);
260
261 clkdev_add_table(periph_clocks_lookups,
262 ARRAY_SIZE(periph_clocks_lookups));
263 clkdev_add_table(usart_clocks_lookups,
264 ARRAY_SIZE(usart_clocks_lookups));
265
266 clk_register(&pck0);
267 clk_register(&pck1);
268}
269#endif
270
271/* --------------------------------------------------------------------
272 * GPIO
273 * -------------------------------------------------------------------- */
274
275static struct at91_gpio_bank at91sam9rl_gpio[] __initdata = {
276 {
277 .id = AT91SAM9RL_ID_PIOA,
278 .regbase = AT91SAM9RL_BASE_PIOA,
279 }, {
280 .id = AT91SAM9RL_ID_PIOB,
281 .regbase = AT91SAM9RL_BASE_PIOB,
282 }, {
283 .id = AT91SAM9RL_ID_PIOC,
284 .regbase = AT91SAM9RL_BASE_PIOC,
285 }, {
286 .id = AT91SAM9RL_ID_PIOD,
287 .regbase = AT91SAM9RL_BASE_PIOD,
288 }
289};
290 20
291/* -------------------------------------------------------------------- 21/* --------------------------------------------------------------------
292 * AT91SAM9RL processor initialization 22 * AT91SAM9RL processor initialization
@@ -309,121 +39,15 @@ static void __init at91sam9rl_map_io(void)
309 at91_init_sram(0, AT91SAM9RL_SRAM_BASE, sram_size); 39 at91_init_sram(0, AT91SAM9RL_SRAM_BASE, sram_size);
310} 40}
311 41
312static void __init at91sam9rl_ioremap_registers(void)
313{
314 at91_ioremap_ramc(0, AT91SAM9RL_BASE_SDRAMC, 512);
315 at91sam926x_ioremap_pit(AT91SAM9RL_BASE_PIT);
316 at91sam9_ioremap_smc(0, AT91SAM9RL_BASE_SMC);
317 at91_ioremap_matrix(AT91SAM9RL_BASE_MATRIX);
318 at91_pm_set_standby(at91sam9_sdram_standby);
319}
320
321static void __init at91sam9rl_initialize(void) 42static void __init at91sam9rl_initialize(void)
322{ 43{
323 arm_pm_idle = at91sam9_idle; 44 arm_pm_idle = at91sam9_idle;
324 45
325 at91_sysirq_mask_rtc(AT91SAM9RL_BASE_RTC); 46 at91_sysirq_mask_rtc(AT91SAM9RL_BASE_RTC);
326 at91_sysirq_mask_rtt(AT91SAM9RL_BASE_RTT); 47 at91_sysirq_mask_rtt(AT91SAM9RL_BASE_RTT);
327
328 /* Register GPIO subsystem */
329 at91_gpio_init(at91sam9rl_gpio, 4);
330}
331
332static struct resource rstc_resources[] = {
333 [0] = {
334 .start = AT91SAM9RL_BASE_RSTC,
335 .end = AT91SAM9RL_BASE_RSTC + SZ_16 - 1,
336 .flags = IORESOURCE_MEM,
337 },
338 [1] = {
339 .start = AT91SAM9RL_BASE_SDRAMC,
340 .end = AT91SAM9RL_BASE_SDRAMC + SZ_512 - 1,
341 .flags = IORESOURCE_MEM,
342 },
343};
344
345static struct platform_device rstc_device = {
346 .name = "at91-sam9260-reset",
347 .resource = rstc_resources,
348 .num_resources = ARRAY_SIZE(rstc_resources),
349};
350
351static struct resource shdwc_resources[] = {
352 [0] = {
353 .start = AT91SAM9RL_BASE_SHDWC,
354 .end = AT91SAM9RL_BASE_SHDWC + SZ_16 - 1,
355 .flags = IORESOURCE_MEM,
356 },
357};
358
359static struct platform_device shdwc_device = {
360 .name = "at91-poweroff",
361 .resource = shdwc_resources,
362 .num_resources = ARRAY_SIZE(shdwc_resources),
363};
364
365static void __init at91sam9rl_register_devices(void)
366{
367 platform_device_register(&rstc_device);
368 platform_device_register(&shdwc_device);
369}
370
371/* --------------------------------------------------------------------
372 * Interrupt initialization
373 * -------------------------------------------------------------------- */
374
375/*
376 * The default interrupt priority levels (0 = lowest, 7 = highest).
377 */
378static unsigned int at91sam9rl_default_irq_priority[NR_AIC_IRQS] __initdata = {
379 7, /* Advanced Interrupt Controller */
380 7, /* System Peripherals */
381 1, /* Parallel IO Controller A */
382 1, /* Parallel IO Controller B */
383 1, /* Parallel IO Controller C */
384 1, /* Parallel IO Controller D */
385 5, /* USART 0 */
386 5, /* USART 1 */
387 5, /* USART 2 */
388 5, /* USART 3 */
389 0, /* Multimedia Card Interface */
390 6, /* Two-Wire Interface 0 */
391 6, /* Two-Wire Interface 1 */
392 5, /* Serial Peripheral Interface */
393 4, /* Serial Synchronous Controller 0 */
394 4, /* Serial Synchronous Controller 1 */
395 0, /* Timer Counter 0 */
396 0, /* Timer Counter 1 */
397 0, /* Timer Counter 2 */
398 0,
399 0, /* Touch Screen Controller */
400 0, /* DMA Controller */
401 2, /* USB Device High speed port */
402 2, /* LCD Controller */
403 6, /* AC97 Controller */
404 0,
405 0,
406 0,
407 0,
408 0,
409 0,
410 0, /* Advanced Interrupt Controller */
411};
412
413static void __init at91sam9rl_init_time(void)
414{
415 at91sam926x_pit_init(NR_IRQS_LEGACY + AT91_ID_SYS);
416} 48}
417 49
418AT91_SOC_START(at91sam9rl) 50AT91_SOC_START(at91sam9rl)
419 .map_io = at91sam9rl_map_io, 51 .map_io = at91sam9rl_map_io,
420 .default_irq_priority = at91sam9rl_default_irq_priority,
421 .extern_irq = (1 << AT91SAM9RL_ID_IRQ0),
422 .ioremap_registers = at91sam9rl_ioremap_registers,
423#if defined(CONFIG_OLD_CLK_AT91)
424 .register_clocks = at91sam9rl_register_clocks,
425#endif
426 .register_devices = at91sam9rl_register_devices,
427 .init = at91sam9rl_initialize, 52 .init = at91sam9rl_initialize,
428 .init_time = at91sam9rl_init_time,
429AT91_SOC_END 53AT91_SOC_END
diff --git a/arch/arm/mach-at91/at91sam9rl_devices.c b/arch/arm/mach-at91/at91sam9rl_devices.c
deleted file mode 100644
index 37d1c9ed4562..000000000000
--- a/arch/arm/mach-at91/at91sam9rl_devices.c
+++ /dev/null
@@ -1,1260 +0,0 @@
1/*
2 * Copyright (C) 2007 Atmel Corporation
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file COPYING in the main directory of this archive for
6 * more details.
7 */
8
9#include <asm/mach/arch.h>
10#include <asm/mach/map.h>
11
12#include <linux/dma-mapping.h>
13#include <linux/gpio.h>
14#include <linux/platform_device.h>
15#include <linux/i2c-gpio.h>
16
17#include <linux/fb.h>
18#include <video/atmel_lcdc.h>
19
20#include <mach/at91sam9rl.h>
21#include <mach/at91sam9rl_matrix.h>
22#include <mach/at91_matrix.h>
23#include <mach/at91sam9_smc.h>
24#include <mach/hardware.h>
25#include <linux/platform_data/dma-atmel.h>
26#include <linux/platform_data/at91_adc.h>
27
28#include "board.h"
29#include "generic.h"
30#include "gpio.h"
31
32
33/* --------------------------------------------------------------------
34 * HDMAC - AHB DMA Controller
35 * -------------------------------------------------------------------- */
36
37#if defined(CONFIG_AT_HDMAC) || defined(CONFIG_AT_HDMAC_MODULE)
38static u64 hdmac_dmamask = DMA_BIT_MASK(32);
39
40static struct resource hdmac_resources[] = {
41 [0] = {
42 .start = AT91SAM9RL_BASE_DMA,
43 .end = AT91SAM9RL_BASE_DMA + SZ_512 - 1,
44 .flags = IORESOURCE_MEM,
45 },
46 [2] = {
47 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_DMA,
48 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_DMA,
49 .flags = IORESOURCE_IRQ,
50 },
51};
52
53static struct platform_device at_hdmac_device = {
54 .name = "at91sam9rl_dma",
55 .id = -1,
56 .dev = {
57 .dma_mask = &hdmac_dmamask,
58 .coherent_dma_mask = DMA_BIT_MASK(32),
59 },
60 .resource = hdmac_resources,
61 .num_resources = ARRAY_SIZE(hdmac_resources),
62};
63
64void __init at91_add_device_hdmac(void)
65{
66 platform_device_register(&at_hdmac_device);
67}
68#else
69void __init at91_add_device_hdmac(void) {}
70#endif
71
72/* --------------------------------------------------------------------
73 * USB HS Device (Gadget)
74 * -------------------------------------------------------------------- */
75
76#if defined(CONFIG_USB_ATMEL_USBA) || defined(CONFIG_USB_ATMEL_USBA_MODULE)
77
78static struct resource usba_udc_resources[] = {
79 [0] = {
80 .start = AT91SAM9RL_UDPHS_FIFO,
81 .end = AT91SAM9RL_UDPHS_FIFO + SZ_512K - 1,
82 .flags = IORESOURCE_MEM,
83 },
84 [1] = {
85 .start = AT91SAM9RL_BASE_UDPHS,
86 .end = AT91SAM9RL_BASE_UDPHS + SZ_1K - 1,
87 .flags = IORESOURCE_MEM,
88 },
89 [2] = {
90 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_UDPHS,
91 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_UDPHS,
92 .flags = IORESOURCE_IRQ,
93 },
94};
95
96#define EP(nam, idx, maxpkt, maxbk, dma, isoc) \
97 [idx] = { \
98 .name = nam, \
99 .index = idx, \
100 .fifo_size = maxpkt, \
101 .nr_banks = maxbk, \
102 .can_dma = dma, \
103 .can_isoc = isoc, \
104 }
105
106static struct usba_ep_data usba_udc_ep[] __initdata = {
107 EP("ep0", 0, 64, 1, 0, 0),
108 EP("ep1", 1, 1024, 2, 1, 1),
109 EP("ep2", 2, 1024, 2, 1, 1),
110 EP("ep3", 3, 1024, 3, 1, 0),
111 EP("ep4", 4, 1024, 3, 1, 0),
112 EP("ep5", 5, 1024, 3, 1, 1),
113 EP("ep6", 6, 1024, 3, 1, 1),
114};
115
116#undef EP
117
118/*
119 * pdata doesn't have room for any endpoints, so we need to
120 * append room for the ones we need right after it.
121 */
122static struct {
123 struct usba_platform_data pdata;
124 struct usba_ep_data ep[7];
125} usba_udc_data;
126
127static struct platform_device at91_usba_udc_device = {
128 .name = "atmel_usba_udc",
129 .id = -1,
130 .dev = {
131 .platform_data = &usba_udc_data.pdata,
132 },
133 .resource = usba_udc_resources,
134 .num_resources = ARRAY_SIZE(usba_udc_resources),
135};
136
137void __init at91_add_device_usba(struct usba_platform_data *data)
138{
139 /*
140 * Invalid pins are 0 on AT91, but the usba driver is shared
141 * with AVR32, which use negative values instead. Once/if
142 * gpio_is_valid() is ported to AT91, revisit this code.
143 */
144 usba_udc_data.pdata.vbus_pin = -EINVAL;
145 usba_udc_data.pdata.num_ep = ARRAY_SIZE(usba_udc_ep);
146 memcpy(usba_udc_data.ep, usba_udc_ep, sizeof(usba_udc_ep));
147
148 if (data && gpio_is_valid(data->vbus_pin)) {
149 at91_set_gpio_input(data->vbus_pin, 0);
150 at91_set_deglitch(data->vbus_pin, 1);
151 usba_udc_data.pdata.vbus_pin = data->vbus_pin;
152 }
153
154 /* Pullup pin is handled internally by USB device peripheral */
155
156 platform_device_register(&at91_usba_udc_device);
157}
158#else
159void __init at91_add_device_usba(struct usba_platform_data *data) {}
160#endif
161
162
163/* --------------------------------------------------------------------
164 * MMC / SD
165 * -------------------------------------------------------------------- */
166
167#if IS_ENABLED(CONFIG_MMC_ATMELMCI)
168static u64 mmc_dmamask = DMA_BIT_MASK(32);
169static struct mci_platform_data mmc_data;
170
171static struct resource mmc_resources[] = {
172 [0] = {
173 .start = AT91SAM9RL_BASE_MCI,
174 .end = AT91SAM9RL_BASE_MCI + SZ_16K - 1,
175 .flags = IORESOURCE_MEM,
176 },
177 [1] = {
178 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_MCI,
179 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_MCI,
180 .flags = IORESOURCE_IRQ,
181 },
182};
183
184static struct platform_device at91sam9rl_mmc_device = {
185 .name = "atmel_mci",
186 .id = -1,
187 .dev = {
188 .dma_mask = &mmc_dmamask,
189 .coherent_dma_mask = DMA_BIT_MASK(32),
190 .platform_data = &mmc_data,
191 },
192 .resource = mmc_resources,
193 .num_resources = ARRAY_SIZE(mmc_resources),
194};
195
196void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
197{
198 if (!data)
199 return;
200
201 if (data->slot[0].bus_width) {
202 /* input/irq */
203 if (gpio_is_valid(data->slot[0].detect_pin)) {
204 at91_set_gpio_input(data->slot[0].detect_pin, 1);
205 at91_set_deglitch(data->slot[0].detect_pin, 1);
206 }
207 if (gpio_is_valid(data->slot[0].wp_pin))
208 at91_set_gpio_input(data->slot[0].wp_pin, 1);
209
210 /* CLK */
211 at91_set_A_periph(AT91_PIN_PA2, 0);
212
213 /* CMD */
214 at91_set_A_periph(AT91_PIN_PA1, 1);
215
216 /* DAT0, maybe DAT1..DAT3 */
217 at91_set_A_periph(AT91_PIN_PA0, 1);
218 if (data->slot[0].bus_width == 4) {
219 at91_set_A_periph(AT91_PIN_PA3, 1);
220 at91_set_A_periph(AT91_PIN_PA4, 1);
221 at91_set_A_periph(AT91_PIN_PA5, 1);
222 }
223
224 mmc_data = *data;
225 platform_device_register(&at91sam9rl_mmc_device);
226 }
227}
228#else
229void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data) {}
230#endif
231
232
233/* --------------------------------------------------------------------
234 * NAND / SmartMedia
235 * -------------------------------------------------------------------- */
236
237#if defined(CONFIG_MTD_NAND_ATMEL) || defined(CONFIG_MTD_NAND_ATMEL_MODULE)
238static struct atmel_nand_data nand_data;
239
240#define NAND_BASE AT91_CHIPSELECT_3
241
242static struct resource nand_resources[] = {
243 [0] = {
244 .start = NAND_BASE,
245 .end = NAND_BASE + SZ_256M - 1,
246 .flags = IORESOURCE_MEM,
247 },
248 [1] = {
249 .start = AT91SAM9RL_BASE_ECC,
250 .end = AT91SAM9RL_BASE_ECC + SZ_512 - 1,
251 .flags = IORESOURCE_MEM,
252 }
253};
254
255static struct platform_device atmel_nand_device = {
256 .name = "atmel_nand",
257 .id = -1,
258 .dev = {
259 .platform_data = &nand_data,
260 },
261 .resource = nand_resources,
262 .num_resources = ARRAY_SIZE(nand_resources),
263};
264
265void __init at91_add_device_nand(struct atmel_nand_data *data)
266{
267 unsigned long csa;
268
269 if (!data)
270 return;
271
272 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
273 at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_CS3A_SMC_SMARTMEDIA);
274
275 /* enable pin */
276 if (gpio_is_valid(data->enable_pin))
277 at91_set_gpio_output(data->enable_pin, 1);
278
279 /* ready/busy pin */
280 if (gpio_is_valid(data->rdy_pin))
281 at91_set_gpio_input(data->rdy_pin, 1);
282
283 /* card detect pin */
284 if (gpio_is_valid(data->det_pin))
285 at91_set_gpio_input(data->det_pin, 1);
286
287 at91_set_A_periph(AT91_PIN_PB4, 0); /* NANDOE */
288 at91_set_A_periph(AT91_PIN_PB5, 0); /* NANDWE */
289
290 nand_data = *data;
291 platform_device_register(&atmel_nand_device);
292}
293
294#else
295void __init at91_add_device_nand(struct atmel_nand_data *data) {}
296#endif
297
298
299/* --------------------------------------------------------------------
300 * TWI (i2c)
301 * -------------------------------------------------------------------- */
302
303/*
304 * Prefer the GPIO code since the TWI controller isn't robust
305 * (gets overruns and underruns under load) and can only issue
306 * repeated STARTs in one scenario (the driver doesn't yet handle them).
307 */
308#if defined(CONFIG_I2C_GPIO) || defined(CONFIG_I2C_GPIO_MODULE)
309
310static struct i2c_gpio_platform_data pdata = {
311 .sda_pin = AT91_PIN_PA23,
312 .sda_is_open_drain = 1,
313 .scl_pin = AT91_PIN_PA24,
314 .scl_is_open_drain = 1,
315 .udelay = 2, /* ~100 kHz */
316};
317
318static struct platform_device at91sam9rl_twi_device = {
319 .name = "i2c-gpio",
320 .id = 0,
321 .dev.platform_data = &pdata,
322};
323
324void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
325{
326 at91_set_GPIO_periph(AT91_PIN_PA23, 1); /* TWD (SDA) */
327 at91_set_multi_drive(AT91_PIN_PA23, 1);
328
329 at91_set_GPIO_periph(AT91_PIN_PA24, 1); /* TWCK (SCL) */
330 at91_set_multi_drive(AT91_PIN_PA24, 1);
331
332 i2c_register_board_info(0, devices, nr_devices);
333 platform_device_register(&at91sam9rl_twi_device);
334}
335
336#elif defined(CONFIG_I2C_AT91) || defined(CONFIG_I2C_AT91_MODULE)
337
338static struct resource twi_resources[] = {
339 [0] = {
340 .start = AT91SAM9RL_BASE_TWI0,
341 .end = AT91SAM9RL_BASE_TWI0 + SZ_16K - 1,
342 .flags = IORESOURCE_MEM,
343 },
344 [1] = {
345 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_TWI0,
346 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_TWI0,
347 .flags = IORESOURCE_IRQ,
348 },
349};
350
351static struct platform_device at91sam9rl_twi_device = {
352 .name = "i2c-at91sam9g20",
353 .id = 0,
354 .resource = twi_resources,
355 .num_resources = ARRAY_SIZE(twi_resources),
356};
357
358void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices)
359{
360 /* pins used for TWI interface */
361 at91_set_A_periph(AT91_PIN_PA23, 0); /* TWD */
362 at91_set_multi_drive(AT91_PIN_PA23, 1);
363
364 at91_set_A_periph(AT91_PIN_PA24, 0); /* TWCK */
365 at91_set_multi_drive(AT91_PIN_PA24, 1);
366
367 i2c_register_board_info(0, devices, nr_devices);
368 platform_device_register(&at91sam9rl_twi_device);
369}
370#else
371void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices) {}
372#endif
373
374
375/* --------------------------------------------------------------------
376 * SPI
377 * -------------------------------------------------------------------- */
378
379#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
380static u64 spi_dmamask = DMA_BIT_MASK(32);
381
382static struct resource spi_resources[] = {
383 [0] = {
384 .start = AT91SAM9RL_BASE_SPI,
385 .end = AT91SAM9RL_BASE_SPI + SZ_16K - 1,
386 .flags = IORESOURCE_MEM,
387 },
388 [1] = {
389 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_SPI,
390 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_SPI,
391 .flags = IORESOURCE_IRQ,
392 },
393};
394
395static struct platform_device at91sam9rl_spi_device = {
396 .name = "atmel_spi",
397 .id = 0,
398 .dev = {
399 .dma_mask = &spi_dmamask,
400 .coherent_dma_mask = DMA_BIT_MASK(32),
401 },
402 .resource = spi_resources,
403 .num_resources = ARRAY_SIZE(spi_resources),
404};
405
406static const unsigned spi_standard_cs[4] = { AT91_PIN_PA28, AT91_PIN_PB7, AT91_PIN_PD8, AT91_PIN_PD9 };
407
408
409void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices)
410{
411 int i;
412 unsigned long cs_pin;
413
414 at91_set_A_periph(AT91_PIN_PA25, 0); /* MISO */
415 at91_set_A_periph(AT91_PIN_PA26, 0); /* MOSI */
416 at91_set_A_periph(AT91_PIN_PA27, 0); /* SPCK */
417
418 /* Enable SPI chip-selects */
419 for (i = 0; i < nr_devices; i++) {
420 if (devices[i].controller_data)
421 cs_pin = (unsigned long) devices[i].controller_data;
422 else
423 cs_pin = spi_standard_cs[devices[i].chip_select];
424
425 if (!gpio_is_valid(cs_pin))
426 continue;
427
428 /* enable chip-select pin */
429 at91_set_gpio_output(cs_pin, 1);
430
431 /* pass chip-select pin to driver */
432 devices[i].controller_data = (void *) cs_pin;
433 }
434
435 spi_register_board_info(devices, nr_devices);
436 platform_device_register(&at91sam9rl_spi_device);
437}
438#else
439void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices) {}
440#endif
441
442
443/* --------------------------------------------------------------------
444 * AC97
445 * -------------------------------------------------------------------- */
446
447#if defined(CONFIG_SND_ATMEL_AC97C) || defined(CONFIG_SND_ATMEL_AC97C_MODULE)
448static u64 ac97_dmamask = DMA_BIT_MASK(32);
449static struct ac97c_platform_data ac97_data;
450
451static struct resource ac97_resources[] = {
452 [0] = {
453 .start = AT91SAM9RL_BASE_AC97C,
454 .end = AT91SAM9RL_BASE_AC97C + SZ_16K - 1,
455 .flags = IORESOURCE_MEM,
456 },
457 [1] = {
458 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_AC97C,
459 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_AC97C,
460 .flags = IORESOURCE_IRQ,
461 },
462};
463
464static struct platform_device at91sam9rl_ac97_device = {
465 .name = "atmel_ac97c",
466 .id = 0,
467 .dev = {
468 .dma_mask = &ac97_dmamask,
469 .coherent_dma_mask = DMA_BIT_MASK(32),
470 .platform_data = &ac97_data,
471 },
472 .resource = ac97_resources,
473 .num_resources = ARRAY_SIZE(ac97_resources),
474};
475
476void __init at91_add_device_ac97(struct ac97c_platform_data *data)
477{
478 if (!data)
479 return;
480
481 at91_set_A_periph(AT91_PIN_PD1, 0); /* AC97FS */
482 at91_set_A_periph(AT91_PIN_PD2, 0); /* AC97CK */
483 at91_set_A_periph(AT91_PIN_PD3, 0); /* AC97TX */
484 at91_set_A_periph(AT91_PIN_PD4, 0); /* AC97RX */
485
486 /* reset */
487 if (gpio_is_valid(data->reset_pin))
488 at91_set_gpio_output(data->reset_pin, 0);
489
490 ac97_data = *data;
491 platform_device_register(&at91sam9rl_ac97_device);
492}
493#else
494void __init at91_add_device_ac97(struct ac97c_platform_data *data) {}
495#endif
496
497
498/* --------------------------------------------------------------------
499 * LCD Controller
500 * -------------------------------------------------------------------- */
501
502#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
503static u64 lcdc_dmamask = DMA_BIT_MASK(32);
504static struct atmel_lcdfb_pdata lcdc_data;
505
506static struct resource lcdc_resources[] = {
507 [0] = {
508 .start = AT91SAM9RL_LCDC_BASE,
509 .end = AT91SAM9RL_LCDC_BASE + SZ_4K - 1,
510 .flags = IORESOURCE_MEM,
511 },
512 [1] = {
513 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_LCDC,
514 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_LCDC,
515 .flags = IORESOURCE_IRQ,
516 },
517};
518
519static struct platform_device at91_lcdc_device = {
520 .name = "at91sam9rl-lcdfb",
521 .id = 0,
522 .dev = {
523 .dma_mask = &lcdc_dmamask,
524 .coherent_dma_mask = DMA_BIT_MASK(32),
525 .platform_data = &lcdc_data,
526 },
527 .resource = lcdc_resources,
528 .num_resources = ARRAY_SIZE(lcdc_resources),
529};
530
531void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data)
532{
533 if (!data) {
534 return;
535 }
536
537 at91_set_B_periph(AT91_PIN_PC1, 0); /* LCDPWR */
538 at91_set_A_periph(AT91_PIN_PC5, 0); /* LCDHSYNC */
539 at91_set_A_periph(AT91_PIN_PC6, 0); /* LCDDOTCK */
540 at91_set_A_periph(AT91_PIN_PC7, 0); /* LCDDEN */
541 at91_set_A_periph(AT91_PIN_PC3, 0); /* LCDCC */
542 at91_set_B_periph(AT91_PIN_PC9, 0); /* LCDD3 */
543 at91_set_B_periph(AT91_PIN_PC10, 0); /* LCDD4 */
544 at91_set_B_periph(AT91_PIN_PC11, 0); /* LCDD5 */
545 at91_set_B_periph(AT91_PIN_PC12, 0); /* LCDD6 */
546 at91_set_B_periph(AT91_PIN_PC13, 0); /* LCDD7 */
547 at91_set_B_periph(AT91_PIN_PC15, 0); /* LCDD11 */
548 at91_set_B_periph(AT91_PIN_PC16, 0); /* LCDD12 */
549 at91_set_B_periph(AT91_PIN_PC17, 0); /* LCDD13 */
550 at91_set_B_periph(AT91_PIN_PC18, 0); /* LCDD14 */
551 at91_set_B_periph(AT91_PIN_PC19, 0); /* LCDD15 */
552 at91_set_B_periph(AT91_PIN_PC20, 0); /* LCDD18 */
553 at91_set_B_periph(AT91_PIN_PC21, 0); /* LCDD19 */
554 at91_set_B_periph(AT91_PIN_PC22, 0); /* LCDD20 */
555 at91_set_B_periph(AT91_PIN_PC23, 0); /* LCDD21 */
556 at91_set_B_periph(AT91_PIN_PC24, 0); /* LCDD22 */
557 at91_set_B_periph(AT91_PIN_PC25, 0); /* LCDD23 */
558
559 lcdc_data = *data;
560 platform_device_register(&at91_lcdc_device);
561}
562#else
563void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data) {}
564#endif
565
566
567/* --------------------------------------------------------------------
568 * Timer/Counter block
569 * -------------------------------------------------------------------- */
570
571#ifdef CONFIG_ATMEL_TCLIB
572
573static struct resource tcb_resources[] = {
574 [0] = {
575 .start = AT91SAM9RL_BASE_TCB0,
576 .end = AT91SAM9RL_BASE_TCB0 + SZ_16K - 1,
577 .flags = IORESOURCE_MEM,
578 },
579 [1] = {
580 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC0,
581 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC0,
582 .flags = IORESOURCE_IRQ,
583 },
584 [2] = {
585 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC1,
586 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC1,
587 .flags = IORESOURCE_IRQ,
588 },
589 [3] = {
590 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC2,
591 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_TC2,
592 .flags = IORESOURCE_IRQ,
593 },
594};
595
596static struct platform_device at91sam9rl_tcb_device = {
597 .name = "atmel_tcb",
598 .id = 0,
599 .resource = tcb_resources,
600 .num_resources = ARRAY_SIZE(tcb_resources),
601};
602
603static void __init at91_add_device_tc(void)
604{
605 platform_device_register(&at91sam9rl_tcb_device);
606}
607#else
608static void __init at91_add_device_tc(void) { }
609#endif
610
611
612/* --------------------------------------------------------------------
613 * ADC and Touchscreen
614 * -------------------------------------------------------------------- */
615
616#if IS_ENABLED(CONFIG_AT91_ADC)
617static struct at91_adc_data adc_data;
618
619static struct resource adc_resources[] = {
620 [0] = {
621 .start = AT91SAM9RL_BASE_TSC,
622 .end = AT91SAM9RL_BASE_TSC + SZ_16K - 1,
623 .flags = IORESOURCE_MEM,
624 },
625 [1] = {
626 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_TSC,
627 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_TSC,
628 .flags = IORESOURCE_IRQ,
629 }
630};
631
632static struct platform_device at91_adc_device = {
633 .name = "at91sam9rl-adc",
634 .id = -1,
635 .dev = {
636 .platform_data = &adc_data,
637 },
638 .resource = adc_resources,
639 .num_resources = ARRAY_SIZE(adc_resources),
640};
641
642static struct at91_adc_trigger at91_adc_triggers[] = {
643 [0] = {
644 .name = "external-rising",
645 .value = 1,
646 .is_external = true,
647 },
648 [1] = {
649 .name = "external-falling",
650 .value = 2,
651 .is_external = true,
652 },
653 [2] = {
654 .name = "external-any",
655 .value = 3,
656 .is_external = true,
657 },
658 [3] = {
659 .name = "continuous",
660 .value = 6,
661 .is_external = false,
662 },
663};
664
665void __init at91_add_device_adc(struct at91_adc_data *data)
666{
667 if (!data)
668 return;
669
670 if (test_bit(0, &data->channels_used))
671 at91_set_A_periph(AT91_PIN_PA17, 0);
672 if (test_bit(1, &data->channels_used))
673 at91_set_A_periph(AT91_PIN_PA18, 0);
674 if (test_bit(2, &data->channels_used))
675 at91_set_A_periph(AT91_PIN_PA19, 0);
676 if (test_bit(3, &data->channels_used))
677 at91_set_A_periph(AT91_PIN_PA20, 0);
678 if (test_bit(4, &data->channels_used))
679 at91_set_A_periph(AT91_PIN_PD6, 0);
680 if (test_bit(5, &data->channels_used))
681 at91_set_A_periph(AT91_PIN_PD7, 0);
682
683 if (data->use_external_triggers)
684 at91_set_A_periph(AT91_PIN_PB15, 0);
685
686 data->startup_time = 40;
687 data->trigger_number = 4;
688 data->trigger_list = at91_adc_triggers;
689
690 adc_data = *data;
691 platform_device_register(&at91_adc_device);
692}
693#else
694void __init at91_add_device_adc(struct at91_adc_data *data) {}
695#endif
696
697/* --------------------------------------------------------------------
698 * RTC
699 * -------------------------------------------------------------------- */
700
701#if defined(CONFIG_RTC_DRV_AT91RM9200) || defined(CONFIG_RTC_DRV_AT91RM9200_MODULE)
702static struct platform_device at91sam9rl_rtc_device = {
703 .name = "at91_rtc",
704 .id = -1,
705 .num_resources = 0,
706};
707
708static void __init at91_add_device_rtc(void)
709{
710 platform_device_register(&at91sam9rl_rtc_device);
711}
712#else
713static void __init at91_add_device_rtc(void) {}
714#endif
715
716
717/* --------------------------------------------------------------------
718 * RTT
719 * -------------------------------------------------------------------- */
720
721static struct resource rtt_resources[] = {
722 {
723 .start = AT91SAM9RL_BASE_RTT,
724 .end = AT91SAM9RL_BASE_RTT + SZ_16 - 1,
725 .flags = IORESOURCE_MEM,
726 }, {
727 .flags = IORESOURCE_MEM,
728 }, {
729 .flags = IORESOURCE_IRQ,
730 }
731};
732
733static struct platform_device at91sam9rl_rtt_device = {
734 .name = "at91_rtt",
735 .id = 0,
736 .resource = rtt_resources,
737};
738
739#if IS_ENABLED(CONFIG_RTC_DRV_AT91SAM9)
740static void __init at91_add_device_rtt_rtc(void)
741{
742 at91sam9rl_rtt_device.name = "rtc-at91sam9";
743 /*
744 * The second resource is needed:
745 * GPBR will serve as the storage for RTC time offset
746 */
747 at91sam9rl_rtt_device.num_resources = 3;
748 rtt_resources[1].start = AT91SAM9RL_BASE_GPBR +
749 4 * CONFIG_RTC_DRV_AT91SAM9_GPBR;
750 rtt_resources[1].end = rtt_resources[1].start + 3;
751 rtt_resources[2].start = NR_IRQS_LEGACY + AT91_ID_SYS;
752 rtt_resources[2].end = NR_IRQS_LEGACY + AT91_ID_SYS;
753}
754#else
755static void __init at91_add_device_rtt_rtc(void)
756{
757 /* Only one resource is needed: RTT not used as RTC */
758 at91sam9rl_rtt_device.num_resources = 1;
759}
760#endif
761
762static void __init at91_add_device_rtt(void)
763{
764 at91_add_device_rtt_rtc();
765 platform_device_register(&at91sam9rl_rtt_device);
766}
767
768
769/* --------------------------------------------------------------------
770 * Watchdog
771 * -------------------------------------------------------------------- */
772
773#if defined(CONFIG_AT91SAM9X_WATCHDOG) || defined(CONFIG_AT91SAM9X_WATCHDOG_MODULE)
774static struct resource wdt_resources[] = {
775 {
776 .start = AT91SAM9RL_BASE_WDT,
777 .end = AT91SAM9RL_BASE_WDT + SZ_16 - 1,
778 .flags = IORESOURCE_MEM,
779 }
780};
781
782static struct platform_device at91sam9rl_wdt_device = {
783 .name = "at91_wdt",
784 .id = -1,
785 .resource = wdt_resources,
786 .num_resources = ARRAY_SIZE(wdt_resources),
787};
788
789static void __init at91_add_device_watchdog(void)
790{
791 platform_device_register(&at91sam9rl_wdt_device);
792}
793#else
794static void __init at91_add_device_watchdog(void) {}
795#endif
796
797
798/* --------------------------------------------------------------------
799 * PWM
800 * --------------------------------------------------------------------*/
801
802#if IS_ENABLED(CONFIG_PWM_ATMEL)
803static struct resource pwm_resources[] = {
804 [0] = {
805 .start = AT91SAM9RL_BASE_PWMC,
806 .end = AT91SAM9RL_BASE_PWMC + SZ_16K - 1,
807 .flags = IORESOURCE_MEM,
808 },
809 [1] = {
810 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_PWMC,
811 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_PWMC,
812 .flags = IORESOURCE_IRQ,
813 },
814};
815
816static struct platform_device at91sam9rl_pwm0_device = {
817 .name = "at91sam9rl-pwm",
818 .id = -1,
819 .resource = pwm_resources,
820 .num_resources = ARRAY_SIZE(pwm_resources),
821};
822
823void __init at91_add_device_pwm(u32 mask)
824{
825 if (mask & (1 << AT91_PWM0))
826 at91_set_B_periph(AT91_PIN_PB8, 1); /* enable PWM0 */
827
828 if (mask & (1 << AT91_PWM1))
829 at91_set_B_periph(AT91_PIN_PB9, 1); /* enable PWM1 */
830
831 if (mask & (1 << AT91_PWM2))
832 at91_set_B_periph(AT91_PIN_PD5, 1); /* enable PWM2 */
833
834 if (mask & (1 << AT91_PWM3))
835 at91_set_B_periph(AT91_PIN_PD8, 1); /* enable PWM3 */
836
837 platform_device_register(&at91sam9rl_pwm0_device);
838}
839#else
840void __init at91_add_device_pwm(u32 mask) {}
841#endif
842
843
844/* --------------------------------------------------------------------
845 * SSC -- Synchronous Serial Controller
846 * -------------------------------------------------------------------- */
847
848#if defined(CONFIG_ATMEL_SSC) || defined(CONFIG_ATMEL_SSC_MODULE)
849static u64 ssc0_dmamask = DMA_BIT_MASK(32);
850
851static struct resource ssc0_resources[] = {
852 [0] = {
853 .start = AT91SAM9RL_BASE_SSC0,
854 .end = AT91SAM9RL_BASE_SSC0 + SZ_16K - 1,
855 .flags = IORESOURCE_MEM,
856 },
857 [1] = {
858 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC0,
859 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC0,
860 .flags = IORESOURCE_IRQ,
861 },
862};
863
864static struct platform_device at91sam9rl_ssc0_device = {
865 .name = "at91rm9200_ssc",
866 .id = 0,
867 .dev = {
868 .dma_mask = &ssc0_dmamask,
869 .coherent_dma_mask = DMA_BIT_MASK(32),
870 },
871 .resource = ssc0_resources,
872 .num_resources = ARRAY_SIZE(ssc0_resources),
873};
874
875static inline void configure_ssc0_pins(unsigned pins)
876{
877 if (pins & ATMEL_SSC_TF)
878 at91_set_A_periph(AT91_PIN_PC0, 1);
879 if (pins & ATMEL_SSC_TK)
880 at91_set_A_periph(AT91_PIN_PC1, 1);
881 if (pins & ATMEL_SSC_TD)
882 at91_set_A_periph(AT91_PIN_PA15, 1);
883 if (pins & ATMEL_SSC_RD)
884 at91_set_A_periph(AT91_PIN_PA16, 1);
885 if (pins & ATMEL_SSC_RK)
886 at91_set_B_periph(AT91_PIN_PA10, 1);
887 if (pins & ATMEL_SSC_RF)
888 at91_set_B_periph(AT91_PIN_PA22, 1);
889}
890
891static u64 ssc1_dmamask = DMA_BIT_MASK(32);
892
893static struct resource ssc1_resources[] = {
894 [0] = {
895 .start = AT91SAM9RL_BASE_SSC1,
896 .end = AT91SAM9RL_BASE_SSC1 + SZ_16K - 1,
897 .flags = IORESOURCE_MEM,
898 },
899 [1] = {
900 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC1,
901 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_SSC1,
902 .flags = IORESOURCE_IRQ,
903 },
904};
905
906static struct platform_device at91sam9rl_ssc1_device = {
907 .name = "at91rm9200_ssc",
908 .id = 1,
909 .dev = {
910 .dma_mask = &ssc1_dmamask,
911 .coherent_dma_mask = DMA_BIT_MASK(32),
912 },
913 .resource = ssc1_resources,
914 .num_resources = ARRAY_SIZE(ssc1_resources),
915};
916
917static inline void configure_ssc1_pins(unsigned pins)
918{
919 if (pins & ATMEL_SSC_TF)
920 at91_set_B_periph(AT91_PIN_PA29, 1);
921 if (pins & ATMEL_SSC_TK)
922 at91_set_B_periph(AT91_PIN_PA30, 1);
923 if (pins & ATMEL_SSC_TD)
924 at91_set_B_periph(AT91_PIN_PA13, 1);
925 if (pins & ATMEL_SSC_RD)
926 at91_set_B_periph(AT91_PIN_PA14, 1);
927 if (pins & ATMEL_SSC_RK)
928 at91_set_B_periph(AT91_PIN_PA9, 1);
929 if (pins & ATMEL_SSC_RF)
930 at91_set_B_periph(AT91_PIN_PA8, 1);
931}
932
933/*
934 * SSC controllers are accessed through library code, instead of any
935 * kind of all-singing/all-dancing driver. For example one could be
936 * used by a particular I2S audio codec's driver, while another one
937 * on the same system might be used by a custom data capture driver.
938 */
939void __init at91_add_device_ssc(unsigned id, unsigned pins)
940{
941 struct platform_device *pdev;
942
943 /*
944 * NOTE: caller is responsible for passing information matching
945 * "pins" to whatever will be using each particular controller.
946 */
947 switch (id) {
948 case AT91SAM9RL_ID_SSC0:
949 pdev = &at91sam9rl_ssc0_device;
950 configure_ssc0_pins(pins);
951 break;
952 case AT91SAM9RL_ID_SSC1:
953 pdev = &at91sam9rl_ssc1_device;
954 configure_ssc1_pins(pins);
955 break;
956 default:
957 return;
958 }
959
960 platform_device_register(pdev);
961}
962
963#else
964void __init at91_add_device_ssc(unsigned id, unsigned pins) {}
965#endif
966
967
968/* --------------------------------------------------------------------
969 * UART
970 * -------------------------------------------------------------------- */
971
972#if defined(CONFIG_SERIAL_ATMEL)
973static struct resource dbgu_resources[] = {
974 [0] = {
975 .start = AT91SAM9RL_BASE_DBGU,
976 .end = AT91SAM9RL_BASE_DBGU + SZ_512 - 1,
977 .flags = IORESOURCE_MEM,
978 },
979 [1] = {
980 .start = NR_IRQS_LEGACY + AT91_ID_SYS,
981 .end = NR_IRQS_LEGACY + AT91_ID_SYS,
982 .flags = IORESOURCE_IRQ,
983 },
984};
985
986static struct atmel_uart_data dbgu_data = {
987 .use_dma_tx = 0,
988 .use_dma_rx = 0, /* DBGU not capable of receive DMA */
989};
990
991static u64 dbgu_dmamask = DMA_BIT_MASK(32);
992
993static struct platform_device at91sam9rl_dbgu_device = {
994 .name = "atmel_usart",
995 .id = 0,
996 .dev = {
997 .dma_mask = &dbgu_dmamask,
998 .coherent_dma_mask = DMA_BIT_MASK(32),
999 .platform_data = &dbgu_data,
1000 },
1001 .resource = dbgu_resources,
1002 .num_resources = ARRAY_SIZE(dbgu_resources),
1003};
1004
1005static inline void configure_dbgu_pins(void)
1006{
1007 at91_set_A_periph(AT91_PIN_PA21, 0); /* DRXD */
1008 at91_set_A_periph(AT91_PIN_PA22, 1); /* DTXD */
1009}
1010
1011static struct resource uart0_resources[] = {
1012 [0] = {
1013 .start = AT91SAM9RL_BASE_US0,
1014 .end = AT91SAM9RL_BASE_US0 + SZ_16K - 1,
1015 .flags = IORESOURCE_MEM,
1016 },
1017 [1] = {
1018 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US0,
1019 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US0,
1020 .flags = IORESOURCE_IRQ,
1021 },
1022};
1023
1024static struct atmel_uart_data uart0_data = {
1025 .use_dma_tx = 1,
1026 .use_dma_rx = 1,
1027};
1028
1029static u64 uart0_dmamask = DMA_BIT_MASK(32);
1030
1031static struct platform_device at91sam9rl_uart0_device = {
1032 .name = "atmel_usart",
1033 .id = 1,
1034 .dev = {
1035 .dma_mask = &uart0_dmamask,
1036 .coherent_dma_mask = DMA_BIT_MASK(32),
1037 .platform_data = &uart0_data,
1038 },
1039 .resource = uart0_resources,
1040 .num_resources = ARRAY_SIZE(uart0_resources),
1041};
1042
1043static inline void configure_usart0_pins(unsigned pins)
1044{
1045 at91_set_A_periph(AT91_PIN_PA6, 1); /* TXD0 */
1046 at91_set_A_periph(AT91_PIN_PA7, 0); /* RXD0 */
1047
1048 if (pins & ATMEL_UART_RTS)
1049 at91_set_A_periph(AT91_PIN_PA9, 0); /* RTS0 */
1050 if (pins & ATMEL_UART_CTS)
1051 at91_set_A_periph(AT91_PIN_PA10, 0); /* CTS0 */
1052 if (pins & ATMEL_UART_DSR)
1053 at91_set_A_periph(AT91_PIN_PD14, 0); /* DSR0 */
1054 if (pins & ATMEL_UART_DTR)
1055 at91_set_A_periph(AT91_PIN_PD15, 0); /* DTR0 */
1056 if (pins & ATMEL_UART_DCD)
1057 at91_set_A_periph(AT91_PIN_PD16, 0); /* DCD0 */
1058 if (pins & ATMEL_UART_RI)
1059 at91_set_A_periph(AT91_PIN_PD17, 0); /* RI0 */
1060}
1061
1062static struct resource uart1_resources[] = {
1063 [0] = {
1064 .start = AT91SAM9RL_BASE_US1,
1065 .end = AT91SAM9RL_BASE_US1 + SZ_16K - 1,
1066 .flags = IORESOURCE_MEM,
1067 },
1068 [1] = {
1069 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US1,
1070 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US1,
1071 .flags = IORESOURCE_IRQ,
1072 },
1073};
1074
1075static struct atmel_uart_data uart1_data = {
1076 .use_dma_tx = 1,
1077 .use_dma_rx = 1,
1078};
1079
1080static u64 uart1_dmamask = DMA_BIT_MASK(32);
1081
1082static struct platform_device at91sam9rl_uart1_device = {
1083 .name = "atmel_usart",
1084 .id = 2,
1085 .dev = {
1086 .dma_mask = &uart1_dmamask,
1087 .coherent_dma_mask = DMA_BIT_MASK(32),
1088 .platform_data = &uart1_data,
1089 },
1090 .resource = uart1_resources,
1091 .num_resources = ARRAY_SIZE(uart1_resources),
1092};
1093
1094static inline void configure_usart1_pins(unsigned pins)
1095{
1096 at91_set_A_periph(AT91_PIN_PA11, 1); /* TXD1 */
1097 at91_set_A_periph(AT91_PIN_PA12, 0); /* RXD1 */
1098
1099 if (pins & ATMEL_UART_RTS)
1100 at91_set_B_periph(AT91_PIN_PA18, 0); /* RTS1 */
1101 if (pins & ATMEL_UART_CTS)
1102 at91_set_B_periph(AT91_PIN_PA19, 0); /* CTS1 */
1103}
1104
1105static struct resource uart2_resources[] = {
1106 [0] = {
1107 .start = AT91SAM9RL_BASE_US2,
1108 .end = AT91SAM9RL_BASE_US2 + SZ_16K - 1,
1109 .flags = IORESOURCE_MEM,
1110 },
1111 [1] = {
1112 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US2,
1113 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US2,
1114 .flags = IORESOURCE_IRQ,
1115 },
1116};
1117
1118static struct atmel_uart_data uart2_data = {
1119 .use_dma_tx = 1,
1120 .use_dma_rx = 1,
1121};
1122
1123static u64 uart2_dmamask = DMA_BIT_MASK(32);
1124
1125static struct platform_device at91sam9rl_uart2_device = {
1126 .name = "atmel_usart",
1127 .id = 3,
1128 .dev = {
1129 .dma_mask = &uart2_dmamask,
1130 .coherent_dma_mask = DMA_BIT_MASK(32),
1131 .platform_data = &uart2_data,
1132 },
1133 .resource = uart2_resources,
1134 .num_resources = ARRAY_SIZE(uart2_resources),
1135};
1136
1137static inline void configure_usart2_pins(unsigned pins)
1138{
1139 at91_set_A_periph(AT91_PIN_PA13, 1); /* TXD2 */
1140 at91_set_A_periph(AT91_PIN_PA14, 0); /* RXD2 */
1141
1142 if (pins & ATMEL_UART_RTS)
1143 at91_set_A_periph(AT91_PIN_PA29, 0); /* RTS2 */
1144 if (pins & ATMEL_UART_CTS)
1145 at91_set_A_periph(AT91_PIN_PA30, 0); /* CTS2 */
1146}
1147
1148static struct resource uart3_resources[] = {
1149 [0] = {
1150 .start = AT91SAM9RL_BASE_US3,
1151 .end = AT91SAM9RL_BASE_US3 + SZ_16K - 1,
1152 .flags = IORESOURCE_MEM,
1153 },
1154 [1] = {
1155 .start = NR_IRQS_LEGACY + AT91SAM9RL_ID_US3,
1156 .end = NR_IRQS_LEGACY + AT91SAM9RL_ID_US3,
1157 .flags = IORESOURCE_IRQ,
1158 },
1159};
1160
1161static struct atmel_uart_data uart3_data = {
1162 .use_dma_tx = 1,
1163 .use_dma_rx = 1,
1164};
1165
1166static u64 uart3_dmamask = DMA_BIT_MASK(32);
1167
1168static struct platform_device at91sam9rl_uart3_device = {
1169 .name = "atmel_usart",
1170 .id = 4,
1171 .dev = {
1172 .dma_mask = &uart3_dmamask,
1173 .coherent_dma_mask = DMA_BIT_MASK(32),
1174 .platform_data = &uart3_data,
1175 },
1176 .resource = uart3_resources,
1177 .num_resources = ARRAY_SIZE(uart3_resources),
1178};
1179
1180static inline void configure_usart3_pins(unsigned pins)
1181{
1182 at91_set_A_periph(AT91_PIN_PB0, 1); /* TXD3 */
1183 at91_set_A_periph(AT91_PIN_PB1, 0); /* RXD3 */
1184
1185 if (pins & ATMEL_UART_RTS)
1186 at91_set_B_periph(AT91_PIN_PD4, 0); /* RTS3 */
1187 if (pins & ATMEL_UART_CTS)
1188 at91_set_B_periph(AT91_PIN_PD3, 0); /* CTS3 */
1189}
1190
1191static struct platform_device *__initdata at91_uarts[ATMEL_MAX_UART]; /* the UARTs to use */
1192
1193void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins)
1194{
1195 struct platform_device *pdev;
1196 struct atmel_uart_data *pdata;
1197
1198 switch (id) {
1199 case 0: /* DBGU */
1200 pdev = &at91sam9rl_dbgu_device;
1201 configure_dbgu_pins();
1202 break;
1203 case AT91SAM9RL_ID_US0:
1204 pdev = &at91sam9rl_uart0_device;
1205 configure_usart0_pins(pins);
1206 break;
1207 case AT91SAM9RL_ID_US1:
1208 pdev = &at91sam9rl_uart1_device;
1209 configure_usart1_pins(pins);
1210 break;
1211 case AT91SAM9RL_ID_US2:
1212 pdev = &at91sam9rl_uart2_device;
1213 configure_usart2_pins(pins);
1214 break;
1215 case AT91SAM9RL_ID_US3:
1216 pdev = &at91sam9rl_uart3_device;
1217 configure_usart3_pins(pins);
1218 break;
1219 default:
1220 return;
1221 }
1222 pdata = pdev->dev.platform_data;
1223 pdata->num = portnr; /* update to mapped ID */
1224
1225 if (portnr < ATMEL_MAX_UART)
1226 at91_uarts[portnr] = pdev;
1227}
1228
1229void __init at91_add_device_serial(void)
1230{
1231 int i;
1232
1233 for (i = 0; i < ATMEL_MAX_UART; i++) {
1234 if (at91_uarts[i])
1235 platform_device_register(at91_uarts[i]);
1236 }
1237}
1238#else
1239void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins) {}
1240void __init at91_add_device_serial(void) {}
1241#endif
1242
1243
1244/* -------------------------------------------------------------------- */
1245
1246/*
1247 * These devices are always present and don't need any board-specific
1248 * setup.
1249 */
1250static int __init at91_add_standard_devices(void)
1251{
1252 at91_add_device_hdmac();
1253 at91_add_device_rtc();
1254 at91_add_device_rtt();
1255 at91_add_device_watchdog();
1256 at91_add_device_tc();
1257 return 0;
1258}
1259
1260arch_initcall(at91_add_standard_devices);
diff --git a/arch/arm/mach-at91/at91sam9x5.c b/arch/arm/mach-at91/at91sam9x5.c
index 028268ff3722..f0d5a69a7237 100644
--- a/arch/arm/mach-at91/at91sam9x5.c
+++ b/arch/arm/mach-at91/at91sam9x5.c
@@ -6,317 +6,11 @@
6 * Licensed under GPLv2 or later. 6 * Licensed under GPLv2 or later.
7 */ 7 */
8 8
9#include <linux/module.h> 9#include <asm/system_misc.h>
10#include <linux/dma-mapping.h> 10#include <mach/hardware.h>
11#include <linux/clk/at91_pmc.h>
12 11
13#include <asm/irq.h>
14#include <asm/mach/arch.h>
15#include <asm/mach/map.h>
16#include <mach/at91sam9x5.h>
17#include <mach/cpu.h>
18
19#include "board.h"
20#include "soc.h" 12#include "soc.h"
21#include "generic.h" 13#include "generic.h"
22#include "sam9_smc.h"
23
24#if defined(CONFIG_OLD_CLK_AT91)
25#include "clock.h"
26/* --------------------------------------------------------------------
27 * Clocks
28 * -------------------------------------------------------------------- */
29
30/*
31 * The peripheral clocks.
32 */
33static struct clk pioAB_clk = {
34 .name = "pioAB_clk",
35 .pmc_mask = 1 << AT91SAM9X5_ID_PIOAB,
36 .type = CLK_TYPE_PERIPHERAL,
37};
38static struct clk pioCD_clk = {
39 .name = "pioCD_clk",
40 .pmc_mask = 1 << AT91SAM9X5_ID_PIOCD,
41 .type = CLK_TYPE_PERIPHERAL,
42};
43static struct clk smd_clk = {
44 .name = "smd_clk",
45 .pmc_mask = 1 << AT91SAM9X5_ID_SMD,
46 .type = CLK_TYPE_PERIPHERAL,
47};
48static struct clk usart0_clk = {
49 .name = "usart0_clk",
50 .pmc_mask = 1 << AT91SAM9X5_ID_USART0,
51 .type = CLK_TYPE_PERIPHERAL,
52};
53static struct clk usart1_clk = {
54 .name = "usart1_clk",
55 .pmc_mask = 1 << AT91SAM9X5_ID_USART1,
56 .type = CLK_TYPE_PERIPHERAL,
57};
58static struct clk usart2_clk = {
59 .name = "usart2_clk",
60 .pmc_mask = 1 << AT91SAM9X5_ID_USART2,
61 .type = CLK_TYPE_PERIPHERAL,
62};
63/* USART3 clock - Only for sam9g25/sam9x25 */
64static struct clk usart3_clk = {
65 .name = "usart3_clk",
66 .pmc_mask = 1 << AT91SAM9X5_ID_USART3,
67 .type = CLK_TYPE_PERIPHERAL,
68};
69static struct clk twi0_clk = {
70 .name = "twi0_clk",
71 .pmc_mask = 1 << AT91SAM9X5_ID_TWI0,
72 .type = CLK_TYPE_PERIPHERAL,
73};
74static struct clk twi1_clk = {
75 .name = "twi1_clk",
76 .pmc_mask = 1 << AT91SAM9X5_ID_TWI1,
77 .type = CLK_TYPE_PERIPHERAL,
78};
79static struct clk twi2_clk = {
80 .name = "twi2_clk",
81 .pmc_mask = 1 << AT91SAM9X5_ID_TWI2,
82 .type = CLK_TYPE_PERIPHERAL,
83};
84static struct clk mmc0_clk = {
85 .name = "mci0_clk",
86 .pmc_mask = 1 << AT91SAM9X5_ID_MCI0,
87 .type = CLK_TYPE_PERIPHERAL,
88};
89static struct clk spi0_clk = {
90 .name = "spi0_clk",
91 .pmc_mask = 1 << AT91SAM9X5_ID_SPI0,
92 .type = CLK_TYPE_PERIPHERAL,
93};
94static struct clk spi1_clk = {
95 .name = "spi1_clk",
96 .pmc_mask = 1 << AT91SAM9X5_ID_SPI1,
97 .type = CLK_TYPE_PERIPHERAL,
98};
99static struct clk uart0_clk = {
100 .name = "uart0_clk",
101 .pmc_mask = 1 << AT91SAM9X5_ID_UART0,
102 .type = CLK_TYPE_PERIPHERAL,
103};
104static struct clk uart1_clk = {
105 .name = "uart1_clk",
106 .pmc_mask = 1 << AT91SAM9X5_ID_UART1,
107 .type = CLK_TYPE_PERIPHERAL,
108};
109static struct clk tcb0_clk = {
110 .name = "tcb0_clk",
111 .pmc_mask = 1 << AT91SAM9X5_ID_TCB,
112 .type = CLK_TYPE_PERIPHERAL,
113};
114static struct clk pwm_clk = {
115 .name = "pwm_clk",
116 .pmc_mask = 1 << AT91SAM9X5_ID_PWM,
117 .type = CLK_TYPE_PERIPHERAL,
118};
119static struct clk adc_clk = {
120 .name = "adc_clk",
121 .pmc_mask = 1 << AT91SAM9X5_ID_ADC,
122 .type = CLK_TYPE_PERIPHERAL,
123};
124static struct clk adc_op_clk = {
125 .name = "adc_op_clk",
126 .type = CLK_TYPE_PERIPHERAL,
127 .rate_hz = 5000000,
128};
129static struct clk dma0_clk = {
130 .name = "dma0_clk",
131 .pmc_mask = 1 << AT91SAM9X5_ID_DMA0,
132 .type = CLK_TYPE_PERIPHERAL,
133};
134static struct clk dma1_clk = {
135 .name = "dma1_clk",
136 .pmc_mask = 1 << AT91SAM9X5_ID_DMA1,
137 .type = CLK_TYPE_PERIPHERAL,
138};
139static struct clk uhphs_clk = {
140 .name = "uhphs",
141 .pmc_mask = 1 << AT91SAM9X5_ID_UHPHS,
142 .type = CLK_TYPE_PERIPHERAL,
143};
144static struct clk udphs_clk = {
145 .name = "udphs_clk",
146 .pmc_mask = 1 << AT91SAM9X5_ID_UDPHS,
147 .type = CLK_TYPE_PERIPHERAL,
148};
149/* emac0 clock - Only for sam9g25/sam9x25/sam9g35/sam9x35 */
150static struct clk macb0_clk = {
151 .name = "pclk",
152 .pmc_mask = 1 << AT91SAM9X5_ID_EMAC0,
153 .type = CLK_TYPE_PERIPHERAL,
154};
155/* lcd clock - Only for sam9g15/sam9g35/sam9x35 */
156static struct clk lcdc_clk = {
157 .name = "lcdc_clk",
158 .pmc_mask = 1 << AT91SAM9X5_ID_LCDC,
159 .type = CLK_TYPE_PERIPHERAL,
160};
161/* isi clock - Only for sam9g25 */
162static struct clk isi_clk = {
163 .name = "isi_clk",
164 .pmc_mask = 1 << AT91SAM9X5_ID_ISI,
165 .type = CLK_TYPE_PERIPHERAL,
166};
167static struct clk mmc1_clk = {
168 .name = "mci1_clk",
169 .pmc_mask = 1 << AT91SAM9X5_ID_MCI1,
170 .type = CLK_TYPE_PERIPHERAL,
171};
172/* emac1 clock - Only for sam9x25 */
173static struct clk macb1_clk = {
174 .name = "pclk",
175 .pmc_mask = 1 << AT91SAM9X5_ID_EMAC1,
176 .type = CLK_TYPE_PERIPHERAL,
177};
178static struct clk ssc_clk = {
179 .name = "ssc_clk",
180 .pmc_mask = 1 << AT91SAM9X5_ID_SSC,
181 .type = CLK_TYPE_PERIPHERAL,
182};
183/* can0 clock - Only for sam9x35 */
184static struct clk can0_clk = {
185 .name = "can0_clk",
186 .pmc_mask = 1 << AT91SAM9X5_ID_CAN0,
187 .type = CLK_TYPE_PERIPHERAL,
188};
189/* can1 clock - Only for sam9x35 */
190static struct clk can1_clk = {
191 .name = "can1_clk",
192 .pmc_mask = 1 << AT91SAM9X5_ID_CAN1,
193 .type = CLK_TYPE_PERIPHERAL,
194};
195
196static struct clk *periph_clocks[] __initdata = {
197 &pioAB_clk,
198 &pioCD_clk,
199 &smd_clk,
200 &usart0_clk,
201 &usart1_clk,
202 &usart2_clk,
203 &twi0_clk,
204 &twi1_clk,
205 &twi2_clk,
206 &mmc0_clk,
207 &spi0_clk,
208 &spi1_clk,
209 &uart0_clk,
210 &uart1_clk,
211 &tcb0_clk,
212 &pwm_clk,
213 &adc_clk,
214 &adc_op_clk,
215 &dma0_clk,
216 &dma1_clk,
217 &uhphs_clk,
218 &udphs_clk,
219 &mmc1_clk,
220 &ssc_clk,
221 // irq0
222};
223
224static struct clk_lookup periph_clocks_lookups[] = {
225 /* lookup table for DT entries */
226 CLKDEV_CON_DEV_ID("usart", "fffff200.serial", &mck),
227 CLKDEV_CON_DEV_ID("usart", "f801c000.serial", &usart0_clk),
228 CLKDEV_CON_DEV_ID("usart", "f8020000.serial", &usart1_clk),
229 CLKDEV_CON_DEV_ID("usart", "f8024000.serial", &usart2_clk),
230 CLKDEV_CON_DEV_ID("usart", "f8028000.serial", &usart3_clk),
231 CLKDEV_CON_DEV_ID("usart", "f8040000.serial", &uart0_clk),
232 CLKDEV_CON_DEV_ID("usart", "f8044000.serial", &uart1_clk),
233 CLKDEV_CON_DEV_ID("t0_clk", "f8008000.timer", &tcb0_clk),
234 CLKDEV_CON_DEV_ID("t0_clk", "f800c000.timer", &tcb0_clk),
235 CLKDEV_CON_DEV_ID("mci_clk", "f0008000.mmc", &mmc0_clk),
236 CLKDEV_CON_DEV_ID("mci_clk", "f000c000.mmc", &mmc1_clk),
237 CLKDEV_CON_DEV_ID("dma_clk", "ffffec00.dma-controller", &dma0_clk),
238 CLKDEV_CON_DEV_ID("dma_clk", "ffffee00.dma-controller", &dma1_clk),
239 CLKDEV_CON_DEV_ID("pclk", "f0010000.ssc", &ssc_clk),
240 CLKDEV_CON_DEV_ID(NULL, "f8010000.i2c", &twi0_clk),
241 CLKDEV_CON_DEV_ID(NULL, "f8014000.i2c", &twi1_clk),
242 CLKDEV_CON_DEV_ID(NULL, "f8018000.i2c", &twi2_clk),
243 CLKDEV_CON_DEV_ID("spi_clk", "f0000000.spi", &spi0_clk),
244 CLKDEV_CON_DEV_ID("spi_clk", "f0004000.spi", &spi1_clk),
245 CLKDEV_CON_DEV_ID(NULL, "fffff400.gpio", &pioAB_clk),
246 CLKDEV_CON_DEV_ID(NULL, "fffff600.gpio", &pioAB_clk),
247 CLKDEV_CON_DEV_ID(NULL, "fffff800.gpio", &pioCD_clk),
248 CLKDEV_CON_DEV_ID(NULL, "fffffa00.gpio", &pioCD_clk),
249 /* additional fake clock for macb_hclk */
250 CLKDEV_CON_DEV_ID("hclk", "f802c000.ethernet", &macb0_clk),
251 CLKDEV_CON_DEV_ID("hclk", "f8030000.ethernet", &macb1_clk),
252 CLKDEV_CON_DEV_ID("hclk", "600000.ohci", &uhphs_clk),
253 CLKDEV_CON_DEV_ID("ohci_clk", "600000.ohci", &uhphs_clk),
254 CLKDEV_CON_DEV_ID("ehci_clk", "700000.ehci", &uhphs_clk),
255 CLKDEV_CON_DEV_ID("hclk", "500000.gadget", &utmi_clk),
256 CLKDEV_CON_DEV_ID("pclk", "500000.gadget", &udphs_clk),
257 CLKDEV_CON_DEV_ID(NULL, "f8034000.pwm", &pwm_clk),
258};
259
260/*
261 * The two programmable clocks.
262 * You must configure pin multiplexing to bring these signals out.
263 */
264static struct clk pck0 = {
265 .name = "pck0",
266 .pmc_mask = AT91_PMC_PCK0,
267 .type = CLK_TYPE_PROGRAMMABLE,
268 .id = 0,
269};
270static struct clk pck1 = {
271 .name = "pck1",
272 .pmc_mask = AT91_PMC_PCK1,
273 .type = CLK_TYPE_PROGRAMMABLE,
274 .id = 1,
275};
276
277static void __init at91sam9x5_register_clocks(void)
278{
279 int i;
280
281 for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
282 clk_register(periph_clocks[i]);
283
284 clkdev_add_table(periph_clocks_lookups,
285 ARRAY_SIZE(periph_clocks_lookups));
286
287 if (cpu_is_at91sam9g25()
288 || cpu_is_at91sam9x25())
289 clk_register(&usart3_clk);
290
291 if (cpu_is_at91sam9g25()
292 || cpu_is_at91sam9x25()
293 || cpu_is_at91sam9g35()
294 || cpu_is_at91sam9x35())
295 clk_register(&macb0_clk);
296
297 if (cpu_is_at91sam9g15()
298 || cpu_is_at91sam9g35()
299 || cpu_is_at91sam9x35())
300 clk_register(&lcdc_clk);
301
302 if (cpu_is_at91sam9g25())
303 clk_register(&isi_clk);
304
305 if (cpu_is_at91sam9x25())
306 clk_register(&macb1_clk);
307
308 if (cpu_is_at91sam9x25()
309 || cpu_is_at91sam9x35()) {
310 clk_register(&can0_clk);
311 clk_register(&can1_clk);
312 }
313
314 clk_register(&pck0);
315 clk_register(&pck1);
316}
317#else
318#define at91sam9x5_register_clocks NULL
319#endif
320 14
321/* -------------------------------------------------------------------- 15/* --------------------------------------------------------------------
322 * AT91SAM9x5 processor initialization 16 * AT91SAM9x5 processor initialization
@@ -338,6 +32,5 @@ static void __init at91sam9x5_initialize(void)
338 32
339AT91_SOC_START(at91sam9x5) 33AT91_SOC_START(at91sam9x5)
340 .map_io = at91sam9x5_map_io, 34 .map_io = at91sam9x5_map_io,
341 .register_clocks = at91sam9x5_register_clocks,
342 .init = at91sam9x5_initialize, 35 .init = at91sam9x5_initialize,
343AT91_SOC_END 36AT91_SOC_END
diff --git a/arch/arm/mach-at91/at91x40.c b/arch/arm/mach-at91/at91x40.c
deleted file mode 100644
index 7523f1cdfe1d..000000000000
--- a/arch/arm/mach-at91/at91x40.c
+++ /dev/null
@@ -1,93 +0,0 @@
1/*
2 * arch/arm/mach-at91/at91x40.c
3 *
4 * (C) Copyright 2007, Greg Ungerer <gerg@snapgear.com>
5 * Copyright (C) 2005 SAN People
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
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/irq.h>
16#include <linux/io.h>
17#include <asm/proc-fns.h>
18#include <asm/system_misc.h>
19#include <asm/mach/arch.h>
20#include <mach/at91x40.h>
21#include <mach/at91_st.h>
22#include <mach/hardware.h>
23
24#include "at91_aic.h"
25#include "generic.h"
26
27/*
28 * Export the clock functions for the AT91X40. Some external code common
29 * to all AT91 family parts relys on this, like the gpio and serial support.
30 */
31int clk_enable(struct clk *clk)
32{
33 return 0;
34}
35
36void clk_disable(struct clk *clk)
37{
38}
39
40unsigned long clk_get_rate(struct clk *clk)
41{
42 return AT91X40_MASTER_CLOCK;
43}
44
45static void at91x40_idle(void)
46{
47 /*
48 * Disable the processor clock. The processor will be automatically
49 * re-enabled by an interrupt or by a reset.
50 */
51 __raw_writel(AT91_PS_CR_CPU, AT91_IO_P2V(AT91_PS_CR));
52 cpu_do_idle();
53}
54
55void __init at91x40_initialize(unsigned long main_clock)
56{
57 arm_pm_idle = at91x40_idle;
58}
59
60/*
61 * The default interrupt priority levels (0 = lowest, 7 = highest).
62 */
63static unsigned int at91x40_default_irq_priority[NR_AIC_IRQS] __initdata = {
64 7, /* Advanced Interrupt Controller (FIQ) */
65 0, /* System Peripherals */
66 0, /* USART 0 */
67 0, /* USART 1 */
68 2, /* Timer Counter 0 */
69 2, /* Timer Counter 1 */
70 2, /* Timer Counter 2 */
71 0, /* Watchdog timer */
72 0, /* Parallel IO Controller A */
73 0, /* Reserved */
74 0, /* Reserved */
75 0, /* Reserved */
76 0, /* Reserved */
77 0, /* Reserved */
78 0, /* Reserved */
79 0, /* Reserved */
80 0, /* External IRQ0 */
81 0, /* External IRQ1 */
82 0, /* External IRQ2 */
83};
84
85void __init at91x40_init_interrupts(unsigned int priority[NR_AIC_IRQS])
86{
87 u32 extern_irq = (1 << AT91X40_ID_IRQ0) | (1 << AT91X40_ID_IRQ1)
88 | (1 << AT91X40_ID_IRQ2);
89 if (!priority)
90 priority = at91x40_default_irq_priority;
91
92 at91_aic_init(priority, extern_irq);
93}
diff --git a/arch/arm/mach-at91/at91x40_time.c b/arch/arm/mach-at91/at91x40_time.c
deleted file mode 100644
index 07d0bf2ac2da..000000000000
--- a/arch/arm/mach-at91/at91x40_time.c
+++ /dev/null
@@ -1,85 +0,0 @@
1/*
2 * arch/arm/mach-at91/at91x40_time.c
3 *
4 * (C) Copyright 2007, Greg Ungerer <gerg@snapgear.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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/interrupt.h>
24#include <linux/irq.h>
25#include <linux/time.h>
26#include <linux/io.h>
27#include <mach/hardware.h>
28#include <mach/at91x40.h>
29#include <asm/mach/time.h>
30
31#include "at91_tc.h"
32
33#define at91_tc_read(field) \
34 __raw_readl(AT91_IO_P2V(AT91_TC) + field)
35
36#define at91_tc_write(field, value) \
37 __raw_writel(value, AT91_IO_P2V(AT91_TC) + field)
38
39/*
40 * 3 counter/timer units present.
41 */
42#define AT91_TC_CLK0BASE 0
43#define AT91_TC_CLK1BASE 0x40
44#define AT91_TC_CLK2BASE 0x80
45
46static u32 at91x40_gettimeoffset(void)
47{
48 return (at91_tc_read(AT91_TC_CLK1BASE + AT91_TC_CV) * 1000000 /
49 (AT91X40_MASTER_CLOCK / 128)) * 1000;
50}
51
52static irqreturn_t at91x40_timer_interrupt(int irq, void *dev_id)
53{
54 at91_tc_read(AT91_TC_CLK1BASE + AT91_TC_SR);
55 timer_tick();
56 return IRQ_HANDLED;
57}
58
59static struct irqaction at91x40_timer_irq = {
60 .name = "at91_tick",
61 .flags = IRQF_TIMER,
62 .handler = at91x40_timer_interrupt
63};
64
65void __init at91x40_timer_init(void)
66{
67 unsigned int v;
68
69 arch_gettimeoffset = at91x40_gettimeoffset;
70
71 at91_tc_write(AT91_TC_BCR, 0);
72 v = at91_tc_read(AT91_TC_BMR);
73 v = (v & ~AT91_TC_TC1XC1S) | AT91_TC_TC1XC1S_NONE;
74 at91_tc_write(AT91_TC_BMR, v);
75
76 at91_tc_write(AT91_TC_CLK1BASE + AT91_TC_CCR, AT91_TC_CLKDIS);
77 at91_tc_write(AT91_TC_CLK1BASE + AT91_TC_CMR, (AT91_TC_TIMER_CLOCK4 | AT91_TC_CPCTRG));
78 at91_tc_write(AT91_TC_CLK1BASE + AT91_TC_IDR, 0xffffffff);
79 at91_tc_write(AT91_TC_CLK1BASE + AT91_TC_RC, (AT91X40_MASTER_CLOCK / 128) / HZ - 1);
80 at91_tc_write(AT91_TC_CLK1BASE + AT91_TC_IER, (1<<4));
81
82 setup_irq(AT91X40_ID_TC1, &at91x40_timer_irq);
83
84 at91_tc_write(AT91_TC_CLK1BASE + AT91_TC_CCR, (AT91_TC_SWTRG | AT91_TC_CLKEN));
85}
diff --git a/arch/arm/mach-at91/board-1arm.c b/arch/arm/mach-at91/board-1arm.c
deleted file mode 100644
index 3f6dbcc34022..000000000000
--- a/arch/arm/mach-at91/board-1arm.c
+++ /dev/null
@@ -1,99 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-1arm.c
3 *
4 * Copyright (C) 2005 SAN People
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/types.h>
22#include <linux/gpio.h>
23#include <linux/init.h>
24#include <linux/mm.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
27
28#include <mach/hardware.h>
29#include <asm/setup.h>
30#include <asm/mach-types.h>
31#include <asm/irq.h>
32
33#include <asm/mach/arch.h>
34#include <asm/mach/map.h>
35#include <asm/mach/irq.h>
36
37#include <mach/cpu.h>
38
39#include "at91_aic.h"
40#include "board.h"
41#include "generic.h"
42#include "gpio.h"
43
44static void __init onearm_init_early(void)
45{
46 /* Set cpu type: PQFP */
47 at91rm9200_set_type(ARCH_REVISON_9200_PQFP);
48
49 /* Initialize processor: 18.432 MHz crystal */
50 at91_initialize(18432000);
51}
52
53static struct macb_platform_data __initdata onearm_eth_data = {
54 .phy_irq_pin = AT91_PIN_PC4,
55 .is_rmii = 1,
56};
57
58static struct at91_usbh_data __initdata onearm_usbh_data = {
59 .ports = 1,
60 .vbus_pin = {-EINVAL, -EINVAL},
61 .overcurrent_pin= {-EINVAL, -EINVAL},
62};
63
64static struct at91_udc_data __initdata onearm_udc_data = {
65 .vbus_pin = AT91_PIN_PC2,
66 .pullup_pin = AT91_PIN_PC3,
67};
68
69static void __init onearm_board_init(void)
70{
71 /* Serial */
72 /* DBGU on ttyS0. (Rx & Tx only) */
73 at91_register_uart(0, 0, 0);
74
75 /* USART0 on ttyS1 (Rx, Tx, CTS, RTS) */
76 at91_register_uart(AT91RM9200_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS);
77
78 /* USART1 on ttyS2 (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
79 at91_register_uart(AT91RM9200_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS
80 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
81 | ATMEL_UART_RI);
82 at91_add_device_serial();
83 /* Ethernet */
84 at91_add_device_eth(&onearm_eth_data);
85 /* USB Host */
86 at91_add_device_usbh(&onearm_usbh_data);
87 /* USB Device */
88 at91_add_device_udc(&onearm_udc_data);
89}
90
91MACHINE_START(ONEARM, "Ajeco 1ARM single board computer")
92 /* Maintainer: Lennert Buytenhek <buytenh@wantstofly.org> */
93 .init_time = at91rm9200_timer_init,
94 .map_io = at91_map_io,
95 .handle_irq = at91_aic_handle_irq,
96 .init_early = onearm_init_early,
97 .init_irq = at91_init_irq_default,
98 .init_machine = onearm_board_init,
99MACHINE_END
diff --git a/arch/arm/mach-at91/board-afeb-9260v1.c b/arch/arm/mach-at91/board-afeb-9260v1.c
deleted file mode 100644
index e76e35ce81e7..000000000000
--- a/arch/arm/mach-at91/board-afeb-9260v1.c
+++ /dev/null
@@ -1,223 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-afeb-9260v1.c
3 *
4 * Copyright (C) 2005 SAN People
5 * Copyright (C) 2006 Atmel
6 * Copyright (C) 2008 Sergey Lapin
7 *
8 * A custom board designed as open hardware; PCBs and various information
9 * is available at http://groups.google.com/group/arm9fpga-evolution-board/
10 * Subversion repository: svn://194.85.238.22/home/users/george/svn/arm9eb
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27#include <linux/types.h>
28#include <linux/gpio.h>
29#include <linux/init.h>
30#include <linux/mm.h>
31#include <linux/module.h>
32#include <linux/platform_device.h>
33#include <linux/spi/spi.h>
34#include <linux/clk.h>
35#include <linux/dma-mapping.h>
36
37#include <mach/hardware.h>
38#include <asm/setup.h>
39#include <asm/mach-types.h>
40#include <asm/irq.h>
41
42#include <asm/mach/arch.h>
43#include <asm/mach/map.h>
44#include <asm/mach/irq.h>
45
46#include "at91_aic.h"
47#include "board.h"
48#include "generic.h"
49#include "gpio.h"
50
51
52static void __init afeb9260_init_early(void)
53{
54 /* Initialize processor: 18.432 MHz crystal */
55 at91_initialize(18432000);
56}
57
58/*
59 * USB Host port
60 */
61static struct at91_usbh_data __initdata afeb9260_usbh_data = {
62 .ports = 1,
63 .vbus_pin = {-EINVAL, -EINVAL},
64 .overcurrent_pin= {-EINVAL, -EINVAL},
65};
66
67/*
68 * USB Device port
69 */
70static struct at91_udc_data __initdata afeb9260_udc_data = {
71 .vbus_pin = AT91_PIN_PC5,
72 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
73};
74
75
76
77/*
78 * SPI devices.
79 */
80static struct spi_board_info afeb9260_spi_devices[] = {
81 { /* DataFlash chip */
82 .modalias = "mtd_dataflash",
83 .chip_select = 1,
84 .max_speed_hz = 15 * 1000 * 1000,
85 .bus_num = 0,
86 },
87};
88
89
90/*
91 * MACB Ethernet device
92 */
93static struct macb_platform_data __initdata afeb9260_macb_data = {
94 .phy_irq_pin = AT91_PIN_PA9,
95 .is_rmii = 0,
96};
97
98
99/*
100 * NAND flash
101 */
102static struct mtd_partition __initdata afeb9260_nand_partition[] = {
103 {
104 .name = "bootloader",
105 .offset = 0,
106 .size = (640 * SZ_1K),
107 },
108 {
109 .name = "kernel",
110 .offset = MTDPART_OFS_NXTBLK,
111 .size = SZ_2M,
112 },
113 {
114 .name = "rootfs",
115 .offset = MTDPART_OFS_NXTBLK,
116 .size = MTDPART_SIZ_FULL,
117 },
118};
119
120static struct atmel_nand_data __initdata afeb9260_nand_data = {
121 .ale = 21,
122 .cle = 22,
123 .rdy_pin = AT91_PIN_PC13,
124 .enable_pin = AT91_PIN_PC14,
125 .bus_width_16 = 0,
126 .ecc_mode = NAND_ECC_SOFT,
127 .parts = afeb9260_nand_partition,
128 .num_parts = ARRAY_SIZE(afeb9260_nand_partition),
129 .det_pin = -EINVAL,
130};
131
132
133/*
134 * MCI (SD/MMC)
135 */
136static struct mci_platform_data __initdata afeb9260_mci0_data = {
137 .slot[1] = {
138 .bus_width = 4,
139 .detect_pin = AT91_PIN_PC9,
140 .wp_pin = AT91_PIN_PC4,
141 },
142};
143
144
145
146static struct i2c_board_info __initdata afeb9260_i2c_devices[] = {
147 {
148 I2C_BOARD_INFO("tlv320aic23", 0x1a),
149 }, {
150 I2C_BOARD_INFO("fm3130", 0x68),
151 }, {
152 I2C_BOARD_INFO("24c64", 0x50),
153 },
154};
155
156/*
157 * IDE (CF True IDE mode)
158 */
159static struct at91_cf_data afeb9260_cf_data = {
160 .chipselect = 4,
161 .irq_pin = AT91_PIN_PA6,
162 .det_pin = -EINVAL,
163 .vcc_pin = -EINVAL,
164 .rst_pin = AT91_PIN_PA7,
165 .flags = AT91_CF_TRUE_IDE,
166};
167
168static void __init afeb9260_board_init(void)
169{
170 at91_register_devices();
171
172 /* Serial */
173 /* DBGU on ttyS0. (Rx & Tx only) */
174 at91_register_uart(0, 0, 0);
175
176 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
177 at91_register_uart(AT91SAM9260_ID_US0, 1,
178 ATMEL_UART_CTS | ATMEL_UART_RTS
179 | ATMEL_UART_DTR | ATMEL_UART_DSR
180 | ATMEL_UART_DCD | ATMEL_UART_RI);
181
182 /* USART1 on ttyS2. (Rx, Tx, RTS, CTS) */
183 at91_register_uart(AT91SAM9260_ID_US1, 2,
184 ATMEL_UART_CTS | ATMEL_UART_RTS);
185 at91_add_device_serial();
186 /* USB Host */
187 at91_add_device_usbh(&afeb9260_usbh_data);
188 /* USB Device */
189 at91_add_device_udc(&afeb9260_udc_data);
190 /* SPI */
191 at91_add_device_spi(afeb9260_spi_devices,
192 ARRAY_SIZE(afeb9260_spi_devices));
193 /* NAND */
194 at91_add_device_nand(&afeb9260_nand_data);
195 /* Ethernet */
196 at91_add_device_eth(&afeb9260_macb_data);
197
198 /* Standard function's pin assignments are not
199 * appropriate for us and generic code provide
200 * no API to configure these pins any other way */
201 at91_set_B_periph(AT91_PIN_PA10, 0); /* ETX2 */
202 at91_set_B_periph(AT91_PIN_PA11, 0); /* ETX3 */
203 /* MMC */
204 at91_add_device_mci(0, &afeb9260_mci0_data);
205 /* I2C */
206 at91_add_device_i2c(afeb9260_i2c_devices,
207 ARRAY_SIZE(afeb9260_i2c_devices));
208 /* Audio */
209 at91_add_device_ssc(AT91SAM9260_ID_SSC, ATMEL_SSC_TX);
210 /* IDE */
211 at91_add_device_cf(&afeb9260_cf_data);
212}
213
214MACHINE_START(AFEB9260, "Custom afeb9260 board")
215 /* Maintainer: Sergey Lapin <slapin@ossfans.org> */
216 .init_time = at91_init_time,
217 .map_io = at91_map_io,
218 .handle_irq = at91_aic_handle_irq,
219 .init_early = afeb9260_init_early,
220 .init_irq = at91_init_irq_default,
221 .init_machine = afeb9260_board_init,
222MACHINE_END
223
diff --git a/arch/arm/mach-at91/board-cam60.c b/arch/arm/mach-at91/board-cam60.c
deleted file mode 100644
index ae827dd2d0d2..000000000000
--- a/arch/arm/mach-at91/board-cam60.c
+++ /dev/null
@@ -1,199 +0,0 @@
1/*
2 * KwikByte CAM60 (KB9260)
3 *
4 * based on board-sam9260ek.c
5 * Copyright (C) 2005 SAN People
6 * Copyright (C) 2006 Atmel
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/types.h>
24#include <linux/gpio.h>
25#include <linux/init.h>
26#include <linux/mm.h>
27#include <linux/module.h>
28#include <linux/platform_device.h>
29#include <linux/spi/spi.h>
30#include <linux/spi/flash.h>
31
32#include <mach/hardware.h>
33#include <asm/setup.h>
34#include <asm/mach-types.h>
35#include <asm/irq.h>
36
37#include <asm/mach/arch.h>
38#include <asm/mach/map.h>
39#include <asm/mach/irq.h>
40
41#include <mach/at91sam9_smc.h>
42
43#include "at91_aic.h"
44#include "board.h"
45#include "sam9_smc.h"
46#include "generic.h"
47#include "gpio.h"
48
49
50static void __init cam60_init_early(void)
51{
52 /* Initialize processor: 10 MHz crystal */
53 at91_initialize(10000000);
54}
55
56/*
57 * USB Host
58 */
59static struct at91_usbh_data __initdata cam60_usbh_data = {
60 .ports = 1,
61 .vbus_pin = {-EINVAL, -EINVAL},
62 .overcurrent_pin= {-EINVAL, -EINVAL},
63};
64
65
66/*
67 * SPI devices.
68 */
69#if defined(CONFIG_MTD_DATAFLASH)
70static struct mtd_partition cam60_spi_partitions[] = {
71 {
72 .name = "BOOT1",
73 .offset = 0,
74 .size = 4 * 1056,
75 },
76 {
77 .name = "BOOT2",
78 .offset = MTDPART_OFS_NXTBLK,
79 .size = 256 * 1056,
80 },
81 {
82 .name = "kernel",
83 .offset = MTDPART_OFS_NXTBLK,
84 .size = 2222 * 1056,
85 },
86 {
87 .name = "file system",
88 .offset = MTDPART_OFS_NXTBLK,
89 .size = MTDPART_SIZ_FULL,
90 },
91};
92
93static struct flash_platform_data cam60_spi_flash_platform_data = {
94 .name = "spi_flash",
95 .parts = cam60_spi_partitions,
96 .nr_parts = ARRAY_SIZE(cam60_spi_partitions)
97};
98#endif
99
100static struct spi_board_info cam60_spi_devices[] __initdata = {
101#if defined(CONFIG_MTD_DATAFLASH)
102 { /* DataFlash chip */
103 .modalias = "mtd_dataflash",
104 .chip_select = 0,
105 .max_speed_hz = 15 * 1000 * 1000,
106 .bus_num = 0,
107 .platform_data = &cam60_spi_flash_platform_data
108 },
109#endif
110};
111
112
113/*
114 * MACB Ethernet device
115 */
116static struct macb_platform_data cam60_macb_data __initdata = {
117 .phy_irq_pin = AT91_PIN_PB5,
118 .is_rmii = 0,
119};
120
121
122/*
123 * NAND Flash
124 */
125static struct mtd_partition __initdata cam60_nand_partition[] = {
126 {
127 .name = "nand_fs",
128 .offset = 0,
129 .size = MTDPART_SIZ_FULL,
130 },
131};
132
133static struct atmel_nand_data __initdata cam60_nand_data = {
134 .ale = 21,
135 .cle = 22,
136 .det_pin = -EINVAL,
137 .rdy_pin = AT91_PIN_PA9,
138 .enable_pin = AT91_PIN_PA7,
139 .ecc_mode = NAND_ECC_SOFT,
140 .parts = cam60_nand_partition,
141 .num_parts = ARRAY_SIZE(cam60_nand_partition),
142};
143
144static struct sam9_smc_config __initdata cam60_nand_smc_config = {
145 .ncs_read_setup = 0,
146 .nrd_setup = 1,
147 .ncs_write_setup = 0,
148 .nwe_setup = 1,
149
150 .ncs_read_pulse = 3,
151 .nrd_pulse = 3,
152 .ncs_write_pulse = 3,
153 .nwe_pulse = 3,
154
155 .read_cycle = 5,
156 .write_cycle = 5,
157
158 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
159 .tdf_cycles = 2,
160};
161
162static void __init cam60_add_device_nand(void)
163{
164 /* configure chip-select 3 (NAND) */
165 sam9_smc_configure(0, 3, &cam60_nand_smc_config);
166
167 at91_add_device_nand(&cam60_nand_data);
168}
169
170
171static void __init cam60_board_init(void)
172{
173 at91_register_devices();
174
175 /* Serial */
176 /* DBGU on ttyS0. (Rx & Tx only) */
177 at91_register_uart(0, 0, 0);
178 at91_add_device_serial();
179 /* SPI */
180 at91_add_device_spi(cam60_spi_devices, ARRAY_SIZE(cam60_spi_devices));
181 /* Ethernet */
182 at91_add_device_eth(&cam60_macb_data);
183 /* USB Host */
184 /* enable USB power supply circuit */
185 at91_set_gpio_output(AT91_PIN_PB18, 1);
186 at91_add_device_usbh(&cam60_usbh_data);
187 /* NAND */
188 cam60_add_device_nand();
189}
190
191MACHINE_START(CAM60, "KwikByte CAM60")
192 /* Maintainer: KwikByte */
193 .init_time = at91_init_time,
194 .map_io = at91_map_io,
195 .handle_irq = at91_aic_handle_irq,
196 .init_early = cam60_init_early,
197 .init_irq = at91_init_irq_default,
198 .init_machine = cam60_board_init,
199MACHINE_END
diff --git a/arch/arm/mach-at91/board-carmeva.c b/arch/arm/mach-at91/board-carmeva.c
deleted file mode 100644
index 47313d3ee037..000000000000
--- a/arch/arm/mach-at91/board-carmeva.c
+++ /dev/null
@@ -1,167 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-carmeva.c
3 *
4 * Copyright (c) 2005 Peer Georgi
5 * Conitec Datasystems
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#include <linux/types.h>
23#include <linux/gpio.h>
24#include <linux/init.h>
25#include <linux/mm.h>
26#include <linux/module.h>
27#include <linux/platform_device.h>
28
29#include <asm/setup.h>
30#include <asm/mach-types.h>
31#include <asm/irq.h>
32
33#include <asm/mach/arch.h>
34#include <asm/mach/map.h>
35#include <asm/mach/irq.h>
36
37#include <mach/hardware.h>
38
39#include "at91_aic.h"
40#include "board.h"
41#include "generic.h"
42#include "gpio.h"
43
44
45static void __init carmeva_init_early(void)
46{
47 /* Initialize processor: 20.000 MHz crystal */
48 at91_initialize(20000000);
49}
50
51static struct macb_platform_data __initdata carmeva_eth_data = {
52 .phy_irq_pin = AT91_PIN_PC4,
53 .is_rmii = 1,
54};
55
56static struct at91_usbh_data __initdata carmeva_usbh_data = {
57 .ports = 2,
58 .vbus_pin = {-EINVAL, -EINVAL},
59 .overcurrent_pin= {-EINVAL, -EINVAL},
60};
61
62static struct at91_udc_data __initdata carmeva_udc_data = {
63 .vbus_pin = AT91_PIN_PD12,
64 .pullup_pin = AT91_PIN_PD9,
65};
66
67/* FIXME: user dependent */
68// static struct at91_cf_data __initdata carmeva_cf_data = {
69// .det_pin = AT91_PIN_PB0,
70// .rst_pin = AT91_PIN_PC5,
71 // .irq_pin = -EINVAL,
72 // .vcc_pin = -EINVAL,
73// };
74
75static struct mci_platform_data __initdata carmeva_mci0_data = {
76 .slot[0] = {
77 .bus_width = 4,
78 .detect_pin = AT91_PIN_PB10,
79 .wp_pin = AT91_PIN_PC14,
80 },
81};
82
83static struct spi_board_info carmeva_spi_devices[] = {
84 { /* DataFlash chip */
85 .modalias = "mtd_dataflash",
86 .chip_select = 0,
87 .max_speed_hz = 10 * 1000 * 1000,
88 },
89 { /* User accessible spi - cs1 (250KHz) */
90 .modalias = "spi-cs1",
91 .chip_select = 1,
92 .max_speed_hz = 250 * 1000,
93 },
94 { /* User accessible spi - cs2 (1MHz) */
95 .modalias = "spi-cs2",
96 .chip_select = 2,
97 .max_speed_hz = 1 * 1000 * 1000,
98 },
99 { /* User accessible spi - cs3 (10MHz) */
100 .modalias = "spi-cs3",
101 .chip_select = 3,
102 .max_speed_hz = 10 * 1000 * 1000,
103 },
104};
105
106static struct gpio_led carmeva_leds[] = {
107 { /* "user led 1", LED9 */
108 .name = "led9",
109 .gpio = AT91_PIN_PA21,
110 .active_low = 1,
111 .default_trigger = "heartbeat",
112 },
113 { /* "user led 2", LED10 */
114 .name = "led10",
115 .gpio = AT91_PIN_PA25,
116 .active_low = 1,
117 },
118 { /* "user led 3", LED11 */
119 .name = "led11",
120 .gpio = AT91_PIN_PA26,
121 .active_low = 1,
122 },
123 { /* "user led 4", LED12 */
124 .name = "led12",
125 .gpio = AT91_PIN_PA18,
126 .active_low = 1,
127 }
128};
129
130static void __init carmeva_board_init(void)
131{
132 /* Serial */
133 /* DBGU on ttyS0. (Rx & Tx only) */
134 at91_register_uart(0, 0, 0);
135
136 /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
137 at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
138 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
139 | ATMEL_UART_RI);
140 at91_add_device_serial();
141 /* Ethernet */
142 at91_add_device_eth(&carmeva_eth_data);
143 /* USB Host */
144 at91_add_device_usbh(&carmeva_usbh_data);
145 /* USB Device */
146 at91_add_device_udc(&carmeva_udc_data);
147 /* I2C */
148 at91_add_device_i2c(NULL, 0);
149 /* SPI */
150 at91_add_device_spi(carmeva_spi_devices, ARRAY_SIZE(carmeva_spi_devices));
151 /* Compact Flash */
152// at91_add_device_cf(&carmeva_cf_data);
153 /* MMC */
154 at91_add_device_mci(0, &carmeva_mci0_data);
155 /* LEDs */
156 at91_gpio_leds(carmeva_leds, ARRAY_SIZE(carmeva_leds));
157}
158
159MACHINE_START(CARMEVA, "Carmeva")
160 /* Maintainer: Conitec Datasystems */
161 .init_time = at91rm9200_timer_init,
162 .map_io = at91_map_io,
163 .handle_irq = at91_aic_handle_irq,
164 .init_early = carmeva_init_early,
165 .init_irq = at91_init_irq_default,
166 .init_machine = carmeva_board_init,
167MACHINE_END
diff --git a/arch/arm/mach-at91/board-cpu9krea.c b/arch/arm/mach-at91/board-cpu9krea.c
deleted file mode 100644
index 731c8318f4f5..000000000000
--- a/arch/arm/mach-at91/board-cpu9krea.c
+++ /dev/null
@@ -1,386 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-cpu9krea.c
3 *
4 * Copyright (C) 2005 SAN People
5 * Copyright (C) 2006 Atmel
6 * Copyright (C) 2009 Eric Benard - eric@eukrea.com
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/types.h>
24#include <linux/gpio.h>
25#include <linux/init.h>
26#include <linux/mm.h>
27#include <linux/module.h>
28#include <linux/platform_device.h>
29#include <linux/clk.h>
30#include <linux/gpio_keys.h>
31#include <linux/input.h>
32#include <linux/mtd/physmap.h>
33
34#include <asm/setup.h>
35#include <asm/mach-types.h>
36#include <asm/irq.h>
37
38#include <asm/mach/arch.h>
39#include <asm/mach/map.h>
40#include <asm/mach/irq.h>
41
42#include <mach/hardware.h>
43#include <mach/at91sam9_smc.h>
44#include <mach/at91sam9260_matrix.h>
45#include <mach/at91_matrix.h>
46
47#include "at91_aic.h"
48#include "board.h"
49#include "sam9_smc.h"
50#include "generic.h"
51#include "gpio.h"
52
53static void __init cpu9krea_init_early(void)
54{
55 /* Initialize processor: 18.432 MHz crystal */
56 at91_initialize(18432000);
57}
58
59/*
60 * USB Host port
61 */
62static struct at91_usbh_data __initdata cpu9krea_usbh_data = {
63 .ports = 2,
64 .vbus_pin = {-EINVAL, -EINVAL},
65 .overcurrent_pin= {-EINVAL, -EINVAL},
66};
67
68/*
69 * USB Device port
70 */
71static struct at91_udc_data __initdata cpu9krea_udc_data = {
72 .vbus_pin = AT91_PIN_PC8,
73 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
74};
75
76/*
77 * MACB Ethernet device
78 */
79static struct macb_platform_data __initdata cpu9krea_macb_data = {
80 .phy_irq_pin = -EINVAL,
81 .is_rmii = 1,
82};
83
84/*
85 * NAND flash
86 */
87static struct atmel_nand_data __initdata cpu9krea_nand_data = {
88 .ale = 21,
89 .cle = 22,
90 .rdy_pin = AT91_PIN_PC13,
91 .enable_pin = AT91_PIN_PC14,
92 .bus_width_16 = 0,
93 .det_pin = -EINVAL,
94 .ecc_mode = NAND_ECC_SOFT,
95};
96
97#ifdef CONFIG_MACH_CPU9260
98static struct sam9_smc_config __initdata cpu9krea_nand_smc_config = {
99 .ncs_read_setup = 0,
100 .nrd_setup = 1,
101 .ncs_write_setup = 0,
102 .nwe_setup = 1,
103
104 .ncs_read_pulse = 3,
105 .nrd_pulse = 3,
106 .ncs_write_pulse = 3,
107 .nwe_pulse = 3,
108
109 .read_cycle = 5,
110 .write_cycle = 5,
111
112 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
113 | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
114 .tdf_cycles = 2,
115};
116#else
117static struct sam9_smc_config __initdata cpu9krea_nand_smc_config = {
118 .ncs_read_setup = 0,
119 .nrd_setup = 2,
120 .ncs_write_setup = 0,
121 .nwe_setup = 2,
122
123 .ncs_read_pulse = 4,
124 .nrd_pulse = 4,
125 .ncs_write_pulse = 4,
126 .nwe_pulse = 4,
127
128 .read_cycle = 7,
129 .write_cycle = 7,
130
131 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
132 | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
133 .tdf_cycles = 3,
134};
135#endif
136
137static void __init cpu9krea_add_device_nand(void)
138{
139 sam9_smc_configure(0, 3, &cpu9krea_nand_smc_config);
140 at91_add_device_nand(&cpu9krea_nand_data);
141}
142
143/*
144 * NOR flash
145 */
146static struct physmap_flash_data cpuat9260_nor_data = {
147 .width = 2,
148};
149
150#define NOR_BASE AT91_CHIPSELECT_0
151#define NOR_SIZE SZ_64M
152
153static struct resource nor_flash_resources[] = {
154 {
155 .start = NOR_BASE,
156 .end = NOR_BASE + NOR_SIZE - 1,
157 .flags = IORESOURCE_MEM,
158 }
159};
160
161static struct platform_device cpu9krea_nor_flash = {
162 .name = "physmap-flash",
163 .id = 0,
164 .dev = {
165 .platform_data = &cpuat9260_nor_data,
166 },
167 .resource = nor_flash_resources,
168 .num_resources = ARRAY_SIZE(nor_flash_resources),
169};
170
171#ifdef CONFIG_MACH_CPU9260
172static struct sam9_smc_config __initdata cpu9krea_nor_smc_config = {
173 .ncs_read_setup = 0,
174 .nrd_setup = 1,
175 .ncs_write_setup = 0,
176 .nwe_setup = 1,
177
178 .ncs_read_pulse = 10,
179 .nrd_pulse = 10,
180 .ncs_write_pulse = 6,
181 .nwe_pulse = 6,
182
183 .read_cycle = 12,
184 .write_cycle = 8,
185
186 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
187 | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE
188 | AT91_SMC_DBW_16,
189 .tdf_cycles = 2,
190};
191#else
192static struct sam9_smc_config __initdata cpu9krea_nor_smc_config = {
193 .ncs_read_setup = 0,
194 .nrd_setup = 1,
195 .ncs_write_setup = 0,
196 .nwe_setup = 1,
197
198 .ncs_read_pulse = 13,
199 .nrd_pulse = 13,
200 .ncs_write_pulse = 8,
201 .nwe_pulse = 8,
202
203 .read_cycle = 15,
204 .write_cycle = 10,
205
206 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
207 | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE
208 | AT91_SMC_DBW_16,
209 .tdf_cycles = 2,
210};
211#endif
212
213static __init void cpu9krea_add_device_nor(void)
214{
215 unsigned long csa;
216
217 csa = at91_matrix_read(AT91_MATRIX_EBICSA);
218 at91_matrix_write(AT91_MATRIX_EBICSA, csa | AT91_MATRIX_VDDIOMSEL_3_3V);
219
220 /* configure chip-select 0 (NOR) */
221 sam9_smc_configure(0, 0, &cpu9krea_nor_smc_config);
222
223 platform_device_register(&cpu9krea_nor_flash);
224}
225
226/*
227 * LEDs
228 */
229static struct gpio_led cpu9krea_leds[] = {
230 { /* LED1 */
231 .name = "LED1",
232 .gpio = AT91_PIN_PC11,
233 .active_low = 1,
234 .default_trigger = "timer",
235 },
236 { /* LED2 */
237 .name = "LED2",
238 .gpio = AT91_PIN_PC12,
239 .active_low = 1,
240 .default_trigger = "heartbeat",
241 },
242 { /* LED3 */
243 .name = "LED3",
244 .gpio = AT91_PIN_PC7,
245 .active_low = 1,
246 .default_trigger = "none",
247 },
248 { /* LED4 */
249 .name = "LED4",
250 .gpio = AT91_PIN_PC9,
251 .active_low = 1,
252 .default_trigger = "none",
253 }
254};
255
256static struct i2c_board_info __initdata cpu9krea_i2c_devices[] = {
257 {
258 I2C_BOARD_INFO("ds1339", 0x68),
259 },
260};
261
262/*
263 * GPIO Buttons
264 */
265#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
266static struct gpio_keys_button cpu9krea_buttons[] = {
267 {
268 .gpio = AT91_PIN_PC3,
269 .code = BTN_0,
270 .desc = "BP1",
271 .active_low = 1,
272 .wakeup = 1,
273 },
274 {
275 .gpio = AT91_PIN_PB20,
276 .code = BTN_1,
277 .desc = "BP2",
278 .active_low = 1,
279 .wakeup = 1,
280 }
281};
282
283static struct gpio_keys_platform_data cpu9krea_button_data = {
284 .buttons = cpu9krea_buttons,
285 .nbuttons = ARRAY_SIZE(cpu9krea_buttons),
286};
287
288static struct platform_device cpu9krea_button_device = {
289 .name = "gpio-keys",
290 .id = -1,
291 .num_resources = 0,
292 .dev = {
293 .platform_data = &cpu9krea_button_data,
294 }
295};
296
297static void __init cpu9krea_add_device_buttons(void)
298{
299 at91_set_gpio_input(AT91_PIN_PC3, 1); /* BP1 */
300 at91_set_deglitch(AT91_PIN_PC3, 1);
301 at91_set_gpio_input(AT91_PIN_PB20, 1); /* BP2 */
302 at91_set_deglitch(AT91_PIN_PB20, 1);
303
304 platform_device_register(&cpu9krea_button_device);
305}
306#else
307static void __init cpu9krea_add_device_buttons(void)
308{
309}
310#endif
311
312/*
313 * MCI (SD/MMC)
314 */
315static struct mci_platform_data __initdata cpu9krea_mci0_data = {
316 .slot[0] = {
317 .bus_width = 4,
318 .detect_pin = AT91_PIN_PA29,
319 .wp_pin = -EINVAL,
320 },
321};
322
323static void __init cpu9krea_board_init(void)
324{
325 at91_register_devices();
326
327 /* NOR */
328 cpu9krea_add_device_nor();
329 /* Serial */
330 /* DGBU on ttyS0. (Rx & Tx only) */
331 at91_register_uart(0, 0, 0);
332
333 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
334 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS |
335 ATMEL_UART_RTS | ATMEL_UART_DTR | ATMEL_UART_DSR |
336 ATMEL_UART_DCD | ATMEL_UART_RI);
337
338 /* USART1 on ttyS2. (Rx, Tx, RTS, CTS) */
339 at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS |
340 ATMEL_UART_RTS);
341
342 /* USART2 on ttyS3. (Rx, Tx, RTS, CTS) */
343 at91_register_uart(AT91SAM9260_ID_US2, 3, ATMEL_UART_CTS |
344 ATMEL_UART_RTS);
345
346 /* USART3 on ttyS4. (Rx, Tx) */
347 at91_register_uart(AT91SAM9260_ID_US3, 4, 0);
348
349 /* USART4 on ttyS5. (Rx, Tx) */
350 at91_register_uart(AT91SAM9260_ID_US4, 5, 0);
351
352 /* USART5 on ttyS6. (Rx, Tx) */
353 at91_register_uart(AT91SAM9260_ID_US5, 6, 0);
354 at91_add_device_serial();
355 /* USB Host */
356 at91_add_device_usbh(&cpu9krea_usbh_data);
357 /* USB Device */
358 at91_add_device_udc(&cpu9krea_udc_data);
359 /* NAND */
360 cpu9krea_add_device_nand();
361 /* Ethernet */
362 at91_add_device_eth(&cpu9krea_macb_data);
363 /* MMC */
364 at91_add_device_mci(0, &cpu9krea_mci0_data);
365 /* I2C */
366 at91_add_device_i2c(cpu9krea_i2c_devices,
367 ARRAY_SIZE(cpu9krea_i2c_devices));
368 /* LEDs */
369 at91_gpio_leds(cpu9krea_leds, ARRAY_SIZE(cpu9krea_leds));
370 /* Push Buttons */
371 cpu9krea_add_device_buttons();
372}
373
374#ifdef CONFIG_MACH_CPU9260
375MACHINE_START(CPUAT9260, "Eukrea CPU9260")
376#else
377MACHINE_START(CPUAT9G20, "Eukrea CPU9G20")
378#endif
379 /* Maintainer: Eric Benard - EUKREA Electromatique */
380 .init_time = at91_init_time,
381 .map_io = at91_map_io,
382 .handle_irq = at91_aic_handle_irq,
383 .init_early = cpu9krea_init_early,
384 .init_irq = at91_init_irq_default,
385 .init_machine = cpu9krea_board_init,
386MACHINE_END
diff --git a/arch/arm/mach-at91/board-cpuat91.c b/arch/arm/mach-at91/board-cpuat91.c
deleted file mode 100644
index c094350c9314..000000000000
--- a/arch/arm/mach-at91/board-cpuat91.c
+++ /dev/null
@@ -1,189 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-cpuat91.c
3 *
4 * Copyright (C) 2009 Eric Benard - eric@eukrea.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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/types.h>
22#include <linux/gpio.h>
23#include <linux/init.h>
24#include <linux/mm.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/mtd/physmap.h>
28#include <linux/mtd/plat-ram.h>
29
30#include <mach/hardware.h>
31#include <asm/setup.h>
32#include <asm/mach-types.h>
33#include <asm/irq.h>
34
35#include <asm/mach/arch.h>
36#include <asm/mach/map.h>
37#include <asm/mach/irq.h>
38
39#include <mach/at91rm9200_mc.h>
40#include <mach/at91_ramc.h>
41#include <mach/cpu.h>
42
43#include "at91_aic.h"
44#include "board.h"
45#include "generic.h"
46#include "gpio.h"
47
48
49static struct gpio_led cpuat91_leds[] = {
50 {
51 .name = "led1",
52 .default_trigger = "heartbeat",
53 .active_low = 1,
54 .gpio = AT91_PIN_PC0,
55 },
56};
57
58static void __init cpuat91_init_early(void)
59{
60 /* Set cpu type: PQFP */
61 at91rm9200_set_type(ARCH_REVISON_9200_PQFP);
62
63 /* Initialize processor: 18.432 MHz crystal */
64 at91_initialize(18432000);
65}
66
67static struct macb_platform_data __initdata cpuat91_eth_data = {
68 .phy_irq_pin = -EINVAL,
69 .is_rmii = 1,
70};
71
72static struct at91_usbh_data __initdata cpuat91_usbh_data = {
73 .ports = 1,
74 .vbus_pin = {-EINVAL, -EINVAL},
75 .overcurrent_pin= {-EINVAL, -EINVAL},
76};
77
78static struct at91_udc_data __initdata cpuat91_udc_data = {
79 .vbus_pin = AT91_PIN_PC15,
80 .pullup_pin = AT91_PIN_PC14,
81};
82
83static struct mci_platform_data __initdata cpuat91_mci0_data = {
84 .slot[0] = {
85 .bus_width = 4,
86 .detect_pin = AT91_PIN_PC2,
87 .wp_pin = -EINVAL,
88 },
89};
90
91static struct physmap_flash_data cpuat91_flash_data = {
92 .width = 2,
93};
94
95static struct resource cpuat91_flash_resource = {
96 .start = AT91_CHIPSELECT_0,
97 .end = AT91_CHIPSELECT_0 + SZ_16M - 1,
98 .flags = IORESOURCE_MEM,
99};
100
101static struct platform_device cpuat91_norflash = {
102 .name = "physmap-flash",
103 .id = 0,
104 .dev = {
105 .platform_data = &cpuat91_flash_data,
106 },
107 .resource = &cpuat91_flash_resource,
108 .num_resources = 1,
109};
110
111#ifdef CONFIG_MTD_PLATRAM
112struct platdata_mtd_ram at91_sram_pdata = {
113 .mapname = "SRAM",
114 .bankwidth = 2,
115};
116
117static struct resource at91_sram_resource[] = {
118 [0] = {
119 .start = AT91RM9200_SRAM_BASE,
120 .end = AT91RM9200_SRAM_BASE + AT91RM9200_SRAM_SIZE - 1,
121 .flags = IORESOURCE_MEM,
122 },
123};
124
125static struct platform_device at91_sram = {
126 .name = "mtd-ram",
127 .id = 0,
128 .resource = at91_sram_resource,
129 .num_resources = ARRAY_SIZE(at91_sram_resource),
130 .dev = {
131 .platform_data = &at91_sram_pdata,
132 },
133};
134#endif /* MTD_PLATRAM */
135
136static struct platform_device *platform_devices[] __initdata = {
137 &cpuat91_norflash,
138#ifdef CONFIG_MTD_PLATRAM
139 &at91_sram,
140#endif /* CONFIG_MTD_PLATRAM */
141};
142
143static void __init cpuat91_board_init(void)
144{
145 /* Serial */
146 /* DBGU on ttyS0. (Rx & Tx only) */
147 at91_register_uart(0, 0, 0);
148
149 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS) */
150 at91_register_uart(AT91RM9200_ID_US0, 1, ATMEL_UART_CTS |
151 ATMEL_UART_RTS);
152
153 /* USART1 on ttyS2. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
154 at91_register_uart(AT91RM9200_ID_US1, 2, ATMEL_UART_CTS |
155 ATMEL_UART_RTS | ATMEL_UART_DTR | ATMEL_UART_DSR |
156 ATMEL_UART_DCD | ATMEL_UART_RI);
157
158 /* USART2 on ttyS3 (Rx, Tx) */
159 at91_register_uart(AT91RM9200_ID_US2, 3, 0);
160
161 /* USART3 on ttyS4 (Rx, Tx, CTS, RTS) */
162 at91_register_uart(AT91RM9200_ID_US3, 4, ATMEL_UART_CTS |
163 ATMEL_UART_RTS);
164 at91_add_device_serial();
165 /* LEDs. */
166 at91_gpio_leds(cpuat91_leds, ARRAY_SIZE(cpuat91_leds));
167 /* Ethernet */
168 at91_add_device_eth(&cpuat91_eth_data);
169 /* USB Host */
170 at91_add_device_usbh(&cpuat91_usbh_data);
171 /* USB Device */
172 at91_add_device_udc(&cpuat91_udc_data);
173 /* MMC */
174 at91_add_device_mci(0, &cpuat91_mci0_data);
175 /* I2C */
176 at91_add_device_i2c(NULL, 0);
177 /* Platform devices */
178 platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
179}
180
181MACHINE_START(CPUAT91, "Eukrea")
182 /* Maintainer: Eric Benard - EUKREA Electromatique */
183 .init_time = at91rm9200_timer_init,
184 .map_io = at91_map_io,
185 .handle_irq = at91_aic_handle_irq,
186 .init_early = cpuat91_init_early,
187 .init_irq = at91_init_irq_default,
188 .init_machine = cpuat91_board_init,
189MACHINE_END
diff --git a/arch/arm/mach-at91/board-csb337.c b/arch/arm/mach-at91/board-csb337.c
deleted file mode 100644
index 0e35a45cf8d4..000000000000
--- a/arch/arm/mach-at91/board-csb337.c
+++ /dev/null
@@ -1,260 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-csb337.c
3 *
4 * Copyright (C) 2005 SAN People
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/types.h>
22#include <linux/gpio.h>
23#include <linux/init.h>
24#include <linux/mm.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/spi/spi.h>
28#include <linux/mtd/physmap.h>
29#include <linux/input.h>
30#include <linux/gpio_keys.h>
31
32#include <asm/setup.h>
33#include <asm/mach-types.h>
34#include <asm/irq.h>
35
36#include <asm/mach/arch.h>
37#include <asm/mach/map.h>
38#include <asm/mach/irq.h>
39
40#include <mach/hardware.h>
41
42#include "at91_aic.h"
43#include "board.h"
44#include "generic.h"
45#include "gpio.h"
46
47static void __init csb337_init_early(void)
48{
49 /* Initialize processor: 3.6864 MHz crystal */
50 at91_initialize(3686400);
51}
52
53static struct macb_platform_data __initdata csb337_eth_data = {
54 .phy_irq_pin = AT91_PIN_PC2,
55 .is_rmii = 0,
56 /* The CSB337 bootloader stores the MAC the wrong-way around */
57 .rev_eth_addr = 1,
58};
59
60static struct at91_usbh_data __initdata csb337_usbh_data = {
61 .ports = 2,
62 .vbus_pin = {-EINVAL, -EINVAL},
63 .overcurrent_pin= {-EINVAL, -EINVAL},
64};
65
66static struct at91_udc_data __initdata csb337_udc_data = {
67 .pullup_pin = AT91_PIN_PA24,
68 .vbus_pin = -EINVAL,
69};
70
71static struct i2c_board_info __initdata csb337_i2c_devices[] = {
72 {
73 I2C_BOARD_INFO("ds1307", 0x68),
74 },
75};
76
77static struct at91_cf_data __initdata csb337_cf_data = {
78 /*
79 * connector P4 on the CSB 337 mates to
80 * connector P8 on the CSB 300CF
81 */
82
83 /* CSB337 specific */
84 .det_pin = AT91_PIN_PC3,
85
86 /* CSB300CF specific */
87 .irq_pin = AT91_PIN_PA19,
88 .vcc_pin = AT91_PIN_PD0,
89 .rst_pin = AT91_PIN_PD2,
90};
91
92static struct mci_platform_data __initdata csb337_mci0_data = {
93 .slot[0] = {
94 .bus_width = 4,
95 .detect_pin = AT91_PIN_PD5,
96 .wp_pin = AT91_PIN_PD6,
97 },
98};
99
100static struct spi_board_info csb337_spi_devices[] = {
101 { /* CAN controller */
102 .modalias = "sak82c900",
103 .chip_select = 0,
104 .max_speed_hz = 6 * 1000 * 1000,
105 },
106};
107
108#define CSB_FLASH_BASE AT91_CHIPSELECT_0
109#define CSB_FLASH_SIZE SZ_8M
110
111static struct mtd_partition csb_flash_partitions[] = {
112 {
113 .name = "uMON flash",
114 .offset = 0,
115 .size = MTDPART_SIZ_FULL,
116 .mask_flags = MTD_WRITEABLE, /* read only */
117 }
118};
119
120static struct physmap_flash_data csb_flash_data = {
121 .width = 2,
122 .parts = csb_flash_partitions,
123 .nr_parts = ARRAY_SIZE(csb_flash_partitions),
124};
125
126static struct resource csb_flash_resources[] = {
127 {
128 .start = CSB_FLASH_BASE,
129 .end = CSB_FLASH_BASE + CSB_FLASH_SIZE - 1,
130 .flags = IORESOURCE_MEM,
131 }
132};
133
134static struct platform_device csb_flash = {
135 .name = "physmap-flash",
136 .id = 0,
137 .dev = {
138 .platform_data = &csb_flash_data,
139 },
140 .resource = csb_flash_resources,
141 .num_resources = ARRAY_SIZE(csb_flash_resources),
142};
143
144/*
145 * GPIO Buttons (on CSB300)
146 */
147#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
148static struct gpio_keys_button csb300_buttons[] = {
149 {
150 .gpio = AT91_PIN_PB29,
151 .code = BTN_0,
152 .desc = "sw0",
153 .active_low = 1,
154 .wakeup = 1,
155 },
156 {
157 .gpio = AT91_PIN_PB28,
158 .code = BTN_1,
159 .desc = "sw1",
160 .active_low = 1,
161 .wakeup = 1,
162 },
163 {
164 .gpio = AT91_PIN_PA21,
165 .code = BTN_2,
166 .desc = "sw2",
167 .active_low = 1,
168 .wakeup = 1,
169 }
170};
171
172static struct gpio_keys_platform_data csb300_button_data = {
173 .buttons = csb300_buttons,
174 .nbuttons = ARRAY_SIZE(csb300_buttons),
175};
176
177static struct platform_device csb300_button_device = {
178 .name = "gpio-keys",
179 .id = -1,
180 .num_resources = 0,
181 .dev = {
182 .platform_data = &csb300_button_data,
183 }
184};
185
186static void __init csb300_add_device_buttons(void)
187{
188 at91_set_gpio_input(AT91_PIN_PB29, 1); /* sw0 */
189 at91_set_deglitch(AT91_PIN_PB29, 1);
190 at91_set_gpio_input(AT91_PIN_PB28, 1); /* sw1 */
191 at91_set_deglitch(AT91_PIN_PB28, 1);
192 at91_set_gpio_input(AT91_PIN_PA21, 1); /* sw2 */
193 at91_set_deglitch(AT91_PIN_PA21, 1);
194
195 platform_device_register(&csb300_button_device);
196}
197#else
198static void __init csb300_add_device_buttons(void) {}
199#endif
200
201static struct gpio_led csb_leds[] = {
202 { /* "led0", yellow */
203 .name = "led0",
204 .gpio = AT91_PIN_PB2,
205 .active_low = 1,
206 .default_trigger = "heartbeat",
207 },
208 { /* "led1", green */
209 .name = "led1",
210 .gpio = AT91_PIN_PB1,
211 .active_low = 1,
212 .default_trigger = "mmc0",
213 },
214 { /* "led2", yellow */
215 .name = "led2",
216 .gpio = AT91_PIN_PB0,
217 .active_low = 1,
218 .default_trigger = "ide-disk",
219 }
220};
221
222
223static void __init csb337_board_init(void)
224{
225 /* Serial */
226 /* DBGU on ttyS0 */
227 at91_register_uart(0, 0, 0);
228 at91_add_device_serial();
229 /* Ethernet */
230 at91_add_device_eth(&csb337_eth_data);
231 /* USB Host */
232 at91_add_device_usbh(&csb337_usbh_data);
233 /* USB Device */
234 at91_add_device_udc(&csb337_udc_data);
235 /* I2C */
236 at91_add_device_i2c(csb337_i2c_devices, ARRAY_SIZE(csb337_i2c_devices));
237 /* Compact Flash */
238 at91_set_gpio_input(AT91_PIN_PB22, 1); /* IOIS16 */
239 at91_add_device_cf(&csb337_cf_data);
240 /* SPI */
241 at91_add_device_spi(csb337_spi_devices, ARRAY_SIZE(csb337_spi_devices));
242 /* MMC */
243 at91_add_device_mci(0, &csb337_mci0_data);
244 /* NOR flash */
245 platform_device_register(&csb_flash);
246 /* LEDs */
247 at91_gpio_leds(csb_leds, ARRAY_SIZE(csb_leds));
248 /* Switches on CSB300 */
249 csb300_add_device_buttons();
250}
251
252MACHINE_START(CSB337, "Cogent CSB337")
253 /* Maintainer: Bill Gatliff */
254 .init_time = at91rm9200_timer_init,
255 .map_io = at91_map_io,
256 .handle_irq = at91_aic_handle_irq,
257 .init_early = csb337_init_early,
258 .init_irq = at91_init_irq_default,
259 .init_machine = csb337_board_init,
260MACHINE_END
diff --git a/arch/arm/mach-at91/board-csb637.c b/arch/arm/mach-at91/board-csb637.c
deleted file mode 100644
index 18d027f529a8..000000000000
--- a/arch/arm/mach-at91/board-csb637.c
+++ /dev/null
@@ -1,142 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-csb637.c
3 *
4 * Copyright (C) 2005 SAN People
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/types.h>
22#include <linux/init.h>
23#include <linux/gpio.h>
24#include <linux/mm.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/mtd/physmap.h>
28
29#include <asm/setup.h>
30#include <asm/mach-types.h>
31#include <asm/irq.h>
32
33#include <asm/mach/arch.h>
34#include <asm/mach/map.h>
35#include <asm/mach/irq.h>
36
37#include <mach/hardware.h>
38
39#include "at91_aic.h"
40#include "board.h"
41#include "generic.h"
42#include "gpio.h"
43
44
45static void __init csb637_init_early(void)
46{
47 /* Initialize processor: 3.6864 MHz crystal */
48 at91_initialize(3686400);
49}
50
51static struct macb_platform_data __initdata csb637_eth_data = {
52 .phy_irq_pin = AT91_PIN_PC0,
53 .is_rmii = 0,
54};
55
56static struct at91_usbh_data __initdata csb637_usbh_data = {
57 .ports = 2,
58 .vbus_pin = {-EINVAL, -EINVAL},
59 .overcurrent_pin= {-EINVAL, -EINVAL},
60};
61
62static struct at91_udc_data __initdata csb637_udc_data = {
63 .vbus_pin = AT91_PIN_PB28,
64 .pullup_pin = AT91_PIN_PB1,
65};
66
67#define CSB_FLASH_BASE AT91_CHIPSELECT_0
68#define CSB_FLASH_SIZE SZ_16M
69
70static struct mtd_partition csb_flash_partitions[] = {
71 {
72 .name = "uMON flash",
73 .offset = 0,
74 .size = MTDPART_SIZ_FULL,
75 .mask_flags = MTD_WRITEABLE, /* read only */
76 }
77};
78
79static struct physmap_flash_data csb_flash_data = {
80 .width = 2,
81 .parts = csb_flash_partitions,
82 .nr_parts = ARRAY_SIZE(csb_flash_partitions),
83};
84
85static struct resource csb_flash_resources[] = {
86 {
87 .start = CSB_FLASH_BASE,
88 .end = CSB_FLASH_BASE + CSB_FLASH_SIZE - 1,
89 .flags = IORESOURCE_MEM,
90 }
91};
92
93static struct platform_device csb_flash = {
94 .name = "physmap-flash",
95 .id = 0,
96 .dev = {
97 .platform_data = &csb_flash_data,
98 },
99 .resource = csb_flash_resources,
100 .num_resources = ARRAY_SIZE(csb_flash_resources),
101};
102
103static struct gpio_led csb_leds[] = {
104 { /* "d1", red */
105 .name = "d1",
106 .gpio = AT91_PIN_PB2,
107 .active_low = 1,
108 .default_trigger = "heartbeat",
109 },
110};
111
112static void __init csb637_board_init(void)
113{
114 /* LED(s) */
115 at91_gpio_leds(csb_leds, ARRAY_SIZE(csb_leds));
116 /* Serial */
117 /* DBGU on ttyS0. (Rx & Tx only) */
118 at91_register_uart(0, 0, 0);
119 at91_add_device_serial();
120 /* Ethernet */
121 at91_add_device_eth(&csb637_eth_data);
122 /* USB Host */
123 at91_add_device_usbh(&csb637_usbh_data);
124 /* USB Device */
125 at91_add_device_udc(&csb637_udc_data);
126 /* I2C */
127 at91_add_device_i2c(NULL, 0);
128 /* SPI */
129 at91_add_device_spi(NULL, 0);
130 /* NOR flash */
131 platform_device_register(&csb_flash);
132}
133
134MACHINE_START(CSB637, "Cogent CSB637")
135 /* Maintainer: Bill Gatliff */
136 .init_time = at91rm9200_timer_init,
137 .map_io = at91_map_io,
138 .handle_irq = at91_aic_handle_irq,
139 .init_early = csb637_init_early,
140 .init_irq = at91_init_irq_default,
141 .init_machine = csb637_board_init,
142MACHINE_END
diff --git a/arch/arm/mach-at91/board-dt-rm9200.c b/arch/arm/mach-at91/board-dt-rm9200.c
index 226563f850b8..76dfe8f9af50 100644
--- a/arch/arm/mach-at91/board-dt-rm9200.c
+++ b/arch/arm/mach-at91/board-dt-rm9200.c
@@ -22,14 +22,11 @@
22#include <asm/mach/map.h> 22#include <asm/mach/map.h>
23#include <asm/mach/irq.h> 23#include <asm/mach/irq.h>
24 24
25#include "at91_aic.h"
26#include "generic.h" 25#include "generic.h"
27 26
28static void __init at91rm9200_dt_timer_init(void) 27static void __init at91rm9200_dt_timer_init(void)
29{ 28{
30#if defined(CONFIG_COMMON_CLK)
31 of_clk_init(NULL); 29 of_clk_init(NULL);
32#endif
33 at91rm9200_timer_init(); 30 at91rm9200_timer_init();
34} 31}
35 32
diff --git a/arch/arm/mach-at91/board-dt-sam9.c b/arch/arm/mach-at91/board-dt-sam9.c
index d3048ccdc41f..f99246aa9b38 100644
--- a/arch/arm/mach-at91/board-dt-sam9.c
+++ b/arch/arm/mach-at91/board-dt-sam9.c
@@ -21,8 +21,6 @@
21#include <asm/mach/map.h> 21#include <asm/mach/map.h>
22#include <asm/mach/irq.h> 22#include <asm/mach/irq.h>
23 23
24#include "at91_aic.h"
25#include "board.h"
26#include "generic.h" 24#include "generic.h"
27 25
28static const char *at91_dt_board_compat[] __initdata = { 26static const char *at91_dt_board_compat[] __initdata = {
diff --git a/arch/arm/mach-at91/board-dt-sama5.c b/arch/arm/mach-at91/board-dt-sama5.c
index 129e2917506b..8fb9ef5333f1 100644
--- a/arch/arm/mach-at91/board-dt-sama5.c
+++ b/arch/arm/mach-at91/board-dt-sama5.c
@@ -24,7 +24,6 @@
24#include <asm/mach/map.h> 24#include <asm/mach/map.h>
25#include <asm/mach/irq.h> 25#include <asm/mach/irq.h>
26 26
27#include "at91_aic.h"
28#include "generic.h" 27#include "generic.h"
29 28
30static void __init sama5_dt_device_init(void) 29static void __init sama5_dt_device_init(void)
diff --git a/arch/arm/mach-at91/board-eb01.c b/arch/arm/mach-at91/board-eb01.c
deleted file mode 100644
index becf0a6a289e..000000000000
--- a/arch/arm/mach-at91/board-eb01.c
+++ /dev/null
@@ -1,52 +0,0 @@
1/*
2 * arch/arm/mach-at91/board-eb01.c
3 *
4 * (C) Copyright 2007, Greg Ungerer <gerg@snapgear.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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
25#include <linux/irq.h>
26#include <asm/mach-types.h>
27#include <mach/hardware.h>
28#include <asm/mach/arch.h>
29#include <asm/mach/map.h>
30
31#include "at91_aic.h"
32#include "board.h"
33#include "generic.h"
34
35static void __init at91eb01_init_irq(void)
36{
37 at91x40_init_interrupts(NULL);
38}
39
40static void __init at91eb01_init_early(void)
41{
42 at91x40_initialize(40000000);
43}
44
45MACHINE_START(AT91EB01, "Atmel AT91 EB01")
46 /* Maintainer: Greg Ungerer <gerg@snapgear.com> */
47 .init_time = at91x40_timer_init,
48 .handle_irq = at91_aic_handle_irq,
49 .init_early = at91eb01_init_early,
50 .init_irq = at91eb01_init_irq,
51MACHINE_END
52
diff --git a/arch/arm/mach-at91/board-eb9200.c b/arch/arm/mach-at91/board-eb9200.c
deleted file mode 100644
index aa457a8b22f5..000000000000
--- a/arch/arm/mach-at91/board-eb9200.c
+++ /dev/null
@@ -1,126 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-eb9200.c
3 *
4 * Copyright (C) 2005 SAN People, adapted for ATEB9200 from Embest
5 * by Andrew Patrikalakis
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#include <linux/types.h>
23#include <linux/gpio.h>
24#include <linux/init.h>
25#include <linux/mm.h>
26#include <linux/module.h>
27#include <linux/device.h>
28
29#include <mach/hardware.h>
30#include <asm/setup.h>
31#include <asm/mach-types.h>
32#include <asm/irq.h>
33
34#include <asm/mach/arch.h>
35#include <asm/mach/map.h>
36#include <asm/mach/irq.h>
37
38#include "at91_aic.h"
39#include "board.h"
40#include "generic.h"
41#include "gpio.h"
42
43
44static void __init eb9200_init_early(void)
45{
46 /* Initialize processor: 18.432 MHz crystal */
47 at91_initialize(18432000);
48}
49
50static struct macb_platform_data __initdata eb9200_eth_data = {
51 .phy_irq_pin = AT91_PIN_PC4,
52 .is_rmii = 1,
53};
54
55static struct at91_usbh_data __initdata eb9200_usbh_data = {
56 .ports = 2,
57 .vbus_pin = {-EINVAL, -EINVAL},
58 .overcurrent_pin= {-EINVAL, -EINVAL},
59};
60
61static struct at91_udc_data __initdata eb9200_udc_data = {
62 .vbus_pin = AT91_PIN_PD4,
63 .pullup_pin = AT91_PIN_PD5,
64};
65
66static struct at91_cf_data __initdata eb9200_cf_data = {
67 .irq_pin = -EINVAL,
68 .det_pin = AT91_PIN_PB0,
69 .vcc_pin = -EINVAL,
70 .rst_pin = AT91_PIN_PC5,
71};
72
73static struct mci_platform_data __initdata eb9200_mci0_data = {
74 .slot[0] = {
75 .bus_width = 4,
76 .detect_pin = -EINVAL,
77 .wp_pin = -EINVAL,
78 },
79};
80
81static struct i2c_board_info __initdata eb9200_i2c_devices[] = {
82 {
83 I2C_BOARD_INFO("24c512", 0x50),
84 },
85};
86
87
88static void __init eb9200_board_init(void)
89{
90 /* Serial */
91 /* DBGU on ttyS0. (Rx & Tx only) */
92 at91_register_uart(0, 0, 0);
93
94 /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
95 at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
96 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
97 | ATMEL_UART_RI);
98
99 /* USART2 on ttyS2. (Rx, Tx) - IRDA */
100 at91_register_uart(AT91RM9200_ID_US2, 2, 0);
101 at91_add_device_serial();
102 /* Ethernet */
103 at91_add_device_eth(&eb9200_eth_data);
104 /* USB Host */
105 at91_add_device_usbh(&eb9200_usbh_data);
106 /* USB Device */
107 at91_add_device_udc(&eb9200_udc_data);
108 /* I2C */
109 at91_add_device_i2c(eb9200_i2c_devices, ARRAY_SIZE(eb9200_i2c_devices));
110 /* Compact Flash */
111 at91_add_device_cf(&eb9200_cf_data);
112 /* SPI */
113 at91_add_device_spi(NULL, 0);
114 /* MMC */
115 /* only supports 1 or 4 bit interface, not wired through to SPI */
116 at91_add_device_mci(0, &eb9200_mci0_data);
117}
118
119MACHINE_START(ATEB9200, "Embest ATEB9200")
120 .init_time = at91rm9200_timer_init,
121 .map_io = at91_map_io,
122 .handle_irq = at91_aic_handle_irq,
123 .init_early = eb9200_init_early,
124 .init_irq = at91_init_irq_default,
125 .init_machine = eb9200_board_init,
126MACHINE_END
diff --git a/arch/arm/mach-at91/board-ecbat91.c b/arch/arm/mach-at91/board-ecbat91.c
deleted file mode 100644
index ede1373ccaba..000000000000
--- a/arch/arm/mach-at91/board-ecbat91.c
+++ /dev/null
@@ -1,191 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91rm9200/board-ecbat91.c
3 * Copyright (C) 2007 emQbit.com.
4 *
5 * We started from board-dk.c, which is Copyright (C) 2005 SAN People.
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#include <linux/types.h>
23#include <linux/gpio.h>
24#include <linux/init.h>
25#include <linux/mm.h>
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/spi/spi.h>
29#include <linux/spi/flash.h>
30
31#include <mach/hardware.h>
32#include <asm/setup.h>
33#include <asm/mach-types.h>
34#include <asm/irq.h>
35
36#include <asm/mach/arch.h>
37#include <asm/mach/map.h>
38#include <asm/mach/irq.h>
39
40#include <mach/cpu.h>
41
42#include "at91_aic.h"
43#include "board.h"
44#include "generic.h"
45#include "gpio.h"
46
47
48static void __init ecb_at91init_early(void)
49{
50 /* Set cpu type: PQFP */
51 at91rm9200_set_type(ARCH_REVISON_9200_PQFP);
52
53 /* Initialize processor: 18.432 MHz crystal */
54 at91_initialize(18432000);
55}
56
57static struct macb_platform_data __initdata ecb_at91eth_data = {
58 .phy_irq_pin = AT91_PIN_PC4,
59 .is_rmii = 0,
60};
61
62static struct at91_usbh_data __initdata ecb_at91usbh_data = {
63 .ports = 1,
64 .vbus_pin = {-EINVAL, -EINVAL},
65 .overcurrent_pin= {-EINVAL, -EINVAL},
66};
67
68static struct mci_platform_data __initdata ecbat91_mci0_data = {
69 .slot[0] = {
70 .bus_width = 4,
71 .detect_pin = -EINVAL,
72 .wp_pin = -EINVAL,
73 },
74};
75
76
77#if defined(CONFIG_MTD_DATAFLASH)
78static struct mtd_partition __initdata my_flash0_partitions[] =
79{
80 { /* 0x8400 */
81 .name = "Darrell-loader",
82 .offset = 0,
83 .size = 12 * 1056,
84 },
85 {
86 .name = "U-boot",
87 .offset = MTDPART_OFS_NXTBLK,
88 .size = 110 * 1056,
89 },
90 { /* 1336 (167 blocks) pages * 1056 bytes = 0x158700 bytes */
91 .name = "UBoot-env",
92 .offset = MTDPART_OFS_NXTBLK,
93 .size = 8 * 1056,
94 },
95 { /* 1336 (167 blocks) pages * 1056 bytes = 0x158700 bytes */
96 .name = "Kernel",
97 .offset = MTDPART_OFS_NXTBLK,
98 .size = 1534 * 1056,
99 },
100 { /* 190200 - jffs2 root filesystem */
101 .name = "Filesystem",
102 .offset = MTDPART_OFS_NXTBLK,
103 .size = MTDPART_SIZ_FULL, /* 26 sectors */
104 }
105};
106
107static struct flash_platform_data __initdata my_flash0_platform = {
108 .name = "Removable flash card",
109 .parts = my_flash0_partitions,
110 .nr_parts = ARRAY_SIZE(my_flash0_partitions)
111};
112
113#endif
114
115static struct spi_board_info __initdata ecb_at91spi_devices[] = {
116 { /* DataFlash chip */
117 .modalias = "mtd_dataflash",
118 .chip_select = 0,
119 .max_speed_hz = 10 * 1000 * 1000,
120 .bus_num = 0,
121#if defined(CONFIG_MTD_DATAFLASH)
122 .platform_data = &my_flash0_platform,
123#endif
124 },
125 { /* User accessible spi - cs1 (250KHz) */
126 .modalias = "spi-cs1",
127 .chip_select = 1,
128 .max_speed_hz = 250 * 1000,
129 },
130 { /* User accessible spi - cs2 (1MHz) */
131 .modalias = "spi-cs2",
132 .chip_select = 2,
133 .max_speed_hz = 1 * 1000 * 1000,
134 },
135 { /* User accessible spi - cs3 (10MHz) */
136 .modalias = "spi-cs3",
137 .chip_select = 3,
138 .max_speed_hz = 10 * 1000 * 1000,
139 },
140};
141
142/*
143 * LEDs
144 */
145static struct gpio_led ecb_leds[] = {
146 { /* D1 */
147 .name = "led1",
148 .gpio = AT91_PIN_PC7,
149 .active_low = 1,
150 .default_trigger = "heartbeat",
151 }
152};
153
154static void __init ecb_at91board_init(void)
155{
156 /* Serial */
157 /* DBGU on ttyS0. (Rx & Tx only) */
158 at91_register_uart(0, 0, 0);
159
160 /* USART0 on ttyS1. (Rx & Tx only) */
161 at91_register_uart(AT91RM9200_ID_US0, 1, 0);
162 at91_add_device_serial();
163
164 /* Ethernet */
165 at91_add_device_eth(&ecb_at91eth_data);
166
167 /* USB Host */
168 at91_add_device_usbh(&ecb_at91usbh_data);
169
170 /* I2C */
171 at91_add_device_i2c(NULL, 0);
172
173 /* MMC */
174 at91_add_device_mci(0, &ecbat91_mci0_data);
175
176 /* SPI */
177 at91_add_device_spi(ecb_at91spi_devices, ARRAY_SIZE(ecb_at91spi_devices));
178
179 /* LEDs */
180 at91_gpio_leds(ecb_leds, ARRAY_SIZE(ecb_leds));
181}
182
183MACHINE_START(ECBAT91, "emQbit's ECB_AT91")
184 /* Maintainer: emQbit.com */
185 .init_time = at91rm9200_timer_init,
186 .map_io = at91_map_io,
187 .handle_irq = at91_aic_handle_irq,
188 .init_early = ecb_at91init_early,
189 .init_irq = at91_init_irq_default,
190 .init_machine = ecb_at91board_init,
191MACHINE_END
diff --git a/arch/arm/mach-at91/board-eco920.c b/arch/arm/mach-at91/board-eco920.c
deleted file mode 100644
index 4e75321a8f2a..000000000000
--- a/arch/arm/mach-at91/board-eco920.c
+++ /dev/null
@@ -1,160 +0,0 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 */
16
17#include <linux/init.h>
18#include <linux/platform_device.h>
19#include <linux/mtd/physmap.h>
20#include <linux/gpio.h>
21
22#include <asm/mach-types.h>
23
24#include <asm/mach/arch.h>
25#include <asm/mach/map.h>
26
27#include <mach/at91rm9200_mc.h>
28#include <mach/at91_ramc.h>
29#include <mach/cpu.h>
30
31#include "at91_aic.h"
32#include "board.h"
33#include "generic.h"
34#include "gpio.h"
35
36
37static void __init eco920_init_early(void)
38{
39 /* Set cpu type: PQFP */
40 at91rm9200_set_type(ARCH_REVISON_9200_PQFP);
41
42 at91_initialize(18432000);
43}
44
45static struct macb_platform_data __initdata eco920_eth_data = {
46 .phy_irq_pin = AT91_PIN_PC2,
47 .is_rmii = 1,
48};
49
50static struct at91_usbh_data __initdata eco920_usbh_data = {
51 .ports = 1,
52 .vbus_pin = {-EINVAL, -EINVAL},
53 .overcurrent_pin= {-EINVAL, -EINVAL},
54};
55
56static struct at91_udc_data __initdata eco920_udc_data = {
57 .vbus_pin = AT91_PIN_PB12,
58 .pullup_pin = AT91_PIN_PB13,
59};
60
61static struct mci_platform_data __initdata eco920_mci0_data = {
62 .slot[0] = {
63 .bus_width = 1,
64 .detect_pin = -EINVAL,
65 .wp_pin = -EINVAL,
66 },
67};
68
69static struct physmap_flash_data eco920_flash_data = {
70 .width = 2,
71};
72
73static struct resource eco920_flash_resource = {
74 .start = 0x11000000,
75 .end = 0x11ffffff,
76 .flags = IORESOURCE_MEM,
77};
78
79static struct platform_device eco920_flash = {
80 .name = "physmap-flash",
81 .id = 0,
82 .dev = {
83 .platform_data = &eco920_flash_data,
84 },
85 .resource = &eco920_flash_resource,
86 .num_resources = 1,
87};
88
89static struct spi_board_info eco920_spi_devices[] = {
90 { /* CAN controller */
91 .modalias = "tlv5638",
92 .chip_select = 3,
93 .max_speed_hz = 20 * 1000 * 1000,
94 .mode = SPI_CPHA,
95 },
96};
97
98/*
99 * LEDs
100 */
101static struct gpio_led eco920_leds[] = {
102 { /* D1 */
103 .name = "led1",
104 .gpio = AT91_PIN_PB0,
105 .active_low = 1,
106 .default_trigger = "heartbeat",
107 },
108 { /* D2 */
109 .name = "led2",
110 .gpio = AT91_PIN_PB1,
111 .active_low = 1,
112 .default_trigger = "timer",
113 }
114};
115
116static void __init eco920_board_init(void)
117{
118 /* DBGU on ttyS0. (Rx & Tx only */
119 at91_register_uart(0, 0, 0);
120 at91_add_device_serial();
121 at91_add_device_eth(&eco920_eth_data);
122 at91_add_device_usbh(&eco920_usbh_data);
123 at91_add_device_udc(&eco920_udc_data);
124
125 at91_add_device_mci(0, &eco920_mci0_data);
126 platform_device_register(&eco920_flash);
127
128 at91_ramc_write(0, AT91_SMC_CSR(7), AT91_SMC_RWHOLD_(1)
129 | AT91_SMC_RWSETUP_(1)
130 | AT91_SMC_DBW_8
131 | AT91_SMC_WSEN
132 | AT91_SMC_NWS_(15));
133
134 at91_set_A_periph(AT91_PIN_PC6, 1);
135
136 at91_set_gpio_input(AT91_PIN_PA23, 0);
137 at91_set_deglitch(AT91_PIN_PA23, 1);
138
139/* Initialization of the Static Memory Controller for Chip Select 3 */
140 at91_ramc_write(0, AT91_SMC_CSR(3),
141 AT91_SMC_DBW_16 | /* 16 bit */
142 AT91_SMC_WSEN |
143 AT91_SMC_NWS_(5) | /* wait states */
144 AT91_SMC_TDF_(1) /* float time */
145 );
146
147 at91_add_device_spi(eco920_spi_devices, ARRAY_SIZE(eco920_spi_devices));
148 /* LEDs */
149 at91_gpio_leds(eco920_leds, ARRAY_SIZE(eco920_leds));
150}
151
152MACHINE_START(ECO920, "eco920")
153 /* Maintainer: Sascha Hauer */
154 .init_time = at91rm9200_timer_init,
155 .map_io = at91_map_io,
156 .handle_irq = at91_aic_handle_irq,
157 .init_early = eco920_init_early,
158 .init_irq = at91_init_irq_default,
159 .init_machine = eco920_board_init,
160MACHINE_END
diff --git a/arch/arm/mach-at91/board-flexibity.c b/arch/arm/mach-at91/board-flexibity.c
deleted file mode 100644
index a6aa4a2432f2..000000000000
--- a/arch/arm/mach-at91/board-flexibity.c
+++ /dev/null
@@ -1,171 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-flexibity.c
3 *
4 * Copyright (C) 2010-2011 Flexibity
5 * Copyright (C) 2005 SAN People
6 * Copyright (C) 2006 Atmel
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/init.h>
24#include <linux/platform_device.h>
25#include <linux/spi/spi.h>
26#include <linux/input.h>
27#include <linux/gpio.h>
28
29#include <asm/mach-types.h>
30
31#include <asm/mach/arch.h>
32#include <asm/mach/map.h>
33#include <asm/mach/irq.h>
34
35#include <mach/hardware.h>
36
37#include "at91_aic.h"
38#include "board.h"
39#include "generic.h"
40#include "gpio.h"
41
42static void __init flexibity_init_early(void)
43{
44 /* Initialize processor: 18.432 MHz crystal */
45 at91_initialize(18432000);
46}
47
48/* USB Host port */
49static struct at91_usbh_data __initdata flexibity_usbh_data = {
50 .ports = 2,
51 .vbus_pin = {-EINVAL, -EINVAL},
52 .overcurrent_pin= {-EINVAL, -EINVAL},
53};
54
55/* USB Device port */
56static struct at91_udc_data __initdata flexibity_udc_data = {
57 .vbus_pin = AT91_PIN_PC5,
58 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
59};
60
61/* I2C devices */
62static struct i2c_board_info __initdata flexibity_i2c_devices[] = {
63 {
64 I2C_BOARD_INFO("ds1307", 0x68),
65 },
66};
67
68/* SPI devices */
69static struct spi_board_info flexibity_spi_devices[] = {
70 { /* DataFlash chip */
71 .modalias = "mtd_dataflash",
72 .chip_select = 1,
73 .max_speed_hz = 15 * 1000 * 1000,
74 .bus_num = 0,
75 },
76};
77
78/* MCI (SD/MMC) */
79static struct mci_platform_data __initdata flexibity_mci0_data = {
80 .slot[0] = {
81 .bus_width = 4,
82 .detect_pin = AT91_PIN_PC9,
83 .wp_pin = AT91_PIN_PC4,
84 },
85};
86
87/* LEDs */
88static struct gpio_led flexibity_leds[] = {
89 {
90 .name = "usb1:green",
91 .gpio = AT91_PIN_PA12,
92 .active_low = 1,
93 .default_trigger = "default-on",
94 },
95 {
96 .name = "usb1:red",
97 .gpio = AT91_PIN_PA13,
98 .active_low = 1,
99 .default_trigger = "default-on",
100 },
101 {
102 .name = "usb2:green",
103 .gpio = AT91_PIN_PB26,
104 .active_low = 1,
105 .default_trigger = "default-on",
106 },
107 {
108 .name = "usb2:red",
109 .gpio = AT91_PIN_PB27,
110 .active_low = 1,
111 .default_trigger = "default-on",
112 },
113 {
114 .name = "usb3:green",
115 .gpio = AT91_PIN_PC8,
116 .active_low = 1,
117 .default_trigger = "default-on",
118 },
119 {
120 .name = "usb3:red",
121 .gpio = AT91_PIN_PC6,
122 .active_low = 1,
123 .default_trigger = "default-on",
124 },
125 {
126 .name = "usb4:green",
127 .gpio = AT91_PIN_PB4,
128 .active_low = 1,
129 .default_trigger = "default-on",
130 },
131 {
132 .name = "usb4:red",
133 .gpio = AT91_PIN_PB5,
134 .active_low = 1,
135 .default_trigger = "default-on",
136 }
137};
138
139static void __init flexibity_board_init(void)
140{
141 at91_register_devices();
142
143 /* Serial */
144 /* DBGU on ttyS0. (Rx & Tx only) */
145 at91_register_uart(0, 0, 0);
146 at91_add_device_serial();
147 /* USB Host */
148 at91_add_device_usbh(&flexibity_usbh_data);
149 /* USB Device */
150 at91_add_device_udc(&flexibity_udc_data);
151 /* I2C */
152 at91_add_device_i2c(flexibity_i2c_devices,
153 ARRAY_SIZE(flexibity_i2c_devices));
154 /* SPI */
155 at91_add_device_spi(flexibity_spi_devices,
156 ARRAY_SIZE(flexibity_spi_devices));
157 /* MMC */
158 at91_add_device_mci(0, &flexibity_mci0_data);
159 /* LEDs */
160 at91_gpio_leds(flexibity_leds, ARRAY_SIZE(flexibity_leds));
161}
162
163MACHINE_START(FLEXIBITY, "Flexibity Connect")
164 /* Maintainer: Maxim Osipov */
165 .init_time = at91_init_time,
166 .map_io = at91_map_io,
167 .handle_irq = at91_aic_handle_irq,
168 .init_early = flexibity_init_early,
169 .init_irq = at91_init_irq_default,
170 .init_machine = flexibity_board_init,
171MACHINE_END
diff --git a/arch/arm/mach-at91/board-gsia18s.c b/arch/arm/mach-at91/board-gsia18s.c
deleted file mode 100644
index bf5cc55c7db6..000000000000
--- a/arch/arm/mach-at91/board-gsia18s.c
+++ /dev/null
@@ -1,585 +0,0 @@
1/*
2 * Copyright (C) 2010 Christian Glindkamp <christian.glindkamp@taskit.de>
3 * taskit GmbH
4 * 2010 Igor Plyatov <plyatov@gmail.com>
5 * GeoSIG Ltd
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#include <linux/platform_device.h>
23#include <linux/gpio.h>
24#include <linux/w1-gpio.h>
25#include <linux/i2c.h>
26#include <linux/i2c/pcf857x.h>
27#include <linux/gpio_keys.h>
28#include <linux/input.h>
29
30#include <asm/mach-types.h>
31#include <asm/mach/arch.h>
32
33#include <mach/at91sam9_smc.h>
34#include <mach/hardware.h>
35
36#include "at91_aic.h"
37#include "board.h"
38#include "sam9_smc.h"
39#include "generic.h"
40#include "gsia18s.h"
41#include "stamp9g20.h"
42#include "gpio.h"
43
44static void __init gsia18s_init_early(void)
45{
46 stamp9g20_init_early();
47}
48
49/*
50 * Two USB Host ports
51 */
52static struct at91_usbh_data __initdata usbh_data = {
53 .ports = 2,
54 .vbus_pin = {-EINVAL, -EINVAL},
55 .overcurrent_pin= {-EINVAL, -EINVAL},
56};
57
58/*
59 * USB Device port
60 */
61static struct at91_udc_data __initdata udc_data = {
62 .vbus_pin = AT91_PIN_PA22,
63 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
64};
65
66/*
67 * MACB Ethernet device
68 */
69static struct macb_platform_data __initdata macb_data = {
70 .phy_irq_pin = AT91_PIN_PA28,
71 .is_rmii = 1,
72};
73
74/*
75 * LEDs and GPOs
76 */
77static struct gpio_led gpio_leds[] = {
78 {
79 .name = "gpo:spi1reset",
80 .gpio = AT91_PIN_PC1,
81 .active_low = 0,
82 .default_trigger = "none",
83 .default_state = LEDS_GPIO_DEFSTATE_OFF,
84 },
85 {
86 .name = "gpo:trig_net_out",
87 .gpio = AT91_PIN_PB20,
88 .active_low = 0,
89 .default_trigger = "none",
90 .default_state = LEDS_GPIO_DEFSTATE_OFF,
91 },
92 {
93 .name = "gpo:trig_net_dir",
94 .gpio = AT91_PIN_PB19,
95 .active_low = 0,
96 .default_trigger = "none",
97 .default_state = LEDS_GPIO_DEFSTATE_OFF,
98 },
99 {
100 .name = "gpo:charge_dis",
101 .gpio = AT91_PIN_PC2,
102 .active_low = 0,
103 .default_trigger = "none",
104 .default_state = LEDS_GPIO_DEFSTATE_OFF,
105 },
106 {
107 .name = "led:event",
108 .gpio = AT91_PIN_PB17,
109 .active_low = 1,
110 .default_trigger = "none",
111 .default_state = LEDS_GPIO_DEFSTATE_OFF,
112 },
113 {
114 .name = "led:lan",
115 .gpio = AT91_PIN_PB18,
116 .active_low = 1,
117 .default_trigger = "none",
118 .default_state = LEDS_GPIO_DEFSTATE_OFF,
119 },
120 {
121 .name = "led:error",
122 .gpio = AT91_PIN_PB16,
123 .active_low = 1,
124 .default_trigger = "none",
125 .default_state = LEDS_GPIO_DEFSTATE_ON,
126 }
127};
128
129static struct gpio_led_platform_data gpio_led_info = {
130 .leds = gpio_leds,
131 .num_leds = ARRAY_SIZE(gpio_leds),
132};
133
134static struct platform_device leds = {
135 .name = "leds-gpio",
136 .id = 0,
137 .dev = {
138 .platform_data = &gpio_led_info,
139 }
140};
141
142static void __init gsia18s_leds_init(void)
143{
144 platform_device_register(&leds);
145}
146
147/* PCF8574 0x20 GPIO - U1 on the GS_IA18-CB_V3 board */
148static struct gpio_led pcf_gpio_leds1[] = {
149 { /* bit 0 */
150 .name = "gpo:hdc_power",
151 .gpio = PCF_GPIO_HDC_POWER,
152 .active_low = 0,
153 .default_trigger = "none",
154 .default_state = LEDS_GPIO_DEFSTATE_OFF,
155 },
156 { /* bit 1 */
157 .name = "gpo:wifi_setup",
158 .gpio = PCF_GPIO_WIFI_SETUP,
159 .active_low = 1,
160 .default_trigger = "none",
161 .default_state = LEDS_GPIO_DEFSTATE_OFF,
162 },
163 { /* bit 2 */
164 .name = "gpo:wifi_enable",
165 .gpio = PCF_GPIO_WIFI_ENABLE,
166 .active_low = 1,
167 .default_trigger = "none",
168 .default_state = LEDS_GPIO_DEFSTATE_OFF,
169 },
170 { /* bit 3 */
171 .name = "gpo:wifi_reset",
172 .gpio = PCF_GPIO_WIFI_RESET,
173 .active_low = 1,
174 .default_trigger = "none",
175 .default_state = LEDS_GPIO_DEFSTATE_ON,
176 },
177 /* bit 4 used as GPI */
178 { /* bit 5 */
179 .name = "gpo:gps_setup",
180 .gpio = PCF_GPIO_GPS_SETUP,
181 .active_low = 1,
182 .default_trigger = "none",
183 .default_state = LEDS_GPIO_DEFSTATE_OFF,
184 },
185 { /* bit 6 */
186 .name = "gpo:gps_standby",
187 .gpio = PCF_GPIO_GPS_STANDBY,
188 .active_low = 0,
189 .default_trigger = "none",
190 .default_state = LEDS_GPIO_DEFSTATE_ON,
191 },
192 { /* bit 7 */
193 .name = "gpo:gps_power",
194 .gpio = PCF_GPIO_GPS_POWER,
195 .active_low = 0,
196 .default_trigger = "none",
197 .default_state = LEDS_GPIO_DEFSTATE_OFF,
198 }
199};
200
201static struct gpio_led_platform_data pcf_gpio_led_info1 = {
202 .leds = pcf_gpio_leds1,
203 .num_leds = ARRAY_SIZE(pcf_gpio_leds1),
204};
205
206static struct platform_device pcf_leds1 = {
207 .name = "leds-gpio", /* GS_IA18-CB_board */
208 .id = 1,
209 .dev = {
210 .platform_data = &pcf_gpio_led_info1,
211 }
212};
213
214/* PCF8574 0x22 GPIO - U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
215static struct gpio_led pcf_gpio_leds2[] = {
216 { /* bit 0 */
217 .name = "gpo:alarm_1",
218 .gpio = PCF_GPIO_ALARM1,
219 .active_low = 1,
220 .default_trigger = "none",
221 .default_state = LEDS_GPIO_DEFSTATE_OFF,
222 },
223 { /* bit 1 */
224 .name = "gpo:alarm_2",
225 .gpio = PCF_GPIO_ALARM2,
226 .active_low = 1,
227 .default_trigger = "none",
228 .default_state = LEDS_GPIO_DEFSTATE_OFF,
229 },
230 { /* bit 2 */
231 .name = "gpo:alarm_3",
232 .gpio = PCF_GPIO_ALARM3,
233 .active_low = 1,
234 .default_trigger = "none",
235 .default_state = LEDS_GPIO_DEFSTATE_OFF,
236 },
237 { /* bit 3 */
238 .name = "gpo:alarm_4",
239 .gpio = PCF_GPIO_ALARM4,
240 .active_low = 1,
241 .default_trigger = "none",
242 .default_state = LEDS_GPIO_DEFSTATE_OFF,
243 },
244 /* bits 4, 5, 6 not used */
245 { /* bit 7 */
246 .name = "gpo:alarm_v_relay_on",
247 .gpio = PCF_GPIO_ALARM_V_RELAY_ON,
248 .active_low = 0,
249 .default_trigger = "none",
250 .default_state = LEDS_GPIO_DEFSTATE_OFF,
251 },
252};
253
254static struct gpio_led_platform_data pcf_gpio_led_info2 = {
255 .leds = pcf_gpio_leds2,
256 .num_leds = ARRAY_SIZE(pcf_gpio_leds2),
257};
258
259static struct platform_device pcf_leds2 = {
260 .name = "leds-gpio",
261 .id = 2,
262 .dev = {
263 .platform_data = &pcf_gpio_led_info2,
264 }
265};
266
267/* PCF8574 0x24 GPIO U1 on the GS_2G-OPT23-A_V0 board (Modem) */
268static struct gpio_led pcf_gpio_leds3[] = {
269 { /* bit 0 */
270 .name = "gpo:modem_power",
271 .gpio = PCF_GPIO_MODEM_POWER,
272 .active_low = 1,
273 .default_trigger = "none",
274 .default_state = LEDS_GPIO_DEFSTATE_OFF,
275 },
276 /* bits 1 and 2 not used */
277 { /* bit 3 */
278 .name = "gpo:modem_reset",
279 .gpio = PCF_GPIO_MODEM_RESET,
280 .active_low = 1,
281 .default_trigger = "none",
282 .default_state = LEDS_GPIO_DEFSTATE_ON,
283 },
284 /* bits 4, 5 and 6 not used */
285 { /* bit 7 */
286 .name = "gpo:trx_reset",
287 .gpio = PCF_GPIO_TRX_RESET,
288 .active_low = 1,
289 .default_trigger = "none",
290 .default_state = LEDS_GPIO_DEFSTATE_ON,
291 }
292};
293
294static struct gpio_led_platform_data pcf_gpio_led_info3 = {
295 .leds = pcf_gpio_leds3,
296 .num_leds = ARRAY_SIZE(pcf_gpio_leds3),
297};
298
299static struct platform_device pcf_leds3 = {
300 .name = "leds-gpio",
301 .id = 3,
302 .dev = {
303 .platform_data = &pcf_gpio_led_info3,
304 }
305};
306
307static void __init gsia18s_pcf_leds_init(void)
308{
309 platform_device_register(&pcf_leds1);
310 platform_device_register(&pcf_leds2);
311 platform_device_register(&pcf_leds3);
312}
313
314/*
315 * SPI busses.
316 */
317static struct spi_board_info gsia18s_spi_devices[] = {
318 { /* User accessible spi0, cs0 used for communication with MSP RTC */
319 .modalias = "spidev",
320 .bus_num = 0,
321 .chip_select = 0,
322 .max_speed_hz = 580000,
323 .mode = SPI_MODE_1,
324 },
325 { /* User accessible spi1, cs0 used for communication with int. DSP */
326 .modalias = "spidev",
327 .bus_num = 1,
328 .chip_select = 0,
329 .max_speed_hz = 5600000,
330 .mode = SPI_MODE_0,
331 },
332 { /* User accessible spi1, cs1 used for communication with ext. DSP */
333 .modalias = "spidev",
334 .bus_num = 1,
335 .chip_select = 1,
336 .max_speed_hz = 5600000,
337 .mode = SPI_MODE_0,
338 },
339 { /* User accessible spi1, cs2 used for communication with ext. DSP */
340 .modalias = "spidev",
341 .bus_num = 1,
342 .chip_select = 2,
343 .max_speed_hz = 5600000,
344 .mode = SPI_MODE_0,
345 },
346 { /* User accessible spi1, cs3 used for communication with ext. DSP */
347 .modalias = "spidev",
348 .bus_num = 1,
349 .chip_select = 3,
350 .max_speed_hz = 5600000,
351 .mode = SPI_MODE_0,
352 }
353};
354
355/*
356 * GPI Buttons
357 */
358static struct gpio_keys_button buttons[] = {
359 {
360 .gpio = GPIO_TRIG_NET_IN,
361 .code = BTN_1,
362 .desc = "TRIG_NET_IN",
363 .type = EV_KEY,
364 .active_low = 0,
365 .wakeup = 1,
366 },
367 { /* SW80 on the GS_IA18_S-MN board*/
368 .gpio = GPIO_CARD_UNMOUNT_0,
369 .code = BTN_2,
370 .desc = "Card umount 0",
371 .type = EV_KEY,
372 .active_low = 1,
373 .wakeup = 1,
374 },
375 { /* SW79 on the GS_IA18_S-MN board*/
376 .gpio = GPIO_CARD_UNMOUNT_1,
377 .code = BTN_3,
378 .desc = "Card umount 1",
379 .type = EV_KEY,
380 .active_low = 1,
381 .wakeup = 1,
382 },
383 { /* SW280 on the GS_IA18-CB board*/
384 .gpio = GPIO_KEY_POWER,
385 .code = KEY_POWER,
386 .desc = "Power Off Button",
387 .type = EV_KEY,
388 .active_low = 0,
389 .wakeup = 1,
390 }
391};
392
393static struct gpio_keys_platform_data button_data = {
394 .buttons = buttons,
395 .nbuttons = ARRAY_SIZE(buttons),
396};
397
398static struct platform_device button_device = {
399 .name = "gpio-keys",
400 .id = -1,
401 .num_resources = 0,
402 .dev = {
403 .platform_data = &button_data,
404 }
405};
406
407static void __init gsia18s_add_device_buttons(void)
408{
409 at91_set_gpio_input(GPIO_TRIG_NET_IN, 1);
410 at91_set_deglitch(GPIO_TRIG_NET_IN, 1);
411 at91_set_gpio_input(GPIO_CARD_UNMOUNT_0, 1);
412 at91_set_deglitch(GPIO_CARD_UNMOUNT_0, 1);
413 at91_set_gpio_input(GPIO_CARD_UNMOUNT_1, 1);
414 at91_set_deglitch(GPIO_CARD_UNMOUNT_1, 1);
415 at91_set_gpio_input(GPIO_KEY_POWER, 0);
416 at91_set_deglitch(GPIO_KEY_POWER, 1);
417
418 platform_device_register(&button_device);
419}
420
421/*
422 * I2C
423 */
424static int pcf8574x_0x20_setup(struct i2c_client *client, int gpio,
425 unsigned int ngpio, void *context)
426{
427 int status;
428
429 status = gpio_request(gpio + PCF_GPIO_ETH_DETECT, "eth_det");
430 if (status < 0) {
431 pr_err("error: can't request GPIO%d\n",
432 gpio + PCF_GPIO_ETH_DETECT);
433 return status;
434 }
435 status = gpio_direction_input(gpio + PCF_GPIO_ETH_DETECT);
436 if (status < 0) {
437 pr_err("error: can't setup GPIO%d as input\n",
438 gpio + PCF_GPIO_ETH_DETECT);
439 return status;
440 }
441 status = gpio_export(gpio + PCF_GPIO_ETH_DETECT, false);
442 if (status < 0) {
443 pr_err("error: can't export GPIO%d\n",
444 gpio + PCF_GPIO_ETH_DETECT);
445 return status;
446 }
447 status = gpio_sysfs_set_active_low(gpio + PCF_GPIO_ETH_DETECT, 1);
448 if (status < 0) {
449 pr_err("error: gpio_sysfs_set active_low(GPIO%d, 1)\n",
450 gpio + PCF_GPIO_ETH_DETECT);
451 return status;
452 }
453
454 return 0;
455}
456
457static int pcf8574x_0x20_teardown(struct i2c_client *client, int gpio,
458 unsigned ngpio, void *context)
459{
460 gpio_free(gpio + PCF_GPIO_ETH_DETECT);
461 return 0;
462}
463
464static struct pcf857x_platform_data pcf20_pdata = {
465 .gpio_base = GS_IA18_S_PCF_GPIO_BASE0,
466 .n_latch = (1 << 4),
467 .setup = pcf8574x_0x20_setup,
468 .teardown = pcf8574x_0x20_teardown,
469};
470
471static struct pcf857x_platform_data pcf22_pdata = {
472 .gpio_base = GS_IA18_S_PCF_GPIO_BASE1,
473};
474
475static struct pcf857x_platform_data pcf24_pdata = {
476 .gpio_base = GS_IA18_S_PCF_GPIO_BASE2,
477};
478
479static struct i2c_board_info __initdata gsia18s_i2c_devices[] = {
480 { /* U1 on the GS_IA18-CB_V3 board */
481 I2C_BOARD_INFO("pcf8574", 0x20),
482 .platform_data = &pcf20_pdata,
483 },
484 { /* U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
485 I2C_BOARD_INFO("pcf8574", 0x22),
486 .platform_data = &pcf22_pdata,
487 },
488 { /* U1 on the GS_2G-OPT23-A_V0 board (Modem) */
489 I2C_BOARD_INFO("pcf8574", 0x24),
490 .platform_data = &pcf24_pdata,
491 },
492 { /* U161 on the GS_IA18_S-MN board */
493 I2C_BOARD_INFO("24c1024", 0x50),
494 },
495 { /* U162 on the GS_IA18_S-MN board */
496 I2C_BOARD_INFO("24c01", 0x53),
497 },
498};
499
500/*
501 * Compact Flash
502 */
503static struct at91_cf_data __initdata gsia18s_cf1_data = {
504 .irq_pin = AT91_PIN_PA27,
505 .det_pin = AT91_PIN_PB30,
506 .vcc_pin = -EINVAL,
507 .rst_pin = AT91_PIN_PB31,
508 .chipselect = 5,
509 .flags = AT91_CF_TRUE_IDE,
510};
511
512/* Power Off by RTC */
513static void gsia18s_power_off(void)
514{
515 pr_notice("Power supply will be switched off automatically now or after 60 seconds without ArmDAS.\n");
516 at91_set_gpio_output(AT91_PIN_PA25, 1);
517 /* Spin to death... */
518 while (1)
519 ;
520}
521
522static int __init gsia18s_power_off_init(void)
523{
524 pm_power_off = gsia18s_power_off;
525 return 0;
526}
527
528/* ---------------------------------------------------------------------------*/
529
530static void __init gsia18s_board_init(void)
531{
532 /*
533 * USART0 on ttyS1 (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI).
534 * Used for Internal Analog Modem.
535 */
536 at91_register_uart(AT91SAM9260_ID_US0, 1,
537 ATMEL_UART_CTS | ATMEL_UART_RTS |
538 ATMEL_UART_DTR | ATMEL_UART_DSR |
539 ATMEL_UART_DCD | ATMEL_UART_RI);
540 /*
541 * USART1 on ttyS2 (Rx, Tx, CTS, RTS).
542 * Used for GPS or WiFi or Data stream.
543 */
544 at91_register_uart(AT91SAM9260_ID_US1, 2,
545 ATMEL_UART_CTS | ATMEL_UART_RTS);
546 /*
547 * USART2 on ttyS3 (Rx, Tx, CTS, RTS).
548 * Used for External Modem.
549 */
550 at91_register_uart(AT91SAM9260_ID_US2, 3,
551 ATMEL_UART_CTS | ATMEL_UART_RTS);
552 /*
553 * USART3 on ttyS4 (Rx, Tx, RTS).
554 * Used for RS-485.
555 */
556 at91_register_uart(AT91SAM9260_ID_US3, 4, ATMEL_UART_RTS);
557
558 /*
559 * USART4 on ttyS5 (Rx, Tx).
560 * Used for TRX433 Radio Module.
561 */
562 at91_register_uart(AT91SAM9260_ID_US4, 5, 0);
563 stamp9g20_board_init();
564 at91_add_device_usbh(&usbh_data);
565 at91_add_device_udc(&udc_data);
566 at91_add_device_eth(&macb_data);
567 gsia18s_leds_init();
568 gsia18s_pcf_leds_init();
569 gsia18s_add_device_buttons();
570 at91_add_device_i2c(gsia18s_i2c_devices,
571 ARRAY_SIZE(gsia18s_i2c_devices));
572 at91_add_device_cf(&gsia18s_cf1_data);
573 at91_add_device_spi(gsia18s_spi_devices,
574 ARRAY_SIZE(gsia18s_spi_devices));
575 gsia18s_power_off_init();
576}
577
578MACHINE_START(GSIA18S, "GS_IA18_S")
579 .init_time = at91_init_time,
580 .map_io = at91_map_io,
581 .handle_irq = at91_aic_handle_irq,
582 .init_early = gsia18s_init_early,
583 .init_irq = at91_init_irq_default,
584 .init_machine = gsia18s_board_init,
585MACHINE_END
diff --git a/arch/arm/mach-at91/board-kafa.c b/arch/arm/mach-at91/board-kafa.c
deleted file mode 100644
index 93b1df42f639..000000000000
--- a/arch/arm/mach-at91/board-kafa.c
+++ /dev/null
@@ -1,113 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-kafa.c
3 *
4 * Copyright (C) 2006 Sperry-Sun
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include <linux/types.h>
22#include <linux/gpio.h>
23#include <linux/init.h>
24#include <linux/mm.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
27
28#include <mach/hardware.h>
29#include <asm/setup.h>
30#include <asm/mach-types.h>
31#include <asm/irq.h>
32
33#include <asm/mach/arch.h>
34#include <asm/mach/map.h>
35#include <asm/mach/irq.h>
36
37#include <mach/cpu.h>
38
39#include "at91_aic.h"
40#include "board.h"
41#include "generic.h"
42#include "gpio.h"
43
44
45static void __init kafa_init_early(void)
46{
47 /* Set cpu type: PQFP */
48 at91rm9200_set_type(ARCH_REVISON_9200_PQFP);
49
50 /* Initialize processor: 18.432 MHz crystal */
51 at91_initialize(18432000);
52}
53
54static struct macb_platform_data __initdata kafa_eth_data = {
55 .phy_irq_pin = AT91_PIN_PC4,
56 .is_rmii = 0,
57};
58
59static struct at91_usbh_data __initdata kafa_usbh_data = {
60 .ports = 1,
61 .vbus_pin = {-EINVAL, -EINVAL},
62 .overcurrent_pin= {-EINVAL, -EINVAL},
63};
64
65static struct at91_udc_data __initdata kafa_udc_data = {
66 .vbus_pin = AT91_PIN_PB6,
67 .pullup_pin = AT91_PIN_PB7,
68};
69
70/*
71 * LEDs
72 */
73static struct gpio_led kafa_leds[] = {
74 { /* D1 */
75 .name = "led1",
76 .gpio = AT91_PIN_PB4,
77 .active_low = 1,
78 .default_trigger = "heartbeat",
79 },
80};
81
82static void __init kafa_board_init(void)
83{
84 /* Serial */
85 /* DBGU on ttyS0. (Rx & Tx only) */
86 at91_register_uart(0, 0, 0);
87
88 /* USART0 on ttyS1 (Rx, Tx, CTS, RTS) */
89 at91_register_uart(AT91RM9200_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS);
90 at91_add_device_serial();
91 /* Ethernet */
92 at91_add_device_eth(&kafa_eth_data);
93 /* USB Host */
94 at91_add_device_usbh(&kafa_usbh_data);
95 /* USB Device */
96 at91_add_device_udc(&kafa_udc_data);
97 /* I2C */
98 at91_add_device_i2c(NULL, 0);
99 /* SPI */
100 at91_add_device_spi(NULL, 0);
101 /* LEDs */
102 at91_gpio_leds(kafa_leds, ARRAY_SIZE(kafa_leds));
103}
104
105MACHINE_START(KAFA, "Sperry-Sun KAFA")
106 /* Maintainer: Sergei Sharonov */
107 .init_time = at91rm9200_timer_init,
108 .map_io = at91_map_io,
109 .handle_irq = at91_aic_handle_irq,
110 .init_early = kafa_init_early,
111 .init_irq = at91_init_irq_default,
112 .init_machine = kafa_board_init,
113MACHINE_END
diff --git a/arch/arm/mach-at91/board-kb9202.c b/arch/arm/mach-at91/board-kb9202.c
deleted file mode 100644
index d58d36225e08..000000000000
--- a/arch/arm/mach-at91/board-kb9202.c
+++ /dev/null
@@ -1,159 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-kb9202.c
3 *
4 * Copyright (c) 2005 kb_admin
5 * KwikByte, Inc.
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#include <linux/types.h>
23#include <linux/gpio.h>
24#include <linux/init.h>
25#include <linux/mm.h>
26#include <linux/module.h>
27#include <linux/platform_device.h>
28
29#include <mach/hardware.h>
30#include <asm/setup.h>
31#include <asm/mach-types.h>
32#include <asm/irq.h>
33
34#include <asm/mach/arch.h>
35#include <asm/mach/map.h>
36#include <asm/mach/irq.h>
37
38#include <mach/cpu.h>
39#include <mach/at91rm9200_mc.h>
40#include <mach/at91_ramc.h>
41
42#include "at91_aic.h"
43#include "board.h"
44#include "generic.h"
45#include "gpio.h"
46
47
48static void __init kb9202_init_early(void)
49{
50 /* Set cpu type: PQFP */
51 at91rm9200_set_type(ARCH_REVISON_9200_PQFP);
52
53 /* Initialize processor: 10 MHz crystal */
54 at91_initialize(10000000);
55}
56
57static struct macb_platform_data __initdata kb9202_eth_data = {
58 .phy_irq_pin = AT91_PIN_PB29,
59 .is_rmii = 0,
60};
61
62static struct at91_usbh_data __initdata kb9202_usbh_data = {
63 .ports = 1,
64 .vbus_pin = {-EINVAL, -EINVAL},
65 .overcurrent_pin= {-EINVAL, -EINVAL},
66};
67
68static struct at91_udc_data __initdata kb9202_udc_data = {
69 .vbus_pin = AT91_PIN_PB24,
70 .pullup_pin = AT91_PIN_PB22,
71};
72
73static struct mci_platform_data __initdata kb9202_mci0_data = {
74 .slot[0] = {
75 .bus_width = 4,
76 .detect_pin = AT91_PIN_PB2,
77 .wp_pin = -EINVAL,
78 },
79};
80
81static struct mtd_partition __initdata kb9202_nand_partition[] = {
82 {
83 .name = "nand_fs",
84 .offset = 0,
85 .size = MTDPART_SIZ_FULL,
86 },
87};
88
89static struct atmel_nand_data __initdata kb9202_nand_data = {
90 .ale = 22,
91 .cle = 21,
92 .det_pin = -EINVAL,
93 .rdy_pin = AT91_PIN_PC29,
94 .enable_pin = AT91_PIN_PC28,
95 .ecc_mode = NAND_ECC_SOFT,
96 .parts = kb9202_nand_partition,
97 .num_parts = ARRAY_SIZE(kb9202_nand_partition),
98};
99
100/*
101 * LEDs
102 */
103static struct gpio_led kb9202_leds[] = {
104 { /* D1 */
105 .name = "led1",
106 .gpio = AT91_PIN_PC19,
107 .active_low = 1,
108 .default_trigger = "heartbeat",
109 },
110 { /* D2 */
111 .name = "led2",
112 .gpio = AT91_PIN_PC18,
113 .active_low = 1,
114 .default_trigger = "timer",
115 }
116};
117
118static void __init kb9202_board_init(void)
119{
120 /* Serial */
121 /* DBGU on ttyS0. (Rx & Tx only) */
122 at91_register_uart(0, 0, 0);
123
124 /* USART0 on ttyS1 (Rx & Tx only) */
125 at91_register_uart(AT91RM9200_ID_US0, 1, 0);
126
127 /* USART1 on ttyS2 (Rx & Tx only) - IRDA (optional) */
128 at91_register_uart(AT91RM9200_ID_US1, 2, 0);
129
130 /* USART3 on ttyS3 (Rx, Tx, CTS, RTS) - RS485 (optional) */
131 at91_register_uart(AT91RM9200_ID_US3, 3, ATMEL_UART_CTS | ATMEL_UART_RTS);
132 at91_add_device_serial();
133 /* Ethernet */
134 at91_add_device_eth(&kb9202_eth_data);
135 /* USB Host */
136 at91_add_device_usbh(&kb9202_usbh_data);
137 /* USB Device */
138 at91_add_device_udc(&kb9202_udc_data);
139 /* MMC */
140 at91_add_device_mci(0, &kb9202_mci0_data);
141 /* I2C */
142 at91_add_device_i2c(NULL, 0);
143 /* SPI */
144 at91_add_device_spi(NULL, 0);
145 /* NAND */
146 at91_add_device_nand(&kb9202_nand_data);
147 /* LEDs */
148 at91_gpio_leds(kb9202_leds, ARRAY_SIZE(kb9202_leds));
149}
150
151MACHINE_START(KB9200, "KB920x")
152 /* Maintainer: KwikByte, Inc. */
153 .init_time = at91rm9200_timer_init,
154 .map_io = at91_map_io,
155 .handle_irq = at91_aic_handle_irq,
156 .init_early = kb9202_init_early,
157 .init_irq = at91_init_irq_default,
158 .init_machine = kb9202_board_init,
159MACHINE_END
diff --git a/arch/arm/mach-at91/board-pcontrol-g20.c b/arch/arm/mach-at91/board-pcontrol-g20.c
deleted file mode 100644
index 9c26b94ce448..000000000000
--- a/arch/arm/mach-at91/board-pcontrol-g20.c
+++ /dev/null
@@ -1,228 +0,0 @@
1/*
2 * Copyright (C) 2010 Christian Glindkamp <christian.glindkamp@taskit.de>
3 * taskit GmbH
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19/*
20 * copied and adjusted from board-stamp9g20.c
21 * by Peter Gsellmann <pgsellmann@portner-elektronik.at>
22 */
23
24#include <linux/mm.h>
25#include <linux/platform_device.h>
26#include <linux/gpio.h>
27#include <linux/w1-gpio.h>
28
29#include <asm/mach-types.h>
30#include <asm/mach/arch.h>
31
32#include <mach/at91sam9_smc.h>
33#include <mach/hardware.h>
34
35#include "at91_aic.h"
36#include "board.h"
37#include "sam9_smc.h"
38#include "generic.h"
39#include "stamp9g20.h"
40#include "gpio.h"
41
42
43static void __init pcontrol_g20_init_early(void)
44{
45 stamp9g20_init_early();
46}
47
48static struct sam9_smc_config __initdata pcontrol_smc_config[2] = { {
49 .ncs_read_setup = 16,
50 .nrd_setup = 18,
51 .ncs_write_setup = 16,
52 .nwe_setup = 18,
53
54 .ncs_read_pulse = 63,
55 .nrd_pulse = 55,
56 .ncs_write_pulse = 63,
57 .nwe_pulse = 55,
58
59 .read_cycle = 127,
60 .write_cycle = 127,
61
62 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
63 | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_SELECT
64 | AT91_SMC_DBW_8 | AT91_SMC_PS_4
65 | AT91_SMC_TDFMODE,
66 .tdf_cycles = 3,
67}, {
68 .ncs_read_setup = 0,
69 .nrd_setup = 0,
70 .ncs_write_setup = 0,
71 .nwe_setup = 1,
72
73 .ncs_read_pulse = 8,
74 .nrd_pulse = 8,
75 .ncs_write_pulse = 5,
76 .nwe_pulse = 4,
77
78 .read_cycle = 8,
79 .write_cycle = 7,
80
81 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE
82 | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_SELECT
83 | AT91_SMC_DBW_16 | AT91_SMC_PS_8
84 | AT91_SMC_TDFMODE,
85 .tdf_cycles = 1,
86} };
87
88static void __init add_device_pcontrol(void)
89{
90 /* configure chip-select 4 (IO compatible to 8051 X4 ) */
91 sam9_smc_configure(0, 4, &pcontrol_smc_config[0]);
92 /* configure chip-select 7 (FerroRAM 256KiBx16bit MR2A16A D4 ) */
93 sam9_smc_configure(0, 7, &pcontrol_smc_config[1]);
94}
95
96
97/*
98 * USB Host port
99 */
100static struct at91_usbh_data __initdata usbh_data = {
101 .ports = 2,
102 .vbus_pin = {-EINVAL, -EINVAL},
103 .overcurrent_pin= {-EINVAL, -EINVAL},
104};
105
106
107/*
108 * USB Device port
109 */
110static struct at91_udc_data __initdata pcontrol_g20_udc_data = {
111 .vbus_pin = AT91_PIN_PA22, /* Detect +5V bus voltage */
112 .pullup_pin = AT91_PIN_PA4, /* K-state, active low */
113};
114
115
116/*
117 * MACB Ethernet device
118 */
119static struct macb_platform_data __initdata macb_data = {
120 .phy_irq_pin = AT91_PIN_PA28,
121 .is_rmii = 1,
122};
123
124
125/*
126 * I2C devices: eeprom and phy/switch
127 */
128static struct i2c_board_info __initdata pcontrol_g20_i2c_devices[] = {
129{ /* D7 address width=2, 8KiB */
130 I2C_BOARD_INFO("24c64", 0x50)
131}, { /* D8 address width=1, 1 byte has 32 bits! */
132 I2C_BOARD_INFO("lan9303", 0x0a)
133}, };
134
135
136/*
137 * LEDs
138 */
139static struct gpio_led pcontrol_g20_leds[] = {
140 {
141 .name = "LED1", /* red H5 */
142 .gpio = AT91_PIN_PB18,
143 .active_low = 1,
144 .default_trigger = "none", /* supervisor */
145 }, {
146 .name = "LED2", /* yellow H7 */
147 .gpio = AT91_PIN_PB19,
148 .active_low = 1,
149 .default_trigger = "mmc0", /* SD-card activity */
150 }, {
151 .name = "LED3", /* green H2 */
152 .gpio = AT91_PIN_PB20,
153 .active_low = 1,
154 .default_trigger = "heartbeat", /* blinky */
155 }, {
156 .name = "LED4", /* red H3 */
157 .gpio = AT91_PIN_PC6,
158 .active_low = 1,
159 .default_trigger = "none", /* connection lost */
160 }, {
161 .name = "LED5", /* yellow H6 */
162 .gpio = AT91_PIN_PC7,
163 .active_low = 1,
164 .default_trigger = "none", /* unsent data */
165 }, {
166 .name = "LED6", /* green H1 */
167 .gpio = AT91_PIN_PC9,
168 .active_low = 1,
169 .default_trigger = "none", /* snafu */
170 }
171};
172
173
174/*
175 * SPI devices
176 */
177static struct spi_board_info pcontrol_g20_spi_devices[] = {
178 {
179 .modalias = "spidev", /* HMI port X4 */
180 .chip_select = 1,
181 .max_speed_hz = 50 * 1000 * 1000,
182 .bus_num = 0,
183 }, {
184 .modalias = "spidev", /* piggyback A2 */
185 .chip_select = 0,
186 .max_speed_hz = 50 * 1000 * 1000,
187 .bus_num = 1,
188 },
189};
190
191
192static void __init pcontrol_g20_board_init(void)
193{
194 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS) piggyback A2 */
195 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS
196 | ATMEL_UART_RTS);
197
198 /* USART1 on ttyS2. (Rx, Tx, CTS, RTS) isolated RS485 X5 */
199 at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS
200 | ATMEL_UART_RTS);
201
202 /* USART2 on ttyS3. (Rx, Tx) 9bit-Bus Multidrop-mode X4 */
203 at91_register_uart(AT91SAM9260_ID_US4, 3, 0);
204 stamp9g20_board_init();
205 at91_add_device_usbh(&usbh_data);
206 at91_add_device_eth(&macb_data);
207 at91_add_device_i2c(pcontrol_g20_i2c_devices,
208 ARRAY_SIZE(pcontrol_g20_i2c_devices));
209 add_device_pcontrol();
210 at91_add_device_spi(pcontrol_g20_spi_devices,
211 ARRAY_SIZE(pcontrol_g20_spi_devices));
212 at91_add_device_udc(&pcontrol_g20_udc_data);
213 at91_gpio_leds(pcontrol_g20_leds,
214 ARRAY_SIZE(pcontrol_g20_leds));
215 /* piggyback A2 */
216 at91_set_gpio_output(AT91_PIN_PB31, 1);
217}
218
219
220MACHINE_START(PCONTROL_G20, "PControl G20")
221 /* Maintainer: pgsellmann@portner-elektronik.at */
222 .init_time = at91_init_time,
223 .map_io = at91_map_io,
224 .handle_irq = at91_aic_handle_irq,
225 .init_early = pcontrol_g20_init_early,
226 .init_irq = at91_init_irq_default,
227 .init_machine = pcontrol_g20_board_init,
228MACHINE_END
diff --git a/arch/arm/mach-at91/board-picotux200.c b/arch/arm/mach-at91/board-picotux200.c
deleted file mode 100644
index 2c0f2d554d84..000000000000
--- a/arch/arm/mach-at91/board-picotux200.c
+++ /dev/null
@@ -1,129 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-picotux200.c
3 *
4 * Copyright (C) 2005 SAN People
5 * Copyright (C) 2007 Kleinhenz Elektronik GmbH
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#include <linux/types.h>
23#include <linux/gpio.h>
24#include <linux/init.h>
25#include <linux/mm.h>
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/spi/spi.h>
29#include <linux/mtd/physmap.h>
30
31#include <mach/hardware.h>
32#include <asm/setup.h>
33#include <asm/mach-types.h>
34#include <asm/irq.h>
35
36#include <asm/mach/arch.h>
37#include <asm/mach/map.h>
38#include <asm/mach/irq.h>
39
40#include <mach/at91rm9200_mc.h>
41#include <mach/at91_ramc.h>
42
43#include "at91_aic.h"
44#include "board.h"
45#include "generic.h"
46#include "gpio.h"
47
48
49static void __init picotux200_init_early(void)
50{
51 /* Initialize processor: 18.432 MHz crystal */
52 at91_initialize(18432000);
53}
54
55static struct macb_platform_data __initdata picotux200_eth_data = {
56 .phy_irq_pin = AT91_PIN_PC4,
57 .is_rmii = 1,
58};
59
60static struct at91_usbh_data __initdata picotux200_usbh_data = {
61 .ports = 1,
62 .vbus_pin = {-EINVAL, -EINVAL},
63 .overcurrent_pin= {-EINVAL, -EINVAL},
64};
65
66static struct mci_platform_data __initdata picotux200_mci0_data = {
67 .slot[0] = {
68 .bus_width = 4,
69 .detect_pin = AT91_PIN_PB27,
70 .wp_pin = AT91_PIN_PA17,
71 },
72};
73
74#define PICOTUX200_FLASH_BASE AT91_CHIPSELECT_0
75#define PICOTUX200_FLASH_SIZE SZ_4M
76
77static struct physmap_flash_data picotux200_flash_data = {
78 .width = 2,
79};
80
81static struct resource picotux200_flash_resource = {
82 .start = PICOTUX200_FLASH_BASE,
83 .end = PICOTUX200_FLASH_BASE + PICOTUX200_FLASH_SIZE - 1,
84 .flags = IORESOURCE_MEM,
85};
86
87static struct platform_device picotux200_flash = {
88 .name = "physmap-flash",
89 .id = 0,
90 .dev = {
91 .platform_data = &picotux200_flash_data,
92 },
93 .resource = &picotux200_flash_resource,
94 .num_resources = 1,
95};
96
97static void __init picotux200_board_init(void)
98{
99 /* Serial */
100 /* DBGU on ttyS0. (Rx & Tx only) */
101 at91_register_uart(0, 0, 0);
102
103 /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
104 at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
105 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
106 | ATMEL_UART_RI);
107 at91_add_device_serial();
108 /* Ethernet */
109 at91_add_device_eth(&picotux200_eth_data);
110 /* USB Host */
111 at91_add_device_usbh(&picotux200_usbh_data);
112 /* I2C */
113 at91_add_device_i2c(NULL, 0);
114 /* MMC */
115 at91_set_gpio_output(AT91_PIN_PB22, 1); /* this MMC card slot can optionally use SPI signaling (CS3). */
116 at91_add_device_mci(0, &picotux200_mci0_data);
117 /* NOR Flash */
118 platform_device_register(&picotux200_flash);
119}
120
121MACHINE_START(PICOTUX2XX, "picotux 200")
122 /* Maintainer: Kleinhenz Elektronik GmbH */
123 .init_time = at91rm9200_timer_init,
124 .map_io = at91_map_io,
125 .handle_irq = at91_aic_handle_irq,
126 .init_early = picotux200_init_early,
127 .init_irq = at91_init_irq_default,
128 .init_machine = picotux200_board_init,
129MACHINE_END
diff --git a/arch/arm/mach-at91/board-rm9200ek.c b/arch/arm/mach-at91/board-rm9200ek.c
deleted file mode 100644
index 953cea416754..000000000000
--- a/arch/arm/mach-at91/board-rm9200ek.c
+++ /dev/null
@@ -1,196 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-rm9200ek.c
3 *
4 * Copyright (C) 2005 SAN People
5 *
6 * Epson S1D framebuffer glue code is:
7 * Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include <linux/types.h>
25#include <linux/gpio.h>
26#include <linux/init.h>
27#include <linux/mm.h>
28#include <linux/module.h>
29#include <linux/platform_device.h>
30#include <linux/spi/spi.h>
31#include <linux/mtd/physmap.h>
32
33#include <asm/setup.h>
34#include <asm/mach-types.h>
35#include <asm/irq.h>
36
37#include <asm/mach/arch.h>
38#include <asm/mach/map.h>
39#include <asm/mach/irq.h>
40
41#include <mach/hardware.h>
42#include <mach/at91rm9200_mc.h>
43#include <mach/at91_ramc.h>
44
45#include "at91_aic.h"
46#include "board.h"
47#include "generic.h"
48#include "gpio.h"
49
50
51static void __init ek_init_early(void)
52{
53 /* Initialize processor: 18.432 MHz crystal */
54 at91_initialize(18432000);
55}
56
57static struct macb_platform_data __initdata ek_eth_data = {
58 .phy_irq_pin = AT91_PIN_PC4,
59 .is_rmii = 1,
60};
61
62static struct at91_usbh_data __initdata ek_usbh_data = {
63 .ports = 2,
64 .vbus_pin = {-EINVAL, -EINVAL},
65 .overcurrent_pin= {-EINVAL, -EINVAL},
66};
67
68static struct at91_udc_data __initdata ek_udc_data = {
69 .vbus_pin = AT91_PIN_PD4,
70 .pullup_pin = AT91_PIN_PD5,
71};
72
73#ifndef CONFIG_MTD_AT91_DATAFLASH_CARD
74static struct mci_platform_data __initdata ek_mci0_data = {
75 .slot[0] = {
76 .bus_width = 4,
77 .detect_pin = AT91_PIN_PB27,
78 .wp_pin = AT91_PIN_PA17,
79 }
80};
81#endif
82
83static struct spi_board_info ek_spi_devices[] = {
84 { /* DataFlash chip */
85 .modalias = "mtd_dataflash",
86 .chip_select = 0,
87 .max_speed_hz = 15 * 1000 * 1000,
88 },
89#ifdef CONFIG_MTD_AT91_DATAFLASH_CARD
90 { /* DataFlash card */
91 .modalias = "mtd_dataflash",
92 .chip_select = 3,
93 .max_speed_hz = 15 * 1000 * 1000,
94 },
95#endif
96};
97
98static struct i2c_board_info __initdata ek_i2c_devices[] = {
99 {
100 I2C_BOARD_INFO("ics1523", 0x26),
101 },
102 {
103 I2C_BOARD_INFO("dac3550", 0x4d),
104 }
105};
106
107#define EK_FLASH_BASE AT91_CHIPSELECT_0
108#define EK_FLASH_SIZE SZ_8M
109
110static struct physmap_flash_data ek_flash_data = {
111 .width = 2,
112};
113
114static struct resource ek_flash_resource = {
115 .start = EK_FLASH_BASE,
116 .end = EK_FLASH_BASE + EK_FLASH_SIZE - 1,
117 .flags = IORESOURCE_MEM,
118};
119
120static struct platform_device ek_flash = {
121 .name = "physmap-flash",
122 .id = 0,
123 .dev = {
124 .platform_data = &ek_flash_data,
125 },
126 .resource = &ek_flash_resource,
127 .num_resources = 1,
128};
129
130static struct gpio_led ek_leds[] = {
131 { /* "user led 1", DS2 */
132 .name = "green",
133 .gpio = AT91_PIN_PB0,
134 .active_low = 1,
135 .default_trigger = "mmc0",
136 },
137 { /* "user led 2", DS4 */
138 .name = "yellow",
139 .gpio = AT91_PIN_PB1,
140 .active_low = 1,
141 .default_trigger = "heartbeat",
142 },
143 { /* "user led 3", DS6 */
144 .name = "red",
145 .gpio = AT91_PIN_PB2,
146 .active_low = 1,
147 }
148};
149
150static void __init ek_board_init(void)
151{
152 /* Serial */
153 /* DBGU on ttyS0. (Rx & Tx only) */
154 at91_register_uart(0, 0, 0);
155
156 /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
157 at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
158 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
159 | ATMEL_UART_RI);
160 at91_add_device_serial();
161 /* Ethernet */
162 at91_add_device_eth(&ek_eth_data);
163 /* USB Host */
164 at91_add_device_usbh(&ek_usbh_data);
165 /* USB Device */
166 at91_add_device_udc(&ek_udc_data);
167 at91_set_multi_drive(ek_udc_data.pullup_pin, 1); /* pullup_pin is connected to reset */
168 /* I2C */
169 at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
170 /* SPI */
171 at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
172#ifdef CONFIG_MTD_AT91_DATAFLASH_CARD
173 /* DataFlash card */
174 at91_set_gpio_output(AT91_PIN_PB22, 0);
175#else
176 /* MMC */
177 at91_set_gpio_output(AT91_PIN_PB22, 1); /* this MMC card slot can optionally use SPI signaling (CS3). */
178 at91_add_device_mci(0, &ek_mci0_data);
179#endif
180 /* NOR Flash */
181 platform_device_register(&ek_flash);
182 /* LEDs */
183 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
184 /* VGA */
185// ek_add_device_video();
186}
187
188MACHINE_START(AT91RM9200EK, "Atmel AT91RM9200-EK")
189 /* Maintainer: SAN People/Atmel */
190 .init_time = at91rm9200_timer_init,
191 .map_io = at91_map_io,
192 .handle_irq = at91_aic_handle_irq,
193 .init_early = ek_init_early,
194 .init_irq = at91_init_irq_default,
195 .init_machine = ek_board_init,
196MACHINE_END
diff --git a/arch/arm/mach-at91/board-sam9-l9260.c b/arch/arm/mach-at91/board-sam9-l9260.c
deleted file mode 100644
index c2166e3a236c..000000000000
--- a/arch/arm/mach-at91/board-sam9-l9260.c
+++ /dev/null
@@ -1,230 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-sam9-l9260.c
3 *
4 * Copyright (C) 2005 SAN People
5 * Copyright (C) 2006 Atmel
6 * Copyright (C) 2007 Olimex Ltd
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/types.h>
24#include <linux/gpio.h>
25#include <linux/init.h>
26#include <linux/mm.h>
27#include <linux/module.h>
28#include <linux/platform_device.h>
29#include <linux/spi/spi.h>
30
31#include <mach/hardware.h>
32#include <asm/setup.h>
33#include <asm/mach-types.h>
34#include <asm/irq.h>
35
36#include <asm/mach/arch.h>
37#include <asm/mach/map.h>
38#include <asm/mach/irq.h>
39
40#include <mach/at91sam9_smc.h>
41
42#include "at91_aic.h"
43#include "board.h"
44#include "sam9_smc.h"
45#include "generic.h"
46#include "gpio.h"
47
48
49static void __init ek_init_early(void)
50{
51 /* Initialize processor: 18.432 MHz crystal */
52 at91_initialize(18432000);
53}
54
55/*
56 * USB Host port
57 */
58static struct at91_usbh_data __initdata ek_usbh_data = {
59 .ports = 2,
60 .vbus_pin = {-EINVAL, -EINVAL},
61 .overcurrent_pin= {-EINVAL, -EINVAL},
62};
63
64/*
65 * USB Device port
66 */
67static struct at91_udc_data __initdata ek_udc_data = {
68 .vbus_pin = AT91_PIN_PC5,
69 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
70};
71
72
73/*
74 * SPI devices.
75 */
76static struct spi_board_info ek_spi_devices[] = {
77#if !IS_ENABLED(CONFIG_MMC_ATMELMCI)
78 { /* DataFlash chip */
79 .modalias = "mtd_dataflash",
80 .chip_select = 1,
81 .max_speed_hz = 15 * 1000 * 1000,
82 .bus_num = 0,
83 },
84#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
85 { /* DataFlash card */
86 .modalias = "mtd_dataflash",
87 .chip_select = 0,
88 .max_speed_hz = 15 * 1000 * 1000,
89 .bus_num = 0,
90 },
91#endif
92#endif
93};
94
95
96/*
97 * MACB Ethernet device
98 */
99static struct macb_platform_data __initdata ek_macb_data = {
100 .phy_irq_pin = AT91_PIN_PA7,
101 .is_rmii = 0,
102};
103
104
105/*
106 * NAND flash
107 */
108static struct mtd_partition __initdata ek_nand_partition[] = {
109 {
110 .name = "Bootloader Area",
111 .offset = 0,
112 .size = 10 * SZ_1M,
113 },
114 {
115 .name = "User Area",
116 .offset = MTDPART_OFS_NXTBLK,
117 .size = MTDPART_SIZ_FULL,
118 },
119};
120
121static struct atmel_nand_data __initdata ek_nand_data = {
122 .ale = 21,
123 .cle = 22,
124 .det_pin = -EINVAL,
125 .rdy_pin = AT91_PIN_PC13,
126 .enable_pin = AT91_PIN_PC14,
127 .ecc_mode = NAND_ECC_SOFT,
128 .parts = ek_nand_partition,
129 .num_parts = ARRAY_SIZE(ek_nand_partition),
130};
131
132static struct sam9_smc_config __initdata ek_nand_smc_config = {
133 .ncs_read_setup = 0,
134 .nrd_setup = 1,
135 .ncs_write_setup = 0,
136 .nwe_setup = 1,
137
138 .ncs_read_pulse = 3,
139 .nrd_pulse = 3,
140 .ncs_write_pulse = 3,
141 .nwe_pulse = 3,
142
143 .read_cycle = 5,
144 .write_cycle = 5,
145
146 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
147 .tdf_cycles = 2,
148};
149
150static void __init ek_add_device_nand(void)
151{
152 /* configure chip-select 3 (NAND) */
153 sam9_smc_configure(0, 3, &ek_nand_smc_config);
154
155 at91_add_device_nand(&ek_nand_data);
156}
157
158
159/*
160 * MCI (SD/MMC)
161 */
162static struct mci_platform_data __initdata ek_mci0_data = {
163 .slot[1] = {
164 .bus_width = 4,
165 .detect_pin = AT91_PIN_PC8,
166 .wp_pin = AT91_PIN_PC4,
167 },
168};
169
170/*
171 * LEDs
172 */
173static struct gpio_led ek_leds[] = {
174 { /* D1 */
175 .name = "led1",
176 .gpio = AT91_PIN_PA9,
177 .active_low = 1,
178 .default_trigger = "heartbeat",
179 },
180 { /* D2 */
181 .name = "led2",
182 .gpio = AT91_PIN_PA6,
183 .active_low = 1,
184 .default_trigger = "timer",
185 }
186};
187
188static void __init ek_board_init(void)
189{
190 at91_register_devices();
191
192 /* Serial */
193 /* DBGU on ttyS0. (Rx & Tx only) */
194 at91_register_uart(0, 0, 0);
195
196 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
197 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
198 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
199 | ATMEL_UART_RI);
200
201 /* USART1 on ttyS2. (Rx, Tx, CTS, RTS) */
202 at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
203 at91_add_device_serial();
204 /* USB Host */
205 at91_add_device_usbh(&ek_usbh_data);
206 /* USB Device */
207 at91_add_device_udc(&ek_udc_data);
208 /* SPI */
209 at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
210 /* NAND */
211 ek_add_device_nand();
212 /* Ethernet */
213 at91_add_device_eth(&ek_macb_data);
214 /* MMC */
215 at91_add_device_mci(0, &ek_mci0_data);
216 /* I2C */
217 at91_add_device_i2c(NULL, 0);
218 /* LEDs */
219 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
220}
221
222MACHINE_START(SAM9_L9260, "Olimex SAM9-L9260")
223 /* Maintainer: Olimex */
224 .init_time = at91_init_time,
225 .map_io = at91_map_io,
226 .handle_irq = at91_aic_handle_irq,
227 .init_early = ek_init_early,
228 .init_irq = at91_init_irq_default,
229 .init_machine = ek_board_init,
230MACHINE_END
diff --git a/arch/arm/mach-at91/board-sam9260ek.c b/arch/arm/mach-at91/board-sam9260ek.c
deleted file mode 100644
index bf8a946b4cd0..000000000000
--- a/arch/arm/mach-at91/board-sam9260ek.c
+++ /dev/null
@@ -1,354 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-sam9260ek.c
3 *
4 * Copyright (C) 2005 SAN People
5 * Copyright (C) 2006 Atmel
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#include <linux/types.h>
23#include <linux/gpio.h>
24#include <linux/init.h>
25#include <linux/mm.h>
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/spi/spi.h>
29#include <linux/spi/at73c213.h>
30#include <linux/clk.h>
31#include <linux/platform_data/at24.h>
32#include <linux/gpio_keys.h>
33#include <linux/input.h>
34
35#include <asm/setup.h>
36#include <asm/mach-types.h>
37#include <asm/irq.h>
38
39#include <asm/mach/arch.h>
40#include <asm/mach/map.h>
41#include <asm/mach/irq.h>
42
43#include <mach/hardware.h>
44#include <mach/at91sam9_smc.h>
45#include <mach/system_rev.h>
46
47#include "at91_aic.h"
48#include "board.h"
49#include "sam9_smc.h"
50#include "generic.h"
51#include "gpio.h"
52
53
54static void __init ek_init_early(void)
55{
56 /* Initialize processor: 18.432 MHz crystal */
57 at91_initialize(18432000);
58}
59
60/*
61 * USB Host port
62 */
63static struct at91_usbh_data __initdata ek_usbh_data = {
64 .ports = 2,
65 .vbus_pin = {-EINVAL, -EINVAL},
66 .overcurrent_pin= {-EINVAL, -EINVAL},
67};
68
69/*
70 * USB Device port
71 */
72static struct at91_udc_data __initdata ek_udc_data = {
73 .vbus_pin = AT91_PIN_PC5,
74 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
75};
76
77
78/*
79 * Audio
80 */
81static struct at73c213_board_info at73c213_data = {
82 .ssc_id = 0,
83 .shortname = "AT91SAM9260-EK external DAC",
84};
85
86#if defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
87static void __init at73c213_set_clk(struct at73c213_board_info *info)
88{
89 struct clk *pck0;
90 struct clk *plla;
91
92 pck0 = clk_get(NULL, "pck0");
93 plla = clk_get(NULL, "plla");
94
95 /* AT73C213 MCK Clock */
96 at91_set_B_periph(AT91_PIN_PC1, 0); /* PCK0 */
97
98 clk_set_parent(pck0, plla);
99 clk_put(plla);
100
101 info->dac_clk = pck0;
102}
103#else
104static void __init at73c213_set_clk(struct at73c213_board_info *info) {}
105#endif
106
107/*
108 * SPI devices.
109 */
110static struct spi_board_info ek_spi_devices[] = {
111#if !IS_ENABLED(CONFIG_MMC_ATMELMCI)
112 { /* DataFlash chip */
113 .modalias = "mtd_dataflash",
114 .chip_select = 1,
115 .max_speed_hz = 15 * 1000 * 1000,
116 .bus_num = 0,
117 },
118#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
119 { /* DataFlash card */
120 .modalias = "mtd_dataflash",
121 .chip_select = 0,
122 .max_speed_hz = 15 * 1000 * 1000,
123 .bus_num = 0,
124 },
125#endif
126#endif
127#if defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
128 { /* AT73C213 DAC */
129 .modalias = "at73c213",
130 .chip_select = 0,
131 .max_speed_hz = 10 * 1000 * 1000,
132 .bus_num = 1,
133 .mode = SPI_MODE_1,
134 .platform_data = &at73c213_data,
135 },
136#endif
137};
138
139
140/*
141 * MACB Ethernet device
142 */
143static struct macb_platform_data __initdata ek_macb_data = {
144 .phy_irq_pin = AT91_PIN_PA7,
145 .is_rmii = 1,
146};
147
148
149/*
150 * NAND flash
151 */
152static struct mtd_partition __initdata ek_nand_partition[] = {
153 {
154 .name = "Partition 1",
155 .offset = 0,
156 .size = SZ_256K,
157 },
158 {
159 .name = "Partition 2",
160 .offset = MTDPART_OFS_NXTBLK,
161 .size = MTDPART_SIZ_FULL,
162 },
163};
164
165static struct atmel_nand_data __initdata ek_nand_data = {
166 .ale = 21,
167 .cle = 22,
168 .det_pin = -EINVAL,
169 .rdy_pin = AT91_PIN_PC13,
170 .enable_pin = AT91_PIN_PC14,
171 .ecc_mode = NAND_ECC_SOFT,
172 .on_flash_bbt = 1,
173 .parts = ek_nand_partition,
174 .num_parts = ARRAY_SIZE(ek_nand_partition),
175};
176
177static struct sam9_smc_config __initdata ek_nand_smc_config = {
178 .ncs_read_setup = 0,
179 .nrd_setup = 1,
180 .ncs_write_setup = 0,
181 .nwe_setup = 1,
182
183 .ncs_read_pulse = 3,
184 .nrd_pulse = 3,
185 .ncs_write_pulse = 3,
186 .nwe_pulse = 3,
187
188 .read_cycle = 5,
189 .write_cycle = 5,
190
191 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
192 .tdf_cycles = 2,
193};
194
195static void __init ek_add_device_nand(void)
196{
197 ek_nand_data.bus_width_16 = board_have_nand_16bit();
198 /* setup bus-width (8 or 16) */
199 if (ek_nand_data.bus_width_16)
200 ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
201 else
202 ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
203
204 /* configure chip-select 3 (NAND) */
205 sam9_smc_configure(0, 3, &ek_nand_smc_config);
206
207 at91_add_device_nand(&ek_nand_data);
208}
209
210
211/*
212 * MCI (SD/MMC)
213 */
214static struct mci_platform_data __initdata ek_mci0_data = {
215 .slot[1] = {
216 .bus_width = 4,
217 .detect_pin = -EINVAL,
218 .wp_pin = -EINVAL,
219 },
220};
221
222
223/*
224 * LEDs
225 */
226static struct gpio_led ek_leds[] = {
227 { /* "bottom" led, green, userled1 to be defined */
228 .name = "ds5",
229 .gpio = AT91_PIN_PA6,
230 .active_low = 1,
231 .default_trigger = "none",
232 },
233 { /* "power" led, yellow */
234 .name = "ds1",
235 .gpio = AT91_PIN_PA9,
236 .default_trigger = "heartbeat",
237 }
238};
239
240/*
241 * I2C devices
242 */
243static struct at24_platform_data at24c512 = {
244 .byte_len = SZ_512K / 8,
245 .page_size = 128,
246 .flags = AT24_FLAG_ADDR16,
247};
248
249static struct i2c_board_info __initdata ek_i2c_devices[] = {
250 {
251 I2C_BOARD_INFO("24c512", 0x50),
252 .platform_data = &at24c512,
253 },
254 /* more devices can be added using expansion connectors */
255};
256
257
258/*
259 * GPIO Buttons
260 */
261#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
262static struct gpio_keys_button ek_buttons[] = {
263 {
264 .gpio = AT91_PIN_PA30,
265 .code = BTN_3,
266 .desc = "Button 3",
267 .active_low = 1,
268 .wakeup = 1,
269 },
270 {
271 .gpio = AT91_PIN_PA31,
272 .code = BTN_4,
273 .desc = "Button 4",
274 .active_low = 1,
275 .wakeup = 1,
276 }
277};
278
279static struct gpio_keys_platform_data ek_button_data = {
280 .buttons = ek_buttons,
281 .nbuttons = ARRAY_SIZE(ek_buttons),
282};
283
284static struct platform_device ek_button_device = {
285 .name = "gpio-keys",
286 .id = -1,
287 .num_resources = 0,
288 .dev = {
289 .platform_data = &ek_button_data,
290 }
291};
292
293static void __init ek_add_device_buttons(void)
294{
295 at91_set_gpio_input(AT91_PIN_PA30, 1); /* btn3 */
296 at91_set_deglitch(AT91_PIN_PA30, 1);
297 at91_set_gpio_input(AT91_PIN_PA31, 1); /* btn4 */
298 at91_set_deglitch(AT91_PIN_PA31, 1);
299
300 platform_device_register(&ek_button_device);
301}
302#else
303static void __init ek_add_device_buttons(void) {}
304#endif
305
306
307static void __init ek_board_init(void)
308{
309 at91_register_devices();
310
311 /* Serial */
312 /* DBGU on ttyS0. (Rx & Tx only) */
313 at91_register_uart(0, 0, 0);
314
315 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
316 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
317 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
318 | ATMEL_UART_RI);
319
320 /* USART1 on ttyS2. (Rx, Tx, RTS, CTS) */
321 at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
322 at91_add_device_serial();
323 /* USB Host */
324 at91_add_device_usbh(&ek_usbh_data);
325 /* USB Device */
326 at91_add_device_udc(&ek_udc_data);
327 /* SPI */
328 at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
329 /* NAND */
330 ek_add_device_nand();
331 /* Ethernet */
332 at91_add_device_eth(&ek_macb_data);
333 /* MMC */
334 at91_add_device_mci(0, &ek_mci0_data);
335 /* I2C */
336 at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
337 /* SSC (to AT73C213) */
338 at73c213_set_clk(&at73c213_data);
339 at91_add_device_ssc(AT91SAM9260_ID_SSC, ATMEL_SSC_TX);
340 /* LEDs */
341 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
342 /* Push Buttons */
343 ek_add_device_buttons();
344}
345
346MACHINE_START(AT91SAM9260EK, "Atmel AT91SAM9260-EK")
347 /* Maintainer: Atmel */
348 .init_time = at91_init_time,
349 .map_io = at91_map_io,
350 .handle_irq = at91_aic_handle_irq,
351 .init_early = ek_init_early,
352 .init_irq = at91_init_irq_default,
353 .init_machine = ek_board_init,
354MACHINE_END
diff --git a/arch/arm/mach-at91/board-sam9261ek.c b/arch/arm/mach-at91/board-sam9261ek.c
deleted file mode 100644
index e85ada820bfb..000000000000
--- a/arch/arm/mach-at91/board-sam9261ek.c
+++ /dev/null
@@ -1,623 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-sam9261ek.c
3 *
4 * Copyright (C) 2005 SAN People
5 * Copyright (C) 2006 Atmel
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#include <linux/types.h>
23#include <linux/gpio.h>
24#include <linux/init.h>
25#include <linux/mm.h>
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/spi/spi.h>
29#include <linux/spi/ads7846.h>
30#include <linux/spi/at73c213.h>
31#include <linux/clk.h>
32#include <linux/dm9000.h>
33#include <linux/fb.h>
34#include <linux/gpio_keys.h>
35#include <linux/input.h>
36
37#include <video/atmel_lcdc.h>
38
39#include <asm/setup.h>
40#include <asm/mach-types.h>
41#include <asm/irq.h>
42
43#include <asm/mach/arch.h>
44#include <asm/mach/map.h>
45#include <asm/mach/irq.h>
46
47#include <mach/hardware.h>
48#include <mach/at91sam9_smc.h>
49#include <mach/system_rev.h>
50
51#include "at91_aic.h"
52#include "board.h"
53#include "sam9_smc.h"
54#include "generic.h"
55#include "gpio.h"
56
57
58static void __init ek_init_early(void)
59{
60 /* Initialize processor: 18.432 MHz crystal */
61 at91_initialize(18432000);
62}
63
64/*
65 * DM9000 ethernet device
66 */
67#if defined(CONFIG_DM9000)
68static struct resource dm9000_resource[] = {
69 [0] = {
70 .start = AT91_CHIPSELECT_2,
71 .end = AT91_CHIPSELECT_2 + 3,
72 .flags = IORESOURCE_MEM
73 },
74 [1] = {
75 .start = AT91_CHIPSELECT_2 + 0x44,
76 .end = AT91_CHIPSELECT_2 + 0xFF,
77 .flags = IORESOURCE_MEM
78 },
79 [2] = {
80 .flags = IORESOURCE_IRQ
81 | IORESOURCE_IRQ_LOWEDGE | IORESOURCE_IRQ_HIGHEDGE,
82 }
83};
84
85static struct dm9000_plat_data dm9000_platdata = {
86 .flags = DM9000_PLATF_16BITONLY | DM9000_PLATF_NO_EEPROM,
87};
88
89static struct platform_device dm9000_device = {
90 .name = "dm9000",
91 .id = 0,
92 .num_resources = ARRAY_SIZE(dm9000_resource),
93 .resource = dm9000_resource,
94 .dev = {
95 .platform_data = &dm9000_platdata,
96 }
97};
98
99/*
100 * SMC timings for the DM9000.
101 * Note: These timings were calculated for MASTER_CLOCK = 100000000 according to the DM9000 timings.
102 */
103static struct sam9_smc_config __initdata dm9000_smc_config = {
104 .ncs_read_setup = 0,
105 .nrd_setup = 2,
106 .ncs_write_setup = 0,
107 .nwe_setup = 2,
108
109 .ncs_read_pulse = 8,
110 .nrd_pulse = 4,
111 .ncs_write_pulse = 8,
112 .nwe_pulse = 4,
113
114 .read_cycle = 16,
115 .write_cycle = 16,
116
117 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_BAT_WRITE | AT91_SMC_DBW_16,
118 .tdf_cycles = 1,
119};
120
121static void __init ek_add_device_dm9000(void)
122{
123 struct resource *r = &dm9000_resource[2];
124
125 /* Configure chip-select 2 (DM9000) */
126 sam9_smc_configure(0, 2, &dm9000_smc_config);
127
128 /* Configure Reset signal as output */
129 at91_set_gpio_output(AT91_PIN_PC10, 0);
130
131 /* Configure Interrupt pin as input, no pull-up */
132 at91_set_gpio_input(AT91_PIN_PC11, 0);
133
134 r->start = r->end = gpio_to_irq(AT91_PIN_PC11);
135 platform_device_register(&dm9000_device);
136}
137#else
138static void __init ek_add_device_dm9000(void) {}
139#endif /* CONFIG_DM9000 */
140
141
142/*
143 * USB Host Port
144 */
145static struct at91_usbh_data __initdata ek_usbh_data = {
146 .ports = 2,
147 .vbus_pin = {-EINVAL, -EINVAL},
148 .overcurrent_pin= {-EINVAL, -EINVAL},
149};
150
151
152/*
153 * USB Device Port
154 */
155static struct at91_udc_data __initdata ek_udc_data = {
156 .vbus_pin = AT91_PIN_PB29,
157 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
158};
159
160
161/*
162 * NAND flash
163 */
164static struct mtd_partition __initdata ek_nand_partition[] = {
165 {
166 .name = "Partition 1",
167 .offset = 0,
168 .size = SZ_256K,
169 },
170 {
171 .name = "Partition 2",
172 .offset = MTDPART_OFS_NXTBLK,
173 .size = MTDPART_SIZ_FULL,
174 },
175};
176
177static struct atmel_nand_data __initdata ek_nand_data = {
178 .ale = 22,
179 .cle = 21,
180 .det_pin = -EINVAL,
181 .rdy_pin = AT91_PIN_PC15,
182 .enable_pin = AT91_PIN_PC14,
183 .ecc_mode = NAND_ECC_SOFT,
184 .on_flash_bbt = 1,
185 .parts = ek_nand_partition,
186 .num_parts = ARRAY_SIZE(ek_nand_partition),
187};
188
189static struct sam9_smc_config __initdata ek_nand_smc_config = {
190 .ncs_read_setup = 0,
191 .nrd_setup = 1,
192 .ncs_write_setup = 0,
193 .nwe_setup = 1,
194
195 .ncs_read_pulse = 3,
196 .nrd_pulse = 3,
197 .ncs_write_pulse = 3,
198 .nwe_pulse = 3,
199
200 .read_cycle = 5,
201 .write_cycle = 5,
202
203 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
204 .tdf_cycles = 2,
205};
206
207static void __init ek_add_device_nand(void)
208{
209 ek_nand_data.bus_width_16 = board_have_nand_16bit();
210 /* setup bus-width (8 or 16) */
211 if (ek_nand_data.bus_width_16)
212 ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
213 else
214 ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
215
216 /* configure chip-select 3 (NAND) */
217 sam9_smc_configure(0, 3, &ek_nand_smc_config);
218
219 at91_add_device_nand(&ek_nand_data);
220}
221
222/*
223 * SPI related devices
224 */
225#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
226
227/*
228 * ADS7846 Touchscreen
229 */
230#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
231
232static int ads7843_pendown_state(void)
233{
234 return !at91_get_gpio_value(AT91_PIN_PC2); /* Touchscreen PENIRQ */
235}
236
237static struct ads7846_platform_data ads_info = {
238 .model = 7843,
239 .x_min = 150,
240 .x_max = 3830,
241 .y_min = 190,
242 .y_max = 3830,
243 .vref_delay_usecs = 100,
244 .x_plate_ohms = 450,
245 .y_plate_ohms = 250,
246 .pressure_max = 15000,
247 .debounce_max = 1,
248 .debounce_rep = 0,
249 .debounce_tol = (~0),
250 .get_pendown_state = ads7843_pendown_state,
251};
252
253static void __init ek_add_device_ts(void)
254{
255 at91_set_B_periph(AT91_PIN_PC2, 1); /* External IRQ0, with pullup */
256 at91_set_gpio_input(AT91_PIN_PA11, 1); /* Touchscreen BUSY signal */
257}
258#else
259static void __init ek_add_device_ts(void) {}
260#endif
261
262/*
263 * Audio
264 */
265static struct at73c213_board_info at73c213_data = {
266 .ssc_id = 1,
267 .shortname = "AT91SAM9261/9G10-EK external DAC",
268};
269
270#if defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
271static void __init at73c213_set_clk(struct at73c213_board_info *info)
272{
273 struct clk *pck2;
274 struct clk *plla;
275
276 pck2 = clk_get(NULL, "pck2");
277 plla = clk_get(NULL, "plla");
278
279 /* AT73C213 MCK Clock */
280 at91_set_B_periph(AT91_PIN_PB31, 0); /* PCK2 */
281
282 clk_set_parent(pck2, plla);
283 clk_put(plla);
284
285 info->dac_clk = pck2;
286}
287#else
288static void __init at73c213_set_clk(struct at73c213_board_info *info) {}
289#endif
290
291/*
292 * SPI devices
293 */
294static struct spi_board_info ek_spi_devices[] = {
295 { /* DataFlash chip */
296 .modalias = "mtd_dataflash",
297 .chip_select = 0,
298 .max_speed_hz = 15 * 1000 * 1000,
299 .bus_num = 0,
300 },
301#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
302 {
303 .modalias = "ads7846",
304 .chip_select = 2,
305 .max_speed_hz = 125000 * 26, /* (max sample rate @ 3V) * (cmd + data + overhead) */
306 .bus_num = 0,
307 .platform_data = &ads_info,
308 .irq = NR_IRQS_LEGACY + AT91SAM9261_ID_IRQ0,
309 .controller_data = (void *) AT91_PIN_PA28, /* CS pin */
310 },
311#endif
312#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
313 { /* DataFlash card - jumper (J12) configurable to CS3 or CS0 */
314 .modalias = "mtd_dataflash",
315 .chip_select = 3,
316 .max_speed_hz = 15 * 1000 * 1000,
317 .bus_num = 0,
318 },
319#elif defined(CONFIG_SND_AT73C213) || defined(CONFIG_SND_AT73C213_MODULE)
320 { /* AT73C213 DAC */
321 .modalias = "at73c213",
322 .chip_select = 3,
323 .max_speed_hz = 10 * 1000 * 1000,
324 .bus_num = 0,
325 .mode = SPI_MODE_1,
326 .platform_data = &at73c213_data,
327 .controller_data = (void*) AT91_PIN_PA29, /* default for CS3 is PA6, but it must be PA29 */
328 },
329#endif
330};
331
332#else /* CONFIG_SPI_ATMEL_* */
333/* spi0 and mmc/sd share the same PIO pins: cannot be used at the same time */
334
335/*
336 * MCI (SD/MMC)
337 * det_pin, wp_pin and vcc_pin are not connected
338 */
339static struct mci_platform_data __initdata mci0_data = {
340 .slot[0] = {
341 .bus_width = 4,
342 .detect_pin = -EINVAL,
343 .wp_pin = -EINVAL,
344 },
345};
346
347#endif /* CONFIG_SPI_ATMEL_* */
348
349
350/*
351 * LCD Controller
352 */
353#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
354
355#if defined(CONFIG_FB_ATMEL_STN)
356
357/* STN */
358static struct fb_videomode at91_stn_modes[] = {
359 {
360 .name = "SP06Q002 @ 75",
361 .refresh = 75,
362 .xres = 320, .yres = 240,
363 .pixclock = KHZ2PICOS(1440),
364
365 .left_margin = 1, .right_margin = 1,
366 .upper_margin = 0, .lower_margin = 0,
367 .hsync_len = 1, .vsync_len = 1,
368
369 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
370 .vmode = FB_VMODE_NONINTERLACED,
371 },
372};
373
374static struct fb_monspecs at91fb_default_stn_monspecs = {
375 .manufacturer = "HIT",
376 .monitor = "SP06Q002",
377
378 .modedb = at91_stn_modes,
379 .modedb_len = ARRAY_SIZE(at91_stn_modes),
380 .hfmin = 15000,
381 .hfmax = 64000,
382 .vfmin = 50,
383 .vfmax = 150,
384};
385
386#define AT91SAM9261_DEFAULT_STN_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \
387 | ATMEL_LCDC_DISTYPE_STNMONO \
388 | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE \
389 | ATMEL_LCDC_IFWIDTH_4 \
390 | ATMEL_LCDC_SCANMOD_SINGLE)
391
392static void at91_lcdc_stn_power_control(struct atmel_lcdfb_pdata *pdata, int on)
393{
394 /* backlight */
395 if (on) { /* power up */
396 at91_set_gpio_value(AT91_PIN_PC14, 0);
397 at91_set_gpio_value(AT91_PIN_PC15, 0);
398 } else { /* power down */
399 at91_set_gpio_value(AT91_PIN_PC14, 1);
400 at91_set_gpio_value(AT91_PIN_PC15, 1);
401 }
402}
403
404static struct atmel_lcdfb_pdata __initdata ek_lcdc_data = {
405 .default_bpp = 1,
406 .default_dmacon = ATMEL_LCDC_DMAEN,
407 .default_lcdcon2 = AT91SAM9261_DEFAULT_STN_LCDCON2,
408 .default_monspecs = &at91fb_default_stn_monspecs,
409 .atmel_lcdfb_power_control = at91_lcdc_stn_power_control,
410 .guard_time = 1,
411};
412
413#else
414
415/* TFT */
416static struct fb_videomode at91_tft_vga_modes[] = {
417 {
418 .name = "TX09D50VM1CCA @ 60",
419 .refresh = 60,
420 .xres = 240, .yres = 320,
421 .pixclock = KHZ2PICOS(4965),
422
423 .left_margin = 1, .right_margin = 33,
424 .upper_margin = 1, .lower_margin = 0,
425 .hsync_len = 5, .vsync_len = 1,
426
427 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
428 .vmode = FB_VMODE_NONINTERLACED,
429 },
430};
431
432static struct fb_monspecs at91fb_default_tft_monspecs = {
433 .manufacturer = "HIT",
434 .monitor = "TX09D50VM1CCA",
435
436 .modedb = at91_tft_vga_modes,
437 .modedb_len = ARRAY_SIZE(at91_tft_vga_modes),
438 .hfmin = 15000,
439 .hfmax = 64000,
440 .vfmin = 50,
441 .vfmax = 150,
442};
443
444#define AT91SAM9261_DEFAULT_TFT_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \
445 | ATMEL_LCDC_DISTYPE_TFT \
446 | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
447
448static void at91_lcdc_tft_power_control(struct atmel_lcdfb_pdata *pdata, int on)
449{
450 if (on)
451 at91_set_gpio_value(AT91_PIN_PA12, 0); /* power up */
452 else
453 at91_set_gpio_value(AT91_PIN_PA12, 1); /* power down */
454}
455
456static struct atmel_lcdfb_pdata __initdata ek_lcdc_data = {
457 .lcdcon_is_backlight = true,
458 .default_bpp = 16,
459 .default_dmacon = ATMEL_LCDC_DMAEN,
460 .default_lcdcon2 = AT91SAM9261_DEFAULT_TFT_LCDCON2,
461 .default_monspecs = &at91fb_default_tft_monspecs,
462 .atmel_lcdfb_power_control = at91_lcdc_tft_power_control,
463 .guard_time = 1,
464};
465#endif
466
467#else
468static struct atmel_lcdfb_pdata __initdata ek_lcdc_data;
469#endif
470
471
472/*
473 * GPIO Buttons
474 */
475#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
476static struct gpio_keys_button ek_buttons[] = {
477 {
478 .gpio = AT91_PIN_PA27,
479 .code = BTN_0,
480 .desc = "Button 0",
481 .active_low = 1,
482 .wakeup = 1,
483 },
484 {
485 .gpio = AT91_PIN_PA26,
486 .code = BTN_1,
487 .desc = "Button 1",
488 .active_low = 1,
489 .wakeup = 1,
490 },
491 {
492 .gpio = AT91_PIN_PA25,
493 .code = BTN_2,
494 .desc = "Button 2",
495 .active_low = 1,
496 .wakeup = 1,
497 },
498 {
499 .gpio = AT91_PIN_PA24,
500 .code = BTN_3,
501 .desc = "Button 3",
502 .active_low = 1,
503 .wakeup = 1,
504 }
505};
506
507static struct gpio_keys_platform_data ek_button_data = {
508 .buttons = ek_buttons,
509 .nbuttons = ARRAY_SIZE(ek_buttons),
510};
511
512static struct platform_device ek_button_device = {
513 .name = "gpio-keys",
514 .id = -1,
515 .num_resources = 0,
516 .dev = {
517 .platform_data = &ek_button_data,
518 }
519};
520
521static void __init ek_add_device_buttons(void)
522{
523 at91_set_gpio_input(AT91_PIN_PA27, 1); /* btn0 */
524 at91_set_deglitch(AT91_PIN_PA27, 1);
525 at91_set_gpio_input(AT91_PIN_PA26, 1); /* btn1 */
526 at91_set_deglitch(AT91_PIN_PA26, 1);
527 at91_set_gpio_input(AT91_PIN_PA25, 1); /* btn2 */
528 at91_set_deglitch(AT91_PIN_PA25, 1);
529 at91_set_gpio_input(AT91_PIN_PA24, 1); /* btn3 */
530 at91_set_deglitch(AT91_PIN_PA24, 1);
531
532 platform_device_register(&ek_button_device);
533}
534#else
535static void __init ek_add_device_buttons(void) {}
536#endif
537
538/*
539 * LEDs
540 */
541static struct gpio_led ek_leds[] = {
542 { /* "bottom" led, green, userled1 to be defined */
543 .name = "ds7",
544 .gpio = AT91_PIN_PA14,
545 .active_low = 1,
546 .default_trigger = "none",
547 },
548 { /* "top" led, green, userled2 to be defined */
549 .name = "ds8",
550 .gpio = AT91_PIN_PA13,
551 .active_low = 1,
552 .default_trigger = "none",
553 },
554 { /* "power" led, yellow */
555 .name = "ds1",
556 .gpio = AT91_PIN_PA23,
557 .default_trigger = "heartbeat",
558 }
559};
560
561static void __init ek_board_init(void)
562{
563 at91_register_devices();
564
565 /* Serial */
566 /* DBGU on ttyS0. (Rx & Tx only) */
567 at91_register_uart(0, 0, 0);
568 at91_add_device_serial();
569
570 if (cpu_is_at91sam9g10())
571 ek_lcdc_data.lcd_wiring_mode = ATMEL_LCDC_WIRING_RGB;
572
573 /* USB Host */
574 at91_add_device_usbh(&ek_usbh_data);
575 /* USB Device */
576 at91_add_device_udc(&ek_udc_data);
577 /* I2C */
578 at91_add_device_i2c(NULL, 0);
579 /* NAND */
580 ek_add_device_nand();
581 /* DM9000 ethernet */
582 ek_add_device_dm9000();
583
584 /* spi0 and mmc/sd share the same PIO pins */
585#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
586 /* SPI */
587 at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
588 /* Touchscreen */
589 ek_add_device_ts();
590 /* SSC (to AT73C213) */
591 at73c213_set_clk(&at73c213_data);
592 at91_add_device_ssc(AT91SAM9261_ID_SSC1, ATMEL_SSC_TX);
593#else
594 /* MMC */
595 at91_add_device_mci(0, &mci0_data);
596#endif
597 /* LCD Controller */
598 at91_add_device_lcdc(&ek_lcdc_data);
599 /* Push Buttons */
600 ek_add_device_buttons();
601 /* LEDs */
602 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
603}
604
605MACHINE_START(AT91SAM9261EK, "Atmel AT91SAM9261-EK")
606 /* Maintainer: Atmel */
607 .init_time = at91_init_time,
608 .map_io = at91_map_io,
609 .handle_irq = at91_aic_handle_irq,
610 .init_early = ek_init_early,
611 .init_irq = at91_init_irq_default,
612 .init_machine = ek_board_init,
613MACHINE_END
614
615MACHINE_START(AT91SAM9G10EK, "Atmel AT91SAM9G10-EK")
616 /* Maintainer: Atmel */
617 .init_time = at91_init_time,
618 .map_io = at91_map_io,
619 .handle_irq = at91_aic_handle_irq,
620 .init_early = ek_init_early,
621 .init_irq = at91_init_irq_default,
622 .init_machine = ek_board_init,
623MACHINE_END
diff --git a/arch/arm/mach-at91/board-sam9263ek.c b/arch/arm/mach-at91/board-sam9263ek.c
deleted file mode 100644
index d76680f2a209..000000000000
--- a/arch/arm/mach-at91/board-sam9263ek.c
+++ /dev/null
@@ -1,493 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-sam9263ek.c
3 *
4 * Copyright (C) 2005 SAN People
5 * Copyright (C) 2007 Atmel Corporation.
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#include <linux/types.h>
23#include <linux/gpio.h>
24#include <linux/init.h>
25#include <linux/mm.h>
26#include <linux/module.h>
27#include <linux/platform_device.h>
28#include <linux/spi/spi.h>
29#include <linux/spi/ads7846.h>
30#include <linux/platform_data/at24.h>
31#include <linux/fb.h>
32#include <linux/gpio_keys.h>
33#include <linux/input.h>
34#include <linux/leds.h>
35#include <linux/pwm.h>
36#include <linux/leds_pwm.h>
37
38#include <video/atmel_lcdc.h>
39
40#include <asm/setup.h>
41#include <asm/mach-types.h>
42#include <asm/irq.h>
43
44#include <asm/mach/arch.h>
45#include <asm/mach/map.h>
46#include <asm/mach/irq.h>
47
48#include <mach/hardware.h>
49#include <mach/at91sam9_smc.h>
50#include <mach/system_rev.h>
51
52#include "at91_aic.h"
53#include "board.h"
54#include "sam9_smc.h"
55#include "generic.h"
56#include "gpio.h"
57
58
59static void __init ek_init_early(void)
60{
61 /* Initialize processor: 16.367 MHz crystal */
62 at91_initialize(16367660);
63}
64
65/*
66 * USB Host port
67 */
68static struct at91_usbh_data __initdata ek_usbh_data = {
69 .ports = 2,
70 .vbus_pin = { AT91_PIN_PA24, AT91_PIN_PA21 },
71 .vbus_pin_active_low = {1, 1},
72 .overcurrent_pin= {-EINVAL, -EINVAL},
73};
74
75/*
76 * USB Device port
77 */
78static struct at91_udc_data __initdata ek_udc_data = {
79 .vbus_pin = AT91_PIN_PA25,
80 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
81};
82
83
84/*
85 * ADS7846 Touchscreen
86 */
87#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
88static int ads7843_pendown_state(void)
89{
90 return !at91_get_gpio_value(AT91_PIN_PA15); /* Touchscreen PENIRQ */
91}
92
93static struct ads7846_platform_data ads_info = {
94 .model = 7843,
95 .x_min = 150,
96 .x_max = 3830,
97 .y_min = 190,
98 .y_max = 3830,
99 .vref_delay_usecs = 100,
100 .x_plate_ohms = 450,
101 .y_plate_ohms = 250,
102 .pressure_max = 15000,
103 .debounce_max = 1,
104 .debounce_rep = 0,
105 .debounce_tol = (~0),
106 .get_pendown_state = ads7843_pendown_state,
107};
108
109static void __init ek_add_device_ts(void)
110{
111 at91_set_B_periph(AT91_PIN_PA15, 1); /* External IRQ1, with pullup */
112 at91_set_gpio_input(AT91_PIN_PA31, 1); /* Touchscreen BUSY signal */
113}
114#else
115static void __init ek_add_device_ts(void) {}
116#endif
117
118/*
119 * SPI devices.
120 */
121static struct spi_board_info ek_spi_devices[] = {
122#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
123 { /* DataFlash card */
124 .modalias = "mtd_dataflash",
125 .chip_select = 0,
126 .max_speed_hz = 15 * 1000 * 1000,
127 .bus_num = 0,
128 },
129#endif
130#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
131 {
132 .modalias = "ads7846",
133 .chip_select = 3,
134 .max_speed_hz = 125000 * 26, /* (max sample rate @ 3V) * (cmd + data + overhead) */
135 .bus_num = 0,
136 .platform_data = &ads_info,
137 .irq = NR_IRQS_LEGACY + AT91SAM9263_ID_IRQ1,
138 },
139#endif
140};
141
142
143/*
144 * MCI (SD/MMC)
145 */
146static struct mci_platform_data __initdata mci1_data = {
147 .slot[0] = {
148 .bus_width = 4,
149 .detect_pin = AT91_PIN_PE18,
150 .wp_pin = AT91_PIN_PE19,
151 },
152};
153
154
155/*
156 * MACB Ethernet device
157 */
158static struct macb_platform_data __initdata ek_macb_data = {
159 .phy_irq_pin = AT91_PIN_PE31,
160 .is_rmii = 1,
161};
162
163
164/*
165 * NAND flash
166 */
167static struct mtd_partition __initdata ek_nand_partition[] = {
168 {
169 .name = "Partition 1",
170 .offset = 0,
171 .size = SZ_64M,
172 },
173 {
174 .name = "Partition 2",
175 .offset = MTDPART_OFS_NXTBLK,
176 .size = MTDPART_SIZ_FULL,
177 },
178};
179
180static struct atmel_nand_data __initdata ek_nand_data = {
181 .ale = 21,
182 .cle = 22,
183 .det_pin = -EINVAL,
184 .rdy_pin = AT91_PIN_PA22,
185 .enable_pin = AT91_PIN_PD15,
186 .ecc_mode = NAND_ECC_SOFT,
187 .on_flash_bbt = 1,
188 .parts = ek_nand_partition,
189 .num_parts = ARRAY_SIZE(ek_nand_partition),
190};
191
192static struct sam9_smc_config __initdata ek_nand_smc_config = {
193 .ncs_read_setup = 0,
194 .nrd_setup = 1,
195 .ncs_write_setup = 0,
196 .nwe_setup = 1,
197
198 .ncs_read_pulse = 3,
199 .nrd_pulse = 3,
200 .ncs_write_pulse = 3,
201 .nwe_pulse = 3,
202
203 .read_cycle = 5,
204 .write_cycle = 5,
205
206 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
207 .tdf_cycles = 2,
208};
209
210static void __init ek_add_device_nand(void)
211{
212 ek_nand_data.bus_width_16 = board_have_nand_16bit();
213 /* setup bus-width (8 or 16) */
214 if (ek_nand_data.bus_width_16)
215 ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
216 else
217 ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
218
219 /* configure chip-select 3 (NAND) */
220 sam9_smc_configure(0, 3, &ek_nand_smc_config);
221
222 at91_add_device_nand(&ek_nand_data);
223}
224
225
226/*
227 * I2C devices
228 */
229static struct at24_platform_data at24c512 = {
230 .byte_len = SZ_512K / 8,
231 .page_size = 128,
232 .flags = AT24_FLAG_ADDR16,
233};
234
235
236static struct i2c_board_info __initdata ek_i2c_devices[] = {
237 {
238 I2C_BOARD_INFO("24c512", 0x50),
239 .platform_data = &at24c512,
240 },
241 /* more devices can be added using expansion connectors */
242};
243
244/*
245 * LCD Controller
246 */
247#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
248static struct fb_videomode at91_tft_vga_modes[] = {
249 {
250 .name = "TX09D50VM1CCA @ 60",
251 .refresh = 60,
252 .xres = 240, .yres = 320,
253 .pixclock = KHZ2PICOS(4965),
254
255 .left_margin = 1, .right_margin = 33,
256 .upper_margin = 1, .lower_margin = 0,
257 .hsync_len = 5, .vsync_len = 1,
258
259 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
260 .vmode = FB_VMODE_NONINTERLACED,
261 },
262};
263
264static struct fb_monspecs at91fb_default_monspecs = {
265 .manufacturer = "HIT",
266 .monitor = "TX09D70VM1CCA",
267
268 .modedb = at91_tft_vga_modes,
269 .modedb_len = ARRAY_SIZE(at91_tft_vga_modes),
270 .hfmin = 15000,
271 .hfmax = 64000,
272 .vfmin = 50,
273 .vfmax = 150,
274};
275
276#define AT91SAM9263_DEFAULT_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \
277 | ATMEL_LCDC_DISTYPE_TFT \
278 | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
279
280static void at91_lcdc_power_control(struct atmel_lcdfb_pdata *pdata, int on)
281{
282 at91_set_gpio_value(AT91_PIN_PA30, on);
283}
284
285/* Driver datas */
286static struct atmel_lcdfb_pdata __initdata ek_lcdc_data = {
287 .lcdcon_is_backlight = true,
288 .default_bpp = 16,
289 .default_dmacon = ATMEL_LCDC_DMAEN,
290 .default_lcdcon2 = AT91SAM9263_DEFAULT_LCDCON2,
291 .default_monspecs = &at91fb_default_monspecs,
292 .atmel_lcdfb_power_control = at91_lcdc_power_control,
293 .guard_time = 1,
294};
295
296#else
297static struct atmel_lcdfb_pdata __initdata ek_lcdc_data;
298#endif
299
300
301/*
302 * GPIO Buttons
303 */
304#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
305static struct gpio_keys_button ek_buttons[] = {
306 { /* BP1, "leftclic" */
307 .code = BTN_LEFT,
308 .gpio = AT91_PIN_PC5,
309 .active_low = 1,
310 .desc = "left_click",
311 .wakeup = 1,
312 },
313 { /* BP2, "rightclic" */
314 .code = BTN_RIGHT,
315 .gpio = AT91_PIN_PC4,
316 .active_low = 1,
317 .desc = "right_click",
318 .wakeup = 1,
319 }
320};
321
322static struct gpio_keys_platform_data ek_button_data = {
323 .buttons = ek_buttons,
324 .nbuttons = ARRAY_SIZE(ek_buttons),
325};
326
327static struct platform_device ek_button_device = {
328 .name = "gpio-keys",
329 .id = -1,
330 .num_resources = 0,
331 .dev = {
332 .platform_data = &ek_button_data,
333 }
334};
335
336static void __init ek_add_device_buttons(void)
337{
338 at91_set_GPIO_periph(AT91_PIN_PC5, 1); /* left button */
339 at91_set_deglitch(AT91_PIN_PC5, 1);
340 at91_set_GPIO_periph(AT91_PIN_PC4, 1); /* right button */
341 at91_set_deglitch(AT91_PIN_PC4, 1);
342
343 platform_device_register(&ek_button_device);
344}
345#else
346static void __init ek_add_device_buttons(void) {}
347#endif
348
349
350/*
351 * AC97
352 * reset_pin is not connected: NRST
353 */
354static struct ac97c_platform_data ek_ac97_data = {
355 .reset_pin = -EINVAL,
356};
357
358
359/*
360 * LEDs ... these could all be PWM-driven, for variable brightness
361 */
362static struct gpio_led ek_leds[] = {
363 { /* "right" led, green, userled2 (could be driven by pwm2) */
364 .name = "ds2",
365 .gpio = AT91_PIN_PC29,
366 .active_low = 1,
367 .default_trigger = "nand-disk",
368 },
369 { /* "power" led, yellow (could be driven by pwm0) */
370 .name = "ds3",
371 .gpio = AT91_PIN_PB7,
372 .default_trigger = "heartbeat",
373 },
374#if !IS_ENABLED(CONFIG_LEDS_PWM)
375 {
376 .name = "ds1",
377 .gpio = AT91_PIN_PB8,
378 .active_low = 1,
379 .default_trigger = "none",
380 }
381#endif
382};
383
384/*
385 * PWM Leds
386 */
387static struct pwm_lookup pwm_lookup[] = {
388 PWM_LOOKUP("at91sam9rl-pwm", 1, "leds_pwm", "ds1",
389 5000, PWM_POLARITY_INVERSED),
390};
391
392#if IS_ENABLED(CONFIG_LEDS_PWM)
393static struct led_pwm pwm_leds[] = {
394 {
395 .name = "ds1",
396 .max_brightness = 255,
397 },
398};
399
400static struct led_pwm_platform_data pwm_data = {
401 .num_leds = ARRAY_SIZE(pwm_leds),
402 .leds = pwm_leds,
403};
404
405static struct platform_device leds_pwm = {
406 .name = "leds_pwm",
407 .id = -1,
408 .dev = {
409 .platform_data = &pwm_data,
410 },
411};
412#endif
413
414
415/*
416 * CAN
417 */
418static void sam9263ek_transceiver_switch(int on)
419{
420 if (on) {
421 at91_set_gpio_output(AT91_PIN_PA18, 1); /* CANRXEN */
422 at91_set_gpio_output(AT91_PIN_PA19, 0); /* CANRS */
423 } else {
424 at91_set_gpio_output(AT91_PIN_PA18, 0); /* CANRXEN */
425 at91_set_gpio_output(AT91_PIN_PA19, 1); /* CANRS */
426 }
427}
428
429static struct at91_can_data ek_can_data = {
430 .transceiver_switch = sam9263ek_transceiver_switch,
431};
432
433static struct platform_device *devices[] __initdata = {
434#if IS_ENABLED(CONFIG_LEDS_PWM)
435 &leds_pwm,
436#endif
437};
438
439static void __init ek_board_init(void)
440{
441 at91_register_devices();
442
443 /* Serial */
444 /* DBGU on ttyS0. (Rx & Tx only) */
445 at91_register_uart(0, 0, 0);
446
447 /* USART0 on ttyS1. (Rx, Tx, RTS, CTS) */
448 at91_register_uart(AT91SAM9263_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS);
449 at91_add_device_serial();
450 /* USB Host */
451 at91_add_device_usbh(&ek_usbh_data);
452 /* USB Device */
453 at91_add_device_udc(&ek_udc_data);
454 /* SPI */
455 at91_set_gpio_output(AT91_PIN_PE20, 1); /* select spi0 clock */
456 at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
457 /* Touchscreen */
458 ek_add_device_ts();
459 /* MMC */
460 at91_add_device_mci(1, &mci1_data);
461 /* Ethernet */
462 at91_add_device_eth(&ek_macb_data);
463 /* NAND */
464 ek_add_device_nand();
465 /* I2C */
466 at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
467 /* LCD Controller */
468 at91_add_device_lcdc(&ek_lcdc_data);
469 /* Push Buttons */
470 ek_add_device_buttons();
471 /* AC97 */
472 at91_add_device_ac97(&ek_ac97_data);
473 /* LEDs */
474 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
475 pwm_add_table(pwm_lookup, ARRAY_SIZE(pwm_lookup));
476#if IS_ENABLED(CONFIG_LEDS_PWM)
477 at91_add_device_pwm(1 << AT91_PWM1);
478#endif
479 /* CAN */
480 at91_add_device_can(&ek_can_data);
481 /* Other platform devices */
482 platform_add_devices(devices, ARRAY_SIZE(devices));
483}
484
485MACHINE_START(AT91SAM9263EK, "Atmel AT91SAM9263-EK")
486 /* Maintainer: Atmel */
487 .init_time = at91_init_time,
488 .map_io = at91_map_io,
489 .handle_irq = at91_aic_handle_irq,
490 .init_early = ek_init_early,
491 .init_irq = at91_init_irq_default,
492 .init_machine = ek_board_init,
493MACHINE_END
diff --git a/arch/arm/mach-at91/board-sam9g20ek.c b/arch/arm/mach-at91/board-sam9g20ek.c
deleted file mode 100644
index 49f075213451..000000000000
--- a/arch/arm/mach-at91/board-sam9g20ek.c
+++ /dev/null
@@ -1,429 +0,0 @@
1/*
2 * Copyright (C) 2005 SAN People
3 * Copyright (C) 2008 Atmel
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/types.h>
21#include <linux/gpio.h>
22#include <linux/init.h>
23#include <linux/mm.h>
24#include <linux/module.h>
25#include <linux/platform_device.h>
26#include <linux/spi/spi.h>
27#include <linux/spi/at73c213.h>
28#include <linux/gpio_keys.h>
29#include <linux/input.h>
30#include <linux/clk.h>
31#include <linux/regulator/machine.h>
32#include <linux/regulator/fixed.h>
33#include <linux/regulator/consumer.h>
34
35#include <linux/platform_data/at91_adc.h>
36
37#include <mach/hardware.h>
38#include <asm/setup.h>
39#include <asm/mach-types.h>
40#include <asm/irq.h>
41
42#include <asm/mach/arch.h>
43#include <asm/mach/map.h>
44#include <asm/mach/irq.h>
45
46#include <mach/at91sam9_smc.h>
47#include <mach/system_rev.h>
48
49#include "at91_aic.h"
50#include "board.h"
51#include "sam9_smc.h"
52#include "generic.h"
53#include "gpio.h"
54
55/*
56 * board revision encoding
57 * bit 0:
58 * 0 => 1 sd/mmc slot
59 * 1 => 2 sd/mmc slots connectors (board from revision C)
60 */
61#define HAVE_2MMC (1 << 0)
62static int inline ek_have_2mmc(void)
63{
64 return machine_is_at91sam9g20ek_2mmc() || (system_rev & HAVE_2MMC);
65}
66
67
68static void __init ek_init_early(void)
69{
70 /* Initialize processor: 18.432 MHz crystal */
71 at91_initialize(18432000);
72}
73
74/*
75 * USB Host port
76 */
77static struct at91_usbh_data __initdata ek_usbh_data = {
78 .ports = 2,
79 .vbus_pin = {-EINVAL, -EINVAL},
80 .overcurrent_pin= {-EINVAL, -EINVAL},
81};
82
83/*
84 * USB Device port
85 */
86static struct at91_udc_data __initdata ek_udc_data = {
87 .vbus_pin = AT91_PIN_PC5,
88 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
89};
90
91
92/*
93 * SPI devices.
94 */
95static struct spi_board_info ek_spi_devices[] = {
96#if !IS_ENABLED(CONFIG_MMC_ATMELMCI)
97 { /* DataFlash chip */
98 .modalias = "mtd_dataflash",
99 .chip_select = 1,
100 .max_speed_hz = 15 * 1000 * 1000,
101 .bus_num = 0,
102 },
103#if defined(CONFIG_MTD_AT91_DATAFLASH_CARD)
104 { /* DataFlash card */
105 .modalias = "mtd_dataflash",
106 .chip_select = 0,
107 .max_speed_hz = 15 * 1000 * 1000,
108 .bus_num = 0,
109 },
110#endif
111#endif
112};
113
114
115/*
116 * MACB Ethernet device
117 */
118static struct macb_platform_data __initdata ek_macb_data = {
119 .phy_irq_pin = AT91_PIN_PA7,
120 .is_rmii = 1,
121};
122
123static void __init ek_add_device_macb(void)
124{
125 if (ek_have_2mmc())
126 ek_macb_data.phy_irq_pin = AT91_PIN_PB0;
127
128 at91_add_device_eth(&ek_macb_data);
129}
130
131/*
132 * NAND flash
133 */
134static struct mtd_partition __initdata ek_nand_partition[] = {
135 {
136 .name = "Bootstrap",
137 .offset = 0,
138 .size = 4 * SZ_1M,
139 },
140 {
141 .name = "Partition 1",
142 .offset = MTDPART_OFS_NXTBLK,
143 .size = 60 * SZ_1M,
144 },
145 {
146 .name = "Partition 2",
147 .offset = MTDPART_OFS_NXTBLK,
148 .size = MTDPART_SIZ_FULL,
149 },
150};
151
152/* det_pin is not connected */
153static struct atmel_nand_data __initdata ek_nand_data = {
154 .ale = 21,
155 .cle = 22,
156 .rdy_pin = AT91_PIN_PC13,
157 .enable_pin = AT91_PIN_PC14,
158 .det_pin = -EINVAL,
159 .ecc_mode = NAND_ECC_SOFT,
160 .on_flash_bbt = 1,
161 .parts = ek_nand_partition,
162 .num_parts = ARRAY_SIZE(ek_nand_partition),
163};
164
165static struct sam9_smc_config __initdata ek_nand_smc_config = {
166 .ncs_read_setup = 0,
167 .nrd_setup = 2,
168 .ncs_write_setup = 0,
169 .nwe_setup = 2,
170
171 .ncs_read_pulse = 4,
172 .nrd_pulse = 4,
173 .ncs_write_pulse = 4,
174 .nwe_pulse = 4,
175
176 .read_cycle = 7,
177 .write_cycle = 7,
178
179 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
180 .tdf_cycles = 3,
181};
182
183static void __init ek_add_device_nand(void)
184{
185 ek_nand_data.bus_width_16 = board_have_nand_16bit();
186 /* setup bus-width (8 or 16) */
187 if (ek_nand_data.bus_width_16)
188 ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
189 else
190 ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
191
192 /* configure chip-select 3 (NAND) */
193 sam9_smc_configure(0, 3, &ek_nand_smc_config);
194
195 at91_add_device_nand(&ek_nand_data);
196}
197
198
199/*
200 * MCI (SD/MMC)
201 * wp_pin and vcc_pin are not connected
202 */
203static struct mci_platform_data __initdata ek_mmc_data = {
204 .slot[1] = {
205 .bus_width = 4,
206 .detect_pin = AT91_PIN_PC9,
207 .wp_pin = -EINVAL,
208 },
209
210};
211
212static void __init ek_add_device_mmc(void)
213{
214 if (ek_have_2mmc()) {
215 ek_mmc_data.slot[0].bus_width = 4;
216 ek_mmc_data.slot[0].detect_pin = AT91_PIN_PC2;
217 ek_mmc_data.slot[0].wp_pin = -1;
218 }
219 at91_add_device_mci(0, &ek_mmc_data);
220}
221
222/*
223 * LEDs
224 */
225static struct gpio_led ek_leds[] = {
226 { /* "bottom" led, green, userled1 to be defined */
227 .name = "ds5",
228 .gpio = AT91_PIN_PA6,
229 .active_low = 1,
230 .default_trigger = "none",
231 },
232 { /* "power" led, yellow */
233 .name = "ds1",
234 .gpio = AT91_PIN_PA9,
235 .default_trigger = "heartbeat",
236 }
237};
238
239static void __init ek_add_device_gpio_leds(void)
240{
241 if (ek_have_2mmc()) {
242 ek_leds[0].gpio = AT91_PIN_PB8;
243 ek_leds[1].gpio = AT91_PIN_PB9;
244 }
245
246 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
247}
248
249/*
250 * GPIO Buttons
251 */
252#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
253static struct gpio_keys_button ek_buttons[] = {
254 {
255 .gpio = AT91_PIN_PA30,
256 .code = BTN_3,
257 .desc = "Button 3",
258 .active_low = 1,
259 .wakeup = 1,
260 },
261 {
262 .gpio = AT91_PIN_PA31,
263 .code = BTN_4,
264 .desc = "Button 4",
265 .active_low = 1,
266 .wakeup = 1,
267 }
268};
269
270static struct gpio_keys_platform_data ek_button_data = {
271 .buttons = ek_buttons,
272 .nbuttons = ARRAY_SIZE(ek_buttons),
273};
274
275static struct platform_device ek_button_device = {
276 .name = "gpio-keys",
277 .id = -1,
278 .num_resources = 0,
279 .dev = {
280 .platform_data = &ek_button_data,
281 }
282};
283
284static void __init ek_add_device_buttons(void)
285{
286 at91_set_gpio_input(AT91_PIN_PA30, 1); /* btn3 */
287 at91_set_deglitch(AT91_PIN_PA30, 1);
288 at91_set_gpio_input(AT91_PIN_PA31, 1); /* btn4 */
289 at91_set_deglitch(AT91_PIN_PA31, 1);
290
291 platform_device_register(&ek_button_device);
292}
293#else
294static void __init ek_add_device_buttons(void) {}
295#endif
296
297/*
298 * ADCs
299 */
300
301static struct at91_adc_data ek_adc_data = {
302 .channels_used = BIT(0) | BIT(1) | BIT(2) | BIT(3),
303 .use_external_triggers = true,
304 .vref = 3300,
305};
306
307#if defined(CONFIG_REGULATOR_FIXED_VOLTAGE) || defined(CONFIG_REGULATOR_FIXED_VOLTAGE_MODULE)
308static struct regulator_consumer_supply ek_audio_consumer_supplies[] = {
309 REGULATOR_SUPPLY("AVDD", "0-001b"),
310 REGULATOR_SUPPLY("HPVDD", "0-001b"),
311 REGULATOR_SUPPLY("DBVDD", "0-001b"),
312 REGULATOR_SUPPLY("DCVDD", "0-001b"),
313};
314
315static struct regulator_init_data ek_avdd_reg_init_data = {
316 .constraints = {
317 .name = "3V3",
318 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
319 },
320 .consumer_supplies = ek_audio_consumer_supplies,
321 .num_consumer_supplies = ARRAY_SIZE(ek_audio_consumer_supplies),
322};
323
324static struct fixed_voltage_config ek_vdd_pdata = {
325 .supply_name = "board-3V3",
326 .microvolts = 3300000,
327 .gpio = -EINVAL,
328 .enabled_at_boot = 0,
329 .init_data = &ek_avdd_reg_init_data,
330};
331static struct platform_device ek_voltage_regulator = {
332 .name = "reg-fixed-voltage",
333 .id = -1,
334 .num_resources = 0,
335 .dev = {
336 .platform_data = &ek_vdd_pdata,
337 },
338};
339static void __init ek_add_regulators(void)
340{
341 platform_device_register(&ek_voltage_regulator);
342}
343#else
344static void __init ek_add_regulators(void) {}
345#endif
346
347
348static struct i2c_board_info __initdata ek_i2c_devices[] = {
349 {
350 I2C_BOARD_INFO("24c512", 0x50)
351 },
352 {
353 I2C_BOARD_INFO("wm8731", 0x1b)
354 },
355};
356
357static struct platform_device sam9g20ek_audio_device = {
358 .name = "at91sam9g20ek-audio",
359 .id = -1,
360};
361
362static void __init ek_add_device_audio(void)
363{
364 platform_device_register(&sam9g20ek_audio_device);
365}
366
367
368static void __init ek_board_init(void)
369{
370 /* Serial */
371 /* DBGU on ttyS0. (Rx & Tx only) */
372 at91_register_uart(0, 0, 0);
373
374 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
375 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
376 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
377 | ATMEL_UART_RI);
378
379 /* USART1 on ttyS2. (Rx, Tx, RTS, CTS) */
380 at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
381 at91_add_device_serial();
382 /* USB Host */
383 at91_add_device_usbh(&ek_usbh_data);
384 /* USB Device */
385 at91_add_device_udc(&ek_udc_data);
386 /* SPI */
387 at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
388 /* NAND */
389 ek_add_device_nand();
390 /* Ethernet */
391 ek_add_device_macb();
392 /* Regulators */
393 ek_add_regulators();
394 /* MMC */
395 ek_add_device_mmc();
396 /* I2C */
397 at91_add_device_i2c(ek_i2c_devices, ARRAY_SIZE(ek_i2c_devices));
398 /* LEDs */
399 ek_add_device_gpio_leds();
400 /* Push Buttons */
401 ek_add_device_buttons();
402 /* ADCs */
403 at91_add_device_adc(&ek_adc_data);
404 /* PCK0 provides MCLK to the WM8731 */
405 at91_set_B_periph(AT91_PIN_PC1, 0);
406 /* SSC (for WM8731) */
407 at91_add_device_ssc(AT91SAM9260_ID_SSC, ATMEL_SSC_TX);
408 ek_add_device_audio();
409}
410
411MACHINE_START(AT91SAM9G20EK, "Atmel AT91SAM9G20-EK")
412 /* Maintainer: Atmel */
413 .init_time = at91_init_time,
414 .map_io = at91_map_io,
415 .handle_irq = at91_aic_handle_irq,
416 .init_early = ek_init_early,
417 .init_irq = at91_init_irq_default,
418 .init_machine = ek_board_init,
419MACHINE_END
420
421MACHINE_START(AT91SAM9G20EK_2MMC, "Atmel AT91SAM9G20-EK 2 MMC Slot Mod")
422 /* Maintainer: Atmel */
423 .init_time = at91_init_time,
424 .map_io = at91_map_io,
425 .handle_irq = at91_aic_handle_irq,
426 .init_early = ek_init_early,
427 .init_irq = at91_init_irq_default,
428 .init_machine = ek_board_init,
429MACHINE_END
diff --git a/arch/arm/mach-at91/board-sam9m10g45ek.c b/arch/arm/mach-at91/board-sam9m10g45ek.c
deleted file mode 100644
index a517c7f7af92..000000000000
--- a/arch/arm/mach-at91/board-sam9m10g45ek.c
+++ /dev/null
@@ -1,527 +0,0 @@
1/*
2 * Board-specific setup code for the AT91SAM9M10G45 Evaluation Kit family
3 *
4 * Covers: * AT91SAM9G45-EKES board
5 * * AT91SAM9M10G45-EK board
6 *
7 * Copyright (C) 2009 Atmel Corporation.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 */
15
16#include <linux/types.h>
17#include <linux/gpio.h>
18#include <linux/init.h>
19#include <linux/mm.h>
20#include <linux/module.h>
21#include <linux/platform_device.h>
22#include <linux/spi/spi.h>
23#include <linux/fb.h>
24#include <linux/gpio_keys.h>
25#include <linux/input.h>
26#include <linux/leds.h>
27#include <linux/atmel-mci.h>
28#include <linux/delay.h>
29#include <linux/pwm.h>
30#include <linux/leds_pwm.h>
31
32#include <linux/platform_data/at91_adc.h>
33
34#include <mach/hardware.h>
35#include <video/atmel_lcdc.h>
36#include <media/soc_camera.h>
37#include <media/atmel-isi.h>
38
39#include <asm/setup.h>
40#include <asm/mach-types.h>
41#include <asm/irq.h>
42
43#include <asm/mach/arch.h>
44#include <asm/mach/map.h>
45#include <asm/mach/irq.h>
46
47#include <mach/at91sam9_smc.h>
48#include <mach/system_rev.h>
49
50#include "at91_aic.h"
51#include "board.h"
52#include "sam9_smc.h"
53#include "generic.h"
54#include "gpio.h"
55
56
57static void __init ek_init_early(void)
58{
59 /* Initialize processor: 12.000 MHz crystal */
60 at91_initialize(12000000);
61}
62
63/*
64 * USB HS Host port (common to OHCI & EHCI)
65 */
66static struct at91_usbh_data __initdata ek_usbh_hs_data = {
67 .ports = 2,
68 .vbus_pin = {AT91_PIN_PD1, AT91_PIN_PD3},
69 .vbus_pin_active_low = {1, 1},
70 .overcurrent_pin= {-EINVAL, -EINVAL},
71};
72
73
74/*
75 * USB HS Device port
76 */
77static struct usba_platform_data __initdata ek_usba_udc_data = {
78 .vbus_pin = AT91_PIN_PB19,
79};
80
81
82/*
83 * SPI devices.
84 */
85static struct spi_board_info ek_spi_devices[] = {
86 { /* DataFlash chip */
87 .modalias = "mtd_dataflash",
88 .chip_select = 0,
89 .max_speed_hz = 15 * 1000 * 1000,
90 .bus_num = 0,
91 },
92};
93
94
95/*
96 * MCI (SD/MMC)
97 */
98static struct mci_platform_data __initdata mci0_data = {
99 .slot[0] = {
100 .bus_width = 4,
101 .detect_pin = AT91_PIN_PD10,
102 .wp_pin = -EINVAL,
103 },
104};
105
106static struct mci_platform_data __initdata mci1_data = {
107 .slot[0] = {
108 .bus_width = 4,
109 .detect_pin = AT91_PIN_PD11,
110 .wp_pin = AT91_PIN_PD29,
111 },
112};
113
114
115/*
116 * MACB Ethernet device
117 */
118static struct macb_platform_data __initdata ek_macb_data = {
119 .phy_irq_pin = AT91_PIN_PD5,
120 .is_rmii = 1,
121};
122
123
124/*
125 * NAND flash
126 */
127static struct mtd_partition __initdata ek_nand_partition[] = {
128 {
129 .name = "Partition 1",
130 .offset = 0,
131 .size = SZ_64M,
132 },
133 {
134 .name = "Partition 2",
135 .offset = MTDPART_OFS_NXTBLK,
136 .size = MTDPART_SIZ_FULL,
137 },
138};
139
140/* det_pin is not connected */
141static struct atmel_nand_data __initdata ek_nand_data = {
142 .ale = 21,
143 .cle = 22,
144 .rdy_pin = AT91_PIN_PC8,
145 .enable_pin = AT91_PIN_PC14,
146 .det_pin = -EINVAL,
147 .ecc_mode = NAND_ECC_SOFT,
148 .on_flash_bbt = 1,
149 .parts = ek_nand_partition,
150 .num_parts = ARRAY_SIZE(ek_nand_partition),
151};
152
153static struct sam9_smc_config __initdata ek_nand_smc_config = {
154 .ncs_read_setup = 0,
155 .nrd_setup = 2,
156 .ncs_write_setup = 0,
157 .nwe_setup = 2,
158
159 .ncs_read_pulse = 4,
160 .nrd_pulse = 4,
161 .ncs_write_pulse = 4,
162 .nwe_pulse = 4,
163
164 .read_cycle = 7,
165 .write_cycle = 7,
166
167 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE,
168 .tdf_cycles = 3,
169};
170
171static void __init ek_add_device_nand(void)
172{
173 ek_nand_data.bus_width_16 = board_have_nand_16bit();
174 /* setup bus-width (8 or 16) */
175 if (ek_nand_data.bus_width_16)
176 ek_nand_smc_config.mode |= AT91_SMC_DBW_16;
177 else
178 ek_nand_smc_config.mode |= AT91_SMC_DBW_8;
179
180 /* configure chip-select 3 (NAND) */
181 sam9_smc_configure(0, 3, &ek_nand_smc_config);
182
183 at91_add_device_nand(&ek_nand_data);
184}
185
186
187/*
188 * ISI
189 */
190static struct isi_platform_data __initdata isi_data = {
191 .frate = ISI_CFG1_FRATE_CAPTURE_ALL,
192 /* to use codec and preview path simultaneously */
193 .full_mode = 1,
194 .data_width_flags = ISI_DATAWIDTH_8 | ISI_DATAWIDTH_10,
195 /* ISI_MCK is provided by programmable clock or external clock */
196 .mck_hz = 25000000,
197};
198
199
200/*
201 * soc-camera OV2640
202 */
203#if defined(CONFIG_SOC_CAMERA_OV2640) || \
204 defined(CONFIG_SOC_CAMERA_OV2640_MODULE)
205static unsigned long isi_camera_query_bus_param(struct soc_camera_link *link)
206{
207 /* ISI board for ek using default 8-bits connection */
208 return SOCAM_DATAWIDTH_8;
209}
210
211static int i2c_camera_power(struct device *dev, int on)
212{
213 /* enable or disable the camera */
214 pr_debug("%s: %s the camera\n", __func__, on ? "ENABLE" : "DISABLE");
215 at91_set_gpio_output(AT91_PIN_PD13, !on);
216
217 if (!on)
218 goto out;
219
220 /* If enabled, give a reset impulse */
221 at91_set_gpio_output(AT91_PIN_PD12, 0);
222 msleep(20);
223 at91_set_gpio_output(AT91_PIN_PD12, 1);
224 msleep(100);
225
226out:
227 return 0;
228}
229
230static struct i2c_board_info i2c_camera = {
231 I2C_BOARD_INFO("ov2640", 0x30),
232};
233
234static struct soc_camera_link iclink_ov2640 = {
235 .bus_id = 0,
236 .board_info = &i2c_camera,
237 .i2c_adapter_id = 0,
238 .power = i2c_camera_power,
239 .query_bus_param = isi_camera_query_bus_param,
240};
241
242static struct platform_device isi_ov2640 = {
243 .name = "soc-camera-pdrv",
244 .id = 0,
245 .dev = {
246 .platform_data = &iclink_ov2640,
247 },
248};
249#endif
250
251
252/*
253 * LCD Controller
254 */
255#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
256static struct fb_videomode at91_tft_vga_modes[] = {
257 {
258 .name = "LG",
259 .refresh = 60,
260 .xres = 480, .yres = 272,
261 .pixclock = KHZ2PICOS(9000),
262
263 .left_margin = 1, .right_margin = 1,
264 .upper_margin = 40, .lower_margin = 1,
265 .hsync_len = 45, .vsync_len = 1,
266
267 .sync = 0,
268 .vmode = FB_VMODE_NONINTERLACED,
269 },
270};
271
272static struct fb_monspecs at91fb_default_monspecs = {
273 .manufacturer = "LG",
274 .monitor = "LB043WQ1",
275
276 .modedb = at91_tft_vga_modes,
277 .modedb_len = ARRAY_SIZE(at91_tft_vga_modes),
278 .hfmin = 15000,
279 .hfmax = 17640,
280 .vfmin = 57,
281 .vfmax = 67,
282};
283
284#define AT91SAM9G45_DEFAULT_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \
285 | ATMEL_LCDC_DISTYPE_TFT \
286 | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
287
288/* Driver datas */
289static struct atmel_lcdfb_pdata __initdata ek_lcdc_data = {
290 .lcdcon_is_backlight = true,
291 .default_bpp = 32,
292 .default_dmacon = ATMEL_LCDC_DMAEN,
293 .default_lcdcon2 = AT91SAM9G45_DEFAULT_LCDCON2,
294 .default_monspecs = &at91fb_default_monspecs,
295 .guard_time = 9,
296 .lcd_wiring_mode = ATMEL_LCDC_WIRING_RGB,
297};
298
299#else
300static struct atmel_lcdfb_pdata __initdata ek_lcdc_data;
301#endif
302
303
304/*
305 * ADCs and touchscreen
306 */
307static struct at91_adc_data ek_adc_data = {
308 .channels_used = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5) | BIT(6) | BIT(7),
309 .use_external_triggers = true,
310 .vref = 3300,
311 .touchscreen_type = ATMEL_ADC_TOUCHSCREEN_4WIRE,
312};
313
314/*
315 * GPIO Buttons
316 */
317#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
318static struct gpio_keys_button ek_buttons[] = {
319 { /* BP1, "leftclic" */
320 .code = BTN_LEFT,
321 .gpio = AT91_PIN_PB6,
322 .active_low = 1,
323 .desc = "left_click",
324 .wakeup = 1,
325 },
326 { /* BP2, "rightclic" */
327 .code = BTN_RIGHT,
328 .gpio = AT91_PIN_PB7,
329 .active_low = 1,
330 .desc = "right_click",
331 .wakeup = 1,
332 },
333 /* BP3, "joystick" */
334 {
335 .code = KEY_LEFT,
336 .gpio = AT91_PIN_PB14,
337 .active_low = 1,
338 .desc = "Joystick Left",
339 },
340 {
341 .code = KEY_RIGHT,
342 .gpio = AT91_PIN_PB15,
343 .active_low = 1,
344 .desc = "Joystick Right",
345 },
346 {
347 .code = KEY_UP,
348 .gpio = AT91_PIN_PB16,
349 .active_low = 1,
350 .desc = "Joystick Up",
351 },
352 {
353 .code = KEY_DOWN,
354 .gpio = AT91_PIN_PB17,
355 .active_low = 1,
356 .desc = "Joystick Down",
357 },
358 {
359 .code = KEY_ENTER,
360 .gpio = AT91_PIN_PB18,
361 .active_low = 1,
362 .desc = "Joystick Press",
363 },
364};
365
366static struct gpio_keys_platform_data ek_button_data = {
367 .buttons = ek_buttons,
368 .nbuttons = ARRAY_SIZE(ek_buttons),
369};
370
371static struct platform_device ek_button_device = {
372 .name = "gpio-keys",
373 .id = -1,
374 .num_resources = 0,
375 .dev = {
376 .platform_data = &ek_button_data,
377 }
378};
379
380static void __init ek_add_device_buttons(void)
381{
382 int i;
383
384 for (i = 0; i < ARRAY_SIZE(ek_buttons); i++) {
385 at91_set_GPIO_periph(ek_buttons[i].gpio, 1);
386 at91_set_deglitch(ek_buttons[i].gpio, 1);
387 }
388
389 platform_device_register(&ek_button_device);
390}
391#else
392static void __init ek_add_device_buttons(void) {}
393#endif
394
395
396/*
397 * AC97
398 * reset_pin is not connected: NRST
399 */
400static struct ac97c_platform_data ek_ac97_data = {
401 .reset_pin = -EINVAL,
402};
403
404
405/*
406 * LEDs ... these could all be PWM-driven, for variable brightness
407 */
408static struct gpio_led ek_leds[] = {
409 { /* "top" led, red, powerled */
410 .name = "d8",
411 .gpio = AT91_PIN_PD30,
412 .default_trigger = "heartbeat",
413 },
414 { /* "left" led, green, userled2, pwm3 */
415 .name = "d6",
416 .gpio = AT91_PIN_PD0,
417 .active_low = 1,
418 .default_trigger = "nand-disk",
419 },
420#if !IS_ENABLED(CONFIG_LEDS_PWM)
421 { /* "right" led, green, userled1, pwm1 */
422 .name = "d7",
423 .gpio = AT91_PIN_PD31,
424 .active_low = 1,
425 .default_trigger = "mmc0",
426 },
427#endif
428};
429
430
431/*
432 * PWM Leds
433 */
434static struct pwm_lookup pwm_lookup[] = {
435 PWM_LOOKUP("at91sam9rl-pwm", 1, "leds_pwm", "d7",
436 5000, PWM_POLARITY_INVERSED),
437};
438
439#if IS_ENABLED(CONFIG_LEDS_PWM)
440static struct led_pwm pwm_leds[] = {
441 { /* "right" led, green, userled1, pwm1 */
442 .name = "d7",
443 .max_brightness = 255,
444 },
445};
446
447static struct led_pwm_platform_data pwm_data = {
448 .num_leds = ARRAY_SIZE(pwm_leds),
449 .leds = pwm_leds,
450};
451
452static struct platform_device leds_pwm = {
453 .name = "leds_pwm",
454 .id = -1,
455 .dev = {
456 .platform_data = &pwm_data,
457 },
458};
459#endif
460
461static struct platform_device *devices[] __initdata = {
462#if defined(CONFIG_SOC_CAMERA_OV2640) || \
463 defined(CONFIG_SOC_CAMERA_OV2640_MODULE)
464 &isi_ov2640,
465#endif
466#if IS_ENABLED(CONFIG_LEDS_PWM)
467 &leds_pwm,
468#endif
469};
470
471static void __init ek_board_init(void)
472{
473 at91_register_devices();
474
475 /* Serial */
476 /* DGBU on ttyS0. (Rx & Tx only) */
477 at91_register_uart(0, 0, 0);
478
479 /* USART0 not connected on the -EK board */
480 /* USART1 on ttyS2. (Rx, Tx, RTS, CTS) */
481 at91_register_uart(AT91SAM9G45_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
482 at91_add_device_serial();
483 /* USB HS Host */
484 at91_add_device_usbh_ohci(&ek_usbh_hs_data);
485 at91_add_device_usbh_ehci(&ek_usbh_hs_data);
486 /* USB HS Device */
487 at91_add_device_usba(&ek_usba_udc_data);
488 /* SPI */
489 at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
490 /* MMC */
491 at91_add_device_mci(0, &mci0_data);
492 at91_add_device_mci(1, &mci1_data);
493 /* Ethernet */
494 at91_add_device_eth(&ek_macb_data);
495 /* NAND */
496 ek_add_device_nand();
497 /* I2C */
498 at91_add_device_i2c(0, NULL, 0);
499 /* ISI, using programmable clock as ISI_MCK */
500 at91_add_device_isi(&isi_data, true);
501 /* LCD Controller */
502 at91_add_device_lcdc(&ek_lcdc_data);
503 /* ADC and touchscreen */
504 at91_add_device_adc(&ek_adc_data);
505 /* Push Buttons */
506 ek_add_device_buttons();
507 /* AC97 */
508 at91_add_device_ac97(&ek_ac97_data);
509 /* LEDs */
510 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
511 pwm_add_table(pwm_lookup, ARRAY_SIZE(pwm_lookup));
512#if IS_ENABLED(CONFIG_LEDS_PWM)
513 at91_add_device_pwm(1 << AT91_PWM1);
514#endif
515 /* Other platform devices */
516 platform_add_devices(devices, ARRAY_SIZE(devices));
517}
518
519MACHINE_START(AT91SAM9M10G45EK, "Atmel AT91SAM9M10G45-EK")
520 /* Maintainer: Atmel */
521 .init_time = at91_init_time,
522 .map_io = at91_map_io,
523 .handle_irq = at91_aic_handle_irq,
524 .init_early = ek_init_early,
525 .init_irq = at91_init_irq_default,
526 .init_machine = ek_board_init,
527MACHINE_END
diff --git a/arch/arm/mach-at91/board-sam9rlek.c b/arch/arm/mach-at91/board-sam9rlek.c
deleted file mode 100644
index 8bca329b0293..000000000000
--- a/arch/arm/mach-at91/board-sam9rlek.c
+++ /dev/null
@@ -1,333 +0,0 @@
1/*
2 * Copyright (C) 2005 SAN People
3 * Copyright (C) 2007 Atmel Corporation
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file COPYING in the main directory of this archive for
7 * more details.
8 */
9
10#include <linux/types.h>
11#include <linux/gpio.h>
12#include <linux/init.h>
13#include <linux/mm.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/spi/spi.h>
17#include <linux/fb.h>
18#include <linux/clk.h>
19#include <linux/input.h>
20#include <linux/gpio_keys.h>
21#include <linux/platform_data/at91_adc.h>
22
23#include <video/atmel_lcdc.h>
24
25#include <asm/setup.h>
26#include <asm/mach-types.h>
27#include <asm/irq.h>
28
29#include <asm/mach/arch.h>
30#include <asm/mach/map.h>
31#include <asm/mach/irq.h>
32
33#include <mach/hardware.h>
34#include <mach/at91sam9_smc.h>
35
36
37#include "at91_aic.h"
38#include "board.h"
39#include "sam9_smc.h"
40#include "generic.h"
41#include "gpio.h"
42
43
44static void __init ek_init_early(void)
45{
46 /* Initialize processor: 12.000 MHz crystal */
47 at91_initialize(12000000);
48}
49
50/*
51 * USB HS Device port
52 */
53static struct usba_platform_data __initdata ek_usba_udc_data = {
54 .vbus_pin = AT91_PIN_PA8,
55};
56
57
58/*
59 * MCI (SD/MMC)
60 */
61static struct mci_platform_data __initdata mci0_data = {
62 .slot[0] = {
63 .bus_width = 4,
64 .detect_pin = AT91_PIN_PA15,
65 .wp_pin = -EINVAL,
66 },
67};
68
69
70/*
71 * NAND flash
72 */
73static struct mtd_partition __initdata ek_nand_partition[] = {
74 {
75 .name = "Partition 1",
76 .offset = 0,
77 .size = SZ_256K,
78 },
79 {
80 .name = "Partition 2",
81 .offset = MTDPART_OFS_NXTBLK,
82 .size = MTDPART_SIZ_FULL,
83 },
84};
85
86static struct atmel_nand_data __initdata ek_nand_data = {
87 .ale = 21,
88 .cle = 22,
89 .det_pin = -EINVAL,
90 .rdy_pin = AT91_PIN_PD17,
91 .enable_pin = AT91_PIN_PB6,
92 .ecc_mode = NAND_ECC_SOFT,
93 .on_flash_bbt = 1,
94 .parts = ek_nand_partition,
95 .num_parts = ARRAY_SIZE(ek_nand_partition),
96};
97
98static struct sam9_smc_config __initdata ek_nand_smc_config = {
99 .ncs_read_setup = 0,
100 .nrd_setup = 1,
101 .ncs_write_setup = 0,
102 .nwe_setup = 1,
103
104 .ncs_read_pulse = 3,
105 .nrd_pulse = 3,
106 .ncs_write_pulse = 3,
107 .nwe_pulse = 3,
108
109 .read_cycle = 5,
110 .write_cycle = 5,
111
112 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
113 .tdf_cycles = 2,
114};
115
116static void __init ek_add_device_nand(void)
117{
118 /* configure chip-select 3 (NAND) */
119 sam9_smc_configure(0, 3, &ek_nand_smc_config);
120
121 at91_add_device_nand(&ek_nand_data);
122}
123
124
125/*
126 * SPI devices
127 */
128static struct spi_board_info ek_spi_devices[] = {
129 { /* DataFlash chip */
130 .modalias = "mtd_dataflash",
131 .chip_select = 0,
132 .max_speed_hz = 15 * 1000 * 1000,
133 .bus_num = 0,
134 },
135};
136
137
138/*
139 * LCD Controller
140 */
141#if defined(CONFIG_FB_ATMEL) || defined(CONFIG_FB_ATMEL_MODULE)
142static struct fb_videomode at91_tft_vga_modes[] = {
143 {
144 .name = "TX09D50VM1CCA @ 60",
145 .refresh = 60,
146 .xres = 240, .yres = 320,
147 .pixclock = KHZ2PICOS(4965),
148
149 .left_margin = 1, .right_margin = 33,
150 .upper_margin = 1, .lower_margin = 0,
151 .hsync_len = 5, .vsync_len = 1,
152
153 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
154 .vmode = FB_VMODE_NONINTERLACED,
155 },
156};
157
158static struct fb_monspecs at91fb_default_monspecs = {
159 .manufacturer = "HIT",
160 .monitor = "TX09D50VM1CCA",
161
162 .modedb = at91_tft_vga_modes,
163 .modedb_len = ARRAY_SIZE(at91_tft_vga_modes),
164 .hfmin = 15000,
165 .hfmax = 64000,
166 .vfmin = 50,
167 .vfmax = 150,
168};
169
170#define AT91SAM9RL_DEFAULT_LCDCON2 (ATMEL_LCDC_MEMOR_LITTLE \
171 | ATMEL_LCDC_DISTYPE_TFT \
172 | ATMEL_LCDC_CLKMOD_ALWAYSACTIVE)
173
174static void at91_lcdc_power_control(struct atmel_lcdfb_pdata *pdata, int on)
175{
176 if (on)
177 at91_set_gpio_value(AT91_PIN_PC1, 0); /* power up */
178 else
179 at91_set_gpio_value(AT91_PIN_PC1, 1); /* power down */
180}
181
182/* Driver datas */
183static struct atmel_lcdfb_pdata __initdata ek_lcdc_data = {
184 .lcdcon_is_backlight = true,
185 .default_bpp = 16,
186 .default_dmacon = ATMEL_LCDC_DMAEN,
187 .default_lcdcon2 = AT91SAM9RL_DEFAULT_LCDCON2,
188 .default_monspecs = &at91fb_default_monspecs,
189 .atmel_lcdfb_power_control = at91_lcdc_power_control,
190 .guard_time = 1,
191 .lcd_wiring_mode = ATMEL_LCDC_WIRING_RGB,
192};
193
194#else
195static struct atmel_lcdfb_pdata __initdata ek_lcdc_data;
196#endif
197
198
199/*
200 * AC97
201 * reset_pin is not connected: NRST
202 */
203static struct ac97c_platform_data ek_ac97_data = {
204 .reset_pin = -EINVAL,
205};
206
207
208/*
209 * LEDs
210 */
211static struct gpio_led ek_leds[] = {
212 { /* "bottom" led, green, userled1 to be defined */
213 .name = "ds1",
214 .gpio = AT91_PIN_PD15,
215 .active_low = 1,
216 .default_trigger = "none",
217 },
218 { /* "bottom" led, green, userled2 to be defined */
219 .name = "ds2",
220 .gpio = AT91_PIN_PD16,
221 .active_low = 1,
222 .default_trigger = "none",
223 },
224 { /* "power" led, yellow */
225 .name = "ds3",
226 .gpio = AT91_PIN_PD14,
227 .default_trigger = "heartbeat",
228 }
229};
230
231
232/*
233 * ADC + Touchscreen
234 */
235static struct at91_adc_data ek_adc_data = {
236 .channels_used = BIT(0) | BIT(1) | BIT(2) | BIT(3) | BIT(4) | BIT(5),
237 .use_external_triggers = true,
238 .vref = 3300,
239 .touchscreen_type = ATMEL_ADC_TOUCHSCREEN_4WIRE,
240};
241
242
243/*
244 * GPIO Buttons
245 */
246#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
247static struct gpio_keys_button ek_buttons[] = {
248 {
249 .gpio = AT91_PIN_PB0,
250 .code = BTN_2,
251 .desc = "Right Click",
252 .active_low = 1,
253 .wakeup = 1,
254 },
255 {
256 .gpio = AT91_PIN_PB1,
257 .code = BTN_1,
258 .desc = "Left Click",
259 .active_low = 1,
260 .wakeup = 1,
261 }
262};
263
264static struct gpio_keys_platform_data ek_button_data = {
265 .buttons = ek_buttons,
266 .nbuttons = ARRAY_SIZE(ek_buttons),
267};
268
269static struct platform_device ek_button_device = {
270 .name = "gpio-keys",
271 .id = -1,
272 .num_resources = 0,
273 .dev = {
274 .platform_data = &ek_button_data,
275 }
276};
277
278static void __init ek_add_device_buttons(void)
279{
280 at91_set_gpio_input(AT91_PIN_PB1, 1); /* btn1 */
281 at91_set_deglitch(AT91_PIN_PB1, 1);
282 at91_set_gpio_input(AT91_PIN_PB0, 1); /* btn2 */
283 at91_set_deglitch(AT91_PIN_PB0, 1);
284
285 platform_device_register(&ek_button_device);
286}
287#else
288static void __init ek_add_device_buttons(void) {}
289#endif
290
291
292static void __init ek_board_init(void)
293{
294 at91_register_devices();
295
296 /* Serial */
297 /* DBGU on ttyS0. (Rx & Tx only) */
298 at91_register_uart(0, 0, 0);
299
300 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS) */
301 at91_register_uart(AT91SAM9RL_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS);
302 at91_add_device_serial();
303 /* USB HS */
304 at91_add_device_usba(&ek_usba_udc_data);
305 /* I2C */
306 at91_add_device_i2c(NULL, 0);
307 /* NAND */
308 ek_add_device_nand();
309 /* SPI */
310 at91_add_device_spi(ek_spi_devices, ARRAY_SIZE(ek_spi_devices));
311 /* MMC */
312 at91_add_device_mci(0, &mci0_data);
313 /* LCD Controller */
314 at91_add_device_lcdc(&ek_lcdc_data);
315 /* AC97 */
316 at91_add_device_ac97(&ek_ac97_data);
317 /* Touch Screen Controller + ADC */
318 at91_add_device_adc(&ek_adc_data);
319 /* LEDs */
320 at91_gpio_leds(ek_leds, ARRAY_SIZE(ek_leds));
321 /* Push Buttons */
322 ek_add_device_buttons();
323}
324
325MACHINE_START(AT91SAM9RLEK, "Atmel AT91SAM9RL-EK")
326 /* Maintainer: Atmel */
327 .init_time = at91_init_time,
328 .map_io = at91_map_io,
329 .handle_irq = at91_aic_handle_irq,
330 .init_early = ek_init_early,
331 .init_irq = at91_init_irq_default,
332 .init_machine = ek_board_init,
333MACHINE_END
diff --git a/arch/arm/mach-at91/board-snapper9260.c b/arch/arm/mach-at91/board-snapper9260.c
deleted file mode 100644
index b4aff840a1a0..000000000000
--- a/arch/arm/mach-at91/board-snapper9260.c
+++ /dev/null
@@ -1,191 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-snapper9260.c
3 *
4 * Copyright (C) 2010 Bluewater System Ltd
5 *
6 * Author: Andre Renaud <andre@bluewatersys.com>
7 * Author: Ryan Mallon
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include <linux/init.h>
26#include <linux/gpio.h>
27#include <linux/platform_device.h>
28#include <linux/spi/spi.h>
29#include <linux/platform_data/pca953x.h>
30
31#include <asm/mach-types.h>
32#include <asm/mach/arch.h>
33
34#include <mach/hardware.h>
35#include <mach/at91sam9_smc.h>
36
37#include "at91_aic.h"
38#include "board.h"
39#include "sam9_smc.h"
40#include "generic.h"
41#include "gpio.h"
42
43#define SNAPPER9260_IO_EXP_GPIO(x) (NR_BUILTIN_GPIO + (x))
44
45static void __init snapper9260_init_early(void)
46{
47 at91_initialize(18432000);
48}
49
50static struct at91_usbh_data __initdata snapper9260_usbh_data = {
51 .ports = 2,
52 .vbus_pin = {-EINVAL, -EINVAL},
53 .overcurrent_pin= {-EINVAL, -EINVAL},
54};
55
56static struct at91_udc_data __initdata snapper9260_udc_data = {
57 .vbus_pin = SNAPPER9260_IO_EXP_GPIO(5),
58 .vbus_active_low = 1,
59 .vbus_polled = 1,
60 .pullup_pin = -EINVAL,
61};
62
63static struct macb_platform_data snapper9260_macb_data = {
64 .phy_irq_pin = -EINVAL,
65 .is_rmii = 1,
66};
67
68static struct mtd_partition __initdata snapper9260_nand_partitions[] = {
69 {
70 .name = "Preboot",
71 .offset = 0,
72 .size = SZ_128K,
73 },
74 {
75 .name = "Bootloader",
76 .offset = MTDPART_OFS_APPEND,
77 .size = SZ_256K,
78 },
79 {
80 .name = "Environment",
81 .offset = MTDPART_OFS_APPEND,
82 .size = SZ_128K,
83 },
84 {
85 .name = "Kernel",
86 .offset = MTDPART_OFS_APPEND,
87 .size = SZ_4M,
88 },
89 {
90 .name = "Filesystem",
91 .offset = MTDPART_OFS_APPEND,
92 .size = MTDPART_SIZ_FULL,
93 },
94};
95
96static struct atmel_nand_data __initdata snapper9260_nand_data = {
97 .ale = 21,
98 .cle = 22,
99 .rdy_pin = AT91_PIN_PC13,
100 .parts = snapper9260_nand_partitions,
101 .num_parts = ARRAY_SIZE(snapper9260_nand_partitions),
102 .bus_width_16 = 0,
103 .enable_pin = -EINVAL,
104 .det_pin = -EINVAL,
105 .ecc_mode = NAND_ECC_SOFT,
106};
107
108static struct sam9_smc_config __initdata snapper9260_nand_smc_config = {
109 .ncs_read_setup = 0,
110 .nrd_setup = 0,
111 .ncs_write_setup = 0,
112 .nwe_setup = 0,
113
114 .ncs_read_pulse = 5,
115 .nrd_pulse = 2,
116 .ncs_write_pulse = 5,
117 .nwe_pulse = 2,
118
119 .read_cycle = 7,
120 .write_cycle = 7,
121
122 .mode = (AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
123 AT91_SMC_EXNWMODE_DISABLE),
124 .tdf_cycles = 1,
125};
126
127static struct pca953x_platform_data snapper9260_io_expander_data = {
128 .gpio_base = SNAPPER9260_IO_EXP_GPIO(0),
129};
130
131static struct i2c_board_info __initdata snapper9260_i2c_devices[] = {
132 {
133 /* IO expander */
134 I2C_BOARD_INFO("max7312", 0x28),
135 .platform_data = &snapper9260_io_expander_data,
136 },
137 {
138 /* Audio codec */
139 I2C_BOARD_INFO("tlv320aic23", 0x1a),
140 },
141};
142
143static struct i2c_board_info __initdata snapper9260_i2c_isl1208 = {
144 /* RTC */
145 I2C_BOARD_INFO("isl1208", 0x6f),
146};
147
148static void __init snapper9260_add_device_nand(void)
149{
150 at91_set_A_periph(AT91_PIN_PC14, 0);
151 sam9_smc_configure(0, 3, &snapper9260_nand_smc_config);
152 at91_add_device_nand(&snapper9260_nand_data);
153}
154
155static void __init snapper9260_board_init(void)
156{
157 at91_register_devices();
158
159 at91_add_device_i2c(snapper9260_i2c_devices,
160 ARRAY_SIZE(snapper9260_i2c_devices));
161
162 snapper9260_i2c_isl1208.irq = gpio_to_irq(AT91_PIN_PA31);
163 i2c_register_board_info(0, &snapper9260_i2c_isl1208, 1);
164
165 /* Debug on ttyS0 */
166 at91_register_uart(0, 0, 0);
167
168 at91_register_uart(AT91SAM9260_ID_US0, 1,
169 ATMEL_UART_CTS | ATMEL_UART_RTS);
170 at91_register_uart(AT91SAM9260_ID_US1, 2,
171 ATMEL_UART_CTS | ATMEL_UART_RTS);
172 at91_register_uart(AT91SAM9260_ID_US2, 3, 0);
173 at91_add_device_serial();
174 at91_add_device_usbh(&snapper9260_usbh_data);
175 at91_add_device_udc(&snapper9260_udc_data);
176 at91_add_device_eth(&snapper9260_macb_data);
177 at91_add_device_ssc(AT91SAM9260_ID_SSC, (ATMEL_SSC_TF | ATMEL_SSC_TK |
178 ATMEL_SSC_TD | ATMEL_SSC_RD));
179 snapper9260_add_device_nand();
180}
181
182MACHINE_START(SNAPPER_9260, "Bluewater Systems Snapper 9260/9G20 module")
183 .init_time = at91_init_time,
184 .map_io = at91_map_io,
185 .handle_irq = at91_aic_handle_irq,
186 .init_early = snapper9260_init_early,
187 .init_irq = at91_init_irq_default,
188 .init_machine = snapper9260_board_init,
189MACHINE_END
190
191
diff --git a/arch/arm/mach-at91/board-stamp9g20.c b/arch/arm/mach-at91/board-stamp9g20.c
deleted file mode 100644
index e825641a1dee..000000000000
--- a/arch/arm/mach-at91/board-stamp9g20.c
+++ /dev/null
@@ -1,294 +0,0 @@
1/*
2 * Copyright (C) 2010 Christian Glindkamp <christian.glindkamp@taskit.de>
3 * taskit GmbH
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/mm.h>
21#include <linux/platform_device.h>
22#include <linux/gpio.h>
23#include <linux/w1-gpio.h>
24
25#include <asm/mach-types.h>
26#include <asm/mach/arch.h>
27
28#include <mach/at91sam9_smc.h>
29#include <mach/hardware.h>
30
31#include "at91_aic.h"
32#include "board.h"
33#include "sam9_smc.h"
34#include "generic.h"
35#include "gpio.h"
36
37
38void __init stamp9g20_init_early(void)
39{
40 /* Initialize processor: 18.432 MHz crystal */
41 at91_initialize(18432000);
42}
43
44/*
45 * NAND flash
46 */
47static struct atmel_nand_data __initdata nand_data = {
48 .ale = 21,
49 .cle = 22,
50 .rdy_pin = AT91_PIN_PC13,
51 .enable_pin = AT91_PIN_PC14,
52 .bus_width_16 = 0,
53 .det_pin = -EINVAL,
54 .ecc_mode = NAND_ECC_SOFT,
55};
56
57static struct sam9_smc_config __initdata nand_smc_config = {
58 .ncs_read_setup = 0,
59 .nrd_setup = 2,
60 .ncs_write_setup = 0,
61 .nwe_setup = 2,
62
63 .ncs_read_pulse = 4,
64 .nrd_pulse = 4,
65 .ncs_write_pulse = 4,
66 .nwe_pulse = 4,
67
68 .read_cycle = 7,
69 .write_cycle = 7,
70
71 .mode = AT91_SMC_READMODE | AT91_SMC_WRITEMODE | AT91_SMC_EXNWMODE_DISABLE | AT91_SMC_DBW_8,
72 .tdf_cycles = 3,
73};
74
75static void __init add_device_nand(void)
76{
77 /* configure chip-select 3 (NAND) */
78 sam9_smc_configure(0, 3, &nand_smc_config);
79
80 at91_add_device_nand(&nand_data);
81}
82
83
84/*
85 * MCI (SD/MMC)
86 * det_pin, wp_pin and vcc_pin are not connected
87 */
88static struct mci_platform_data __initdata mmc_data = {
89 .slot[0] = {
90 .bus_width = 4,
91 .detect_pin = -1,
92 .wp_pin = -1,
93 },
94};
95
96
97/*
98 * USB Host port
99 */
100static struct at91_usbh_data __initdata usbh_data = {
101 .ports = 2,
102 .vbus_pin = {-EINVAL, -EINVAL},
103 .overcurrent_pin= {-EINVAL, -EINVAL},
104};
105
106
107/*
108 * USB Device port
109 */
110static struct at91_udc_data __initdata portuxg20_udc_data = {
111 .vbus_pin = AT91_PIN_PC7,
112 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
113};
114
115static struct at91_udc_data __initdata stamp9g20evb_udc_data = {
116 .vbus_pin = AT91_PIN_PA22,
117 .pullup_pin = -EINVAL, /* pull-up driven by UDC */
118};
119
120
121/*
122 * MACB Ethernet device
123 */
124static struct macb_platform_data __initdata macb_data = {
125 .phy_irq_pin = AT91_PIN_PA28,
126 .is_rmii = 1,
127};
128
129
130/*
131 * LEDs
132 */
133static struct gpio_led portuxg20_leds[] = {
134 {
135 .name = "LED2",
136 .gpio = AT91_PIN_PC5,
137 .default_trigger = "none",
138 }, {
139 .name = "LED3",
140 .gpio = AT91_PIN_PC4,
141 .default_trigger = "none",
142 }, {
143 .name = "LED4",
144 .gpio = AT91_PIN_PC10,
145 .default_trigger = "heartbeat",
146 }
147};
148
149static struct gpio_led stamp9g20evb_leds[] = {
150 {
151 .name = "D8",
152 .gpio = AT91_PIN_PB18,
153 .active_low = 1,
154 .default_trigger = "none",
155 }, {
156 .name = "D9",
157 .gpio = AT91_PIN_PB19,
158 .active_low = 1,
159 .default_trigger = "none",
160 }, {
161 .name = "D10",
162 .gpio = AT91_PIN_PB20,
163 .active_low = 1,
164 .default_trigger = "heartbeat",
165 }
166};
167
168
169/*
170 * SPI devices
171 */
172static struct spi_board_info portuxg20_spi_devices[] = {
173 {
174 .modalias = "spidev",
175 .chip_select = 0,
176 .max_speed_hz = 1 * 1000 * 1000,
177 .bus_num = 0,
178 }, {
179 .modalias = "spidev",
180 .chip_select = 0,
181 .max_speed_hz = 1 * 1000 * 1000,
182 .bus_num = 1,
183 },
184};
185
186
187/*
188 * Dallas 1-Wire
189 */
190static struct w1_gpio_platform_data w1_gpio_pdata = {
191 .pin = AT91_PIN_PA29,
192 .is_open_drain = 1,
193 .ext_pullup_enable_pin = -EINVAL,
194};
195
196static struct platform_device w1_device = {
197 .name = "w1-gpio",
198 .id = -1,
199 .dev.platform_data = &w1_gpio_pdata,
200};
201
202void add_w1(void)
203{
204 at91_set_GPIO_periph(w1_gpio_pdata.pin, 1);
205 at91_set_multi_drive(w1_gpio_pdata.pin, 1);
206 platform_device_register(&w1_device);
207}
208
209
210void __init stamp9g20_board_init(void)
211{
212 /* Serial */
213 /* DGBU on ttyS0. (Rx & Tx only) */
214 at91_register_uart(0, 0, 0);
215 at91_add_device_serial();
216 /* NAND */
217 add_device_nand();
218 /* MMC */
219 at91_add_device_mci(0, &mmc_data);
220 /* W1 */
221 add_w1();
222}
223
224static void __init portuxg20_board_init(void)
225{
226 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
227 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
228 | ATMEL_UART_DTR | ATMEL_UART_DSR
229 | ATMEL_UART_DCD | ATMEL_UART_RI);
230
231 /* USART1 on ttyS2. (Rx, Tx, CTS, RTS) */
232 at91_register_uart(AT91SAM9260_ID_US1, 2, ATMEL_UART_CTS | ATMEL_UART_RTS);
233
234 /* USART2 on ttyS3. (Rx, Tx, CTS, RTS) */
235 at91_register_uart(AT91SAM9260_ID_US2, 3, ATMEL_UART_CTS | ATMEL_UART_RTS);
236
237 /* USART4 on ttyS5. (Rx, Tx only) */
238 at91_register_uart(AT91SAM9260_ID_US4, 5, 0);
239
240 /* USART5 on ttyS6. (Rx, Tx only) */
241 at91_register_uart(AT91SAM9260_ID_US5, 6, 0);
242 stamp9g20_board_init();
243 /* USB Host */
244 at91_add_device_usbh(&usbh_data);
245 /* USB Device */
246 at91_add_device_udc(&portuxg20_udc_data);
247 /* Ethernet */
248 at91_add_device_eth(&macb_data);
249 /* I2C */
250 at91_add_device_i2c(NULL, 0);
251 /* SPI */
252 at91_add_device_spi(portuxg20_spi_devices, ARRAY_SIZE(portuxg20_spi_devices));
253 /* LEDs */
254 at91_gpio_leds(portuxg20_leds, ARRAY_SIZE(portuxg20_leds));
255}
256
257static void __init stamp9g20evb_board_init(void)
258{
259 /* USART0 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
260 at91_register_uart(AT91SAM9260_ID_US0, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
261 | ATMEL_UART_DTR | ATMEL_UART_DSR
262 | ATMEL_UART_DCD | ATMEL_UART_RI);
263 stamp9g20_board_init();
264 /* USB Host */
265 at91_add_device_usbh(&usbh_data);
266 /* USB Device */
267 at91_add_device_udc(&stamp9g20evb_udc_data);
268 /* Ethernet */
269 at91_add_device_eth(&macb_data);
270 /* I2C */
271 at91_add_device_i2c(NULL, 0);
272 /* LEDs */
273 at91_gpio_leds(stamp9g20evb_leds, ARRAY_SIZE(stamp9g20evb_leds));
274}
275
276MACHINE_START(PORTUXG20, "taskit PortuxG20")
277 /* Maintainer: taskit GmbH */
278 .init_time = at91_init_time,
279 .map_io = at91_map_io,
280 .handle_irq = at91_aic_handle_irq,
281 .init_early = stamp9g20_init_early,
282 .init_irq = at91_init_irq_default,
283 .init_machine = portuxg20_board_init,
284MACHINE_END
285
286MACHINE_START(STAMP9G20, "taskit Stamp9G20")
287 /* Maintainer: taskit GmbH */
288 .init_time = at91_init_time,
289 .map_io = at91_map_io,
290 .handle_irq = at91_aic_handle_irq,
291 .init_early = stamp9g20_init_early,
292 .init_irq = at91_init_irq_default,
293 .init_machine = stamp9g20evb_board_init,
294MACHINE_END
diff --git a/arch/arm/mach-at91/board-yl-9200.c b/arch/arm/mach-at91/board-yl-9200.c
deleted file mode 100644
index 46fdb0c68a68..000000000000
--- a/arch/arm/mach-at91/board-yl-9200.c
+++ /dev/null
@@ -1,597 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/board-yl-9200.c
3 *
4 * Adapted from various board files in arch/arm/mach-at91
5 *
6 * Modifications for YL-9200 platform:
7 * Copyright (C) 2007 S. Birtles
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include <linux/types.h>
25#include <linux/gpio.h>
26#include <linux/init.h>
27#include <linux/mm.h>
28#include <linux/module.h>
29#include <linux/dma-mapping.h>
30#include <linux/platform_device.h>
31#include <linux/spi/spi.h>
32#include <linux/spi/ads7846.h>
33#include <linux/mtd/physmap.h>
34#include <linux/gpio_keys.h>
35#include <linux/input.h>
36
37#include <asm/setup.h>
38#include <asm/mach-types.h>
39#include <asm/irq.h>
40
41#include <asm/mach/arch.h>
42#include <asm/mach/map.h>
43#include <asm/mach/irq.h>
44
45#include <mach/hardware.h>
46#include <mach/at91rm9200_mc.h>
47#include <mach/at91_ramc.h>
48#include <mach/cpu.h>
49
50#include "at91_aic.h"
51#include "board.h"
52#include "generic.h"
53#include "gpio.h"
54
55
56static void __init yl9200_init_early(void)
57{
58 /* Set cpu type: PQFP */
59 at91rm9200_set_type(ARCH_REVISON_9200_PQFP);
60
61 /* Initialize processor: 18.432 MHz crystal */
62 at91_initialize(18432000);
63}
64
65/*
66 * LEDs
67 */
68static struct gpio_led yl9200_leds[] = {
69 { /* D2 */
70 .name = "led2",
71 .gpio = AT91_PIN_PB17,
72 .active_low = 1,
73 .default_trigger = "timer",
74 },
75 { /* D3 */
76 .name = "led3",
77 .gpio = AT91_PIN_PB16,
78 .active_low = 1,
79 .default_trigger = "heartbeat",
80 },
81 { /* D4 */
82 .name = "led4",
83 .gpio = AT91_PIN_PB15,
84 .active_low = 1,
85 },
86 { /* D5 */
87 .name = "led5",
88 .gpio = AT91_PIN_PB8,
89 .active_low = 1,
90 }
91};
92
93/*
94 * Ethernet
95 */
96static struct macb_platform_data __initdata yl9200_eth_data = {
97 .phy_irq_pin = AT91_PIN_PB28,
98 .is_rmii = 1,
99};
100
101/*
102 * USB Host
103 */
104static struct at91_usbh_data __initdata yl9200_usbh_data = {
105 .ports = 1, /* PQFP version of AT91RM9200 */
106 .vbus_pin = {-EINVAL, -EINVAL},
107 .overcurrent_pin= {-EINVAL, -EINVAL},
108};
109
110/*
111 * USB Device
112 */
113static struct at91_udc_data __initdata yl9200_udc_data = {
114 .pullup_pin = AT91_PIN_PC4,
115 .vbus_pin = AT91_PIN_PC5,
116 .pullup_active_low = 1, /* Active Low due to PNP transistor (pg 7) */
117
118};
119
120/*
121 * MMC
122 */
123static struct mci_platform_data __initdata yl9200_mci0_data = {
124 .slot[0] = {
125 .bus_width = 4,
126 .detect_pin = AT91_PIN_PB9,
127 .wp_pin = -EINVAL,
128 },
129};
130
131/*
132 * NAND Flash
133 */
134static struct mtd_partition __initdata yl9200_nand_partition[] = {
135 {
136 .name = "AT91 NAND partition 1, boot",
137 .offset = 0,
138 .size = SZ_256K
139 },
140 {
141 .name = "AT91 NAND partition 2, kernel",
142 .offset = MTDPART_OFS_NXTBLK,
143 .size = (2 * SZ_1M) - SZ_256K
144 },
145 {
146 .name = "AT91 NAND partition 3, filesystem",
147 .offset = MTDPART_OFS_NXTBLK,
148 .size = 14 * SZ_1M
149 },
150 {
151 .name = "AT91 NAND partition 4, storage",
152 .offset = MTDPART_OFS_NXTBLK,
153 .size = SZ_16M
154 },
155 {
156 .name = "AT91 NAND partition 5, ext-fs",
157 .offset = MTDPART_OFS_NXTBLK,
158 .size = SZ_32M
159 }
160};
161
162static struct atmel_nand_data __initdata yl9200_nand_data = {
163 .ale = 6,
164 .cle = 7,
165 .det_pin = -EINVAL,
166 .rdy_pin = AT91_PIN_PC14, /* R/!B (Sheet10) */
167 .enable_pin = AT91_PIN_PC15, /* !CE (Sheet10) */
168 .ecc_mode = NAND_ECC_SOFT,
169 .parts = yl9200_nand_partition,
170 .num_parts = ARRAY_SIZE(yl9200_nand_partition),
171};
172
173/*
174 * NOR Flash
175 */
176#define YL9200_FLASH_BASE AT91_CHIPSELECT_0
177#define YL9200_FLASH_SIZE SZ_16M
178
179static struct mtd_partition yl9200_flash_partitions[] = {
180 {
181 .name = "Bootloader",
182 .offset = 0,
183 .size = SZ_256K,
184 .mask_flags = MTD_WRITEABLE, /* force read-only */
185 },
186 {
187 .name = "Kernel",
188 .offset = MTDPART_OFS_NXTBLK,
189 .size = (2 * SZ_1M) - SZ_256K
190 },
191 {
192 .name = "Filesystem",
193 .offset = MTDPART_OFS_NXTBLK,
194 .size = MTDPART_SIZ_FULL
195 }
196};
197
198static struct physmap_flash_data yl9200_flash_data = {
199 .width = 2,
200 .parts = yl9200_flash_partitions,
201 .nr_parts = ARRAY_SIZE(yl9200_flash_partitions),
202};
203
204static struct resource yl9200_flash_resources[] = {
205 {
206 .start = YL9200_FLASH_BASE,
207 .end = YL9200_FLASH_BASE + YL9200_FLASH_SIZE - 1,
208 .flags = IORESOURCE_MEM,
209 }
210};
211
212static struct platform_device yl9200_flash = {
213 .name = "physmap-flash",
214 .id = 0,
215 .dev = {
216 .platform_data = &yl9200_flash_data,
217 },
218 .resource = yl9200_flash_resources,
219 .num_resources = ARRAY_SIZE(yl9200_flash_resources),
220};
221
222/*
223 * I2C (TWI)
224 */
225static struct i2c_board_info __initdata yl9200_i2c_devices[] = {
226 { /* EEPROM */
227 I2C_BOARD_INFO("24c128", 0x50),
228 }
229};
230
231/*
232 * GPIO Buttons
233*/
234#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
235static struct gpio_keys_button yl9200_buttons[] = {
236 {
237 .gpio = AT91_PIN_PA24,
238 .code = BTN_2,
239 .desc = "SW2",
240 .active_low = 1,
241 .wakeup = 1,
242 },
243 {
244 .gpio = AT91_PIN_PB1,
245 .code = BTN_3,
246 .desc = "SW3",
247 .active_low = 1,
248 .wakeup = 1,
249 },
250 {
251 .gpio = AT91_PIN_PB2,
252 .code = BTN_4,
253 .desc = "SW4",
254 .active_low = 1,
255 .wakeup = 1,
256 },
257 {
258 .gpio = AT91_PIN_PB6,
259 .code = BTN_5,
260 .desc = "SW5",
261 .active_low = 1,
262 .wakeup = 1,
263 }
264};
265
266static struct gpio_keys_platform_data yl9200_button_data = {
267 .buttons = yl9200_buttons,
268 .nbuttons = ARRAY_SIZE(yl9200_buttons),
269};
270
271static struct platform_device yl9200_button_device = {
272 .name = "gpio-keys",
273 .id = -1,
274 .num_resources = 0,
275 .dev = {
276 .platform_data = &yl9200_button_data,
277 }
278};
279
280static void __init yl9200_add_device_buttons(void)
281{
282 at91_set_gpio_input(AT91_PIN_PA24, 1); /* SW2 */
283 at91_set_deglitch(AT91_PIN_PA24, 1);
284 at91_set_gpio_input(AT91_PIN_PB1, 1); /* SW3 */
285 at91_set_deglitch(AT91_PIN_PB1, 1);
286 at91_set_gpio_input(AT91_PIN_PB2, 1); /* SW4 */
287 at91_set_deglitch(AT91_PIN_PB2, 1);
288 at91_set_gpio_input(AT91_PIN_PB6, 1); /* SW5 */
289 at91_set_deglitch(AT91_PIN_PB6, 1);
290
291 /* Enable buttons (Sheet 5) */
292 at91_set_gpio_output(AT91_PIN_PB7, 1);
293
294 platform_device_register(&yl9200_button_device);
295}
296#else
297static void __init yl9200_add_device_buttons(void) {}
298#endif
299
300/*
301 * Touchscreen
302 */
303#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
304static int ads7843_pendown_state(void)
305{
306 return !at91_get_gpio_value(AT91_PIN_PB11); /* Touchscreen PENIRQ */
307}
308
309static struct ads7846_platform_data ads_info = {
310 .model = 7843,
311 .x_min = 150,
312 .x_max = 3830,
313 .y_min = 190,
314 .y_max = 3830,
315 .vref_delay_usecs = 100,
316
317 /* For a 8" touch-screen */
318 // .x_plate_ohms = 603,
319 // .y_plate_ohms = 332,
320
321 /* For a 10.4" touch-screen */
322 // .x_plate_ohms = 611,
323 // .y_plate_ohms = 325,
324
325 .x_plate_ohms = 576,
326 .y_plate_ohms = 366,
327
328 .pressure_max = 15000, /* generally nonsense on the 7843 */
329 .debounce_max = 1,
330 .debounce_rep = 0,
331 .debounce_tol = (~0),
332 .get_pendown_state = ads7843_pendown_state,
333};
334
335static void __init yl9200_add_device_ts(void)
336{
337 at91_set_gpio_input(AT91_PIN_PB11, 1); /* Touchscreen interrupt pin */
338 at91_set_gpio_input(AT91_PIN_PB10, 1); /* Touchscreen BUSY signal - not used! */
339}
340#else
341static void __init yl9200_add_device_ts(void) {}
342#endif
343
344/*
345 * SPI devices
346 */
347static struct spi_board_info yl9200_spi_devices[] = {
348#if defined(CONFIG_TOUCHSCREEN_ADS7846) || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
349 { /* Touchscreen */
350 .modalias = "ads7846",
351 .chip_select = 0,
352 .max_speed_hz = 5000 * 26,
353 .platform_data = &ads_info,
354 .irq = AT91_PIN_PB11,
355 },
356#endif
357 { /* CAN */
358 .modalias = "mcp2510",
359 .chip_select = 1,
360 .max_speed_hz = 25000 * 26,
361 .irq = AT91_PIN_PC0,
362 }
363};
364
365/*
366 * LCD / VGA
367 *
368 * EPSON S1D13806 FB (discontinued chip)
369 * EPSON S1D13506 FB
370 */
371#if defined(CONFIG_FB_S1D13XXX) || defined(CONFIG_FB_S1D13XXX_MODULE)
372#include <video/s1d13xxxfb.h>
373
374
375static void yl9200_init_video(void)
376{
377 /* NWAIT Signal */
378 at91_set_A_periph(AT91_PIN_PC6, 0);
379
380 /* Initialization of the Static Memory Controller for Chip Select 2 */
381 at91_ramc_write(0, AT91_SMC_CSR(2), AT91_SMC_DBW_16 /* 16 bit */
382 | AT91_SMC_WSEN | AT91_SMC_NWS_(0x4) /* wait states */
383 | AT91_SMC_TDF_(0x100) /* float time */
384 );
385}
386
387static struct s1d13xxxfb_regval yl9200_s1dfb_initregs[] =
388{
389 {S1DREG_MISC, 0x00}, /* Miscellaneous Register*/
390 {S1DREG_COM_DISP_MODE, 0x01}, /* Display Mode Register, LCD only*/
391 {S1DREG_GPIO_CNF0, 0x00}, /* General IO Pins Configuration Register*/
392 {S1DREG_GPIO_CTL0, 0x00}, /* General IO Pins Control Register*/
393 {S1DREG_CLK_CNF, 0x11}, /* Memory Clock Configuration Register*/
394 {S1DREG_LCD_CLK_CNF, 0x10}, /* LCD Pixel Clock Configuration Register*/
395 {S1DREG_CRT_CLK_CNF, 0x12}, /* CRT/TV Pixel Clock Configuration Register*/
396 {S1DREG_MPLUG_CLK_CNF, 0x01}, /* MediaPlug Clock Configuration Register*/
397 {S1DREG_CPU2MEM_WST_SEL, 0x02}, /* CPU To Memory Wait State Select Register*/
398 {S1DREG_MEM_CNF, 0x00}, /* Memory Configuration Register*/
399 {S1DREG_SDRAM_REF_RATE, 0x04}, /* DRAM Refresh Rate Register, MCLK source*/
400 {S1DREG_SDRAM_TC0, 0x12}, /* DRAM Timings Control Register 0*/
401 {S1DREG_SDRAM_TC1, 0x02}, /* DRAM Timings Control Register 1*/
402 {S1DREG_PANEL_TYPE, 0x25}, /* Panel Type Register*/
403 {S1DREG_MOD_RATE, 0x00}, /* MOD Rate Register*/
404 {S1DREG_LCD_DISP_HWIDTH, 0x4F}, /* LCD Horizontal Display Width Register*/
405 {S1DREG_LCD_NDISP_HPER, 0x13}, /* LCD Horizontal Non-Display Period Register*/
406 {S1DREG_TFT_FPLINE_START, 0x01}, /* TFT FPLINE Start Position Register*/
407 {S1DREG_TFT_FPLINE_PWIDTH, 0x0c}, /* TFT FPLINE Pulse Width Register*/
408 {S1DREG_LCD_DISP_VHEIGHT0, 0xDF}, /* LCD Vertical Display Height Register 0*/
409 {S1DREG_LCD_DISP_VHEIGHT1, 0x01}, /* LCD Vertical Display Height Register 1*/
410 {S1DREG_LCD_NDISP_VPER, 0x2c}, /* LCD Vertical Non-Display Period Register*/
411 {S1DREG_TFT_FPFRAME_START, 0x0a}, /* TFT FPFRAME Start Position Register*/
412 {S1DREG_TFT_FPFRAME_PWIDTH, 0x02}, /* TFT FPFRAME Pulse Width Register*/
413 {S1DREG_LCD_DISP_MODE, 0x05}, /* LCD Display Mode Register*/
414 {S1DREG_LCD_MISC, 0x01}, /* LCD Miscellaneous Register*/
415 {S1DREG_LCD_DISP_START0, 0x00}, /* LCD Display Start Address Register 0*/
416 {S1DREG_LCD_DISP_START1, 0x00}, /* LCD Display Start Address Register 1*/
417 {S1DREG_LCD_DISP_START2, 0x00}, /* LCD Display Start Address Register 2*/
418 {S1DREG_LCD_MEM_OFF0, 0x80}, /* LCD Memory Address Offset Register 0*/
419 {S1DREG_LCD_MEM_OFF1, 0x02}, /* LCD Memory Address Offset Register 1*/
420 {S1DREG_LCD_PIX_PAN, 0x03}, /* LCD Pixel Panning Register*/
421 {S1DREG_LCD_DISP_FIFO_HTC, 0x00}, /* LCD Display FIFO High Threshold Control Register*/
422 {S1DREG_LCD_DISP_FIFO_LTC, 0x00}, /* LCD Display FIFO Low Threshold Control Register*/
423 {S1DREG_CRT_DISP_HWIDTH, 0x4F}, /* CRT/TV Horizontal Display Width Register*/
424 {S1DREG_CRT_NDISP_HPER, 0x13}, /* CRT/TV Horizontal Non-Display Period Register*/
425 {S1DREG_CRT_HRTC_START, 0x01}, /* CRT/TV HRTC Start Position Register*/
426 {S1DREG_CRT_HRTC_PWIDTH, 0x0B}, /* CRT/TV HRTC Pulse Width Register*/
427 {S1DREG_CRT_DISP_VHEIGHT0, 0xDF}, /* CRT/TV Vertical Display Height Register 0*/
428 {S1DREG_CRT_DISP_VHEIGHT1, 0x01}, /* CRT/TV Vertical Display Height Register 1*/
429 {S1DREG_CRT_NDISP_VPER, 0x2B}, /* CRT/TV Vertical Non-Display Period Register*/
430 {S1DREG_CRT_VRTC_START, 0x09}, /* CRT/TV VRTC Start Position Register*/
431 {S1DREG_CRT_VRTC_PWIDTH, 0x01}, /* CRT/TV VRTC Pulse Width Register*/
432 {S1DREG_TV_OUT_CTL, 0x18}, /* TV Output Control Register */
433 {S1DREG_CRT_DISP_MODE, 0x05}, /* CRT/TV Display Mode Register, 16BPP*/
434 {S1DREG_CRT_DISP_START0, 0x00}, /* CRT/TV Display Start Address Register 0*/
435 {S1DREG_CRT_DISP_START1, 0x00}, /* CRT/TV Display Start Address Register 1*/
436 {S1DREG_CRT_DISP_START2, 0x00}, /* CRT/TV Display Start Address Register 2*/
437 {S1DREG_CRT_MEM_OFF0, 0x80}, /* CRT/TV Memory Address Offset Register 0*/
438 {S1DREG_CRT_MEM_OFF1, 0x02}, /* CRT/TV Memory Address Offset Register 1*/
439 {S1DREG_CRT_PIX_PAN, 0x00}, /* CRT/TV Pixel Panning Register*/
440 {S1DREG_CRT_DISP_FIFO_HTC, 0x00}, /* CRT/TV Display FIFO High Threshold Control Register*/
441 {S1DREG_CRT_DISP_FIFO_LTC, 0x00}, /* CRT/TV Display FIFO Low Threshold Control Register*/
442 {S1DREG_LCD_CUR_CTL, 0x00}, /* LCD Ink/Cursor Control Register*/
443 {S1DREG_LCD_CUR_START, 0x01}, /* LCD Ink/Cursor Start Address Register*/
444 {S1DREG_LCD_CUR_XPOS0, 0x00}, /* LCD Cursor X Position Register 0*/
445 {S1DREG_LCD_CUR_XPOS1, 0x00}, /* LCD Cursor X Position Register 1*/
446 {S1DREG_LCD_CUR_YPOS0, 0x00}, /* LCD Cursor Y Position Register 0*/
447 {S1DREG_LCD_CUR_YPOS1, 0x00}, /* LCD Cursor Y Position Register 1*/
448 {S1DREG_LCD_CUR_BCTL0, 0x00}, /* LCD Ink/Cursor Blue Color 0 Register*/
449 {S1DREG_LCD_CUR_GCTL0, 0x00}, /* LCD Ink/Cursor Green Color 0 Register*/
450 {S1DREG_LCD_CUR_RCTL0, 0x00}, /* LCD Ink/Cursor Red Color 0 Register*/
451 {S1DREG_LCD_CUR_BCTL1, 0x1F}, /* LCD Ink/Cursor Blue Color 1 Register*/
452 {S1DREG_LCD_CUR_GCTL1, 0x3F}, /* LCD Ink/Cursor Green Color 1 Register*/
453 {S1DREG_LCD_CUR_RCTL1, 0x1F}, /* LCD Ink/Cursor Red Color 1 Register*/
454 {S1DREG_LCD_CUR_FIFO_HTC, 0x00}, /* LCD Ink/Cursor FIFO Threshold Register*/
455 {S1DREG_CRT_CUR_CTL, 0x00}, /* CRT/TV Ink/Cursor Control Register*/
456 {S1DREG_CRT_CUR_START, 0x01}, /* CRT/TV Ink/Cursor Start Address Register*/
457 {S1DREG_CRT_CUR_XPOS0, 0x00}, /* CRT/TV Cursor X Position Register 0*/
458 {S1DREG_CRT_CUR_XPOS1, 0x00}, /* CRT/TV Cursor X Position Register 1*/
459 {S1DREG_CRT_CUR_YPOS0, 0x00}, /* CRT/TV Cursor Y Position Register 0*/
460 {S1DREG_CRT_CUR_YPOS1, 0x00}, /* CRT/TV Cursor Y Position Register 1*/
461 {S1DREG_CRT_CUR_BCTL0, 0x00}, /* CRT/TV Ink/Cursor Blue Color 0 Register*/
462 {S1DREG_CRT_CUR_GCTL0, 0x00}, /* CRT/TV Ink/Cursor Green Color 0 Register*/
463 {S1DREG_CRT_CUR_RCTL0, 0x00}, /* CRT/TV Ink/Cursor Red Color 0 Register*/
464 {S1DREG_CRT_CUR_BCTL1, 0x1F}, /* CRT/TV Ink/Cursor Blue Color 1 Register*/
465 {S1DREG_CRT_CUR_GCTL1, 0x3F}, /* CRT/TV Ink/Cursor Green Color 1 Register*/
466 {S1DREG_CRT_CUR_RCTL1, 0x1F}, /* CRT/TV Ink/Cursor Red Color 1 Register*/
467 {S1DREG_CRT_CUR_FIFO_HTC, 0x00}, /* CRT/TV Ink/Cursor FIFO Threshold Register*/
468 {S1DREG_BBLT_CTL0, 0x00}, /* BitBlt Control Register 0*/
469 {S1DREG_BBLT_CTL1, 0x01}, /* BitBlt Control Register 1*/
470 {S1DREG_BBLT_CC_EXP, 0x00}, /* BitBlt ROP Code/Color Expansion Register*/
471 {S1DREG_BBLT_OP, 0x00}, /* BitBlt Operation Register*/
472 {S1DREG_BBLT_SRC_START0, 0x00}, /* BitBlt Source Start Address Register 0*/
473 {S1DREG_BBLT_SRC_START1, 0x00}, /* BitBlt Source Start Address Register 1*/
474 {S1DREG_BBLT_SRC_START2, 0x00}, /* BitBlt Source Start Address Register 2*/
475 {S1DREG_BBLT_DST_START0, 0x00}, /* BitBlt Destination Start Address Register 0*/
476 {S1DREG_BBLT_DST_START1, 0x00}, /* BitBlt Destination Start Address Register 1*/
477 {S1DREG_BBLT_DST_START2, 0x00}, /* BitBlt Destination Start Address Register 2*/
478 {S1DREG_BBLT_MEM_OFF0, 0x00}, /* BitBlt Memory Address Offset Register 0*/
479 {S1DREG_BBLT_MEM_OFF1, 0x00}, /* BitBlt Memory Address Offset Register 1*/
480 {S1DREG_BBLT_WIDTH0, 0x00}, /* BitBlt Width Register 0*/
481 {S1DREG_BBLT_WIDTH1, 0x00}, /* BitBlt Width Register 1*/
482 {S1DREG_BBLT_HEIGHT0, 0x00}, /* BitBlt Height Register 0*/
483 {S1DREG_BBLT_HEIGHT1, 0x00}, /* BitBlt Height Register 1*/
484 {S1DREG_BBLT_BGC0, 0x00}, /* BitBlt Background Color Register 0*/
485 {S1DREG_BBLT_BGC1, 0x00}, /* BitBlt Background Color Register 1*/
486 {S1DREG_BBLT_FGC0, 0x00}, /* BitBlt Foreground Color Register 0*/
487 {S1DREG_BBLT_FGC1, 0x00}, /* BitBlt Foreground Color Register 1*/
488 {S1DREG_LKUP_MODE, 0x00}, /* Look-Up Table Mode Register*/
489 {S1DREG_LKUP_ADDR, 0x00}, /* Look-Up Table Address Register*/
490 {S1DREG_PS_CNF, 0x00}, /* Power Save Configuration Register*/
491 {S1DREG_PS_STATUS, 0x00}, /* Power Save Status Register*/
492 {S1DREG_CPU2MEM_WDOGT, 0x00}, /* CPU-to-Memory Access Watchdog Timer Register*/
493 {S1DREG_COM_DISP_MODE, 0x01}, /* Display Mode Register, LCD only*/
494};
495
496static struct s1d13xxxfb_pdata yl9200_s1dfb_pdata = {
497 .initregs = yl9200_s1dfb_initregs,
498 .initregssize = ARRAY_SIZE(yl9200_s1dfb_initregs),
499 .platform_init_video = yl9200_init_video,
500};
501
502#define YL9200_FB_REG_BASE AT91_CHIPSELECT_7
503#define YL9200_FB_VMEM_BASE YL9200_FB_REG_BASE + SZ_2M
504#define YL9200_FB_VMEM_SIZE SZ_2M
505
506static struct resource yl9200_s1dfb_resource[] = {
507 [0] = { /* video mem */
508 .name = "s1d13xxxfb memory",
509 .start = YL9200_FB_VMEM_BASE,
510 .end = YL9200_FB_VMEM_BASE + YL9200_FB_VMEM_SIZE -1,
511 .flags = IORESOURCE_MEM,
512 },
513 [1] = { /* video registers */
514 .name = "s1d13xxxfb registers",
515 .start = YL9200_FB_REG_BASE,
516 .end = YL9200_FB_REG_BASE + SZ_512 -1,
517 .flags = IORESOURCE_MEM,
518 },
519};
520
521static u64 s1dfb_dmamask = DMA_BIT_MASK(32);
522
523static struct platform_device yl9200_s1dfb_device = {
524 .name = "s1d13806fb",
525 .id = -1,
526 .dev = {
527 .dma_mask = &s1dfb_dmamask,
528 .coherent_dma_mask = DMA_BIT_MASK(32),
529 .platform_data = &yl9200_s1dfb_pdata,
530 },
531 .resource = yl9200_s1dfb_resource,
532 .num_resources = ARRAY_SIZE(yl9200_s1dfb_resource),
533};
534
535void __init yl9200_add_device_video(void)
536{
537 platform_device_register(&yl9200_s1dfb_device);
538}
539#else
540void __init yl9200_add_device_video(void) {}
541#endif
542
543
544static void __init yl9200_board_init(void)
545{
546 /* Serial */
547 /* DBGU on ttyS0. (Rx & Tx only) */
548 at91_register_uart(0, 0, 0);
549
550 /* USART1 on ttyS1. (Rx, Tx, CTS, RTS, DTR, DSR, DCD, RI) */
551 at91_register_uart(AT91RM9200_ID_US1, 1, ATMEL_UART_CTS | ATMEL_UART_RTS
552 | ATMEL_UART_DTR | ATMEL_UART_DSR | ATMEL_UART_DCD
553 | ATMEL_UART_RI);
554
555 /* USART0 on ttyS2. (Rx & Tx only to JP3) */
556 at91_register_uart(AT91RM9200_ID_US0, 2, 0);
557
558 /* USART3 on ttyS3. (Rx, Tx, RTS - RS485 interface) */
559 at91_register_uart(AT91RM9200_ID_US3, 3, ATMEL_UART_RTS);
560 at91_add_device_serial();
561 /* Ethernet */
562 at91_add_device_eth(&yl9200_eth_data);
563 /* USB Host */
564 at91_add_device_usbh(&yl9200_usbh_data);
565 /* USB Device */
566 at91_add_device_udc(&yl9200_udc_data);
567 /* I2C */
568 at91_add_device_i2c(yl9200_i2c_devices, ARRAY_SIZE(yl9200_i2c_devices));
569 /* MMC */
570 at91_add_device_mci(0, &yl9200_mci0_data);
571 /* NAND */
572 at91_add_device_nand(&yl9200_nand_data);
573 /* NOR Flash */
574 platform_device_register(&yl9200_flash);
575#if defined(CONFIG_SPI_ATMEL) || defined(CONFIG_SPI_ATMEL_MODULE)
576 /* SPI */
577 at91_add_device_spi(yl9200_spi_devices, ARRAY_SIZE(yl9200_spi_devices));
578 /* Touchscreen */
579 yl9200_add_device_ts();
580#endif
581 /* LEDs. */
582 at91_gpio_leds(yl9200_leds, ARRAY_SIZE(yl9200_leds));
583 /* Push Buttons */
584 yl9200_add_device_buttons();
585 /* VGA */
586 yl9200_add_device_video();
587}
588
589MACHINE_START(YL9200, "uCdragon YL-9200")
590 /* Maintainer: S.Birtles */
591 .init_time = at91rm9200_timer_init,
592 .map_io = at91_map_io,
593 .handle_irq = at91_aic_handle_irq,
594 .init_early = yl9200_init_early,
595 .init_irq = at91_init_irq_default,
596 .init_machine = yl9200_board_init,
597MACHINE_END
diff --git a/arch/arm/mach-at91/board.h b/arch/arm/mach-at91/board.h
deleted file mode 100644
index 836e9a537e0c..000000000000
--- a/arch/arm/mach-at91/board.h
+++ /dev/null
@@ -1,127 +0,0 @@
1/*
2 * arch/arm/mach-at91/include/mach/board.h
3 *
4 * Copyright (C) 2005 HP Labs
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * These are data structures found in platform_device.dev.platform_data,
23 * and describing board-specific data needed by drivers. For example,
24 * which pin is used for a given GPIO role.
25 *
26 * In 2.6, drivers should strongly avoid board-specific knowledge so
27 * that supporting new boards normally won't require driver patches.
28 * Most board-specific knowledge should be in arch/.../board-*.c files.
29 */
30
31#ifndef __ASM_ARCH_BOARD_H
32#define __ASM_ARCH_BOARD_H
33
34#include <linux/platform_data/atmel.h>
35
36 /* USB Device */
37extern void __init at91_add_device_udc(struct at91_udc_data *data);
38
39 /* USB High Speed Device */
40extern void __init at91_add_device_usba(struct usba_platform_data *data);
41
42 /* Compact Flash */
43extern void __init at91_add_device_cf(struct at91_cf_data *data);
44
45 /* MMC / SD */
46 /* atmel-mci platform config */
47extern void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data);
48
49extern void __init at91_add_device_eth(struct macb_platform_data *data);
50
51 /* USB Host */
52extern void __init at91_add_device_usbh(struct at91_usbh_data *data);
53extern void __init at91_add_device_usbh_ohci(struct at91_usbh_data *data);
54extern void __init at91_add_device_usbh_ehci(struct at91_usbh_data *data);
55
56extern void __init at91_add_device_nand(struct atmel_nand_data *data);
57
58 /* I2C*/
59#if defined(CONFIG_ARCH_AT91SAM9G45)
60extern void __init at91_add_device_i2c(short i2c_id, struct i2c_board_info *devices, int nr_devices);
61#else
62extern void __init at91_add_device_i2c(struct i2c_board_info *devices, int nr_devices);
63#endif
64
65 /* SPI */
66extern void __init at91_add_device_spi(struct spi_board_info *devices, int nr_devices);
67
68 /* Serial */
69#define ATMEL_UART_CTS 0x01
70#define ATMEL_UART_RTS 0x02
71#define ATMEL_UART_DSR 0x04
72#define ATMEL_UART_DTR 0x08
73#define ATMEL_UART_DCD 0x10
74#define ATMEL_UART_RI 0x20
75
76extern void __init at91_register_uart(unsigned id, unsigned portnr, unsigned pins);
77
78extern struct platform_device *atmel_default_console_device;
79
80extern void __init at91_add_device_serial(void);
81
82/*
83 * PWM
84 */
85#define AT91_PWM0 0
86#define AT91_PWM1 1
87#define AT91_PWM2 2
88#define AT91_PWM3 3
89
90extern void __init at91_add_device_pwm(u32 mask);
91
92/*
93 * SSC -- accessed through ssc_request(id). Drivers don't bind to SSC
94 * platform devices. Their SSC ID is part of their configuration data,
95 * along with information about which SSC signals they should use.
96 */
97#define ATMEL_SSC_TK 0x01
98#define ATMEL_SSC_TF 0x02
99#define ATMEL_SSC_TD 0x04
100#define ATMEL_SSC_TX (ATMEL_SSC_TK | ATMEL_SSC_TF | ATMEL_SSC_TD)
101
102#define ATMEL_SSC_RK 0x10
103#define ATMEL_SSC_RF 0x20
104#define ATMEL_SSC_RD 0x40
105#define ATMEL_SSC_RX (ATMEL_SSC_RK | ATMEL_SSC_RF | ATMEL_SSC_RD)
106
107extern void __init at91_add_device_ssc(unsigned id, unsigned pins);
108
109 /* LCD Controller */
110struct atmel_lcdfb_pdata;
111extern void __init at91_add_device_lcdc(struct atmel_lcdfb_pdata *data);
112
113 /* AC97 */
114extern void __init at91_add_device_ac97(struct ac97c_platform_data *data);
115
116 /* ISI */
117struct isi_platform_data;
118extern void __init at91_add_device_isi(struct isi_platform_data *data,
119 bool use_pck_as_mck);
120
121/* CAN */
122extern void __init at91_add_device_can(struct at91_can_data *data);
123
124 /* LEDs */
125extern void __init at91_gpio_leds(struct gpio_led *leds, int nr);
126
127#endif
diff --git a/arch/arm/mach-at91/clock.c b/arch/arm/mach-at91/clock.c
deleted file mode 100644
index d66f102c352a..000000000000
--- a/arch/arm/mach-at91/clock.c
+++ /dev/null
@@ -1,977 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/clock.c
3 *
4 * Copyright (C) 2005 David Brownell
5 * Copyright (C) 2005 Ivan Kokshaysky
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
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/fs.h>
17#include <linux/debugfs.h>
18#include <linux/seq_file.h>
19#include <linux/list.h>
20#include <linux/errno.h>
21#include <linux/err.h>
22#include <linux/spinlock.h>
23#include <linux/delay.h>
24#include <linux/clk.h>
25#include <linux/io.h>
26#include <linux/of_address.h>
27#include <linux/clk/at91_pmc.h>
28
29#include <mach/hardware.h>
30#include <mach/cpu.h>
31
32#include <asm/proc-fns.h>
33
34#include "clock.h"
35#include "generic.h"
36
37void __iomem *at91_pmc_base;
38EXPORT_SYMBOL_GPL(at91_pmc_base);
39
40/*
41 * There's a lot more which can be done with clocks, including cpufreq
42 * integration, slow clock mode support (for system suspend), letting
43 * PLLB be used at other rates (on boards that don't need USB), etc.
44 */
45
46#define clk_is_primary(x) ((x)->type & CLK_TYPE_PRIMARY)
47#define clk_is_programmable(x) ((x)->type & CLK_TYPE_PROGRAMMABLE)
48#define clk_is_peripheral(x) ((x)->type & CLK_TYPE_PERIPHERAL)
49#define clk_is_sys(x) ((x)->type & CLK_TYPE_SYSTEM)
50
51
52/*
53 * Chips have some kind of clocks : group them by functionality
54 */
55#define cpu_has_utmi() ( cpu_is_at91sam9rl() \
56 || cpu_is_at91sam9g45() \
57 || cpu_is_at91sam9x5() \
58 || cpu_is_sama5d3())
59
60#define cpu_has_1056M_plla() (cpu_is_sama5d3())
61
62#define cpu_has_800M_plla() ( cpu_is_at91sam9g20() \
63 || cpu_is_at91sam9g45() \
64 || cpu_is_at91sam9x5() \
65 || cpu_is_at91sam9n12())
66
67#define cpu_has_300M_plla() (cpu_is_at91sam9g10())
68
69#define cpu_has_240M_plla() (cpu_is_at91sam9261() \
70 || cpu_is_at91sam9263() \
71 || cpu_is_at91sam9rl())
72
73#define cpu_has_210M_plla() (cpu_is_at91sam9260())
74
75#define cpu_has_pllb() (!(cpu_is_at91sam9rl() \
76 || cpu_is_at91sam9g45() \
77 || cpu_is_at91sam9x5() \
78 || cpu_is_sama5d3()))
79
80#define cpu_has_upll() (cpu_is_at91sam9g45() \
81 || cpu_is_at91sam9x5() \
82 || cpu_is_sama5d3())
83
84/* USB host HS & FS */
85#define cpu_has_uhp() (!cpu_is_at91sam9rl())
86
87/* USB device FS only */
88#define cpu_has_udpfs() (!(cpu_is_at91sam9rl() \
89 || cpu_is_at91sam9g45() \
90 || cpu_is_at91sam9x5() \
91 || cpu_is_sama5d3()))
92
93#define cpu_has_plladiv2() (cpu_is_at91sam9g45() \
94 || cpu_is_at91sam9x5() \
95 || cpu_is_at91sam9n12() \
96 || cpu_is_sama5d3())
97
98#define cpu_has_mdiv3() (cpu_is_at91sam9g45() \
99 || cpu_is_at91sam9x5() \
100 || cpu_is_at91sam9n12() \
101 || cpu_is_sama5d3())
102
103#define cpu_has_alt_prescaler() (cpu_is_at91sam9x5() \
104 || cpu_is_at91sam9n12() \
105 || cpu_is_sama5d3())
106
107static LIST_HEAD(clocks);
108static DEFINE_SPINLOCK(clk_lock);
109
110static u32 at91_pllb_usb_init;
111
112/*
113 * Four primary clock sources: two crystal oscillators (32K, main), and
114 * two PLLs. PLLA usually runs the master clock; and PLLB must run at
115 * 48 MHz (unless no USB function clocks are needed). The main clock and
116 * both PLLs are turned off to run in "slow clock mode" (system suspend).
117 */
118static struct clk clk32k = {
119 .name = "clk32k",
120 .rate_hz = AT91_SLOW_CLOCK,
121 .users = 1, /* always on */
122 .id = 0,
123 .type = CLK_TYPE_PRIMARY,
124};
125static struct clk main_clk = {
126 .name = "main",
127 .pmc_mask = AT91_PMC_MOSCS, /* in PMC_SR */
128 .id = 1,
129 .type = CLK_TYPE_PRIMARY,
130};
131static struct clk plla = {
132 .name = "plla",
133 .parent = &main_clk,
134 .pmc_mask = AT91_PMC_LOCKA, /* in PMC_SR */
135 .id = 2,
136 .type = CLK_TYPE_PRIMARY | CLK_TYPE_PLL,
137};
138
139static void pllb_mode(struct clk *clk, int is_on)
140{
141 u32 value;
142
143 if (is_on) {
144 is_on = AT91_PMC_LOCKB;
145 value = at91_pllb_usb_init;
146 } else
147 value = 0;
148
149 // REVISIT: Add work-around for AT91RM9200 Errata #26 ?
150 at91_pmc_write(AT91_CKGR_PLLBR, value);
151
152 do {
153 cpu_relax();
154 } while ((at91_pmc_read(AT91_PMC_SR) & AT91_PMC_LOCKB) != is_on);
155}
156
157static struct clk pllb = {
158 .name = "pllb",
159 .parent = &main_clk,
160 .pmc_mask = AT91_PMC_LOCKB, /* in PMC_SR */
161 .mode = pllb_mode,
162 .id = 3,
163 .type = CLK_TYPE_PRIMARY | CLK_TYPE_PLL,
164};
165
166static void pmc_sys_mode(struct clk *clk, int is_on)
167{
168 if (is_on)
169 at91_pmc_write(AT91_PMC_SCER, clk->pmc_mask);
170 else
171 at91_pmc_write(AT91_PMC_SCDR, clk->pmc_mask);
172}
173
174static void pmc_uckr_mode(struct clk *clk, int is_on)
175{
176 unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
177
178 if (is_on) {
179 is_on = AT91_PMC_LOCKU;
180 at91_pmc_write(AT91_CKGR_UCKR, uckr | clk->pmc_mask);
181 } else
182 at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(clk->pmc_mask));
183
184 do {
185 cpu_relax();
186 } while ((at91_pmc_read(AT91_PMC_SR) & AT91_PMC_LOCKU) != is_on);
187}
188
189/* USB function clocks (PLLB must be 48 MHz) */
190static struct clk udpck = {
191 .name = "udpck",
192 .parent = &pllb,
193 .mode = pmc_sys_mode,
194};
195struct clk utmi_clk = {
196 .name = "utmi_clk",
197 .parent = &main_clk,
198 .pmc_mask = AT91_PMC_UPLLEN, /* in CKGR_UCKR */
199 .mode = pmc_uckr_mode,
200 .type = CLK_TYPE_PLL,
201};
202static struct clk uhpck = {
203 .name = "uhpck",
204 /*.parent = ... we choose parent at runtime */
205 .mode = pmc_sys_mode,
206};
207
208
209/*
210 * The master clock is divided from the CPU clock (by 1-4). It's used for
211 * memory, interfaces to on-chip peripherals, the AIC, and sometimes more
212 * (e.g baud rate generation). It's sourced from one of the primary clocks.
213 */
214struct clk mck = {
215 .name = "mck",
216 .pmc_mask = AT91_PMC_MCKRDY, /* in PMC_SR */
217};
218
219static void pmc_periph_mode(struct clk *clk, int is_on)
220{
221 u32 regval = 0;
222
223 /*
224 * With sama5d3 devices, we are managing clock division so we have to
225 * use the Peripheral Control Register introduced from at91sam9x5
226 * devices.
227 */
228 if (cpu_is_sama5d3()) {
229 regval |= AT91_PMC_PCR_CMD; /* write command */
230 regval |= clk->pid & AT91_PMC_PCR_PID; /* peripheral selection */
231 regval |= AT91_PMC_PCR_DIV(clk->div);
232 if (is_on)
233 regval |= AT91_PMC_PCR_EN; /* enable clock */
234 at91_pmc_write(AT91_PMC_PCR, regval);
235 } else {
236 if (is_on)
237 at91_pmc_write(AT91_PMC_PCER, clk->pmc_mask);
238 else
239 at91_pmc_write(AT91_PMC_PCDR, clk->pmc_mask);
240 }
241}
242
243static struct clk __init *at91_css_to_clk(unsigned long css)
244{
245 switch (css) {
246 case AT91_PMC_CSS_SLOW:
247 return &clk32k;
248 case AT91_PMC_CSS_MAIN:
249 return &main_clk;
250 case AT91_PMC_CSS_PLLA:
251 return &plla;
252 case AT91_PMC_CSS_PLLB:
253 if (cpu_has_upll())
254 /* CSS_PLLB == CSS_UPLL */
255 return &utmi_clk;
256 else if (cpu_has_pllb())
257 return &pllb;
258 break;
259 /* alternate PMC: can use master clock */
260 case AT91_PMC_CSS_MASTER:
261 return &mck;
262 }
263
264 return NULL;
265}
266
267static int pmc_prescaler_divider(u32 reg)
268{
269 if (cpu_has_alt_prescaler()) {
270 return 1 << ((reg & AT91_PMC_ALT_PRES) >> PMC_ALT_PRES_OFFSET);
271 } else {
272 return 1 << ((reg & AT91_PMC_PRES) >> PMC_PRES_OFFSET);
273 }
274}
275
276static void __clk_enable(struct clk *clk)
277{
278 if (clk->parent)
279 __clk_enable(clk->parent);
280 if (clk->users++ == 0 && clk->mode)
281 clk->mode(clk, 1);
282}
283
284int clk_enable(struct clk *clk)
285{
286 unsigned long flags;
287
288 spin_lock_irqsave(&clk_lock, flags);
289 __clk_enable(clk);
290 spin_unlock_irqrestore(&clk_lock, flags);
291 return 0;
292}
293EXPORT_SYMBOL(clk_enable);
294
295static void __clk_disable(struct clk *clk)
296{
297 BUG_ON(clk->users == 0);
298 if (--clk->users == 0 && clk->mode)
299 clk->mode(clk, 0);
300 if (clk->parent)
301 __clk_disable(clk->parent);
302}
303
304void clk_disable(struct clk *clk)
305{
306 unsigned long flags;
307
308 spin_lock_irqsave(&clk_lock, flags);
309 __clk_disable(clk);
310 spin_unlock_irqrestore(&clk_lock, flags);
311}
312EXPORT_SYMBOL(clk_disable);
313
314unsigned long clk_get_rate(struct clk *clk)
315{
316 unsigned long flags;
317 unsigned long rate;
318
319 spin_lock_irqsave(&clk_lock, flags);
320 for (;;) {
321 rate = clk->rate_hz;
322 if (rate || !clk->parent)
323 break;
324 clk = clk->parent;
325 }
326 spin_unlock_irqrestore(&clk_lock, flags);
327 return rate;
328}
329EXPORT_SYMBOL(clk_get_rate);
330
331/*------------------------------------------------------------------------*/
332
333/*
334 * For now, only the programmable clocks support reparenting (MCK could
335 * do this too, with care) or rate changing (the PLLs could do this too,
336 * ditto MCK but that's more for cpufreq). Drivers may reparent to get
337 * a better rate match; we don't.
338 */
339
340long clk_round_rate(struct clk *clk, unsigned long rate)
341{
342 unsigned long flags;
343 unsigned prescale;
344 unsigned long actual;
345 unsigned long prev = ULONG_MAX;
346
347 if (!clk_is_programmable(clk))
348 return -EINVAL;
349 spin_lock_irqsave(&clk_lock, flags);
350
351 actual = clk->parent->rate_hz;
352 for (prescale = 0; prescale < 7; prescale++) {
353 if (actual > rate)
354 prev = actual;
355
356 if (actual && actual <= rate) {
357 if ((prev - rate) < (rate - actual)) {
358 actual = prev;
359 prescale--;
360 }
361 break;
362 }
363 actual >>= 1;
364 }
365
366 spin_unlock_irqrestore(&clk_lock, flags);
367 return (prescale < 7) ? actual : -ENOENT;
368}
369EXPORT_SYMBOL(clk_round_rate);
370
371int clk_set_rate(struct clk *clk, unsigned long rate)
372{
373 unsigned long flags;
374 unsigned prescale;
375 unsigned long prescale_offset, css_mask;
376 unsigned long actual;
377
378 if (!clk_is_programmable(clk))
379 return -EINVAL;
380 if (clk->users)
381 return -EBUSY;
382
383 if (cpu_has_alt_prescaler()) {
384 prescale_offset = PMC_ALT_PRES_OFFSET;
385 css_mask = AT91_PMC_ALT_PCKR_CSS;
386 } else {
387 prescale_offset = PMC_PRES_OFFSET;
388 css_mask = AT91_PMC_CSS;
389 }
390
391 spin_lock_irqsave(&clk_lock, flags);
392
393 actual = clk->parent->rate_hz;
394 for (prescale = 0; prescale < 7; prescale++) {
395 if (actual && actual <= rate) {
396 u32 pckr;
397
398 pckr = at91_pmc_read(AT91_PMC_PCKR(clk->id));
399 pckr &= css_mask; /* keep clock selection */
400 pckr |= prescale << prescale_offset;
401 at91_pmc_write(AT91_PMC_PCKR(clk->id), pckr);
402 clk->rate_hz = actual;
403 break;
404 }
405 actual >>= 1;
406 }
407
408 spin_unlock_irqrestore(&clk_lock, flags);
409 return (prescale < 7) ? actual : -ENOENT;
410}
411EXPORT_SYMBOL(clk_set_rate);
412
413struct clk *clk_get_parent(struct clk *clk)
414{
415 return clk->parent;
416}
417EXPORT_SYMBOL(clk_get_parent);
418
419int clk_set_parent(struct clk *clk, struct clk *parent)
420{
421 unsigned long flags;
422
423 if (clk->users)
424 return -EBUSY;
425 if (!clk_is_primary(parent) || !clk_is_programmable(clk))
426 return -EINVAL;
427
428 if (cpu_is_at91sam9rl() && parent->id == AT91_PMC_CSS_PLLB)
429 return -EINVAL;
430
431 spin_lock_irqsave(&clk_lock, flags);
432
433 clk->rate_hz = parent->rate_hz;
434 clk->parent = parent;
435 at91_pmc_write(AT91_PMC_PCKR(clk->id), parent->id);
436
437 spin_unlock_irqrestore(&clk_lock, flags);
438 return 0;
439}
440EXPORT_SYMBOL(clk_set_parent);
441
442/* establish PCK0..PCKN parentage and rate */
443static void __init init_programmable_clock(struct clk *clk)
444{
445 struct clk *parent;
446 u32 pckr;
447 unsigned int css_mask;
448
449 if (cpu_has_alt_prescaler())
450 css_mask = AT91_PMC_ALT_PCKR_CSS;
451 else
452 css_mask = AT91_PMC_CSS;
453
454 pckr = at91_pmc_read(AT91_PMC_PCKR(clk->id));
455 parent = at91_css_to_clk(pckr & css_mask);
456 clk->parent = parent;
457 clk->rate_hz = parent->rate_hz / pmc_prescaler_divider(pckr);
458}
459
460/*------------------------------------------------------------------------*/
461
462#ifdef CONFIG_DEBUG_FS
463
464static int at91_clk_show(struct seq_file *s, void *unused)
465{
466 u32 scsr, pcsr, pcsr1 = 0, uckr = 0, sr;
467 struct clk *clk;
468
469 scsr = at91_pmc_read(AT91_PMC_SCSR);
470 pcsr = at91_pmc_read(AT91_PMC_PCSR);
471 if (cpu_is_sama5d3())
472 pcsr1 = at91_pmc_read(AT91_PMC_PCSR1);
473 sr = at91_pmc_read(AT91_PMC_SR);
474 seq_printf(s, "SCSR = %8x\n", scsr);
475 seq_printf(s, "PCSR = %8x\n", pcsr);
476 if (cpu_is_sama5d3())
477 seq_printf(s, "PCSR1 = %8x\n", pcsr1);
478 seq_printf(s, "MOR = %8x\n", at91_pmc_read(AT91_CKGR_MOR));
479 seq_printf(s, "MCFR = %8x\n", at91_pmc_read(AT91_CKGR_MCFR));
480 seq_printf(s, "PLLA = %8x\n", at91_pmc_read(AT91_CKGR_PLLAR));
481 if (cpu_has_pllb())
482 seq_printf(s, "PLLB = %8x\n", at91_pmc_read(AT91_CKGR_PLLBR));
483 if (cpu_has_utmi()) {
484 uckr = at91_pmc_read(AT91_CKGR_UCKR);
485 seq_printf(s, "UCKR = %8x\n", uckr);
486 }
487 seq_printf(s, "MCKR = %8x\n", at91_pmc_read(AT91_PMC_MCKR));
488 if (cpu_has_upll() || cpu_is_at91sam9n12())
489 seq_printf(s, "USB = %8x\n", at91_pmc_read(AT91_PMC_USB));
490 seq_printf(s, "SR = %8x\n", sr);
491
492 seq_printf(s, "\n");
493
494 list_for_each_entry(clk, &clocks, node) {
495 char *state;
496
497 if (clk->mode == pmc_sys_mode) {
498 state = (scsr & clk->pmc_mask) ? "on" : "off";
499 } else if (clk->mode == pmc_periph_mode) {
500 if (cpu_is_sama5d3()) {
501 u32 pmc_mask = 1 << (clk->pid % 32);
502
503 if (clk->pid > 31)
504 state = (pcsr1 & pmc_mask) ? "on" : "off";
505 else
506 state = (pcsr & pmc_mask) ? "on" : "off";
507 } else {
508 state = (pcsr & clk->pmc_mask) ? "on" : "off";
509 }
510 } else if (clk->mode == pmc_uckr_mode) {
511 state = (uckr & clk->pmc_mask) ? "on" : "off";
512 } else if (clk->pmc_mask) {
513 state = (sr & clk->pmc_mask) ? "on" : "off";
514 } else if (clk == &clk32k || clk == &main_clk) {
515 state = "on";
516 } else {
517 state = "";
518 }
519
520 seq_printf(s, "%-10s users=%2d %-3s %9lu Hz %s\n",
521 clk->name, clk->users, state, clk_get_rate(clk),
522 clk->parent ? clk->parent->name : "");
523 }
524 return 0;
525}
526
527static int at91_clk_open(struct inode *inode, struct file *file)
528{
529 return single_open(file, at91_clk_show, NULL);
530}
531
532static const struct file_operations at91_clk_operations = {
533 .open = at91_clk_open,
534 .read = seq_read,
535 .llseek = seq_lseek,
536 .release = single_release,
537};
538
539static int __init at91_clk_debugfs_init(void)
540{
541 /* /sys/kernel/debug/at91_clk */
542 (void) debugfs_create_file("at91_clk", S_IFREG | S_IRUGO, NULL, NULL, &at91_clk_operations);
543
544 return 0;
545}
546postcore_initcall(at91_clk_debugfs_init);
547
548#endif
549
550/*------------------------------------------------------------------------*/
551
552/* Register a new clock */
553static void __init at91_clk_add(struct clk *clk)
554{
555 list_add_tail(&clk->node, &clocks);
556
557 clk->cl.con_id = clk->name;
558 clk->cl.clk = clk;
559 clkdev_add(&clk->cl);
560}
561
562int __init clk_register(struct clk *clk)
563{
564 if (clk_is_peripheral(clk)) {
565 if (!clk->parent)
566 clk->parent = &mck;
567 if (cpu_is_sama5d3())
568 clk->rate_hz = DIV_ROUND_UP(clk->parent->rate_hz,
569 1 << clk->div);
570 clk->mode = pmc_periph_mode;
571 }
572 else if (clk_is_sys(clk)) {
573 clk->parent = &mck;
574 clk->mode = pmc_sys_mode;
575 }
576 else if (clk_is_programmable(clk)) {
577 clk->mode = pmc_sys_mode;
578 init_programmable_clock(clk);
579 }
580
581 at91_clk_add(clk);
582
583 return 0;
584}
585
586/*------------------------------------------------------------------------*/
587
588static u32 __init at91_pll_rate(struct clk *pll, u32 freq, u32 reg)
589{
590 unsigned mul, div;
591
592 div = reg & 0xff;
593 if (cpu_is_sama5d3())
594 mul = AT91_PMC3_MUL_GET(reg);
595 else
596 mul = AT91_PMC_MUL_GET(reg);
597
598 if (div && mul) {
599 freq /= div;
600 freq *= mul + 1;
601 } else
602 freq = 0;
603
604 return freq;
605}
606
607static u32 __init at91_usb_rate(struct clk *pll, u32 freq, u32 reg)
608{
609 if (pll == &pllb && (reg & AT91_PMC_USB96M))
610 return freq / 2;
611 else if (pll == &utmi_clk || cpu_is_at91sam9n12())
612 return freq / (1 + ((reg & AT91_PMC_OHCIUSBDIV) >> 8));
613 else
614 return freq;
615}
616
617static unsigned __init at91_pll_calc(unsigned main_freq, unsigned out_freq)
618{
619 unsigned i, div = 0, mul = 0, diff = 1 << 30;
620 unsigned ret = (out_freq > 155000000) ? 0xbe00 : 0x3e00;
621
622 /* PLL output max 240 MHz (or 180 MHz per errata) */
623 if (out_freq > 240000000)
624 goto fail;
625
626 for (i = 1; i < 256; i++) {
627 int diff1;
628 unsigned input, mul1;
629
630 /*
631 * PLL input between 1MHz and 32MHz per spec, but lower
632 * frequences seem necessary in some cases so allow 100K.
633 * Warning: some newer products need 2MHz min.
634 */
635 input = main_freq / i;
636 if (cpu_is_at91sam9g20() && input < 2000000)
637 continue;
638 if (input < 100000)
639 continue;
640 if (input > 32000000)
641 continue;
642
643 mul1 = out_freq / input;
644 if (cpu_is_at91sam9g20() && mul > 63)
645 continue;
646 if (mul1 > 2048)
647 continue;
648 if (mul1 < 2)
649 goto fail;
650
651 diff1 = out_freq - input * mul1;
652 if (diff1 < 0)
653 diff1 = -diff1;
654 if (diff > diff1) {
655 diff = diff1;
656 div = i;
657 mul = mul1;
658 if (diff == 0)
659 break;
660 }
661 }
662 if (i == 256 && diff > (out_freq >> 5))
663 goto fail;
664 return ret | ((mul - 1) << 16) | div;
665fail:
666 return 0;
667}
668
669static struct clk *const standard_pmc_clocks[] __initconst = {
670 /* four primary clocks */
671 &clk32k,
672 &main_clk,
673 &plla,
674
675 /* MCK */
676 &mck
677};
678
679/* PLLB generated USB full speed clock init */
680static void __init at91_pllb_usbfs_clock_init(unsigned long main_clock)
681{
682 unsigned int reg;
683
684 /*
685 * USB clock init: choose 48 MHz PLLB value,
686 * disable 48MHz clock during usb peripheral suspend.
687 *
688 * REVISIT: assumes MCK doesn't derive from PLLB!
689 */
690 uhpck.parent = &pllb;
691
692 reg = at91_pllb_usb_init = at91_pll_calc(main_clock, 48000000 * 2);
693 pllb.rate_hz = at91_pll_rate(&pllb, main_clock, at91_pllb_usb_init);
694 if (cpu_is_at91rm9200()) {
695 reg = at91_pllb_usb_init |= AT91_PMC_USB96M;
696 uhpck.pmc_mask = AT91RM9200_PMC_UHP;
697 udpck.pmc_mask = AT91RM9200_PMC_UDP;
698 at91_pmc_write(AT91_PMC_SCER, AT91RM9200_PMC_MCKUDP);
699 } else if (cpu_is_at91sam9260() || cpu_is_at91sam9261() ||
700 cpu_is_at91sam9263() || cpu_is_at91sam9g20() ||
701 cpu_is_at91sam9g10()) {
702 reg = at91_pllb_usb_init |= AT91_PMC_USB96M;
703 uhpck.pmc_mask = AT91SAM926x_PMC_UHP;
704 udpck.pmc_mask = AT91SAM926x_PMC_UDP;
705 } else if (cpu_is_at91sam9n12()) {
706 /* Divider for USB clock is in USB clock register for 9n12 */
707 reg = AT91_PMC_USBS_PLLB;
708
709 /* For PLLB output 96M, set usb divider 2 (USBDIV + 1) */
710 reg |= AT91_PMC_OHCIUSBDIV_2;
711 at91_pmc_write(AT91_PMC_USB, reg);
712
713 /* Still setup masks */
714 uhpck.pmc_mask = AT91SAM926x_PMC_UHP;
715 udpck.pmc_mask = AT91SAM926x_PMC_UDP;
716 }
717 at91_pmc_write(AT91_CKGR_PLLBR, 0);
718
719 udpck.rate_hz = at91_usb_rate(&pllb, pllb.rate_hz, reg);
720 uhpck.rate_hz = at91_usb_rate(&pllb, pllb.rate_hz, reg);
721}
722
723/* UPLL generated USB full speed clock init */
724static void __init at91_upll_usbfs_clock_init(unsigned long main_clock)
725{
726 /*
727 * USB clock init: choose 480 MHz from UPLL,
728 */
729 unsigned int usbr = AT91_PMC_USBS_UPLL;
730
731 /* Setup divider by 10 to reach 48 MHz */
732 usbr |= ((10 - 1) << 8) & AT91_PMC_OHCIUSBDIV;
733
734 at91_pmc_write(AT91_PMC_USB, usbr);
735
736 /* Now set uhpck values */
737 uhpck.parent = &utmi_clk;
738 uhpck.pmc_mask = AT91SAM926x_PMC_UHP;
739 uhpck.rate_hz = at91_usb_rate(&utmi_clk, utmi_clk.rate_hz, usbr);
740}
741
742static int __init at91_pmc_init(unsigned long main_clock)
743{
744 unsigned tmp, freq, mckr;
745 int i;
746 int pll_overclock = false;
747
748 /*
749 * When the bootloader initialized the main oscillator correctly,
750 * there's no problem using the cycle counter. But if it didn't,
751 * or when using oscillator bypass mode, we must be told the speed
752 * of the main clock.
753 */
754 if (!main_clock) {
755 do {
756 tmp = at91_pmc_read(AT91_CKGR_MCFR);
757 } while (!(tmp & AT91_PMC_MAINRDY));
758 main_clock = (tmp & AT91_PMC_MAINF) * (AT91_SLOW_CLOCK / 16);
759 }
760 main_clk.rate_hz = main_clock;
761
762 /* report if PLLA is more than mildly overclocked */
763 plla.rate_hz = at91_pll_rate(&plla, main_clock, at91_pmc_read(AT91_CKGR_PLLAR));
764 if (cpu_has_1056M_plla()) {
765 if (plla.rate_hz > 1056000000)
766 pll_overclock = true;
767 } else if (cpu_has_800M_plla()) {
768 if (plla.rate_hz > 800000000)
769 pll_overclock = true;
770 } else if (cpu_has_300M_plla()) {
771 if (plla.rate_hz > 300000000)
772 pll_overclock = true;
773 } else if (cpu_has_240M_plla()) {
774 if (plla.rate_hz > 240000000)
775 pll_overclock = true;
776 } else if (cpu_has_210M_plla()) {
777 if (plla.rate_hz > 210000000)
778 pll_overclock = true;
779 } else {
780 if (plla.rate_hz > 209000000)
781 pll_overclock = true;
782 }
783 if (pll_overclock)
784 pr_info("Clocks: PLLA overclocked, %ld MHz\n", plla.rate_hz / 1000000);
785
786 if (cpu_has_plladiv2()) {
787 mckr = at91_pmc_read(AT91_PMC_MCKR);
788 plla.rate_hz /= (1 << ((mckr & AT91_PMC_PLLADIV2) >> 12)); /* plla divisor by 2 */
789 }
790
791 if (!cpu_has_pllb() && cpu_has_upll()) {
792 /* setup UTMI clock as the fourth primary clock
793 * (instead of pllb) */
794 utmi_clk.type |= CLK_TYPE_PRIMARY;
795 utmi_clk.id = 3;
796 }
797
798
799 /*
800 * USB HS clock init
801 */
802 if (cpu_has_utmi()) {
803 /*
804 * multiplier is hard-wired to 40
805 * (obtain the USB High Speed 480 MHz when input is 12 MHz)
806 */
807 utmi_clk.rate_hz = 40 * utmi_clk.parent->rate_hz;
808
809 /* UTMI bias and PLL are managed at the same time */
810 if (cpu_has_upll())
811 utmi_clk.pmc_mask |= AT91_PMC_BIASEN;
812 }
813
814 /*
815 * USB FS clock init
816 */
817 if (cpu_has_pllb())
818 at91_pllb_usbfs_clock_init(main_clock);
819 if (cpu_has_upll())
820 /* assumes that we choose UPLL for USB and not PLLA */
821 at91_upll_usbfs_clock_init(main_clock);
822
823 /*
824 * MCK and CPU derive from one of those primary clocks.
825 * For now, assume this parentage won't change.
826 */
827 mckr = at91_pmc_read(AT91_PMC_MCKR);
828 mck.parent = at91_css_to_clk(mckr & AT91_PMC_CSS);
829 freq = mck.parent->rate_hz;
830 freq /= pmc_prescaler_divider(mckr); /* prescale */
831 if (cpu_is_at91rm9200()) {
832 mck.rate_hz = freq / (1 + ((mckr & AT91_PMC_MDIV) >> 8)); /* mdiv */
833 } else if (cpu_is_at91sam9g20()) {
834 mck.rate_hz = (mckr & AT91_PMC_MDIV) ?
835 freq / ((mckr & AT91_PMC_MDIV) >> 7) : freq; /* mdiv ; (x >> 7) = ((x >> 8) * 2) */
836 if (mckr & AT91_PMC_PDIV)
837 freq /= 2; /* processor clock division */
838 } else if (cpu_has_mdiv3()) {
839 mck.rate_hz = (mckr & AT91_PMC_MDIV) == AT91SAM9_PMC_MDIV_3 ?
840 freq / 3 : freq / (1 << ((mckr & AT91_PMC_MDIV) >> 8)); /* mdiv */
841 } else {
842 mck.rate_hz = freq / (1 << ((mckr & AT91_PMC_MDIV) >> 8)); /* mdiv */
843 }
844
845 if (cpu_has_alt_prescaler()) {
846 /* Programmable clocks can use MCK */
847 mck.type |= CLK_TYPE_PRIMARY;
848 mck.id = 4;
849 }
850
851 /* Register the PMC's standard clocks */
852 for (i = 0; i < ARRAY_SIZE(standard_pmc_clocks); i++)
853 at91_clk_add(standard_pmc_clocks[i]);
854
855 if (cpu_has_pllb())
856 at91_clk_add(&pllb);
857
858 if (cpu_has_uhp())
859 at91_clk_add(&uhpck);
860
861 if (cpu_has_udpfs())
862 at91_clk_add(&udpck);
863
864 if (cpu_has_utmi())
865 at91_clk_add(&utmi_clk);
866
867 /* MCK and CPU clock are "always on" */
868 clk_enable(&mck);
869
870 printk("Clocks: CPU %u MHz, master %u MHz, main %u.%03u MHz\n",
871 freq / 1000000, (unsigned) mck.rate_hz / 1000000,
872 (unsigned) main_clock / 1000000,
873 ((unsigned) main_clock % 1000000) / 1000);
874
875 return 0;
876}
877
878#if defined(CONFIG_OF)
879static struct of_device_id pmc_ids[] = {
880 { .compatible = "atmel,at91rm9200-pmc" },
881 { .compatible = "atmel,at91sam9260-pmc" },
882 { .compatible = "atmel,at91sam9g45-pmc" },
883 { .compatible = "atmel,at91sam9n12-pmc" },
884 { .compatible = "atmel,at91sam9x5-pmc" },
885 { .compatible = "atmel,sama5d3-pmc" },
886 { /*sentinel*/ }
887};
888
889static struct of_device_id osc_ids[] = {
890 { .compatible = "atmel,osc" },
891 { /*sentinel*/ }
892};
893
894int __init at91_dt_clock_init(void)
895{
896 struct device_node *np;
897 u32 main_clock = 0;
898
899 np = of_find_matching_node(NULL, pmc_ids);
900 if (!np)
901 panic("unable to find compatible pmc node in dtb\n");
902
903 at91_pmc_base = of_iomap(np, 0);
904 if (!at91_pmc_base)
905 panic("unable to map pmc cpu registers\n");
906
907 of_node_put(np);
908
909 /* retrieve the freqency of fixed clocks from device tree */
910 np = of_find_matching_node(NULL, osc_ids);
911 if (np) {
912 u32 rate;
913 if (!of_property_read_u32(np, "clock-frequency", &rate))
914 main_clock = rate;
915 }
916
917 of_node_put(np);
918
919 return at91_pmc_init(main_clock);
920}
921#endif
922
923int __init at91_clock_init(unsigned long main_clock)
924{
925 at91_pmc_base = ioremap(AT91_PMC, 256);
926 if (!at91_pmc_base)
927 panic("Impossible to ioremap AT91_PMC 0x%x\n", AT91_PMC);
928
929 return at91_pmc_init(main_clock);
930}
931
932/*
933 * Several unused clocks may be active. Turn them off.
934 */
935static int __init at91_clock_reset(void)
936{
937 unsigned long pcdr = 0;
938 unsigned long pcdr1 = 0;
939 unsigned long scdr = 0;
940 struct clk *clk;
941
942 list_for_each_entry(clk, &clocks, node) {
943 if (clk->users > 0)
944 continue;
945
946 if (clk->mode == pmc_periph_mode) {
947 if (cpu_is_sama5d3()) {
948 u32 pmc_mask = 1 << (clk->pid % 32);
949
950 if (clk->pid > 31)
951 pcdr1 |= pmc_mask;
952 else
953 pcdr |= pmc_mask;
954 } else
955 pcdr |= clk->pmc_mask;
956 }
957
958 if (clk->mode == pmc_sys_mode)
959 scdr |= clk->pmc_mask;
960
961 pr_debug("Clocks: disable unused %s\n", clk->name);
962 }
963
964 at91_pmc_write(AT91_PMC_SCDR, scdr);
965 at91_pmc_write(AT91_PMC_PCDR, pcdr);
966 if (cpu_is_sama5d3())
967 at91_pmc_write(AT91_PMC_PCDR1, pcdr1);
968
969 return 0;
970}
971late_initcall(at91_clock_reset);
972
973void at91sam9_idle(void)
974{
975 at91_pmc_write(AT91_PMC_SCDR, AT91_PMC_PCK);
976 cpu_do_idle();
977}
diff --git a/arch/arm/mach-at91/clock.h b/arch/arm/mach-at91/clock.h
deleted file mode 100644
index a98a39bbd883..000000000000
--- a/arch/arm/mach-at91/clock.h
+++ /dev/null
@@ -1,49 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/clock.h
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/clkdev.h>
10
11#define CLK_TYPE_PRIMARY 0x1
12#define CLK_TYPE_PLL 0x2
13#define CLK_TYPE_PROGRAMMABLE 0x4
14#define CLK_TYPE_PERIPHERAL 0x8
15#define CLK_TYPE_SYSTEM 0x10
16
17
18struct clk {
19 struct list_head node;
20 const char *name; /* unique clock name */
21 struct clk_lookup cl;
22 unsigned long rate_hz;
23 unsigned div; /* parent clock divider */
24 struct clk *parent;
25 unsigned pid; /* peripheral ID */
26 u32 pmc_mask;
27 void (*mode)(struct clk *, int);
28 unsigned id:3; /* PCK0..4, or 32k/main/a/b */
29 unsigned type; /* clock type */
30 u16 users;
31};
32
33
34extern int __init clk_register(struct clk *clk);
35extern struct clk mck;
36extern struct clk utmi_clk;
37
38#define CLKDEV_CON_ID(_id, _clk) \
39 { \
40 .con_id = _id, \
41 .clk = _clk, \
42 }
43
44#define CLKDEV_CON_DEV_ID(_con_id, _dev_id, _clk) \
45 { \
46 .con_id = _con_id, \
47 .dev_id = _dev_id, \
48 .clk = _clk, \
49 }
diff --git a/arch/arm/mach-at91/generic.h b/arch/arm/mach-at91/generic.h
index 81959cf4a137..d53324210adf 100644
--- a/arch/arm/mach-at91/generic.h
+++ b/arch/arm/mach-at91/generic.h
@@ -11,7 +11,6 @@
11#ifndef _AT91_GENERIC_H 11#ifndef _AT91_GENERIC_H
12#define _AT91_GENERIC_H 12#define _AT91_GENERIC_H
13 13
14#include <linux/clkdev.h>
15#include <linux/of.h> 14#include <linux/of.h>
16#include <linux/reboot.h> 15#include <linux/reboot.h>
17 16
@@ -23,71 +22,19 @@ extern void __init at91_init_sram(int bank, unsigned long base,
23 22
24 /* Processors */ 23 /* Processors */
25extern void __init at91rm9200_set_type(int type); 24extern void __init at91rm9200_set_type(int type);
26extern void __init at91_initialize(unsigned long main_clock);
27extern void __init at91x40_initialize(unsigned long main_clock);
28extern void __init at91rm9200_dt_initialize(void); 25extern void __init at91rm9200_dt_initialize(void);
29extern void __init at91_dt_initialize(void); 26extern void __init at91_dt_initialize(void);
30 27
31 /* Interrupts */ 28 /* Interrupts */
32extern void __init at91_init_irq_default(void);
33extern void __init at91_init_interrupts(unsigned int priority[]);
34extern void __init at91x40_init_interrupts(unsigned int priority[]);
35extern void __init at91_aic_init(unsigned int priority[],
36 unsigned int ext_irq_mask);
37extern int __init at91_aic_of_init(struct device_node *node,
38 struct device_node *parent);
39extern int __init at91_aic5_of_init(struct device_node *node,
40 struct device_node *parent);
41extern void __init at91_sysirq_mask_rtc(u32 rtc_base); 29extern void __init at91_sysirq_mask_rtc(u32 rtc_base);
42extern void __init at91_sysirq_mask_rtt(u32 rtt_base); 30extern void __init at91_sysirq_mask_rtt(u32 rtt_base);
43 31
44 /* Devices */
45extern void __init at91_register_devices(void);
46
47 /* Timer */ 32 /* Timer */
48extern void __init at91_init_time(void);
49extern void at91rm9200_ioremap_st(u32 addr);
50extern void at91rm9200_timer_init(void); 33extern void at91rm9200_timer_init(void);
51extern void at91sam926x_ioremap_pit(u32 addr);
52extern void at91sam926x_pit_init(int irq);
53extern void at91x40_timer_init(void);
54
55 /* Clocks */
56#ifdef CONFIG_OLD_CLK_AT91
57extern int __init at91_clock_init(unsigned long main_clock);
58extern int __init at91_dt_clock_init(void);
59#else
60static int inline at91_clock_init(unsigned long main_clock) { return 0; }
61static int inline at91_dt_clock_init(void) { return 0; }
62#endif
63struct device;
64
65 /* Power Management */
66extern void at91_irq_suspend(void);
67extern void at91_irq_resume(void);
68 34
69/* idle */ 35/* idle */
70extern void at91sam9_idle(void); 36extern void at91sam9_idle(void);
71 37
72/* Matrix */ 38/* Matrix */
73extern void at91_ioremap_matrix(u32 base_addr); 39extern void at91_ioremap_matrix(u32 base_addr);
74
75/* Ram Controler */
76extern void at91_ioremap_ramc(int id, u32 addr, u32 size);
77
78 /* GPIO */
79#define AT91RM9200_PQFP 3 /* AT91RM9200 PQFP package has 3 banks */
80#define AT91RM9200_BGA 4 /* AT91RM9200 BGA package has 4 banks */
81
82struct at91_gpio_bank {
83 unsigned short id; /* peripheral ID */
84 unsigned long regbase; /* offset from system peripheral base */
85};
86extern void __init at91_gpio_init(struct at91_gpio_bank *, int nr_banks);
87extern void __init at91_gpio_irq_setup(void);
88extern int __init at91_gpio_of_irq_setup(struct device_node *node,
89 struct device_node *parent);
90
91extern u32 at91_get_extern_irq(void);
92
93#endif /* _AT91_GENERIC_H */ 40#endif /* _AT91_GENERIC_H */
diff --git a/arch/arm/mach-at91/gpio.c b/arch/arm/mach-at91/gpio.c
deleted file mode 100644
index d3f05aaad8ba..000000000000
--- a/arch/arm/mach-at91/gpio.c
+++ /dev/null
@@ -1,982 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/gpio.c
3 *
4 * Copyright (C) 2005 HP Labs
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/clk.h>
13#include <linux/errno.h>
14#include <linux/device.h>
15#include <linux/gpio.h>
16#include <linux/interrupt.h>
17#include <linux/irq.h>
18#include <linux/debugfs.h>
19#include <linux/seq_file.h>
20#include <linux/kernel.h>
21#include <linux/list.h>
22#include <linux/module.h>
23#include <linux/io.h>
24#include <linux/irqdomain.h>
25#include <linux/irqchip/chained_irq.h>
26#include <linux/of_address.h>
27
28#include <mach/hardware.h>
29#include <mach/at91_pio.h>
30
31#include "generic.h"
32#include "gpio.h"
33
34#define MAX_NB_GPIO_PER_BANK 32
35
36struct at91_gpio_chip {
37 struct gpio_chip chip;
38 struct at91_gpio_chip *next; /* Bank sharing same clock */
39 int pioc_hwirq; /* PIO bank interrupt identifier on AIC */
40 int pioc_virq; /* PIO bank Linux virtual interrupt */
41 int pioc_idx; /* PIO bank index */
42 void __iomem *regbase; /* PIO bank virtual address */
43 struct clk *clock; /* associated clock */
44 struct irq_domain *domain; /* associated irq domain */
45};
46
47#define to_at91_gpio_chip(c) container_of(c, struct at91_gpio_chip, chip)
48
49static int at91_gpiolib_request(struct gpio_chip *chip, unsigned offset);
50static void at91_gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip);
51static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val);
52static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset);
53static int at91_gpiolib_get_direction(struct gpio_chip *chip, unsigned offset);
54static int at91_gpiolib_direction_output(struct gpio_chip *chip,
55 unsigned offset, int val);
56static int at91_gpiolib_direction_input(struct gpio_chip *chip,
57 unsigned offset);
58static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset);
59
60#define AT91_GPIO_CHIP(name) \
61 { \
62 .chip = { \
63 .label = name, \
64 .request = at91_gpiolib_request, \
65 .get_direction = at91_gpiolib_get_direction, \
66 .direction_input = at91_gpiolib_direction_input, \
67 .direction_output = at91_gpiolib_direction_output, \
68 .get = at91_gpiolib_get, \
69 .set = at91_gpiolib_set, \
70 .dbg_show = at91_gpiolib_dbg_show, \
71 .to_irq = at91_gpiolib_to_irq, \
72 .ngpio = MAX_NB_GPIO_PER_BANK, \
73 }, \
74 }
75
76static struct at91_gpio_chip gpio_chip[] = {
77 AT91_GPIO_CHIP("pioA"),
78 AT91_GPIO_CHIP("pioB"),
79 AT91_GPIO_CHIP("pioC"),
80 AT91_GPIO_CHIP("pioD"),
81 AT91_GPIO_CHIP("pioE"),
82};
83
84static int gpio_banks;
85static unsigned long at91_gpio_caps;
86
87/* All PIO controllers support PIO3 features */
88#define AT91_GPIO_CAP_PIO3 (1 << 0)
89
90#define has_pio3() (at91_gpio_caps & AT91_GPIO_CAP_PIO3)
91
92/*--------------------------------------------------------------------------*/
93
94static inline void __iomem *pin_to_controller(unsigned pin)
95{
96 pin /= MAX_NB_GPIO_PER_BANK;
97 if (likely(pin < gpio_banks))
98 return gpio_chip[pin].regbase;
99
100 return NULL;
101}
102
103static inline unsigned pin_to_mask(unsigned pin)
104{
105 return 1 << (pin % MAX_NB_GPIO_PER_BANK);
106}
107
108
109static char peripheral_function(void __iomem *pio, unsigned mask)
110{
111 char ret = 'X';
112 u8 select;
113
114 if (pio) {
115 if (has_pio3()) {
116 select = !!(__raw_readl(pio + PIO_ABCDSR1) & mask);
117 select |= (!!(__raw_readl(pio + PIO_ABCDSR2) & mask) << 1);
118 ret = 'A' + select;
119 } else {
120 ret = __raw_readl(pio + PIO_ABSR) & mask ?
121 'B' : 'A';
122 }
123 }
124
125 return ret;
126}
127
128/*--------------------------------------------------------------------------*/
129
130/* Not all hardware capabilities are exposed through these calls; they
131 * only encapsulate the most common features and modes. (So if you
132 * want to change signals in groups, do it directly.)
133 *
134 * Bootloaders will usually handle some of the pin multiplexing setup.
135 * The intent is certainly that by the time Linux is fully booted, all
136 * pins should have been fully initialized. These setup calls should
137 * only be used by board setup routines, or possibly in driver probe().
138 *
139 * For bootloaders doing all that setup, these calls could be inlined
140 * as NOPs so Linux won't duplicate any setup code
141 */
142
143
144/*
145 * mux the pin to the "GPIO" peripheral role.
146 */
147int __init_or_module at91_set_GPIO_periph(unsigned pin, int use_pullup)
148{
149 void __iomem *pio = pin_to_controller(pin);
150 unsigned mask = pin_to_mask(pin);
151
152 if (!pio)
153 return -EINVAL;
154 __raw_writel(mask, pio + PIO_IDR);
155 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
156 __raw_writel(mask, pio + PIO_PER);
157 return 0;
158}
159EXPORT_SYMBOL(at91_set_GPIO_periph);
160
161
162/*
163 * mux the pin to the "A" internal peripheral role.
164 */
165int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup)
166{
167 void __iomem *pio = pin_to_controller(pin);
168 unsigned mask = pin_to_mask(pin);
169
170 if (!pio)
171 return -EINVAL;
172
173 __raw_writel(mask, pio + PIO_IDR);
174 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
175 if (has_pio3()) {
176 __raw_writel(__raw_readl(pio + PIO_ABCDSR1) & ~mask,
177 pio + PIO_ABCDSR1);
178 __raw_writel(__raw_readl(pio + PIO_ABCDSR2) & ~mask,
179 pio + PIO_ABCDSR2);
180 } else {
181 __raw_writel(mask, pio + PIO_ASR);
182 }
183 __raw_writel(mask, pio + PIO_PDR);
184 return 0;
185}
186EXPORT_SYMBOL(at91_set_A_periph);
187
188
189/*
190 * mux the pin to the "B" internal peripheral role.
191 */
192int __init_or_module at91_set_B_periph(unsigned pin, int use_pullup)
193{
194 void __iomem *pio = pin_to_controller(pin);
195 unsigned mask = pin_to_mask(pin);
196
197 if (!pio)
198 return -EINVAL;
199
200 __raw_writel(mask, pio + PIO_IDR);
201 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
202 if (has_pio3()) {
203 __raw_writel(__raw_readl(pio + PIO_ABCDSR1) | mask,
204 pio + PIO_ABCDSR1);
205 __raw_writel(__raw_readl(pio + PIO_ABCDSR2) & ~mask,
206 pio + PIO_ABCDSR2);
207 } else {
208 __raw_writel(mask, pio + PIO_BSR);
209 }
210 __raw_writel(mask, pio + PIO_PDR);
211 return 0;
212}
213EXPORT_SYMBOL(at91_set_B_periph);
214
215
216/*
217 * mux the pin to the "C" internal peripheral role.
218 */
219int __init_or_module at91_set_C_periph(unsigned pin, int use_pullup)
220{
221 void __iomem *pio = pin_to_controller(pin);
222 unsigned mask = pin_to_mask(pin);
223
224 if (!pio || !has_pio3())
225 return -EINVAL;
226
227 __raw_writel(mask, pio + PIO_IDR);
228 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
229 __raw_writel(__raw_readl(pio + PIO_ABCDSR1) & ~mask, pio + PIO_ABCDSR1);
230 __raw_writel(__raw_readl(pio + PIO_ABCDSR2) | mask, pio + PIO_ABCDSR2);
231 __raw_writel(mask, pio + PIO_PDR);
232 return 0;
233}
234EXPORT_SYMBOL(at91_set_C_periph);
235
236
237/*
238 * mux the pin to the "D" internal peripheral role.
239 */
240int __init_or_module at91_set_D_periph(unsigned pin, int use_pullup)
241{
242 void __iomem *pio = pin_to_controller(pin);
243 unsigned mask = pin_to_mask(pin);
244
245 if (!pio || !has_pio3())
246 return -EINVAL;
247
248 __raw_writel(mask, pio + PIO_IDR);
249 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
250 __raw_writel(__raw_readl(pio + PIO_ABCDSR1) | mask, pio + PIO_ABCDSR1);
251 __raw_writel(__raw_readl(pio + PIO_ABCDSR2) | mask, pio + PIO_ABCDSR2);
252 __raw_writel(mask, pio + PIO_PDR);
253 return 0;
254}
255EXPORT_SYMBOL(at91_set_D_periph);
256
257
258/*
259 * mux the pin to the gpio controller (instead of "A", "B", "C"
260 * or "D" peripheral), and configure it for an input.
261 */
262int __init_or_module at91_set_gpio_input(unsigned pin, int use_pullup)
263{
264 void __iomem *pio = pin_to_controller(pin);
265 unsigned mask = pin_to_mask(pin);
266
267 if (!pio)
268 return -EINVAL;
269
270 __raw_writel(mask, pio + PIO_IDR);
271 __raw_writel(mask, pio + (use_pullup ? PIO_PUER : PIO_PUDR));
272 __raw_writel(mask, pio + PIO_ODR);
273 __raw_writel(mask, pio + PIO_PER);
274 return 0;
275}
276EXPORT_SYMBOL(at91_set_gpio_input);
277
278
279/*
280 * mux the pin to the gpio controller (instead of "A", "B", "C"
281 * or "D" peripheral), and configure it for an output.
282 */
283int __init_or_module at91_set_gpio_output(unsigned pin, int value)
284{
285 void __iomem *pio = pin_to_controller(pin);
286 unsigned mask = pin_to_mask(pin);
287
288 if (!pio)
289 return -EINVAL;
290
291 __raw_writel(mask, pio + PIO_IDR);
292 __raw_writel(mask, pio + PIO_PUDR);
293 __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR));
294 __raw_writel(mask, pio + PIO_OER);
295 __raw_writel(mask, pio + PIO_PER);
296 return 0;
297}
298EXPORT_SYMBOL(at91_set_gpio_output);
299
300
301/*
302 * enable/disable the glitch filter; mostly used with IRQ handling.
303 */
304int __init_or_module at91_set_deglitch(unsigned pin, int is_on)
305{
306 void __iomem *pio = pin_to_controller(pin);
307 unsigned mask = pin_to_mask(pin);
308
309 if (!pio)
310 return -EINVAL;
311
312 if (has_pio3() && is_on)
313 __raw_writel(mask, pio + PIO_IFSCDR);
314 __raw_writel(mask, pio + (is_on ? PIO_IFER : PIO_IFDR));
315 return 0;
316}
317EXPORT_SYMBOL(at91_set_deglitch);
318
319/*
320 * enable/disable the debounce filter;
321 */
322int __init_or_module at91_set_debounce(unsigned pin, int is_on, int div)
323{
324 void __iomem *pio = pin_to_controller(pin);
325 unsigned mask = pin_to_mask(pin);
326
327 if (!pio || !has_pio3())
328 return -EINVAL;
329
330 if (is_on) {
331 __raw_writel(mask, pio + PIO_IFSCER);
332 __raw_writel(div & PIO_SCDR_DIV, pio + PIO_SCDR);
333 __raw_writel(mask, pio + PIO_IFER);
334 } else {
335 __raw_writel(mask, pio + PIO_IFDR);
336 }
337 return 0;
338}
339EXPORT_SYMBOL(at91_set_debounce);
340
341/*
342 * enable/disable the multi-driver; This is only valid for output and
343 * allows the output pin to run as an open collector output.
344 */
345int __init_or_module at91_set_multi_drive(unsigned pin, int is_on)
346{
347 void __iomem *pio = pin_to_controller(pin);
348 unsigned mask = pin_to_mask(pin);
349
350 if (!pio)
351 return -EINVAL;
352
353 __raw_writel(mask, pio + (is_on ? PIO_MDER : PIO_MDDR));
354 return 0;
355}
356EXPORT_SYMBOL(at91_set_multi_drive);
357
358/*
359 * enable/disable the pull-down.
360 * If pull-up already enabled while calling the function, we disable it.
361 */
362int __init_or_module at91_set_pulldown(unsigned pin, int is_on)
363{
364 void __iomem *pio = pin_to_controller(pin);
365 unsigned mask = pin_to_mask(pin);
366
367 if (!pio || !has_pio3())
368 return -EINVAL;
369
370 /* Disable pull-up anyway */
371 __raw_writel(mask, pio + PIO_PUDR);
372 __raw_writel(mask, pio + (is_on ? PIO_PPDER : PIO_PPDDR));
373 return 0;
374}
375EXPORT_SYMBOL(at91_set_pulldown);
376
377/*
378 * disable Schmitt trigger
379 */
380int __init_or_module at91_disable_schmitt_trig(unsigned pin)
381{
382 void __iomem *pio = pin_to_controller(pin);
383 unsigned mask = pin_to_mask(pin);
384
385 if (!pio || !has_pio3())
386 return -EINVAL;
387
388 __raw_writel(__raw_readl(pio + PIO_SCHMITT) | mask, pio + PIO_SCHMITT);
389 return 0;
390}
391EXPORT_SYMBOL(at91_disable_schmitt_trig);
392
393/*
394 * assuming the pin is muxed as a gpio output, set its value.
395 */
396int at91_set_gpio_value(unsigned pin, int value)
397{
398 void __iomem *pio = pin_to_controller(pin);
399 unsigned mask = pin_to_mask(pin);
400
401 if (!pio)
402 return -EINVAL;
403 __raw_writel(mask, pio + (value ? PIO_SODR : PIO_CODR));
404 return 0;
405}
406EXPORT_SYMBOL(at91_set_gpio_value);
407
408
409/*
410 * read the pin's value (works even if it's not muxed as a gpio).
411 */
412int at91_get_gpio_value(unsigned pin)
413{
414 void __iomem *pio = pin_to_controller(pin);
415 unsigned mask = pin_to_mask(pin);
416 u32 pdsr;
417
418 if (!pio)
419 return -EINVAL;
420 pdsr = __raw_readl(pio + PIO_PDSR);
421 return (pdsr & mask) != 0;
422}
423EXPORT_SYMBOL(at91_get_gpio_value);
424
425/*--------------------------------------------------------------------------*/
426
427#ifdef CONFIG_PM
428
429static u32 wakeups[MAX_GPIO_BANKS];
430static u32 backups[MAX_GPIO_BANKS];
431
432static int gpio_irq_set_wake(struct irq_data *d, unsigned state)
433{
434 struct at91_gpio_chip *at91_gpio = irq_data_get_irq_chip_data(d);
435 unsigned mask = 1 << d->hwirq;
436 unsigned bank = at91_gpio->pioc_idx;
437
438 if (unlikely(bank >= MAX_GPIO_BANKS))
439 return -EINVAL;
440
441 if (state)
442 wakeups[bank] |= mask;
443 else
444 wakeups[bank] &= ~mask;
445
446 irq_set_irq_wake(at91_gpio->pioc_virq, state);
447
448 return 0;
449}
450
451void at91_gpio_suspend(void)
452{
453 int i;
454
455 for (i = 0; i < gpio_banks; i++) {
456 void __iomem *pio = gpio_chip[i].regbase;
457
458 backups[i] = __raw_readl(pio + PIO_IMR);
459 __raw_writel(backups[i], pio + PIO_IDR);
460 __raw_writel(wakeups[i], pio + PIO_IER);
461
462 if (!wakeups[i]) {
463 clk_unprepare(gpio_chip[i].clock);
464 clk_disable(gpio_chip[i].clock);
465 } else {
466#ifdef CONFIG_PM_DEBUG
467 printk(KERN_DEBUG "GPIO-%c may wake for %08x\n", 'A'+i, wakeups[i]);
468#endif
469 }
470 }
471}
472
473void at91_gpio_resume(void)
474{
475 int i;
476
477 for (i = 0; i < gpio_banks; i++) {
478 void __iomem *pio = gpio_chip[i].regbase;
479
480 if (!wakeups[i]) {
481 if (clk_prepare(gpio_chip[i].clock) == 0)
482 clk_enable(gpio_chip[i].clock);
483 }
484
485 __raw_writel(wakeups[i], pio + PIO_IDR);
486 __raw_writel(backups[i], pio + PIO_IER);
487 }
488}
489
490#else
491#define gpio_irq_set_wake NULL
492#endif
493
494
495/* Several AIC controller irqs are dispatched through this GPIO handler.
496 * To use any AT91_PIN_* as an externally triggered IRQ, first call
497 * at91_set_gpio_input() then maybe enable its glitch filter.
498 * Then just request_irq() with the pin ID; it works like any ARM IRQ
499 * handler.
500 * First implementation always triggers on rising and falling edges
501 * whereas the newer PIO3 can be additionally configured to trigger on
502 * level, edge with any polarity.
503 *
504 * Alternatively, certain pins may be used directly as IRQ0..IRQ6 after
505 * configuring them with at91_set_a_periph() or at91_set_b_periph().
506 * IRQ0..IRQ6 should be configurable, e.g. level vs edge triggering.
507 */
508
509static void gpio_irq_mask(struct irq_data *d)
510{
511 struct at91_gpio_chip *at91_gpio = irq_data_get_irq_chip_data(d);
512 void __iomem *pio = at91_gpio->regbase;
513 unsigned mask = 1 << d->hwirq;
514
515 if (pio)
516 __raw_writel(mask, pio + PIO_IDR);
517}
518
519static void gpio_irq_unmask(struct irq_data *d)
520{
521 struct at91_gpio_chip *at91_gpio = irq_data_get_irq_chip_data(d);
522 void __iomem *pio = at91_gpio->regbase;
523 unsigned mask = 1 << d->hwirq;
524
525 if (pio)
526 __raw_writel(mask, pio + PIO_IER);
527}
528
529static int gpio_irq_type(struct irq_data *d, unsigned type)
530{
531 switch (type) {
532 case IRQ_TYPE_NONE:
533 case IRQ_TYPE_EDGE_BOTH:
534 return 0;
535 default:
536 return -EINVAL;
537 }
538}
539
540/* Alternate irq type for PIO3 support */
541static int alt_gpio_irq_type(struct irq_data *d, unsigned type)
542{
543 struct at91_gpio_chip *at91_gpio = irq_data_get_irq_chip_data(d);
544 void __iomem *pio = at91_gpio->regbase;
545 unsigned mask = 1 << d->hwirq;
546
547 switch (type) {
548 case IRQ_TYPE_EDGE_RISING:
549 __raw_writel(mask, pio + PIO_ESR);
550 __raw_writel(mask, pio + PIO_REHLSR);
551 break;
552 case IRQ_TYPE_EDGE_FALLING:
553 __raw_writel(mask, pio + PIO_ESR);
554 __raw_writel(mask, pio + PIO_FELLSR);
555 break;
556 case IRQ_TYPE_LEVEL_LOW:
557 __raw_writel(mask, pio + PIO_LSR);
558 __raw_writel(mask, pio + PIO_FELLSR);
559 break;
560 case IRQ_TYPE_LEVEL_HIGH:
561 __raw_writel(mask, pio + PIO_LSR);
562 __raw_writel(mask, pio + PIO_REHLSR);
563 break;
564 case IRQ_TYPE_EDGE_BOTH:
565 /*
566 * disable additional interrupt modes:
567 * fall back to default behavior
568 */
569 __raw_writel(mask, pio + PIO_AIMDR);
570 return 0;
571 case IRQ_TYPE_NONE:
572 default:
573 pr_warn("AT91: No type for irq %d\n", gpio_to_irq(d->irq));
574 return -EINVAL;
575 }
576
577 /* enable additional interrupt modes */
578 __raw_writel(mask, pio + PIO_AIMER);
579
580 return 0;
581}
582
583static struct irq_chip gpio_irqchip = {
584 .name = "GPIO",
585 .irq_disable = gpio_irq_mask,
586 .irq_mask = gpio_irq_mask,
587 .irq_unmask = gpio_irq_unmask,
588 /* .irq_set_type is set dynamically */
589 .irq_set_wake = gpio_irq_set_wake,
590};
591
592static void gpio_irq_handler(unsigned irq, struct irq_desc *desc)
593{
594 struct irq_chip *chip = irq_desc_get_chip(desc);
595 struct irq_data *idata = irq_desc_get_irq_data(desc);
596 struct at91_gpio_chip *at91_gpio = irq_data_get_irq_chip_data(idata);
597 void __iomem *pio = at91_gpio->regbase;
598 unsigned long isr;
599 int n;
600
601 chained_irq_enter(chip, desc);
602 for (;;) {
603 /* Reading ISR acks pending (edge triggered) GPIO interrupts.
604 * When there none are pending, we're finished unless we need
605 * to process multiple banks (like ID_PIOCDE on sam9263).
606 */
607 isr = __raw_readl(pio + PIO_ISR) & __raw_readl(pio + PIO_IMR);
608 if (!isr) {
609 if (!at91_gpio->next)
610 break;
611 at91_gpio = at91_gpio->next;
612 pio = at91_gpio->regbase;
613 continue;
614 }
615
616 n = find_first_bit(&isr, BITS_PER_LONG);
617 while (n < BITS_PER_LONG) {
618 generic_handle_irq(irq_find_mapping(at91_gpio->domain, n));
619 n = find_next_bit(&isr, BITS_PER_LONG, n + 1);
620 }
621 }
622 chained_irq_exit(chip, desc);
623 /* now it may re-trigger */
624}
625
626/*--------------------------------------------------------------------------*/
627
628#ifdef CONFIG_DEBUG_FS
629
630static void gpio_printf(struct seq_file *s, void __iomem *pio, unsigned mask)
631{
632 char *trigger = NULL;
633 char *polarity = NULL;
634
635 if (__raw_readl(pio + PIO_IMR) & mask) {
636 if (!has_pio3() || !(__raw_readl(pio + PIO_AIMMR) & mask )) {
637 trigger = "edge";
638 polarity = "both";
639 } else {
640 if (__raw_readl(pio + PIO_ELSR) & mask) {
641 trigger = "level";
642 polarity = __raw_readl(pio + PIO_FRLHSR) & mask ?
643 "high" : "low";
644 } else {
645 trigger = "edge";
646 polarity = __raw_readl(pio + PIO_FRLHSR) & mask ?
647 "rising" : "falling";
648 }
649 }
650 seq_printf(s, "IRQ:%s-%s\t", trigger, polarity);
651 } else {
652 seq_printf(s, "GPIO:%s\t\t",
653 __raw_readl(pio + PIO_PDSR) & mask ? "1" : "0");
654 }
655}
656
657static int at91_gpio_show(struct seq_file *s, void *unused)
658{
659 int bank, j;
660
661 /* print heading */
662 seq_printf(s, "Pin\t");
663 for (bank = 0; bank < gpio_banks; bank++) {
664 seq_printf(s, "PIO%c\t\t", 'A' + bank);
665 };
666 seq_printf(s, "\n\n");
667
668 /* print pin status */
669 for (j = 0; j < 32; j++) {
670 seq_printf(s, "%i:\t", j);
671
672 for (bank = 0; bank < gpio_banks; bank++) {
673 unsigned pin = (32 * bank) + j;
674 void __iomem *pio = pin_to_controller(pin);
675 unsigned mask = pin_to_mask(pin);
676
677 if (__raw_readl(pio + PIO_PSR) & mask)
678 gpio_printf(s, pio, mask);
679 else
680 seq_printf(s, "%c\t\t",
681 peripheral_function(pio, mask));
682 }
683
684 seq_printf(s, "\n");
685 }
686
687 return 0;
688}
689
690static int at91_gpio_open(struct inode *inode, struct file *file)
691{
692 return single_open(file, at91_gpio_show, NULL);
693}
694
695static const struct file_operations at91_gpio_operations = {
696 .open = at91_gpio_open,
697 .read = seq_read,
698 .llseek = seq_lseek,
699 .release = single_release,
700};
701
702static int __init at91_gpio_debugfs_init(void)
703{
704 /* /sys/kernel/debug/at91_gpio */
705 (void) debugfs_create_file("at91_gpio", S_IFREG | S_IRUGO, NULL, NULL, &at91_gpio_operations);
706 return 0;
707}
708postcore_initcall(at91_gpio_debugfs_init);
709
710#endif
711
712/*--------------------------------------------------------------------------*/
713
714/*
715 * This lock class tells lockdep that GPIO irqs are in a different
716 * category than their parents, so it won't report false recursion.
717 */
718static struct lock_class_key gpio_lock_class;
719
720/*
721 * irqdomain initialization: pile up irqdomains on top of AIC range
722 */
723static void __init at91_gpio_irqdomain(struct at91_gpio_chip *at91_gpio)
724{
725 int irq_base;
726
727 irq_base = irq_alloc_descs(-1, 0, at91_gpio->chip.ngpio, 0);
728 if (irq_base < 0)
729 panic("at91_gpio.%d: error %d: couldn't allocate IRQ numbers.\n",
730 at91_gpio->pioc_idx, irq_base);
731 at91_gpio->domain = irq_domain_add_legacy(NULL, at91_gpio->chip.ngpio,
732 irq_base, 0,
733 &irq_domain_simple_ops, NULL);
734 if (!at91_gpio->domain)
735 panic("at91_gpio.%d: couldn't allocate irq domain.\n",
736 at91_gpio->pioc_idx);
737}
738
739/*
740 * Called from the processor-specific init to enable GPIO interrupt support.
741 */
742void __init at91_gpio_irq_setup(void)
743{
744 unsigned pioc;
745 int gpio_irqnbr = 0;
746 struct at91_gpio_chip *this, *prev;
747
748 /* Setup proper .irq_set_type function */
749 if (has_pio3())
750 gpio_irqchip.irq_set_type = alt_gpio_irq_type;
751 else
752 gpio_irqchip.irq_set_type = gpio_irq_type;
753
754 for (pioc = 0, this = gpio_chip, prev = NULL;
755 pioc++ < gpio_banks;
756 prev = this, this++) {
757 int offset;
758
759 __raw_writel(~0, this->regbase + PIO_IDR);
760
761 /* setup irq domain for this GPIO controller */
762 at91_gpio_irqdomain(this);
763
764 for (offset = 0; offset < this->chip.ngpio; offset++) {
765 unsigned int virq = irq_find_mapping(this->domain, offset);
766 irq_set_lockdep_class(virq, &gpio_lock_class);
767
768 /*
769 * Can use the "simple" and not "edge" handler since it's
770 * shorter, and the AIC handles interrupts sanely.
771 */
772 irq_set_chip_and_handler(virq, &gpio_irqchip,
773 handle_simple_irq);
774 set_irq_flags(virq, IRQF_VALID);
775 irq_set_chip_data(virq, this);
776
777 gpio_irqnbr++;
778 }
779
780 /* The toplevel handler handles one bank of GPIOs, except
781 * on some SoC it can handles up to three...
782 * We only set up the handler for the first of the list.
783 */
784 if (prev && prev->next == this)
785 continue;
786
787 this->pioc_virq = irq_create_mapping(NULL, this->pioc_hwirq);
788 irq_set_chip_data(this->pioc_virq, this);
789 irq_set_chained_handler(this->pioc_virq, gpio_irq_handler);
790 }
791 pr_info("AT91: %d gpio irqs in %d banks\n", gpio_irqnbr, gpio_banks);
792}
793
794/* gpiolib support */
795static int at91_gpiolib_request(struct gpio_chip *chip, unsigned offset)
796{
797 struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip);
798 void __iomem *pio = at91_gpio->regbase;
799 unsigned mask = 1 << offset;
800
801 __raw_writel(mask, pio + PIO_PER);
802 return 0;
803}
804
805static int at91_gpiolib_get_direction(struct gpio_chip *chip, unsigned offset)
806{
807 struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip);
808 void __iomem *pio = at91_gpio->regbase;
809 unsigned mask = 1 << offset;
810 u32 osr;
811
812 osr = __raw_readl(pio + PIO_OSR);
813 return !(osr & mask);
814}
815
816static int at91_gpiolib_direction_input(struct gpio_chip *chip,
817 unsigned offset)
818{
819 struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip);
820 void __iomem *pio = at91_gpio->regbase;
821 unsigned mask = 1 << offset;
822
823 __raw_writel(mask, pio + PIO_ODR);
824 return 0;
825}
826
827static int at91_gpiolib_direction_output(struct gpio_chip *chip,
828 unsigned offset, int val)
829{
830 struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip);
831 void __iomem *pio = at91_gpio->regbase;
832 unsigned mask = 1 << offset;
833
834 __raw_writel(mask, pio + (val ? PIO_SODR : PIO_CODR));
835 __raw_writel(mask, pio + PIO_OER);
836 return 0;
837}
838
839static int at91_gpiolib_get(struct gpio_chip *chip, unsigned offset)
840{
841 struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip);
842 void __iomem *pio = at91_gpio->regbase;
843 unsigned mask = 1 << offset;
844 u32 pdsr;
845
846 pdsr = __raw_readl(pio + PIO_PDSR);
847 return (pdsr & mask) != 0;
848}
849
850static void at91_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)
851{
852 struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip);
853 void __iomem *pio = at91_gpio->regbase;
854 unsigned mask = 1 << offset;
855
856 __raw_writel(mask, pio + (val ? PIO_SODR : PIO_CODR));
857}
858
859static void at91_gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *chip)
860{
861 int i;
862
863 for (i = 0; i < chip->ngpio; i++) {
864 unsigned pin = chip->base + i;
865 void __iomem *pio = pin_to_controller(pin);
866 unsigned mask = pin_to_mask(pin);
867 const char *gpio_label;
868
869 gpio_label = gpiochip_is_requested(chip, i);
870 if (gpio_label) {
871 seq_printf(s, "[%s] GPIO%s%d: ",
872 gpio_label, chip->label, i);
873 if (__raw_readl(pio + PIO_PSR) & mask)
874 seq_printf(s, "[gpio] %s\n",
875 at91_get_gpio_value(pin) ?
876 "set" : "clear");
877 else
878 seq_printf(s, "[periph %c]\n",
879 peripheral_function(pio, mask));
880 }
881 }
882}
883
884static int at91_gpiolib_to_irq(struct gpio_chip *chip, unsigned offset)
885{
886 struct at91_gpio_chip *at91_gpio = to_at91_gpio_chip(chip);
887 int virq;
888
889 if (offset < chip->ngpio)
890 virq = irq_create_mapping(at91_gpio->domain, offset);
891 else
892 virq = -ENXIO;
893
894 dev_dbg(chip->dev, "%s: request IRQ for GPIO %d, return %d\n",
895 chip->label, offset + chip->base, virq);
896 return virq;
897}
898
899static int __init at91_gpio_setup_clk(int idx)
900{
901 struct at91_gpio_chip *at91_gpio = &gpio_chip[idx];
902
903 /* retreive PIO controller's clock */
904 at91_gpio->clock = clk_get_sys(NULL, at91_gpio->chip.label);
905 if (IS_ERR(at91_gpio->clock)) {
906 pr_err("at91_gpio.%d, failed to get clock, ignoring.\n", idx);
907 goto err;
908 }
909
910 if (clk_prepare(at91_gpio->clock))
911 goto clk_prep_err;
912
913 /* enable PIO controller's clock */
914 if (clk_enable(at91_gpio->clock)) {
915 pr_err("at91_gpio.%d, failed to enable clock, ignoring.\n", idx);
916 goto clk_err;
917 }
918
919 return 0;
920
921clk_err:
922 clk_unprepare(at91_gpio->clock);
923clk_prep_err:
924 clk_put(at91_gpio->clock);
925err:
926 return -EINVAL;
927}
928
929static void __init at91_gpio_init_one(int idx, u32 regbase, int pioc_hwirq)
930{
931 struct at91_gpio_chip *at91_gpio = &gpio_chip[idx];
932
933 at91_gpio->chip.base = idx * MAX_NB_GPIO_PER_BANK;
934 at91_gpio->pioc_hwirq = pioc_hwirq;
935 at91_gpio->pioc_idx = idx;
936
937 at91_gpio->regbase = ioremap(regbase, 512);
938 if (!at91_gpio->regbase) {
939 pr_err("at91_gpio.%d, failed to map registers, ignoring.\n", idx);
940 return;
941 }
942
943 if (at91_gpio_setup_clk(idx))
944 goto ioremap_err;
945
946 gpio_banks = max(gpio_banks, idx + 1);
947 return;
948
949ioremap_err:
950 iounmap(at91_gpio->regbase);
951}
952
953/*
954 * Called from the processor-specific init to enable GPIO pin support.
955 */
956void __init at91_gpio_init(struct at91_gpio_bank *data, int nr_banks)
957{
958 unsigned i;
959 struct at91_gpio_chip *at91_gpio, *last = NULL;
960
961 BUG_ON(nr_banks > MAX_GPIO_BANKS);
962
963 if (of_have_populated_dt())
964 return;
965
966 for (i = 0; i < nr_banks; i++)
967 at91_gpio_init_one(i, data[i].regbase, data[i].id);
968
969 for (i = 0; i < gpio_banks; i++) {
970 at91_gpio = &gpio_chip[i];
971
972 /*
973 * GPIO controller are grouped on some SoC:
974 * PIOC, PIOD and PIOE can share the same IRQ line
975 */
976 if (last && last->pioc_hwirq == at91_gpio->pioc_hwirq)
977 last->next = at91_gpio;
978 last = at91_gpio;
979
980 gpiochip_add(&at91_gpio->chip);
981 }
982}
diff --git a/arch/arm/mach-at91/gpio.h b/arch/arm/mach-at91/gpio.h
deleted file mode 100644
index eed465ab0dd7..000000000000
--- a/arch/arm/mach-at91/gpio.h
+++ /dev/null
@@ -1,214 +0,0 @@
1/*
2 * arch/arm/mach-at91/include/mach/gpio.h
3 *
4 * Copyright (C) 2005 HP Labs
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12
13#ifndef __ASM_ARCH_AT91RM9200_GPIO_H
14#define __ASM_ARCH_AT91RM9200_GPIO_H
15
16#include <linux/kernel.h>
17#include <asm/irq.h>
18
19#define MAX_GPIO_BANKS 5
20#define NR_BUILTIN_GPIO (MAX_GPIO_BANKS * 32)
21
22/* these pin numbers double as IRQ numbers, like AT91xxx_ID_* values */
23
24#define AT91_PIN_PA0 (0x00 + 0)
25#define AT91_PIN_PA1 (0x00 + 1)
26#define AT91_PIN_PA2 (0x00 + 2)
27#define AT91_PIN_PA3 (0x00 + 3)
28#define AT91_PIN_PA4 (0x00 + 4)
29#define AT91_PIN_PA5 (0x00 + 5)
30#define AT91_PIN_PA6 (0x00 + 6)
31#define AT91_PIN_PA7 (0x00 + 7)
32#define AT91_PIN_PA8 (0x00 + 8)
33#define AT91_PIN_PA9 (0x00 + 9)
34#define AT91_PIN_PA10 (0x00 + 10)
35#define AT91_PIN_PA11 (0x00 + 11)
36#define AT91_PIN_PA12 (0x00 + 12)
37#define AT91_PIN_PA13 (0x00 + 13)
38#define AT91_PIN_PA14 (0x00 + 14)
39#define AT91_PIN_PA15 (0x00 + 15)
40#define AT91_PIN_PA16 (0x00 + 16)
41#define AT91_PIN_PA17 (0x00 + 17)
42#define AT91_PIN_PA18 (0x00 + 18)
43#define AT91_PIN_PA19 (0x00 + 19)
44#define AT91_PIN_PA20 (0x00 + 20)
45#define AT91_PIN_PA21 (0x00 + 21)
46#define AT91_PIN_PA22 (0x00 + 22)
47#define AT91_PIN_PA23 (0x00 + 23)
48#define AT91_PIN_PA24 (0x00 + 24)
49#define AT91_PIN_PA25 (0x00 + 25)
50#define AT91_PIN_PA26 (0x00 + 26)
51#define AT91_PIN_PA27 (0x00 + 27)
52#define AT91_PIN_PA28 (0x00 + 28)
53#define AT91_PIN_PA29 (0x00 + 29)
54#define AT91_PIN_PA30 (0x00 + 30)
55#define AT91_PIN_PA31 (0x00 + 31)
56
57#define AT91_PIN_PB0 (0x20 + 0)
58#define AT91_PIN_PB1 (0x20 + 1)
59#define AT91_PIN_PB2 (0x20 + 2)
60#define AT91_PIN_PB3 (0x20 + 3)
61#define AT91_PIN_PB4 (0x20 + 4)
62#define AT91_PIN_PB5 (0x20 + 5)
63#define AT91_PIN_PB6 (0x20 + 6)
64#define AT91_PIN_PB7 (0x20 + 7)
65#define AT91_PIN_PB8 (0x20 + 8)
66#define AT91_PIN_PB9 (0x20 + 9)
67#define AT91_PIN_PB10 (0x20 + 10)
68#define AT91_PIN_PB11 (0x20 + 11)
69#define AT91_PIN_PB12 (0x20 + 12)
70#define AT91_PIN_PB13 (0x20 + 13)
71#define AT91_PIN_PB14 (0x20 + 14)
72#define AT91_PIN_PB15 (0x20 + 15)
73#define AT91_PIN_PB16 (0x20 + 16)
74#define AT91_PIN_PB17 (0x20 + 17)
75#define AT91_PIN_PB18 (0x20 + 18)
76#define AT91_PIN_PB19 (0x20 + 19)
77#define AT91_PIN_PB20 (0x20 + 20)
78#define AT91_PIN_PB21 (0x20 + 21)
79#define AT91_PIN_PB22 (0x20 + 22)
80#define AT91_PIN_PB23 (0x20 + 23)
81#define AT91_PIN_PB24 (0x20 + 24)
82#define AT91_PIN_PB25 (0x20 + 25)
83#define AT91_PIN_PB26 (0x20 + 26)
84#define AT91_PIN_PB27 (0x20 + 27)
85#define AT91_PIN_PB28 (0x20 + 28)
86#define AT91_PIN_PB29 (0x20 + 29)
87#define AT91_PIN_PB30 (0x20 + 30)
88#define AT91_PIN_PB31 (0x20 + 31)
89
90#define AT91_PIN_PC0 (0x40 + 0)
91#define AT91_PIN_PC1 (0x40 + 1)
92#define AT91_PIN_PC2 (0x40 + 2)
93#define AT91_PIN_PC3 (0x40 + 3)
94#define AT91_PIN_PC4 (0x40 + 4)
95#define AT91_PIN_PC5 (0x40 + 5)
96#define AT91_PIN_PC6 (0x40 + 6)
97#define AT91_PIN_PC7 (0x40 + 7)
98#define AT91_PIN_PC8 (0x40 + 8)
99#define AT91_PIN_PC9 (0x40 + 9)
100#define AT91_PIN_PC10 (0x40 + 10)
101#define AT91_PIN_PC11 (0x40 + 11)
102#define AT91_PIN_PC12 (0x40 + 12)
103#define AT91_PIN_PC13 (0x40 + 13)
104#define AT91_PIN_PC14 (0x40 + 14)
105#define AT91_PIN_PC15 (0x40 + 15)
106#define AT91_PIN_PC16 (0x40 + 16)
107#define AT91_PIN_PC17 (0x40 + 17)
108#define AT91_PIN_PC18 (0x40 + 18)
109#define AT91_PIN_PC19 (0x40 + 19)
110#define AT91_PIN_PC20 (0x40 + 20)
111#define AT91_PIN_PC21 (0x40 + 21)
112#define AT91_PIN_PC22 (0x40 + 22)
113#define AT91_PIN_PC23 (0x40 + 23)
114#define AT91_PIN_PC24 (0x40 + 24)
115#define AT91_PIN_PC25 (0x40 + 25)
116#define AT91_PIN_PC26 (0x40 + 26)
117#define AT91_PIN_PC27 (0x40 + 27)
118#define AT91_PIN_PC28 (0x40 + 28)
119#define AT91_PIN_PC29 (0x40 + 29)
120#define AT91_PIN_PC30 (0x40 + 30)
121#define AT91_PIN_PC31 (0x40 + 31)
122
123#define AT91_PIN_PD0 (0x60 + 0)
124#define AT91_PIN_PD1 (0x60 + 1)
125#define AT91_PIN_PD2 (0x60 + 2)
126#define AT91_PIN_PD3 (0x60 + 3)
127#define AT91_PIN_PD4 (0x60 + 4)
128#define AT91_PIN_PD5 (0x60 + 5)
129#define AT91_PIN_PD6 (0x60 + 6)
130#define AT91_PIN_PD7 (0x60 + 7)
131#define AT91_PIN_PD8 (0x60 + 8)
132#define AT91_PIN_PD9 (0x60 + 9)
133#define AT91_PIN_PD10 (0x60 + 10)
134#define AT91_PIN_PD11 (0x60 + 11)
135#define AT91_PIN_PD12 (0x60 + 12)
136#define AT91_PIN_PD13 (0x60 + 13)
137#define AT91_PIN_PD14 (0x60 + 14)
138#define AT91_PIN_PD15 (0x60 + 15)
139#define AT91_PIN_PD16 (0x60 + 16)
140#define AT91_PIN_PD17 (0x60 + 17)
141#define AT91_PIN_PD18 (0x60 + 18)
142#define AT91_PIN_PD19 (0x60 + 19)
143#define AT91_PIN_PD20 (0x60 + 20)
144#define AT91_PIN_PD21 (0x60 + 21)
145#define AT91_PIN_PD22 (0x60 + 22)
146#define AT91_PIN_PD23 (0x60 + 23)
147#define AT91_PIN_PD24 (0x60 + 24)
148#define AT91_PIN_PD25 (0x60 + 25)
149#define AT91_PIN_PD26 (0x60 + 26)
150#define AT91_PIN_PD27 (0x60 + 27)
151#define AT91_PIN_PD28 (0x60 + 28)
152#define AT91_PIN_PD29 (0x60 + 29)
153#define AT91_PIN_PD30 (0x60 + 30)
154#define AT91_PIN_PD31 (0x60 + 31)
155
156#define AT91_PIN_PE0 (0x80 + 0)
157#define AT91_PIN_PE1 (0x80 + 1)
158#define AT91_PIN_PE2 (0x80 + 2)
159#define AT91_PIN_PE3 (0x80 + 3)
160#define AT91_PIN_PE4 (0x80 + 4)
161#define AT91_PIN_PE5 (0x80 + 5)
162#define AT91_PIN_PE6 (0x80 + 6)
163#define AT91_PIN_PE7 (0x80 + 7)
164#define AT91_PIN_PE8 (0x80 + 8)
165#define AT91_PIN_PE9 (0x80 + 9)
166#define AT91_PIN_PE10 (0x80 + 10)
167#define AT91_PIN_PE11 (0x80 + 11)
168#define AT91_PIN_PE12 (0x80 + 12)
169#define AT91_PIN_PE13 (0x80 + 13)
170#define AT91_PIN_PE14 (0x80 + 14)
171#define AT91_PIN_PE15 (0x80 + 15)
172#define AT91_PIN_PE16 (0x80 + 16)
173#define AT91_PIN_PE17 (0x80 + 17)
174#define AT91_PIN_PE18 (0x80 + 18)
175#define AT91_PIN_PE19 (0x80 + 19)
176#define AT91_PIN_PE20 (0x80 + 20)
177#define AT91_PIN_PE21 (0x80 + 21)
178#define AT91_PIN_PE22 (0x80 + 22)
179#define AT91_PIN_PE23 (0x80 + 23)
180#define AT91_PIN_PE24 (0x80 + 24)
181#define AT91_PIN_PE25 (0x80 + 25)
182#define AT91_PIN_PE26 (0x80 + 26)
183#define AT91_PIN_PE27 (0x80 + 27)
184#define AT91_PIN_PE28 (0x80 + 28)
185#define AT91_PIN_PE29 (0x80 + 29)
186#define AT91_PIN_PE30 (0x80 + 30)
187#define AT91_PIN_PE31 (0x80 + 31)
188
189#ifndef __ASSEMBLY__
190/* setup setup routines, called from board init or driver probe() */
191extern int __init_or_module at91_set_GPIO_periph(unsigned pin, int use_pullup);
192extern int __init_or_module at91_set_A_periph(unsigned pin, int use_pullup);
193extern int __init_or_module at91_set_B_periph(unsigned pin, int use_pullup);
194extern int __init_or_module at91_set_C_periph(unsigned pin, int use_pullup);
195extern int __init_or_module at91_set_D_periph(unsigned pin, int use_pullup);
196extern int __init_or_module at91_set_gpio_input(unsigned pin, int use_pullup);
197extern int __init_or_module at91_set_gpio_output(unsigned pin, int value);
198extern int __init_or_module at91_set_deglitch(unsigned pin, int is_on);
199extern int __init_or_module at91_set_debounce(unsigned pin, int is_on, int div);
200extern int __init_or_module at91_set_multi_drive(unsigned pin, int is_on);
201extern int __init_or_module at91_set_pulldown(unsigned pin, int is_on);
202extern int __init_or_module at91_disable_schmitt_trig(unsigned pin);
203
204/* callable at any time */
205extern int at91_set_gpio_value(unsigned pin, int value);
206extern int at91_get_gpio_value(unsigned pin);
207
208/* callable only from core power-management code */
209extern void at91_gpio_suspend(void);
210extern void at91_gpio_resume(void);
211
212#endif /* __ASSEMBLY__ */
213
214#endif
diff --git a/arch/arm/mach-at91/gsia18s.h b/arch/arm/mach-at91/gsia18s.h
deleted file mode 100644
index 307c194926f9..000000000000
--- a/arch/arm/mach-at91/gsia18s.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/* Buttons */
2#define GPIO_TRIG_NET_IN AT91_PIN_PB21
3#define GPIO_CARD_UNMOUNT_0 AT91_PIN_PB13
4#define GPIO_CARD_UNMOUNT_1 AT91_PIN_PB12
5#define GPIO_KEY_POWER AT91_PIN_PA25
6
7/* PCF8574 0x20 GPIO - U1 on the GS_IA18-CB_V3 board */
8#define GS_IA18_S_PCF_GPIO_BASE0 NR_BUILTIN_GPIO
9#define PCF_GPIO_HDC_POWER (GS_IA18_S_PCF_GPIO_BASE0 + 0)
10#define PCF_GPIO_WIFI_SETUP (GS_IA18_S_PCF_GPIO_BASE0 + 1)
11#define PCF_GPIO_WIFI_ENABLE (GS_IA18_S_PCF_GPIO_BASE0 + 2)
12#define PCF_GPIO_WIFI_RESET (GS_IA18_S_PCF_GPIO_BASE0 + 3)
13#define PCF_GPIO_ETH_DETECT 4 /* this is a GPI */
14#define PCF_GPIO_GPS_SETUP (GS_IA18_S_PCF_GPIO_BASE0 + 5)
15#define PCF_GPIO_GPS_STANDBY (GS_IA18_S_PCF_GPIO_BASE0 + 6)
16#define PCF_GPIO_GPS_POWER (GS_IA18_S_PCF_GPIO_BASE0 + 7)
17
18/* PCF8574 0x22 GPIO - U1 on the GS_2G_OPT1-A_V0 board (Alarm) */
19#define GS_IA18_S_PCF_GPIO_BASE1 (GS_IA18_S_PCF_GPIO_BASE0 + 8)
20#define PCF_GPIO_ALARM1 (GS_IA18_S_PCF_GPIO_BASE1 + 0)
21#define PCF_GPIO_ALARM2 (GS_IA18_S_PCF_GPIO_BASE1 + 1)
22#define PCF_GPIO_ALARM3 (GS_IA18_S_PCF_GPIO_BASE1 + 2)
23#define PCF_GPIO_ALARM4 (GS_IA18_S_PCF_GPIO_BASE1 + 3)
24/* bits 4, 5, 6 not used */
25#define PCF_GPIO_ALARM_V_RELAY_ON (GS_IA18_S_PCF_GPIO_BASE1 + 7)
26
27/* PCF8574 0x24 GPIO U1 on the GS_2G-OPT23-A_V0 board (Modem) */
28#define GS_IA18_S_PCF_GPIO_BASE2 (GS_IA18_S_PCF_GPIO_BASE1 + 8)
29#define PCF_GPIO_MODEM_POWER (GS_IA18_S_PCF_GPIO_BASE2 + 0)
30#define PCF_GPIO_MODEM_RESET (GS_IA18_S_PCF_GPIO_BASE2 + 3)
31/* bits 1, 2, 4, 5 not used */
32#define PCF_GPIO_TRX_RESET (GS_IA18_S_PCF_GPIO_BASE2 + 6)
33/* bit 7 not used */
diff --git a/arch/arm/mach-at91/include/mach/at91_dbgu.h b/arch/arm/mach-at91/include/mach/at91_dbgu.h
index 3b5948566e52..42925e8f78e4 100644
--- a/arch/arm/mach-at91/include/mach/at91_dbgu.h
+++ b/arch/arm/mach-at91/include/mach/at91_dbgu.h
@@ -16,7 +16,6 @@
16#ifndef AT91_DBGU_H 16#ifndef AT91_DBGU_H
17#define AT91_DBGU_H 17#define AT91_DBGU_H
18 18
19#if !defined(CONFIG_ARCH_AT91X40)
20#define AT91_DBGU_CR (0x00) /* Control Register */ 19#define AT91_DBGU_CR (0x00) /* Control Register */
21#define AT91_DBGU_MR (0x04) /* Mode Register */ 20#define AT91_DBGU_MR (0x04) /* Mode Register */
22#define AT91_DBGU_IER (0x08) /* Interrupt Enable Register */ 21#define AT91_DBGU_IER (0x08) /* Interrupt Enable Register */
@@ -34,8 +33,6 @@
34#define AT91_DBGU_FNR (0x48) /* Force NTRST Register [SAM9 only] */ 33#define AT91_DBGU_FNR (0x48) /* Force NTRST Register [SAM9 only] */
35#define AT91_DBGU_FNTRST (1 << 0) /* Force NTRST */ 34#define AT91_DBGU_FNTRST (1 << 0) /* Force NTRST */
36 35
37#endif /* AT91_DBGU */
38
39/* 36/*
40 * Some AT91 parts that don't have full DEBUG units still support the ID 37 * Some AT91 parts that don't have full DEBUG units still support the ID
41 * and extensions register. 38 * and extensions register.
diff --git a/arch/arm/mach-at91/include/mach/at91_ramc.h b/arch/arm/mach-at91/include/mach/at91_ramc.h
index d8aeb278614e..e4492b151fee 100644
--- a/arch/arm/mach-at91/include/mach/at91_ramc.h
+++ b/arch/arm/mach-at91/include/mach/at91_ramc.h
@@ -25,8 +25,8 @@ extern void __iomem *at91_ramc_base[];
25#define AT91_MEMCTRL_SDRAMC 1 25#define AT91_MEMCTRL_SDRAMC 1
26#define AT91_MEMCTRL_DDRSDR 2 26#define AT91_MEMCTRL_DDRSDR 2
27 27
28#include <mach/at91rm9200_sdramc.h> 28#include <soc/at91/at91rm9200_sdramc.h>
29#include <mach/at91sam9_ddrsdr.h> 29#include <soc/at91/at91sam9_ddrsdr.h>
30#include <mach/at91sam9_sdramc.h> 30#include <soc/at91/at91sam9_sdramc.h>
31 31
32#endif /* __AT91_RAMC_H__ */ 32#endif /* __AT91_RAMC_H__ */
diff --git a/arch/arm/mach-at91/include/mach/at91x40.h b/arch/arm/mach-at91/include/mach/at91x40.h
deleted file mode 100644
index 38dca2bb027f..000000000000
--- a/arch/arm/mach-at91/include/mach/at91x40.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * arch/arm/mach-at91/include/mach/at91x40.h
3 *
4 * (C) Copyright 2007, Greg Ungerer <gerg@snapgear.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 as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#ifndef AT91X40_H
13#define AT91X40_H
14
15/*
16 * IRQ list.
17 */
18#define AT91X40_ID_USART0 2 /* USART port 0 */
19#define AT91X40_ID_USART1 3 /* USART port 1 */
20#define AT91X40_ID_TC0 4 /* Timer/Counter 0 */
21#define AT91X40_ID_TC1 5 /* Timer/Counter 1*/
22#define AT91X40_ID_TC2 6 /* Timer/Counter 2*/
23#define AT91X40_ID_WD 7 /* Watchdog? */
24#define AT91X40_ID_PIOA 8 /* Parallel IO Controller A */
25
26#define AT91X40_ID_IRQ0 16 /* External IRQ 0 */
27#define AT91X40_ID_IRQ1 17 /* External IRQ 1 */
28#define AT91X40_ID_IRQ2 18 /* External IRQ 2 */
29
30/*
31 * System Peripherals
32 */
33#define AT91_BASE_SYS 0xffc00000
34
35#define AT91_EBI 0xffe00000 /* External Bus Interface */
36#define AT91_SF 0xfff00000 /* Special Function */
37#define AT91_USART1 0xfffcc000 /* USART 1 */
38#define AT91_USART0 0xfffd0000 /* USART 0 */
39#define AT91_TC 0xfffe0000 /* Timer Counter */
40#define AT91_PIOA 0xffff0000 /* PIO Controller A */
41#define AT91_PS 0xffff4000 /* Power Save */
42#define AT91_WD 0xffff8000 /* Watchdog Timer */
43
44/*
45 * The AT91x40 series doesn't have a debug unit like the other AT91 parts.
46 * But it does have a chip identify register and extension ID, so define at
47 * least these here.
48 */
49#define AT91_DBGU_CIDR (AT91_SF + 0) /* CIDR in PS segment */
50#define AT91_DBGU_EXID (AT91_SF + 4) /* EXID in PS segment */
51
52/*
53 * Support defines for the simple Power Controller module.
54 */
55#define AT91_PS_CR (AT91_PS + 0) /* PS Control register */
56#define AT91_PS_CR_CPU (1 << 0) /* CPU clock disable bit */
57
58#define AT91X40_MASTER_CLOCK 40000000
59
60#endif /* AT91X40_H */
diff --git a/arch/arm/mach-at91/include/mach/cpu.h b/arch/arm/mach-at91/include/mach/cpu.h
index b27e9ca65653..61914fb35f5d 100644
--- a/arch/arm/mach-at91/include/mach/cpu.h
+++ b/arch/arm/mach-at91/include/mach/cpu.h
@@ -62,7 +62,6 @@
62#define ARCH_EXID_SAMA5D43 0x00000003 62#define ARCH_EXID_SAMA5D43 0x00000003
63#define ARCH_EXID_SAMA5D44 0x00000004 63#define ARCH_EXID_SAMA5D44 0x00000004
64 64
65#define ARCH_FAMILY_AT91X92 0x09200000
66#define ARCH_FAMILY_AT91SAM9 0x01900000 65#define ARCH_FAMILY_AT91SAM9 0x01900000
67#define ARCH_FAMILY_AT91SAM9XE 0x02900000 66#define ARCH_FAMILY_AT91SAM9XE 0x02900000
68 67
diff --git a/arch/arm/mach-at91/include/mach/hardware.h b/arch/arm/mach-at91/include/mach/hardware.h
index c13797352688..cacbaa52418f 100644
--- a/arch/arm/mach-at91/include/mach/hardware.h
+++ b/arch/arm/mach-at91/include/mach/hardware.h
@@ -24,9 +24,6 @@
24/* sama5d4 */ 24/* sama5d4 */
25#define AT91_BASE_DBGU2 0xfc069000 25#define AT91_BASE_DBGU2 0xfc069000
26 26
27#if defined(CONFIG_ARCH_AT91X40)
28#include <mach/at91x40.h>
29#else
30#include <mach/at91rm9200.h> 27#include <mach/at91rm9200.h>
31#include <mach/at91sam9260.h> 28#include <mach/at91sam9260.h>
32#include <mach/at91sam9261.h> 29#include <mach/at91sam9261.h>
@@ -51,8 +48,6 @@
51 */ 48 */
52#define AT91_BASE_SYS 0xffffc000 49#define AT91_BASE_SYS 0xffffc000
53 50
54#endif
55
56/* 51/*
57 * On sama5d4 there is no system controller, we map some needed peripherals 52 * On sama5d4 there is no system controller, we map some needed peripherals
58 */ 53 */
@@ -132,13 +127,8 @@
132 * called as part of the generic suspend/resume path. 127 * called as part of the generic suspend/resume path.
133 */ 128 */
134#ifndef __ASSEMBLY__ 129#ifndef __ASSEMBLY__
135#ifdef CONFIG_PINCTRL_AT91
136extern void at91_pinctrl_gpio_suspend(void); 130extern void at91_pinctrl_gpio_suspend(void);
137extern void at91_pinctrl_gpio_resume(void); 131extern void at91_pinctrl_gpio_resume(void);
138#else
139static inline void at91_pinctrl_gpio_suspend(void) {}
140static inline void at91_pinctrl_gpio_resume(void) {}
141#endif
142#endif 132#endif
143 133
144#endif 134#endif
diff --git a/arch/arm/mach-at91/include/mach/uncompress.h b/arch/arm/mach-at91/include/mach/uncompress.h
index acb2d890ad7e..4ebb609369e3 100644
--- a/arch/arm/mach-at91/include/mach/uncompress.h
+++ b/arch/arm/mach-at91/include/mach/uncompress.h
@@ -31,7 +31,6 @@
31 31
32void __iomem *at91_uart; 32void __iomem *at91_uart;
33 33
34#if !defined(CONFIG_ARCH_AT91X40)
35static const u32 uarts_rm9200[] = { 34static const u32 uarts_rm9200[] = {
36 AT91_BASE_DBGU0, 35 AT91_BASE_DBGU0,
37 AT91RM9200_BASE_US0, 36 AT91RM9200_BASE_US0,
@@ -188,12 +187,6 @@ static inline void arch_decomp_setup(void)
188 187
189 at91_uart = NULL; 188 at91_uart = NULL;
190} 189}
191#else
192static inline void arch_decomp_setup(void)
193{
194 at91_uart = NULL;
195}
196#endif
197 190
198/* 191/*
199 * The following code assumes the serial port has already been 192 * The following code assumes the serial port has already been
diff --git a/arch/arm/mach-at91/irq.c b/arch/arm/mach-at91/irq.c
deleted file mode 100644
index cdb3ec9efd2b..000000000000
--- a/arch/arm/mach-at91/irq.c
+++ /dev/null
@@ -1,296 +0,0 @@
1/*
2 * linux/arch/arm/mach-at91/irq.c
3 *
4 * Copyright (C) 2004 SAN People
5 * Copyright (C) 2004 ATMEL
6 * Copyright (C) Rick Bronson
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/mm.h>
26#include <linux/bitmap.h>
27#include <linux/types.h>
28#include <linux/irq.h>
29#include <linux/of.h>
30#include <linux/of_address.h>
31#include <linux/of_irq.h>
32#include <linux/irqdomain.h>
33#include <linux/err.h>
34#include <linux/slab.h>
35
36#include <mach/hardware.h>
37#include <asm/irq.h>
38#include <asm/setup.h>
39
40#include <asm/exception.h>
41#include <asm/mach/arch.h>
42#include <asm/mach/irq.h>
43#include <asm/mach/map.h>
44
45#include "at91_aic.h"
46
47void __iomem *at91_aic_base;
48static struct irq_domain *at91_aic_domain;
49static struct device_node *at91_aic_np;
50static unsigned int n_irqs = NR_AIC_IRQS;
51
52#ifdef CONFIG_PM
53
54static unsigned long *wakeups;
55static unsigned long *backups;
56
57#define set_backup(bit) set_bit(bit, backups)
58#define clear_backup(bit) clear_bit(bit, backups)
59
60static int at91_aic_pm_init(void)
61{
62 backups = kzalloc(BITS_TO_LONGS(n_irqs) * sizeof(*backups), GFP_KERNEL);
63 if (!backups)
64 return -ENOMEM;
65
66 wakeups = kzalloc(BITS_TO_LONGS(n_irqs) * sizeof(*backups), GFP_KERNEL);
67 if (!wakeups) {
68 kfree(backups);
69 return -ENOMEM;
70 }
71
72 return 0;
73}
74
75static int at91_aic_set_wake(struct irq_data *d, unsigned value)
76{
77 if (unlikely(d->hwirq >= n_irqs))
78 return -EINVAL;
79
80 if (value)
81 set_bit(d->hwirq, wakeups);
82 else
83 clear_bit(d->hwirq, wakeups);
84
85 return 0;
86}
87
88void at91_irq_suspend(void)
89{
90 at91_aic_write(AT91_AIC_IDCR, *backups);
91 at91_aic_write(AT91_AIC_IECR, *wakeups);
92}
93
94void at91_irq_resume(void)
95{
96 at91_aic_write(AT91_AIC_IDCR, *wakeups);
97 at91_aic_write(AT91_AIC_IECR, *backups);
98}
99
100#else
101static inline int at91_aic_pm_init(void)
102{
103 return 0;
104}
105
106#define set_backup(bit)
107#define clear_backup(bit)
108#define at91_aic_set_wake NULL
109
110#endif /* CONFIG_PM */
111
112asmlinkage void __exception_irq_entry
113at91_aic_handle_irq(struct pt_regs *regs)
114{
115 u32 irqnr;
116 u32 irqstat;
117
118 irqnr = at91_aic_read(AT91_AIC_IVR);
119 irqstat = at91_aic_read(AT91_AIC_ISR);
120
121 /*
122 * ISR value is 0 when there is no current interrupt or when there is
123 * a spurious interrupt
124 */
125 if (!irqstat)
126 at91_aic_write(AT91_AIC_EOICR, 0);
127 else
128 handle_IRQ(irqnr, regs);
129}
130
131static void at91_aic_mask_irq(struct irq_data *d)
132{
133 /* Disable interrupt on AIC */
134 at91_aic_write(AT91_AIC_IDCR, 1 << d->hwirq);
135 /* Update ISR cache */
136 clear_backup(d->hwirq);
137}
138
139static void at91_aic_unmask_irq(struct irq_data *d)
140{
141 /* Enable interrupt on AIC */
142 at91_aic_write(AT91_AIC_IECR, 1 << d->hwirq);
143 /* Update ISR cache */
144 set_backup(d->hwirq);
145}
146
147static void at91_aic_eoi(struct irq_data *d)
148{
149 /*
150 * Mark end-of-interrupt on AIC, the controller doesn't care about
151 * the value written. Moreover it's a write-only register.
152 */
153 at91_aic_write(AT91_AIC_EOICR, 0);
154}
155
156static unsigned long *at91_extern_irq;
157
158u32 at91_get_extern_irq(void)
159{
160 if (!at91_extern_irq)
161 return 0;
162 return *at91_extern_irq;
163}
164
165#define is_extern_irq(hwirq) test_bit(hwirq, at91_extern_irq)
166
167static int at91_aic_compute_srctype(struct irq_data *d, unsigned type)
168{
169 int srctype;
170
171 switch (type) {
172 case IRQ_TYPE_LEVEL_HIGH:
173 srctype = AT91_AIC_SRCTYPE_HIGH;
174 break;
175 case IRQ_TYPE_EDGE_RISING:
176 srctype = AT91_AIC_SRCTYPE_RISING;
177 break;
178 case IRQ_TYPE_LEVEL_LOW:
179 if ((d->hwirq == AT91_ID_FIQ) || is_extern_irq(d->hwirq)) /* only supported on external interrupts */
180 srctype = AT91_AIC_SRCTYPE_LOW;
181 else
182 srctype = -EINVAL;
183 break;
184 case IRQ_TYPE_EDGE_FALLING:
185 if ((d->hwirq == AT91_ID_FIQ) || is_extern_irq(d->hwirq)) /* only supported on external interrupts */
186 srctype = AT91_AIC_SRCTYPE_FALLING;
187 else
188 srctype = -EINVAL;
189 break;
190 default:
191 srctype = -EINVAL;
192 }
193
194 return srctype;
195}
196
197static int at91_aic_set_type(struct irq_data *d, unsigned type)
198{
199 unsigned int smr;
200 int srctype;
201
202 srctype = at91_aic_compute_srctype(d, type);
203 if (srctype < 0)
204 return srctype;
205
206 smr = at91_aic_read(AT91_AIC_SMR(d->hwirq)) & ~AT91_AIC_SRCTYPE;
207 at91_aic_write(AT91_AIC_SMR(d->hwirq), smr | srctype);
208
209 return 0;
210}
211
212static struct irq_chip at91_aic_chip = {
213 .name = "AIC",
214 .irq_mask = at91_aic_mask_irq,
215 .irq_unmask = at91_aic_unmask_irq,
216 .irq_set_type = at91_aic_set_type,
217 .irq_set_wake = at91_aic_set_wake,
218 .irq_eoi = at91_aic_eoi,
219};
220
221static void __init at91_aic_hw_init(unsigned int spu_vector)
222{
223 int i;
224
225 /*
226 * Perform 8 End Of Interrupt Command to make sure AIC
227 * will not Lock out nIRQ
228 */
229 for (i = 0; i < 8; i++)
230 at91_aic_write(AT91_AIC_EOICR, 0);
231
232 /*
233 * Spurious Interrupt ID in Spurious Vector Register.
234 * When there is no current interrupt, the IRQ Vector Register
235 * reads the value stored in AIC_SPU
236 */
237 at91_aic_write(AT91_AIC_SPU, spu_vector);
238
239 /* No debugging in AIC: Debug (Protect) Control Register */
240 at91_aic_write(AT91_AIC_DCR, 0);
241
242 /* Disable and clear all interrupts initially */
243 at91_aic_write(AT91_AIC_IDCR, 0xFFFFFFFF);
244 at91_aic_write(AT91_AIC_ICCR, 0xFFFFFFFF);
245}
246
247/*
248 * Initialize the AIC interrupt controller.
249 */
250void __init at91_aic_init(unsigned int *priority, unsigned int ext_irq_mask)
251{
252 unsigned int i;
253 int irq_base;
254
255 at91_extern_irq = kzalloc(BITS_TO_LONGS(n_irqs)
256 * sizeof(*at91_extern_irq), GFP_KERNEL);
257
258 if (at91_aic_pm_init() || at91_extern_irq == NULL)
259 panic("Unable to allocate bit maps\n");
260
261 *at91_extern_irq = ext_irq_mask;
262
263 at91_aic_base = ioremap(AT91_AIC, 512);
264 if (!at91_aic_base)
265 panic("Unable to ioremap AIC registers\n");
266
267 /* Add irq domain for AIC */
268 irq_base = irq_alloc_descs(-1, 0, n_irqs, 0);
269 if (irq_base < 0) {
270 WARN(1, "Cannot allocate irq_descs, assuming pre-allocated\n");
271 irq_base = 0;
272 }
273 at91_aic_domain = irq_domain_add_legacy(at91_aic_np, n_irqs,
274 irq_base, 0,
275 &irq_domain_simple_ops, NULL);
276
277 if (!at91_aic_domain)
278 panic("Unable to add AIC irq domain\n");
279
280 irq_set_default_host(at91_aic_domain);
281
282 /*
283 * The IVR is used by macro get_irqnr_and_base to read and verify.
284 * The irq number is NR_AIC_IRQS when a spurious interrupt has occurred.
285 */
286 for (i = 0; i < n_irqs; i++) {
287 /* Put hardware irq number in Source Vector Register: */
288 at91_aic_write(AT91_AIC_SVR(i), NR_IRQS_LEGACY + i);
289 /* Active Low interrupt, with the specified priority */
290 at91_aic_write(AT91_AIC_SMR(i), AT91_AIC_SRCTYPE_LOW | priority[i]);
291 irq_set_chip_and_handler(NR_IRQS_LEGACY + i, &at91_aic_chip, handle_fasteoi_irq);
292 set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
293 }
294
295 at91_aic_hw_init(n_irqs);
296}
diff --git a/arch/arm/mach-at91/leds.c b/arch/arm/mach-at91/leds.c
deleted file mode 100644
index eb22e3357e87..000000000000
--- a/arch/arm/mach-at91/leds.c
+++ /dev/null
@@ -1,56 +0,0 @@
1/*
2 * LED driver for Atmel AT91-based boards.
3 *
4 * Copyright (C) SAN People (Pty) Ltd
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10*/
11
12#include <linux/gpio.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/platform_device.h>
17
18#include "board.h"
19#include "gpio.h"
20
21
22/* ------------------------------------------------------------------------- */
23
24#if defined(CONFIG_NEW_LEDS)
25
26/*
27 * New cross-platform LED support.
28 */
29
30static struct gpio_led_platform_data led_data;
31
32static struct platform_device at91_gpio_leds_device = {
33 .name = "leds-gpio",
34 .id = -1,
35 .dev.platform_data = &led_data,
36};
37
38void __init at91_gpio_leds(struct gpio_led *leds, int nr)
39{
40 int i;
41
42 if (!nr)
43 return;
44
45 for (i = 0; i < nr; i++)
46 at91_set_gpio_output(leds[i].gpio, leds[i].active_low);
47
48 led_data.leds = leds;
49 led_data.num_leds = nr;
50 platform_device_register(&at91_gpio_leds_device);
51}
52
53#else
54void __init at91_gpio_leds(struct gpio_led *leds, int nr) {}
55#endif
56
diff --git a/arch/arm/mach-at91/pm.c b/arch/arm/mach-at91/pm.c
index 4073ab7f38f3..9b15169a1c62 100644
--- a/arch/arm/mach-at91/pm.c
+++ b/arch/arm/mach-at91/pm.c
@@ -29,10 +29,8 @@
29#include <mach/cpu.h> 29#include <mach/cpu.h>
30#include <mach/hardware.h> 30#include <mach/hardware.h>
31 31
32#include "at91_aic.h"
33#include "generic.h" 32#include "generic.h"
34#include "pm.h" 33#include "pm.h"
35#include "gpio.h"
36 34
37static void (*at91_pm_standby)(void); 35static void (*at91_pm_standby)(void);
38 36
@@ -131,23 +129,7 @@ extern u32 at91_slow_clock_sz;
131 129
132static int at91_pm_enter(suspend_state_t state) 130static int at91_pm_enter(suspend_state_t state)
133{ 131{
134 if (of_have_populated_dt()) 132 at91_pinctrl_gpio_suspend();
135 at91_pinctrl_gpio_suspend();
136 else
137 at91_gpio_suspend();
138
139 if (IS_ENABLED(CONFIG_OLD_IRQ_AT91) && at91_aic_base) {
140 at91_irq_suspend();
141
142 pr_debug("AT91: PM - wake mask %08x, pm state %d\n",
143 /* remember all the always-wake irqs */
144 (at91_pmc_read(AT91_PMC_PCSR)
145 | (1 << AT91_ID_FIQ)
146 | (1 << AT91_ID_SYS)
147 | (at91_get_extern_irq()))
148 & at91_aic_read(AT91_AIC_IMR),
149 state);
150 }
151 133
152 switch (state) { 134 switch (state) {
153 /* 135 /*
@@ -212,21 +194,10 @@ static int at91_pm_enter(suspend_state_t state)
212 goto error; 194 goto error;
213 } 195 }
214 196
215 if (IS_ENABLED(CONFIG_OLD_IRQ_AT91) && at91_aic_base)
216 pr_debug("AT91: PM - wakeup %08x\n",
217 at91_aic_read(AT91_AIC_IPR) &
218 at91_aic_read(AT91_AIC_IMR));
219
220error: 197error:
221 target_state = PM_SUSPEND_ON; 198 target_state = PM_SUSPEND_ON;
222 199
223 if (IS_ENABLED(CONFIG_OLD_IRQ_AT91) && at91_aic_base) 200 at91_pinctrl_gpio_resume();
224 at91_irq_resume();
225
226 if (of_have_populated_dt())
227 at91_pinctrl_gpio_resume();
228 else
229 at91_gpio_resume();
230 return 0; 201 return 0;
231} 202}
232 203
diff --git a/arch/arm/mach-at91/pm.h b/arch/arm/mach-at91/pm.h
index c5101dcb4fb0..d2c89963af2d 100644
--- a/arch/arm/mach-at91/pm.h
+++ b/arch/arm/mach-at91/pm.h
@@ -14,7 +14,6 @@
14#include <asm/proc-fns.h> 14#include <asm/proc-fns.h>
15 15
16#include <mach/at91_ramc.h> 16#include <mach/at91_ramc.h>
17#include <mach/at91rm9200_sdramc.h>
18 17
19#ifdef CONFIG_PM 18#ifdef CONFIG_PM
20extern void at91_pm_set_standby(void (*at91_standby)(void)); 19extern void at91_pm_set_standby(void (*at91_standby)(void));
diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
index 961079250b83..ce25e85720fb 100644
--- a/arch/arm/mach-at91/setup.c
+++ b/arch/arm/mach-at91/setup.c
@@ -42,35 +42,9 @@ void __init at91rm9200_set_type(int type)
42 at91_get_soc_subtype(&at91_soc_initdata)); 42 at91_get_soc_subtype(&at91_soc_initdata));
43} 43}
44 44
45void __init at91_init_irq_default(void)
46{
47 at91_init_interrupts(at91_boot_soc.default_irq_priority);
48}
49
50void __init at91_init_interrupts(unsigned int *priority)
51{
52 /* Initialize the AIC interrupt controller */
53 if (IS_ENABLED(CONFIG_OLD_IRQ_AT91))
54 at91_aic_init(priority, at91_boot_soc.extern_irq);
55
56 /* Enable GPIO interrupts */
57 at91_gpio_irq_setup();
58}
59
60void __iomem *at91_ramc_base[2]; 45void __iomem *at91_ramc_base[2];
61EXPORT_SYMBOL_GPL(at91_ramc_base); 46EXPORT_SYMBOL_GPL(at91_ramc_base);
62 47
63void __init at91_ioremap_ramc(int id, u32 addr, u32 size)
64{
65 if (id < 0 || id > 1) {
66 pr_emerg("Wrong RAM controller id (%d), cannot continue\n", id);
67 BUG();
68 }
69 at91_ramc_base[id] = ioremap(addr, size);
70 if (!at91_ramc_base[id])
71 panic(pr_fmt("Impossible to ioremap ramc.%d 0x%x\n"), id, addr);
72}
73
74static struct map_desc sram_desc[2] __initdata; 48static struct map_desc sram_desc[2] __initdata;
75 49
76void __init at91_init_sram(int bank, unsigned long base, unsigned int length) 50void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
@@ -418,7 +392,6 @@ void __init at91_ioremap_matrix(u32 base_addr)
418 panic(pr_fmt("Impossible to ioremap at91_matrix_base\n")); 392 panic(pr_fmt("Impossible to ioremap at91_matrix_base\n"));
419} 393}
420 394
421#if defined(CONFIG_OF) && !defined(CONFIG_ARCH_AT91X40)
422static struct of_device_id ramc_ids[] = { 395static struct of_device_id ramc_ids[] = {
423 { .compatible = "atmel,at91rm9200-sdramc", .data = at91rm9200_standby }, 396 { .compatible = "atmel,at91rm9200-sdramc", .data = at91rm9200_standby },
424 { .compatible = "atmel,at91sam9260-sdramc", .data = at91sam9_sdram_standby }, 397 { .compatible = "atmel,at91sam9260-sdramc", .data = at91sam9_sdram_standby },
@@ -460,13 +433,6 @@ void __init at91rm9200_dt_initialize(void)
460{ 433{
461 at91_dt_ramc(); 434 at91_dt_ramc();
462 435
463 /* Init clock subsystem */
464 at91_dt_clock_init();
465
466 /* Register the processor-specific clocks */
467 if (at91_boot_soc.register_clocks)
468 at91_boot_soc.register_clocks();
469
470 at91_boot_soc.init(); 436 at91_boot_soc.init();
471} 437}
472 438
@@ -474,39 +440,6 @@ void __init at91_dt_initialize(void)
474{ 440{
475 at91_dt_ramc(); 441 at91_dt_ramc();
476 442
477 /* Init clock subsystem */
478 at91_dt_clock_init();
479
480 /* Register the processor-specific clocks */
481 if (at91_boot_soc.register_clocks)
482 at91_boot_soc.register_clocks();
483
484 if (at91_boot_soc.init) 443 if (at91_boot_soc.init)
485 at91_boot_soc.init(); 444 at91_boot_soc.init();
486} 445}
487#endif
488
489void __init at91_initialize(unsigned long main_clock)
490{
491 at91_boot_soc.ioremap_registers();
492
493 /* Init clock subsystem */
494 at91_clock_init(main_clock);
495
496 /* Register the processor-specific clocks */
497 at91_boot_soc.register_clocks();
498
499 at91_boot_soc.init();
500
501 pinctrl_provide_dummies();
502}
503
504void __init at91_register_devices(void)
505{
506 at91_boot_soc.register_devices();
507}
508
509void __init at91_init_time(void)
510{
511 at91_boot_soc.init_time();
512}
diff --git a/arch/arm/mach-at91/soc.h b/arch/arm/mach-at91/soc.h
index 9a8fd97a8bef..ae6c0b2f1146 100644
--- a/arch/arm/mach-at91/soc.h
+++ b/arch/arm/mach-at91/soc.h
@@ -6,14 +6,8 @@
6 6
7struct at91_init_soc { 7struct at91_init_soc {
8 int builtin; 8 int builtin;
9 u32 extern_irq;
10 unsigned int *default_irq_priority;
11 void (*map_io)(void); 9 void (*map_io)(void);
12 void (*ioremap_registers)(void);
13 void (*register_clocks)(void);
14 void (*register_devices)(void);
15 void (*init)(void); 10 void (*init)(void);
16 void (*init_time)(void);
17}; 11};
18 12
19extern struct at91_init_soc at91_boot_soc; 13extern struct at91_init_soc at91_boot_soc;
diff --git a/arch/arm/mach-at91/stamp9g20.h b/arch/arm/mach-at91/stamp9g20.h
deleted file mode 100644
index f62c0abca4b4..000000000000
--- a/arch/arm/mach-at91/stamp9g20.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef __MACH_STAMP9G20_H
2#define __MACH_STAMP9G20_H
3
4void stamp9g20_init_early(void);
5void stamp9g20_board_init(void);
6
7#endif
diff --git a/arch/arm/mach-davinci/board-da830-evm.c b/arch/arm/mach-davinci/board-da830-evm.c
index 5623131c4f0b..f8f62fbaa915 100644
--- a/arch/arm/mach-davinci/board-da830-evm.c
+++ b/arch/arm/mach-davinci/board-da830-evm.c
@@ -80,8 +80,8 @@ static int da830_evm_usb_ocic_notify(da8xx_ocic_handler_t handler)
80 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 80 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
81 "OHCI over-current indicator", NULL); 81 "OHCI over-current indicator", NULL);
82 if (error) 82 if (error)
83 printk(KERN_ERR "%s: could not request IRQ to watch " 83 pr_err("%s: could not request IRQ to watch over-current indicator changes\n",
84 "over-current indicator changes\n", __func__); 84 __func__);
85 } else 85 } else
86 free_irq(irq, NULL); 86 free_irq(irq, NULL);
87 87
@@ -145,8 +145,7 @@ static __init void da830_evm_usb_init(void)
145 /* USB_REFCLKIN is not used. */ 145 /* USB_REFCLKIN is not used. */
146 ret = davinci_cfg_reg(DA830_USB0_DRVVBUS); 146 ret = davinci_cfg_reg(DA830_USB0_DRVVBUS);
147 if (ret) 147 if (ret)
148 pr_warning("%s: USB 2.0 PinMux setup failed: %d\n", 148 pr_warn("%s: USB 2.0 PinMux setup failed: %d\n", __func__, ret);
149 __func__, ret);
150 else { 149 else {
151 /* 150 /*
152 * TPS2065 switch @ 5V supplies 1 A (sustains 1.5 A), 151 * TPS2065 switch @ 5V supplies 1 A (sustains 1.5 A),
@@ -154,37 +153,35 @@ static __init void da830_evm_usb_init(void)
154 */ 153 */
155 ret = da8xx_register_usb20(1000, 3); 154 ret = da8xx_register_usb20(1000, 3);
156 if (ret) 155 if (ret)
157 pr_warning("%s: USB 2.0 registration failed: %d\n", 156 pr_warn("%s: USB 2.0 registration failed: %d\n",
158 __func__, ret); 157 __func__, ret);
159 } 158 }
160 159
161 ret = davinci_cfg_reg_list(da830_evm_usb11_pins); 160 ret = davinci_cfg_reg_list(da830_evm_usb11_pins);
162 if (ret) { 161 if (ret) {
163 pr_warning("%s: USB 1.1 PinMux setup failed: %d\n", 162 pr_warn("%s: USB 1.1 PinMux setup failed: %d\n", __func__, ret);
164 __func__, ret);
165 return; 163 return;
166 } 164 }
167 165
168 ret = gpio_request(ON_BD_USB_DRV, "ON_BD_USB_DRV"); 166 ret = gpio_request(ON_BD_USB_DRV, "ON_BD_USB_DRV");
169 if (ret) { 167 if (ret) {
170 printk(KERN_ERR "%s: failed to request GPIO for USB 1.1 port " 168 pr_err("%s: failed to request GPIO for USB 1.1 port power control: %d\n",
171 "power control: %d\n", __func__, ret); 169 __func__, ret);
172 return; 170 return;
173 } 171 }
174 gpio_direction_output(ON_BD_USB_DRV, 0); 172 gpio_direction_output(ON_BD_USB_DRV, 0);
175 173
176 ret = gpio_request(ON_BD_USB_OVC, "ON_BD_USB_OVC"); 174 ret = gpio_request(ON_BD_USB_OVC, "ON_BD_USB_OVC");
177 if (ret) { 175 if (ret) {
178 printk(KERN_ERR "%s: failed to request GPIO for USB 1.1 port " 176 pr_err("%s: failed to request GPIO for USB 1.1 port over-current indicator: %d\n",
179 "over-current indicator: %d\n", __func__, ret); 177 __func__, ret);
180 return; 178 return;
181 } 179 }
182 gpio_direction_input(ON_BD_USB_OVC); 180 gpio_direction_input(ON_BD_USB_OVC);
183 181
184 ret = da8xx_register_usb11(&da830_evm_usb11_pdata); 182 ret = da8xx_register_usb11(&da830_evm_usb11_pdata);
185 if (ret) 183 if (ret)
186 pr_warning("%s: USB 1.1 registration failed: %d\n", 184 pr_warn("%s: USB 1.1 registration failed: %d\n", __func__, ret);
187 __func__, ret);
188} 185}
189 186
190static const short da830_evm_mcasp1_pins[] = { 187static const short da830_evm_mcasp1_pins[] = {
@@ -252,31 +249,29 @@ static inline void da830_evm_init_mmc(void)
252 249
253 ret = davinci_cfg_reg_list(da830_evm_mmc_sd_pins); 250 ret = davinci_cfg_reg_list(da830_evm_mmc_sd_pins);
254 if (ret) { 251 if (ret) {
255 pr_warning("da830_evm_init: mmc/sd mux setup failed: %d\n", 252 pr_warn("%s: mmc/sd mux setup failed: %d\n", __func__, ret);
256 ret);
257 return; 253 return;
258 } 254 }
259 255
260 ret = gpio_request(DA830_MMCSD_WP_PIN, "MMC WP"); 256 ret = gpio_request(DA830_MMCSD_WP_PIN, "MMC WP");
261 if (ret) { 257 if (ret) {
262 pr_warning("da830_evm_init: can not open GPIO %d\n", 258 pr_warn("%s: can not open GPIO %d\n",
263 DA830_MMCSD_WP_PIN); 259 __func__, DA830_MMCSD_WP_PIN);
264 return; 260 return;
265 } 261 }
266 gpio_direction_input(DA830_MMCSD_WP_PIN); 262 gpio_direction_input(DA830_MMCSD_WP_PIN);
267 263
268 ret = gpio_request(DA830_MMCSD_CD_PIN, "MMC CD\n"); 264 ret = gpio_request(DA830_MMCSD_CD_PIN, "MMC CD\n");
269 if (ret) { 265 if (ret) {
270 pr_warning("da830_evm_init: can not open GPIO %d\n", 266 pr_warn("%s: can not open GPIO %d\n",
271 DA830_MMCSD_CD_PIN); 267 __func__, DA830_MMCSD_CD_PIN);
272 return; 268 return;
273 } 269 }
274 gpio_direction_input(DA830_MMCSD_CD_PIN); 270 gpio_direction_input(DA830_MMCSD_CD_PIN);
275 271
276 ret = da8xx_register_mmcsd0(&da830_evm_mmc_config); 272 ret = da8xx_register_mmcsd0(&da830_evm_mmc_config);
277 if (ret) { 273 if (ret) {
278 pr_warning("da830_evm_init: mmc/sd registration failed: %d\n", 274 pr_warn("%s: mmc/sd registration failed: %d\n", __func__, ret);
279 ret);
280 gpio_free(DA830_MMCSD_WP_PIN); 275 gpio_free(DA830_MMCSD_WP_PIN);
281 } 276 }
282} 277}
@@ -404,23 +399,21 @@ static inline void da830_evm_init_nand(int mux_mode)
404 int ret; 399 int ret;
405 400
406 if (HAS_MMC) { 401 if (HAS_MMC) {
407 pr_warning("WARNING: both MMC/SD and NAND are " 402 pr_warn("WARNING: both MMC/SD and NAND are enabled, but they share AEMIF pins\n"
408 "enabled, but they share AEMIF pins.\n" 403 "\tDisable MMC/SD for NAND support\n");
409 "\tDisable MMC/SD for NAND support.\n");
410 return; 404 return;
411 } 405 }
412 406
413 ret = davinci_cfg_reg_list(da830_evm_emif25_pins); 407 ret = davinci_cfg_reg_list(da830_evm_emif25_pins);
414 if (ret) 408 if (ret)
415 pr_warning("da830_evm_init: emif25 mux setup failed: %d\n", 409 pr_warn("%s: emif25 mux setup failed: %d\n", __func__, ret);
416 ret);
417 410
418 ret = platform_device_register(&da830_evm_nand_device); 411 ret = platform_device_register(&da830_evm_nand_device);
419 if (ret) 412 if (ret)
420 pr_warning("da830_evm_init: NAND device not registered.\n"); 413 pr_warn("%s: NAND device not registered\n", __func__);
421 414
422 if (davinci_aemif_setup(&da830_evm_nand_device)) 415 if (davinci_aemif_setup(&da830_evm_nand_device))
423 pr_warn("%s: Cannot configure AEMIF.\n", __func__); 416 pr_warn("%s: Cannot configure AEMIF\n", __func__);
424 417
425 gpio_direction_output(mux_mode, 1); 418 gpio_direction_output(mux_mode, 1);
426} 419}
@@ -435,12 +428,11 @@ static inline void da830_evm_init_lcdc(int mux_mode)
435 428
436 ret = davinci_cfg_reg_list(da830_lcdcntl_pins); 429 ret = davinci_cfg_reg_list(da830_lcdcntl_pins);
437 if (ret) 430 if (ret)
438 pr_warning("da830_evm_init: lcdcntl mux setup failed: %d\n", 431 pr_warn("%s: lcdcntl mux setup failed: %d\n", __func__, ret);
439 ret);
440 432
441 ret = da8xx_register_lcdc(&sharp_lcd035q3dg01_pdata); 433 ret = da8xx_register_lcdc(&sharp_lcd035q3dg01_pdata);
442 if (ret) 434 if (ret)
443 pr_warning("da830_evm_init: lcd setup failed: %d\n", ret); 435 pr_warn("%s: lcd setup failed: %d\n", __func__, ret);
444 436
445 gpio_direction_output(mux_mode, 0); 437 gpio_direction_output(mux_mode, 0);
446} 438}
@@ -598,22 +590,19 @@ static __init void da830_evm_init(void)
598 590
599 ret = da830_register_gpio(); 591 ret = da830_register_gpio();
600 if (ret) 592 if (ret)
601 pr_warn("da830_evm_init: GPIO init failed: %d\n", ret); 593 pr_warn("%s: GPIO init failed: %d\n", __func__, ret);
602 594
603 ret = da830_register_edma(da830_edma_rsv); 595 ret = da830_register_edma(da830_edma_rsv);
604 if (ret) 596 if (ret)
605 pr_warning("da830_evm_init: edma registration failed: %d\n", 597 pr_warn("%s: edma registration failed: %d\n", __func__, ret);
606 ret);
607 598
608 ret = davinci_cfg_reg_list(da830_i2c0_pins); 599 ret = davinci_cfg_reg_list(da830_i2c0_pins);
609 if (ret) 600 if (ret)
610 pr_warning("da830_evm_init: i2c0 mux setup failed: %d\n", 601 pr_warn("%s: i2c0 mux setup failed: %d\n", __func__, ret);
611 ret);
612 602
613 ret = da8xx_register_i2c(0, &da830_evm_i2c_0_pdata); 603 ret = da8xx_register_i2c(0, &da830_evm_i2c_0_pdata);
614 if (ret) 604 if (ret)
615 pr_warning("da830_evm_init: i2c0 registration failed: %d\n", 605 pr_warn("%s: i2c0 registration failed: %d\n", __func__, ret);
616 ret);
617 606
618 da830_evm_usb_init(); 607 da830_evm_usb_init();
619 608
@@ -622,18 +611,16 @@ static __init void da830_evm_init(void)
622 611
623 ret = davinci_cfg_reg_list(da830_cpgmac_pins); 612 ret = davinci_cfg_reg_list(da830_cpgmac_pins);
624 if (ret) 613 if (ret)
625 pr_warning("da830_evm_init: cpgmac mux setup failed: %d\n", 614 pr_warn("%s: cpgmac mux setup failed: %d\n", __func__, ret);
626 ret);
627 615
628 ret = da8xx_register_emac(); 616 ret = da8xx_register_emac();
629 if (ret) 617 if (ret)
630 pr_warning("da830_evm_init: emac registration failed: %d\n", 618 pr_warn("%s: emac registration failed: %d\n", __func__, ret);
631 ret);
632 619
633 ret = da8xx_register_watchdog(); 620 ret = da8xx_register_watchdog();
634 if (ret) 621 if (ret)
635 pr_warning("da830_evm_init: watchdog registration failed: %d\n", 622 pr_warn("%s: watchdog registration failed: %d\n",
636 ret); 623 __func__, ret);
637 624
638 davinci_serial_init(da8xx_serial_device); 625 davinci_serial_init(da8xx_serial_device);
639 i2c_register_board_info(1, da830_evm_i2c_devices, 626 i2c_register_board_info(1, da830_evm_i2c_devices,
@@ -641,8 +628,7 @@ static __init void da830_evm_init(void)
641 628
642 ret = davinci_cfg_reg_list(da830_evm_mcasp1_pins); 629 ret = davinci_cfg_reg_list(da830_evm_mcasp1_pins);
643 if (ret) 630 if (ret)
644 pr_warning("da830_evm_init: mcasp1 mux setup failed: %d\n", 631 pr_warn("%s: mcasp1 mux setup failed: %d\n", __func__, ret);
645 ret);
646 632
647 da8xx_register_mcasp(1, &da830_evm_snd_data); 633 da8xx_register_mcasp(1, &da830_evm_snd_data);
648 634
@@ -650,18 +636,17 @@ static __init void da830_evm_init(void)
650 636
651 ret = da8xx_register_rtc(); 637 ret = da8xx_register_rtc();
652 if (ret) 638 if (ret)
653 pr_warning("da830_evm_init: rtc setup failed: %d\n", ret); 639 pr_warn("%s: rtc setup failed: %d\n", __func__, ret);
654 640
655 ret = spi_register_board_info(da830evm_spi_info, 641 ret = spi_register_board_info(da830evm_spi_info,
656 ARRAY_SIZE(da830evm_spi_info)); 642 ARRAY_SIZE(da830evm_spi_info));
657 if (ret) 643 if (ret)
658 pr_warn("%s: spi info registration failed: %d\n", __func__, 644 pr_warn("%s: spi info registration failed: %d\n",
659 ret); 645 __func__, ret);
660 646
661 ret = da8xx_register_spi_bus(0, ARRAY_SIZE(da830evm_spi_info)); 647 ret = da8xx_register_spi_bus(0, ARRAY_SIZE(da830evm_spi_info));
662 if (ret) 648 if (ret)
663 pr_warning("da830_evm_init: spi 0 registration failed: %d\n", 649 pr_warn("%s: spi 0 registration failed: %d\n", __func__, ret);
664 ret);
665} 650}
666 651
667#ifdef CONFIG_SERIAL_8250_CONSOLE 652#ifdef CONFIG_SERIAL_8250_CONSOLE
diff --git a/arch/arm/mach-davinci/board-da850-evm.c b/arch/arm/mach-davinci/board-da850-evm.c
index fa11415e906a..6b5a97da9fe3 100644
--- a/arch/arm/mach-davinci/board-da850-evm.c
+++ b/arch/arm/mach-davinci/board-da850-evm.c
@@ -452,8 +452,7 @@ static void da850_evm_ui_keys_init(unsigned gpio)
452 for (i = 0; i < DA850_N_UI_PB; i++) { 452 for (i = 0; i < DA850_N_UI_PB; i++) {
453 button = &da850_evm_ui_keys[i]; 453 button = &da850_evm_ui_keys[i];
454 button->code = KEY_F8 - i; 454 button->code = KEY_F8 - i;
455 button->desc = (char *) 455 button->desc = da850_evm_ui_exp[DA850_EVM_UI_EXP_PB8 + i];
456 da850_evm_ui_exp[DA850_EVM_UI_EXP_PB8 + i];
457 button->gpio = gpio + DA850_EVM_UI_EXP_PB8 + i; 456 button->gpio = gpio + DA850_EVM_UI_EXP_PB8 + i;
458 } 457 }
459} 458}
@@ -628,15 +627,13 @@ static void da850_evm_bb_keys_init(unsigned gpio)
628 struct gpio_keys_button *button; 627 struct gpio_keys_button *button;
629 628
630 button = &da850_evm_bb_keys[0]; 629 button = &da850_evm_bb_keys[0];
631 button->desc = (char *) 630 button->desc = da850_evm_bb_exp[DA850_EVM_BB_EXP_USER_PB1];
632 da850_evm_bb_exp[DA850_EVM_BB_EXP_USER_PB1];
633 button->gpio = gpio + DA850_EVM_BB_EXP_USER_PB1; 631 button->gpio = gpio + DA850_EVM_BB_EXP_USER_PB1;
634 632
635 for (i = 0; i < DA850_N_BB_USER_SW; i++) { 633 for (i = 0; i < DA850_N_BB_USER_SW; i++) {
636 button = &da850_evm_bb_keys[i + 1]; 634 button = &da850_evm_bb_keys[i + 1];
637 button->code = SW_LID + i; 635 button->code = SW_LID + i;
638 button->desc = (char *) 636 button->desc = da850_evm_bb_exp[DA850_EVM_BB_EXP_USER_SW1 + i];
639 da850_evm_bb_exp[DA850_EVM_BB_EXP_USER_SW1 + i];
640 button->gpio = gpio + DA850_EVM_BB_EXP_USER_SW1 + i; 637 button->gpio = gpio + DA850_EVM_BB_EXP_USER_SW1 + i;
641 } 638 }
642} 639}
diff --git a/arch/arm/mach-davinci/board-dm644x-evm.c b/arch/arm/mach-davinci/board-dm644x-evm.c
index e583e58b5e1e..1a0898c1c17e 100644
--- a/arch/arm/mach-davinci/board-dm644x-evm.c
+++ b/arch/arm/mach-davinci/board-dm644x-evm.c
@@ -767,9 +767,8 @@ static __init void davinci_evm_init(void)
767 767
768 if (HAS_ATA) { 768 if (HAS_ATA) {
769 if (HAS_NAND || HAS_NOR) 769 if (HAS_NAND || HAS_NOR)
770 pr_warning("WARNING: both IDE and Flash are " 770 pr_warn("WARNING: both IDE and Flash are enabled, but they share AEMIF pins\n"
771 "enabled, but they share AEMIF pins.\n" 771 "\tDisable IDE for NAND/NOR support\n");
772 "\tDisable IDE for NAND/NOR support.\n");
773 davinci_init_ide(); 772 davinci_init_ide();
774 } else if (HAS_NAND || HAS_NOR) { 773 } else if (HAS_NAND || HAS_NOR) {
775 davinci_cfg_reg(DM644X_HPIEN_DISABLE); 774 davinci_cfg_reg(DM644X_HPIEN_DISABLE);
@@ -780,13 +779,12 @@ static __init void davinci_evm_init(void)
780 platform_device_register(&davinci_evm_nandflash_device); 779 platform_device_register(&davinci_evm_nandflash_device);
781 780
782 if (davinci_aemif_setup(&davinci_evm_nandflash_device)) 781 if (davinci_aemif_setup(&davinci_evm_nandflash_device))
783 pr_warn("%s: Cannot configure AEMIF.\n", 782 pr_warn("%s: Cannot configure AEMIF\n",
784 __func__); 783 __func__);
785 784
786 evm_leds[7].default_trigger = "nand-disk"; 785 evm_leds[7].default_trigger = "nand-disk";
787 if (HAS_NOR) 786 if (HAS_NOR)
788 pr_warning("WARNING: both NAND and NOR flash " 787 pr_warn("WARNING: both NAND and NOR flash are enabled; disable one of them.\n");
789 "are enabled; disable one of them.\n");
790 } else if (HAS_NOR) 788 } else if (HAS_NOR)
791 platform_device_register(&davinci_evm_norflash_device); 789 platform_device_register(&davinci_evm_norflash_device);
792 } 790 }
diff --git a/arch/arm/mach-davinci/board-mityomapl138.c b/arch/arm/mach-davinci/board-mityomapl138.c
index 96fc00a167f5..8cfbfe084535 100644
--- a/arch/arm/mach-davinci/board-mityomapl138.c
+++ b/arch/arm/mach-davinci/board-mityomapl138.c
@@ -8,6 +8,8 @@
8 * any kind, whether express or implied. 8 * any kind, whether express or implied.
9 */ 9 */
10 10
11#define pr_fmt(fmt) "MityOMAPL138: " fmt
12
11#include <linux/kernel.h> 13#include <linux/kernel.h>
12#include <linux/init.h> 14#include <linux/init.h>
13#include <linux/console.h> 15#include <linux/console.h>
@@ -107,7 +109,7 @@ static void mityomapl138_cpufreq_init(const char *partnum)
107 109
108 ret = da850_register_cpufreq("pll0_sysclk3"); 110 ret = da850_register_cpufreq("pll0_sysclk3");
109 if (ret) 111 if (ret)
110 pr_warning("cpufreq registration failed: %d\n", ret); 112 pr_warn("cpufreq registration failed: %d\n", ret);
111} 113}
112#else 114#else
113static void mityomapl138_cpufreq_init(const char *partnum) { } 115static void mityomapl138_cpufreq_init(const char *partnum) { }
@@ -121,33 +123,31 @@ static void read_factory_config(struct memory_accessor *a, void *context)
121 123
122 ret = a->read(a, (char *)&factory_config, 0, sizeof(factory_config)); 124 ret = a->read(a, (char *)&factory_config, 0, sizeof(factory_config));
123 if (ret != sizeof(struct factory_config)) { 125 if (ret != sizeof(struct factory_config)) {
124 pr_warning("MityOMAPL138: Read Factory Config Failed: %d\n", 126 pr_warn("Read Factory Config Failed: %d\n", ret);
125 ret);
126 goto bad_config; 127 goto bad_config;
127 } 128 }
128 129
129 if (factory_config.magic != FACTORY_CONFIG_MAGIC) { 130 if (factory_config.magic != FACTORY_CONFIG_MAGIC) {
130 pr_warning("MityOMAPL138: Factory Config Magic Wrong (%X)\n", 131 pr_warn("Factory Config Magic Wrong (%X)\n",
131 factory_config.magic); 132 factory_config.magic);
132 goto bad_config; 133 goto bad_config;
133 } 134 }
134 135
135 if (factory_config.version != FACTORY_CONFIG_VERSION) { 136 if (factory_config.version != FACTORY_CONFIG_VERSION) {
136 pr_warning("MityOMAPL138: Factory Config Version Wrong (%X)\n", 137 pr_warn("Factory Config Version Wrong (%X)\n",
137 factory_config.version); 138 factory_config.version);
138 goto bad_config; 139 goto bad_config;
139 } 140 }
140 141
141 pr_info("MityOMAPL138: Found MAC = %pM\n", factory_config.mac); 142 pr_info("Found MAC = %pM\n", factory_config.mac);
142 if (is_valid_ether_addr(factory_config.mac)) 143 if (is_valid_ether_addr(factory_config.mac))
143 memcpy(soc_info->emac_pdata->mac_addr, 144 memcpy(soc_info->emac_pdata->mac_addr,
144 factory_config.mac, ETH_ALEN); 145 factory_config.mac, ETH_ALEN);
145 else 146 else
146 pr_warning("MityOMAPL138: Invalid MAC found " 147 pr_warn("Invalid MAC found in factory config block\n");
147 "in factory config block\n");
148 148
149 partnum = factory_config.partnum; 149 partnum = factory_config.partnum;
150 pr_info("MityOMAPL138: Part Number = %s\n", partnum); 150 pr_info("Part Number = %s\n", partnum);
151 151
152bad_config: 152bad_config:
153 /* default maximum speed is valid for all platforms */ 153 /* default maximum speed is valid for all platforms */
@@ -435,7 +435,7 @@ static void __init mityomapl138_setup_nand(void)
435 ARRAY_SIZE(mityomapl138_devices)); 435 ARRAY_SIZE(mityomapl138_devices));
436 436
437 if (davinci_aemif_setup(&mityomapl138_nandflash_device)) 437 if (davinci_aemif_setup(&mityomapl138_nandflash_device))
438 pr_warn("%s: Cannot configure AEMIF.\n", __func__); 438 pr_warn("%s: Cannot configure AEMIF\n", __func__);
439} 439}
440 440
441static const short mityomap_mii_pins[] = { 441static const short mityomap_mii_pins[] = {
@@ -478,7 +478,7 @@ static void __init mityomapl138_config_emac(void)
478 } 478 }
479 479
480 if (ret) { 480 if (ret) {
481 pr_warning("mii/rmii mux setup failed: %d\n", ret); 481 pr_warn("mii/rmii mux setup failed: %d\n", ret);
482 return; 482 return;
483 } 483 }
484 484
@@ -489,7 +489,7 @@ static void __init mityomapl138_config_emac(void)
489 489
490 ret = da8xx_register_emac(); 490 ret = da8xx_register_emac();
491 if (ret) 491 if (ret)
492 pr_warning("emac registration failed: %d\n", ret); 492 pr_warn("emac registration failed: %d\n", ret);
493} 493}
494 494
495static struct davinci_pm_config da850_pm_pdata = { 495static struct davinci_pm_config da850_pm_pdata = {
@@ -511,21 +511,21 @@ static void __init mityomapl138_init(void)
511 /* for now, no special EDMA channels are reserved */ 511 /* for now, no special EDMA channels are reserved */
512 ret = da850_register_edma(NULL); 512 ret = da850_register_edma(NULL);
513 if (ret) 513 if (ret)
514 pr_warning("edma registration failed: %d\n", ret); 514 pr_warn("edma registration failed: %d\n", ret);
515 515
516 ret = da8xx_register_watchdog(); 516 ret = da8xx_register_watchdog();
517 if (ret) 517 if (ret)
518 pr_warning("watchdog registration failed: %d\n", ret); 518 pr_warn("watchdog registration failed: %d\n", ret);
519 519
520 davinci_serial_init(da8xx_serial_device); 520 davinci_serial_init(da8xx_serial_device);
521 521
522 ret = da8xx_register_i2c(0, &mityomap_i2c_0_pdata); 522 ret = da8xx_register_i2c(0, &mityomap_i2c_0_pdata);
523 if (ret) 523 if (ret)
524 pr_warning("i2c0 registration failed: %d\n", ret); 524 pr_warn("i2c0 registration failed: %d\n", ret);
525 525
526 ret = pmic_tps65023_init(); 526 ret = pmic_tps65023_init();
527 if (ret) 527 if (ret)
528 pr_warning("TPS65023 PMIC init failed: %d\n", ret); 528 pr_warn("TPS65023 PMIC init failed: %d\n", ret);
529 529
530 mityomapl138_setup_nand(); 530 mityomapl138_setup_nand();
531 531
@@ -537,22 +537,21 @@ static void __init mityomapl138_init(void)
537 ret = da8xx_register_spi_bus(1, 537 ret = da8xx_register_spi_bus(1,
538 ARRAY_SIZE(mityomapl138_spi_flash_info)); 538 ARRAY_SIZE(mityomapl138_spi_flash_info));
539 if (ret) 539 if (ret)
540 pr_warning("spi 1 registration failed: %d\n", ret); 540 pr_warn("spi 1 registration failed: %d\n", ret);
541 541
542 mityomapl138_config_emac(); 542 mityomapl138_config_emac();
543 543
544 ret = da8xx_register_rtc(); 544 ret = da8xx_register_rtc();
545 if (ret) 545 if (ret)
546 pr_warning("rtc setup failed: %d\n", ret); 546 pr_warn("rtc setup failed: %d\n", ret);
547 547
548 ret = da8xx_register_cpuidle(); 548 ret = da8xx_register_cpuidle();
549 if (ret) 549 if (ret)
550 pr_warning("cpuidle registration failed: %d\n", ret); 550 pr_warn("cpuidle registration failed: %d\n", ret);
551 551
552 ret = da850_register_pm(&da850_pm_device); 552 ret = da850_register_pm(&da850_pm_device);
553 if (ret) 553 if (ret)
554 pr_warning("da850_evm_init: suspend registration failed: %d\n", 554 pr_warn("suspend registration failed: %d\n", ret);
555 ret);
556} 555}
557 556
558#ifdef CONFIG_SERIAL_8250_CONSOLE 557#ifdef CONFIG_SERIAL_8250_CONSOLE
diff --git a/arch/arm/mach-davinci/board-neuros-osd2.c b/arch/arm/mach-davinci/board-neuros-osd2.c
index bb680af98374..8fcdcf87c47c 100644
--- a/arch/arm/mach-davinci/board-neuros-osd2.c
+++ b/arch/arm/mach-davinci/board-neuros-osd2.c
@@ -183,9 +183,8 @@ static __init void davinci_ntosd2_init(void)
183 183
184 if (HAS_ATA) { 184 if (HAS_ATA) {
185 if (HAS_NAND) 185 if (HAS_NAND)
186 pr_warning("WARNING: both IDE and Flash are " 186 pr_warn("WARNING: both IDE and Flash are enabled, but they share AEMIF pins\n"
187 "enabled, but they share AEMIF pins.\n" 187 "\tDisable IDE for NAND/NOR support\n");
188 "\tDisable IDE for NAND/NOR support.\n");
189 davinci_init_ide(); 188 davinci_init_ide();
190 } else if (HAS_NAND) { 189 } else if (HAS_NAND) {
191 davinci_cfg_reg(DM644X_HPIEN_DISABLE); 190 davinci_cfg_reg(DM644X_HPIEN_DISABLE);
diff --git a/arch/arm/mach-davinci/clock.c b/arch/arm/mach-davinci/clock.c
index 985e5fd00fb2..c70bb0a4dfb4 100644
--- a/arch/arm/mach-davinci/clock.c
+++ b/arch/arm/mach-davinci/clock.c
@@ -564,7 +564,7 @@ int davinci_set_refclk_rate(unsigned long rate)
564 564
565 refclk = clk_get(NULL, "ref"); 565 refclk = clk_get(NULL, "ref");
566 if (IS_ERR(refclk)) { 566 if (IS_ERR(refclk)) {
567 pr_err("%s: failed to get reference clock.\n", __func__); 567 pr_err("%s: failed to get reference clock\n", __func__);
568 return PTR_ERR(refclk); 568 return PTR_ERR(refclk);
569 } 569 }
570 570
diff --git a/arch/arm/mach-davinci/mux.c b/arch/arm/mach-davinci/mux.c
index f34a8dcdae2b..a8eb909a2b6c 100644
--- a/arch/arm/mach-davinci/mux.c
+++ b/arch/arm/mach-davinci/mux.c
@@ -15,6 +15,9 @@
15 * 15 *
16 * Copyright (C) 2008 Texas Instruments. 16 * Copyright (C) 2008 Texas Instruments.
17 */ 17 */
18
19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20
18#include <linux/io.h> 21#include <linux/io.h>
19#include <linux/module.h> 22#include <linux/module.h>
20#include <linux/spinlock.h> 23#include <linux/spinlock.h>
@@ -46,7 +49,7 @@ int __init_or_module davinci_cfg_reg(const unsigned long index)
46 } 49 }
47 50
48 if (index >= soc_info->pinmux_pins_num) { 51 if (index >= soc_info->pinmux_pins_num) {
49 printk(KERN_ERR "Invalid pin mux index: %lu (%lu)\n", 52 pr_err("Invalid pin mux index: %lu (%lu)\n",
50 index, soc_info->pinmux_pins_num); 53 index, soc_info->pinmux_pins_num);
51 dump_stack(); 54 dump_stack();
52 return -ENODEV; 55 return -ENODEV;
@@ -55,7 +58,7 @@ int __init_or_module davinci_cfg_reg(const unsigned long index)
55 cfg = &soc_info->pinmux_pins[index]; 58 cfg = &soc_info->pinmux_pins[index];
56 59
57 if (cfg->name == NULL) { 60 if (cfg->name == NULL) {
58 printk(KERN_ERR "No entry for the specified index\n"); 61 pr_err("No entry for the specified index\n");
59 return -ENODEV; 62 return -ENODEV;
60 } 63 }
61 64
@@ -82,15 +85,15 @@ int __init_or_module davinci_cfg_reg(const unsigned long index)
82 85
83 if (warn) { 86 if (warn) {
84#ifdef CONFIG_DAVINCI_MUX_WARNINGS 87#ifdef CONFIG_DAVINCI_MUX_WARNINGS
85 printk(KERN_WARNING "MUX: initialized %s\n", cfg->name); 88 pr_warn("initialized %s\n", cfg->name);
86#endif 89#endif
87 } 90 }
88 91
89#ifdef CONFIG_DAVINCI_MUX_DEBUG 92#ifdef CONFIG_DAVINCI_MUX_DEBUG
90 if (cfg->debug || warn) { 93 if (cfg->debug || warn) {
91 printk(KERN_WARNING "MUX: Setting register %s\n", cfg->name); 94 pr_warn("Setting register %s\n", cfg->name);
92 printk(KERN_WARNING " %s (0x%08x) = 0x%08x -> 0x%08x\n", 95 pr_warn(" %s (0x%08x) = 0x%08x -> 0x%08x\n",
93 cfg->mux_reg_name, cfg->mux_reg, reg_orig, reg); 96 cfg->mux_reg_name, cfg->mux_reg, reg_orig, reg);
94 } 97 }
95#endif 98#endif
96 99
diff --git a/arch/arm/mach-davinci/time.c b/arch/arm/mach-davinci/time.c
index 24ad30f32ae3..160c9602f490 100644
--- a/arch/arm/mach-davinci/time.c
+++ b/arch/arm/mach-davinci/time.c
@@ -342,8 +342,6 @@ void __init davinci_timer_init(void)
342 struct davinci_soc_info *soc_info = &davinci_soc_info; 342 struct davinci_soc_info *soc_info = &davinci_soc_info;
343 unsigned int clockevent_id; 343 unsigned int clockevent_id;
344 unsigned int clocksource_id; 344 unsigned int clocksource_id;
345 static char err[] __initdata = KERN_ERR
346 "%s: can't register clocksource!\n";
347 int i; 345 int i;
348 346
349 clockevent_id = soc_info->timer_info->clockevent_id; 347 clockevent_id = soc_info->timer_info->clockevent_id;
@@ -364,12 +362,12 @@ void __init davinci_timer_init(void)
364 362
365 /* Only bottom timers can use compare regs */ 363 /* Only bottom timers can use compare regs */
366 if (IS_TIMER_TOP(clockevent_id)) 364 if (IS_TIMER_TOP(clockevent_id))
367 pr_warning("davinci_timer_init: Invalid use" 365 pr_warn("%s: Invalid use of system timers. Results unpredictable.\n",
368 " of system timers. Results unpredictable.\n"); 366 __func__);
369 else if ((dtip[event_timer].cmp_off == 0) 367 else if ((dtip[event_timer].cmp_off == 0)
370 || (dtip[event_timer].cmp_irq == 0)) 368 || (dtip[event_timer].cmp_irq == 0))
371 pr_warning("davinci_timer_init: Invalid timer instance" 369 pr_warn("%s: Invalid timer instance setup. Results unpredictable.\n",
372 " setup. Results unpredictable.\n"); 370 __func__);
373 else { 371 else {
374 timers[TID_CLOCKEVENT].opts |= TIMER_OPTS_USE_COMPARE; 372 timers[TID_CLOCKEVENT].opts |= TIMER_OPTS_USE_COMPARE;
375 clockevent_davinci.features = CLOCK_EVT_FEAT_ONESHOT; 373 clockevent_davinci.features = CLOCK_EVT_FEAT_ONESHOT;
@@ -389,7 +387,8 @@ void __init davinci_timer_init(void)
389 clocksource_davinci.name = id_to_name[clocksource_id]; 387 clocksource_davinci.name = id_to_name[clocksource_id];
390 if (clocksource_register_hz(&clocksource_davinci, 388 if (clocksource_register_hz(&clocksource_davinci,
391 davinci_clock_tick_rate)) 389 davinci_clock_tick_rate))
392 printk(err, clocksource_davinci.name); 390 pr_err("%s: can't register clocksource!\n",
391 clocksource_davinci.name);
393 392
394 sched_clock_register(davinci_read_sched_clock, 32, 393 sched_clock_register(davinci_read_sched_clock, 32,
395 davinci_clock_tick_rate); 394 davinci_clock_tick_rate);
diff --git a/arch/arm/mach-ep93xx/dma.c b/arch/arm/mach-ep93xx/dma.c
index d8bfd02f5047..88a4c9b089a5 100644
--- a/arch/arm/mach-ep93xx/dma.c
+++ b/arch/arm/mach-ep93xx/dma.c
@@ -66,11 +66,15 @@ static struct ep93xx_dma_platform_data ep93xx_dma_m2p_data = {
66 .num_channels = ARRAY_SIZE(ep93xx_dma_m2p_channels), 66 .num_channels = ARRAY_SIZE(ep93xx_dma_m2p_channels),
67}; 67};
68 68
69static u64 ep93xx_dma_m2p_mask = DMA_BIT_MASK(32);
70
69static struct platform_device ep93xx_dma_m2p_device = { 71static struct platform_device ep93xx_dma_m2p_device = {
70 .name = "ep93xx-dma-m2p", 72 .name = "ep93xx-dma-m2p",
71 .id = -1, 73 .id = -1,
72 .dev = { 74 .dev = {
73 .platform_data = &ep93xx_dma_m2p_data, 75 .platform_data = &ep93xx_dma_m2p_data,
76 .dma_mask = &ep93xx_dma_m2p_mask,
77 .coherent_dma_mask = DMA_BIT_MASK(32),
74 }, 78 },
75}; 79};
76 80
@@ -93,11 +97,15 @@ static struct ep93xx_dma_platform_data ep93xx_dma_m2m_data = {
93 .num_channels = ARRAY_SIZE(ep93xx_dma_m2m_channels), 97 .num_channels = ARRAY_SIZE(ep93xx_dma_m2m_channels),
94}; 98};
95 99
100static u64 ep93xx_dma_m2m_mask = DMA_BIT_MASK(32);
101
96static struct platform_device ep93xx_dma_m2m_device = { 102static struct platform_device ep93xx_dma_m2m_device = {
97 .name = "ep93xx-dma-m2m", 103 .name = "ep93xx-dma-m2m",
98 .id = -1, 104 .id = -1,
99 .dev = { 105 .dev = {
100 .platform_data = &ep93xx_dma_m2m_data, 106 .platform_data = &ep93xx_dma_m2m_data,
107 .dma_mask = &ep93xx_dma_m2m_mask,
108 .coherent_dma_mask = DMA_BIT_MASK(32),
101 }, 109 },
102}; 110};
103 111
diff --git a/arch/arm/mach-exynos/exynos.c b/arch/arm/mach-exynos/exynos.c
index 80d744db7dc7..c13d0837fa8c 100644
--- a/arch/arm/mach-exynos/exynos.c
+++ b/arch/arm/mach-exynos/exynos.c
@@ -41,41 +41,11 @@ static struct map_desc exynos4_iodesc[] __initdata = {
41 .length = SZ_64K, 41 .length = SZ_64K,
42 .type = MT_DEVICE, 42 .type = MT_DEVICE,
43 }, { 43 }, {
44 .virtual = (unsigned long)S3C_VA_TIMER,
45 .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER),
46 .length = SZ_16K,
47 .type = MT_DEVICE,
48 }, {
49 .virtual = (unsigned long)S3C_VA_WATCHDOG,
50 .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG),
51 .length = SZ_4K,
52 .type = MT_DEVICE,
53 }, {
54 .virtual = (unsigned long)S5P_VA_SROMC, 44 .virtual = (unsigned long)S5P_VA_SROMC,
55 .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC), 45 .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC),
56 .length = SZ_4K, 46 .length = SZ_4K,
57 .type = MT_DEVICE, 47 .type = MT_DEVICE,
58 }, { 48 }, {
59 .virtual = (unsigned long)S5P_VA_SYSTIMER,
60 .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER),
61 .length = SZ_4K,
62 .type = MT_DEVICE,
63 }, {
64 .virtual = (unsigned long)S5P_VA_COMBINER_BASE,
65 .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER),
66 .length = SZ_4K,
67 .type = MT_DEVICE,
68 }, {
69 .virtual = (unsigned long)S5P_VA_GIC_CPU,
70 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU),
71 .length = SZ_64K,
72 .type = MT_DEVICE,
73 }, {
74 .virtual = (unsigned long)S5P_VA_GIC_DIST,
75 .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST),
76 .length = SZ_64K,
77 .type = MT_DEVICE,
78 }, {
79 .virtual = (unsigned long)S5P_VA_CMU, 49 .virtual = (unsigned long)S5P_VA_CMU,
80 .pfn = __phys_to_pfn(EXYNOS4_PA_CMU), 50 .pfn = __phys_to_pfn(EXYNOS4_PA_CMU),
81 .length = SZ_128K, 51 .length = SZ_128K,
@@ -86,11 +56,6 @@ static struct map_desc exynos4_iodesc[] __initdata = {
86 .length = SZ_8K, 56 .length = SZ_8K,
87 .type = MT_DEVICE, 57 .type = MT_DEVICE,
88 }, { 58 }, {
89 .virtual = (unsigned long)S5P_VA_L2CC,
90 .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC),
91 .length = SZ_4K,
92 .type = MT_DEVICE,
93 }, {
94 .virtual = (unsigned long)S5P_VA_DMC0, 59 .virtual = (unsigned long)S5P_VA_DMC0,
95 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0), 60 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0),
96 .length = SZ_64K, 61 .length = SZ_64K,
@@ -100,11 +65,6 @@ static struct map_desc exynos4_iodesc[] __initdata = {
100 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1), 65 .pfn = __phys_to_pfn(EXYNOS4_PA_DMC1),
101 .length = SZ_64K, 66 .length = SZ_64K,
102 .type = MT_DEVICE, 67 .type = MT_DEVICE,
103 }, {
104 .virtual = (unsigned long)S3C_VA_USB_HSPHY,
105 .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY),
106 .length = SZ_4K,
107 .type = MT_DEVICE,
108 }, 68 },
109}; 69};
110 70
@@ -115,16 +75,6 @@ static struct map_desc exynos5_iodesc[] __initdata = {
115 .length = SZ_64K, 75 .length = SZ_64K,
116 .type = MT_DEVICE, 76 .type = MT_DEVICE,
117 }, { 77 }, {
118 .virtual = (unsigned long)S3C_VA_TIMER,
119 .pfn = __phys_to_pfn(EXYNOS5_PA_TIMER),
120 .length = SZ_16K,
121 .type = MT_DEVICE,
122 }, {
123 .virtual = (unsigned long)S3C_VA_WATCHDOG,
124 .pfn = __phys_to_pfn(EXYNOS5_PA_WATCHDOG),
125 .length = SZ_4K,
126 .type = MT_DEVICE,
127 }, {
128 .virtual = (unsigned long)S5P_VA_SROMC, 78 .virtual = (unsigned long)S5P_VA_SROMC,
129 .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC), 79 .pfn = __phys_to_pfn(EXYNOS5_PA_SROMC),
130 .length = SZ_4K, 80 .length = SZ_4K,
diff --git a/arch/arm/mach-exynos/include/mach/map.h b/arch/arm/mach-exynos/include/mach/map.h
index f0b7e92bad6c..1ad3f496ef56 100644
--- a/arch/arm/mach-exynos/include/mach/map.h
+++ b/arch/arm/mach-exynos/include/mach/map.h
@@ -30,40 +30,17 @@
30#define EXYNOS4_PA_CMU 0x10030000 30#define EXYNOS4_PA_CMU 0x10030000
31#define EXYNOS5_PA_CMU 0x10010000 31#define EXYNOS5_PA_CMU 0x10010000
32 32
33#define EXYNOS4_PA_SYSTIMER 0x10050000
34
35#define EXYNOS4_PA_WATCHDOG 0x10060000
36#define EXYNOS5_PA_WATCHDOG 0x101D0000
37
38#define EXYNOS4_PA_DMC0 0x10400000 33#define EXYNOS4_PA_DMC0 0x10400000
39#define EXYNOS4_PA_DMC1 0x10410000 34#define EXYNOS4_PA_DMC1 0x10410000
40 35
41#define EXYNOS4_PA_COMBINER 0x10440000
42#define EXYNOS5_PA_COMBINER 0x10440000
43
44#define EXYNOS4_PA_GIC_CPU 0x10480000
45#define EXYNOS4_PA_GIC_DIST 0x10490000
46#define EXYNOS5_PA_GIC_CPU 0x10482000
47#define EXYNOS5_PA_GIC_DIST 0x10481000
48
49#define EXYNOS4_PA_COREPERI 0x10500000 36#define EXYNOS4_PA_COREPERI 0x10500000
50#define EXYNOS4_PA_L2CC 0x10502000 37#define EXYNOS4_PA_L2CC 0x10502000
51 38
52#define EXYNOS4_PA_SROMC 0x12570000 39#define EXYNOS4_PA_SROMC 0x12570000
53#define EXYNOS5_PA_SROMC 0x12250000 40#define EXYNOS5_PA_SROMC 0x12250000
54 41
55#define EXYNOS4_PA_HSPHY 0x125B0000
56
57#define EXYNOS4_PA_UART 0x13800000
58#define EXYNOS5_PA_UART 0x12C00000
59
60#define EXYNOS4_PA_TIMER 0x139D0000
61#define EXYNOS5_PA_TIMER 0x12DD0000
62
63/* Compatibility UART */ 42/* Compatibility UART */
64 43
65#define EXYNOS5440_PA_UART0 0x000B0000 44#define EXYNOS5440_PA_UART0 0x000B0000
66 45
67#define S3C_VA_UARTx(x) (S3C_VA_UART + ((x) * S3C_UART_OFFSET))
68
69#endif /* __ASM_ARCH_MAP_H */ 46#endif /* __ASM_ARCH_MAP_H */
diff --git a/arch/arm/mach-imx/clk-imx6q.c b/arch/arm/mach-imx/clk-imx6q.c
index 4e79da7c5e30..5951660d1bd2 100644
--- a/arch/arm/mach-imx/clk-imx6q.c
+++ b/arch/arm/mach-imx/clk-imx6q.c
@@ -145,7 +145,7 @@ static void __init imx6q_clocks_init(struct device_node *ccm_node)
145 post_div_table[2].div = 1; 145 post_div_table[2].div = 1;
146 video_div_table[1].div = 1; 146 video_div_table[1].div = 1;
147 video_div_table[2].div = 1; 147 video_div_table[2].div = 1;
148 }; 148 }
149 149
150 clk[IMX6QDL_PLL1_BYPASS_SRC] = imx_clk_mux("pll1_bypass_src", base + 0x00, 14, 2, pll_bypass_src_sels, ARRAY_SIZE(pll_bypass_src_sels)); 150 clk[IMX6QDL_PLL1_BYPASS_SRC] = imx_clk_mux("pll1_bypass_src", base + 0x00, 14, 2, pll_bypass_src_sels, ARRAY_SIZE(pll_bypass_src_sels));
151 clk[IMX6QDL_PLL2_BYPASS_SRC] = imx_clk_mux("pll2_bypass_src", base + 0x30, 14, 2, pll_bypass_src_sels, ARRAY_SIZE(pll_bypass_src_sels)); 151 clk[IMX6QDL_PLL2_BYPASS_SRC] = imx_clk_mux("pll2_bypass_src", base + 0x30, 14, 2, pll_bypass_src_sels, ARRAY_SIZE(pll_bypass_src_sels));
diff --git a/arch/arm/mach-imx/clk-pllv3.c b/arch/arm/mach-imx/clk-pllv3.c
index 57de74da0acf..0ad6e5442fd8 100644
--- a/arch/arm/mach-imx/clk-pllv3.c
+++ b/arch/arm/mach-imx/clk-pllv3.c
@@ -69,7 +69,6 @@ static int clk_pllv3_prepare(struct clk_hw *hw)
69{ 69{
70 struct clk_pllv3 *pll = to_clk_pllv3(hw); 70 struct clk_pllv3 *pll = to_clk_pllv3(hw);
71 u32 val; 71 u32 val;
72 int ret;
73 72
74 val = readl_relaxed(pll->base); 73 val = readl_relaxed(pll->base);
75 if (pll->powerup_set) 74 if (pll->powerup_set)
@@ -78,11 +77,7 @@ static int clk_pllv3_prepare(struct clk_hw *hw)
78 val &= ~BM_PLL_POWER; 77 val &= ~BM_PLL_POWER;
79 writel_relaxed(val, pll->base); 78 writel_relaxed(val, pll->base);
80 79
81 ret = clk_pllv3_wait_lock(pll); 80 return clk_pllv3_wait_lock(pll);
82 if (ret)
83 return ret;
84
85 return 0;
86} 81}
87 82
88static void clk_pllv3_unprepare(struct clk_hw *hw) 83static void clk_pllv3_unprepare(struct clk_hw *hw)
diff --git a/arch/arm/mach-imx/common.h b/arch/arm/mach-imx/common.h
index fe9a908da3ed..cfcdb623d78f 100644
--- a/arch/arm/mach-imx/common.h
+++ b/arch/arm/mach-imx/common.h
@@ -61,7 +61,6 @@ struct platform_device *mxc_register_gpio(char *name, int id,
61void mxc_set_cpu_type(unsigned int type); 61void mxc_set_cpu_type(unsigned int type);
62void mxc_restart(enum reboot_mode, const char *); 62void mxc_restart(enum reboot_mode, const char *);
63void mxc_arch_reset_init(void __iomem *); 63void mxc_arch_reset_init(void __iomem *);
64void mxc_arch_reset_init_dt(void);
65int mx51_revision(void); 64int mx51_revision(void);
66int mx53_revision(void); 65int mx53_revision(void);
67void imx_set_aips(void __iomem *); 66void imx_set_aips(void __iomem *);
@@ -108,8 +107,8 @@ void imx_gpc_pre_suspend(bool arm_power_off);
108void imx_gpc_post_resume(void); 107void imx_gpc_post_resume(void);
109void imx_gpc_mask_all(void); 108void imx_gpc_mask_all(void);
110void imx_gpc_restore_all(void); 109void imx_gpc_restore_all(void);
111void imx_gpc_irq_mask(struct irq_data *d); 110void imx_gpc_hwirq_mask(unsigned int hwirq);
112void imx_gpc_irq_unmask(struct irq_data *d); 111void imx_gpc_hwirq_unmask(unsigned int hwirq);
113void imx_anatop_init(void); 112void imx_anatop_init(void);
114void imx_anatop_pre_suspend(void); 113void imx_anatop_pre_suspend(void);
115void imx_anatop_post_resume(void); 114void imx_anatop_post_resume(void);
diff --git a/arch/arm/mach-imx/gpc.c b/arch/arm/mach-imx/gpc.c
index 82ea74e68482..5f3602ec74fa 100644
--- a/arch/arm/mach-imx/gpc.c
+++ b/arch/arm/mach-imx/gpc.c
@@ -56,14 +56,14 @@ void imx_gpc_post_resume(void)
56 56
57static int imx_gpc_irq_set_wake(struct irq_data *d, unsigned int on) 57static int imx_gpc_irq_set_wake(struct irq_data *d, unsigned int on)
58{ 58{
59 unsigned int idx = d->irq / 32 - 1; 59 unsigned int idx = d->hwirq / 32 - 1;
60 u32 mask; 60 u32 mask;
61 61
62 /* Sanity check for SPI irq */ 62 /* Sanity check for SPI irq */
63 if (d->irq < 32) 63 if (d->hwirq < 32)
64 return -EINVAL; 64 return -EINVAL;
65 65
66 mask = 1 << d->irq % 32; 66 mask = 1 << d->hwirq % 32;
67 gpc_wake_irqs[idx] = on ? gpc_wake_irqs[idx] | mask : 67 gpc_wake_irqs[idx] = on ? gpc_wake_irqs[idx] | mask :
68 gpc_wake_irqs[idx] & ~mask; 68 gpc_wake_irqs[idx] & ~mask;
69 69
@@ -91,34 +91,44 @@ void imx_gpc_restore_all(void)
91 writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4); 91 writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
92} 92}
93 93
94void imx_gpc_irq_unmask(struct irq_data *d) 94void imx_gpc_hwirq_unmask(unsigned int hwirq)
95{ 95{
96 void __iomem *reg; 96 void __iomem *reg;
97 u32 val; 97 u32 val;
98 98
99 /* Sanity check for SPI irq */ 99 reg = gpc_base + GPC_IMR1 + (hwirq / 32 - 1) * 4;
100 if (d->irq < 32)
101 return;
102
103 reg = gpc_base + GPC_IMR1 + (d->irq / 32 - 1) * 4;
104 val = readl_relaxed(reg); 100 val = readl_relaxed(reg);
105 val &= ~(1 << d->irq % 32); 101 val &= ~(1 << hwirq % 32);
106 writel_relaxed(val, reg); 102 writel_relaxed(val, reg);
107} 103}
108 104
109void imx_gpc_irq_mask(struct irq_data *d) 105void imx_gpc_hwirq_mask(unsigned int hwirq)
110{ 106{
111 void __iomem *reg; 107 void __iomem *reg;
112 u32 val; 108 u32 val;
113 109
110 reg = gpc_base + GPC_IMR1 + (hwirq / 32 - 1) * 4;
111 val = readl_relaxed(reg);
112 val |= 1 << (hwirq % 32);
113 writel_relaxed(val, reg);
114}
115
116static void imx_gpc_irq_unmask(struct irq_data *d)
117{
118 /* Sanity check for SPI irq */
119 if (d->hwirq < 32)
120 return;
121
122 imx_gpc_hwirq_unmask(d->hwirq);
123}
124
125static void imx_gpc_irq_mask(struct irq_data *d)
126{
114 /* Sanity check for SPI irq */ 127 /* Sanity check for SPI irq */
115 if (d->irq < 32) 128 if (d->hwirq < 32)
116 return; 129 return;
117 130
118 reg = gpc_base + GPC_IMR1 + (d->irq / 32 - 1) * 4; 131 imx_gpc_hwirq_mask(d->hwirq);
119 val = readl_relaxed(reg);
120 val |= 1 << (d->irq % 32);
121 writel_relaxed(val, reg);
122} 132}
123 133
124void __init imx_gpc_init(void) 134void __init imx_gpc_init(void)
diff --git a/arch/arm/mach-imx/imx25-dt.c b/arch/arm/mach-imx/imx25-dt.c
index cf8032bae277..25defbdb06c4 100644
--- a/arch/arm/mach-imx/imx25-dt.c
+++ b/arch/arm/mach-imx/imx25-dt.c
@@ -17,13 +17,6 @@
17#include "common.h" 17#include "common.h"
18#include "mx25.h" 18#include "mx25.h"
19 19
20static void __init imx25_dt_init(void)
21{
22 mxc_arch_reset_init_dt();
23
24 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
25}
26
27static const char * const imx25_dt_board_compat[] __initconst = { 20static const char * const imx25_dt_board_compat[] __initconst = {
28 "fsl,imx25", 21 "fsl,imx25",
29 NULL 22 NULL
@@ -33,7 +26,5 @@ DT_MACHINE_START(IMX25_DT, "Freescale i.MX25 (Device Tree Support)")
33 .map_io = mx25_map_io, 26 .map_io = mx25_map_io,
34 .init_early = imx25_init_early, 27 .init_early = imx25_init_early,
35 .init_irq = mx25_init_irq, 28 .init_irq = mx25_init_irq,
36 .init_machine = imx25_dt_init,
37 .dt_compat = imx25_dt_board_compat, 29 .dt_compat = imx25_dt_board_compat,
38 .restart = mxc_restart,
39MACHINE_END 30MACHINE_END
diff --git a/arch/arm/mach-imx/imx27-dt.c b/arch/arm/mach-imx/imx27-dt.c
index dc8f1a6f45f2..bd42d1bd10af 100644
--- a/arch/arm/mach-imx/imx27-dt.c
+++ b/arch/arm/mach-imx/imx27-dt.c
@@ -22,8 +22,6 @@ static void __init imx27_dt_init(void)
22{ 22{
23 struct platform_device_info devinfo = { .name = "cpufreq-dt", }; 23 struct platform_device_info devinfo = { .name = "cpufreq-dt", };
24 24
25 mxc_arch_reset_init_dt();
26
27 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); 25 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
28 26
29 platform_device_register_full(&devinfo); 27 platform_device_register_full(&devinfo);
@@ -40,5 +38,4 @@ DT_MACHINE_START(IMX27_DT, "Freescale i.MX27 (Device Tree Support)")
40 .init_irq = mx27_init_irq, 38 .init_irq = mx27_init_irq,
41 .init_machine = imx27_dt_init, 39 .init_machine = imx27_dt_init,
42 .dt_compat = imx27_dt_board_compat, 40 .dt_compat = imx27_dt_board_compat,
43 .restart = mxc_restart,
44MACHINE_END 41MACHINE_END
diff --git a/arch/arm/mach-imx/imx31-dt.c b/arch/arm/mach-imx/imx31-dt.c
index 418dbc82adc4..32100222a017 100644
--- a/arch/arm/mach-imx/imx31-dt.c
+++ b/arch/arm/mach-imx/imx31-dt.c
@@ -18,13 +18,6 @@
18#include "common.h" 18#include "common.h"
19#include "mx31.h" 19#include "mx31.h"
20 20
21static void __init imx31_dt_init(void)
22{
23 mxc_arch_reset_init_dt();
24
25 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
26}
27
28static const char * const imx31_dt_board_compat[] __initconst = { 21static const char * const imx31_dt_board_compat[] __initconst = {
29 "fsl,imx31", 22 "fsl,imx31",
30 NULL 23 NULL
@@ -40,7 +33,5 @@ DT_MACHINE_START(IMX31_DT, "Freescale i.MX31 (Device Tree Support)")
40 .init_early = imx31_init_early, 33 .init_early = imx31_init_early,
41 .init_irq = mx31_init_irq, 34 .init_irq = mx31_init_irq,
42 .init_time = imx31_dt_timer_init, 35 .init_time = imx31_dt_timer_init,
43 .init_machine = imx31_dt_init,
44 .dt_compat = imx31_dt_board_compat, 36 .dt_compat = imx31_dt_board_compat,
45 .restart = mxc_restart,
46MACHINE_END 37MACHINE_END
diff --git a/arch/arm/mach-imx/imx35-dt.c b/arch/arm/mach-imx/imx35-dt.c
index 584fbe105579..e9396037235d 100644
--- a/arch/arm/mach-imx/imx35-dt.c
+++ b/arch/arm/mach-imx/imx35-dt.c
@@ -20,14 +20,6 @@
20#include "common.h" 20#include "common.h"
21#include "mx35.h" 21#include "mx35.h"
22 22
23static void __init imx35_dt_init(void)
24{
25 mxc_arch_reset_init_dt();
26
27 of_platform_populate(NULL, of_default_bus_match_table,
28 NULL, NULL);
29}
30
31static void __init imx35_irq_init(void) 23static void __init imx35_irq_init(void)
32{ 24{
33 imx_init_l2cache(); 25 imx_init_l2cache();
@@ -43,7 +35,5 @@ DT_MACHINE_START(IMX35_DT, "Freescale i.MX35 (Device Tree Support)")
43 .map_io = mx35_map_io, 35 .map_io = mx35_map_io,
44 .init_early = imx35_init_early, 36 .init_early = imx35_init_early,
45 .init_irq = imx35_irq_init, 37 .init_irq = imx35_irq_init,
46 .init_machine = imx35_dt_init,
47 .dt_compat = imx35_dt_board_compat, 38 .dt_compat = imx35_dt_board_compat,
48 .restart = mxc_restart,
49MACHINE_END 39MACHINE_END
diff --git a/arch/arm/mach-imx/iomux-imx31.c b/arch/arm/mach-imx/iomux-imx31.c
index 1657fe64cd0f..d6a30753ca7c 100644
--- a/arch/arm/mach-imx/iomux-imx31.c
+++ b/arch/arm/mach-imx/iomux-imx31.c
@@ -44,9 +44,11 @@ static unsigned long mxc_pin_alloc_map[NB_PORTS * 32 / BITS_PER_LONG];
44/* 44/*
45 * set the mode for a IOMUX pin. 45 * set the mode for a IOMUX pin.
46 */ 46 */
47int mxc_iomux_mode(unsigned int pin_mode) 47void mxc_iomux_mode(unsigned int pin_mode)
48{ 48{
49 u32 field, l, mode, ret = 0; 49 u32 field;
50 u32 l;
51 u32 mode;
50 void __iomem *reg; 52 void __iomem *reg;
51 53
52 reg = IOMUXSW_MUX_CTL + (pin_mode & IOMUX_REG_MASK); 54 reg = IOMUXSW_MUX_CTL + (pin_mode & IOMUX_REG_MASK);
@@ -61,8 +63,6 @@ int mxc_iomux_mode(unsigned int pin_mode)
61 __raw_writel(l, reg); 63 __raw_writel(l, reg);
62 64
63 spin_unlock(&gpio_mux_lock); 65 spin_unlock(&gpio_mux_lock);
64
65 return ret;
66} 66}
67 67
68/* 68/*
diff --git a/arch/arm/mach-imx/iomux-mx3.h b/arch/arm/mach-imx/iomux-mx3.h
index f79f78a1c0ed..0a5adba61e0b 100644
--- a/arch/arm/mach-imx/iomux-mx3.h
+++ b/arch/arm/mach-imx/iomux-mx3.h
@@ -144,7 +144,7 @@ void mxc_iomux_set_gpr(enum iomux_gp_func, bool en);
144 * It is called by the setup functions and should not be called directly anymore. 144 * It is called by the setup functions and should not be called directly anymore.
145 * It is here visible for backward compatibility 145 * It is here visible for backward compatibility
146 */ 146 */
147int mxc_iomux_mode(unsigned int pin_mode); 147void mxc_iomux_mode(unsigned int pin_mode);
148 148
149#define IOMUX_PADNUM_MASK 0x1ff 149#define IOMUX_PADNUM_MASK 0x1ff
150#define IOMUX_GPIONUM_SHIFT 9 150#define IOMUX_GPIONUM_SHIFT 9
diff --git a/arch/arm/mach-imx/mach-imx50.c b/arch/arm/mach-imx/mach-imx50.c
index b1e56a94a382..ecf58b9e974b 100644
--- a/arch/arm/mach-imx/mach-imx50.c
+++ b/arch/arm/mach-imx/mach-imx50.c
@@ -16,13 +16,6 @@
16 16
17#include "common.h" 17#include "common.h"
18 18
19static void __init imx50_dt_init(void)
20{
21 mxc_arch_reset_init_dt();
22
23 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
24}
25
26static const char * const imx50_dt_board_compat[] __initconst = { 19static const char * const imx50_dt_board_compat[] __initconst = {
27 "fsl,imx50", 20 "fsl,imx50",
28 NULL 21 NULL
@@ -30,7 +23,5 @@ static const char * const imx50_dt_board_compat[] __initconst = {
30 23
31DT_MACHINE_START(IMX50_DT, "Freescale i.MX50 (Device Tree Support)") 24DT_MACHINE_START(IMX50_DT, "Freescale i.MX50 (Device Tree Support)")
32 .init_irq = tzic_init_irq, 25 .init_irq = tzic_init_irq,
33 .init_machine = imx50_dt_init,
34 .dt_compat = imx50_dt_board_compat, 26 .dt_compat = imx50_dt_board_compat,
35 .restart = mxc_restart,
36MACHINE_END 27MACHINE_END
diff --git a/arch/arm/mach-imx/mach-imx51.c b/arch/arm/mach-imx/mach-imx51.c
index 2c5fcaf8675b..b015129e4045 100644
--- a/arch/arm/mach-imx/mach-imx51.c
+++ b/arch/arm/mach-imx/mach-imx51.c
@@ -53,7 +53,6 @@ static void __init imx51_dt_init(void)
53{ 53{
54 struct platform_device_info devinfo = { .name = "cpufreq-dt", }; 54 struct platform_device_info devinfo = { .name = "cpufreq-dt", };
55 55
56 mxc_arch_reset_init_dt();
57 imx51_ipu_mipi_setup(); 56 imx51_ipu_mipi_setup();
58 imx_src_init(); 57 imx_src_init();
59 58
@@ -78,5 +77,4 @@ DT_MACHINE_START(IMX51_DT, "Freescale i.MX51 (Device Tree Support)")
78 .init_machine = imx51_dt_init, 77 .init_machine = imx51_dt_init,
79 .init_late = imx51_init_late, 78 .init_late = imx51_init_late,
80 .dt_compat = imx51_dt_board_compat, 79 .dt_compat = imx51_dt_board_compat,
81 .restart = mxc_restart,
82MACHINE_END 80MACHINE_END
diff --git a/arch/arm/mach-imx/mach-imx53.c b/arch/arm/mach-imx/mach-imx53.c
index 7587cf0cba3e..86316a979297 100644
--- a/arch/arm/mach-imx/mach-imx53.c
+++ b/arch/arm/mach-imx/mach-imx53.c
@@ -30,7 +30,6 @@ static void __init imx53_init_early(void)
30 30
31static void __init imx53_dt_init(void) 31static void __init imx53_dt_init(void)
32{ 32{
33 mxc_arch_reset_init_dt();
34 imx_src_init(); 33 imx_src_init();
35 34
36 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL); 35 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
@@ -56,5 +55,4 @@ DT_MACHINE_START(IMX53_DT, "Freescale i.MX53 (Device Tree Support)")
56 .init_machine = imx53_dt_init, 55 .init_machine = imx53_dt_init,
57 .init_late = imx53_init_late, 56 .init_late = imx53_init_late,
58 .dt_compat = imx53_dt_board_compat, 57 .dt_compat = imx53_dt_board_compat,
59 .restart = mxc_restart,
60MACHINE_END 58MACHINE_END
diff --git a/arch/arm/mach-imx/mach-imx6q.c b/arch/arm/mach-imx/mach-imx6q.c
index d51c6e99a2e9..5057d61298b7 100644
--- a/arch/arm/mach-imx/mach-imx6q.c
+++ b/arch/arm/mach-imx/mach-imx6q.c
@@ -268,8 +268,6 @@ static void __init imx6q_init_machine(void)
268 imx_print_silicon_rev(cpu_is_imx6dl() ? "i.MX6DL" : "i.MX6Q", 268 imx_print_silicon_rev(cpu_is_imx6dl() ? "i.MX6DL" : "i.MX6Q",
269 imx_get_soc_revision()); 269 imx_get_soc_revision());
270 270
271 mxc_arch_reset_init_dt();
272
273 parent = imx_soc_device_init(); 271 parent = imx_soc_device_init();
274 if (parent == NULL) 272 if (parent == NULL)
275 pr_warn("failed to initialize soc device\n"); 273 pr_warn("failed to initialize soc device\n");
@@ -409,5 +407,4 @@ DT_MACHINE_START(IMX6Q, "Freescale i.MX6 Quad/DualLite (Device Tree)")
409 .init_machine = imx6q_init_machine, 407 .init_machine = imx6q_init_machine,
410 .init_late = imx6q_init_late, 408 .init_late = imx6q_init_late,
411 .dt_compat = imx6q_dt_compat, 409 .dt_compat = imx6q_dt_compat,
412 .restart = mxc_restart,
413MACHINE_END 410MACHINE_END
diff --git a/arch/arm/mach-imx/mach-imx6sl.c b/arch/arm/mach-imx/mach-imx6sl.c
index ed263a21d928..24bfaaf944c8 100644
--- a/arch/arm/mach-imx/mach-imx6sl.c
+++ b/arch/arm/mach-imx/mach-imx6sl.c
@@ -48,8 +48,6 @@ static void __init imx6sl_init_machine(void)
48{ 48{
49 struct device *parent; 49 struct device *parent;
50 50
51 mxc_arch_reset_init_dt();
52
53 parent = imx_soc_device_init(); 51 parent = imx_soc_device_init();
54 if (parent == NULL) 52 if (parent == NULL)
55 pr_warn("failed to initialize soc device\n"); 53 pr_warn("failed to initialize soc device\n");
@@ -76,10 +74,8 @@ static const char * const imx6sl_dt_compat[] __initconst = {
76}; 74};
77 75
78DT_MACHINE_START(IMX6SL, "Freescale i.MX6 SoloLite (Device Tree)") 76DT_MACHINE_START(IMX6SL, "Freescale i.MX6 SoloLite (Device Tree)")
79 .map_io = debug_ll_io_init,
80 .init_irq = imx6sl_init_irq, 77 .init_irq = imx6sl_init_irq,
81 .init_machine = imx6sl_init_machine, 78 .init_machine = imx6sl_init_machine,
82 .init_late = imx6sl_init_late, 79 .init_late = imx6sl_init_late,
83 .dt_compat = imx6sl_dt_compat, 80 .dt_compat = imx6sl_dt_compat,
84 .restart = mxc_restart,
85MACHINE_END 81MACHINE_END
diff --git a/arch/arm/mach-imx/mach-imx6sx.c b/arch/arm/mach-imx/mach-imx6sx.c
index 982224922fb1..7a96c6577234 100644
--- a/arch/arm/mach-imx/mach-imx6sx.c
+++ b/arch/arm/mach-imx/mach-imx6sx.c
@@ -68,8 +68,6 @@ static void __init imx6sx_init_machine(void)
68{ 68{
69 struct device *parent; 69 struct device *parent;
70 70
71 mxc_arch_reset_init_dt();
72
73 parent = imx_soc_device_init(); 71 parent = imx_soc_device_init();
74 if (parent == NULL) 72 if (parent == NULL)
75 pr_warn("failed to initialize soc device\n"); 73 pr_warn("failed to initialize soc device\n");
@@ -104,10 +102,8 @@ static const char * const imx6sx_dt_compat[] __initconst = {
104}; 102};
105 103
106DT_MACHINE_START(IMX6SX, "Freescale i.MX6 SoloX (Device Tree)") 104DT_MACHINE_START(IMX6SX, "Freescale i.MX6 SoloX (Device Tree)")
107 .map_io = debug_ll_io_init,
108 .init_irq = imx6sx_init_irq, 105 .init_irq = imx6sx_init_irq,
109 .init_machine = imx6sx_init_machine, 106 .init_machine = imx6sx_init_machine,
110 .dt_compat = imx6sx_dt_compat, 107 .dt_compat = imx6sx_dt_compat,
111 .init_late = imx6sx_init_late, 108 .init_late = imx6sx_init_late,
112 .restart = mxc_restart,
113MACHINE_END 109MACHINE_END
diff --git a/arch/arm/mach-imx/mach-vf610.c b/arch/arm/mach-imx/mach-vf610.c
index ee7e57b752a7..c11ab6a1dc87 100644
--- a/arch/arm/mach-imx/mach-vf610.c
+++ b/arch/arm/mach-imx/mach-vf610.c
@@ -12,14 +12,6 @@
12#include <asm/mach/arch.h> 12#include <asm/mach/arch.h>
13#include <asm/hardware/cache-l2x0.h> 13#include <asm/hardware/cache-l2x0.h>
14 14
15#include "common.h"
16
17static void __init vf610_init_machine(void)
18{
19 mxc_arch_reset_init_dt();
20 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
21}
22
23static const char * const vf610_dt_compat[] __initconst = { 15static const char * const vf610_dt_compat[] __initconst = {
24 "fsl,vf610", 16 "fsl,vf610",
25 NULL, 17 NULL,
@@ -28,7 +20,5 @@ static const char * const vf610_dt_compat[] __initconst = {
28DT_MACHINE_START(VYBRID_VF610, "Freescale Vybrid VF610 (Device Tree)") 20DT_MACHINE_START(VYBRID_VF610, "Freescale Vybrid VF610 (Device Tree)")
29 .l2c_aux_val = 0, 21 .l2c_aux_val = 0,
30 .l2c_aux_mask = ~0, 22 .l2c_aux_mask = ~0,
31 .init_machine = vf610_init_machine,
32 .dt_compat = vf610_dt_compat, 23 .dt_compat = vf610_dt_compat,
33 .restart = mxc_restart,
34MACHINE_END 24MACHINE_END
diff --git a/arch/arm/mach-imx/pm-imx6.c b/arch/arm/mach-imx/pm-imx6.c
index c653dd4c9103..5d2c1bd5f5ef 100644
--- a/arch/arm/mach-imx/pm-imx6.c
+++ b/arch/arm/mach-imx/pm-imx6.c
@@ -257,7 +257,6 @@ static void imx6q_enable_wb(bool enable)
257 257
258int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode) 258int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode)
259{ 259{
260 struct irq_data *iomuxc_irq_data = irq_get_irq_data(32);
261 u32 val = readl_relaxed(ccm_base + CLPCR); 260 u32 val = readl_relaxed(ccm_base + CLPCR);
262 261
263 val &= ~BM_CLPCR_LPM; 262 val &= ~BM_CLPCR_LPM;
@@ -312,9 +311,9 @@ int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode)
312 * 3) Software should mask IRQ #32 right after CCM Low-Power mode 311 * 3) Software should mask IRQ #32 right after CCM Low-Power mode
313 * is set (set bits 0-1 of CCM_CLPCR). 312 * is set (set bits 0-1 of CCM_CLPCR).
314 */ 313 */
315 imx_gpc_irq_unmask(iomuxc_irq_data); 314 imx_gpc_hwirq_unmask(32);
316 writel_relaxed(val, ccm_base + CLPCR); 315 writel_relaxed(val, ccm_base + CLPCR);
317 imx_gpc_irq_mask(iomuxc_irq_data); 316 imx_gpc_hwirq_mask(32);
318 317
319 return 0; 318 return 0;
320} 319}
diff --git a/arch/arm/mach-imx/system.c b/arch/arm/mach-imx/system.c
index d14c33fd6b03..51c35013b673 100644
--- a/arch/arm/mach-imx/system.c
+++ b/arch/arm/mach-imx/system.c
@@ -89,21 +89,6 @@ void __init mxc_arch_reset_init(void __iomem *base)
89 clk_prepare(wdog_clk); 89 clk_prepare(wdog_clk);
90} 90}
91 91
92void __init mxc_arch_reset_init_dt(void)
93{
94 struct device_node *np;
95
96 np = of_find_compatible_node(NULL, NULL, "fsl,imx21-wdt");
97 wdog_base = of_iomap(np, 0);
98 WARN_ON(!wdog_base);
99
100 wdog_clk = of_clk_get(np, 0);
101 if (IS_ERR(wdog_clk))
102 pr_warn("%s: failed to get wdog clock\n", __func__);
103 else
104 clk_prepare(wdog_clk);
105}
106
107#ifdef CONFIG_CACHE_L2X0 92#ifdef CONFIG_CACHE_L2X0
108void __init imx_init_l2cache(void) 93void __init imx_init_l2cache(void)
109{ 94{
diff --git a/arch/arm/mach-ixp4xx/include/mach/io.h b/arch/arm/mach-ixp4xx/include/mach/io.h
index 559c69a47731..7d11979da030 100644
--- a/arch/arm/mach-ixp4xx/include/mach/io.h
+++ b/arch/arm/mach-ixp4xx/include/mach/io.h
@@ -76,7 +76,7 @@ static inline void __indirect_writeb(u8 value, volatile void __iomem *p)
76 u32 n, byte_enables, data; 76 u32 n, byte_enables, data;
77 77
78 if (!is_pci_memory(addr)) { 78 if (!is_pci_memory(addr)) {
79 __raw_writeb(value, addr); 79 __raw_writeb(value, p);
80 return; 80 return;
81 } 81 }
82 82
@@ -141,7 +141,7 @@ static inline unsigned char __indirect_readb(const volatile void __iomem *p)
141 u32 n, byte_enables, data; 141 u32 n, byte_enables, data;
142 142
143 if (!is_pci_memory(addr)) 143 if (!is_pci_memory(addr))
144 return __raw_readb(addr); 144 return __raw_readb(p);
145 145
146 n = addr % 4; 146 n = addr % 4;
147 byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL; 147 byte_enables = (0xf & ~BIT(n)) << IXP4XX_PCI_NP_CBE_BESL;
diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
index 97767a27ca9d..e0ad64fde20e 100644
--- a/arch/arm/mach-omap2/board-n8x0.c
+++ b/arch/arm/mach-omap2/board-n8x0.c
@@ -21,8 +21,10 @@
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/spi/spi.h> 22#include <linux/spi/spi.h>
23#include <linux/usb/musb.h> 23#include <linux/usb/musb.h>
24#include <linux/mmc/host.h>
24#include <linux/platform_data/spi-omap2-mcspi.h> 25#include <linux/platform_data/spi-omap2-mcspi.h>
25#include <linux/platform_data/mtd-onenand-omap2.h> 26#include <linux/platform_data/mtd-onenand-omap2.h>
27#include <linux/platform_data/mmc-omap.h>
26#include <linux/mfd/menelaus.h> 28#include <linux/mfd/menelaus.h>
27#include <sound/tlv320aic3x.h> 29#include <sound/tlv320aic3x.h>
28 30
diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c
index ddfc8df83c6a..3d5040f82e90 100644
--- a/arch/arm/mach-omap2/board-rx51-peripherals.c
+++ b/arch/arm/mach-omap2/board-rx51-peripherals.c
@@ -484,7 +484,7 @@ static struct omap_mux_partition *partition;
484 * Current flows to eMMC when eMMC is off and the data lines are pulled up, 484 * Current flows to eMMC when eMMC is off and the data lines are pulled up,
485 * so pull them down. N.B. we pull 8 lines because we are using 8 lines. 485 * so pull them down. N.B. we pull 8 lines because we are using 8 lines.
486 */ 486 */
487static void rx51_mmc2_remux(struct device *dev, int slot, int power_on) 487static void rx51_mmc2_remux(struct device *dev, int power_on)
488{ 488{
489 if (power_on) 489 if (power_on)
490 omap_mux_write_array(partition, rx51_mmc2_on_mux); 490 omap_mux_write_array(partition, rx51_mmc2_on_mux);
@@ -500,7 +500,6 @@ static struct omap2_hsmmc_info mmc[] __initdata = {
500 .cover_only = true, 500 .cover_only = true,
501 .gpio_cd = 160, 501 .gpio_cd = 160,
502 .gpio_wp = -EINVAL, 502 .gpio_wp = -EINVAL,
503 .power_saving = true,
504 }, 503 },
505 { 504 {
506 .name = "internal", 505 .name = "internal",
@@ -510,7 +509,6 @@ static struct omap2_hsmmc_info mmc[] __initdata = {
510 .gpio_cd = -EINVAL, 509 .gpio_cd = -EINVAL,
511 .gpio_wp = -EINVAL, 510 .gpio_wp = -EINVAL,
512 .nonremovable = true, 511 .nonremovable = true,
513 .power_saving = true,
514 .remux = rx51_mmc2_remux, 512 .remux = rx51_mmc2_remux,
515 }, 513 },
516 {} /* Terminator */ 514 {} /* Terminator */
diff --git a/arch/arm/mach-omap2/devices.c b/arch/arm/mach-omap2/devices.c
index 324f02bf8a51..492ef1607115 100644
--- a/arch/arm/mach-omap2/devices.c
+++ b/arch/arm/mach-omap2/devices.c
@@ -49,7 +49,7 @@ static int __init omap3_l3_init(void)
49 * To avoid code running on other OMAPs in 49 * To avoid code running on other OMAPs in
50 * multi-omap builds 50 * multi-omap builds
51 */ 51 */
52 if (!(cpu_is_omap34xx())) 52 if (!(cpu_is_omap34xx()) || of_have_populated_dt())
53 return -ENODEV; 53 return -ENODEV;
54 54
55 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main"); 55 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main");
@@ -67,40 +67,6 @@ static int __init omap3_l3_init(void)
67} 67}
68omap_postcore_initcall(omap3_l3_init); 68omap_postcore_initcall(omap3_l3_init);
69 69
70static int __init omap4_l3_init(void)
71{
72 int i;
73 struct omap_hwmod *oh[3];
74 struct platform_device *pdev;
75 char oh_name[L3_MODULES_MAX_LEN];
76
77 /* If dtb is there, the devices will be created dynamically */
78 if (of_have_populated_dt())
79 return -ENODEV;
80
81 /*
82 * To avoid code running on other OMAPs in
83 * multi-omap builds
84 */
85 if (!cpu_is_omap44xx() && !soc_is_omap54xx())
86 return -ENODEV;
87
88 for (i = 0; i < L3_MODULES; i++) {
89 snprintf(oh_name, L3_MODULES_MAX_LEN, "l3_main_%d", i+1);
90
91 oh[i] = omap_hwmod_lookup(oh_name);
92 if (!(oh[i]))
93 pr_err("could not look up %s\n", oh_name);
94 }
95
96 pdev = omap_device_build_ss("omap_l3_noc", 0, oh, 3, NULL, 0);
97
98 WARN(IS_ERR(pdev), "could not build omap_device for %s\n", oh_name);
99
100 return PTR_RET(pdev);
101}
102omap_postcore_initcall(omap4_l3_init);
103
104#if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE) 70#if defined(CONFIG_VIDEO_OMAP2) || defined(CONFIG_VIDEO_OMAP2_MODULE)
105 71
106static struct resource omap2cam_resources[] = { 72static struct resource omap2cam_resources[] = {
diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
index 5fa3755261ce..8fb5bbce102f 100644
--- a/arch/arm/mach-omap2/gpmc.c
+++ b/arch/arm/mach-omap2/gpmc.c
@@ -1394,8 +1394,6 @@ static int gpmc_probe_nand_child(struct platform_device *pdev,
1394 if (gpmc_nand_data->elm_of_node == NULL) 1394 if (gpmc_nand_data->elm_of_node == NULL)
1395 gpmc_nand_data->elm_of_node = 1395 gpmc_nand_data->elm_of_node =
1396 of_parse_phandle(child, "elm_id", 0); 1396 of_parse_phandle(child, "elm_id", 0);
1397 if (gpmc_nand_data->elm_of_node == NULL)
1398 pr_warn("%s: ti,elm-id property not found\n", __func__);
1399 1397
1400 /* select ecc-scheme for NAND */ 1398 /* select ecc-scheme for NAND */
1401 if (of_property_read_string(child, "ti,nand-ecc-opt", &s)) { 1399 if (of_property_read_string(child, "ti,nand-ecc-opt", &s)) {
diff --git a/arch/arm/mach-omap2/hsmmc.c b/arch/arm/mach-omap2/hsmmc.c
index 07d4c7b35754..dc6e79c4484a 100644
--- a/arch/arm/mach-omap2/hsmmc.c
+++ b/arch/arm/mach-omap2/hsmmc.c
@@ -14,14 +14,15 @@
14#include <linux/string.h> 14#include <linux/string.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/mmc/host.h>
17#include <linux/platform_data/gpio-omap.h> 18#include <linux/platform_data/gpio-omap.h>
19#include <linux/platform_data/hsmmc-omap.h>
18 20
19#include "soc.h" 21#include "soc.h"
20#include "omap_device.h" 22#include "omap_device.h"
21#include "omap-pm.h" 23#include "omap-pm.h"
22 24
23#include "mux.h" 25#include "mux.h"
24#include "mmc.h"
25#include "hsmmc.h" 26#include "hsmmc.h"
26#include "control.h" 27#include "control.h"
27 28
@@ -32,25 +33,14 @@ static u16 control_devconf1_offset;
32 33
33#define HSMMC_NAME_LEN 9 34#define HSMMC_NAME_LEN 9
34 35
35#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM) 36static void omap_hsmmc1_before_set_reg(struct device *dev,
36 37 int power_on, int vdd)
37static int hsmmc_get_context_loss(struct device *dev)
38{
39 return omap_pm_get_dev_context_loss_count(dev);
40}
41
42#else
43#define hsmmc_get_context_loss NULL
44#endif
45
46static void omap_hsmmc1_before_set_reg(struct device *dev, int slot,
47 int power_on, int vdd)
48{ 38{
49 u32 reg, prog_io; 39 u32 reg, prog_io;
50 struct omap_mmc_platform_data *mmc = dev->platform_data; 40 struct omap_hsmmc_platform_data *mmc = dev->platform_data;
51 41
52 if (mmc->slots[0].remux) 42 if (mmc->remux)
53 mmc->slots[0].remux(dev, slot, power_on); 43 mmc->remux(dev, power_on);
54 44
55 /* 45 /*
56 * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the 46 * Assume we power both OMAP VMMC1 (for CMD, CLK, DAT0..3) and the
@@ -72,7 +62,7 @@ static void omap_hsmmc1_before_set_reg(struct device *dev, int slot,
72 omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1); 62 omap_ctrl_writel(reg, OMAP243X_CONTROL_DEVCONF1);
73 } 63 }
74 64
75 if (mmc->slots[0].internal_clock) { 65 if (mmc->internal_clock) {
76 reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0); 66 reg = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
77 reg |= OMAP2_MMCSDIO1ADPCLKISEL; 67 reg |= OMAP2_MMCSDIO1ADPCLKISEL;
78 omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0); 68 omap_ctrl_writel(reg, OMAP2_CONTROL_DEVCONF0);
@@ -96,8 +86,7 @@ static void omap_hsmmc1_before_set_reg(struct device *dev, int slot,
96 } 86 }
97} 87}
98 88
99static void omap_hsmmc1_after_set_reg(struct device *dev, int slot, 89static void omap_hsmmc1_after_set_reg(struct device *dev, int power_on, int vdd)
100 int power_on, int vdd)
101{ 90{
102 u32 reg; 91 u32 reg;
103 92
@@ -120,34 +109,32 @@ static void omap_hsmmc1_after_set_reg(struct device *dev, int slot,
120 } 109 }
121} 110}
122 111
123static void hsmmc2_select_input_clk_src(struct omap_mmc_platform_data *mmc) 112static void hsmmc2_select_input_clk_src(struct omap_hsmmc_platform_data *mmc)
124{ 113{
125 u32 reg; 114 u32 reg;
126 115
127 reg = omap_ctrl_readl(control_devconf1_offset); 116 reg = omap_ctrl_readl(control_devconf1_offset);
128 if (mmc->slots[0].internal_clock) 117 if (mmc->internal_clock)
129 reg |= OMAP2_MMCSDIO2ADPCLKISEL; 118 reg |= OMAP2_MMCSDIO2ADPCLKISEL;
130 else 119 else
131 reg &= ~OMAP2_MMCSDIO2ADPCLKISEL; 120 reg &= ~OMAP2_MMCSDIO2ADPCLKISEL;
132 omap_ctrl_writel(reg, control_devconf1_offset); 121 omap_ctrl_writel(reg, control_devconf1_offset);
133} 122}
134 123
135static void hsmmc2_before_set_reg(struct device *dev, int slot, 124static void hsmmc2_before_set_reg(struct device *dev, int power_on, int vdd)
136 int power_on, int vdd)
137{ 125{
138 struct omap_mmc_platform_data *mmc = dev->platform_data; 126 struct omap_hsmmc_platform_data *mmc = dev->platform_data;
139 127
140 if (mmc->slots[0].remux) 128 if (mmc->remux)
141 mmc->slots[0].remux(dev, slot, power_on); 129 mmc->remux(dev, power_on);
142 130
143 if (power_on) 131 if (power_on)
144 hsmmc2_select_input_clk_src(mmc); 132 hsmmc2_select_input_clk_src(mmc);
145} 133}
146 134
147static int am35x_hsmmc2_set_power(struct device *dev, int slot, 135static int am35x_hsmmc2_set_power(struct device *dev, int power_on, int vdd)
148 int power_on, int vdd)
149{ 136{
150 struct omap_mmc_platform_data *mmc = dev->platform_data; 137 struct omap_hsmmc_platform_data *mmc = dev->platform_data;
151 138
152 if (power_on) 139 if (power_on)
153 hsmmc2_select_input_clk_src(mmc); 140 hsmmc2_select_input_clk_src(mmc);
@@ -155,23 +142,22 @@ static int am35x_hsmmc2_set_power(struct device *dev, int slot,
155 return 0; 142 return 0;
156} 143}
157 144
158static int nop_mmc_set_power(struct device *dev, int slot, int power_on, 145static int nop_mmc_set_power(struct device *dev, int power_on, int vdd)
159 int vdd)
160{ 146{
161 return 0; 147 return 0;
162} 148}
163 149
164static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller, 150static inline void omap_hsmmc_mux(struct omap_hsmmc_platform_data
165 int controller_nr) 151 *mmc_controller, int controller_nr)
166{ 152{
167 if (gpio_is_valid(mmc_controller->slots[0].switch_pin) && 153 if (gpio_is_valid(mmc_controller->switch_pin) &&
168 (mmc_controller->slots[0].switch_pin < OMAP_MAX_GPIO_LINES)) 154 (mmc_controller->switch_pin < OMAP_MAX_GPIO_LINES))
169 omap_mux_init_gpio(mmc_controller->slots[0].switch_pin, 155 omap_mux_init_gpio(mmc_controller->switch_pin,
170 OMAP_PIN_INPUT_PULLUP); 156 OMAP_PIN_INPUT_PULLUP);
171 if (gpio_is_valid(mmc_controller->slots[0].gpio_wp) && 157 if (gpio_is_valid(mmc_controller->gpio_wp) &&
172 (mmc_controller->slots[0].gpio_wp < OMAP_MAX_GPIO_LINES)) 158 (mmc_controller->gpio_wp < OMAP_MAX_GPIO_LINES))
173 omap_mux_init_gpio(mmc_controller->slots[0].gpio_wp, 159 omap_mux_init_gpio(mmc_controller->gpio_wp,
174 OMAP_PIN_INPUT_PULLUP); 160 OMAP_PIN_INPUT_PULLUP);
175 if (cpu_is_omap34xx()) { 161 if (cpu_is_omap34xx()) {
176 if (controller_nr == 0) { 162 if (controller_nr == 0) {
177 omap_mux_init_signal("sdmmc1_clk", 163 omap_mux_init_signal("sdmmc1_clk",
@@ -180,7 +166,7 @@ static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller,
180 OMAP_PIN_INPUT_PULLUP); 166 OMAP_PIN_INPUT_PULLUP);
181 omap_mux_init_signal("sdmmc1_dat0", 167 omap_mux_init_signal("sdmmc1_dat0",
182 OMAP_PIN_INPUT_PULLUP); 168 OMAP_PIN_INPUT_PULLUP);
183 if (mmc_controller->slots[0].caps & 169 if (mmc_controller->caps &
184 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) { 170 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
185 omap_mux_init_signal("sdmmc1_dat1", 171 omap_mux_init_signal("sdmmc1_dat1",
186 OMAP_PIN_INPUT_PULLUP); 172 OMAP_PIN_INPUT_PULLUP);
@@ -189,7 +175,7 @@ static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller,
189 omap_mux_init_signal("sdmmc1_dat3", 175 omap_mux_init_signal("sdmmc1_dat3",
190 OMAP_PIN_INPUT_PULLUP); 176 OMAP_PIN_INPUT_PULLUP);
191 } 177 }
192 if (mmc_controller->slots[0].caps & 178 if (mmc_controller->caps &
193 MMC_CAP_8_BIT_DATA) { 179 MMC_CAP_8_BIT_DATA) {
194 omap_mux_init_signal("sdmmc1_dat4", 180 omap_mux_init_signal("sdmmc1_dat4",
195 OMAP_PIN_INPUT_PULLUP); 181 OMAP_PIN_INPUT_PULLUP);
@@ -214,7 +200,7 @@ static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller,
214 * For 8 wire configurations, Lines DAT4, 5, 6 and 7 200 * For 8 wire configurations, Lines DAT4, 5, 6 and 7
215 * need to be muxed in the board-*.c files 201 * need to be muxed in the board-*.c files
216 */ 202 */
217 if (mmc_controller->slots[0].caps & 203 if (mmc_controller->caps &
218 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) { 204 (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)) {
219 omap_mux_init_signal("sdmmc2_dat1", 205 omap_mux_init_signal("sdmmc2_dat1",
220 OMAP_PIN_INPUT_PULLUP); 206 OMAP_PIN_INPUT_PULLUP);
@@ -223,7 +209,7 @@ static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller,
223 omap_mux_init_signal("sdmmc2_dat3", 209 omap_mux_init_signal("sdmmc2_dat3",
224 OMAP_PIN_INPUT_PULLUP); 210 OMAP_PIN_INPUT_PULLUP);
225 } 211 }
226 if (mmc_controller->slots[0].caps & 212 if (mmc_controller->caps &
227 MMC_CAP_8_BIT_DATA) { 213 MMC_CAP_8_BIT_DATA) {
228 omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4", 214 omap_mux_init_signal("sdmmc2_dat4.sdmmc2_dat4",
229 OMAP_PIN_INPUT_PULLUP); 215 OMAP_PIN_INPUT_PULLUP);
@@ -243,7 +229,7 @@ static inline void omap_hsmmc_mux(struct omap_mmc_platform_data *mmc_controller,
243} 229}
244 230
245static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c, 231static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
246 struct omap_mmc_platform_data *mmc) 232 struct omap_hsmmc_platform_data *mmc)
247{ 233{
248 char *hc_name; 234 char *hc_name;
249 235
@@ -259,38 +245,22 @@ static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
259 else 245 else
260 snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i", 246 snprintf(hc_name, (HSMMC_NAME_LEN + 1), "mmc%islot%i",
261 c->mmc, 1); 247 c->mmc, 1);
262 mmc->slots[0].name = hc_name; 248 mmc->name = hc_name;
263 mmc->nr_slots = 1; 249 mmc->caps = c->caps;
264 mmc->slots[0].caps = c->caps; 250 mmc->internal_clock = !c->ext_clock;
265 mmc->slots[0].pm_caps = c->pm_caps;
266 mmc->slots[0].internal_clock = !c->ext_clock;
267 mmc->max_freq = c->max_freq;
268 mmc->reg_offset = 0; 251 mmc->reg_offset = 0;
269 mmc->get_context_loss_count = hsmmc_get_context_loss;
270 252
271 mmc->slots[0].switch_pin = c->gpio_cd; 253 mmc->switch_pin = c->gpio_cd;
272 mmc->slots[0].gpio_wp = c->gpio_wp; 254 mmc->gpio_wp = c->gpio_wp;
273 255
274 mmc->slots[0].remux = c->remux; 256 mmc->remux = c->remux;
275 mmc->slots[0].init_card = c->init_card; 257 mmc->init_card = c->init_card;
276 258
277 if (c->cover_only) 259 if (c->cover_only)
278 mmc->slots[0].cover = 1; 260 mmc->cover = 1;
279 261
280 if (c->nonremovable) 262 if (c->nonremovable)
281 mmc->slots[0].nonremovable = 1; 263 mmc->nonremovable = 1;
282
283 if (c->power_saving)
284 mmc->slots[0].power_saving = 1;
285
286 if (c->no_off)
287 mmc->slots[0].no_off = 1;
288
289 if (c->no_off_init)
290 mmc->slots[0].no_regulator_off_init = c->no_off_init;
291
292 if (c->vcc_aux_disable_is_sleep)
293 mmc->slots[0].vcc_aux_disable_is_sleep = 1;
294 264
295 /* 265 /*
296 * NOTE: MMC slots should have a Vcc regulator set up. 266 * NOTE: MMC slots should have a Vcc regulator set up.
@@ -300,42 +270,42 @@ static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
300 * temporary HACK: ocr_mask instead of fixed supply 270 * temporary HACK: ocr_mask instead of fixed supply
301 */ 271 */
302 if (soc_is_am35xx()) 272 if (soc_is_am35xx())
303 mmc->slots[0].ocr_mask = MMC_VDD_165_195 | 273 mmc->ocr_mask = MMC_VDD_165_195 |
304 MMC_VDD_26_27 | 274 MMC_VDD_26_27 |
305 MMC_VDD_27_28 | 275 MMC_VDD_27_28 |
306 MMC_VDD_29_30 | 276 MMC_VDD_29_30 |
307 MMC_VDD_30_31 | 277 MMC_VDD_30_31 |
308 MMC_VDD_31_32; 278 MMC_VDD_31_32;
309 else 279 else
310 mmc->slots[0].ocr_mask = c->ocr_mask; 280 mmc->ocr_mask = c->ocr_mask;
311 281
312 if (!soc_is_am35xx()) 282 if (!soc_is_am35xx())
313 mmc->slots[0].features |= HSMMC_HAS_PBIAS; 283 mmc->features |= HSMMC_HAS_PBIAS;
314 284
315 switch (c->mmc) { 285 switch (c->mmc) {
316 case 1: 286 case 1:
317 if (mmc->slots[0].features & HSMMC_HAS_PBIAS) { 287 if (mmc->features & HSMMC_HAS_PBIAS) {
318 /* on-chip level shifting via PBIAS0/PBIAS1 */ 288 /* on-chip level shifting via PBIAS0/PBIAS1 */
319 mmc->slots[0].before_set_reg = 289 mmc->before_set_reg =
320 omap_hsmmc1_before_set_reg; 290 omap_hsmmc1_before_set_reg;
321 mmc->slots[0].after_set_reg = 291 mmc->after_set_reg =
322 omap_hsmmc1_after_set_reg; 292 omap_hsmmc1_after_set_reg;
323 } 293 }
324 294
325 if (soc_is_am35xx()) 295 if (soc_is_am35xx())
326 mmc->slots[0].set_power = nop_mmc_set_power; 296 mmc->set_power = nop_mmc_set_power;
327 297
328 /* OMAP3630 HSMMC1 supports only 4-bit */ 298 /* OMAP3630 HSMMC1 supports only 4-bit */
329 if (cpu_is_omap3630() && 299 if (cpu_is_omap3630() &&
330 (c->caps & MMC_CAP_8_BIT_DATA)) { 300 (c->caps & MMC_CAP_8_BIT_DATA)) {
331 c->caps &= ~MMC_CAP_8_BIT_DATA; 301 c->caps &= ~MMC_CAP_8_BIT_DATA;
332 c->caps |= MMC_CAP_4_BIT_DATA; 302 c->caps |= MMC_CAP_4_BIT_DATA;
333 mmc->slots[0].caps = c->caps; 303 mmc->caps = c->caps;
334 } 304 }
335 break; 305 break;
336 case 2: 306 case 2:
337 if (soc_is_am35xx()) 307 if (soc_is_am35xx())
338 mmc->slots[0].set_power = am35x_hsmmc2_set_power; 308 mmc->set_power = am35x_hsmmc2_set_power;
339 309
340 if (c->ext_clock) 310 if (c->ext_clock)
341 c->transceiver = 1; 311 c->transceiver = 1;
@@ -343,17 +313,17 @@ static int __init omap_hsmmc_pdata_init(struct omap2_hsmmc_info *c,
343 c->caps &= ~MMC_CAP_8_BIT_DATA; 313 c->caps &= ~MMC_CAP_8_BIT_DATA;
344 c->caps |= MMC_CAP_4_BIT_DATA; 314 c->caps |= MMC_CAP_4_BIT_DATA;
345 } 315 }
346 if (mmc->slots[0].features & HSMMC_HAS_PBIAS) { 316 if (mmc->features & HSMMC_HAS_PBIAS) {
347 /* off-chip level shifting, or none */ 317 /* off-chip level shifting, or none */
348 mmc->slots[0].before_set_reg = hsmmc2_before_set_reg; 318 mmc->before_set_reg = hsmmc2_before_set_reg;
349 mmc->slots[0].after_set_reg = NULL; 319 mmc->after_set_reg = NULL;
350 } 320 }
351 break; 321 break;
352 case 3: 322 case 3:
353 case 4: 323 case 4:
354 case 5: 324 case 5:
355 mmc->slots[0].before_set_reg = NULL; 325 mmc->before_set_reg = NULL;
356 mmc->slots[0].after_set_reg = NULL; 326 mmc->after_set_reg = NULL;
357 break; 327 break;
358 default: 328 default:
359 pr_err("MMC%d configuration not supported!\n", c->mmc); 329 pr_err("MMC%d configuration not supported!\n", c->mmc);
@@ -368,7 +338,7 @@ static int omap_hsmmc_done;
368void omap_hsmmc_late_init(struct omap2_hsmmc_info *c) 338void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
369{ 339{
370 struct platform_device *pdev; 340 struct platform_device *pdev;
371 struct omap_mmc_platform_data *mmc_pdata; 341 struct omap_hsmmc_platform_data *mmc_pdata;
372 int res; 342 int res;
373 343
374 if (omap_hsmmc_done != 1) 344 if (omap_hsmmc_done != 1)
@@ -388,8 +358,8 @@ void omap_hsmmc_late_init(struct omap2_hsmmc_info *c)
388 if (!mmc_pdata) 358 if (!mmc_pdata)
389 continue; 359 continue;
390 360
391 mmc_pdata->slots[0].switch_pin = c->gpio_cd; 361 mmc_pdata->switch_pin = c->gpio_cd;
392 mmc_pdata->slots[0].gpio_wp = c->gpio_wp; 362 mmc_pdata->gpio_wp = c->gpio_wp;
393 363
394 res = omap_device_register(pdev); 364 res = omap_device_register(pdev);
395 if (res) 365 if (res)
@@ -408,12 +378,12 @@ static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
408 struct omap_device *od; 378 struct omap_device *od;
409 struct platform_device *pdev; 379 struct platform_device *pdev;
410 char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN]; 380 char oh_name[MAX_OMAP_MMC_HWMOD_NAME_LEN];
411 struct omap_mmc_platform_data *mmc_data; 381 struct omap_hsmmc_platform_data *mmc_data;
412 struct omap_mmc_dev_attr *mmc_dev_attr; 382 struct omap_hsmmc_dev_attr *mmc_dev_attr;
413 char *name; 383 char *name;
414 int res; 384 int res;
415 385
416 mmc_data = kzalloc(sizeof(struct omap_mmc_platform_data), GFP_KERNEL); 386 mmc_data = kzalloc(sizeof(*mmc_data), GFP_KERNEL);
417 if (!mmc_data) { 387 if (!mmc_data) {
418 pr_err("Cannot allocate memory for mmc device!\n"); 388 pr_err("Cannot allocate memory for mmc device!\n");
419 return; 389 return;
@@ -463,7 +433,7 @@ static void __init omap_hsmmc_init_one(struct omap2_hsmmc_info *hsmmcinfo,
463 } 433 }
464 434
465 res = platform_device_add_data(pdev, mmc_data, 435 res = platform_device_add_data(pdev, mmc_data,
466 sizeof(struct omap_mmc_platform_data)); 436 sizeof(struct omap_hsmmc_platform_data));
467 if (res) { 437 if (res) {
468 pr_err("Could not add pdata for %s\n", name); 438 pr_err("Could not add pdata for %s\n", name);
469 goto put_pdev; 439 goto put_pdev;
@@ -489,7 +459,7 @@ put_pdev:
489 platform_device_put(pdev); 459 platform_device_put(pdev);
490 460
491free_name: 461free_name:
492 kfree(mmc_data->slots[0].name); 462 kfree(mmc_data->name);
493 463
494free_mmc: 464free_mmc:
495 kfree(mmc_data); 465 kfree(mmc_data);
diff --git a/arch/arm/mach-omap2/hsmmc.h b/arch/arm/mach-omap2/hsmmc.h
index 7f2e790e0929..148cd9b15499 100644
--- a/arch/arm/mach-omap2/hsmmc.h
+++ b/arch/arm/mach-omap2/hsmmc.h
@@ -12,25 +12,18 @@ struct omap2_hsmmc_info {
12 u8 mmc; /* controller 1/2/3 */ 12 u8 mmc; /* controller 1/2/3 */
13 u32 caps; /* 4/8 wires and any additional host 13 u32 caps; /* 4/8 wires and any additional host
14 * capabilities OR'd (ref. linux/mmc/host.h) */ 14 * capabilities OR'd (ref. linux/mmc/host.h) */
15 u32 pm_caps; /* PM capabilities */
16 bool transceiver; /* MMC-2 option */ 15 bool transceiver; /* MMC-2 option */
17 bool ext_clock; /* use external pin for input clock */ 16 bool ext_clock; /* use external pin for input clock */
18 bool cover_only; /* No card detect - just cover switch */ 17 bool cover_only; /* No card detect - just cover switch */
19 bool nonremovable; /* Nonremovable e.g. eMMC */ 18 bool nonremovable; /* Nonremovable e.g. eMMC */
20 bool power_saving; /* Try to sleep or power off when possible */
21 bool no_off; /* power_saving and power is not to go off */
22 bool no_off_init; /* no power off when not in MMC sleep state */
23 bool vcc_aux_disable_is_sleep; /* Regulator off remapped to sleep */
24 bool deferred; /* mmc needs a deferred probe */ 19 bool deferred; /* mmc needs a deferred probe */
25 int gpio_cd; /* or -EINVAL */ 20 int gpio_cd; /* or -EINVAL */
26 int gpio_wp; /* or -EINVAL */ 21 int gpio_wp; /* or -EINVAL */
27 char *name; /* or NULL for default */ 22 char *name; /* or NULL for default */
28 struct platform_device *pdev; /* mmc controller instance */ 23 struct platform_device *pdev; /* mmc controller instance */
29 int ocr_mask; /* temporary HACK */ 24 int ocr_mask; /* temporary HACK */
30 int max_freq; /* maximum clock, if constrained by external
31 * circuitry, or 0 for default */
32 /* Remux (pad configuration) when powering on/off */ 25 /* Remux (pad configuration) when powering on/off */
33 void (*remux)(struct device *dev, int slot, int power_on); 26 void (*remux)(struct device *dev, int power_on);
34 /* init some special card */ 27 /* init some special card */
35 void (*init_card)(struct mmc_card *card); 28 void (*init_card)(struct mmc_card *card);
36}; 29};
diff --git a/arch/arm/mach-omap2/mmc.h b/arch/arm/mach-omap2/mmc.h
index 0cd4b089da9c..30d39b97e7dd 100644
--- a/arch/arm/mach-omap2/mmc.h
+++ b/arch/arm/mach-omap2/mmc.h
@@ -1,5 +1,3 @@
1#include <linux/mmc/host.h>
2#include <linux/platform_data/mmc-omap.h>
3 1
4#define OMAP24XX_NR_MMC 2 2#define OMAP24XX_NR_MMC 2
5#define OMAP2420_MMC_SIZE OMAP1_MMC_SIZE 3#define OMAP2420_MMC_SIZE OMAP1_MMC_SIZE
@@ -7,14 +5,6 @@
7 5
8#define OMAP4_MMC_REG_OFFSET 0x100 6#define OMAP4_MMC_REG_OFFSET 0x100
9 7
10#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
11void omap242x_init_mmc(struct omap_mmc_platform_data **mmc_data);
12#else
13static inline void omap242x_init_mmc(struct omap_mmc_platform_data **mmc_data)
14{
15}
16#endif
17
18struct omap_hwmod; 8struct omap_hwmod;
19int omap_msdi_reset(struct omap_hwmod *oh); 9int omap_msdi_reset(struct omap_hwmod *oh);
20 10
diff --git a/arch/arm/mach-omap2/omap4-common.c b/arch/arm/mach-omap2/omap4-common.c
index 16b20cedc38d..b7cb44abe49b 100644
--- a/arch/arm/mach-omap2/omap4-common.c
+++ b/arch/arm/mach-omap2/omap4-common.c
@@ -36,7 +36,6 @@
36#include "soc.h" 36#include "soc.h"
37#include "iomap.h" 37#include "iomap.h"
38#include "common.h" 38#include "common.h"
39#include "mmc.h"
40#include "prminst44xx.h" 39#include "prminst44xx.h"
41#include "prcm_mpu44xx.h" 40#include "prcm_mpu44xx.h"
42#include "omap4-sar-layout.h" 41#include "omap4-sar-layout.h"
diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
index d22c30d3ccfa..8c58b71c2727 100644
--- a/arch/arm/mach-omap2/omap_device.c
+++ b/arch/arm/mach-omap2/omap_device.c
@@ -917,6 +917,10 @@ static int __init omap_device_late_idle(struct device *dev, void *data)
917static int __init omap_device_late_init(void) 917static int __init omap_device_late_init(void)
918{ 918{
919 bus_for_each_dev(&platform_bus_type, NULL, NULL, omap_device_late_idle); 919 bus_for_each_dev(&platform_bus_type, NULL, NULL, omap_device_late_idle);
920
921 WARN(!of_have_populated_dt(),
922 "legacy booting deprecated, please update to boot with .dts\n");
923
920 return 0; 924 return 0;
921} 925}
922omap_late_initcall_sync(omap_device_late_init); 926omap_late_initcall_sync(omap_device_late_init);
diff --git a/arch/arm/mach-omap2/omap_hwmod_2430_data.c b/arch/arm/mach-omap2/omap_hwmod_2430_data.c
index c2555cb95e71..79127b35fe60 100644
--- a/arch/arm/mach-omap2/omap_hwmod_2430_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_2430_data.c
@@ -15,12 +15,12 @@
15 15
16#include <linux/i2c-omap.h> 16#include <linux/i2c-omap.h>
17#include <linux/platform_data/asoc-ti-mcbsp.h> 17#include <linux/platform_data/asoc-ti-mcbsp.h>
18#include <linux/platform_data/hsmmc-omap.h>
18#include <linux/platform_data/spi-omap2-mcspi.h> 19#include <linux/platform_data/spi-omap2-mcspi.h>
19#include <linux/omap-dma.h> 20#include <linux/omap-dma.h>
20#include <plat/dmtimer.h> 21#include <plat/dmtimer.h>
21 22
22#include "omap_hwmod.h" 23#include "omap_hwmod.h"
23#include "mmc.h"
24#include "l3_2xxx.h" 24#include "l3_2xxx.h"
25 25
26#include "soc.h" 26#include "soc.h"
@@ -372,7 +372,7 @@ static struct omap_hwmod_opt_clk omap2430_mmc1_opt_clks[] = {
372 { .role = "dbck", .clk = "mmchsdb1_fck" }, 372 { .role = "dbck", .clk = "mmchsdb1_fck" },
373}; 373};
374 374
375static struct omap_mmc_dev_attr mmc1_dev_attr = { 375static struct omap_hsmmc_dev_attr mmc1_dev_attr = {
376 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT, 376 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT,
377}; 377};
378 378
diff --git a/arch/arm/mach-omap2/omap_hwmod_33xx_43xx_ipblock_data.c b/arch/arm/mach-omap2/omap_hwmod_33xx_43xx_ipblock_data.c
index a579b89ce9b7..cabc5695b504 100644
--- a/arch/arm/mach-omap2/omap_hwmod_33xx_43xx_ipblock_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_33xx_43xx_ipblock_data.c
@@ -15,10 +15,10 @@
15 */ 15 */
16 16
17#include <linux/platform_data/gpio-omap.h> 17#include <linux/platform_data/gpio-omap.h>
18#include <linux/platform_data/hsmmc-omap.h>
18#include <linux/platform_data/spi-omap2-mcspi.h> 19#include <linux/platform_data/spi-omap2-mcspi.h>
19#include "omap_hwmod.h" 20#include "omap_hwmod.h"
20#include "i2c.h" 21#include "i2c.h"
21#include "mmc.h"
22#include "wd_timer.h" 22#include "wd_timer.h"
23#include "cm33xx.h" 23#include "cm33xx.h"
24#include "prm33xx.h" 24#include "prm33xx.h"
@@ -836,7 +836,7 @@ static struct omap_hwmod_class am33xx_mmc_hwmod_class = {
836}; 836};
837 837
838/* mmc0 */ 838/* mmc0 */
839static struct omap_mmc_dev_attr am33xx_mmc0_dev_attr = { 839static struct omap_hsmmc_dev_attr am33xx_mmc0_dev_attr = {
840 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT, 840 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT,
841}; 841};
842 842
@@ -854,7 +854,7 @@ struct omap_hwmod am33xx_mmc0_hwmod = {
854}; 854};
855 855
856/* mmc1 */ 856/* mmc1 */
857static struct omap_mmc_dev_attr am33xx_mmc1_dev_attr = { 857static struct omap_hsmmc_dev_attr am33xx_mmc1_dev_attr = {
858 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT, 858 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT,
859}; 859};
860 860
@@ -872,7 +872,7 @@ struct omap_hwmod am33xx_mmc1_hwmod = {
872}; 872};
873 873
874/* mmc2 */ 874/* mmc2 */
875static struct omap_mmc_dev_attr am33xx_mmc2_dev_attr = { 875static struct omap_hsmmc_dev_attr am33xx_mmc2_dev_attr = {
876 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT, 876 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT,
877}; 877};
878struct omap_hwmod am33xx_mmc2_hwmod = { 878struct omap_hwmod am33xx_mmc2_hwmod = {
diff --git a/arch/arm/mach-omap2/omap_hwmod_33xx_data.c b/arch/arm/mach-omap2/omap_hwmod_33xx_data.c
index 6b406ca4bd3b..0cf7b563dcd1 100644
--- a/arch/arm/mach-omap2/omap_hwmod_33xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_33xx_data.c
@@ -27,7 +27,6 @@
27#include "prm33xx.h" 27#include "prm33xx.h"
28#include "prm-regbits-33xx.h" 28#include "prm-regbits-33xx.h"
29#include "i2c.h" 29#include "i2c.h"
30#include "mmc.h"
31#include "wd_timer.h" 30#include "wd_timer.h"
32#include "omap_hwmod_33xx_43xx_common_data.h" 31#include "omap_hwmod_33xx_43xx_common_data.h"
33 32
diff --git a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
index 2a78b093c0ce..11468eea3871 100644
--- a/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_3xxx_data.c
@@ -18,6 +18,7 @@
18#include <linux/i2c-omap.h> 18#include <linux/i2c-omap.h>
19#include <linux/power/smartreflex.h> 19#include <linux/power/smartreflex.h>
20#include <linux/platform_data/gpio-omap.h> 20#include <linux/platform_data/gpio-omap.h>
21#include <linux/platform_data/hsmmc-omap.h>
21 22
22#include <linux/omap-dma.h> 23#include <linux/omap-dma.h>
23#include "l3_3xxx.h" 24#include "l3_3xxx.h"
@@ -37,7 +38,6 @@
37#include "cm-regbits-34xx.h" 38#include "cm-regbits-34xx.h"
38 39
39#include "i2c.h" 40#include "i2c.h"
40#include "mmc.h"
41#include "wd_timer.h" 41#include "wd_timer.h"
42#include "serial.h" 42#include "serial.h"
43 43
@@ -1786,12 +1786,12 @@ static struct omap_hwmod_opt_clk omap34xx_mmc1_opt_clks[] = {
1786 { .role = "dbck", .clk = "omap_32k_fck", }, 1786 { .role = "dbck", .clk = "omap_32k_fck", },
1787}; 1787};
1788 1788
1789static struct omap_mmc_dev_attr mmc1_dev_attr = { 1789static struct omap_hsmmc_dev_attr mmc1_dev_attr = {
1790 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT, 1790 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT,
1791}; 1791};
1792 1792
1793/* See 35xx errata 2.1.1.128 in SPRZ278F */ 1793/* See 35xx errata 2.1.1.128 in SPRZ278F */
1794static struct omap_mmc_dev_attr mmc1_pre_es3_dev_attr = { 1794static struct omap_hsmmc_dev_attr mmc1_pre_es3_dev_attr = {
1795 .flags = (OMAP_HSMMC_SUPPORTS_DUAL_VOLT | 1795 .flags = (OMAP_HSMMC_SUPPORTS_DUAL_VOLT |
1796 OMAP_HSMMC_BROKEN_MULTIBLOCK_READ), 1796 OMAP_HSMMC_BROKEN_MULTIBLOCK_READ),
1797}; 1797};
@@ -1854,7 +1854,7 @@ static struct omap_hwmod_opt_clk omap34xx_mmc2_opt_clks[] = {
1854}; 1854};
1855 1855
1856/* See 35xx errata 2.1.1.128 in SPRZ278F */ 1856/* See 35xx errata 2.1.1.128 in SPRZ278F */
1857static struct omap_mmc_dev_attr mmc2_pre_es3_dev_attr = { 1857static struct omap_hsmmc_dev_attr mmc2_pre_es3_dev_attr = {
1858 .flags = OMAP_HSMMC_BROKEN_MULTIBLOCK_READ, 1858 .flags = OMAP_HSMMC_BROKEN_MULTIBLOCK_READ,
1859}; 1859};
1860 1860
diff --git a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
index d6f41e1b6d1b..c314b3c31117 100644
--- a/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_44xx_data.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/platform_data/gpio-omap.h> 24#include <linux/platform_data/gpio-omap.h>
25#include <linux/platform_data/hsmmc-omap.h>
25#include <linux/power/smartreflex.h> 26#include <linux/power/smartreflex.h>
26#include <linux/i2c-omap.h> 27#include <linux/i2c-omap.h>
27 28
@@ -39,7 +40,6 @@
39#include "prm44xx.h" 40#include "prm44xx.h"
40#include "prm-regbits-44xx.h" 41#include "prm-regbits-44xx.h"
41#include "i2c.h" 42#include "i2c.h"
42#include "mmc.h"
43#include "wd_timer.h" 43#include "wd_timer.h"
44 44
45/* Base offset for all OMAP4 interrupts external to MPUSS */ 45/* Base offset for all OMAP4 interrupts external to MPUSS */
@@ -1959,7 +1959,7 @@ static struct omap_hwmod_dma_info omap44xx_mmc1_sdma_reqs[] = {
1959}; 1959};
1960 1960
1961/* mmc1 dev_attr */ 1961/* mmc1 dev_attr */
1962static struct omap_mmc_dev_attr mmc1_dev_attr = { 1962static struct omap_hsmmc_dev_attr mmc1_dev_attr = {
1963 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT, 1963 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT,
1964}; 1964};
1965 1965
diff --git a/arch/arm/mach-omap2/omap_hwmod_54xx_data.c b/arch/arm/mach-omap2/omap_hwmod_54xx_data.c
index 229c7fb7e1c3..3e9523084b2a 100644
--- a/arch/arm/mach-omap2/omap_hwmod_54xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_54xx_data.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/platform_data/gpio-omap.h> 21#include <linux/platform_data/gpio-omap.h>
22#include <linux/platform_data/hsmmc-omap.h>
22#include <linux/power/smartreflex.h> 23#include <linux/power/smartreflex.h>
23#include <linux/i2c-omap.h> 24#include <linux/i2c-omap.h>
24 25
@@ -33,7 +34,6 @@
33#include "cm2_54xx.h" 34#include "cm2_54xx.h"
34#include "prm54xx.h" 35#include "prm54xx.h"
35#include "i2c.h" 36#include "i2c.h"
36#include "mmc.h"
37#include "wd_timer.h" 37#include "wd_timer.h"
38 38
39/* Base offset for all OMAP5 interrupts external to MPUSS */ 39/* Base offset for all OMAP5 interrupts external to MPUSS */
@@ -1274,7 +1274,7 @@ static struct omap_hwmod_opt_clk mmc1_opt_clks[] = {
1274}; 1274};
1275 1275
1276/* mmc1 dev_attr */ 1276/* mmc1 dev_attr */
1277static struct omap_mmc_dev_attr mmc1_dev_attr = { 1277static struct omap_hsmmc_dev_attr mmc1_dev_attr = {
1278 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT, 1278 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT,
1279}; 1279};
1280 1280
diff --git a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
index e2a70439bf35..ffd6604cd546 100644
--- a/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
+++ b/arch/arm/mach-omap2/omap_hwmod_7xx_data.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/platform_data/gpio-omap.h> 21#include <linux/platform_data/gpio-omap.h>
22#include <linux/platform_data/hsmmc-omap.h>
22#include <linux/power/smartreflex.h> 23#include <linux/power/smartreflex.h>
23#include <linux/i2c-omap.h> 24#include <linux/i2c-omap.h>
24 25
@@ -33,7 +34,6 @@
33#include "cm2_7xx.h" 34#include "cm2_7xx.h"
34#include "prm7xx.h" 35#include "prm7xx.h"
35#include "i2c.h" 36#include "i2c.h"
36#include "mmc.h"
37#include "wd_timer.h" 37#include "wd_timer.h"
38#include "soc.h" 38#include "soc.h"
39 39
@@ -1301,7 +1301,7 @@ static struct omap_hwmod_opt_clk mmc1_opt_clks[] = {
1301}; 1301};
1302 1302
1303/* mmc1 dev_attr */ 1303/* mmc1 dev_attr */
1304static struct omap_mmc_dev_attr mmc1_dev_attr = { 1304static struct omap_hsmmc_dev_attr mmc1_dev_attr = {
1305 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT, 1305 .flags = OMAP_HSMMC_SUPPORTS_DUAL_VOLT,
1306}; 1306};
1307 1307
diff --git a/arch/arm/mach-omap2/omap_phy_internal.c b/arch/arm/mach-omap2/omap_phy_internal.c
index 50640b38f0bf..1a19fa096bab 100644
--- a/arch/arm/mach-omap2/omap_phy_internal.c
+++ b/arch/arm/mach-omap2/omap_phy_internal.c
@@ -21,6 +21,8 @@
21 * 21 *
22 */ 22 */
23 23
24#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25
24#include <linux/types.h> 26#include <linux/types.h>
25#include <linux/delay.h> 27#include <linux/delay.h>
26#include <linux/clk.h> 28#include <linux/clk.h>
@@ -97,13 +99,13 @@ void am35x_musb_phy_power(u8 on)
97 99
98 omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2); 100 omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
99 101
100 pr_info(KERN_INFO "Waiting for PHY clock good...\n"); 102 pr_info("Waiting for PHY clock good...\n");
101 while (!(omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2) 103 while (!(omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2)
102 & CONF2_PHYCLKGD)) { 104 & CONF2_PHYCLKGD)) {
103 cpu_relax(); 105 cpu_relax();
104 106
105 if (time_after(jiffies, timeout)) { 107 if (time_after(jiffies, timeout)) {
106 pr_err(KERN_ERR "musb PHY clock good timed out\n"); 108 pr_err("musb PHY clock good timed out\n");
107 break; 109 break;
108 } 110 }
109 } 111 }
@@ -145,7 +147,7 @@ void am35x_set_mode(u8 musb_mode)
145 devconf2 |= CONF2_NO_OVERRIDE; 147 devconf2 |= CONF2_NO_OVERRIDE;
146 break; 148 break;
147 default: 149 default:
148 pr_info(KERN_INFO "Unsupported mode %u\n", musb_mode); 150 pr_info("Unsupported mode %u\n", musb_mode);
149 } 151 }
150 152
151 omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2); 153 omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
diff --git a/arch/arm/mach-omap2/serial.c b/arch/arm/mach-omap2/serial.c
index a388f8c1bcb3..57dee0c7cd2b 100644
--- a/arch/arm/mach-omap2/serial.c
+++ b/arch/arm/mach-omap2/serial.c
@@ -263,9 +263,6 @@ void __init omap_serial_init_port(struct omap_board_data *bdata,
263 omap_up.dma_rx_timeout = info->dma_rx_timeout; 263 omap_up.dma_rx_timeout = info->dma_rx_timeout;
264 omap_up.dma_rx_poll_rate = info->dma_rx_poll_rate; 264 omap_up.dma_rx_poll_rate = info->dma_rx_poll_rate;
265 omap_up.autosuspend_timeout = info->autosuspend_timeout; 265 omap_up.autosuspend_timeout = info->autosuspend_timeout;
266 omap_up.DTR_gpio = info->DTR_gpio;
267 omap_up.DTR_inverted = info->DTR_inverted;
268 omap_up.DTR_present = info->DTR_present;
269 266
270 pdata = &omap_up; 267 pdata = &omap_up;
271 pdata_size = sizeof(struct omap_uart_port_info); 268 pdata_size = sizeof(struct omap_uart_port_info);
diff --git a/arch/arm/mach-pxa/include/mach/addr-map.h b/arch/arm/mach-pxa/include/mach/addr-map.h
index bbf9df37ad4b..d28fe291233a 100644
--- a/arch/arm/mach-pxa/include/mach/addr-map.h
+++ b/arch/arm/mach-pxa/include/mach/addr-map.h
@@ -39,6 +39,11 @@
39#define DMEMC_SIZE 0x00100000 39#define DMEMC_SIZE 0x00100000
40 40
41/* 41/*
42 * Reserved space for low level debug virtual addresses within
43 * 0xf6200000..0xf6201000
44 */
45
46/*
42 * Internal Memory Controller (PXA27x and later) 47 * Internal Memory Controller (PXA27x and later)
43 */ 48 */
44#define IMEMC_PHYS 0x58000000 49#define IMEMC_PHYS 0x58000000
diff --git a/arch/arm/mach-shmobile/Kconfig b/arch/arm/mach-shmobile/Kconfig
index b0a9e1a7955a..1b4fafe524ff 100644
--- a/arch/arm/mach-shmobile/Kconfig
+++ b/arch/arm/mach-shmobile/Kconfig
@@ -38,7 +38,6 @@ menuconfig ARCH_SHMOBILE_MULTI
38 select NO_IOPORT_MAP 38 select NO_IOPORT_MAP
39 select PINCTRL 39 select PINCTRL
40 select ARCH_REQUIRE_GPIOLIB 40 select ARCH_REQUIRE_GPIOLIB
41 select ARCH_HAS_OPP
42 41
43if ARCH_SHMOBILE_MULTI 42if ARCH_SHMOBILE_MULTI
44 43
@@ -75,11 +74,6 @@ config ARCH_R8A7794
75 74
76comment "Renesas ARM SoCs Board Type" 75comment "Renesas ARM SoCs Board Type"
77 76
78config MACH_KOELSCH
79 bool "Koelsch board"
80 depends on ARCH_R8A7791
81 select MICREL_PHY if SH_ETH
82
83config MACH_LAGER 77config MACH_LAGER
84 bool "Lager board" 78 bool "Lager board"
85 depends on ARCH_R8A7790 79 depends on ARCH_R8A7790
@@ -147,14 +141,6 @@ config ARCH_R8A7790
147 select MIGHT_HAVE_PCI 141 select MIGHT_HAVE_PCI
148 select ARCH_DMA_ADDR_T_64BIT if ARM_LPAE 142 select ARCH_DMA_ADDR_T_64BIT if ARM_LPAE
149 143
150config ARCH_R8A7791
151 bool "R-Car M2-W (R8A77910)"
152 select ARCH_RCAR_GEN2
153 select ARCH_WANT_OPTIONAL_GPIOLIB
154 select ARM_GIC
155 select MIGHT_HAVE_PCI
156 select ARCH_DMA_ADDR_T_64BIT if ARM_LPAE
157
158comment "Renesas ARM SoCs Board Type" 144comment "Renesas ARM SoCs Board Type"
159 145
160config MACH_APE6EVM 146config MACH_APE6EVM
@@ -229,12 +215,6 @@ config MACH_LAGER
229 select MICREL_PHY if SH_ETH 215 select MICREL_PHY if SH_ETH
230 select SND_SOC_AK4642 if SND_SIMPLE_CARD 216 select SND_SOC_AK4642 if SND_SIMPLE_CARD
231 217
232config MACH_KOELSCH
233 bool "Koelsch board"
234 depends on ARCH_R8A7791
235 select USE_OF
236 select MICREL_PHY if SH_ETH
237
238config MACH_KZM9G 218config MACH_KZM9G
239 bool "KZM-A9-GT board" 219 bool "KZM-A9-GT board"
240 depends on ARCH_SH73A0 220 depends on ARCH_SH73A0
diff --git a/arch/arm/mach-shmobile/Makefile b/arch/arm/mach-shmobile/Makefile
index 71e68ca56886..b55cac0e5b2b 100644
--- a/arch/arm/mach-shmobile/Makefile
+++ b/arch/arm/mach-shmobile/Makefile
@@ -19,8 +19,8 @@ obj-$(CONFIG_ARCH_EMEV2) += setup-emev2.o
19obj-$(CONFIG_ARCH_R7S72100) += setup-r7s72100.o 19obj-$(CONFIG_ARCH_R7S72100) += setup-r7s72100.o
20 20
21# Clock objects 21# Clock objects
22obj-y += clock.o
23ifndef CONFIG_COMMON_CLK 22ifndef CONFIG_COMMON_CLK
23obj-y += clock.o
24obj-$(CONFIG_ARCH_SH7372) += clock-sh7372.o 24obj-$(CONFIG_ARCH_SH7372) += clock-sh7372.o
25obj-$(CONFIG_ARCH_SH73A0) += clock-sh73a0.o 25obj-$(CONFIG_ARCH_SH73A0) += clock-sh73a0.o
26obj-$(CONFIG_ARCH_R8A73A4) += clock-r8a73a4.o 26obj-$(CONFIG_ARCH_R8A73A4) += clock-r8a73a4.o
@@ -28,7 +28,6 @@ obj-$(CONFIG_ARCH_R8A7740) += clock-r8a7740.o
28obj-$(CONFIG_ARCH_R8A7778) += clock-r8a7778.o 28obj-$(CONFIG_ARCH_R8A7778) += clock-r8a7778.o
29obj-$(CONFIG_ARCH_R8A7779) += clock-r8a7779.o 29obj-$(CONFIG_ARCH_R8A7779) += clock-r8a7779.o
30obj-$(CONFIG_ARCH_R8A7790) += clock-r8a7790.o 30obj-$(CONFIG_ARCH_R8A7790) += clock-r8a7790.o
31obj-$(CONFIG_ARCH_R8A7791) += clock-r8a7791.o
32endif 31endif
33 32
34# CPU reset vector handling objects 33# CPU reset vector handling objects
@@ -58,7 +57,6 @@ obj-$(CONFIG_ARCH_SH7372) += entry-intc.o sleep-sh7372.o
58 57
59# Board objects 58# Board objects
60ifdef CONFIG_ARCH_SHMOBILE_MULTI 59ifdef CONFIG_ARCH_SHMOBILE_MULTI
61obj-$(CONFIG_MACH_KOELSCH) += board-koelsch-reference.o
62obj-$(CONFIG_MACH_LAGER) += board-lager-reference.o 60obj-$(CONFIG_MACH_LAGER) += board-lager-reference.o
63obj-$(CONFIG_MACH_MARZEN) += board-marzen-reference.o 61obj-$(CONFIG_MACH_MARZEN) += board-marzen-reference.o
64else 62else
@@ -70,7 +68,6 @@ obj-$(CONFIG_MACH_BOCKW_REFERENCE) += board-bockw-reference.o
70obj-$(CONFIG_MACH_MARZEN) += board-marzen.o 68obj-$(CONFIG_MACH_MARZEN) += board-marzen.o
71obj-$(CONFIG_MACH_LAGER) += board-lager.o 69obj-$(CONFIG_MACH_LAGER) += board-lager.o
72obj-$(CONFIG_MACH_ARMADILLO800EVA) += board-armadillo800eva.o 70obj-$(CONFIG_MACH_ARMADILLO800EVA) += board-armadillo800eva.o
73obj-$(CONFIG_MACH_KOELSCH) += board-koelsch.o
74obj-$(CONFIG_MACH_KZM9G) += board-kzm9g.o 71obj-$(CONFIG_MACH_KZM9G) += board-kzm9g.o
75obj-$(CONFIG_MACH_KZM9G_REFERENCE) += board-kzm9g-reference.o 72obj-$(CONFIG_MACH_KZM9G_REFERENCE) += board-kzm9g-reference.o
76endif 73endif
diff --git a/arch/arm/mach-shmobile/Makefile.boot b/arch/arm/mach-shmobile/Makefile.boot
index de9a23852fc8..57d00ed6ec0c 100644
--- a/arch/arm/mach-shmobile/Makefile.boot
+++ b/arch/arm/mach-shmobile/Makefile.boot
@@ -5,7 +5,6 @@ loadaddr-$(CONFIG_MACH_APE6EVM_REFERENCE) += 0x40008000
5loadaddr-$(CONFIG_MACH_ARMADILLO800EVA) += 0x40008000 5loadaddr-$(CONFIG_MACH_ARMADILLO800EVA) += 0x40008000
6loadaddr-$(CONFIG_MACH_BOCKW) += 0x60008000 6loadaddr-$(CONFIG_MACH_BOCKW) += 0x60008000
7loadaddr-$(CONFIG_MACH_BOCKW_REFERENCE) += 0x60008000 7loadaddr-$(CONFIG_MACH_BOCKW_REFERENCE) += 0x60008000
8loadaddr-$(CONFIG_MACH_KOELSCH) += 0x40008000
9loadaddr-$(CONFIG_MACH_KZM9G) += 0x41008000 8loadaddr-$(CONFIG_MACH_KZM9G) += 0x41008000
10loadaddr-$(CONFIG_MACH_KZM9G_REFERENCE) += 0x41008000 9loadaddr-$(CONFIG_MACH_KZM9G_REFERENCE) += 0x41008000
11loadaddr-$(CONFIG_MACH_LAGER) += 0x40008000 10loadaddr-$(CONFIG_MACH_LAGER) += 0x40008000
diff --git a/arch/arm/mach-shmobile/board-ape6evm-reference.c b/arch/arm/mach-shmobile/board-ape6evm-reference.c
index a6503d8c77de..004ed92ee598 100644
--- a/arch/arm/mach-shmobile/board-ape6evm-reference.c
+++ b/arch/arm/mach-shmobile/board-ape6evm-reference.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20 16
21#include <linux/gpio.h> 17#include <linux/gpio.h>
diff --git a/arch/arm/mach-shmobile/board-ape6evm.c b/arch/arm/mach-shmobile/board-ape6evm.c
index b222f68d55b7..66f67816a844 100644
--- a/arch/arm/mach-shmobile/board-ape6evm.c
+++ b/arch/arm/mach-shmobile/board-ape6evm.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20 16
21#include <linux/gpio.h> 17#include <linux/gpio.h>
diff --git a/arch/arm/mach-shmobile/board-armadillo800eva.c b/arch/arm/mach-shmobile/board-armadillo800eva.c
index 25813dac77d9..6d949f1c850b 100644
--- a/arch/arm/mach-shmobile/board-armadillo800eva.c
+++ b/arch/arm/mach-shmobile/board-armadillo800eva.c
@@ -12,53 +12,48 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */ 15 */
21 16
22#include <linux/clk.h> 17#include <linux/clk.h>
23#include <linux/delay.h> 18#include <linux/delay.h>
24#include <linux/err.h> 19#include <linux/err.h>
25#include <linux/kernel.h>
26#include <linux/input.h>
27#include <linux/platform_data/st1232_pdata.h>
28#include <linux/irq.h>
29#include <linux/platform_device.h>
30#include <linux/gpio.h> 20#include <linux/gpio.h>
31#include <linux/gpio_keys.h> 21#include <linux/gpio_keys.h>
32#include <linux/regulator/driver.h> 22#include <linux/i2c-gpio.h>
23#include <linux/input.h>
24#include <linux/irq.h>
25#include <linux/kernel.h>
26#include <linux/mfd/tmio.h>
27#include <linux/mmc/host.h>
28#include <linux/mmc/sh_mmcif.h>
29#include <linux/mmc/sh_mobile_sdhi.h>
33#include <linux/pinctrl/machine.h> 30#include <linux/pinctrl/machine.h>
31#include <linux/platform_data/st1232_pdata.h>
32#include <linux/platform_device.h>
34#include <linux/pwm.h> 33#include <linux/pwm.h>
35#include <linux/pwm_backlight.h> 34#include <linux/pwm_backlight.h>
35#include <linux/reboot.h>
36#include <linux/regulator/driver.h>
36#include <linux/regulator/fixed.h> 37#include <linux/regulator/fixed.h>
37#include <linux/regulator/gpio-regulator.h> 38#include <linux/regulator/gpio-regulator.h>
38#include <linux/regulator/machine.h> 39#include <linux/regulator/machine.h>
39#include <linux/sh_eth.h> 40#include <linux/sh_eth.h>
40#include <linux/videodev2.h>
41#include <linux/usb/renesas_usbhs.h> 41#include <linux/usb/renesas_usbhs.h>
42#include <linux/mfd/tmio.h> 42#include <linux/videodev2.h>
43#include <linux/mmc/host.h>
44#include <linux/mmc/sh_mmcif.h>
45#include <linux/mmc/sh_mobile_sdhi.h>
46#include <linux/i2c-gpio.h>
47#include <linux/reboot.h>
48 43
49#include <media/mt9t112.h> 44#include <asm/hardware/cache-l2x0.h>
50#include <media/sh_mobile_ceu.h>
51#include <media/soc_camera.h>
52#include <asm/page.h>
53#include <asm/mach-types.h> 45#include <asm/mach-types.h>
54#include <asm/mach/arch.h> 46#include <asm/mach/arch.h>
55#include <asm/mach/map.h> 47#include <asm/mach/map.h>
56#include <asm/mach/time.h> 48#include <asm/mach/time.h>
57#include <asm/hardware/cache-l2x0.h> 49#include <asm/page.h>
58#include <video/sh_mobile_lcdc.h> 50#include <media/mt9t112.h>
59#include <video/sh_mobile_hdmi.h> 51#include <media/sh_mobile_ceu.h>
52#include <media/soc_camera.h>
60#include <sound/sh_fsi.h> 53#include <sound/sh_fsi.h>
61#include <sound/simple_card.h> 54#include <sound/simple_card.h>
55#include <video/sh_mobile_hdmi.h>
56#include <video/sh_mobile_lcdc.h>
62 57
63#include "common.h" 58#include "common.h"
64#include "irqs.h" 59#include "irqs.h"
diff --git a/arch/arm/mach-shmobile/board-bockw-reference.c b/arch/arm/mach-shmobile/board-bockw-reference.c
index 79c47847f200..d649ade4a202 100644
--- a/arch/arm/mach-shmobile/board-bockw-reference.c
+++ b/arch/arm/mach-shmobile/board-bockw-reference.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20 16
21#include <linux/of_platform.h> 17#include <linux/of_platform.h>
diff --git a/arch/arm/mach-shmobile/board-bockw.c b/arch/arm/mach-shmobile/board-bockw.c
index 1cf2c75dacfb..f27b5a833bf0 100644
--- a/arch/arm/mach-shmobile/board-bockw.c
+++ b/arch/arm/mach-shmobile/board-bockw.c
@@ -13,10 +13,6 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 16 */
21 17
22#include <linux/mfd/tmio.h> 18#include <linux/mfd/tmio.h>
diff --git a/arch/arm/mach-shmobile/board-koelsch-reference.c b/arch/arm/mach-shmobile/board-koelsch-reference.c
deleted file mode 100644
index 46aa540133d6..000000000000
--- a/arch/arm/mach-shmobile/board-koelsch-reference.c
+++ /dev/null
@@ -1,117 +0,0 @@
1/*
2 * Koelsch board support - Reference DT implementation
3 *
4 * Copyright (C) 2013 Renesas Electronics Corporation
5 * Copyright (C) 2013 Renesas Solutions Corp.
6 * Copyright (C) 2013 Magnus Damm
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <linux/dma-mapping.h>
23#include <linux/kernel.h>
24#include <linux/of_platform.h>
25#include <linux/platform_data/rcar-du.h>
26
27#include <asm/mach/arch.h>
28
29#include "clock.h"
30#include "common.h"
31#include "irqs.h"
32#include "r8a7791.h"
33#include "rcar-gen2.h"
34
35/* DU */
36static struct rcar_du_encoder_data koelsch_du_encoders[] = {
37 {
38 .type = RCAR_DU_ENCODER_NONE,
39 .output = RCAR_DU_OUTPUT_LVDS0,
40 .connector.lvds.panel = {
41 .width_mm = 210,
42 .height_mm = 158,
43 .mode = {
44 .pixelclock = 65000000,
45 .hactive = 1024,
46 .hfront_porch = 20,
47 .hback_porch = 160,
48 .hsync_len = 136,
49 .vactive = 768,
50 .vfront_porch = 3,
51 .vback_porch = 29,
52 .vsync_len = 6,
53 },
54 },
55 },
56};
57
58static struct rcar_du_platform_data koelsch_du_pdata = {
59 .encoders = koelsch_du_encoders,
60 .num_encoders = ARRAY_SIZE(koelsch_du_encoders),
61};
62
63static const struct resource du_resources[] __initconst = {
64 DEFINE_RES_MEM(0xfeb00000, 0x40000),
65 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
66 DEFINE_RES_IRQ(gic_spi(256)),
67 DEFINE_RES_IRQ(gic_spi(268)),
68};
69
70static void __init koelsch_add_du_device(void)
71{
72 struct platform_device_info info = {
73 .name = "rcar-du-r8a7791",
74 .id = -1,
75 .res = du_resources,
76 .num_res = ARRAY_SIZE(du_resources),
77 .data = &koelsch_du_pdata,
78 .size_data = sizeof(koelsch_du_pdata),
79 .dma_mask = DMA_BIT_MASK(32),
80 };
81
82 platform_device_register_full(&info);
83}
84
85/*
86 * This is a really crude hack to provide clkdev support to platform
87 * devices until they get moved to DT.
88 */
89static const struct clk_name clk_names[] __initconst = {
90 { "du0", "du.0", "rcar-du-r8a7791" },
91 { "du1", "du.1", "rcar-du-r8a7791" },
92 { "lvds0", "lvds.0", "rcar-du-r8a7791" },
93};
94
95static void __init koelsch_add_standard_devices(void)
96{
97 shmobile_clk_workaround(clk_names, ARRAY_SIZE(clk_names), false);
98 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
99
100 koelsch_add_du_device();
101}
102
103static const char * const koelsch_boards_compat_dt[] __initconst = {
104 "renesas,koelsch",
105 "renesas,koelsch-reference",
106 NULL,
107};
108
109DT_MACHINE_START(KOELSCH_DT, "koelsch")
110 .smp = smp_ops(r8a7791_smp_ops),
111 .init_early = shmobile_init_delay,
112 .init_time = rcar_gen2_timer_init,
113 .init_machine = koelsch_add_standard_devices,
114 .init_late = shmobile_init_late,
115 .reserve = rcar_gen2_reserve,
116 .dt_compat = koelsch_boards_compat_dt,
117MACHINE_END
diff --git a/arch/arm/mach-shmobile/board-koelsch.c b/arch/arm/mach-shmobile/board-koelsch.c
deleted file mode 100644
index 7111b5c1d67b..000000000000
--- a/arch/arm/mach-shmobile/board-koelsch.c
+++ /dev/null
@@ -1,527 +0,0 @@
1/*
2 * Koelsch board support
3 *
4 * Copyright (C) 2013 Renesas Electronics Corporation
5 * Copyright (C) 2013-2014 Renesas Solutions Corp.
6 * Copyright (C) 2013 Magnus Damm
7 * Copyright (C) 2014 Cogent Embedded, Inc.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <linux/dma-mapping.h>
24#include <linux/gpio.h>
25#include <linux/gpio_keys.h>
26#include <linux/input.h>
27#include <linux/irq.h>
28#include <linux/kernel.h>
29#include <linux/leds.h>
30#include <linux/mfd/tmio.h>
31#include <linux/mmc/host.h>
32#include <linux/mmc/sh_mobile_sdhi.h>
33#include <linux/mtd/mtd.h>
34#include <linux/mtd/partitions.h>
35#include <linux/phy.h>
36#include <linux/pinctrl/machine.h>
37#include <linux/platform_data/gpio-rcar.h>
38#include <linux/platform_data/rcar-du.h>
39#include <linux/platform_device.h>
40#include <linux/regulator/driver.h>
41#include <linux/regulator/fixed.h>
42#include <linux/regulator/gpio-regulator.h>
43#include <linux/regulator/machine.h>
44#include <linux/sh_eth.h>
45#include <linux/spi/flash.h>
46#include <linux/spi/rspi.h>
47#include <linux/spi/spi.h>
48
49#include <asm/mach-types.h>
50#include <asm/mach/arch.h>
51
52#include "common.h"
53#include "irqs.h"
54#include "r8a7791.h"
55#include "rcar-gen2.h"
56
57/* DU */
58static struct rcar_du_encoder_data koelsch_du_encoders[] = {
59 {
60 .type = RCAR_DU_ENCODER_NONE,
61 .output = RCAR_DU_OUTPUT_LVDS0,
62 .connector.lvds.panel = {
63 .width_mm = 210,
64 .height_mm = 158,
65 .mode = {
66 .pixelclock = 65000000,
67 .hactive = 1024,
68 .hfront_porch = 20,
69 .hback_porch = 160,
70 .hsync_len = 136,
71 .vactive = 768,
72 .vfront_porch = 3,
73 .vback_porch = 29,
74 .vsync_len = 6,
75 },
76 },
77 },
78};
79
80static const struct rcar_du_platform_data koelsch_du_pdata __initconst = {
81 .encoders = koelsch_du_encoders,
82 .num_encoders = ARRAY_SIZE(koelsch_du_encoders),
83};
84
85static const struct resource du_resources[] __initconst = {
86 DEFINE_RES_MEM(0xfeb00000, 0x40000),
87 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
88 DEFINE_RES_IRQ(gic_spi(256)),
89 DEFINE_RES_IRQ(gic_spi(268)),
90};
91
92static void __init koelsch_add_du_device(void)
93{
94 struct platform_device_info info = {
95 .name = "rcar-du-r8a7791",
96 .id = -1,
97 .res = du_resources,
98 .num_res = ARRAY_SIZE(du_resources),
99 .data = &koelsch_du_pdata,
100 .size_data = sizeof(koelsch_du_pdata),
101 .dma_mask = DMA_BIT_MASK(32),
102 };
103
104 platform_device_register_full(&info);
105}
106
107/* Ether */
108static const struct sh_eth_plat_data ether_pdata __initconst = {
109 .phy = 0x1,
110 .phy_irq = irq_pin(0),
111 .edmac_endian = EDMAC_LITTLE_ENDIAN,
112 .phy_interface = PHY_INTERFACE_MODE_RMII,
113 .ether_link_active_low = 1,
114};
115
116static const struct resource ether_resources[] __initconst = {
117 DEFINE_RES_MEM(0xee700000, 0x400),
118 DEFINE_RES_IRQ(gic_spi(162)),
119};
120
121static const struct platform_device_info ether_info __initconst = {
122 .name = "r8a7791-ether",
123 .id = -1,
124 .res = ether_resources,
125 .num_res = ARRAY_SIZE(ether_resources),
126 .data = &ether_pdata,
127 .size_data = sizeof(ether_pdata),
128 .dma_mask = DMA_BIT_MASK(32),
129};
130
131/* LEDS */
132static struct gpio_led koelsch_leds[] = {
133 {
134 .name = "led8",
135 .gpio = RCAR_GP_PIN(2, 21),
136 .default_state = LEDS_GPIO_DEFSTATE_ON,
137 }, {
138 .name = "led7",
139 .gpio = RCAR_GP_PIN(2, 20),
140 .default_state = LEDS_GPIO_DEFSTATE_ON,
141 }, {
142 .name = "led6",
143 .gpio = RCAR_GP_PIN(2, 19),
144 .default_state = LEDS_GPIO_DEFSTATE_ON,
145 },
146};
147
148static const struct gpio_led_platform_data koelsch_leds_pdata __initconst = {
149 .leds = koelsch_leds,
150 .num_leds = ARRAY_SIZE(koelsch_leds),
151};
152
153/* GPIO KEY */
154#define GPIO_KEY(c, g, d, ...) \
155 { .code = c, .gpio = g, .desc = d, .active_low = 1, \
156 .wakeup = 1, .debounce_interval = 20 }
157
158static struct gpio_keys_button gpio_buttons[] = {
159 GPIO_KEY(KEY_4, RCAR_GP_PIN(5, 3), "SW2-pin4"),
160 GPIO_KEY(KEY_3, RCAR_GP_PIN(5, 2), "SW2-pin3"),
161 GPIO_KEY(KEY_2, RCAR_GP_PIN(5, 1), "SW2-pin2"),
162 GPIO_KEY(KEY_1, RCAR_GP_PIN(5, 0), "SW2-pin1"),
163 GPIO_KEY(KEY_G, RCAR_GP_PIN(7, 6), "SW36"),
164 GPIO_KEY(KEY_F, RCAR_GP_PIN(7, 5), "SW35"),
165 GPIO_KEY(KEY_E, RCAR_GP_PIN(7, 4), "SW34"),
166 GPIO_KEY(KEY_D, RCAR_GP_PIN(7, 3), "SW33"),
167 GPIO_KEY(KEY_C, RCAR_GP_PIN(7, 2), "SW32"),
168 GPIO_KEY(KEY_B, RCAR_GP_PIN(7, 1), "SW31"),
169 GPIO_KEY(KEY_A, RCAR_GP_PIN(7, 0), "SW30"),
170};
171
172static const struct gpio_keys_platform_data koelsch_keys_pdata __initconst = {
173 .buttons = gpio_buttons,
174 .nbuttons = ARRAY_SIZE(gpio_buttons),
175};
176
177/* QSPI */
178static const struct resource qspi_resources[] __initconst = {
179 DEFINE_RES_MEM(0xe6b10000, 0x1000),
180 DEFINE_RES_IRQ_NAMED(gic_spi(184), "mux"),
181};
182
183static const struct rspi_plat_data qspi_pdata __initconst = {
184 .num_chipselect = 1,
185};
186
187/* SPI Flash memory (Spansion S25FL512SAGMFIG11 64 MiB) */
188static struct mtd_partition spi_flash_part[] = {
189 {
190 .name = "loader",
191 .offset = 0x00000000,
192 .size = 512 * 1024,
193 .mask_flags = MTD_WRITEABLE,
194 },
195 {
196 .name = "bootenv",
197 .offset = MTDPART_OFS_APPEND,
198 .size = 512 * 1024,
199 .mask_flags = MTD_WRITEABLE,
200 },
201 {
202 .name = "data",
203 .offset = MTDPART_OFS_APPEND,
204 .size = MTDPART_SIZ_FULL,
205 },
206};
207
208static const struct flash_platform_data spi_flash_data = {
209 .name = "m25p80",
210 .parts = spi_flash_part,
211 .nr_parts = ARRAY_SIZE(spi_flash_part),
212 .type = "s25fl512s",
213};
214
215static const struct spi_board_info spi_info[] __initconst = {
216 {
217 .modalias = "m25p80",
218 .platform_data = &spi_flash_data,
219 .mode = SPI_MODE_0 | SPI_TX_QUAD | SPI_RX_QUAD,
220 .max_speed_hz = 30000000,
221 .bus_num = 0,
222 .chip_select = 0,
223 },
224};
225
226/* SATA0 */
227static const struct resource sata0_resources[] __initconst = {
228 DEFINE_RES_MEM(0xee300000, 0x2000),
229 DEFINE_RES_IRQ(gic_spi(105)),
230};
231
232static const struct platform_device_info sata0_info __initconst = {
233 .name = "sata-r8a7791",
234 .id = 0,
235 .res = sata0_resources,
236 .num_res = ARRAY_SIZE(sata0_resources),
237 .dma_mask = DMA_BIT_MASK(32),
238};
239
240/* I2C */
241static const struct resource i2c_resources[] __initconst = {
242 /* I2C0 */
243 DEFINE_RES_MEM(0xE6508000, 0x40),
244 DEFINE_RES_IRQ(gic_spi(287)),
245 /* I2C1 */
246 DEFINE_RES_MEM(0xE6518000, 0x40),
247 DEFINE_RES_IRQ(gic_spi(288)),
248 /* I2C2 */
249 DEFINE_RES_MEM(0xE6530000, 0x40),
250 DEFINE_RES_IRQ(gic_spi(286)),
251 /* I2C3 */
252 DEFINE_RES_MEM(0xE6540000, 0x40),
253 DEFINE_RES_IRQ(gic_spi(290)),
254 /* I2C4 */
255 DEFINE_RES_MEM(0xE6520000, 0x40),
256 DEFINE_RES_IRQ(gic_spi(19)),
257 /* I2C5 */
258 DEFINE_RES_MEM(0xE6528000, 0x40),
259 DEFINE_RES_IRQ(gic_spi(20)),
260};
261
262static void __init koelsch_add_i2c(unsigned idx)
263{
264 unsigned res_idx = idx * 2;
265
266 BUG_ON(res_idx >= ARRAY_SIZE(i2c_resources));
267
268 platform_device_register_simple("i2c-rcar_gen2", idx,
269 i2c_resources + res_idx, 2);
270}
271
272#define SDHI_REGULATOR(idx, vdd_pin, vccq_pin) \
273static struct regulator_consumer_supply vcc_sdhi##idx##_consumer = \
274 REGULATOR_SUPPLY("vmmc", "sh_mobile_sdhi." #idx); \
275 \
276static struct regulator_init_data vcc_sdhi##idx##_init_data = { \
277 .constraints = { \
278 .valid_ops_mask = REGULATOR_CHANGE_STATUS, \
279 }, \
280 .consumer_supplies = &vcc_sdhi##idx##_consumer, \
281 .num_consumer_supplies = 1, \
282}; \
283 \
284static const struct fixed_voltage_config vcc_sdhi##idx##_info __initconst = {\
285 .supply_name = "SDHI" #idx "Vcc", \
286 .microvolts = 3300000, \
287 .gpio = vdd_pin, \
288 .enable_high = 1, \
289 .init_data = &vcc_sdhi##idx##_init_data, \
290}; \
291 \
292static struct regulator_consumer_supply vccq_sdhi##idx##_consumer = \
293 REGULATOR_SUPPLY("vqmmc", "sh_mobile_sdhi." #idx); \
294 \
295static struct regulator_init_data vccq_sdhi##idx##_init_data = { \
296 .constraints = { \
297 .input_uV = 3300000, \
298 .min_uV = 1800000, \
299 .max_uV = 3300000, \
300 .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE | \
301 REGULATOR_CHANGE_STATUS, \
302 }, \
303 .consumer_supplies = &vccq_sdhi##idx##_consumer, \
304 .num_consumer_supplies = 1, \
305}; \
306 \
307static struct gpio vccq_sdhi##idx##_gpio = \
308 { vccq_pin, GPIOF_OUT_INIT_HIGH, "vccq-sdhi" #idx }; \
309 \
310static struct gpio_regulator_state vccq_sdhi##idx##_states[] = { \
311 { .value = 1800000, .gpios = 0 }, \
312 { .value = 3300000, .gpios = 1 }, \
313}; \
314 \
315static const struct gpio_regulator_config vccq_sdhi##idx##_info __initconst = {\
316 .supply_name = "vqmmc", \
317 .gpios = &vccq_sdhi##idx##_gpio, \
318 .nr_gpios = 1, \
319 .states = vccq_sdhi##idx##_states, \
320 .nr_states = ARRAY_SIZE(vccq_sdhi##idx##_states), \
321 .type = REGULATOR_VOLTAGE, \
322 .init_data = &vccq_sdhi##idx##_init_data, \
323};
324
325SDHI_REGULATOR(0, RCAR_GP_PIN(7, 17), RCAR_GP_PIN(2, 12));
326SDHI_REGULATOR(1, RCAR_GP_PIN(7, 18), RCAR_GP_PIN(2, 13));
327SDHI_REGULATOR(2, RCAR_GP_PIN(7, 19), RCAR_GP_PIN(2, 26));
328
329/* SDHI0 */
330static struct sh_mobile_sdhi_info sdhi0_info __initdata = {
331 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
332 MMC_CAP_POWER_OFF_CARD,
333 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
334};
335
336static struct resource sdhi0_resources[] __initdata = {
337 DEFINE_RES_MEM(0xee100000, 0x200),
338 DEFINE_RES_IRQ(gic_spi(165)),
339};
340
341/* SDHI1 */
342static struct sh_mobile_sdhi_info sdhi1_info __initdata = {
343 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
344 MMC_CAP_POWER_OFF_CARD,
345 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT,
346};
347
348static struct resource sdhi1_resources[] __initdata = {
349 DEFINE_RES_MEM(0xee140000, 0x100),
350 DEFINE_RES_IRQ(gic_spi(167)),
351};
352
353/* SDHI2 */
354static struct sh_mobile_sdhi_info sdhi2_info __initdata = {
355 .tmio_caps = MMC_CAP_SD_HIGHSPEED | MMC_CAP_SDIO_IRQ |
356 MMC_CAP_POWER_OFF_CARD,
357 .tmio_flags = TMIO_MMC_HAS_IDLE_WAIT |
358 TMIO_MMC_WRPROTECT_DISABLE,
359};
360
361static struct resource sdhi2_resources[] __initdata = {
362 DEFINE_RES_MEM(0xee160000, 0x100),
363 DEFINE_RES_IRQ(gic_spi(168)),
364};
365
366static const struct pinctrl_map koelsch_pinctrl_map[] = {
367 /* DU */
368 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
369 "du_rgb666", "du"),
370 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
371 "du_sync", "du"),
372 PIN_MAP_MUX_GROUP_DEFAULT("rcar-du-r8a7791", "pfc-r8a7791",
373 "du_clk_out_0", "du"),
374 /* Ether */
375 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
376 "eth_link", "eth"),
377 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
378 "eth_mdio", "eth"),
379 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
380 "eth_rmii", "eth"),
381 PIN_MAP_MUX_GROUP_DEFAULT("r8a7791-ether", "pfc-r8a7791",
382 "intc_irq0", "intc"),
383 /* QSPI */
384 PIN_MAP_MUX_GROUP_DEFAULT("qspi.0", "pfc-r8a7791",
385 "qspi_ctrl", "qspi"),
386 PIN_MAP_MUX_GROUP_DEFAULT("qspi.0", "pfc-r8a7791",
387 "qspi_data4", "qspi"),
388 /* SCIF0 (CN19: DEBUG SERIAL0) */
389 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.6", "pfc-r8a7791",
390 "scif0_data_d", "scif0"),
391 /* SCIF1 (CN20: DEBUG SERIAL1) */
392 PIN_MAP_MUX_GROUP_DEFAULT("sh-sci.7", "pfc-r8a7791",
393 "scif1_data_d", "scif1"),
394 /* I2C1 */
395 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.1", "pfc-r8a7791",
396 "i2c1_e", "i2c1"),
397 /* I2C2 */
398 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.2", "pfc-r8a7791",
399 "i2c2", "i2c2"),
400 /* I2C4 */
401 PIN_MAP_MUX_GROUP_DEFAULT("i2c-rcar_gen2.4", "pfc-r8a7791",
402 "i2c4_c", "i2c4"),
403 /* SDHI0 */
404 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
405 "sdhi0_data4", "sdhi0"),
406 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
407 "sdhi0_ctrl", "sdhi0"),
408 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
409 "sdhi0_cd", "sdhi0"),
410 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.0", "pfc-r8a7791",
411 "sdhi0_wp", "sdhi0"),
412 /* SDHI2 */
413 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
414 "sdhi1_data4", "sdhi1"),
415 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
416 "sdhi1_ctrl", "sdhi1"),
417 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
418 "sdhi1_cd", "sdhi1"),
419 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.1", "pfc-r8a7791",
420 "sdhi1_wp", "sdhi1"),
421 /* SDHI2 */
422 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
423 "sdhi2_data4", "sdhi2"),
424 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
425 "sdhi2_ctrl", "sdhi2"),
426 PIN_MAP_MUX_GROUP_DEFAULT("sh_mobile_sdhi.2", "pfc-r8a7791",
427 "sdhi2_cd", "sdhi2"),
428};
429
430static void __init koelsch_add_standard_devices(void)
431{
432 r8a7791_clock_init();
433 pinctrl_register_mappings(koelsch_pinctrl_map,
434 ARRAY_SIZE(koelsch_pinctrl_map));
435 r8a7791_pinmux_init();
436 r8a7791_add_standard_devices();
437 platform_device_register_full(&ether_info);
438 platform_device_register_data(NULL, "leds-gpio", -1,
439 &koelsch_leds_pdata,
440 sizeof(koelsch_leds_pdata));
441 platform_device_register_data(NULL, "gpio-keys", -1,
442 &koelsch_keys_pdata,
443 sizeof(koelsch_keys_pdata));
444 platform_device_register_resndata(NULL, "qspi", 0,
445 qspi_resources,
446 ARRAY_SIZE(qspi_resources),
447 &qspi_pdata, sizeof(qspi_pdata));
448 spi_register_board_info(spi_info, ARRAY_SIZE(spi_info));
449
450 koelsch_add_du_device();
451
452 platform_device_register_full(&sata0_info);
453
454 koelsch_add_i2c(1);
455 koelsch_add_i2c(2);
456 koelsch_add_i2c(4);
457 koelsch_add_i2c(5);
458
459 platform_device_register_data(NULL, "reg-fixed-voltage", 0,
460 &vcc_sdhi0_info, sizeof(struct fixed_voltage_config));
461 platform_device_register_data(NULL, "reg-fixed-voltage", 1,
462 &vcc_sdhi1_info, sizeof(struct fixed_voltage_config));
463 platform_device_register_data(NULL, "reg-fixed-voltage", 2,
464 &vcc_sdhi2_info, sizeof(struct fixed_voltage_config));
465 platform_device_register_data(NULL, "gpio-regulator", 0,
466 &vccq_sdhi0_info, sizeof(struct gpio_regulator_config));
467 platform_device_register_data(NULL, "gpio-regulator", 1,
468 &vccq_sdhi1_info, sizeof(struct gpio_regulator_config));
469 platform_device_register_data(NULL, "gpio-regulator", 2,
470 &vccq_sdhi2_info, sizeof(struct gpio_regulator_config));
471
472 platform_device_register_resndata(NULL, "sh_mobile_sdhi", 0,
473 sdhi0_resources, ARRAY_SIZE(sdhi0_resources),
474 &sdhi0_info, sizeof(struct sh_mobile_sdhi_info));
475
476 platform_device_register_resndata(NULL, "sh_mobile_sdhi", 1,
477 sdhi1_resources, ARRAY_SIZE(sdhi1_resources),
478 &sdhi1_info, sizeof(struct sh_mobile_sdhi_info));
479
480 platform_device_register_resndata(NULL, "sh_mobile_sdhi", 2,
481 sdhi2_resources, ARRAY_SIZE(sdhi2_resources),
482 &sdhi2_info, sizeof(struct sh_mobile_sdhi_info));
483
484}
485
486/*
487 * Ether LEDs on the Koelsch board are named LINK and ACTIVE which corresponds
488 * to non-default 01 setting of the Micrel KSZ8041 PHY control register 1 bits
489 * 14-15. We have to set them back to 01 from the default 00 value each time
490 * the PHY is reset. It's also important because the PHY's LED0 signal is
491 * connected to SoC's ETH_LINK signal and in the PHY's default mode it will
492 * bounce on and off after each packet, which we apparently want to avoid.
493 */
494static int koelsch_ksz8041_fixup(struct phy_device *phydev)
495{
496 u16 phyctrl1 = phy_read(phydev, 0x1e);
497
498 phyctrl1 &= ~0xc000;
499 phyctrl1 |= 0x4000;
500 return phy_write(phydev, 0x1e, phyctrl1);
501}
502
503static void __init koelsch_init(void)
504{
505 koelsch_add_standard_devices();
506
507 irq_set_irq_type(irq_pin(0), IRQ_TYPE_LEVEL_LOW);
508
509 if (IS_ENABLED(CONFIG_PHYLIB))
510 phy_register_fixup_for_id("r8a7791-ether-ff:01",
511 koelsch_ksz8041_fixup);
512}
513
514static const char * const koelsch_boards_compat_dt[] __initconst = {
515 "renesas,koelsch",
516 NULL,
517};
518
519DT_MACHINE_START(KOELSCH_DT, "koelsch")
520 .smp = smp_ops(r8a7791_smp_ops),
521 .init_early = shmobile_init_delay,
522 .init_time = rcar_gen2_timer_init,
523 .init_machine = koelsch_init,
524 .init_late = shmobile_init_late,
525 .reserve = rcar_gen2_reserve,
526 .dt_compat = koelsch_boards_compat_dt,
527MACHINE_END
diff --git a/arch/arm/mach-shmobile/board-kzm9g-reference.c b/arch/arm/mach-shmobile/board-kzm9g-reference.c
index 0e1de7455c5c..2e82e44ab852 100644
--- a/arch/arm/mach-shmobile/board-kzm9g-reference.c
+++ b/arch/arm/mach-shmobile/board-kzm9g-reference.c
@@ -14,10 +14,6 @@
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */ 17 */
22 18
23#include <linux/delay.h> 19#include <linux/delay.h>
diff --git a/arch/arm/mach-shmobile/board-kzm9g.c b/arch/arm/mach-shmobile/board-kzm9g.c
index 77e36fa0b142..7c9b63bdde9f 100644
--- a/arch/arm/mach-shmobile/board-kzm9g.c
+++ b/arch/arm/mach-shmobile/board-kzm9g.c
@@ -11,10 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */ 14 */
19 15
20#include <linux/delay.h> 16#include <linux/delay.h>
diff --git a/arch/arm/mach-shmobile/board-lager-reference.c b/arch/arm/mach-shmobile/board-lager-reference.c
index bc4b48357dde..fa06bdba61df 100644
--- a/arch/arm/mach-shmobile/board-lager-reference.c
+++ b/arch/arm/mach-shmobile/board-lager-reference.c
@@ -12,100 +12,17 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20 16
21#include <linux/dma-mapping.h>
22#include <linux/init.h> 17#include <linux/init.h>
23#include <linux/of_platform.h> 18#include <linux/of_platform.h>
24#include <linux/platform_data/rcar-du.h>
25 19
26#include <asm/mach/arch.h> 20#include <asm/mach/arch.h>
27 21
28#include "clock.h"
29#include "common.h" 22#include "common.h"
30#include "irqs.h"
31#include "r8a7790.h" 23#include "r8a7790.h"
32#include "rcar-gen2.h" 24#include "rcar-gen2.h"
33 25
34/* DU */
35static struct rcar_du_encoder_data lager_du_encoders[] = {
36 {
37 .type = RCAR_DU_ENCODER_VGA,
38 .output = RCAR_DU_OUTPUT_DPAD0,
39 }, {
40 .type = RCAR_DU_ENCODER_NONE,
41 .output = RCAR_DU_OUTPUT_LVDS1,
42 .connector.lvds.panel = {
43 .width_mm = 210,
44 .height_mm = 158,
45 .mode = {
46 .pixelclock = 65000000,
47 .hactive = 1024,
48 .hfront_porch = 20,
49 .hback_porch = 160,
50 .hsync_len = 136,
51 .vactive = 768,
52 .vfront_porch = 3,
53 .vback_porch = 29,
54 .vsync_len = 6,
55 },
56 },
57 },
58};
59
60static struct rcar_du_platform_data lager_du_pdata = {
61 .encoders = lager_du_encoders,
62 .num_encoders = ARRAY_SIZE(lager_du_encoders),
63};
64
65static const struct resource du_resources[] __initconst = {
66 DEFINE_RES_MEM(0xfeb00000, 0x70000),
67 DEFINE_RES_MEM_NAMED(0xfeb90000, 0x1c, "lvds.0"),
68 DEFINE_RES_MEM_NAMED(0xfeb94000, 0x1c, "lvds.1"),
69 DEFINE_RES_IRQ(gic_spi(256)),
70 DEFINE_RES_IRQ(gic_spi(268)),
71 DEFINE_RES_IRQ(gic_spi(269)),
72};
73
74static void __init lager_add_du_device(void)
75{
76 struct platform_device_info info = {
77 .name = "rcar-du-r8a7790",
78 .id = -1,
79 .res = du_resources,
80 .num_res = ARRAY_SIZE(du_resources),
81 .data = &lager_du_pdata,
82 .size_data = sizeof(lager_du_pdata),
83 .dma_mask = DMA_BIT_MASK(32),
84 };
85
86 platform_device_register_full(&info);
87}
88
89/*
90 * This is a really crude hack to provide clkdev support to platform
91 * devices until they get moved to DT.
92 */
93static const struct clk_name clk_names[] __initconst = {
94 { "du0", "du.0", "rcar-du-r8a7790" },
95 { "du1", "du.1", "rcar-du-r8a7790" },
96 { "du2", "du.2", "rcar-du-r8a7790" },
97 { "lvds0", "lvds.0", "rcar-du-r8a7790" },
98 { "lvds1", "lvds.1", "rcar-du-r8a7790" },
99};
100
101static void __init lager_add_standard_devices(void)
102{
103 shmobile_clk_workaround(clk_names, ARRAY_SIZE(clk_names), false);
104 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
105
106 lager_add_du_device();
107}
108
109static const char *lager_boards_compat_dt[] __initdata = { 26static const char *lager_boards_compat_dt[] __initdata = {
110 "renesas,lager", 27 "renesas,lager",
111 "renesas,lager-reference", 28 "renesas,lager-reference",
@@ -116,7 +33,6 @@ DT_MACHINE_START(LAGER_DT, "lager")
116 .smp = smp_ops(r8a7790_smp_ops), 33 .smp = smp_ops(r8a7790_smp_ops),
117 .init_early = shmobile_init_delay, 34 .init_early = shmobile_init_delay,
118 .init_time = rcar_gen2_timer_init, 35 .init_time = rcar_gen2_timer_init,
119 .init_machine = lager_add_standard_devices,
120 .init_late = shmobile_init_late, 36 .init_late = shmobile_init_late,
121 .reserve = rcar_gen2_reserve, 37 .reserve = rcar_gen2_reserve,
122 .dt_compat = lager_boards_compat_dt, 38 .dt_compat = lager_boards_compat_dt,
diff --git a/arch/arm/mach-shmobile/board-lager.c b/arch/arm/mach-shmobile/board-lager.c
index 571327b1c942..b47262afb240 100644
--- a/arch/arm/mach-shmobile/board-lager.c
+++ b/arch/arm/mach-shmobile/board-lager.c
@@ -13,10 +13,6 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 16 */
21 17
22#include <linux/gpio.h> 18#include <linux/gpio.h>
diff --git a/arch/arm/mach-shmobile/board-mackerel.c b/arch/arm/mach-shmobile/board-mackerel.c
index ca5d34b92aa7..ed1087031c5d 100644
--- a/arch/arm/mach-shmobile/board-mackerel.c
+++ b/arch/arm/mach-shmobile/board-mackerel.c
@@ -16,10 +16,6 @@
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details. 18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */ 19 */
24#include <linux/delay.h> 20#include <linux/delay.h>
25#include <linux/kernel.h> 21#include <linux/kernel.h>
diff --git a/arch/arm/mach-shmobile/board-marzen-reference.c b/arch/arm/mach-shmobile/board-marzen-reference.c
index 38d9cdd26587..b15eb923263f 100644
--- a/arch/arm/mach-shmobile/board-marzen-reference.c
+++ b/arch/arm/mach-shmobile/board-marzen-reference.c
@@ -13,10 +13,6 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 16 */
21 17
22#include <linux/clk/shmobile.h> 18#include <linux/clk/shmobile.h>
@@ -26,7 +22,6 @@
26#include <asm/irq.h> 22#include <asm/irq.h>
27#include <asm/mach/arch.h> 23#include <asm/mach/arch.h>
28 24
29#include "clock.h"
30#include "common.h" 25#include "common.h"
31#include "irqs.h" 26#include "irqs.h"
32#include "r8a7779.h" 27#include "r8a7779.h"
diff --git a/arch/arm/mach-shmobile/board-marzen.c b/arch/arm/mach-shmobile/board-marzen.c
index ce33d7825c49..994dc7d86ae2 100644
--- a/arch/arm/mach-shmobile/board-marzen.c
+++ b/arch/arm/mach-shmobile/board-marzen.c
@@ -13,10 +13,6 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 16 */
21 17
22#include <linux/kernel.h> 18#include <linux/kernel.h>
diff --git a/arch/arm/mach-shmobile/clock-r8a73a4.c b/arch/arm/mach-shmobile/clock-r8a73a4.c
index c2330ea1802c..1cf44dc6d718 100644
--- a/arch/arm/mach-shmobile/clock-r8a73a4.c
+++ b/arch/arm/mach-shmobile/clock-r8a73a4.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20#include <linux/init.h> 16#include <linux/init.h>
21#include <linux/io.h> 17#include <linux/io.h>
diff --git a/arch/arm/mach-shmobile/clock-r8a7740.c b/arch/arm/mach-shmobile/clock-r8a7740.c
index 0794f0426e70..9cac8247c72b 100644
--- a/arch/arm/mach-shmobile/clock-r8a7740.c
+++ b/arch/arm/mach-shmobile/clock-r8a7740.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 15 */
20#include <linux/init.h> 16#include <linux/init.h>
21#include <linux/kernel.h> 17#include <linux/kernel.h>
@@ -455,7 +451,7 @@ enum {
455 MSTP128, MSTP127, MSTP125, 451 MSTP128, MSTP127, MSTP125,
456 MSTP116, MSTP111, MSTP100, MSTP117, 452 MSTP116, MSTP111, MSTP100, MSTP117,
457 453
458 MSTP230, 454 MSTP230, MSTP229,
459 MSTP222, 455 MSTP222,
460 MSTP218, MSTP217, MSTP216, MSTP214, 456 MSTP218, MSTP217, MSTP216, MSTP214,
461 MSTP207, MSTP206, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200, 457 MSTP207, MSTP206, MSTP204, MSTP203, MSTP202, MSTP201, MSTP200,
@@ -474,11 +470,12 @@ static struct clk mstp_clks[MSTP_NR] = {
474 [MSTP127] = SH_CLK_MSTP32(&div4_clks[DIV4_S], SMSTPCR1, 27, 0), /* CEU20 */ 470 [MSTP127] = SH_CLK_MSTP32(&div4_clks[DIV4_S], SMSTPCR1, 27, 0), /* CEU20 */
475 [MSTP125] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 25, 0), /* TMU0 */ 471 [MSTP125] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 25, 0), /* TMU0 */
476 [MSTP117] = SH_CLK_MSTP32(&div4_clks[DIV4_B], SMSTPCR1, 17, 0), /* LCDC1 */ 472 [MSTP117] = SH_CLK_MSTP32(&div4_clks[DIV4_B], SMSTPCR1, 17, 0), /* LCDC1 */
477 [MSTP116] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 16, 0), /* IIC0 */ 473 [MSTP116] = SH_CLK_MSTP32(&div4_clks[DIV4_HPP], SMSTPCR1, 16, 0), /* IIC0 */
478 [MSTP111] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 11, 0), /* TMU1 */ 474 [MSTP111] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR1, 11, 0), /* TMU1 */
479 [MSTP100] = SH_CLK_MSTP32(&div4_clks[DIV4_B], SMSTPCR1, 0, 0), /* LCDC0 */ 475 [MSTP100] = SH_CLK_MSTP32(&div4_clks[DIV4_B], SMSTPCR1, 0, 0), /* LCDC0 */
480 476
481 [MSTP230] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 30, 0), /* SCIFA6 */ 477 [MSTP230] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 30, 0), /* SCIFA6 */
478 [MSTP229] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR2, 29, 0), /* INTCA */
482 [MSTP222] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 22, 0), /* SCIFA7 */ 479 [MSTP222] = SH_CLK_MSTP32(&div6_clks[DIV6_SUB], SMSTPCR2, 22, 0), /* SCIFA7 */
483 [MSTP218] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR2, 18, 0), /* DMAC1 */ 480 [MSTP218] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR2, 18, 0), /* DMAC1 */
484 [MSTP217] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR2, 17, 0), /* DMAC2 */ 481 [MSTP217] = SH_CLK_MSTP32(&div4_clks[DIV4_HP], SMSTPCR2, 17, 0), /* DMAC2 */
@@ -575,6 +572,10 @@ static struct clk_lookup lookups[] = {
575 CLKDEV_DEV_ID("sh-dma-engine.0", &mstp_clks[MSTP218]), 572 CLKDEV_DEV_ID("sh-dma-engine.0", &mstp_clks[MSTP218]),
576 CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP222]), 573 CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP222]),
577 CLKDEV_DEV_ID("e6cd0000.serial", &mstp_clks[MSTP222]), 574 CLKDEV_DEV_ID("e6cd0000.serial", &mstp_clks[MSTP222]),
575 CLKDEV_DEV_ID("renesas_intc_irqpin.0", &mstp_clks[MSTP229]),
576 CLKDEV_DEV_ID("renesas_intc_irqpin.1", &mstp_clks[MSTP229]),
577 CLKDEV_DEV_ID("renesas_intc_irqpin.2", &mstp_clks[MSTP229]),
578 CLKDEV_DEV_ID("renesas_intc_irqpin.3", &mstp_clks[MSTP229]),
578 CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP230]), 579 CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP230]),
579 CLKDEV_DEV_ID("e6cc0000.serial", &mstp_clks[MSTP230]), 580 CLKDEV_DEV_ID("e6cc0000.serial", &mstp_clks[MSTP230]),
580 581
diff --git a/arch/arm/mach-shmobile/clock-r8a7778.c b/arch/arm/mach-shmobile/clock-r8a7778.c
index 67980a08a601..e8510c35558c 100644
--- a/arch/arm/mach-shmobile/clock-r8a7778.c
+++ b/arch/arm/mach-shmobile/clock-r8a7778.c
@@ -17,10 +17,6 @@
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details. 19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */ 20 */
25 21
26/* 22/*
diff --git a/arch/arm/mach-shmobile/clock-r8a7779.c b/arch/arm/mach-shmobile/clock-r8a7779.c
index c51f9db3f66f..fa8ab2cc9187 100644
--- a/arch/arm/mach-shmobile/clock-r8a7779.c
+++ b/arch/arm/mach-shmobile/clock-r8a7779.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 15 */
20#include <linux/bitops.h> 16#include <linux/bitops.h>
21#include <linux/init.h> 17#include <linux/init.h>
diff --git a/arch/arm/mach-shmobile/clock-r8a7790.c b/arch/arm/mach-shmobile/clock-r8a7790.c
index 126ddafad526..f9bbc5f0a9a1 100644
--- a/arch/arm/mach-shmobile/clock-r8a7790.c
+++ b/arch/arm/mach-shmobile/clock-r8a7790.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20#include <linux/init.h> 16#include <linux/init.h>
21#include <linux/io.h> 17#include <linux/io.h>
@@ -68,7 +64,7 @@
68 64
69#define SDCKCR 0xE6150074 65#define SDCKCR 0xE6150074
70#define SD2CKCR 0xE6150078 66#define SD2CKCR 0xE6150078
71#define SD3CKCR 0xE615007C 67#define SD3CKCR 0xE615026C
72#define MMC0CKCR 0xE6150240 68#define MMC0CKCR 0xE6150240
73#define MMC1CKCR 0xE6150244 69#define MMC1CKCR 0xE6150244
74#define SSPCKCR 0xE6150248 70#define SSPCKCR 0xE6150248
diff --git a/arch/arm/mach-shmobile/clock-r8a7791.c b/arch/arm/mach-shmobile/clock-r8a7791.c
deleted file mode 100644
index 453b23129cfa..000000000000
--- a/arch/arm/mach-shmobile/clock-r8a7791.c
+++ /dev/null
@@ -1,342 +0,0 @@
1/*
2 * r8a7791 clock framework support
3 *
4 * Copyright (C) 2013 Renesas Electronics Corporation
5 * Copyright (C) 2013 Renesas Solutions Corp.
6 * Copyright (C) 2013 Magnus Damm
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21#include <linux/init.h>
22#include <linux/io.h>
23#include <linux/kernel.h>
24#include <linux/sh_clk.h>
25#include <linux/clkdev.h>
26#include "clock.h"
27#include "common.h"
28#include "rcar-gen2.h"
29
30/*
31 * MD EXTAL PLL0 PLL1 PLL3
32 * 14 13 19 (MHz) *1 *1
33 *---------------------------------------------------
34 * 0 0 0 15 x 1 x172/2 x208/2 x106
35 * 0 0 1 15 x 1 x172/2 x208/2 x88
36 * 0 1 0 20 x 1 x130/2 x156/2 x80
37 * 0 1 1 20 x 1 x130/2 x156/2 x66
38 * 1 0 0 26 / 2 x200/2 x240/2 x122
39 * 1 0 1 26 / 2 x200/2 x240/2 x102
40 * 1 1 0 30 / 2 x172/2 x208/2 x106
41 * 1 1 1 30 / 2 x172/2 x208/2 x88
42 *
43 * *1 : Table 7.6 indicates VCO ouput (PLLx = VCO/2)
44 * see "p1 / 2" on R8A7791_CLOCK_ROOT() below
45 */
46
47#define CPG_BASE 0xe6150000
48#define CPG_LEN 0x1000
49
50#define SMSTPCR0 0xE6150130
51#define SMSTPCR1 0xE6150134
52#define SMSTPCR2 0xe6150138
53#define SMSTPCR3 0xE615013C
54#define SMSTPCR5 0xE6150144
55#define SMSTPCR7 0xe615014c
56#define SMSTPCR8 0xE6150990
57#define SMSTPCR9 0xE6150994
58#define SMSTPCR10 0xE6150998
59#define SMSTPCR11 0xE615099C
60
61#define MSTPSR1 IOMEM(0xe6150038)
62#define MSTPSR2 IOMEM(0xe6150040)
63#define MSTPSR3 IOMEM(0xe6150048)
64#define MSTPSR5 IOMEM(0xe615003c)
65#define MSTPSR7 IOMEM(0xe61501c4)
66#define MSTPSR8 IOMEM(0xe61509a0)
67#define MSTPSR9 IOMEM(0xe61509a4)
68#define MSTPSR11 IOMEM(0xe61509ac)
69
70#define SDCKCR 0xE6150074
71#define SD1CKCR 0xE6150078
72#define SD2CKCR 0xE615026c
73#define MMC0CKCR 0xE6150240
74#define MMC1CKCR 0xE6150244
75#define SSPCKCR 0xE6150248
76#define SSPRSCKCR 0xE615024C
77
78static struct clk_mapping cpg_mapping = {
79 .phys = CPG_BASE,
80 .len = CPG_LEN,
81};
82
83static struct clk extal_clk = {
84 /* .rate will be updated on r8a7791_clock_init() */
85 .mapping = &cpg_mapping,
86};
87
88static struct sh_clk_ops followparent_clk_ops = {
89 .recalc = followparent_recalc,
90};
91
92static struct clk main_clk = {
93 /* .parent will be set r8a73a4_clock_init */
94 .ops = &followparent_clk_ops,
95};
96
97/*
98 * clock ratio of these clock will be updated
99 * on r8a7791_clock_init()
100 */
101SH_FIXED_RATIO_CLK_SET(pll1_clk, main_clk, 1, 1);
102SH_FIXED_RATIO_CLK_SET(pll3_clk, main_clk, 1, 1);
103SH_FIXED_RATIO_CLK_SET(qspi_clk, pll1_clk, 1, 1);
104
105/* fixed ratio clock */
106SH_FIXED_RATIO_CLK_SET(extal_div2_clk, extal_clk, 1, 2);
107SH_FIXED_RATIO_CLK_SET(cp_clk, extal_clk, 1, 2);
108
109SH_FIXED_RATIO_CLK_SET(pll1_div2_clk, pll1_clk, 1, 2);
110SH_FIXED_RATIO_CLK_SET(hp_clk, pll1_clk, 1, 12);
111SH_FIXED_RATIO_CLK_SET(p_clk, pll1_clk, 1, 24);
112SH_FIXED_RATIO_CLK_SET(rclk_clk, pll1_clk, 1, (48 * 1024));
113SH_FIXED_RATIO_CLK_SET(mp_clk, pll1_div2_clk, 1, 15);
114SH_FIXED_RATIO_CLK_SET(zg_clk, pll1_clk, 1, 3);
115SH_FIXED_RATIO_CLK_SET(zx_clk, pll1_clk, 1, 3);
116SH_FIXED_RATIO_CLK_SET(zs_clk, pll1_clk, 1, 6);
117
118static struct clk *main_clks[] = {
119 &extal_clk,
120 &extal_div2_clk,
121 &main_clk,
122 &pll1_clk,
123 &pll1_div2_clk,
124 &pll3_clk,
125 &hp_clk,
126 &p_clk,
127 &qspi_clk,
128 &rclk_clk,
129 &mp_clk,
130 &cp_clk,
131 &zg_clk,
132 &zx_clk,
133 &zs_clk,
134};
135
136/* SDHI (DIV4) clock */
137static int divisors[] = { 2, 3, 4, 6, 8, 12, 16, 18, 24, 0, 36, 48, 10 };
138
139static struct clk_div_mult_table div4_div_mult_table = {
140 .divisors = divisors,
141 .nr_divisors = ARRAY_SIZE(divisors),
142};
143
144static struct clk_div4_table div4_table = {
145 .div_mult_table = &div4_div_mult_table,
146};
147
148enum {
149 DIV4_SDH, DIV4_SD0,
150 DIV4_NR
151};
152
153static struct clk div4_clks[DIV4_NR] = {
154 [DIV4_SDH] = SH_CLK_DIV4(&pll1_clk, SDCKCR, 8, 0x0dff, CLK_ENABLE_ON_INIT),
155 [DIV4_SD0] = SH_CLK_DIV4(&pll1_clk, SDCKCR, 4, 0x1df0, CLK_ENABLE_ON_INIT),
156};
157
158/* DIV6 clocks */
159enum {
160 DIV6_SD1, DIV6_SD2,
161 DIV6_NR
162};
163
164static struct clk div6_clks[DIV6_NR] = {
165 [DIV6_SD1] = SH_CLK_DIV6(&pll1_div2_clk, SD1CKCR, 0),
166 [DIV6_SD2] = SH_CLK_DIV6(&pll1_div2_clk, SD2CKCR, 0),
167};
168
169/* MSTP */
170enum {
171 MSTP1108, MSTP1107, MSTP1106,
172 MSTP931, MSTP930, MSTP929, MSTP928, MSTP927, MSTP925,
173 MSTP917,
174 MSTP815, MSTP814,
175 MSTP813,
176 MSTP811, MSTP810, MSTP809,
177 MSTP726, MSTP724, MSTP723, MSTP721, MSTP720,
178 MSTP719, MSTP718, MSTP715, MSTP714,
179 MSTP522,
180 MSTP314, MSTP312, MSTP311,
181 MSTP216, MSTP207, MSTP206,
182 MSTP204, MSTP203, MSTP202,
183 MSTP124,
184 MSTP_NR
185};
186
187static struct clk mstp_clks[MSTP_NR] = {
188 [MSTP1108] = SH_CLK_MSTP32_STS(&mp_clk, SMSTPCR11, 8, MSTPSR11, 0), /* SCIFA5 */
189 [MSTP1107] = SH_CLK_MSTP32_STS(&mp_clk, SMSTPCR11, 7, MSTPSR11, 0), /* SCIFA4 */
190 [MSTP1106] = SH_CLK_MSTP32_STS(&mp_clk, SMSTPCR11, 6, MSTPSR11, 0), /* SCIFA3 */
191 [MSTP931] = SH_CLK_MSTP32_STS(&hp_clk, SMSTPCR9, 31, MSTPSR9, 0), /* I2C0 */
192 [MSTP930] = SH_CLK_MSTP32_STS(&hp_clk, SMSTPCR9, 30, MSTPSR9, 0), /* I2C1 */
193 [MSTP929] = SH_CLK_MSTP32_STS(&hp_clk, SMSTPCR9, 29, MSTPSR9, 0), /* I2C2 */
194 [MSTP928] = SH_CLK_MSTP32_STS(&hp_clk, SMSTPCR9, 28, MSTPSR9, 0), /* I2C3 */
195 [MSTP927] = SH_CLK_MSTP32_STS(&hp_clk, SMSTPCR9, 27, MSTPSR9, 0), /* I2C4 */
196 [MSTP925] = SH_CLK_MSTP32_STS(&hp_clk, SMSTPCR9, 25, MSTPSR9, 0), /* I2C5 */
197 [MSTP917] = SH_CLK_MSTP32_STS(&qspi_clk, SMSTPCR9, 17, MSTPSR9, 0), /* QSPI */
198 [MSTP815] = SH_CLK_MSTP32_STS(&zs_clk, SMSTPCR8, 15, MSTPSR8, 0), /* SATA0 */
199 [MSTP814] = SH_CLK_MSTP32_STS(&zs_clk, SMSTPCR8, 14, MSTPSR8, 0), /* SATA1 */
200 [MSTP813] = SH_CLK_MSTP32_STS(&p_clk, SMSTPCR8, 13, MSTPSR8, 0), /* Ether */
201 [MSTP811] = SH_CLK_MSTP32_STS(&zg_clk, SMSTPCR8, 11, MSTPSR8, 0), /* VIN0 */
202 [MSTP810] = SH_CLK_MSTP32_STS(&zg_clk, SMSTPCR8, 10, MSTPSR8, 0), /* VIN1 */
203 [MSTP809] = SH_CLK_MSTP32_STS(&zg_clk, SMSTPCR8, 9, MSTPSR8, 0), /* VIN2 */
204 [MSTP726] = SH_CLK_MSTP32_STS(&zx_clk, SMSTPCR7, 26, MSTPSR7, 0), /* LVDS0 */
205 [MSTP724] = SH_CLK_MSTP32_STS(&zx_clk, SMSTPCR7, 24, MSTPSR7, 0), /* DU0 */
206 [MSTP723] = SH_CLK_MSTP32_STS(&zx_clk, SMSTPCR7, 23, MSTPSR7, 0), /* DU1 */
207 [MSTP721] = SH_CLK_MSTP32_STS(&p_clk, SMSTPCR7, 21, MSTPSR7, 0), /* SCIF0 */
208 [MSTP720] = SH_CLK_MSTP32_STS(&p_clk, SMSTPCR7, 20, MSTPSR7, 0), /* SCIF1 */
209 [MSTP719] = SH_CLK_MSTP32_STS(&p_clk, SMSTPCR7, 19, MSTPSR7, 0), /* SCIF2 */
210 [MSTP718] = SH_CLK_MSTP32_STS(&p_clk, SMSTPCR7, 18, MSTPSR7, 0), /* SCIF3 */
211 [MSTP715] = SH_CLK_MSTP32_STS(&p_clk, SMSTPCR7, 15, MSTPSR7, 0), /* SCIF4 */
212 [MSTP714] = SH_CLK_MSTP32_STS(&p_clk, SMSTPCR7, 14, MSTPSR7, 0), /* SCIF5 */
213 [MSTP522] = SH_CLK_MSTP32_STS(&extal_clk, SMSTPCR5, 22, MSTPSR5, 0), /* Thermal */
214 [MSTP314] = SH_CLK_MSTP32_STS(&div4_clks[DIV4_SD0], SMSTPCR3, 14, MSTPSR3, 0), /* SDHI0 */
215 [MSTP312] = SH_CLK_MSTP32_STS(&div6_clks[DIV6_SD1], SMSTPCR3, 12, MSTPSR3, 0), /* SDHI1 */
216 [MSTP311] = SH_CLK_MSTP32_STS(&div6_clks[DIV6_SD2], SMSTPCR3, 11, MSTPSR3, 0), /* SDHI2 */
217 [MSTP216] = SH_CLK_MSTP32_STS(&mp_clk, SMSTPCR2, 16, MSTPSR2, 0), /* SCIFB2 */
218 [MSTP207] = SH_CLK_MSTP32_STS(&mp_clk, SMSTPCR2, 7, MSTPSR2, 0), /* SCIFB1 */
219 [MSTP206] = SH_CLK_MSTP32_STS(&mp_clk, SMSTPCR2, 6, MSTPSR2, 0), /* SCIFB0 */
220 [MSTP204] = SH_CLK_MSTP32_STS(&mp_clk, SMSTPCR2, 4, MSTPSR2, 0), /* SCIFA0 */
221 [MSTP203] = SH_CLK_MSTP32_STS(&mp_clk, SMSTPCR2, 3, MSTPSR2, 0), /* SCIFA1 */
222 [MSTP202] = SH_CLK_MSTP32_STS(&mp_clk, SMSTPCR2, 2, MSTPSR2, 0), /* SCIFA2 */
223 [MSTP124] = SH_CLK_MSTP32_STS(&rclk_clk, SMSTPCR1, 24, MSTPSR1, 0), /* CMT0 */
224};
225
226static struct clk_lookup lookups[] = {
227
228 /* main clocks */
229 CLKDEV_CON_ID("extal", &extal_clk),
230 CLKDEV_CON_ID("extal_div2", &extal_div2_clk),
231 CLKDEV_CON_ID("main", &main_clk),
232 CLKDEV_CON_ID("pll1", &pll1_clk),
233 CLKDEV_CON_ID("pll1_div2", &pll1_div2_clk),
234 CLKDEV_CON_ID("pll3", &pll3_clk),
235 CLKDEV_CON_ID("zg", &zg_clk),
236 CLKDEV_CON_ID("zs", &zs_clk),
237 CLKDEV_CON_ID("hp", &hp_clk),
238 CLKDEV_CON_ID("p", &p_clk),
239 CLKDEV_CON_ID("qspi", &qspi_clk),
240 CLKDEV_CON_ID("rclk", &rclk_clk),
241 CLKDEV_CON_ID("mp", &mp_clk),
242 CLKDEV_CON_ID("cp", &cp_clk),
243 CLKDEV_CON_ID("peripheral_clk", &hp_clk),
244
245 /* MSTP */
246 CLKDEV_ICK_ID("lvds.0", "rcar-du-r8a7791", &mstp_clks[MSTP726]),
247 CLKDEV_ICK_ID("du.0", "rcar-du-r8a7791", &mstp_clks[MSTP724]),
248 CLKDEV_ICK_ID("du.1", "rcar-du-r8a7791", &mstp_clks[MSTP723]),
249 CLKDEV_DEV_ID("sh-sci.0", &mstp_clks[MSTP204]), /* SCIFA0 */
250 CLKDEV_DEV_ID("sh-sci.1", &mstp_clks[MSTP203]), /* SCIFA1 */
251 CLKDEV_DEV_ID("sh-sci.2", &mstp_clks[MSTP206]), /* SCIFB0 */
252 CLKDEV_DEV_ID("sh-sci.3", &mstp_clks[MSTP207]), /* SCIFB1 */
253 CLKDEV_DEV_ID("sh-sci.4", &mstp_clks[MSTP216]), /* SCIFB2 */
254 CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP202]), /* SCIFA2 */
255 CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP721]), /* SCIF0 */
256 CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP720]), /* SCIF1 */
257 CLKDEV_DEV_ID("sh-sci.8", &mstp_clks[MSTP719]), /* SCIF2 */
258 CLKDEV_DEV_ID("sh-sci.9", &mstp_clks[MSTP718]), /* SCIF3 */
259 CLKDEV_DEV_ID("sh-sci.10", &mstp_clks[MSTP715]), /* SCIF4 */
260 CLKDEV_DEV_ID("sh-sci.11", &mstp_clks[MSTP714]), /* SCIF5 */
261 CLKDEV_DEV_ID("sh-sci.12", &mstp_clks[MSTP1106]), /* SCIFA3 */
262 CLKDEV_DEV_ID("sh-sci.13", &mstp_clks[MSTP1107]), /* SCIFA4 */
263 CLKDEV_DEV_ID("sh-sci.14", &mstp_clks[MSTP1108]), /* SCIFA5 */
264 CLKDEV_DEV_ID("sh_mobile_sdhi.0", &mstp_clks[MSTP314]),
265 CLKDEV_DEV_ID("sh_mobile_sdhi.1", &mstp_clks[MSTP312]),
266 CLKDEV_DEV_ID("sh_mobile_sdhi.2", &mstp_clks[MSTP311]),
267 CLKDEV_ICK_ID("fck", "sh-cmt-48-gen2.0", &mstp_clks[MSTP124]),
268 CLKDEV_DEV_ID("qspi.0", &mstp_clks[MSTP917]),
269 CLKDEV_DEV_ID("rcar_thermal", &mstp_clks[MSTP522]),
270 CLKDEV_DEV_ID("i2c-rcar_gen2.0", &mstp_clks[MSTP931]),
271 CLKDEV_DEV_ID("i2c-rcar_gen2.1", &mstp_clks[MSTP930]),
272 CLKDEV_DEV_ID("i2c-rcar_gen2.2", &mstp_clks[MSTP929]),
273 CLKDEV_DEV_ID("i2c-rcar_gen2.3", &mstp_clks[MSTP928]),
274 CLKDEV_DEV_ID("i2c-rcar_gen2.4", &mstp_clks[MSTP927]),
275 CLKDEV_DEV_ID("i2c-rcar_gen2.5", &mstp_clks[MSTP925]),
276 CLKDEV_DEV_ID("r8a7791-ether", &mstp_clks[MSTP813]), /* Ether */
277 CLKDEV_DEV_ID("r8a7791-vin.0", &mstp_clks[MSTP811]),
278 CLKDEV_DEV_ID("r8a7791-vin.1", &mstp_clks[MSTP810]),
279 CLKDEV_DEV_ID("r8a7791-vin.2", &mstp_clks[MSTP809]),
280 CLKDEV_DEV_ID("sata-r8a7791.0", &mstp_clks[MSTP815]),
281 CLKDEV_DEV_ID("sata-r8a7791.1", &mstp_clks[MSTP814]),
282};
283
284#define R8A7791_CLOCK_ROOT(e, m, p0, p1, p30, p31) \
285 extal_clk.rate = e * 1000 * 1000; \
286 main_clk.parent = m; \
287 SH_CLK_SET_RATIO(&pll1_clk_ratio, p1 / 2, 1); \
288 if (mode & MD(19)) \
289 SH_CLK_SET_RATIO(&pll3_clk_ratio, p31, 1); \
290 else \
291 SH_CLK_SET_RATIO(&pll3_clk_ratio, p30, 1)
292
293
294void __init r8a7791_clock_init(void)
295{
296 u32 mode = rcar_gen2_read_mode_pins();
297 int k, ret = 0;
298
299 switch (mode & (MD(14) | MD(13))) {
300 case 0:
301 R8A7791_CLOCK_ROOT(15, &extal_clk, 172, 208, 106, 88);
302 break;
303 case MD(13):
304 R8A7791_CLOCK_ROOT(20, &extal_clk, 130, 156, 80, 66);
305 break;
306 case MD(14):
307 R8A7791_CLOCK_ROOT(26, &extal_div2_clk, 200, 240, 122, 102);
308 break;
309 case MD(13) | MD(14):
310 R8A7791_CLOCK_ROOT(30, &extal_div2_clk, 172, 208, 106, 88);
311 break;
312 }
313
314 if ((mode & (MD(3) | MD(2) | MD(1))) == MD(2))
315 SH_CLK_SET_RATIO(&qspi_clk_ratio, 1, 16);
316 else
317 SH_CLK_SET_RATIO(&qspi_clk_ratio, 1, 20);
318
319 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
320 ret = clk_register(main_clks[k]);
321
322 if (!ret)
323 ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
324
325 if (!ret)
326 ret = sh_clk_div6_register(div6_clks, DIV6_NR);
327
328 if (!ret)
329 ret = sh_clk_mstp_register(mstp_clks, MSTP_NR);
330
331 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
332
333 if (!ret)
334 shmobile_clk_init();
335 else
336 goto epanic;
337
338 return;
339
340epanic:
341 panic("failed to setup r8a7791 clocks\n");
342}
diff --git a/arch/arm/mach-shmobile/clock-sh7372.c b/arch/arm/mach-shmobile/clock-sh7372.c
index 7071676145c4..3bc92f46060e 100644
--- a/arch/arm/mach-shmobile/clock-sh7372.c
+++ b/arch/arm/mach-shmobile/clock-sh7372.c
@@ -11,10 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 14 */
19#include <linux/init.h> 15#include <linux/init.h>
20#include <linux/kernel.h> 16#include <linux/kernel.h>
diff --git a/arch/arm/mach-shmobile/clock-sh73a0.c b/arch/arm/mach-shmobile/clock-sh73a0.c
index 02a6f45a0b9e..6b4c1f313cc9 100644
--- a/arch/arm/mach-shmobile/clock-sh73a0.c
+++ b/arch/arm/mach-shmobile/clock-sh73a0.c
@@ -11,10 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 14 */
19#include <linux/init.h> 15#include <linux/init.h>
20#include <linux/kernel.h> 16#include <linux/kernel.h>
diff --git a/arch/arm/mach-shmobile/clock.c b/arch/arm/mach-shmobile/clock.c
index 806f94038cc4..34f056fc3756 100644
--- a/arch/arm/mach-shmobile/clock.c
+++ b/arch/arm/mach-shmobile/clock.c
@@ -14,41 +14,13 @@
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */ 17 */
18
19#include <linux/export.h>
22#include <linux/kernel.h> 20#include <linux/kernel.h>
23#include <linux/init.h> 21#include <linux/init.h>
24
25#ifdef CONFIG_COMMON_CLK
26#include <linux/clk.h>
27#include <linux/clkdev.h>
28#include "clock.h"
29
30void __init shmobile_clk_workaround(const struct clk_name *clks,
31 int nr_clks, bool enable)
32{
33 const struct clk_name *clkn;
34 struct clk *clk;
35 unsigned int i;
36
37 for (i = 0; i < nr_clks; ++i) {
38 clkn = clks + i;
39 clk = clk_get(NULL, clkn->clk);
40 if (!IS_ERR(clk)) {
41 clk_register_clkdev(clk, clkn->con_id, clkn->dev_id);
42 if (enable)
43 clk_prepare_enable(clk);
44 clk_put(clk);
45 }
46 }
47}
48
49#else /* CONFIG_COMMON_CLK */
50#include <linux/sh_clk.h> 22#include <linux/sh_clk.h>
51#include <linux/export.h> 23
52#include "clock.h" 24#include "clock.h"
53#include "common.h" 25#include "common.h"
54 26
@@ -84,5 +56,3 @@ void __clk_put(struct clk *clk)
84{ 56{
85} 57}
86EXPORT_SYMBOL(__clk_put); 58EXPORT_SYMBOL(__clk_put);
87
88#endif /* CONFIG_COMMON_CLK */
diff --git a/arch/arm/mach-shmobile/clock.h b/arch/arm/mach-shmobile/clock.h
index 31b6417463e6..cf3552ea1019 100644
--- a/arch/arm/mach-shmobile/clock.h
+++ b/arch/arm/mach-shmobile/clock.h
@@ -1,19 +1,6 @@
1#ifndef CLOCK_H 1#ifndef CLOCK_H
2#define CLOCK_H 2#define CLOCK_H
3 3
4#ifdef CONFIG_COMMON_CLK
5/* temporary clock configuration helper for platform devices */
6
7struct clk_name {
8 const char *clk;
9 const char *con_id;
10 const char *dev_id;
11};
12
13void shmobile_clk_workaround(const struct clk_name *clks, int nr_clks,
14 bool enable);
15
16#else /* CONFIG_COMMON_CLK */
17/* legacy clock implementation */ 4/* legacy clock implementation */
18 5
19struct clk; 6struct clk;
@@ -52,5 +39,4 @@ do { \
52 (p)->div = d; \ 39 (p)->div = d; \
53} while (0) 40} while (0)
54 41
55#endif /* CONFIG_COMMON_CLK */
56#endif 42#endif
diff --git a/arch/arm/mach-shmobile/console.c b/arch/arm/mach-shmobile/console.c
index f2e79f2376e1..e329ccbd0a67 100644
--- a/arch/arm/mach-shmobile/console.c
+++ b/arch/arm/mach-shmobile/console.c
@@ -11,10 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */ 14 */
19#include <linux/kernel.h> 15#include <linux/kernel.h>
20#include <linux/init.h> 16#include <linux/init.h>
diff --git a/arch/arm/mach-shmobile/headsmp-scu.S b/arch/arm/mach-shmobile/headsmp-scu.S
index f45dde701d7b..69df8bfac167 100644
--- a/arch/arm/mach-shmobile/headsmp-scu.S
+++ b/arch/arm/mach-shmobile/headsmp-scu.S
@@ -12,11 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
19 * MA 02111-1307 USA
20 */ 15 */
21 16
22#include <linux/linkage.h> 17#include <linux/linkage.h>
diff --git a/arch/arm/mach-shmobile/intc-sh7372.c b/arch/arm/mach-shmobile/intc-sh7372.c
index e2af00b1bd9d..1ccf49cb485f 100644
--- a/arch/arm/mach-shmobile/intc-sh7372.c
+++ b/arch/arm/mach-shmobile/intc-sh7372.c
@@ -11,10 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */ 14 */
19#include <linux/kernel.h> 15#include <linux/kernel.h>
20#include <linux/init.h> 16#include <linux/init.h>
diff --git a/arch/arm/mach-shmobile/intc-sh73a0.c b/arch/arm/mach-shmobile/intc-sh73a0.c
index 44457a94897b..9e3618028acc 100644
--- a/arch/arm/mach-shmobile/intc-sh73a0.c
+++ b/arch/arm/mach-shmobile/intc-sh73a0.c
@@ -11,10 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */ 14 */
19#include <linux/kernel.h> 15#include <linux/kernel.h>
20#include <linux/init.h> 16#include <linux/init.h>
diff --git a/arch/arm/mach-shmobile/r8a7740.h b/arch/arm/mach-shmobile/r8a7740.h
index f369b4b0863d..ca7805ad7ea3 100644
--- a/arch/arm/mach-shmobile/r8a7740.h
+++ b/arch/arm/mach-shmobile/r8a7740.h
@@ -10,10 +10,6 @@
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */ 13 */
18 14
19#ifndef __ASM_R8A7740_H__ 15#ifndef __ASM_R8A7740_H__
diff --git a/arch/arm/mach-shmobile/r8a7778.h b/arch/arm/mach-shmobile/r8a7778.h
index f4076a50e970..f64fedb1f2cc 100644
--- a/arch/arm/mach-shmobile/r8a7778.h
+++ b/arch/arm/mach-shmobile/r8a7778.h
@@ -11,10 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */ 14 */
19#ifndef __ASM_R8A7778_H__ 15#ifndef __ASM_R8A7778_H__
20#define __ASM_R8A7778_H__ 16#define __ASM_R8A7778_H__
@@ -71,7 +67,6 @@ extern void r8a7778_add_standard_devices_dt(void);
71extern void r8a7778_add_dt_devices(void); 67extern void r8a7778_add_dt_devices(void);
72 68
73extern void r8a7778_init_late(void); 69extern void r8a7778_init_late(void);
74extern void r8a7778_init_delay(void);
75extern void r8a7778_init_irq_dt(void); 70extern void r8a7778_init_irq_dt(void);
76extern void r8a7778_clock_init(void); 71extern void r8a7778_clock_init(void);
77extern void r8a7778_init_irq_extpin(int irlm); 72extern void r8a7778_init_irq_extpin(int irlm);
diff --git a/arch/arm/mach-shmobile/r8a7791.h b/arch/arm/mach-shmobile/r8a7791.h
index c1bf7abefa5a..6cf11eb69d10 100644
--- a/arch/arm/mach-shmobile/r8a7791.h
+++ b/arch/arm/mach-shmobile/r8a7791.h
@@ -1,9 +1,6 @@
1#ifndef __ASM_R8A7791_H__ 1#ifndef __ASM_R8A7791_H__
2#define __ASM_R8A7791_H__ 2#define __ASM_R8A7791_H__
3 3
4void r8a7791_add_standard_devices(void);
5void r8a7791_clock_init(void);
6void r8a7791_pinmux_init(void);
7void r8a7791_pm_init(void); 4void r8a7791_pm_init(void);
8extern struct smp_operations r8a7791_smp_ops; 5extern struct smp_operations r8a7791_smp_ops;
9 6
diff --git a/arch/arm/mach-shmobile/setup-emev2.c b/arch/arm/mach-shmobile/setup-emev2.c
index b06a9e8f59a5..aad97be9cbe1 100644
--- a/arch/arm/mach-shmobile/setup-emev2.c
+++ b/arch/arm/mach-shmobile/setup-emev2.c
@@ -11,10 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */ 14 */
19#include <linux/kernel.h> 15#include <linux/kernel.h>
20#include <linux/init.h> 16#include <linux/init.h>
diff --git a/arch/arm/mach-shmobile/setup-r7s72100.c b/arch/arm/mach-shmobile/setup-r7s72100.c
index 4122104359f9..171174777b6f 100644
--- a/arch/arm/mach-shmobile/setup-r7s72100.c
+++ b/arch/arm/mach-shmobile/setup-r7s72100.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20 16
21#include <linux/kernel.h> 17#include <linux/kernel.h>
diff --git a/arch/arm/mach-shmobile/setup-r8a73a4.c b/arch/arm/mach-shmobile/setup-r8a73a4.c
index 53f40b70680d..b88b88a40a3c 100644
--- a/arch/arm/mach-shmobile/setup-r8a73a4.c
+++ b/arch/arm/mach-shmobile/setup-r8a73a4.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20#include <linux/irq.h> 16#include <linux/irq.h>
21#include <linux/kernel.h> 17#include <linux/kernel.h>
diff --git a/arch/arm/mach-shmobile/setup-r8a7740.c b/arch/arm/mach-shmobile/setup-r8a7740.c
index c3712239fe29..79ad93dfdae4 100644
--- a/arch/arm/mach-shmobile/setup-r8a7740.c
+++ b/arch/arm/mach-shmobile/setup-r8a7740.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20#include <linux/delay.h> 16#include <linux/delay.h>
21#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
diff --git a/arch/arm/mach-shmobile/setup-r8a7778.c b/arch/arm/mach-shmobile/setup-r8a7778.c
index 85fe016d6a87..45bd3588fa15 100644
--- a/arch/arm/mach-shmobile/setup-r8a7778.c
+++ b/arch/arm/mach-shmobile/setup-r8a7778.c
@@ -13,10 +13,6 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 16 */
21 17
22#include <linux/kernel.h> 18#include <linux/kernel.h>
@@ -572,11 +568,6 @@ void __init r8a7778_init_irq_extpin(int irlm)
572 &irqpin_platform_data, sizeof(irqpin_platform_data)); 568 &irqpin_platform_data, sizeof(irqpin_platform_data));
573} 569}
574 570
575void __init r8a7778_init_delay(void)
576{
577 shmobile_init_delay();
578}
579
580#ifdef CONFIG_USE_OF 571#ifdef CONFIG_USE_OF
581#define INT2SMSKCR0 0x82288 /* 0xfe782288 */ 572#define INT2SMSKCR0 0x82288 /* 0xfe782288 */
582#define INT2SMSKCR1 0x8228c /* 0xfe78228c */ 573#define INT2SMSKCR1 0x8228c /* 0xfe78228c */
@@ -608,7 +599,7 @@ static const char *r8a7778_compat_dt[] __initdata = {
608}; 599};
609 600
610DT_MACHINE_START(R8A7778_DT, "Generic R8A7778 (Flattened Device Tree)") 601DT_MACHINE_START(R8A7778_DT, "Generic R8A7778 (Flattened Device Tree)")
611 .init_early = r8a7778_init_delay, 602 .init_early = shmobile_init_delay,
612 .init_irq = r8a7778_init_irq_dt, 603 .init_irq = r8a7778_init_irq_dt,
613 .init_late = shmobile_init_late, 604 .init_late = shmobile_init_late,
614 .dt_compat = r8a7778_compat_dt, 605 .dt_compat = r8a7778_compat_dt,
diff --git a/arch/arm/mach-shmobile/setup-r8a7779.c b/arch/arm/mach-shmobile/setup-r8a7779.c
index 434d1504066a..6156d172cf31 100644
--- a/arch/arm/mach-shmobile/setup-r8a7779.c
+++ b/arch/arm/mach-shmobile/setup-r8a7779.c
@@ -13,10 +13,6 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 16 */
21#include <linux/kernel.h> 17#include <linux/kernel.h>
22#include <linux/init.h> 18#include <linux/init.h>
@@ -52,14 +48,14 @@
52#include "r8a7779.h" 48#include "r8a7779.h"
53 49
54static struct map_desc r8a7779_io_desc[] __initdata = { 50static struct map_desc r8a7779_io_desc[] __initdata = {
55 /* 2M entity map for 0xf0000000 (MPCORE) */ 51 /* 2M identity mapping for 0xf0000000 (MPCORE) */
56 { 52 {
57 .virtual = 0xf0000000, 53 .virtual = 0xf0000000,
58 .pfn = __phys_to_pfn(0xf0000000), 54 .pfn = __phys_to_pfn(0xf0000000),
59 .length = SZ_2M, 55 .length = SZ_2M,
60 .type = MT_DEVICE_NONSHARED 56 .type = MT_DEVICE_NONSHARED
61 }, 57 },
62 /* 16M entity map for 0xfexxxxxx (DMAC-S/HPBREG/INTC2/LRAM/DBSC) */ 58 /* 16M identity mapping for 0xfexxxxxx (DMAC-S/HPBREG/INTC2/LRAM/DBSC) */
63 { 59 {
64 .virtual = 0xfe000000, 60 .virtual = 0xfe000000,
65 .pfn = __phys_to_pfn(0xfe000000), 61 .pfn = __phys_to_pfn(0xfe000000),
@@ -684,7 +680,7 @@ void __init r8a7779_add_early_devices(void)
684 680
685 /* Early serial console setup is not included here due to 681 /* Early serial console setup is not included here due to
686 * memory map collisions. The SCIF serial ports in r8a7779 682 * memory map collisions. The SCIF serial ports in r8a7779
687 * are difficult to entity map 1:1 due to collision with the 683 * are difficult to identity map 1:1 due to collision with the
688 * virtual memory range used by the coherent DMA code on ARM. 684 * virtual memory range used by the coherent DMA code on ARM.
689 * 685 *
690 * Anyone wanting to debug early can remove UPF_IOREMAP from 686 * Anyone wanting to debug early can remove UPF_IOREMAP from
diff --git a/arch/arm/mach-shmobile/setup-r8a7790.c b/arch/arm/mach-shmobile/setup-r8a7790.c
index 877fdeb985d0..ec7d97dca4de 100644
--- a/arch/arm/mach-shmobile/setup-r8a7790.c
+++ b/arch/arm/mach-shmobile/setup-r8a7790.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20 16
21#include <linux/irq.h> 17#include <linux/irq.h>
diff --git a/arch/arm/mach-shmobile/setup-r8a7791.c b/arch/arm/mach-shmobile/setup-r8a7791.c
index 35d78639244f..ef8eb3af586d 100644
--- a/arch/arm/mach-shmobile/setup-r8a7791.c
+++ b/arch/arm/mach-shmobile/setup-r8a7791.c
@@ -13,198 +13,16 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 16 */
21 17
22#include <linux/irq.h> 18#include <linux/init.h>
23#include <linux/kernel.h>
24#include <linux/of_platform.h>
25#include <linux/platform_data/gpio-rcar.h>
26#include <linux/platform_data/irq-renesas-irqc.h>
27#include <linux/serial_sci.h>
28#include <linux/sh_timer.h>
29 19
30#include <asm/mach/arch.h> 20#include <asm/mach/arch.h>
31 21
32#include "common.h" 22#include "common.h"
33#include "irqs.h"
34#include "r8a7791.h" 23#include "r8a7791.h"
35#include "rcar-gen2.h" 24#include "rcar-gen2.h"
36 25
37static const struct resource pfc_resources[] __initconst = {
38 DEFINE_RES_MEM(0xe6060000, 0x250),
39};
40
41#define r8a7791_register_pfc() \
42 platform_device_register_simple("pfc-r8a7791", -1, pfc_resources, \
43 ARRAY_SIZE(pfc_resources))
44
45#define R8A7791_GPIO(idx, base, nr) \
46static const struct resource r8a7791_gpio##idx##_resources[] __initconst = { \
47 DEFINE_RES_MEM((base), 0x50), \
48 DEFINE_RES_IRQ(gic_spi(4 + (idx))), \
49}; \
50 \
51static const struct gpio_rcar_config \
52r8a7791_gpio##idx##_platform_data __initconst = { \
53 .gpio_base = 32 * (idx), \
54 .irq_base = 0, \
55 .number_of_pins = (nr), \
56 .pctl_name = "pfc-r8a7791", \
57 .has_both_edge_trigger = 1, \
58}; \
59
60R8A7791_GPIO(0, 0xe6050000, 32);
61R8A7791_GPIO(1, 0xe6051000, 32);
62R8A7791_GPIO(2, 0xe6052000, 32);
63R8A7791_GPIO(3, 0xe6053000, 32);
64R8A7791_GPIO(4, 0xe6054000, 32);
65R8A7791_GPIO(5, 0xe6055000, 32);
66R8A7791_GPIO(6, 0xe6055400, 32);
67R8A7791_GPIO(7, 0xe6055800, 26);
68
69#define r8a7791_register_gpio(idx) \
70 platform_device_register_resndata(NULL, "gpio_rcar", idx, \
71 r8a7791_gpio##idx##_resources, \
72 ARRAY_SIZE(r8a7791_gpio##idx##_resources), \
73 &r8a7791_gpio##idx##_platform_data, \
74 sizeof(r8a7791_gpio##idx##_platform_data))
75
76void __init r8a7791_pinmux_init(void)
77{
78 r8a7791_register_pfc();
79 r8a7791_register_gpio(0);
80 r8a7791_register_gpio(1);
81 r8a7791_register_gpio(2);
82 r8a7791_register_gpio(3);
83 r8a7791_register_gpio(4);
84 r8a7791_register_gpio(5);
85 r8a7791_register_gpio(6);
86 r8a7791_register_gpio(7);
87}
88
89#define __R8A7791_SCIF(scif_type, index, baseaddr, irq) \
90static struct plat_sci_port scif##index##_platform_data = { \
91 .type = scif_type, \
92 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP, \
93 .scscr = SCSCR_RE | SCSCR_TE, \
94}; \
95 \
96static struct resource scif##index##_resources[] = { \
97 DEFINE_RES_MEM(baseaddr, 0x100), \
98 DEFINE_RES_IRQ(irq), \
99}
100
101#define R8A7791_SCIF(index, baseaddr, irq) \
102 __R8A7791_SCIF(PORT_SCIF, index, baseaddr, irq)
103
104#define R8A7791_SCIFA(index, baseaddr, irq) \
105 __R8A7791_SCIF(PORT_SCIFA, index, baseaddr, irq)
106
107#define R8A7791_SCIFB(index, baseaddr, irq) \
108 __R8A7791_SCIF(PORT_SCIFB, index, baseaddr, irq)
109
110R8A7791_SCIFA(0, 0xe6c40000, gic_spi(144)); /* SCIFA0 */
111R8A7791_SCIFA(1, 0xe6c50000, gic_spi(145)); /* SCIFA1 */
112R8A7791_SCIFB(2, 0xe6c20000, gic_spi(148)); /* SCIFB0 */
113R8A7791_SCIFB(3, 0xe6c30000, gic_spi(149)); /* SCIFB1 */
114R8A7791_SCIFB(4, 0xe6ce0000, gic_spi(150)); /* SCIFB2 */
115R8A7791_SCIFA(5, 0xe6c60000, gic_spi(151)); /* SCIFA2 */
116R8A7791_SCIF(6, 0xe6e60000, gic_spi(152)); /* SCIF0 */
117R8A7791_SCIF(7, 0xe6e68000, gic_spi(153)); /* SCIF1 */
118R8A7791_SCIF(8, 0xe6e58000, gic_spi(22)); /* SCIF2 */
119R8A7791_SCIF(9, 0xe6ea8000, gic_spi(23)); /* SCIF3 */
120R8A7791_SCIF(10, 0xe6ee0000, gic_spi(24)); /* SCIF4 */
121R8A7791_SCIF(11, 0xe6ee8000, gic_spi(25)); /* SCIF5 */
122R8A7791_SCIFA(12, 0xe6c70000, gic_spi(29)); /* SCIFA3 */
123R8A7791_SCIFA(13, 0xe6c78000, gic_spi(30)); /* SCIFA4 */
124R8A7791_SCIFA(14, 0xe6c80000, gic_spi(31)); /* SCIFA5 */
125
126#define r8a7791_register_scif(index) \
127 platform_device_register_resndata(NULL, "sh-sci", index, \
128 scif##index##_resources, \
129 ARRAY_SIZE(scif##index##_resources), \
130 &scif##index##_platform_data, \
131 sizeof(scif##index##_platform_data))
132
133static struct sh_timer_config cmt0_platform_data = {
134 .channels_mask = 0x60,
135};
136
137static struct resource cmt0_resources[] = {
138 DEFINE_RES_MEM(0xffca0000, 0x1004),
139 DEFINE_RES_IRQ(gic_spi(142)),
140};
141
142#define r8a7791_register_cmt(idx) \
143 platform_device_register_resndata(NULL, "sh-cmt-48-gen2", \
144 idx, cmt##idx##_resources, \
145 ARRAY_SIZE(cmt##idx##_resources), \
146 &cmt##idx##_platform_data, \
147 sizeof(struct sh_timer_config))
148
149static struct renesas_irqc_config irqc0_data = {
150 .irq_base = irq_pin(0), /* IRQ0 -> IRQ9 */
151};
152
153static struct resource irqc0_resources[] = {
154 DEFINE_RES_MEM(0xe61c0000, 0x200), /* IRQC Event Detector Block_0 */
155 DEFINE_RES_IRQ(gic_spi(0)), /* IRQ0 */
156 DEFINE_RES_IRQ(gic_spi(1)), /* IRQ1 */
157 DEFINE_RES_IRQ(gic_spi(2)), /* IRQ2 */
158 DEFINE_RES_IRQ(gic_spi(3)), /* IRQ3 */
159 DEFINE_RES_IRQ(gic_spi(12)), /* IRQ4 */
160 DEFINE_RES_IRQ(gic_spi(13)), /* IRQ5 */
161 DEFINE_RES_IRQ(gic_spi(14)), /* IRQ6 */
162 DEFINE_RES_IRQ(gic_spi(15)), /* IRQ7 */
163 DEFINE_RES_IRQ(gic_spi(16)), /* IRQ8 */
164 DEFINE_RES_IRQ(gic_spi(17)), /* IRQ9 */
165};
166
167#define r8a7791_register_irqc(idx) \
168 platform_device_register_resndata(NULL, "renesas_irqc", \
169 idx, irqc##idx##_resources, \
170 ARRAY_SIZE(irqc##idx##_resources), \
171 &irqc##idx##_data, \
172 sizeof(struct renesas_irqc_config))
173
174static const struct resource thermal_resources[] __initconst = {
175 DEFINE_RES_MEM(0xe61f0000, 0x14),
176 DEFINE_RES_MEM(0xe61f0100, 0x38),
177 DEFINE_RES_IRQ(gic_spi(69)),
178};
179
180#define r8a7791_register_thermal() \
181 platform_device_register_simple("rcar_thermal", -1, \
182 thermal_resources, \
183 ARRAY_SIZE(thermal_resources))
184
185void __init r8a7791_add_standard_devices(void)
186{
187 r8a7791_register_scif(0);
188 r8a7791_register_scif(1);
189 r8a7791_register_scif(2);
190 r8a7791_register_scif(3);
191 r8a7791_register_scif(4);
192 r8a7791_register_scif(5);
193 r8a7791_register_scif(6);
194 r8a7791_register_scif(7);
195 r8a7791_register_scif(8);
196 r8a7791_register_scif(9);
197 r8a7791_register_scif(10);
198 r8a7791_register_scif(11);
199 r8a7791_register_scif(12);
200 r8a7791_register_scif(13);
201 r8a7791_register_scif(14);
202 r8a7791_register_cmt(0);
203 r8a7791_register_irqc(0);
204 r8a7791_register_thermal();
205}
206
207#ifdef CONFIG_USE_OF
208static const char *r8a7791_boards_compat_dt[] __initdata = { 26static const char *r8a7791_boards_compat_dt[] __initdata = {
209 "renesas,r8a7791", 27 "renesas,r8a7791",
210 NULL, 28 NULL,
@@ -218,4 +36,3 @@ DT_MACHINE_START(R8A7791_DT, "Generic R8A7791 (Flattened Device Tree)")
218 .reserve = rcar_gen2_reserve, 36 .reserve = rcar_gen2_reserve,
219 .dt_compat = r8a7791_boards_compat_dt, 37 .dt_compat = r8a7791_boards_compat_dt,
220MACHINE_END 38MACHINE_END
221#endif /* CONFIG_USE_OF */
diff --git a/arch/arm/mach-shmobile/setup-rcar-gen2.c b/arch/arm/mach-shmobile/setup-rcar-gen2.c
index 7ed92790d13f..3dd6edd9bd1d 100644
--- a/arch/arm/mach-shmobile/setup-rcar-gen2.c
+++ b/arch/arm/mach-shmobile/setup-rcar-gen2.c
@@ -13,10 +13,6 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 16 */
21 17
22#include <linux/clk/shmobile.h> 18#include <linux/clk/shmobile.h>
diff --git a/arch/arm/mach-shmobile/setup-sh7372.c b/arch/arm/mach-shmobile/setup-sh7372.c
index 322e2dc3fa36..458a2cfad417 100644
--- a/arch/arm/mach-shmobile/setup-sh7372.c
+++ b/arch/arm/mach-shmobile/setup-sh7372.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20#include <linux/kernel.h> 16#include <linux/kernel.h>
21#include <linux/init.h> 17#include <linux/init.h>
@@ -47,7 +43,7 @@
47#include "sh7372.h" 43#include "sh7372.h"
48 44
49static struct map_desc sh7372_io_desc[] __initdata = { 45static struct map_desc sh7372_io_desc[] __initdata = {
50 /* create a 1:1 entity map for 0xe6xxxxxx 46 /* create a 1:1 identity mapping for 0xe6xxxxxx
51 * used by CPGA, INTC and PFC. 47 * used by CPGA, INTC and PFC.
52 */ 48 */
53 { 49 {
diff --git a/arch/arm/mach-shmobile/setup-sh73a0.c b/arch/arm/mach-shmobile/setup-sh73a0.c
index fa7cab820ab9..93ebe3430bfe 100644
--- a/arch/arm/mach-shmobile/setup-sh73a0.c
+++ b/arch/arm/mach-shmobile/setup-sh73a0.c
@@ -13,10 +13,6 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 16 */
21#include <linux/kernel.h> 17#include <linux/kernel.h>
22#include <linux/init.h> 18#include <linux/init.h>
@@ -26,6 +22,7 @@
26#include <linux/of_platform.h> 22#include <linux/of_platform.h>
27#include <linux/delay.h> 23#include <linux/delay.h>
28#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/i2c/i2c-sh_mobile.h>
29#include <linux/io.h> 26#include <linux/io.h>
30#include <linux/serial_sci.h> 27#include <linux/serial_sci.h>
31#include <linux/sh_dma.h> 28#include <linux/sh_dma.h>
@@ -45,7 +42,7 @@
45#include "sh73a0.h" 42#include "sh73a0.h"
46 43
47static struct map_desc sh73a0_io_desc[] __initdata = { 44static struct map_desc sh73a0_io_desc[] __initdata = {
48 /* create a 1:1 entity map for 0xe6xxxxxx 45 /* create a 1:1 identity mapping for 0xe6xxxxxx
49 * used by CPGA, INTC and PFC. 46 * used by CPGA, INTC and PFC.
50 */ 47 */
51 { 48 {
@@ -193,11 +190,18 @@ static struct resource i2c4_resources[] = {
193 }, 190 },
194}; 191};
195 192
193static struct i2c_sh_mobile_platform_data i2c_platform_data = {
194 .clks_per_count = 2,
195};
196
196static struct platform_device i2c0_device = { 197static struct platform_device i2c0_device = {
197 .name = "i2c-sh_mobile", 198 .name = "i2c-sh_mobile",
198 .id = 0, 199 .id = 0,
199 .resource = i2c0_resources, 200 .resource = i2c0_resources,
200 .num_resources = ARRAY_SIZE(i2c0_resources), 201 .num_resources = ARRAY_SIZE(i2c0_resources),
202 .dev = {
203 .platform_data = &i2c_platform_data,
204 },
201}; 205};
202 206
203static struct platform_device i2c1_device = { 207static struct platform_device i2c1_device = {
@@ -205,6 +209,9 @@ static struct platform_device i2c1_device = {
205 .id = 1, 209 .id = 1,
206 .resource = i2c1_resources, 210 .resource = i2c1_resources,
207 .num_resources = ARRAY_SIZE(i2c1_resources), 211 .num_resources = ARRAY_SIZE(i2c1_resources),
212 .dev = {
213 .platform_data = &i2c_platform_data,
214 },
208}; 215};
209 216
210static struct platform_device i2c2_device = { 217static struct platform_device i2c2_device = {
@@ -212,6 +219,9 @@ static struct platform_device i2c2_device = {
212 .id = 2, 219 .id = 2,
213 .resource = i2c2_resources, 220 .resource = i2c2_resources,
214 .num_resources = ARRAY_SIZE(i2c2_resources), 221 .num_resources = ARRAY_SIZE(i2c2_resources),
222 .dev = {
223 .platform_data = &i2c_platform_data,
224 },
215}; 225};
216 226
217static struct platform_device i2c3_device = { 227static struct platform_device i2c3_device = {
@@ -219,6 +229,9 @@ static struct platform_device i2c3_device = {
219 .id = 3, 229 .id = 3,
220 .resource = i2c3_resources, 230 .resource = i2c3_resources,
221 .num_resources = ARRAY_SIZE(i2c3_resources), 231 .num_resources = ARRAY_SIZE(i2c3_resources),
232 .dev = {
233 .platform_data = &i2c_platform_data,
234 },
222}; 235};
223 236
224static struct platform_device i2c4_device = { 237static struct platform_device i2c4_device = {
@@ -226,6 +239,9 @@ static struct platform_device i2c4_device = {
226 .id = 4, 239 .id = 4,
227 .resource = i2c4_resources, 240 .resource = i2c4_resources,
228 .num_resources = ARRAY_SIZE(i2c4_resources), 241 .num_resources = ARRAY_SIZE(i2c4_resources),
242 .dev = {
243 .platform_data = &i2c_platform_data,
244 },
229}; 245};
230 246
231static const struct sh_dmae_slave_config sh73a0_dmae_slaves[] = { 247static const struct sh_dmae_slave_config sh73a0_dmae_slaves[] = {
@@ -741,17 +757,12 @@ void __init sh73a0_add_standard_devices(void)
741 ARRAY_SIZE(sh73a0_late_devices)); 757 ARRAY_SIZE(sh73a0_late_devices));
742} 758}
743 759
744void __init sh73a0_init_delay(void)
745{
746 shmobile_init_delay();
747}
748
749/* do nothing for !CONFIG_SMP or !CONFIG_HAVE_TWD */ 760/* do nothing for !CONFIG_SMP or !CONFIG_HAVE_TWD */
750void __init __weak sh73a0_register_twd(void) { } 761void __init __weak sh73a0_register_twd(void) { }
751 762
752void __init sh73a0_earlytimer_init(void) 763void __init sh73a0_earlytimer_init(void)
753{ 764{
754 sh73a0_init_delay(); 765 shmobile_init_delay();
755 sh73a0_clock_init(); 766 sh73a0_clock_init();
756 shmobile_earlytimer_init(); 767 shmobile_earlytimer_init();
757 sh73a0_register_twd(); 768 sh73a0_register_twd();
@@ -791,7 +802,7 @@ static const char *sh73a0_boards_compat_dt[] __initdata = {
791DT_MACHINE_START(SH73A0_DT, "Generic SH73A0 (Flattened Device Tree)") 802DT_MACHINE_START(SH73A0_DT, "Generic SH73A0 (Flattened Device Tree)")
792 .smp = smp_ops(sh73a0_smp_ops), 803 .smp = smp_ops(sh73a0_smp_ops),
793 .map_io = sh73a0_map_io, 804 .map_io = sh73a0_map_io,
794 .init_early = sh73a0_init_delay, 805 .init_early = shmobile_init_delay,
795 .init_machine = sh73a0_add_standard_devices_dt, 806 .init_machine = sh73a0_add_standard_devices_dt,
796 .init_late = shmobile_init_late, 807 .init_late = shmobile_init_late,
797 .restart = sh73a0_restart, 808 .restart = sh73a0_restart,
diff --git a/arch/arm/mach-shmobile/sh73a0.h b/arch/arm/mach-shmobile/sh73a0.h
index 359b582dc270..f037c64b14fc 100644
--- a/arch/arm/mach-shmobile/sh73a0.h
+++ b/arch/arm/mach-shmobile/sh73a0.h
@@ -71,7 +71,6 @@ enum {
71#define SH73A0_PINT0_IRQ(irq) ((irq) + 700) 71#define SH73A0_PINT0_IRQ(irq) ((irq) + 700)
72#define SH73A0_PINT1_IRQ(irq) ((irq) + 732) 72#define SH73A0_PINT1_IRQ(irq) ((irq) + 732)
73 73
74extern void sh73a0_init_delay(void);
75extern void sh73a0_init_irq(void); 74extern void sh73a0_init_irq(void);
76extern void sh73a0_init_irq_dt(void); 75extern void sh73a0_init_irq_dt(void);
77extern void sh73a0_map_io(void); 76extern void sh73a0_map_io(void);
diff --git a/arch/arm/mach-shmobile/sleep-sh7372.S b/arch/arm/mach-shmobile/sleep-sh7372.S
index 9782862899e8..146b8de16432 100644
--- a/arch/arm/mach-shmobile/sleep-sh7372.S
+++ b/arch/arm/mach-shmobile/sleep-sh7372.S
@@ -22,11 +22,6 @@
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
24 * GNU General Public License for more details. 24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
30 */ 25 */
31 26
32#include <linux/linkage.h> 27#include <linux/linkage.h>
diff --git a/arch/arm/mach-shmobile/smp-emev2.c b/arch/arm/mach-shmobile/smp-emev2.c
index 6ff1df1df9a7..baff3b5efed8 100644
--- a/arch/arm/mach-shmobile/smp-emev2.c
+++ b/arch/arm/mach-shmobile/smp-emev2.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20#include <linux/kernel.h> 16#include <linux/kernel.h>
21#include <linux/init.h> 17#include <linux/init.h>
diff --git a/arch/arm/mach-shmobile/smp-r8a7779.c b/arch/arm/mach-shmobile/smp-r8a7779.c
index 3100e355c3fd..3f761f839043 100644
--- a/arch/arm/mach-shmobile/smp-r8a7779.c
+++ b/arch/arm/mach-shmobile/smp-r8a7779.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20#include <linux/kernel.h> 16#include <linux/kernel.h>
21#include <linux/init.h> 17#include <linux/init.h>
diff --git a/arch/arm/mach-shmobile/smp-sh73a0.c b/arch/arm/mach-shmobile/smp-sh73a0.c
index 22d8f87b23e9..c16dbfe9836c 100644
--- a/arch/arm/mach-shmobile/smp-sh73a0.c
+++ b/arch/arm/mach-shmobile/smp-sh73a0.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 15 */
20#include <linux/kernel.h> 16#include <linux/kernel.h>
21#include <linux/init.h> 17#include <linux/init.h>
diff --git a/arch/arm/mach-shmobile/timer.c b/arch/arm/mach-shmobile/timer.c
index 32ee335d2632..f1d027aa7a81 100644
--- a/arch/arm/mach-shmobile/timer.c
+++ b/arch/arm/mach-shmobile/timer.c
@@ -12,11 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */ 15 */
21#include <linux/platform_device.h> 16#include <linux/platform_device.h>
22#include <linux/clocksource.h> 17#include <linux/clocksource.h>
diff --git a/arch/arm/mach-tegra/irq.c b/arch/arm/mach-tegra/irq.c
index da7be13aecce..ab95f5391a2b 100644
--- a/arch/arm/mach-tegra/irq.c
+++ b/arch/arm/mach-tegra/irq.c
@@ -99,42 +99,42 @@ static inline void tegra_irq_write_mask(unsigned int irq, unsigned long reg)
99 99
100static void tegra_mask(struct irq_data *d) 100static void tegra_mask(struct irq_data *d)
101{ 101{
102 if (d->irq < FIRST_LEGACY_IRQ) 102 if (d->hwirq < FIRST_LEGACY_IRQ)
103 return; 103 return;
104 104
105 tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_CLR); 105 tegra_irq_write_mask(d->hwirq, ICTLR_CPU_IER_CLR);
106} 106}
107 107
108static void tegra_unmask(struct irq_data *d) 108static void tegra_unmask(struct irq_data *d)
109{ 109{
110 if (d->irq < FIRST_LEGACY_IRQ) 110 if (d->hwirq < FIRST_LEGACY_IRQ)
111 return; 111 return;
112 112
113 tegra_irq_write_mask(d->irq, ICTLR_CPU_IER_SET); 113 tegra_irq_write_mask(d->hwirq, ICTLR_CPU_IER_SET);
114} 114}
115 115
116static void tegra_ack(struct irq_data *d) 116static void tegra_ack(struct irq_data *d)
117{ 117{
118 if (d->irq < FIRST_LEGACY_IRQ) 118 if (d->hwirq < FIRST_LEGACY_IRQ)
119 return; 119 return;
120 120
121 tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR); 121 tegra_irq_write_mask(d->hwirq, ICTLR_CPU_IEP_FIR_CLR);
122} 122}
123 123
124static void tegra_eoi(struct irq_data *d) 124static void tegra_eoi(struct irq_data *d)
125{ 125{
126 if (d->irq < FIRST_LEGACY_IRQ) 126 if (d->hwirq < FIRST_LEGACY_IRQ)
127 return; 127 return;
128 128
129 tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_CLR); 129 tegra_irq_write_mask(d->hwirq, ICTLR_CPU_IEP_FIR_CLR);
130} 130}
131 131
132static int tegra_retrigger(struct irq_data *d) 132static int tegra_retrigger(struct irq_data *d)
133{ 133{
134 if (d->irq < FIRST_LEGACY_IRQ) 134 if (d->hwirq < FIRST_LEGACY_IRQ)
135 return 0; 135 return 0;
136 136
137 tegra_irq_write_mask(d->irq, ICTLR_CPU_IEP_FIR_SET); 137 tegra_irq_write_mask(d->hwirq, ICTLR_CPU_IEP_FIR_SET);
138 138
139 return 1; 139 return 1;
140} 140}
@@ -142,7 +142,7 @@ static int tegra_retrigger(struct irq_data *d)
142#ifdef CONFIG_PM_SLEEP 142#ifdef CONFIG_PM_SLEEP
143static int tegra_set_wake(struct irq_data *d, unsigned int enable) 143static int tegra_set_wake(struct irq_data *d, unsigned int enable)
144{ 144{
145 u32 irq = d->irq; 145 u32 irq = d->hwirq;
146 u32 index, mask; 146 u32 index, mask;
147 147
148 if (irq < FIRST_LEGACY_IRQ || 148 if (irq < FIRST_LEGACY_IRQ ||
diff --git a/arch/arm/mach-tegra/reset-handler.S b/arch/arm/mach-tegra/reset-handler.S
index 7b2baab0f0bd..71be4af5e975 100644
--- a/arch/arm/mach-tegra/reset-handler.S
+++ b/arch/arm/mach-tegra/reset-handler.S
@@ -51,6 +51,7 @@ ENTRY(tegra_resume)
51 THUMB( it ne ) 51 THUMB( it ne )
52 bne cpu_resume @ no 52 bne cpu_resume @ no
53 53
54 tegra_get_soc_id TEGRA_APB_MISC_BASE, r6
54 /* Are we on Tegra20? */ 55 /* Are we on Tegra20? */
55 cmp r6, #TEGRA20 56 cmp r6, #TEGRA20
56 beq 1f @ Yes 57 beq 1f @ Yes
diff --git a/arch/arm/mach-vexpress/Kconfig b/arch/arm/mach-vexpress/Kconfig
index b2cfba16c4e8..d6b16d9a7838 100644
--- a/arch/arm/mach-vexpress/Kconfig
+++ b/arch/arm/mach-vexpress/Kconfig
@@ -16,6 +16,7 @@ menuconfig ARCH_VEXPRESS
16 select POWER_RESET 16 select POWER_RESET
17 select POWER_RESET_VEXPRESS 17 select POWER_RESET_VEXPRESS
18 select POWER_SUPPLY 18 select POWER_SUPPLY
19 select REGULATOR if MMC_ARMMMCI
19 select REGULATOR_FIXED_VOLTAGE if REGULATOR 20 select REGULATOR_FIXED_VOLTAGE if REGULATOR
20 select VEXPRESS_CONFIG 21 select VEXPRESS_CONFIG
21 select VEXPRESS_SYSCFG 22 select VEXPRESS_SYSCFG
@@ -49,9 +50,6 @@ config ARCH_VEXPRESS_CORTEX_A5_A9_ERRATA
49 build a working kernel, you must also enable relevant core 50 build a working kernel, you must also enable relevant core
50 tile support or Flattened Device Tree based support options. 51 tile support or Flattened Device Tree based support options.
51 52
52config ARCH_VEXPRESS_CA9X4
53 bool "Versatile Express Cortex-A9x4 tile"
54
55config ARCH_VEXPRESS_DCSCB 53config ARCH_VEXPRESS_DCSCB
56 bool "Dual Cluster System Control Block (DCSCB) support" 54 bool "Dual Cluster System Control Block (DCSCB) support"
57 depends on MCPM 55 depends on MCPM
diff --git a/arch/arm/mach-vexpress/Makefile b/arch/arm/mach-vexpress/Makefile
index fc649bc09d0c..f5c1006dd6a1 100644
--- a/arch/arm/mach-vexpress/Makefile
+++ b/arch/arm/mach-vexpress/Makefile
@@ -1,11 +1,10 @@
1# 1#
2# Makefile for the linux kernel. 2# Makefile for the linux kernel.
3# 3#
4ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := -I$(srctree)/$(src)/include \ 4ccflags-$(CONFIG_ARCH_MULTIPLATFORM) := \
5 -I$(srctree)/arch/arm/plat-versatile/include 5 -I$(srctree)/arch/arm/plat-versatile/include
6 6
7obj-y := v2m.o 7obj-y := v2m.o
8obj-$(CONFIG_ARCH_VEXPRESS_CA9X4) += ct-ca9x4.o
9obj-$(CONFIG_ARCH_VEXPRESS_DCSCB) += dcscb.o dcscb_setup.o 8obj-$(CONFIG_ARCH_VEXPRESS_DCSCB) += dcscb.o dcscb_setup.o
10CFLAGS_dcscb.o += -march=armv7-a 9CFLAGS_dcscb.o += -march=armv7-a
11CFLAGS_REMOVE_dcscb.o = -pg 10CFLAGS_REMOVE_dcscb.o = -pg
diff --git a/arch/arm/mach-vexpress/core.h b/arch/arm/mach-vexpress/core.h
index 152fad91b3ae..2a11d3ac8c68 100644
--- a/arch/arm/mach-vexpress/core.h
+++ b/arch/arm/mach-vexpress/core.h
@@ -1,12 +1,5 @@
1/* 2MB large area for motherboard's peripherals static mapping */
2#define V2M_PERIPH 0xf8000000
3
4/* Tile's peripherals static mappings should start here */
5#define V2T_PERIPH 0xf8200000
6
7bool vexpress_smp_init_ops(void); 1bool vexpress_smp_init_ops(void);
8 2
9extern struct smp_operations vexpress_smp_ops;
10extern struct smp_operations vexpress_smp_dt_ops; 3extern struct smp_operations vexpress_smp_dt_ops;
11 4
12extern void vexpress_cpu_die(unsigned int cpu); 5extern void vexpress_cpu_die(unsigned int cpu);
diff --git a/arch/arm/mach-vexpress/ct-ca9x4.c b/arch/arm/mach-vexpress/ct-ca9x4.c
deleted file mode 100644
index 27bea049380a..000000000000
--- a/arch/arm/mach-vexpress/ct-ca9x4.c
+++ /dev/null
@@ -1,212 +0,0 @@
1/*
2 * Versatile Express Core Tile Cortex A9x4 Support
3 */
4#include <linux/init.h>
5#include <linux/gfp.h>
6#include <linux/device.h>
7#include <linux/dma-mapping.h>
8#include <linux/platform_device.h>
9#include <linux/amba/bus.h>
10#include <linux/amba/clcd.h>
11#include <linux/platform_data/video-clcd-versatile.h>
12#include <linux/clkdev.h>
13#include <linux/vexpress.h>
14#include <linux/irqchip/arm-gic.h>
15
16#include <asm/hardware/arm_timer.h>
17#include <asm/hardware/cache-l2x0.h>
18#include <asm/smp_scu.h>
19#include <asm/smp_twd.h>
20
21#include <mach/ct-ca9x4.h>
22
23#include <asm/hardware/timer-sp.h>
24
25#include <asm/mach/map.h>
26#include <asm/mach/time.h>
27
28#include "core.h"
29
30#include <mach/motherboard.h>
31#include <mach/irqs.h>
32
33static struct map_desc ct_ca9x4_io_desc[] __initdata = {
34 {
35 .virtual = V2T_PERIPH,
36 .pfn = __phys_to_pfn(CT_CA9X4_MPIC),
37 .length = SZ_8K,
38 .type = MT_DEVICE,
39 },
40};
41
42static void __init ct_ca9x4_map_io(void)
43{
44 iotable_init(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc));
45}
46
47static void __init ca9x4_l2_init(void)
48{
49#ifdef CONFIG_CACHE_L2X0
50 void __iomem *l2x0_base = ioremap(CT_CA9X4_L2CC, SZ_4K);
51
52 if (l2x0_base) {
53 /* set RAM latencies to 1 cycle for this core tile. */
54 writel(0, l2x0_base + L310_TAG_LATENCY_CTRL);
55 writel(0, l2x0_base + L310_DATA_LATENCY_CTRL);
56
57 l2x0_init(l2x0_base, 0x00400000, 0xfe0fffff);
58 } else {
59 pr_err("L2C: unable to map L2 cache controller\n");
60 }
61#endif
62}
63
64#ifdef CONFIG_HAVE_ARM_TWD
65static DEFINE_TWD_LOCAL_TIMER(twd_local_timer, A9_MPCORE_TWD, IRQ_LOCALTIMER);
66
67static void __init ca9x4_twd_init(void)
68{
69 int err = twd_local_timer_register(&twd_local_timer);
70 if (err)
71 pr_err("twd_local_timer_register failed %d\n", err);
72}
73#else
74#define ca9x4_twd_init() do {} while(0)
75#endif
76
77static void __init ct_ca9x4_init_irq(void)
78{
79 gic_init(0, 29, ioremap(A9_MPCORE_GIC_DIST, SZ_4K),
80 ioremap(A9_MPCORE_GIC_CPU, SZ_256));
81 ca9x4_twd_init();
82 ca9x4_l2_init();
83}
84
85static int ct_ca9x4_clcd_setup(struct clcd_fb *fb)
86{
87 unsigned long framesize = 1024 * 768 * 2;
88
89 fb->panel = versatile_clcd_get_panel("XVGA");
90 if (!fb->panel)
91 return -EINVAL;
92
93 return versatile_clcd_setup_dma(fb, framesize);
94}
95
96static struct clcd_board ct_ca9x4_clcd_data = {
97 .name = "CT-CA9X4",
98 .caps = CLCD_CAP_5551 | CLCD_CAP_565,
99 .check = clcdfb_check,
100 .decode = clcdfb_decode,
101 .setup = ct_ca9x4_clcd_setup,
102 .mmap = versatile_clcd_mmap_dma,
103 .remove = versatile_clcd_remove_dma,
104};
105
106static AMBA_AHB_DEVICE(clcd, "ct:clcd", 0, CT_CA9X4_CLCDC, IRQ_CT_CA9X4_CLCDC, &ct_ca9x4_clcd_data);
107static AMBA_APB_DEVICE(dmc, "ct:dmc", 0, CT_CA9X4_DMC, IRQ_CT_CA9X4_DMC, NULL);
108static AMBA_APB_DEVICE(smc, "ct:smc", 0, CT_CA9X4_SMC, IRQ_CT_CA9X4_SMC, NULL);
109static AMBA_APB_DEVICE(gpio, "ct:gpio", 0, CT_CA9X4_GPIO, IRQ_CT_CA9X4_GPIO, NULL);
110
111static struct amba_device *ct_ca9x4_amba_devs[] __initdata = {
112 &clcd_device,
113 &dmc_device,
114 &smc_device,
115 &gpio_device,
116};
117
118static struct resource pmu_resources[] = {
119 [0] = {
120 .start = IRQ_CT_CA9X4_PMU_CPU0,
121 .end = IRQ_CT_CA9X4_PMU_CPU0,
122 .flags = IORESOURCE_IRQ,
123 },
124 [1] = {
125 .start = IRQ_CT_CA9X4_PMU_CPU1,
126 .end = IRQ_CT_CA9X4_PMU_CPU1,
127 .flags = IORESOURCE_IRQ,
128 },
129 [2] = {
130 .start = IRQ_CT_CA9X4_PMU_CPU2,
131 .end = IRQ_CT_CA9X4_PMU_CPU2,
132 .flags = IORESOURCE_IRQ,
133 },
134 [3] = {
135 .start = IRQ_CT_CA9X4_PMU_CPU3,
136 .end = IRQ_CT_CA9X4_PMU_CPU3,
137 .flags = IORESOURCE_IRQ,
138 },
139};
140
141static struct platform_device pmu_device = {
142 .name = "arm-pmu",
143 .id = -1,
144 .num_resources = ARRAY_SIZE(pmu_resources),
145 .resource = pmu_resources,
146};
147
148static struct clk_lookup osc1_lookup = {
149 .dev_id = "ct:clcd",
150};
151
152static struct platform_device osc1_device = {
153 .name = "vexpress-osc",
154 .id = 1,
155 .num_resources = 1,
156 .resource = (struct resource []) {
157 VEXPRESS_RES_FUNC(0xf, 1),
158 },
159 .dev.platform_data = &osc1_lookup,
160};
161
162static void __init ct_ca9x4_init(void)
163{
164 int i;
165
166 for (i = 0; i < ARRAY_SIZE(ct_ca9x4_amba_devs); i++)
167 amba_device_register(ct_ca9x4_amba_devs[i], &iomem_resource);
168
169 platform_device_register(&pmu_device);
170 vexpress_syscfg_device_register(&osc1_device);
171}
172
173#ifdef CONFIG_SMP
174static void *ct_ca9x4_scu_base __initdata;
175
176static void __init ct_ca9x4_init_cpu_map(void)
177{
178 int i, ncores;
179
180 ct_ca9x4_scu_base = ioremap(A9_MPCORE_SCU, SZ_128);
181 if (WARN_ON(!ct_ca9x4_scu_base))
182 return;
183
184 ncores = scu_get_core_count(ct_ca9x4_scu_base);
185
186 if (ncores > nr_cpu_ids) {
187 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
188 ncores, nr_cpu_ids);
189 ncores = nr_cpu_ids;
190 }
191
192 for (i = 0; i < ncores; ++i)
193 set_cpu_possible(i, true);
194}
195
196static void __init ct_ca9x4_smp_enable(unsigned int max_cpus)
197{
198 scu_enable(ct_ca9x4_scu_base);
199}
200#endif
201
202struct ct_desc ct_ca9x4_desc __initdata = {
203 .id = V2M_CT_ID_CA9,
204 .name = "CA9x4",
205 .map_io = ct_ca9x4_map_io,
206 .init_irq = ct_ca9x4_init_irq,
207 .init_tile = ct_ca9x4_init,
208#ifdef CONFIG_SMP
209 .init_cpu_map = ct_ca9x4_init_cpu_map,
210 .smp_enable = ct_ca9x4_smp_enable,
211#endif
212};
diff --git a/arch/arm/mach-vexpress/include/mach/ct-ca9x4.h b/arch/arm/mach-vexpress/include/mach/ct-ca9x4.h
deleted file mode 100644
index 84acf8439d4b..000000000000
--- a/arch/arm/mach-vexpress/include/mach/ct-ca9x4.h
+++ /dev/null
@@ -1,47 +0,0 @@
1#ifndef __MACH_CT_CA9X4_H
2#define __MACH_CT_CA9X4_H
3
4/*
5 * Physical base addresses
6 */
7#define CT_CA9X4_CLCDC (0x10020000)
8#define CT_CA9X4_AXIRAM (0x10060000)
9#define CT_CA9X4_DMC (0x100e0000)
10#define CT_CA9X4_SMC (0x100e1000)
11#define CT_CA9X4_SCC (0x100e2000)
12#define CT_CA9X4_SP804_TIMER (0x100e4000)
13#define CT_CA9X4_SP805_WDT (0x100e5000)
14#define CT_CA9X4_TZPC (0x100e6000)
15#define CT_CA9X4_GPIO (0x100e8000)
16#define CT_CA9X4_FASTAXI (0x100e9000)
17#define CT_CA9X4_SLOWAXI (0x100ea000)
18#define CT_CA9X4_TZASC (0x100ec000)
19#define CT_CA9X4_CORESIGHT (0x10200000)
20#define CT_CA9X4_MPIC (0x1e000000)
21#define CT_CA9X4_SYSTIMER (0x1e004000)
22#define CT_CA9X4_SYSWDT (0x1e007000)
23#define CT_CA9X4_L2CC (0x1e00a000)
24
25#define A9_MPCORE_SCU (CT_CA9X4_MPIC + 0x0000)
26#define A9_MPCORE_GIC_CPU (CT_CA9X4_MPIC + 0x0100)
27#define A9_MPCORE_GIT (CT_CA9X4_MPIC + 0x0200)
28#define A9_MPCORE_TWD (CT_CA9X4_MPIC + 0x0600)
29#define A9_MPCORE_GIC_DIST (CT_CA9X4_MPIC + 0x1000)
30
31/*
32 * Interrupts. Those in {} are for AMBA devices
33 */
34#define IRQ_CT_CA9X4_CLCDC { 76 }
35#define IRQ_CT_CA9X4_DMC { 0 }
36#define IRQ_CT_CA9X4_SMC { 77, 78 }
37#define IRQ_CT_CA9X4_TIMER0 80
38#define IRQ_CT_CA9X4_TIMER1 81
39#define IRQ_CT_CA9X4_GPIO { 82 }
40#define IRQ_CT_CA9X4_PMU_CPU0 92
41#define IRQ_CT_CA9X4_PMU_CPU1 93
42#define IRQ_CT_CA9X4_PMU_CPU2 94
43#define IRQ_CT_CA9X4_PMU_CPU3 95
44
45extern struct ct_desc ct_ca9x4_desc;
46
47#endif
diff --git a/arch/arm/mach-vexpress/include/mach/hardware.h b/arch/arm/mach-vexpress/include/mach/hardware.h
deleted file mode 100644
index 40a8c178f10d..000000000000
--- a/arch/arm/mach-vexpress/include/mach/hardware.h
+++ /dev/null
@@ -1 +0,0 @@
1/* empty */
diff --git a/arch/arm/mach-vexpress/include/mach/irqs.h b/arch/arm/mach-vexpress/include/mach/irqs.h
deleted file mode 100644
index f8f7f782eb55..000000000000
--- a/arch/arm/mach-vexpress/include/mach/irqs.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#define IRQ_LOCALTIMER 29
2#define IRQ_LOCALWDOG 30
3
4#ifndef CONFIG_SPARSE_IRQ
5#define NR_IRQS 256
6#endif
diff --git a/arch/arm/mach-vexpress/include/mach/motherboard.h b/arch/arm/mach-vexpress/include/mach/motherboard.h
deleted file mode 100644
index 68abc8b72781..000000000000
--- a/arch/arm/mach-vexpress/include/mach/motherboard.h
+++ /dev/null
@@ -1,88 +0,0 @@
1#ifndef __MACH_MOTHERBOARD_H
2#define __MACH_MOTHERBOARD_H
3
4/*
5 * Physical addresses, offset from V2M_PA_CS0-3
6 */
7#define V2M_NOR0 (V2M_PA_CS0)
8#define V2M_NOR1 (V2M_PA_CS1)
9#define V2M_SRAM (V2M_PA_CS2)
10#define V2M_VIDEO_SRAM (V2M_PA_CS3 + 0x00000000)
11#define V2M_LAN9118 (V2M_PA_CS3 + 0x02000000)
12#define V2M_ISP1761 (V2M_PA_CS3 + 0x03000000)
13
14/*
15 * Physical addresses, offset from V2M_PA_CS7
16 */
17#define V2M_SYSREGS (V2M_PA_CS7 + 0x00000000)
18#define V2M_SYSCTL (V2M_PA_CS7 + 0x00001000)
19#define V2M_SERIAL_BUS_PCI (V2M_PA_CS7 + 0x00002000)
20
21#define V2M_AACI (V2M_PA_CS7 + 0x00004000)
22#define V2M_MMCI (V2M_PA_CS7 + 0x00005000)
23#define V2M_KMI0 (V2M_PA_CS7 + 0x00006000)
24#define V2M_KMI1 (V2M_PA_CS7 + 0x00007000)
25
26#define V2M_UART0 (V2M_PA_CS7 + 0x00009000)
27#define V2M_UART1 (V2M_PA_CS7 + 0x0000a000)
28#define V2M_UART2 (V2M_PA_CS7 + 0x0000b000)
29#define V2M_UART3 (V2M_PA_CS7 + 0x0000c000)
30
31#define V2M_WDT (V2M_PA_CS7 + 0x0000f000)
32
33#define V2M_TIMER01 (V2M_PA_CS7 + 0x00011000)
34#define V2M_TIMER23 (V2M_PA_CS7 + 0x00012000)
35
36#define V2M_SERIAL_BUS_DVI (V2M_PA_CS7 + 0x00016000)
37#define V2M_RTC (V2M_PA_CS7 + 0x00017000)
38
39#define V2M_CF (V2M_PA_CS7 + 0x0001a000)
40#define V2M_CLCD (V2M_PA_CS7 + 0x0001f000)
41
42
43/*
44 * Interrupts. Those in {} are for AMBA devices
45 */
46#define IRQ_V2M_WDT { (32 + 0) }
47#define IRQ_V2M_TIMER0 (32 + 2)
48#define IRQ_V2M_TIMER1 (32 + 2)
49#define IRQ_V2M_TIMER2 (32 + 3)
50#define IRQ_V2M_TIMER3 (32 + 3)
51#define IRQ_V2M_RTC { (32 + 4) }
52#define IRQ_V2M_UART0 { (32 + 5) }
53#define IRQ_V2M_UART1 { (32 + 6) }
54#define IRQ_V2M_UART2 { (32 + 7) }
55#define IRQ_V2M_UART3 { (32 + 8) }
56#define IRQ_V2M_MMCI { (32 + 9), (32 + 10) }
57#define IRQ_V2M_AACI { (32 + 11) }
58#define IRQ_V2M_KMI0 { (32 + 12) }
59#define IRQ_V2M_KMI1 { (32 + 13) }
60#define IRQ_V2M_CLCD { (32 + 14) }
61#define IRQ_V2M_LAN9118 (32 + 15)
62#define IRQ_V2M_ISP1761 (32 + 16)
63#define IRQ_V2M_PCIE (32 + 17)
64
65
66/*
67 * Core tile IDs
68 */
69#define V2M_CT_ID_CA9 0x0c000191
70#define V2M_CT_ID_UNSUPPORTED 0xff000191
71#define V2M_CT_ID_MASK 0xff000fff
72
73struct ct_desc {
74 u32 id;
75 const char *name;
76 void (*map_io)(void);
77 void (*init_early)(void);
78 void (*init_irq)(void);
79 void (*init_tile)(void);
80#ifdef CONFIG_SMP
81 void (*init_cpu_map)(void);
82 void (*smp_enable)(unsigned int);
83#endif
84};
85
86extern struct ct_desc *ct_desc;
87
88#endif
diff --git a/arch/arm/mach-vexpress/platsmp.c b/arch/arm/mach-vexpress/platsmp.c
index a1f3804fd5a5..83188cf1875d 100644
--- a/arch/arm/mach-vexpress/platsmp.c
+++ b/arch/arm/mach-vexpress/platsmp.c
@@ -19,48 +19,10 @@
19#include <asm/smp_scu.h> 19#include <asm/smp_scu.h>
20#include <asm/mach/map.h> 20#include <asm/mach/map.h>
21 21
22#include <mach/motherboard.h>
23
24#include <plat/platsmp.h> 22#include <plat/platsmp.h>
25 23
26#include "core.h" 24#include "core.h"
27 25
28/*
29 * Initialise the CPU possible map early - this describes the CPUs
30 * which may be present or become present in the system.
31 */
32static void __init vexpress_smp_init_cpus(void)
33{
34 ct_desc->init_cpu_map();
35}
36
37static void __init vexpress_smp_prepare_cpus(unsigned int max_cpus)
38{
39 /*
40 * Initialise the present map, which describes the set of CPUs
41 * actually populated at the present time.
42 */
43 ct_desc->smp_enable(max_cpus);
44
45 /*
46 * Write the address of secondary startup into the
47 * system-wide flags register. The boot monitor waits
48 * until it receives a soft interrupt, and then the
49 * secondary CPU branches to this address.
50 */
51 vexpress_flags_set(virt_to_phys(versatile_secondary_startup));
52}
53
54struct smp_operations __initdata vexpress_smp_ops = {
55 .smp_init_cpus = vexpress_smp_init_cpus,
56 .smp_prepare_cpus = vexpress_smp_prepare_cpus,
57 .smp_secondary_init = versatile_secondary_init,
58 .smp_boot_secondary = versatile_boot_secondary,
59#ifdef CONFIG_HOTPLUG_CPU
60 .cpu_die = vexpress_cpu_die,
61#endif
62};
63
64bool __init vexpress_smp_init_ops(void) 26bool __init vexpress_smp_init_ops(void)
65{ 27{
66#ifdef CONFIG_MCPM 28#ifdef CONFIG_MCPM
@@ -79,8 +41,6 @@ bool __init vexpress_smp_init_ops(void)
79 return false; 41 return false;
80} 42}
81 43
82#if defined(CONFIG_OF)
83
84static const struct of_device_id vexpress_smp_dt_scu_match[] __initconst = { 44static const struct of_device_id vexpress_smp_dt_scu_match[] __initconst = {
85 { .compatible = "arm,cortex-a5-scu", }, 45 { .compatible = "arm,cortex-a5-scu", },
86 { .compatible = "arm,cortex-a9-scu", }, 46 { .compatible = "arm,cortex-a9-scu", },
@@ -112,5 +72,3 @@ struct smp_operations __initdata vexpress_smp_dt_ops = {
112 .cpu_die = vexpress_cpu_die, 72 .cpu_die = vexpress_cpu_die,
113#endif 73#endif
114}; 74};
115
116#endif
diff --git a/arch/arm/mach-vexpress/v2m.c b/arch/arm/mach-vexpress/v2m.c
index 6ff681a24ba7..a0400f4cca89 100644
--- a/arch/arm/mach-vexpress/v2m.c
+++ b/arch/arm/mach-vexpress/v2m.c
@@ -1,380 +1,7 @@
1/*
2 * Versatile Express V2M Motherboard Support
3 */
4#include <linux/device.h>
5#include <linux/amba/bus.h>
6#include <linux/amba/mmci.h>
7#include <linux/io.h>
8#include <linux/smp.h>
9#include <linux/init.h>
10#include <linux/of_address.h>
11#include <linux/of_fdt.h>
12#include <linux/of_irq.h>
13#include <linux/of_platform.h>
14#include <linux/platform_device.h>
15#include <linux/ata_platform.h>
16#include <linux/smsc911x.h>
17#include <linux/spinlock.h>
18#include <linux/usb/isp1760.h>
19#include <linux/mtd/physmap.h>
20#include <linux/regulator/fixed.h>
21#include <linux/regulator/machine.h>
22#include <linux/vexpress.h>
23#include <linux/clkdev.h>
24
25#include <asm/mach-types.h>
26#include <asm/sizes.h>
27#include <asm/mach/arch.h> 1#include <asm/mach/arch.h>
28#include <asm/mach/map.h>
29#include <asm/mach/time.h>
30#include <asm/hardware/arm_timer.h>
31#include <asm/hardware/cache-l2x0.h>
32#include <asm/hardware/timer-sp.h>
33
34#include <mach/ct-ca9x4.h>
35#include <mach/motherboard.h>
36
37#include <plat/sched_clock.h>
38#include <plat/platsmp.h>
39 2
40#include "core.h" 3#include "core.h"
41 4
42#define V2M_PA_CS0 0x40000000
43#define V2M_PA_CS1 0x44000000
44#define V2M_PA_CS2 0x48000000
45#define V2M_PA_CS3 0x4c000000
46#define V2M_PA_CS7 0x10000000
47
48static struct map_desc v2m_io_desc[] __initdata = {
49 {
50 .virtual = V2M_PERIPH,
51 .pfn = __phys_to_pfn(V2M_PA_CS7),
52 .length = SZ_128K,
53 .type = MT_DEVICE,
54 },
55};
56
57static void __init v2m_sp804_init(void __iomem *base, unsigned int irq)
58{
59 if (WARN_ON(!base || irq == NO_IRQ))
60 return;
61
62 sp804_clocksource_init(base + TIMER_2_BASE, "v2m-timer1");
63 sp804_clockevents_init(base + TIMER_1_BASE, irq, "v2m-timer0");
64}
65
66
67static struct resource v2m_pcie_i2c_resource = {
68 .start = V2M_SERIAL_BUS_PCI,
69 .end = V2M_SERIAL_BUS_PCI + SZ_4K - 1,
70 .flags = IORESOURCE_MEM,
71};
72
73static struct platform_device v2m_pcie_i2c_device = {
74 .name = "versatile-i2c",
75 .id = 0,
76 .num_resources = 1,
77 .resource = &v2m_pcie_i2c_resource,
78};
79
80static struct resource v2m_ddc_i2c_resource = {
81 .start = V2M_SERIAL_BUS_DVI,
82 .end = V2M_SERIAL_BUS_DVI + SZ_4K - 1,
83 .flags = IORESOURCE_MEM,
84};
85
86static struct platform_device v2m_ddc_i2c_device = {
87 .name = "versatile-i2c",
88 .id = 1,
89 .num_resources = 1,
90 .resource = &v2m_ddc_i2c_resource,
91};
92
93static struct resource v2m_eth_resources[] = {
94 {
95 .start = V2M_LAN9118,
96 .end = V2M_LAN9118 + SZ_64K - 1,
97 .flags = IORESOURCE_MEM,
98 }, {
99 .start = IRQ_V2M_LAN9118,
100 .end = IRQ_V2M_LAN9118,
101 .flags = IORESOURCE_IRQ,
102 },
103};
104
105static struct smsc911x_platform_config v2m_eth_config = {
106 .flags = SMSC911X_USE_32BIT,
107 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_HIGH,
108 .irq_type = SMSC911X_IRQ_TYPE_PUSH_PULL,
109 .phy_interface = PHY_INTERFACE_MODE_MII,
110};
111
112static struct platform_device v2m_eth_device = {
113 .name = "smsc911x",
114 .id = -1,
115 .resource = v2m_eth_resources,
116 .num_resources = ARRAY_SIZE(v2m_eth_resources),
117 .dev.platform_data = &v2m_eth_config,
118};
119
120static struct regulator_consumer_supply v2m_eth_supplies[] = {
121 REGULATOR_SUPPLY("vddvario", "smsc911x"),
122 REGULATOR_SUPPLY("vdd33a", "smsc911x"),
123};
124
125static struct resource v2m_usb_resources[] = {
126 {
127 .start = V2M_ISP1761,
128 .end = V2M_ISP1761 + SZ_128K - 1,
129 .flags = IORESOURCE_MEM,
130 }, {
131 .start = IRQ_V2M_ISP1761,
132 .end = IRQ_V2M_ISP1761,
133 .flags = IORESOURCE_IRQ,
134 },
135};
136
137static struct isp1760_platform_data v2m_usb_config = {
138 .is_isp1761 = true,
139 .bus_width_16 = false,
140 .port1_otg = true,
141 .analog_oc = false,
142 .dack_polarity_high = false,
143 .dreq_polarity_high = false,
144};
145
146static struct platform_device v2m_usb_device = {
147 .name = "isp1760",
148 .id = -1,
149 .resource = v2m_usb_resources,
150 .num_resources = ARRAY_SIZE(v2m_usb_resources),
151 .dev.platform_data = &v2m_usb_config,
152};
153
154static struct physmap_flash_data v2m_flash_data = {
155 .width = 4,
156};
157
158static struct resource v2m_flash_resources[] = {
159 {
160 .start = V2M_NOR0,
161 .end = V2M_NOR0 + SZ_64M - 1,
162 .flags = IORESOURCE_MEM,
163 }, {
164 .start = V2M_NOR1,
165 .end = V2M_NOR1 + SZ_64M - 1,
166 .flags = IORESOURCE_MEM,
167 },
168};
169
170static struct platform_device v2m_flash_device = {
171 .name = "physmap-flash",
172 .id = -1,
173 .resource = v2m_flash_resources,
174 .num_resources = ARRAY_SIZE(v2m_flash_resources),
175 .dev.platform_data = &v2m_flash_data,
176};
177
178static struct pata_platform_info v2m_pata_data = {
179 .ioport_shift = 2,
180};
181
182static struct resource v2m_pata_resources[] = {
183 {
184 .start = V2M_CF,
185 .end = V2M_CF + 0xff,
186 .flags = IORESOURCE_MEM,
187 }, {
188 .start = V2M_CF + 0x100,
189 .end = V2M_CF + SZ_4K - 1,
190 .flags = IORESOURCE_MEM,
191 },
192};
193
194static struct platform_device v2m_cf_device = {
195 .name = "pata_platform",
196 .id = -1,
197 .resource = v2m_pata_resources,
198 .num_resources = ARRAY_SIZE(v2m_pata_resources),
199 .dev.platform_data = &v2m_pata_data,
200};
201
202static struct mmci_platform_data v2m_mmci_data = {
203 .ocr_mask = MMC_VDD_32_33|MMC_VDD_33_34,
204 .status = vexpress_get_mci_cardin,
205 .gpio_cd = -1,
206 .gpio_wp = -1,
207};
208
209static struct resource v2m_sysreg_resources[] = {
210 {
211 .start = V2M_SYSREGS,
212 .end = V2M_SYSREGS + 0xfff,
213 .flags = IORESOURCE_MEM,
214 },
215};
216
217static struct platform_device v2m_sysreg_device = {
218 .name = "vexpress-sysreg",
219 .id = -1,
220 .resource = v2m_sysreg_resources,
221 .num_resources = ARRAY_SIZE(v2m_sysreg_resources),
222};
223
224static struct platform_device v2m_muxfpga_device = {
225 .name = "vexpress-muxfpga",
226 .id = 0,
227 .num_resources = 1,
228 .resource = (struct resource []) {
229 VEXPRESS_RES_FUNC(0, 7),
230 }
231};
232
233static struct platform_device v2m_shutdown_device = {
234 .name = "vexpress-shutdown",
235 .id = 0,
236 .num_resources = 1,
237 .resource = (struct resource []) {
238 VEXPRESS_RES_FUNC(0, 8),
239 }
240};
241
242static struct platform_device v2m_reboot_device = {
243 .name = "vexpress-reboot",
244 .id = 0,
245 .num_resources = 1,
246 .resource = (struct resource []) {
247 VEXPRESS_RES_FUNC(0, 9),
248 }
249};
250
251static struct platform_device v2m_dvimode_device = {
252 .name = "vexpress-dvimode",
253 .id = 0,
254 .num_resources = 1,
255 .resource = (struct resource []) {
256 VEXPRESS_RES_FUNC(0, 11),
257 }
258};
259
260static AMBA_APB_DEVICE(aaci, "mb:aaci", 0, V2M_AACI, IRQ_V2M_AACI, NULL);
261static AMBA_APB_DEVICE(mmci, "mb:mmci", 0, V2M_MMCI, IRQ_V2M_MMCI, &v2m_mmci_data);
262static AMBA_APB_DEVICE(kmi0, "mb:kmi0", 0, V2M_KMI0, IRQ_V2M_KMI0, NULL);
263static AMBA_APB_DEVICE(kmi1, "mb:kmi1", 0, V2M_KMI1, IRQ_V2M_KMI1, NULL);
264static AMBA_APB_DEVICE(uart0, "mb:uart0", 0, V2M_UART0, IRQ_V2M_UART0, NULL);
265static AMBA_APB_DEVICE(uart1, "mb:uart1", 0, V2M_UART1, IRQ_V2M_UART1, NULL);
266static AMBA_APB_DEVICE(uart2, "mb:uart2", 0, V2M_UART2, IRQ_V2M_UART2, NULL);
267static AMBA_APB_DEVICE(uart3, "mb:uart3", 0, V2M_UART3, IRQ_V2M_UART3, NULL);
268static AMBA_APB_DEVICE(wdt, "mb:wdt", 0, V2M_WDT, IRQ_V2M_WDT, NULL);
269static AMBA_APB_DEVICE(rtc, "mb:rtc", 0, V2M_RTC, IRQ_V2M_RTC, NULL);
270
271static struct amba_device *v2m_amba_devs[] __initdata = {
272 &aaci_device,
273 &mmci_device,
274 &kmi0_device,
275 &kmi1_device,
276 &uart0_device,
277 &uart1_device,
278 &uart2_device,
279 &uart3_device,
280 &wdt_device,
281 &rtc_device,
282};
283
284static void __init v2m_timer_init(void)
285{
286 vexpress_clk_init(ioremap(V2M_SYSCTL, SZ_4K));
287 v2m_sp804_init(ioremap(V2M_TIMER01, SZ_4K), IRQ_V2M_TIMER0);
288}
289
290static void __init v2m_init_early(void)
291{
292 if (ct_desc->init_early)
293 ct_desc->init_early();
294 versatile_sched_clock_init(vexpress_get_24mhz_clock_base(), 24000000);
295}
296
297struct ct_desc *ct_desc;
298
299static struct ct_desc *ct_descs[] __initdata = {
300#ifdef CONFIG_ARCH_VEXPRESS_CA9X4
301 &ct_ca9x4_desc,
302#endif
303};
304
305static void __init v2m_populate_ct_desc(void)
306{
307 int i;
308 u32 current_tile_id;
309
310 ct_desc = NULL;
311 current_tile_id = vexpress_get_procid(VEXPRESS_SITE_MASTER)
312 & V2M_CT_ID_MASK;
313
314 for (i = 0; i < ARRAY_SIZE(ct_descs) && !ct_desc; ++i)
315 if (ct_descs[i]->id == current_tile_id)
316 ct_desc = ct_descs[i];
317
318 if (!ct_desc)
319 panic("vexpress: this kernel does not support core tile ID 0x%08x when booting via ATAGs.\n"
320 "You may need a device tree blob or a different kernel to boot on this board.\n",
321 current_tile_id);
322}
323
324static void __init v2m_map_io(void)
325{
326 iotable_init(v2m_io_desc, ARRAY_SIZE(v2m_io_desc));
327 vexpress_sysreg_early_init(ioremap(V2M_SYSREGS, SZ_4K));
328 v2m_populate_ct_desc();
329 ct_desc->map_io();
330}
331
332static void __init v2m_init_irq(void)
333{
334 ct_desc->init_irq();
335}
336
337static void __init v2m_init(void)
338{
339 int i;
340
341 regulator_register_fixed(0, v2m_eth_supplies,
342 ARRAY_SIZE(v2m_eth_supplies));
343
344 platform_device_register(&v2m_sysreg_device);
345 platform_device_register(&v2m_pcie_i2c_device);
346 platform_device_register(&v2m_ddc_i2c_device);
347 platform_device_register(&v2m_flash_device);
348 platform_device_register(&v2m_cf_device);
349 platform_device_register(&v2m_eth_device);
350 platform_device_register(&v2m_usb_device);
351
352 for (i = 0; i < ARRAY_SIZE(v2m_amba_devs); i++)
353 amba_device_register(v2m_amba_devs[i], &iomem_resource);
354
355 vexpress_syscfg_device_register(&v2m_muxfpga_device);
356 vexpress_syscfg_device_register(&v2m_shutdown_device);
357 vexpress_syscfg_device_register(&v2m_reboot_device);
358 vexpress_syscfg_device_register(&v2m_dvimode_device);
359
360 ct_desc->init_tile();
361}
362
363MACHINE_START(VEXPRESS, "ARM-Versatile Express")
364 .atag_offset = 0x100,
365 .smp = smp_ops(vexpress_smp_ops),
366 .map_io = v2m_map_io,
367 .init_early = v2m_init_early,
368 .init_irq = v2m_init_irq,
369 .init_time = v2m_timer_init,
370 .init_machine = v2m_init,
371MACHINE_END
372
373static void __init v2m_dt_init(void)
374{
375 of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
376}
377
378static const char * const v2m_dt_match[] __initconst = { 5static const char * const v2m_dt_match[] __initconst = {
379 "arm,vexpress", 6 "arm,vexpress",
380 NULL, 7 NULL,
@@ -386,5 +13,4 @@ DT_MACHINE_START(VEXPRESS_DT, "ARM-Versatile Express")
386 .l2c_aux_mask = 0xfe0fffff, 13 .l2c_aux_mask = 0xfe0fffff,
387 .smp = smp_ops(vexpress_smp_dt_ops), 14 .smp = smp_ops(vexpress_smp_dt_ops),
388 .smp_init = smp_init_ops(vexpress_smp_init_ops), 15 .smp_init = smp_init_ops(vexpress_smp_init_ops),
389 .init_machine = v2m_dt_init,
390MACHINE_END 16MACHINE_END
diff --git a/arch/arm/mach-zynq/Makefile b/arch/arm/mach-zynq/Makefile
index c85fb3f7d5cd..b03a97eb7501 100644
--- a/arch/arm/mach-zynq/Makefile
+++ b/arch/arm/mach-zynq/Makefile
@@ -4,6 +4,4 @@
4 4
5# Common support 5# Common support
6obj-y := common.o slcr.o pm.o 6obj-y := common.o slcr.o pm.o
7CFLAGS_REMOVE_hotplug.o =-march=armv6k
8CFLAGS_hotplug.o =-Wa,-march=armv7-a -mcpu=cortex-a9
9obj-$(CONFIG_SMP) += headsmp.o platsmp.o 7obj-$(CONFIG_SMP) += headsmp.o platsmp.o
diff --git a/arch/arm/mach-zynq/common.h b/arch/arm/mach-zynq/common.h
index 2bc71273c73c..382c60e9aa16 100644
--- a/arch/arm/mach-zynq/common.h
+++ b/arch/arm/mach-zynq/common.h
@@ -29,7 +29,6 @@ extern void zynq_slcr_cpu_state_write(int cpu, bool die);
29extern u32 zynq_slcr_get_device_id(void); 29extern u32 zynq_slcr_get_device_id(void);
30 30
31#ifdef CONFIG_SMP 31#ifdef CONFIG_SMP
32extern void secondary_startup(void);
33extern char zynq_secondary_trampoline; 32extern char zynq_secondary_trampoline;
34extern char zynq_secondary_trampoline_jump; 33extern char zynq_secondary_trampoline_jump;
35extern char zynq_secondary_trampoline_end; 34extern char zynq_secondary_trampoline_end;
diff --git a/arch/arm/mach-zynq/hotplug.c b/arch/arm/mach-zynq/hotplug.c
deleted file mode 100644
index b685c89f11e4..000000000000
--- a/arch/arm/mach-zynq/hotplug.c
+++ /dev/null
@@ -1,14 +0,0 @@
1/*
2 * Copyright (C) 2012-2013 Xilinx
3 *
4 * based on linux/arch/arm/mach-realview/hotplug.c
5 *
6 * Copyright (C) 2002 ARM Ltd.
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#include <asm/proc-fns.h>
14
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index 179a100493f5..ab906b801047 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -798,6 +798,7 @@ config NEED_KUSER_HELPERS
798 798
799config KUSER_HELPERS 799config KUSER_HELPERS
800 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS 800 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
801 depends on MMU
801 default y 802 default y
802 help 803 help
803 Warning: disabling this option may break user programs. 804 Warning: disabling this option may break user programs.
diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S
index b3a947863ac7..22ac2a6fbfe3 100644
--- a/arch/arm/mm/proc-v7.S
+++ b/arch/arm/mm/proc-v7.S
@@ -270,7 +270,6 @@ __v7_pj4b_setup:
270/* Auxiliary Debug Modes Control 1 Register */ 270/* Auxiliary Debug Modes Control 1 Register */
271#define PJ4B_STATIC_BP (1 << 2) /* Enable Static BP */ 271#define PJ4B_STATIC_BP (1 << 2) /* Enable Static BP */
272#define PJ4B_INTER_PARITY (1 << 8) /* Disable Internal Parity Handling */ 272#define PJ4B_INTER_PARITY (1 << 8) /* Disable Internal Parity Handling */
273#define PJ4B_BCK_OFF_STREX (1 << 5) /* Enable the back off of STREX instr */
274#define PJ4B_CLEAN_LINE (1 << 16) /* Disable data transfer for clean line */ 273#define PJ4B_CLEAN_LINE (1 << 16) /* Disable data transfer for clean line */
275 274
276/* Auxiliary Debug Modes Control 2 Register */ 275/* Auxiliary Debug Modes Control 2 Register */
@@ -293,7 +292,6 @@ __v7_pj4b_setup:
293 /* Auxiliary Debug Modes Control 1 Register */ 292 /* Auxiliary Debug Modes Control 1 Register */
294 mrc p15, 1, r0, c15, c1, 1 293 mrc p15, 1, r0, c15, c1, 1
295 orr r0, r0, #PJ4B_CLEAN_LINE 294 orr r0, r0, #PJ4B_CLEAN_LINE
296 orr r0, r0, #PJ4B_BCK_OFF_STREX
297 orr r0, r0, #PJ4B_INTER_PARITY 295 orr r0, r0, #PJ4B_INTER_PARITY
298 bic r0, r0, #PJ4B_STATIC_BP 296 bic r0, r0, #PJ4B_STATIC_BP
299 mcr p15, 1, r0, c15, c1, 1 297 mcr p15, 1, r0, c15, c1, 1
diff --git a/arch/arm/mm/proc-xscale.S b/arch/arm/mm/proc-xscale.S
index 23259f104c66..afa2b3c4df4a 100644
--- a/arch/arm/mm/proc-xscale.S
+++ b/arch/arm/mm/proc-xscale.S
@@ -535,7 +535,7 @@ ENTRY(cpu_xscale_do_suspend)
535 mrc p15, 0, r5, c15, c1, 0 @ CP access reg 535 mrc p15, 0, r5, c15, c1, 0 @ CP access reg
536 mrc p15, 0, r6, c13, c0, 0 @ PID 536 mrc p15, 0, r6, c13, c0, 0 @ PID
537 mrc p15, 0, r7, c3, c0, 0 @ domain ID 537 mrc p15, 0, r7, c3, c0, 0 @ domain ID
538 mrc p15, 0, r8, c1, c1, 0 @ auxiliary control reg 538 mrc p15, 0, r8, c1, c0, 1 @ auxiliary control reg
539 mrc p15, 0, r9, c1, c0, 0 @ control reg 539 mrc p15, 0, r9, c1, c0, 0 @ control reg
540 bic r4, r4, #2 @ clear frequency change bit 540 bic r4, r4, #2 @ clear frequency change bit
541 stmia r0, {r4 - r9} @ store cp regs 541 stmia r0, {r4 - r9} @ store cp regs
@@ -552,7 +552,7 @@ ENTRY(cpu_xscale_do_resume)
552 mcr p15, 0, r6, c13, c0, 0 @ PID 552 mcr p15, 0, r6, c13, c0, 0 @ PID
553 mcr p15, 0, r7, c3, c0, 0 @ domain ID 553 mcr p15, 0, r7, c3, c0, 0 @ domain ID
554 mcr p15, 0, r1, c2, c0, 0 @ translation table base addr 554 mcr p15, 0, r1, c2, c0, 0 @ translation table base addr
555 mcr p15, 0, r8, c1, c1, 0 @ auxiliary control reg 555 mcr p15, 0, r8, c1, c0, 1 @ auxiliary control reg
556 mov r0, r9 @ control register 556 mov r0, r9 @ control register
557 b cpu_resume_mmu 557 b cpu_resume_mmu
558ENDPROC(cpu_xscale_do_resume) 558ENDPROC(cpu_xscale_do_resume)
diff --git a/arch/arm/plat-samsung/include/plat/map-s5p.h b/arch/arm/plat-samsung/include/plat/map-s5p.h
index f5b9d3ff9cd4..f5cf2bd208e0 100644
--- a/arch/arm/plat-samsung/include/plat/map-s5p.h
+++ b/arch/arm/plat-samsung/include/plat/map-s5p.h
@@ -15,43 +15,22 @@
15 15
16#define S5P_VA_CHIPID S3C_ADDR(0x02000000) 16#define S5P_VA_CHIPID S3C_ADDR(0x02000000)
17#define S5P_VA_CMU S3C_ADDR(0x02100000) 17#define S5P_VA_CMU S3C_ADDR(0x02100000)
18#define S5P_VA_GPIO S3C_ADDR(0x02200000)
19#define S5P_VA_GPIO1 S5P_VA_GPIO
20#define S5P_VA_GPIO2 S3C_ADDR(0x02240000)
21#define S5P_VA_GPIO3 S3C_ADDR(0x02280000)
22 18
23#define S5P_VA_SYSRAM S3C_ADDR(0x02400000)
24#define S5P_VA_SYSRAM_NS S3C_ADDR(0x02410000)
25#define S5P_VA_DMC0 S3C_ADDR(0x02440000) 19#define S5P_VA_DMC0 S3C_ADDR(0x02440000)
26#define S5P_VA_DMC1 S3C_ADDR(0x02480000) 20#define S5P_VA_DMC1 S3C_ADDR(0x02480000)
27#define S5P_VA_SROMC S3C_ADDR(0x024C0000) 21#define S5P_VA_SROMC S3C_ADDR(0x024C0000)
28 22
29#define S5P_VA_SYSTIMER S3C_ADDR(0x02500000)
30#define S5P_VA_L2CC S3C_ADDR(0x02600000)
31
32#define S5P_VA_COMBINER_BASE S3C_ADDR(0x02700000)
33#define S5P_VA_COMBINER(x) (S5P_VA_COMBINER_BASE + ((x) >> 2) * 0x10)
34
35#define S5P_VA_COREPERI_BASE S3C_ADDR(0x02800000) 23#define S5P_VA_COREPERI_BASE S3C_ADDR(0x02800000)
36#define S5P_VA_COREPERI(x) (S5P_VA_COREPERI_BASE + (x)) 24#define S5P_VA_COREPERI(x) (S5P_VA_COREPERI_BASE + (x))
37#define S5P_VA_SCU S5P_VA_COREPERI(0x0) 25#define S5P_VA_SCU S5P_VA_COREPERI(0x0)
38#define S5P_VA_TWD S5P_VA_COREPERI(0x600) 26#define S5P_VA_TWD S5P_VA_COREPERI(0x600)
39 27
40#define S5P_VA_GIC_CPU S3C_ADDR(0x02810000)
41#define S5P_VA_GIC_DIST S3C_ADDR(0x02820000)
42
43#define VA_VIC(x) (S3C_VA_IRQ + ((x) * 0x10000)) 28#define VA_VIC(x) (S3C_VA_IRQ + ((x) * 0x10000))
44#define VA_VIC0 VA_VIC(0) 29#define VA_VIC0 VA_VIC(0)
45#define VA_VIC1 VA_VIC(1) 30#define VA_VIC1 VA_VIC(1)
46#define VA_VIC2 VA_VIC(2) 31#define VA_VIC2 VA_VIC(2)
47#define VA_VIC3 VA_VIC(3) 32#define VA_VIC3 VA_VIC(3)
48 33
49#define S5P_VA_UART(x) (S3C_VA_UART + ((x) * S3C_UART_OFFSET))
50#define S5P_VA_UART0 S5P_VA_UART(0)
51#define S5P_VA_UART1 S5P_VA_UART(1)
52#define S5P_VA_UART2 S5P_VA_UART(2)
53#define S5P_VA_UART3 S5P_VA_UART(3)
54
55#ifndef S3C_UART_OFFSET 34#ifndef S3C_UART_OFFSET
56#define S3C_UART_OFFSET (0x400) 35#define S3C_UART_OFFSET (0x400)
57#endif 36#endif
diff --git a/arch/arm/plat-versatile/Kconfig b/arch/arm/plat-versatile/Kconfig
index a301ca2c7d00..49b8ef91584a 100644
--- a/arch/arm/plat-versatile/Kconfig
+++ b/arch/arm/plat-versatile/Kconfig
@@ -4,6 +4,6 @@ config PLAT_VERSATILE_CLOCK
4 bool 4 bool
5 5
6config PLAT_VERSATILE_SCHED_CLOCK 6config PLAT_VERSATILE_SCHED_CLOCK
7 def_bool y 7 bool
8 8
9endif 9endif
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 9532f8d5857e..7c79c6494379 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -34,13 +34,16 @@ config ARM64
34 select GENERIC_TIME_VSYSCALL 34 select GENERIC_TIME_VSYSCALL
35 select HANDLE_DOMAIN_IRQ 35 select HANDLE_DOMAIN_IRQ
36 select HARDIRQS_SW_RESEND 36 select HARDIRQS_SW_RESEND
37 select HAVE_ALIGNED_STRUCT_PAGE if SLUB
37 select HAVE_ARCH_AUDITSYSCALL 38 select HAVE_ARCH_AUDITSYSCALL
38 select HAVE_ARCH_JUMP_LABEL 39 select HAVE_ARCH_JUMP_LABEL
39 select HAVE_ARCH_KGDB 40 select HAVE_ARCH_KGDB
41 select HAVE_ARCH_SECCOMP_FILTER
40 select HAVE_ARCH_TRACEHOOK 42 select HAVE_ARCH_TRACEHOOK
41 select HAVE_BPF_JIT 43 select HAVE_BPF_JIT
42 select HAVE_C_RECORDMCOUNT 44 select HAVE_C_RECORDMCOUNT
43 select HAVE_CC_STACKPROTECTOR 45 select HAVE_CC_STACKPROTECTOR
46 select HAVE_CMPXCHG_DOUBLE
44 select HAVE_DEBUG_BUGVERBOSE 47 select HAVE_DEBUG_BUGVERBOSE
45 select HAVE_DEBUG_KMEMLEAK 48 select HAVE_DEBUG_KMEMLEAK
46 select HAVE_DMA_API_DEBUG 49 select HAVE_DMA_API_DEBUG
@@ -193,6 +196,114 @@ endmenu
193 196
194menu "Kernel Features" 197menu "Kernel Features"
195 198
199menu "ARM errata workarounds via the alternatives framework"
200
201config ARM64_ERRATUM_826319
202 bool "Cortex-A53: 826319: System might deadlock if a write cannot complete until read data is accepted"
203 default y
204 help
205 This option adds an alternative code sequence to work around ARM
206 erratum 826319 on Cortex-A53 parts up to r0p2 with an AMBA 4 ACE or
207 AXI master interface and an L2 cache.
208
209 If a Cortex-A53 uses an AMBA AXI4 ACE interface to other processors
210 and is unable to accept a certain write via this interface, it will
211 not progress on read data presented on the read data channel and the
212 system can deadlock.
213
214 The workaround promotes data cache clean instructions to
215 data cache clean-and-invalidate.
216 Please note that this does not necessarily enable the workaround,
217 as it depends on the alternative framework, which will only patch
218 the kernel if an affected CPU is detected.
219
220 If unsure, say Y.
221
222config ARM64_ERRATUM_827319
223 bool "Cortex-A53: 827319: Data cache clean instructions might cause overlapping transactions to the interconnect"
224 default y
225 help
226 This option adds an alternative code sequence to work around ARM
227 erratum 827319 on Cortex-A53 parts up to r0p2 with an AMBA 5 CHI
228 master interface and an L2 cache.
229
230 Under certain conditions this erratum can cause a clean line eviction
231 to occur at the same time as another transaction to the same address
232 on the AMBA 5 CHI interface, which can cause data corruption if the
233 interconnect reorders the two transactions.
234
235 The workaround promotes data cache clean instructions to
236 data cache clean-and-invalidate.
237 Please note that this does not necessarily enable the workaround,
238 as it depends on the alternative framework, which will only patch
239 the kernel if an affected CPU is detected.
240
241 If unsure, say Y.
242
243config ARM64_ERRATUM_824069
244 bool "Cortex-A53: 824069: Cache line might not be marked as clean after a CleanShared snoop"
245 default y
246 help
247 This option adds an alternative code sequence to work around ARM
248 erratum 824069 on Cortex-A53 parts up to r0p2 when it is connected
249 to a coherent interconnect.
250
251 If a Cortex-A53 processor is executing a store or prefetch for
252 write instruction at the same time as a processor in another
253 cluster is executing a cache maintenance operation to the same
254 address, then this erratum might cause a clean cache line to be
255 incorrectly marked as dirty.
256
257 The workaround promotes data cache clean instructions to
258 data cache clean-and-invalidate.
259 Please note that this option does not necessarily enable the
260 workaround, as it depends on the alternative framework, which will
261 only patch the kernel if an affected CPU is detected.
262
263 If unsure, say Y.
264
265config ARM64_ERRATUM_819472
266 bool "Cortex-A53: 819472: Store exclusive instructions might cause data corruption"
267 default y
268 help
269 This option adds an alternative code sequence to work around ARM
270 erratum 819472 on Cortex-A53 parts up to r0p1 with an L2 cache
271 present when it is connected to a coherent interconnect.
272
273 If the processor is executing a load and store exclusive sequence at
274 the same time as a processor in another cluster is executing a cache
275 maintenance operation to the same address, then this erratum might
276 cause data corruption.
277
278 The workaround promotes data cache clean instructions to
279 data cache clean-and-invalidate.
280 Please note that this does not necessarily enable the workaround,
281 as it depends on the alternative framework, which will only patch
282 the kernel if an affected CPU is detected.
283
284 If unsure, say Y.
285
286config ARM64_ERRATUM_832075
287 bool "Cortex-A57: 832075: possible deadlock on mixing exclusive memory accesses with device loads"
288 default y
289 help
290 This option adds an alternative code sequence to work around ARM
291 erratum 832075 on Cortex-A57 parts up to r1p2.
292
293 Affected Cortex-A57 parts might deadlock when exclusive load/store
294 instructions to Write-Back memory are mixed with Device loads.
295
296 The workaround is to promote device loads to use Load-Acquire
297 semantics.
298 Please note that this does not necessarily enable the workaround,
299 as it depends on the alternative framework, which will only patch
300 the kernel if an affected CPU is detected.
301
302 If unsure, say Y.
303
304endmenu
305
306
196choice 307choice
197 prompt "Page size" 308 prompt "Page size"
198 default ARM64_4K_PAGES 309 default ARM64_4K_PAGES
@@ -345,6 +456,19 @@ config ARCH_HAS_CACHE_LINE_SIZE
345 456
346source "mm/Kconfig" 457source "mm/Kconfig"
347 458
459config SECCOMP
460 bool "Enable seccomp to safely compute untrusted bytecode"
461 ---help---
462 This kernel feature is useful for number crunching applications
463 that may need to compute untrusted bytecode during their
464 execution. By using pipes or other transports made available to
465 the process as file descriptors supporting the read/write
466 syscalls, it's possible to isolate those applications in
467 their own address space using seccomp. Once seccomp is
468 enabled via prctl(PR_SET_SECCOMP), it cannot be disabled
469 and the task is only allowed to execute a few safe syscalls
470 defined by each seccomp mode.
471
348config XEN_DOM0 472config XEN_DOM0
349 def_bool y 473 def_bool y
350 depends on XEN 474 depends on XEN
@@ -361,6 +485,58 @@ config FORCE_MAX_ZONEORDER
361 default "14" if (ARM64_64K_PAGES && TRANSPARENT_HUGEPAGE) 485 default "14" if (ARM64_64K_PAGES && TRANSPARENT_HUGEPAGE)
362 default "11" 486 default "11"
363 487
488menuconfig ARMV8_DEPRECATED
489 bool "Emulate deprecated/obsolete ARMv8 instructions"
490 depends on COMPAT
491 help
492 Legacy software support may require certain instructions
493 that have been deprecated or obsoleted in the architecture.
494
495 Enable this config to enable selective emulation of these
496 features.
497
498 If unsure, say Y
499
500if ARMV8_DEPRECATED
501
502config SWP_EMULATION
503 bool "Emulate SWP/SWPB instructions"
504 help
505 ARMv8 obsoletes the use of A32 SWP/SWPB instructions such that
506 they are always undefined. Say Y here to enable software
507 emulation of these instructions for userspace using LDXR/STXR.
508
509 In some older versions of glibc [<=2.8] SWP is used during futex
510 trylock() operations with the assumption that the code will not
511 be preempted. This invalid assumption may be more likely to fail
512 with SWP emulation enabled, leading to deadlock of the user
513 application.
514
515 NOTE: when accessing uncached shared regions, LDXR/STXR rely
516 on an external transaction monitoring block called a global
517 monitor to maintain update atomicity. If your system does not
518 implement a global monitor, this option can cause programs that
519 perform SWP operations to uncached memory to deadlock.
520
521 If unsure, say Y
522
523config CP15_BARRIER_EMULATION
524 bool "Emulate CP15 Barrier instructions"
525 help
526 The CP15 barrier instructions - CP15ISB, CP15DSB, and
527 CP15DMB - are deprecated in ARMv8 (and ARMv7). It is
528 strongly recommended to use the ISB, DSB, and DMB
529 instructions instead.
530
531 Say Y here to enable software emulation of these
532 instructions for AArch32 userspace code. When this option is
533 enabled, CP15 barrier usage is traced which can help
534 identify software that needs updating.
535
536 If unsure, say Y
537
538endif
539
364endmenu 540endmenu
365 541
366menu "Boot options" 542menu "Boot options"
@@ -401,6 +577,17 @@ config EFI
401 allow the kernel to be booted as an EFI application. This 577 allow the kernel to be booted as an EFI application. This
402 is only useful on systems that have UEFI firmware. 578 is only useful on systems that have UEFI firmware.
403 579
580config DMI
581 bool "Enable support for SMBIOS (DMI) tables"
582 depends on EFI
583 default y
584 help
585 This enables SMBIOS/DMI feature for systems.
586
587 This option is only useful on systems that have UEFI firmware.
588 However, even with this option, the resultant kernel should
589 continue to boot on existing non-UEFI platforms.
590
404endmenu 591endmenu
405 592
406menu "Userspace binary formats" 593menu "Userspace binary formats"
diff --git a/arch/arm64/Kconfig.debug b/arch/arm64/Kconfig.debug
index 0a12933e50ed..5fdd6dce8061 100644
--- a/arch/arm64/Kconfig.debug
+++ b/arch/arm64/Kconfig.debug
@@ -6,6 +6,18 @@ config FRAME_POINTER
6 bool 6 bool
7 default y 7 default y
8 8
9config ARM64_PTDUMP
10 bool "Export kernel pagetable layout to userspace via debugfs"
11 depends on DEBUG_KERNEL
12 select DEBUG_FS
13 help
14 Say Y here if you want to show the kernel pagetable layout in a
15 debugfs file. This information is only useful for kernel developers
16 who are working in architecture specific areas of the kernel.
17 It is probably not a good idea to enable this feature in a production
18 kernel.
19 If in doubt, say "N"
20
9config STRICT_DEVMEM 21config STRICT_DEVMEM
10 bool "Filter access to /dev/mem" 22 bool "Filter access to /dev/mem"
11 depends on MMU 23 depends on MMU
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
index 20901ffed182..1c43cec971b5 100644
--- a/arch/arm64/Makefile
+++ b/arch/arm64/Makefile
@@ -70,8 +70,13 @@ zinstall install: vmlinux
70%.dtb: scripts 70%.dtb: scripts
71 $(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@ 71 $(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@
72 72
73dtbs: scripts 73PHONY += dtbs dtbs_install
74 $(Q)$(MAKE) $(build)=$(boot)/dts dtbs 74
75dtbs: prepare scripts
76 $(Q)$(MAKE) $(build)=$(boot)/dts
77
78dtbs_install:
79 $(Q)$(MAKE) $(dtbinst)=$(boot)/dts
75 80
76PHONY += vdso_install 81PHONY += vdso_install
77vdso_install: 82vdso_install:
@@ -85,6 +90,7 @@ define archhelp
85 echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)' 90 echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
86 echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)' 91 echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
87 echo '* dtbs - Build device tree blobs for enabled boards' 92 echo '* dtbs - Build device tree blobs for enabled boards'
93 echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'
88 echo ' install - Install uncompressed kernel' 94 echo ' install - Install uncompressed kernel'
89 echo ' zinstall - Install compressed kernel' 95 echo ' zinstall - Install compressed kernel'
90 echo ' Install using (your) ~/bin/installkernel or' 96 echo ' Install using (your) ~/bin/installkernel or'
diff --git a/arch/arm64/boot/dts/Makefile b/arch/arm64/boot/dts/Makefile
index f8001a62029c..e8efc8ff3d58 100644
--- a/arch/arm64/boot/dts/Makefile
+++ b/arch/arm64/boot/dts/Makefile
@@ -1,10 +1,7 @@
1dtb-$(CONFIG_ARCH_THUNDER) += thunder-88xx.dtb 1dts-dirs += apm
2dtb-$(CONFIG_ARCH_VEXPRESS) += rtsm_ve-aemv8a.dtb foundation-v8.dtb 2dts-dirs += arm
3dtb-$(CONFIG_ARCH_XGENE) += apm-mustang.dtb 3dts-dirs += cavium
4 4
5targets += dtbs 5always := $(dtb-y)
6targets += $(dtb-y) 6subdir-y := $(dts-dirs)
7 7clean-files := *.dtb
8dtbs: $(addprefix $(obj)/, $(dtb-y))
9
10clean-files := *.dtb
diff --git a/arch/arm64/boot/dts/apm/Makefile b/arch/arm64/boot/dts/apm/Makefile
new file mode 100644
index 000000000000..a2afabbc1717
--- /dev/null
+++ b/arch/arm64/boot/dts/apm/Makefile
@@ -0,0 +1,5 @@
1dtb-$(CONFIG_ARCH_XGENE) += apm-mustang.dtb
2
3always := $(dtb-y)
4subdir-y := $(dts-dirs)
5clean-files := *.dtb
diff --git a/arch/arm64/boot/dts/apm-mustang.dts b/arch/arm64/boot/dts/apm/apm-mustang.dts
index 2e25de0800b9..2e25de0800b9 100644
--- a/arch/arm64/boot/dts/apm-mustang.dts
+++ b/arch/arm64/boot/dts/apm/apm-mustang.dts
diff --git a/arch/arm64/boot/dts/apm-storm.dtsi b/arch/arm64/boot/dts/apm/apm-storm.dtsi
index 295c72d52a1f..f1ad9c2ab2e9 100644
--- a/arch/arm64/boot/dts/apm-storm.dtsi
+++ b/arch/arm64/boot/dts/apm/apm-storm.dtsi
@@ -599,7 +599,7 @@
599 compatible = "apm,xgene-enet"; 599 compatible = "apm,xgene-enet";
600 status = "disabled"; 600 status = "disabled";
601 reg = <0x0 0x17020000 0x0 0xd100>, 601 reg = <0x0 0x17020000 0x0 0xd100>,
602 <0x0 0X17030000 0x0 0X400>, 602 <0x0 0X17030000 0x0 0Xc300>,
603 <0x0 0X10000000 0x0 0X200>; 603 <0x0 0X10000000 0x0 0X200>;
604 reg-names = "enet_csr", "ring_csr", "ring_cmd"; 604 reg-names = "enet_csr", "ring_csr", "ring_cmd";
605 interrupts = <0x0 0x3c 0x4>; 605 interrupts = <0x0 0x3c 0x4>;
@@ -624,9 +624,9 @@
624 sgenet0: ethernet@1f210000 { 624 sgenet0: ethernet@1f210000 {
625 compatible = "apm,xgene-enet"; 625 compatible = "apm,xgene-enet";
626 status = "disabled"; 626 status = "disabled";
627 reg = <0x0 0x1f210000 0x0 0x10000>, 627 reg = <0x0 0x1f210000 0x0 0xd100>,
628 <0x0 0x1f200000 0x0 0X10000>, 628 <0x0 0x1f200000 0x0 0Xc300>,
629 <0x0 0x1B000000 0x0 0X20000>; 629 <0x0 0x1B000000 0x0 0X200>;
630 reg-names = "enet_csr", "ring_csr", "ring_cmd"; 630 reg-names = "enet_csr", "ring_csr", "ring_cmd";
631 interrupts = <0x0 0xA0 0x4>; 631 interrupts = <0x0 0xA0 0x4>;
632 dma-coherent; 632 dma-coherent;
@@ -639,7 +639,7 @@
639 compatible = "apm,xgene-enet"; 639 compatible = "apm,xgene-enet";
640 status = "disabled"; 640 status = "disabled";
641 reg = <0x0 0x1f610000 0x0 0xd100>, 641 reg = <0x0 0x1f610000 0x0 0xd100>,
642 <0x0 0x1f600000 0x0 0X400>, 642 <0x0 0x1f600000 0x0 0Xc300>,
643 <0x0 0x18000000 0x0 0X200>; 643 <0x0 0x18000000 0x0 0X200>;
644 reg-names = "enet_csr", "ring_csr", "ring_cmd"; 644 reg-names = "enet_csr", "ring_csr", "ring_cmd";
645 interrupts = <0x0 0x60 0x4>; 645 interrupts = <0x0 0x60 0x4>;
diff --git a/arch/arm64/boot/dts/arm/Makefile b/arch/arm64/boot/dts/arm/Makefile
new file mode 100644
index 000000000000..43d1404bb3c1
--- /dev/null
+++ b/arch/arm64/boot/dts/arm/Makefile
@@ -0,0 +1,6 @@
1dtb-$(CONFIG_ARCH_VEXPRESS) += foundation-v8.dtb
2dtb-$(CONFIG_ARCH_VEXPRESS) += rtsm_ve-aemv8a.dtb
3
4always := $(dtb-y)
5subdir-y := $(dts-dirs)
6clean-files := *.dtb
diff --git a/arch/arm64/boot/dts/foundation-v8.dts b/arch/arm64/boot/dts/arm/foundation-v8.dts
index 4a060906809d..4a060906809d 100644
--- a/arch/arm64/boot/dts/foundation-v8.dts
+++ b/arch/arm64/boot/dts/arm/foundation-v8.dts
diff --git a/arch/arm64/boot/dts/rtsm_ve-aemv8a.dts b/arch/arm64/boot/dts/arm/rtsm_ve-aemv8a.dts
index 572005ea2217..572005ea2217 100644
--- a/arch/arm64/boot/dts/rtsm_ve-aemv8a.dts
+++ b/arch/arm64/boot/dts/arm/rtsm_ve-aemv8a.dts
diff --git a/arch/arm64/boot/dts/rtsm_ve-motherboard.dtsi b/arch/arm64/boot/dts/arm/rtsm_ve-motherboard.dtsi
index c46cbb29f3c6..c46cbb29f3c6 100644
--- a/arch/arm64/boot/dts/rtsm_ve-motherboard.dtsi
+++ b/arch/arm64/boot/dts/arm/rtsm_ve-motherboard.dtsi
diff --git a/arch/arm64/boot/dts/cavium/Makefile b/arch/arm64/boot/dts/cavium/Makefile
new file mode 100644
index 000000000000..e34f89ddabb2
--- /dev/null
+++ b/arch/arm64/boot/dts/cavium/Makefile
@@ -0,0 +1,5 @@
1dtb-$(CONFIG_ARCH_THUNDER) += thunder-88xx.dtb
2
3always := $(dtb-y)
4subdir-y := $(dts-dirs)
5clean-files := *.dtb
diff --git a/arch/arm64/boot/dts/thunder-88xx.dts b/arch/arm64/boot/dts/cavium/thunder-88xx.dts
index 800ba65991f7..800ba65991f7 100644
--- a/arch/arm64/boot/dts/thunder-88xx.dts
+++ b/arch/arm64/boot/dts/cavium/thunder-88xx.dts
diff --git a/arch/arm64/boot/dts/thunder-88xx.dtsi b/arch/arm64/boot/dts/cavium/thunder-88xx.dtsi
index d8c0bdc51882..d8c0bdc51882 100644
--- a/arch/arm64/boot/dts/thunder-88xx.dtsi
+++ b/arch/arm64/boot/dts/cavium/thunder-88xx.dtsi
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index 4ce602c2c6de..dd301be89ecc 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -35,6 +35,9 @@ CONFIG_MODULE_UNLOAD=y
35CONFIG_ARCH_THUNDER=y 35CONFIG_ARCH_THUNDER=y
36CONFIG_ARCH_VEXPRESS=y 36CONFIG_ARCH_VEXPRESS=y
37CONFIG_ARCH_XGENE=y 37CONFIG_ARCH_XGENE=y
38CONFIG_PCI=y
39CONFIG_PCI_MSI=y
40CONFIG_PCI_XGENE=y
38CONFIG_SMP=y 41CONFIG_SMP=y
39CONFIG_PREEMPT=y 42CONFIG_PREEMPT=y
40CONFIG_KSM=y 43CONFIG_KSM=y
@@ -52,6 +55,7 @@ CONFIG_IP_PNP_DHCP=y
52CONFIG_IP_PNP_BOOTP=y 55CONFIG_IP_PNP_BOOTP=y
53# CONFIG_INET_LRO is not set 56# CONFIG_INET_LRO is not set
54# CONFIG_IPV6 is not set 57# CONFIG_IPV6 is not set
58CONFIG_BPF_JIT=y
55# CONFIG_WIRELESS is not set 59# CONFIG_WIRELESS is not set
56CONFIG_NET_9P=y 60CONFIG_NET_9P=y
57CONFIG_NET_9P_VIRTIO=y 61CONFIG_NET_9P_VIRTIO=y
@@ -65,16 +69,17 @@ CONFIG_VIRTIO_BLK=y
65CONFIG_BLK_DEV_SD=y 69CONFIG_BLK_DEV_SD=y
66# CONFIG_SCSI_LOWLEVEL is not set 70# CONFIG_SCSI_LOWLEVEL is not set
67CONFIG_ATA=y 71CONFIG_ATA=y
72CONFIG_SATA_AHCI=y
73CONFIG_SATA_AHCI_PLATFORM=y
68CONFIG_AHCI_XGENE=y 74CONFIG_AHCI_XGENE=y
69CONFIG_PHY_XGENE=y
70CONFIG_PATA_PLATFORM=y 75CONFIG_PATA_PLATFORM=y
71CONFIG_PATA_OF_PLATFORM=y 76CONFIG_PATA_OF_PLATFORM=y
72CONFIG_NETDEVICES=y 77CONFIG_NETDEVICES=y
73CONFIG_TUN=y 78CONFIG_TUN=y
74CONFIG_VIRTIO_NET=y 79CONFIG_VIRTIO_NET=y
80CONFIG_NET_XGENE=y
75CONFIG_SMC91X=y 81CONFIG_SMC91X=y
76CONFIG_SMSC911X=y 82CONFIG_SMSC911X=y
77CONFIG_NET_XGENE=y
78# CONFIG_WLAN is not set 83# CONFIG_WLAN is not set
79CONFIG_INPUT_EVDEV=y 84CONFIG_INPUT_EVDEV=y
80# CONFIG_SERIO_SERPORT is not set 85# CONFIG_SERIO_SERPORT is not set
@@ -87,6 +92,11 @@ CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
87CONFIG_SERIAL_OF_PLATFORM=y 92CONFIG_SERIAL_OF_PLATFORM=y
88CONFIG_VIRTIO_CONSOLE=y 93CONFIG_VIRTIO_CONSOLE=y
89# CONFIG_HW_RANDOM is not set 94# CONFIG_HW_RANDOM is not set
95# CONFIG_HMC_DRV is not set
96CONFIG_SPI=y
97CONFIG_SPI_PL022=y
98CONFIG_GPIO_PL061=y
99CONFIG_GPIO_XGENE=y
90# CONFIG_HWMON is not set 100# CONFIG_HWMON is not set
91CONFIG_REGULATOR=y 101CONFIG_REGULATOR=y
92CONFIG_REGULATOR_FIXED_VOLTAGE=y 102CONFIG_REGULATOR_FIXED_VOLTAGE=y
@@ -97,13 +107,25 @@ CONFIG_LOGO=y
97# CONFIG_LOGO_LINUX_MONO is not set 107# CONFIG_LOGO_LINUX_MONO is not set
98# CONFIG_LOGO_LINUX_VGA16 is not set 108# CONFIG_LOGO_LINUX_VGA16 is not set
99CONFIG_USB=y 109CONFIG_USB=y
110CONFIG_USB_EHCI_HCD=y
111CONFIG_USB_EHCI_HCD_PLATFORM=y
100CONFIG_USB_ISP1760_HCD=y 112CONFIG_USB_ISP1760_HCD=y
113CONFIG_USB_OHCI_HCD=y
114CONFIG_USB_OHCI_HCD_PLATFORM=y
101CONFIG_USB_STORAGE=y 115CONFIG_USB_STORAGE=y
116CONFIG_USB_ULPI=y
102CONFIG_MMC=y 117CONFIG_MMC=y
103CONFIG_MMC_ARMMMCI=y 118CONFIG_MMC_ARMMMCI=y
119CONFIG_MMC_SDHCI=y
120CONFIG_MMC_SDHCI_PLTFM=y
121CONFIG_MMC_SPI=y
122CONFIG_RTC_CLASS=y
123CONFIG_RTC_DRV_EFI=y
124CONFIG_RTC_DRV_XGENE=y
104CONFIG_VIRTIO_BALLOON=y 125CONFIG_VIRTIO_BALLOON=y
105CONFIG_VIRTIO_MMIO=y 126CONFIG_VIRTIO_MMIO=y
106# CONFIG_IOMMU_SUPPORT is not set 127# CONFIG_IOMMU_SUPPORT is not set
128CONFIG_PHY_XGENE=y
107CONFIG_EXT2_FS=y 129CONFIG_EXT2_FS=y
108CONFIG_EXT3_FS=y 130CONFIG_EXT3_FS=y
109# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set 131# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
diff --git a/arch/arm64/crypto/Kconfig b/arch/arm64/crypto/Kconfig
index 5562652c5316..a38b02ce5f9a 100644
--- a/arch/arm64/crypto/Kconfig
+++ b/arch/arm64/crypto/Kconfig
@@ -27,20 +27,19 @@ config CRYPTO_AES_ARM64_CE
27 tristate "AES core cipher using ARMv8 Crypto Extensions" 27 tristate "AES core cipher using ARMv8 Crypto Extensions"
28 depends on ARM64 && KERNEL_MODE_NEON 28 depends on ARM64 && KERNEL_MODE_NEON
29 select CRYPTO_ALGAPI 29 select CRYPTO_ALGAPI
30 select CRYPTO_AES
31 30
32config CRYPTO_AES_ARM64_CE_CCM 31config CRYPTO_AES_ARM64_CE_CCM
33 tristate "AES in CCM mode using ARMv8 Crypto Extensions" 32 tristate "AES in CCM mode using ARMv8 Crypto Extensions"
34 depends on ARM64 && KERNEL_MODE_NEON 33 depends on ARM64 && KERNEL_MODE_NEON
35 select CRYPTO_ALGAPI 34 select CRYPTO_ALGAPI
36 select CRYPTO_AES 35 select CRYPTO_AES_ARM64_CE
37 select CRYPTO_AEAD 36 select CRYPTO_AEAD
38 37
39config CRYPTO_AES_ARM64_CE_BLK 38config CRYPTO_AES_ARM64_CE_BLK
40 tristate "AES in ECB/CBC/CTR/XTS modes using ARMv8 Crypto Extensions" 39 tristate "AES in ECB/CBC/CTR/XTS modes using ARMv8 Crypto Extensions"
41 depends on ARM64 && KERNEL_MODE_NEON 40 depends on ARM64 && KERNEL_MODE_NEON
42 select CRYPTO_BLKCIPHER 41 select CRYPTO_BLKCIPHER
43 select CRYPTO_AES 42 select CRYPTO_AES_ARM64_CE
44 select CRYPTO_ABLK_HELPER 43 select CRYPTO_ABLK_HELPER
45 44
46config CRYPTO_AES_ARM64_NEON_BLK 45config CRYPTO_AES_ARM64_NEON_BLK
diff --git a/arch/arm64/crypto/aes-ce-ccm-glue.c b/arch/arm64/crypto/aes-ce-ccm-glue.c
index 9e6cdde9b43d..0ac73b838fa3 100644
--- a/arch/arm64/crypto/aes-ce-ccm-glue.c
+++ b/arch/arm64/crypto/aes-ce-ccm-glue.c
@@ -16,6 +16,8 @@
16#include <linux/crypto.h> 16#include <linux/crypto.h>
17#include <linux/module.h> 17#include <linux/module.h>
18 18
19#include "aes-ce-setkey.h"
20
19static int num_rounds(struct crypto_aes_ctx *ctx) 21static int num_rounds(struct crypto_aes_ctx *ctx)
20{ 22{
21 /* 23 /*
@@ -48,7 +50,7 @@ static int ccm_setkey(struct crypto_aead *tfm, const u8 *in_key,
48 struct crypto_aes_ctx *ctx = crypto_aead_ctx(tfm); 50 struct crypto_aes_ctx *ctx = crypto_aead_ctx(tfm);
49 int ret; 51 int ret;
50 52
51 ret = crypto_aes_expand_key(ctx, in_key, key_len); 53 ret = ce_aes_expandkey(ctx, in_key, key_len);
52 if (!ret) 54 if (!ret)
53 return 0; 55 return 0;
54 56
diff --git a/arch/arm64/crypto/aes-ce-cipher.c b/arch/arm64/crypto/aes-ce-cipher.c
index 2075e1acae6b..ce47792a983d 100644
--- a/arch/arm64/crypto/aes-ce-cipher.c
+++ b/arch/arm64/crypto/aes-ce-cipher.c
@@ -14,6 +14,8 @@
14#include <linux/crypto.h> 14#include <linux/crypto.h>
15#include <linux/module.h> 15#include <linux/module.h>
16 16
17#include "aes-ce-setkey.h"
18
17MODULE_DESCRIPTION("Synchronous AES cipher using ARMv8 Crypto Extensions"); 19MODULE_DESCRIPTION("Synchronous AES cipher using ARMv8 Crypto Extensions");
18MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>"); 20MODULE_AUTHOR("Ard Biesheuvel <ard.biesheuvel@linaro.org>");
19MODULE_LICENSE("GPL v2"); 21MODULE_LICENSE("GPL v2");
@@ -124,6 +126,114 @@ static void aes_cipher_decrypt(struct crypto_tfm *tfm, u8 dst[], u8 const src[])
124 kernel_neon_end(); 126 kernel_neon_end();
125} 127}
126 128
129/*
130 * aes_sub() - use the aese instruction to perform the AES sbox substitution
131 * on each byte in 'input'
132 */
133static u32 aes_sub(u32 input)
134{
135 u32 ret;
136
137 __asm__("dup v1.4s, %w[in] ;"
138 "movi v0.16b, #0 ;"
139 "aese v0.16b, v1.16b ;"
140 "umov %w[out], v0.4s[0] ;"
141
142 : [out] "=r"(ret)
143 : [in] "r"(input)
144 : "v0","v1");
145
146 return ret;
147}
148
149int ce_aes_expandkey(struct crypto_aes_ctx *ctx, const u8 *in_key,
150 unsigned int key_len)
151{
152 /*
153 * The AES key schedule round constants
154 */
155 static u8 const rcon[] = {
156 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36,
157 };
158
159 u32 kwords = key_len / sizeof(u32);
160 struct aes_block *key_enc, *key_dec;
161 int i, j;
162
163 if (key_len != AES_KEYSIZE_128 &&
164 key_len != AES_KEYSIZE_192 &&
165 key_len != AES_KEYSIZE_256)
166 return -EINVAL;
167
168 memcpy(ctx->key_enc, in_key, key_len);
169 ctx->key_length = key_len;
170
171 kernel_neon_begin_partial(2);
172 for (i = 0; i < sizeof(rcon); i++) {
173 u32 *rki = ctx->key_enc + (i * kwords);
174 u32 *rko = rki + kwords;
175
176 rko[0] = ror32(aes_sub(rki[kwords - 1]), 8) ^ rcon[i] ^ rki[0];
177 rko[1] = rko[0] ^ rki[1];
178 rko[2] = rko[1] ^ rki[2];
179 rko[3] = rko[2] ^ rki[3];
180
181 if (key_len == AES_KEYSIZE_192) {
182 if (i >= 7)
183 break;
184 rko[4] = rko[3] ^ rki[4];
185 rko[5] = rko[4] ^ rki[5];
186 } else if (key_len == AES_KEYSIZE_256) {
187 if (i >= 6)
188 break;
189 rko[4] = aes_sub(rko[3]) ^ rki[4];
190 rko[5] = rko[4] ^ rki[5];
191 rko[6] = rko[5] ^ rki[6];
192 rko[7] = rko[6] ^ rki[7];
193 }
194 }
195
196 /*
197 * Generate the decryption keys for the Equivalent Inverse Cipher.
198 * This involves reversing the order of the round keys, and applying
199 * the Inverse Mix Columns transformation on all but the first and
200 * the last one.
201 */
202 key_enc = (struct aes_block *)ctx->key_enc;
203 key_dec = (struct aes_block *)ctx->key_dec;
204 j = num_rounds(ctx);
205
206 key_dec[0] = key_enc[j];
207 for (i = 1, j--; j > 0; i++, j--)
208 __asm__("ld1 {v0.16b}, %[in] ;"
209 "aesimc v1.16b, v0.16b ;"
210 "st1 {v1.16b}, %[out] ;"
211
212 : [out] "=Q"(key_dec[i])
213 : [in] "Q"(key_enc[j])
214 : "v0","v1");
215 key_dec[i] = key_enc[0];
216
217 kernel_neon_end();
218 return 0;
219}
220EXPORT_SYMBOL(ce_aes_expandkey);
221
222int ce_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,
223 unsigned int key_len)
224{
225 struct crypto_aes_ctx *ctx = crypto_tfm_ctx(tfm);
226 int ret;
227
228 ret = ce_aes_expandkey(ctx, in_key, key_len);
229 if (!ret)
230 return 0;
231
232 tfm->crt_flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
233 return -EINVAL;
234}
235EXPORT_SYMBOL(ce_aes_setkey);
236
127static struct crypto_alg aes_alg = { 237static struct crypto_alg aes_alg = {
128 .cra_name = "aes", 238 .cra_name = "aes",
129 .cra_driver_name = "aes-ce", 239 .cra_driver_name = "aes-ce",
@@ -135,7 +245,7 @@ static struct crypto_alg aes_alg = {
135 .cra_cipher = { 245 .cra_cipher = {
136 .cia_min_keysize = AES_MIN_KEY_SIZE, 246 .cia_min_keysize = AES_MIN_KEY_SIZE,
137 .cia_max_keysize = AES_MAX_KEY_SIZE, 247 .cia_max_keysize = AES_MAX_KEY_SIZE,
138 .cia_setkey = crypto_aes_set_key, 248 .cia_setkey = ce_aes_setkey,
139 .cia_encrypt = aes_cipher_encrypt, 249 .cia_encrypt = aes_cipher_encrypt,
140 .cia_decrypt = aes_cipher_decrypt 250 .cia_decrypt = aes_cipher_decrypt
141 } 251 }
diff --git a/arch/arm64/crypto/aes-ce-setkey.h b/arch/arm64/crypto/aes-ce-setkey.h
new file mode 100644
index 000000000000..f08a6471d034
--- /dev/null
+++ b/arch/arm64/crypto/aes-ce-setkey.h
@@ -0,0 +1,5 @@
1
2int ce_aes_setkey(struct crypto_tfm *tfm, const u8 *in_key,
3 unsigned int key_len);
4int ce_aes_expandkey(struct crypto_aes_ctx *ctx, const u8 *in_key,
5 unsigned int key_len);
diff --git a/arch/arm64/crypto/aes-glue.c b/arch/arm64/crypto/aes-glue.c
index 79cd911ef88c..801aae32841f 100644
--- a/arch/arm64/crypto/aes-glue.c
+++ b/arch/arm64/crypto/aes-glue.c
@@ -16,9 +16,13 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/cpufeature.h> 17#include <linux/cpufeature.h>
18 18
19#include "aes-ce-setkey.h"
20
19#ifdef USE_V8_CRYPTO_EXTENSIONS 21#ifdef USE_V8_CRYPTO_EXTENSIONS
20#define MODE "ce" 22#define MODE "ce"
21#define PRIO 300 23#define PRIO 300
24#define aes_setkey ce_aes_setkey
25#define aes_expandkey ce_aes_expandkey
22#define aes_ecb_encrypt ce_aes_ecb_encrypt 26#define aes_ecb_encrypt ce_aes_ecb_encrypt
23#define aes_ecb_decrypt ce_aes_ecb_decrypt 27#define aes_ecb_decrypt ce_aes_ecb_decrypt
24#define aes_cbc_encrypt ce_aes_cbc_encrypt 28#define aes_cbc_encrypt ce_aes_cbc_encrypt
@@ -30,6 +34,8 @@ MODULE_DESCRIPTION("AES-ECB/CBC/CTR/XTS using ARMv8 Crypto Extensions");
30#else 34#else
31#define MODE "neon" 35#define MODE "neon"
32#define PRIO 200 36#define PRIO 200
37#define aes_setkey crypto_aes_set_key
38#define aes_expandkey crypto_aes_expand_key
33#define aes_ecb_encrypt neon_aes_ecb_encrypt 39#define aes_ecb_encrypt neon_aes_ecb_encrypt
34#define aes_ecb_decrypt neon_aes_ecb_decrypt 40#define aes_ecb_decrypt neon_aes_ecb_decrypt
35#define aes_cbc_encrypt neon_aes_cbc_encrypt 41#define aes_cbc_encrypt neon_aes_cbc_encrypt
@@ -79,10 +85,10 @@ static int xts_set_key(struct crypto_tfm *tfm, const u8 *in_key,
79 struct crypto_aes_xts_ctx *ctx = crypto_tfm_ctx(tfm); 85 struct crypto_aes_xts_ctx *ctx = crypto_tfm_ctx(tfm);
80 int ret; 86 int ret;
81 87
82 ret = crypto_aes_expand_key(&ctx->key1, in_key, key_len / 2); 88 ret = aes_expandkey(&ctx->key1, in_key, key_len / 2);
83 if (!ret) 89 if (!ret)
84 ret = crypto_aes_expand_key(&ctx->key2, &in_key[key_len / 2], 90 ret = aes_expandkey(&ctx->key2, &in_key[key_len / 2],
85 key_len / 2); 91 key_len / 2);
86 if (!ret) 92 if (!ret)
87 return 0; 93 return 0;
88 94
@@ -288,7 +294,7 @@ static struct crypto_alg aes_algs[] = { {
288 .min_keysize = AES_MIN_KEY_SIZE, 294 .min_keysize = AES_MIN_KEY_SIZE,
289 .max_keysize = AES_MAX_KEY_SIZE, 295 .max_keysize = AES_MAX_KEY_SIZE,
290 .ivsize = AES_BLOCK_SIZE, 296 .ivsize = AES_BLOCK_SIZE,
291 .setkey = crypto_aes_set_key, 297 .setkey = aes_setkey,
292 .encrypt = ecb_encrypt, 298 .encrypt = ecb_encrypt,
293 .decrypt = ecb_decrypt, 299 .decrypt = ecb_decrypt,
294 }, 300 },
@@ -306,7 +312,7 @@ static struct crypto_alg aes_algs[] = { {
306 .min_keysize = AES_MIN_KEY_SIZE, 312 .min_keysize = AES_MIN_KEY_SIZE,
307 .max_keysize = AES_MAX_KEY_SIZE, 313 .max_keysize = AES_MAX_KEY_SIZE,
308 .ivsize = AES_BLOCK_SIZE, 314 .ivsize = AES_BLOCK_SIZE,
309 .setkey = crypto_aes_set_key, 315 .setkey = aes_setkey,
310 .encrypt = cbc_encrypt, 316 .encrypt = cbc_encrypt,
311 .decrypt = cbc_decrypt, 317 .decrypt = cbc_decrypt,
312 }, 318 },
@@ -324,7 +330,7 @@ static struct crypto_alg aes_algs[] = { {
324 .min_keysize = AES_MIN_KEY_SIZE, 330 .min_keysize = AES_MIN_KEY_SIZE,
325 .max_keysize = AES_MAX_KEY_SIZE, 331 .max_keysize = AES_MAX_KEY_SIZE,
326 .ivsize = AES_BLOCK_SIZE, 332 .ivsize = AES_BLOCK_SIZE,
327 .setkey = crypto_aes_set_key, 333 .setkey = aes_setkey,
328 .encrypt = ctr_encrypt, 334 .encrypt = ctr_encrypt,
329 .decrypt = ctr_encrypt, 335 .decrypt = ctr_encrypt,
330 }, 336 },
diff --git a/arch/arm64/include/asm/alternative-asm.h b/arch/arm64/include/asm/alternative-asm.h
new file mode 100644
index 000000000000..919a67855b63
--- /dev/null
+++ b/arch/arm64/include/asm/alternative-asm.h
@@ -0,0 +1,29 @@
1#ifndef __ASM_ALTERNATIVE_ASM_H
2#define __ASM_ALTERNATIVE_ASM_H
3
4#ifdef __ASSEMBLY__
5
6.macro altinstruction_entry orig_offset alt_offset feature orig_len alt_len
7 .word \orig_offset - .
8 .word \alt_offset - .
9 .hword \feature
10 .byte \orig_len
11 .byte \alt_len
12.endm
13
14.macro alternative_insn insn1 insn2 cap
15661: \insn1
16662: .pushsection .altinstructions, "a"
17 altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f
18 .popsection
19 .pushsection .altinstr_replacement, "ax"
20663: \insn2
21664: .popsection
22 .if ((664b-663b) != (662b-661b))
23 .error "Alternatives instruction length mismatch"
24 .endif
25.endm
26
27#endif /* __ASSEMBLY__ */
28
29#endif /* __ASM_ALTERNATIVE_ASM_H */
diff --git a/arch/arm64/include/asm/alternative.h b/arch/arm64/include/asm/alternative.h
new file mode 100644
index 000000000000..d261f01e2bae
--- /dev/null
+++ b/arch/arm64/include/asm/alternative.h
@@ -0,0 +1,44 @@
1#ifndef __ASM_ALTERNATIVE_H
2#define __ASM_ALTERNATIVE_H
3
4#include <linux/types.h>
5#include <linux/stddef.h>
6#include <linux/stringify.h>
7
8struct alt_instr {
9 s32 orig_offset; /* offset to original instruction */
10 s32 alt_offset; /* offset to replacement instruction */
11 u16 cpufeature; /* cpufeature bit set for replacement */
12 u8 orig_len; /* size of original instruction(s) */
13 u8 alt_len; /* size of new instruction(s), <= orig_len */
14};
15
16void apply_alternatives_all(void);
17void apply_alternatives(void *start, size_t length);
18void free_alternatives_memory(void);
19
20#define ALTINSTR_ENTRY(feature) \
21 " .word 661b - .\n" /* label */ \
22 " .word 663f - .\n" /* new instruction */ \
23 " .hword " __stringify(feature) "\n" /* feature bit */ \
24 " .byte 662b-661b\n" /* source len */ \
25 " .byte 664f-663f\n" /* replacement len */
26
27/* alternative assembly primitive: */
28#define ALTERNATIVE(oldinstr, newinstr, feature) \
29 "661:\n\t" \
30 oldinstr "\n" \
31 "662:\n" \
32 ".pushsection .altinstructions,\"a\"\n" \
33 ALTINSTR_ENTRY(feature) \
34 ".popsection\n" \
35 ".pushsection .altinstr_replacement, \"a\"\n" \
36 "663:\n\t" \
37 newinstr "\n" \
38 "664:\n\t" \
39 ".popsection\n\t" \
40 ".if ((664b-663b) != (662b-661b))\n\t" \
41 " .error \"Alternatives instruction length mismatch\"\n\t"\
42 ".endif\n"
43
44#endif /* __ASM_ALTERNATIVE_H */
diff --git a/arch/arm64/include/asm/cache.h b/arch/arm64/include/asm/cache.h
index 88cc05b5f3ac..bde449936e2f 100644
--- a/arch/arm64/include/asm/cache.h
+++ b/arch/arm64/include/asm/cache.h
@@ -32,6 +32,8 @@
32 32
33#ifndef __ASSEMBLY__ 33#ifndef __ASSEMBLY__
34 34
35#define __read_mostly __attribute__((__section__(".data..read_mostly")))
36
35static inline int cache_line_size(void) 37static inline int cache_line_size(void)
36{ 38{
37 u32 cwg = cache_type_cwg(); 39 u32 cwg = cache_type_cwg();
diff --git a/arch/arm64/include/asm/cacheflush.h b/arch/arm64/include/asm/cacheflush.h
index 689b6379188c..7ae31a2cc6c0 100644
--- a/arch/arm64/include/asm/cacheflush.h
+++ b/arch/arm64/include/asm/cacheflush.h
@@ -73,7 +73,7 @@ extern void flush_cache_all(void);
73extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end); 73extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
74extern void flush_icache_range(unsigned long start, unsigned long end); 74extern void flush_icache_range(unsigned long start, unsigned long end);
75extern void __flush_dcache_area(void *addr, size_t len); 75extern void __flush_dcache_area(void *addr, size_t len);
76extern void __flush_cache_user_range(unsigned long start, unsigned long end); 76extern long __flush_cache_user_range(unsigned long start, unsigned long end);
77 77
78static inline void flush_cache_mm(struct mm_struct *mm) 78static inline void flush_cache_mm(struct mm_struct *mm)
79{ 79{
diff --git a/arch/arm64/include/asm/cmpxchg.h b/arch/arm64/include/asm/cmpxchg.h
index ddb9d7830558..cb9593079f29 100644
--- a/arch/arm64/include/asm/cmpxchg.h
+++ b/arch/arm64/include/asm/cmpxchg.h
@@ -19,6 +19,7 @@
19#define __ASM_CMPXCHG_H 19#define __ASM_CMPXCHG_H
20 20
21#include <linux/bug.h> 21#include <linux/bug.h>
22#include <linux/mmdebug.h>
22 23
23#include <asm/barrier.h> 24#include <asm/barrier.h>
24 25
@@ -152,6 +153,51 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
152 return oldval; 153 return oldval;
153} 154}
154 155
156#define system_has_cmpxchg_double() 1
157
158static inline int __cmpxchg_double(volatile void *ptr1, volatile void *ptr2,
159 unsigned long old1, unsigned long old2,
160 unsigned long new1, unsigned long new2, int size)
161{
162 unsigned long loop, lost;
163
164 switch (size) {
165 case 8:
166 VM_BUG_ON((unsigned long *)ptr2 - (unsigned long *)ptr1 != 1);
167 do {
168 asm volatile("// __cmpxchg_double8\n"
169 " ldxp %0, %1, %2\n"
170 " eor %0, %0, %3\n"
171 " eor %1, %1, %4\n"
172 " orr %1, %0, %1\n"
173 " mov %w0, #0\n"
174 " cbnz %1, 1f\n"
175 " stxp %w0, %5, %6, %2\n"
176 "1:\n"
177 : "=&r"(loop), "=&r"(lost), "+Q" (*(u64 *)ptr1)
178 : "r" (old1), "r"(old2), "r"(new1), "r"(new2));
179 } while (loop);
180 break;
181 default:
182 BUILD_BUG();
183 }
184
185 return !lost;
186}
187
188static inline int __cmpxchg_double_mb(volatile void *ptr1, volatile void *ptr2,
189 unsigned long old1, unsigned long old2,
190 unsigned long new1, unsigned long new2, int size)
191{
192 int ret;
193
194 smp_mb();
195 ret = __cmpxchg_double(ptr1, ptr2, old1, old2, new1, new2, size);
196 smp_mb();
197
198 return ret;
199}
200
155static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old, 201static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old,
156 unsigned long new, int size) 202 unsigned long new, int size)
157{ 203{
@@ -182,6 +228,33 @@ static inline unsigned long __cmpxchg_mb(volatile void *ptr, unsigned long old,
182 __ret; \ 228 __ret; \
183}) 229})
184 230
231#define cmpxchg_double(ptr1, ptr2, o1, o2, n1, n2) \
232({\
233 int __ret;\
234 __ret = __cmpxchg_double_mb((ptr1), (ptr2), (unsigned long)(o1), \
235 (unsigned long)(o2), (unsigned long)(n1), \
236 (unsigned long)(n2), sizeof(*(ptr1)));\
237 __ret; \
238})
239
240#define cmpxchg_double_local(ptr1, ptr2, o1, o2, n1, n2) \
241({\
242 int __ret;\
243 __ret = __cmpxchg_double((ptr1), (ptr2), (unsigned long)(o1), \
244 (unsigned long)(o2), (unsigned long)(n1), \
245 (unsigned long)(n2), sizeof(*(ptr1)));\
246 __ret; \
247})
248
249#define this_cpu_cmpxchg_1(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
250#define this_cpu_cmpxchg_2(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
251#define this_cpu_cmpxchg_4(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
252#define this_cpu_cmpxchg_8(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
253
254#define this_cpu_cmpxchg_double_8(ptr1, ptr2, o1, o2, n1, n2) \
255 cmpxchg_double_local(raw_cpu_ptr(&(ptr1)), raw_cpu_ptr(&(ptr2)), \
256 o1, o2, n1, n2)
257
185#define cmpxchg64(ptr,o,n) cmpxchg((ptr),(o),(n)) 258#define cmpxchg64(ptr,o,n) cmpxchg((ptr),(o),(n))
186#define cmpxchg64_local(ptr,o,n) cmpxchg_local((ptr),(o),(n)) 259#define cmpxchg64_local(ptr,o,n) cmpxchg_local((ptr),(o),(n))
187 260
diff --git a/arch/arm64/include/asm/compat.h b/arch/arm64/include/asm/compat.h
index 56de5aadede2..3fb053fa6e98 100644
--- a/arch/arm64/include/asm/compat.h
+++ b/arch/arm64/include/asm/compat.h
@@ -205,6 +205,13 @@ typedef struct compat_siginfo {
205 compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */ 205 compat_long_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */
206 int _fd; 206 int _fd;
207 } _sigpoll; 207 } _sigpoll;
208
209 /* SIGSYS */
210 struct {
211 compat_uptr_t _call_addr; /* calling user insn */
212 int _syscall; /* triggering system call number */
213 compat_uint_t _arch; /* AUDIT_ARCH_* of syscall */
214 } _sigsys;
208 } _sifields; 215 } _sifields;
209} compat_siginfo_t; 216} compat_siginfo_t;
210 217
diff --git a/arch/arm64/include/asm/cpu.h b/arch/arm64/include/asm/cpu.h
index 056443086019..ace70682499b 100644
--- a/arch/arm64/include/asm/cpu.h
+++ b/arch/arm64/include/asm/cpu.h
@@ -30,6 +30,8 @@ struct cpuinfo_arm64 {
30 u32 reg_dczid; 30 u32 reg_dczid;
31 u32 reg_midr; 31 u32 reg_midr;
32 32
33 u64 reg_id_aa64dfr0;
34 u64 reg_id_aa64dfr1;
33 u64 reg_id_aa64isar0; 35 u64 reg_id_aa64isar0;
34 u64 reg_id_aa64isar1; 36 u64 reg_id_aa64isar1;
35 u64 reg_id_aa64mmfr0; 37 u64 reg_id_aa64mmfr0;
diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h
index cd4ac0516488..07547ccc1f2b 100644
--- a/arch/arm64/include/asm/cpufeature.h
+++ b/arch/arm64/include/asm/cpufeature.h
@@ -21,9 +21,38 @@
21#define MAX_CPU_FEATURES (8 * sizeof(elf_hwcap)) 21#define MAX_CPU_FEATURES (8 * sizeof(elf_hwcap))
22#define cpu_feature(x) ilog2(HWCAP_ ## x) 22#define cpu_feature(x) ilog2(HWCAP_ ## x)
23 23
24#define ARM64_WORKAROUND_CLEAN_CACHE 0
25#define ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE 1
26
27#define ARM64_NCAPS 2
28
29#ifndef __ASSEMBLY__
30
31extern DECLARE_BITMAP(cpu_hwcaps, ARM64_NCAPS);
32
24static inline bool cpu_have_feature(unsigned int num) 33static inline bool cpu_have_feature(unsigned int num)
25{ 34{
26 return elf_hwcap & (1UL << num); 35 return elf_hwcap & (1UL << num);
27} 36}
28 37
38static inline bool cpus_have_cap(unsigned int num)
39{
40 if (num >= ARM64_NCAPS)
41 return false;
42 return test_bit(num, cpu_hwcaps);
43}
44
45static inline void cpus_set_cap(unsigned int num)
46{
47 if (num >= ARM64_NCAPS)
48 pr_warn("Attempt to set an illegal CPU capability (%d >= %d)\n",
49 num, ARM64_NCAPS);
50 else
51 __set_bit(num, cpu_hwcaps);
52}
53
54void check_local_cpu_errata(void);
55
56#endif /* __ASSEMBLY__ */
57
29#endif 58#endif
diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h
index 379d0b874328..8adb986a3086 100644
--- a/arch/arm64/include/asm/cputype.h
+++ b/arch/arm64/include/asm/cputype.h
@@ -57,6 +57,11 @@
57#define MIDR_IMPLEMENTOR(midr) \ 57#define MIDR_IMPLEMENTOR(midr) \
58 (((midr) & MIDR_IMPLEMENTOR_MASK) >> MIDR_IMPLEMENTOR_SHIFT) 58 (((midr) & MIDR_IMPLEMENTOR_MASK) >> MIDR_IMPLEMENTOR_SHIFT)
59 59
60#define MIDR_CPU_PART(imp, partnum) \
61 (((imp) << MIDR_IMPLEMENTOR_SHIFT) | \
62 (0xf << MIDR_ARCHITECTURE_SHIFT) | \
63 ((partnum) << MIDR_PARTNUM_SHIFT))
64
60#define ARM_CPU_IMP_ARM 0x41 65#define ARM_CPU_IMP_ARM 0x41
61#define ARM_CPU_IMP_APM 0x50 66#define ARM_CPU_IMP_APM 0x50
62 67
diff --git a/arch/arm64/include/asm/dmi.h b/arch/arm64/include/asm/dmi.h
new file mode 100644
index 000000000000..69d37d87b159
--- /dev/null
+++ b/arch/arm64/include/asm/dmi.h
@@ -0,0 +1,31 @@
1/*
2 * arch/arm64/include/asm/dmi.h
3 *
4 * Copyright (C) 2013 Linaro Limited.
5 * Written by: Yi Li (yi.li@linaro.org)
6 *
7 * based on arch/ia64/include/asm/dmi.h
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
13
14#ifndef __ASM_DMI_H
15#define __ASM_DMI_H
16
17#include <linux/io.h>
18#include <linux/slab.h>
19
20/*
21 * According to section 2.3.6 of the UEFI spec, the firmware should not
22 * request a virtual mapping for configuration tables such as SMBIOS.
23 * This means we have to map them before use.
24 */
25#define dmi_early_remap(x, l) ioremap_cache(x, l)
26#define dmi_early_unmap(x, l) iounmap(x)
27#define dmi_remap(x, l) ioremap_cache(x, l)
28#define dmi_unmap(x) iounmap(x)
29#define dmi_alloc(l) kzalloc(l, GFP_KERNEL)
30
31#endif
diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h
index 5f7bfe6df723..9ef6eca905ca 100644
--- a/arch/arm64/include/asm/fixmap.h
+++ b/arch/arm64/include/asm/fixmap.h
@@ -31,6 +31,7 @@
31 * 31 *
32 */ 32 */
33enum fixed_addresses { 33enum fixed_addresses {
34 FIX_HOLE,
34 FIX_EARLYCON_MEM_BASE, 35 FIX_EARLYCON_MEM_BASE,
35 __end_of_permanent_fixed_addresses, 36 __end_of_permanent_fixed_addresses,
36 37
@@ -56,10 +57,11 @@ enum fixed_addresses {
56 57
57#define FIXMAP_PAGE_IO __pgprot(PROT_DEVICE_nGnRE) 58#define FIXMAP_PAGE_IO __pgprot(PROT_DEVICE_nGnRE)
58 59
59extern void __early_set_fixmap(enum fixed_addresses idx, 60void __init early_fixmap_init(void);
60 phys_addr_t phys, pgprot_t flags);
61 61
62#define __set_fixmap __early_set_fixmap 62#define __early_set_fixmap __set_fixmap
63
64extern void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot);
63 65
64#include <asm-generic/fixmap.h> 66#include <asm-generic/fixmap.h>
65 67
diff --git a/arch/arm64/include/asm/hwcap.h b/arch/arm64/include/asm/hwcap.h
index 024c46183c3c..0ad735166d9f 100644
--- a/arch/arm64/include/asm/hwcap.h
+++ b/arch/arm64/include/asm/hwcap.h
@@ -30,6 +30,7 @@
30#define COMPAT_HWCAP_IDIVA (1 << 17) 30#define COMPAT_HWCAP_IDIVA (1 << 17)
31#define COMPAT_HWCAP_IDIVT (1 << 18) 31#define COMPAT_HWCAP_IDIVT (1 << 18)
32#define COMPAT_HWCAP_IDIV (COMPAT_HWCAP_IDIVA|COMPAT_HWCAP_IDIVT) 32#define COMPAT_HWCAP_IDIV (COMPAT_HWCAP_IDIVA|COMPAT_HWCAP_IDIVT)
33#define COMPAT_HWCAP_LPAE (1 << 20)
33#define COMPAT_HWCAP_EVTSTRM (1 << 21) 34#define COMPAT_HWCAP_EVTSTRM (1 << 21)
34 35
35#define COMPAT_HWCAP2_AES (1 << 0) 36#define COMPAT_HWCAP2_AES (1 << 0)
diff --git a/arch/arm64/include/asm/insn.h b/arch/arm64/include/asm/insn.h
index 56a9e63b6c33..e2ff32a93b5c 100644
--- a/arch/arm64/include/asm/insn.h
+++ b/arch/arm64/include/asm/insn.h
@@ -354,6 +354,16 @@ bool aarch64_insn_hotpatch_safe(u32 old_insn, u32 new_insn);
354int aarch64_insn_patch_text_nosync(void *addr, u32 insn); 354int aarch64_insn_patch_text_nosync(void *addr, u32 insn);
355int aarch64_insn_patch_text_sync(void *addrs[], u32 insns[], int cnt); 355int aarch64_insn_patch_text_sync(void *addrs[], u32 insns[], int cnt);
356int aarch64_insn_patch_text(void *addrs[], u32 insns[], int cnt); 356int aarch64_insn_patch_text(void *addrs[], u32 insns[], int cnt);
357
358bool aarch32_insn_is_wide(u32 insn);
359
360#define A32_RN_OFFSET 16
361#define A32_RT_OFFSET 12
362#define A32_RT2_OFFSET 0
363
364u32 aarch32_insn_extract_reg_num(u32 insn, int offset);
365u32 aarch32_insn_mcr_extract_opc2(u32 insn);
366u32 aarch32_insn_mcr_extract_crm(u32 insn);
357#endif /* __ASSEMBLY__ */ 367#endif /* __ASSEMBLY__ */
358 368
359#endif /* __ASM_INSN_H */ 369#endif /* __ASM_INSN_H */
diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
index 79f1d519221f..75825b63464d 100644
--- a/arch/arm64/include/asm/io.h
+++ b/arch/arm64/include/asm/io.h
@@ -28,6 +28,8 @@
28#include <asm/barrier.h> 28#include <asm/barrier.h>
29#include <asm/pgtable.h> 29#include <asm/pgtable.h>
30#include <asm/early_ioremap.h> 30#include <asm/early_ioremap.h>
31#include <asm/alternative.h>
32#include <asm/cpufeature.h>
31 33
32#include <xen/xen.h> 34#include <xen/xen.h>
33 35
@@ -57,28 +59,41 @@ static inline void __raw_writeq(u64 val, volatile void __iomem *addr)
57static inline u8 __raw_readb(const volatile void __iomem *addr) 59static inline u8 __raw_readb(const volatile void __iomem *addr)
58{ 60{
59 u8 val; 61 u8 val;
60 asm volatile("ldrb %w0, [%1]" : "=r" (val) : "r" (addr)); 62 asm volatile(ALTERNATIVE("ldrb %w0, [%1]",
63 "ldarb %w0, [%1]",
64 ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE)
65 : "=r" (val) : "r" (addr));
61 return val; 66 return val;
62} 67}
63 68
64static inline u16 __raw_readw(const volatile void __iomem *addr) 69static inline u16 __raw_readw(const volatile void __iomem *addr)
65{ 70{
66 u16 val; 71 u16 val;
67 asm volatile("ldrh %w0, [%1]" : "=r" (val) : "r" (addr)); 72
73 asm volatile(ALTERNATIVE("ldrh %w0, [%1]",
74 "ldarh %w0, [%1]",
75 ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE)
76 : "=r" (val) : "r" (addr));
68 return val; 77 return val;
69} 78}
70 79
71static inline u32 __raw_readl(const volatile void __iomem *addr) 80static inline u32 __raw_readl(const volatile void __iomem *addr)
72{ 81{
73 u32 val; 82 u32 val;
74 asm volatile("ldr %w0, [%1]" : "=r" (val) : "r" (addr)); 83 asm volatile(ALTERNATIVE("ldr %w0, [%1]",
84 "ldar %w0, [%1]",
85 ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE)
86 : "=r" (val) : "r" (addr));
75 return val; 87 return val;
76} 88}
77 89
78static inline u64 __raw_readq(const volatile void __iomem *addr) 90static inline u64 __raw_readq(const volatile void __iomem *addr)
79{ 91{
80 u64 val; 92 u64 val;
81 asm volatile("ldr %0, [%1]" : "=r" (val) : "r" (addr)); 93 asm volatile(ALTERNATIVE("ldr %0, [%1]",
94 "ldar %0, [%1]",
95 ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE)
96 : "=r" (val) : "r" (addr));
82 return val; 97 return val;
83} 98}
84 99
diff --git a/arch/arm64/include/asm/irq.h b/arch/arm64/include/asm/irq.h
index e1f7ecdde11f..94c53674a31d 100644
--- a/arch/arm64/include/asm/irq.h
+++ b/arch/arm64/include/asm/irq.h
@@ -3,7 +3,8 @@
3 3
4#include <asm-generic/irq.h> 4#include <asm-generic/irq.h>
5 5
6extern void (*handle_arch_irq)(struct pt_regs *); 6struct pt_regs;
7
7extern void migrate_irqs(void); 8extern void migrate_irqs(void);
8extern void set_handle_irq(void (*handle_irq)(struct pt_regs *)); 9extern void set_handle_irq(void (*handle_irq)(struct pt_regs *));
9 10
diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index 7fd3e27e3ccc..8afb863f5a9e 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -18,6 +18,7 @@
18#ifndef __ARM64_KVM_ARM_H__ 18#ifndef __ARM64_KVM_ARM_H__
19#define __ARM64_KVM_ARM_H__ 19#define __ARM64_KVM_ARM_H__
20 20
21#include <asm/memory.h>
21#include <asm/types.h> 22#include <asm/types.h>
22 23
23/* Hyp Configuration Register (HCR) bits */ 24/* Hyp Configuration Register (HCR) bits */
@@ -160,9 +161,9 @@
160#endif 161#endif
161 162
162#define VTTBR_BADDR_SHIFT (VTTBR_X - 1) 163#define VTTBR_BADDR_SHIFT (VTTBR_X - 1)
163#define VTTBR_BADDR_MASK (((1LLU << (PHYS_MASK_SHIFT - VTTBR_X)) - 1) << VTTBR_BADDR_SHIFT) 164#define VTTBR_BADDR_MASK (((UL(1) << (PHYS_MASK_SHIFT - VTTBR_X)) - 1) << VTTBR_BADDR_SHIFT)
164#define VTTBR_VMID_SHIFT (48LLU) 165#define VTTBR_VMID_SHIFT (UL(48))
165#define VTTBR_VMID_MASK (0xffLLU << VTTBR_VMID_SHIFT) 166#define VTTBR_VMID_MASK (UL(0xFF) << VTTBR_VMID_SHIFT)
166 167
167/* Hyp System Trap Register */ 168/* Hyp System Trap Register */
168#define HSTR_EL2_TTEE (1 << 16) 169#define HSTR_EL2_TTEE (1 << 16)
@@ -185,13 +186,13 @@
185 186
186/* Exception Syndrome Register (ESR) bits */ 187/* Exception Syndrome Register (ESR) bits */
187#define ESR_EL2_EC_SHIFT (26) 188#define ESR_EL2_EC_SHIFT (26)
188#define ESR_EL2_EC (0x3fU << ESR_EL2_EC_SHIFT) 189#define ESR_EL2_EC (UL(0x3f) << ESR_EL2_EC_SHIFT)
189#define ESR_EL2_IL (1U << 25) 190#define ESR_EL2_IL (UL(1) << 25)
190#define ESR_EL2_ISS (ESR_EL2_IL - 1) 191#define ESR_EL2_ISS (ESR_EL2_IL - 1)
191#define ESR_EL2_ISV_SHIFT (24) 192#define ESR_EL2_ISV_SHIFT (24)
192#define ESR_EL2_ISV (1U << ESR_EL2_ISV_SHIFT) 193#define ESR_EL2_ISV (UL(1) << ESR_EL2_ISV_SHIFT)
193#define ESR_EL2_SAS_SHIFT (22) 194#define ESR_EL2_SAS_SHIFT (22)
194#define ESR_EL2_SAS (3U << ESR_EL2_SAS_SHIFT) 195#define ESR_EL2_SAS (UL(3) << ESR_EL2_SAS_SHIFT)
195#define ESR_EL2_SSE (1 << 21) 196#define ESR_EL2_SSE (1 << 21)
196#define ESR_EL2_SRT_SHIFT (16) 197#define ESR_EL2_SRT_SHIFT (16)
197#define ESR_EL2_SRT_MASK (0x1f << ESR_EL2_SRT_SHIFT) 198#define ESR_EL2_SRT_MASK (0x1f << ESR_EL2_SRT_SHIFT)
@@ -205,16 +206,16 @@
205#define ESR_EL2_FSC_TYPE (0x3c) 206#define ESR_EL2_FSC_TYPE (0x3c)
206 207
207#define ESR_EL2_CV_SHIFT (24) 208#define ESR_EL2_CV_SHIFT (24)
208#define ESR_EL2_CV (1U << ESR_EL2_CV_SHIFT) 209#define ESR_EL2_CV (UL(1) << ESR_EL2_CV_SHIFT)
209#define ESR_EL2_COND_SHIFT (20) 210#define ESR_EL2_COND_SHIFT (20)
210#define ESR_EL2_COND (0xfU << ESR_EL2_COND_SHIFT) 211#define ESR_EL2_COND (UL(0xf) << ESR_EL2_COND_SHIFT)
211 212
212 213
213#define FSC_FAULT (0x04) 214#define FSC_FAULT (0x04)
214#define FSC_PERM (0x0c) 215#define FSC_PERM (0x0c)
215 216
216/* Hyp Prefetch Fault Address Register (HPFAR/HDFAR) */ 217/* Hyp Prefetch Fault Address Register (HPFAR/HDFAR) */
217#define HPFAR_MASK (~0xFUL) 218#define HPFAR_MASK (~UL(0xf))
218 219
219#define ESR_EL2_EC_UNKNOWN (0x00) 220#define ESR_EL2_EC_UNKNOWN (0x00)
220#define ESR_EL2_EC_WFI (0x01) 221#define ESR_EL2_EC_WFI (0x01)
diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h
index ccc7087d3c4e..a62cd077457b 100644
--- a/arch/arm64/include/asm/memory.h
+++ b/arch/arm64/include/asm/memory.h
@@ -142,7 +142,7 @@ static inline void *phys_to_virt(phys_addr_t x)
142 * virt_to_page(k) convert a _valid_ virtual address to struct page * 142 * virt_to_page(k) convert a _valid_ virtual address to struct page *
143 * virt_addr_valid(k) indicates whether a virtual address is valid 143 * virt_addr_valid(k) indicates whether a virtual address is valid
144 */ 144 */
145#define ARCH_PFN_OFFSET PHYS_PFN_OFFSET 145#define ARCH_PFN_OFFSET ((unsigned long)PHYS_PFN_OFFSET)
146 146
147#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 147#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
148#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) 148#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
diff --git a/arch/arm64/include/asm/opcodes.h b/arch/arm64/include/asm/opcodes.h
new file mode 100644
index 000000000000..4e603ea36ad3
--- /dev/null
+++ b/arch/arm64/include/asm/opcodes.h
@@ -0,0 +1 @@
#include <../../arm/include/asm/opcodes.h>
diff --git a/arch/arm64/include/asm/percpu.h b/arch/arm64/include/asm/percpu.h
index 5279e5733386..09da25bc596f 100644
--- a/arch/arm64/include/asm/percpu.h
+++ b/arch/arm64/include/asm/percpu.h
@@ -44,6 +44,221 @@ static inline unsigned long __my_cpu_offset(void)
44 44
45#endif /* CONFIG_SMP */ 45#endif /* CONFIG_SMP */
46 46
47#define PERCPU_OP(op, asm_op) \
48static inline unsigned long __percpu_##op(void *ptr, \
49 unsigned long val, int size) \
50{ \
51 unsigned long loop, ret; \
52 \
53 switch (size) { \
54 case 1: \
55 do { \
56 asm ("//__per_cpu_" #op "_1\n" \
57 "ldxrb %w[ret], %[ptr]\n" \
58 #asm_op " %w[ret], %w[ret], %w[val]\n" \
59 "stxrb %w[loop], %w[ret], %[ptr]\n" \
60 : [loop] "=&r" (loop), [ret] "=&r" (ret), \
61 [ptr] "+Q"(*(u8 *)ptr) \
62 : [val] "Ir" (val)); \
63 } while (loop); \
64 break; \
65 case 2: \
66 do { \
67 asm ("//__per_cpu_" #op "_2\n" \
68 "ldxrh %w[ret], %[ptr]\n" \
69 #asm_op " %w[ret], %w[ret], %w[val]\n" \
70 "stxrh %w[loop], %w[ret], %[ptr]\n" \
71 : [loop] "=&r" (loop), [ret] "=&r" (ret), \
72 [ptr] "+Q"(*(u16 *)ptr) \
73 : [val] "Ir" (val)); \
74 } while (loop); \
75 break; \
76 case 4: \
77 do { \
78 asm ("//__per_cpu_" #op "_4\n" \
79 "ldxr %w[ret], %[ptr]\n" \
80 #asm_op " %w[ret], %w[ret], %w[val]\n" \
81 "stxr %w[loop], %w[ret], %[ptr]\n" \
82 : [loop] "=&r" (loop), [ret] "=&r" (ret), \
83 [ptr] "+Q"(*(u32 *)ptr) \
84 : [val] "Ir" (val)); \
85 } while (loop); \
86 break; \
87 case 8: \
88 do { \
89 asm ("//__per_cpu_" #op "_8\n" \
90 "ldxr %[ret], %[ptr]\n" \
91 #asm_op " %[ret], %[ret], %[val]\n" \
92 "stxr %w[loop], %[ret], %[ptr]\n" \
93 : [loop] "=&r" (loop), [ret] "=&r" (ret), \
94 [ptr] "+Q"(*(u64 *)ptr) \
95 : [val] "Ir" (val)); \
96 } while (loop); \
97 break; \
98 default: \
99 BUILD_BUG(); \
100 } \
101 \
102 return ret; \
103}
104
105PERCPU_OP(add, add)
106PERCPU_OP(and, and)
107PERCPU_OP(or, orr)
108#undef PERCPU_OP
109
110static inline unsigned long __percpu_read(void *ptr, int size)
111{
112 unsigned long ret;
113
114 switch (size) {
115 case 1:
116 ret = ACCESS_ONCE(*(u8 *)ptr);
117 break;
118 case 2:
119 ret = ACCESS_ONCE(*(u16 *)ptr);
120 break;
121 case 4:
122 ret = ACCESS_ONCE(*(u32 *)ptr);
123 break;
124 case 8:
125 ret = ACCESS_ONCE(*(u64 *)ptr);
126 break;
127 default:
128 BUILD_BUG();
129 }
130
131 return ret;
132}
133
134static inline void __percpu_write(void *ptr, unsigned long val, int size)
135{
136 switch (size) {
137 case 1:
138 ACCESS_ONCE(*(u8 *)ptr) = (u8)val;
139 break;
140 case 2:
141 ACCESS_ONCE(*(u16 *)ptr) = (u16)val;
142 break;
143 case 4:
144 ACCESS_ONCE(*(u32 *)ptr) = (u32)val;
145 break;
146 case 8:
147 ACCESS_ONCE(*(u64 *)ptr) = (u64)val;
148 break;
149 default:
150 BUILD_BUG();
151 }
152}
153
154static inline unsigned long __percpu_xchg(void *ptr, unsigned long val,
155 int size)
156{
157 unsigned long ret, loop;
158
159 switch (size) {
160 case 1:
161 do {
162 asm ("//__percpu_xchg_1\n"
163 "ldxrb %w[ret], %[ptr]\n"
164 "stxrb %w[loop], %w[val], %[ptr]\n"
165 : [loop] "=&r"(loop), [ret] "=&r"(ret),
166 [ptr] "+Q"(*(u8 *)ptr)
167 : [val] "r" (val));
168 } while (loop);
169 break;
170 case 2:
171 do {
172 asm ("//__percpu_xchg_2\n"
173 "ldxrh %w[ret], %[ptr]\n"
174 "stxrh %w[loop], %w[val], %[ptr]\n"
175 : [loop] "=&r"(loop), [ret] "=&r"(ret),
176 [ptr] "+Q"(*(u16 *)ptr)
177 : [val] "r" (val));
178 } while (loop);
179 break;
180 case 4:
181 do {
182 asm ("//__percpu_xchg_4\n"
183 "ldxr %w[ret], %[ptr]\n"
184 "stxr %w[loop], %w[val], %[ptr]\n"
185 : [loop] "=&r"(loop), [ret] "=&r"(ret),
186 [ptr] "+Q"(*(u32 *)ptr)
187 : [val] "r" (val));
188 } while (loop);
189 break;
190 case 8:
191 do {
192 asm ("//__percpu_xchg_8\n"
193 "ldxr %[ret], %[ptr]\n"
194 "stxr %w[loop], %[val], %[ptr]\n"
195 : [loop] "=&r"(loop), [ret] "=&r"(ret),
196 [ptr] "+Q"(*(u64 *)ptr)
197 : [val] "r" (val));
198 } while (loop);
199 break;
200 default:
201 BUILD_BUG();
202 }
203
204 return ret;
205}
206
207#define _percpu_add(pcp, val) \
208 __percpu_add(raw_cpu_ptr(&(pcp)), val, sizeof(pcp))
209
210#define _percpu_add_return(pcp, val) (typeof(pcp)) (_percpu_add(pcp, val))
211
212#define _percpu_and(pcp, val) \
213 __percpu_and(raw_cpu_ptr(&(pcp)), val, sizeof(pcp))
214
215#define _percpu_or(pcp, val) \
216 __percpu_or(raw_cpu_ptr(&(pcp)), val, sizeof(pcp))
217
218#define _percpu_read(pcp) (typeof(pcp)) \
219 (__percpu_read(raw_cpu_ptr(&(pcp)), sizeof(pcp)))
220
221#define _percpu_write(pcp, val) \
222 __percpu_write(raw_cpu_ptr(&(pcp)), (unsigned long)(val), sizeof(pcp))
223
224#define _percpu_xchg(pcp, val) (typeof(pcp)) \
225 (__percpu_xchg(raw_cpu_ptr(&(pcp)), (unsigned long)(val), sizeof(pcp)))
226
227#define this_cpu_add_1(pcp, val) _percpu_add(pcp, val)
228#define this_cpu_add_2(pcp, val) _percpu_add(pcp, val)
229#define this_cpu_add_4(pcp, val) _percpu_add(pcp, val)
230#define this_cpu_add_8(pcp, val) _percpu_add(pcp, val)
231
232#define this_cpu_add_return_1(pcp, val) _percpu_add_return(pcp, val)
233#define this_cpu_add_return_2(pcp, val) _percpu_add_return(pcp, val)
234#define this_cpu_add_return_4(pcp, val) _percpu_add_return(pcp, val)
235#define this_cpu_add_return_8(pcp, val) _percpu_add_return(pcp, val)
236
237#define this_cpu_and_1(pcp, val) _percpu_and(pcp, val)
238#define this_cpu_and_2(pcp, val) _percpu_and(pcp, val)
239#define this_cpu_and_4(pcp, val) _percpu_and(pcp, val)
240#define this_cpu_and_8(pcp, val) _percpu_and(pcp, val)
241
242#define this_cpu_or_1(pcp, val) _percpu_or(pcp, val)
243#define this_cpu_or_2(pcp, val) _percpu_or(pcp, val)
244#define this_cpu_or_4(pcp, val) _percpu_or(pcp, val)
245#define this_cpu_or_8(pcp, val) _percpu_or(pcp, val)
246
247#define this_cpu_read_1(pcp) _percpu_read(pcp)
248#define this_cpu_read_2(pcp) _percpu_read(pcp)
249#define this_cpu_read_4(pcp) _percpu_read(pcp)
250#define this_cpu_read_8(pcp) _percpu_read(pcp)
251
252#define this_cpu_write_1(pcp, val) _percpu_write(pcp, val)
253#define this_cpu_write_2(pcp, val) _percpu_write(pcp, val)
254#define this_cpu_write_4(pcp, val) _percpu_write(pcp, val)
255#define this_cpu_write_8(pcp, val) _percpu_write(pcp, val)
256
257#define this_cpu_xchg_1(pcp, val) _percpu_xchg(pcp, val)
258#define this_cpu_xchg_2(pcp, val) _percpu_xchg(pcp, val)
259#define this_cpu_xchg_4(pcp, val) _percpu_xchg(pcp, val)
260#define this_cpu_xchg_8(pcp, val) _percpu_xchg(pcp, val)
261
47#include <asm-generic/percpu.h> 262#include <asm-generic/percpu.h>
48 263
49#endif /* __ASM_PERCPU_H */ 264#endif /* __ASM_PERCPU_H */
diff --git a/arch/arm64/include/asm/pgalloc.h b/arch/arm64/include/asm/pgalloc.h
index d5bed02073d6..e20df38a8ff3 100644
--- a/arch/arm64/include/asm/pgalloc.h
+++ b/arch/arm64/include/asm/pgalloc.h
@@ -26,11 +26,13 @@
26 26
27#define check_pgt_cache() do { } while (0) 27#define check_pgt_cache() do { } while (0)
28 28
29#define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO)
30
29#if CONFIG_ARM64_PGTABLE_LEVELS > 2 31#if CONFIG_ARM64_PGTABLE_LEVELS > 2
30 32
31static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr) 33static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
32{ 34{
33 return (pmd_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT); 35 return (pmd_t *)__get_free_page(PGALLOC_GFP);
34} 36}
35 37
36static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd) 38static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
@@ -50,7 +52,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
50 52
51static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr) 53static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
52{ 54{
53 return (pud_t *)get_zeroed_page(GFP_KERNEL | __GFP_REPEAT); 55 return (pud_t *)__get_free_page(PGALLOC_GFP);
54} 56}
55 57
56static inline void pud_free(struct mm_struct *mm, pud_t *pud) 58static inline void pud_free(struct mm_struct *mm, pud_t *pud)
@@ -69,8 +71,6 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
69extern pgd_t *pgd_alloc(struct mm_struct *mm); 71extern pgd_t *pgd_alloc(struct mm_struct *mm);
70extern void pgd_free(struct mm_struct *mm, pgd_t *pgd); 72extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
71 73
72#define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_REPEAT | __GFP_ZERO)
73
74static inline pte_t * 74static inline pte_t *
75pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr) 75pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
76{ 76{
diff --git a/arch/arm64/include/asm/seccomp.h b/arch/arm64/include/asm/seccomp.h
new file mode 100644
index 000000000000..c76fac979629
--- /dev/null
+++ b/arch/arm64/include/asm/seccomp.h
@@ -0,0 +1,25 @@
1/*
2 * arch/arm64/include/asm/seccomp.h
3 *
4 * Copyright (C) 2014 Linaro Limited
5 * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef _ASM_SECCOMP_H
12#define _ASM_SECCOMP_H
13
14#include <asm/unistd.h>
15
16#ifdef CONFIG_COMPAT
17#define __NR_seccomp_read_32 __NR_compat_read
18#define __NR_seccomp_write_32 __NR_compat_write
19#define __NR_seccomp_exit_32 __NR_compat_exit
20#define __NR_seccomp_sigreturn_32 __NR_compat_rt_sigreturn
21#endif /* CONFIG_COMPAT */
22
23#include <asm-generic/seccomp.h>
24
25#endif /* _ASM_SECCOMP_H */
diff --git a/arch/arm64/include/asm/tlb.h b/arch/arm64/include/asm/tlb.h
index a82c0c5c8b52..c028fe37456f 100644
--- a/arch/arm64/include/asm/tlb.h
+++ b/arch/arm64/include/asm/tlb.h
@@ -19,10 +19,6 @@
19#ifndef __ASM_TLB_H 19#ifndef __ASM_TLB_H
20#define __ASM_TLB_H 20#define __ASM_TLB_H
21 21
22#define __tlb_remove_pmd_tlb_entry __tlb_remove_pmd_tlb_entry
23
24#include <asm-generic/tlb.h>
25
26#include <linux/pagemap.h> 22#include <linux/pagemap.h>
27#include <linux/swap.h> 23#include <linux/swap.h>
28 24
@@ -37,71 +33,22 @@ static inline void __tlb_remove_table(void *_table)
37#define tlb_remove_entry(tlb, entry) tlb_remove_page(tlb, entry) 33#define tlb_remove_entry(tlb, entry) tlb_remove_page(tlb, entry)
38#endif /* CONFIG_HAVE_RCU_TABLE_FREE */ 34#endif /* CONFIG_HAVE_RCU_TABLE_FREE */
39 35
40/* 36#include <asm-generic/tlb.h>
41 * There's three ways the TLB shootdown code is used: 37
42 * 1. Unmapping a range of vmas. See zap_page_range(), unmap_region().
43 * tlb->fullmm = 0, and tlb_start_vma/tlb_end_vma will be called.
44 * 2. Unmapping all vmas. See exit_mmap().
45 * tlb->fullmm = 1, and tlb_start_vma/tlb_end_vma will be called.
46 * Page tables will be freed.
47 * 3. Unmapping argument pages. See shift_arg_pages().
48 * tlb->fullmm = 0, but tlb_start_vma/tlb_end_vma will not be called.
49 */
50static inline void tlb_flush(struct mmu_gather *tlb) 38static inline void tlb_flush(struct mmu_gather *tlb)
51{ 39{
52 if (tlb->fullmm) { 40 if (tlb->fullmm) {
53 flush_tlb_mm(tlb->mm); 41 flush_tlb_mm(tlb->mm);
54 } else if (tlb->end > 0) { 42 } else {
55 struct vm_area_struct vma = { .vm_mm = tlb->mm, }; 43 struct vm_area_struct vma = { .vm_mm = tlb->mm, };
56 flush_tlb_range(&vma, tlb->start, tlb->end); 44 flush_tlb_range(&vma, tlb->start, tlb->end);
57 tlb->start = TASK_SIZE;
58 tlb->end = 0;
59 }
60}
61
62static inline void tlb_add_flush(struct mmu_gather *tlb, unsigned long addr)
63{
64 if (!tlb->fullmm) {
65 tlb->start = min(tlb->start, addr);
66 tlb->end = max(tlb->end, addr + PAGE_SIZE);
67 }
68}
69
70/*
71 * Memorize the range for the TLB flush.
72 */
73static inline void __tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep,
74 unsigned long addr)
75{
76 tlb_add_flush(tlb, addr);
77}
78
79/*
80 * In the case of tlb vma handling, we can optimise these away in the
81 * case where we're doing a full MM flush. When we're doing a munmap,
82 * the vmas are adjusted to only cover the region to be torn down.
83 */
84static inline void tlb_start_vma(struct mmu_gather *tlb,
85 struct vm_area_struct *vma)
86{
87 if (!tlb->fullmm) {
88 tlb->start = TASK_SIZE;
89 tlb->end = 0;
90 } 45 }
91} 46}
92 47
93static inline void tlb_end_vma(struct mmu_gather *tlb,
94 struct vm_area_struct *vma)
95{
96 if (!tlb->fullmm)
97 tlb_flush(tlb);
98}
99
100static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte, 48static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
101 unsigned long addr) 49 unsigned long addr)
102{ 50{
103 pgtable_page_dtor(pte); 51 pgtable_page_dtor(pte);
104 tlb_add_flush(tlb, addr);
105 tlb_remove_entry(tlb, pte); 52 tlb_remove_entry(tlb, pte);
106} 53}
107 54
@@ -109,7 +56,6 @@ static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t pte,
109static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp, 56static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
110 unsigned long addr) 57 unsigned long addr)
111{ 58{
112 tlb_add_flush(tlb, addr);
113 tlb_remove_entry(tlb, virt_to_page(pmdp)); 59 tlb_remove_entry(tlb, virt_to_page(pmdp));
114} 60}
115#endif 61#endif
@@ -118,15 +64,8 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmdp,
118static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp, 64static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pudp,
119 unsigned long addr) 65 unsigned long addr)
120{ 66{
121 tlb_add_flush(tlb, addr);
122 tlb_remove_entry(tlb, virt_to_page(pudp)); 67 tlb_remove_entry(tlb, virt_to_page(pudp));
123} 68}
124#endif 69#endif
125 70
126static inline void __tlb_remove_pmd_tlb_entry(struct mmu_gather *tlb, pmd_t *pmdp,
127 unsigned long address)
128{
129 tlb_add_flush(tlb, address);
130}
131
132#endif 71#endif
diff --git a/arch/arm64/include/asm/traps.h b/arch/arm64/include/asm/traps.h
index 10ca8ff93cc2..232e4ba5d314 100644
--- a/arch/arm64/include/asm/traps.h
+++ b/arch/arm64/include/asm/traps.h
@@ -18,6 +18,22 @@
18#ifndef __ASM_TRAP_H 18#ifndef __ASM_TRAP_H
19#define __ASM_TRAP_H 19#define __ASM_TRAP_H
20 20
21#include <linux/list.h>
22
23struct pt_regs;
24
25struct undef_hook {
26 struct list_head node;
27 u32 instr_mask;
28 u32 instr_val;
29 u64 pstate_mask;
30 u64 pstate_val;
31 int (*fn)(struct pt_regs *regs, u32 instr);
32};
33
34void register_undef_hook(struct undef_hook *hook);
35void unregister_undef_hook(struct undef_hook *hook);
36
21static inline int in_exception_text(unsigned long ptr) 37static inline int in_exception_text(unsigned long ptr)
22{ 38{
23 extern char __exception_text_start[]; 39 extern char __exception_text_start[];
diff --git a/arch/arm64/include/asm/unistd.h b/arch/arm64/include/asm/unistd.h
index 6d2bf419431d..49c9aefd24a5 100644
--- a/arch/arm64/include/asm/unistd.h
+++ b/arch/arm64/include/asm/unistd.h
@@ -31,6 +31,9 @@
31 * Compat syscall numbers used by the AArch64 kernel. 31 * Compat syscall numbers used by the AArch64 kernel.
32 */ 32 */
33#define __NR_compat_restart_syscall 0 33#define __NR_compat_restart_syscall 0
34#define __NR_compat_exit 1
35#define __NR_compat_read 3
36#define __NR_compat_write 4
34#define __NR_compat_sigreturn 119 37#define __NR_compat_sigreturn 119
35#define __NR_compat_rt_sigreturn 173 38#define __NR_compat_rt_sigreturn 173
36 39
diff --git a/arch/arm64/include/asm/unistd32.h b/arch/arm64/include/asm/unistd32.h
index da1f06b535e3..8893cebcea5b 100644
--- a/arch/arm64/include/asm/unistd32.h
+++ b/arch/arm64/include/asm/unistd32.h
@@ -787,8 +787,11 @@ __SYSCALL(__NR_sched_setattr, sys_sched_setattr)
787__SYSCALL(__NR_sched_getattr, sys_sched_getattr) 787__SYSCALL(__NR_sched_getattr, sys_sched_getattr)
788#define __NR_renameat2 382 788#define __NR_renameat2 382
789__SYSCALL(__NR_renameat2, sys_renameat2) 789__SYSCALL(__NR_renameat2, sys_renameat2)
790 /* 383 for seccomp */ 790#define __NR_seccomp 383
791__SYSCALL(__NR_seccomp, sys_seccomp)
791#define __NR_getrandom 384 792#define __NR_getrandom 384
792__SYSCALL(__NR_getrandom, sys_getrandom) 793__SYSCALL(__NR_getrandom, sys_getrandom)
793#define __NR_memfd_create 385 794#define __NR_memfd_create 385
794__SYSCALL(__NR_memfd_create, sys_memfd_create) 795__SYSCALL(__NR_memfd_create, sys_memfd_create)
796#define __NR_bpf 386
797__SYSCALL(__NR_bpf, sys_bpf)
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile
index 5bd029b43644..eaa77ed7766a 100644
--- a/arch/arm64/kernel/Makefile
+++ b/arch/arm64/kernel/Makefile
@@ -5,6 +5,7 @@
5CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET) 5CPPFLAGS_vmlinux.lds := -DTEXT_OFFSET=$(TEXT_OFFSET)
6AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 6AFLAGS_head.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
7CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET) 7CFLAGS_efi-stub.o := -DTEXT_OFFSET=$(TEXT_OFFSET)
8CFLAGS_armv8_deprecated.o := -I$(src)
8 9
9CFLAGS_REMOVE_ftrace.o = -pg 10CFLAGS_REMOVE_ftrace.o = -pg
10CFLAGS_REMOVE_insn.o = -pg 11CFLAGS_REMOVE_insn.o = -pg
@@ -15,10 +16,11 @@ arm64-obj-y := cputable.o debug-monitors.o entry.o irq.o fpsimd.o \
15 entry-fpsimd.o process.o ptrace.o setup.o signal.o \ 16 entry-fpsimd.o process.o ptrace.o setup.o signal.o \
16 sys.o stacktrace.o time.o traps.o io.o vdso.o \ 17 sys.o stacktrace.o time.o traps.o io.o vdso.o \
17 hyp-stub.o psci.o cpu_ops.o insn.o return_address.o \ 18 hyp-stub.o psci.o cpu_ops.o insn.o return_address.o \
18 cpuinfo.o 19 cpuinfo.o cpu_errata.o alternative.o
19 20
20arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \ 21arm64-obj-$(CONFIG_COMPAT) += sys32.o kuser32.o signal32.o \
21 sys_compat.o 22 sys_compat.o \
23 ../../arm/kernel/opcodes.o
22arm64-obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o 24arm64-obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o
23arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o 25arm64-obj-$(CONFIG_MODULES) += arm64ksyms.o module.o
24arm64-obj-$(CONFIG_SMP) += smp.o smp_spin_table.o topology.o 26arm64-obj-$(CONFIG_SMP) += smp.o smp_spin_table.o topology.o
@@ -31,6 +33,7 @@ arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o
31arm64-obj-$(CONFIG_KGDB) += kgdb.o 33arm64-obj-$(CONFIG_KGDB) += kgdb.o
32arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o 34arm64-obj-$(CONFIG_EFI) += efi.o efi-stub.o efi-entry.o
33arm64-obj-$(CONFIG_PCI) += pci.o 35arm64-obj-$(CONFIG_PCI) += pci.o
36arm64-obj-$(CONFIG_ARMV8_DEPRECATED) += armv8_deprecated.o
34 37
35obj-y += $(arm64-obj-y) vdso/ 38obj-y += $(arm64-obj-y) vdso/
36obj-m += $(arm64-obj-m) 39obj-m += $(arm64-obj-m)
diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c
new file mode 100644
index 000000000000..ad7821d64a1d
--- /dev/null
+++ b/arch/arm64/kernel/alternative.c
@@ -0,0 +1,85 @@
1/*
2 * alternative runtime patching
3 * inspired by the x86 version
4 *
5 * Copyright (C) 2014 ARM Ltd.
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 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#define pr_fmt(fmt) "alternatives: " fmt
21
22#include <linux/init.h>
23#include <linux/cpu.h>
24#include <asm/cacheflush.h>
25#include <asm/alternative.h>
26#include <asm/cpufeature.h>
27#include <linux/stop_machine.h>
28
29extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
30
31struct alt_region {
32 struct alt_instr *begin;
33 struct alt_instr *end;
34};
35
36static int __apply_alternatives(void *alt_region)
37{
38 struct alt_instr *alt;
39 struct alt_region *region = alt_region;
40 u8 *origptr, *replptr;
41
42 for (alt = region->begin; alt < region->end; alt++) {
43 if (!cpus_have_cap(alt->cpufeature))
44 continue;
45
46 BUG_ON(alt->alt_len > alt->orig_len);
47
48 pr_info_once("patching kernel code\n");
49
50 origptr = (u8 *)&alt->orig_offset + alt->orig_offset;
51 replptr = (u8 *)&alt->alt_offset + alt->alt_offset;
52 memcpy(origptr, replptr, alt->alt_len);
53 flush_icache_range((uintptr_t)origptr,
54 (uintptr_t)(origptr + alt->alt_len));
55 }
56
57 return 0;
58}
59
60void apply_alternatives_all(void)
61{
62 struct alt_region region = {
63 .begin = __alt_instructions,
64 .end = __alt_instructions_end,
65 };
66
67 /* better not try code patching on a live SMP system */
68 stop_machine(__apply_alternatives, &region, NULL);
69}
70
71void apply_alternatives(void *start, size_t length)
72{
73 struct alt_region region = {
74 .begin = start,
75 .end = start + length,
76 };
77
78 __apply_alternatives(&region);
79}
80
81void free_alternatives_memory(void)
82{
83 free_reserved_area(__alt_instructions, __alt_instructions_end,
84 0, "alternatives");
85}
diff --git a/arch/arm64/kernel/armv8_deprecated.c b/arch/arm64/kernel/armv8_deprecated.c
new file mode 100644
index 000000000000..c363671d7509
--- /dev/null
+++ b/arch/arm64/kernel/armv8_deprecated.c
@@ -0,0 +1,553 @@
1/*
2 * Copyright (C) 2014 ARM Limited
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/cpu.h>
10#include <linux/init.h>
11#include <linux/list.h>
12#include <linux/perf_event.h>
13#include <linux/sched.h>
14#include <linux/slab.h>
15#include <linux/sysctl.h>
16
17#include <asm/insn.h>
18#include <asm/opcodes.h>
19#include <asm/system_misc.h>
20#include <asm/traps.h>
21#include <asm/uaccess.h>
22
23#define CREATE_TRACE_POINTS
24#include "trace-events-emulation.h"
25
26/*
27 * The runtime support for deprecated instruction support can be in one of
28 * following three states -
29 *
30 * 0 = undef
31 * 1 = emulate (software emulation)
32 * 2 = hw (supported in hardware)
33 */
34enum insn_emulation_mode {
35 INSN_UNDEF,
36 INSN_EMULATE,
37 INSN_HW,
38};
39
40enum legacy_insn_status {
41 INSN_DEPRECATED,
42 INSN_OBSOLETE,
43};
44
45struct insn_emulation_ops {
46 const char *name;
47 enum legacy_insn_status status;
48 struct undef_hook *hooks;
49 int (*set_hw_mode)(bool enable);
50};
51
52struct insn_emulation {
53 struct list_head node;
54 struct insn_emulation_ops *ops;
55 int current_mode;
56 int min;
57 int max;
58};
59
60static LIST_HEAD(insn_emulation);
61static int nr_insn_emulated;
62static DEFINE_RAW_SPINLOCK(insn_emulation_lock);
63
64static void register_emulation_hooks(struct insn_emulation_ops *ops)
65{
66 struct undef_hook *hook;
67
68 BUG_ON(!ops->hooks);
69
70 for (hook = ops->hooks; hook->instr_mask; hook++)
71 register_undef_hook(hook);
72
73 pr_notice("Registered %s emulation handler\n", ops->name);
74}
75
76static void remove_emulation_hooks(struct insn_emulation_ops *ops)
77{
78 struct undef_hook *hook;
79
80 BUG_ON(!ops->hooks);
81
82 for (hook = ops->hooks; hook->instr_mask; hook++)
83 unregister_undef_hook(hook);
84
85 pr_notice("Removed %s emulation handler\n", ops->name);
86}
87
88static int update_insn_emulation_mode(struct insn_emulation *insn,
89 enum insn_emulation_mode prev)
90{
91 int ret = 0;
92
93 switch (prev) {
94 case INSN_UNDEF: /* Nothing to be done */
95 break;
96 case INSN_EMULATE:
97 remove_emulation_hooks(insn->ops);
98 break;
99 case INSN_HW:
100 if (insn->ops->set_hw_mode) {
101 insn->ops->set_hw_mode(false);
102 pr_notice("Disabled %s support\n", insn->ops->name);
103 }
104 break;
105 }
106
107 switch (insn->current_mode) {
108 case INSN_UNDEF:
109 break;
110 case INSN_EMULATE:
111 register_emulation_hooks(insn->ops);
112 break;
113 case INSN_HW:
114 if (insn->ops->set_hw_mode && insn->ops->set_hw_mode(true))
115 pr_notice("Enabled %s support\n", insn->ops->name);
116 else
117 ret = -EINVAL;
118 break;
119 }
120
121 return ret;
122}
123
124static void register_insn_emulation(struct insn_emulation_ops *ops)
125{
126 unsigned long flags;
127 struct insn_emulation *insn;
128
129 insn = kzalloc(sizeof(*insn), GFP_KERNEL);
130 insn->ops = ops;
131 insn->min = INSN_UNDEF;
132
133 switch (ops->status) {
134 case INSN_DEPRECATED:
135 insn->current_mode = INSN_EMULATE;
136 insn->max = INSN_HW;
137 break;
138 case INSN_OBSOLETE:
139 insn->current_mode = INSN_UNDEF;
140 insn->max = INSN_EMULATE;
141 break;
142 }
143
144 raw_spin_lock_irqsave(&insn_emulation_lock, flags);
145 list_add(&insn->node, &insn_emulation);
146 nr_insn_emulated++;
147 raw_spin_unlock_irqrestore(&insn_emulation_lock, flags);
148
149 /* Register any handlers if required */
150 update_insn_emulation_mode(insn, INSN_UNDEF);
151}
152
153static int emulation_proc_handler(struct ctl_table *table, int write,
154 void __user *buffer, size_t *lenp,
155 loff_t *ppos)
156{
157 int ret = 0;
158 struct insn_emulation *insn = (struct insn_emulation *) table->data;
159 enum insn_emulation_mode prev_mode = insn->current_mode;
160
161 table->data = &insn->current_mode;
162 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
163
164 if (ret || !write || prev_mode == insn->current_mode)
165 goto ret;
166
167 ret = update_insn_emulation_mode(insn, prev_mode);
168 if (ret) {
169 /* Mode change failed, revert to previous mode. */
170 insn->current_mode = prev_mode;
171 update_insn_emulation_mode(insn, INSN_UNDEF);
172 }
173ret:
174 table->data = insn;
175 return ret;
176}
177
178static struct ctl_table ctl_abi[] = {
179 {
180 .procname = "abi",
181 .mode = 0555,
182 },
183 { }
184};
185
186static void register_insn_emulation_sysctl(struct ctl_table *table)
187{
188 unsigned long flags;
189 int i = 0;
190 struct insn_emulation *insn;
191 struct ctl_table *insns_sysctl, *sysctl;
192
193 insns_sysctl = kzalloc(sizeof(*sysctl) * (nr_insn_emulated + 1),
194 GFP_KERNEL);
195
196 raw_spin_lock_irqsave(&insn_emulation_lock, flags);
197 list_for_each_entry(insn, &insn_emulation, node) {
198 sysctl = &insns_sysctl[i];
199
200 sysctl->mode = 0644;
201 sysctl->maxlen = sizeof(int);
202
203 sysctl->procname = insn->ops->name;
204 sysctl->data = insn;
205 sysctl->extra1 = &insn->min;
206 sysctl->extra2 = &insn->max;
207 sysctl->proc_handler = emulation_proc_handler;
208 i++;
209 }
210 raw_spin_unlock_irqrestore(&insn_emulation_lock, flags);
211
212 table->child = insns_sysctl;
213 register_sysctl_table(table);
214}
215
216/*
217 * Implement emulation of the SWP/SWPB instructions using load-exclusive and
218 * store-exclusive.
219 *
220 * Syntax of SWP{B} instruction: SWP{B}<c> <Rt>, <Rt2>, [<Rn>]
221 * Where: Rt = destination
222 * Rt2 = source
223 * Rn = address
224 */
225
226/*
227 * Error-checking SWP macros implemented using ldxr{b}/stxr{b}
228 */
229#define __user_swpX_asm(data, addr, res, temp, B) \
230 __asm__ __volatile__( \
231 " mov %w2, %w1\n" \
232 "0: ldxr"B" %w1, [%3]\n" \
233 "1: stxr"B" %w0, %w2, [%3]\n" \
234 " cbz %w0, 2f\n" \
235 " mov %w0, %w4\n" \
236 "2:\n" \
237 " .pushsection .fixup,\"ax\"\n" \
238 " .align 2\n" \
239 "3: mov %w0, %w5\n" \
240 " b 2b\n" \
241 " .popsection" \
242 " .pushsection __ex_table,\"a\"\n" \
243 " .align 3\n" \
244 " .quad 0b, 3b\n" \
245 " .quad 1b, 3b\n" \
246 " .popsection" \
247 : "=&r" (res), "+r" (data), "=&r" (temp) \
248 : "r" (addr), "i" (-EAGAIN), "i" (-EFAULT) \
249 : "memory")
250
251#define __user_swp_asm(data, addr, res, temp) \
252 __user_swpX_asm(data, addr, res, temp, "")
253#define __user_swpb_asm(data, addr, res, temp) \
254 __user_swpX_asm(data, addr, res, temp, "b")
255
256/*
257 * Bit 22 of the instruction encoding distinguishes between
258 * the SWP and SWPB variants (bit set means SWPB).
259 */
260#define TYPE_SWPB (1 << 22)
261
262/*
263 * Set up process info to signal segmentation fault - called on access error.
264 */
265static void set_segfault(struct pt_regs *regs, unsigned long addr)
266{
267 siginfo_t info;
268
269 down_read(&current->mm->mmap_sem);
270 if (find_vma(current->mm, addr) == NULL)
271 info.si_code = SEGV_MAPERR;
272 else
273 info.si_code = SEGV_ACCERR;
274 up_read(&current->mm->mmap_sem);
275
276 info.si_signo = SIGSEGV;
277 info.si_errno = 0;
278 info.si_addr = (void *) instruction_pointer(regs);
279
280 pr_debug("SWP{B} emulation: access caused memory abort!\n");
281 arm64_notify_die("Illegal memory access", regs, &info, 0);
282}
283
284static int emulate_swpX(unsigned int address, unsigned int *data,
285 unsigned int type)
286{
287 unsigned int res = 0;
288
289 if ((type != TYPE_SWPB) && (address & 0x3)) {
290 /* SWP to unaligned address not permitted */
291 pr_debug("SWP instruction on unaligned pointer!\n");
292 return -EFAULT;
293 }
294
295 while (1) {
296 unsigned long temp;
297
298 if (type == TYPE_SWPB)
299 __user_swpb_asm(*data, address, res, temp);
300 else
301 __user_swp_asm(*data, address, res, temp);
302
303 if (likely(res != -EAGAIN) || signal_pending(current))
304 break;
305
306 cond_resched();
307 }
308
309 return res;
310}
311
312/*
313 * swp_handler logs the id of calling process, dissects the instruction, sanity
314 * checks the memory location, calls emulate_swpX for the actual operation and
315 * deals with fixup/error handling before returning
316 */
317static int swp_handler(struct pt_regs *regs, u32 instr)
318{
319 u32 destreg, data, type, address = 0;
320 int rn, rt2, res = 0;
321
322 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, regs->pc);
323
324 type = instr & TYPE_SWPB;
325
326 switch (arm_check_condition(instr, regs->pstate)) {
327 case ARM_OPCODE_CONDTEST_PASS:
328 break;
329 case ARM_OPCODE_CONDTEST_FAIL:
330 /* Condition failed - return to next instruction */
331 goto ret;
332 case ARM_OPCODE_CONDTEST_UNCOND:
333 /* If unconditional encoding - not a SWP, undef */
334 return -EFAULT;
335 default:
336 return -EINVAL;
337 }
338
339 rn = aarch32_insn_extract_reg_num(instr, A32_RN_OFFSET);
340 rt2 = aarch32_insn_extract_reg_num(instr, A32_RT2_OFFSET);
341
342 address = (u32)regs->user_regs.regs[rn];
343 data = (u32)regs->user_regs.regs[rt2];
344 destreg = aarch32_insn_extract_reg_num(instr, A32_RT_OFFSET);
345
346 pr_debug("addr in r%d->0x%08x, dest is r%d, source in r%d->0x%08x)\n",
347 rn, address, destreg,
348 aarch32_insn_extract_reg_num(instr, A32_RT2_OFFSET), data);
349
350 /* Check access in reasonable access range for both SWP and SWPB */
351 if (!access_ok(VERIFY_WRITE, (address & ~3), 4)) {
352 pr_debug("SWP{B} emulation: access to 0x%08x not allowed!\n",
353 address);
354 goto fault;
355 }
356
357 res = emulate_swpX(address, &data, type);
358 if (res == -EFAULT)
359 goto fault;
360 else if (res == 0)
361 regs->user_regs.regs[destreg] = data;
362
363ret:
364 if (type == TYPE_SWPB)
365 trace_instruction_emulation("swpb", regs->pc);
366 else
367 trace_instruction_emulation("swp", regs->pc);
368
369 pr_warn_ratelimited("\"%s\" (%ld) uses obsolete SWP{B} instruction at 0x%llx\n",
370 current->comm, (unsigned long)current->pid, regs->pc);
371
372 regs->pc += 4;
373 return 0;
374
375fault:
376 set_segfault(regs, address);
377
378 return 0;
379}
380
381/*
382 * Only emulate SWP/SWPB executed in ARM state/User mode.
383 * The kernel must be SWP free and SWP{B} does not exist in Thumb.
384 */
385static struct undef_hook swp_hooks[] = {
386 {
387 .instr_mask = 0x0fb00ff0,
388 .instr_val = 0x01000090,
389 .pstate_mask = COMPAT_PSR_MODE_MASK,
390 .pstate_val = COMPAT_PSR_MODE_USR,
391 .fn = swp_handler
392 },
393 { }
394};
395
396static struct insn_emulation_ops swp_ops = {
397 .name = "swp",
398 .status = INSN_OBSOLETE,
399 .hooks = swp_hooks,
400 .set_hw_mode = NULL,
401};
402
403static int cp15barrier_handler(struct pt_regs *regs, u32 instr)
404{
405 perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, regs->pc);
406
407 switch (arm_check_condition(instr, regs->pstate)) {
408 case ARM_OPCODE_CONDTEST_PASS:
409 break;
410 case ARM_OPCODE_CONDTEST_FAIL:
411 /* Condition failed - return to next instruction */
412 goto ret;
413 case ARM_OPCODE_CONDTEST_UNCOND:
414 /* If unconditional encoding - not a barrier instruction */
415 return -EFAULT;
416 default:
417 return -EINVAL;
418 }
419
420 switch (aarch32_insn_mcr_extract_crm(instr)) {
421 case 10:
422 /*
423 * dmb - mcr p15, 0, Rt, c7, c10, 5
424 * dsb - mcr p15, 0, Rt, c7, c10, 4
425 */
426 if (aarch32_insn_mcr_extract_opc2(instr) == 5) {
427 dmb(sy);
428 trace_instruction_emulation(
429 "mcr p15, 0, Rt, c7, c10, 5 ; dmb", regs->pc);
430 } else {
431 dsb(sy);
432 trace_instruction_emulation(
433 "mcr p15, 0, Rt, c7, c10, 4 ; dsb", regs->pc);
434 }
435 break;
436 case 5:
437 /*
438 * isb - mcr p15, 0, Rt, c7, c5, 4
439 *
440 * Taking an exception or returning from one acts as an
441 * instruction barrier. So no explicit barrier needed here.
442 */
443 trace_instruction_emulation(
444 "mcr p15, 0, Rt, c7, c5, 4 ; isb", regs->pc);
445 break;
446 }
447
448ret:
449 pr_warn_ratelimited("\"%s\" (%ld) uses deprecated CP15 Barrier instruction at 0x%llx\n",
450 current->comm, (unsigned long)current->pid, regs->pc);
451
452 regs->pc += 4;
453 return 0;
454}
455
456#define SCTLR_EL1_CP15BEN (1 << 5)
457
458static inline void config_sctlr_el1(u32 clear, u32 set)
459{
460 u32 val;
461
462 asm volatile("mrs %0, sctlr_el1" : "=r" (val));
463 val &= ~clear;
464 val |= set;
465 asm volatile("msr sctlr_el1, %0" : : "r" (val));
466}
467
468static void enable_cp15_ben(void *info)
469{
470 config_sctlr_el1(0, SCTLR_EL1_CP15BEN);
471}
472
473static void disable_cp15_ben(void *info)
474{
475 config_sctlr_el1(SCTLR_EL1_CP15BEN, 0);
476}
477
478static int cpu_hotplug_notify(struct notifier_block *b,
479 unsigned long action, void *hcpu)
480{
481 switch (action) {
482 case CPU_STARTING:
483 case CPU_STARTING_FROZEN:
484 enable_cp15_ben(NULL);
485 return NOTIFY_DONE;
486 case CPU_DYING:
487 case CPU_DYING_FROZEN:
488 disable_cp15_ben(NULL);
489 return NOTIFY_DONE;
490 }
491
492 return NOTIFY_OK;
493}
494
495static struct notifier_block cpu_hotplug_notifier = {
496 .notifier_call = cpu_hotplug_notify,
497};
498
499static int cp15_barrier_set_hw_mode(bool enable)
500{
501 if (enable) {
502 register_cpu_notifier(&cpu_hotplug_notifier);
503 on_each_cpu(enable_cp15_ben, NULL, true);
504 } else {
505 unregister_cpu_notifier(&cpu_hotplug_notifier);
506 on_each_cpu(disable_cp15_ben, NULL, true);
507 }
508
509 return true;
510}
511
512static struct undef_hook cp15_barrier_hooks[] = {
513 {
514 .instr_mask = 0x0fff0fdf,
515 .instr_val = 0x0e070f9a,
516 .pstate_mask = COMPAT_PSR_MODE_MASK,
517 .pstate_val = COMPAT_PSR_MODE_USR,
518 .fn = cp15barrier_handler,
519 },
520 {
521 .instr_mask = 0x0fff0fff,
522 .instr_val = 0x0e070f95,
523 .pstate_mask = COMPAT_PSR_MODE_MASK,
524 .pstate_val = COMPAT_PSR_MODE_USR,
525 .fn = cp15barrier_handler,
526 },
527 { }
528};
529
530static struct insn_emulation_ops cp15_barrier_ops = {
531 .name = "cp15_barrier",
532 .status = INSN_DEPRECATED,
533 .hooks = cp15_barrier_hooks,
534 .set_hw_mode = cp15_barrier_set_hw_mode,
535};
536
537/*
538 * Invoked as late_initcall, since not needed before init spawned.
539 */
540static int __init armv8_deprecated_init(void)
541{
542 if (IS_ENABLED(CONFIG_SWP_EMULATION))
543 register_insn_emulation(&swp_ops);
544
545 if (IS_ENABLED(CONFIG_CP15_BARRIER_EMULATION))
546 register_insn_emulation(&cp15_barrier_ops);
547
548 register_insn_emulation_sysctl(ctl_abi);
549
550 return 0;
551}
552
553late_initcall(armv8_deprecated_init);
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c
new file mode 100644
index 000000000000..fa62637e63a8
--- /dev/null
+++ b/arch/arm64/kernel/cpu_errata.c
@@ -0,0 +1,111 @@
1/*
2 * Contains CPU specific errata definitions
3 *
4 * Copyright (C) 2014 ARM Ltd.
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 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#define pr_fmt(fmt) "alternatives: " fmt
20
21#include <linux/types.h>
22#include <asm/cpu.h>
23#include <asm/cputype.h>
24#include <asm/cpufeature.h>
25
26#define MIDR_CORTEX_A53 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53)
27#define MIDR_CORTEX_A57 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A57)
28
29/*
30 * Add a struct or another datatype to the union below if you need
31 * different means to detect an affected CPU.
32 */
33struct arm64_cpu_capabilities {
34 const char *desc;
35 u16 capability;
36 bool (*is_affected)(struct arm64_cpu_capabilities *);
37 union {
38 struct {
39 u32 midr_model;
40 u32 midr_range_min, midr_range_max;
41 };
42 };
43};
44
45#define CPU_MODEL_MASK (MIDR_IMPLEMENTOR_MASK | MIDR_PARTNUM_MASK | \
46 MIDR_ARCHITECTURE_MASK)
47
48static bool __maybe_unused
49is_affected_midr_range(struct arm64_cpu_capabilities *entry)
50{
51 u32 midr = read_cpuid_id();
52
53 if ((midr & CPU_MODEL_MASK) != entry->midr_model)
54 return false;
55
56 midr &= MIDR_REVISION_MASK | MIDR_VARIANT_MASK;
57
58 return (midr >= entry->midr_range_min && midr <= entry->midr_range_max);
59}
60
61#define MIDR_RANGE(model, min, max) \
62 .is_affected = is_affected_midr_range, \
63 .midr_model = model, \
64 .midr_range_min = min, \
65 .midr_range_max = max
66
67struct arm64_cpu_capabilities arm64_errata[] = {
68#if defined(CONFIG_ARM64_ERRATUM_826319) || \
69 defined(CONFIG_ARM64_ERRATUM_827319) || \
70 defined(CONFIG_ARM64_ERRATUM_824069)
71 {
72 /* Cortex-A53 r0p[012] */
73 .desc = "ARM errata 826319, 827319, 824069",
74 .capability = ARM64_WORKAROUND_CLEAN_CACHE,
75 MIDR_RANGE(MIDR_CORTEX_A53, 0x00, 0x02),
76 },
77#endif
78#ifdef CONFIG_ARM64_ERRATUM_819472
79 {
80 /* Cortex-A53 r0p[01] */
81 .desc = "ARM errata 819472",
82 .capability = ARM64_WORKAROUND_CLEAN_CACHE,
83 MIDR_RANGE(MIDR_CORTEX_A53, 0x00, 0x01),
84 },
85#endif
86#ifdef CONFIG_ARM64_ERRATUM_832075
87 {
88 /* Cortex-A57 r0p0 - r1p2 */
89 .desc = "ARM erratum 832075",
90 .capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE,
91 MIDR_RANGE(MIDR_CORTEX_A57, 0x00, 0x12),
92 },
93#endif
94 {
95 }
96};
97
98void check_local_cpu_errata(void)
99{
100 struct arm64_cpu_capabilities *cpus = arm64_errata;
101 int i;
102
103 for (i = 0; cpus[i].desc; i++) {
104 if (!cpus[i].is_affected(&cpus[i]))
105 continue;
106
107 if (!cpus_have_cap(cpus[i].capability))
108 pr_info("enabling workaround for %s\n", cpus[i].desc);
109 cpus_set_cap(cpus[i].capability);
110 }
111}
diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index 504fdaa8367e..57b641747534 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -18,6 +18,7 @@
18#include <asm/cachetype.h> 18#include <asm/cachetype.h>
19#include <asm/cpu.h> 19#include <asm/cpu.h>
20#include <asm/cputype.h> 20#include <asm/cputype.h>
21#include <asm/cpufeature.h>
21 22
22#include <linux/bitops.h> 23#include <linux/bitops.h>
23#include <linux/bug.h> 24#include <linux/bug.h>
@@ -111,6 +112,15 @@ static void cpuinfo_sanity_check(struct cpuinfo_arm64 *cur)
111 diff |= CHECK(cntfrq, boot, cur, cpu); 112 diff |= CHECK(cntfrq, boot, cur, cpu);
112 113
113 /* 114 /*
115 * The kernel uses self-hosted debug features and expects CPUs to
116 * support identical debug features. We presently need CTX_CMPs, WRPs,
117 * and BRPs to be identical.
118 * ID_AA64DFR1 is currently RES0.
119 */
120 diff |= CHECK(id_aa64dfr0, boot, cur, cpu);
121 diff |= CHECK(id_aa64dfr1, boot, cur, cpu);
122
123 /*
114 * Even in big.LITTLE, processors should be identical instruction-set 124 * Even in big.LITTLE, processors should be identical instruction-set
115 * wise. 125 * wise.
116 */ 126 */
@@ -143,7 +153,12 @@ static void cpuinfo_sanity_check(struct cpuinfo_arm64 *cur)
143 diff |= CHECK(id_isar3, boot, cur, cpu); 153 diff |= CHECK(id_isar3, boot, cur, cpu);
144 diff |= CHECK(id_isar4, boot, cur, cpu); 154 diff |= CHECK(id_isar4, boot, cur, cpu);
145 diff |= CHECK(id_isar5, boot, cur, cpu); 155 diff |= CHECK(id_isar5, boot, cur, cpu);
146 diff |= CHECK(id_mmfr0, boot, cur, cpu); 156 /*
157 * Regardless of the value of the AuxReg field, the AIFSR, ADFSR, and
158 * ACTLR formats could differ across CPUs and therefore would have to
159 * be trapped for virtualization anyway.
160 */
161 diff |= CHECK_MASK(id_mmfr0, 0xff0fffff, boot, cur, cpu);
147 diff |= CHECK(id_mmfr1, boot, cur, cpu); 162 diff |= CHECK(id_mmfr1, boot, cur, cpu);
148 diff |= CHECK(id_mmfr2, boot, cur, cpu); 163 diff |= CHECK(id_mmfr2, boot, cur, cpu);
149 diff |= CHECK(id_mmfr3, boot, cur, cpu); 164 diff |= CHECK(id_mmfr3, boot, cur, cpu);
@@ -155,7 +170,7 @@ static void cpuinfo_sanity_check(struct cpuinfo_arm64 *cur)
155 * pretend to support them. 170 * pretend to support them.
156 */ 171 */
157 WARN_TAINT_ONCE(diff, TAINT_CPU_OUT_OF_SPEC, 172 WARN_TAINT_ONCE(diff, TAINT_CPU_OUT_OF_SPEC,
158 "Unsupported CPU feature variation."); 173 "Unsupported CPU feature variation.\n");
159} 174}
160 175
161static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info) 176static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info)
@@ -165,6 +180,8 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info)
165 info->reg_dczid = read_cpuid(DCZID_EL0); 180 info->reg_dczid = read_cpuid(DCZID_EL0);
166 info->reg_midr = read_cpuid_id(); 181 info->reg_midr = read_cpuid_id();
167 182
183 info->reg_id_aa64dfr0 = read_cpuid(ID_AA64DFR0_EL1);
184 info->reg_id_aa64dfr1 = read_cpuid(ID_AA64DFR1_EL1);
168 info->reg_id_aa64isar0 = read_cpuid(ID_AA64ISAR0_EL1); 185 info->reg_id_aa64isar0 = read_cpuid(ID_AA64ISAR0_EL1);
169 info->reg_id_aa64isar1 = read_cpuid(ID_AA64ISAR1_EL1); 186 info->reg_id_aa64isar1 = read_cpuid(ID_AA64ISAR1_EL1);
170 info->reg_id_aa64mmfr0 = read_cpuid(ID_AA64MMFR0_EL1); 187 info->reg_id_aa64mmfr0 = read_cpuid(ID_AA64MMFR0_EL1);
@@ -186,6 +203,8 @@ static void __cpuinfo_store_cpu(struct cpuinfo_arm64 *info)
186 info->reg_id_pfr1 = read_cpuid(ID_PFR1_EL1); 203 info->reg_id_pfr1 = read_cpuid(ID_PFR1_EL1);
187 204
188 cpuinfo_detect_icache_policy(info); 205 cpuinfo_detect_icache_policy(info);
206
207 check_local_cpu_errata();
189} 208}
190 209
191void cpuinfo_store_cpu(void) 210void cpuinfo_store_cpu(void)
diff --git a/arch/arm64/kernel/efi-entry.S b/arch/arm64/kernel/efi-entry.S
index 619b1dd7bcde..8ce9b0577442 100644
--- a/arch/arm64/kernel/efi-entry.S
+++ b/arch/arm64/kernel/efi-entry.S
@@ -54,18 +54,18 @@ ENTRY(efi_stub_entry)
54 b.eq efi_load_fail 54 b.eq efi_load_fail
55 55
56 /* 56 /*
57 * efi_entry() will have relocated the kernel image if necessary 57 * efi_entry() will have copied the kernel image if necessary and we
58 * and we return here with device tree address in x0 and the kernel 58 * return here with device tree address in x0 and the kernel entry
59 * entry point stored at *image_addr. Save those values in registers 59 * point stored at *image_addr. Save those values in registers which
60 * which are callee preserved. 60 * are callee preserved.
61 */ 61 */
62 mov x20, x0 // DTB address 62 mov x20, x0 // DTB address
63 ldr x0, [sp, #16] // relocated _text address 63 ldr x0, [sp, #16] // relocated _text address
64 mov x21, x0 64 ldr x21, =stext_offset
65 add x21, x0, x21
65 66
66 /* 67 /*
67 * Flush dcache covering current runtime addresses 68 * Calculate size of the kernel Image (same for original and copy).
68 * of kernel text/data. Then flush all of icache.
69 */ 69 */
70 adrp x1, _text 70 adrp x1, _text
71 add x1, x1, #:lo12:_text 71 add x1, x1, #:lo12:_text
@@ -73,9 +73,24 @@ ENTRY(efi_stub_entry)
73 add x2, x2, #:lo12:_edata 73 add x2, x2, #:lo12:_edata
74 sub x1, x2, x1 74 sub x1, x2, x1
75 75
76 /*
77 * Flush the copied Image to the PoC, and ensure it is not shadowed by
78 * stale icache entries from before relocation.
79 */
76 bl __flush_dcache_area 80 bl __flush_dcache_area
77 ic ialluis 81 ic ialluis
78 82
83 /*
84 * Ensure that the rest of this function (in the original Image) is
85 * visible when the caches are disabled. The I-cache can't have stale
86 * entries for the VA range of the current image, so no maintenance is
87 * necessary.
88 */
89 adr x0, efi_stub_entry
90 adr x1, efi_stub_entry_end
91 sub x1, x1, x0
92 bl __flush_dcache_area
93
79 /* Turn off Dcache and MMU */ 94 /* Turn off Dcache and MMU */
80 mrs x0, CurrentEL 95 mrs x0, CurrentEL
81 cmp x0, #CurrentEL_EL2 96 cmp x0, #CurrentEL_EL2
@@ -105,4 +120,5 @@ efi_load_fail:
105 ldp x29, x30, [sp], #32 120 ldp x29, x30, [sp], #32
106 ret 121 ret
107 122
123efi_stub_entry_end:
108ENDPROC(efi_stub_entry) 124ENDPROC(efi_stub_entry)
diff --git a/arch/arm64/kernel/efi.c b/arch/arm64/kernel/efi.c
index 95c49ebc660d..6fac253bc783 100644
--- a/arch/arm64/kernel/efi.c
+++ b/arch/arm64/kernel/efi.c
@@ -11,6 +11,7 @@
11 * 11 *
12 */ 12 */
13 13
14#include <linux/dmi.h>
14#include <linux/efi.h> 15#include <linux/efi.h>
15#include <linux/export.h> 16#include <linux/export.h>
16#include <linux/memblock.h> 17#include <linux/memblock.h>
@@ -112,8 +113,6 @@ static int __init uefi_init(void)
112 efi.systab->hdr.revision & 0xffff, vendor); 113 efi.systab->hdr.revision & 0xffff, vendor);
113 114
114 retval = efi_config_init(NULL); 115 retval = efi_config_init(NULL);
115 if (retval == 0)
116 set_bit(EFI_CONFIG_TABLES, &efi.flags);
117 116
118out: 117out:
119 early_memunmap(efi.systab, sizeof(efi_system_table_t)); 118 early_memunmap(efi.systab, sizeof(efi_system_table_t));
@@ -125,17 +124,17 @@ out:
125 */ 124 */
126static __init int is_reserve_region(efi_memory_desc_t *md) 125static __init int is_reserve_region(efi_memory_desc_t *md)
127{ 126{
128 if (!is_normal_ram(md)) 127 switch (md->type) {
128 case EFI_LOADER_CODE:
129 case EFI_LOADER_DATA:
130 case EFI_BOOT_SERVICES_CODE:
131 case EFI_BOOT_SERVICES_DATA:
132 case EFI_CONVENTIONAL_MEMORY:
129 return 0; 133 return 0;
130 134 default:
131 if (md->attribute & EFI_MEMORY_RUNTIME) 135 break;
132 return 1; 136 }
133 137 return is_normal_ram(md);
134 if (md->type == EFI_ACPI_RECLAIM_MEMORY ||
135 md->type == EFI_RESERVED_TYPE)
136 return 1;
137
138 return 0;
139} 138}
140 139
141static __init void reserve_regions(void) 140static __init void reserve_regions(void)
@@ -471,3 +470,17 @@ err_unmap:
471 return -1; 470 return -1;
472} 471}
473early_initcall(arm64_enter_virtual_mode); 472early_initcall(arm64_enter_virtual_mode);
473
474static int __init arm64_dmi_init(void)
475{
476 /*
477 * On arm64, DMI depends on UEFI, and dmi_scan_machine() needs to
478 * be called early because dmi_id_init(), which is an arch_initcall
479 * itself, depends on dmi_scan_machine() having been called already.
480 */
481 dmi_scan_machine();
482 if (dmi_available)
483 dmi_set_dump_stack_arch_desc();
484 return 0;
485}
486core_initcall(arm64_dmi_init);
diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S
index 38e704e597f7..08cafc518b9a 100644
--- a/arch/arm64/kernel/entry-ftrace.S
+++ b/arch/arm64/kernel/entry-ftrace.S
@@ -98,8 +98,8 @@
98ENTRY(_mcount) 98ENTRY(_mcount)
99 mcount_enter 99 mcount_enter
100 100
101 ldr x0, =ftrace_trace_function 101 adrp x0, ftrace_trace_function
102 ldr x2, [x0] 102 ldr x2, [x0, #:lo12:ftrace_trace_function]
103 adr x0, ftrace_stub 103 adr x0, ftrace_stub
104 cmp x0, x2 // if (ftrace_trace_function 104 cmp x0, x2 // if (ftrace_trace_function
105 b.eq skip_ftrace_call // != ftrace_stub) { 105 b.eq skip_ftrace_call // != ftrace_stub) {
@@ -115,14 +115,15 @@ skip_ftrace_call: // return;
115 mcount_exit // return; 115 mcount_exit // return;
116 // } 116 // }
117skip_ftrace_call: 117skip_ftrace_call:
118 ldr x1, =ftrace_graph_return 118 adrp x1, ftrace_graph_return
119 ldr x2, [x1] // if ((ftrace_graph_return 119 ldr x2, [x1, #:lo12:ftrace_graph_return]
120 cmp x0, x2 // != ftrace_stub) 120 cmp x0, x2 // if ((ftrace_graph_return
121 b.ne ftrace_graph_caller 121 b.ne ftrace_graph_caller // != ftrace_stub)
122 122
123 ldr x1, =ftrace_graph_entry // || (ftrace_graph_entry 123 adrp x1, ftrace_graph_entry // || (ftrace_graph_entry
124 ldr x2, [x1] // != ftrace_graph_entry_stub)) 124 adrp x0, ftrace_graph_entry_stub // != ftrace_graph_entry_stub))
125 ldr x0, =ftrace_graph_entry_stub 125 ldr x2, [x1, #:lo12:ftrace_graph_entry]
126 add x0, x0, #:lo12:ftrace_graph_entry_stub
126 cmp x0, x2 127 cmp x0, x2
127 b.ne ftrace_graph_caller // ftrace_graph_caller(); 128 b.ne ftrace_graph_caller // ftrace_graph_caller();
128 129
diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index 726b910fe6ec..fd4fa374e5d2 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -64,25 +64,26 @@
64#define BAD_ERROR 3 64#define BAD_ERROR 3
65 65
66 .macro kernel_entry, el, regsize = 64 66 .macro kernel_entry, el, regsize = 64
67 sub sp, sp, #S_FRAME_SIZE - S_LR // room for LR, SP, SPSR, ELR 67 sub sp, sp, #S_FRAME_SIZE
68 .if \regsize == 32 68 .if \regsize == 32
69 mov w0, w0 // zero upper 32 bits of x0 69 mov w0, w0 // zero upper 32 bits of x0
70 .endif 70 .endif
71 push x28, x29 71 stp x0, x1, [sp, #16 * 0]
72 push x26, x27 72 stp x2, x3, [sp, #16 * 1]
73 push x24, x25 73 stp x4, x5, [sp, #16 * 2]
74 push x22, x23 74 stp x6, x7, [sp, #16 * 3]
75 push x20, x21 75 stp x8, x9, [sp, #16 * 4]
76 push x18, x19 76 stp x10, x11, [sp, #16 * 5]
77 push x16, x17 77 stp x12, x13, [sp, #16 * 6]
78 push x14, x15 78 stp x14, x15, [sp, #16 * 7]
79 push x12, x13 79 stp x16, x17, [sp, #16 * 8]
80 push x10, x11 80 stp x18, x19, [sp, #16 * 9]
81 push x8, x9 81 stp x20, x21, [sp, #16 * 10]
82 push x6, x7 82 stp x22, x23, [sp, #16 * 11]
83 push x4, x5 83 stp x24, x25, [sp, #16 * 12]
84 push x2, x3 84 stp x26, x27, [sp, #16 * 13]
85 push x0, x1 85 stp x28, x29, [sp, #16 * 14]
86
86 .if \el == 0 87 .if \el == 0
87 mrs x21, sp_el0 88 mrs x21, sp_el0
88 get_thread_info tsk // Ensure MDSCR_EL1.SS is clear, 89 get_thread_info tsk // Ensure MDSCR_EL1.SS is clear,
@@ -118,33 +119,31 @@
118 .if \el == 0 119 .if \el == 0
119 ct_user_enter 120 ct_user_enter
120 ldr x23, [sp, #S_SP] // load return stack pointer 121 ldr x23, [sp, #S_SP] // load return stack pointer
122 msr sp_el0, x23
121 .endif 123 .endif
124 msr elr_el1, x21 // set up the return data
125 msr spsr_el1, x22
122 .if \ret 126 .if \ret
123 ldr x1, [sp, #S_X1] // preserve x0 (syscall return) 127 ldr x1, [sp, #S_X1] // preserve x0 (syscall return)
124 add sp, sp, S_X2
125 .else 128 .else
126 pop x0, x1 129 ldp x0, x1, [sp, #16 * 0]
127 .endif 130 .endif
128 pop x2, x3 // load the rest of the registers 131 ldp x2, x3, [sp, #16 * 1]
129 pop x4, x5 132 ldp x4, x5, [sp, #16 * 2]
130 pop x6, x7 133 ldp x6, x7, [sp, #16 * 3]
131 pop x8, x9 134 ldp x8, x9, [sp, #16 * 4]
132 msr elr_el1, x21 // set up the return data 135 ldp x10, x11, [sp, #16 * 5]
133 msr spsr_el1, x22 136 ldp x12, x13, [sp, #16 * 6]
134 .if \el == 0 137 ldp x14, x15, [sp, #16 * 7]
135 msr sp_el0, x23 138 ldp x16, x17, [sp, #16 * 8]
136 .endif 139 ldp x18, x19, [sp, #16 * 9]
137 pop x10, x11 140 ldp x20, x21, [sp, #16 * 10]
138 pop x12, x13 141 ldp x22, x23, [sp, #16 * 11]
139 pop x14, x15 142 ldp x24, x25, [sp, #16 * 12]
140 pop x16, x17 143 ldp x26, x27, [sp, #16 * 13]
141 pop x18, x19 144 ldp x28, x29, [sp, #16 * 14]
142 pop x20, x21 145 ldr lr, [sp, #S_LR]
143 pop x22, x23 146 add sp, sp, #S_FRAME_SIZE // restore sp
144 pop x24, x25
145 pop x26, x27
146 pop x28, x29
147 ldr lr, [sp], #S_FRAME_SIZE - S_LR // load LR and restore SP
148 eret // return to kernel 147 eret // return to kernel
149 .endm 148 .endm
150 149
@@ -168,7 +167,8 @@ tsk .req x28 // current thread_info
168 * Interrupt handling. 167 * Interrupt handling.
169 */ 168 */
170 .macro irq_handler 169 .macro irq_handler
171 ldr x1, handle_arch_irq 170 adrp x1, handle_arch_irq
171 ldr x1, [x1, #:lo12:handle_arch_irq]
172 mov x0, sp 172 mov x0, sp
173 blr x1 173 blr x1
174 .endm 174 .endm
@@ -455,8 +455,8 @@ el0_da:
455 bic x0, x26, #(0xff << 56) 455 bic x0, x26, #(0xff << 56)
456 mov x1, x25 456 mov x1, x25
457 mov x2, sp 457 mov x2, sp
458 adr lr, ret_to_user 458 bl do_mem_abort
459 b do_mem_abort 459 b ret_to_user
460el0_ia: 460el0_ia:
461 /* 461 /*
462 * Instruction abort handling 462 * Instruction abort handling
@@ -468,8 +468,8 @@ el0_ia:
468 mov x0, x26 468 mov x0, x26
469 orr x1, x25, #1 << 24 // use reserved ISS bit for instruction aborts 469 orr x1, x25, #1 << 24 // use reserved ISS bit for instruction aborts
470 mov x2, sp 470 mov x2, sp
471 adr lr, ret_to_user 471 bl do_mem_abort
472 b do_mem_abort 472 b ret_to_user
473el0_fpsimd_acc: 473el0_fpsimd_acc:
474 /* 474 /*
475 * Floating Point or Advanced SIMD access 475 * Floating Point or Advanced SIMD access
@@ -478,8 +478,8 @@ el0_fpsimd_acc:
478 ct_user_exit 478 ct_user_exit
479 mov x0, x25 479 mov x0, x25
480 mov x1, sp 480 mov x1, sp
481 adr lr, ret_to_user 481 bl do_fpsimd_acc
482 b do_fpsimd_acc 482 b ret_to_user
483el0_fpsimd_exc: 483el0_fpsimd_exc:
484 /* 484 /*
485 * Floating Point or Advanced SIMD exception 485 * Floating Point or Advanced SIMD exception
@@ -488,8 +488,8 @@ el0_fpsimd_exc:
488 ct_user_exit 488 ct_user_exit
489 mov x0, x25 489 mov x0, x25
490 mov x1, sp 490 mov x1, sp
491 adr lr, ret_to_user 491 bl do_fpsimd_exc
492 b do_fpsimd_exc 492 b ret_to_user
493el0_sp_pc: 493el0_sp_pc:
494 /* 494 /*
495 * Stack or PC alignment exception handling 495 * Stack or PC alignment exception handling
@@ -500,8 +500,8 @@ el0_sp_pc:
500 mov x0, x26 500 mov x0, x26
501 mov x1, x25 501 mov x1, x25
502 mov x2, sp 502 mov x2, sp
503 adr lr, ret_to_user 503 bl do_sp_pc_abort
504 b do_sp_pc_abort 504 b ret_to_user
505el0_undef: 505el0_undef:
506 /* 506 /*
507 * Undefined instruction 507 * Undefined instruction
@@ -510,8 +510,8 @@ el0_undef:
510 enable_dbg_and_irq 510 enable_dbg_and_irq
511 ct_user_exit 511 ct_user_exit
512 mov x0, sp 512 mov x0, sp
513 adr lr, ret_to_user 513 bl do_undefinstr
514 b do_undefinstr 514 b ret_to_user
515el0_dbg: 515el0_dbg:
516 /* 516 /*
517 * Debug exception handling 517 * Debug exception handling
@@ -530,8 +530,8 @@ el0_inv:
530 mov x0, sp 530 mov x0, sp
531 mov x1, #BAD_SYNC 531 mov x1, #BAD_SYNC
532 mrs x2, esr_el1 532 mrs x2, esr_el1
533 adr lr, ret_to_user 533 bl bad_mode
534 b bad_mode 534 b ret_to_user
535ENDPROC(el0_sync) 535ENDPROC(el0_sync)
536 536
537 .align 6 537 .align 6
@@ -653,14 +653,15 @@ el0_svc_naked: // compat entry point
653 ldr x16, [tsk, #TI_FLAGS] // check for syscall hooks 653 ldr x16, [tsk, #TI_FLAGS] // check for syscall hooks
654 tst x16, #_TIF_SYSCALL_WORK 654 tst x16, #_TIF_SYSCALL_WORK
655 b.ne __sys_trace 655 b.ne __sys_trace
656 adr lr, ret_fast_syscall // return address
657 cmp scno, sc_nr // check upper syscall limit 656 cmp scno, sc_nr // check upper syscall limit
658 b.hs ni_sys 657 b.hs ni_sys
659 ldr x16, [stbl, scno, lsl #3] // address in the syscall table 658 ldr x16, [stbl, scno, lsl #3] // address in the syscall table
660 br x16 // call sys_* routine 659 blr x16 // call sys_* routine
660 b ret_fast_syscall
661ni_sys: 661ni_sys:
662 mov x0, sp 662 mov x0, sp
663 b do_ni_syscall 663 bl do_ni_syscall
664 b ret_fast_syscall
664ENDPROC(el0_svc) 665ENDPROC(el0_svc)
665 666
666 /* 667 /*
@@ -668,26 +669,38 @@ ENDPROC(el0_svc)
668 * switches, and waiting for our parent to respond. 669 * switches, and waiting for our parent to respond.
669 */ 670 */
670__sys_trace: 671__sys_trace:
671 mov x0, sp 672 mov w0, #-1 // set default errno for
673 cmp scno, x0 // user-issued syscall(-1)
674 b.ne 1f
675 mov x0, #-ENOSYS
676 str x0, [sp, #S_X0]
6771: mov x0, sp
672 bl syscall_trace_enter 678 bl syscall_trace_enter
673 adr lr, __sys_trace_return // return address 679 cmp w0, #-1 // skip the syscall?
680 b.eq __sys_trace_return_skipped
674 uxtw scno, w0 // syscall number (possibly new) 681 uxtw scno, w0 // syscall number (possibly new)
675 mov x1, sp // pointer to regs 682 mov x1, sp // pointer to regs
676 cmp scno, sc_nr // check upper syscall limit 683 cmp scno, sc_nr // check upper syscall limit
677 b.hs ni_sys 684 b.hs __ni_sys_trace
678 ldp x0, x1, [sp] // restore the syscall args 685 ldp x0, x1, [sp] // restore the syscall args
679 ldp x2, x3, [sp, #S_X2] 686 ldp x2, x3, [sp, #S_X2]
680 ldp x4, x5, [sp, #S_X4] 687 ldp x4, x5, [sp, #S_X4]
681 ldp x6, x7, [sp, #S_X6] 688 ldp x6, x7, [sp, #S_X6]
682 ldr x16, [stbl, scno, lsl #3] // address in the syscall table 689 ldr x16, [stbl, scno, lsl #3] // address in the syscall table
683 br x16 // call sys_* routine 690 blr x16 // call sys_* routine
684 691
685__sys_trace_return: 692__sys_trace_return:
686 str x0, [sp] // save returned x0 693 str x0, [sp, #S_X0] // save returned x0
694__sys_trace_return_skipped:
687 mov x0, sp 695 mov x0, sp
688 bl syscall_trace_exit 696 bl syscall_trace_exit
689 b ret_to_user 697 b ret_to_user
690 698
699__ni_sys_trace:
700 mov x0, sp
701 bl do_ni_syscall
702 b __sys_trace_return
703
691/* 704/*
692 * Special system call wrappers. 705 * Special system call wrappers.
693 */ 706 */
@@ -695,6 +708,3 @@ ENTRY(sys_rt_sigreturn_wrapper)
695 mov x0, sp 708 mov x0, sp
696 b sys_rt_sigreturn 709 b sys_rt_sigreturn
697ENDPROC(sys_rt_sigreturn_wrapper) 710ENDPROC(sys_rt_sigreturn_wrapper)
698
699ENTRY(handle_arch_irq)
700 .quad 0
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 0a6e4f924df8..8ce88e08c030 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -132,6 +132,8 @@ efi_head:
132#endif 132#endif
133 133
134#ifdef CONFIG_EFI 134#ifdef CONFIG_EFI
135 .globl stext_offset
136 .set stext_offset, stext - efi_head
135 .align 3 137 .align 3
136pe_header: 138pe_header:
137 .ascii "PE" 139 .ascii "PE"
@@ -155,12 +157,12 @@ optional_header:
155 .long 0 // SizeOfInitializedData 157 .long 0 // SizeOfInitializedData
156 .long 0 // SizeOfUninitializedData 158 .long 0 // SizeOfUninitializedData
157 .long efi_stub_entry - efi_head // AddressOfEntryPoint 159 .long efi_stub_entry - efi_head // AddressOfEntryPoint
158 .long stext - efi_head // BaseOfCode 160 .long stext_offset // BaseOfCode
159 161
160extra_header_fields: 162extra_header_fields:
161 .quad 0 // ImageBase 163 .quad 0 // ImageBase
162 .long 0x20 // SectionAlignment 164 .long 0x1000 // SectionAlignment
163 .long 0x8 // FileAlignment 165 .long PECOFF_FILE_ALIGNMENT // FileAlignment
164 .short 0 // MajorOperatingSystemVersion 166 .short 0 // MajorOperatingSystemVersion
165 .short 0 // MinorOperatingSystemVersion 167 .short 0 // MinorOperatingSystemVersion
166 .short 0 // MajorImageVersion 168 .short 0 // MajorImageVersion
@@ -172,7 +174,7 @@ extra_header_fields:
172 .long _end - efi_head // SizeOfImage 174 .long _end - efi_head // SizeOfImage
173 175
174 // Everything before the kernel image is considered part of the header 176 // Everything before the kernel image is considered part of the header
175 .long stext - efi_head // SizeOfHeaders 177 .long stext_offset // SizeOfHeaders
176 .long 0 // CheckSum 178 .long 0 // CheckSum
177 .short 0xa // Subsystem (EFI application) 179 .short 0xa // Subsystem (EFI application)
178 .short 0 // DllCharacteristics 180 .short 0 // DllCharacteristics
@@ -217,16 +219,24 @@ section_table:
217 .byte 0 219 .byte 0
218 .byte 0 // end of 0 padding of section name 220 .byte 0 // end of 0 padding of section name
219 .long _end - stext // VirtualSize 221 .long _end - stext // VirtualSize
220 .long stext - efi_head // VirtualAddress 222 .long stext_offset // VirtualAddress
221 .long _edata - stext // SizeOfRawData 223 .long _edata - stext // SizeOfRawData
222 .long stext - efi_head // PointerToRawData 224 .long stext_offset // PointerToRawData
223 225
224 .long 0 // PointerToRelocations (0 for executables) 226 .long 0 // PointerToRelocations (0 for executables)
225 .long 0 // PointerToLineNumbers (0 for executables) 227 .long 0 // PointerToLineNumbers (0 for executables)
226 .short 0 // NumberOfRelocations (0 for executables) 228 .short 0 // NumberOfRelocations (0 for executables)
227 .short 0 // NumberOfLineNumbers (0 for executables) 229 .short 0 // NumberOfLineNumbers (0 for executables)
228 .long 0xe0500020 // Characteristics (section flags) 230 .long 0xe0500020 // Characteristics (section flags)
229 .align 5 231
232 /*
233 * EFI will load stext onwards at the 4k section alignment
234 * described in the PE/COFF header. To ensure that instruction
235 * sequences using an adrp and a :lo12: immediate will function
236 * correctly at this alignment, we must ensure that stext is
237 * placed at a 4k boundary in the Image to begin with.
238 */
239 .align 12
230#endif 240#endif
231 241
232ENTRY(stext) 242ENTRY(stext)
@@ -238,7 +248,13 @@ ENTRY(stext)
238 mov x0, x22 248 mov x0, x22
239 bl lookup_processor_type 249 bl lookup_processor_type
240 mov x23, x0 // x23=current cpu_table 250 mov x23, x0 // x23=current cpu_table
241 cbz x23, __error_p // invalid processor (x23=0)? 251 /*
252 * __error_p may end up out of range for cbz if text areas are
253 * aligned up to section sizes.
254 */
255 cbnz x23, 1f // invalid processor (x23=0)?
256 b __error_p
2571:
242 bl __vet_fdt 258 bl __vet_fdt
243 bl __create_page_tables // x25=TTBR0, x26=TTBR1 259 bl __create_page_tables // x25=TTBR0, x26=TTBR1
244 /* 260 /*
@@ -250,13 +266,214 @@ ENTRY(stext)
250 */ 266 */
251 ldr x27, __switch_data // address to jump to after 267 ldr x27, __switch_data // address to jump to after
252 // MMU has been enabled 268 // MMU has been enabled
253 adr lr, __enable_mmu // return (PIC) address 269 adrp lr, __enable_mmu // return (PIC) address
270 add lr, lr, #:lo12:__enable_mmu
254 ldr x12, [x23, #CPU_INFO_SETUP] 271 ldr x12, [x23, #CPU_INFO_SETUP]
255 add x12, x12, x28 // __virt_to_phys 272 add x12, x12, x28 // __virt_to_phys
256 br x12 // initialise processor 273 br x12 // initialise processor
257ENDPROC(stext) 274ENDPROC(stext)
258 275
259/* 276/*
277 * Determine validity of the x21 FDT pointer.
278 * The dtb must be 8-byte aligned and live in the first 512M of memory.
279 */
280__vet_fdt:
281 tst x21, #0x7
282 b.ne 1f
283 cmp x21, x24
284 b.lt 1f
285 mov x0, #(1 << 29)
286 add x0, x0, x24
287 cmp x21, x0
288 b.ge 1f
289 ret
2901:
291 mov x21, #0
292 ret
293ENDPROC(__vet_fdt)
294/*
295 * Macro to create a table entry to the next page.
296 *
297 * tbl: page table address
298 * virt: virtual address
299 * shift: #imm page table shift
300 * ptrs: #imm pointers per table page
301 *
302 * Preserves: virt
303 * Corrupts: tmp1, tmp2
304 * Returns: tbl -> next level table page address
305 */
306 .macro create_table_entry, tbl, virt, shift, ptrs, tmp1, tmp2
307 lsr \tmp1, \virt, #\shift
308 and \tmp1, \tmp1, #\ptrs - 1 // table index
309 add \tmp2, \tbl, #PAGE_SIZE
310 orr \tmp2, \tmp2, #PMD_TYPE_TABLE // address of next table and entry type
311 str \tmp2, [\tbl, \tmp1, lsl #3]
312 add \tbl, \tbl, #PAGE_SIZE // next level table page
313 .endm
314
315/*
316 * Macro to populate the PGD (and possibily PUD) for the corresponding
317 * block entry in the next level (tbl) for the given virtual address.
318 *
319 * Preserves: tbl, next, virt
320 * Corrupts: tmp1, tmp2
321 */
322 .macro create_pgd_entry, tbl, virt, tmp1, tmp2
323 create_table_entry \tbl, \virt, PGDIR_SHIFT, PTRS_PER_PGD, \tmp1, \tmp2
324#if SWAPPER_PGTABLE_LEVELS == 3
325 create_table_entry \tbl, \virt, TABLE_SHIFT, PTRS_PER_PTE, \tmp1, \tmp2
326#endif
327 .endm
328
329/*
330 * Macro to populate block entries in the page table for the start..end
331 * virtual range (inclusive).
332 *
333 * Preserves: tbl, flags
334 * Corrupts: phys, start, end, pstate
335 */
336 .macro create_block_map, tbl, flags, phys, start, end
337 lsr \phys, \phys, #BLOCK_SHIFT
338 lsr \start, \start, #BLOCK_SHIFT
339 and \start, \start, #PTRS_PER_PTE - 1 // table index
340 orr \phys, \flags, \phys, lsl #BLOCK_SHIFT // table entry
341 lsr \end, \end, #BLOCK_SHIFT
342 and \end, \end, #PTRS_PER_PTE - 1 // table end index
3439999: str \phys, [\tbl, \start, lsl #3] // store the entry
344 add \start, \start, #1 // next entry
345 add \phys, \phys, #BLOCK_SIZE // next block
346 cmp \start, \end
347 b.ls 9999b
348 .endm
349
350/*
351 * Setup the initial page tables. We only setup the barest amount which is
352 * required to get the kernel running. The following sections are required:
353 * - identity mapping to enable the MMU (low address, TTBR0)
354 * - first few MB of the kernel linear mapping to jump to once the MMU has
355 * been enabled, including the FDT blob (TTBR1)
356 * - pgd entry for fixed mappings (TTBR1)
357 */
358__create_page_tables:
359 pgtbl x25, x26, x28 // idmap_pg_dir and swapper_pg_dir addresses
360 mov x27, lr
361
362 /*
363 * Invalidate the idmap and swapper page tables to avoid potential
364 * dirty cache lines being evicted.
365 */
366 mov x0, x25
367 add x1, x26, #SWAPPER_DIR_SIZE
368 bl __inval_cache_range
369
370 /*
371 * Clear the idmap and swapper page tables.
372 */
373 mov x0, x25
374 add x6, x26, #SWAPPER_DIR_SIZE
3751: stp xzr, xzr, [x0], #16
376 stp xzr, xzr, [x0], #16
377 stp xzr, xzr, [x0], #16
378 stp xzr, xzr, [x0], #16
379 cmp x0, x6
380 b.lo 1b
381
382 ldr x7, =MM_MMUFLAGS
383
384 /*
385 * Create the identity mapping.
386 */
387 mov x0, x25 // idmap_pg_dir
388 ldr x3, =KERNEL_START
389 add x3, x3, x28 // __pa(KERNEL_START)
390 create_pgd_entry x0, x3, x5, x6
391 ldr x6, =KERNEL_END
392 mov x5, x3 // __pa(KERNEL_START)
393 add x6, x6, x28 // __pa(KERNEL_END)
394 create_block_map x0, x7, x3, x5, x6
395
396 /*
397 * Map the kernel image (starting with PHYS_OFFSET).
398 */
399 mov x0, x26 // swapper_pg_dir
400 mov x5, #PAGE_OFFSET
401 create_pgd_entry x0, x5, x3, x6
402 ldr x6, =KERNEL_END
403 mov x3, x24 // phys offset
404 create_block_map x0, x7, x3, x5, x6
405
406 /*
407 * Map the FDT blob (maximum 2MB; must be within 512MB of
408 * PHYS_OFFSET).
409 */
410 mov x3, x21 // FDT phys address
411 and x3, x3, #~((1 << 21) - 1) // 2MB aligned
412 mov x6, #PAGE_OFFSET
413 sub x5, x3, x24 // subtract PHYS_OFFSET
414 tst x5, #~((1 << 29) - 1) // within 512MB?
415 csel x21, xzr, x21, ne // zero the FDT pointer
416 b.ne 1f
417 add x5, x5, x6 // __va(FDT blob)
418 add x6, x5, #1 << 21 // 2MB for the FDT blob
419 sub x6, x6, #1 // inclusive range
420 create_block_map x0, x7, x3, x5, x6
4211:
422 /*
423 * Since the page tables have been populated with non-cacheable
424 * accesses (MMU disabled), invalidate the idmap and swapper page
425 * tables again to remove any speculatively loaded cache lines.
426 */
427 mov x0, x25
428 add x1, x26, #SWAPPER_DIR_SIZE
429 bl __inval_cache_range
430
431 mov lr, x27
432 ret
433ENDPROC(__create_page_tables)
434 .ltorg
435
436 .align 3
437 .type __switch_data, %object
438__switch_data:
439 .quad __mmap_switched
440 .quad __bss_start // x6
441 .quad __bss_stop // x7
442 .quad processor_id // x4
443 .quad __fdt_pointer // x5
444 .quad memstart_addr // x6
445 .quad init_thread_union + THREAD_START_SP // sp
446
447/*
448 * The following fragment of code is executed with the MMU on in MMU mode, and
449 * uses absolute addresses; this is not position independent.
450 */
451__mmap_switched:
452 adr x3, __switch_data + 8
453
454 ldp x6, x7, [x3], #16
4551: cmp x6, x7
456 b.hs 2f
457 str xzr, [x6], #8 // Clear BSS
458 b 1b
4592:
460 ldp x4, x5, [x3], #16
461 ldr x6, [x3], #8
462 ldr x16, [x3]
463 mov sp, x16
464 str x22, [x4] // Save processor ID
465 str x21, [x5] // Save FDT pointer
466 str x24, [x6] // Save PHYS_OFFSET
467 mov x29, #0
468 b start_kernel
469ENDPROC(__mmap_switched)
470
471/*
472 * end early head section, begin head code that is also used for
473 * hotplug and needs to have the same protections as the text region
474 */
475 .section ".text","ax"
476/*
260 * If we're fortunate enough to boot at EL2, ensure that the world is 477 * If we're fortunate enough to boot at EL2, ensure that the world is
261 * sane before dropping to EL1. 478 * sane before dropping to EL1.
262 * 479 *
@@ -331,7 +548,8 @@ CPU_LE( movk x0, #0x30d0, lsl #16 ) // Clear EE and E0E on LE systems
331 msr vttbr_el2, xzr 548 msr vttbr_el2, xzr
332 549
333 /* Hypervisor stub */ 550 /* Hypervisor stub */
334 adr x0, __hyp_stub_vectors 551 adrp x0, __hyp_stub_vectors
552 add x0, x0, #:lo12:__hyp_stub_vectors
335 msr vbar_el2, x0 553 msr vbar_el2, x0
336 554
337 /* spsr */ 555 /* spsr */
@@ -492,183 +710,6 @@ ENDPROC(__calc_phys_offset)
492 .quad PAGE_OFFSET 710 .quad PAGE_OFFSET
493 711
494/* 712/*
495 * Macro to create a table entry to the next page.
496 *
497 * tbl: page table address
498 * virt: virtual address
499 * shift: #imm page table shift
500 * ptrs: #imm pointers per table page
501 *
502 * Preserves: virt
503 * Corrupts: tmp1, tmp2
504 * Returns: tbl -> next level table page address
505 */
506 .macro create_table_entry, tbl, virt, shift, ptrs, tmp1, tmp2
507 lsr \tmp1, \virt, #\shift
508 and \tmp1, \tmp1, #\ptrs - 1 // table index
509 add \tmp2, \tbl, #PAGE_SIZE
510 orr \tmp2, \tmp2, #PMD_TYPE_TABLE // address of next table and entry type
511 str \tmp2, [\tbl, \tmp1, lsl #3]
512 add \tbl, \tbl, #PAGE_SIZE // next level table page
513 .endm
514
515/*
516 * Macro to populate the PGD (and possibily PUD) for the corresponding
517 * block entry in the next level (tbl) for the given virtual address.
518 *
519 * Preserves: tbl, next, virt
520 * Corrupts: tmp1, tmp2
521 */
522 .macro create_pgd_entry, tbl, virt, tmp1, tmp2
523 create_table_entry \tbl, \virt, PGDIR_SHIFT, PTRS_PER_PGD, \tmp1, \tmp2
524#if SWAPPER_PGTABLE_LEVELS == 3
525 create_table_entry \tbl, \virt, TABLE_SHIFT, PTRS_PER_PTE, \tmp1, \tmp2
526#endif
527 .endm
528
529/*
530 * Macro to populate block entries in the page table for the start..end
531 * virtual range (inclusive).
532 *
533 * Preserves: tbl, flags
534 * Corrupts: phys, start, end, pstate
535 */
536 .macro create_block_map, tbl, flags, phys, start, end
537 lsr \phys, \phys, #BLOCK_SHIFT
538 lsr \start, \start, #BLOCK_SHIFT
539 and \start, \start, #PTRS_PER_PTE - 1 // table index
540 orr \phys, \flags, \phys, lsl #BLOCK_SHIFT // table entry
541 lsr \end, \end, #BLOCK_SHIFT
542 and \end, \end, #PTRS_PER_PTE - 1 // table end index
5439999: str \phys, [\tbl, \start, lsl #3] // store the entry
544 add \start, \start, #1 // next entry
545 add \phys, \phys, #BLOCK_SIZE // next block
546 cmp \start, \end
547 b.ls 9999b
548 .endm
549
550/*
551 * Setup the initial page tables. We only setup the barest amount which is
552 * required to get the kernel running. The following sections are required:
553 * - identity mapping to enable the MMU (low address, TTBR0)
554 * - first few MB of the kernel linear mapping to jump to once the MMU has
555 * been enabled, including the FDT blob (TTBR1)
556 * - pgd entry for fixed mappings (TTBR1)
557 */
558__create_page_tables:
559 pgtbl x25, x26, x28 // idmap_pg_dir and swapper_pg_dir addresses
560 mov x27, lr
561
562 /*
563 * Invalidate the idmap and swapper page tables to avoid potential
564 * dirty cache lines being evicted.
565 */
566 mov x0, x25
567 add x1, x26, #SWAPPER_DIR_SIZE
568 bl __inval_cache_range
569
570 /*
571 * Clear the idmap and swapper page tables.
572 */
573 mov x0, x25
574 add x6, x26, #SWAPPER_DIR_SIZE
5751: stp xzr, xzr, [x0], #16
576 stp xzr, xzr, [x0], #16
577 stp xzr, xzr, [x0], #16
578 stp xzr, xzr, [x0], #16
579 cmp x0, x6
580 b.lo 1b
581
582 ldr x7, =MM_MMUFLAGS
583
584 /*
585 * Create the identity mapping.
586 */
587 mov x0, x25 // idmap_pg_dir
588 ldr x3, =KERNEL_START
589 add x3, x3, x28 // __pa(KERNEL_START)
590 create_pgd_entry x0, x3, x5, x6
591 ldr x6, =KERNEL_END
592 mov x5, x3 // __pa(KERNEL_START)
593 add x6, x6, x28 // __pa(KERNEL_END)
594 create_block_map x0, x7, x3, x5, x6
595
596 /*
597 * Map the kernel image (starting with PHYS_OFFSET).
598 */
599 mov x0, x26 // swapper_pg_dir
600 mov x5, #PAGE_OFFSET
601 create_pgd_entry x0, x5, x3, x6
602 ldr x6, =KERNEL_END
603 mov x3, x24 // phys offset
604 create_block_map x0, x7, x3, x5, x6
605
606 /*
607 * Map the FDT blob (maximum 2MB; must be within 512MB of
608 * PHYS_OFFSET).
609 */
610 mov x3, x21 // FDT phys address
611 and x3, x3, #~((1 << 21) - 1) // 2MB aligned
612 mov x6, #PAGE_OFFSET
613 sub x5, x3, x24 // subtract PHYS_OFFSET
614 tst x5, #~((1 << 29) - 1) // within 512MB?
615 csel x21, xzr, x21, ne // zero the FDT pointer
616 b.ne 1f
617 add x5, x5, x6 // __va(FDT blob)
618 add x6, x5, #1 << 21 // 2MB for the FDT blob
619 sub x6, x6, #1 // inclusive range
620 create_block_map x0, x7, x3, x5, x6
6211:
622 /*
623 * Since the page tables have been populated with non-cacheable
624 * accesses (MMU disabled), invalidate the idmap and swapper page
625 * tables again to remove any speculatively loaded cache lines.
626 */
627 mov x0, x25
628 add x1, x26, #SWAPPER_DIR_SIZE
629 bl __inval_cache_range
630
631 mov lr, x27
632 ret
633ENDPROC(__create_page_tables)
634 .ltorg
635
636 .align 3
637 .type __switch_data, %object
638__switch_data:
639 .quad __mmap_switched
640 .quad __bss_start // x6
641 .quad __bss_stop // x7
642 .quad processor_id // x4
643 .quad __fdt_pointer // x5
644 .quad memstart_addr // x6
645 .quad init_thread_union + THREAD_START_SP // sp
646
647/*
648 * The following fragment of code is executed with the MMU on in MMU mode, and
649 * uses absolute addresses; this is not position independent.
650 */
651__mmap_switched:
652 adr x3, __switch_data + 8
653
654 ldp x6, x7, [x3], #16
6551: cmp x6, x7
656 b.hs 2f
657 str xzr, [x6], #8 // Clear BSS
658 b 1b
6592:
660 ldp x4, x5, [x3], #16
661 ldr x6, [x3], #8
662 ldr x16, [x3]
663 mov sp, x16
664 str x22, [x4] // Save processor ID
665 str x21, [x5] // Save FDT pointer
666 str x24, [x6] // Save PHYS_OFFSET
667 mov x29, #0
668 b start_kernel
669ENDPROC(__mmap_switched)
670
671/*
672 * Exception handling. Something went wrong and we can't proceed. We ought to 713 * Exception handling. Something went wrong and we can't proceed. We ought to
673 * tell the user, but since we don't have any guarantee that we're even 714 * tell the user, but since we don't have any guarantee that we're even
674 * running on the right architecture, we do virtually nothing. 715 * running on the right architecture, we do virtually nothing.
@@ -715,22 +756,3 @@ __lookup_processor_type_data:
715 .quad . 756 .quad .
716 .quad cpu_table 757 .quad cpu_table
717 .size __lookup_processor_type_data, . - __lookup_processor_type_data 758 .size __lookup_processor_type_data, . - __lookup_processor_type_data
718
719/*
720 * Determine validity of the x21 FDT pointer.
721 * The dtb must be 8-byte aligned and live in the first 512M of memory.
722 */
723__vet_fdt:
724 tst x21, #0x7
725 b.ne 1f
726 cmp x21, x24
727 b.lt 1f
728 mov x0, #(1 << 29)
729 add x0, x0, x24
730 cmp x21, x0
731 b.ge 1f
732 ret
7331:
734 mov x21, #0
735 ret
736ENDPROC(__vet_fdt)
diff --git a/arch/arm64/kernel/insn.c b/arch/arm64/kernel/insn.c
index e007714ded04..7e9327a0986d 100644
--- a/arch/arm64/kernel/insn.c
+++ b/arch/arm64/kernel/insn.c
@@ -163,9 +163,10 @@ static int __kprobes aarch64_insn_patch_text_cb(void *arg)
163 * which ends with "dsb; isb" pair guaranteeing global 163 * which ends with "dsb; isb" pair guaranteeing global
164 * visibility. 164 * visibility.
165 */ 165 */
166 atomic_set(&pp->cpu_count, -1); 166 /* Notify other processors with an additional increment. */
167 atomic_inc(&pp->cpu_count);
167 } else { 168 } else {
168 while (atomic_read(&pp->cpu_count) != -1) 169 while (atomic_read(&pp->cpu_count) <= num_online_cpus())
169 cpu_relax(); 170 cpu_relax();
170 isb(); 171 isb();
171 } 172 }
@@ -959,3 +960,29 @@ u32 aarch64_insn_gen_logical_shifted_reg(enum aarch64_insn_register dst,
959 960
960 return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_6, insn, shift); 961 return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_6, insn, shift);
961} 962}
963
964bool aarch32_insn_is_wide(u32 insn)
965{
966 return insn >= 0xe800;
967}
968
969/*
970 * Macros/defines for extracting register numbers from instruction.
971 */
972u32 aarch32_insn_extract_reg_num(u32 insn, int offset)
973{
974 return (insn & (0xf << offset)) >> offset;
975}
976
977#define OPC2_MASK 0x7
978#define OPC2_OFFSET 5
979u32 aarch32_insn_mcr_extract_opc2(u32 insn)
980{
981 return (insn & (OPC2_MASK << OPC2_OFFSET)) >> OPC2_OFFSET;
982}
983
984#define CRM_MASK 0xf
985u32 aarch32_insn_mcr_extract_crm(u32 insn)
986{
987 return insn & CRM_MASK;
988}
diff --git a/arch/arm64/kernel/io.c b/arch/arm64/kernel/io.c
index 7d37ead4d199..354be2a872ae 100644
--- a/arch/arm64/kernel/io.c
+++ b/arch/arm64/kernel/io.c
@@ -25,12 +25,26 @@
25 */ 25 */
26void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count) 26void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count)
27{ 27{
28 unsigned char *t = to; 28 while (count && (!IS_ALIGNED((unsigned long)from, 8) ||
29 while (count) { 29 !IS_ALIGNED((unsigned long)to, 8))) {
30 *(u8 *)to = __raw_readb(from);
31 from++;
32 to++;
30 count--; 33 count--;
31 *t = readb(from); 34 }
32 t++; 35
36 while (count >= 8) {
37 *(u64 *)to = __raw_readq(from);
38 from += 8;
39 to += 8;
40 count -= 8;
41 }
42
43 while (count) {
44 *(u8 *)to = __raw_readb(from);
33 from++; 45 from++;
46 to++;
47 count--;
34 } 48 }
35} 49}
36EXPORT_SYMBOL(__memcpy_fromio); 50EXPORT_SYMBOL(__memcpy_fromio);
@@ -40,12 +54,26 @@ EXPORT_SYMBOL(__memcpy_fromio);
40 */ 54 */
41void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count) 55void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count)
42{ 56{
43 const unsigned char *f = from; 57 while (count && (!IS_ALIGNED((unsigned long)to, 8) ||
44 while (count) { 58 !IS_ALIGNED((unsigned long)from, 8))) {
59 __raw_writeb(*(volatile u8 *)from, to);
60 from++;
61 to++;
45 count--; 62 count--;
46 writeb(*f, to); 63 }
47 f++; 64
65 while (count >= 8) {
66 __raw_writeq(*(volatile u64 *)from, to);
67 from += 8;
68 to += 8;
69 count -= 8;
70 }
71
72 while (count) {
73 __raw_writeb(*(volatile u8 *)from, to);
74 from++;
48 to++; 75 to++;
76 count--;
49 } 77 }
50} 78}
51EXPORT_SYMBOL(__memcpy_toio); 79EXPORT_SYMBOL(__memcpy_toio);
@@ -55,10 +83,28 @@ EXPORT_SYMBOL(__memcpy_toio);
55 */ 83 */
56void __memset_io(volatile void __iomem *dst, int c, size_t count) 84void __memset_io(volatile void __iomem *dst, int c, size_t count)
57{ 85{
58 while (count) { 86 u64 qc = (u8)c;
87
88 qc |= qc << 8;
89 qc |= qc << 16;
90 qc |= qc << 32;
91
92 while (count && !IS_ALIGNED((unsigned long)dst, 8)) {
93 __raw_writeb(c, dst);
94 dst++;
59 count--; 95 count--;
60 writeb(c, dst); 96 }
97
98 while (count >= 8) {
99 __raw_writeq(qc, dst);
100 dst += 8;
101 count -= 8;
102 }
103
104 while (count) {
105 __raw_writeb(c, dst);
61 dst++; 106 dst++;
107 count--;
62 } 108 }
63} 109}
64EXPORT_SYMBOL(__memset_io); 110EXPORT_SYMBOL(__memset_io);
diff --git a/arch/arm64/kernel/irq.c b/arch/arm64/kernel/irq.c
index 071a6ec13bd8..240b75c0e94f 100644
--- a/arch/arm64/kernel/irq.c
+++ b/arch/arm64/kernel/irq.c
@@ -40,6 +40,8 @@ int arch_show_interrupts(struct seq_file *p, int prec)
40 return 0; 40 return 0;
41} 41}
42 42
43void (*handle_arch_irq)(struct pt_regs *) = NULL;
44
43void __init set_handle_irq(void (*handle_irq)(struct pt_regs *)) 45void __init set_handle_irq(void (*handle_irq)(struct pt_regs *))
44{ 46{
45 if (handle_arch_irq) 47 if (handle_arch_irq)
diff --git a/arch/arm64/kernel/jump_label.c b/arch/arm64/kernel/jump_label.c
index 263a166291fb..4f1fec7a46db 100644
--- a/arch/arm64/kernel/jump_label.c
+++ b/arch/arm64/kernel/jump_label.c
@@ -22,9 +22,8 @@
22 22
23#ifdef HAVE_JUMP_LABEL 23#ifdef HAVE_JUMP_LABEL
24 24
25static void __arch_jump_label_transform(struct jump_entry *entry, 25void arch_jump_label_transform(struct jump_entry *entry,
26 enum jump_label_type type, 26 enum jump_label_type type)
27 bool is_static)
28{ 27{
29 void *addr = (void *)entry->code; 28 void *addr = (void *)entry->code;
30 u32 insn; 29 u32 insn;
@@ -37,22 +36,18 @@ static void __arch_jump_label_transform(struct jump_entry *entry,
37 insn = aarch64_insn_gen_nop(); 36 insn = aarch64_insn_gen_nop();
38 } 37 }
39 38
40 if (is_static) 39 aarch64_insn_patch_text(&addr, &insn, 1);
41 aarch64_insn_patch_text_nosync(addr, insn);
42 else
43 aarch64_insn_patch_text(&addr, &insn, 1);
44}
45
46void arch_jump_label_transform(struct jump_entry *entry,
47 enum jump_label_type type)
48{
49 __arch_jump_label_transform(entry, type, false);
50} 40}
51 41
52void arch_jump_label_transform_static(struct jump_entry *entry, 42void arch_jump_label_transform_static(struct jump_entry *entry,
53 enum jump_label_type type) 43 enum jump_label_type type)
54{ 44{
55 __arch_jump_label_transform(entry, type, true); 45 /*
46 * We use the architected A64 NOP in arch_static_branch, so there's no
47 * need to patch an identical A64 NOP over the top of it here. The core
48 * will call arch_jump_label_transform from a module notifier if the
49 * NOP needs to be replaced by a branch.
50 */
56} 51}
57 52
58#endif /* HAVE_JUMP_LABEL */ 53#endif /* HAVE_JUMP_LABEL */
diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c
index 1eb1cc955139..fd027b101de5 100644
--- a/arch/arm64/kernel/module.c
+++ b/arch/arm64/kernel/module.c
@@ -26,6 +26,7 @@
26#include <linux/moduleloader.h> 26#include <linux/moduleloader.h>
27#include <linux/vmalloc.h> 27#include <linux/vmalloc.h>
28#include <asm/insn.h> 28#include <asm/insn.h>
29#include <asm/sections.h>
29 30
30#define AARCH64_INSN_IMM_MOVNZ AARCH64_INSN_IMM_MAX 31#define AARCH64_INSN_IMM_MOVNZ AARCH64_INSN_IMM_MAX
31#define AARCH64_INSN_IMM_MOVK AARCH64_INSN_IMM_16 32#define AARCH64_INSN_IMM_MOVK AARCH64_INSN_IMM_16
@@ -394,3 +395,20 @@ overflow:
394 me->name, (int)ELF64_R_TYPE(rel[i].r_info), val); 395 me->name, (int)ELF64_R_TYPE(rel[i].r_info), val);
395 return -ENOEXEC; 396 return -ENOEXEC;
396} 397}
398
399int module_finalize(const Elf_Ehdr *hdr,
400 const Elf_Shdr *sechdrs,
401 struct module *me)
402{
403 const Elf_Shdr *s, *se;
404 const char *secstrs = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
405
406 for (s = sechdrs, se = sechdrs + hdr->e_shnum; s < se; s++) {
407 if (strcmp(".altinstructions", secstrs + s->sh_name) == 0) {
408 apply_alternatives((void *)s->sh_addr, s->sh_size);
409 return 0;
410 }
411 }
412
413 return 0;
414}
diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.c
index aa29ecb4f800..25a5308744b1 100644
--- a/arch/arm64/kernel/perf_event.c
+++ b/arch/arm64/kernel/perf_event.c
@@ -169,8 +169,14 @@ armpmu_event_set_period(struct perf_event *event,
169 ret = 1; 169 ret = 1;
170 } 170 }
171 171
172 if (left > (s64)armpmu->max_period) 172 /*
173 left = armpmu->max_period; 173 * Limit the maximum period to prevent the counter value
174 * from overtaking the one we are about to program. In
175 * effect we are reducing max_period to account for
176 * interrupt latency (and we are being very conservative).
177 */
178 if (left > (armpmu->max_period >> 1))
179 left = armpmu->max_period >> 1;
174 180
175 local64_set(&hwc->prev_count, (u64)-left); 181 local64_set(&hwc->prev_count, (u64)-left);
176 182
diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
index 866c1c821860..663da771580a 100644
--- a/arch/arm64/kernel/psci.c
+++ b/arch/arm64/kernel/psci.c
@@ -528,7 +528,7 @@ static int __maybe_unused cpu_psci_cpu_suspend(unsigned long index)
528 if (WARN_ON_ONCE(!index)) 528 if (WARN_ON_ONCE(!index))
529 return -EINVAL; 529 return -EINVAL;
530 530
531 if (state->type == PSCI_POWER_STATE_TYPE_STANDBY) 531 if (state[index - 1].type == PSCI_POWER_STATE_TYPE_STANDBY)
532 ret = psci_ops.cpu_suspend(state[index - 1], 0); 532 ret = psci_ops.cpu_suspend(state[index - 1], 0);
533 else 533 else
534 ret = __cpu_suspend(index, psci_suspend_finisher); 534 ret = __cpu_suspend(index, psci_suspend_finisher);
diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c
index 8a4ae8e73213..d882b833dbdb 100644
--- a/arch/arm64/kernel/ptrace.c
+++ b/arch/arm64/kernel/ptrace.c
@@ -27,6 +27,7 @@
27#include <linux/smp.h> 27#include <linux/smp.h>
28#include <linux/ptrace.h> 28#include <linux/ptrace.h>
29#include <linux/user.h> 29#include <linux/user.h>
30#include <linux/seccomp.h>
30#include <linux/security.h> 31#include <linux/security.h>
31#include <linux/init.h> 32#include <linux/init.h>
32#include <linux/signal.h> 33#include <linux/signal.h>
@@ -551,6 +552,32 @@ static int tls_set(struct task_struct *target, const struct user_regset *regset,
551 return ret; 552 return ret;
552} 553}
553 554
555static int system_call_get(struct task_struct *target,
556 const struct user_regset *regset,
557 unsigned int pos, unsigned int count,
558 void *kbuf, void __user *ubuf)
559{
560 int syscallno = task_pt_regs(target)->syscallno;
561
562 return user_regset_copyout(&pos, &count, &kbuf, &ubuf,
563 &syscallno, 0, -1);
564}
565
566static int system_call_set(struct task_struct *target,
567 const struct user_regset *regset,
568 unsigned int pos, unsigned int count,
569 const void *kbuf, const void __user *ubuf)
570{
571 int syscallno, ret;
572
573 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &syscallno, 0, -1);
574 if (ret)
575 return ret;
576
577 task_pt_regs(target)->syscallno = syscallno;
578 return ret;
579}
580
554enum aarch64_regset { 581enum aarch64_regset {
555 REGSET_GPR, 582 REGSET_GPR,
556 REGSET_FPR, 583 REGSET_FPR,
@@ -559,6 +586,7 @@ enum aarch64_regset {
559 REGSET_HW_BREAK, 586 REGSET_HW_BREAK,
560 REGSET_HW_WATCH, 587 REGSET_HW_WATCH,
561#endif 588#endif
589 REGSET_SYSTEM_CALL,
562}; 590};
563 591
564static const struct user_regset aarch64_regsets[] = { 592static const struct user_regset aarch64_regsets[] = {
@@ -608,6 +636,14 @@ static const struct user_regset aarch64_regsets[] = {
608 .set = hw_break_set, 636 .set = hw_break_set,
609 }, 637 },
610#endif 638#endif
639 [REGSET_SYSTEM_CALL] = {
640 .core_note_type = NT_ARM_SYSTEM_CALL,
641 .n = 1,
642 .size = sizeof(int),
643 .align = sizeof(int),
644 .get = system_call_get,
645 .set = system_call_set,
646 },
611}; 647};
612 648
613static const struct user_regset_view user_aarch64_view = { 649static const struct user_regset_view user_aarch64_view = {
@@ -1114,6 +1150,10 @@ static void tracehook_report_syscall(struct pt_regs *regs,
1114 1150
1115asmlinkage int syscall_trace_enter(struct pt_regs *regs) 1151asmlinkage int syscall_trace_enter(struct pt_regs *regs)
1116{ 1152{
1153 /* Do the secure computing check first; failures should be fast. */
1154 if (secure_computing() == -1)
1155 return -1;
1156
1117 if (test_thread_flag(TIF_SYSCALL_TRACE)) 1157 if (test_thread_flag(TIF_SYSCALL_TRACE))
1118 tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER); 1158 tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
1119 1159
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 2437196cc5d4..b80991166754 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -43,12 +43,14 @@
43#include <linux/of_fdt.h> 43#include <linux/of_fdt.h>
44#include <linux/of_platform.h> 44#include <linux/of_platform.h>
45#include <linux/efi.h> 45#include <linux/efi.h>
46#include <linux/personality.h>
46 47
47#include <asm/fixmap.h> 48#include <asm/fixmap.h>
48#include <asm/cpu.h> 49#include <asm/cpu.h>
49#include <asm/cputype.h> 50#include <asm/cputype.h>
50#include <asm/elf.h> 51#include <asm/elf.h>
51#include <asm/cputable.h> 52#include <asm/cputable.h>
53#include <asm/cpufeature.h>
52#include <asm/cpu_ops.h> 54#include <asm/cpu_ops.h>
53#include <asm/sections.h> 55#include <asm/sections.h>
54#include <asm/setup.h> 56#include <asm/setup.h>
@@ -72,13 +74,15 @@ EXPORT_SYMBOL_GPL(elf_hwcap);
72 COMPAT_HWCAP_FAST_MULT|COMPAT_HWCAP_EDSP|\ 74 COMPAT_HWCAP_FAST_MULT|COMPAT_HWCAP_EDSP|\
73 COMPAT_HWCAP_TLS|COMPAT_HWCAP_VFP|\ 75 COMPAT_HWCAP_TLS|COMPAT_HWCAP_VFP|\
74 COMPAT_HWCAP_VFPv3|COMPAT_HWCAP_VFPv4|\ 76 COMPAT_HWCAP_VFPv3|COMPAT_HWCAP_VFPv4|\
75 COMPAT_HWCAP_NEON|COMPAT_HWCAP_IDIV) 77 COMPAT_HWCAP_NEON|COMPAT_HWCAP_IDIV|\
78 COMPAT_HWCAP_LPAE)
76unsigned int compat_elf_hwcap __read_mostly = COMPAT_ELF_HWCAP_DEFAULT; 79unsigned int compat_elf_hwcap __read_mostly = COMPAT_ELF_HWCAP_DEFAULT;
77unsigned int compat_elf_hwcap2 __read_mostly; 80unsigned int compat_elf_hwcap2 __read_mostly;
78#endif 81#endif
79 82
83DECLARE_BITMAP(cpu_hwcaps, ARM64_NCAPS);
84
80static const char *cpu_name; 85static const char *cpu_name;
81static const char *machine_name;
82phys_addr_t __fdt_pointer __initdata; 86phys_addr_t __fdt_pointer __initdata;
83 87
84/* 88/*
@@ -116,12 +120,16 @@ void __init early_print(const char *str, ...)
116 120
117void __init smp_setup_processor_id(void) 121void __init smp_setup_processor_id(void)
118{ 122{
123 u64 mpidr = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
124 cpu_logical_map(0) = mpidr;
125
119 /* 126 /*
120 * clear __my_cpu_offset on boot CPU to avoid hang caused by 127 * clear __my_cpu_offset on boot CPU to avoid hang caused by
121 * using percpu variable early, for example, lockdep will 128 * using percpu variable early, for example, lockdep will
122 * access percpu variable inside lock_release 129 * access percpu variable inside lock_release
123 */ 130 */
124 set_my_cpu_offset(0); 131 set_my_cpu_offset(0);
132 pr_info("Booting Linux on physical CPU 0x%lx\n", (unsigned long)mpidr);
125} 133}
126 134
127bool arch_match_cpu_phys_id(int cpu, u64 phys_id) 135bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
@@ -311,7 +319,7 @@ static void __init setup_machine_fdt(phys_addr_t dt_phys)
311 cpu_relax(); 319 cpu_relax();
312 } 320 }
313 321
314 machine_name = of_flat_dt_get_machine_name(); 322 dump_stack_set_arch_desc("%s (DT)", of_flat_dt_get_machine_name());
315} 323}
316 324
317/* 325/*
@@ -376,6 +384,7 @@ void __init setup_arch(char **cmdline_p)
376 384
377 *cmdline_p = boot_command_line; 385 *cmdline_p = boot_command_line;
378 386
387 early_fixmap_init();
379 early_ioremap_init(); 388 early_ioremap_init();
380 389
381 parse_early_param(); 390 parse_early_param();
@@ -398,7 +407,6 @@ void __init setup_arch(char **cmdline_p)
398 407
399 psci_init(); 408 psci_init();
400 409
401 cpu_logical_map(0) = read_cpuid_mpidr() & MPIDR_HWID_BITMASK;
402 cpu_read_bootcpu_ops(); 410 cpu_read_bootcpu_ops();
403#ifdef CONFIG_SMP 411#ifdef CONFIG_SMP
404 smp_init_cpus(); 412 smp_init_cpus();
@@ -447,14 +455,50 @@ static const char *hwcap_str[] = {
447 NULL 455 NULL
448}; 456};
449 457
458#ifdef CONFIG_COMPAT
459static const char *compat_hwcap_str[] = {
460 "swp",
461 "half",
462 "thumb",
463 "26bit",
464 "fastmult",
465 "fpa",
466 "vfp",
467 "edsp",
468 "java",
469 "iwmmxt",
470 "crunch",
471 "thumbee",
472 "neon",
473 "vfpv3",
474 "vfpv3d16",
475 "tls",
476 "vfpv4",
477 "idiva",
478 "idivt",
479 "vfpd32",
480 "lpae",
481 "evtstrm"
482};
483
484static const char *compat_hwcap2_str[] = {
485 "aes",
486 "pmull",
487 "sha1",
488 "sha2",
489 "crc32",
490 NULL
491};
492#endif /* CONFIG_COMPAT */
493
450static int c_show(struct seq_file *m, void *v) 494static int c_show(struct seq_file *m, void *v)
451{ 495{
452 int i; 496 int i, j;
453
454 seq_printf(m, "Processor\t: %s rev %d (%s)\n",
455 cpu_name, read_cpuid_id() & 15, ELF_PLATFORM);
456 497
457 for_each_online_cpu(i) { 498 for_each_online_cpu(i) {
499 struct cpuinfo_arm64 *cpuinfo = &per_cpu(cpu_data, i);
500 u32 midr = cpuinfo->reg_midr;
501
458 /* 502 /*
459 * glibc reads /proc/cpuinfo to determine the number of 503 * glibc reads /proc/cpuinfo to determine the number of
460 * online processors, looking for lines beginning with 504 * online processors, looking for lines beginning with
@@ -463,24 +507,38 @@ static int c_show(struct seq_file *m, void *v)
463#ifdef CONFIG_SMP 507#ifdef CONFIG_SMP
464 seq_printf(m, "processor\t: %d\n", i); 508 seq_printf(m, "processor\t: %d\n", i);
465#endif 509#endif
466 }
467
468 /* dump out the processor features */
469 seq_puts(m, "Features\t: ");
470
471 for (i = 0; hwcap_str[i]; i++)
472 if (elf_hwcap & (1 << i))
473 seq_printf(m, "%s ", hwcap_str[i]);
474
475 seq_printf(m, "\nCPU implementer\t: 0x%02x\n", read_cpuid_id() >> 24);
476 seq_printf(m, "CPU architecture: AArch64\n");
477 seq_printf(m, "CPU variant\t: 0x%x\n", (read_cpuid_id() >> 20) & 15);
478 seq_printf(m, "CPU part\t: 0x%03x\n", (read_cpuid_id() >> 4) & 0xfff);
479 seq_printf(m, "CPU revision\t: %d\n", read_cpuid_id() & 15);
480 510
481 seq_puts(m, "\n"); 511 /*
482 512 * Dump out the common processor features in a single line.
483 seq_printf(m, "Hardware\t: %s\n", machine_name); 513 * Userspace should read the hwcaps with getauxval(AT_HWCAP)
514 * rather than attempting to parse this, but there's a body of
515 * software which does already (at least for 32-bit).
516 */
517 seq_puts(m, "Features\t:");
518 if (personality(current->personality) == PER_LINUX32) {
519#ifdef CONFIG_COMPAT
520 for (j = 0; compat_hwcap_str[j]; j++)
521 if (compat_elf_hwcap & (1 << j))
522 seq_printf(m, " %s", compat_hwcap_str[j]);
523
524 for (j = 0; compat_hwcap2_str[j]; j++)
525 if (compat_elf_hwcap2 & (1 << j))
526 seq_printf(m, " %s", compat_hwcap2_str[j]);
527#endif /* CONFIG_COMPAT */
528 } else {
529 for (j = 0; hwcap_str[j]; j++)
530 if (elf_hwcap & (1 << j))
531 seq_printf(m, " %s", hwcap_str[j]);
532 }
533 seq_puts(m, "\n");
534
535 seq_printf(m, "CPU implementer\t: 0x%02x\n",
536 MIDR_IMPLEMENTOR(midr));
537 seq_printf(m, "CPU architecture: 8\n");
538 seq_printf(m, "CPU variant\t: 0x%x\n", MIDR_VARIANT(midr));
539 seq_printf(m, "CPU part\t: 0x%03x\n", MIDR_PARTNUM(midr));
540 seq_printf(m, "CPU revision\t: %d\n\n", MIDR_REVISION(midr));
541 }
484 542
485 return 0; 543 return 0;
486} 544}
diff --git a/arch/arm64/kernel/signal32.c b/arch/arm64/kernel/signal32.c
index 1b9ad02837cf..5a1ba6e80d4e 100644
--- a/arch/arm64/kernel/signal32.c
+++ b/arch/arm64/kernel/signal32.c
@@ -186,6 +186,12 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, const siginfo_t *from)
186 err |= __put_user(from->si_uid, &to->si_uid); 186 err |= __put_user(from->si_uid, &to->si_uid);
187 err |= __put_user((compat_uptr_t)(unsigned long)from->si_ptr, &to->si_ptr); 187 err |= __put_user((compat_uptr_t)(unsigned long)from->si_ptr, &to->si_ptr);
188 break; 188 break;
189 case __SI_SYS:
190 err |= __put_user((compat_uptr_t)(unsigned long)
191 from->si_call_addr, &to->si_call_addr);
192 err |= __put_user(from->si_syscall, &to->si_syscall);
193 err |= __put_user(from->si_arch, &to->si_arch);
194 break;
189 default: /* this is just in case for now ... */ 195 default: /* this is just in case for now ... */
190 err |= __put_user(from->si_pid, &to->si_pid); 196 err |= __put_user(from->si_pid, &to->si_pid);
191 err |= __put_user(from->si_uid, &to->si_uid); 197 err |= __put_user(from->si_uid, &to->si_uid);
diff --git a/arch/arm64/kernel/sleep.S b/arch/arm64/kernel/sleep.S
index a564b440416a..ede186cdd452 100644
--- a/arch/arm64/kernel/sleep.S
+++ b/arch/arm64/kernel/sleep.S
@@ -147,14 +147,12 @@ cpu_resume_after_mmu:
147 ret 147 ret
148ENDPROC(cpu_resume_after_mmu) 148ENDPROC(cpu_resume_after_mmu)
149 149
150 .data
151ENTRY(cpu_resume) 150ENTRY(cpu_resume)
152 bl el2_setup // if in EL2 drop to EL1 cleanly 151 bl el2_setup // if in EL2 drop to EL1 cleanly
153#ifdef CONFIG_SMP 152#ifdef CONFIG_SMP
154 mrs x1, mpidr_el1 153 mrs x1, mpidr_el1
155 adr x4, mpidr_hash_ptr 154 adrp x8, mpidr_hash
156 ldr x5, [x4] 155 add x8, x8, #:lo12:mpidr_hash // x8 = struct mpidr_hash phys address
157 add x8, x4, x5 // x8 = struct mpidr_hash phys address
158 /* retrieve mpidr_hash members to compute the hash */ 156 /* retrieve mpidr_hash members to compute the hash */
159 ldr x2, [x8, #MPIDR_HASH_MASK] 157 ldr x2, [x8, #MPIDR_HASH_MASK]
160 ldp w3, w4, [x8, #MPIDR_HASH_SHIFTS] 158 ldp w3, w4, [x8, #MPIDR_HASH_SHIFTS]
@@ -164,14 +162,15 @@ ENTRY(cpu_resume)
164#else 162#else
165 mov x7, xzr 163 mov x7, xzr
166#endif 164#endif
167 adr x0, sleep_save_sp 165 adrp x0, sleep_save_sp
166 add x0, x0, #:lo12:sleep_save_sp
168 ldr x0, [x0, #SLEEP_SAVE_SP_PHYS] 167 ldr x0, [x0, #SLEEP_SAVE_SP_PHYS]
169 ldr x0, [x0, x7, lsl #3] 168 ldr x0, [x0, x7, lsl #3]
170 /* load sp from context */ 169 /* load sp from context */
171 ldr x2, [x0, #CPU_CTX_SP] 170 ldr x2, [x0, #CPU_CTX_SP]
172 adr x1, sleep_idmap_phys 171 adrp x1, sleep_idmap_phys
173 /* load physical address of identity map page table in x1 */ 172 /* load physical address of identity map page table in x1 */
174 ldr x1, [x1] 173 ldr x1, [x1, #:lo12:sleep_idmap_phys]
175 mov sp, x2 174 mov sp, x2
176 /* 175 /*
177 * cpu_do_resume expects x0 to contain context physical address 176 * cpu_do_resume expects x0 to contain context physical address
@@ -180,26 +179,3 @@ ENTRY(cpu_resume)
180 bl cpu_do_resume // PC relative jump, MMU off 179 bl cpu_do_resume // PC relative jump, MMU off
181 b cpu_resume_mmu // Resume MMU, never returns 180 b cpu_resume_mmu // Resume MMU, never returns
182ENDPROC(cpu_resume) 181ENDPROC(cpu_resume)
183
184 .align 3
185mpidr_hash_ptr:
186 /*
187 * offset of mpidr_hash symbol from current location
188 * used to obtain run-time mpidr_hash address with MMU off
189 */
190 .quad mpidr_hash - .
191/*
192 * physical address of identity mapped page tables
193 */
194 .type sleep_idmap_phys, #object
195ENTRY(sleep_idmap_phys)
196 .quad 0
197/*
198 * struct sleep_save_sp {
199 * phys_addr_t *save_ptr_stash;
200 * phys_addr_t save_ptr_stash_phys;
201 * };
202 */
203 .type sleep_save_sp, #object
204ENTRY(sleep_save_sp)
205 .space SLEEP_SAVE_SP_SZ // struct sleep_save_sp
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index b06d1d90ee8c..7ae6ee085261 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -37,6 +37,7 @@
37#include <linux/of.h> 37#include <linux/of.h>
38#include <linux/irq_work.h> 38#include <linux/irq_work.h>
39 39
40#include <asm/alternative.h>
40#include <asm/atomic.h> 41#include <asm/atomic.h>
41#include <asm/cacheflush.h> 42#include <asm/cacheflush.h>
42#include <asm/cpu.h> 43#include <asm/cpu.h>
@@ -309,6 +310,7 @@ void cpu_die(void)
309void __init smp_cpus_done(unsigned int max_cpus) 310void __init smp_cpus_done(unsigned int max_cpus)
310{ 311{
311 pr_info("SMP: Total of %d processors activated.\n", num_online_cpus()); 312 pr_info("SMP: Total of %d processors activated.\n", num_online_cpus());
313 apply_alternatives_all();
312} 314}
313 315
314void __init smp_prepare_boot_cpu(void) 316void __init smp_prepare_boot_cpu(void)
diff --git a/arch/arm64/kernel/suspend.c b/arch/arm64/kernel/suspend.c
index 13ad4dbb1615..3771b72b6569 100644
--- a/arch/arm64/kernel/suspend.c
+++ b/arch/arm64/kernel/suspend.c
@@ -126,8 +126,8 @@ int __cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
126 return ret; 126 return ret;
127} 127}
128 128
129extern struct sleep_save_sp sleep_save_sp; 129struct sleep_save_sp sleep_save_sp;
130extern phys_addr_t sleep_idmap_phys; 130phys_addr_t sleep_idmap_phys;
131 131
132static int __init cpu_suspend_init(void) 132static int __init cpu_suspend_init(void)
133{ 133{
diff --git a/arch/arm64/kernel/sys_compat.c b/arch/arm64/kernel/sys_compat.c
index dc47e53e9e28..28c511b06edf 100644
--- a/arch/arm64/kernel/sys_compat.c
+++ b/arch/arm64/kernel/sys_compat.c
@@ -28,29 +28,39 @@
28#include <asm/cacheflush.h> 28#include <asm/cacheflush.h>
29#include <asm/unistd.h> 29#include <asm/unistd.h>
30 30
31static inline void 31static long
32do_compat_cache_op(unsigned long start, unsigned long end, int flags) 32__do_compat_cache_op(unsigned long start, unsigned long end)
33{ 33{
34 struct mm_struct *mm = current->active_mm; 34 long ret;
35 struct vm_area_struct *vma;
36 35
37 if (end < start || flags) 36 do {
38 return; 37 unsigned long chunk = min(PAGE_SIZE, end - start);
39 38
40 down_read(&mm->mmap_sem); 39 if (fatal_signal_pending(current))
41 vma = find_vma(mm, start); 40 return 0;
42 if (vma && vma->vm_start < end) { 41
43 if (start < vma->vm_start) 42 ret = __flush_cache_user_range(start, start + chunk);
44 start = vma->vm_start; 43 if (ret)
45 if (end > vma->vm_end) 44 return ret;
46 end = vma->vm_end; 45
47 up_read(&mm->mmap_sem); 46 cond_resched();
48 __flush_cache_user_range(start & PAGE_MASK, PAGE_ALIGN(end)); 47 start += chunk;
49 return; 48 } while (start < end);
50 } 49
51 up_read(&mm->mmap_sem); 50 return 0;
52} 51}
53 52
53static inline long
54do_compat_cache_op(unsigned long start, unsigned long end, int flags)
55{
56 if (end < start || flags)
57 return -EINVAL;
58
59 if (!access_ok(VERIFY_READ, start, end - start))
60 return -EFAULT;
61
62 return __do_compat_cache_op(start, end);
63}
54/* 64/*
55 * Handle all unrecognised system calls. 65 * Handle all unrecognised system calls.
56 */ 66 */
@@ -74,8 +84,7 @@ long compat_arm_syscall(struct pt_regs *regs)
74 * the specified region). 84 * the specified region).
75 */ 85 */
76 case __ARM_NR_compat_cacheflush: 86 case __ARM_NR_compat_cacheflush:
77 do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]); 87 return do_compat_cache_op(regs->regs[0], regs->regs[1], regs->regs[2]);
78 return 0;
79 88
80 case __ARM_NR_compat_set_tls: 89 case __ARM_NR_compat_set_tls:
81 current->thread.tp_value = regs->regs[0]; 90 current->thread.tp_value = regs->regs[0];
diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c
index b6ee26b0939a..fcb8f7b42271 100644
--- a/arch/arm64/kernel/topology.c
+++ b/arch/arm64/kernel/topology.c
@@ -255,12 +255,15 @@ void store_cpu_topology(unsigned int cpuid)
255 /* Multiprocessor system : Multi-threads per core */ 255 /* Multiprocessor system : Multi-threads per core */
256 cpuid_topo->thread_id = MPIDR_AFFINITY_LEVEL(mpidr, 0); 256 cpuid_topo->thread_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
257 cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 1); 257 cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 1);
258 cpuid_topo->cluster_id = MPIDR_AFFINITY_LEVEL(mpidr, 2); 258 cpuid_topo->cluster_id = MPIDR_AFFINITY_LEVEL(mpidr, 2) |
259 MPIDR_AFFINITY_LEVEL(mpidr, 3) << 8;
259 } else { 260 } else {
260 /* Multiprocessor system : Single-thread per core */ 261 /* Multiprocessor system : Single-thread per core */
261 cpuid_topo->thread_id = -1; 262 cpuid_topo->thread_id = -1;
262 cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0); 263 cpuid_topo->core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
263 cpuid_topo->cluster_id = MPIDR_AFFINITY_LEVEL(mpidr, 1); 264 cpuid_topo->cluster_id = MPIDR_AFFINITY_LEVEL(mpidr, 1) |
265 MPIDR_AFFINITY_LEVEL(mpidr, 2) << 8 |
266 MPIDR_AFFINITY_LEVEL(mpidr, 3) << 16;
264 } 267 }
265 268
266 pr_debug("CPU%u: cluster %d core %d thread %d mpidr %#016llx\n", 269 pr_debug("CPU%u: cluster %d core %d thread %d mpidr %#016llx\n",
diff --git a/arch/arm64/kernel/trace-events-emulation.h b/arch/arm64/kernel/trace-events-emulation.h
new file mode 100644
index 000000000000..ae1dd598ea65
--- /dev/null
+++ b/arch/arm64/kernel/trace-events-emulation.h
@@ -0,0 +1,35 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM emulation
3
4#if !defined(_TRACE_EMULATION_H) || defined(TRACE_HEADER_MULTI_READ)
5#define _TRACE_EMULATION_H
6
7#include <linux/tracepoint.h>
8
9TRACE_EVENT(instruction_emulation,
10
11 TP_PROTO(const char *instr, u64 addr),
12 TP_ARGS(instr, addr),
13
14 TP_STRUCT__entry(
15 __string(instr, instr)
16 __field(u64, addr)
17 ),
18
19 TP_fast_assign(
20 __assign_str(instr, instr);
21 __entry->addr = addr;
22 ),
23
24 TP_printk("instr=\"%s\" addr=0x%llx", __get_str(instr), __entry->addr)
25);
26
27#endif /* _TRACE_EMULATION_H */
28
29/* This part must be outside protection */
30#undef TRACE_INCLUDE_PATH
31#undef TRACE_INCLUDE_FILE
32#define TRACE_INCLUDE_PATH .
33
34#define TRACE_INCLUDE_FILE trace-events-emulation
35#include <trace/define_trace.h>
diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c
index de1b085e7963..0a801e3743d5 100644
--- a/arch/arm64/kernel/traps.c
+++ b/arch/arm64/kernel/traps.c
@@ -259,6 +259,69 @@ void arm64_notify_die(const char *str, struct pt_regs *regs,
259 } 259 }
260} 260}
261 261
262static LIST_HEAD(undef_hook);
263static DEFINE_RAW_SPINLOCK(undef_lock);
264
265void register_undef_hook(struct undef_hook *hook)
266{
267 unsigned long flags;
268
269 raw_spin_lock_irqsave(&undef_lock, flags);
270 list_add(&hook->node, &undef_hook);
271 raw_spin_unlock_irqrestore(&undef_lock, flags);
272}
273
274void unregister_undef_hook(struct undef_hook *hook)
275{
276 unsigned long flags;
277
278 raw_spin_lock_irqsave(&undef_lock, flags);
279 list_del(&hook->node);
280 raw_spin_unlock_irqrestore(&undef_lock, flags);
281}
282
283static int call_undef_hook(struct pt_regs *regs)
284{
285 struct undef_hook *hook;
286 unsigned long flags;
287 u32 instr;
288 int (*fn)(struct pt_regs *regs, u32 instr) = NULL;
289 void __user *pc = (void __user *)instruction_pointer(regs);
290
291 if (!user_mode(regs))
292 return 1;
293
294 if (compat_thumb_mode(regs)) {
295 /* 16-bit Thumb instruction */
296 if (get_user(instr, (u16 __user *)pc))
297 goto exit;
298 instr = le16_to_cpu(instr);
299 if (aarch32_insn_is_wide(instr)) {
300 u32 instr2;
301
302 if (get_user(instr2, (u16 __user *)(pc + 2)))
303 goto exit;
304 instr2 = le16_to_cpu(instr2);
305 instr = (instr << 16) | instr2;
306 }
307 } else {
308 /* 32-bit ARM instruction */
309 if (get_user(instr, (u32 __user *)pc))
310 goto exit;
311 instr = le32_to_cpu(instr);
312 }
313
314 raw_spin_lock_irqsave(&undef_lock, flags);
315 list_for_each_entry(hook, &undef_hook, node)
316 if ((instr & hook->instr_mask) == hook->instr_val &&
317 (regs->pstate & hook->pstate_mask) == hook->pstate_val)
318 fn = hook->fn;
319
320 raw_spin_unlock_irqrestore(&undef_lock, flags);
321exit:
322 return fn ? fn(regs, instr) : 1;
323}
324
262asmlinkage void __exception do_undefinstr(struct pt_regs *regs) 325asmlinkage void __exception do_undefinstr(struct pt_regs *regs)
263{ 326{
264 siginfo_t info; 327 siginfo_t info;
@@ -268,6 +331,9 @@ asmlinkage void __exception do_undefinstr(struct pt_regs *regs)
268 if (!aarch32_break_handler(regs)) 331 if (!aarch32_break_handler(regs))
269 return; 332 return;
270 333
334 if (call_undef_hook(regs) == 0)
335 return;
336
271 if (show_unhandled_signals && unhandled_signal(current, SIGILL) && 337 if (show_unhandled_signals && unhandled_signal(current, SIGILL) &&
272 printk_ratelimit()) { 338 printk_ratelimit()) {
273 pr_info("%s[%d]: undefined instruction: pc=%p\n", 339 pr_info("%s[%d]: undefined instruction: pc=%p\n",
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index edf8715ba39b..9965ec87cbec 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -11,8 +11,9 @@
11 11
12#include "image.h" 12#include "image.h"
13 13
14#define ARM_EXIT_KEEP(x) 14/* .exit.text needed in case of alternative patching */
15#define ARM_EXIT_DISCARD(x) x 15#define ARM_EXIT_KEEP(x) x
16#define ARM_EXIT_DISCARD(x)
16 17
17OUTPUT_ARCH(aarch64) 18OUTPUT_ARCH(aarch64)
18ENTRY(_text) 19ENTRY(_text)
@@ -32,6 +33,22 @@ jiffies = jiffies_64;
32 *(.hyp.text) \ 33 *(.hyp.text) \
33 VMLINUX_SYMBOL(__hyp_text_end) = .; 34 VMLINUX_SYMBOL(__hyp_text_end) = .;
34 35
36/*
37 * The size of the PE/COFF section that covers the kernel image, which
38 * runs from stext to _edata, must be a round multiple of the PE/COFF
39 * FileAlignment, which we set to its minimum value of 0x200. 'stext'
40 * itself is 4 KB aligned, so padding out _edata to a 0x200 aligned
41 * boundary should be sufficient.
42 */
43PECOFF_FILE_ALIGNMENT = 0x200;
44
45#ifdef CONFIG_EFI
46#define PECOFF_EDATA_PADDING \
47 .pecoff_edata_padding : { BYTE(0); . = ALIGN(PECOFF_FILE_ALIGNMENT); }
48#else
49#define PECOFF_EDATA_PADDING
50#endif
51
35SECTIONS 52SECTIONS
36{ 53{
37 /* 54 /*
@@ -100,9 +117,21 @@ SECTIONS
100 . = ALIGN(PAGE_SIZE); 117 . = ALIGN(PAGE_SIZE);
101 __init_end = .; 118 __init_end = .;
102 119
120 . = ALIGN(4);
121 .altinstructions : {
122 __alt_instructions = .;
123 *(.altinstructions)
124 __alt_instructions_end = .;
125 }
126 .altinstr_replacement : {
127 *(.altinstr_replacement)
128 }
129
130 . = ALIGN(PAGE_SIZE);
103 _data = .; 131 _data = .;
104 _sdata = .; 132 _sdata = .;
105 RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE) 133 RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE)
134 PECOFF_EDATA_PADDING
106 _edata = .; 135 _edata = .;
107 136
108 BSS_SECTION(0, 0, 0) 137 BSS_SECTION(0, 0, 0)
diff --git a/arch/arm64/kvm/hyp.S b/arch/arm64/kvm/hyp.S
index b72aa9f9215c..fbe909fb0a1a 100644
--- a/arch/arm64/kvm/hyp.S
+++ b/arch/arm64/kvm/hyp.S
@@ -761,10 +761,10 @@
761.macro activate_traps 761.macro activate_traps
762 ldr x2, [x0, #VCPU_HCR_EL2] 762 ldr x2, [x0, #VCPU_HCR_EL2]
763 msr hcr_el2, x2 763 msr hcr_el2, x2
764 ldr x2, =(CPTR_EL2_TTA) 764 mov x2, #CPTR_EL2_TTA
765 msr cptr_el2, x2 765 msr cptr_el2, x2
766 766
767 ldr x2, =(1 << 15) // Trap CP15 Cr=15 767 mov x2, #(1 << 15) // Trap CP15 Cr=15
768 msr hstr_el2, x2 768 msr hstr_el2, x2
769 769
770 mrs x2, mdcr_el2 770 mrs x2, mdcr_el2
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
index 4cc3b719208e..3d7c2df89946 100644
--- a/arch/arm64/kvm/sys_regs.c
+++ b/arch/arm64/kvm/sys_regs.c
@@ -424,6 +424,11 @@ static const struct sys_reg_desc sys_reg_descs[] = {
424 /* VBAR_EL1 */ 424 /* VBAR_EL1 */
425 { Op0(0b11), Op1(0b000), CRn(0b1100), CRm(0b0000), Op2(0b000), 425 { Op0(0b11), Op1(0b000), CRn(0b1100), CRm(0b0000), Op2(0b000),
426 NULL, reset_val, VBAR_EL1, 0 }, 426 NULL, reset_val, VBAR_EL1, 0 },
427
428 /* ICC_SRE_EL1 */
429 { Op0(0b11), Op1(0b000), CRn(0b1100), CRm(0b1100), Op2(0b101),
430 trap_raz_wi },
431
427 /* CONTEXTIDR_EL1 */ 432 /* CONTEXTIDR_EL1 */
428 { Op0(0b11), Op1(0b000), CRn(0b1101), CRm(0b0000), Op2(0b001), 433 { Op0(0b11), Op1(0b000), CRn(0b1101), CRm(0b0000), Op2(0b001),
429 access_vm_reg, reset_val, CONTEXTIDR_EL1, 0 }, 434 access_vm_reg, reset_val, CONTEXTIDR_EL1, 0 },
@@ -690,6 +695,10 @@ static const struct sys_reg_desc cp15_regs[] = {
690 { Op1( 0), CRn(10), CRm( 2), Op2( 1), access_vm_reg, NULL, c10_NMRR }, 695 { Op1( 0), CRn(10), CRm( 2), Op2( 1), access_vm_reg, NULL, c10_NMRR },
691 { Op1( 0), CRn(10), CRm( 3), Op2( 0), access_vm_reg, NULL, c10_AMAIR0 }, 696 { Op1( 0), CRn(10), CRm( 3), Op2( 0), access_vm_reg, NULL, c10_AMAIR0 },
692 { Op1( 0), CRn(10), CRm( 3), Op2( 1), access_vm_reg, NULL, c10_AMAIR1 }, 697 { Op1( 0), CRn(10), CRm( 3), Op2( 1), access_vm_reg, NULL, c10_AMAIR1 },
698
699 /* ICC_SRE */
700 { Op1( 0), CRn(12), CRm(12), Op2( 5), trap_raz_wi },
701
693 { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, c13_CID }, 702 { Op1( 0), CRn(13), CRm( 0), Op2( 1), access_vm_reg, NULL, c13_CID },
694}; 703};
695 704
diff --git a/arch/arm64/lib/clear_user.S b/arch/arm64/lib/clear_user.S
index 6e0ed93d51fe..c17967fdf5f6 100644
--- a/arch/arm64/lib/clear_user.S
+++ b/arch/arm64/lib/clear_user.S
@@ -46,7 +46,7 @@ USER(9f, strh wzr, [x0], #2 )
46 sub x1, x1, #2 46 sub x1, x1, #2
474: adds x1, x1, #1 474: adds x1, x1, #1
48 b.mi 5f 48 b.mi 5f
49 strb wzr, [x0] 49USER(9f, strb wzr, [x0] )
505: mov x0, #0 505: mov x0, #0
51 ret 51 ret
52ENDPROC(__clear_user) 52ENDPROC(__clear_user)
diff --git a/arch/arm64/mm/Makefile b/arch/arm64/mm/Makefile
index c56179ed2c09..773d37a14039 100644
--- a/arch/arm64/mm/Makefile
+++ b/arch/arm64/mm/Makefile
@@ -3,3 +3,4 @@ obj-y := dma-mapping.o extable.o fault.o init.o \
3 ioremap.o mmap.o pgd.o mmu.o \ 3 ioremap.o mmap.o pgd.o mmu.o \
4 context.o proc.o pageattr.o 4 context.o proc.o pageattr.o
5obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o 5obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
6obj-$(CONFIG_ARM64_PTDUMP) += dump.o
diff --git a/arch/arm64/mm/cache.S b/arch/arm64/mm/cache.S
index 23663837acff..2560e1e1562e 100644
--- a/arch/arm64/mm/cache.S
+++ b/arch/arm64/mm/cache.S
@@ -17,9 +17,12 @@
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */ 18 */
19 19
20#include <linux/errno.h>
20#include <linux/linkage.h> 21#include <linux/linkage.h>
21#include <linux/init.h> 22#include <linux/init.h>
22#include <asm/assembler.h> 23#include <asm/assembler.h>
24#include <asm/cpufeature.h>
25#include <asm/alternative-asm.h>
23 26
24#include "proc-macros.S" 27#include "proc-macros.S"
25 28
@@ -138,9 +141,12 @@ USER(9f, ic ivau, x4 ) // invalidate I line PoU
138 add x4, x4, x2 141 add x4, x4, x2
139 cmp x4, x1 142 cmp x4, x1
140 b.lo 1b 143 b.lo 1b
1419: // ignore any faulting cache operation
142 dsb ish 144 dsb ish
143 isb 145 isb
146 mov x0, #0
147 ret
1489:
149 mov x0, #-EFAULT
144 ret 150 ret
145ENDPROC(flush_icache_range) 151ENDPROC(flush_icache_range)
146ENDPROC(__flush_cache_user_range) 152ENDPROC(__flush_cache_user_range)
@@ -210,7 +216,7 @@ __dma_clean_range:
210 dcache_line_size x2, x3 216 dcache_line_size x2, x3
211 sub x3, x2, #1 217 sub x3, x2, #1
212 bic x0, x0, x3 218 bic x0, x0, x3
2131: dc cvac, x0 // clean D / U line 2191: alternative_insn "dc cvac, x0", "dc civac, x0", ARM64_WORKAROUND_CLEAN_CACHE
214 add x0, x0, x2 220 add x0, x0, x2
215 cmp x0, x1 221 cmp x0, x1
216 b.lo 1b 222 b.lo 1b
diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c
new file mode 100644
index 000000000000..bf69601be546
--- /dev/null
+++ b/arch/arm64/mm/dump.c
@@ -0,0 +1,332 @@
1/*
2 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
3 * Debug helper to dump the current kernel pagetables of the system
4 * so that we can see what the various memory ranges are set to.
5 *
6 * Derived from x86 and arm implementation:
7 * (C) Copyright 2008 Intel Corporation
8 *
9 * Author: Arjan van de Ven <arjan@linux.intel.com>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; version 2
14 * of the License.
15 */
16#include <linux/debugfs.h>
17#include <linux/fs.h>
18#include <linux/mm.h>
19#include <linux/sched.h>
20#include <linux/seq_file.h>
21
22#include <asm/fixmap.h>
23#include <asm/pgtable.h>
24
25#define LOWEST_ADDR (UL(0xffffffffffffffff) << VA_BITS)
26
27struct addr_marker {
28 unsigned long start_address;
29 const char *name;
30};
31
32enum address_markers_idx {
33 VMALLOC_START_NR = 0,
34 VMALLOC_END_NR,
35#ifdef CONFIG_SPARSEMEM_VMEMMAP
36 VMEMMAP_START_NR,
37 VMEMMAP_END_NR,
38#endif
39 PCI_START_NR,
40 PCI_END_NR,
41 FIXADDR_START_NR,
42 FIXADDR_END_NR,
43 MODULES_START_NR,
44 MODUELS_END_NR,
45 KERNEL_SPACE_NR,
46};
47
48static struct addr_marker address_markers[] = {
49 { VMALLOC_START, "vmalloc() Area" },
50 { VMALLOC_END, "vmalloc() End" },
51#ifdef CONFIG_SPARSEMEM_VMEMMAP
52 { 0, "vmemmap start" },
53 { 0, "vmemmap end" },
54#endif
55 { (unsigned long) PCI_IOBASE, "PCI I/O start" },
56 { (unsigned long) PCI_IOBASE + SZ_16M, "PCI I/O end" },
57 { FIXADDR_START, "Fixmap start" },
58 { FIXADDR_TOP, "Fixmap end" },
59 { MODULES_VADDR, "Modules start" },
60 { MODULES_END, "Modules end" },
61 { PAGE_OFFSET, "Kernel Mapping" },
62 { -1, NULL },
63};
64
65struct pg_state {
66 struct seq_file *seq;
67 const struct addr_marker *marker;
68 unsigned long start_address;
69 unsigned level;
70 u64 current_prot;
71};
72
73struct prot_bits {
74 u64 mask;
75 u64 val;
76 const char *set;
77 const char *clear;
78};
79
80static const struct prot_bits pte_bits[] = {
81 {
82 .mask = PTE_USER,
83 .val = PTE_USER,
84 .set = "USR",
85 .clear = " ",
86 }, {
87 .mask = PTE_RDONLY,
88 .val = PTE_RDONLY,
89 .set = "ro",
90 .clear = "RW",
91 }, {
92 .mask = PTE_PXN,
93 .val = PTE_PXN,
94 .set = "NX",
95 .clear = "x ",
96 }, {
97 .mask = PTE_SHARED,
98 .val = PTE_SHARED,
99 .set = "SHD",
100 .clear = " ",
101 }, {
102 .mask = PTE_AF,
103 .val = PTE_AF,
104 .set = "AF",
105 .clear = " ",
106 }, {
107 .mask = PTE_NG,
108 .val = PTE_NG,
109 .set = "NG",
110 .clear = " ",
111 }, {
112 .mask = PTE_UXN,
113 .val = PTE_UXN,
114 .set = "UXN",
115 }, {
116 .mask = PTE_ATTRINDX_MASK,
117 .val = PTE_ATTRINDX(MT_DEVICE_nGnRnE),
118 .set = "DEVICE/nGnRnE",
119 }, {
120 .mask = PTE_ATTRINDX_MASK,
121 .val = PTE_ATTRINDX(MT_DEVICE_nGnRE),
122 .set = "DEVICE/nGnRE",
123 }, {
124 .mask = PTE_ATTRINDX_MASK,
125 .val = PTE_ATTRINDX(MT_DEVICE_GRE),
126 .set = "DEVICE/GRE",
127 }, {
128 .mask = PTE_ATTRINDX_MASK,
129 .val = PTE_ATTRINDX(MT_NORMAL_NC),
130 .set = "MEM/NORMAL-NC",
131 }, {
132 .mask = PTE_ATTRINDX_MASK,
133 .val = PTE_ATTRINDX(MT_NORMAL),
134 .set = "MEM/NORMAL",
135 }
136};
137
138struct pg_level {
139 const struct prot_bits *bits;
140 size_t num;
141 u64 mask;
142};
143
144static struct pg_level pg_level[] = {
145 {
146 }, { /* pgd */
147 .bits = pte_bits,
148 .num = ARRAY_SIZE(pte_bits),
149 }, { /* pud */
150 .bits = pte_bits,
151 .num = ARRAY_SIZE(pte_bits),
152 }, { /* pmd */
153 .bits = pte_bits,
154 .num = ARRAY_SIZE(pte_bits),
155 }, { /* pte */
156 .bits = pte_bits,
157 .num = ARRAY_SIZE(pte_bits),
158 },
159};
160
161static void dump_prot(struct pg_state *st, const struct prot_bits *bits,
162 size_t num)
163{
164 unsigned i;
165
166 for (i = 0; i < num; i++, bits++) {
167 const char *s;
168
169 if ((st->current_prot & bits->mask) == bits->val)
170 s = bits->set;
171 else
172 s = bits->clear;
173
174 if (s)
175 seq_printf(st->seq, " %s", s);
176 }
177}
178
179static void note_page(struct pg_state *st, unsigned long addr, unsigned level,
180 u64 val)
181{
182 static const char units[] = "KMGTPE";
183 u64 prot = val & pg_level[level].mask;
184
185 if (addr < LOWEST_ADDR)
186 return;
187
188 if (!st->level) {
189 st->level = level;
190 st->current_prot = prot;
191 st->start_address = addr;
192 seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
193 } else if (prot != st->current_prot || level != st->level ||
194 addr >= st->marker[1].start_address) {
195 const char *unit = units;
196 unsigned long delta;
197
198 if (st->current_prot) {
199 seq_printf(st->seq, "0x%16lx-0x%16lx ",
200 st->start_address, addr);
201
202 delta = (addr - st->start_address) >> 10;
203 while (!(delta & 1023) && unit[1]) {
204 delta >>= 10;
205 unit++;
206 }
207 seq_printf(st->seq, "%9lu%c", delta, *unit);
208 if (pg_level[st->level].bits)
209 dump_prot(st, pg_level[st->level].bits,
210 pg_level[st->level].num);
211 seq_puts(st->seq, "\n");
212 }
213
214 if (addr >= st->marker[1].start_address) {
215 st->marker++;
216 seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
217 }
218
219 st->start_address = addr;
220 st->current_prot = prot;
221 st->level = level;
222 }
223
224 if (addr >= st->marker[1].start_address) {
225 st->marker++;
226 seq_printf(st->seq, "---[ %s ]---\n", st->marker->name);
227 }
228
229}
230
231static void walk_pte(struct pg_state *st, pmd_t *pmd, unsigned long start)
232{
233 pte_t *pte = pte_offset_kernel(pmd, 0);
234 unsigned long addr;
235 unsigned i;
236
237 for (i = 0; i < PTRS_PER_PTE; i++, pte++) {
238 addr = start + i * PAGE_SIZE;
239 note_page(st, addr, 4, pte_val(*pte));
240 }
241}
242
243static void walk_pmd(struct pg_state *st, pud_t *pud, unsigned long start)
244{
245 pmd_t *pmd = pmd_offset(pud, 0);
246 unsigned long addr;
247 unsigned i;
248
249 for (i = 0; i < PTRS_PER_PMD; i++, pmd++) {
250 addr = start + i * PMD_SIZE;
251 if (pmd_none(*pmd) || pmd_sect(*pmd) || pmd_bad(*pmd))
252 note_page(st, addr, 3, pmd_val(*pmd));
253 else
254 walk_pte(st, pmd, addr);
255 }
256}
257
258static void walk_pud(struct pg_state *st, pgd_t *pgd, unsigned long start)
259{
260 pud_t *pud = pud_offset(pgd, 0);
261 unsigned long addr;
262 unsigned i;
263
264 for (i = 0; i < PTRS_PER_PUD; i++, pud++) {
265 addr = start + i * PUD_SIZE;
266 if (pud_none(*pud) || pud_sect(*pud) || pud_bad(*pud))
267 note_page(st, addr, 2, pud_val(*pud));
268 else
269 walk_pmd(st, pud, addr);
270 }
271}
272
273static void walk_pgd(struct pg_state *st, struct mm_struct *mm, unsigned long start)
274{
275 pgd_t *pgd = pgd_offset(mm, 0);
276 unsigned i;
277 unsigned long addr;
278
279 for (i = 0; i < PTRS_PER_PGD; i++, pgd++) {
280 addr = start + i * PGDIR_SIZE;
281 if (pgd_none(*pgd) || pgd_bad(*pgd))
282 note_page(st, addr, 1, pgd_val(*pgd));
283 else
284 walk_pud(st, pgd, addr);
285 }
286}
287
288static int ptdump_show(struct seq_file *m, void *v)
289{
290 struct pg_state st = {
291 .seq = m,
292 .marker = address_markers,
293 };
294
295 walk_pgd(&st, &init_mm, LOWEST_ADDR);
296
297 note_page(&st, 0, 0, 0);
298 return 0;
299}
300
301static int ptdump_open(struct inode *inode, struct file *file)
302{
303 return single_open(file, ptdump_show, NULL);
304}
305
306static const struct file_operations ptdump_fops = {
307 .open = ptdump_open,
308 .read = seq_read,
309 .llseek = seq_lseek,
310 .release = single_release,
311};
312
313static int ptdump_init(void)
314{
315 struct dentry *pe;
316 unsigned i, j;
317
318 for (i = 0; i < ARRAY_SIZE(pg_level); i++)
319 if (pg_level[i].bits)
320 for (j = 0; j < pg_level[i].num; j++)
321 pg_level[i].mask |= pg_level[i].bits[j].mask;
322
323 address_markers[VMEMMAP_START_NR].start_address =
324 (unsigned long)virt_to_page(PAGE_OFFSET);
325 address_markers[VMEMMAP_END_NR].start_address =
326 (unsigned long)virt_to_page(high_memory);
327
328 pe = debugfs_create_file("kernel_page_tables", 0400, NULL, NULL,
329 &ptdump_fops);
330 return pe ? 0 : -ENOMEM;
331}
332device_initcall(ptdump_init);
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index 41cb6d3d6075..c11cd27ca8f5 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -380,7 +380,7 @@ static struct fault_info {
380 { do_bad, SIGBUS, 0, "level 1 address size fault" }, 380 { do_bad, SIGBUS, 0, "level 1 address size fault" },
381 { do_bad, SIGBUS, 0, "level 2 address size fault" }, 381 { do_bad, SIGBUS, 0, "level 2 address size fault" },
382 { do_bad, SIGBUS, 0, "level 3 address size fault" }, 382 { do_bad, SIGBUS, 0, "level 3 address size fault" },
383 { do_translation_fault, SIGSEGV, SEGV_MAPERR, "input address range fault" }, 383 { do_translation_fault, SIGSEGV, SEGV_MAPERR, "level 0 translation fault" },
384 { do_translation_fault, SIGSEGV, SEGV_MAPERR, "level 1 translation fault" }, 384 { do_translation_fault, SIGSEGV, SEGV_MAPERR, "level 1 translation fault" },
385 { do_translation_fault, SIGSEGV, SEGV_MAPERR, "level 2 translation fault" }, 385 { do_translation_fault, SIGSEGV, SEGV_MAPERR, "level 2 translation fault" },
386 { do_page_fault, SIGSEGV, SEGV_MAPERR, "level 3 translation fault" }, 386 { do_page_fault, SIGSEGV, SEGV_MAPERR, "level 3 translation fault" },
diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index 494297c698ca..bac492c12fcc 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -39,6 +39,7 @@
39#include <asm/setup.h> 39#include <asm/setup.h>
40#include <asm/sizes.h> 40#include <asm/sizes.h>
41#include <asm/tlb.h> 41#include <asm/tlb.h>
42#include <asm/alternative.h>
42 43
43#include "mm.h" 44#include "mm.h"
44 45
@@ -325,6 +326,7 @@ void __init mem_init(void)
325void free_initmem(void) 326void free_initmem(void)
326{ 327{
327 free_initmem_default(0); 328 free_initmem_default(0);
329 free_alternatives_memory();
328} 330}
329 331
330#ifdef CONFIG_BLK_DEV_INITRD 332#ifdef CONFIG_BLK_DEV_INITRD
diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c
index 4a07630a6616..cbb99c8f1e04 100644
--- a/arch/arm64/mm/ioremap.c
+++ b/arch/arm64/mm/ioremap.c
@@ -103,97 +103,10 @@ void __iomem *ioremap_cache(phys_addr_t phys_addr, size_t size)
103} 103}
104EXPORT_SYMBOL(ioremap_cache); 104EXPORT_SYMBOL(ioremap_cache);
105 105
106static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss; 106/*
107#if CONFIG_ARM64_PGTABLE_LEVELS > 2 107 * Must be called after early_fixmap_init
108static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss; 108 */
109#endif
110#if CONFIG_ARM64_PGTABLE_LEVELS > 3
111static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss;
112#endif
113
114static inline pud_t * __init early_ioremap_pud(unsigned long addr)
115{
116 pgd_t *pgd;
117
118 pgd = pgd_offset_k(addr);
119 BUG_ON(pgd_none(*pgd) || pgd_bad(*pgd));
120
121 return pud_offset(pgd, addr);
122}
123
124static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
125{
126 pud_t *pud = early_ioremap_pud(addr);
127
128 BUG_ON(pud_none(*pud) || pud_bad(*pud));
129
130 return pmd_offset(pud, addr);
131}
132
133static inline pte_t * __init early_ioremap_pte(unsigned long addr)
134{
135 pmd_t *pmd = early_ioremap_pmd(addr);
136
137 BUG_ON(pmd_none(*pmd) || pmd_bad(*pmd));
138
139 return pte_offset_kernel(pmd, addr);
140}
141
142void __init early_ioremap_init(void) 109void __init early_ioremap_init(void)
143{ 110{
144 pgd_t *pgd;
145 pud_t *pud;
146 pmd_t *pmd;
147 unsigned long addr = fix_to_virt(FIX_BTMAP_BEGIN);
148
149 pgd = pgd_offset_k(addr);
150 pgd_populate(&init_mm, pgd, bm_pud);
151 pud = pud_offset(pgd, addr);
152 pud_populate(&init_mm, pud, bm_pmd);
153 pmd = pmd_offset(pud, addr);
154 pmd_populate_kernel(&init_mm, pmd, bm_pte);
155
156 /*
157 * The boot-ioremap range spans multiple pmds, for which
158 * we are not prepared:
159 */
160 BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT)
161 != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT));
162
163 if (pmd != early_ioremap_pmd(fix_to_virt(FIX_BTMAP_END))) {
164 WARN_ON(1);
165 pr_warn("pmd %p != %p\n",
166 pmd, early_ioremap_pmd(fix_to_virt(FIX_BTMAP_END)));
167 pr_warn("fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n",
168 fix_to_virt(FIX_BTMAP_BEGIN));
169 pr_warn("fix_to_virt(FIX_BTMAP_END): %08lx\n",
170 fix_to_virt(FIX_BTMAP_END));
171
172 pr_warn("FIX_BTMAP_END: %d\n", FIX_BTMAP_END);
173 pr_warn("FIX_BTMAP_BEGIN: %d\n",
174 FIX_BTMAP_BEGIN);
175 }
176
177 early_ioremap_setup(); 111 early_ioremap_setup();
178} 112}
179
180void __init __early_set_fixmap(enum fixed_addresses idx,
181 phys_addr_t phys, pgprot_t flags)
182{
183 unsigned long addr = __fix_to_virt(idx);
184 pte_t *pte;
185
186 if (idx >= __end_of_fixed_addresses) {
187 BUG();
188 return;
189 }
190
191 pte = early_ioremap_pte(addr);
192
193 if (pgprot_val(flags))
194 set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags));
195 else {
196 pte_clear(&init_mm, addr, pte);
197 flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
198 }
199}
diff --git a/arch/arm64/mm/mm.h b/arch/arm64/mm/mm.h
index d519f4f50c8c..50c3351df9c7 100644
--- a/arch/arm64/mm/mm.h
+++ b/arch/arm64/mm/mm.h
@@ -1,2 +1 @@
1extern void __init bootmem_init(void); extern void __init bootmem_init(void);
2extern void __init arm64_swiotlb_init(void);
diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c
index 1d73662f00ff..54922d1275b8 100644
--- a/arch/arm64/mm/mmap.c
+++ b/arch/arm64/mm/mmap.c
@@ -47,22 +47,14 @@ static int mmap_is_legacy(void)
47 return sysctl_legacy_va_layout; 47 return sysctl_legacy_va_layout;
48} 48}
49 49
50/*
51 * Since get_random_int() returns the same value within a 1 jiffy window, we
52 * will almost always get the same randomisation for the stack and mmap
53 * region. This will mean the relative distance between stack and mmap will be
54 * the same.
55 *
56 * To avoid this we can shift the randomness by 1 bit.
57 */
58static unsigned long mmap_rnd(void) 50static unsigned long mmap_rnd(void)
59{ 51{
60 unsigned long rnd = 0; 52 unsigned long rnd = 0;
61 53
62 if (current->flags & PF_RANDOMIZE) 54 if (current->flags & PF_RANDOMIZE)
63 rnd = (long)get_random_int() & (STACK_RND_MASK >> 1); 55 rnd = (long)get_random_int() & STACK_RND_MASK;
64 56
65 return rnd << (PAGE_SHIFT + 1); 57 return rnd << PAGE_SHIFT;
66} 58}
67 59
68static unsigned long mmap_base(void) 60static unsigned long mmap_base(void)
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index 0bf90d26e745..6032f3e3056a 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -28,6 +28,7 @@
28#include <linux/io.h> 28#include <linux/io.h>
29 29
30#include <asm/cputype.h> 30#include <asm/cputype.h>
31#include <asm/fixmap.h>
31#include <asm/sections.h> 32#include <asm/sections.h>
32#include <asm/setup.h> 33#include <asm/setup.h>
33#include <asm/sizes.h> 34#include <asm/sizes.h>
@@ -202,7 +203,7 @@ static void __init alloc_init_pmd(pud_t *pud, unsigned long addr,
202} 203}
203 204
204static void __init alloc_init_pud(pgd_t *pgd, unsigned long addr, 205static void __init alloc_init_pud(pgd_t *pgd, unsigned long addr,
205 unsigned long end, unsigned long phys, 206 unsigned long end, phys_addr_t phys,
206 int map_io) 207 int map_io)
207{ 208{
208 pud_t *pud; 209 pud_t *pud;
@@ -463,3 +464,96 @@ void vmemmap_free(unsigned long start, unsigned long end)
463{ 464{
464} 465}
465#endif /* CONFIG_SPARSEMEM_VMEMMAP */ 466#endif /* CONFIG_SPARSEMEM_VMEMMAP */
467
468static pte_t bm_pte[PTRS_PER_PTE] __page_aligned_bss;
469#if CONFIG_ARM64_PGTABLE_LEVELS > 2
470static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss;
471#endif
472#if CONFIG_ARM64_PGTABLE_LEVELS > 3
473static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss;
474#endif
475
476static inline pud_t * fixmap_pud(unsigned long addr)
477{
478 pgd_t *pgd = pgd_offset_k(addr);
479
480 BUG_ON(pgd_none(*pgd) || pgd_bad(*pgd));
481
482 return pud_offset(pgd, addr);
483}
484
485static inline pmd_t * fixmap_pmd(unsigned long addr)
486{
487 pud_t *pud = fixmap_pud(addr);
488
489 BUG_ON(pud_none(*pud) || pud_bad(*pud));
490
491 return pmd_offset(pud, addr);
492}
493
494static inline pte_t * fixmap_pte(unsigned long addr)
495{
496 pmd_t *pmd = fixmap_pmd(addr);
497
498 BUG_ON(pmd_none(*pmd) || pmd_bad(*pmd));
499
500 return pte_offset_kernel(pmd, addr);
501}
502
503void __init early_fixmap_init(void)
504{
505 pgd_t *pgd;
506 pud_t *pud;
507 pmd_t *pmd;
508 unsigned long addr = FIXADDR_START;
509
510 pgd = pgd_offset_k(addr);
511 pgd_populate(&init_mm, pgd, bm_pud);
512 pud = pud_offset(pgd, addr);
513 pud_populate(&init_mm, pud, bm_pmd);
514 pmd = pmd_offset(pud, addr);
515 pmd_populate_kernel(&init_mm, pmd, bm_pte);
516
517 /*
518 * The boot-ioremap range spans multiple pmds, for which
519 * we are not preparted:
520 */
521 BUILD_BUG_ON((__fix_to_virt(FIX_BTMAP_BEGIN) >> PMD_SHIFT)
522 != (__fix_to_virt(FIX_BTMAP_END) >> PMD_SHIFT));
523
524 if ((pmd != fixmap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)))
525 || pmd != fixmap_pmd(fix_to_virt(FIX_BTMAP_END))) {
526 WARN_ON(1);
527 pr_warn("pmd %p != %p, %p\n",
528 pmd, fixmap_pmd(fix_to_virt(FIX_BTMAP_BEGIN)),
529 fixmap_pmd(fix_to_virt(FIX_BTMAP_END)));
530 pr_warn("fix_to_virt(FIX_BTMAP_BEGIN): %08lx\n",
531 fix_to_virt(FIX_BTMAP_BEGIN));
532 pr_warn("fix_to_virt(FIX_BTMAP_END): %08lx\n",
533 fix_to_virt(FIX_BTMAP_END));
534
535 pr_warn("FIX_BTMAP_END: %d\n", FIX_BTMAP_END);
536 pr_warn("FIX_BTMAP_BEGIN: %d\n", FIX_BTMAP_BEGIN);
537 }
538}
539
540void __set_fixmap(enum fixed_addresses idx,
541 phys_addr_t phys, pgprot_t flags)
542{
543 unsigned long addr = __fix_to_virt(idx);
544 pte_t *pte;
545
546 if (idx >= __end_of_fixed_addresses) {
547 BUG();
548 return;
549 }
550
551 pte = fixmap_pte(addr);
552
553 if (pgprot_val(flags)) {
554 set_pte(pte, pfn_pte(phys >> PAGE_SHIFT, flags));
555 } else {
556 pte_clear(&init_mm, addr, pte);
557 flush_tlb_kernel_range(addr, addr+PAGE_SIZE);
558 }
559}
diff --git a/arch/arm64/mm/pgd.c b/arch/arm64/mm/pgd.c
index 6682b361d3ac..71ca104f97bd 100644
--- a/arch/arm64/mm/pgd.c
+++ b/arch/arm64/mm/pgd.c
@@ -35,9 +35,9 @@ static struct kmem_cache *pgd_cache;
35pgd_t *pgd_alloc(struct mm_struct *mm) 35pgd_t *pgd_alloc(struct mm_struct *mm)
36{ 36{
37 if (PGD_SIZE == PAGE_SIZE) 37 if (PGD_SIZE == PAGE_SIZE)
38 return (pgd_t *)get_zeroed_page(GFP_KERNEL); 38 return (pgd_t *)__get_free_page(PGALLOC_GFP);
39 else 39 else
40 return kmem_cache_zalloc(pgd_cache, GFP_KERNEL); 40 return kmem_cache_alloc(pgd_cache, PGALLOC_GFP);
41} 41}
42 42
43void pgd_free(struct mm_struct *mm, pgd_t *pgd) 43void pgd_free(struct mm_struct *mm, pgd_t *pgd)
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 41f1e3e2ea24..edba042b2325 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -60,7 +60,7 @@ struct jit_ctx {
60 const struct bpf_prog *prog; 60 const struct bpf_prog *prog;
61 int idx; 61 int idx;
62 int tmp_used; 62 int tmp_used;
63 int body_offset; 63 int epilogue_offset;
64 int *offset; 64 int *offset;
65 u32 *image; 65 u32 *image;
66}; 66};
@@ -130,8 +130,8 @@ static void jit_fill_hole(void *area, unsigned int size)
130 130
131static inline int epilogue_offset(const struct jit_ctx *ctx) 131static inline int epilogue_offset(const struct jit_ctx *ctx)
132{ 132{
133 int to = ctx->offset[ctx->prog->len - 1]; 133 int to = ctx->epilogue_offset;
134 int from = ctx->idx - ctx->body_offset; 134 int from = ctx->idx;
135 135
136 return to - from; 136 return to - from;
137} 137}
@@ -463,6 +463,8 @@ emit_cond_jmp:
463 } 463 }
464 /* function return */ 464 /* function return */
465 case BPF_JMP | BPF_EXIT: 465 case BPF_JMP | BPF_EXIT:
466 /* Optimization: when last instruction is EXIT,
467 simply fallthrough to epilogue. */
466 if (i == ctx->prog->len - 1) 468 if (i == ctx->prog->len - 1)
467 break; 469 break;
468 jmp_offset = epilogue_offset(ctx); 470 jmp_offset = epilogue_offset(ctx);
@@ -685,11 +687,13 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
685 687
686 /* 1. Initial fake pass to compute ctx->idx. */ 688 /* 1. Initial fake pass to compute ctx->idx. */
687 689
688 /* Fake pass to fill in ctx->offset. */ 690 /* Fake pass to fill in ctx->offset and ctx->tmp_used. */
689 if (build_body(&ctx)) 691 if (build_body(&ctx))
690 goto out; 692 goto out;
691 693
692 build_prologue(&ctx); 694 build_prologue(&ctx);
695
696 ctx.epilogue_offset = ctx.idx;
693 build_epilogue(&ctx); 697 build_epilogue(&ctx);
694 698
695 /* Now we know the actual image size. */ 699 /* Now we know the actual image size. */
@@ -706,7 +710,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
706 710
707 build_prologue(&ctx); 711 build_prologue(&ctx);
708 712
709 ctx.body_offset = ctx.idx;
710 if (build_body(&ctx)) { 713 if (build_body(&ctx)) {
711 bpf_jit_binary_free(header); 714 bpf_jit_binary_free(header);
712 goto out; 715 goto out;
diff --git a/arch/avr32/mach-at32ap/at32ap700x.c b/arch/avr32/mach-at32ap/at32ap700x.c
index 37b75602adf6..cc92cdb9994c 100644
--- a/arch/avr32/mach-at32ap/at32ap700x.c
+++ b/arch/avr32/mach-at32ap/at32ap700x.c
@@ -17,7 +17,7 @@
17#include <linux/spi/spi.h> 17#include <linux/spi/spi.h>
18#include <linux/usb/atmel_usba_udc.h> 18#include <linux/usb/atmel_usba_udc.h>
19 19
20#include <mach/atmel-mci.h> 20#include <linux/platform_data/mmc-atmel-mci.h>
21#include <linux/atmel-mci.h> 21#include <linux/atmel-mci.h>
22 22
23#include <asm/io.h> 23#include <asm/io.h>
diff --git a/arch/avr32/mach-at32ap/include/mach/atmel-mci.h b/arch/avr32/mach-at32ap/include/mach/atmel-mci.h
deleted file mode 100644
index 11d7f4b28dc8..000000000000
--- a/arch/avr32/mach-at32ap/include/mach/atmel-mci.h
+++ /dev/null
@@ -1,17 +0,0 @@
1#ifndef __MACH_ATMEL_MCI_H
2#define __MACH_ATMEL_MCI_H
3
4#include <linux/platform_data/dma-dw.h>
5
6/**
7 * struct mci_dma_data - DMA data for MCI interface
8 */
9struct mci_dma_data {
10 struct dw_dma_slave sdata;
11};
12
13/* accessor macros */
14#define slave_data_ptr(s) (&(s)->sdata)
15#define find_slave_dev(s) ((s)->sdata.dma_dev)
16
17#endif /* __MACH_ATMEL_MCI_H */
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
index ec6b9acb6bea..dbe46f43884d 100644
--- a/arch/ia64/kvm/kvm-ia64.c
+++ b/arch/ia64/kvm/kvm-ia64.c
@@ -1563,7 +1563,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
1563 1563
1564 for (i = 0; i < npages; i++) { 1564 for (i = 0; i < npages; i++) {
1565 pfn = gfn_to_pfn(kvm, base_gfn + i); 1565 pfn = gfn_to_pfn(kvm, base_gfn + i);
1566 if (!kvm_is_mmio_pfn(pfn)) { 1566 if (!kvm_is_reserved_pfn(pfn)) {
1567 kvm_set_pmt_entry(kvm, base_gfn + i, 1567 kvm_set_pmt_entry(kvm, base_gfn + i,
1568 pfn << PAGE_SHIFT, 1568 pfn << PAGE_SHIFT,
1569 _PAGE_AR_RWX | _PAGE_MA_WB); 1569 _PAGE_AR_RWX | _PAGE_MA_WB);
diff --git a/arch/m68k/atari/config.c b/arch/m68k/atari/config.c
index 01a62161b08a..192b00f098f4 100644
--- a/arch/m68k/atari/config.c
+++ b/arch/m68k/atari/config.c
@@ -858,6 +858,24 @@ static struct platform_device *atari_netusbee_devices[] __initdata = {
858}; 858};
859#endif /* CONFIG_ATARI_ETHERNEC */ 859#endif /* CONFIG_ATARI_ETHERNEC */
860 860
861#ifdef CONFIG_ATARI_SCSI
862static const struct resource atari_scsi_st_rsrc[] __initconst = {
863 {
864 .flags = IORESOURCE_IRQ,
865 .start = IRQ_MFP_FSCSI,
866 .end = IRQ_MFP_FSCSI,
867 },
868};
869
870static const struct resource atari_scsi_tt_rsrc[] __initconst = {
871 {
872 .flags = IORESOURCE_IRQ,
873 .start = IRQ_TT_MFP_SCSI,
874 .end = IRQ_TT_MFP_SCSI,
875 },
876};
877#endif
878
861int __init atari_platform_init(void) 879int __init atari_platform_init(void)
862{ 880{
863 int rv = 0; 881 int rv = 0;
@@ -892,6 +910,15 @@ int __init atari_platform_init(void)
892 } 910 }
893#endif 911#endif
894 912
913#ifdef CONFIG_ATARI_SCSI
914 if (ATARIHW_PRESENT(ST_SCSI))
915 platform_device_register_simple("atari_scsi", -1,
916 atari_scsi_st_rsrc, ARRAY_SIZE(atari_scsi_st_rsrc));
917 else if (ATARIHW_PRESENT(TT_SCSI))
918 platform_device_register_simple("atari_scsi", -1,
919 atari_scsi_tt_rsrc, ARRAY_SIZE(atari_scsi_tt_rsrc));
920#endif
921
895 return rv; 922 return rv;
896} 923}
897 924
diff --git a/arch/m68k/atari/stdma.c b/arch/m68k/atari/stdma.c
index ddbf43ca8858..e5a66596b116 100644
--- a/arch/m68k/atari/stdma.c
+++ b/arch/m68k/atari/stdma.c
@@ -59,6 +59,31 @@ static irqreturn_t stdma_int (int irq, void *dummy);
59/************************* End of Prototypes **************************/ 59/************************* End of Prototypes **************************/
60 60
61 61
62/**
63 * stdma_try_lock - attempt to acquire ST DMA interrupt "lock"
64 * @handler: interrupt handler to use after acquisition
65 *
66 * Returns !0 if lock was acquired; otherwise 0.
67 */
68
69int stdma_try_lock(irq_handler_t handler, void *data)
70{
71 unsigned long flags;
72
73 local_irq_save(flags);
74 if (stdma_locked) {
75 local_irq_restore(flags);
76 return 0;
77 }
78
79 stdma_locked = 1;
80 stdma_isr = handler;
81 stdma_isr_data = data;
82 local_irq_restore(flags);
83 return 1;
84}
85EXPORT_SYMBOL(stdma_try_lock);
86
62 87
63/* 88/*
64 * Function: void stdma_lock( isrfunc isr, void *data ) 89 * Function: void stdma_lock( isrfunc isr, void *data )
@@ -78,19 +103,10 @@ static irqreturn_t stdma_int (int irq, void *dummy);
78 103
79void stdma_lock(irq_handler_t handler, void *data) 104void stdma_lock(irq_handler_t handler, void *data)
80{ 105{
81 unsigned long flags;
82
83 local_irq_save(flags); /* protect lock */
84
85 /* Since the DMA is used for file system purposes, we 106 /* Since the DMA is used for file system purposes, we
86 have to sleep uninterruptible (there may be locked 107 have to sleep uninterruptible (there may be locked
87 buffers) */ 108 buffers) */
88 wait_event(stdma_wait, !stdma_locked); 109 wait_event(stdma_wait, stdma_try_lock(handler, data));
89
90 stdma_locked = 1;
91 stdma_isr = handler;
92 stdma_isr_data = data;
93 local_irq_restore(flags);
94} 110}
95EXPORT_SYMBOL(stdma_lock); 111EXPORT_SYMBOL(stdma_lock);
96 112
@@ -122,22 +138,25 @@ void stdma_release(void)
122EXPORT_SYMBOL(stdma_release); 138EXPORT_SYMBOL(stdma_release);
123 139
124 140
125/* 141/**
126 * Function: int stdma_others_waiting( void ) 142 * stdma_is_locked_by - allow lock holder to check whether it needs to release.
127 * 143 * @handler: interrupt handler previously used to acquire lock.
128 * Purpose: Check if someone waits for the ST-DMA lock.
129 *
130 * Inputs: none
131 *
132 * Returns: 0 if no one is waiting, != 0 otherwise
133 * 144 *
145 * Returns !0 if locked for the given handler; 0 otherwise.
134 */ 146 */
135 147
136int stdma_others_waiting(void) 148int stdma_is_locked_by(irq_handler_t handler)
137{ 149{
138 return waitqueue_active(&stdma_wait); 150 unsigned long flags;
151 int result;
152
153 local_irq_save(flags);
154 result = stdma_locked && (stdma_isr == handler);
155 local_irq_restore(flags);
156
157 return result;
139} 158}
140EXPORT_SYMBOL(stdma_others_waiting); 159EXPORT_SYMBOL(stdma_is_locked_by);
141 160
142 161
143/* 162/*
diff --git a/arch/m68k/include/asm/atari_stdma.h b/arch/m68k/include/asm/atari_stdma.h
index 8e389b7fa70c..d24e34d870dc 100644
--- a/arch/m68k/include/asm/atari_stdma.h
+++ b/arch/m68k/include/asm/atari_stdma.h
@@ -8,11 +8,11 @@
8 8
9/***************************** Prototypes *****************************/ 9/***************************** Prototypes *****************************/
10 10
11int stdma_try_lock(irq_handler_t, void *);
11void stdma_lock(irq_handler_t handler, void *data); 12void stdma_lock(irq_handler_t handler, void *data);
12void stdma_release( void ); 13void stdma_release( void );
13int stdma_others_waiting( void );
14int stdma_islocked( void ); 14int stdma_islocked( void );
15void *stdma_locked_by( void ); 15int stdma_is_locked_by(irq_handler_t);
16void stdma_init( void ); 16void stdma_init( void );
17 17
18/************************* End of Prototypes **************************/ 18/************************* End of Prototypes **************************/
diff --git a/arch/m68k/include/asm/macintosh.h b/arch/m68k/include/asm/macintosh.h
index d323b2c2d07d..29c7c6c3a5f2 100644
--- a/arch/m68k/include/asm/macintosh.h
+++ b/arch/m68k/include/asm/macintosh.h
@@ -53,6 +53,10 @@ struct mac_model
53#define MAC_SCSI_QUADRA 2 53#define MAC_SCSI_QUADRA 2
54#define MAC_SCSI_QUADRA2 3 54#define MAC_SCSI_QUADRA2 3
55#define MAC_SCSI_QUADRA3 4 55#define MAC_SCSI_QUADRA3 4
56#define MAC_SCSI_IIFX 5
57#define MAC_SCSI_DUO 6
58#define MAC_SCSI_CCL 7
59#define MAC_SCSI_LATE 8
56 60
57#define MAC_IDE_NONE 0 61#define MAC_IDE_NONE 0
58#define MAC_IDE_QUADRA 1 62#define MAC_IDE_QUADRA 1
diff --git a/arch/m68k/include/asm/unistd.h b/arch/m68k/include/asm/unistd.h
index 4ef7a54813e6..75e75d7b1702 100644
--- a/arch/m68k/include/asm/unistd.h
+++ b/arch/m68k/include/asm/unistd.h
@@ -4,7 +4,7 @@
4#include <uapi/asm/unistd.h> 4#include <uapi/asm/unistd.h>
5 5
6 6
7#define NR_syscalls 354 7#define NR_syscalls 355
8 8
9#define __ARCH_WANT_OLD_READDIR 9#define __ARCH_WANT_OLD_READDIR
10#define __ARCH_WANT_OLD_STAT 10#define __ARCH_WANT_OLD_STAT
diff --git a/arch/m68k/include/uapi/asm/unistd.h b/arch/m68k/include/uapi/asm/unistd.h
index b419c6b7ac37..2c1bec9a14b6 100644
--- a/arch/m68k/include/uapi/asm/unistd.h
+++ b/arch/m68k/include/uapi/asm/unistd.h
@@ -359,5 +359,6 @@
359#define __NR_renameat2 351 359#define __NR_renameat2 351
360#define __NR_getrandom 352 360#define __NR_getrandom 352
361#define __NR_memfd_create 353 361#define __NR_memfd_create 353
362#define __NR_bpf 354
362 363
363#endif /* _UAPI_ASM_M68K_UNISTD_H_ */ 364#endif /* _UAPI_ASM_M68K_UNISTD_H_ */
diff --git a/arch/m68k/kernel/syscalltable.S b/arch/m68k/kernel/syscalltable.S
index 05b46c2b08b8..2ca219e184cd 100644
--- a/arch/m68k/kernel/syscalltable.S
+++ b/arch/m68k/kernel/syscalltable.S
@@ -374,4 +374,5 @@ ENTRY(sys_call_table)
374 .long sys_renameat2 374 .long sys_renameat2
375 .long sys_getrandom 375 .long sys_getrandom
376 .long sys_memfd_create 376 .long sys_memfd_create
377 .long sys_bpf
377 378
diff --git a/arch/m68k/mac/config.c b/arch/m68k/mac/config.c
index a471eab1a4dd..e9c3756139fc 100644
--- a/arch/m68k/mac/config.c
+++ b/arch/m68k/mac/config.c
@@ -278,7 +278,7 @@ static struct mac_model mac_data_table[] = {
278 .name = "IIfx", 278 .name = "IIfx",
279 .adb_type = MAC_ADB_IOP, 279 .adb_type = MAC_ADB_IOP,
280 .via_type = MAC_VIA_IICI, 280 .via_type = MAC_VIA_IICI,
281 .scsi_type = MAC_SCSI_OLD, 281 .scsi_type = MAC_SCSI_IIFX,
282 .scc_type = MAC_SCC_IOP, 282 .scc_type = MAC_SCC_IOP,
283 .nubus_type = MAC_NUBUS, 283 .nubus_type = MAC_NUBUS,
284 .floppy_type = MAC_FLOPPY_SWIM_IOP, 284 .floppy_type = MAC_FLOPPY_SWIM_IOP,
@@ -329,7 +329,7 @@ static struct mac_model mac_data_table[] = {
329 .name = "Color Classic", 329 .name = "Color Classic",
330 .adb_type = MAC_ADB_CUDA, 330 .adb_type = MAC_ADB_CUDA,
331 .via_type = MAC_VIA_IICI, 331 .via_type = MAC_VIA_IICI,
332 .scsi_type = MAC_SCSI_OLD, 332 .scsi_type = MAC_SCSI_CCL,
333 .scc_type = MAC_SCC_II, 333 .scc_type = MAC_SCC_II,
334 .nubus_type = MAC_NUBUS, 334 .nubus_type = MAC_NUBUS,
335 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 335 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -338,7 +338,7 @@ static struct mac_model mac_data_table[] = {
338 .name = "Color Classic II", 338 .name = "Color Classic II",
339 .adb_type = MAC_ADB_CUDA, 339 .adb_type = MAC_ADB_CUDA,
340 .via_type = MAC_VIA_IICI, 340 .via_type = MAC_VIA_IICI,
341 .scsi_type = MAC_SCSI_OLD, 341 .scsi_type = MAC_SCSI_CCL,
342 .scc_type = MAC_SCC_II, 342 .scc_type = MAC_SCC_II,
343 .nubus_type = MAC_NUBUS, 343 .nubus_type = MAC_NUBUS,
344 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 344 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -526,7 +526,7 @@ static struct mac_model mac_data_table[] = {
526 .name = "Performa 520", 526 .name = "Performa 520",
527 .adb_type = MAC_ADB_CUDA, 527 .adb_type = MAC_ADB_CUDA,
528 .via_type = MAC_VIA_IICI, 528 .via_type = MAC_VIA_IICI,
529 .scsi_type = MAC_SCSI_OLD, 529 .scsi_type = MAC_SCSI_CCL,
530 .scc_type = MAC_SCC_II, 530 .scc_type = MAC_SCC_II,
531 .nubus_type = MAC_NUBUS, 531 .nubus_type = MAC_NUBUS,
532 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 532 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -535,7 +535,7 @@ static struct mac_model mac_data_table[] = {
535 .name = "Performa 550", 535 .name = "Performa 550",
536 .adb_type = MAC_ADB_CUDA, 536 .adb_type = MAC_ADB_CUDA,
537 .via_type = MAC_VIA_IICI, 537 .via_type = MAC_VIA_IICI,
538 .scsi_type = MAC_SCSI_OLD, 538 .scsi_type = MAC_SCSI_CCL,
539 .scc_type = MAC_SCC_II, 539 .scc_type = MAC_SCC_II,
540 .nubus_type = MAC_NUBUS, 540 .nubus_type = MAC_NUBUS,
541 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 541 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -567,7 +567,7 @@ static struct mac_model mac_data_table[] = {
567 .name = "TV", 567 .name = "TV",
568 .adb_type = MAC_ADB_CUDA, 568 .adb_type = MAC_ADB_CUDA,
569 .via_type = MAC_VIA_IICI, 569 .via_type = MAC_VIA_IICI,
570 .scsi_type = MAC_SCSI_OLD, 570 .scsi_type = MAC_SCSI_CCL,
571 .scc_type = MAC_SCC_II, 571 .scc_type = MAC_SCC_II,
572 .nubus_type = MAC_NUBUS, 572 .nubus_type = MAC_NUBUS,
573 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 573 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -712,7 +712,7 @@ static struct mac_model mac_data_table[] = {
712 .name = "PowerBook 190", 712 .name = "PowerBook 190",
713 .adb_type = MAC_ADB_PB2, 713 .adb_type = MAC_ADB_PB2,
714 .via_type = MAC_VIA_QUADRA, 714 .via_type = MAC_VIA_QUADRA,
715 .scsi_type = MAC_SCSI_OLD, 715 .scsi_type = MAC_SCSI_LATE,
716 .ide_type = MAC_IDE_BABOON, 716 .ide_type = MAC_IDE_BABOON,
717 .scc_type = MAC_SCC_QUADRA, 717 .scc_type = MAC_SCC_QUADRA,
718 .nubus_type = MAC_NUBUS, 718 .nubus_type = MAC_NUBUS,
@@ -722,7 +722,7 @@ static struct mac_model mac_data_table[] = {
722 .name = "PowerBook 520", 722 .name = "PowerBook 520",
723 .adb_type = MAC_ADB_PB2, 723 .adb_type = MAC_ADB_PB2,
724 .via_type = MAC_VIA_QUADRA, 724 .via_type = MAC_VIA_QUADRA,
725 .scsi_type = MAC_SCSI_OLD, 725 .scsi_type = MAC_SCSI_LATE,
726 .scc_type = MAC_SCC_QUADRA, 726 .scc_type = MAC_SCC_QUADRA,
727 .ether_type = MAC_ETHER_SONIC, 727 .ether_type = MAC_ETHER_SONIC,
728 .nubus_type = MAC_NUBUS, 728 .nubus_type = MAC_NUBUS,
@@ -740,7 +740,7 @@ static struct mac_model mac_data_table[] = {
740 .name = "PowerBook Duo 210", 740 .name = "PowerBook Duo 210",
741 .adb_type = MAC_ADB_PB2, 741 .adb_type = MAC_ADB_PB2,
742 .via_type = MAC_VIA_IICI, 742 .via_type = MAC_VIA_IICI,
743 .scsi_type = MAC_SCSI_OLD, 743 .scsi_type = MAC_SCSI_DUO,
744 .scc_type = MAC_SCC_QUADRA, 744 .scc_type = MAC_SCC_QUADRA,
745 .nubus_type = MAC_NUBUS, 745 .nubus_type = MAC_NUBUS,
746 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 746 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -749,7 +749,7 @@ static struct mac_model mac_data_table[] = {
749 .name = "PowerBook Duo 230", 749 .name = "PowerBook Duo 230",
750 .adb_type = MAC_ADB_PB2, 750 .adb_type = MAC_ADB_PB2,
751 .via_type = MAC_VIA_IICI, 751 .via_type = MAC_VIA_IICI,
752 .scsi_type = MAC_SCSI_OLD, 752 .scsi_type = MAC_SCSI_DUO,
753 .scc_type = MAC_SCC_QUADRA, 753 .scc_type = MAC_SCC_QUADRA,
754 .nubus_type = MAC_NUBUS, 754 .nubus_type = MAC_NUBUS,
755 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 755 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -758,7 +758,7 @@ static struct mac_model mac_data_table[] = {
758 .name = "PowerBook Duo 250", 758 .name = "PowerBook Duo 250",
759 .adb_type = MAC_ADB_PB2, 759 .adb_type = MAC_ADB_PB2,
760 .via_type = MAC_VIA_IICI, 760 .via_type = MAC_VIA_IICI,
761 .scsi_type = MAC_SCSI_OLD, 761 .scsi_type = MAC_SCSI_DUO,
762 .scc_type = MAC_SCC_QUADRA, 762 .scc_type = MAC_SCC_QUADRA,
763 .nubus_type = MAC_NUBUS, 763 .nubus_type = MAC_NUBUS,
764 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 764 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -767,7 +767,7 @@ static struct mac_model mac_data_table[] = {
767 .name = "PowerBook Duo 270c", 767 .name = "PowerBook Duo 270c",
768 .adb_type = MAC_ADB_PB2, 768 .adb_type = MAC_ADB_PB2,
769 .via_type = MAC_VIA_IICI, 769 .via_type = MAC_VIA_IICI,
770 .scsi_type = MAC_SCSI_OLD, 770 .scsi_type = MAC_SCSI_DUO,
771 .scc_type = MAC_SCC_QUADRA, 771 .scc_type = MAC_SCC_QUADRA,
772 .nubus_type = MAC_NUBUS, 772 .nubus_type = MAC_NUBUS,
773 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 773 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -776,7 +776,7 @@ static struct mac_model mac_data_table[] = {
776 .name = "PowerBook Duo 280", 776 .name = "PowerBook Duo 280",
777 .adb_type = MAC_ADB_PB2, 777 .adb_type = MAC_ADB_PB2,
778 .via_type = MAC_VIA_IICI, 778 .via_type = MAC_VIA_IICI,
779 .scsi_type = MAC_SCSI_OLD, 779 .scsi_type = MAC_SCSI_DUO,
780 .scc_type = MAC_SCC_QUADRA, 780 .scc_type = MAC_SCC_QUADRA,
781 .nubus_type = MAC_NUBUS, 781 .nubus_type = MAC_NUBUS,
782 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 782 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -785,7 +785,7 @@ static struct mac_model mac_data_table[] = {
785 .name = "PowerBook Duo 280c", 785 .name = "PowerBook Duo 280c",
786 .adb_type = MAC_ADB_PB2, 786 .adb_type = MAC_ADB_PB2,
787 .via_type = MAC_VIA_IICI, 787 .via_type = MAC_VIA_IICI,
788 .scsi_type = MAC_SCSI_OLD, 788 .scsi_type = MAC_SCSI_DUO,
789 .scc_type = MAC_SCC_QUADRA, 789 .scc_type = MAC_SCC_QUADRA,
790 .nubus_type = MAC_NUBUS, 790 .nubus_type = MAC_NUBUS,
791 .floppy_type = MAC_FLOPPY_SWIM_ADDR2, 791 .floppy_type = MAC_FLOPPY_SWIM_ADDR2,
@@ -929,6 +929,70 @@ static struct platform_device swim_pdev = {
929 .resource = &swim_rsrc, 929 .resource = &swim_rsrc,
930}; 930};
931 931
932static const struct resource mac_scsi_iifx_rsrc[] __initconst = {
933 {
934 .flags = IORESOURCE_IRQ,
935 .start = IRQ_MAC_SCSI,
936 .end = IRQ_MAC_SCSI,
937 }, {
938 .flags = IORESOURCE_MEM,
939 .start = 0x50008000,
940 .end = 0x50009FFF,
941 },
942};
943
944static const struct resource mac_scsi_duo_rsrc[] __initconst = {
945 {
946 .flags = IORESOURCE_MEM,
947 .start = 0xFEE02000,
948 .end = 0xFEE03FFF,
949 },
950};
951
952static const struct resource mac_scsi_old_rsrc[] __initconst = {
953 {
954 .flags = IORESOURCE_IRQ,
955 .start = IRQ_MAC_SCSI,
956 .end = IRQ_MAC_SCSI,
957 }, {
958 .flags = IORESOURCE_MEM,
959 .start = 0x50010000,
960 .end = 0x50011FFF,
961 }, {
962 .flags = IORESOURCE_MEM,
963 .start = 0x50006000,
964 .end = 0x50007FFF,
965 },
966};
967
968static const struct resource mac_scsi_late_rsrc[] __initconst = {
969 {
970 .flags = IORESOURCE_IRQ,
971 .start = IRQ_MAC_SCSI,
972 .end = IRQ_MAC_SCSI,
973 }, {
974 .flags = IORESOURCE_MEM,
975 .start = 0x50010000,
976 .end = 0x50011FFF,
977 },
978};
979
980static const struct resource mac_scsi_ccl_rsrc[] __initconst = {
981 {
982 .flags = IORESOURCE_IRQ,
983 .start = IRQ_MAC_SCSI,
984 .end = IRQ_MAC_SCSI,
985 }, {
986 .flags = IORESOURCE_MEM,
987 .start = 0x50F10000,
988 .end = 0x50F11FFF,
989 }, {
990 .flags = IORESOURCE_MEM,
991 .start = 0x50F06000,
992 .end = 0x50F07FFF,
993 },
994};
995
932static struct platform_device esp_0_pdev = { 996static struct platform_device esp_0_pdev = {
933 .name = "mac_esp", 997 .name = "mac_esp",
934 .id = 0, 998 .id = 0,
@@ -1000,6 +1064,60 @@ int __init mac_platform_init(void)
1000 (macintosh_config->ident == MAC_MODEL_Q950)) 1064 (macintosh_config->ident == MAC_MODEL_Q950))
1001 platform_device_register(&esp_1_pdev); 1065 platform_device_register(&esp_1_pdev);
1002 break; 1066 break;
1067 case MAC_SCSI_IIFX:
1068 /* Addresses from The Guide to Mac Family Hardware.
1069 * $5000 8000 - $5000 9FFF: SCSI DMA
1070 * $5000 C000 - $5000 DFFF: Alternate SCSI (DMA)
1071 * $5000 E000 - $5000 FFFF: Alternate SCSI (Hsk)
1072 * The SCSI DMA custom IC embeds the 53C80 core. mac_scsi does
1073 * not make use of its DMA or hardware handshaking logic.
1074 */
1075 platform_device_register_simple("mac_scsi", 0,
1076 mac_scsi_iifx_rsrc, ARRAY_SIZE(mac_scsi_iifx_rsrc));
1077 break;
1078 case MAC_SCSI_DUO:
1079 /* Addresses from the Duo Dock II Developer Note.
1080 * $FEE0 2000 - $FEE0 3FFF: normal mode
1081 * $FEE0 4000 - $FEE0 5FFF: pseudo DMA without /DRQ
1082 * $FEE0 6000 - $FEE0 7FFF: pseudo DMA with /DRQ
1083 * The NetBSD code indicates that both 5380 chips share
1084 * an IRQ (?) which would need careful handling (see mac_esp).
1085 */
1086 platform_device_register_simple("mac_scsi", 1,
1087 mac_scsi_duo_rsrc, ARRAY_SIZE(mac_scsi_duo_rsrc));
1088 /* fall through */
1089 case MAC_SCSI_OLD:
1090 /* Addresses from Developer Notes for Duo System,
1091 * PowerBook 180 & 160, 140 & 170, Macintosh IIsi
1092 * and also from The Guide to Mac Family Hardware for
1093 * SE/30, II, IIx, IIcx, IIci.
1094 * $5000 6000 - $5000 7FFF: pseudo-DMA with /DRQ
1095 * $5001 0000 - $5001 1FFF: normal mode
1096 * $5001 2000 - $5001 3FFF: pseudo-DMA without /DRQ
1097 * GMFH says that $5000 0000 - $50FF FFFF "wraps
1098 * $5000 0000 - $5001 FFFF eight times" (!)
1099 * mess.org says IIci and Color Classic do not alias
1100 * I/O address space.
1101 */
1102 platform_device_register_simple("mac_scsi", 0,
1103 mac_scsi_old_rsrc, ARRAY_SIZE(mac_scsi_old_rsrc));
1104 break;
1105 case MAC_SCSI_LATE:
1106 /* PDMA logic in 68040 PowerBooks is somehow different to
1107 * '030 models. It's probably more like Quadras (see mac_esp).
1108 */
1109 platform_device_register_simple("mac_scsi", 0,
1110 mac_scsi_late_rsrc, ARRAY_SIZE(mac_scsi_late_rsrc));
1111 break;
1112 case MAC_SCSI_CCL:
1113 /* Addresses from the Color Classic Developer Note.
1114 * $50F0 6000 - $50F0 7FFF: SCSI handshake
1115 * $50F1 0000 - $50F1 1FFF: SCSI
1116 * $50F1 2000 - $50F1 3FFF: SCSI DMA
1117 */
1118 platform_device_register_simple("mac_scsi", 0,
1119 mac_scsi_ccl_rsrc, ARRAY_SIZE(mac_scsi_ccl_rsrc));
1120 break;
1003 } 1121 }
1004 1122
1005 /* 1123 /*
diff --git a/arch/m68k/mm/init.c b/arch/m68k/mm/init.c
index acaff6a49e35..b09a3cb29b68 100644
--- a/arch/m68k/mm/init.c
+++ b/arch/m68k/mm/init.c
@@ -94,7 +94,6 @@ void __init paging_init(void)
94 high_memory = (void *) end_mem; 94 high_memory = (void *) end_mem;
95 95
96 empty_zero_page = alloc_bootmem_pages(PAGE_SIZE); 96 empty_zero_page = alloc_bootmem_pages(PAGE_SIZE);
97 memset(empty_zero_page, 0, PAGE_SIZE);
98 97
99 /* 98 /*
100 * Set up SFC/DFC registers (user data space). 99 * Set up SFC/DFC registers (user data space).
diff --git a/arch/m68k/sun3/config.c b/arch/m68k/sun3/config.c
index f59ec58083f8..a8b942bf7163 100644
--- a/arch/m68k/sun3/config.c
+++ b/arch/m68k/sun3/config.c
@@ -16,6 +16,7 @@
16#include <linux/console.h> 16#include <linux/console.h>
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/bootmem.h> 18#include <linux/bootmem.h>
19#include <linux/platform_device.h>
19 20
20#include <asm/oplib.h> 21#include <asm/oplib.h>
21#include <asm/setup.h> 22#include <asm/setup.h>
@@ -27,6 +28,7 @@
27#include <asm/sun3mmu.h> 28#include <asm/sun3mmu.h>
28#include <asm/rtc.h> 29#include <asm/rtc.h>
29#include <asm/machdep.h> 30#include <asm/machdep.h>
31#include <asm/machines.h>
30#include <asm/idprom.h> 32#include <asm/idprom.h>
31#include <asm/intersil.h> 33#include <asm/intersil.h>
32#include <asm/irq.h> 34#include <asm/irq.h>
@@ -169,3 +171,61 @@ static void __init sun3_sched_init(irq_handler_t timer_routine)
169 intersil_clear(); 171 intersil_clear();
170} 172}
171 173
174#ifdef CONFIG_SUN3_SCSI
175
176static const struct resource sun3_scsi_vme_rsrc[] __initconst = {
177 {
178 .flags = IORESOURCE_IRQ,
179 .start = SUN3_VEC_VMESCSI0,
180 .end = SUN3_VEC_VMESCSI0,
181 }, {
182 .flags = IORESOURCE_MEM,
183 .start = 0xff200000,
184 .end = 0xff200021,
185 }, {
186 .flags = IORESOURCE_IRQ,
187 .start = SUN3_VEC_VMESCSI1,
188 .end = SUN3_VEC_VMESCSI1,
189 }, {
190 .flags = IORESOURCE_MEM,
191 .start = 0xff204000,
192 .end = 0xff204021,
193 },
194};
195
196/*
197 * Int: level 2 autovector
198 * IO: type 1, base 0x00140000, 5 bits phys space: A<4..0>
199 */
200static const struct resource sun3_scsi_rsrc[] __initconst = {
201 {
202 .flags = IORESOURCE_IRQ,
203 .start = 2,
204 .end = 2,
205 }, {
206 .flags = IORESOURCE_MEM,
207 .start = 0x00140000,
208 .end = 0x0014001f,
209 },
210};
211
212int __init sun3_platform_init(void)
213{
214 switch (idprom->id_machtype) {
215 case SM_SUN3 | SM_3_160:
216 case SM_SUN3 | SM_3_260:
217 platform_device_register_simple("sun3_scsi_vme", -1,
218 sun3_scsi_vme_rsrc, ARRAY_SIZE(sun3_scsi_vme_rsrc));
219 break;
220 case SM_SUN3 | SM_3_50:
221 case SM_SUN3 | SM_3_60:
222 platform_device_register_simple("sun3_scsi", -1,
223 sun3_scsi_rsrc, ARRAY_SIZE(sun3_scsi_rsrc));
224 break;
225 }
226 return 0;
227}
228
229arch_initcall(sun3_platform_init);
230
231#endif
diff --git a/arch/microblaze/include/asm/tlb.h b/arch/microblaze/include/asm/tlb.h
index 8aa97817cc8c..99b6ded54849 100644
--- a/arch/microblaze/include/asm/tlb.h
+++ b/arch/microblaze/include/asm/tlb.h
@@ -14,7 +14,6 @@
14#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm) 14#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm)
15 15
16#include <linux/pagemap.h> 16#include <linux/pagemap.h>
17#include <asm-generic/tlb.h>
18 17
19#ifdef CONFIG_MMU 18#ifdef CONFIG_MMU
20#define tlb_start_vma(tlb, vma) do { } while (0) 19#define tlb_start_vma(tlb, vma) do { } while (0)
@@ -22,4 +21,6 @@
22#define __tlb_remove_tlb_entry(tlb, pte, address) do { } while (0) 21#define __tlb_remove_tlb_entry(tlb, pte, address) do { } while (0)
23#endif 22#endif
24 23
24#include <asm-generic/tlb.h>
25
25#endif /* _ASM_MICROBLAZE_TLB_H */ 26#endif /* _ASM_MICROBLAZE_TLB_H */
diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index f43aa536c517..9536ef912f59 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2101,9 +2101,17 @@ config 64BIT_PHYS_ADDR
2101config ARCH_PHYS_ADDR_T_64BIT 2101config ARCH_PHYS_ADDR_T_64BIT
2102 def_bool 64BIT_PHYS_ADDR 2102 def_bool 64BIT_PHYS_ADDR
2103 2103
2104choice
2105 prompt "SmartMIPS or microMIPS ASE support"
2106
2107config CPU_NEEDS_NO_SMARTMIPS_OR_MICROMIPS
2108 bool "None"
2109 help
2110 Select this if you want neither microMIPS nor SmartMIPS support
2111
2104config CPU_HAS_SMARTMIPS 2112config CPU_HAS_SMARTMIPS
2105 depends on SYS_SUPPORTS_SMARTMIPS 2113 depends on SYS_SUPPORTS_SMARTMIPS
2106 bool "Support for the SmartMIPS ASE" 2114 bool "SmartMIPS"
2107 help 2115 help
2108 SmartMIPS is a extension of the MIPS32 architecture aimed at 2116 SmartMIPS is a extension of the MIPS32 architecture aimed at
2109 increased security at both hardware and software level for 2117 increased security at both hardware and software level for
@@ -2115,11 +2123,13 @@ config CPU_HAS_SMARTMIPS
2115 2123
2116config CPU_MICROMIPS 2124config CPU_MICROMIPS
2117 depends on SYS_SUPPORTS_MICROMIPS 2125 depends on SYS_SUPPORTS_MICROMIPS
2118 bool "Build kernel using microMIPS ISA" 2126 bool "microMIPS"
2119 help 2127 help
2120 When this option is enabled the kernel will be built using the 2128 When this option is enabled the kernel will be built using the
2121 microMIPS ISA 2129 microMIPS ISA
2122 2130
2131endchoice
2132
2123config CPU_HAS_MSA 2133config CPU_HAS_MSA
2124 bool "Support for the MIPS SIMD Architecture (EXPERIMENTAL)" 2134 bool "Support for the MIPS SIMD Architecture (EXPERIMENTAL)"
2125 depends on CPU_SUPPORTS_MSA 2135 depends on CPU_SUPPORTS_MSA
diff --git a/arch/mips/Makefile b/arch/mips/Makefile
index 23cb94806fbc..58076472bdd8 100644
--- a/arch/mips/Makefile
+++ b/arch/mips/Makefile
@@ -93,6 +93,15 @@ LDFLAGS_vmlinux += -G 0 -static -n -nostdlib
93KBUILD_AFLAGS_MODULE += -mlong-calls 93KBUILD_AFLAGS_MODULE += -mlong-calls
94KBUILD_CFLAGS_MODULE += -mlong-calls 94KBUILD_CFLAGS_MODULE += -mlong-calls
95 95
96#
97# pass -msoft-float to GAS if it supports it. However on newer binutils
98# (specifically newer than 2.24.51.20140728) we then also need to explicitly
99# set ".set hardfloat" in all files which manipulate floating point registers.
100#
101ifneq ($(call as-option,-Wa$(comma)-msoft-float,),)
102 cflags-y += -DGAS_HAS_SET_HARDFLOAT -Wa,-msoft-float
103endif
104
96cflags-y += -ffreestanding 105cflags-y += -ffreestanding
97 106
98# 107#
diff --git a/arch/mips/cavium-octeon/octeon-irq.c b/arch/mips/cavium-octeon/octeon-irq.c
index 741734049675..2bc4aa95944e 100644
--- a/arch/mips/cavium-octeon/octeon-irq.c
+++ b/arch/mips/cavium-octeon/octeon-irq.c
@@ -809,6 +809,7 @@ static struct irq_chip octeon_irq_chip_ciu_gpio_v2 = {
809 .irq_set_type = octeon_irq_ciu_gpio_set_type, 809 .irq_set_type = octeon_irq_ciu_gpio_set_type,
810#ifdef CONFIG_SMP 810#ifdef CONFIG_SMP
811 .irq_set_affinity = octeon_irq_ciu_set_affinity_v2, 811 .irq_set_affinity = octeon_irq_ciu_set_affinity_v2,
812 .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
812#endif 813#endif
813 .flags = IRQCHIP_SET_TYPE_MASKED, 814 .flags = IRQCHIP_SET_TYPE_MASKED,
814}; 815};
@@ -823,6 +824,7 @@ static struct irq_chip octeon_irq_chip_ciu_gpio = {
823 .irq_set_type = octeon_irq_ciu_gpio_set_type, 824 .irq_set_type = octeon_irq_ciu_gpio_set_type,
824#ifdef CONFIG_SMP 825#ifdef CONFIG_SMP
825 .irq_set_affinity = octeon_irq_ciu_set_affinity, 826 .irq_set_affinity = octeon_irq_ciu_set_affinity,
827 .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
826#endif 828#endif
827 .flags = IRQCHIP_SET_TYPE_MASKED, 829 .flags = IRQCHIP_SET_TYPE_MASKED,
828}; 830};
diff --git a/arch/mips/include/asm/asmmacro-32.h b/arch/mips/include/asm/asmmacro-32.h
index e38c2811d4e2..cdac7b3eeaf7 100644
--- a/arch/mips/include/asm/asmmacro-32.h
+++ b/arch/mips/include/asm/asmmacro-32.h
@@ -13,6 +13,8 @@
13#include <asm/mipsregs.h> 13#include <asm/mipsregs.h>
14 14
15 .macro fpu_save_single thread tmp=t0 15 .macro fpu_save_single thread tmp=t0
16 .set push
17 SET_HARDFLOAT
16 cfc1 \tmp, fcr31 18 cfc1 \tmp, fcr31
17 swc1 $f0, THREAD_FPR0_LS64(\thread) 19 swc1 $f0, THREAD_FPR0_LS64(\thread)
18 swc1 $f1, THREAD_FPR1_LS64(\thread) 20 swc1 $f1, THREAD_FPR1_LS64(\thread)
@@ -47,9 +49,12 @@
47 swc1 $f30, THREAD_FPR30_LS64(\thread) 49 swc1 $f30, THREAD_FPR30_LS64(\thread)
48 swc1 $f31, THREAD_FPR31_LS64(\thread) 50 swc1 $f31, THREAD_FPR31_LS64(\thread)
49 sw \tmp, THREAD_FCR31(\thread) 51 sw \tmp, THREAD_FCR31(\thread)
52 .set pop
50 .endm 53 .endm
51 54
52 .macro fpu_restore_single thread tmp=t0 55 .macro fpu_restore_single thread tmp=t0
56 .set push
57 SET_HARDFLOAT
53 lw \tmp, THREAD_FCR31(\thread) 58 lw \tmp, THREAD_FCR31(\thread)
54 lwc1 $f0, THREAD_FPR0_LS64(\thread) 59 lwc1 $f0, THREAD_FPR0_LS64(\thread)
55 lwc1 $f1, THREAD_FPR1_LS64(\thread) 60 lwc1 $f1, THREAD_FPR1_LS64(\thread)
@@ -84,6 +89,7 @@
84 lwc1 $f30, THREAD_FPR30_LS64(\thread) 89 lwc1 $f30, THREAD_FPR30_LS64(\thread)
85 lwc1 $f31, THREAD_FPR31_LS64(\thread) 90 lwc1 $f31, THREAD_FPR31_LS64(\thread)
86 ctc1 \tmp, fcr31 91 ctc1 \tmp, fcr31
92 .set pop
87 .endm 93 .endm
88 94
89 .macro cpu_save_nonscratch thread 95 .macro cpu_save_nonscratch thread
diff --git a/arch/mips/include/asm/asmmacro.h b/arch/mips/include/asm/asmmacro.h
index cd9a98bc8f60..6caf8766b80f 100644
--- a/arch/mips/include/asm/asmmacro.h
+++ b/arch/mips/include/asm/asmmacro.h
@@ -57,6 +57,8 @@
57#endif /* CONFIG_CPU_MIPSR2 */ 57#endif /* CONFIG_CPU_MIPSR2 */
58 58
59 .macro fpu_save_16even thread tmp=t0 59 .macro fpu_save_16even thread tmp=t0
60 .set push
61 SET_HARDFLOAT
60 cfc1 \tmp, fcr31 62 cfc1 \tmp, fcr31
61 sdc1 $f0, THREAD_FPR0_LS64(\thread) 63 sdc1 $f0, THREAD_FPR0_LS64(\thread)
62 sdc1 $f2, THREAD_FPR2_LS64(\thread) 64 sdc1 $f2, THREAD_FPR2_LS64(\thread)
@@ -75,11 +77,13 @@
75 sdc1 $f28, THREAD_FPR28_LS64(\thread) 77 sdc1 $f28, THREAD_FPR28_LS64(\thread)
76 sdc1 $f30, THREAD_FPR30_LS64(\thread) 78 sdc1 $f30, THREAD_FPR30_LS64(\thread)
77 sw \tmp, THREAD_FCR31(\thread) 79 sw \tmp, THREAD_FCR31(\thread)
80 .set pop
78 .endm 81 .endm
79 82
80 .macro fpu_save_16odd thread 83 .macro fpu_save_16odd thread
81 .set push 84 .set push
82 .set mips64r2 85 .set mips64r2
86 SET_HARDFLOAT
83 sdc1 $f1, THREAD_FPR1_LS64(\thread) 87 sdc1 $f1, THREAD_FPR1_LS64(\thread)
84 sdc1 $f3, THREAD_FPR3_LS64(\thread) 88 sdc1 $f3, THREAD_FPR3_LS64(\thread)
85 sdc1 $f5, THREAD_FPR5_LS64(\thread) 89 sdc1 $f5, THREAD_FPR5_LS64(\thread)
@@ -110,6 +114,8 @@
110 .endm 114 .endm
111 115
112 .macro fpu_restore_16even thread tmp=t0 116 .macro fpu_restore_16even thread tmp=t0
117 .set push
118 SET_HARDFLOAT
113 lw \tmp, THREAD_FCR31(\thread) 119 lw \tmp, THREAD_FCR31(\thread)
114 ldc1 $f0, THREAD_FPR0_LS64(\thread) 120 ldc1 $f0, THREAD_FPR0_LS64(\thread)
115 ldc1 $f2, THREAD_FPR2_LS64(\thread) 121 ldc1 $f2, THREAD_FPR2_LS64(\thread)
@@ -133,6 +139,7 @@
133 .macro fpu_restore_16odd thread 139 .macro fpu_restore_16odd thread
134 .set push 140 .set push
135 .set mips64r2 141 .set mips64r2
142 SET_HARDFLOAT
136 ldc1 $f1, THREAD_FPR1_LS64(\thread) 143 ldc1 $f1, THREAD_FPR1_LS64(\thread)
137 ldc1 $f3, THREAD_FPR3_LS64(\thread) 144 ldc1 $f3, THREAD_FPR3_LS64(\thread)
138 ldc1 $f5, THREAD_FPR5_LS64(\thread) 145 ldc1 $f5, THREAD_FPR5_LS64(\thread)
@@ -277,6 +284,7 @@
277 .macro cfcmsa rd, cs 284 .macro cfcmsa rd, cs
278 .set push 285 .set push
279 .set noat 286 .set noat
287 SET_HARDFLOAT
280 .insn 288 .insn
281 .word CFC_MSA_INSN | (\cs << 11) 289 .word CFC_MSA_INSN | (\cs << 11)
282 move \rd, $1 290 move \rd, $1
@@ -286,6 +294,7 @@
286 .macro ctcmsa cd, rs 294 .macro ctcmsa cd, rs
287 .set push 295 .set push
288 .set noat 296 .set noat
297 SET_HARDFLOAT
289 move $1, \rs 298 move $1, \rs
290 .word CTC_MSA_INSN | (\cd << 6) 299 .word CTC_MSA_INSN | (\cd << 6)
291 .set pop 300 .set pop
@@ -294,6 +303,7 @@
294 .macro ld_d wd, off, base 303 .macro ld_d wd, off, base
295 .set push 304 .set push
296 .set noat 305 .set noat
306 SET_HARDFLOAT
297 add $1, \base, \off 307 add $1, \base, \off
298 .word LDD_MSA_INSN | (\wd << 6) 308 .word LDD_MSA_INSN | (\wd << 6)
299 .set pop 309 .set pop
@@ -302,6 +312,7 @@
302 .macro st_d wd, off, base 312 .macro st_d wd, off, base
303 .set push 313 .set push
304 .set noat 314 .set noat
315 SET_HARDFLOAT
305 add $1, \base, \off 316 add $1, \base, \off
306 .word STD_MSA_INSN | (\wd << 6) 317 .word STD_MSA_INSN | (\wd << 6)
307 .set pop 318 .set pop
@@ -310,6 +321,7 @@
310 .macro copy_u_w rd, ws, n 321 .macro copy_u_w rd, ws, n
311 .set push 322 .set push
312 .set noat 323 .set noat
324 SET_HARDFLOAT
313 .insn 325 .insn
314 .word COPY_UW_MSA_INSN | (\n << 16) | (\ws << 11) 326 .word COPY_UW_MSA_INSN | (\n << 16) | (\ws << 11)
315 /* move triggers an assembler bug... */ 327 /* move triggers an assembler bug... */
@@ -320,6 +332,7 @@
320 .macro copy_u_d rd, ws, n 332 .macro copy_u_d rd, ws, n
321 .set push 333 .set push
322 .set noat 334 .set noat
335 SET_HARDFLOAT
323 .insn 336 .insn
324 .word COPY_UD_MSA_INSN | (\n << 16) | (\ws << 11) 337 .word COPY_UD_MSA_INSN | (\n << 16) | (\ws << 11)
325 /* move triggers an assembler bug... */ 338 /* move triggers an assembler bug... */
@@ -330,6 +343,7 @@
330 .macro insert_w wd, n, rs 343 .macro insert_w wd, n, rs
331 .set push 344 .set push
332 .set noat 345 .set noat
346 SET_HARDFLOAT
333 /* move triggers an assembler bug... */ 347 /* move triggers an assembler bug... */
334 or $1, \rs, zero 348 or $1, \rs, zero
335 .word INSERT_W_MSA_INSN | (\n << 16) | (\wd << 6) 349 .word INSERT_W_MSA_INSN | (\n << 16) | (\wd << 6)
@@ -339,6 +353,7 @@
339 .macro insert_d wd, n, rs 353 .macro insert_d wd, n, rs
340 .set push 354 .set push
341 .set noat 355 .set noat
356 SET_HARDFLOAT
342 /* move triggers an assembler bug... */ 357 /* move triggers an assembler bug... */
343 or $1, \rs, zero 358 or $1, \rs, zero
344 .word INSERT_D_MSA_INSN | (\n << 16) | (\wd << 6) 359 .word INSERT_D_MSA_INSN | (\n << 16) | (\wd << 6)
@@ -381,6 +396,7 @@
381 st_d 31, THREAD_FPR31, \thread 396 st_d 31, THREAD_FPR31, \thread
382 .set push 397 .set push
383 .set noat 398 .set noat
399 SET_HARDFLOAT
384 cfcmsa $1, MSA_CSR 400 cfcmsa $1, MSA_CSR
385 sw $1, THREAD_MSA_CSR(\thread) 401 sw $1, THREAD_MSA_CSR(\thread)
386 .set pop 402 .set pop
@@ -389,6 +405,7 @@
389 .macro msa_restore_all thread 405 .macro msa_restore_all thread
390 .set push 406 .set push
391 .set noat 407 .set noat
408 SET_HARDFLOAT
392 lw $1, THREAD_MSA_CSR(\thread) 409 lw $1, THREAD_MSA_CSR(\thread)
393 ctcmsa MSA_CSR, $1 410 ctcmsa MSA_CSR, $1
394 .set pop 411 .set pop
@@ -441,6 +458,7 @@
441 .macro msa_init_all_upper 458 .macro msa_init_all_upper
442 .set push 459 .set push
443 .set noat 460 .set noat
461 SET_HARDFLOAT
444 not $1, zero 462 not $1, zero
445 msa_init_upper 0 463 msa_init_upper 0
446 .set pop 464 .set pop
diff --git a/arch/mips/include/asm/fpregdef.h b/arch/mips/include/asm/fpregdef.h
index 429481f9028d..f184ba088532 100644
--- a/arch/mips/include/asm/fpregdef.h
+++ b/arch/mips/include/asm/fpregdef.h
@@ -14,6 +14,20 @@
14 14
15#include <asm/sgidefs.h> 15#include <asm/sgidefs.h>
16 16
17/*
18 * starting with binutils 2.24.51.20140729, MIPS binutils warn about mixing
19 * hardfloat and softfloat object files. The kernel build uses soft-float by
20 * default, so we also need to pass -msoft-float along to GAS if it supports it.
21 * But this in turn causes assembler errors in files which access hardfloat
22 * registers. We detect if GAS supports "-msoft-float" in the Makefile and
23 * explicitly put ".set hardfloat" where floating point registers are touched.
24 */
25#ifdef GAS_HAS_SET_HARDFLOAT
26#define SET_HARDFLOAT .set hardfloat
27#else
28#define SET_HARDFLOAT
29#endif
30
17#if _MIPS_SIM == _MIPS_SIM_ABI32 31#if _MIPS_SIM == _MIPS_SIM_ABI32
18 32
19/* 33/*
diff --git a/arch/mips/include/asm/fpu.h b/arch/mips/include/asm/fpu.h
index 4d0aeda68397..dd562414cd5e 100644
--- a/arch/mips/include/asm/fpu.h
+++ b/arch/mips/include/asm/fpu.h
@@ -145,8 +145,8 @@ static inline void lose_fpu(int save)
145 if (is_msa_enabled()) { 145 if (is_msa_enabled()) {
146 if (save) { 146 if (save) {
147 save_msa(current); 147 save_msa(current);
148 asm volatile("cfc1 %0, $31" 148 current->thread.fpu.fcr31 =
149 : "=r"(current->thread.fpu.fcr31)); 149 read_32bit_cp1_register(CP1_STATUS);
150 } 150 }
151 disable_msa(); 151 disable_msa();
152 clear_thread_flag(TIF_USEDMSA); 152 clear_thread_flag(TIF_USEDMSA);
diff --git a/arch/mips/include/asm/jump_label.h b/arch/mips/include/asm/jump_label.h
index e194f957ca8c..fdbff44e5482 100644
--- a/arch/mips/include/asm/jump_label.h
+++ b/arch/mips/include/asm/jump_label.h
@@ -20,9 +20,15 @@
20#define WORD_INSN ".word" 20#define WORD_INSN ".word"
21#endif 21#endif
22 22
23#ifdef CONFIG_CPU_MICROMIPS
24#define NOP_INSN "nop32"
25#else
26#define NOP_INSN "nop"
27#endif
28
23static __always_inline bool arch_static_branch(struct static_key *key) 29static __always_inline bool arch_static_branch(struct static_key *key)
24{ 30{
25 asm_volatile_goto("1:\tnop\n\t" 31 asm_volatile_goto("1:\t" NOP_INSN "\n\t"
26 "nop\n\t" 32 "nop\n\t"
27 ".pushsection __jump_table, \"aw\"\n\t" 33 ".pushsection __jump_table, \"aw\"\n\t"
28 WORD_INSN " 1b, %l[l_yes], %0\n\t" 34 WORD_INSN " 1b, %l[l_yes], %0\n\t"
diff --git a/arch/mips/include/asm/mach-loongson/cpu-feature-overrides.h b/arch/mips/include/asm/mach-loongson/cpu-feature-overrides.h
index 7d28f95b0512..6d69332f21ec 100644
--- a/arch/mips/include/asm/mach-loongson/cpu-feature-overrides.h
+++ b/arch/mips/include/asm/mach-loongson/cpu-feature-overrides.h
@@ -41,10 +41,8 @@
41#define cpu_has_mcheck 0 41#define cpu_has_mcheck 0
42#define cpu_has_mdmx 0 42#define cpu_has_mdmx 0
43#define cpu_has_mips16 0 43#define cpu_has_mips16 0
44#define cpu_has_mips32r1 0
45#define cpu_has_mips32r2 0 44#define cpu_has_mips32r2 0
46#define cpu_has_mips3d 0 45#define cpu_has_mips3d 0
47#define cpu_has_mips64r1 0
48#define cpu_has_mips64r2 0 46#define cpu_has_mips64r2 0
49#define cpu_has_mipsmt 0 47#define cpu_has_mipsmt 0
50#define cpu_has_prefetch 0 48#define cpu_has_prefetch 0
diff --git a/arch/mips/include/asm/mipsregs.h b/arch/mips/include/asm/mipsregs.h
index cf3b580c3df6..22a135ac91de 100644
--- a/arch/mips/include/asm/mipsregs.h
+++ b/arch/mips/include/asm/mipsregs.h
@@ -661,6 +661,8 @@
661#define MIPS_CONF6_SYND (_ULCAST_(1) << 13) 661#define MIPS_CONF6_SYND (_ULCAST_(1) << 13)
662/* proAptiv FTLB on/off bit */ 662/* proAptiv FTLB on/off bit */
663#define MIPS_CONF6_FTLBEN (_ULCAST_(1) << 15) 663#define MIPS_CONF6_FTLBEN (_ULCAST_(1) << 15)
664/* FTLB probability bits */
665#define MIPS_CONF6_FTLBP_SHIFT (16)
664 666
665#define MIPS_CONF7_WII (_ULCAST_(1) << 31) 667#define MIPS_CONF7_WII (_ULCAST_(1) << 31)
666 668
@@ -1324,7 +1326,7 @@ do { \
1324/* 1326/*
1325 * Macros to access the floating point coprocessor control registers 1327 * Macros to access the floating point coprocessor control registers
1326 */ 1328 */
1327#define read_32bit_cp1_register(source) \ 1329#define _read_32bit_cp1_register(source, gas_hardfloat) \
1328({ \ 1330({ \
1329 int __res; \ 1331 int __res; \
1330 \ 1332 \
@@ -1334,12 +1336,21 @@ do { \
1334 " # gas fails to assemble cfc1 for some archs, \n" \ 1336 " # gas fails to assemble cfc1 for some archs, \n" \
1335 " # like Octeon. \n" \ 1337 " # like Octeon. \n" \
1336 " .set mips1 \n" \ 1338 " .set mips1 \n" \
1339 " "STR(gas_hardfloat)" \n" \
1337 " cfc1 %0,"STR(source)" \n" \ 1340 " cfc1 %0,"STR(source)" \n" \
1338 " .set pop \n" \ 1341 " .set pop \n" \
1339 : "=r" (__res)); \ 1342 : "=r" (__res)); \
1340 __res; \ 1343 __res; \
1341}) 1344})
1342 1345
1346#ifdef GAS_HAS_SET_HARDFLOAT
1347#define read_32bit_cp1_register(source) \
1348 _read_32bit_cp1_register(source, .set hardfloat)
1349#else
1350#define read_32bit_cp1_register(source) \
1351 _read_32bit_cp1_register(source, )
1352#endif
1353
1343#ifdef HAVE_AS_DSP 1354#ifdef HAVE_AS_DSP
1344#define rddsp(mask) \ 1355#define rddsp(mask) \
1345({ \ 1356({ \
diff --git a/arch/mips/include/asm/r4kcache.h b/arch/mips/include/asm/r4kcache.h
index 4520adc8699b..cd6e0afc6833 100644
--- a/arch/mips/include/asm/r4kcache.h
+++ b/arch/mips/include/asm/r4kcache.h
@@ -257,7 +257,11 @@ static inline void protected_flush_icache_line(unsigned long addr)
257 */ 257 */
258static inline void protected_writeback_dcache_line(unsigned long addr) 258static inline void protected_writeback_dcache_line(unsigned long addr)
259{ 259{
260#ifdef CONFIG_EVA
261 protected_cachee_op(Hit_Writeback_Inv_D, addr);
262#else
260 protected_cache_op(Hit_Writeback_Inv_D, addr); 263 protected_cache_op(Hit_Writeback_Inv_D, addr);
264#endif
261} 265}
262 266
263static inline void protected_writeback_scache_line(unsigned long addr) 267static inline void protected_writeback_scache_line(unsigned long addr)
diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
index a10951090234..22a5624e2fd2 100644
--- a/arch/mips/include/asm/uaccess.h
+++ b/arch/mips/include/asm/uaccess.h
@@ -301,7 +301,8 @@ do { \
301 __get_kernel_common((x), size, __gu_ptr); \ 301 __get_kernel_common((x), size, __gu_ptr); \
302 else \ 302 else \
303 __get_user_common((x), size, __gu_ptr); \ 303 __get_user_common((x), size, __gu_ptr); \
304 } \ 304 } else \
305 (x) = 0; \
305 \ 306 \
306 __gu_err; \ 307 __gu_err; \
307}) 308})
@@ -316,6 +317,7 @@ do { \
316 " .insn \n" \ 317 " .insn \n" \
317 " .section .fixup,\"ax\" \n" \ 318 " .section .fixup,\"ax\" \n" \
318 "3: li %0, %4 \n" \ 319 "3: li %0, %4 \n" \
320 " move %1, $0 \n" \
319 " j 2b \n" \ 321 " j 2b \n" \
320 " .previous \n" \ 322 " .previous \n" \
321 " .section __ex_table,\"a\" \n" \ 323 " .section __ex_table,\"a\" \n" \
@@ -630,6 +632,7 @@ do { \
630 " .insn \n" \ 632 " .insn \n" \
631 " .section .fixup,\"ax\" \n" \ 633 " .section .fixup,\"ax\" \n" \
632 "3: li %0, %4 \n" \ 634 "3: li %0, %4 \n" \
635 " move %1, $0 \n" \
633 " j 2b \n" \ 636 " j 2b \n" \
634 " .previous \n" \ 637 " .previous \n" \
635 " .section __ex_table,\"a\" \n" \ 638 " .section __ex_table,\"a\" \n" \
@@ -773,10 +776,11 @@ extern void __put_user_unaligned_unknown(void);
773 "jal\t" #destination "\n\t" 776 "jal\t" #destination "\n\t"
774#endif 777#endif
775 778
776#ifndef CONFIG_CPU_DADDI_WORKAROUNDS 779#if defined(CONFIG_CPU_DADDI_WORKAROUNDS) || (defined(CONFIG_EVA) && \
777#define DADDI_SCRATCH "$0" 780 defined(CONFIG_CPU_HAS_PREFETCH))
778#else
779#define DADDI_SCRATCH "$3" 781#define DADDI_SCRATCH "$3"
782#else
783#define DADDI_SCRATCH "$0"
780#endif 784#endif
781 785
782extern size_t __copy_user(void *__to, const void *__from, size_t __n); 786extern size_t __copy_user(void *__to, const void *__from, size_t __n);
@@ -1418,7 +1422,7 @@ static inline long __strnlen_user(const char __user *s, long n)
1418} 1422}
1419 1423
1420/* 1424/*
1421 * strlen_user: - Get the size of a string in user space. 1425 * strnlen_user: - Get the size of a string in user space.
1422 * @str: The string to measure. 1426 * @str: The string to measure.
1423 * 1427 *
1424 * Context: User context only. This function may sleep. 1428 * Context: User context only. This function may sleep.
@@ -1427,9 +1431,7 @@ static inline long __strnlen_user(const char __user *s, long n)
1427 * 1431 *
1428 * Returns the size of the string INCLUDING the terminating NUL. 1432 * Returns the size of the string INCLUDING the terminating NUL.
1429 * On exception, returns 0. 1433 * On exception, returns 0.
1430 * 1434 * If the string is too long, returns a value greater than @n.
1431 * If there is a limit on the length of a valid string, you may wish to
1432 * consider using strnlen_user() instead.
1433 */ 1435 */
1434static inline long strnlen_user(const char __user *s, long n) 1436static inline long strnlen_user(const char __user *s, long n)
1435{ 1437{
diff --git a/arch/mips/include/uapi/asm/unistd.h b/arch/mips/include/uapi/asm/unistd.h
index fdb4923777d1..d001bb1ad177 100644
--- a/arch/mips/include/uapi/asm/unistd.h
+++ b/arch/mips/include/uapi/asm/unistd.h
@@ -375,16 +375,17 @@
375#define __NR_seccomp (__NR_Linux + 352) 375#define __NR_seccomp (__NR_Linux + 352)
376#define __NR_getrandom (__NR_Linux + 353) 376#define __NR_getrandom (__NR_Linux + 353)
377#define __NR_memfd_create (__NR_Linux + 354) 377#define __NR_memfd_create (__NR_Linux + 354)
378#define __NR_bpf (__NR_Linux + 355)
378 379
379/* 380/*
380 * Offset of the last Linux o32 flavoured syscall 381 * Offset of the last Linux o32 flavoured syscall
381 */ 382 */
382#define __NR_Linux_syscalls 354 383#define __NR_Linux_syscalls 355
383 384
384#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */ 385#endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */
385 386
386#define __NR_O32_Linux 4000 387#define __NR_O32_Linux 4000
387#define __NR_O32_Linux_syscalls 354 388#define __NR_O32_Linux_syscalls 355
388 389
389#if _MIPS_SIM == _MIPS_SIM_ABI64 390#if _MIPS_SIM == _MIPS_SIM_ABI64
390 391
@@ -707,16 +708,17 @@
707#define __NR_seccomp (__NR_Linux + 312) 708#define __NR_seccomp (__NR_Linux + 312)
708#define __NR_getrandom (__NR_Linux + 313) 709#define __NR_getrandom (__NR_Linux + 313)
709#define __NR_memfd_create (__NR_Linux + 314) 710#define __NR_memfd_create (__NR_Linux + 314)
711#define __NR_bpf (__NR_Linux + 315)
710 712
711/* 713/*
712 * Offset of the last Linux 64-bit flavoured syscall 714 * Offset of the last Linux 64-bit flavoured syscall
713 */ 715 */
714#define __NR_Linux_syscalls 314 716#define __NR_Linux_syscalls 315
715 717
716#endif /* _MIPS_SIM == _MIPS_SIM_ABI64 */ 718#endif /* _MIPS_SIM == _MIPS_SIM_ABI64 */
717 719
718#define __NR_64_Linux 5000 720#define __NR_64_Linux 5000
719#define __NR_64_Linux_syscalls 314 721#define __NR_64_Linux_syscalls 315
720 722
721#if _MIPS_SIM == _MIPS_SIM_NABI32 723#if _MIPS_SIM == _MIPS_SIM_NABI32
722 724
@@ -1043,15 +1045,16 @@
1043#define __NR_seccomp (__NR_Linux + 316) 1045#define __NR_seccomp (__NR_Linux + 316)
1044#define __NR_getrandom (__NR_Linux + 317) 1046#define __NR_getrandom (__NR_Linux + 317)
1045#define __NR_memfd_create (__NR_Linux + 318) 1047#define __NR_memfd_create (__NR_Linux + 318)
1048#define __NR_bpf (__NR_Linux + 319)
1046 1049
1047/* 1050/*
1048 * Offset of the last N32 flavoured syscall 1051 * Offset of the last N32 flavoured syscall
1049 */ 1052 */
1050#define __NR_Linux_syscalls 318 1053#define __NR_Linux_syscalls 319
1051 1054
1052#endif /* _MIPS_SIM == _MIPS_SIM_NABI32 */ 1055#endif /* _MIPS_SIM == _MIPS_SIM_NABI32 */
1053 1056
1054#define __NR_N32_Linux 6000 1057#define __NR_N32_Linux 6000
1055#define __NR_N32_Linux_syscalls 318 1058#define __NR_N32_Linux_syscalls 319
1056 1059
1057#endif /* _UAPI_ASM_UNISTD_H */ 1060#endif /* _UAPI_ASM_UNISTD_H */
diff --git a/arch/mips/kernel/bmips_vec.S b/arch/mips/kernel/bmips_vec.S
index 290c23b51678..86495072a922 100644
--- a/arch/mips/kernel/bmips_vec.S
+++ b/arch/mips/kernel/bmips_vec.S
@@ -208,7 +208,6 @@ bmips_reset_nmi_vec_end:
208END(bmips_reset_nmi_vec) 208END(bmips_reset_nmi_vec)
209 209
210 .set pop 210 .set pop
211 .previous
212 211
213/*********************************************************************** 212/***********************************************************************
214 * CPU1 warm restart vector (used for second and subsequent boots). 213 * CPU1 warm restart vector (used for second and subsequent boots).
@@ -281,5 +280,3 @@ LEAF(bmips_enable_xks01)
281 jr ra 280 jr ra
282 281
283END(bmips_enable_xks01) 282END(bmips_enable_xks01)
284
285 .previous
diff --git a/arch/mips/kernel/branch.c b/arch/mips/kernel/branch.c
index 7b2df224f041..4d7d99d601cc 100644
--- a/arch/mips/kernel/branch.c
+++ b/arch/mips/kernel/branch.c
@@ -144,7 +144,7 @@ int __mm_isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
144 case mm_bc1t_op: 144 case mm_bc1t_op:
145 preempt_disable(); 145 preempt_disable();
146 if (is_fpu_owner()) 146 if (is_fpu_owner())
147 asm volatile("cfc1\t%0,$31" : "=r" (fcr31)); 147 fcr31 = read_32bit_cp1_register(CP1_STATUS);
148 else 148 else
149 fcr31 = current->thread.fpu.fcr31; 149 fcr31 = current->thread.fpu.fcr31;
150 preempt_enable(); 150 preempt_enable();
@@ -562,11 +562,7 @@ int __compute_return_epc_for_insn(struct pt_regs *regs,
562 case cop1_op: 562 case cop1_op:
563 preempt_disable(); 563 preempt_disable();
564 if (is_fpu_owner()) 564 if (is_fpu_owner())
565 asm volatile( 565 fcr31 = read_32bit_cp1_register(CP1_STATUS);
566 ".set push\n"
567 "\t.set mips1\n"
568 "\tcfc1\t%0,$31\n"
569 "\t.set pop" : "=r" (fcr31));
570 else 566 else
571 fcr31 = current->thread.fpu.fcr31; 567 fcr31 = current->thread.fpu.fcr31;
572 preempt_enable(); 568 preempt_enable();
diff --git a/arch/mips/kernel/cps-vec.S b/arch/mips/kernel/cps-vec.S
index e6e97d2a5c9e..0384b05ab5a0 100644
--- a/arch/mips/kernel/cps-vec.S
+++ b/arch/mips/kernel/cps-vec.S
@@ -229,6 +229,7 @@ LEAF(mips_cps_core_init)
229 nop 229 nop
230 230
231 .set push 231 .set push
232 .set mips32r2
232 .set mt 233 .set mt
233 234
234 /* Only allow 1 TC per VPE to execute... */ 235 /* Only allow 1 TC per VPE to execute... */
@@ -345,6 +346,7 @@ LEAF(mips_cps_boot_vpes)
345 nop 346 nop
346 347
347 .set push 348 .set push
349 .set mips32r2
348 .set mt 350 .set mt
349 351
3501: /* Enter VPE configuration state */ 3521: /* Enter VPE configuration state */
diff --git a/arch/mips/kernel/cpu-probe.c b/arch/mips/kernel/cpu-probe.c
index 94c4a0c0a577..dc49cf30c2db 100644
--- a/arch/mips/kernel/cpu-probe.c
+++ b/arch/mips/kernel/cpu-probe.c
@@ -193,6 +193,32 @@ static void set_isa(struct cpuinfo_mips *c, unsigned int isa)
193static char unknown_isa[] = KERN_ERR \ 193static char unknown_isa[] = KERN_ERR \
194 "Unsupported ISA type, c0.config0: %d."; 194 "Unsupported ISA type, c0.config0: %d.";
195 195
196static unsigned int calculate_ftlb_probability(struct cpuinfo_mips *c)
197{
198
199 unsigned int probability = c->tlbsize / c->tlbsizevtlb;
200
201 /*
202 * 0 = All TLBWR instructions go to FTLB
203 * 1 = 15:1: For every 16 TBLWR instructions, 15 go to the
204 * FTLB and 1 goes to the VTLB.
205 * 2 = 7:1: As above with 7:1 ratio.
206 * 3 = 3:1: As above with 3:1 ratio.
207 *
208 * Use the linear midpoint as the probability threshold.
209 */
210 if (probability >= 12)
211 return 1;
212 else if (probability >= 6)
213 return 2;
214 else
215 /*
216 * So FTLB is less than 4 times bigger than VTLB.
217 * A 3:1 ratio can still be useful though.
218 */
219 return 3;
220}
221
196static void set_ftlb_enable(struct cpuinfo_mips *c, int enable) 222static void set_ftlb_enable(struct cpuinfo_mips *c, int enable)
197{ 223{
198 unsigned int config6; 224 unsigned int config6;
@@ -203,9 +229,14 @@ static void set_ftlb_enable(struct cpuinfo_mips *c, int enable)
203 case CPU_P5600: 229 case CPU_P5600:
204 /* proAptiv & related cores use Config6 to enable the FTLB */ 230 /* proAptiv & related cores use Config6 to enable the FTLB */
205 config6 = read_c0_config6(); 231 config6 = read_c0_config6();
232 /* Clear the old probability value */
233 config6 &= ~(3 << MIPS_CONF6_FTLBP_SHIFT);
206 if (enable) 234 if (enable)
207 /* Enable FTLB */ 235 /* Enable FTLB */
208 write_c0_config6(config6 | MIPS_CONF6_FTLBEN); 236 write_c0_config6(config6 |
237 (calculate_ftlb_probability(c)
238 << MIPS_CONF6_FTLBP_SHIFT)
239 | MIPS_CONF6_FTLBEN);
209 else 240 else
210 /* Disable FTLB */ 241 /* Disable FTLB */
211 write_c0_config6(config6 & ~MIPS_CONF6_FTLBEN); 242 write_c0_config6(config6 & ~MIPS_CONF6_FTLBEN);
@@ -757,31 +788,34 @@ static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
757 c->cputype = CPU_LOONGSON2; 788 c->cputype = CPU_LOONGSON2;
758 __cpu_name[cpu] = "ICT Loongson-2"; 789 __cpu_name[cpu] = "ICT Loongson-2";
759 set_elf_platform(cpu, "loongson2e"); 790 set_elf_platform(cpu, "loongson2e");
791 set_isa(c, MIPS_CPU_ISA_III);
760 break; 792 break;
761 case PRID_REV_LOONGSON2F: 793 case PRID_REV_LOONGSON2F:
762 c->cputype = CPU_LOONGSON2; 794 c->cputype = CPU_LOONGSON2;
763 __cpu_name[cpu] = "ICT Loongson-2"; 795 __cpu_name[cpu] = "ICT Loongson-2";
764 set_elf_platform(cpu, "loongson2f"); 796 set_elf_platform(cpu, "loongson2f");
797 set_isa(c, MIPS_CPU_ISA_III);
765 break; 798 break;
766 case PRID_REV_LOONGSON3A: 799 case PRID_REV_LOONGSON3A:
767 c->cputype = CPU_LOONGSON3; 800 c->cputype = CPU_LOONGSON3;
768 c->writecombine = _CACHE_UNCACHED_ACCELERATED;
769 __cpu_name[cpu] = "ICT Loongson-3"; 801 __cpu_name[cpu] = "ICT Loongson-3";
770 set_elf_platform(cpu, "loongson3a"); 802 set_elf_platform(cpu, "loongson3a");
803 set_isa(c, MIPS_CPU_ISA_M64R1);
771 break; 804 break;
772 case PRID_REV_LOONGSON3B_R1: 805 case PRID_REV_LOONGSON3B_R1:
773 case PRID_REV_LOONGSON3B_R2: 806 case PRID_REV_LOONGSON3B_R2:
774 c->cputype = CPU_LOONGSON3; 807 c->cputype = CPU_LOONGSON3;
775 __cpu_name[cpu] = "ICT Loongson-3"; 808 __cpu_name[cpu] = "ICT Loongson-3";
776 set_elf_platform(cpu, "loongson3b"); 809 set_elf_platform(cpu, "loongson3b");
810 set_isa(c, MIPS_CPU_ISA_M64R1);
777 break; 811 break;
778 } 812 }
779 813
780 set_isa(c, MIPS_CPU_ISA_III);
781 c->options = R4K_OPTS | 814 c->options = R4K_OPTS |
782 MIPS_CPU_FPU | MIPS_CPU_LLSC | 815 MIPS_CPU_FPU | MIPS_CPU_LLSC |
783 MIPS_CPU_32FPR; 816 MIPS_CPU_32FPR;
784 c->tlbsize = 64; 817 c->tlbsize = 64;
818 c->writecombine = _CACHE_UNCACHED_ACCELERATED;
785 break; 819 break;
786 case PRID_IMP_LOONGSON_32: /* Loongson-1 */ 820 case PRID_IMP_LOONGSON_32: /* Loongson-1 */
787 decode_configs(c); 821 decode_configs(c);
diff --git a/arch/mips/kernel/genex.S b/arch/mips/kernel/genex.S
index ac35e12cb1f3..a5e26dd90592 100644
--- a/arch/mips/kernel/genex.S
+++ b/arch/mips/kernel/genex.S
@@ -358,6 +358,7 @@ NESTED(nmi_handler, PT_SIZE, sp)
358 .set push 358 .set push
359 /* gas fails to assemble cfc1 for some archs (octeon).*/ \ 359 /* gas fails to assemble cfc1 for some archs (octeon).*/ \
360 .set mips1 360 .set mips1
361 SET_HARDFLOAT
361 cfc1 a1, fcr31 362 cfc1 a1, fcr31
362 li a2, ~(0x3f << 12) 363 li a2, ~(0x3f << 12)
363 and a2, a1 364 and a2, a1
diff --git a/arch/mips/kernel/jump_label.c b/arch/mips/kernel/jump_label.c
index 6001610cfe55..dda800e9e731 100644
--- a/arch/mips/kernel/jump_label.c
+++ b/arch/mips/kernel/jump_label.c
@@ -18,31 +18,53 @@
18 18
19#ifdef HAVE_JUMP_LABEL 19#ifdef HAVE_JUMP_LABEL
20 20
21#define J_RANGE_MASK ((1ul << 28) - 1) 21/*
22 * Define parameters for the standard MIPS and the microMIPS jump
23 * instruction encoding respectively:
24 *
25 * - the ISA bit of the target, either 0 or 1 respectively,
26 *
27 * - the amount the jump target address is shifted right to fit in the
28 * immediate field of the machine instruction, either 2 or 1,
29 *
30 * - the mask determining the size of the jump region relative to the
31 * delay-slot instruction, either 256MB or 128MB,
32 *
33 * - the jump target alignment, either 4 or 2 bytes.
34 */
35#define J_ISA_BIT IS_ENABLED(CONFIG_CPU_MICROMIPS)
36#define J_RANGE_SHIFT (2 - J_ISA_BIT)
37#define J_RANGE_MASK ((1ul << (26 + J_RANGE_SHIFT)) - 1)
38#define J_ALIGN_MASK ((1ul << J_RANGE_SHIFT) - 1)
22 39
23void arch_jump_label_transform(struct jump_entry *e, 40void arch_jump_label_transform(struct jump_entry *e,
24 enum jump_label_type type) 41 enum jump_label_type type)
25{ 42{
43 union mips_instruction *insn_p;
26 union mips_instruction insn; 44 union mips_instruction insn;
27 union mips_instruction *insn_p =
28 (union mips_instruction *)(unsigned long)e->code;
29 45
30 /* Jump only works within a 256MB aligned region. */ 46 insn_p = (union mips_instruction *)msk_isa16_mode(e->code);
31 BUG_ON((e->target & ~J_RANGE_MASK) != (e->code & ~J_RANGE_MASK)); 47
48 /* Jump only works within an aligned region its delay slot is in. */
49 BUG_ON((e->target & ~J_RANGE_MASK) != ((e->code + 4) & ~J_RANGE_MASK));
32 50
33 /* Target must have 4 byte alignment. */ 51 /* Target must have the right alignment and ISA must be preserved. */
34 BUG_ON((e->target & 3) != 0); 52 BUG_ON((e->target & J_ALIGN_MASK) != J_ISA_BIT);
35 53
36 if (type == JUMP_LABEL_ENABLE) { 54 if (type == JUMP_LABEL_ENABLE) {
37 insn.j_format.opcode = j_op; 55 insn.j_format.opcode = J_ISA_BIT ? mm_j32_op : j_op;
38 insn.j_format.target = (e->target & J_RANGE_MASK) >> 2; 56 insn.j_format.target = e->target >> J_RANGE_SHIFT;
39 } else { 57 } else {
40 insn.word = 0; /* nop */ 58 insn.word = 0; /* nop */
41 } 59 }
42 60
43 get_online_cpus(); 61 get_online_cpus();
44 mutex_lock(&text_mutex); 62 mutex_lock(&text_mutex);
45 *insn_p = insn; 63 if (IS_ENABLED(CONFIG_CPU_MICROMIPS)) {
64 insn_p->halfword[0] = insn.word >> 16;
65 insn_p->halfword[1] = insn.word;
66 } else
67 *insn_p = insn;
46 68
47 flush_icache_range((unsigned long)insn_p, 69 flush_icache_range((unsigned long)insn_p,
48 (unsigned long)insn_p + sizeof(*insn_p)); 70 (unsigned long)insn_p + sizeof(*insn_p));
diff --git a/arch/mips/kernel/r2300_fpu.S b/arch/mips/kernel/r2300_fpu.S
index f31063dbdaeb..5ce3b746cedc 100644
--- a/arch/mips/kernel/r2300_fpu.S
+++ b/arch/mips/kernel/r2300_fpu.S
@@ -28,6 +28,8 @@
28 .set mips1 28 .set mips1
29 /* Save floating point context */ 29 /* Save floating point context */
30LEAF(_save_fp_context) 30LEAF(_save_fp_context)
31 .set push
32 SET_HARDFLOAT
31 li v0, 0 # assume success 33 li v0, 0 # assume success
32 cfc1 t1,fcr31 34 cfc1 t1,fcr31
33 EX(swc1 $f0,(SC_FPREGS+0)(a0)) 35 EX(swc1 $f0,(SC_FPREGS+0)(a0))
@@ -65,6 +67,7 @@ LEAF(_save_fp_context)
65 EX(sw t1,(SC_FPC_CSR)(a0)) 67 EX(sw t1,(SC_FPC_CSR)(a0))
66 cfc1 t0,$0 # implementation/version 68 cfc1 t0,$0 # implementation/version
67 jr ra 69 jr ra
70 .set pop
68 .set nomacro 71 .set nomacro
69 EX(sw t0,(SC_FPC_EIR)(a0)) 72 EX(sw t0,(SC_FPC_EIR)(a0))
70 .set macro 73 .set macro
@@ -80,6 +83,8 @@ LEAF(_save_fp_context)
80 * stack frame which might have been changed by the user. 83 * stack frame which might have been changed by the user.
81 */ 84 */
82LEAF(_restore_fp_context) 85LEAF(_restore_fp_context)
86 .set push
87 SET_HARDFLOAT
83 li v0, 0 # assume success 88 li v0, 0 # assume success
84 EX(lw t0,(SC_FPC_CSR)(a0)) 89 EX(lw t0,(SC_FPC_CSR)(a0))
85 EX(lwc1 $f0,(SC_FPREGS+0)(a0)) 90 EX(lwc1 $f0,(SC_FPREGS+0)(a0))
@@ -116,6 +121,7 @@ LEAF(_restore_fp_context)
116 EX(lwc1 $f31,(SC_FPREGS+248)(a0)) 121 EX(lwc1 $f31,(SC_FPREGS+248)(a0))
117 jr ra 122 jr ra
118 ctc1 t0,fcr31 123 ctc1 t0,fcr31
124 .set pop
119 END(_restore_fp_context) 125 END(_restore_fp_context)
120 .set reorder 126 .set reorder
121 127
diff --git a/arch/mips/kernel/r2300_switch.S b/arch/mips/kernel/r2300_switch.S
index 20b7b040e76f..435ea652f5fa 100644
--- a/arch/mips/kernel/r2300_switch.S
+++ b/arch/mips/kernel/r2300_switch.S
@@ -120,6 +120,9 @@ LEAF(_restore_fp)
120 120
121#define FPU_DEFAULT 0x00000000 121#define FPU_DEFAULT 0x00000000
122 122
123 .set push
124 SET_HARDFLOAT
125
123LEAF(_init_fpu) 126LEAF(_init_fpu)
124 mfc0 t0, CP0_STATUS 127 mfc0 t0, CP0_STATUS
125 li t1, ST0_CU1 128 li t1, ST0_CU1
@@ -165,3 +168,5 @@ LEAF(_init_fpu)
165 mtc1 t0, $f31 168 mtc1 t0, $f31
166 jr ra 169 jr ra
167 END(_init_fpu) 170 END(_init_fpu)
171
172 .set pop
diff --git a/arch/mips/kernel/r4k_fpu.S b/arch/mips/kernel/r4k_fpu.S
index 8352523568e6..6c160c67984c 100644
--- a/arch/mips/kernel/r4k_fpu.S
+++ b/arch/mips/kernel/r4k_fpu.S
@@ -19,8 +19,12 @@
19#include <asm/asm-offsets.h> 19#include <asm/asm-offsets.h>
20#include <asm/regdef.h> 20#include <asm/regdef.h>
21 21
22/* preprocessor replaces the fp in ".set fp=64" with $30 otherwise */
23#undef fp
24
22 .macro EX insn, reg, src 25 .macro EX insn, reg, src
23 .set push 26 .set push
27 SET_HARDFLOAT
24 .set nomacro 28 .set nomacro
25.ex\@: \insn \reg, \src 29.ex\@: \insn \reg, \src
26 .set pop 30 .set pop
@@ -33,12 +37,17 @@
33 .set arch=r4000 37 .set arch=r4000
34 38
35LEAF(_save_fp_context) 39LEAF(_save_fp_context)
40 .set push
41 SET_HARDFLOAT
36 cfc1 t1, fcr31 42 cfc1 t1, fcr31
43 .set pop
37 44
38#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2) 45#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
39 .set push 46 .set push
47 SET_HARDFLOAT
40#ifdef CONFIG_CPU_MIPS32_R2 48#ifdef CONFIG_CPU_MIPS32_R2
41 .set mips64r2 49 .set mips32r2
50 .set fp=64
42 mfc0 t0, CP0_STATUS 51 mfc0 t0, CP0_STATUS
43 sll t0, t0, 5 52 sll t0, t0, 5
44 bgez t0, 1f # skip storing odd if FR=0 53 bgez t0, 1f # skip storing odd if FR=0
@@ -64,6 +73,8 @@ LEAF(_save_fp_context)
641: .set pop 731: .set pop
65#endif 74#endif
66 75
76 .set push
77 SET_HARDFLOAT
67 /* Store the 16 even double precision registers */ 78 /* Store the 16 even double precision registers */
68 EX sdc1 $f0, SC_FPREGS+0(a0) 79 EX sdc1 $f0, SC_FPREGS+0(a0)
69 EX sdc1 $f2, SC_FPREGS+16(a0) 80 EX sdc1 $f2, SC_FPREGS+16(a0)
@@ -84,11 +95,14 @@ LEAF(_save_fp_context)
84 EX sw t1, SC_FPC_CSR(a0) 95 EX sw t1, SC_FPC_CSR(a0)
85 jr ra 96 jr ra
86 li v0, 0 # success 97 li v0, 0 # success
98 .set pop
87 END(_save_fp_context) 99 END(_save_fp_context)
88 100
89#ifdef CONFIG_MIPS32_COMPAT 101#ifdef CONFIG_MIPS32_COMPAT
90 /* Save 32-bit process floating point context */ 102 /* Save 32-bit process floating point context */
91LEAF(_save_fp_context32) 103LEAF(_save_fp_context32)
104 .set push
105 SET_HARDFLOAT
92 cfc1 t1, fcr31 106 cfc1 t1, fcr31
93 107
94 mfc0 t0, CP0_STATUS 108 mfc0 t0, CP0_STATUS
@@ -134,6 +148,7 @@ LEAF(_save_fp_context32)
134 EX sw t1, SC32_FPC_CSR(a0) 148 EX sw t1, SC32_FPC_CSR(a0)
135 cfc1 t0, $0 # implementation/version 149 cfc1 t0, $0 # implementation/version
136 EX sw t0, SC32_FPC_EIR(a0) 150 EX sw t0, SC32_FPC_EIR(a0)
151 .set pop
137 152
138 jr ra 153 jr ra
139 li v0, 0 # success 154 li v0, 0 # success
@@ -150,8 +165,10 @@ LEAF(_restore_fp_context)
150 165
151#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2) 166#if defined(CONFIG_64BIT) || defined(CONFIG_CPU_MIPS32_R2)
152 .set push 167 .set push
168 SET_HARDFLOAT
153#ifdef CONFIG_CPU_MIPS32_R2 169#ifdef CONFIG_CPU_MIPS32_R2
154 .set mips64r2 170 .set mips32r2
171 .set fp=64
155 mfc0 t0, CP0_STATUS 172 mfc0 t0, CP0_STATUS
156 sll t0, t0, 5 173 sll t0, t0, 5
157 bgez t0, 1f # skip loading odd if FR=0 174 bgez t0, 1f # skip loading odd if FR=0
@@ -175,6 +192,8 @@ LEAF(_restore_fp_context)
175 EX ldc1 $f31, SC_FPREGS+248(a0) 192 EX ldc1 $f31, SC_FPREGS+248(a0)
1761: .set pop 1931: .set pop
177#endif 194#endif
195 .set push
196 SET_HARDFLOAT
178 EX ldc1 $f0, SC_FPREGS+0(a0) 197 EX ldc1 $f0, SC_FPREGS+0(a0)
179 EX ldc1 $f2, SC_FPREGS+16(a0) 198 EX ldc1 $f2, SC_FPREGS+16(a0)
180 EX ldc1 $f4, SC_FPREGS+32(a0) 199 EX ldc1 $f4, SC_FPREGS+32(a0)
@@ -192,6 +211,7 @@ LEAF(_restore_fp_context)
192 EX ldc1 $f28, SC_FPREGS+224(a0) 211 EX ldc1 $f28, SC_FPREGS+224(a0)
193 EX ldc1 $f30, SC_FPREGS+240(a0) 212 EX ldc1 $f30, SC_FPREGS+240(a0)
194 ctc1 t1, fcr31 213 ctc1 t1, fcr31
214 .set pop
195 jr ra 215 jr ra
196 li v0, 0 # success 216 li v0, 0 # success
197 END(_restore_fp_context) 217 END(_restore_fp_context)
@@ -199,6 +219,8 @@ LEAF(_restore_fp_context)
199#ifdef CONFIG_MIPS32_COMPAT 219#ifdef CONFIG_MIPS32_COMPAT
200LEAF(_restore_fp_context32) 220LEAF(_restore_fp_context32)
201 /* Restore an o32 sigcontext. */ 221 /* Restore an o32 sigcontext. */
222 .set push
223 SET_HARDFLOAT
202 EX lw t1, SC32_FPC_CSR(a0) 224 EX lw t1, SC32_FPC_CSR(a0)
203 225
204 mfc0 t0, CP0_STATUS 226 mfc0 t0, CP0_STATUS
@@ -242,6 +264,7 @@ LEAF(_restore_fp_context32)
242 ctc1 t1, fcr31 264 ctc1 t1, fcr31
243 jr ra 265 jr ra
244 li v0, 0 # success 266 li v0, 0 # success
267 .set pop
245 END(_restore_fp_context32) 268 END(_restore_fp_context32)
246#endif 269#endif
247 270
diff --git a/arch/mips/kernel/r4k_switch.S b/arch/mips/kernel/r4k_switch.S
index 4c4ec1812420..64591e671878 100644
--- a/arch/mips/kernel/r4k_switch.S
+++ b/arch/mips/kernel/r4k_switch.S
@@ -22,6 +22,9 @@
22 22
23#include <asm/asmmacro.h> 23#include <asm/asmmacro.h>
24 24
25/* preprocessor replaces the fp in ".set fp=64" with $30 otherwise */
26#undef fp
27
25/* 28/*
26 * Offset to the current process status flags, the first 32 bytes of the 29 * Offset to the current process status flags, the first 32 bytes of the
27 * stack are not used. 30 * stack are not used.
@@ -65,8 +68,12 @@
65 bgtz a3, 1f 68 bgtz a3, 1f
66 69
67 /* Save 128b MSA vector context + scalar FP control & status. */ 70 /* Save 128b MSA vector context + scalar FP control & status. */
71 .set push
72 SET_HARDFLOAT
68 cfc1 t1, fcr31 73 cfc1 t1, fcr31
69 msa_save_all a0 74 msa_save_all a0
75 .set pop /* SET_HARDFLOAT */
76
70 sw t1, THREAD_FCR31(a0) 77 sw t1, THREAD_FCR31(a0)
71 b 2f 78 b 2f
72 79
@@ -161,6 +168,9 @@ LEAF(_init_msa_upper)
161 168
162#define FPU_DEFAULT 0x00000000 169#define FPU_DEFAULT 0x00000000
163 170
171 .set push
172 SET_HARDFLOAT
173
164LEAF(_init_fpu) 174LEAF(_init_fpu)
165 mfc0 t0, CP0_STATUS 175 mfc0 t0, CP0_STATUS
166 li t1, ST0_CU1 176 li t1, ST0_CU1
@@ -232,7 +242,8 @@ LEAF(_init_fpu)
232 242
233#ifdef CONFIG_CPU_MIPS32_R2 243#ifdef CONFIG_CPU_MIPS32_R2
234 .set push 244 .set push
235 .set mips64r2 245 .set mips32r2
246 .set fp=64
236 sll t0, t0, 5 # is Status.FR set? 247 sll t0, t0, 5 # is Status.FR set?
237 bgez t0, 1f # no: skip setting upper 32b 248 bgez t0, 1f # no: skip setting upper 32b
238 249
@@ -291,3 +302,5 @@ LEAF(_init_fpu)
291#endif 302#endif
292 jr ra 303 jr ra
293 END(_init_fpu) 304 END(_init_fpu)
305
306 .set pop /* SET_HARDFLOAT */
diff --git a/arch/mips/kernel/r6000_fpu.S b/arch/mips/kernel/r6000_fpu.S
index da0fbe46d83b..47077380c15c 100644
--- a/arch/mips/kernel/r6000_fpu.S
+++ b/arch/mips/kernel/r6000_fpu.S
@@ -18,6 +18,9 @@
18 18
19 .set noreorder 19 .set noreorder
20 .set mips2 20 .set mips2
21 .set push
22 SET_HARDFLOAT
23
21 /* Save floating point context */ 24 /* Save floating point context */
22 LEAF(_save_fp_context) 25 LEAF(_save_fp_context)
23 mfc0 t0,CP0_STATUS 26 mfc0 t0,CP0_STATUS
@@ -85,3 +88,5 @@
851: jr ra 881: jr ra
86 nop 89 nop
87 END(_restore_fp_context) 90 END(_restore_fp_context)
91
92 .set pop /* SET_HARDFLOAT */
diff --git a/arch/mips/kernel/rtlx.c b/arch/mips/kernel/rtlx.c
index 31b1b763cb29..c5c4fd54d797 100644
--- a/arch/mips/kernel/rtlx.c
+++ b/arch/mips/kernel/rtlx.c
@@ -94,12 +94,12 @@ int rtlx_open(int index, int can_sleep)
94 int ret = 0; 94 int ret = 0;
95 95
96 if (index >= RTLX_CHANNELS) { 96 if (index >= RTLX_CHANNELS) {
97 pr_debug(KERN_DEBUG "rtlx_open index out of range\n"); 97 pr_debug("rtlx_open index out of range\n");
98 return -ENOSYS; 98 return -ENOSYS;
99 } 99 }
100 100
101 if (atomic_inc_return(&channel_wqs[index].in_open) > 1) { 101 if (atomic_inc_return(&channel_wqs[index].in_open) > 1) {
102 pr_debug(KERN_DEBUG "rtlx_open channel %d already opened\n", index); 102 pr_debug("rtlx_open channel %d already opened\n", index);
103 ret = -EBUSY; 103 ret = -EBUSY;
104 goto out_fail; 104 goto out_fail;
105 } 105 }
diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
index 744cd10ba599..00cad1005a16 100644
--- a/arch/mips/kernel/scall32-o32.S
+++ b/arch/mips/kernel/scall32-o32.S
@@ -579,3 +579,4 @@ EXPORT(sys_call_table)
579 PTR sys_seccomp 579 PTR sys_seccomp
580 PTR sys_getrandom 580 PTR sys_getrandom
581 PTR sys_memfd_create 581 PTR sys_memfd_create
582 PTR sys_bpf /* 4355 */
diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
index 002b1bc09c38..5251565e344b 100644
--- a/arch/mips/kernel/scall64-64.S
+++ b/arch/mips/kernel/scall64-64.S
@@ -434,4 +434,5 @@ EXPORT(sys_call_table)
434 PTR sys_seccomp 434 PTR sys_seccomp
435 PTR sys_getrandom 435 PTR sys_getrandom
436 PTR sys_memfd_create 436 PTR sys_memfd_create
437 PTR sys_bpf /* 5315 */
437 .size sys_call_table,.-sys_call_table 438 .size sys_call_table,.-sys_call_table
diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
index ca6cbbe9805b..77e74398b828 100644
--- a/arch/mips/kernel/scall64-n32.S
+++ b/arch/mips/kernel/scall64-n32.S
@@ -427,4 +427,5 @@ EXPORT(sysn32_call_table)
427 PTR sys_seccomp 427 PTR sys_seccomp
428 PTR sys_getrandom 428 PTR sys_getrandom
429 PTR sys_memfd_create 429 PTR sys_memfd_create
430 PTR sys_bpf
430 .size sysn32_call_table,.-sysn32_call_table 431 .size sysn32_call_table,.-sysn32_call_table
diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
index 9e10d11fbb84..6f8db9f728e8 100644
--- a/arch/mips/kernel/scall64-o32.S
+++ b/arch/mips/kernel/scall64-o32.S
@@ -564,4 +564,5 @@ EXPORT(sys32_call_table)
564 PTR sys_seccomp 564 PTR sys_seccomp
565 PTR sys_getrandom 565 PTR sys_getrandom
566 PTR sys_memfd_create 566 PTR sys_memfd_create
567 PTR sys_bpf /* 4355 */
567 .size sys32_call_table,.-sys32_call_table 568 .size sys32_call_table,.-sys32_call_table
diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c
index b3b8f0d9d4a7..f3b635f86c39 100644
--- a/arch/mips/kernel/setup.c
+++ b/arch/mips/kernel/setup.c
@@ -485,7 +485,7 @@ static void __init bootmem_init(void)
485 * NOTE: historically plat_mem_setup did the entire platform initialization. 485 * NOTE: historically plat_mem_setup did the entire platform initialization.
486 * This was rather impractical because it meant plat_mem_setup had to 486 * This was rather impractical because it meant plat_mem_setup had to
487 * get away without any kind of memory allocator. To keep old code from 487 * get away without any kind of memory allocator. To keep old code from
488 * breaking plat_setup was just renamed to plat_setup and a second platform 488 * breaking plat_setup was just renamed to plat_mem_setup and a second platform
489 * initialization hook for anything else was introduced. 489 * initialization hook for anything else was introduced.
490 */ 490 */
491 491
@@ -493,7 +493,7 @@ static int usermem __initdata;
493 493
494static int __init early_parse_mem(char *p) 494static int __init early_parse_mem(char *p)
495{ 495{
496 unsigned long start, size; 496 phys_t start, size;
497 497
498 /* 498 /*
499 * If a user specifies memory size, we 499 * If a user specifies memory size, we
@@ -683,7 +683,8 @@ static void __init arch_mem_init(char **cmdline_p)
683 dma_contiguous_reserve(PFN_PHYS(max_low_pfn)); 683 dma_contiguous_reserve(PFN_PHYS(max_low_pfn));
684 /* Tell bootmem about cma reserved memblock section */ 684 /* Tell bootmem about cma reserved memblock section */
685 for_each_memblock(reserved, reg) 685 for_each_memblock(reserved, reg)
686 reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT); 686 if (reg->size != 0)
687 reserve_bootmem(reg->base, reg->size, BOOTMEM_DEFAULT);
687} 688}
688 689
689static void __init resource_init(void) 690static void __init resource_init(void)
diff --git a/arch/mips/kernel/signal.c b/arch/mips/kernel/signal.c
index 1d57605e4615..16f1e4f2bf3c 100644
--- a/arch/mips/kernel/signal.c
+++ b/arch/mips/kernel/signal.c
@@ -658,13 +658,13 @@ static int signal_setup(void)
658 save_fp_context = _save_fp_context; 658 save_fp_context = _save_fp_context;
659 restore_fp_context = _restore_fp_context; 659 restore_fp_context = _restore_fp_context;
660 } else { 660 } else {
661 save_fp_context = copy_fp_from_sigcontext; 661 save_fp_context = copy_fp_to_sigcontext;
662 restore_fp_context = copy_fp_to_sigcontext; 662 restore_fp_context = copy_fp_from_sigcontext;
663 } 663 }
664#endif /* CONFIG_SMP */ 664#endif /* CONFIG_SMP */
665#else 665#else
666 save_fp_context = copy_fp_from_sigcontext;; 666 save_fp_context = copy_fp_to_sigcontext;
667 restore_fp_context = copy_fp_to_sigcontext; 667 restore_fp_context = copy_fp_from_sigcontext;
668#endif 668#endif
669 669
670 return 0; 670 return 0;
diff --git a/arch/mips/lib/memcpy.S b/arch/mips/lib/memcpy.S
index c17ef80cf65a..5d3238af9b5c 100644
--- a/arch/mips/lib/memcpy.S
+++ b/arch/mips/lib/memcpy.S
@@ -503,6 +503,7 @@
503 STOREB(t0, NBYTES-2(dst), .Ls_exc_p1\@) 503 STOREB(t0, NBYTES-2(dst), .Ls_exc_p1\@)
504.Ldone\@: 504.Ldone\@:
505 jr ra 505 jr ra
506 nop
506 .if __memcpy == 1 507 .if __memcpy == 1
507 END(memcpy) 508 END(memcpy)
508 .set __memcpy, 0 509 .set __memcpy, 0
diff --git a/arch/mips/lib/r3k_dump_tlb.c b/arch/mips/lib/r3k_dump_tlb.c
index 91615c2ef0cf..1ef365ab3cd3 100644
--- a/arch/mips/lib/r3k_dump_tlb.c
+++ b/arch/mips/lib/r3k_dump_tlb.c
@@ -34,7 +34,7 @@ static void dump_tlb(int first, int last)
34 entrylo0 = read_c0_entrylo0(); 34 entrylo0 = read_c0_entrylo0();
35 35
36 /* Unused entries have a virtual address of KSEG0. */ 36 /* Unused entries have a virtual address of KSEG0. */
37 if ((entryhi & 0xffffe000) != 0x80000000 37 if ((entryhi & 0xfffff000) != 0x80000000
38 && (entryhi & 0xfc0) == asid) { 38 && (entryhi & 0xfc0) == asid) {
39 /* 39 /*
40 * Only print entries in use 40 * Only print entries in use
@@ -43,7 +43,7 @@ static void dump_tlb(int first, int last)
43 43
44 printk("va=%08lx asid=%08lx" 44 printk("va=%08lx asid=%08lx"
45 " [pa=%06lx n=%d d=%d v=%d g=%d]", 45 " [pa=%06lx n=%d d=%d v=%d g=%d]",
46 (entryhi & 0xffffe000), 46 (entryhi & 0xfffff000),
47 entryhi & 0xfc0, 47 entryhi & 0xfc0,
48 entrylo0 & PAGE_MASK, 48 entrylo0 & PAGE_MASK,
49 (entrylo0 & (1 << 11)) ? 1 : 0, 49 (entrylo0 & (1 << 11)) ? 1 : 0,
diff --git a/arch/mips/lib/strnlen_user.S b/arch/mips/lib/strnlen_user.S
index f3af6995e2a6..7d12c0dded3d 100644
--- a/arch/mips/lib/strnlen_user.S
+++ b/arch/mips/lib/strnlen_user.S
@@ -40,9 +40,11 @@ FEXPORT(__strnlen_\func\()_nocheck_asm)
40.else 40.else
41 EX(lbe, t0, (v0), .Lfault\@) 41 EX(lbe, t0, (v0), .Lfault\@)
42.endif 42.endif
43 PTR_ADDIU v0, 1 43 .set noreorder
44 bnez t0, 1b 44 bnez t0, 1b
451: PTR_SUBU v0, a0 451: PTR_ADDIU v0, 1
46 .set reorder
47 PTR_SUBU v0, a0
46 jr ra 48 jr ra
47 END(__strnlen_\func\()_asm) 49 END(__strnlen_\func\()_asm)
48 50
diff --git a/arch/mips/loongson/common/Makefile b/arch/mips/loongson/common/Makefile
index 0bb9cc9dc621..d87e03330b29 100644
--- a/arch/mips/loongson/common/Makefile
+++ b/arch/mips/loongson/common/Makefile
@@ -11,7 +11,8 @@ obj-$(CONFIG_PCI) += pci.o
11# Serial port support 11# Serial port support
12# 12#
13obj-$(CONFIG_EARLY_PRINTK) += early_printk.o 13obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
14obj-$(CONFIG_SERIAL_8250) += serial.o 14loongson-serial-$(CONFIG_SERIAL_8250) := serial.o
15obj-y += $(loongson-serial-m) $(loongson-serial-y)
15obj-$(CONFIG_LOONGSON_UART_BASE) += uart_base.o 16obj-$(CONFIG_LOONGSON_UART_BASE) += uart_base.o
16obj-$(CONFIG_LOONGSON_MC146818) += rtc.o 17obj-$(CONFIG_LOONGSON_MC146818) += rtc.o
17 18
diff --git a/arch/mips/loongson/loongson-3/numa.c b/arch/mips/loongson/loongson-3/numa.c
index 37ed184398c6..42323bcc5d28 100644
--- a/arch/mips/loongson/loongson-3/numa.c
+++ b/arch/mips/loongson/loongson-3/numa.c
@@ -33,6 +33,7 @@
33 33
34static struct node_data prealloc__node_data[MAX_NUMNODES]; 34static struct node_data prealloc__node_data[MAX_NUMNODES];
35unsigned char __node_distances[MAX_NUMNODES][MAX_NUMNODES]; 35unsigned char __node_distances[MAX_NUMNODES][MAX_NUMNODES];
36EXPORT_SYMBOL(__node_distances);
36struct node_data *__node_data[MAX_NUMNODES]; 37struct node_data *__node_data[MAX_NUMNODES];
37EXPORT_SYMBOL(__node_data); 38EXPORT_SYMBOL(__node_data);
38 39
diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c
index 51a0fde4bec1..cac529a405b8 100644
--- a/arch/mips/math-emu/cp1emu.c
+++ b/arch/mips/math-emu/cp1emu.c
@@ -584,11 +584,7 @@ static int isBranchInstr(struct pt_regs *regs, struct mm_decoded_insn dec_insn,
584 if (insn.i_format.rs == bc_op) { 584 if (insn.i_format.rs == bc_op) {
585 preempt_disable(); 585 preempt_disable();
586 if (is_fpu_owner()) 586 if (is_fpu_owner())
587 asm volatile( 587 fcr31 = read_32bit_cp1_register(CP1_STATUS);
588 ".set push\n"
589 "\t.set mips1\n"
590 "\tcfc1\t%0,$31\n"
591 "\t.set pop" : "=r" (fcr31));
592 else 588 else
593 fcr31 = current->thread.fpu.fcr31; 589 fcr31 = current->thread.fpu.fcr31;
594 preempt_enable(); 590 preempt_enable();
diff --git a/arch/mips/mm/tlb-r4k.c b/arch/mips/mm/tlb-r4k.c
index fa6ebd4bc9e9..c3917e251f59 100644
--- a/arch/mips/mm/tlb-r4k.c
+++ b/arch/mips/mm/tlb-r4k.c
@@ -299,6 +299,7 @@ void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte)
299 299
300 local_irq_save(flags); 300 local_irq_save(flags);
301 301
302 htw_stop();
302 pid = read_c0_entryhi() & ASID_MASK; 303 pid = read_c0_entryhi() & ASID_MASK;
303 address &= (PAGE_MASK << 1); 304 address &= (PAGE_MASK << 1);
304 write_c0_entryhi(address | pid); 305 write_c0_entryhi(address | pid);
@@ -346,6 +347,7 @@ void __update_tlb(struct vm_area_struct * vma, unsigned long address, pte_t pte)
346 tlb_write_indexed(); 347 tlb_write_indexed();
347 } 348 }
348 tlbw_use_hazard(); 349 tlbw_use_hazard();
350 htw_start();
349 flush_itlb_vm(vma); 351 flush_itlb_vm(vma);
350 local_irq_restore(flags); 352 local_irq_restore(flags);
351} 353}
@@ -422,6 +424,7 @@ __init int add_temporary_entry(unsigned long entrylo0, unsigned long entrylo1,
422 424
423 local_irq_save(flags); 425 local_irq_save(flags);
424 /* Save old context and create impossible VPN2 value */ 426 /* Save old context and create impossible VPN2 value */
427 htw_stop();
425 old_ctx = read_c0_entryhi(); 428 old_ctx = read_c0_entryhi();
426 old_pagemask = read_c0_pagemask(); 429 old_pagemask = read_c0_pagemask();
427 wired = read_c0_wired(); 430 wired = read_c0_wired();
@@ -443,6 +446,7 @@ __init int add_temporary_entry(unsigned long entrylo0, unsigned long entrylo1,
443 446
444 write_c0_entryhi(old_ctx); 447 write_c0_entryhi(old_ctx);
445 write_c0_pagemask(old_pagemask); 448 write_c0_pagemask(old_pagemask);
449 htw_start();
446out: 450out:
447 local_irq_restore(flags); 451 local_irq_restore(flags);
448 return ret; 452 return ret;
diff --git a/arch/mips/mm/tlbex.c b/arch/mips/mm/tlbex.c
index b5f228e7eae6..e3328a96e809 100644
--- a/arch/mips/mm/tlbex.c
+++ b/arch/mips/mm/tlbex.c
@@ -1872,8 +1872,16 @@ build_r4000_tlbchange_handler_head(u32 **p, struct uasm_label **l,
1872 uasm_l_smp_pgtable_change(l, *p); 1872 uasm_l_smp_pgtable_change(l, *p);
1873#endif 1873#endif
1874 iPTE_LW(p, wr.r1, wr.r2); /* get even pte */ 1874 iPTE_LW(p, wr.r1, wr.r2); /* get even pte */
1875 if (!m4kc_tlbp_war()) 1875 if (!m4kc_tlbp_war()) {
1876 build_tlb_probe_entry(p); 1876 build_tlb_probe_entry(p);
1877 if (cpu_has_htw) {
1878 /* race condition happens, leaving */
1879 uasm_i_ehb(p);
1880 uasm_i_mfc0(p, wr.r3, C0_INDEX);
1881 uasm_il_bltz(p, r, wr.r3, label_leave);
1882 uasm_i_nop(p);
1883 }
1884 }
1877 return wr; 1885 return wr;
1878} 1886}
1879 1887
diff --git a/arch/mips/mti-sead3/sead3-leds.c b/arch/mips/mti-sead3/sead3-leds.c
index 20102a6d4141..c427c5778186 100644
--- a/arch/mips/mti-sead3/sead3-leds.c
+++ b/arch/mips/mti-sead3/sead3-leds.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. 6 * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
7 */ 7 */
8#include <linux/module.h> 8#include <linux/init.h>
9#include <linux/leds.h> 9#include <linux/leds.h>
10#include <linux/platform_device.h> 10#include <linux/platform_device.h>
11 11
@@ -76,8 +76,4 @@ static int __init led_init(void)
76 return platform_device_register(&fled_device); 76 return platform_device_register(&fled_device);
77} 77}
78 78
79module_init(led_init); 79device_initcall(led_init);
80
81MODULE_AUTHOR("Chris Dearman <chris@mips.com>");
82MODULE_LICENSE("GPL");
83MODULE_DESCRIPTION("LED probe driver for SEAD-3");
diff --git a/arch/mips/netlogic/xlp/Makefile b/arch/mips/netlogic/xlp/Makefile
index be358a8050c5..6b43af0a34d9 100644
--- a/arch/mips/netlogic/xlp/Makefile
+++ b/arch/mips/netlogic/xlp/Makefile
@@ -1,6 +1,10 @@
1obj-y += setup.o nlm_hal.o cop2-ex.o dt.o 1obj-y += setup.o nlm_hal.o cop2-ex.o dt.o
2obj-$(CONFIG_SMP) += wakeup.o 2obj-$(CONFIG_SMP) += wakeup.o
3obj-$(CONFIG_USB) += usb-init.o 3ifdef CONFIG_USB
4obj-$(CONFIG_USB) += usb-init-xlp2.o 4obj-y += usb-init.o
5obj-$(CONFIG_SATA_AHCI) += ahci-init.o 5obj-y += usb-init-xlp2.o
6obj-$(CONFIG_SATA_AHCI) += ahci-init-xlp2.o 6endif
7ifdef CONFIG_SATA_AHCI
8obj-y += ahci-init.o
9obj-y += ahci-init-xlp2.o
10endif
diff --git a/arch/mips/oprofile/backtrace.c b/arch/mips/oprofile/backtrace.c
index 6854ed5097d2..83a1dfd8f0e3 100644
--- a/arch/mips/oprofile/backtrace.c
+++ b/arch/mips/oprofile/backtrace.c
@@ -92,7 +92,7 @@ static inline int unwind_user_frame(struct stackframe *old_frame,
92 /* This marks the end of the previous function, 92 /* This marks the end of the previous function,
93 which means we overran. */ 93 which means we overran. */
94 break; 94 break;
95 stack_size = (unsigned) stack_adjustment; 95 stack_size = (unsigned long) stack_adjustment;
96 } else if (is_ra_save_ins(&ip)) { 96 } else if (is_ra_save_ins(&ip)) {
97 int ra_slot = ip.i_format.simmediate; 97 int ra_slot = ip.i_format.simmediate;
98 if (ra_slot < 0) 98 if (ra_slot < 0)
diff --git a/arch/mips/pci/msi-xlp.c b/arch/mips/pci/msi-xlp.c
index fa374fe3746b..f7ac3edda1b2 100644
--- a/arch/mips/pci/msi-xlp.c
+++ b/arch/mips/pci/msi-xlp.c
@@ -443,10 +443,8 @@ static int xlp_setup_msix(uint64_t lnkbase, int node, int link,
443 msg.data = 0xc00 | msixvec; 443 msg.data = 0xc00 | msixvec;
444 444
445 ret = irq_set_msi_desc(xirq, desc); 445 ret = irq_set_msi_desc(xirq, desc);
446 if (ret < 0) { 446 if (ret < 0)
447 destroy_irq(xirq);
448 return ret; 447 return ret;
449 }
450 448
451 write_msi_msg(xirq, &msg); 449 write_msi_msg(xirq, &msg);
452 return 0; 450 return 0;
diff --git a/arch/mips/sgi-ip27/ip27-memory.c b/arch/mips/sgi-ip27/ip27-memory.c
index a95c00f5fb96..a304bcc37e4f 100644
--- a/arch/mips/sgi-ip27/ip27-memory.c
+++ b/arch/mips/sgi-ip27/ip27-memory.c
@@ -107,6 +107,7 @@ static void router_recurse(klrou_t *router_a, klrou_t *router_b, int depth)
107} 107}
108 108
109unsigned char __node_distances[MAX_COMPACT_NODES][MAX_COMPACT_NODES]; 109unsigned char __node_distances[MAX_COMPACT_NODES][MAX_COMPACT_NODES];
110EXPORT_SYMBOL(__node_distances);
110 111
111static int __init compute_node_distance(nasid_t nasid_a, nasid_t nasid_b) 112static int __init compute_node_distance(nasid_t nasid_a, nasid_t nasid_b)
112{ 113{
diff --git a/arch/nios2/Kconfig b/arch/nios2/Kconfig
new file mode 100644
index 000000000000..2361acf6d2b1
--- /dev/null
+++ b/arch/nios2/Kconfig
@@ -0,0 +1,206 @@
1config NIOS2
2 def_bool y
3 select ARCH_WANT_OPTIONAL_GPIOLIB
4 select CLKSRC_OF
5 select GENERIC_ATOMIC64
6 select GENERIC_CLOCKEVENTS
7 select GENERIC_CPU_DEVICES
8 select GENERIC_IRQ_PROBE
9 select GENERIC_IRQ_SHOW
10 select HAVE_ARCH_TRACEHOOK
11 select IRQ_DOMAIN
12 select MODULES_USE_ELF_RELA
13 select OF
14 select OF_EARLY_FLATTREE
15 select SOC_BUS
16 select SPARSE_IRQ
17 select USB_ARCH_HAS_HCD if USB_SUPPORT
18
19config GENERIC_CSUM
20 def_bool y
21
22config GENERIC_HWEIGHT
23 def_bool y
24
25config GENERIC_CALIBRATE_DELAY
26 def_bool y
27
28config NO_IOPORT_MAP
29 def_bool y
30
31config HAS_DMA
32 def_bool y
33
34config FPU
35 def_bool n
36
37config SWAP
38 def_bool n
39
40config RWSEM_GENERIC_SPINLOCK
41 def_bool y
42
43config TRACE_IRQFLAGS_SUPPORT
44 def_bool n
45
46source "init/Kconfig"
47
48menu "Kernel features"
49
50source "kernel/Kconfig.preempt"
51
52source "kernel/Kconfig.freezer"
53
54source "kernel/Kconfig.hz"
55
56source "mm/Kconfig"
57
58config FORCE_MAX_ZONEORDER
59 int "Maximum zone order"
60 range 9 20
61 default "11"
62 help
63 The kernel memory allocator divides physically contiguous memory
64 blocks into "zones", where each zone is a power of two number of
65 pages. This option selects the largest power of two that the kernel
66 keeps in the memory allocator. If you need to allocate very large
67 blocks of physically contiguous memory, then you may need to
68 increase this value.
69
70 This config option is actually maximum order plus one. For example,
71 a value of 11 means that the largest free memory block is 2^10 pages.
72
73endmenu
74
75source "arch/nios2/platform/Kconfig.platform"
76
77menu "Processor type and features"
78
79config MMU
80 def_bool y
81
82config NR_CPUS
83 int
84 default "1"
85
86config NIOS2_ALIGNMENT_TRAP
87 bool "Catch alignment trap"
88 default y
89 help
90 Nios II CPUs cannot fetch/store data which is not bus aligned,
91 i.e., a 2 or 4 byte fetch must start at an address divisible by
92 2 or 4. Any non-aligned load/store instructions will be trapped and
93 emulated in software if you say Y here, which has a performance
94 impact.
95
96comment "Boot options"
97
98config CMDLINE_BOOL
99 bool "Default bootloader kernel arguments"
100 default y
101
102config CMDLINE
103 string "Default kernel command string"
104 default ""
105 depends on CMDLINE_BOOL
106 help
107 On some platforms, there is currently no way for the boot loader to
108 pass arguments to the kernel. For these platforms, you can supply
109 some command-line options at build time by entering them here. In
110 other cases you can specify kernel args so that you don't have
111 to set them up in board prom initialization routines.
112
113config CMDLINE_FORCE
114 bool "Force default kernel command string"
115 depends on CMDLINE_BOOL
116 help
117 Set this to have arguments from the default kernel command string
118 override those passed by the boot loader.
119
120config NIOS2_CMDLINE_IGNORE_DTB
121 bool "Ignore kernel command string from DTB"
122 depends on CMDLINE_BOOL
123 depends on !CMDLINE_FORCE
124 default y
125 help
126 Set this to ignore the bootargs property from the devicetree's
127 chosen node and fall back to CMDLINE if nothing is passed.
128
129config NIOS2_PASS_CMDLINE
130 bool "Passed kernel command line from u-boot"
131 default n
132 help
133 Use bootargs env variable from u-boot for kernel command line.
134 will override "Default kernel command string".
135 Say N if you are unsure.
136
137endmenu
138
139menu "Advanced setup"
140
141config ADVANCED_OPTIONS
142 bool "Prompt for advanced kernel configuration options"
143 help
144
145comment "Default settings for advanced configuration options are used"
146 depends on !ADVANCED_OPTIONS
147
148config NIOS2_KERNEL_MMU_REGION_BASE_BOOL
149 bool "Set custom kernel MMU region base address"
150 depends on ADVANCED_OPTIONS
151 help
152 This option allows you to set the virtual address of the kernel MMU region.
153
154 Say N here unless you know what you are doing.
155
156config NIOS2_KERNEL_MMU_REGION_BASE
157 hex "Virtual base address of the kernel MMU region " if NIOS2_KERNEL_MMU_REGION_BASE_BOOL
158 default "0x80000000"
159 help
160 This option allows you to set the virtual base address of the kernel MMU region.
161
162config NIOS2_KERNEL_REGION_BASE_BOOL
163 bool "Set custom kernel region base address"
164 depends on ADVANCED_OPTIONS
165 help
166 This option allows you to set the virtual address of the kernel region.
167
168 Say N here unless you know what you are doing.
169
170config NIOS2_KERNEL_REGION_BASE
171 hex "Virtual base address of the kernel region " if NIOS2_KERNEL_REGION_BASE_BOOL
172 default "0xc0000000"
173
174config NIOS2_IO_REGION_BASE_BOOL
175 bool "Set custom I/O region base address"
176 depends on ADVANCED_OPTIONS
177 help
178 This option allows you to set the virtual address of the I/O region.
179
180 Say N here unless you know what you are doing.
181
182config NIOS2_IO_REGION_BASE
183 hex "Virtual base address of the I/O region" if NIOS2_IO_REGION_BASE_BOOL
184 default "0xe0000000"
185
186endmenu
187
188menu "Executable file formats"
189
190source "fs/Kconfig.binfmt"
191
192endmenu
193
194source "net/Kconfig"
195
196source "drivers/Kconfig"
197
198source "fs/Kconfig"
199
200source "arch/nios2/Kconfig.debug"
201
202source "security/Kconfig"
203
204source "crypto/Kconfig"
205
206source "lib/Kconfig"
diff --git a/arch/nios2/Kconfig.debug b/arch/nios2/Kconfig.debug
new file mode 100644
index 000000000000..8d4e6bacd997
--- /dev/null
+++ b/arch/nios2/Kconfig.debug
@@ -0,0 +1,17 @@
1menu "Kernel hacking"
2
3config TRACE_IRQFLAGS_SUPPORT
4 def_bool y
5
6source "lib/Kconfig.debug"
7
8config DEBUG_STACK_USAGE
9 bool "Enable stack utilization instrumentation"
10 depends on DEBUG_KERNEL
11 help
12 Enables the display of the minimum amount of free stack which each
13 task has ever had available in the sysrq-T and sysrq-P debug output.
14
15 This option will slow down process creation somewhat.
16
17endmenu
diff --git a/arch/nios2/Makefile b/arch/nios2/Makefile
new file mode 100644
index 000000000000..e142c9ee51fa
--- /dev/null
+++ b/arch/nios2/Makefile
@@ -0,0 +1,73 @@
1#
2# This file is subject to the terms and conditions of the GNU General Public
3# License. See the file "COPYING" in the main directory of this archive
4# for more details.
5#
6# Copyright (C) 2013 Altera Corporation
7# Copyright (C) 1994, 95, 96, 2003 by Wind River Systems
8# Written by Fredrik Markstrom
9#
10# This file is included by the global makefile so that you can add your own
11# architecture-specific flags and dependencies. Remember to do have actions
12# for "archclean" cleaning up for this architecture.
13#
14# Nios2 port by Wind River Systems Inc trough:
15# fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
16
17UTS_SYSNAME = Linux
18
19export MMU
20
21LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
22
23KBUILD_CFLAGS += -pipe -D__linux__ -D__ELF__
24KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MUL_SUPPORT),-mhw-mul,-mno-hw-mul)
25KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_MULX_SUPPORT),-mhw-mulx,-mno-hw-mulx)
26KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_HW_DIV_SUPPORT),-mhw-div,-mno-hw-div)
27KBUILD_CFLAGS += $(if $(CONFIG_NIOS2_FPU_SUPPORT),-mcustom-fpu-cfg=60-1,)
28
29KBUILD_CFLAGS += -fno-optimize-sibling-calls
30KBUILD_CFLAGS += -DUTS_SYSNAME=\"$(UTS_SYSNAME)\"
31KBUILD_CFLAGS += -fno-builtin
32KBUILD_CFLAGS += -G 0
33
34head-y := arch/nios2/kernel/head.o
35libs-y += arch/nios2/lib/ $(LIBGCC)
36core-y += arch/nios2/kernel/ arch/nios2/mm/
37core-y += arch/nios2/platform/
38
39INSTALL_PATH ?= /tftpboot
40nios2-boot := arch/$(ARCH)/boot
41BOOT_TARGETS = vmImage zImage
42PHONY += $(BOOT_TARGETS) install
43KBUILD_IMAGE := $(nios2-boot)/vmImage
44
45ifneq ($(CONFIG_NIOS2_DTB_SOURCE),"")
46 core-y += $(nios2-boot)/
47endif
48
49all: vmImage
50
51archclean:
52 $(Q)$(MAKE) $(clean)=$(nios2-boot)
53
54%.dtb:
55 $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@
56
57dtbs:
58 $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@
59
60$(BOOT_TARGETS): vmlinux
61 $(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@
62
63install:
64 $(Q)$(MAKE) $(build)=$(nios2-boot) BOOTIMAGE=$(KBUILD_IMAGE) install
65
66define archhelp
67 echo '* vmImage - Kernel-only image for U-Boot ($(KBUILD_IMAGE))'
68 echo ' install - Install kernel using'
69 echo ' (your) ~/bin/$(INSTALLKERNEL) or'
70 echo ' (distribution) /sbin/$(INSTALLKERNEL) or'
71 echo ' install to $$(INSTALL_PATH)'
72 echo ' dtbs - Build device tree blobs for enabled boards'
73endef
diff --git a/arch/nios2/boot/Makefile b/arch/nios2/boot/Makefile
new file mode 100644
index 000000000000..59392dc0bdcb
--- /dev/null
+++ b/arch/nios2/boot/Makefile
@@ -0,0 +1,52 @@
1#
2# arch/nios2/boot/Makefile
3#
4# This file is subject to the terms and conditions of the GNU General Public
5# License. See the file "COPYING" in the main directory of this archive
6# for more details.
7#
8
9UIMAGE_LOADADDR = $(shell $(NM) vmlinux | awk '$$NF == "_stext" {print $$1}')
10UIMAGE_ENTRYADDR = $(shell $(NM) vmlinux | awk '$$NF == "_start" {print $$1}')
11UIMAGE_COMPRESSION = gzip
12
13OBJCOPYFLAGS_vmlinux.bin := -O binary
14
15targets += vmlinux.bin vmlinux.gz vmImage
16
17$(obj)/vmlinux.bin: vmlinux FORCE
18 $(call if_changed,objcopy)
19
20$(obj)/vmlinux.gz: $(obj)/vmlinux.bin FORCE
21 $(call if_changed,gzip)
22
23$(obj)/vmImage: $(obj)/vmlinux.gz
24 $(call if_changed,uimage)
25 @$(kecho) 'Kernel: $@ is ready'
26
27# Rule to build device tree blobs
28DTB_SRC := $(patsubst "%",%,$(CONFIG_NIOS2_DTB_SOURCE))
29
30# Make sure the generated dtb gets removed during clean
31extra-$(CONFIG_NIOS2_DTB_SOURCE_BOOL) += system.dtb
32
33$(obj)/system.dtb: $(DTB_SRC) FORCE
34 $(call cmd,dtc)
35
36# Ensure system.dtb exists
37$(obj)/linked_dtb.o: $(obj)/system.dtb
38
39obj-$(CONFIG_NIOS2_DTB_SOURCE_BOOL) += linked_dtb.o
40
41targets += $(dtb-y)
42
43# Rule to build device tree blobs with make command
44$(obj)/%.dtb: $(src)/dts/%.dts FORCE
45 $(call if_changed_dep,dtc)
46
47$(obj)/dtbs: $(addprefix $(obj)/, $(dtb-y))
48
49clean-files := *.dtb
50
51install:
52 sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(BOOTIMAGE) System.map "$(INSTALL_PATH)"
diff --git a/arch/nios2/boot/dts/3c120_devboard.dts b/arch/nios2/boot/dts/3c120_devboard.dts
new file mode 100644
index 000000000000..31c51f9a2f09
--- /dev/null
+++ b/arch/nios2/boot/dts/3c120_devboard.dts
@@ -0,0 +1,164 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * This file is generated by sopc2dts.
18 */
19
20/dts-v1/;
21
22/ {
23 model = "altr,qsys_ghrd_3c120";
24 compatible = "altr,qsys_ghrd_3c120";
25 #address-cells = <1>;
26 #size-cells = <1>;
27
28 cpus {
29 #address-cells = <1>;
30 #size-cells = <0>;
31
32 cpu: cpu@0x0 {
33 device_type = "cpu";
34 compatible = "altr,nios2-1.0";
35 reg = <0x00000000>;
36 interrupt-controller;
37 #interrupt-cells = <1>;
38 clock-frequency = <125000000>;
39 dcache-line-size = <32>;
40 icache-line-size = <32>;
41 dcache-size = <32768>;
42 icache-size = <32768>;
43 altr,implementation = "fast";
44 altr,pid-num-bits = <8>;
45 altr,tlb-num-ways = <16>;
46 altr,tlb-num-entries = <128>;
47 altr,tlb-ptr-sz = <7>;
48 altr,has-div = <1>;
49 altr,has-mul = <1>;
50 altr,reset-addr = <0xc2800000>;
51 altr,fast-tlb-miss-addr = <0xc7fff400>;
52 altr,exception-addr = <0xd0000020>;
53 altr,has-initda = <1>;
54 altr,has-mmu = <1>;
55 };
56 };
57
58 memory@0 {
59 device_type = "memory";
60 reg = <0x10000000 0x08000000>,
61 <0x07fff400 0x00000400>;
62 };
63
64 sopc@0 {
65 device_type = "soc";
66 ranges;
67 #address-cells = <1>;
68 #size-cells = <1>;
69 compatible = "altr,avalon", "simple-bus";
70 bus-frequency = <125000000>;
71
72 pb_cpu_to_io: bridge@0x8000000 {
73 compatible = "simple-bus";
74 reg = <0x08000000 0x00800000>;
75 #address-cells = <1>;
76 #size-cells = <1>;
77 ranges = <0x00002000 0x08002000 0x00002000>,
78 <0x00004000 0x08004000 0x00000400>,
79 <0x00004400 0x08004400 0x00000040>,
80 <0x00004800 0x08004800 0x00000040>,
81 <0x00004c80 0x08004c80 0x00000020>,
82 <0x00004d50 0x08004d50 0x00000008>,
83 <0x00008000 0x08008000 0x00000020>,
84 <0x00400000 0x08400000 0x00000020>;
85
86 timer_1ms: timer@0x400000 {
87 compatible = "altr,timer-1.0";
88 reg = <0x00400000 0x00000020>;
89 interrupt-parent = <&cpu>;
90 interrupts = <11>;
91 clock-frequency = <125000000>;
92 };
93
94 timer_0: timer@0x8000 {
95 compatible = "altr,timer-1.0";
96 reg = < 0x00008000 0x00000020 >;
97 interrupt-parent = < &cpu >;
98 interrupts = < 5 >;
99 clock-frequency = < 125000000 >;
100 };
101
102 jtag_uart: serial@0x4d50 {
103 compatible = "altr,juart-1.0";
104 reg = <0x00004d50 0x00000008>;
105 interrupt-parent = <&cpu>;
106 interrupts = <1>;
107 };
108
109 tse_mac: ethernet@0x4000 {
110 compatible = "altr,tse-1.0";
111 reg = <0x00004000 0x00000400>,
112 <0x00004400 0x00000040>,
113 <0x00004800 0x00000040>,
114 <0x00002000 0x00002000>;
115 reg-names = "control_port", "rx_csr", "tx_csr", "s1";
116 interrupt-parent = <&cpu>;
117 interrupts = <2 3>;
118 interrupt-names = "rx_irq", "tx_irq";
119 rx-fifo-depth = <8192>;
120 tx-fifo-depth = <8192>;
121 max-frame-size = <1518>;
122 local-mac-address = [ 00 00 00 00 00 00 ];
123 phy-mode = "rgmii-id";
124 phy-handle = <&phy0>;
125 tse_mac_mdio: mdio {
126 compatible = "altr,tse-mdio";
127 #address-cells = <1>;
128 #size-cells = <0>;
129 phy0: ethernet-phy@18 {
130 reg = <18>;
131 device_type = "ethernet-phy";
132 };
133 };
134 };
135
136 uart: serial@0x4c80 {
137 compatible = "altr,uart-1.0";
138 reg = <0x00004c80 0x00000020>;
139 interrupt-parent = <&cpu>;
140 interrupts = <10>;
141 current-speed = <115200>;
142 clock-frequency = <62500000>;
143 };
144 };
145
146 cfi_flash_64m: flash@0x0 {
147 compatible = "cfi-flash";
148 reg = <0x00000000 0x04000000>;
149 bank-width = <2>;
150 device-width = <1>;
151 #address-cells = <1>;
152 #size-cells = <1>;
153
154 partition@800000 {
155 reg = <0x00800000 0x01e00000>;
156 label = "JFFS2 Filesystem";
157 };
158 };
159 };
160
161 chosen {
162 bootargs = "debug console=ttyJ0,115200";
163 };
164};
diff --git a/arch/nios2/boot/install.sh b/arch/nios2/boot/install.sh
new file mode 100644
index 000000000000..3cb3f468bc51
--- /dev/null
+++ b/arch/nios2/boot/install.sh
@@ -0,0 +1,52 @@
1#!/bin/sh
2#
3# This file is subject to the terms and conditions of the GNU General Public
4# License. See the file "COPYING" in the main directory of this archive
5# for more details.
6#
7# Copyright (C) 1995 by Linus Torvalds
8#
9# Adapted from code in arch/i386/boot/Makefile by H. Peter Anvin
10#
11# "make install" script for nios2 architecture
12#
13# Arguments:
14# $1 - kernel version
15# $2 - kernel image file
16# $3 - kernel map file
17# $4 - default install path (blank if root directory)
18#
19
20verify () {
21 if [ ! -f "$1" ]; then
22 echo "" 1>&2
23 echo " *** Missing file: $1" 1>&2
24 echo ' *** You need to run "make" before "make install".' 1>&2
25 echo "" 1>&2
26 exit 1
27 fi
28}
29
30# Make sure the files actually exist
31verify "$2"
32verify "$3"
33
34# User may have a custom install script
35
36if [ -x ~/bin/${INSTALLKERNEL} ]; then exec ~/bin/${INSTALLKERNEL} "$@"; fi
37if [ -x /sbin/${INSTALLKERNEL} ]; then exec /sbin/${INSTALLKERNEL} "$@"; fi
38
39# Default install - same as make zlilo
40
41if [ -f $4/vmlinuz ]; then
42 mv $4/vmlinuz $4/vmlinuz.old
43fi
44
45if [ -f $4/System.map ]; then
46 mv $4/System.map $4/System.old
47fi
48
49cat $2 > $4/vmlinuz
50cp $3 $4/System.map
51
52sync
diff --git a/arch/nios2/boot/linked_dtb.S b/arch/nios2/boot/linked_dtb.S
new file mode 100644
index 000000000000..071f922db338
--- /dev/null
+++ b/arch/nios2/boot/linked_dtb.S
@@ -0,0 +1,19 @@
1/*
2 * Copyright (C) 2011 Thomas Chou <thomas@wytron.com.tw>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18.section .dtb.init.rodata,"a"
19.incbin "arch/nios2/boot/system.dtb"
diff --git a/arch/nios2/configs/3c120_defconfig b/arch/nios2/configs/3c120_defconfig
new file mode 100644
index 000000000000..87541f0a5d6e
--- /dev/null
+++ b/arch/nios2/configs/3c120_defconfig
@@ -0,0 +1,77 @@
1CONFIG_SYSVIPC=y
2CONFIG_NO_HZ_IDLE=y
3CONFIG_BSD_PROCESS_ACCT=y
4CONFIG_LOG_BUF_SHIFT=14
5CONFIG_SYSCTL_SYSCALL=y
6# CONFIG_ELF_CORE is not set
7# CONFIG_EPOLL is not set
8# CONFIG_SIGNALFD is not set
9# CONFIG_TIMERFD is not set
10# CONFIG_EVENTFD is not set
11# CONFIG_SHMEM is not set
12# CONFIG_AIO is not set
13CONFIG_EMBEDDED=y
14CONFIG_SLAB=y
15CONFIG_MODULES=y
16CONFIG_MODULE_UNLOAD=y
17CONFIG_NIOS2_MEM_BASE=0x10000000
18CONFIG_NIOS2_HW_MUL_SUPPORT=y
19CONFIG_NIOS2_HW_DIV_SUPPORT=y
20CONFIG_CUSTOM_CACHE_SETTINGS=y
21CONFIG_NIOS2_DCACHE_SIZE=0x8000
22CONFIG_NIOS2_ICACHE_SIZE=0x8000
23# CONFIG_NIOS2_CMDLINE_IGNORE_DTB is not set
24CONFIG_NIOS2_PASS_CMDLINE=y
25CONFIG_NET=y
26CONFIG_PACKET=y
27CONFIG_UNIX=y
28CONFIG_INET=y
29CONFIG_IP_MULTICAST=y
30CONFIG_IP_PNP=y
31CONFIG_IP_PNP_DHCP=y
32CONFIG_IP_PNP_BOOTP=y
33CONFIG_IP_PNP_RARP=y
34# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
35# CONFIG_INET_XFRM_MODE_TUNNEL is not set
36# CONFIG_INET_XFRM_MODE_BEET is not set
37# CONFIG_INET_LRO is not set
38# CONFIG_IPV6 is not set
39# CONFIG_WIRELESS is not set
40CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
41CONFIG_DEVTMPFS=y
42CONFIG_DEVTMPFS_MOUNT=y
43# CONFIG_FW_LOADER is not set
44CONFIG_MTD=y
45CONFIG_MTD_CMDLINE_PARTS=y
46CONFIG_MTD_BLOCK=y
47CONFIG_MTD_CFI=y
48CONFIG_MTD_CFI_INTELEXT=y
49CONFIG_MTD_CFI_AMDSTD=y
50CONFIG_MTD_PHYSMAP_OF=y
51CONFIG_BLK_DEV_LOOP=y
52CONFIG_NETDEVICES=y
53CONFIG_ALTERA_TSE=y
54CONFIG_MARVELL_PHY=y
55# CONFIG_WLAN is not set
56# CONFIG_INPUT_MOUSE is not set
57# CONFIG_SERIO_SERPORT is not set
58# CONFIG_VT is not set
59CONFIG_SERIAL_ALTERA_JTAGUART=y
60CONFIG_SERIAL_ALTERA_JTAGUART_CONSOLE=y
61CONFIG_SERIAL_ALTERA_UART=y
62# CONFIG_HW_RANDOM is not set
63# CONFIG_HWMON is not set
64# CONFIG_USB_SUPPORT is not set
65CONFIG_NEW_LEDS=y
66CONFIG_LEDS_CLASS=y
67CONFIG_LEDS_TRIGGERS=y
68CONFIG_LEDS_TRIGGER_HEARTBEAT=y
69# CONFIG_DNOTIFY is not set
70# CONFIG_INOTIFY_USER is not set
71CONFIG_JFFS2_FS=y
72CONFIG_NFS_FS=y
73CONFIG_NFS_V3_ACL=y
74CONFIG_ROOT_NFS=y
75CONFIG_SUNRPC_DEBUG=y
76CONFIG_DEBUG_INFO=y
77# CONFIG_ENABLE_WARN_DEPRECATED is not set
diff --git a/arch/nios2/include/asm/Kbuild b/arch/nios2/include/asm/Kbuild
new file mode 100644
index 000000000000..bb160be0dc28
--- /dev/null
+++ b/arch/nios2/include/asm/Kbuild
@@ -0,0 +1,66 @@
1generic-y += atomic.h
2generic-y += auxvec.h
3generic-y += barrier.h
4generic-y += bitops.h
5generic-y += bitsperlong.h
6generic-y += bug.h
7generic-y += bugs.h
8generic-y += clkdev.h
9generic-y += cputime.h
10generic-y += current.h
11generic-y += device.h
12generic-y += div64.h
13generic-y += dma.h
14generic-y += emergency-restart.h
15generic-y += errno.h
16generic-y += exec.h
17generic-y += fb.h
18generic-y += fcntl.h
19generic-y += ftrace.h
20generic-y += futex.h
21generic-y += hardirq.h
22generic-y += hash.h
23generic-y += hw_irq.h
24generic-y += ioctl.h
25generic-y += ioctls.h
26generic-y += ipcbuf.h
27generic-y += irq_regs.h
28generic-y += irq_work.h
29generic-y += kdebug.h
30generic-y += kmap_types.h
31generic-y += kvm_para.h
32generic-y += local.h
33generic-y += mcs_spinlock.h
34generic-y += mman.h
35generic-y += module.h
36generic-y += msgbuf.h
37generic-y += param.h
38generic-y += pci.h
39generic-y += percpu.h
40generic-y += poll.h
41generic-y += posix_types.h
42generic-y += preempt.h
43generic-y += resource.h
44generic-y += scatterlist.h
45generic-y += sections.h
46generic-y += segment.h
47generic-y += sembuf.h
48generic-y += serial.h
49generic-y += shmbuf.h
50generic-y += shmparam.h
51generic-y += siginfo.h
52generic-y += signal.h
53generic-y += socket.h
54generic-y += sockios.h
55generic-y += spinlock.h
56generic-y += stat.h
57generic-y += statfs.h
58generic-y += termbits.h
59generic-y += termios.h
60generic-y += topology.h
61generic-y += trace_clock.h
62generic-y += types.h
63generic-y += unaligned.h
64generic-y += user.h
65generic-y += vga.h
66generic-y += xor.h
diff --git a/arch/nios2/include/asm/asm-macros.h b/arch/nios2/include/asm/asm-macros.h
new file mode 100644
index 000000000000..29fa2e4d7b00
--- /dev/null
+++ b/arch/nios2/include/asm/asm-macros.h
@@ -0,0 +1,309 @@
1/*
2 * Macro used to simplify coding multi-line assembler.
3 * Some of the bit test macro can simplify down to one line
4 * depending on the mask value.
5 *
6 * Copyright (C) 2004 Microtronix Datacom Ltd.
7 *
8 * All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18 * NON INFRINGEMENT. See the GNU General Public License for more
19 * details.
20 *
21 */
22#ifndef _ASM_NIOS2_ASMMACROS_H
23#define _ASM_NIOS2_ASMMACROS_H
24/*
25 * ANDs reg2 with mask and places the result in reg1.
26 *
27 * You cannnot use the same register for reg1 & reg2.
28 */
29
30.macro ANDI32 reg1, reg2, mask
31.if \mask & 0xffff
32 .if \mask & 0xffff0000
33 movhi \reg1, %hi(\mask)
34 movui \reg1, %lo(\mask)
35 and \reg1, \reg1, \reg2
36 .else
37 andi \reg1, \reg2, %lo(\mask)
38 .endif
39.else
40 andhi \reg1, \reg2, %hi(\mask)
41.endif
42.endm
43
44/*
45 * ORs reg2 with mask and places the result in reg1.
46 *
47 * It is safe to use the same register for reg1 & reg2.
48 */
49
50.macro ORI32 reg1, reg2, mask
51.if \mask & 0xffff
52 .if \mask & 0xffff0000
53 orhi \reg1, \reg2, %hi(\mask)
54 ori \reg1, \reg2, %lo(\mask)
55 .else
56 ori \reg1, \reg2, %lo(\mask)
57 .endif
58.else
59 orhi \reg1, \reg2, %hi(\mask)
60.endif
61.endm
62
63/*
64 * XORs reg2 with mask and places the result in reg1.
65 *
66 * It is safe to use the same register for reg1 & reg2.
67 */
68
69.macro XORI32 reg1, reg2, mask
70.if \mask & 0xffff
71 .if \mask & 0xffff0000
72 xorhi \reg1, \reg2, %hi(\mask)
73 xori \reg1, \reg1, %lo(\mask)
74 .else
75 xori \reg1, \reg2, %lo(\mask)
76 .endif
77.else
78 xorhi \reg1, \reg2, %hi(\mask)
79.endif
80.endm
81
82/*
83 * This is a support macro for BTBZ & BTBNZ. It checks
84 * the bit to make sure it is valid 32 value.
85 *
86 * It is safe to use the same register for reg1 & reg2.
87 */
88
89.macro BT reg1, reg2, bit
90.if \bit > 31
91 .err
92.else
93 .if \bit < 16
94 andi \reg1, \reg2, (1 << \bit)
95 .else
96 andhi \reg1, \reg2, (1 << (\bit - 16))
97 .endif
98.endif
99.endm
100
101/*
102 * Tests the bit in reg2 and branches to label if the
103 * bit is zero. The result of the bit test is stored in reg1.
104 *
105 * It is safe to use the same register for reg1 & reg2.
106 */
107
108.macro BTBZ reg1, reg2, bit, label
109 BT \reg1, \reg2, \bit
110 beq \reg1, r0, \label
111.endm
112
113/*
114 * Tests the bit in reg2 and branches to label if the
115 * bit is non-zero. The result of the bit test is stored in reg1.
116 *
117 * It is safe to use the same register for reg1 & reg2.
118 */
119
120.macro BTBNZ reg1, reg2, bit, label
121 BT \reg1, \reg2, \bit
122 bne \reg1, r0, \label
123.endm
124
125/*
126 * Tests the bit in reg2 and then compliments the bit in reg2.
127 * The result of the bit test is stored in reg1.
128 *
129 * It is NOT safe to use the same register for reg1 & reg2.
130 */
131
132.macro BTC reg1, reg2, bit
133.if \bit > 31
134 .err
135.else
136 .if \bit < 16
137 andi \reg1, \reg2, (1 << \bit)
138 xori \reg2, \reg2, (1 << \bit)
139 .else
140 andhi \reg1, \reg2, (1 << (\bit - 16))
141 xorhi \reg2, \reg2, (1 << (\bit - 16))
142 .endif
143.endif
144.endm
145
146/*
147 * Tests the bit in reg2 and then sets the bit in reg2.
148 * The result of the bit test is stored in reg1.
149 *
150 * It is NOT safe to use the same register for reg1 & reg2.
151 */
152
153.macro BTS reg1, reg2, bit
154.if \bit > 31
155 .err
156.else
157 .if \bit < 16
158 andi \reg1, \reg2, (1 << \bit)
159 ori \reg2, \reg2, (1 << \bit)
160 .else
161 andhi \reg1, \reg2, (1 << (\bit - 16))
162 orhi \reg2, \reg2, (1 << (\bit - 16))
163 .endif
164.endif
165.endm
166
167/*
168 * Tests the bit in reg2 and then resets the bit in reg2.
169 * The result of the bit test is stored in reg1.
170 *
171 * It is NOT safe to use the same register for reg1 & reg2.
172 */
173
174.macro BTR reg1, reg2, bit
175.if \bit > 31
176 .err
177.else
178 .if \bit < 16
179 andi \reg1, \reg2, (1 << \bit)
180 andi \reg2, \reg2, %lo(~(1 << \bit))
181 .else
182 andhi \reg1, \reg2, (1 << (\bit - 16))
183 andhi \reg2, \reg2, %lo(~(1 << (\bit - 16)))
184 .endif
185.endif
186.endm
187
188/*
189 * Tests the bit in reg2 and then compliments the bit in reg2.
190 * The result of the bit test is stored in reg1. If the
191 * original bit was zero it branches to label.
192 *
193 * It is NOT safe to use the same register for reg1 & reg2.
194 */
195
196.macro BTCBZ reg1, reg2, bit, label
197 BTC \reg1, \reg2, \bit
198 beq \reg1, r0, \label
199.endm
200
201/*
202 * Tests the bit in reg2 and then compliments the bit in reg2.
203 * The result of the bit test is stored in reg1. If the
204 * original bit was non-zero it branches to label.
205 *
206 * It is NOT safe to use the same register for reg1 & reg2.
207 */
208
209.macro BTCBNZ reg1, reg2, bit, label
210 BTC \reg1, \reg2, \bit
211 bne \reg1, r0, \label
212.endm
213
214/*
215 * Tests the bit in reg2 and then sets the bit in reg2.
216 * The result of the bit test is stored in reg1. If the
217 * original bit was zero it branches to label.
218 *
219 * It is NOT safe to use the same register for reg1 & reg2.
220 */
221
222.macro BTSBZ reg1, reg2, bit, label
223 BTS \reg1, \reg2, \bit
224 beq \reg1, r0, \label
225.endm
226
227/*
228 * Tests the bit in reg2 and then sets the bit in reg2.
229 * The result of the bit test is stored in reg1. If the
230 * original bit was non-zero it branches to label.
231 *
232 * It is NOT safe to use the same register for reg1 & reg2.
233 */
234
235.macro BTSBNZ reg1, reg2, bit, label
236 BTS \reg1, \reg2, \bit
237 bne \reg1, r0, \label
238.endm
239
240/*
241 * Tests the bit in reg2 and then resets the bit in reg2.
242 * The result of the bit test is stored in reg1. If the
243 * original bit was zero it branches to label.
244 *
245 * It is NOT safe to use the same register for reg1 & reg2.
246 */
247
248.macro BTRBZ reg1, reg2, bit, label
249 BTR \reg1, \reg2, \bit
250 bne \reg1, r0, \label
251.endm
252
253/*
254 * Tests the bit in reg2 and then resets the bit in reg2.
255 * The result of the bit test is stored in reg1. If the
256 * original bit was non-zero it branches to label.
257 *
258 * It is NOT safe to use the same register for reg1 & reg2.
259 */
260
261.macro BTRBNZ reg1, reg2, bit, label
262 BTR \reg1, \reg2, \bit
263 bne \reg1, r0, \label
264.endm
265
266/*
267 * Tests the bits in mask against reg2 stores the result in reg1.
268 * If the all the bits in the mask are zero it branches to label.
269 *
270 * It is safe to use the same register for reg1 & reg2.
271 */
272
273.macro TSTBZ reg1, reg2, mask, label
274 ANDI32 \reg1, \reg2, \mask
275 beq \reg1, r0, \label
276.endm
277
278/*
279 * Tests the bits in mask against reg2 stores the result in reg1.
280 * If the any of the bits in the mask are 1 it branches to label.
281 *
282 * It is safe to use the same register for reg1 & reg2.
283 */
284
285.macro TSTBNZ reg1, reg2, mask, label
286 ANDI32 \reg1, \reg2, \mask
287 bne \reg1, r0, \label
288.endm
289
290/*
291 * Pushes reg onto the stack.
292 */
293
294.macro PUSH reg
295 addi sp, sp, -4
296 stw \reg, 0(sp)
297.endm
298
299/*
300 * Pops the top of the stack into reg.
301 */
302
303.macro POP reg
304 ldw \reg, 0(sp)
305 addi sp, sp, 4
306.endm
307
308
309#endif /* _ASM_NIOS2_ASMMACROS_H */
diff --git a/arch/nios2/include/asm/asm-offsets.h b/arch/nios2/include/asm/asm-offsets.h
new file mode 100644
index 000000000000..5b9f5e04a058
--- /dev/null
+++ b/arch/nios2/include/asm/asm-offsets.h
@@ -0,0 +1,20 @@
1/*
2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2009 Thomas Chou <thomas@wytron.com.tw>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#include <generated/asm-offsets.h>
diff --git a/arch/nios2/include/asm/cache.h b/arch/nios2/include/asm/cache.h
new file mode 100644
index 000000000000..2293cf57e307
--- /dev/null
+++ b/arch/nios2/include/asm/cache.h
@@ -0,0 +1,36 @@
1/*
2 * Copyright (C) 2004 Microtronix Datacom Ltd.
3 *
4 * All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
15 * details.
16 */
17
18#ifndef _ASM_NIOS2_CACHE_H
19#define _ASM_NIOS2_CACHE_H
20
21#define NIOS2_DCACHE_SIZE CONFIG_NIOS2_DCACHE_SIZE
22#define NIOS2_ICACHE_SIZE CONFIG_NIOS2_ICACHE_SIZE
23#define NIOS2_DCACHE_LINE_SIZE CONFIG_NIOS2_DCACHE_LINE_SIZE
24#define NIOS2_ICACHE_LINE_SHIFT 5
25#define NIOS2_ICACHE_LINE_SIZE (1 << NIOS2_ICACHE_LINE_SHIFT)
26
27/* bytes per L1 cache line */
28#define L1_CACHE_SHIFT NIOS2_ICACHE_LINE_SHIFT
29#define L1_CACHE_BYTES NIOS2_ICACHE_LINE_SIZE
30
31#define ARCH_DMA_MINALIGN L1_CACHE_BYTES
32
33#define __cacheline_aligned
34#define ____cacheline_aligned
35
36#endif
diff --git a/arch/nios2/include/asm/cacheflush.h b/arch/nios2/include/asm/cacheflush.h
new file mode 100644
index 000000000000..52abba973dc2
--- /dev/null
+++ b/arch/nios2/include/asm/cacheflush.h
@@ -0,0 +1,52 @@
1/*
2 * Copyright (C) 2003 Microtronix Datacom Ltd.
3 * Copyright (C) 2000-2002 Greg Ungerer <gerg@snapgear.com>
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#ifndef _ASM_NIOS2_CACHEFLUSH_H
11#define _ASM_NIOS2_CACHEFLUSH_H
12
13#include <linux/mm_types.h>
14
15/*
16 * This flag is used to indicate that the page pointed to by a pte is clean
17 * and does not require cleaning before returning it to the user.
18 */
19#define PG_dcache_clean PG_arch_1
20
21struct mm_struct;
22
23extern void flush_cache_all(void);
24extern void flush_cache_mm(struct mm_struct *mm);
25extern void flush_cache_dup_mm(struct mm_struct *mm);
26extern void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
27 unsigned long end);
28extern void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr,
29 unsigned long pfn);
30#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1
31extern void flush_dcache_page(struct page *page);
32
33extern void flush_icache_range(unsigned long start, unsigned long end);
34extern void flush_icache_page(struct vm_area_struct *vma, struct page *page);
35
36#define flush_cache_vmap(start, end) flush_dcache_range(start, end)
37#define flush_cache_vunmap(start, end) flush_dcache_range(start, end)
38
39extern void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
40 unsigned long user_vaddr,
41 void *dst, void *src, int len);
42extern void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
43 unsigned long user_vaddr,
44 void *dst, void *src, int len);
45
46extern void flush_dcache_range(unsigned long start, unsigned long end);
47extern void invalidate_dcache_range(unsigned long start, unsigned long end);
48
49#define flush_dcache_mmap_lock(mapping) do { } while (0)
50#define flush_dcache_mmap_unlock(mapping) do { } while (0)
51
52#endif /* _ASM_NIOS2_CACHEFLUSH_H */
diff --git a/arch/nios2/include/asm/checksum.h b/arch/nios2/include/asm/checksum.h
new file mode 100644
index 000000000000..6bc1f0d5df7b
--- /dev/null
+++ b/arch/nios2/include/asm/checksum.h
@@ -0,0 +1,78 @@
1/*
2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd.
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#ifndef _ASM_NIOS_CHECKSUM_H
11#define _ASM_NIOS_CHECKSUM_H
12
13/* Take these from lib/checksum.c */
14extern __wsum csum_partial(const void *buff, int len, __wsum sum);
15extern __wsum csum_partial_copy(const void *src, void *dst, int len,
16 __wsum sum);
17extern __wsum csum_partial_copy_from_user(const void __user *src, void *dst,
18 int len, __wsum sum, int *csum_err);
19#define csum_partial_copy_nocheck(src, dst, len, sum) \
20 csum_partial_copy((src), (dst), (len), (sum))
21
22extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
23extern __sum16 ip_compute_csum(const void *buff, int len);
24
25/*
26 * Fold a partial checksum
27 */
28static inline __sum16 csum_fold(__wsum sum)
29{
30 __asm__ __volatile__(
31 "add %0, %1, %0\n"
32 "cmpltu r8, %0, %1\n"
33 "srli %0, %0, 16\n"
34 "add %0, %0, r8\n"
35 "nor %0, %0, %0\n"
36 : "=r" (sum)
37 : "r" (sum << 16), "0" (sum)
38 : "r8");
39 return (__force __sum16) sum;
40}
41
42/*
43 * computes the checksum of the TCP/UDP pseudo-header
44 * returns a 16-bit checksum, already complemented
45 */
46#define csum_tcpudp_nofold csum_tcpudp_nofold
47static inline __wsum csum_tcpudp_nofold(__be32 saddr, __be32 daddr,
48 unsigned short len,
49 unsigned short proto,
50 __wsum sum)
51{
52 __asm__ __volatile__(
53 "add %0, %1, %0\n"
54 "cmpltu r8, %0, %1\n"
55 "add %0, %0, r8\n" /* add carry */
56 "add %0, %2, %0\n"
57 "cmpltu r8, %0, %2\n"
58 "add %0, %0, r8\n" /* add carry */
59 "add %0, %3, %0\n"
60 "cmpltu r8, %0, %3\n"
61 "add %0, %0, r8\n" /* add carry */
62 : "=r" (sum), "=r" (saddr)
63 : "r" (daddr), "r" ((ntohs(len) << 16) + (proto * 256)),
64 "0" (sum),
65 "1" (saddr)
66 : "r8");
67
68 return sum;
69}
70
71static inline __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
72 unsigned short len,
73 unsigned short proto, __wsum sum)
74{
75 return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
76}
77
78#endif /* _ASM_NIOS_CHECKSUM_H */
diff --git a/arch/nios2/include/asm/cmpxchg.h b/arch/nios2/include/asm/cmpxchg.h
new file mode 100644
index 000000000000..85938711542d
--- /dev/null
+++ b/arch/nios2/include/asm/cmpxchg.h
@@ -0,0 +1,61 @@
1/*
2 * Copyright (C) 2004 Microtronix Datacom Ltd.
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 */
8
9#ifndef _ASM_NIOS2_CMPXCHG_H
10#define _ASM_NIOS2_CMPXCHG_H
11
12#include <linux/irqflags.h>
13
14#define xchg(ptr, x) \
15 ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
16
17struct __xchg_dummy { unsigned long a[100]; };
18#define __xg(x) ((volatile struct __xchg_dummy *)(x))
19
20static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
21 int size)
22{
23 unsigned long tmp, flags;
24
25 local_irq_save(flags);
26
27 switch (size) {
28 case 1:
29 __asm__ __volatile__(
30 "ldb %0, %2\n"
31 "stb %1, %2\n"
32 : "=&r" (tmp)
33 : "r" (x), "m" (*__xg(ptr))
34 : "memory");
35 break;
36 case 2:
37 __asm__ __volatile__(
38 "ldh %0, %2\n"
39 "sth %1, %2\n"
40 : "=&r" (tmp)
41 : "r" (x), "m" (*__xg(ptr))
42 : "memory");
43 break;
44 case 4:
45 __asm__ __volatile__(
46 "ldw %0, %2\n"
47 "stw %1, %2\n"
48 : "=&r" (tmp)
49 : "r" (x), "m" (*__xg(ptr))
50 : "memory");
51 break;
52 }
53
54 local_irq_restore(flags);
55 return tmp;
56}
57
58#include <asm-generic/cmpxchg.h>
59#include <asm-generic/cmpxchg-local.h>
60
61#endif /* _ASM_NIOS2_CMPXCHG_H */
diff --git a/arch/nios2/include/asm/cpuinfo.h b/arch/nios2/include/asm/cpuinfo.h
new file mode 100644
index 000000000000..e88fcae464d9
--- /dev/null
+++ b/arch/nios2/include/asm/cpuinfo.h
@@ -0,0 +1,57 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19#ifndef _ASM_NIOS2_CPUINFO_H
20#define _ASM_NIOS2_CPUINFO_H
21
22#include <linux/types.h>
23
24struct cpuinfo {
25 /* Core CPU configuration */
26 char cpu_impl[12];
27 u32 cpu_clock_freq;
28 u32 mmu;
29 u32 has_div;
30 u32 has_mul;
31 u32 has_mulx;
32
33 /* CPU caches */
34 u32 icache_line_size;
35 u32 icache_size;
36 u32 dcache_line_size;
37 u32 dcache_size;
38
39 /* TLB */
40 u32 tlb_pid_num_bits; /* number of bits used for the PID in TLBMISC */
41 u32 tlb_num_ways;
42 u32 tlb_num_ways_log2;
43 u32 tlb_num_entries;
44 u32 tlb_num_lines;
45 u32 tlb_ptr_sz;
46
47 /* Addresses */
48 u32 reset_addr;
49 u32 exception_addr;
50 u32 fast_tlb_miss_exc_addr;
51};
52
53extern struct cpuinfo cpuinfo;
54
55extern void setup_cpuinfo(void);
56
57#endif /* _ASM_NIOS2_CPUINFO_H */
diff --git a/arch/nios2/include/asm/delay.h b/arch/nios2/include/asm/delay.h
new file mode 100644
index 000000000000..098e49bf3aa3
--- /dev/null
+++ b/arch/nios2/include/asm/delay.h
@@ -0,0 +1,21 @@
1/*
2 * Copyright (C) 2014 Altera Corporation
3 * Copyright (C) 2004 Microtronix Datacom Ltd
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#ifndef _ASM_NIOS2_DELAY_H
11#define _ASM_NIOS2_DELAY_H
12
13#include <asm-generic/delay.h>
14
15/* Undefined functions to get compile-time errors */
16extern void __bad_udelay(void);
17extern void __bad_ndelay(void);
18
19extern unsigned long loops_per_jiffy;
20
21#endif /* _ASM_NIOS2_DELAY_H */
diff --git a/arch/nios2/include/asm/dma-mapping.h b/arch/nios2/include/asm/dma-mapping.h
new file mode 100644
index 000000000000..b5567233f7f1
--- /dev/null
+++ b/arch/nios2/include/asm/dma-mapping.h
@@ -0,0 +1,140 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2009 Wind River Systems Inc
4 *
5 * This file is subject to the terms and conditions of the GNU General
6 * Public License. See the file COPYING in the main directory of this
7 * archive for more details.
8 */
9
10#ifndef _ASM_NIOS2_DMA_MAPPING_H
11#define _ASM_NIOS2_DMA_MAPPING_H
12
13#include <linux/scatterlist.h>
14#include <linux/cache.h>
15#include <asm/cacheflush.h>
16
17static inline void __dma_sync_for_device(void *vaddr, size_t size,
18 enum dma_data_direction direction)
19{
20 switch (direction) {
21 case DMA_FROM_DEVICE:
22 invalidate_dcache_range((unsigned long)vaddr,
23 (unsigned long)(vaddr + size));
24 break;
25 case DMA_TO_DEVICE:
26 /*
27 * We just need to flush the caches here , but Nios2 flush
28 * instruction will do both writeback and invalidate.
29 */
30 case DMA_BIDIRECTIONAL: /* flush and invalidate */
31 flush_dcache_range((unsigned long)vaddr,
32 (unsigned long)(vaddr + size));
33 break;
34 default:
35 BUG();
36 }
37}
38
39static inline void __dma_sync_for_cpu(void *vaddr, size_t size,
40 enum dma_data_direction direction)
41{
42 switch (direction) {
43 case DMA_BIDIRECTIONAL:
44 case DMA_FROM_DEVICE:
45 invalidate_dcache_range((unsigned long)vaddr,
46 (unsigned long)(vaddr + size));
47 break;
48 case DMA_TO_DEVICE:
49 break;
50 default:
51 BUG();
52 }
53}
54
55#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
56#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
57
58void *dma_alloc_coherent(struct device *dev, size_t size,
59 dma_addr_t *dma_handle, gfp_t flag);
60
61void dma_free_coherent(struct device *dev, size_t size,
62 void *vaddr, dma_addr_t dma_handle);
63
64static inline dma_addr_t dma_map_single(struct device *dev, void *ptr,
65 size_t size,
66 enum dma_data_direction direction)
67{
68 BUG_ON(!valid_dma_direction(direction));
69 __dma_sync_for_device(ptr, size, direction);
70 return virt_to_phys(ptr);
71}
72
73static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
74 size_t size, enum dma_data_direction direction)
75{
76}
77
78extern int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
79 enum dma_data_direction direction);
80extern dma_addr_t dma_map_page(struct device *dev, struct page *page,
81 unsigned long offset, size_t size, enum dma_data_direction direction);
82extern void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
83 size_t size, enum dma_data_direction direction);
84extern void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
85 int nhwentries, enum dma_data_direction direction);
86extern void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
87 size_t size, enum dma_data_direction direction);
88extern void dma_sync_single_for_device(struct device *dev,
89 dma_addr_t dma_handle, size_t size, enum dma_data_direction direction);
90extern void dma_sync_single_range_for_cpu(struct device *dev,
91 dma_addr_t dma_handle, unsigned long offset, size_t size,
92 enum dma_data_direction direction);
93extern void dma_sync_single_range_for_device(struct device *dev,
94 dma_addr_t dma_handle, unsigned long offset, size_t size,
95 enum dma_data_direction direction);
96extern void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
97 int nelems, enum dma_data_direction direction);
98extern void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
99 int nelems, enum dma_data_direction direction);
100
101static inline int dma_supported(struct device *dev, u64 mask)
102{
103 return 1;
104}
105
106static inline int dma_set_mask(struct device *dev, u64 mask)
107{
108 if (!dev->dma_mask || !dma_supported(dev, mask))
109 return -EIO;
110
111 *dev->dma_mask = mask;
112
113 return 0;
114}
115
116static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
117{
118 return 0;
119}
120
121/*
122* dma_alloc_noncoherent() returns non-cacheable memory, so there's no need to
123* do any flushing here.
124*/
125static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
126 enum dma_data_direction direction)
127{
128}
129
130/* drivers/base/dma-mapping.c */
131extern int dma_common_mmap(struct device *dev, struct vm_area_struct *vma,
132 void *cpu_addr, dma_addr_t dma_addr, size_t size);
133extern int dma_common_get_sgtable(struct device *dev, struct sg_table *sgt,
134 void *cpu_addr, dma_addr_t dma_addr,
135 size_t size);
136
137#define dma_mmap_coherent(d, v, c, h, s) dma_common_mmap(d, v, c, h, s)
138#define dma_get_sgtable(d, t, v, h, s) dma_common_get_sgtable(d, t, v, h, s)
139
140#endif /* _ASM_NIOS2_DMA_MAPPING_H */
diff --git a/arch/nios2/include/asm/elf.h b/arch/nios2/include/asm/elf.h
new file mode 100644
index 000000000000..b7d655dff731
--- /dev/null
+++ b/arch/nios2/include/asm/elf.h
@@ -0,0 +1,101 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19#ifndef _ASM_NIOS2_ELF_H
20#define _ASM_NIOS2_ELF_H
21
22#include <uapi/asm/elf.h>
23
24/*
25 * This is used to ensure we don't load something for the wrong architecture.
26 */
27#define elf_check_arch(x) ((x)->e_machine == EM_ALTERA_NIOS2)
28
29#define ELF_PLAT_INIT(_r, load_addr)
30
31#define CORE_DUMP_USE_REGSET
32#define ELF_EXEC_PAGESIZE 4096
33
34/* This is the location that an ET_DYN program is loaded if exec'ed. Typical
35 use of this is to invoke "./ld.so someprog" to test out a new version of
36 the loader. We need to make sure that it is out of the way of the program
37 that it will "exec", and that there is sufficient room for the brk. */
38
39#define ELF_ET_DYN_BASE 0xD0000000UL
40
41/* regs is struct pt_regs, pr_reg is elf_gregset_t (which is
42 now struct_user_regs, they are different) */
43
44#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
45struct linux_binprm;
46extern int arch_setup_additional_pages(struct linux_binprm *bprm,
47 int uses_interp);
48#define ELF_CORE_COPY_REGS(pr_reg, regs) \
49{ do { \
50 /* Bleech. */ \
51 pr_reg[0] = regs->r8; \
52 pr_reg[1] = regs->r9; \
53 pr_reg[2] = regs->r10; \
54 pr_reg[3] = regs->r11; \
55 pr_reg[4] = regs->r12; \
56 pr_reg[5] = regs->r13; \
57 pr_reg[6] = regs->r14; \
58 pr_reg[7] = regs->r15; \
59 pr_reg[8] = regs->r1; \
60 pr_reg[9] = regs->r2; \
61 pr_reg[10] = regs->r3; \
62 pr_reg[11] = regs->r4; \
63 pr_reg[12] = regs->r5; \
64 pr_reg[13] = regs->r6; \
65 pr_reg[14] = regs->r7; \
66 pr_reg[15] = regs->orig_r2; \
67 pr_reg[16] = regs->ra; \
68 pr_reg[17] = regs->fp; \
69 pr_reg[18] = regs->sp; \
70 pr_reg[19] = regs->gp; \
71 pr_reg[20] = regs->estatus; \
72 pr_reg[21] = regs->ea; \
73 pr_reg[22] = regs->orig_r7; \
74 { \
75 struct switch_stack *sw = ((struct switch_stack *)regs) - 1; \
76 pr_reg[23] = sw->r16; \
77 pr_reg[24] = sw->r17; \
78 pr_reg[25] = sw->r18; \
79 pr_reg[26] = sw->r19; \
80 pr_reg[27] = sw->r20; \
81 pr_reg[28] = sw->r21; \
82 pr_reg[29] = sw->r22; \
83 pr_reg[30] = sw->r23; \
84 pr_reg[31] = sw->fp; \
85 pr_reg[32] = sw->gp; \
86 pr_reg[33] = sw->ra; \
87 } \
88} while (0); }
89
90/* This yields a mask that user programs can use to figure out what
91 instruction set this cpu supports. */
92
93#define ELF_HWCAP (0)
94
95/* This yields a string that ld.so will use to load implementation
96 specific libraries for optimization. This is more specific in
97 intent than poking at uname or /proc/cpuinfo. */
98
99#define ELF_PLATFORM (NULL)
100
101#endif /* _ASM_NIOS2_ELF_H */
diff --git a/arch/nios2/include/asm/entry.h b/arch/nios2/include/asm/entry.h
new file mode 100644
index 000000000000..cf37f55efbc2
--- /dev/null
+++ b/arch/nios2/include/asm/entry.h
@@ -0,0 +1,120 @@
1/*
2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd.
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#ifndef _ASM_NIOS2_ENTRY_H
11#define _ASM_NIOS2_ENTRY_H
12
13#ifdef __ASSEMBLY__
14
15#include <asm/processor.h>
16#include <asm/registers.h>
17#include <asm/asm-offsets.h>
18
19/*
20 * Standard Nios2 interrupt entry and exit macros.
21 * Must be called with interrupts disabled.
22 */
23.macro SAVE_ALL
24 rdctl r24, estatus
25 andi r24, r24, ESTATUS_EU
26 beq r24, r0, 1f /* In supervisor mode, already on kernel stack */
27
28 movia r24, _current_thread /* Switch to current kernel stack */
29 ldw r24, 0(r24) /* using the thread_info */
30 addi r24, r24, THREAD_SIZE-PT_REGS_SIZE
31 stw sp, PT_SP(r24) /* Save user stack before changing */
32 mov sp, r24
33 br 2f
34
351 : mov r24, sp
36 addi sp, sp, -PT_REGS_SIZE /* Backup the kernel stack pointer */
37 stw r24, PT_SP(sp)
382 : stw r1, PT_R1(sp)
39 stw r2, PT_R2(sp)
40 stw r3, PT_R3(sp)
41 stw r4, PT_R4(sp)
42 stw r5, PT_R5(sp)
43 stw r6, PT_R6(sp)
44 stw r7, PT_R7(sp)
45 stw r8, PT_R8(sp)
46 stw r9, PT_R9(sp)
47 stw r10, PT_R10(sp)
48 stw r11, PT_R11(sp)
49 stw r12, PT_R12(sp)
50 stw r13, PT_R13(sp)
51 stw r14, PT_R14(sp)
52 stw r15, PT_R15(sp)
53 stw r2, PT_ORIG_R2(sp)
54 stw r7, PT_ORIG_R7(sp)
55
56 stw ra, PT_RA(sp)
57 stw fp, PT_FP(sp)
58 stw gp, PT_GP(sp)
59 rdctl r24, estatus
60 stw r24, PT_ESTATUS(sp)
61 stw ea, PT_EA(sp)
62.endm
63
64.macro RESTORE_ALL
65 ldw r1, PT_R1(sp) /* Restore registers */
66 ldw r2, PT_R2(sp)
67 ldw r3, PT_R3(sp)
68 ldw r4, PT_R4(sp)
69 ldw r5, PT_R5(sp)
70 ldw r6, PT_R6(sp)
71 ldw r7, PT_R7(sp)
72 ldw r8, PT_R8(sp)
73 ldw r9, PT_R9(sp)
74 ldw r10, PT_R10(sp)
75 ldw r11, PT_R11(sp)
76 ldw r12, PT_R12(sp)
77 ldw r13, PT_R13(sp)
78 ldw r14, PT_R14(sp)
79 ldw r15, PT_R15(sp)
80 ldw ra, PT_RA(sp)
81 ldw fp, PT_FP(sp)
82 ldw gp, PT_GP(sp)
83 ldw r24, PT_ESTATUS(sp)
84 wrctl estatus, r24
85 ldw ea, PT_EA(sp)
86 ldw sp, PT_SP(sp) /* Restore sp last */
87.endm
88
89.macro SAVE_SWITCH_STACK
90 addi sp, sp, -SWITCH_STACK_SIZE
91 stw r16, SW_R16(sp)
92 stw r17, SW_R17(sp)
93 stw r18, SW_R18(sp)
94 stw r19, SW_R19(sp)
95 stw r20, SW_R20(sp)
96 stw r21, SW_R21(sp)
97 stw r22, SW_R22(sp)
98 stw r23, SW_R23(sp)
99 stw fp, SW_FP(sp)
100 stw gp, SW_GP(sp)
101 stw ra, SW_RA(sp)
102.endm
103
104.macro RESTORE_SWITCH_STACK
105 ldw r16, SW_R16(sp)
106 ldw r17, SW_R17(sp)
107 ldw r18, SW_R18(sp)
108 ldw r19, SW_R19(sp)
109 ldw r20, SW_R20(sp)
110 ldw r21, SW_R21(sp)
111 ldw r22, SW_R22(sp)
112 ldw r23, SW_R23(sp)
113 ldw fp, SW_FP(sp)
114 ldw gp, SW_GP(sp)
115 ldw ra, SW_RA(sp)
116 addi sp, sp, SWITCH_STACK_SIZE
117.endm
118
119#endif /* __ASSEMBLY__ */
120#endif /* _ASM_NIOS2_ENTRY_H */
diff --git a/arch/nios2/include/asm/io.h b/arch/nios2/include/asm/io.h
new file mode 100644
index 000000000000..9102bfd3fa1c
--- /dev/null
+++ b/arch/nios2/include/asm/io.h
@@ -0,0 +1,61 @@
1/*
2 * Copyright (C) 2014 Altera Corporation
3 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
4 * Copyright (C) 2004 Microtronix Datacom Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#ifndef _ASM_NIOS2_IO_H
12#define _ASM_NIOS2_IO_H
13
14#include <linux/types.h>
15#include <asm/pgtable-bits.h>
16
17/* PCI is not supported in nios2, set this to 0. */
18#define IO_SPACE_LIMIT 0
19
20#define readb_relaxed(addr) readb(addr)
21#define readw_relaxed(addr) readw(addr)
22#define readl_relaxed(addr) readl(addr)
23
24#define writeb_relaxed(x, addr) writeb(x, addr)
25#define writew_relaxed(x, addr) writew(x, addr)
26#define writel_relaxed(x, addr) writel(x, addr)
27
28extern void __iomem *__ioremap(unsigned long physaddr, unsigned long size,
29 unsigned long cacheflag);
30extern void __iounmap(void __iomem *addr);
31
32static inline void __iomem *ioremap(unsigned long physaddr, unsigned long size)
33{
34 return __ioremap(physaddr, size, 0);
35}
36
37static inline void __iomem *ioremap_nocache(unsigned long physaddr,
38 unsigned long size)
39{
40 return __ioremap(physaddr, size, 0);
41}
42
43static inline void iounmap(void __iomem *addr)
44{
45 __iounmap(addr);
46}
47
48/* Pages to physical address... */
49#define page_to_phys(page) virt_to_phys(page_to_virt(page))
50#define page_to_bus(page) page_to_virt(page)
51
52/* Macros used for converting between virtual and physical mappings. */
53#define phys_to_virt(vaddr) \
54 ((void *)((unsigned long)(vaddr) | CONFIG_NIOS2_KERNEL_REGION_BASE))
55/* Clear top 3 bits */
56#define virt_to_phys(vaddr) \
57 ((unsigned long)((unsigned long)(vaddr) & ~0xE0000000))
58
59#include <asm-generic/io.h>
60
61#endif /* _ASM_NIOS2_IO_H */
diff --git a/arch/nios2/include/asm/irq.h b/arch/nios2/include/asm/irq.h
new file mode 100644
index 000000000000..8e40fd94a36c
--- /dev/null
+++ b/arch/nios2/include/asm/irq.h
@@ -0,0 +1,28 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#ifndef _ASM_NIOS2_IRQ_H
21#define _ASM_NIOS2_IRQ_H
22
23#define NIOS2_CPU_NR_IRQS 32
24
25#include <asm-generic/irq.h>
26#include <linux/irqdomain.h>
27
28#endif
diff --git a/arch/nios2/include/asm/irqflags.h b/arch/nios2/include/asm/irqflags.h
new file mode 100644
index 000000000000..75ab92e639f8
--- /dev/null
+++ b/arch/nios2/include/asm/irqflags.h
@@ -0,0 +1,72 @@
1/*
2 * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18#ifndef _ASM_IRQFLAGS_H
19#define _ASM_IRQFLAGS_H
20
21#include <asm/registers.h>
22
23static inline unsigned long arch_local_save_flags(void)
24{
25 return RDCTL(CTL_STATUS);
26}
27
28/*
29 * This will restore ALL status register flags, not only the interrupt
30 * mask flag.
31 */
32static inline void arch_local_irq_restore(unsigned long flags)
33{
34 WRCTL(CTL_STATUS, flags);
35}
36
37static inline void arch_local_irq_disable(void)
38{
39 unsigned long flags;
40
41 flags = arch_local_save_flags();
42 arch_local_irq_restore(flags & ~STATUS_PIE);
43}
44
45static inline void arch_local_irq_enable(void)
46{
47 unsigned long flags;
48
49 flags = arch_local_save_flags();
50 arch_local_irq_restore(flags | STATUS_PIE);
51}
52
53static inline int arch_irqs_disabled_flags(unsigned long flags)
54{
55 return (flags & STATUS_PIE) == 0;
56}
57
58static inline int arch_irqs_disabled(void)
59{
60 return arch_irqs_disabled_flags(arch_local_save_flags());
61}
62
63static inline unsigned long arch_local_irq_save(void)
64{
65 unsigned long flags;
66
67 flags = arch_local_save_flags();
68 arch_local_irq_restore(flags & ~STATUS_PIE);
69 return flags;
70}
71
72#endif /* _ASM_IRQFLAGS_H */
diff --git a/arch/nios2/include/asm/linkage.h b/arch/nios2/include/asm/linkage.h
new file mode 100644
index 000000000000..e0c6decd7d58
--- /dev/null
+++ b/arch/nios2/include/asm/linkage.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2009 Thomas Chou <thomas@wytron.com.tw>
3 *
4 * All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
15 * details.
16 */
17
18#ifndef _ASM_NIOS2_LINKAGE_H
19#define _ASM_NIOS2_LINKAGE_H
20
21/* This file is required by include/linux/linkage.h */
22#define __ALIGN .align 4
23#define __ALIGN_STR ".align 4"
24
25#endif
diff --git a/arch/nios2/include/asm/mmu.h b/arch/nios2/include/asm/mmu.h
new file mode 100644
index 000000000000..d9c0b1010f26
--- /dev/null
+++ b/arch/nios2/include/asm/mmu.h
@@ -0,0 +1,16 @@
1/*
2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd.
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#ifndef _ASM_NIOS2_MMU_H
11#define _ASM_NIOS2_MMU_H
12
13/* Default "unsigned long" context */
14typedef unsigned long mm_context_t;
15
16#endif /* _ASM_NIOS2_MMU_H */
diff --git a/arch/nios2/include/asm/mmu_context.h b/arch/nios2/include/asm/mmu_context.h
new file mode 100644
index 000000000000..294b4b1f81d4
--- /dev/null
+++ b/arch/nios2/include/asm/mmu_context.h
@@ -0,0 +1,66 @@
1/*
2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 1996, 1997, 1998, 1999 by Ralf Baechle
4 * Copyright (C) 1999 Silicon Graphics, Inc.
5 *
6 * based on MIPS asm/mmu_context.h
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12
13#ifndef _ASM_NIOS2_MMU_CONTEXT_H
14#define _ASM_NIOS2_MMU_CONTEXT_H
15
16#include <asm-generic/mm_hooks.h>
17
18extern void mmu_context_init(void);
19extern unsigned long get_pid_from_context(mm_context_t *ctx);
20
21/*
22 * For the fast tlb miss handlers, we keep a pointer to the current pgd.
23 * processor.
24 */
25extern pgd_t *pgd_current;
26
27static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
28{
29}
30
31/*
32 * Initialize the context related info for a new mm_struct instance.
33 *
34 * Set all new contexts to 0, that way the generation will never match
35 * the currently running generation when this context is switched in.
36 */
37static inline int init_new_context(struct task_struct *tsk,
38 struct mm_struct *mm)
39{
40 mm->context = 0;
41 return 0;
42}
43
44/*
45 * Destroy context related info for an mm_struct that is about
46 * to be put to rest.
47 */
48static inline void destroy_context(struct mm_struct *mm)
49{
50}
51
52void switch_mm(struct mm_struct *prev, struct mm_struct *next,
53 struct task_struct *tsk);
54
55static inline void deactivate_mm(struct task_struct *tsk,
56 struct mm_struct *mm)
57{
58}
59
60/*
61 * After we have set current->mm to a new value, this activates
62 * the context for the new mm so we see the new mappings.
63 */
64void activate_mm(struct mm_struct *prev, struct mm_struct *next);
65
66#endif /* _ASM_NIOS2_MMU_CONTEXT_H */
diff --git a/arch/nios2/include/asm/mutex.h b/arch/nios2/include/asm/mutex.h
new file mode 100644
index 000000000000..ff6101aa2c71
--- /dev/null
+++ b/arch/nios2/include/asm/mutex.h
@@ -0,0 +1 @@
#include <asm-generic/mutex-dec.h>
diff --git a/arch/nios2/include/asm/page.h b/arch/nios2/include/asm/page.h
new file mode 100644
index 000000000000..4b32d6fd9d98
--- /dev/null
+++ b/arch/nios2/include/asm/page.h
@@ -0,0 +1,109 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd.
4 *
5 * MMU support based on asm/page.h from mips which is:
6 *
7 * Copyright (C) 1994 - 1999, 2000, 03 Ralf Baechle
8 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 */
14
15#ifndef _ASM_NIOS2_PAGE_H
16#define _ASM_NIOS2_PAGE_H
17
18#include <linux/pfn.h>
19#include <linux/const.h>
20
21/*
22 * PAGE_SHIFT determines the page size
23 */
24#define PAGE_SHIFT 12
25#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
26#define PAGE_MASK (~(PAGE_SIZE - 1))
27
28/*
29 * PAGE_OFFSET -- the first address of the first page of memory.
30 */
31#define PAGE_OFFSET \
32 (CONFIG_NIOS2_MEM_BASE + CONFIG_NIOS2_KERNEL_REGION_BASE)
33
34#ifndef __ASSEMBLY__
35
36/*
37 * This gives the physical RAM offset.
38 */
39#define PHYS_OFFSET CONFIG_NIOS2_MEM_BASE
40
41/*
42 * It's normally defined only for FLATMEM config but it's
43 * used in our early mem init code for all memory models.
44 * So always define it.
45 */
46#define ARCH_PFN_OFFSET PFN_UP(PHYS_OFFSET)
47
48#define clear_page(page) memset((page), 0, PAGE_SIZE)
49#define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
50
51struct page;
52
53extern void clear_user_page(void *addr, unsigned long vaddr, struct page *page);
54extern void copy_user_page(void *vto, void *vfrom, unsigned long vaddr,
55 struct page *to);
56
57/*
58 * These are used to make use of C type-checking.
59 */
60typedef struct page *pgtable_t;
61typedef struct { unsigned long pte; } pte_t;
62typedef struct { unsigned long pgd; } pgd_t;
63typedef struct { unsigned long pgprot; } pgprot_t;
64
65#define pte_val(x) ((x).pte)
66#define pgd_val(x) ((x).pgd)
67#define pgprot_val(x) ((x).pgprot)
68
69#define __pte(x) ((pte_t) { (x) })
70#define __pgd(x) ((pgd_t) { (x) })
71#define __pgprot(x) ((pgprot_t) { (x) })
72
73extern unsigned long memory_start;
74extern unsigned long memory_end;
75extern unsigned long memory_size;
76
77extern struct page *mem_map;
78
79#endif /* !__ASSEMBLY__ */
80
81# define __pa(x) \
82 ((unsigned long)(x) - PAGE_OFFSET + PHYS_OFFSET)
83# define __va(x) \
84 ((void *)((unsigned long)(x) + PAGE_OFFSET - PHYS_OFFSET))
85
86#define page_to_virt(page) \
87 ((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET)
88
89# define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
90# define pfn_valid(pfn) ((pfn) >= ARCH_PFN_OFFSET && \
91 (pfn) < max_mapnr)
92
93# define virt_to_page(vaddr) pfn_to_page(PFN_DOWN(virt_to_phys(vaddr)))
94# define virt_addr_valid(vaddr) pfn_valid(PFN_DOWN(virt_to_phys(vaddr)))
95
96# define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | \
97 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
98
99# define UNCAC_ADDR(addr) \
100 ((void *)((unsigned)(addr) | CONFIG_NIOS2_IO_REGION_BASE))
101# define CAC_ADDR(addr) \
102 ((void *)(((unsigned)(addr) & ~CONFIG_NIOS2_IO_REGION_BASE) | \
103 CONFIG_NIOS2_KERNEL_REGION_BASE))
104
105#include <asm-generic/memory_model.h>
106
107#include <asm-generic/getorder.h>
108
109#endif /* _ASM_NIOS2_PAGE_H */
diff --git a/arch/nios2/include/asm/pgalloc.h b/arch/nios2/include/asm/pgalloc.h
new file mode 100644
index 000000000000..6e2985e0a7b9
--- /dev/null
+++ b/arch/nios2/include/asm/pgalloc.h
@@ -0,0 +1,86 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 1994 - 2001, 2003 by Ralf Baechle
7 * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
8 */
9
10#ifndef _ASM_NIOS2_PGALLOC_H
11#define _ASM_NIOS2_PGALLOC_H
12
13#include <linux/mm.h>
14
15static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
16 pte_t *pte)
17{
18 set_pmd(pmd, __pmd((unsigned long)pte));
19}
20
21static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
22 pgtable_t pte)
23{
24 set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
25}
26#define pmd_pgtable(pmd) pmd_page(pmd)
27
28/*
29 * Initialize a new pmd table with invalid pointers.
30 */
31extern void pmd_init(unsigned long page, unsigned long pagetable);
32
33extern pgd_t *pgd_alloc(struct mm_struct *mm);
34
35static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
36{
37 free_pages((unsigned long)pgd, PGD_ORDER);
38}
39
40static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
41 unsigned long address)
42{
43 pte_t *pte;
44
45 pte = (pte_t *) __get_free_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO,
46 PTE_ORDER);
47
48 return pte;
49}
50
51static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
52 unsigned long address)
53{
54 struct page *pte;
55
56 pte = alloc_pages(GFP_KERNEL | __GFP_REPEAT, PTE_ORDER);
57 if (pte) {
58 if (!pgtable_page_ctor(pte)) {
59 __free_page(pte);
60 return NULL;
61 }
62 clear_highpage(pte);
63 }
64 return pte;
65}
66
67static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
68{
69 free_pages((unsigned long)pte, PTE_ORDER);
70}
71
72static inline void pte_free(struct mm_struct *mm, struct page *pte)
73{
74 pgtable_page_dtor(pte);
75 __free_pages(pte, PTE_ORDER);
76}
77
78#define __pte_free_tlb(tlb, pte, addr) \
79 do { \
80 pgtable_page_dtor(pte); \
81 tlb_remove_page((tlb), (pte)); \
82 } while (0)
83
84#define check_pgt_cache() do { } while (0)
85
86#endif /* _ASM_NIOS2_PGALLOC_H */
diff --git a/arch/nios2/include/asm/pgtable-bits.h b/arch/nios2/include/asm/pgtable-bits.h
new file mode 100644
index 000000000000..ce9e7069aa96
--- /dev/null
+++ b/arch/nios2/include/asm/pgtable-bits.h
@@ -0,0 +1,35 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2009 Wind River Systems Inc
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#ifndef _ASM_NIOS2_PGTABLE_BITS_H
11#define _ASM_NIOS2_PGTABLE_BITS_H
12
13/*
14 * These are actual hardware defined protection bits in the tlbacc register
15 * which looks like this:
16 *
17 * 31 30 ... 26 25 24 23 22 21 20 19 18 ... 1 0
18 * ignored........ C R W X G PFN............
19 */
20#define _PAGE_GLOBAL (1<<20)
21#define _PAGE_EXEC (1<<21)
22#define _PAGE_WRITE (1<<22)
23#define _PAGE_READ (1<<23)
24#define _PAGE_CACHED (1<<24) /* C: data access cacheable */
25
26/*
27 * Software defined bits. They are ignored by the hardware and always read back
28 * as zero, but can be written as non-zero.
29 */
30#define _PAGE_PRESENT (1<<25) /* PTE contains a translation */
31#define _PAGE_ACCESSED (1<<26) /* page referenced */
32#define _PAGE_DIRTY (1<<27) /* dirty page */
33#define _PAGE_FILE (1<<28) /* PTE used for file mapping or swap */
34
35#endif /* _ASM_NIOS2_PGTABLE_BITS_H */
diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h
new file mode 100644
index 000000000000..ccbaffd47671
--- /dev/null
+++ b/arch/nios2/include/asm/pgtable.h
@@ -0,0 +1,310 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2009 Wind River Systems Inc
4 *
5 * Based on asm/pgtable-32.h from mips which is:
6 *
7 * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 2003 Ralf Baechle
8 * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 */
14
15#ifndef _ASM_NIOS2_PGTABLE_H
16#define _ASM_NIOS2_PGTABLE_H
17
18#include <linux/io.h>
19#include <linux/bug.h>
20#include <asm/page.h>
21#include <asm/cacheflush.h>
22#include <asm/tlbflush.h>
23
24#include <asm/pgtable-bits.h>
25#include <asm-generic/pgtable-nopmd.h>
26
27#define FIRST_USER_ADDRESS 0
28
29#define VMALLOC_START CONFIG_NIOS2_KERNEL_MMU_REGION_BASE
30#define VMALLOC_END (CONFIG_NIOS2_KERNEL_REGION_BASE - 1)
31
32struct mm_struct;
33
34/* Helper macro */
35#define MKP(x, w, r) __pgprot(_PAGE_PRESENT | _PAGE_CACHED | \
36 ((x) ? _PAGE_EXEC : 0) | \
37 ((r) ? _PAGE_READ : 0) | \
38 ((w) ? _PAGE_WRITE : 0))
39/*
40 * These are the macros that generic kernel code needs
41 * (to populate protection_map[])
42 */
43
44/* Remove W bit on private pages for COW support */
45#define __P000 MKP(0, 0, 0)
46#define __P001 MKP(0, 0, 1)
47#define __P010 MKP(0, 0, 0) /* COW */
48#define __P011 MKP(0, 0, 1) /* COW */
49#define __P100 MKP(1, 0, 0)
50#define __P101 MKP(1, 0, 1)
51#define __P110 MKP(1, 0, 0) /* COW */
52#define __P111 MKP(1, 0, 1) /* COW */
53
54/* Shared pages can have exact HW mapping */
55#define __S000 MKP(0, 0, 0)
56#define __S001 MKP(0, 0, 1)
57#define __S010 MKP(0, 1, 0)
58#define __S011 MKP(0, 1, 1)
59#define __S100 MKP(1, 0, 0)
60#define __S101 MKP(1, 0, 1)
61#define __S110 MKP(1, 1, 0)
62#define __S111 MKP(1, 1, 1)
63
64/* Used all over the kernel */
65#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_CACHED | _PAGE_READ | \
66 _PAGE_WRITE | _PAGE_EXEC | _PAGE_GLOBAL)
67
68#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_CACHED | _PAGE_READ | \
69 _PAGE_WRITE | _PAGE_ACCESSED)
70
71#define PAGE_COPY MKP(0, 0, 1)
72
73#define PGD_ORDER 0
74#define PTE_ORDER 0
75
76#define PTRS_PER_PGD ((PAGE_SIZE << PGD_ORDER) / sizeof(pgd_t))
77#define PTRS_PER_PTE ((PAGE_SIZE << PTE_ORDER) / sizeof(pte_t))
78
79#define USER_PTRS_PER_PGD \
80 (CONFIG_NIOS2_KERNEL_MMU_REGION_BASE / PGDIR_SIZE)
81
82#define PGDIR_SHIFT 22
83#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
84#define PGDIR_MASK (~(PGDIR_SIZE-1))
85
86/*
87 * ZERO_PAGE is a global shared page that is always zero: used
88 * for zero-mapped memory areas etc..
89 */
90extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
91#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
92
93extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
94extern pte_t invalid_pte_table[PAGE_SIZE/sizeof(pte_t)];
95
96/*
97 * (pmds are folded into puds so this doesn't get actually called,
98 * but the define is needed for a generic inline function.)
99 */
100static inline void set_pmd(pmd_t *pmdptr, pmd_t pmdval)
101{
102 pmdptr->pud.pgd.pgd = pmdval.pud.pgd.pgd;
103}
104
105/* to find an entry in a page-table-directory */
106#define pgd_index(addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
107#define pgd_offset(mm, addr) ((mm)->pgd + pgd_index(addr))
108
109static inline int pte_write(pte_t pte) \
110 { return pte_val(pte) & _PAGE_WRITE; }
111static inline int pte_dirty(pte_t pte) \
112 { return pte_val(pte) & _PAGE_DIRTY; }
113static inline int pte_young(pte_t pte) \
114 { return pte_val(pte) & _PAGE_ACCESSED; }
115static inline int pte_file(pte_t pte) \
116 { return pte_val(pte) & _PAGE_FILE; }
117static inline int pte_special(pte_t pte) { return 0; }
118
119#define pgprot_noncached pgprot_noncached
120
121static inline pgprot_t pgprot_noncached(pgprot_t _prot)
122{
123 unsigned long prot = pgprot_val(_prot);
124
125 prot &= ~_PAGE_CACHED;
126
127 return __pgprot(prot);
128}
129
130static inline int pte_none(pte_t pte)
131{
132 return !(pte_val(pte) & ~(_PAGE_GLOBAL|0xf));
133}
134
135static inline int pte_present(pte_t pte) \
136 { return pte_val(pte) & _PAGE_PRESENT; }
137
138/*
139 * The following only work if pte_present() is true.
140 * Undefined behaviour if not..
141 */
142static inline pte_t pte_wrprotect(pte_t pte)
143{
144 pte_val(pte) &= ~_PAGE_WRITE;
145 return pte;
146}
147
148static inline pte_t pte_mkclean(pte_t pte)
149{
150 pte_val(pte) &= ~_PAGE_DIRTY;
151 return pte;
152}
153
154static inline pte_t pte_mkold(pte_t pte)
155{
156 pte_val(pte) &= ~_PAGE_ACCESSED;
157 return pte;
158}
159
160static inline pte_t pte_mkwrite(pte_t pte)
161{
162 pte_val(pte) |= _PAGE_WRITE;
163 return pte;
164}
165
166static inline pte_t pte_mkdirty(pte_t pte)
167{
168 pte_val(pte) |= _PAGE_DIRTY;
169 return pte;
170}
171
172static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
173
174static inline pte_t pte_mkyoung(pte_t pte)
175{
176 pte_val(pte) |= _PAGE_ACCESSED;
177 return pte;
178}
179
180static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
181{
182 const unsigned long mask = _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC;
183
184 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
185 return pte;
186}
187
188static inline int pmd_present(pmd_t pmd)
189{
190 return (pmd_val(pmd) != (unsigned long) invalid_pte_table)
191 && (pmd_val(pmd) != 0UL);
192}
193
194static inline void pmd_clear(pmd_t *pmdp)
195{
196 pmd_val(*pmdp) = (unsigned long) invalid_pte_table;
197}
198
199#define pte_pfn(pte) (pte_val(pte) & 0xfffff)
200#define pfn_pte(pfn, prot) (__pte(pfn | pgprot_val(prot)))
201#define pte_page(pte) (pfn_to_page(pte_pfn(pte)))
202
203/*
204 * Store a linux PTE into the linux page table.
205 */
206static inline void set_pte(pte_t *ptep, pte_t pteval)
207{
208 *ptep = pteval;
209}
210
211static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
212 pte_t *ptep, pte_t pteval)
213{
214 unsigned long paddr = page_to_virt(pte_page(pteval));
215
216 flush_dcache_range(paddr, paddr + PAGE_SIZE);
217 set_pte(ptep, pteval);
218}
219
220static inline int pmd_none(pmd_t pmd)
221{
222 return (pmd_val(pmd) ==
223 (unsigned long) invalid_pte_table) || (pmd_val(pmd) == 0UL);
224}
225
226#define pmd_bad(pmd) (pmd_val(pmd) & ~PAGE_MASK)
227
228static inline void pte_clear(struct mm_struct *mm,
229 unsigned long addr, pte_t *ptep)
230{
231 pte_t null;
232
233 pte_val(null) = (addr >> PAGE_SHIFT) & 0xf;
234
235 set_pte_at(mm, addr, ptep, null);
236 flush_tlb_one(addr);
237}
238
239/*
240 * Conversion functions: convert a page and protection to a page entry,
241 * and a page entry and page directory to the page they refer to.
242 */
243#define mk_pte(page, prot) (pfn_pte(page_to_pfn(page), prot))
244
245#define pte_unmap(pte) do { } while (0)
246
247/*
248 * Conversion functions: convert a page and protection to a page entry,
249 * and a page entry and page directory to the page they refer to.
250 */
251#define pmd_phys(pmd) virt_to_phys((void *)pmd_val(pmd))
252#define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT))
253#define pmd_page_vaddr(pmd) pmd_val(pmd)
254
255#define pte_offset_map(dir, addr) \
256 ((pte_t *) page_address(pmd_page(*dir)) + \
257 (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
258
259/* to find an entry in a kernel page-table-directory */
260#define pgd_offset_k(addr) pgd_offset(&init_mm, addr)
261
262/* Get the address to the PTE for a vaddr in specific directory */
263#define pte_offset_kernel(dir, addr) \
264 ((pte_t *) pmd_page_vaddr(*(dir)) + \
265 (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)))
266
267#define pte_ERROR(e) \
268 pr_err("%s:%d: bad pte %08lx.\n", \
269 __FILE__, __LINE__, pte_val(e))
270#define pgd_ERROR(e) \
271 pr_err("%s:%d: bad pgd %08lx.\n", \
272 __FILE__, __LINE__, pgd_val(e))
273
274/*
275 * Encode and decode a swap entry (must be !pte_none(pte) && !pte_present(pte)
276 * && !pte_file(pte)):
277 *
278 * 31 30 29 28 27 26 25 24 23 22 21 20 19 18 ... 1 0
279 * 0 0 0 0 type. 0 0 0 0 0 0 offset.........
280 *
281 * This gives us up to 2**2 = 4 swap files and 2**20 * 4K = 4G per swap file.
282 *
283 * Note that the offset field is always non-zero, thus !pte_none(pte) is always
284 * true.
285 */
286#define __swp_type(swp) (((swp).val >> 26) & 0x3)
287#define __swp_offset(swp) ((swp).val & 0xfffff)
288#define __swp_entry(type, off) ((swp_entry_t) { (((type) & 0x3) << 26) \
289 | ((off) & 0xfffff) })
290#define __swp_entry_to_pte(swp) ((pte_t) { (swp).val })
291#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
292
293/* Encode and decode a nonlinear file mapping entry */
294#define PTE_FILE_MAX_BITS 25
295#define pte_to_pgoff(pte) (pte_val(pte) & 0x1ffffff)
296#define pgoff_to_pte(off) __pte(((off) & 0x1ffffff) | _PAGE_FILE)
297
298#define kern_addr_valid(addr) (1)
299
300#include <asm-generic/pgtable.h>
301
302#define pgtable_cache_init() do { } while (0)
303
304extern void __init paging_init(void);
305extern void __init mmu_init(void);
306
307extern void update_mmu_cache(struct vm_area_struct *vma,
308 unsigned long address, pte_t *pte);
309
310#endif /* _ASM_NIOS2_PGTABLE_H */
diff --git a/arch/nios2/include/asm/processor.h b/arch/nios2/include/asm/processor.h
new file mode 100644
index 000000000000..3bd349473b06
--- /dev/null
+++ b/arch/nios2/include/asm/processor.h
@@ -0,0 +1,103 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
4 * Copyright (C) 2004 Microtronix Datacom Ltd
5 * Copyright (C) 2001 Ken Hill (khill@microtronix.com)
6 * Vic Phillips (vic@microtronix.com)
7 *
8 * based on SPARC asm/processor_32.h which is:
9 *
10 * Copyright (C) 1994 David S. Miller
11 *
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file "COPYING" in the main directory of this archive
14 * for more details.
15 */
16
17#ifndef _ASM_NIOS2_PROCESSOR_H
18#define _ASM_NIOS2_PROCESSOR_H
19
20#include <asm/ptrace.h>
21#include <asm/registers.h>
22#include <asm/page.h>
23
24#define NIOS2_FLAG_KTHREAD 0x00000001 /* task is a kernel thread */
25
26#define NIOS2_OP_NOP 0x1883a
27#define NIOS2_OP_BREAK 0x3da03a
28
29#ifdef __KERNEL__
30
31#define STACK_TOP TASK_SIZE
32#define STACK_TOP_MAX STACK_TOP
33
34#endif /* __KERNEL__ */
35
36/* Kuser helpers is mapped to this user space address */
37#define KUSER_BASE 0x1000
38#define KUSER_SIZE (PAGE_SIZE)
39#ifndef __ASSEMBLY__
40
41/*
42 * Default implementation of macro that returns current
43 * instruction pointer ("program counter").
44 */
45#define current_text_addr() ({ __label__ _l; _l: &&_l; })
46
47# define TASK_SIZE 0x7FFF0000UL
48# define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
49
50/* The Nios processor specific thread struct. */
51struct thread_struct {
52 struct pt_regs *kregs;
53
54 /* Context switch saved kernel state. */
55 unsigned long ksp;
56 unsigned long kpsr;
57};
58
59#define INIT_MMAP \
60 { &init_mm, (0), (0), __pgprot(0x0), VM_READ | VM_WRITE | VM_EXEC }
61
62# define INIT_THREAD { \
63 .kregs = NULL, \
64 .ksp = 0, \
65 .kpsr = 0, \
66}
67
68extern void start_thread(struct pt_regs *regs, unsigned long pc,
69 unsigned long sp);
70
71struct task_struct;
72
73/* Free all resources held by a thread. */
74static inline void release_thread(struct task_struct *dead_task)
75{
76}
77
78/* Free current thread data structures etc.. */
79static inline void exit_thread(void)
80{
81}
82
83/* Return saved PC of a blocked thread. */
84#define thread_saved_pc(tsk) ((tsk)->thread.kregs->ea)
85
86extern unsigned long get_wchan(struct task_struct *p);
87
88/* Prepare to copy thread state - unlazy all lazy status */
89#define prepare_to_copy(tsk) do { } while (0)
90
91#define task_pt_regs(p) \
92 ((struct pt_regs *)(THREAD_SIZE + task_stack_page(p)) - 1)
93
94/* Used by procfs */
95#define KSTK_EIP(tsk) ((tsk)->thread.kregs->ea)
96#define KSTK_ESP(tsk) ((tsk)->thread.kregs->sp)
97
98#define cpu_relax() barrier()
99#define cpu_relax_lowlatency() cpu_relax()
100
101#endif /* __ASSEMBLY__ */
102
103#endif /* _ASM_NIOS2_PROCESSOR_H */
diff --git a/arch/nios2/include/asm/ptrace.h b/arch/nios2/include/asm/ptrace.h
new file mode 100644
index 000000000000..20fb1cf2dab6
--- /dev/null
+++ b/arch/nios2/include/asm/ptrace.h
@@ -0,0 +1,33 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
4 * Copyright (C) 2004 Microtronix Datacom Ltd
5 *
6 * based on m68k asm/processor.h
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12
13#ifndef _ASM_NIOS2_PTRACE_H
14#define _ASM_NIOS2_PTRACE_H
15
16#include <uapi/asm/ptrace.h>
17
18#ifndef __ASSEMBLY__
19#define user_mode(regs) (((regs)->estatus & ESTATUS_EU))
20
21#define instruction_pointer(regs) ((regs)->ra)
22#define profile_pc(regs) instruction_pointer(regs)
23#define user_stack_pointer(regs) ((regs)->sp)
24extern void show_regs(struct pt_regs *);
25
26#define current_pt_regs() \
27 ((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE)\
28 - 1)
29
30int do_syscall_trace_enter(void);
31void do_syscall_trace_exit(void);
32#endif /* __ASSEMBLY__ */
33#endif /* _ASM_NIOS2_PTRACE_H */
diff --git a/arch/nios2/include/asm/registers.h b/arch/nios2/include/asm/registers.h
new file mode 100644
index 000000000000..615bce19b546
--- /dev/null
+++ b/arch/nios2/include/asm/registers.h
@@ -0,0 +1,71 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19#ifndef _ASM_NIOS2_REGISTERS_H
20#define _ASM_NIOS2_REGISTERS_H
21
22#ifndef __ASSEMBLY__
23#include <asm/cpuinfo.h>
24#endif
25
26/* control register numbers */
27#define CTL_STATUS 0
28#define CTL_ESTATUS 1
29#define CTL_BSTATUS 2
30#define CTL_IENABLE 3
31#define CTL_IPENDING 4
32#define CTL_CPUID 5
33#define CTL_RSV1 6
34#define CTL_EXCEPTION 7
35#define CTL_PTEADDR 8
36#define CTL_TLBACC 9
37#define CTL_TLBMISC 10
38#define CTL_RSV2 11
39#define CTL_BADADDR 12
40#define CTL_CONFIG 13
41#define CTL_MPUBASE 14
42#define CTL_MPUACC 15
43
44/* access control registers using GCC builtins */
45#define RDCTL(r) __builtin_rdctl(r)
46#define WRCTL(r, v) __builtin_wrctl(r, v)
47
48/* status register bits */
49#define STATUS_PIE (1 << 0) /* processor interrupt enable */
50#define STATUS_U (1 << 1) /* user mode */
51#define STATUS_EH (1 << 2) /* Exception mode */
52
53/* estatus register bits */
54#define ESTATUS_EPIE (1 << 0) /* processor interrupt enable */
55#define ESTATUS_EU (1 << 1) /* user mode */
56#define ESTATUS_EH (1 << 2) /* Exception mode */
57
58/* tlbmisc register bits */
59#define TLBMISC_PID_SHIFT 4
60#ifndef __ASSEMBLY__
61#define TLBMISC_PID_MASK ((1UL << cpuinfo.tlb_pid_num_bits) - 1)
62#endif
63#define TLBMISC_WAY_MASK 0xf
64#define TLBMISC_WAY_SHIFT 20
65
66#define TLBMISC_PID (TLBMISC_PID_MASK << TLBMISC_PID_SHIFT) /* TLB PID */
67#define TLBMISC_WE (1 << 18) /* TLB write enable */
68#define TLBMISC_RD (1 << 19) /* TLB read */
69#define TLBMISC_WAY (TLBMISC_WAY_MASK << TLBMISC_WAY_SHIFT) /* TLB way */
70
71#endif /* _ASM_NIOS2_REGISTERS_H */
diff --git a/arch/nios2/include/asm/setup.h b/arch/nios2/include/asm/setup.h
new file mode 100644
index 000000000000..dcbf8cf1a344
--- /dev/null
+++ b/arch/nios2/include/asm/setup.h
@@ -0,0 +1,38 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19#ifndef _ASM_NIOS2_SETUP_H
20#define _ASM_NIOS2_SETUP_H
21
22#include <asm-generic/setup.h>
23
24#ifndef __ASSEMBLY__
25#ifdef __KERNEL__
26
27extern char exception_handler_hook[];
28extern char fast_handler[];
29extern char fast_handler_end[];
30
31extern void pagetable_init(void);
32
33extern void setup_early_printk(void);
34
35#endif/* __KERNEL__ */
36#endif /* __ASSEMBLY__ */
37
38#endif /* _ASM_NIOS2_SETUP_H */
diff --git a/arch/nios2/include/asm/signal.h b/arch/nios2/include/asm/signal.h
new file mode 100644
index 000000000000..bbcf11eecb01
--- /dev/null
+++ b/arch/nios2/include/asm/signal.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright Altera Corporation (C) 2013. All rights reserved
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17#ifndef _NIOS2_SIGNAL_H
18#define _NIOS2_SIGNAL_H
19
20#include <uapi/asm/signal.h>
21
22#endif /* _NIOS2_SIGNAL_H */
diff --git a/arch/nios2/include/asm/string.h b/arch/nios2/include/asm/string.h
new file mode 100644
index 000000000000..14dd570d64f7
--- /dev/null
+++ b/arch/nios2/include/asm/string.h
@@ -0,0 +1,24 @@
1/*
2 * Copyright (C) 2004 Microtronix Datacom Ltd
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 */
8
9#ifndef _ASM_NIOS2_STRING_H
10#define _ASM_NIOS2_STRING_H
11
12#ifdef __KERNEL__
13
14#define __HAVE_ARCH_MEMSET
15#define __HAVE_ARCH_MEMCPY
16#define __HAVE_ARCH_MEMMOVE
17
18extern void *memset(void *s, int c, size_t count);
19extern void *memcpy(void *d, const void *s, size_t count);
20extern void *memmove(void *d, const void *s, size_t count);
21
22#endif /* __KERNEL__ */
23
24#endif /* _ASM_NIOS2_STRING_H */
diff --git a/arch/nios2/include/asm/switch_to.h b/arch/nios2/include/asm/switch_to.h
new file mode 100644
index 000000000000..c47b3f4afbcd
--- /dev/null
+++ b/arch/nios2/include/asm/switch_to.h
@@ -0,0 +1,31 @@
1/*
2 * Copyright (C) 2004 Microtronix Datacom Ltd.
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 */
8#ifndef _ASM_NIOS2_SWITCH_TO_H
9#define _ASM_NIOS2_SWITCH_TO_H
10
11/*
12 * switch_to(n) should switch tasks to task ptr, first checking that
13 * ptr isn't the current task, in which case it does nothing. This
14 * also clears the TS-flag if the task we switched to has used the
15 * math co-processor latest.
16 */
17#define switch_to(prev, next, last) \
18{ \
19 void *_last; \
20 __asm__ __volatile__ ( \
21 "mov r4, %1\n" \
22 "mov r5, %2\n" \
23 "call resume\n" \
24 "mov %0,r4\n" \
25 : "=r" (_last) \
26 : "r" (prev), "r" (next) \
27 : "r4", "r5", "r7", "r8", "ra"); \
28 (last) = _last; \
29}
30
31#endif /* _ASM_NIOS2_SWITCH_TO_H */
diff --git a/arch/nios2/include/asm/syscall.h b/arch/nios2/include/asm/syscall.h
new file mode 100644
index 000000000000..9de220854c4a
--- /dev/null
+++ b/arch/nios2/include/asm/syscall.h
@@ -0,0 +1,138 @@
1/*
2 * Copyright Altera Corporation (C) <2014>. All rights reserved
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef __ASM_NIOS2_SYSCALL_H__
18#define __ASM_NIOS2_SYSCALL_H__
19
20#include <linux/err.h>
21#include <linux/sched.h>
22
23static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
24{
25 return regs->r2;
26}
27
28static inline void syscall_rollback(struct task_struct *task,
29 struct pt_regs *regs)
30{
31 regs->r2 = regs->orig_r2;
32 regs->r7 = regs->orig_r7;
33}
34
35static inline long syscall_get_error(struct task_struct *task,
36 struct pt_regs *regs)
37{
38 return regs->r7 ? regs->r2 : 0;
39}
40
41static inline long syscall_get_return_value(struct task_struct *task,
42 struct pt_regs *regs)
43{
44 return regs->r2;
45}
46
47static inline void syscall_set_return_value(struct task_struct *task,
48 struct pt_regs *regs, int error, long val)
49{
50 if (error) {
51 /* error < 0, but nios2 uses > 0 return value */
52 regs->r2 = -error;
53 regs->r7 = 1;
54 } else {
55 regs->r2 = val;
56 regs->r7 = 0;
57 }
58}
59
60static inline void syscall_get_arguments(struct task_struct *task,
61 struct pt_regs *regs, unsigned int i, unsigned int n,
62 unsigned long *args)
63{
64 BUG_ON(i + n > 6);
65
66 switch (i) {
67 case 0:
68 if (!n--)
69 break;
70 *args++ = regs->r4;
71 case 1:
72 if (!n--)
73 break;
74 *args++ = regs->r5;
75 case 2:
76 if (!n--)
77 break;
78 *args++ = regs->r6;
79 case 3:
80 if (!n--)
81 break;
82 *args++ = regs->r7;
83 case 4:
84 if (!n--)
85 break;
86 *args++ = regs->r8;
87 case 5:
88 if (!n--)
89 break;
90 *args++ = regs->r9;
91 case 6:
92 if (!n--)
93 break;
94 default:
95 BUG();
96 }
97}
98
99static inline void syscall_set_arguments(struct task_struct *task,
100 struct pt_regs *regs, unsigned int i, unsigned int n,
101 const unsigned long *args)
102{
103 BUG_ON(i + n > 6);
104
105 switch (i) {
106 case 0:
107 if (!n--)
108 break;
109 regs->r4 = *args++;
110 case 1:
111 if (!n--)
112 break;
113 regs->r5 = *args++;
114 case 2:
115 if (!n--)
116 break;
117 regs->r6 = *args++;
118 case 3:
119 if (!n--)
120 break;
121 regs->r7 = *args++;
122 case 4:
123 if (!n--)
124 break;
125 regs->r8 = *args++;
126 case 5:
127 if (!n--)
128 break;
129 regs->r9 = *args++;
130 case 6:
131 if (!n)
132 break;
133 default:
134 BUG();
135 }
136}
137
138#endif
diff --git a/arch/nios2/include/asm/syscalls.h b/arch/nios2/include/asm/syscalls.h
new file mode 100644
index 000000000000..0245d780351b
--- /dev/null
+++ b/arch/nios2/include/asm/syscalls.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright Altera Corporation (C) 2013. All rights reserved
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17#ifndef __ASM_NIOS2_SYSCALLS_H
18#define __ASM_NIOS2_SYSCALLS_H
19
20int sys_cacheflush(unsigned long addr, unsigned long len,
21 unsigned int op);
22
23#include <asm-generic/syscalls.h>
24
25#endif /* __ASM_NIOS2_SYSCALLS_H */
diff --git a/arch/nios2/include/asm/thread_info.h b/arch/nios2/include/asm/thread_info.h
new file mode 100644
index 000000000000..1f266575beb5
--- /dev/null
+++ b/arch/nios2/include/asm/thread_info.h
@@ -0,0 +1,120 @@
1/*
2 * NiosII low-level thread information
3 *
4 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
5 * Copyright (C) 2004 Microtronix Datacom Ltd.
6 *
7 * Based on asm/thread_info_no.h from m68k which is:
8 *
9 * Copyright (C) 2002 David Howells <dhowells@redhat.com>
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 */
15
16#ifndef _ASM_NIOS2_THREAD_INFO_H
17#define _ASM_NIOS2_THREAD_INFO_H
18
19#ifdef __KERNEL__
20
21/*
22 * Size of the kernel stack for each process.
23 */
24#define THREAD_SIZE_ORDER 1
25#define THREAD_SIZE 8192 /* 2 * PAGE_SIZE */
26
27#ifndef __ASSEMBLY__
28
29typedef struct {
30 unsigned long seg;
31} mm_segment_t;
32
33/*
34 * low level task data that entry.S needs immediate access to
35 * - this struct should fit entirely inside of one cache line
36 * - this struct shares the supervisor stack pages
37 * - if the contents of this structure are changed, the assembly constants
38 * must also be changed
39 */
40struct thread_info {
41 struct task_struct *task; /* main task structure */
42 struct exec_domain *exec_domain; /* execution domain */
43 unsigned long flags; /* low level flags */
44 __u32 cpu; /* current CPU */
45 int preempt_count; /* 0 => preemptable,<0 => BUG */
46 mm_segment_t addr_limit; /* thread address space:
47 0-0x7FFFFFFF for user-thead
48 0-0xFFFFFFFF for kernel-thread
49 */
50 struct restart_block restart_block;
51 struct pt_regs *regs;
52};
53
54/*
55 * macros/functions for gaining access to the thread information structure
56 *
57 * preempt_count needs to be 1 initially, until the scheduler is functional.
58 */
59#define INIT_THREAD_INFO(tsk) \
60{ \
61 .task = &tsk, \
62 .exec_domain = &default_exec_domain, \
63 .flags = 0, \
64 .cpu = 0, \
65 .preempt_count = INIT_PREEMPT_COUNT, \
66 .addr_limit = KERNEL_DS, \
67 .restart_block = { \
68 .fn = do_no_restart_syscall, \
69 }, \
70}
71
72#define init_thread_info (init_thread_union.thread_info)
73#define init_stack (init_thread_union.stack)
74
75/* how to get the thread information struct from C */
76static inline struct thread_info *current_thread_info(void)
77{
78 register unsigned long sp asm("sp");
79
80 return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
81}
82#endif /* !__ASSEMBLY__ */
83
84/*
85 * thread information flags
86 * - these are process state flags that various assembly files may need to
87 * access
88 * - pending work-to-be-done flags are in LSW
89 * - other flags in MSW
90 */
91#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
92#define TIF_NOTIFY_RESUME 1 /* resumption notification requested */
93#define TIF_SIGPENDING 2 /* signal pending */
94#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
95#define TIF_MEMDIE 4 /* is terminating due to OOM killer */
96#define TIF_SECCOMP 5 /* secure computing */
97#define TIF_SYSCALL_AUDIT 6 /* syscall auditing active */
98#define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
99
100#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling
101 TIF_NEED_RESCHED */
102
103#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
104#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
105#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
106#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
107#define _TIF_SECCOMP (1 << TIF_SECCOMP)
108#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
109#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
110#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
111
112/* work to do on interrupt/exception return */
113#define _TIF_WORK_MASK 0x0000FFFE
114
115/* work to do on any return to u-space */
116# define _TIF_ALLWORK_MASK 0x0000FFFF
117
118#endif /* __KERNEL__ */
119
120#endif /* _ASM_NIOS2_THREAD_INFO_H */
diff --git a/arch/nios2/include/asm/timex.h b/arch/nios2/include/asm/timex.h
new file mode 100644
index 000000000000..2f2abb28ec2f
--- /dev/null
+++ b/arch/nios2/include/asm/timex.h
@@ -0,0 +1,24 @@
1/* Copyright Altera Corporation (C) 2014. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License, version 2,
5 * as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *
15 */
16
17#ifndef _ASM_NIOS2_TIMEX_H
18#define _ASM_NIOS2_TIMEX_H
19
20typedef unsigned long cycles_t;
21
22extern cycles_t get_cycles(void);
23
24#endif
diff --git a/arch/nios2/include/asm/tlb.h b/arch/nios2/include/asm/tlb.h
new file mode 100644
index 000000000000..d3bc648e08b5
--- /dev/null
+++ b/arch/nios2/include/asm/tlb.h
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2009 Wind River Systems Inc
4 * Copyright (C) 2004 Microtronix Datacom Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#ifndef _ASM_NIOS2_TLB_H
12#define _ASM_NIOS2_TLB_H
13
14#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm)
15
16extern void set_mmu_pid(unsigned long pid);
17
18/*
19 * NiosII doesn't need any special per-pte or per-vma handling, except
20 * we need to flush cache for the area to be unmapped.
21 */
22#define tlb_start_vma(tlb, vma) \
23 do { \
24 if (!tlb->fullmm) \
25 flush_cache_range(vma, vma->vm_start, vma->vm_end); \
26 } while (0)
27
28#define tlb_end_vma(tlb, vma) do { } while (0)
29#define __tlb_remove_tlb_entry(tlb, ptep, address) do { } while (0)
30
31#include <linux/pagemap.h>
32#include <asm-generic/tlb.h>
33
34#endif /* _ASM_NIOS2_TLB_H */
diff --git a/arch/nios2/include/asm/tlbflush.h b/arch/nios2/include/asm/tlbflush.h
new file mode 100644
index 000000000000..e19652fca1c6
--- /dev/null
+++ b/arch/nios2/include/asm/tlbflush.h
@@ -0,0 +1,46 @@
1/*
2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19#ifndef _ASM_NIOS2_TLBFLUSH_H
20#define _ASM_NIOS2_TLBFLUSH_H
21
22struct mm_struct;
23
24/*
25 * TLB flushing:
26 *
27 * - flush_tlb_all() flushes all processes TLB entries
28 * - flush_tlb_mm(mm) flushes the specified mm context TLB entries
29 * - flush_tlb_page(vma, vmaddr) flushes one page
30 * - flush_tlb_range(vma, start, end) flushes a range of pages
31 * - flush_tlb_kernel_range(start, end) flushes a range of kernel pages
32 */
33extern void flush_tlb_all(void);
34extern void flush_tlb_mm(struct mm_struct *mm);
35extern void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
36 unsigned long end);
37extern void flush_tlb_kernel_range(unsigned long start, unsigned long end);
38extern void flush_tlb_one(unsigned long vaddr);
39
40static inline void flush_tlb_page(struct vm_area_struct *vma,
41 unsigned long addr)
42{
43 flush_tlb_one(addr);
44}
45
46#endif /* _ASM_NIOS2_TLBFLUSH_H */
diff --git a/arch/nios2/include/asm/traps.h b/arch/nios2/include/asm/traps.h
new file mode 100644
index 000000000000..82a48473280d
--- /dev/null
+++ b/arch/nios2/include/asm/traps.h
@@ -0,0 +1,19 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd.
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#ifndef _ASM_NIOS2_TRAPS_H
11#define _ASM_NIOS2_TRAPS_H
12
13#define TRAP_ID_SYSCALL 0
14
15#ifndef __ASSEMBLY__
16void _exception(int signo, struct pt_regs *regs, int code, unsigned long addr);
17#endif
18
19#endif /* _ASM_NIOS2_TRAPS_H */
diff --git a/arch/nios2/include/asm/uaccess.h b/arch/nios2/include/asm/uaccess.h
new file mode 100644
index 000000000000..acedc0a2860e
--- /dev/null
+++ b/arch/nios2/include/asm/uaccess.h
@@ -0,0 +1,231 @@
1/*
2 * User space memory access functions for Nios II
3 *
4 * Copyright (C) 2010-2011, Tobias Klauser <tklauser@distanz.ch>
5 * Copyright (C) 2009, Wind River Systems Inc
6 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12
13#ifndef _ASM_NIOS2_UACCESS_H
14#define _ASM_NIOS2_UACCESS_H
15
16#include <linux/errno.h>
17#include <linux/thread_info.h>
18#include <linux/string.h>
19
20#include <asm/page.h>
21
22#define VERIFY_READ 0
23#define VERIFY_WRITE 1
24
25/*
26 * The exception table consists of pairs of addresses: the first is the
27 * address of an instruction that is allowed to fault, and the second is
28 * the address at which the program should continue. No registers are
29 * modified, so it is entirely up to the continuation code to figure out
30 * what to do.
31 *
32 * All the routines below use bits of fixup code that are out of line
33 * with the main instruction path. This means when everything is well,
34 * we don't even have to jump over them. Further, they do not intrude
35 * on our cache or tlb entries.
36 */
37struct exception_table_entry {
38 unsigned long insn;
39 unsigned long fixup;
40};
41
42extern int fixup_exception(struct pt_regs *regs);
43
44/*
45 * Segment stuff
46 */
47#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
48#define USER_DS MAKE_MM_SEG(0x80000000UL)
49#define KERNEL_DS MAKE_MM_SEG(0)
50
51#define get_ds() (KERNEL_DS)
52
53#define get_fs() (current_thread_info()->addr_limit)
54#define set_fs(seg) (current_thread_info()->addr_limit = (seg))
55
56#define segment_eq(a, b) ((a).seg == (b).seg)
57
58#define __access_ok(addr, len) \
59 (((signed long)(((long)get_fs().seg) & \
60 ((long)(addr) | (((long)(addr)) + (len)) | (len)))) == 0)
61
62#define access_ok(type, addr, len) \
63 likely(__access_ok((unsigned long)(addr), (unsigned long)(len)))
64
65# define __EX_TABLE_SECTION ".section __ex_table,\"a\"\n"
66
67/*
68 * Zero Userspace
69 */
70
71static inline unsigned long __must_check __clear_user(void __user *to,
72 unsigned long n)
73{
74 __asm__ __volatile__ (
75 "1: stb zero, 0(%1)\n"
76 " addi %0, %0, -1\n"
77 " addi %1, %1, 1\n"
78 " bne %0, zero, 1b\n"
79 "2:\n"
80 __EX_TABLE_SECTION
81 ".word 1b, 2b\n"
82 ".previous\n"
83 : "=r" (n), "=r" (to)
84 : "0" (n), "1" (to)
85 );
86
87 return n;
88}
89
90static inline unsigned long __must_check clear_user(void __user *to,
91 unsigned long n)
92{
93 if (!access_ok(VERIFY_WRITE, to, n))
94 return n;
95 return __clear_user(to, n);
96}
97
98extern long __copy_from_user(void *to, const void __user *from,
99 unsigned long n);
100extern long __copy_to_user(void __user *to, const void *from, unsigned long n);
101
102static inline long copy_from_user(void *to, const void __user *from,
103 unsigned long n)
104{
105 if (!access_ok(VERIFY_READ, from, n))
106 return n;
107 return __copy_from_user(to, from, n);
108}
109
110static inline long copy_to_user(void __user *to, const void *from,
111 unsigned long n)
112{
113 if (!access_ok(VERIFY_WRITE, to, n))
114 return n;
115 return __copy_to_user(to, from, n);
116}
117
118extern long strncpy_from_user(char *__to, const char __user *__from,
119 long __len);
120extern long strnlen_user(const char __user *s, long n);
121
122#define __copy_from_user_inatomic __copy_from_user
123#define __copy_to_user_inatomic __copy_to_user
124
125/* Optimized macros */
126#define __get_user_asm(val, insn, addr, err) \
127{ \
128 __asm__ __volatile__( \
129 " movi %0, %3\n" \
130 "1: " insn " %1, 0(%2)\n" \
131 " movi %0, 0\n" \
132 "2:\n" \
133 " .section __ex_table,\"a\"\n" \
134 " .word 1b, 2b\n" \
135 " .previous" \
136 : "=&r" (err), "=r" (val) \
137 : "r" (addr), "i" (-EFAULT)); \
138}
139
140#define __get_user_unknown(val, size, ptr, err) do { \
141 err = 0; \
142 if (copy_from_user(&(val), ptr, size)) { \
143 err = -EFAULT; \
144 } \
145 } while (0)
146
147#define __get_user_common(val, size, ptr, err) \
148do { \
149 switch (size) { \
150 case 1: \
151 __get_user_asm(val, "ldbu", ptr, err); \
152 break; \
153 case 2: \
154 __get_user_asm(val, "ldhu", ptr, err); \
155 break; \
156 case 4: \
157 __get_user_asm(val, "ldw", ptr, err); \
158 break; \
159 default: \
160 __get_user_unknown(val, size, ptr, err); \
161 break; \
162 } \
163} while (0)
164
165#define __get_user(x, ptr) \
166 ({ \
167 long __gu_err = -EFAULT; \
168 const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
169 unsigned long __gu_val; \
170 __get_user_common(__gu_val, sizeof(*(ptr)), __gu_ptr, __gu_err);\
171 (x) = (__typeof__(x))__gu_val; \
172 __gu_err; \
173 })
174
175#define get_user(x, ptr) \
176({ \
177 long __gu_err = -EFAULT; \
178 const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
179 unsigned long __gu_val = 0; \
180 if (access_ok(VERIFY_READ, __gu_ptr, sizeof(*__gu_ptr))) \
181 __get_user_common(__gu_val, sizeof(*__gu_ptr), \
182 __gu_ptr, __gu_err); \
183 (x) = (__typeof__(x))__gu_val; \
184 __gu_err; \
185})
186
187#define __put_user_asm(val, insn, ptr, err) \
188{ \
189 __asm__ __volatile__( \
190 " movi %0, %3\n" \
191 "1: " insn " %1, 0(%2)\n" \
192 " movi %0, 0\n" \
193 "2:\n" \
194 " .section __ex_table,\"a\"\n" \
195 " .word 1b, 2b\n" \
196 " .previous\n" \
197 : "=&r" (err) \
198 : "r" (val), "r" (ptr), "i" (-EFAULT)); \
199}
200
201#define put_user(x, ptr) \
202({ \
203 long __pu_err = -EFAULT; \
204 __typeof__(*(ptr)) __user *__pu_ptr = (ptr); \
205 __typeof__(*(ptr)) __pu_val = (__typeof(*ptr))(x); \
206 if (access_ok(VERIFY_WRITE, __pu_ptr, sizeof(*__pu_ptr))) { \
207 switch (sizeof(*__pu_ptr)) { \
208 case 1: \
209 __put_user_asm(__pu_val, "stb", __pu_ptr, __pu_err); \
210 break; \
211 case 2: \
212 __put_user_asm(__pu_val, "sth", __pu_ptr, __pu_err); \
213 break; \
214 case 4: \
215 __put_user_asm(__pu_val, "stw", __pu_ptr, __pu_err); \
216 break; \
217 default: \
218 /* XXX: This looks wrong... */ \
219 __pu_err = 0; \
220 if (copy_to_user(__pu_ptr, &(__pu_val), \
221 sizeof(*__pu_ptr))) \
222 __pu_err = -EFAULT; \
223 break; \
224 } \
225 } \
226 __pu_err; \
227})
228
229#define __put_user(x, ptr) put_user(x, ptr)
230
231#endif /* _ASM_NIOS2_UACCESS_H */
diff --git a/arch/nios2/include/asm/ucontext.h b/arch/nios2/include/asm/ucontext.h
new file mode 100644
index 000000000000..2c87614b0f6e
--- /dev/null
+++ b/arch/nios2/include/asm/ucontext.h
@@ -0,0 +1,32 @@
1/*
2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#ifndef _ASM_NIOS2_UCONTEXT_H
11#define _ASM_NIOS2_UCONTEXT_H
12
13typedef int greg_t;
14#define NGREG 32
15typedef greg_t gregset_t[NGREG];
16
17struct mcontext {
18 int version;
19 gregset_t gregs;
20};
21
22#define MCONTEXT_VERSION 2
23
24struct ucontext {
25 unsigned long uc_flags;
26 struct ucontext *uc_link;
27 stack_t uc_stack;
28 struct mcontext uc_mcontext;
29 sigset_t uc_sigmask; /* mask last for extensibility */
30};
31
32#endif
diff --git a/arch/nios2/include/uapi/asm/Kbuild b/arch/nios2/include/uapi/asm/Kbuild
new file mode 100644
index 000000000000..4f07ca3f8d10
--- /dev/null
+++ b/arch/nios2/include/uapi/asm/Kbuild
@@ -0,0 +1,4 @@
1include include/uapi/asm-generic/Kbuild.asm
2
3header-y += elf.h
4header-y += ucontext.h
diff --git a/arch/nios2/include/uapi/asm/byteorder.h b/arch/nios2/include/uapi/asm/byteorder.h
new file mode 100644
index 000000000000..3ab5dc20d757
--- /dev/null
+++ b/arch/nios2/include/uapi/asm/byteorder.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2009 Thomas Chou <thomas@wytron.com.tw>
3 * Copyright (C) 2004 Microtronix Datacom Ltd
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#ifndef _ASM_NIOS2_BYTEORDER_H
18#define _ASM_NIOS2_BYTEORDER_H
19
20#include <linux/byteorder/little_endian.h>
21
22#endif
diff --git a/arch/nios2/include/uapi/asm/elf.h b/arch/nios2/include/uapi/asm/elf.h
new file mode 100644
index 000000000000..a5b91ae5cf56
--- /dev/null
+++ b/arch/nios2/include/uapi/asm/elf.h
@@ -0,0 +1,67 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19
20#ifndef _UAPI_ASM_NIOS2_ELF_H
21#define _UAPI_ASM_NIOS2_ELF_H
22
23#include <linux/ptrace.h>
24
25/* Relocation types */
26#define R_NIOS2_NONE 0
27#define R_NIOS2_S16 1
28#define R_NIOS2_U16 2
29#define R_NIOS2_PCREL16 3
30#define R_NIOS2_CALL26 4
31#define R_NIOS2_IMM5 5
32#define R_NIOS2_CACHE_OPX 6
33#define R_NIOS2_IMM6 7
34#define R_NIOS2_IMM8 8
35#define R_NIOS2_HI16 9
36#define R_NIOS2_LO16 10
37#define R_NIOS2_HIADJ16 11
38#define R_NIOS2_BFD_RELOC_32 12
39#define R_NIOS2_BFD_RELOC_16 13
40#define R_NIOS2_BFD_RELOC_8 14
41#define R_NIOS2_GPREL 15
42#define R_NIOS2_GNU_VTINHERIT 16
43#define R_NIOS2_GNU_VTENTRY 17
44#define R_NIOS2_UJMP 18
45#define R_NIOS2_CJMP 19
46#define R_NIOS2_CALLR 20
47#define R_NIOS2_ALIGN 21
48/* Keep this the last entry. */
49#define R_NIOS2_NUM 22
50
51typedef unsigned long elf_greg_t;
52
53#define ELF_NGREG \
54 ((sizeof(struct pt_regs) + sizeof(struct switch_stack)) / \
55 sizeof(elf_greg_t))
56typedef elf_greg_t elf_gregset_t[ELF_NGREG];
57
58typedef unsigned long elf_fpregset_t;
59
60/*
61 * These are used to set parameters in the core dumps.
62 */
63#define ELF_CLASS ELFCLASS32
64#define ELF_DATA ELFDATA2LSB
65#define ELF_ARCH EM_ALTERA_NIOS2
66
67#endif /* _UAPI_ASM_NIOS2_ELF_H */
diff --git a/arch/nios2/include/uapi/asm/ptrace.h b/arch/nios2/include/uapi/asm/ptrace.h
new file mode 100644
index 000000000000..e83a7c9d1c36
--- /dev/null
+++ b/arch/nios2/include/uapi/asm/ptrace.h
@@ -0,0 +1,120 @@
1/*
2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd
4 *
5 * based on m68k asm/processor.h
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
12#ifndef _UAPI_ASM_NIOS2_PTRACE_H
13#define _UAPI_ASM_NIOS2_PTRACE_H
14
15#ifndef __ASSEMBLY__
16
17/*
18 * Register numbers used by 'ptrace' system call interface.
19 */
20
21/* GP registers */
22#define PTR_R0 0
23#define PTR_R1 1
24#define PTR_R2 2
25#define PTR_R3 3
26#define PTR_R4 4
27#define PTR_R5 5
28#define PTR_R6 6
29#define PTR_R7 7
30#define PTR_R8 8
31#define PTR_R9 9
32#define PTR_R10 10
33#define PTR_R11 11
34#define PTR_R12 12
35#define PTR_R13 13
36#define PTR_R14 14
37#define PTR_R15 15
38#define PTR_R16 16
39#define PTR_R17 17
40#define PTR_R18 18
41#define PTR_R19 19
42#define PTR_R20 20
43#define PTR_R21 21
44#define PTR_R22 22
45#define PTR_R23 23
46#define PTR_R24 24
47#define PTR_R25 25
48#define PTR_GP 26
49#define PTR_SP 27
50#define PTR_FP 28
51#define PTR_EA 29
52#define PTR_BA 30
53#define PTR_RA 31
54/* Control registers */
55#define PTR_PC 32
56#define PTR_STATUS 33
57#define PTR_ESTATUS 34
58#define PTR_BSTATUS 35
59#define PTR_IENABLE 36
60#define PTR_IPENDING 37
61#define PTR_CPUID 38
62#define PTR_CTL6 39
63#define PTR_CTL7 40
64#define PTR_PTEADDR 41
65#define PTR_TLBACC 42
66#define PTR_TLBMISC 43
67
68#define NUM_PTRACE_REG (PTR_TLBMISC + 1)
69
70/* this struct defines the way the registers are stored on the
71 stack during a system call.
72
73 There is a fake_regs in setup.c that has to match pt_regs.*/
74
75struct pt_regs {
76 unsigned long r8; /* r8-r15 Caller-saved GP registers */
77 unsigned long r9;
78 unsigned long r10;
79 unsigned long r11;
80 unsigned long r12;
81 unsigned long r13;
82 unsigned long r14;
83 unsigned long r15;
84 unsigned long r1; /* Assembler temporary */
85 unsigned long r2; /* Retval LS 32bits */
86 unsigned long r3; /* Retval MS 32bits */
87 unsigned long r4; /* r4-r7 Register arguments */
88 unsigned long r5;
89 unsigned long r6;
90 unsigned long r7;
91 unsigned long orig_r2; /* Copy of r2 ?? */
92 unsigned long ra; /* Return address */
93 unsigned long fp; /* Frame pointer */
94 unsigned long sp; /* Stack pointer */
95 unsigned long gp; /* Global pointer */
96 unsigned long estatus;
97 unsigned long ea; /* Exception return address (pc) */
98 unsigned long orig_r7;
99};
100
101/*
102 * This is the extended stack used by signal handlers and the context
103 * switcher: it's pushed after the normal "struct pt_regs".
104 */
105struct switch_stack {
106 unsigned long r16; /* r16-r23 Callee-saved GP registers */
107 unsigned long r17;
108 unsigned long r18;
109 unsigned long r19;
110 unsigned long r20;
111 unsigned long r21;
112 unsigned long r22;
113 unsigned long r23;
114 unsigned long fp;
115 unsigned long gp;
116 unsigned long ra;
117};
118
119#endif /* __ASSEMBLY__ */
120#endif /* _UAPI_ASM_NIOS2_PTRACE_H */
diff --git a/arch/nios2/include/uapi/asm/sigcontext.h b/arch/nios2/include/uapi/asm/sigcontext.h
new file mode 100644
index 000000000000..7b8bb41867d4
--- /dev/null
+++ b/arch/nios2/include/uapi/asm/sigcontext.h
@@ -0,0 +1,28 @@
1/*
2 * Copyright (C) 2004, Microtronix Datacom Ltd.
3 *
4 * All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
15 * details.
16 */
17
18#ifndef _ASM_NIOS2_SIGCONTEXT_H
19#define _ASM_NIOS2_SIGCONTEXT_H
20
21#include <asm/ptrace.h>
22
23struct sigcontext {
24 struct pt_regs regs;
25 unsigned long sc_mask; /* old sigmask */
26};
27
28#endif
diff --git a/arch/nios2/include/uapi/asm/signal.h b/arch/nios2/include/uapi/asm/signal.h
new file mode 100644
index 000000000000..f29ee6314481
--- /dev/null
+++ b/arch/nios2/include/uapi/asm/signal.h
@@ -0,0 +1,23 @@
1/*
2 * Copyright Altera Corporation (C) 2013. All rights reserved
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17#ifndef _ASM_NIOS2_SIGNAL_H
18#define _ASM_NIOS2_SIGNAL_H
19
20#define SA_RESTORER 0x04000000
21#include <asm-generic/signal.h>
22
23#endif /* _ASM_NIOS2_SIGNAL_H */
diff --git a/arch/nios2/include/uapi/asm/swab.h b/arch/nios2/include/uapi/asm/swab.h
new file mode 100644
index 000000000000..b4e22ebaeb17
--- /dev/null
+++ b/arch/nios2/include/uapi/asm/swab.h
@@ -0,0 +1,37 @@
1/*
2 * Copyright (C) 2012 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2011 Pyramid Technical Consultants, Inc.
4 *
5 * This file is subject to the terms and conditions of the GNU General
6 * Public License. See the file COPYING in the main directory of this
7 * archive for more details.
8 */
9
10#ifndef _ASM_NIOS2_SWAB_H
11#define _ASM_NIOS2_SWAB_H
12
13#include <linux/types.h>
14#include <asm-generic/swab.h>
15
16#ifdef CONFIG_NIOS2_CI_SWAB_SUPPORT
17#ifdef __GNUC__
18
19#define __nios2_swab(x) \
20 __builtin_custom_ini(CONFIG_NIOS2_CI_SWAB_NO, (x))
21
22static inline __attribute__((const)) __u16 __arch_swab16(__u16 x)
23{
24 return (__u16) __nios2_swab(((__u32) x) << 16);
25}
26#define __arch_swab16 __arch_swab16
27
28static inline __attribute__((const)) __u32 __arch_swab32(__u32 x)
29{
30 return (__u32) __nios2_swab(x);
31}
32#define __arch_swab32 __arch_swab32
33
34#endif /* __GNUC__ */
35#endif /* CONFIG_NIOS2_CI_SWAB_SUPPORT */
36
37#endif /* _ASM_NIOS2_SWAB_H */
diff --git a/arch/nios2/include/uapi/asm/unistd.h b/arch/nios2/include/uapi/asm/unistd.h
new file mode 100644
index 000000000000..c4bf79510461
--- /dev/null
+++ b/arch/nios2/include/uapi/asm/unistd.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 #define sys_mmap2 sys_mmap_pgoff
19
20/* Use the standard ABI for syscalls */
21#include <asm-generic/unistd.h>
22
23/* Additional Nios II specific syscalls. */
24#define __NR_cacheflush (__NR_arch_specific_syscall)
25__SYSCALL(__NR_cacheflush, sys_cacheflush)
diff --git a/arch/nios2/kernel/Makefile b/arch/nios2/kernel/Makefile
new file mode 100644
index 000000000000..8ae76823ff93
--- /dev/null
+++ b/arch/nios2/kernel/Makefile
@@ -0,0 +1,24 @@
1#
2# Makefile for the nios2 linux kernel.
3#
4
5extra-y += head.o
6extra-y += vmlinux.lds
7
8obj-y += cpuinfo.o
9obj-y += entry.o
10obj-y += insnemu.o
11obj-y += irq.o
12obj-y += nios2_ksyms.o
13obj-y += process.o
14obj-y += prom.o
15obj-y += ptrace.o
16obj-y += setup.o
17obj-y += signal.o
18obj-y += sys_nios2.o
19obj-y += syscall_table.o
20obj-y += time.o
21obj-y += traps.o
22
23obj-$(CONFIG_MODULES) += module.o
24obj-$(CONFIG_NIOS2_ALIGNMENT_TRAP) += misaligned.o
diff --git a/arch/nios2/kernel/asm-offsets.c b/arch/nios2/kernel/asm-offsets.c
new file mode 100644
index 000000000000..c3ee73c18b71
--- /dev/null
+++ b/arch/nios2/kernel/asm-offsets.c
@@ -0,0 +1,87 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19#include <linux/stddef.h>
20#include <linux/sched.h>
21#include <linux/kernel_stat.h>
22#include <linux/ptrace.h>
23#include <linux/hardirq.h>
24#include <linux/thread_info.h>
25#include <linux/kbuild.h>
26
27int main(void)
28{
29 /* struct task_struct */
30 OFFSET(TASK_THREAD, task_struct, thread);
31 BLANK();
32
33 /* struct thread_struct */
34 OFFSET(THREAD_KSP, thread_struct, ksp);
35 OFFSET(THREAD_KPSR, thread_struct, kpsr);
36 BLANK();
37
38 /* struct pt_regs */
39 OFFSET(PT_ORIG_R2, pt_regs, orig_r2);
40 OFFSET(PT_ORIG_R7, pt_regs, orig_r7);
41
42 OFFSET(PT_R1, pt_regs, r1);
43 OFFSET(PT_R2, pt_regs, r2);
44 OFFSET(PT_R3, pt_regs, r3);
45 OFFSET(PT_R4, pt_regs, r4);
46 OFFSET(PT_R5, pt_regs, r5);
47 OFFSET(PT_R6, pt_regs, r6);
48 OFFSET(PT_R7, pt_regs, r7);
49 OFFSET(PT_R8, pt_regs, r8);
50 OFFSET(PT_R9, pt_regs, r9);
51 OFFSET(PT_R10, pt_regs, r10);
52 OFFSET(PT_R11, pt_regs, r11);
53 OFFSET(PT_R12, pt_regs, r12);
54 OFFSET(PT_R13, pt_regs, r13);
55 OFFSET(PT_R14, pt_regs, r14);
56 OFFSET(PT_R15, pt_regs, r15);
57 OFFSET(PT_EA, pt_regs, ea);
58 OFFSET(PT_RA, pt_regs, ra);
59 OFFSET(PT_FP, pt_regs, fp);
60 OFFSET(PT_SP, pt_regs, sp);
61 OFFSET(PT_GP, pt_regs, gp);
62 OFFSET(PT_ESTATUS, pt_regs, estatus);
63 DEFINE(PT_REGS_SIZE, sizeof(struct pt_regs));
64 BLANK();
65
66 /* struct switch_stack */
67 OFFSET(SW_R16, switch_stack, r16);
68 OFFSET(SW_R17, switch_stack, r17);
69 OFFSET(SW_R18, switch_stack, r18);
70 OFFSET(SW_R19, switch_stack, r19);
71 OFFSET(SW_R20, switch_stack, r20);
72 OFFSET(SW_R21, switch_stack, r21);
73 OFFSET(SW_R22, switch_stack, r22);
74 OFFSET(SW_R23, switch_stack, r23);
75 OFFSET(SW_FP, switch_stack, fp);
76 OFFSET(SW_GP, switch_stack, gp);
77 OFFSET(SW_RA, switch_stack, ra);
78 DEFINE(SWITCH_STACK_SIZE, sizeof(struct switch_stack));
79 BLANK();
80
81 /* struct thread_info */
82 OFFSET(TI_FLAGS, thread_info, flags);
83 OFFSET(TI_PREEMPT_COUNT, thread_info, preempt_count);
84 BLANK();
85
86 return 0;
87}
diff --git a/arch/nios2/kernel/cpuinfo.c b/arch/nios2/kernel/cpuinfo.c
new file mode 100644
index 000000000000..51d5bb90d3e5
--- /dev/null
+++ b/arch/nios2/kernel/cpuinfo.c
@@ -0,0 +1,197 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
4 *
5 * Based on cpuinfo.c from microblaze
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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#include <linux/kernel.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/seq_file.h>
26#include <linux/string.h>
27#include <linux/of.h>
28#include <asm/cpuinfo.h>
29
30struct cpuinfo cpuinfo;
31
32#define err_cpu(x) \
33 pr_err("ERROR: Nios II " x " different for kernel and DTS\n")
34
35static inline u32 fcpu(struct device_node *cpu, const char *n)
36{
37 u32 val = 0;
38
39 of_property_read_u32(cpu, n, &val);
40
41 return val;
42}
43
44static inline u32 fcpu_has(struct device_node *cpu, const char *n)
45{
46 return of_get_property(cpu, n, NULL) ? 1 : 0;
47}
48
49void __init setup_cpuinfo(void)
50{
51 struct device_node *cpu;
52 const char *str;
53 int len;
54
55 cpu = of_find_node_by_type(NULL, "cpu");
56 if (!cpu)
57 panic("%s: No CPU found in devicetree!\n", __func__);
58
59 if (!fcpu_has(cpu, "altr,has-initda"))
60 panic("initda instruction is unimplemented. Please update your "
61 "hardware system to have more than 4-byte line data "
62 "cache\n");
63
64 cpuinfo.cpu_clock_freq = fcpu(cpu, "clock-frequency");
65
66 str = of_get_property(cpu, "altr,implementation", &len);
67 if (str)
68 strlcpy(cpuinfo.cpu_impl, str, sizeof(cpuinfo.cpu_impl));
69 else
70 strcpy(cpuinfo.cpu_impl, "<unknown>");
71
72 cpuinfo.has_div = fcpu_has(cpu, "altr,has-div");
73 cpuinfo.has_mul = fcpu_has(cpu, "altr,has-mul");
74 cpuinfo.has_mulx = fcpu_has(cpu, "altr,has-mulx");
75
76 if (IS_ENABLED(CONFIG_NIOS2_HW_DIV_SUPPORT) && !cpuinfo.has_div)
77 err_cpu("DIV");
78
79 if (IS_ENABLED(CONFIG_NIOS2_HW_MUL_SUPPORT) && !cpuinfo.has_mul)
80 err_cpu("MUL");
81
82 if (IS_ENABLED(CONFIG_NIOS2_HW_MULX_SUPPORT) && !cpuinfo.has_mulx)
83 err_cpu("MULX");
84
85 cpuinfo.tlb_num_ways = fcpu(cpu, "altr,tlb-num-ways");
86 if (!cpuinfo.tlb_num_ways)
87 panic("altr,tlb-num-ways can't be 0. Please check your hardware "
88 "system\n");
89 cpuinfo.icache_line_size = fcpu(cpu, "icache-line-size");
90 cpuinfo.icache_size = fcpu(cpu, "icache-size");
91 if (CONFIG_NIOS2_ICACHE_SIZE != cpuinfo.icache_size)
92 pr_warn("Warning: icache size configuration mismatch "
93 "(0x%x vs 0x%x) of CONFIG_NIOS2_ICACHE_SIZE vs "
94 "device tree icache-size\n",
95 CONFIG_NIOS2_ICACHE_SIZE, cpuinfo.icache_size);
96
97 cpuinfo.dcache_line_size = fcpu(cpu, "dcache-line-size");
98 if (CONFIG_NIOS2_DCACHE_LINE_SIZE != cpuinfo.dcache_line_size)
99 pr_warn("Warning: dcache line size configuration mismatch "
100 "(0x%x vs 0x%x) of CONFIG_NIOS2_DCACHE_LINE_SIZE vs "
101 "device tree dcache-line-size\n",
102 CONFIG_NIOS2_DCACHE_LINE_SIZE, cpuinfo.dcache_line_size);
103 cpuinfo.dcache_size = fcpu(cpu, "dcache-size");
104 if (CONFIG_NIOS2_DCACHE_SIZE != cpuinfo.dcache_size)
105 pr_warn("Warning: dcache size configuration mismatch "
106 "(0x%x vs 0x%x) of CONFIG_NIOS2_DCACHE_SIZE vs "
107 "device tree dcache-size\n",
108 CONFIG_NIOS2_DCACHE_SIZE, cpuinfo.dcache_size);
109
110 cpuinfo.tlb_pid_num_bits = fcpu(cpu, "altr,pid-num-bits");
111 cpuinfo.tlb_num_ways_log2 = ilog2(cpuinfo.tlb_num_ways);
112 cpuinfo.tlb_num_entries = fcpu(cpu, "altr,tlb-num-entries");
113 cpuinfo.tlb_num_lines = cpuinfo.tlb_num_entries / cpuinfo.tlb_num_ways;
114 cpuinfo.tlb_ptr_sz = fcpu(cpu, "altr,tlb-ptr-sz");
115
116 cpuinfo.reset_addr = fcpu(cpu, "altr,reset-addr");
117 cpuinfo.exception_addr = fcpu(cpu, "altr,exception-addr");
118 cpuinfo.fast_tlb_miss_exc_addr = fcpu(cpu, "altr,fast-tlb-miss-addr");
119}
120
121#ifdef CONFIG_PROC_FS
122
123/*
124 * Get CPU information for use by the procfs.
125 */
126static int show_cpuinfo(struct seq_file *m, void *v)
127{
128 int count = 0;
129 const u32 clockfreq = cpuinfo.cpu_clock_freq;
130
131 count = seq_printf(m,
132 "CPU:\t\tNios II/%s\n"
133 "MMU:\t\t%s\n"
134 "FPU:\t\tnone\n"
135 "Clocking:\t%u.%02u MHz\n"
136 "BogoMips:\t%lu.%02lu\n"
137 "Calibration:\t%lu loops\n",
138 cpuinfo.cpu_impl,
139 cpuinfo.mmu ? "present" : "none",
140 clockfreq / 1000000, (clockfreq / 100000) % 10,
141 (loops_per_jiffy * HZ) / 500000,
142 ((loops_per_jiffy * HZ) / 5000) % 100,
143 (loops_per_jiffy * HZ));
144
145 count += seq_printf(m,
146 "HW:\n"
147 " MUL:\t\t%s\n"
148 " MULX:\t\t%s\n"
149 " DIV:\t\t%s\n",
150 cpuinfo.has_mul ? "yes" : "no",
151 cpuinfo.has_mulx ? "yes" : "no",
152 cpuinfo.has_div ? "yes" : "no");
153
154 count += seq_printf(m,
155 "Icache:\t\t%ukB, line length: %u\n",
156 cpuinfo.icache_size >> 10,
157 cpuinfo.icache_line_size);
158
159 count += seq_printf(m,
160 "Dcache:\t\t%ukB, line length: %u\n",
161 cpuinfo.dcache_size >> 10,
162 cpuinfo.dcache_line_size);
163
164 count += seq_printf(m,
165 "TLB:\t\t%u ways, %u entries, %u PID bits\n",
166 cpuinfo.tlb_num_ways,
167 cpuinfo.tlb_num_entries,
168 cpuinfo.tlb_pid_num_bits);
169
170 return 0;
171}
172
173static void *cpuinfo_start(struct seq_file *m, loff_t *pos)
174{
175 unsigned long i = *pos;
176
177 return i < num_possible_cpus() ? (void *) (i + 1) : NULL;
178}
179
180static void *cpuinfo_next(struct seq_file *m, void *v, loff_t *pos)
181{
182 ++*pos;
183 return cpuinfo_start(m, pos);
184}
185
186static void cpuinfo_stop(struct seq_file *m, void *v)
187{
188}
189
190const struct seq_operations cpuinfo_op = {
191 .start = cpuinfo_start,
192 .next = cpuinfo_next,
193 .stop = cpuinfo_stop,
194 .show = show_cpuinfo
195};
196
197#endif /* CONFIG_PROC_FS */
diff --git a/arch/nios2/kernel/entry.S b/arch/nios2/kernel/entry.S
new file mode 100644
index 000000000000..83bca17d1008
--- /dev/null
+++ b/arch/nios2/kernel/entry.S
@@ -0,0 +1,555 @@
1/*
2 * linux/arch/nios2/kernel/entry.S
3 *
4 * Copyright (C) 2013-2014 Altera Corporation
5 * Copyright (C) 2009, Wind River Systems Inc
6 *
7 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
8 *
9 * Copyright (C) 1999-2002, Greg Ungerer (gerg@snapgear.com)
10 * Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>,
11 * Kenneth Albanowski <kjahds@kjahds.com>,
12 * Copyright (C) 2000 Lineo Inc. (www.lineo.com)
13 * Copyright (C) 2004 Microtronix Datacom Ltd.
14 *
15 * This file is subject to the terms and conditions of the GNU General Public
16 * License. See the file "COPYING" in the main directory of this archive
17 * for more details.
18 *
19 * Linux/m68k support by Hamish Macdonald
20 *
21 * 68060 fixes by Jesper Skov
22 * ColdFire support by Greg Ungerer (gerg@snapgear.com)
23 * 5307 fixes by David W. Miller
24 * linux 2.4 support David McCullough <davidm@snapgear.com>
25 */
26
27#include <linux/sys.h>
28#include <linux/linkage.h>
29#include <asm/asm-offsets.h>
30#include <asm/asm-macros.h>
31#include <asm/thread_info.h>
32#include <asm/errno.h>
33#include <asm/setup.h>
34#include <asm/entry.h>
35#include <asm/unistd.h>
36#include <asm/processor.h>
37
38.macro GET_THREAD_INFO reg
39.if THREAD_SIZE & 0xffff0000
40 andhi \reg, sp, %hi(~(THREAD_SIZE-1))
41.else
42 addi \reg, r0, %lo(~(THREAD_SIZE-1))
43 and \reg, \reg, sp
44.endif
45.endm
46
47.macro kuser_cmpxchg_check
48 /*
49 * Make sure our user space atomic helper is restarted if it was
50 * interrupted in a critical region.
51 * ea-4 = address of interrupted insn (ea must be preserved).
52 * sp = saved regs.
53 * cmpxchg_ldw = first critical insn, cmpxchg_stw = last critical insn.
54 * If ea <= cmpxchg_stw and ea > cmpxchg_ldw then saved EA is set to
55 * cmpxchg_ldw + 4.
56 */
57 /* et = cmpxchg_stw + 4 */
58 movui et, (KUSER_BASE + 4 + (cmpxchg_stw - __kuser_helper_start))
59 bgtu ea, et, 1f
60
61 subi et, et, (cmpxchg_stw - cmpxchg_ldw) /* et = cmpxchg_ldw + 4 */
62 bltu ea, et, 1f
63 stw et, PT_EA(sp) /* fix up EA */
64 mov ea, et
651:
66.endm
67
68.section .rodata
69.align 4
70exception_table:
71 .word unhandled_exception /* 0 - Reset */
72 .word unhandled_exception /* 1 - Processor-only Reset */
73 .word external_interrupt /* 2 - Interrupt */
74 .word handle_trap /* 3 - Trap Instruction */
75
76 .word instruction_trap /* 4 - Unimplemented instruction */
77 .word handle_illegal /* 5 - Illegal instruction */
78 .word handle_unaligned /* 6 - Misaligned data access */
79 .word handle_unaligned /* 7 - Misaligned destination address */
80
81 .word handle_diverror /* 8 - Division error */
82 .word protection_exception_ba /* 9 - Supervisor-only instr. address */
83 .word protection_exception_instr /* 10 - Supervisor only instruction */
84 .word protection_exception_ba /* 11 - Supervisor only data address */
85
86 .word unhandled_exception /* 12 - Double TLB miss (data) */
87 .word protection_exception_pte /* 13 - TLB permission violation (x) */
88 .word protection_exception_pte /* 14 - TLB permission violation (r) */
89 .word protection_exception_pte /* 15 - TLB permission violation (w) */
90
91 .word unhandled_exception /* 16 - MPU region violation */
92
93trap_table:
94 .word handle_system_call /* 0 */
95 .word instruction_trap /* 1 */
96 .word instruction_trap /* 2 */
97 .word instruction_trap /* 3 */
98 .word instruction_trap /* 4 */
99 .word instruction_trap /* 5 */
100 .word instruction_trap /* 6 */
101 .word instruction_trap /* 7 */
102 .word instruction_trap /* 8 */
103 .word instruction_trap /* 9 */
104 .word instruction_trap /* 10 */
105 .word instruction_trap /* 11 */
106 .word instruction_trap /* 12 */
107 .word instruction_trap /* 13 */
108 .word instruction_trap /* 14 */
109 .word instruction_trap /* 15 */
110 .word instruction_trap /* 16 */
111 .word instruction_trap /* 17 */
112 .word instruction_trap /* 18 */
113 .word instruction_trap /* 19 */
114 .word instruction_trap /* 20 */
115 .word instruction_trap /* 21 */
116 .word instruction_trap /* 22 */
117 .word instruction_trap /* 23 */
118 .word instruction_trap /* 24 */
119 .word instruction_trap /* 25 */
120 .word instruction_trap /* 26 */
121 .word instruction_trap /* 27 */
122 .word instruction_trap /* 28 */
123 .word instruction_trap /* 29 */
124 .word instruction_trap /* 30 */
125 .word handle_breakpoint /* 31 */
126
127.text
128.set noat
129.set nobreak
130
131ENTRY(inthandler)
132 SAVE_ALL
133
134 kuser_cmpxchg_check
135
136 /* Clear EH bit before we get a new excpetion in the kernel
137 * and after we have saved it to the exception frame. This is done
138 * whether it's trap, tlb-miss or interrupt. If we don't do this
139 * estatus is not updated the next exception.
140 */
141 rdctl r24, status
142 movi r9, %lo(~STATUS_EH)
143 and r24, r24, r9
144 wrctl status, r24
145
146 /* Read cause and vector and branch to the associated handler */
147 mov r4, sp
148 rdctl r5, exception
149 movia r9, exception_table
150 add r24, r9, r5
151 ldw r24, 0(r24)
152 jmp r24
153
154
155/***********************************************************************
156 * Handle traps
157 ***********************************************************************
158 */
159ENTRY(handle_trap)
160 ldw r24, -4(ea) /* instruction that caused the exception */
161 srli r24, r24, 4
162 andi r24, r24, 0x7c
163 movia r9,trap_table
164 add r24, r24, r9
165 ldw r24, 0(r24)
166 jmp r24
167
168
169/***********************************************************************
170 * Handle system calls
171 ***********************************************************************
172 */
173ENTRY(handle_system_call)
174 /* Enable interrupts */
175 rdctl r10, status
176 ori r10, r10, STATUS_PIE
177 wrctl status, r10
178
179 /* Reload registers destroyed by common code. */
180 ldw r4, PT_R4(sp)
181 ldw r5, PT_R5(sp)
182
183local_restart:
184 /* Check that the requested system call is within limits */
185 movui r1, __NR_syscalls
186 bgeu r2, r1, ret_invsyscall
187 slli r1, r2, 2
188 movhi r11, %hiadj(sys_call_table)
189 add r1, r1, r11
190 ldw r1, %lo(sys_call_table)(r1)
191 beq r1, r0, ret_invsyscall
192
193 /* Check if we are being traced */
194 GET_THREAD_INFO r11
195 ldw r11,TI_FLAGS(r11)
196 BTBNZ r11,r11,TIF_SYSCALL_TRACE,traced_system_call
197
198 /* Execute the system call */
199 callr r1
200
201 /* If the syscall returns a negative result:
202 * Set r7 to 1 to indicate error,
203 * Negate r2 to get a positive error code
204 * If the syscall returns zero or a positive value:
205 * Set r7 to 0.
206 * The sigreturn system calls will skip the code below by
207 * adding to register ra. To avoid destroying registers
208 */
209translate_rc_and_ret:
210 movi r1, 0
211 bge r2, zero, 3f
212 sub r2, zero, r2
213 movi r1, 1
2143:
215 stw r2, PT_R2(sp)
216 stw r1, PT_R7(sp)
217end_translate_rc_and_ret:
218
219ret_from_exception:
220 ldw r1, PT_ESTATUS(sp)
221 /* if so, skip resched, signals */
222 TSTBNZ r1, r1, ESTATUS_EU, Luser_return
223
224restore_all:
225 rdctl r10, status /* disable intrs */
226 andi r10, r10, %lo(~STATUS_PIE)
227 wrctl status, r10
228 RESTORE_ALL
229 eret
230
231 /* If the syscall number was invalid return ENOSYS */
232ret_invsyscall:
233 movi r2, -ENOSYS
234 br translate_rc_and_ret
235
236 /* This implements the same as above, except it calls
237 * do_syscall_trace_enter and do_syscall_trace_exit before and after the
238 * syscall in order for utilities like strace and gdb to work.
239 */
240traced_system_call:
241 SAVE_SWITCH_STACK
242 call do_syscall_trace_enter
243 RESTORE_SWITCH_STACK
244
245 /* Create system call register arguments. The 5th and 6th
246 arguments on stack are already in place at the beginning
247 of pt_regs. */
248 ldw r2, PT_R2(sp)
249 ldw r4, PT_R4(sp)
250 ldw r5, PT_R5(sp)
251 ldw r6, PT_R6(sp)
252 ldw r7, PT_R7(sp)
253
254 /* Fetch the syscall function, we don't need to check the boundaries
255 * since this is already done.
256 */
257 slli r1, r2, 2
258 movhi r11,%hiadj(sys_call_table)
259 add r1, r1, r11
260 ldw r1, %lo(sys_call_table)(r1)
261
262 callr r1
263
264 /* If the syscall returns a negative result:
265 * Set r7 to 1 to indicate error,
266 * Negate r2 to get a positive error code
267 * If the syscall returns zero or a positive value:
268 * Set r7 to 0.
269 * The sigreturn system calls will skip the code below by
270 * adding to register ra. To avoid destroying registers
271 */
272translate_rc_and_ret2:
273 movi r1, 0
274 bge r2, zero, 4f
275 sub r2, zero, r2
276 movi r1, 1
2774:
278 stw r2, PT_R2(sp)
279 stw r1, PT_R7(sp)
280end_translate_rc_and_ret2:
281 SAVE_SWITCH_STACK
282 call do_syscall_trace_exit
283 RESTORE_SWITCH_STACK
284 br ret_from_exception
285
286Luser_return:
287 GET_THREAD_INFO r11 /* get thread_info pointer */
288 ldw r10, TI_FLAGS(r11) /* get thread_info->flags */
289 ANDI32 r11, r10, _TIF_WORK_MASK
290 beq r11, r0, restore_all /* Nothing to do */
291 BTBZ r1, r10, TIF_NEED_RESCHED, Lsignal_return
292
293 /* Reschedule work */
294 call schedule
295 br ret_from_exception
296
297Lsignal_return:
298 ANDI32 r1, r10, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
299 beq r1, r0, restore_all
300 mov r4, sp /* pt_regs */
301 SAVE_SWITCH_STACK
302 call do_notify_resume
303 beq r2, r0, no_work_pending
304 RESTORE_SWITCH_STACK
305 /* prepare restart syscall here without leaving kernel */
306 ldw r2, PT_R2(sp) /* reload syscall number in r2 */
307 ldw r4, PT_R4(sp) /* reload syscall arguments r4-r9 */
308 ldw r5, PT_R5(sp)
309 ldw r6, PT_R6(sp)
310 ldw r7, PT_R7(sp)
311 ldw r8, PT_R8(sp)
312 ldw r9, PT_R9(sp)
313 br local_restart /* restart syscall */
314
315no_work_pending:
316 RESTORE_SWITCH_STACK
317 br ret_from_exception
318
319/***********************************************************************
320 * Handle external interrupts.
321 ***********************************************************************
322 */
323/*
324 * This is the generic interrupt handler (for all hardware interrupt
325 * sources). It figures out the vector number and calls the appropriate
326 * interrupt service routine directly.
327 */
328external_interrupt:
329 rdctl r12, ipending
330 rdctl r9, ienable
331 and r12, r12, r9
332 /* skip if no interrupt is pending */
333 beq r12, r0, ret_from_interrupt
334
335 movi r24, -1
336 stw r24, PT_ORIG_R2(sp)
337
338 /*
339 * Process an external hardware interrupt.
340 */
341
342 addi ea, ea, -4 /* re-issue the interrupted instruction */
343 stw ea, PT_EA(sp)
3442: movi r4, %lo(-1) /* Start from bit position 0,
345 highest priority */
346 /* This is the IRQ # for handler call */
3471: andi r10, r12, 1 /* Isolate bit we are interested in */
348 srli r12, r12, 1 /* shift count is costly without hardware
349 multiplier */
350 addi r4, r4, 1
351 beq r10, r0, 1b
352 mov r5, sp /* Setup pt_regs pointer for handler call */
353 call do_IRQ
354 rdctl r12, ipending /* check again if irq still pending */
355 rdctl r9, ienable /* Isolate possible interrupts */
356 and r12, r12, r9
357 bne r12, r0, 2b
358 /* br ret_from_interrupt */ /* fall through to ret_from_interrupt */
359
360ENTRY(ret_from_interrupt)
361 ldw r1, PT_ESTATUS(sp) /* check if returning to kernel */
362 TSTBNZ r1, r1, ESTATUS_EU, Luser_return
363
364#ifdef CONFIG_PREEMPT
365 GET_THREAD_INFO r1
366 ldw r4, TI_PREEMPT_COUNT(r1)
367 bne r4, r0, restore_all
368
369need_resched:
370 ldw r4, TI_FLAGS(r1) /* ? Need resched set */
371 BTBZ r10, r4, TIF_NEED_RESCHED, restore_all
372 ldw r4, PT_ESTATUS(sp) /* ? Interrupts off */
373 andi r10, r4, ESTATUS_EPIE
374 beq r10, r0, restore_all
375 movia r4, PREEMPT_ACTIVE
376 stw r4, TI_PREEMPT_COUNT(r1)
377 rdctl r10, status /* enable intrs again */
378 ori r10, r10 ,STATUS_PIE
379 wrctl status, r10
380 PUSH r1
381 call schedule
382 POP r1
383 mov r4, r0
384 stw r4, TI_PREEMPT_COUNT(r1)
385 rdctl r10, status /* disable intrs */
386 andi r10, r10, %lo(~STATUS_PIE)
387 wrctl status, r10
388 br need_resched
389#else
390 br restore_all
391#endif
392
393/***********************************************************************
394 * A few syscall wrappers
395 ***********************************************************************
396 */
397/*
398 * int clone(unsigned long clone_flags, unsigned long newsp,
399 * int __user * parent_tidptr, int __user * child_tidptr,
400 * int tls_val)
401 */
402ENTRY(sys_clone)
403 SAVE_SWITCH_STACK
404 addi sp, sp, -4
405 stw r7, 0(sp) /* Pass 5th arg thru stack */
406 mov r7, r6 /* 4th arg is 3rd of clone() */
407 mov r6, zero /* 3rd arg always 0 */
408 call do_fork
409 addi sp, sp, 4
410 RESTORE_SWITCH_STACK
411 ret
412
413ENTRY(sys_rt_sigreturn)
414 SAVE_SWITCH_STACK
415 mov r4, sp
416 call do_rt_sigreturn
417 RESTORE_SWITCH_STACK
418 addi ra, ra, (end_translate_rc_and_ret - translate_rc_and_ret)
419 ret
420
421/***********************************************************************
422 * A few other wrappers and stubs
423 ***********************************************************************
424 */
425protection_exception_pte:
426 rdctl r6, pteaddr
427 slli r6, r6, 10
428 call do_page_fault
429 br ret_from_exception
430
431protection_exception_ba:
432 rdctl r6, badaddr
433 call do_page_fault
434 br ret_from_exception
435
436protection_exception_instr:
437 call handle_supervisor_instr
438 br ret_from_exception
439
440handle_breakpoint:
441 call breakpoint_c
442 br ret_from_exception
443
444#ifdef CONFIG_NIOS2_ALIGNMENT_TRAP
445handle_unaligned:
446 SAVE_SWITCH_STACK
447 call handle_unaligned_c
448 RESTORE_SWITCH_STACK
449 br ret_from_exception
450#else
451handle_unaligned:
452 call handle_unaligned_c
453 br ret_from_exception
454#endif
455
456handle_illegal:
457 call handle_illegal_c
458 br ret_from_exception
459
460handle_diverror:
461 call handle_diverror_c
462 br ret_from_exception
463
464/*
465 * Beware - when entering resume, prev (the current task) is
466 * in r4, next (the new task) is in r5, don't change these
467 * registers.
468 */
469ENTRY(resume)
470
471 rdctl r7, status /* save thread status reg */
472 stw r7, TASK_THREAD + THREAD_KPSR(r4)
473
474 andi r7, r7, %lo(~STATUS_PIE) /* disable interrupts */
475 wrctl status, r7
476
477 SAVE_SWITCH_STACK
478 stw sp, TASK_THREAD + THREAD_KSP(r4)/* save kernel stack pointer */
479 ldw sp, TASK_THREAD + THREAD_KSP(r5)/* restore new thread stack */
480 movia r24, _current_thread /* save thread */
481 GET_THREAD_INFO r1
482 stw r1, 0(r24)
483 RESTORE_SWITCH_STACK
484
485 ldw r7, TASK_THREAD + THREAD_KPSR(r5)/* restore thread status reg */
486 wrctl status, r7
487 ret
488
489ENTRY(ret_from_fork)
490 call schedule_tail
491 br ret_from_exception
492
493ENTRY(ret_from_kernel_thread)
494 call schedule_tail
495 mov r4,r17 /* arg */
496 callr r16 /* function */
497 br ret_from_exception
498
499/*
500 * Kernel user helpers.
501 *
502 * Each segment is 64-byte aligned and will be mapped to the <User space>.
503 * New segments (if ever needed) must be added after the existing ones.
504 * This mechanism should be used only for things that are really small and
505 * justified, and not be abused freely.
506 *
507 */
508
509 /* Filling pads with undefined instructions. */
510.macro kuser_pad sym size
511 .if ((. - \sym) & 3)
512 .rept (4 - (. - \sym) & 3)
513 .byte 0
514 .endr
515 .endif
516 .rept ((\size - (. - \sym)) / 4)
517 .word 0xdeadbeef
518 .endr
519.endm
520
521 .align 6
522 .globl __kuser_helper_start
523__kuser_helper_start:
524
525__kuser_helper_version: /* @ 0x1000 */
526 .word ((__kuser_helper_end - __kuser_helper_start) >> 6)
527
528__kuser_cmpxchg: /* @ 0x1004 */
529 /*
530 * r4 pointer to exchange variable
531 * r5 old value
532 * r6 new value
533 */
534cmpxchg_ldw:
535 ldw r2, 0(r4) /* load current value */
536 sub r2, r2, r5 /* compare with old value */
537 bne r2, zero, cmpxchg_ret
538
539 /* We had a match, store the new value */
540cmpxchg_stw:
541 stw r6, 0(r4)
542cmpxchg_ret:
543 ret
544
545 kuser_pad __kuser_cmpxchg, 64
546
547 .globl __kuser_sigtramp
548__kuser_sigtramp:
549 movi r2, __NR_rt_sigreturn
550 trap
551
552 kuser_pad __kuser_sigtramp, 64
553
554 .globl __kuser_helper_end
555__kuser_helper_end:
diff --git a/arch/nios2/kernel/head.S b/arch/nios2/kernel/head.S
new file mode 100644
index 000000000000..372ce4a33018
--- /dev/null
+++ b/arch/nios2/kernel/head.S
@@ -0,0 +1,175 @@
1/*
2 * Copyright (C) 2009 Wind River Systems Inc
3 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
4 * Copyright (C) 2004 Microtronix Datacom Ltd
5 * Copyright (C) 2001 Vic Phillips, Microtronix Datacom Ltd.
6 *
7 * Based on head.S for Altera's Excalibur development board with nios processor
8 *
9 * Based on the following from the Excalibur sdk distribution:
10 * NA_MemoryMap.s, NR_JumpToStart.s, NR_Setup.s, NR_CWPManager.s
11 *
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file "COPYING" in the main directory of this archive
14 * for more details.
15 */
16
17#include <linux/init.h>
18#include <linux/linkage.h>
19#include <asm/thread_info.h>
20#include <asm/processor.h>
21#include <asm/cache.h>
22#include <asm/page.h>
23#include <asm/asm-offsets.h>
24#include <asm/asm-macros.h>
25
26/*
27 * ZERO_PAGE is a special page that is used for zero-initialized
28 * data and COW.
29 */
30.data
31.global empty_zero_page
32.align 12
33empty_zero_page:
34 .space PAGE_SIZE
35
36/*
37 * This global variable is used as an extension to the nios'
38 * STATUS register to emulate a user/supervisor mode.
39 */
40 .data
41 .align 2
42 .set noat
43
44 .global _current_thread
45_current_thread:
46 .long 0
47/*
48 * Input(s): passed from u-boot
49 * r4 - Optional pointer to a board information structure.
50 * r5 - Optional pointer to the physical starting address of the init RAM
51 * disk.
52 * r6 - Optional pointer to the physical ending address of the init RAM
53 * disk.
54 * r7 - Optional pointer to the physical starting address of any kernel
55 * command-line parameters.
56 */
57
58/*
59 * First executable code - detected and jumped to by the ROM bootstrap
60 * if the code resides in flash (looks for "Nios" at offset 0x0c from
61 * the potential executable image).
62 */
63 __HEAD
64ENTRY(_start)
65 wrctl status, r0 /* Disable interrupts */
66
67 /* Initialize all cache lines within the instruction cache */
68 movia r1, NIOS2_ICACHE_SIZE
69 movui r2, NIOS2_ICACHE_LINE_SIZE
70
71icache_init:
72 initi r1
73 sub r1, r1, r2
74 bgt r1, r0, icache_init
75 br 1f
76
77 /*
78 * This is the default location for the exception handler. Code in jump
79 * to our handler
80 */
81ENTRY(exception_handler_hook)
82 movia r24, inthandler
83 jmp r24
84
85ENTRY(fast_handler)
86 nextpc et
87helper:
88 stw r3, r3save - helper(et)
89
90 rdctl r3 , pteaddr
91 srli r3, r3, 12
92 slli r3, r3, 2
93 movia et, pgd_current
94
95 ldw et, 0(et)
96 add r3, et, r3
97 ldw et, 0(r3)
98
99 rdctl r3, pteaddr
100 andi r3, r3, 0xfff
101 add et, r3, et
102 ldw et, 0(et)
103 wrctl tlbacc, et
104 nextpc et
105helper2:
106 ldw r3, r3save - helper2(et)
107 subi ea, ea, 4
108 eret
109r3save:
110 .word 0x0
111ENTRY(fast_handler_end)
112
1131:
114 /*
115 * After the instruction cache is initialized, the data cache must
116 * also be initialized.
117 */
118 movia r1, NIOS2_DCACHE_SIZE
119 movui r2, NIOS2_DCACHE_LINE_SIZE
120
121dcache_init:
122 initd 0(r1)
123 sub r1, r1, r2
124 bgt r1, r0, dcache_init
125
126 nextpc r1 /* Find out where we are */
127chkadr:
128 movia r2, chkadr
129 beq r1, r2,finish_move /* We are running in RAM done */
130 addi r1, r1,(_start - chkadr) /* Source */
131 movia r2, _start /* Destination */
132 movia r3, __bss_start /* End of copy */
133
134loop_move: /* r1: src, r2: dest, r3: last dest */
135 ldw r8, 0(r1) /* load a word from [r1] */
136 stw r8, 0(r2) /* store a word to dest [r2] */
137 flushd 0(r2) /* Flush cache for safety */
138 addi r1, r1, 4 /* inc the src addr */
139 addi r2, r2, 4 /* inc the dest addr */
140 blt r2, r3, loop_move
141
142 movia r1, finish_move /* VMA(_start)->l1 */
143 jmp r1 /* jmp to _start */
144
145finish_move:
146
147 /* Mask off all possible interrupts */
148 wrctl ienable, r0
149
150 /* Clear .bss */
151 movia r2, __bss_start
152 movia r1, __bss_stop
1531:
154 stb r0, 0(r2)
155 addi r2, r2, 1
156 bne r1, r2, 1b
157
158 movia r1, init_thread_union /* set stack at top of the task union */
159 addi sp, r1, THREAD_SIZE
160 movia r2, _current_thread /* Remember current thread */
161 stw r1, 0(r2)
162
163 movia r1, nios2_boot_init /* save args r4-r7 passed from u-boot */
164 callr r1
165
166 movia r1, start_kernel /* call start_kernel as a subroutine */
167 callr r1
168
169 /* If we return from start_kernel, break to the oci debugger and
170 * buggered we are.
171 */
172 break
173
174 /* End of startup code */
175.set at
diff --git a/arch/nios2/kernel/insnemu.S b/arch/nios2/kernel/insnemu.S
new file mode 100644
index 000000000000..1c6b651e770d
--- /dev/null
+++ b/arch/nios2/kernel/insnemu.S
@@ -0,0 +1,592 @@
1/*
2 * Copyright (C) 2003-2013 Altera Corporation
3 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20#include <linux/linkage.h>
21#include <asm/entry.h>
22
23.set noat
24.set nobreak
25
26/*
27* Explicitly allow the use of r1 (the assembler temporary register)
28* within this code. This register is normally reserved for the use of
29* the compiler.
30*/
31
32ENTRY(instruction_trap)
33 ldw r1, PT_R1(sp) // Restore registers
34 ldw r2, PT_R2(sp)
35 ldw r3, PT_R3(sp)
36 ldw r4, PT_R4(sp)
37 ldw r5, PT_R5(sp)
38 ldw r6, PT_R6(sp)
39 ldw r7, PT_R7(sp)
40 ldw r8, PT_R8(sp)
41 ldw r9, PT_R9(sp)
42 ldw r10, PT_R10(sp)
43 ldw r11, PT_R11(sp)
44 ldw r12, PT_R12(sp)
45 ldw r13, PT_R13(sp)
46 ldw r14, PT_R14(sp)
47 ldw r15, PT_R15(sp)
48 ldw ra, PT_RA(sp)
49 ldw fp, PT_FP(sp)
50 ldw gp, PT_GP(sp)
51 ldw et, PT_ESTATUS(sp)
52 wrctl estatus, et
53 ldw ea, PT_EA(sp)
54 ldw et, PT_SP(sp) /* backup sp in et */
55
56 addi sp, sp, PT_REGS_SIZE
57
58 /* INSTRUCTION EMULATION
59 * ---------------------
60 *
61 * Nios II processors generate exceptions for unimplemented instructions.
62 * The routines below emulate these instructions. Depending on the
63 * processor core, the only instructions that might need to be emulated
64 * are div, divu, mul, muli, mulxss, mulxsu, and mulxuu.
65 *
66 * The emulations match the instructions, except for the following
67 * limitations:
68 *
69 * 1) The emulation routines do not emulate the use of the exception
70 * temporary register (et) as a source operand because the exception
71 * handler already has modified it.
72 *
73 * 2) The routines do not emulate the use of the stack pointer (sp) or
74 * the exception return address register (ea) as a destination because
75 * modifying these registers crashes the exception handler or the
76 * interrupted routine.
77 *
78 * Detailed Design
79 * ---------------
80 *
81 * The emulation routines expect the contents of integer registers r0-r31
82 * to be on the stack at addresses sp, 4(sp), 8(sp), ... 124(sp). The
83 * routines retrieve source operands from the stack and modify the
84 * destination register's value on the stack prior to the end of the
85 * exception handler. Then all registers except the destination register
86 * are restored to their previous values.
87 *
88 * The instruction that causes the exception is found at address -4(ea).
89 * The instruction's OP and OPX fields identify the operation to be
90 * performed.
91 *
92 * One instruction, muli, is an I-type instruction that is identified by
93 * an OP field of 0x24.
94 *
95 * muli AAAAA,BBBBB,IIIIIIIIIIIIIIII,-0x24-
96 * 27 22 6 0 <-- LSB of field
97 *
98 * The remaining emulated instructions are R-type and have an OP field
99 * of 0x3a. Their OPX fields identify them.
100 *
101 * R-type AAAAA,BBBBB,CCCCC,XXXXXX,NNNNN,-0x3a-
102 * 27 22 17 11 6 0 <-- LSB of field
103 *
104 *
105 * Opcode Encoding. muli is identified by its OP value. Then OPX & 0x02
106 * is used to differentiate between the division opcodes and the
107 * remaining multiplication opcodes.
108 *
109 * Instruction OP OPX OPX & 0x02
110 * ----------- ---- ---- ----------
111 * muli 0x24
112 * divu 0x3a 0x24 0
113 * div 0x3a 0x25 0
114 * mul 0x3a 0x27 != 0
115 * mulxuu 0x3a 0x07 != 0
116 * mulxsu 0x3a 0x17 != 0
117 * mulxss 0x3a 0x1f != 0
118 */
119
120
121 /*
122 * Save everything on the stack to make it easy for the emulation
123 * routines to retrieve the source register operands.
124 */
125
126 addi sp, sp, -128
127 stw zero, 0(sp) /* Save zero on stack to avoid special case for r0. */
128 stw r1, 4(sp)
129 stw r2, 8(sp)
130 stw r3, 12(sp)
131 stw r4, 16(sp)
132 stw r5, 20(sp)
133 stw r6, 24(sp)
134 stw r7, 28(sp)
135 stw r8, 32(sp)
136 stw r9, 36(sp)
137 stw r10, 40(sp)
138 stw r11, 44(sp)
139 stw r12, 48(sp)
140 stw r13, 52(sp)
141 stw r14, 56(sp)
142 stw r15, 60(sp)
143 stw r16, 64(sp)
144 stw r17, 68(sp)
145 stw r18, 72(sp)
146 stw r19, 76(sp)
147 stw r20, 80(sp)
148 stw r21, 84(sp)
149 stw r22, 88(sp)
150 stw r23, 92(sp)
151 /* Don't bother to save et. It's already been changed. */
152 rdctl r5, estatus
153 stw r5, 100(sp)
154
155 stw gp, 104(sp)
156 stw et, 108(sp) /* et contains previous sp value. */
157 stw fp, 112(sp)
158 stw ea, 116(sp)
159 stw ra, 120(sp)
160
161
162 /*
163 * Split the instruction into its fields. We need 4*A, 4*B, and 4*C as
164 * offsets to the stack pointer for access to the stored register values.
165 */
166 ldw r2,-4(ea) /* r2 = AAAAA,BBBBB,IIIIIIIIIIIIIIII,PPPPPP */
167 roli r3, r2, 7 /* r3 = BBB,IIIIIIIIIIIIIIII,PPPPPP,AAAAA,BB */
168 roli r4, r3, 3 /* r4 = IIIIIIIIIIIIIIII,PPPPPP,AAAAA,BBBBB */
169 roli r5, r4, 2 /* r5 = IIIIIIIIIIIIII,PPPPPP,AAAAA,BBBBB,II */
170 srai r4, r4, 16 /* r4 = (sign-extended) IMM16 */
171 roli r6, r5, 5 /* r6 = XXXX,NNNNN,PPPPPP,AAAAA,BBBBB,CCCCC,XX */
172 andi r2, r2, 0x3f /* r2 = 00000000000000000000000000,PPPPPP */
173 andi r3, r3, 0x7c /* r3 = 0000000000000000000000000,AAAAA,00 */
174 andi r5, r5, 0x7c /* r5 = 0000000000000000000000000,BBBBB,00 */
175 andi r6, r6, 0x7c /* r6 = 0000000000000000000000000,CCCCC,00 */
176
177 /* Now
178 * r2 = OP
179 * r3 = 4*A
180 * r4 = IMM16 (sign extended)
181 * r5 = 4*B
182 * r6 = 4*C
183 */
184
185 /*
186 * Get the operands.
187 *
188 * It is necessary to check for muli because it uses an I-type
189 * instruction format, while the other instructions are have an R-type
190 * format.
191 *
192 * Prepare for either multiplication or division loop.
193 * They both loop 32 times.
194 */
195 movi r14, 32
196
197 add r3, r3, sp /* r3 = address of A-operand. */
198 ldw r3, 0(r3) /* r3 = A-operand. */
199 movi r7, 0x24 /* muli opcode (I-type instruction format) */
200 beq r2, r7, mul_immed /* muli doesn't use the B register as a source */
201
202 add r5, r5, sp /* r5 = address of B-operand. */
203 ldw r5, 0(r5) /* r5 = B-operand. */
204 /* r4 = SSSSSSSSSSSSSSSS,-----IMM16------ */
205 /* IMM16 not needed, align OPX portion */
206 /* r4 = SSSSSSSSSSSSSSSS,CCCCC,-OPX--,00000 */
207 srli r4, r4, 5 /* r4 = 00000,SSSSSSSSSSSSSSSS,CCCCC,-OPX-- */
208 andi r4, r4, 0x3f /* r4 = 00000000000000000000000000,-OPX-- */
209
210 /* Now
211 * r2 = OP
212 * r3 = src1
213 * r5 = src2
214 * r4 = OPX (no longer can be muli)
215 * r6 = 4*C
216 */
217
218
219 /*
220 * Multiply or Divide?
221 */
222 andi r7, r4, 0x02 /* For R-type multiply instructions,
223 OPX & 0x02 != 0 */
224 bne r7, zero, multiply
225
226
227 /* DIVISION
228 *
229 * Divide an unsigned dividend by an unsigned divisor using
230 * a shift-and-subtract algorithm. The example below shows
231 * 43 div 7 = 6 for 8-bit integers. This classic algorithm uses a
232 * single register to store both the dividend and the quotient,
233 * allowing both values to be shifted with a single instruction.
234 *
235 * remainder dividend:quotient
236 * --------- -----------------
237 * initialize 00000000 00101011:
238 * shift 00000000 0101011:_
239 * remainder >= divisor? no 00000000 0101011:0
240 * shift 00000000 101011:0_
241 * remainder >= divisor? no 00000000 101011:00
242 * shift 00000001 01011:00_
243 * remainder >= divisor? no 00000001 01011:000
244 * shift 00000010 1011:000_
245 * remainder >= divisor? no 00000010 1011:0000
246 * shift 00000101 011:0000_
247 * remainder >= divisor? no 00000101 011:00000
248 * shift 00001010 11:00000_
249 * remainder >= divisor? yes 00001010 11:000001
250 * remainder -= divisor - 00000111
251 * ----------
252 * 00000011 11:000001
253 * shift 00000111 1:000001_
254 * remainder >= divisor? yes 00000111 1:0000011
255 * remainder -= divisor - 00000111
256 * ----------
257 * 00000000 1:0000011
258 * shift 00000001 :0000011_
259 * remainder >= divisor? no 00000001 :00000110
260 *
261 * The quotient is 00000110.
262 */
263
264divide:
265 /*
266 * Prepare for division by assuming the result
267 * is unsigned, and storing its "sign" as 0.
268 */
269 movi r17, 0
270
271
272 /* Which division opcode? */
273 xori r7, r4, 0x25 /* OPX of div */
274 bne r7, zero, unsigned_division
275
276
277 /*
278 * OPX is div. Determine and store the sign of the quotient.
279 * Then take the absolute value of both operands.
280 */
281 xor r17, r3, r5 /* MSB contains sign of quotient */
282 bge r3,zero,dividend_is_nonnegative
283 sub r3, zero, r3 /* -r3 */
284dividend_is_nonnegative:
285 bge r5, zero, divisor_is_nonnegative
286 sub r5, zero, r5 /* -r5 */
287divisor_is_nonnegative:
288
289
290unsigned_division:
291 /* Initialize the unsigned-division loop. */
292 movi r13, 0 /* remainder = 0 */
293
294 /* Now
295 * r3 = dividend : quotient
296 * r4 = 0x25 for div, 0x24 for divu
297 * r5 = divisor
298 * r13 = remainder
299 * r14 = loop counter (already initialized to 32)
300 * r17 = MSB contains sign of quotient
301 */
302
303
304 /*
305 * for (count = 32; count > 0; --count)
306 * {
307 */
308divide_loop:
309
310 /*
311 * Division:
312 *
313 * (remainder:dividend:quotient) <<= 1;
314 */
315 slli r13, r13, 1
316 cmplt r7, r3, zero /* r7 = MSB of r3 */
317 or r13, r13, r7
318 slli r3, r3, 1
319
320
321 /*
322 * if (remainder >= divisor)
323 * {
324 * set LSB of quotient
325 * remainder -= divisor;
326 * }
327 */
328 bltu r13, r5, div_skip
329 ori r3, r3, 1
330 sub r13, r13, r5
331div_skip:
332
333 /*
334 * }
335 */
336 subi r14, r14, 1
337 bne r14, zero, divide_loop
338
339
340 /* Now
341 * r3 = quotient
342 * r4 = 0x25 for div, 0x24 for divu
343 * r6 = 4*C
344 * r17 = MSB contains sign of quotient
345 */
346
347
348 /*
349 * Conditionally negate signed quotient. If quotient is unsigned,
350 * the sign already is initialized to 0.
351 */
352 bge r17, zero, quotient_is_nonnegative
353 sub r3, zero, r3 /* -r3 */
354 quotient_is_nonnegative:
355
356
357 /*
358 * Final quotient is in r3.
359 */
360 add r6, r6, sp
361 stw r3, 0(r6) /* write quotient to stack */
362 br restore_registers
363
364
365
366
367 /* MULTIPLICATION
368 *
369 * A "product" is the number that one gets by summing a "multiplicand"
370 * several times. The "multiplier" specifies the number of copies of the
371 * multiplicand that are summed.
372 *
373 * Actual multiplication algorithms don't use repeated addition, however.
374 * Shift-and-add algorithms get the same answer as repeated addition, and
375 * they are faster. To compute the lower half of a product (pppp below)
376 * one shifts the product left before adding in each of the partial
377 * products (a * mmmm) through (d * mmmm).
378 *
379 * To compute the upper half of a product (PPPP below), one adds in the
380 * partial products (d * mmmm) through (a * mmmm), each time following
381 * the add by a right shift of the product.
382 *
383 * mmmm
384 * * abcd
385 * ------
386 * #### = d * mmmm
387 * #### = c * mmmm
388 * #### = b * mmmm
389 * #### = a * mmmm
390 * --------
391 * PPPPpppp
392 *
393 * The example above shows 4 partial products. Computing actual Nios II
394 * products requires 32 partials.
395 *
396 * It is possible to compute the result of mulxsu from the result of
397 * mulxuu because the only difference between the results of these two
398 * opcodes is the value of the partial product associated with the sign
399 * bit of rA.
400 *
401 * mulxsu = mulxuu - (rA < 0) ? rB : 0;
402 *
403 * It is possible to compute the result of mulxss from the result of
404 * mulxsu because the only difference between the results of these two
405 * opcodes is the value of the partial product associated with the sign
406 * bit of rB.
407 *
408 * mulxss = mulxsu - (rB < 0) ? rA : 0;
409 *
410 */
411
412mul_immed:
413 /* Opcode is muli. Change it into mul for remainder of algorithm. */
414 mov r6, r5 /* Field B is dest register, not field C. */
415 mov r5, r4 /* Field IMM16 is src2, not field B. */
416 movi r4, 0x27 /* OPX of mul is 0x27 */
417
418multiply:
419 /* Initialize the multiplication loop. */
420 movi r9, 0 /* mul_product = 0 */
421 movi r10, 0 /* mulxuu_product = 0 */
422 mov r11, r5 /* save original multiplier for mulxsu and mulxss */
423 mov r12, r5 /* mulxuu_multiplier (will be shifted) */
424 movi r16, 1 /* used to create "rori B,A,1" from "ror B,A,r16" */
425
426 /* Now
427 * r3 = multiplicand
428 * r5 = mul_multiplier
429 * r6 = 4 * dest_register (used later as offset to sp)
430 * r7 = temp
431 * r9 = mul_product
432 * r10 = mulxuu_product
433 * r11 = original multiplier
434 * r12 = mulxuu_multiplier
435 * r14 = loop counter (already initialized)
436 * r16 = 1
437 */
438
439
440 /*
441 * for (count = 32; count > 0; --count)
442 * {
443 */
444multiply_loop:
445
446 /*
447 * mul_product <<= 1;
448 * lsb = multiplier & 1;
449 */
450 slli r9, r9, 1
451 andi r7, r12, 1
452
453 /*
454 * if (lsb == 1)
455 * {
456 * mulxuu_product += multiplicand;
457 * }
458 */
459 beq r7, zero, mulx_skip
460 add r10, r10, r3
461 cmpltu r7, r10, r3 /* Save the carry from the MSB of mulxuu_product. */
462 ror r7, r7, r16 /* r7 = 0x80000000 on carry, or else 0x00000000 */
463mulx_skip:
464
465 /*
466 * if (MSB of mul_multiplier == 1)
467 * {
468 * mul_product += multiplicand;
469 * }
470 */
471 bge r5, zero, mul_skip
472 add r9, r9, r3
473mul_skip:
474
475 /*
476 * mulxuu_product >>= 1; logical shift
477 * mul_multiplier <<= 1; done with MSB
478 * mulx_multiplier >>= 1; done with LSB
479 */
480 srli r10, r10, 1
481 or r10, r10, r7 /* OR in the saved carry bit. */
482 slli r5, r5, 1
483 srli r12, r12, 1
484
485
486 /*
487 * }
488 */
489 subi r14, r14, 1
490 bne r14, zero, multiply_loop
491
492
493 /*
494 * Multiply emulation loop done.
495 */
496
497 /* Now
498 * r3 = multiplicand
499 * r4 = OPX
500 * r6 = 4 * dest_register (used later as offset to sp)
501 * r7 = temp
502 * r9 = mul_product
503 * r10 = mulxuu_product
504 * r11 = original multiplier
505 */
506
507
508 /* Calculate address for result from 4 * dest_register */
509 add r6, r6, sp
510
511
512 /*
513 * Select/compute the result based on OPX.
514 */
515
516
517 /* OPX == mul? Then store. */
518 xori r7, r4, 0x27
519 beq r7, zero, store_product
520
521 /* It's one of the mulx.. opcodes. Move over the result. */
522 mov r9, r10
523
524 /* OPX == mulxuu? Then store. */
525 xori r7, r4, 0x07
526 beq r7, zero, store_product
527
528 /* Compute mulxsu
529 *
530 * mulxsu = mulxuu - (rA < 0) ? rB : 0;
531 */
532 bge r3, zero, mulxsu_skip
533 sub r9, r9, r11
534mulxsu_skip:
535
536 /* OPX == mulxsu? Then store. */
537 xori r7, r4, 0x17
538 beq r7, zero, store_product
539
540 /* Compute mulxss
541 *
542 * mulxss = mulxsu - (rB < 0) ? rA : 0;
543 */
544 bge r11,zero,mulxss_skip
545 sub r9, r9, r3
546mulxss_skip:
547 /* At this point, assume that OPX is mulxss, so store*/
548
549
550store_product:
551 stw r9, 0(r6)
552
553
554restore_registers:
555 /* No need to restore r0. */
556 ldw r5, 100(sp)
557 wrctl estatus, r5
558
559 ldw r1, 4(sp)
560 ldw r2, 8(sp)
561 ldw r3, 12(sp)
562 ldw r4, 16(sp)
563 ldw r5, 20(sp)
564 ldw r6, 24(sp)
565 ldw r7, 28(sp)
566 ldw r8, 32(sp)
567 ldw r9, 36(sp)
568 ldw r10, 40(sp)
569 ldw r11, 44(sp)
570 ldw r12, 48(sp)
571 ldw r13, 52(sp)
572 ldw r14, 56(sp)
573 ldw r15, 60(sp)
574 ldw r16, 64(sp)
575 ldw r17, 68(sp)
576 ldw r18, 72(sp)
577 ldw r19, 76(sp)
578 ldw r20, 80(sp)
579 ldw r21, 84(sp)
580 ldw r22, 88(sp)
581 ldw r23, 92(sp)
582 /* Does not need to restore et */
583 ldw gp, 104(sp)
584
585 ldw fp, 112(sp)
586 ldw ea, 116(sp)
587 ldw ra, 120(sp)
588 ldw sp, 108(sp) /* last restore sp */
589 eret
590
591.set at
592.set break
diff --git a/arch/nios2/kernel/irq.c b/arch/nios2/kernel/irq.c
new file mode 100644
index 000000000000..f5b74ae69b5b
--- /dev/null
+++ b/arch/nios2/kernel/irq.c
@@ -0,0 +1,93 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
4 * Copyright (C) 2008 Thomas Chou <thomas@wytron.com.tw>
5 *
6 * based on irq.c from m68k which is:
7 *
8 * Copyright (C) 2007 Greg Ungerer <gerg@snapgear.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#include <linux/init.h>
26#include <linux/interrupt.h>
27#include <linux/of.h>
28
29static u32 ienable;
30
31asmlinkage void do_IRQ(int hwirq, struct pt_regs *regs)
32{
33 struct pt_regs *oldregs = set_irq_regs(regs);
34 int irq;
35
36 irq_enter();
37 irq = irq_find_mapping(NULL, hwirq);
38 generic_handle_irq(irq);
39 irq_exit();
40
41 set_irq_regs(oldregs);
42}
43
44static void chip_unmask(struct irq_data *d)
45{
46 ienable |= (1 << d->hwirq);
47 WRCTL(CTL_IENABLE, ienable);
48}
49
50static void chip_mask(struct irq_data *d)
51{
52 ienable &= ~(1 << d->hwirq);
53 WRCTL(CTL_IENABLE, ienable);
54}
55
56static struct irq_chip m_irq_chip = {
57 .name = "NIOS2-INTC",
58 .irq_unmask = chip_unmask,
59 .irq_mask = chip_mask,
60};
61
62static int irq_map(struct irq_domain *h, unsigned int virq,
63 irq_hw_number_t hw_irq_num)
64{
65 irq_set_chip_and_handler(virq, &m_irq_chip, handle_level_irq);
66
67 return 0;
68}
69
70static struct irq_domain_ops irq_ops = {
71 .map = irq_map,
72 .xlate = irq_domain_xlate_onecell,
73};
74
75void __init init_IRQ(void)
76{
77 struct irq_domain *domain;
78 struct device_node *node;
79
80 node = of_find_compatible_node(NULL, NULL, "altr,nios2-1.0");
81 if (!node)
82 node = of_find_compatible_node(NULL, NULL, "altr,nios2-1.1");
83
84 BUG_ON(!node);
85
86 domain = irq_domain_add_linear(node, NIOS2_CPU_NR_IRQS, &irq_ops, NULL);
87 BUG_ON(!domain);
88
89 irq_set_default_host(domain);
90 of_node_put(node);
91 /* Load the initial ienable value */
92 ienable = RDCTL(CTL_IENABLE);
93}
diff --git a/arch/nios2/kernel/misaligned.c b/arch/nios2/kernel/misaligned.c
new file mode 100644
index 000000000000..4e5907a0cabe
--- /dev/null
+++ b/arch/nios2/kernel/misaligned.c
@@ -0,0 +1,256 @@
1/*
2 * linux/arch/nios2/kernel/misaligned.c
3 *
4 * basic emulation for mis-aligned accesses on the NIOS II cpu
5 * modelled after the version for arm in arm/alignment.c
6 *
7 * Brad Parker <brad@heeltoe.com>
8 * Copyright (C) 2010 Ambient Corporation
9 * Copyright (c) 2010 Altera Corporation, San Jose, California, USA.
10 * Copyright (c) 2010 Arrow Electronics, Inc.
11 *
12 * This file is subject to the terms and conditions of the GNU General
13 * Public License. See the file COPYING in the main directory of
14 * this archive for more details.
15 */
16
17#include <linux/errno.h>
18#include <linux/string.h>
19#include <linux/proc_fs.h>
20#include <linux/init.h>
21#include <linux/sched.h>
22#include <linux/uaccess.h>
23#include <linux/seq_file.h>
24
25#include <asm/traps.h>
26#include <asm/unaligned.h>
27
28/* instructions we emulate */
29#define INST_LDHU 0x0b
30#define INST_STH 0x0d
31#define INST_LDH 0x0f
32#define INST_STW 0x15
33#define INST_LDW 0x17
34
35static unsigned long ma_user, ma_kern, ma_skipped, ma_half, ma_word;
36
37static unsigned int ma_usermode;
38#define UM_WARN 0x01
39#define UM_FIXUP 0x02
40#define UM_SIGNAL 0x04
41#define KM_WARN 0x08
42
43/* see arch/nios2/include/asm/ptrace.h */
44static u8 sys_stack_frame_reg_offset[] = {
45 /* struct pt_regs */
46 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 0,
47 /* struct switch_stack */
48 16, 17, 18, 19, 20, 21, 22, 23, 0, 0, 0, 0, 0, 0, 0, 0
49};
50
51static int reg_offsets[32];
52
53static inline u32 get_reg_val(struct pt_regs *fp, int reg)
54{
55 u8 *p = ((u8 *)fp) + reg_offsets[reg];
56
57 return *(u32 *)p;
58}
59
60static inline void put_reg_val(struct pt_regs *fp, int reg, u32 val)
61{
62 u8 *p = ((u8 *)fp) + reg_offsets[reg];
63 *(u32 *)p = val;
64}
65
66/*
67 * (mis)alignment handler
68 */
69asmlinkage void handle_unaligned_c(struct pt_regs *fp, int cause)
70{
71 u32 isn, addr, val;
72 int in_kernel;
73 u8 a, b, d0, d1, d2, d3;
74 u16 imm16;
75 unsigned int fault;
76
77 /* back up one instruction */
78 fp->ea -= 4;
79
80 if (fixup_exception(fp)) {
81 ma_skipped++;
82 return;
83 }
84
85 in_kernel = !user_mode(fp);
86
87 isn = *(unsigned long *)(fp->ea);
88
89 fault = 0;
90
91 /* do fixup if in kernel or mode turned on */
92 if (in_kernel || (ma_usermode & UM_FIXUP)) {
93 /* decompose instruction */
94 a = (isn >> 27) & 0x1f;
95 b = (isn >> 22) & 0x1f;
96 imm16 = (isn >> 6) & 0xffff;
97 addr = get_reg_val(fp, a) + imm16;
98
99 /* do fixup to saved registers */
100 switch (isn & 0x3f) {
101 case INST_LDHU:
102 fault |= __get_user(d0, (u8 *)(addr+0));
103 fault |= __get_user(d1, (u8 *)(addr+1));
104 val = (d1 << 8) | d0;
105 put_reg_val(fp, b, val);
106 ma_half++;
107 break;
108 case INST_STH:
109 val = get_reg_val(fp, b);
110 d1 = val >> 8;
111 d0 = val >> 0;
112
113 pr_debug("sth: ra=%d (%08x) rb=%d (%08x), imm16 %04x addr %08x val %08x\n",
114 a, get_reg_val(fp, a),
115 b, get_reg_val(fp, b),
116 imm16, addr, val);
117
118 if (in_kernel) {
119 *(u8 *)(addr+0) = d0;
120 *(u8 *)(addr+1) = d1;
121 } else {
122 fault |= __put_user(d0, (u8 *)(addr+0));
123 fault |= __put_user(d1, (u8 *)(addr+1));
124 }
125 ma_half++;
126 break;
127 case INST_LDH:
128 fault |= __get_user(d0, (u8 *)(addr+0));
129 fault |= __get_user(d1, (u8 *)(addr+1));
130 val = (short)((d1 << 8) | d0);
131 put_reg_val(fp, b, val);
132 ma_half++;
133 break;
134 case INST_STW:
135 val = get_reg_val(fp, b);
136 d3 = val >> 24;
137 d2 = val >> 16;
138 d1 = val >> 8;
139 d0 = val >> 0;
140 if (in_kernel) {
141 *(u8 *)(addr+0) = d0;
142 *(u8 *)(addr+1) = d1;
143 *(u8 *)(addr+2) = d2;
144 *(u8 *)(addr+3) = d3;
145 } else {
146 fault |= __put_user(d0, (u8 *)(addr+0));
147 fault |= __put_user(d1, (u8 *)(addr+1));
148 fault |= __put_user(d2, (u8 *)(addr+2));
149 fault |= __put_user(d3, (u8 *)(addr+3));
150 }
151 ma_word++;
152 break;
153 case INST_LDW:
154 fault |= __get_user(d0, (u8 *)(addr+0));
155 fault |= __get_user(d1, (u8 *)(addr+1));
156 fault |= __get_user(d2, (u8 *)(addr+2));
157 fault |= __get_user(d3, (u8 *)(addr+3));
158 val = (d3 << 24) | (d2 << 16) | (d1 << 8) | d0;
159 put_reg_val(fp, b, val);
160 ma_word++;
161 break;
162 }
163 }
164
165 addr = RDCTL(CTL_BADADDR);
166 cause >>= 2;
167
168 if (fault) {
169 if (in_kernel) {
170 pr_err("fault during kernel misaligned fixup @ %#lx; addr 0x%08x; isn=0x%08x\n",
171 fp->ea, (unsigned int)addr,
172 (unsigned int)isn);
173 } else {
174 pr_err("fault during user misaligned fixup @ %#lx; isn=%08x addr=0x%08x sp=0x%08lx pid=%d\n",
175 fp->ea,
176 (unsigned int)isn, addr, fp->sp,
177 current->pid);
178
179 _exception(SIGSEGV, fp, SEGV_MAPERR, fp->ea);
180 return;
181 }
182 }
183
184 /*
185 * kernel mode -
186 * note exception and skip bad instruction (return)
187 */
188 if (in_kernel) {
189 ma_kern++;
190 fp->ea += 4;
191
192 if (ma_usermode & KM_WARN) {
193 pr_err("kernel unaligned access @ %#lx; BADADDR 0x%08x; cause=%d, isn=0x%08x\n",
194 fp->ea,
195 (unsigned int)addr, cause,
196 (unsigned int)isn);
197 /* show_regs(fp); */
198 }
199
200 return;
201 }
202
203 ma_user++;
204
205 /*
206 * user mode -
207 * possibly warn,
208 * possibly send SIGBUS signal to process
209 */
210 if (ma_usermode & UM_WARN) {
211 pr_err("user unaligned access @ %#lx; isn=0x%08lx ea=0x%08lx ra=0x%08lx sp=0x%08lx\n",
212 (unsigned long)addr, (unsigned long)isn,
213 fp->ea, fp->ra, fp->sp);
214 }
215
216 if (ma_usermode & UM_SIGNAL)
217 _exception(SIGBUS, fp, BUS_ADRALN, fp->ea);
218 else
219 fp->ea += 4; /* else advance */
220}
221
222static void __init misaligned_calc_reg_offsets(void)
223{
224 int i, r, offset;
225
226 /* pre-calc offsets of registers on sys call stack frame */
227 offset = 0;
228
229 /* struct pt_regs */
230 for (i = 0; i < 16; i++) {
231 r = sys_stack_frame_reg_offset[i];
232 reg_offsets[r] = offset;
233 offset += 4;
234 }
235
236 /* struct switch_stack */
237 offset = -sizeof(struct switch_stack);
238 for (i = 16; i < 32; i++) {
239 r = sys_stack_frame_reg_offset[i];
240 reg_offsets[r] = offset;
241 offset += 4;
242 }
243}
244
245
246static int __init misaligned_init(void)
247{
248 /* default mode - silent fix */
249 ma_usermode = UM_FIXUP | KM_WARN;
250
251 misaligned_calc_reg_offsets();
252
253 return 0;
254}
255
256fs_initcall(misaligned_init);
diff --git a/arch/nios2/kernel/module.c b/arch/nios2/kernel/module.c
new file mode 100644
index 000000000000..cc924a38f22a
--- /dev/null
+++ b/arch/nios2/kernel/module.c
@@ -0,0 +1,138 @@
1/*
2 * Kernel module support for Nios II.
3 *
4 * Copyright (C) 2004 Microtronix Datacom Ltd.
5 * Written by Wentao Xu <xuwentao@microtronix.com>
6 * Copyright (C) 2001, 2003 Rusty Russell
7 *
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file COPYING in the main directory of this
10 * archive for more details.
11 */
12
13#include <linux/moduleloader.h>
14#include <linux/elf.h>
15#include <linux/mm.h>
16#include <linux/vmalloc.h>
17#include <linux/slab.h>
18#include <linux/fs.h>
19#include <linux/string.h>
20#include <linux/kernel.h>
21
22#include <asm/pgtable.h>
23#include <asm/cacheflush.h>
24
25/*
26 * Modules should NOT be allocated with kmalloc for (obvious) reasons.
27 * But we do it for now to avoid relocation issues. CALL26/PCREL26 cannot reach
28 * from 0x80000000 (vmalloc area) to 0xc00000000 (kernel) (kmalloc returns
29 * addresses in 0xc0000000)
30 */
31void *module_alloc(unsigned long size)
32{
33 if (size == 0)
34 return NULL;
35 return kmalloc(size, GFP_KERNEL);
36}
37
38/* Free memory returned from module_alloc */
39void module_free(struct module *mod, void *module_region)
40{
41 kfree(module_region);
42}
43
44int apply_relocate_add(Elf32_Shdr *sechdrs, const char *strtab,
45 unsigned int symindex, unsigned int relsec,
46 struct module *mod)
47{
48 unsigned int i;
49 Elf32_Rela *rela = (void *)sechdrs[relsec].sh_addr;
50
51 pr_debug("Applying relocate section %u to %u\n", relsec,
52 sechdrs[relsec].sh_info);
53
54 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) {
55 /* This is where to make the change */
56 uint32_t word;
57 uint32_t *loc
58 = ((void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
59 + rela[i].r_offset);
60 /* This is the symbol it is referring to. Note that all
61 undefined symbols have been resolved. */
62 Elf32_Sym *sym
63 = ((Elf32_Sym *)sechdrs[symindex].sh_addr
64 + ELF32_R_SYM(rela[i].r_info));
65 uint32_t v = sym->st_value + rela[i].r_addend;
66
67 pr_debug("reltype %d 0x%x name:<%s>\n",
68 ELF32_R_TYPE(rela[i].r_info),
69 rela[i].r_offset, strtab + sym->st_name);
70
71 switch (ELF32_R_TYPE(rela[i].r_info)) {
72 case R_NIOS2_NONE:
73 break;
74 case R_NIOS2_BFD_RELOC_32:
75 *loc += v;
76 break;
77 case R_NIOS2_PCREL16:
78 v -= (uint32_t)loc + 4;
79 if ((int32_t)v > 0x7fff ||
80 (int32_t)v < -(int32_t)0x8000) {
81 pr_err("module %s: relocation overflow\n",
82 mod->name);
83 return -ENOEXEC;
84 }
85 word = *loc;
86 *loc = ((((word >> 22) << 16) | (v & 0xffff)) << 6) |
87 (word & 0x3f);
88 break;
89 case R_NIOS2_CALL26:
90 if (v & 3) {
91 pr_err("module %s: dangerous relocation\n",
92 mod->name);
93 return -ENOEXEC;
94 }
95 if ((v >> 28) != ((uint32_t)loc >> 28)) {
96 pr_err("module %s: relocation overflow\n",
97 mod->name);
98 return -ENOEXEC;
99 }
100 *loc = (*loc & 0x3f) | ((v >> 2) << 6);
101 break;
102 case R_NIOS2_HI16:
103 word = *loc;
104 *loc = ((((word >> 22) << 16) |
105 ((v >> 16) & 0xffff)) << 6) | (word & 0x3f);
106 break;
107 case R_NIOS2_LO16:
108 word = *loc;
109 *loc = ((((word >> 22) << 16) | (v & 0xffff)) << 6) |
110 (word & 0x3f);
111 break;
112 case R_NIOS2_HIADJ16:
113 {
114 Elf32_Addr word2;
115
116 word = *loc;
117 word2 = ((v >> 16) + ((v >> 15) & 1)) & 0xffff;
118 *loc = ((((word >> 22) << 16) | word2) << 6) |
119 (word & 0x3f);
120 }
121 break;
122
123 default:
124 pr_err("module %s: Unknown reloc: %u\n",
125 mod->name, ELF32_R_TYPE(rela[i].r_info));
126 return -ENOEXEC;
127 }
128 }
129
130 return 0;
131}
132
133int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
134 struct module *me)
135{
136 flush_cache_all();
137 return 0;
138}
diff --git a/arch/nios2/kernel/nios2_ksyms.c b/arch/nios2/kernel/nios2_ksyms.c
new file mode 100644
index 000000000000..bf2f55d10a4d
--- /dev/null
+++ b/arch/nios2/kernel/nios2_ksyms.c
@@ -0,0 +1,33 @@
1/*
2 * Copyright (C) 2004 Microtronix Datacom Ltd
3 *
4 * This file is subject to the terms and conditions of the GNU General
5 * Public License. See the file COPYING in the main directory of this
6 * archive for more details.
7 */
8
9#include <linux/export.h>
10#include <linux/string.h>
11
12/* string functions */
13
14EXPORT_SYMBOL(memcpy);
15EXPORT_SYMBOL(memset);
16EXPORT_SYMBOL(memmove);
17
18/*
19 * libgcc functions - functions that are used internally by the
20 * compiler... (prototypes are not correct though, but that
21 * doesn't really matter since they're not versioned).
22 */
23#define DECLARE_EXPORT(name) extern void name(void); EXPORT_SYMBOL(name)
24
25DECLARE_EXPORT(__gcc_bcmp);
26DECLARE_EXPORT(__divsi3);
27DECLARE_EXPORT(__moddi3);
28DECLARE_EXPORT(__modsi3);
29DECLARE_EXPORT(__udivmoddi4);
30DECLARE_EXPORT(__udivsi3);
31DECLARE_EXPORT(__umoddi3);
32DECLARE_EXPORT(__umodsi3);
33DECLARE_EXPORT(__muldi3);
diff --git a/arch/nios2/kernel/process.c b/arch/nios2/kernel/process.c
new file mode 100644
index 000000000000..0e075b5ad2a5
--- /dev/null
+++ b/arch/nios2/kernel/process.c
@@ -0,0 +1,258 @@
1/*
2 * Architecture-dependent parts of process handling.
3 *
4 * Copyright (C) 2013 Altera Corporation
5 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
6 * Copyright (C) 2009 Wind River Systems Inc
7 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
8 * Copyright (C) 2004 Microtronix Datacom Ltd
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 */
14
15#include <linux/export.h>
16#include <linux/sched.h>
17#include <linux/tick.h>
18#include <linux/uaccess.h>
19
20#include <asm/unistd.h>
21#include <asm/traps.h>
22#include <asm/cpuinfo.h>
23
24asmlinkage void ret_from_fork(void);
25asmlinkage void ret_from_kernel_thread(void);
26
27void (*pm_power_off)(void) = NULL;
28EXPORT_SYMBOL(pm_power_off);
29
30void arch_cpu_idle(void)
31{
32 local_irq_enable();
33}
34
35/*
36 * The development boards have no way to pull a board reset. Just jump to the
37 * cpu reset address and let the boot loader or the code in head.S take care of
38 * resetting peripherals.
39 */
40void machine_restart(char *__unused)
41{
42 pr_notice("Machine restart (%08x)...\n", cpuinfo.reset_addr);
43 local_irq_disable();
44 __asm__ __volatile__ (
45 "jmp %0\n\t"
46 :
47 : "r" (cpuinfo.reset_addr)
48 : "r4");
49}
50
51void machine_halt(void)
52{
53 pr_notice("Machine halt...\n");
54 local_irq_disable();
55 for (;;)
56 ;
57}
58
59/*
60 * There is no way to power off the development boards. So just spin for now. If
61 * we ever have a way of resetting a board using a GPIO we should add that here.
62 */
63void machine_power_off(void)
64{
65 pr_notice("Machine power off...\n");
66 local_irq_disable();
67 for (;;)
68 ;
69}
70
71void show_regs(struct pt_regs *regs)
72{
73 pr_notice("\n");
74 show_regs_print_info(KERN_DEFAULT);
75
76 pr_notice("r1: %08lx r2: %08lx r3: %08lx r4: %08lx\n",
77 regs->r1, regs->r2, regs->r3, regs->r4);
78
79 pr_notice("r5: %08lx r6: %08lx r7: %08lx r8: %08lx\n",
80 regs->r5, regs->r6, regs->r7, regs->r8);
81
82 pr_notice("r9: %08lx r10: %08lx r11: %08lx r12: %08lx\n",
83 regs->r9, regs->r10, regs->r11, regs->r12);
84
85 pr_notice("r13: %08lx r14: %08lx r15: %08lx\n",
86 regs->r13, regs->r14, regs->r15);
87
88 pr_notice("ra: %08lx fp: %08lx sp: %08lx gp: %08lx\n",
89 regs->ra, regs->fp, regs->sp, regs->gp);
90
91 pr_notice("ea: %08lx estatus: %08lx\n",
92 regs->ea, regs->estatus);
93}
94
95void flush_thread(void)
96{
97 set_fs(USER_DS);
98}
99
100int copy_thread(unsigned long clone_flags,
101 unsigned long usp, unsigned long arg, struct task_struct *p)
102{
103 struct pt_regs *childregs = task_pt_regs(p);
104 struct pt_regs *regs;
105 struct switch_stack *stack;
106 struct switch_stack *childstack =
107 ((struct switch_stack *)childregs) - 1;
108
109 if (unlikely(p->flags & PF_KTHREAD)) {
110 memset(childstack, 0,
111 sizeof(struct switch_stack) + sizeof(struct pt_regs));
112
113 childstack->r16 = usp; /* fn */
114 childstack->r17 = arg;
115 childstack->ra = (unsigned long) ret_from_kernel_thread;
116 childregs->estatus = STATUS_PIE;
117 childregs->sp = (unsigned long) childstack;
118
119 p->thread.ksp = (unsigned long) childstack;
120 p->thread.kregs = childregs;
121 return 0;
122 }
123
124 regs = current_pt_regs();
125 *childregs = *regs;
126 childregs->r2 = 0; /* Set the return value for the child. */
127 childregs->r7 = 0;
128
129 stack = ((struct switch_stack *) regs) - 1;
130 *childstack = *stack;
131 childstack->ra = (unsigned long)ret_from_fork;
132 p->thread.kregs = childregs;
133 p->thread.ksp = (unsigned long) childstack;
134
135 if (usp)
136 childregs->sp = usp;
137
138 /* Initialize tls register. */
139 if (clone_flags & CLONE_SETTLS)
140 childstack->r23 = regs->r8;
141
142 return 0;
143}
144
145/*
146 * Generic dumping code. Used for panic and debug.
147 */
148void dump(struct pt_regs *fp)
149{
150 unsigned long *sp;
151 unsigned char *tp;
152 int i;
153
154 pr_emerg("\nCURRENT PROCESS:\n\n");
155 pr_emerg("COMM=%s PID=%d\n", current->comm, current->pid);
156
157 if (current->mm) {
158 pr_emerg("TEXT=%08x-%08x DATA=%08x-%08x BSS=%08x-%08x\n",
159 (int) current->mm->start_code,
160 (int) current->mm->end_code,
161 (int) current->mm->start_data,
162 (int) current->mm->end_data,
163 (int) current->mm->end_data,
164 (int) current->mm->brk);
165 pr_emerg("USER-STACK=%08x KERNEL-STACK=%08x\n\n",
166 (int) current->mm->start_stack,
167 (int)(((unsigned long) current) + THREAD_SIZE));
168 }
169
170 pr_emerg("PC: %08lx\n", fp->ea);
171 pr_emerg("SR: %08lx SP: %08lx\n",
172 (long) fp->estatus, (long) fp);
173
174 pr_emerg("r1: %08lx r2: %08lx r3: %08lx\n",
175 fp->r1, fp->r2, fp->r3);
176
177 pr_emerg("r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
178 fp->r4, fp->r5, fp->r6, fp->r7);
179 pr_emerg("r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
180 fp->r8, fp->r9, fp->r10, fp->r11);
181 pr_emerg("r12: %08lx r13: %08lx r14: %08lx r15: %08lx\n",
182 fp->r12, fp->r13, fp->r14, fp->r15);
183 pr_emerg("or2: %08lx ra: %08lx fp: %08lx sp: %08lx\n",
184 fp->orig_r2, fp->ra, fp->fp, fp->sp);
185 pr_emerg("\nUSP: %08x TRAPFRAME: %08x\n",
186 (unsigned int) fp->sp, (unsigned int) fp);
187
188 pr_emerg("\nCODE:");
189 tp = ((unsigned char *) fp->ea) - 0x20;
190 for (sp = (unsigned long *) tp, i = 0; (i < 0x40); i += 4) {
191 if ((i % 0x10) == 0)
192 pr_emerg("\n%08x: ", (int) (tp + i));
193 pr_emerg("%08x ", (int) *sp++);
194 }
195 pr_emerg("\n");
196
197 pr_emerg("\nKERNEL STACK:");
198 tp = ((unsigned char *) fp) - 0x40;
199 for (sp = (unsigned long *) tp, i = 0; (i < 0xc0); i += 4) {
200 if ((i % 0x10) == 0)
201 pr_emerg("\n%08x: ", (int) (tp + i));
202 pr_emerg("%08x ", (int) *sp++);
203 }
204 pr_emerg("\n");
205 pr_emerg("\n");
206
207 pr_emerg("\nUSER STACK:");
208 tp = (unsigned char *) (fp->sp - 0x10);
209 for (sp = (unsigned long *) tp, i = 0; (i < 0x80); i += 4) {
210 if ((i % 0x10) == 0)
211 pr_emerg("\n%08x: ", (int) (tp + i));
212 pr_emerg("%08x ", (int) *sp++);
213 }
214 pr_emerg("\n\n");
215}
216
217unsigned long get_wchan(struct task_struct *p)
218{
219 unsigned long fp, pc;
220 unsigned long stack_page;
221 int count = 0;
222
223 if (!p || p == current || p->state == TASK_RUNNING)
224 return 0;
225
226 stack_page = (unsigned long)p;
227 fp = ((struct switch_stack *)p->thread.ksp)->fp; /* ;dgt2 */
228 do {
229 if (fp < stack_page+sizeof(struct task_struct) ||
230 fp >= 8184+stack_page) /* ;dgt2;tmp */
231 return 0;
232 pc = ((unsigned long *)fp)[1];
233 if (!in_sched_functions(pc))
234 return pc;
235 fp = *(unsigned long *) fp;
236 } while (count++ < 16); /* ;dgt2;tmp */
237 return 0;
238}
239
240/*
241 * Do necessary setup to start up a newly executed thread.
242 * Will startup in user mode (status_extension = 0).
243 */
244void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
245{
246 memset((void *) regs, 0, sizeof(struct pt_regs));
247 regs->estatus = ESTATUS_EPIE | ESTATUS_EU;
248 regs->ea = pc;
249 regs->sp = sp;
250}
251
252#include <linux/elfcore.h>
253
254/* Fill in the FPU structure for a core dump. */
255int dump_fpu(struct pt_regs *regs, elf_fpregset_t *r)
256{
257 return 0; /* Nios2 has no FPU and thus no FPU registers */
258}
diff --git a/arch/nios2/kernel/prom.c b/arch/nios2/kernel/prom.c
new file mode 100644
index 000000000000..0522d3378e3f
--- /dev/null
+++ b/arch/nios2/kernel/prom.c
@@ -0,0 +1,65 @@
1/*
2 * Device tree support
3 *
4 * Copyright (C) 2013 Altera Corporation
5 * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw>
6 *
7 * Based on MIPS support for CONFIG_OF device tree support
8 *
9 * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 */
25
26#include <linux/init.h>
27#include <linux/types.h>
28#include <linux/bootmem.h>
29#include <linux/of.h>
30#include <linux/of_fdt.h>
31#include <linux/io.h>
32
33#include <asm/sections.h>
34
35void __init early_init_dt_add_memory_arch(u64 base, u64 size)
36{
37 u64 kernel_start = (u64)virt_to_phys(_text);
38
39 if (!memory_size &&
40 (kernel_start >= base) && (kernel_start < (base + size)))
41 memory_size = size;
42
43}
44
45void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
46{
47 return alloc_bootmem_align(size, align);
48}
49
50void __init early_init_devtree(void *params)
51{
52 __be32 *dtb = (u32 *)__dtb_start;
53#if defined(CONFIG_NIOS2_DTB_AT_PHYS_ADDR)
54 if (be32_to_cpup((__be32 *)CONFIG_NIOS2_DTB_PHYS_ADDR) ==
55 OF_DT_HEADER) {
56 params = (void *)CONFIG_NIOS2_DTB_PHYS_ADDR;
57 early_init_dt_scan(params);
58 return;
59 }
60#endif
61 if (be32_to_cpu((__be32) *dtb) == OF_DT_HEADER)
62 params = (void *)__dtb_start;
63
64 early_init_dt_scan(params);
65}
diff --git a/arch/nios2/kernel/ptrace.c b/arch/nios2/kernel/ptrace.c
new file mode 100644
index 000000000000..681dda92eff1
--- /dev/null
+++ b/arch/nios2/kernel/ptrace.c
@@ -0,0 +1,166 @@
1/*
2 * Copyright (C) 2014 Altera Corporation
3 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
4 *
5 * This file is subject to the terms and conditions of the GNU General
6 * Public License. See the file COPYING in the main directory of this
7 * archive for more details.
8 */
9
10#include <linux/elf.h>
11#include <linux/errno.h>
12#include <linux/kernel.h>
13#include <linux/mm.h>
14#include <linux/ptrace.h>
15#include <linux/regset.h>
16#include <linux/sched.h>
17#include <linux/tracehook.h>
18#include <linux/uaccess.h>
19#include <linux/user.h>
20
21static int genregs_get(struct task_struct *target,
22 const struct user_regset *regset,
23 unsigned int pos, unsigned int count,
24 void *kbuf, void __user *ubuf)
25{
26 const struct pt_regs *regs = task_pt_regs(target);
27 const struct switch_stack *sw = (struct switch_stack *)regs - 1;
28 int ret = 0;
29
30#define REG_O_ZERO_RANGE(START, END) \
31 if (!ret) \
32 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf, \
33 START * 4, (END * 4) + 4);
34
35#define REG_O_ONE(PTR, LOC) \
36 if (!ret) \
37 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \
38 LOC * 4, (LOC * 4) + 4);
39
40#define REG_O_RANGE(PTR, START, END) \
41 if (!ret) \
42 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf, PTR, \
43 START * 4, (END * 4) + 4);
44
45 REG_O_ZERO_RANGE(PTR_R0, PTR_R0);
46 REG_O_RANGE(&regs->r1, PTR_R1, PTR_R7);
47 REG_O_RANGE(&regs->r8, PTR_R8, PTR_R15);
48 REG_O_RANGE(sw, PTR_R16, PTR_R23);
49 REG_O_ZERO_RANGE(PTR_R24, PTR_R25); /* et and bt */
50 REG_O_ONE(&regs->gp, PTR_GP);
51 REG_O_ONE(&regs->sp, PTR_SP);
52 REG_O_ONE(&regs->fp, PTR_FP);
53 REG_O_ONE(&regs->ea, PTR_EA);
54 REG_O_ZERO_RANGE(PTR_BA, PTR_BA);
55 REG_O_ONE(&regs->ra, PTR_RA);
56 REG_O_ONE(&regs->ea, PTR_PC); /* use ea for PC */
57 if (!ret)
58 ret = user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
59 PTR_STATUS * 4, -1);
60
61 return ret;
62}
63
64/*
65 * Set the thread state from a regset passed in via ptrace
66 */
67static int genregs_set(struct task_struct *target,
68 const struct user_regset *regset,
69 unsigned int pos, unsigned int count,
70 const void *kbuf, const void __user *ubuf)
71{
72 struct pt_regs *regs = task_pt_regs(target);
73 const struct switch_stack *sw = (struct switch_stack *)regs - 1;
74 int ret = 0;
75
76#define REG_IGNORE_RANGE(START, END) \
77 if (!ret) \
78 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, \
79 START * 4, (END * 4) + 4);
80
81#define REG_IN_ONE(PTR, LOC) \
82 if (!ret) \
83 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
84 (void *)(PTR), LOC * 4, (LOC * 4) + 4);
85
86#define REG_IN_RANGE(PTR, START, END) \
87 if (!ret) \
88 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, \
89 (void *)(PTR), START * 4, (END * 4) + 4);
90
91 REG_IGNORE_RANGE(PTR_R0, PTR_R0);
92 REG_IN_RANGE(&regs->r1, PTR_R1, PTR_R7);
93 REG_IN_RANGE(&regs->r8, PTR_R8, PTR_R15);
94 REG_IN_RANGE(sw, PTR_R16, PTR_R23);
95 REG_IGNORE_RANGE(PTR_R24, PTR_R25); /* et and bt */
96 REG_IN_ONE(&regs->gp, PTR_GP);
97 REG_IN_ONE(&regs->sp, PTR_SP);
98 REG_IN_ONE(&regs->fp, PTR_FP);
99 REG_IN_ONE(&regs->ea, PTR_EA);
100 REG_IGNORE_RANGE(PTR_BA, PTR_BA);
101 REG_IN_ONE(&regs->ra, PTR_RA);
102 REG_IN_ONE(&regs->ea, PTR_PC); /* use ea for PC */
103 if (!ret)
104 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
105 PTR_STATUS * 4, -1);
106
107 return ret;
108}
109
110/*
111 * Define the register sets available on Nios2 under Linux
112 */
113enum nios2_regset {
114 REGSET_GENERAL,
115};
116
117static const struct user_regset nios2_regsets[] = {
118 [REGSET_GENERAL] = {
119 .core_note_type = NT_PRSTATUS,
120 .n = NUM_PTRACE_REG,
121 .size = sizeof(unsigned long),
122 .align = sizeof(unsigned long),
123 .get = genregs_get,
124 .set = genregs_set,
125 }
126};
127
128static const struct user_regset_view nios2_user_view = {
129 .name = "nios2",
130 .e_machine = ELF_ARCH,
131 .ei_osabi = ELF_OSABI,
132 .regsets = nios2_regsets,
133 .n = ARRAY_SIZE(nios2_regsets)
134};
135
136const struct user_regset_view *task_user_regset_view(struct task_struct *task)
137{
138 return &nios2_user_view;
139}
140
141void ptrace_disable(struct task_struct *child)
142{
143
144}
145
146long arch_ptrace(struct task_struct *child, long request, unsigned long addr,
147 unsigned long data)
148{
149 return ptrace_request(child, request, addr, data);
150}
151
152asmlinkage int do_syscall_trace_enter(void)
153{
154 int ret = 0;
155
156 if (test_thread_flag(TIF_SYSCALL_TRACE))
157 ret = tracehook_report_syscall_entry(task_pt_regs(current));
158
159 return ret;
160}
161
162asmlinkage void do_syscall_trace_exit(void)
163{
164 if (test_thread_flag(TIF_SYSCALL_TRACE))
165 tracehook_report_syscall_exit(task_pt_regs(current), 0);
166}
diff --git a/arch/nios2/kernel/setup.c b/arch/nios2/kernel/setup.c
new file mode 100644
index 000000000000..cb3121f975d4
--- /dev/null
+++ b/arch/nios2/kernel/setup.c
@@ -0,0 +1,218 @@
1/*
2 * Nios2-specific parts of system setup
3 *
4 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
5 * Copyright (C) 2004 Microtronix Datacom Ltd.
6 * Copyright (C) 2001 Vic Phillips <vic@microtronix.com>
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12
13#include <linux/export.h>
14#include <linux/kernel.h>
15#include <linux/mm.h>
16#include <linux/sched.h>
17#include <linux/console.h>
18#include <linux/bootmem.h>
19#include <linux/initrd.h>
20#include <linux/of_fdt.h>
21
22#include <asm/mmu_context.h>
23#include <asm/sections.h>
24#include <asm/setup.h>
25#include <asm/cpuinfo.h>
26
27unsigned long memory_start;
28EXPORT_SYMBOL(memory_start);
29
30unsigned long memory_end;
31EXPORT_SYMBOL(memory_end);
32
33unsigned long memory_size;
34
35static struct pt_regs fake_regs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36 0, 0, 0, 0, 0, 0,
37 0};
38
39/* Copy a short hook instruction sequence to the exception address */
40static inline void copy_exception_handler(unsigned int addr)
41{
42 unsigned int start = (unsigned int) exception_handler_hook;
43 volatile unsigned int tmp = 0;
44
45 if (start == addr) {
46 /* The CPU exception address already points to the handler. */
47 return;
48 }
49
50 __asm__ __volatile__ (
51 "ldw %2,0(%0)\n"
52 "stw %2,0(%1)\n"
53 "ldw %2,4(%0)\n"
54 "stw %2,4(%1)\n"
55 "ldw %2,8(%0)\n"
56 "stw %2,8(%1)\n"
57 "flushd 0(%1)\n"
58 "flushd 4(%1)\n"
59 "flushd 8(%1)\n"
60 "flushi %1\n"
61 "addi %1,%1,4\n"
62 "flushi %1\n"
63 "addi %1,%1,4\n"
64 "flushi %1\n"
65 "flushp\n"
66 : /* no output registers */
67 : "r" (start), "r" (addr), "r" (tmp)
68 : "memory"
69 );
70}
71
72/* Copy the fast TLB miss handler */
73static inline void copy_fast_tlb_miss_handler(unsigned int addr)
74{
75 unsigned int start = (unsigned int) fast_handler;
76 unsigned int end = (unsigned int) fast_handler_end;
77 volatile unsigned int tmp = 0;
78
79 __asm__ __volatile__ (
80 "1:\n"
81 " ldw %3,0(%0)\n"
82 " stw %3,0(%1)\n"
83 " flushd 0(%1)\n"
84 " flushi %1\n"
85 " flushp\n"
86 " addi %0,%0,4\n"
87 " addi %1,%1,4\n"
88 " bne %0,%2,1b\n"
89 : /* no output registers */
90 : "r" (start), "r" (addr), "r" (end), "r" (tmp)
91 : "memory"
92 );
93}
94
95/*
96 * save args passed from u-boot, called from head.S
97 *
98 * @r4: NIOS magic
99 * @r5: initrd start
100 * @r6: initrd end or fdt
101 * @r7: kernel command line
102 */
103asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
104 unsigned r7)
105{
106 unsigned dtb_passed = 0;
107 char cmdline_passed[COMMAND_LINE_SIZE] = { 0, };
108
109#if defined(CONFIG_NIOS2_PASS_CMDLINE)
110 if (r4 == 0x534f494e) { /* r4 is magic NIOS */
111#if defined(CONFIG_BLK_DEV_INITRD)
112 if (r5) { /* initramfs */
113 initrd_start = r5;
114 initrd_end = r6;
115 }
116#endif /* CONFIG_BLK_DEV_INITRD */
117 dtb_passed = r6;
118
119 if (r7)
120 strncpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
121 }
122#endif
123
124 early_init_devtree((void *)dtb_passed);
125
126#ifndef CONFIG_CMDLINE_FORCE
127 if (cmdline_passed[0])
128 strncpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
129#ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
130 else
131 strncpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
132#endif
133#endif
134}
135
136void __init setup_arch(char **cmdline_p)
137{
138 int bootmap_size;
139
140 console_verbose();
141
142 memory_start = PAGE_ALIGN((unsigned long)__pa(_end));
143 memory_end = (unsigned long) CONFIG_NIOS2_MEM_BASE + memory_size;
144
145 init_mm.start_code = (unsigned long) _stext;
146 init_mm.end_code = (unsigned long) _etext;
147 init_mm.end_data = (unsigned long) _edata;
148 init_mm.brk = (unsigned long) _end;
149 init_task.thread.kregs = &fake_regs;
150
151 /* Keep a copy of command line */
152 *cmdline_p = boot_command_line;
153
154 min_low_pfn = PFN_UP(memory_start);
155 max_low_pfn = PFN_DOWN(memory_end);
156 max_mapnr = max_low_pfn;
157
158 /*
159 * give all the memory to the bootmap allocator, tell it to put the
160 * boot mem_map at the start of memory
161 */
162 pr_debug("init_bootmem_node(?,%#lx, %#x, %#lx)\n",
163 min_low_pfn, PFN_DOWN(PHYS_OFFSET), max_low_pfn);
164 bootmap_size = init_bootmem_node(NODE_DATA(0),
165 min_low_pfn, PFN_DOWN(PHYS_OFFSET),
166 max_low_pfn);
167
168 /*
169 * free the usable memory, we have to make sure we do not free
170 * the bootmem bitmap so we then reserve it after freeing it :-)
171 */
172 pr_debug("free_bootmem(%#lx, %#lx)\n",
173 memory_start, memory_end - memory_start);
174 free_bootmem(memory_start, memory_end - memory_start);
175
176 /*
177 * Reserve the bootmem bitmap itself as well. We do this in two
178 * steps (first step was init_bootmem()) because this catches
179 * the (very unlikely) case of us accidentally initializing the
180 * bootmem allocator with an invalid RAM area.
181 *
182 * Arguments are start, size
183 */
184 pr_debug("reserve_bootmem(%#lx, %#x)\n", memory_start, bootmap_size);
185 reserve_bootmem(memory_start, bootmap_size, BOOTMEM_DEFAULT);
186
187#ifdef CONFIG_BLK_DEV_INITRD
188 if (initrd_start) {
189 reserve_bootmem(virt_to_phys((void *)initrd_start),
190 initrd_end - initrd_start, BOOTMEM_DEFAULT);
191 }
192#endif /* CONFIG_BLK_DEV_INITRD */
193
194 unflatten_and_copy_device_tree();
195
196 setup_cpuinfo();
197
198 copy_exception_handler(cpuinfo.exception_addr);
199
200 mmu_init();
201
202 copy_fast_tlb_miss_handler(cpuinfo.fast_tlb_miss_exc_addr);
203
204 /*
205 * Initialize MMU context handling here because data from cpuinfo is
206 * needed for this.
207 */
208 mmu_context_init();
209
210 /*
211 * get kmalloc into gear
212 */
213 paging_init();
214
215#if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
216 conswitchp = &dummy_con;
217#endif
218}
diff --git a/arch/nios2/kernel/signal.c b/arch/nios2/kernel/signal.c
new file mode 100644
index 000000000000..f9d27883a714
--- /dev/null
+++ b/arch/nios2/kernel/signal.c
@@ -0,0 +1,323 @@
1/*
2 * Copyright (C) 2013-2014 Altera Corporation
3 * Copyright (C) 2011-2012 Tobias Klauser <tklauser@distanz.ch>
4 * Copyright (C) 2004 Microtronix Datacom Ltd
5 * Copyright (C) 1991, 1992 Linus Torvalds
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive
9 * for more details.
10 */
11
12#include <linux/signal.h>
13#include <linux/errno.h>
14#include <linux/ptrace.h>
15#include <linux/uaccess.h>
16#include <linux/unistd.h>
17#include <linux/personality.h>
18#include <linux/tracehook.h>
19
20#include <asm/ucontext.h>
21#include <asm/cacheflush.h>
22
23#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
24
25/*
26 * Do a signal return; undo the signal stack.
27 *
28 * Keep the return code on the stack quadword aligned!
29 * That makes the cache flush below easier.
30 */
31
32struct rt_sigframe {
33 struct siginfo info;
34 struct ucontext uc;
35};
36
37static inline int rt_restore_ucontext(struct pt_regs *regs,
38 struct switch_stack *sw,
39 struct ucontext *uc, int *pr2)
40{
41 int temp;
42 greg_t *gregs = uc->uc_mcontext.gregs;
43 int err;
44
45 /* Always make any pending restarted system calls return -EINTR */
46 current_thread_info()->restart_block.fn = do_no_restart_syscall;
47
48 err = __get_user(temp, &uc->uc_mcontext.version);
49 if (temp != MCONTEXT_VERSION)
50 goto badframe;
51 /* restore passed registers */
52 err |= __get_user(regs->r1, &gregs[0]);
53 err |= __get_user(regs->r2, &gregs[1]);
54 err |= __get_user(regs->r3, &gregs[2]);
55 err |= __get_user(regs->r4, &gregs[3]);
56 err |= __get_user(regs->r5, &gregs[4]);
57 err |= __get_user(regs->r6, &gregs[5]);
58 err |= __get_user(regs->r7, &gregs[6]);
59 err |= __get_user(regs->r8, &gregs[7]);
60 err |= __get_user(regs->r9, &gregs[8]);
61 err |= __get_user(regs->r10, &gregs[9]);
62 err |= __get_user(regs->r11, &gregs[10]);
63 err |= __get_user(regs->r12, &gregs[11]);
64 err |= __get_user(regs->r13, &gregs[12]);
65 err |= __get_user(regs->r14, &gregs[13]);
66 err |= __get_user(regs->r15, &gregs[14]);
67 err |= __get_user(sw->r16, &gregs[15]);
68 err |= __get_user(sw->r17, &gregs[16]);
69 err |= __get_user(sw->r18, &gregs[17]);
70 err |= __get_user(sw->r19, &gregs[18]);
71 err |= __get_user(sw->r20, &gregs[19]);
72 err |= __get_user(sw->r21, &gregs[20]);
73 err |= __get_user(sw->r22, &gregs[21]);
74 err |= __get_user(sw->r23, &gregs[22]);
75 /* gregs[23] is handled below */
76 err |= __get_user(sw->fp, &gregs[24]); /* Verify, should this be
77 settable */
78 err |= __get_user(sw->gp, &gregs[25]); /* Verify, should this be
79 settable */
80
81 err |= __get_user(temp, &gregs[26]); /* Not really necessary no user
82 settable bits */
83 err |= __get_user(regs->ea, &gregs[27]);
84
85 err |= __get_user(regs->ra, &gregs[23]);
86 err |= __get_user(regs->sp, &gregs[28]);
87
88 regs->orig_r2 = -1; /* disable syscall checks */
89
90 err |= restore_altstack(&uc->uc_stack);
91 if (err)
92 goto badframe;
93
94 *pr2 = regs->r2;
95 return err;
96
97badframe:
98 return 1;
99}
100
101asmlinkage int do_rt_sigreturn(struct switch_stack *sw)
102{
103 struct pt_regs *regs = (struct pt_regs *)(sw + 1);
104 /* Verify, can we follow the stack back */
105 struct rt_sigframe *frame = (struct rt_sigframe *) regs->sp;
106 sigset_t set;
107 int rval;
108
109 if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
110 goto badframe;
111
112 if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
113 goto badframe;
114
115 set_current_blocked(&set);
116
117 if (rt_restore_ucontext(regs, sw, &frame->uc, &rval))
118 goto badframe;
119
120 return rval;
121
122badframe:
123 force_sig(SIGSEGV, current);
124 return 0;
125}
126
127static inline int rt_setup_ucontext(struct ucontext *uc, struct pt_regs *regs)
128{
129 struct switch_stack *sw = (struct switch_stack *)regs - 1;
130 greg_t *gregs = uc->uc_mcontext.gregs;
131 int err = 0;
132
133 err |= __put_user(MCONTEXT_VERSION, &uc->uc_mcontext.version);
134 err |= __put_user(regs->r1, &gregs[0]);
135 err |= __put_user(regs->r2, &gregs[1]);
136 err |= __put_user(regs->r3, &gregs[2]);
137 err |= __put_user(regs->r4, &gregs[3]);
138 err |= __put_user(regs->r5, &gregs[4]);
139 err |= __put_user(regs->r6, &gregs[5]);
140 err |= __put_user(regs->r7, &gregs[6]);
141 err |= __put_user(regs->r8, &gregs[7]);
142 err |= __put_user(regs->r9, &gregs[8]);
143 err |= __put_user(regs->r10, &gregs[9]);
144 err |= __put_user(regs->r11, &gregs[10]);
145 err |= __put_user(regs->r12, &gregs[11]);
146 err |= __put_user(regs->r13, &gregs[12]);
147 err |= __put_user(regs->r14, &gregs[13]);
148 err |= __put_user(regs->r15, &gregs[14]);
149 err |= __put_user(sw->r16, &gregs[15]);
150 err |= __put_user(sw->r17, &gregs[16]);
151 err |= __put_user(sw->r18, &gregs[17]);
152 err |= __put_user(sw->r19, &gregs[18]);
153 err |= __put_user(sw->r20, &gregs[19]);
154 err |= __put_user(sw->r21, &gregs[20]);
155 err |= __put_user(sw->r22, &gregs[21]);
156 err |= __put_user(sw->r23, &gregs[22]);
157 err |= __put_user(regs->ra, &gregs[23]);
158 err |= __put_user(sw->fp, &gregs[24]);
159 err |= __put_user(sw->gp, &gregs[25]);
160 err |= __put_user(regs->ea, &gregs[27]);
161 err |= __put_user(regs->sp, &gregs[28]);
162 return err;
163}
164
165static inline void *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
166 size_t frame_size)
167{
168 unsigned long usp;
169
170 /* Default to using normal stack. */
171 usp = regs->sp;
172
173 /* This is the X/Open sanctioned signal stack switching. */
174 usp = sigsp(usp, ksig);
175
176 /* Verify, is it 32 or 64 bit aligned */
177 return (void *)((usp - frame_size) & -8UL);
178}
179
180static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
181 struct pt_regs *regs)
182{
183 struct rt_sigframe *frame;
184 int err = 0;
185
186 frame = get_sigframe(ksig, regs, sizeof(*frame));
187
188 if (ksig->ka.sa.sa_flags & SA_SIGINFO)
189 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
190
191 /* Create the ucontext. */
192 err |= __put_user(0, &frame->uc.uc_flags);
193 err |= __put_user(0, &frame->uc.uc_link);
194 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
195 err |= rt_setup_ucontext(&frame->uc, regs);
196 err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
197
198 if (err)
199 goto give_sigsegv;
200
201 /* Set up to return from userspace; jump to fixed address sigreturn
202 trampoline on kuser page. */
203 regs->ra = (unsigned long) (0x1040);
204
205 /* Set up registers for signal handler */
206 regs->sp = (unsigned long) frame;
207 regs->r4 = (unsigned long) ksig->sig;
208 regs->r5 = (unsigned long) &frame->info;
209 regs->r6 = (unsigned long) &frame->uc;
210 regs->ea = (unsigned long) ksig->ka.sa.sa_handler;
211 return 0;
212
213give_sigsegv:
214 force_sigsegv(ksig->sig, current);
215 return -EFAULT;
216}
217
218/*
219 * OK, we're invoking a handler
220 */
221static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
222{
223 int ret;
224 sigset_t *oldset = sigmask_to_save();
225
226 /* set up the stack frame */
227 ret = setup_rt_frame(ksig, oldset, regs);
228
229 signal_setup_done(ret, ksig, 0);
230}
231
232static int do_signal(struct pt_regs *regs)
233{
234 unsigned int retval = 0, continue_addr = 0, restart_addr = 0;
235 int restart = 0;
236 struct ksignal ksig;
237
238 current->thread.kregs = regs;
239
240 /*
241 * If we were from a system call, check for system call restarting...
242 */
243 if (regs->orig_r2 >= 0) {
244 continue_addr = regs->ea;
245 restart_addr = continue_addr - 4;
246 retval = regs->r2;
247
248 /*
249 * Prepare for system call restart. We do this here so that a
250 * debugger will see the already changed PC.
251 */
252 switch (retval) {
253 case ERESTART_RESTARTBLOCK:
254 restart = -2;
255 case ERESTARTNOHAND:
256 case ERESTARTSYS:
257 case ERESTARTNOINTR:
258 restart++;
259 regs->r2 = regs->orig_r2;
260 regs->r7 = regs->orig_r7;
261 regs->ea = restart_addr;
262 break;
263 }
264 }
265
266 if (get_signal(&ksig)) {
267 /* handler */
268 if (unlikely(restart && regs->ea == restart_addr)) {
269 if (retval == ERESTARTNOHAND ||
270 retval == ERESTART_RESTARTBLOCK ||
271 (retval == ERESTARTSYS
272 && !(ksig.ka.sa.sa_flags & SA_RESTART))) {
273 regs->r2 = EINTR;
274 regs->r7 = 1;
275 regs->ea = continue_addr;
276 }
277 }
278 handle_signal(&ksig, regs);
279 return 0;
280 }
281
282 /*
283 * No handler present
284 */
285 if (unlikely(restart) && regs->ea == restart_addr) {
286 regs->ea = continue_addr;
287 regs->r2 = __NR_restart_syscall;
288 }
289
290 /*
291 * If there's no signal to deliver, we just put the saved sigmask back.
292 */
293 restore_saved_sigmask();
294
295 return restart;
296}
297
298asmlinkage int do_notify_resume(struct pt_regs *regs)
299{
300 /*
301 * We want the common case to go fast, which is why we may in certain
302 * cases get here from kernel mode. Just return without doing anything
303 * if so.
304 */
305 if (!user_mode(regs))
306 return 0;
307
308 if (test_thread_flag(TIF_SIGPENDING)) {
309 int restart = do_signal(regs);
310
311 if (unlikely(restart)) {
312 /*
313 * Restart without handlers.
314 * Deal with it without leaving
315 * the kernel space.
316 */
317 return restart;
318 }
319 } else if (test_and_clear_thread_flag(TIF_NOTIFY_RESUME))
320 tracehook_notify_resume(regs);
321
322 return 0;
323}
diff --git a/arch/nios2/kernel/sys_nios2.c b/arch/nios2/kernel/sys_nios2.c
new file mode 100644
index 000000000000..cd390ec4f88b
--- /dev/null
+++ b/arch/nios2/kernel/sys_nios2.c
@@ -0,0 +1,53 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 * Copyright (C) 2011-2012 Tobias Klauser <tklauser@distanz.ch>
4 * Copyright (C) 2004 Microtronix Datacom Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/export.h>
12#include <linux/file.h>
13#include <linux/fs.h>
14#include <linux/slab.h>
15#include <linux/syscalls.h>
16
17#include <asm/cacheflush.h>
18#include <asm/traps.h>
19
20/* sys_cacheflush -- flush the processor cache. */
21asmlinkage int sys_cacheflush(unsigned long addr, unsigned long len,
22 unsigned int op)
23{
24 struct vm_area_struct *vma;
25
26 if (len == 0)
27 return 0;
28
29 /* We only support op 0 now, return error if op is non-zero.*/
30 if (op)
31 return -EINVAL;
32
33 /* Check for overflow */
34 if (addr + len < addr)
35 return -EFAULT;
36
37 /*
38 * Verify that the specified address region actually belongs
39 * to this process.
40 */
41 vma = find_vma(current->mm, addr);
42 if (vma == NULL || addr < vma->vm_start || addr + len > vma->vm_end)
43 return -EFAULT;
44
45 flush_cache_range(vma, addr, addr + len);
46
47 return 0;
48}
49
50asmlinkage int sys_getpagesize(void)
51{
52 return PAGE_SIZE;
53}
diff --git a/arch/nios2/kernel/syscall_table.c b/arch/nios2/kernel/syscall_table.c
new file mode 100644
index 000000000000..06e6ac1835b2
--- /dev/null
+++ b/arch/nios2/kernel/syscall_table.c
@@ -0,0 +1,29 @@
1/*
2 * Copyright Altera Corporation (C) 2013. All rights reserved
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#include <linux/syscalls.h>
19#include <linux/signal.h>
20#include <linux/unistd.h>
21
22#include <asm/syscalls.h>
23
24#undef __SYSCALL
25#define __SYSCALL(nr, call) [nr] = (call),
26
27void *sys_call_table[__NR_syscalls] = {
28#include <asm/unistd.h>
29};
diff --git a/arch/nios2/kernel/time.c b/arch/nios2/kernel/time.c
new file mode 100644
index 000000000000..7f4547418ee1
--- /dev/null
+++ b/arch/nios2/kernel/time.c
@@ -0,0 +1,308 @@
1/*
2 * Copyright (C) 2013-2014 Altera Corporation
3 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
4 * Copyright (C) 2004 Microtronix Datacom Ltd.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/interrupt.h>
12#include <linux/clockchips.h>
13#include <linux/clocksource.h>
14#include <linux/delay.h>
15#include <linux/of.h>
16#include <linux/of_address.h>
17#include <linux/of_irq.h>
18#include <linux/io.h>
19#include <linux/slab.h>
20
21#define ALTERA_TIMER_STATUS_REG 0
22#define ALTERA_TIMER_CONTROL_REG 4
23#define ALTERA_TIMER_PERIODL_REG 8
24#define ALTERA_TIMER_PERIODH_REG 12
25#define ALTERA_TIMER_SNAPL_REG 16
26#define ALTERA_TIMER_SNAPH_REG 20
27
28#define ALTERA_TIMER_CONTROL_ITO_MSK (0x1)
29#define ALTERA_TIMER_CONTROL_CONT_MSK (0x2)
30#define ALTERA_TIMER_CONTROL_START_MSK (0x4)
31#define ALTERA_TIMER_CONTROL_STOP_MSK (0x8)
32
33struct nios2_timer {
34 void __iomem *base;
35 unsigned long freq;
36};
37
38struct nios2_clockevent_dev {
39 struct nios2_timer timer;
40 struct clock_event_device ced;
41};
42
43struct nios2_clocksource {
44 struct nios2_timer timer;
45 struct clocksource cs;
46};
47
48static inline struct nios2_clockevent_dev *
49 to_nios2_clkevent(struct clock_event_device *evt)
50{
51 return container_of(evt, struct nios2_clockevent_dev, ced);
52}
53
54static inline struct nios2_clocksource *
55 to_nios2_clksource(struct clocksource *cs)
56{
57 return container_of(cs, struct nios2_clocksource, cs);
58}
59
60static u16 timer_readw(struct nios2_timer *timer, u32 offs)
61{
62 return readw(timer->base + offs);
63}
64
65static void timer_writew(struct nios2_timer *timer, u16 val, u32 offs)
66{
67 writew(val, timer->base + offs);
68}
69
70static inline unsigned long read_timersnapshot(struct nios2_timer *timer)
71{
72 unsigned long count;
73
74 timer_writew(timer, 0, ALTERA_TIMER_SNAPL_REG);
75 count = timer_readw(timer, ALTERA_TIMER_SNAPH_REG) << 16 |
76 timer_readw(timer, ALTERA_TIMER_SNAPL_REG);
77
78 return count;
79}
80
81static cycle_t nios2_timer_read(struct clocksource *cs)
82{
83 struct nios2_clocksource *nios2_cs = to_nios2_clksource(cs);
84 unsigned long flags;
85 u32 count;
86
87 local_irq_save(flags);
88 count = read_timersnapshot(&nios2_cs->timer);
89 local_irq_restore(flags);
90
91 /* Counter is counting down */
92 return ~count;
93}
94
95static struct nios2_clocksource nios2_cs = {
96 .cs = {
97 .name = "nios2-clksrc",
98 .rating = 250,
99 .read = nios2_timer_read,
100 .mask = CLOCKSOURCE_MASK(32),
101 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
102 },
103};
104
105cycles_t get_cycles(void)
106{
107 return nios2_timer_read(&nios2_cs.cs);
108}
109
110static void nios2_timer_start(struct nios2_timer *timer)
111{
112 u16 ctrl;
113
114 ctrl = timer_readw(timer, ALTERA_TIMER_CONTROL_REG);
115 ctrl |= ALTERA_TIMER_CONTROL_START_MSK;
116 timer_writew(timer, ctrl, ALTERA_TIMER_CONTROL_REG);
117}
118
119static void nios2_timer_stop(struct nios2_timer *timer)
120{
121 u16 ctrl;
122
123 ctrl = timer_readw(timer, ALTERA_TIMER_CONTROL_REG);
124 ctrl |= ALTERA_TIMER_CONTROL_STOP_MSK;
125 timer_writew(timer, ctrl, ALTERA_TIMER_CONTROL_REG);
126}
127
128static void nios2_timer_config(struct nios2_timer *timer, unsigned long period,
129 enum clock_event_mode mode)
130{
131 u16 ctrl;
132
133 /* The timer's actual period is one cycle greater than the value
134 * stored in the period register. */
135 period--;
136
137 ctrl = timer_readw(timer, ALTERA_TIMER_CONTROL_REG);
138 /* stop counter */
139 timer_writew(timer, ctrl | ALTERA_TIMER_CONTROL_STOP_MSK,
140 ALTERA_TIMER_CONTROL_REG);
141
142 /* write new count */
143 timer_writew(timer, period, ALTERA_TIMER_PERIODL_REG);
144 timer_writew(timer, period >> 16, ALTERA_TIMER_PERIODH_REG);
145
146 ctrl |= ALTERA_TIMER_CONTROL_START_MSK | ALTERA_TIMER_CONTROL_ITO_MSK;
147 if (mode == CLOCK_EVT_MODE_PERIODIC)
148 ctrl |= ALTERA_TIMER_CONTROL_CONT_MSK;
149 else
150 ctrl &= ~ALTERA_TIMER_CONTROL_CONT_MSK;
151 timer_writew(timer, ctrl, ALTERA_TIMER_CONTROL_REG);
152}
153
154static int nios2_timer_set_next_event(unsigned long delta,
155 struct clock_event_device *evt)
156{
157 struct nios2_clockevent_dev *nios2_ced = to_nios2_clkevent(evt);
158
159 nios2_timer_config(&nios2_ced->timer, delta, evt->mode);
160
161 return 0;
162}
163
164static void nios2_timer_set_mode(enum clock_event_mode mode,
165 struct clock_event_device *evt)
166{
167 unsigned long period;
168 struct nios2_clockevent_dev *nios2_ced = to_nios2_clkevent(evt);
169 struct nios2_timer *timer = &nios2_ced->timer;
170
171 switch (mode) {
172 case CLOCK_EVT_MODE_PERIODIC:
173 period = DIV_ROUND_UP(timer->freq, HZ);
174 nios2_timer_config(timer, period, CLOCK_EVT_MODE_PERIODIC);
175 break;
176 case CLOCK_EVT_MODE_ONESHOT:
177 case CLOCK_EVT_MODE_UNUSED:
178 case CLOCK_EVT_MODE_SHUTDOWN:
179 nios2_timer_stop(timer);
180 break;
181 case CLOCK_EVT_MODE_RESUME:
182 nios2_timer_start(timer);
183 break;
184 }
185}
186
187irqreturn_t timer_interrupt(int irq, void *dev_id)
188{
189 struct clock_event_device *evt = (struct clock_event_device *) dev_id;
190 struct nios2_clockevent_dev *nios2_ced = to_nios2_clkevent(evt);
191
192 /* Clear the interrupt condition */
193 timer_writew(&nios2_ced->timer, 0, ALTERA_TIMER_STATUS_REG);
194 evt->event_handler(evt);
195
196 return IRQ_HANDLED;
197}
198
199static void __init nios2_timer_get_base_and_freq(struct device_node *np,
200 void __iomem **base, u32 *freq)
201{
202 *base = of_iomap(np, 0);
203 if (!*base)
204 panic("Unable to map reg for %s\n", np->name);
205
206 if (of_property_read_u32(np, "clock-frequency", freq))
207 panic("Unable to get %s clock frequency\n", np->name);
208}
209
210static struct nios2_clockevent_dev nios2_ce = {
211 .ced = {
212 .name = "nios2-clkevent",
213 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
214 .rating = 250,
215 .shift = 32,
216 .set_next_event = nios2_timer_set_next_event,
217 .set_mode = nios2_timer_set_mode,
218 },
219};
220
221static __init void nios2_clockevent_init(struct device_node *timer)
222{
223 void __iomem *iobase;
224 u32 freq;
225 int irq;
226
227 nios2_timer_get_base_and_freq(timer, &iobase, &freq);
228
229 irq = irq_of_parse_and_map(timer, 0);
230 if (!irq)
231 panic("Unable to parse timer irq\n");
232
233 nios2_ce.timer.base = iobase;
234 nios2_ce.timer.freq = freq;
235
236 nios2_ce.ced.cpumask = cpumask_of(0);
237 nios2_ce.ced.irq = irq;
238
239 nios2_timer_stop(&nios2_ce.timer);
240 /* clear pending interrupt */
241 timer_writew(&nios2_ce.timer, 0, ALTERA_TIMER_STATUS_REG);
242
243 if (request_irq(irq, timer_interrupt, IRQF_TIMER, timer->name,
244 &nios2_ce.ced))
245 panic("Unable to setup timer irq\n");
246
247 clockevents_config_and_register(&nios2_ce.ced, freq, 1, ULONG_MAX);
248}
249
250static __init void nios2_clocksource_init(struct device_node *timer)
251{
252 unsigned int ctrl;
253 void __iomem *iobase;
254 u32 freq;
255
256 nios2_timer_get_base_and_freq(timer, &iobase, &freq);
257
258 nios2_cs.timer.base = iobase;
259 nios2_cs.timer.freq = freq;
260
261 clocksource_register_hz(&nios2_cs.cs, freq);
262
263 timer_writew(&nios2_cs.timer, USHRT_MAX, ALTERA_TIMER_PERIODL_REG);
264 timer_writew(&nios2_cs.timer, USHRT_MAX, ALTERA_TIMER_PERIODH_REG);
265
266 /* interrupt disable + continuous + start */
267 ctrl = ALTERA_TIMER_CONTROL_CONT_MSK | ALTERA_TIMER_CONTROL_START_MSK;
268 timer_writew(&nios2_cs.timer, ctrl, ALTERA_TIMER_CONTROL_REG);
269
270 /* Calibrate the delay loop directly */
271 lpj_fine = freq / HZ;
272}
273
274/*
275 * The first timer instance will use as a clockevent. If there are two or
276 * more instances, the second one gets used as clocksource and all
277 * others are unused.
278*/
279static void __init nios2_time_init(struct device_node *timer)
280{
281 static int num_called;
282
283 switch (num_called) {
284 case 0:
285 nios2_clockevent_init(timer);
286 break;
287 case 1:
288 nios2_clocksource_init(timer);
289 break;
290 default:
291 break;
292 }
293
294 num_called++;
295}
296
297void read_persistent_clock(struct timespec *ts)
298{
299 ts->tv_sec = mktime(2007, 1, 1, 0, 0, 0);
300 ts->tv_nsec = 0;
301}
302
303void __init time_init(void)
304{
305 clocksource_of_init();
306}
307
308CLOCKSOURCE_OF_DECLARE(nios2_timer, "altr,timer-1.0", nios2_time_init);
diff --git a/arch/nios2/kernel/traps.c b/arch/nios2/kernel/traps.c
new file mode 100644
index 000000000000..b7b97641a9a6
--- /dev/null
+++ b/arch/nios2/kernel/traps.c
@@ -0,0 +1,185 @@
1/*
2 * Hardware exception handling
3 *
4 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
5 * Copyright (C) 2004 Microtronix Datacom Ltd.
6 * Copyright (C) 2001 Vic Phillips
7 *
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file COPYING in the main directory of this
10 * archive for more details.
11 */
12
13#include <linux/sched.h>
14#include <linux/kernel.h>
15#include <linux/signal.h>
16#include <linux/export.h>
17#include <linux/mm.h>
18#include <linux/ptrace.h>
19
20#include <asm/traps.h>
21#include <asm/sections.h>
22#include <asm/uaccess.h>
23
24static DEFINE_SPINLOCK(die_lock);
25
26void die(const char *str, struct pt_regs *regs, long err)
27{
28 console_verbose();
29 spin_lock_irq(&die_lock);
30 pr_warn("Oops: %s, sig: %ld\n", str, err);
31 show_regs(regs);
32 spin_unlock_irq(&die_lock);
33 /*
34 * do_exit() should take care of panic'ing from an interrupt
35 * context so we don't handle it here
36 */
37 do_exit(err);
38}
39
40void _exception(int signo, struct pt_regs *regs, int code, unsigned long addr)
41{
42 siginfo_t info;
43
44 if (!user_mode(regs))
45 die("Exception in kernel mode", regs, signo);
46
47 info.si_signo = signo;
48 info.si_errno = 0;
49 info.si_code = code;
50 info.si_addr = (void __user *) addr;
51 force_sig_info(signo, &info, current);
52}
53
54/*
55 * The show_stack is an external API which we do not use ourselves.
56 */
57
58int kstack_depth_to_print = 48;
59
60void show_stack(struct task_struct *task, unsigned long *stack)
61{
62 unsigned long *endstack, addr;
63 int i;
64
65 if (!stack) {
66 if (task)
67 stack = (unsigned long *)task->thread.ksp;
68 else
69 stack = (unsigned long *)&stack;
70 }
71
72 addr = (unsigned long) stack;
73 endstack = (unsigned long *) PAGE_ALIGN(addr);
74
75 pr_emerg("Stack from %08lx:", (unsigned long)stack);
76 for (i = 0; i < kstack_depth_to_print; i++) {
77 if (stack + 1 > endstack)
78 break;
79 if (i % 8 == 0)
80 pr_emerg("\n ");
81 pr_emerg(" %08lx", *stack++);
82 }
83
84 pr_emerg("\nCall Trace:");
85 i = 0;
86 while (stack + 1 <= endstack) {
87 addr = *stack++;
88 /*
89 * If the address is either in the text segment of the
90 * kernel, or in the region which contains vmalloc'ed
91 * memory, it *may* be the address of a calling
92 * routine; if so, print it so that someone tracing
93 * down the cause of the crash will be able to figure
94 * out the call path that was taken.
95 */
96 if (((addr >= (unsigned long) _stext) &&
97 (addr <= (unsigned long) _etext))) {
98 if (i % 4 == 0)
99 pr_emerg("\n ");
100 pr_emerg(" [<%08lx>]", addr);
101 i++;
102 }
103 }
104 pr_emerg("\n");
105}
106
107void __init trap_init(void)
108{
109 /* Nothing to do here */
110}
111
112/* Breakpoint handler */
113asmlinkage void breakpoint_c(struct pt_regs *fp)
114{
115 /*
116 * The breakpoint entry code has moved the PC on by 4 bytes, so we must
117 * move it back. This could be done on the host but we do it here
118 * because monitor.S of JTAG gdbserver does it too.
119 */
120 fp->ea -= 4;
121 _exception(SIGTRAP, fp, TRAP_BRKPT, fp->ea);
122}
123
124#ifndef CONFIG_NIOS2_ALIGNMENT_TRAP
125/* Alignment exception handler */
126asmlinkage void handle_unaligned_c(struct pt_regs *fp, int cause)
127{
128 unsigned long addr = RDCTL(CTL_BADADDR);
129
130 cause >>= 2;
131 fp->ea -= 4;
132
133 if (fixup_exception(fp))
134 return;
135
136 if (!user_mode(fp)) {
137 pr_alert("Unaligned access from kernel mode, this might be a hardware\n");
138 pr_alert("problem, dump registers and restart the instruction\n");
139 pr_alert(" BADADDR 0x%08lx\n", addr);
140 pr_alert(" cause %d\n", cause);
141 pr_alert(" op-code 0x%08lx\n", *(unsigned long *)(fp->ea));
142 show_regs(fp);
143 return;
144 }
145
146 _exception(SIGBUS, fp, BUS_ADRALN, addr);
147}
148#endif /* CONFIG_NIOS2_ALIGNMENT_TRAP */
149
150/* Illegal instruction handler */
151asmlinkage void handle_illegal_c(struct pt_regs *fp)
152{
153 fp->ea -= 4;
154 _exception(SIGILL, fp, ILL_ILLOPC, fp->ea);
155}
156
157/* Supervisor instruction handler */
158asmlinkage void handle_supervisor_instr(struct pt_regs *fp)
159{
160 fp->ea -= 4;
161 _exception(SIGILL, fp, ILL_PRVOPC, fp->ea);
162}
163
164/* Division error handler */
165asmlinkage void handle_diverror_c(struct pt_regs *fp)
166{
167 fp->ea -= 4;
168 _exception(SIGFPE, fp, FPE_INTDIV, fp->ea);
169}
170
171/* Unhandled exception handler */
172asmlinkage void unhandled_exception(struct pt_regs *regs, int cause)
173{
174 unsigned long addr = RDCTL(CTL_BADADDR);
175
176 cause /= 4;
177
178 pr_emerg("Unhandled exception #%d in %s mode (badaddr=0x%08lx)\n",
179 cause, user_mode(regs) ? "user" : "kernel", addr);
180
181 regs->ea -= 4;
182 show_regs(regs);
183
184 pr_emerg("opcode: 0x%08lx\n", *(unsigned long *)(regs->ea));
185}
diff --git a/arch/nios2/kernel/vmlinux.lds.S b/arch/nios2/kernel/vmlinux.lds.S
new file mode 100644
index 000000000000..326fab40a9de
--- /dev/null
+++ b/arch/nios2/kernel/vmlinux.lds.S
@@ -0,0 +1,75 @@
1/*
2 * Copyright (C) 2009 Thomas Chou <thomas@wytron.com.tw>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18#include <asm/page.h>
19#include <asm-generic/vmlinux.lds.h>
20#include <asm/cache.h>
21#include <asm/thread_info.h>
22
23OUTPUT_FORMAT("elf32-littlenios2", "elf32-littlenios2", "elf32-littlenios2")
24
25OUTPUT_ARCH(nios)
26ENTRY(_start) /* Defined in head.S */
27
28jiffies = jiffies_64;
29
30SECTIONS
31{
32 . = CONFIG_NIOS2_MEM_BASE | CONFIG_NIOS2_KERNEL_REGION_BASE;
33
34 _text = .;
35 _stext = .;
36 HEAD_TEXT_SECTION
37 .text : {
38 TEXT_TEXT
39 SCHED_TEXT
40 LOCK_TEXT
41 IRQENTRY_TEXT
42 KPROBES_TEXT
43 } =0
44 _etext = .;
45
46 .got : {
47 *(.got.plt)
48 *(.igot.plt)
49 *(.got)
50 *(.igot)
51 }
52
53 EXCEPTION_TABLE(L1_CACHE_BYTES)
54
55 . = ALIGN(PAGE_SIZE);
56 __init_begin = .;
57 INIT_TEXT_SECTION(PAGE_SIZE)
58 INIT_DATA_SECTION(PAGE_SIZE)
59 PERCPU_SECTION(L1_CACHE_BYTES)
60 __init_end = .;
61
62 _sdata = .;
63 RO_DATA_SECTION(PAGE_SIZE)
64 RW_DATA_SECTION(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE)
65 _edata = .;
66
67 BSS_SECTION(0, 0, 0)
68 _end = .;
69
70 STABS_DEBUG
71 DWARF_DEBUG
72 NOTES
73
74 DISCARDS
75}
diff --git a/arch/nios2/lib/Makefile b/arch/nios2/lib/Makefile
new file mode 100644
index 000000000000..557256628ecd
--- /dev/null
+++ b/arch/nios2/lib/Makefile
@@ -0,0 +1,8 @@
1#
2# Makefile for Nios2-specific library files.
3#
4
5lib-y += delay.o
6lib-y += memcpy.o
7lib-y += memmove.o
8lib-y += memset.o
diff --git a/arch/nios2/lib/delay.c b/arch/nios2/lib/delay.c
new file mode 100644
index 000000000000..088119cd0cc5
--- /dev/null
+++ b/arch/nios2/lib/delay.c
@@ -0,0 +1,52 @@
1/* Copyright Altera Corporation (C) 2014. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License, version 2,
5 * as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *
15 */
16
17#include <linux/module.h>
18#include <asm/delay.h>
19#include <asm/param.h>
20#include <asm/processor.h>
21#include <asm/timex.h>
22
23void __delay(unsigned long cycles)
24{
25 cycles_t start = get_cycles();
26
27 while ((get_cycles() - start) < cycles)
28 cpu_relax();
29}
30EXPORT_SYMBOL(__delay);
31
32void __const_udelay(unsigned long xloops)
33{
34 u64 loops;
35
36 loops = (u64)xloops * loops_per_jiffy * HZ;
37
38 __delay(loops >> 32);
39}
40EXPORT_SYMBOL(__const_udelay);
41
42void __udelay(unsigned long usecs)
43{
44 __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
45}
46EXPORT_SYMBOL(__udelay);
47
48void __ndelay(unsigned long nsecs)
49{
50 __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
51}
52EXPORT_SYMBOL(__ndelay);
diff --git a/arch/nios2/lib/memcpy.c b/arch/nios2/lib/memcpy.c
new file mode 100644
index 000000000000..1715f5d28b11
--- /dev/null
+++ b/arch/nios2/lib/memcpy.c
@@ -0,0 +1,202 @@
1/* Extracted from GLIBC memcpy.c and memcopy.h, which is:
2 Copyright (C) 1991, 1992, 1993, 1997, 2004 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Torbjorn Granlund (tege@sics.se).
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
19
20#include <linux/types.h>
21
22/* Type to use for aligned memory operations.
23 This should normally be the biggest type supported by a single load
24 and store. */
25#define op_t unsigned long int
26#define OPSIZ (sizeof(op_t))
27
28/* Optimal type for storing bytes in registers. */
29#define reg_char char
30
31#define MERGE(w0, sh_1, w1, sh_2) (((w0) >> (sh_1)) | ((w1) << (sh_2)))
32
33/* Copy exactly NBYTES bytes from SRC_BP to DST_BP,
34 without any assumptions about alignment of the pointers. */
35#define BYTE_COPY_FWD(dst_bp, src_bp, nbytes) \
36do { \
37 size_t __nbytes = (nbytes); \
38 while (__nbytes > 0) { \
39 unsigned char __x = ((unsigned char *) src_bp)[0]; \
40 src_bp += 1; \
41 __nbytes -= 1; \
42 ((unsigned char *) dst_bp)[0] = __x; \
43 dst_bp += 1; \
44 } \
45} while (0)
46
47/* Copy *up to* NBYTES bytes from SRC_BP to DST_BP, with
48 the assumption that DST_BP is aligned on an OPSIZ multiple. If
49 not all bytes could be easily copied, store remaining number of bytes
50 in NBYTES_LEFT, otherwise store 0. */
51/* extern void _wordcopy_fwd_aligned __P ((long int, long int, size_t)); */
52/* extern void _wordcopy_fwd_dest_aligned __P ((long int, long int, size_t)); */
53#define WORD_COPY_FWD(dst_bp, src_bp, nbytes_left, nbytes) \
54do { \
55 if (src_bp % OPSIZ == 0) \
56 _wordcopy_fwd_aligned(dst_bp, src_bp, (nbytes) / OPSIZ);\
57 else \
58 _wordcopy_fwd_dest_aligned(dst_bp, src_bp, (nbytes) / OPSIZ);\
59 src_bp += (nbytes) & -OPSIZ; \
60 dst_bp += (nbytes) & -OPSIZ; \
61 (nbytes_left) = (nbytes) % OPSIZ; \
62} while (0)
63
64
65/* Threshold value for when to enter the unrolled loops. */
66#define OP_T_THRES 16
67
68/* _wordcopy_fwd_aligned -- Copy block beginning at SRCP to
69 block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
70 Both SRCP and DSTP should be aligned for memory operations on `op_t's. */
71/* stream-lined (read x8 + write x8) */
72static void _wordcopy_fwd_aligned(long int dstp, long int srcp, size_t len)
73{
74 while (len > 7) {
75 register op_t a0, a1, a2, a3, a4, a5, a6, a7;
76
77 a0 = ((op_t *) srcp)[0];
78 a1 = ((op_t *) srcp)[1];
79 a2 = ((op_t *) srcp)[2];
80 a3 = ((op_t *) srcp)[3];
81 a4 = ((op_t *) srcp)[4];
82 a5 = ((op_t *) srcp)[5];
83 a6 = ((op_t *) srcp)[6];
84 a7 = ((op_t *) srcp)[7];
85 ((op_t *) dstp)[0] = a0;
86 ((op_t *) dstp)[1] = a1;
87 ((op_t *) dstp)[2] = a2;
88 ((op_t *) dstp)[3] = a3;
89 ((op_t *) dstp)[4] = a4;
90 ((op_t *) dstp)[5] = a5;
91 ((op_t *) dstp)[6] = a6;
92 ((op_t *) dstp)[7] = a7;
93
94 srcp += 8 * OPSIZ;
95 dstp += 8 * OPSIZ;
96 len -= 8;
97 }
98 while (len > 0) {
99 *(op_t *)dstp = *(op_t *)srcp;
100
101 srcp += OPSIZ;
102 dstp += OPSIZ;
103 len -= 1;
104 }
105}
106
107/* _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to
108 block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
109 DSTP should be aligned for memory operations on `op_t's, but SRCP must
110 *not* be aligned. */
111/* stream-lined (read x4 + write x4) */
112static void _wordcopy_fwd_dest_aligned(long int dstp, long int srcp,
113 size_t len)
114{
115 op_t ap;
116 int sh_1, sh_2;
117
118 /* Calculate how to shift a word read at the memory operation
119 aligned srcp to make it aligned for copy. */
120
121 sh_1 = 8 * (srcp % OPSIZ);
122 sh_2 = 8 * OPSIZ - sh_1;
123
124 /* Make SRCP aligned by rounding it down to the beginning of the `op_t'
125 it points in the middle of. */
126 srcp &= -OPSIZ;
127 ap = ((op_t *) srcp)[0];
128 srcp += OPSIZ;
129
130 while (len > 3) {
131 op_t a0, a1, a2, a3;
132
133 a0 = ((op_t *) srcp)[0];
134 a1 = ((op_t *) srcp)[1];
135 a2 = ((op_t *) srcp)[2];
136 a3 = ((op_t *) srcp)[3];
137 ((op_t *) dstp)[0] = MERGE(ap, sh_1, a0, sh_2);
138 ((op_t *) dstp)[1] = MERGE(a0, sh_1, a1, sh_2);
139 ((op_t *) dstp)[2] = MERGE(a1, sh_1, a2, sh_2);
140 ((op_t *) dstp)[3] = MERGE(a2, sh_1, a3, sh_2);
141
142 ap = a3;
143 srcp += 4 * OPSIZ;
144 dstp += 4 * OPSIZ;
145 len -= 4;
146 }
147 while (len > 0) {
148 register op_t a0;
149
150 a0 = ((op_t *) srcp)[0];
151 ((op_t *) dstp)[0] = MERGE(ap, sh_1, a0, sh_2);
152
153 ap = a0;
154 srcp += OPSIZ;
155 dstp += OPSIZ;
156 len -= 1;
157 }
158}
159
160void *memcpy(void *dstpp, const void *srcpp, size_t len)
161{
162 unsigned long int dstp = (long int) dstpp;
163 unsigned long int srcp = (long int) srcpp;
164
165 /* Copy from the beginning to the end. */
166
167 /* If there not too few bytes to copy, use word copy. */
168 if (len >= OP_T_THRES) {
169 /* Copy just a few bytes to make DSTP aligned. */
170 len -= (-dstp) % OPSIZ;
171 BYTE_COPY_FWD(dstp, srcp, (-dstp) % OPSIZ);
172
173 /* Copy whole pages from SRCP to DSTP by virtual address
174 manipulation, as much as possible. */
175
176 /* PAGE_COPY_FWD_MAYBE (dstp, srcp, len, len); */
177
178 /* Copy from SRCP to DSTP taking advantage of the known
179 alignment of DSTP. Number of bytes remaining is put in the
180 third argument, i.e. in LEN. This number may vary from
181 machine to machine. */
182
183 WORD_COPY_FWD(dstp, srcp, len, len);
184
185 /* Fall out and copy the tail. */
186 }
187
188 /* There are just a few bytes to copy. Use byte memory operations. */
189 BYTE_COPY_FWD(dstp, srcp, len);
190
191 return dstpp;
192}
193
194void *memcpyb(void *dstpp, const void *srcpp, unsigned len)
195{
196 unsigned long int dstp = (long int) dstpp;
197 unsigned long int srcp = (long int) srcpp;
198
199 BYTE_COPY_FWD(dstp, srcp, len);
200
201 return dstpp;
202}
diff --git a/arch/nios2/lib/memmove.c b/arch/nios2/lib/memmove.c
new file mode 100644
index 000000000000..c65ef517eb80
--- /dev/null
+++ b/arch/nios2/lib/memmove.c
@@ -0,0 +1,82 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#include <linux/types.h>
11#include <linux/string.h>
12
13#ifdef __HAVE_ARCH_MEMMOVE
14void *memmove(void *d, const void *s, size_t count)
15{
16 unsigned long dst, src;
17
18 if (!count)
19 return d;
20
21 if (d < s) {
22 dst = (unsigned long) d;
23 src = (unsigned long) s;
24
25 if ((count < 8) || ((dst ^ src) & 3))
26 goto restup;
27
28 if (dst & 1) {
29 *(char *)dst++ = *(char *)src++;
30 count--;
31 }
32 if (dst & 2) {
33 *(short *)dst = *(short *)src;
34 src += 2;
35 dst += 2;
36 count -= 2;
37 }
38 while (count > 3) {
39 *(long *)dst = *(long *)src;
40 src += 4;
41 dst += 4;
42 count -= 4;
43 }
44restup:
45 while (count--)
46 *(char *)dst++ = *(char *)src++;
47 } else {
48 dst = (unsigned long) d + count;
49 src = (unsigned long) s + count;
50
51 if ((count < 8) || ((dst ^ src) & 3))
52 goto restdown;
53
54 if (dst & 1) {
55 src--;
56 dst--;
57 count--;
58 *(char *)dst = *(char *)src;
59 }
60 if (dst & 2) {
61 src -= 2;
62 dst -= 2;
63 count -= 2;
64 *(short *)dst = *(short *)src;
65 }
66 while (count > 3) {
67 src -= 4;
68 dst -= 4;
69 count -= 4;
70 *(long *)dst = *(long *)src;
71 }
72restdown:
73 while (count--) {
74 src--;
75 dst--;
76 *(char *)dst = *(char *)src;
77 }
78 }
79
80 return d;
81}
82#endif /* __HAVE_ARCH_MEMMOVE */
diff --git a/arch/nios2/lib/memset.c b/arch/nios2/lib/memset.c
new file mode 100644
index 000000000000..65e97802f5cc
--- /dev/null
+++ b/arch/nios2/lib/memset.c
@@ -0,0 +1,81 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2004 Microtronix Datacom Ltd
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#include <linux/types.h>
11#include <linux/string.h>
12
13#ifdef __HAVE_ARCH_MEMSET
14void *memset(void *s, int c, size_t count)
15{
16 int destptr, charcnt, dwordcnt, fill8reg, wrkrega;
17
18 if (!count)
19 return s;
20
21 c &= 0xFF;
22
23 if (count <= 8) {
24 char *xs = (char *) s;
25
26 while (count--)
27 *xs++ = c;
28 return s;
29 }
30
31 __asm__ __volatile__ (
32 /* fill8 %3, %5 (c & 0xff) */
33 " slli %4, %5, 8\n"
34 " or %4, %4, %5\n"
35 " slli %3, %4, 16\n"
36 " or %3, %3, %4\n"
37 /* Word-align %0 (s) if necessary */
38 " andi %4, %0, 0x01\n"
39 " beq %4, zero, 1f\n"
40 " addi %1, %1, -1\n"
41 " stb %3, 0(%0)\n"
42 " addi %0, %0, 1\n"
43 "1: mov %2, %1\n"
44 /* Dword-align %0 (s) if necessary */
45 " andi %4, %0, 0x02\n"
46 " beq %4, zero, 2f\n"
47 " addi %1, %1, -2\n"
48 " sth %3, 0(%0)\n"
49 " addi %0, %0, 2\n"
50 " mov %2, %1\n"
51 /* %1 and %2 are how many more bytes to set */
52 "2: srli %2, %2, 2\n"
53 /* %2 is how many dwords to set */
54 "3: stw %3, 0(%0)\n"
55 " addi %0, %0, 4\n"
56 " addi %2, %2, -1\n"
57 " bne %2, zero, 3b\n"
58 /* store residual word and/or byte if necessary */
59 " andi %4, %1, 0x02\n"
60 " beq %4, zero, 4f\n"
61 " sth %3, 0(%0)\n"
62 " addi %0, %0, 2\n"
63 /* store residual byte if necessary */
64 "4: andi %4, %1, 0x01\n"
65 " beq %4, zero, 5f\n"
66 " stb %3, 0(%0)\n"
67 "5:\n"
68 : "=r" (destptr), /* %0 Output */
69 "=r" (charcnt), /* %1 Output */
70 "=r" (dwordcnt), /* %2 Output */
71 "=r" (fill8reg), /* %3 Output */
72 "=r" (wrkrega) /* %4 Output */
73 : "r" (c), /* %5 Input */
74 "0" (s), /* %0 Input/Output */
75 "1" (count) /* %1 Input/Output */
76 : "memory" /* clobbered */
77 );
78
79 return s;
80}
81#endif /* __HAVE_ARCH_MEMSET */
diff --git a/arch/nios2/mm/Makefile b/arch/nios2/mm/Makefile
new file mode 100644
index 000000000000..3cbd0840873c
--- /dev/null
+++ b/arch/nios2/mm/Makefile
@@ -0,0 +1,14 @@
1#
2# Makefile for the Nios2-specific parts of the memory manager.
3#
4
5obj-y += cacheflush.o
6obj-y += dma-mapping.o
7obj-y += extable.o
8obj-y += fault.o
9obj-y += init.o
10obj-y += ioremap.o
11obj-y += mmu_context.o
12obj-y += pgtable.o
13obj-y += tlb.o
14obj-y += uaccess.o
diff --git a/arch/nios2/mm/cacheflush.c b/arch/nios2/mm/cacheflush.c
new file mode 100644
index 000000000000..2ae482b42669
--- /dev/null
+++ b/arch/nios2/mm/cacheflush.c
@@ -0,0 +1,271 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2009, Wind River Systems Inc
7 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
8 */
9
10#include <linux/export.h>
11#include <linux/sched.h>
12#include <linux/mm.h>
13#include <linux/fs.h>
14
15#include <asm/cacheflush.h>
16#include <asm/cpuinfo.h>
17
18static void __flush_dcache(unsigned long start, unsigned long end)
19{
20 unsigned long addr;
21
22 start &= ~(cpuinfo.dcache_line_size - 1);
23 end += (cpuinfo.dcache_line_size - 1);
24 end &= ~(cpuinfo.dcache_line_size - 1);
25
26 if (end > start + cpuinfo.dcache_size)
27 end = start + cpuinfo.dcache_size;
28
29 for (addr = start; addr < end; addr += cpuinfo.dcache_line_size) {
30 __asm__ __volatile__ (" flushda 0(%0)\n"
31 : /* Outputs */
32 : /* Inputs */ "r"(addr)
33 /* : No clobber */);
34 }
35}
36
37static void __flush_dcache_all(unsigned long start, unsigned long end)
38{
39 unsigned long addr;
40
41 start &= ~(cpuinfo.dcache_line_size - 1);
42 end += (cpuinfo.dcache_line_size - 1);
43 end &= ~(cpuinfo.dcache_line_size - 1);
44
45 if (end > start + cpuinfo.dcache_size)
46 end = start + cpuinfo.dcache_size;
47
48 for (addr = start; addr < end; addr += cpuinfo.dcache_line_size) {
49 __asm__ __volatile__ (" flushd 0(%0)\n"
50 : /* Outputs */
51 : /* Inputs */ "r"(addr)
52 /* : No clobber */);
53 }
54}
55
56static void __invalidate_dcache(unsigned long start, unsigned long end)
57{
58 unsigned long addr;
59
60 start &= ~(cpuinfo.dcache_line_size - 1);
61 end += (cpuinfo.dcache_line_size - 1);
62 end &= ~(cpuinfo.dcache_line_size - 1);
63
64 if (end > start + cpuinfo.dcache_size)
65 end = start + cpuinfo.dcache_size;
66
67 for (addr = start; addr < end; addr += cpuinfo.dcache_line_size) {
68 __asm__ __volatile__ (" initda 0(%0)\n"
69 : /* Outputs */
70 : /* Inputs */ "r"(addr)
71 /* : No clobber */);
72 }
73}
74
75static void __flush_icache(unsigned long start, unsigned long end)
76{
77 unsigned long addr;
78
79 start &= ~(cpuinfo.icache_line_size - 1);
80 end += (cpuinfo.icache_line_size - 1);
81 end &= ~(cpuinfo.icache_line_size - 1);
82
83 if (end > start + cpuinfo.icache_size)
84 end = start + cpuinfo.icache_size;
85
86 for (addr = start; addr < end; addr += cpuinfo.icache_line_size) {
87 __asm__ __volatile__ (" flushi %0\n"
88 : /* Outputs */
89 : /* Inputs */ "r"(addr)
90 /* : No clobber */);
91 }
92 __asm__ __volatile(" flushp\n");
93}
94
95static void flush_aliases(struct address_space *mapping, struct page *page)
96{
97 struct mm_struct *mm = current->active_mm;
98 struct vm_area_struct *mpnt;
99 pgoff_t pgoff;
100
101 pgoff = page->index;
102
103 flush_dcache_mmap_lock(mapping);
104 vma_interval_tree_foreach(mpnt, &mapping->i_mmap, pgoff, pgoff) {
105 unsigned long offset;
106
107 if (mpnt->vm_mm != mm)
108 continue;
109 if (!(mpnt->vm_flags & VM_MAYSHARE))
110 continue;
111
112 offset = (pgoff - mpnt->vm_pgoff) << PAGE_SHIFT;
113 flush_cache_page(mpnt, mpnt->vm_start + offset,
114 page_to_pfn(page));
115 }
116 flush_dcache_mmap_unlock(mapping);
117}
118
119void flush_cache_all(void)
120{
121 __flush_dcache_all(0, cpuinfo.dcache_size);
122 __flush_icache(0, cpuinfo.icache_size);
123}
124
125void flush_cache_mm(struct mm_struct *mm)
126{
127 flush_cache_all();
128}
129
130void flush_cache_dup_mm(struct mm_struct *mm)
131{
132 flush_cache_all();
133}
134
135void flush_icache_range(unsigned long start, unsigned long end)
136{
137 __flush_icache(start, end);
138}
139
140void flush_dcache_range(unsigned long start, unsigned long end)
141{
142 __flush_dcache(start, end);
143}
144EXPORT_SYMBOL(flush_dcache_range);
145
146void invalidate_dcache_range(unsigned long start, unsigned long end)
147{
148 __invalidate_dcache(start, end);
149}
150EXPORT_SYMBOL(invalidate_dcache_range);
151
152void flush_cache_range(struct vm_area_struct *vma, unsigned long start,
153 unsigned long end)
154{
155 __flush_dcache(start, end);
156 if (vma == NULL || (vma->vm_flags & VM_EXEC))
157 __flush_icache(start, end);
158}
159
160void flush_icache_page(struct vm_area_struct *vma, struct page *page)
161{
162 unsigned long start = (unsigned long) page_address(page);
163 unsigned long end = start + PAGE_SIZE;
164
165 __flush_icache(start, end);
166}
167
168void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr,
169 unsigned long pfn)
170{
171 unsigned long start = vmaddr;
172 unsigned long end = start + PAGE_SIZE;
173
174 __flush_dcache(start, end);
175 if (vma->vm_flags & VM_EXEC)
176 __flush_icache(start, end);
177}
178
179void flush_dcache_page(struct page *page)
180{
181 struct address_space *mapping;
182
183 /*
184 * The zero page is never written to, so never has any dirty
185 * cache lines, and therefore never needs to be flushed.
186 */
187 if (page == ZERO_PAGE(0))
188 return;
189
190 mapping = page_mapping(page);
191
192 /* Flush this page if there are aliases. */
193 if (mapping && !mapping_mapped(mapping)) {
194 clear_bit(PG_dcache_clean, &page->flags);
195 } else {
196 unsigned long start = (unsigned long)page_address(page);
197
198 __flush_dcache_all(start, start + PAGE_SIZE);
199 if (mapping)
200 flush_aliases(mapping, page);
201 set_bit(PG_dcache_clean, &page->flags);
202 }
203}
204EXPORT_SYMBOL(flush_dcache_page);
205
206void update_mmu_cache(struct vm_area_struct *vma,
207 unsigned long address, pte_t *pte)
208{
209 unsigned long pfn = pte_pfn(*pte);
210 struct page *page;
211
212 if (!pfn_valid(pfn))
213 return;
214
215 /*
216 * The zero page is never written to, so never has any dirty
217 * cache lines, and therefore never needs to be flushed.
218 */
219 page = pfn_to_page(pfn);
220 if (page == ZERO_PAGE(0))
221 return;
222
223 if (!PageReserved(page) &&
224 !test_and_set_bit(PG_dcache_clean, &page->flags)) {
225 unsigned long start = page_to_virt(page);
226 struct address_space *mapping;
227
228 __flush_dcache(start, start + PAGE_SIZE);
229
230 mapping = page_mapping(page);
231 if (mapping)
232 flush_aliases(mapping, page);
233 }
234}
235
236void copy_user_page(void *vto, void *vfrom, unsigned long vaddr,
237 struct page *to)
238{
239 __flush_dcache(vaddr, vaddr + PAGE_SIZE);
240 copy_page(vto, vfrom);
241 __flush_dcache((unsigned long)vto, (unsigned long)vto + PAGE_SIZE);
242}
243
244void clear_user_page(void *addr, unsigned long vaddr, struct page *page)
245{
246 __flush_dcache(vaddr, vaddr + PAGE_SIZE);
247 clear_page(addr);
248 __flush_dcache((unsigned long)addr, (unsigned long)addr + PAGE_SIZE);
249}
250
251void copy_from_user_page(struct vm_area_struct *vma, struct page *page,
252 unsigned long user_vaddr,
253 void *dst, void *src, int len)
254{
255 flush_cache_page(vma, user_vaddr, page_to_pfn(page));
256 memcpy(dst, src, len);
257 __flush_dcache((unsigned long)src, (unsigned long)src + len);
258 if (vma->vm_flags & VM_EXEC)
259 __flush_icache((unsigned long)src, (unsigned long)src + len);
260}
261
262void copy_to_user_page(struct vm_area_struct *vma, struct page *page,
263 unsigned long user_vaddr,
264 void *dst, void *src, int len)
265{
266 flush_cache_page(vma, user_vaddr, page_to_pfn(page));
267 memcpy(dst, src, len);
268 __flush_dcache((unsigned long)dst, (unsigned long)dst + len);
269 if (vma->vm_flags & VM_EXEC)
270 __flush_icache((unsigned long)dst, (unsigned long)dst + len);
271}
diff --git a/arch/nios2/mm/dma-mapping.c b/arch/nios2/mm/dma-mapping.c
new file mode 100644
index 000000000000..ac5da7594f0b
--- /dev/null
+++ b/arch/nios2/mm/dma-mapping.c
@@ -0,0 +1,186 @@
1/*
2 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2009 Wind River Systems Inc
4 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
5 *
6 * Based on DMA code from MIPS.
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12
13#include <linux/types.h>
14#include <linux/mm.h>
15#include <linux/export.h>
16#include <linux/string.h>
17#include <linux/scatterlist.h>
18#include <linux/dma-mapping.h>
19#include <linux/io.h>
20#include <linux/cache.h>
21#include <asm/cacheflush.h>
22
23
24void *dma_alloc_coherent(struct device *dev, size_t size,
25 dma_addr_t *dma_handle, gfp_t gfp)
26{
27 void *ret;
28
29 /* ignore region specifiers */
30 gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
31
32 /* optimized page clearing */
33 gfp |= __GFP_ZERO;
34
35 if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff))
36 gfp |= GFP_DMA;
37
38 ret = (void *) __get_free_pages(gfp, get_order(size));
39 if (ret != NULL) {
40 *dma_handle = virt_to_phys(ret);
41 flush_dcache_range((unsigned long) ret,
42 (unsigned long) ret + size);
43 ret = UNCAC_ADDR(ret);
44 }
45
46 return ret;
47}
48EXPORT_SYMBOL(dma_alloc_coherent);
49
50void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
51 dma_addr_t dma_handle)
52{
53 unsigned long addr = (unsigned long) CAC_ADDR((unsigned long) vaddr);
54
55 free_pages(addr, get_order(size));
56}
57EXPORT_SYMBOL(dma_free_coherent);
58
59int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
60 enum dma_data_direction direction)
61{
62 int i;
63
64 BUG_ON(!valid_dma_direction(direction));
65
66 for_each_sg(sg, sg, nents, i) {
67 void *addr;
68
69 addr = sg_virt(sg);
70 if (addr) {
71 __dma_sync_for_device(addr, sg->length, direction);
72 sg->dma_address = sg_phys(sg);
73 }
74 }
75
76 return nents;
77}
78EXPORT_SYMBOL(dma_map_sg);
79
80dma_addr_t dma_map_page(struct device *dev, struct page *page,
81 unsigned long offset, size_t size,
82 enum dma_data_direction direction)
83{
84 void *addr;
85
86 BUG_ON(!valid_dma_direction(direction));
87
88 addr = page_address(page) + offset;
89 __dma_sync_for_device(addr, size, direction);
90
91 return page_to_phys(page) + offset;
92}
93EXPORT_SYMBOL(dma_map_page);
94
95void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
96 enum dma_data_direction direction)
97{
98 BUG_ON(!valid_dma_direction(direction));
99
100 __dma_sync_for_cpu(phys_to_virt(dma_address), size, direction);
101}
102EXPORT_SYMBOL(dma_unmap_page);
103
104void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
105 enum dma_data_direction direction)
106{
107 void *addr;
108 int i;
109
110 BUG_ON(!valid_dma_direction(direction));
111
112 if (direction == DMA_TO_DEVICE)
113 return;
114
115 for_each_sg(sg, sg, nhwentries, i) {
116 addr = sg_virt(sg);
117 if (addr)
118 __dma_sync_for_cpu(addr, sg->length, direction);
119 }
120}
121EXPORT_SYMBOL(dma_unmap_sg);
122
123void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
124 size_t size, enum dma_data_direction direction)
125{
126 BUG_ON(!valid_dma_direction(direction));
127
128 __dma_sync_for_cpu(phys_to_virt(dma_handle), size, direction);
129}
130EXPORT_SYMBOL(dma_sync_single_for_cpu);
131
132void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
133 size_t size, enum dma_data_direction direction)
134{
135 BUG_ON(!valid_dma_direction(direction));
136
137 __dma_sync_for_device(phys_to_virt(dma_handle), size, direction);
138}
139EXPORT_SYMBOL(dma_sync_single_for_device);
140
141void dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
142 unsigned long offset, size_t size,
143 enum dma_data_direction direction)
144{
145 BUG_ON(!valid_dma_direction(direction));
146
147 __dma_sync_for_cpu(phys_to_virt(dma_handle), size, direction);
148}
149EXPORT_SYMBOL(dma_sync_single_range_for_cpu);
150
151void dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
152 unsigned long offset, size_t size,
153 enum dma_data_direction direction)
154{
155 BUG_ON(!valid_dma_direction(direction));
156
157 __dma_sync_for_device(phys_to_virt(dma_handle), size, direction);
158}
159EXPORT_SYMBOL(dma_sync_single_range_for_device);
160
161void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
162 enum dma_data_direction direction)
163{
164 int i;
165
166 BUG_ON(!valid_dma_direction(direction));
167
168 /* Make sure that gcc doesn't leave the empty loop body. */
169 for_each_sg(sg, sg, nelems, i)
170 __dma_sync_for_cpu(sg_virt(sg), sg->length, direction);
171}
172EXPORT_SYMBOL(dma_sync_sg_for_cpu);
173
174void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
175 int nelems, enum dma_data_direction direction)
176{
177 int i;
178
179 BUG_ON(!valid_dma_direction(direction));
180
181 /* Make sure that gcc doesn't leave the empty loop body. */
182 for_each_sg(sg, sg, nelems, i)
183 __dma_sync_for_device(sg_virt(sg), sg->length, direction);
184
185}
186EXPORT_SYMBOL(dma_sync_sg_for_device);
diff --git a/arch/nios2/mm/extable.c b/arch/nios2/mm/extable.c
new file mode 100644
index 000000000000..4d2fc5a589d0
--- /dev/null
+++ b/arch/nios2/mm/extable.c
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2010, Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2009, Wind River Systems Inc
4 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/module.h>
12#include <linux/uaccess.h>
13
14int fixup_exception(struct pt_regs *regs)
15{
16 const struct exception_table_entry *fixup;
17
18 fixup = search_exception_tables(regs->ea);
19 if (fixup) {
20 regs->ea = fixup->fixup;
21 return 1;
22 }
23
24 return 0;
25}
diff --git a/arch/nios2/mm/fault.c b/arch/nios2/mm/fault.c
new file mode 100644
index 000000000000..15a0bb5fc06d
--- /dev/null
+++ b/arch/nios2/mm/fault.c
@@ -0,0 +1,251 @@
1/*
2 * Copyright (C) 2009 Wind River Systems Inc
3 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
4 *
5 * based on arch/mips/mm/fault.c which is:
6 *
7 * Copyright (C) 1995-2000 Ralf Baechle
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
13
14#include <linux/signal.h>
15#include <linux/sched.h>
16#include <linux/interrupt.h>
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/string.h>
20#include <linux/types.h>
21#include <linux/ptrace.h>
22#include <linux/mman.h>
23#include <linux/mm.h>
24#include <linux/module.h>
25#include <linux/uaccess.h>
26#include <linux/ptrace.h>
27
28#include <asm/mmu_context.h>
29#include <asm/traps.h>
30
31#define EXC_SUPERV_INSN_ACCESS 9 /* Supervisor only instruction address */
32#define EXC_SUPERV_DATA_ACCESS 11 /* Supervisor only data address */
33#define EXC_X_PROTECTION_FAULT 13 /* TLB permission violation (x) */
34#define EXC_R_PROTECTION_FAULT 14 /* TLB permission violation (r) */
35#define EXC_W_PROTECTION_FAULT 15 /* TLB permission violation (w) */
36
37/*
38 * This routine handles page faults. It determines the address,
39 * and the problem, and then passes it off to one of the appropriate
40 * routines.
41 */
42asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long cause,
43 unsigned long address)
44{
45 struct vm_area_struct *vma = NULL;
46 struct task_struct *tsk = current;
47 struct mm_struct *mm = tsk->mm;
48 int code = SEGV_MAPERR;
49 int fault;
50 unsigned int flags = 0;
51
52 cause >>= 2;
53
54 /* Restart the instruction */
55 regs->ea -= 4;
56
57 /*
58 * We fault-in kernel-space virtual memory on-demand. The
59 * 'reference' page table is init_mm.pgd.
60 *
61 * NOTE! We MUST NOT take any locks for this case. We may
62 * be in an interrupt or a critical region, and should
63 * only copy the information from the master page table,
64 * nothing more.
65 */
66 if (unlikely(address >= VMALLOC_START && address <= VMALLOC_END)) {
67 if (user_mode(regs))
68 goto bad_area_nosemaphore;
69 else
70 goto vmalloc_fault;
71 }
72
73 if (unlikely(address >= TASK_SIZE))
74 goto bad_area_nosemaphore;
75
76 /*
77 * If we're in an interrupt or have no user
78 * context, we must not take the fault..
79 */
80 if (in_atomic() || !mm)
81 goto bad_area_nosemaphore;
82
83 if (user_mode(regs))
84 flags |= FAULT_FLAG_USER;
85
86 if (!down_read_trylock(&mm->mmap_sem)) {
87 if (!user_mode(regs) && !search_exception_tables(regs->ea))
88 goto bad_area_nosemaphore;
89 down_read(&mm->mmap_sem);
90 }
91
92 vma = find_vma(mm, address);
93 if (!vma)
94 goto bad_area;
95 if (vma->vm_start <= address)
96 goto good_area;
97 if (!(vma->vm_flags & VM_GROWSDOWN))
98 goto bad_area;
99 if (expand_stack(vma, address))
100 goto bad_area;
101/*
102 * Ok, we have a good vm_area for this memory access, so
103 * we can handle it..
104 */
105good_area:
106 code = SEGV_ACCERR;
107
108 switch (cause) {
109 case EXC_SUPERV_INSN_ACCESS:
110 goto bad_area;
111 case EXC_SUPERV_DATA_ACCESS:
112 goto bad_area;
113 case EXC_X_PROTECTION_FAULT:
114 if (!(vma->vm_flags & VM_EXEC))
115 goto bad_area;
116 break;
117 case EXC_R_PROTECTION_FAULT:
118 if (!(vma->vm_flags & VM_READ))
119 goto bad_area;
120 break;
121 case EXC_W_PROTECTION_FAULT:
122 if (!(vma->vm_flags & VM_WRITE))
123 goto bad_area;
124 flags = FAULT_FLAG_WRITE;
125 break;
126 }
127
128survive:
129 /*
130 * If for any reason at all we couldn't handle the fault,
131 * make sure we exit gracefully rather than endlessly redo
132 * the fault.
133 */
134 fault = handle_mm_fault(mm, vma, address, flags);
135 if (unlikely(fault & VM_FAULT_ERROR)) {
136 if (fault & VM_FAULT_OOM)
137 goto out_of_memory;
138 else if (fault & VM_FAULT_SIGBUS)
139 goto do_sigbus;
140 BUG();
141 }
142 if (fault & VM_FAULT_MAJOR)
143 tsk->maj_flt++;
144 else
145 tsk->min_flt++;
146
147 up_read(&mm->mmap_sem);
148 return;
149
150/*
151 * Something tried to access memory that isn't in our memory map..
152 * Fix it, but check if it's kernel or user first..
153 */
154bad_area:
155 up_read(&mm->mmap_sem);
156
157bad_area_nosemaphore:
158 /* User mode accesses just cause a SIGSEGV */
159 if (user_mode(regs)) {
160 pr_alert("%s: unhandled page fault (%d) at 0x%08lx, "
161 "cause %ld\n", current->comm, SIGSEGV, address, cause);
162 show_regs(regs);
163 _exception(SIGSEGV, regs, code, address);
164 return;
165 }
166
167no_context:
168 /* Are we prepared to handle this kernel fault? */
169 if (fixup_exception(regs))
170 return;
171
172 /*
173 * Oops. The kernel tried to access some bad page. We'll have to
174 * terminate things with extreme prejudice.
175 */
176 bust_spinlocks(1);
177
178 pr_alert("Unable to handle kernel %s at virtual address %08lx",
179 address < PAGE_SIZE ? "NULL pointer dereference" :
180 "paging request", address);
181 pr_alert("ea = %08lx, ra = %08lx, cause = %ld\n", regs->ea, regs->ra,
182 cause);
183 panic("Oops");
184 return;
185
186/*
187 * We ran out of memory, or some other thing happened to us that made
188 * us unable to handle the page fault gracefully.
189 */
190out_of_memory:
191 up_read(&mm->mmap_sem);
192 if (is_global_init(tsk)) {
193 yield();
194 down_read(&mm->mmap_sem);
195 goto survive;
196 }
197 if (!user_mode(regs))
198 goto no_context;
199 pagefault_out_of_memory();
200 return;
201
202do_sigbus:
203 up_read(&mm->mmap_sem);
204
205 /* Kernel mode? Handle exceptions or die */
206 if (!user_mode(regs))
207 goto no_context;
208
209 _exception(SIGBUS, regs, BUS_ADRERR, address);
210 return;
211
212vmalloc_fault:
213 {
214 /*
215 * Synchronize this task's top level page-table
216 * with the 'reference' page table.
217 *
218 * Do _not_ use "tsk" here. We might be inside
219 * an interrupt in the middle of a task switch..
220 */
221 int offset = pgd_index(address);
222 pgd_t *pgd, *pgd_k;
223 pud_t *pud, *pud_k;
224 pmd_t *pmd, *pmd_k;
225 pte_t *pte_k;
226
227 pgd = pgd_current + offset;
228 pgd_k = init_mm.pgd + offset;
229
230 if (!pgd_present(*pgd_k))
231 goto no_context;
232 set_pgd(pgd, *pgd_k);
233
234 pud = pud_offset(pgd, address);
235 pud_k = pud_offset(pgd_k, address);
236 if (!pud_present(*pud_k))
237 goto no_context;
238 pmd = pmd_offset(pud, address);
239 pmd_k = pmd_offset(pud_k, address);
240 if (!pmd_present(*pmd_k))
241 goto no_context;
242 set_pmd(pmd, *pmd_k);
243
244 pte_k = pte_offset_kernel(pmd_k, address);
245 if (!pte_present(*pte_k))
246 goto no_context;
247
248 flush_tlb_one(address);
249 return;
250 }
251}
diff --git a/arch/nios2/mm/init.c b/arch/nios2/mm/init.c
new file mode 100644
index 000000000000..e75c75d249d6
--- /dev/null
+++ b/arch/nios2/mm/init.c
@@ -0,0 +1,142 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
4 * Copyright (C) 2009 Wind River Systems Inc
5 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
6 * Copyright (C) 2004 Microtronix Datacom Ltd
7 *
8 * based on arch/m68k/mm/init.c
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 */
14
15#include <linux/signal.h>
16#include <linux/sched.h>
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/string.h>
20#include <linux/types.h>
21#include <linux/ptrace.h>
22#include <linux/mman.h>
23#include <linux/mm.h>
24#include <linux/init.h>
25#include <linux/pagemap.h>
26#include <linux/bootmem.h>
27#include <linux/slab.h>
28#include <linux/binfmts.h>
29
30#include <asm/setup.h>
31#include <asm/page.h>
32#include <asm/pgtable.h>
33#include <asm/sections.h>
34#include <asm/tlb.h>
35#include <asm/mmu_context.h>
36#include <asm/cpuinfo.h>
37#include <asm/processor.h>
38
39pgd_t *pgd_current;
40
41/*
42 * paging_init() continues the virtual memory environment setup which
43 * was begun by the code in arch/head.S.
44 * The parameters are pointers to where to stick the starting and ending
45 * addresses of available kernel virtual memory.
46 */
47void __init paging_init(void)
48{
49 unsigned long zones_size[MAX_NR_ZONES];
50
51 memset(zones_size, 0, sizeof(zones_size));
52
53 pagetable_init();
54 pgd_current = swapper_pg_dir;
55
56 zones_size[ZONE_NORMAL] = max_mapnr;
57
58 /* pass the memory from the bootmem allocator to the main allocator */
59 free_area_init(zones_size);
60
61 flush_dcache_range((unsigned long)empty_zero_page,
62 (unsigned long)empty_zero_page + PAGE_SIZE);
63}
64
65void __init mem_init(void)
66{
67 unsigned long end_mem = memory_end; /* this must not include
68 kernel stack at top */
69
70 pr_debug("mem_init: start=%lx, end=%lx\n", memory_start, memory_end);
71
72 end_mem &= PAGE_MASK;
73 high_memory = __va(end_mem);
74
75 /* this will put all memory onto the freelists */
76 free_all_bootmem();
77 mem_init_print_info(NULL);
78}
79
80void __init mmu_init(void)
81{
82 flush_tlb_all();
83}
84
85#ifdef CONFIG_BLK_DEV_INITRD
86void __init free_initrd_mem(unsigned long start, unsigned long end)
87{
88 free_reserved_area((void *)start, (void *)end, -1, "initrd");
89}
90#endif
91
92void __init_refok free_initmem(void)
93{
94 free_initmem_default(-1);
95}
96
97#define __page_aligned(order) __aligned(PAGE_SIZE << (order))
98pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned(PGD_ORDER);
99pte_t invalid_pte_table[PTRS_PER_PTE] __page_aligned(PTE_ORDER);
100static struct page *kuser_page[1];
101
102static int alloc_kuser_page(void)
103{
104 extern char __kuser_helper_start[], __kuser_helper_end[];
105 int kuser_sz = __kuser_helper_end - __kuser_helper_start;
106 unsigned long vpage;
107
108 vpage = get_zeroed_page(GFP_ATOMIC);
109 if (!vpage)
110 return -ENOMEM;
111
112 /* Copy kuser helpers */
113 memcpy((void *)vpage, __kuser_helper_start, kuser_sz);
114
115 flush_icache_range(vpage, vpage + KUSER_SIZE);
116 kuser_page[0] = virt_to_page(vpage);
117
118 return 0;
119}
120arch_initcall(alloc_kuser_page);
121
122int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
123{
124 struct mm_struct *mm = current->mm;
125 int ret;
126
127 down_write(&mm->mmap_sem);
128
129 /* Map kuser helpers to user space address */
130 ret = install_special_mapping(mm, KUSER_BASE, KUSER_SIZE,
131 VM_READ | VM_EXEC | VM_MAYREAD |
132 VM_MAYEXEC, kuser_page);
133
134 up_write(&mm->mmap_sem);
135
136 return ret;
137}
138
139const char *arch_vma_name(struct vm_area_struct *vma)
140{
141 return (vma->vm_start == KUSER_BASE) ? "[kuser]" : NULL;
142}
diff --git a/arch/nios2/mm/ioremap.c b/arch/nios2/mm/ioremap.c
new file mode 100644
index 000000000000..3a28177a01eb
--- /dev/null
+++ b/arch/nios2/mm/ioremap.c
@@ -0,0 +1,187 @@
1/*
2 * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
3 * Copyright (C) 2009 Wind River Systems Inc
4 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
5 * Copyright (C) 2004 Microtronix Datacom Ltd.
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
12#include <linux/export.h>
13#include <linux/sched.h>
14#include <linux/mm.h>
15#include <linux/slab.h>
16#include <linux/vmalloc.h>
17#include <linux/io.h>
18
19#include <asm/cacheflush.h>
20#include <asm/tlbflush.h>
21
22static inline void remap_area_pte(pte_t *pte, unsigned long address,
23 unsigned long size, unsigned long phys_addr,
24 unsigned long flags)
25{
26 unsigned long end;
27 unsigned long pfn;
28 pgprot_t pgprot = __pgprot(_PAGE_GLOBAL | _PAGE_PRESENT | _PAGE_READ
29 | _PAGE_WRITE | flags);
30
31 address &= ~PMD_MASK;
32 end = address + size;
33 if (end > PMD_SIZE)
34 end = PMD_SIZE;
35 if (address >= end)
36 BUG();
37 pfn = PFN_DOWN(phys_addr);
38 do {
39 if (!pte_none(*pte)) {
40 pr_err("remap_area_pte: page already exists\n");
41 BUG();
42 }
43 set_pte(pte, pfn_pte(pfn, pgprot));
44 address += PAGE_SIZE;
45 pfn++;
46 pte++;
47 } while (address && (address < end));
48}
49
50static inline int remap_area_pmd(pmd_t *pmd, unsigned long address,
51 unsigned long size, unsigned long phys_addr,
52 unsigned long flags)
53{
54 unsigned long end;
55
56 address &= ~PGDIR_MASK;
57 end = address + size;
58 if (end > PGDIR_SIZE)
59 end = PGDIR_SIZE;
60 phys_addr -= address;
61 if (address >= end)
62 BUG();
63 do {
64 pte_t *pte = pte_alloc_kernel(pmd, address);
65
66 if (!pte)
67 return -ENOMEM;
68 remap_area_pte(pte, address, end - address, address + phys_addr,
69 flags);
70 address = (address + PMD_SIZE) & PMD_MASK;
71 pmd++;
72 } while (address && (address < end));
73 return 0;
74}
75
76static int remap_area_pages(unsigned long address, unsigned long phys_addr,
77 unsigned long size, unsigned long flags)
78{
79 int error;
80 pgd_t *dir;
81 unsigned long end = address + size;
82
83 phys_addr -= address;
84 dir = pgd_offset(&init_mm, address);
85 flush_cache_all();
86 if (address >= end)
87 BUG();
88 do {
89 pud_t *pud;
90 pmd_t *pmd;
91
92 error = -ENOMEM;
93 pud = pud_alloc(&init_mm, dir, address);
94 if (!pud)
95 break;
96 pmd = pmd_alloc(&init_mm, pud, address);
97 if (!pmd)
98 break;
99 if (remap_area_pmd(pmd, address, end - address,
100 phys_addr + address, flags))
101 break;
102 error = 0;
103 address = (address + PGDIR_SIZE) & PGDIR_MASK;
104 dir++;
105 } while (address && (address < end));
106 flush_tlb_all();
107 return error;
108}
109
110#define IS_MAPPABLE_UNCACHEABLE(addr) (addr < 0x20000000UL)
111
112/*
113 * Map some physical address range into the kernel address space.
114 */
115void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
116 unsigned long cacheflag)
117{
118 struct vm_struct *area;
119 unsigned long offset;
120 unsigned long last_addr;
121 void *addr;
122
123 /* Don't allow wraparound or zero size */
124 last_addr = phys_addr + size - 1;
125
126 if (!size || last_addr < phys_addr)
127 return NULL;
128
129 /* Don't allow anybody to remap normal RAM that we're using */
130 if (phys_addr > PHYS_OFFSET && phys_addr < virt_to_phys(high_memory)) {
131 char *t_addr, *t_end;
132 struct page *page;
133
134 t_addr = __va(phys_addr);
135 t_end = t_addr + (size - 1);
136 for (page = virt_to_page(t_addr);
137 page <= virt_to_page(t_end); page++)
138 if (!PageReserved(page))
139 return NULL;
140 }
141
142 /*
143 * Map uncached objects in the low part of address space to
144 * CONFIG_NIOS2_IO_REGION_BASE
145 */
146 if (IS_MAPPABLE_UNCACHEABLE(phys_addr) &&
147 IS_MAPPABLE_UNCACHEABLE(last_addr) &&
148 !(cacheflag & _PAGE_CACHED))
149 return (void __iomem *)(CONFIG_NIOS2_IO_REGION_BASE + phys_addr);
150
151 /* Mappings have to be page-aligned */
152 offset = phys_addr & ~PAGE_MASK;
153 phys_addr &= PAGE_MASK;
154 size = PAGE_ALIGN(last_addr + 1) - phys_addr;
155
156 /* Ok, go for it */
157 area = get_vm_area(size, VM_IOREMAP);
158 if (!area)
159 return NULL;
160 addr = area->addr;
161 if (remap_area_pages((unsigned long) addr, phys_addr, size,
162 cacheflag)) {
163 vunmap(addr);
164 return NULL;
165 }
166 return (void __iomem *) (offset + (char *)addr);
167}
168EXPORT_SYMBOL(__ioremap);
169
170/*
171 * __iounmap unmaps nearly everything, so be careful
172 * it doesn't free currently pointer/page tables anymore but it
173 * wasn't used anyway and might be added later.
174 */
175void __iounmap(void __iomem *addr)
176{
177 struct vm_struct *p;
178
179 if ((unsigned long) addr > CONFIG_NIOS2_IO_REGION_BASE)
180 return;
181
182 p = remove_vm_area((void *) (PAGE_MASK & (unsigned long __force) addr));
183 if (!p)
184 pr_err("iounmap: bad address %p\n", addr);
185 kfree(p);
186}
187EXPORT_SYMBOL(__iounmap);
diff --git a/arch/nios2/mm/mmu_context.c b/arch/nios2/mm/mmu_context.c
new file mode 100644
index 000000000000..45d6b9c58d67
--- /dev/null
+++ b/arch/nios2/mm/mmu_context.c
@@ -0,0 +1,116 @@
1/*
2 * MMU context handling.
3 *
4 * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
5 * Copyright (C) 2009 Wind River Systems Inc
6 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12
13#include <linux/mm.h>
14
15#include <asm/cpuinfo.h>
16#include <asm/mmu_context.h>
17#include <asm/tlb.h>
18
19/* The pids position and mask in context */
20#define PID_SHIFT 0
21#define PID_BITS (cpuinfo.tlb_pid_num_bits)
22#define PID_MASK ((1UL << PID_BITS) - 1)
23
24/* The versions position and mask in context */
25#define VERSION_BITS (32 - PID_BITS)
26#define VERSION_SHIFT (PID_SHIFT + PID_BITS)
27#define VERSION_MASK ((1UL << VERSION_BITS) - 1)
28
29/* Return the version part of a context */
30#define CTX_VERSION(c) (((c) >> VERSION_SHIFT) & VERSION_MASK)
31
32/* Return the pid part of a context */
33#define CTX_PID(c) (((c) >> PID_SHIFT) & PID_MASK)
34
35/* Value of the first context (version 1, pid 0) */
36#define FIRST_CTX ((1UL << VERSION_SHIFT) | (0 << PID_SHIFT))
37
38static mm_context_t next_mmu_context;
39
40/*
41 * Initialize MMU context management stuff.
42 */
43void __init mmu_context_init(void)
44{
45 /* We need to set this here because the value depends on runtime data
46 * from cpuinfo */
47 next_mmu_context = FIRST_CTX;
48}
49
50/*
51 * Set new context (pid), keep way
52 */
53static void set_context(mm_context_t context)
54{
55 set_mmu_pid(CTX_PID(context));
56}
57
58static mm_context_t get_new_context(void)
59{
60 /* Return the next pid */
61 next_mmu_context += (1UL << PID_SHIFT);
62
63 /* If the pid field wraps around we increase the version and
64 * flush the tlb */
65 if (unlikely(CTX_PID(next_mmu_context) == 0)) {
66 /* Version is incremented since the pid increment above
67 * overflows info version */
68 flush_cache_all();
69 flush_tlb_all();
70 }
71
72 /* If the version wraps we start over with the first generation, we do
73 * not need to flush the tlb here since it's always done above */
74 if (unlikely(CTX_VERSION(next_mmu_context) == 0))
75 next_mmu_context = FIRST_CTX;
76
77 return next_mmu_context;
78}
79
80void switch_mm(struct mm_struct *prev, struct mm_struct *next,
81 struct task_struct *tsk)
82{
83 unsigned long flags;
84
85 local_irq_save(flags);
86
87 /* If the process context we are swapping in has a different context
88 * generation then we have it should get a new generation/pid */
89 if (unlikely(CTX_VERSION(next->context) !=
90 CTX_VERSION(next_mmu_context)))
91 next->context = get_new_context();
92
93 /* Save the current pgd so the fast tlb handler can find it */
94 pgd_current = next->pgd;
95
96 /* Set the current context */
97 set_context(next->context);
98
99 local_irq_restore(flags);
100}
101
102/*
103 * After we have set current->mm to a new value, this activates
104 * the context for the new mm so we see the new mappings.
105 */
106void activate_mm(struct mm_struct *prev, struct mm_struct *next)
107{
108 next->context = get_new_context();
109 set_context(next->context);
110 pgd_current = next->pgd;
111}
112
113unsigned long get_pid_from_context(mm_context_t *context)
114{
115 return CTX_PID((*context));
116}
diff --git a/arch/nios2/mm/pgtable.c b/arch/nios2/mm/pgtable.c
new file mode 100644
index 000000000000..61e24a25f71a
--- /dev/null
+++ b/arch/nios2/mm/pgtable.c
@@ -0,0 +1,74 @@
1/*
2 * Copyright (C) 2009 Wind River Systems Inc
3 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 */
9
10#include <linux/mm.h>
11#include <linux/sched.h>
12
13#include <asm/pgtable.h>
14#include <asm/cpuinfo.h>
15
16/* pteaddr:
17 * ptbase | vpn* | zero
18 * 31-22 | 21-2 | 1-0
19 *
20 * *vpn is preserved on double fault
21 *
22 * tlbacc:
23 * IG |*flags| pfn
24 * 31-25|24-20 | 19-0
25 *
26 * *crwxg
27 *
28 * tlbmisc:
29 * resv |way |rd | we|pid |dbl|bad|perm|d
30 * 31-24 |23-20 |19 | 20|17-4|3 |2 |1 |0
31 *
32 */
33
34/*
35 * Initialize a new pgd / pmd table with invalid pointers.
36 */
37static void pgd_init(pgd_t *pgd)
38{
39 unsigned long *p = (unsigned long *) pgd;
40 int i;
41
42 for (i = 0; i < USER_PTRS_PER_PGD; i += 8) {
43 p[i + 0] = (unsigned long) invalid_pte_table;
44 p[i + 1] = (unsigned long) invalid_pte_table;
45 p[i + 2] = (unsigned long) invalid_pte_table;
46 p[i + 3] = (unsigned long) invalid_pte_table;
47 p[i + 4] = (unsigned long) invalid_pte_table;
48 p[i + 5] = (unsigned long) invalid_pte_table;
49 p[i + 6] = (unsigned long) invalid_pte_table;
50 p[i + 7] = (unsigned long) invalid_pte_table;
51 }
52}
53
54pgd_t *pgd_alloc(struct mm_struct *mm)
55{
56 pgd_t *ret, *init;
57
58 ret = (pgd_t *) __get_free_pages(GFP_KERNEL, PGD_ORDER);
59 if (ret) {
60 init = pgd_offset(&init_mm, 0UL);
61 pgd_init(ret);
62 memcpy(ret + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
63 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
64 }
65
66 return ret;
67}
68
69void __init pagetable_init(void)
70{
71 /* Initialize the entire pgd. */
72 pgd_init(swapper_pg_dir);
73 pgd_init(swapper_pg_dir + USER_PTRS_PER_PGD);
74}
diff --git a/arch/nios2/mm/tlb.c b/arch/nios2/mm/tlb.c
new file mode 100644
index 000000000000..cf10326aab1c
--- /dev/null
+++ b/arch/nios2/mm/tlb.c
@@ -0,0 +1,275 @@
1/*
2 * Nios2 TLB handling
3 *
4 * Copyright (C) 2009, Wind River Systems Inc
5 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
12#include <linux/init.h>
13#include <linux/sched.h>
14#include <linux/mm.h>
15#include <linux/pagemap.h>
16
17#include <asm/tlb.h>
18#include <asm/mmu_context.h>
19#include <asm/pgtable.h>
20#include <asm/cpuinfo.h>
21
22#define TLB_INDEX_MASK \
23 ((((1UL << (cpuinfo.tlb_ptr_sz - cpuinfo.tlb_num_ways_log2))) - 1) \
24 << PAGE_SHIFT)
25
26/* Used as illegal PHYS_ADDR for TLB mappings
27 */
28#define MAX_PHYS_ADDR 0
29
30static void get_misc_and_pid(unsigned long *misc, unsigned long *pid)
31{
32 *misc = RDCTL(CTL_TLBMISC);
33 *misc &= (TLBMISC_PID | TLBMISC_WAY);
34 *pid = *misc & TLBMISC_PID;
35}
36
37/*
38 * All entries common to a mm share an asid. To effectively flush these
39 * entries, we just bump the asid.
40 */
41void flush_tlb_mm(struct mm_struct *mm)
42{
43 if (current->mm == mm)
44 flush_tlb_all();
45 else
46 memset(&mm->context, 0, sizeof(mm_context_t));
47}
48
49/*
50 * This one is only used for pages with the global bit set so we don't care
51 * much about the ASID.
52 */
53void flush_tlb_one_pid(unsigned long addr, unsigned long mmu_pid)
54{
55 unsigned int way;
56 unsigned long org_misc, pid_misc;
57
58 pr_debug("Flush tlb-entry for vaddr=%#lx\n", addr);
59
60 /* remember pid/way until we return. */
61 get_misc_and_pid(&org_misc, &pid_misc);
62
63 WRCTL(CTL_PTEADDR, (addr >> PAGE_SHIFT) << 2);
64
65 for (way = 0; way < cpuinfo.tlb_num_ways; way++) {
66 unsigned long pteaddr;
67 unsigned long tlbmisc;
68 unsigned long pid;
69
70 tlbmisc = pid_misc | TLBMISC_RD | (way << TLBMISC_WAY_SHIFT);
71 WRCTL(CTL_TLBMISC, tlbmisc);
72 pteaddr = RDCTL(CTL_PTEADDR);
73 tlbmisc = RDCTL(CTL_TLBMISC);
74 pid = (tlbmisc >> TLBMISC_PID_SHIFT) & TLBMISC_PID_MASK;
75 if (((((pteaddr >> 2) & 0xfffff)) == (addr >> PAGE_SHIFT)) &&
76 pid == mmu_pid) {
77 unsigned long vaddr = CONFIG_NIOS2_IO_REGION_BASE +
78 ((PAGE_SIZE * cpuinfo.tlb_num_lines) * way) +
79 (addr & TLB_INDEX_MASK);
80 pr_debug("Flush entry by writing %#lx way=%dl pid=%ld\n",
81 vaddr, way, (pid_misc >> TLBMISC_PID_SHIFT));
82
83 WRCTL(CTL_PTEADDR, (vaddr >> 12) << 2);
84 tlbmisc = pid_misc | TLBMISC_WE |
85 (way << TLBMISC_WAY_SHIFT);
86 WRCTL(CTL_TLBMISC, tlbmisc);
87 WRCTL(CTL_TLBACC, (MAX_PHYS_ADDR >> PAGE_SHIFT));
88 }
89 }
90
91 WRCTL(CTL_TLBMISC, org_misc);
92}
93
94void flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
95 unsigned long end)
96{
97 unsigned long mmu_pid = get_pid_from_context(&vma->vm_mm->context);
98
99 while (start < end) {
100 flush_tlb_one_pid(start, mmu_pid);
101 start += PAGE_SIZE;
102 }
103}
104
105void flush_tlb_kernel_range(unsigned long start, unsigned long end)
106{
107 while (start < end) {
108 flush_tlb_one(start);
109 start += PAGE_SIZE;
110 }
111}
112
113/*
114 * This one is only used for pages with the global bit set so we don't care
115 * much about the ASID.
116 */
117void flush_tlb_one(unsigned long addr)
118{
119 unsigned int way;
120 unsigned long org_misc, pid_misc;
121
122 pr_debug("Flush tlb-entry for vaddr=%#lx\n", addr);
123
124 /* remember pid/way until we return. */
125 get_misc_and_pid(&org_misc, &pid_misc);
126
127 WRCTL(CTL_PTEADDR, (addr >> PAGE_SHIFT) << 2);
128
129 for (way = 0; way < cpuinfo.tlb_num_ways; way++) {
130 unsigned long pteaddr;
131 unsigned long tlbmisc;
132
133 tlbmisc = pid_misc | TLBMISC_RD | (way << TLBMISC_WAY_SHIFT);
134 WRCTL(CTL_TLBMISC, tlbmisc);
135 pteaddr = RDCTL(CTL_PTEADDR);
136 tlbmisc = RDCTL(CTL_TLBMISC);
137
138 if ((((pteaddr >> 2) & 0xfffff)) == (addr >> PAGE_SHIFT)) {
139 unsigned long vaddr = CONFIG_NIOS2_IO_REGION_BASE +
140 ((PAGE_SIZE * cpuinfo.tlb_num_lines) * way) +
141 (addr & TLB_INDEX_MASK);
142
143 pr_debug("Flush entry by writing %#lx way=%dl pid=%ld\n",
144 vaddr, way, (pid_misc >> TLBMISC_PID_SHIFT));
145
146 tlbmisc = pid_misc | TLBMISC_WE |
147 (way << TLBMISC_WAY_SHIFT);
148 WRCTL(CTL_PTEADDR, (vaddr >> 12) << 2);
149 WRCTL(CTL_TLBMISC, tlbmisc);
150 WRCTL(CTL_TLBACC, (MAX_PHYS_ADDR >> PAGE_SHIFT));
151 }
152 }
153
154 WRCTL(CTL_TLBMISC, org_misc);
155}
156
157void dump_tlb_line(unsigned long line)
158{
159 unsigned int way;
160 unsigned long org_misc;
161
162 pr_debug("dump tlb-entries for line=%#lx (addr %08lx)\n", line,
163 line << (PAGE_SHIFT + cpuinfo.tlb_num_ways_log2));
164
165 /* remember pid/way until we return */
166 org_misc = (RDCTL(CTL_TLBMISC) & (TLBMISC_PID | TLBMISC_WAY));
167
168 WRCTL(CTL_PTEADDR, line << 2);
169
170 for (way = 0; way < cpuinfo.tlb_num_ways; way++) {
171 unsigned long pteaddr;
172 unsigned long tlbmisc;
173 unsigned long tlbacc;
174
175 WRCTL(CTL_TLBMISC, TLBMISC_RD | (way << TLBMISC_WAY_SHIFT));
176 pteaddr = RDCTL(CTL_PTEADDR);
177 tlbmisc = RDCTL(CTL_TLBMISC);
178 tlbacc = RDCTL(CTL_TLBACC);
179
180 if ((tlbacc << PAGE_SHIFT) != (MAX_PHYS_ADDR & PAGE_MASK)) {
181 pr_debug("-- way:%02x vpn:0x%08lx phys:0x%08lx pid:0x%02lx flags:%c%c%c%c%c\n",
182 way,
183 (pteaddr << (PAGE_SHIFT-2)),
184 (tlbacc << PAGE_SHIFT),
185 ((tlbmisc >> TLBMISC_PID_SHIFT) &
186 TLBMISC_PID_MASK),
187 (tlbacc & _PAGE_READ ? 'r' : '-'),
188 (tlbacc & _PAGE_WRITE ? 'w' : '-'),
189 (tlbacc & _PAGE_EXEC ? 'x' : '-'),
190 (tlbacc & _PAGE_GLOBAL ? 'g' : '-'),
191 (tlbacc & _PAGE_CACHED ? 'c' : '-'));
192 }
193 }
194
195 WRCTL(CTL_TLBMISC, org_misc);
196}
197
198void dump_tlb(void)
199{
200 unsigned int i;
201
202 for (i = 0; i < cpuinfo.tlb_num_lines; i++)
203 dump_tlb_line(i);
204}
205
206void flush_tlb_pid(unsigned long pid)
207{
208 unsigned int line;
209 unsigned int way;
210 unsigned long org_misc, pid_misc;
211
212 /* remember pid/way until we return */
213 get_misc_and_pid(&org_misc, &pid_misc);
214
215 for (line = 0; line < cpuinfo.tlb_num_lines; line++) {
216 WRCTL(CTL_PTEADDR, line << 2);
217
218 for (way = 0; way < cpuinfo.tlb_num_ways; way++) {
219 unsigned long pteaddr;
220 unsigned long tlbmisc;
221 unsigned long tlbacc;
222
223 tlbmisc = pid_misc | TLBMISC_RD |
224 (way << TLBMISC_WAY_SHIFT);
225 WRCTL(CTL_TLBMISC, tlbmisc);
226 pteaddr = RDCTL(CTL_PTEADDR);
227 tlbmisc = RDCTL(CTL_TLBMISC);
228 tlbacc = RDCTL(CTL_TLBACC);
229
230 if (((tlbmisc>>TLBMISC_PID_SHIFT) & TLBMISC_PID_MASK)
231 == pid) {
232 tlbmisc = pid_misc | TLBMISC_WE |
233 (way << TLBMISC_WAY_SHIFT);
234 WRCTL(CTL_TLBMISC, tlbmisc);
235 WRCTL(CTL_TLBACC,
236 (MAX_PHYS_ADDR >> PAGE_SHIFT));
237 }
238 }
239
240 WRCTL(CTL_TLBMISC, org_misc);
241 }
242}
243
244void flush_tlb_all(void)
245{
246 int i;
247 unsigned long vaddr = CONFIG_NIOS2_IO_REGION_BASE;
248 unsigned int way;
249 unsigned long org_misc, pid_misc, tlbmisc;
250
251 /* remember pid/way until we return */
252 get_misc_and_pid(&org_misc, &pid_misc);
253 pid_misc |= TLBMISC_WE;
254
255 /* Map each TLB entry to physcal address 0 with no-access and a
256 bad ptbase */
257 for (way = 0; way < cpuinfo.tlb_num_ways; way++) {
258 tlbmisc = pid_misc | (way << TLBMISC_WAY_SHIFT);
259 for (i = 0; i < cpuinfo.tlb_num_lines; i++) {
260 WRCTL(CTL_PTEADDR, ((vaddr) >> PAGE_SHIFT) << 2);
261 WRCTL(CTL_TLBMISC, tlbmisc);
262 WRCTL(CTL_TLBACC, (MAX_PHYS_ADDR >> PAGE_SHIFT));
263 vaddr += 1UL << 12;
264 }
265 }
266
267 /* restore pid/way */
268 WRCTL(CTL_TLBMISC, org_misc);
269}
270
271void set_mmu_pid(unsigned long pid)
272{
273 WRCTL(CTL_TLBMISC, (RDCTL(CTL_TLBMISC) & TLBMISC_WAY) |
274 ((pid & TLBMISC_PID_MASK) << TLBMISC_PID_SHIFT));
275}
diff --git a/arch/nios2/mm/uaccess.c b/arch/nios2/mm/uaccess.c
new file mode 100644
index 000000000000..7663e156ff4f
--- /dev/null
+++ b/arch/nios2/mm/uaccess.c
@@ -0,0 +1,163 @@
1/*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2009, Wind River Systems Inc
7 * Implemented by fredrik.markstrom@gmail.com and ivarholmqvist@gmail.com
8 */
9
10#include <linux/export.h>
11#include <linux/uaccess.h>
12
13asm(".global __copy_from_user\n"
14 " .type __copy_from_user, @function\n"
15 "__copy_from_user:\n"
16 " movi r2,7\n"
17 " mov r3,r4\n"
18 " bge r2,r6,1f\n"
19 " xor r2,r4,r5\n"
20 " andi r2,r2,3\n"
21 " movi r7,3\n"
22 " beq r2,zero,4f\n"
23 "1: addi r6,r6,-1\n"
24 " movi r2,-1\n"
25 " beq r6,r2,3f\n"
26 " mov r7,r2\n"
27 "2: ldbu r2,0(r5)\n"
28 " addi r6,r6,-1\n"
29 " addi r5,r5,1\n"
30 " stb r2,0(r3)\n"
31 " addi r3,r3,1\n"
32 " bne r6,r7,2b\n"
33 "3:\n"
34 " addi r2,r6,1\n"
35 " ret\n"
36 "13:mov r2,r6\n"
37 " ret\n"
38 "4: andi r2,r4,1\n"
39 " cmpeq r2,r2,zero\n"
40 " beq r2,zero,7f\n"
41 "5: andi r2,r3,2\n"
42 " beq r2,zero,6f\n"
43 "9: ldhu r2,0(r5)\n"
44 " addi r6,r6,-2\n"
45 " addi r5,r5,2\n"
46 " sth r2,0(r3)\n"
47 " addi r3,r3,2\n"
48 "6: bge r7,r6,1b\n"
49 "10:ldw r2,0(r5)\n"
50 " addi r6,r6,-4\n"
51 " addi r5,r5,4\n"
52 " stw r2,0(r3)\n"
53 " addi r3,r3,4\n"
54 " br 6b\n"
55 "7: ldbu r2,0(r5)\n"
56 " addi r6,r6,-1\n"
57 " addi r5,r5,1\n"
58 " addi r3,r4,1\n"
59 " stb r2,0(r4)\n"
60 " br 5b\n"
61 ".section __ex_table,\"a\"\n"
62 ".word 2b,3b\n"
63 ".word 9b,13b\n"
64 ".word 10b,13b\n"
65 ".word 7b,13b\n"
66 ".previous\n"
67 );
68EXPORT_SYMBOL(__copy_from_user);
69
70asm(
71 " .global __copy_to_user\n"
72 " .type __copy_to_user, @function\n"
73 "__copy_to_user:\n"
74 " movi r2,7\n"
75 " mov r3,r4\n"
76 " bge r2,r6,1f\n"
77 " xor r2,r4,r5\n"
78 " andi r2,r2,3\n"
79 " movi r7,3\n"
80 " beq r2,zero,4f\n"
81 /* Bail if we try to copy zero bytes */
82 "1: addi r6,r6,-1\n"
83 " movi r2,-1\n"
84 " beq r6,r2,3f\n"
85 /* Copy byte by byte for small copies and if src^dst != 0 */
86 " mov r7,r2\n"
87 "2: ldbu r2,0(r5)\n"
88 " addi r5,r5,1\n"
89 "9: stb r2,0(r3)\n"
90 " addi r6,r6,-1\n"
91 " addi r3,r3,1\n"
92 " bne r6,r7,2b\n"
93 "3: addi r2,r6,1\n"
94 " ret\n"
95 "13:mov r2,r6\n"
96 " ret\n"
97 /* If 'to' is an odd address byte copy */
98 "4: andi r2,r4,1\n"
99 " cmpeq r2,r2,zero\n"
100 " beq r2,zero,7f\n"
101 /* If 'to' is not divideable by four copy halfwords */
102 "5: andi r2,r3,2\n"
103 " beq r2,zero,6f\n"
104 " ldhu r2,0(r5)\n"
105 " addi r5,r5,2\n"
106 "10:sth r2,0(r3)\n"
107 " addi r6,r6,-2\n"
108 " addi r3,r3,2\n"
109 /* Copy words */
110 "6: bge r7,r6,1b\n"
111 " ldw r2,0(r5)\n"
112 " addi r5,r5,4\n"
113 "11:stw r2,0(r3)\n"
114 " addi r6,r6,-4\n"
115 " addi r3,r3,4\n"
116 " br 6b\n"
117 /* Copy remaining bytes */
118 "7: ldbu r2,0(r5)\n"
119 " addi r5,r5,1\n"
120 " addi r3,r4,1\n"
121 "12: stb r2,0(r4)\n"
122 " addi r6,r6,-1\n"
123 " br 5b\n"
124 ".section __ex_table,\"a\"\n"
125 ".word 9b,3b\n"
126 ".word 10b,13b\n"
127 ".word 11b,13b\n"
128 ".word 12b,13b\n"
129 ".previous\n");
130EXPORT_SYMBOL(__copy_to_user);
131
132long strncpy_from_user(char *__to, const char __user *__from, long __len)
133{
134 int l = strnlen_user(__from, __len);
135 int is_zt = 1;
136
137 if (l > __len) {
138 is_zt = 0;
139 l = __len;
140 }
141
142 if (l == 0 || copy_from_user(__to, __from, l))
143 return -EFAULT;
144
145 if (is_zt)
146 l--;
147 return l;
148}
149
150long strnlen_user(const char __user *s, long n)
151{
152 long i;
153
154 for (i = 0; i < n; i++) {
155 char c;
156
157 if (get_user(c, s + i) == -EFAULT)
158 return 0;
159 if (c == 0)
160 return i + 1;
161 }
162 return n + 1;
163}
diff --git a/arch/nios2/platform/Kconfig.platform b/arch/nios2/platform/Kconfig.platform
new file mode 100644
index 000000000000..d3e5df9fb36b
--- /dev/null
+++ b/arch/nios2/platform/Kconfig.platform
@@ -0,0 +1,129 @@
1menu "Platform options"
2
3comment "Memory settings"
4
5config NIOS2_MEM_BASE
6 hex "Memory base address"
7 default "0x00000000"
8 help
9 This is the physical address of the memory that the kernel will run
10 from. This address is used to link the kernel and setup initial memory
11 management. You should take the raw memory address without any MMU
12 or cache bits set.
13 Please not that this address is used directly so you have to manually
14 do address translation if it's connected to a bridge.
15
16comment "Device tree"
17
18config NIOS2_DTB_AT_PHYS_ADDR
19 bool "DTB at physical address"
20 default n
21 help
22 When enabled you can select a physical address to load the dtb from.
23 Normally this address is passed by a bootloader such as u-boot but
24 using this you can use a devicetree without a bootloader.
25 This way you can store a devicetree in NOR flash or an onchip rom.
26 Please note that this address is used directly so you have to manually
27 do address translation if it's connected to a bridge. Also take into
28 account that when using an MMU you'd have to ad 0xC0000000 to your
29 address
30
31config NIOS2_DTB_PHYS_ADDR
32 hex "DTB Address"
33 depends on NIOS2_DTB_AT_PHYS_ADDR
34 default "0xC0000000"
35 help
36 Physical address of a dtb blob.
37
38config NIOS2_DTB_SOURCE_BOOL
39 bool "Compile and link device tree into kernel image"
40 default n
41 help
42 This allows you to specify a dts (device tree source) file
43 which will be compiled and linked into the kernel image.
44
45config NIOS2_DTB_SOURCE
46 string "Device tree source file"
47 depends on NIOS2_DTB_SOURCE_BOOL
48 default ""
49 help
50 Absolute path to the device tree source (dts) file describing your
51 system.
52
53comment "Nios II instructions"
54
55config NIOS2_HW_MUL_SUPPORT
56 bool "Enable MUL instruction"
57 default n
58 help
59 Set to true if you configured the Nios II to include the MUL
60 instruction. This will enable the -mhw-mul compiler flag.
61
62config NIOS2_HW_MULX_SUPPORT
63 bool "Enable MULX instruction"
64 default n
65 help
66 Set to true if you configured the Nios II to include the MULX
67 instruction. Enables the -mhw-mulx compiler flag.
68
69config NIOS2_HW_DIV_SUPPORT
70 bool "Enable DIV instruction"
71 default n
72 help
73 Set to true if you configured the Nios II to include the DIV
74 instruction. Enables the -mhw-div compiler flag.
75
76config NIOS2_FPU_SUPPORT
77 bool "Custom floating point instr support"
78 default n
79 help
80 Enables the -mcustom-fpu-cfg=60-1 compiler flag.
81
82config NIOS2_CI_SWAB_SUPPORT
83 bool "Byteswap custom instruction"
84 default n
85 help
86 Use the byteswap (endian converter) Nios II custom instruction provided
87 by Altera and which can be enabled in QSYS builder. This accelerates
88 endian conversions in the kernel (e.g. ntohs).
89
90config NIOS2_CI_SWAB_NO
91 int "Byteswap custom instruction number" if NIOS2_CI_SWAB_SUPPORT
92 default 0
93 help
94 Number of the instruction as configured in QSYS Builder.
95
96comment "Cache settings"
97
98config CUSTOM_CACHE_SETTINGS
99 bool "Custom cache settings"
100 help
101 This option allows you to tweak the cache settings used during early
102 boot (where the information from device tree is not yet available).
103 There should be no reason to change these values. Linux will work
104 perfectly fine, even if the Nios II is configured with smaller caches.
105
106 Say N here unless you know what you are doing.
107
108config NIOS2_DCACHE_SIZE
109 hex "D-Cache size" if CUSTOM_CACHE_SETTINGS
110 range 0x200 0x10000
111 default "0x800"
112 help
113 Maximum possible data cache size.
114
115config NIOS2_DCACHE_LINE_SIZE
116 hex "D-Cache line size" if CUSTOM_CACHE_SETTINGS
117 range 0x10 0x20
118 default "0x20"
119 help
120 Minimum possible data cache line size.
121
122config NIOS2_ICACHE_SIZE
123 hex "I-Cache size" if CUSTOM_CACHE_SETTINGS
124 range 0x200 0x10000
125 default "0x1000"
126 help
127 Maximum possible instruction cache size.
128
129endmenu
diff --git a/arch/nios2/platform/Makefile b/arch/nios2/platform/Makefile
new file mode 100644
index 000000000000..46364f1d9352
--- /dev/null
+++ b/arch/nios2/platform/Makefile
@@ -0,0 +1 @@
obj-y += platform.o
diff --git a/arch/nios2/platform/platform.c b/arch/nios2/platform/platform.c
new file mode 100644
index 000000000000..d478773f758a
--- /dev/null
+++ b/arch/nios2/platform/platform.c
@@ -0,0 +1,46 @@
1/*
2 * Copyright (C) 2013 Altera Corporation
3 * Copyright (C) 2011 Thomas Chou
4 * Copyright (C) 2011 Walter Goossens
5 *
6 * This file is subject to the terms and conditions of the GNU General
7 * Public License. See the file COPYING in the main directory of this
8 * archive for more details.
9 */
10
11#include <linux/init.h>
12#include <linux/of_platform.h>
13#include <linux/of_address.h>
14#include <linux/of_fdt.h>
15#include <linux/err.h>
16#include <linux/slab.h>
17#include <linux/sys_soc.h>
18#include <linux/io.h>
19
20static int __init nios2_soc_device_init(void)
21{
22 struct soc_device *soc_dev;
23 struct soc_device_attribute *soc_dev_attr;
24 const char *machine;
25
26 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
27 if (soc_dev_attr) {
28 machine = of_flat_dt_get_machine_name();
29 if (machine)
30 soc_dev_attr->machine = kasprintf(GFP_KERNEL, "%s",
31 machine);
32
33 soc_dev_attr->family = "Nios II";
34
35 soc_dev = soc_device_register(soc_dev_attr);
36 if (IS_ERR(soc_dev)) {
37 kfree(soc_dev_attr->machine);
38 kfree(soc_dev_attr);
39 }
40 }
41
42 return of_platform_populate(NULL, of_default_bus_match_table,
43 NULL, NULL);
44}
45
46device_initcall(nios2_soc_device_init);
diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
index 4006964d8e12..a5cb070b54bf 100644
--- a/arch/parisc/include/asm/uaccess.h
+++ b/arch/parisc/include/asm/uaccess.h
@@ -9,6 +9,8 @@
9#include <asm/errno.h> 9#include <asm/errno.h>
10#include <asm-generic/uaccess-unaligned.h> 10#include <asm-generic/uaccess-unaligned.h>
11 11
12#include <linux/bug.h>
13
12#define VERIFY_READ 0 14#define VERIFY_READ 0
13#define VERIFY_WRITE 1 15#define VERIFY_WRITE 1
14 16
@@ -28,11 +30,6 @@
28 * that put_user is the same as __put_user, etc. 30 * that put_user is the same as __put_user, etc.
29 */ 31 */
30 32
31extern int __get_kernel_bad(void);
32extern int __get_user_bad(void);
33extern int __put_kernel_bad(void);
34extern int __put_user_bad(void);
35
36static inline long access_ok(int type, const void __user * addr, 33static inline long access_ok(int type, const void __user * addr,
37 unsigned long size) 34 unsigned long size)
38{ 35{
@@ -43,8 +40,8 @@ static inline long access_ok(int type, const void __user * addr,
43#define get_user __get_user 40#define get_user __get_user
44 41
45#if !defined(CONFIG_64BIT) 42#if !defined(CONFIG_64BIT)
46#define LDD_KERNEL(ptr) __get_kernel_bad(); 43#define LDD_KERNEL(ptr) BUILD_BUG()
47#define LDD_USER(ptr) __get_user_bad(); 44#define LDD_USER(ptr) BUILD_BUG()
48#define STD_KERNEL(x, ptr) __put_kernel_asm64(x,ptr) 45#define STD_KERNEL(x, ptr) __put_kernel_asm64(x,ptr)
49#define STD_USER(x, ptr) __put_user_asm64(x,ptr) 46#define STD_USER(x, ptr) __put_user_asm64(x,ptr)
50#define ASM_WORD_INSN ".word\t" 47#define ASM_WORD_INSN ".word\t"
@@ -94,7 +91,7 @@ struct exception_data {
94 case 2: __get_kernel_asm("ldh",ptr); break; \ 91 case 2: __get_kernel_asm("ldh",ptr); break; \
95 case 4: __get_kernel_asm("ldw",ptr); break; \ 92 case 4: __get_kernel_asm("ldw",ptr); break; \
96 case 8: LDD_KERNEL(ptr); break; \ 93 case 8: LDD_KERNEL(ptr); break; \
97 default: __get_kernel_bad(); break; \ 94 default: BUILD_BUG(); break; \
98 } \ 95 } \
99 } \ 96 } \
100 else { \ 97 else { \
@@ -103,7 +100,7 @@ struct exception_data {
103 case 2: __get_user_asm("ldh",ptr); break; \ 100 case 2: __get_user_asm("ldh",ptr); break; \
104 case 4: __get_user_asm("ldw",ptr); break; \ 101 case 4: __get_user_asm("ldw",ptr); break; \
105 case 8: LDD_USER(ptr); break; \ 102 case 8: LDD_USER(ptr); break; \
106 default: __get_user_bad(); break; \ 103 default: BUILD_BUG(); break; \
107 } \ 104 } \
108 } \ 105 } \
109 \ 106 \
@@ -136,7 +133,7 @@ struct exception_data {
136 case 2: __put_kernel_asm("sth",__x,ptr); break; \ 133 case 2: __put_kernel_asm("sth",__x,ptr); break; \
137 case 4: __put_kernel_asm("stw",__x,ptr); break; \ 134 case 4: __put_kernel_asm("stw",__x,ptr); break; \
138 case 8: STD_KERNEL(__x,ptr); break; \ 135 case 8: STD_KERNEL(__x,ptr); break; \
139 default: __put_kernel_bad(); break; \ 136 default: BUILD_BUG(); break; \
140 } \ 137 } \
141 } \ 138 } \
142 else { \ 139 else { \
@@ -145,7 +142,7 @@ struct exception_data {
145 case 2: __put_user_asm("sth",__x,ptr); break; \ 142 case 2: __put_user_asm("sth",__x,ptr); break; \
146 case 4: __put_user_asm("stw",__x,ptr); break; \ 143 case 4: __put_user_asm("stw",__x,ptr); break; \
147 case 8: STD_USER(__x,ptr); break; \ 144 case 8: STD_USER(__x,ptr); break; \
148 default: __put_user_bad(); break; \ 145 default: BUILD_BUG(); break; \
149 } \ 146 } \
150 } \ 147 } \
151 \ 148 \
diff --git a/arch/parisc/include/uapi/asm/bitsperlong.h b/arch/parisc/include/uapi/asm/bitsperlong.h
index 75196b415d3f..e0a23c7bdd43 100644
--- a/arch/parisc/include/uapi/asm/bitsperlong.h
+++ b/arch/parisc/include/uapi/asm/bitsperlong.h
@@ -1,13 +1,7 @@
1#ifndef __ASM_PARISC_BITSPERLONG_H 1#ifndef __ASM_PARISC_BITSPERLONG_H
2#define __ASM_PARISC_BITSPERLONG_H 2#define __ASM_PARISC_BITSPERLONG_H
3 3
4/* 4#if defined(__LP64__)
5 * using CONFIG_* outside of __KERNEL__ is wrong,
6 * __LP64__ was also removed from headers, so what
7 * is the right approach on parisc?
8 * -arnd
9 */
10#if (defined(__KERNEL__) && defined(CONFIG_64BIT)) || defined (__LP64__)
11#define __BITS_PER_LONG 64 5#define __BITS_PER_LONG 64
12#define SHIFT_PER_LONG 6 6#define SHIFT_PER_LONG 6
13#else 7#else
diff --git a/arch/parisc/include/uapi/asm/msgbuf.h b/arch/parisc/include/uapi/asm/msgbuf.h
index fe88f2649418..342138983914 100644
--- a/arch/parisc/include/uapi/asm/msgbuf.h
+++ b/arch/parisc/include/uapi/asm/msgbuf.h
@@ -1,6 +1,8 @@
1#ifndef _PARISC_MSGBUF_H 1#ifndef _PARISC_MSGBUF_H
2#define _PARISC_MSGBUF_H 2#define _PARISC_MSGBUF_H
3 3
4#include <asm/bitsperlong.h>
5
4/* 6/*
5 * The msqid64_ds structure for parisc architecture, copied from sparc. 7 * The msqid64_ds structure for parisc architecture, copied from sparc.
6 * Note extra padding because this structure is passed back and forth 8 * Note extra padding because this structure is passed back and forth
@@ -13,15 +15,15 @@
13 15
14struct msqid64_ds { 16struct msqid64_ds {
15 struct ipc64_perm msg_perm; 17 struct ipc64_perm msg_perm;
16#ifndef CONFIG_64BIT 18#if __BITS_PER_LONG != 64
17 unsigned int __pad1; 19 unsigned int __pad1;
18#endif 20#endif
19 __kernel_time_t msg_stime; /* last msgsnd time */ 21 __kernel_time_t msg_stime; /* last msgsnd time */
20#ifndef CONFIG_64BIT 22#if __BITS_PER_LONG != 64
21 unsigned int __pad2; 23 unsigned int __pad2;
22#endif 24#endif
23 __kernel_time_t msg_rtime; /* last msgrcv time */ 25 __kernel_time_t msg_rtime; /* last msgrcv time */
24#ifndef CONFIG_64BIT 26#if __BITS_PER_LONG != 64
25 unsigned int __pad3; 27 unsigned int __pad3;
26#endif 28#endif
27 __kernel_time_t msg_ctime; /* last change time */ 29 __kernel_time_t msg_ctime; /* last change time */
diff --git a/arch/parisc/include/uapi/asm/sembuf.h b/arch/parisc/include/uapi/asm/sembuf.h
index 1e59ffd3bd1e..f01d89e30d73 100644
--- a/arch/parisc/include/uapi/asm/sembuf.h
+++ b/arch/parisc/include/uapi/asm/sembuf.h
@@ -1,6 +1,8 @@
1#ifndef _PARISC_SEMBUF_H 1#ifndef _PARISC_SEMBUF_H
2#define _PARISC_SEMBUF_H 2#define _PARISC_SEMBUF_H
3 3
4#include <asm/bitsperlong.h>
5
4/* 6/*
5 * The semid64_ds structure for parisc architecture. 7 * The semid64_ds structure for parisc architecture.
6 * Note extra padding because this structure is passed back and forth 8 * Note extra padding because this structure is passed back and forth
@@ -13,11 +15,11 @@
13 15
14struct semid64_ds { 16struct semid64_ds {
15 struct ipc64_perm sem_perm; /* permissions .. see ipc.h */ 17 struct ipc64_perm sem_perm; /* permissions .. see ipc.h */
16#ifndef CONFIG_64BIT 18#if __BITS_PER_LONG != 64
17 unsigned int __pad1; 19 unsigned int __pad1;
18#endif 20#endif
19 __kernel_time_t sem_otime; /* last semop time */ 21 __kernel_time_t sem_otime; /* last semop time */
20#ifndef CONFIG_64BIT 22#if __BITS_PER_LONG != 64
21 unsigned int __pad2; 23 unsigned int __pad2;
22#endif 24#endif
23 __kernel_time_t sem_ctime; /* last change time */ 25 __kernel_time_t sem_ctime; /* last change time */
diff --git a/arch/parisc/include/uapi/asm/shmbuf.h b/arch/parisc/include/uapi/asm/shmbuf.h
index 0a3eada1863b..8496c38560c6 100644
--- a/arch/parisc/include/uapi/asm/shmbuf.h
+++ b/arch/parisc/include/uapi/asm/shmbuf.h
@@ -1,6 +1,8 @@
1#ifndef _PARISC_SHMBUF_H 1#ifndef _PARISC_SHMBUF_H
2#define _PARISC_SHMBUF_H 2#define _PARISC_SHMBUF_H
3 3
4#include <asm/bitsperlong.h>
5
4/* 6/*
5 * The shmid64_ds structure for parisc architecture. 7 * The shmid64_ds structure for parisc architecture.
6 * Note extra padding because this structure is passed back and forth 8 * Note extra padding because this structure is passed back and forth
@@ -13,19 +15,19 @@
13 15
14struct shmid64_ds { 16struct shmid64_ds {
15 struct ipc64_perm shm_perm; /* operation perms */ 17 struct ipc64_perm shm_perm; /* operation perms */
16#ifndef CONFIG_64BIT 18#if __BITS_PER_LONG != 64
17 unsigned int __pad1; 19 unsigned int __pad1;
18#endif 20#endif
19 __kernel_time_t shm_atime; /* last attach time */ 21 __kernel_time_t shm_atime; /* last attach time */
20#ifndef CONFIG_64BIT 22#if __BITS_PER_LONG != 64
21 unsigned int __pad2; 23 unsigned int __pad2;
22#endif 24#endif
23 __kernel_time_t shm_dtime; /* last detach time */ 25 __kernel_time_t shm_dtime; /* last detach time */
24#ifndef CONFIG_64BIT 26#if __BITS_PER_LONG != 64
25 unsigned int __pad3; 27 unsigned int __pad3;
26#endif 28#endif
27 __kernel_time_t shm_ctime; /* last change time */ 29 __kernel_time_t shm_ctime; /* last change time */
28#ifndef CONFIG_64BIT 30#if __BITS_PER_LONG != 64
29 unsigned int __pad4; 31 unsigned int __pad4;
30#endif 32#endif
31 size_t shm_segsz; /* size of segment (bytes) */ 33 size_t shm_segsz; /* size of segment (bytes) */
@@ -36,23 +38,16 @@ struct shmid64_ds {
36 unsigned int __unused2; 38 unsigned int __unused2;
37}; 39};
38 40
39#ifdef CONFIG_64BIT
40/* The 'unsigned int' (formerly 'unsigned long') data types below will
41 * ensure that a 32-bit app calling shmctl(*,IPC_INFO,*) will work on
42 * a wide kernel, but if some of these values are meant to contain pointers
43 * they may need to be 'long long' instead. -PB XXX FIXME
44 */
45#endif
46struct shminfo64 { 41struct shminfo64 {
47 unsigned int shmmax; 42 unsigned long shmmax;
48 unsigned int shmmin; 43 unsigned long shmmin;
49 unsigned int shmmni; 44 unsigned long shmmni;
50 unsigned int shmseg; 45 unsigned long shmseg;
51 unsigned int shmall; 46 unsigned long shmall;
52 unsigned int __unused1; 47 unsigned long __unused1;
53 unsigned int __unused2; 48 unsigned long __unused2;
54 unsigned int __unused3; 49 unsigned long __unused3;
55 unsigned int __unused4; 50 unsigned long __unused4;
56}; 51};
57 52
58#endif /* _PARISC_SHMBUF_H */ 53#endif /* _PARISC_SHMBUF_H */
diff --git a/arch/parisc/include/uapi/asm/signal.h b/arch/parisc/include/uapi/asm/signal.h
index 10df7079f4cd..e26043b73f5d 100644
--- a/arch/parisc/include/uapi/asm/signal.h
+++ b/arch/parisc/include/uapi/asm/signal.h
@@ -85,7 +85,7 @@
85struct siginfo; 85struct siginfo;
86 86
87/* Type of a signal handler. */ 87/* Type of a signal handler. */
88#ifdef CONFIG_64BIT 88#if defined(__LP64__)
89/* function pointers on 64-bit parisc are pointers to little structs and the 89/* function pointers on 64-bit parisc are pointers to little structs and the
90 * compiler doesn't support code which changes or tests the address of 90 * compiler doesn't support code which changes or tests the address of
91 * the function in the little struct. This is really ugly -PB 91 * the function in the little struct. This is really ugly -PB
diff --git a/arch/parisc/include/uapi/asm/unistd.h b/arch/parisc/include/uapi/asm/unistd.h
index 8667f18be238..5f5c0373de63 100644
--- a/arch/parisc/include/uapi/asm/unistd.h
+++ b/arch/parisc/include/uapi/asm/unistd.h
@@ -833,8 +833,9 @@
833#define __NR_seccomp (__NR_Linux + 338) 833#define __NR_seccomp (__NR_Linux + 338)
834#define __NR_getrandom (__NR_Linux + 339) 834#define __NR_getrandom (__NR_Linux + 339)
835#define __NR_memfd_create (__NR_Linux + 340) 835#define __NR_memfd_create (__NR_Linux + 340)
836#define __NR_bpf (__NR_Linux + 341)
836 837
837#define __NR_Linux_syscalls (__NR_memfd_create + 1) 838#define __NR_Linux_syscalls (__NR_bpf + 1)
838 839
839 840
840#define __IGNORE_select /* newselect */ 841#define __IGNORE_select /* newselect */
diff --git a/arch/parisc/kernel/syscall_table.S b/arch/parisc/kernel/syscall_table.S
index b563d9c8268b..fe4f0b89bf8f 100644
--- a/arch/parisc/kernel/syscall_table.S
+++ b/arch/parisc/kernel/syscall_table.S
@@ -286,11 +286,11 @@
286 ENTRY_COMP(msgsnd) 286 ENTRY_COMP(msgsnd)
287 ENTRY_COMP(msgrcv) 287 ENTRY_COMP(msgrcv)
288 ENTRY_SAME(msgget) /* 190 */ 288 ENTRY_SAME(msgget) /* 190 */
289 ENTRY_SAME(msgctl) 289 ENTRY_COMP(msgctl)
290 ENTRY_SAME(shmat) 290 ENTRY_COMP(shmat)
291 ENTRY_SAME(shmdt) 291 ENTRY_SAME(shmdt)
292 ENTRY_SAME(shmget) 292 ENTRY_SAME(shmget)
293 ENTRY_SAME(shmctl) /* 195 */ 293 ENTRY_COMP(shmctl) /* 195 */
294 ENTRY_SAME(ni_syscall) /* streams1 */ 294 ENTRY_SAME(ni_syscall) /* streams1 */
295 ENTRY_SAME(ni_syscall) /* streams2 */ 295 ENTRY_SAME(ni_syscall) /* streams2 */
296 ENTRY_SAME(lstat64) 296 ENTRY_SAME(lstat64)
@@ -323,7 +323,7 @@
323 ENTRY_SAME(epoll_ctl) /* 225 */ 323 ENTRY_SAME(epoll_ctl) /* 225 */
324 ENTRY_SAME(epoll_wait) 324 ENTRY_SAME(epoll_wait)
325 ENTRY_SAME(remap_file_pages) 325 ENTRY_SAME(remap_file_pages)
326 ENTRY_SAME(semtimedop) 326 ENTRY_COMP(semtimedop)
327 ENTRY_COMP(mq_open) 327 ENTRY_COMP(mq_open)
328 ENTRY_SAME(mq_unlink) /* 230 */ 328 ENTRY_SAME(mq_unlink) /* 230 */
329 ENTRY_COMP(mq_timedsend) 329 ENTRY_COMP(mq_timedsend)
@@ -436,6 +436,7 @@
436 ENTRY_SAME(seccomp) 436 ENTRY_SAME(seccomp)
437 ENTRY_SAME(getrandom) 437 ENTRY_SAME(getrandom)
438 ENTRY_SAME(memfd_create) /* 340 */ 438 ENTRY_SAME(memfd_create) /* 340 */
439 ENTRY_SAME(bpf)
439 440
440 /* Nothing yet */ 441 /* Nothing yet */
441 442
diff --git a/arch/powerpc/include/asm/fadump.h b/arch/powerpc/include/asm/fadump.h
index a6774560afe3..493e72f64b35 100644
--- a/arch/powerpc/include/asm/fadump.h
+++ b/arch/powerpc/include/asm/fadump.h
@@ -70,39 +70,39 @@
70#define CPU_UNKNOWN (~((u32)0)) 70#define CPU_UNKNOWN (~((u32)0))
71 71
72/* Utility macros */ 72/* Utility macros */
73#define SKIP_TO_NEXT_CPU(reg_entry) \ 73#define SKIP_TO_NEXT_CPU(reg_entry) \
74({ \ 74({ \
75 while (reg_entry->reg_id != REG_ID("CPUEND")) \ 75 while (be64_to_cpu(reg_entry->reg_id) != REG_ID("CPUEND")) \
76 reg_entry++; \ 76 reg_entry++; \
77 reg_entry++; \ 77 reg_entry++; \
78}) 78})
79 79
80/* Kernel Dump section info */ 80/* Kernel Dump section info */
81struct fadump_section { 81struct fadump_section {
82 u32 request_flag; 82 __be32 request_flag;
83 u16 source_data_type; 83 __be16 source_data_type;
84 u16 error_flags; 84 __be16 error_flags;
85 u64 source_address; 85 __be64 source_address;
86 u64 source_len; 86 __be64 source_len;
87 u64 bytes_dumped; 87 __be64 bytes_dumped;
88 u64 destination_address; 88 __be64 destination_address;
89}; 89};
90 90
91/* ibm,configure-kernel-dump header. */ 91/* ibm,configure-kernel-dump header. */
92struct fadump_section_header { 92struct fadump_section_header {
93 u32 dump_format_version; 93 __be32 dump_format_version;
94 u16 dump_num_sections; 94 __be16 dump_num_sections;
95 u16 dump_status_flag; 95 __be16 dump_status_flag;
96 u32 offset_first_dump_section; 96 __be32 offset_first_dump_section;
97 97
98 /* Fields for disk dump option. */ 98 /* Fields for disk dump option. */
99 u32 dd_block_size; 99 __be32 dd_block_size;
100 u64 dd_block_offset; 100 __be64 dd_block_offset;
101 u64 dd_num_blocks; 101 __be64 dd_num_blocks;
102 u32 dd_offset_disk_path; 102 __be32 dd_offset_disk_path;
103 103
104 /* Maximum time allowed to prevent an automatic dump-reboot. */ 104 /* Maximum time allowed to prevent an automatic dump-reboot. */
105 u32 max_time_auto; 105 __be32 max_time_auto;
106}; 106};
107 107
108/* 108/*
@@ -174,15 +174,15 @@ static inline u64 str_to_u64(const char *str)
174 174
175/* Register save area header. */ 175/* Register save area header. */
176struct fadump_reg_save_area_header { 176struct fadump_reg_save_area_header {
177 u64 magic_number; 177 __be64 magic_number;
178 u32 version; 178 __be32 version;
179 u32 num_cpu_offset; 179 __be32 num_cpu_offset;
180}; 180};
181 181
182/* Register entry. */ 182/* Register entry. */
183struct fadump_reg_entry { 183struct fadump_reg_entry {
184 u64 reg_id; 184 __be64 reg_id;
185 u64 reg_value; 185 __be64 reg_value;
186}; 186};
187 187
188/* fadump crash info structure */ 188/* fadump crash info structure */
diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h
index 4ca90a39d6d0..725247beebec 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -159,8 +159,6 @@ struct pci_dn {
159 159
160 int pci_ext_config_space; /* for pci devices */ 160 int pci_ext_config_space; /* for pci devices */
161 161
162 bool force_32bit_msi;
163
164 struct pci_dev *pcidev; /* back-pointer to the pci device */ 162 struct pci_dev *pcidev; /* back-pointer to the pci device */
165#ifdef CONFIG_EEH 163#ifdef CONFIG_EEH
166 struct eeh_dev *edev; /* eeh device */ 164 struct eeh_dev *edev; /* eeh device */
diff --git a/arch/powerpc/include/asm/pgalloc.h b/arch/powerpc/include/asm/pgalloc.h
index e9a9f60e596d..fc3ee06eab87 100644
--- a/arch/powerpc/include/asm/pgalloc.h
+++ b/arch/powerpc/include/asm/pgalloc.h
@@ -3,7 +3,6 @@
3#ifdef __KERNEL__ 3#ifdef __KERNEL__
4 4
5#include <linux/mm.h> 5#include <linux/mm.h>
6#include <asm-generic/tlb.h>
7 6
8#ifdef CONFIG_PPC_BOOK3E 7#ifdef CONFIG_PPC_BOOK3E
9extern void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address); 8extern void tlb_flush_pgtable(struct mmu_gather *tlb, unsigned long address);
@@ -14,6 +13,8 @@ static inline void tlb_flush_pgtable(struct mmu_gather *tlb,
14} 13}
15#endif /* !CONFIG_PPC_BOOK3E */ 14#endif /* !CONFIG_PPC_BOOK3E */
16 15
16extern void tlb_remove_table(struct mmu_gather *tlb, void *table);
17
17#ifdef CONFIG_PPC64 18#ifdef CONFIG_PPC64
18#include <asm/pgalloc-64.h> 19#include <asm/pgalloc-64.h>
19#else 20#else
diff --git a/arch/powerpc/include/asm/tlb.h b/arch/powerpc/include/asm/tlb.h
index e2b428b0f7ba..20733fa518ae 100644
--- a/arch/powerpc/include/asm/tlb.h
+++ b/arch/powerpc/include/asm/tlb.h
@@ -27,6 +27,7 @@
27 27
28#define tlb_start_vma(tlb, vma) do { } while (0) 28#define tlb_start_vma(tlb, vma) do { } while (0)
29#define tlb_end_vma(tlb, vma) do { } while (0) 29#define tlb_end_vma(tlb, vma) do { } while (0)
30#define __tlb_remove_tlb_entry __tlb_remove_tlb_entry
30 31
31extern void tlb_flush(struct mmu_gather *tlb); 32extern void tlb_flush(struct mmu_gather *tlb);
32 33
diff --git a/arch/powerpc/kernel/eeh_sysfs.c b/arch/powerpc/kernel/eeh_sysfs.c
index f19b1e5cb060..1ceecdda810b 100644
--- a/arch/powerpc/kernel/eeh_sysfs.c
+++ b/arch/powerpc/kernel/eeh_sysfs.c
@@ -65,7 +65,7 @@ static ssize_t eeh_pe_state_show(struct device *dev,
65 return -ENODEV; 65 return -ENODEV;
66 66
67 state = eeh_ops->get_state(edev->pe, NULL); 67 state = eeh_ops->get_state(edev->pe, NULL);
68 return sprintf(buf, "%0x08x %0x08x\n", 68 return sprintf(buf, "0x%08x 0x%08x\n",
69 state, edev->pe->state); 69 state, edev->pe->state);
70} 70}
71 71
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 5bbd1bc8c3b0..0905c8da90f1 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -659,7 +659,13 @@ _GLOBAL(ret_from_except_lite)
6593: 6593:
660#endif 660#endif
661 bl save_nvgprs 661 bl save_nvgprs
662 /*
663 * Use a non volatile GPR to save and restore our thread_info flags
664 * across the call to restore_interrupts.
665 */
666 mr r30,r4
662 bl restore_interrupts 667 bl restore_interrupts
668 mr r4,r30
663 addi r3,r1,STACK_FRAME_OVERHEAD 669 addi r3,r1,STACK_FRAME_OVERHEAD
664 bl do_notify_resume 670 bl do_notify_resume
665 b ret_from_except 671 b ret_from_except
diff --git a/arch/powerpc/kernel/fadump.c b/arch/powerpc/kernel/fadump.c
index 742694c1d852..26d091a1a54c 100644
--- a/arch/powerpc/kernel/fadump.c
+++ b/arch/powerpc/kernel/fadump.c
@@ -58,7 +58,7 @@ int __init early_init_dt_scan_fw_dump(unsigned long node,
58 const __be32 *sections; 58 const __be32 *sections;
59 int i, num_sections; 59 int i, num_sections;
60 int size; 60 int size;
61 const int *token; 61 const __be32 *token;
62 62
63 if (depth != 1 || strcmp(uname, "rtas") != 0) 63 if (depth != 1 || strcmp(uname, "rtas") != 0)
64 return 0; 64 return 0;
@@ -72,7 +72,7 @@ int __init early_init_dt_scan_fw_dump(unsigned long node,
72 return 1; 72 return 1;
73 73
74 fw_dump.fadump_supported = 1; 74 fw_dump.fadump_supported = 1;
75 fw_dump.ibm_configure_kernel_dump = *token; 75 fw_dump.ibm_configure_kernel_dump = be32_to_cpu(*token);
76 76
77 /* 77 /*
78 * The 'ibm,kernel-dump' rtas node is present only if there is 78 * The 'ibm,kernel-dump' rtas node is present only if there is
@@ -147,11 +147,11 @@ static unsigned long init_fadump_mem_struct(struct fadump_mem_struct *fdm,
147 memset(fdm, 0, sizeof(struct fadump_mem_struct)); 147 memset(fdm, 0, sizeof(struct fadump_mem_struct));
148 addr = addr & PAGE_MASK; 148 addr = addr & PAGE_MASK;
149 149
150 fdm->header.dump_format_version = 0x00000001; 150 fdm->header.dump_format_version = cpu_to_be32(0x00000001);
151 fdm->header.dump_num_sections = 3; 151 fdm->header.dump_num_sections = cpu_to_be16(3);
152 fdm->header.dump_status_flag = 0; 152 fdm->header.dump_status_flag = 0;
153 fdm->header.offset_first_dump_section = 153 fdm->header.offset_first_dump_section =
154 (u32)offsetof(struct fadump_mem_struct, cpu_state_data); 154 cpu_to_be32((u32)offsetof(struct fadump_mem_struct, cpu_state_data));
155 155
156 /* 156 /*
157 * Fields for disk dump option. 157 * Fields for disk dump option.
@@ -167,27 +167,27 @@ static unsigned long init_fadump_mem_struct(struct fadump_mem_struct *fdm,
167 167
168 /* Kernel dump sections */ 168 /* Kernel dump sections */
169 /* cpu state data section. */ 169 /* cpu state data section. */
170 fdm->cpu_state_data.request_flag = FADUMP_REQUEST_FLAG; 170 fdm->cpu_state_data.request_flag = cpu_to_be32(FADUMP_REQUEST_FLAG);
171 fdm->cpu_state_data.source_data_type = FADUMP_CPU_STATE_DATA; 171 fdm->cpu_state_data.source_data_type = cpu_to_be16(FADUMP_CPU_STATE_DATA);
172 fdm->cpu_state_data.source_address = 0; 172 fdm->cpu_state_data.source_address = 0;
173 fdm->cpu_state_data.source_len = fw_dump.cpu_state_data_size; 173 fdm->cpu_state_data.source_len = cpu_to_be64(fw_dump.cpu_state_data_size);
174 fdm->cpu_state_data.destination_address = addr; 174 fdm->cpu_state_data.destination_address = cpu_to_be64(addr);
175 addr += fw_dump.cpu_state_data_size; 175 addr += fw_dump.cpu_state_data_size;
176 176
177 /* hpte region section */ 177 /* hpte region section */
178 fdm->hpte_region.request_flag = FADUMP_REQUEST_FLAG; 178 fdm->hpte_region.request_flag = cpu_to_be32(FADUMP_REQUEST_FLAG);
179 fdm->hpte_region.source_data_type = FADUMP_HPTE_REGION; 179 fdm->hpte_region.source_data_type = cpu_to_be16(FADUMP_HPTE_REGION);
180 fdm->hpte_region.source_address = 0; 180 fdm->hpte_region.source_address = 0;
181 fdm->hpte_region.source_len = fw_dump.hpte_region_size; 181 fdm->hpte_region.source_len = cpu_to_be64(fw_dump.hpte_region_size);
182 fdm->hpte_region.destination_address = addr; 182 fdm->hpte_region.destination_address = cpu_to_be64(addr);
183 addr += fw_dump.hpte_region_size; 183 addr += fw_dump.hpte_region_size;
184 184
185 /* RMA region section */ 185 /* RMA region section */
186 fdm->rmr_region.request_flag = FADUMP_REQUEST_FLAG; 186 fdm->rmr_region.request_flag = cpu_to_be32(FADUMP_REQUEST_FLAG);
187 fdm->rmr_region.source_data_type = FADUMP_REAL_MODE_REGION; 187 fdm->rmr_region.source_data_type = cpu_to_be16(FADUMP_REAL_MODE_REGION);
188 fdm->rmr_region.source_address = RMA_START; 188 fdm->rmr_region.source_address = cpu_to_be64(RMA_START);
189 fdm->rmr_region.source_len = fw_dump.boot_memory_size; 189 fdm->rmr_region.source_len = cpu_to_be64(fw_dump.boot_memory_size);
190 fdm->rmr_region.destination_address = addr; 190 fdm->rmr_region.destination_address = cpu_to_be64(addr);
191 addr += fw_dump.boot_memory_size; 191 addr += fw_dump.boot_memory_size;
192 192
193 return addr; 193 return addr;
@@ -272,7 +272,7 @@ int __init fadump_reserve_mem(void)
272 * first kernel. 272 * first kernel.
273 */ 273 */
274 if (fdm_active) 274 if (fdm_active)
275 fw_dump.boot_memory_size = fdm_active->rmr_region.source_len; 275 fw_dump.boot_memory_size = be64_to_cpu(fdm_active->rmr_region.source_len);
276 else 276 else
277 fw_dump.boot_memory_size = fadump_calculate_reserve_size(); 277 fw_dump.boot_memory_size = fadump_calculate_reserve_size();
278 278
@@ -314,8 +314,8 @@ int __init fadump_reserve_mem(void)
314 (unsigned long)(base >> 20)); 314 (unsigned long)(base >> 20));
315 315
316 fw_dump.fadumphdr_addr = 316 fw_dump.fadumphdr_addr =
317 fdm_active->rmr_region.destination_address + 317 be64_to_cpu(fdm_active->rmr_region.destination_address) +
318 fdm_active->rmr_region.source_len; 318 be64_to_cpu(fdm_active->rmr_region.source_len);
319 pr_debug("fadumphdr_addr = %p\n", 319 pr_debug("fadumphdr_addr = %p\n",
320 (void *) fw_dump.fadumphdr_addr); 320 (void *) fw_dump.fadumphdr_addr);
321 } else { 321 } else {
@@ -472,9 +472,9 @@ fadump_read_registers(struct fadump_reg_entry *reg_entry, struct pt_regs *regs)
472{ 472{
473 memset(regs, 0, sizeof(struct pt_regs)); 473 memset(regs, 0, sizeof(struct pt_regs));
474 474
475 while (reg_entry->reg_id != REG_ID("CPUEND")) { 475 while (be64_to_cpu(reg_entry->reg_id) != REG_ID("CPUEND")) {
476 fadump_set_regval(regs, reg_entry->reg_id, 476 fadump_set_regval(regs, be64_to_cpu(reg_entry->reg_id),
477 reg_entry->reg_value); 477 be64_to_cpu(reg_entry->reg_value));
478 reg_entry++; 478 reg_entry++;
479 } 479 }
480 reg_entry++; 480 reg_entry++;
@@ -603,20 +603,20 @@ static int __init fadump_build_cpu_notes(const struct fadump_mem_struct *fdm)
603 if (!fdm->cpu_state_data.bytes_dumped) 603 if (!fdm->cpu_state_data.bytes_dumped)
604 return -EINVAL; 604 return -EINVAL;
605 605
606 addr = fdm->cpu_state_data.destination_address; 606 addr = be64_to_cpu(fdm->cpu_state_data.destination_address);
607 vaddr = __va(addr); 607 vaddr = __va(addr);
608 608
609 reg_header = vaddr; 609 reg_header = vaddr;
610 if (reg_header->magic_number != REGSAVE_AREA_MAGIC) { 610 if (be64_to_cpu(reg_header->magic_number) != REGSAVE_AREA_MAGIC) {
611 printk(KERN_ERR "Unable to read register save area.\n"); 611 printk(KERN_ERR "Unable to read register save area.\n");
612 return -ENOENT; 612 return -ENOENT;
613 } 613 }
614 pr_debug("--------CPU State Data------------\n"); 614 pr_debug("--------CPU State Data------------\n");
615 pr_debug("Magic Number: %llx\n", reg_header->magic_number); 615 pr_debug("Magic Number: %llx\n", be64_to_cpu(reg_header->magic_number));
616 pr_debug("NumCpuOffset: %x\n", reg_header->num_cpu_offset); 616 pr_debug("NumCpuOffset: %x\n", be32_to_cpu(reg_header->num_cpu_offset));
617 617
618 vaddr += reg_header->num_cpu_offset; 618 vaddr += be32_to_cpu(reg_header->num_cpu_offset);
619 num_cpus = *((u32 *)(vaddr)); 619 num_cpus = be32_to_cpu(*((__be32 *)(vaddr)));
620 pr_debug("NumCpus : %u\n", num_cpus); 620 pr_debug("NumCpus : %u\n", num_cpus);
621 vaddr += sizeof(u32); 621 vaddr += sizeof(u32);
622 reg_entry = (struct fadump_reg_entry *)vaddr; 622 reg_entry = (struct fadump_reg_entry *)vaddr;
@@ -639,13 +639,13 @@ static int __init fadump_build_cpu_notes(const struct fadump_mem_struct *fdm)
639 fdh = __va(fw_dump.fadumphdr_addr); 639 fdh = __va(fw_dump.fadumphdr_addr);
640 640
641 for (i = 0; i < num_cpus; i++) { 641 for (i = 0; i < num_cpus; i++) {
642 if (reg_entry->reg_id != REG_ID("CPUSTRT")) { 642 if (be64_to_cpu(reg_entry->reg_id) != REG_ID("CPUSTRT")) {
643 printk(KERN_ERR "Unable to read CPU state data\n"); 643 printk(KERN_ERR "Unable to read CPU state data\n");
644 rc = -ENOENT; 644 rc = -ENOENT;
645 goto error_out; 645 goto error_out;
646 } 646 }
647 /* Lower 4 bytes of reg_value contains logical cpu id */ 647 /* Lower 4 bytes of reg_value contains logical cpu id */
648 cpu = reg_entry->reg_value & FADUMP_CPU_ID_MASK; 648 cpu = be64_to_cpu(reg_entry->reg_value) & FADUMP_CPU_ID_MASK;
649 if (fdh && !cpumask_test_cpu(cpu, &fdh->cpu_online_mask)) { 649 if (fdh && !cpumask_test_cpu(cpu, &fdh->cpu_online_mask)) {
650 SKIP_TO_NEXT_CPU(reg_entry); 650 SKIP_TO_NEXT_CPU(reg_entry);
651 continue; 651 continue;
@@ -692,7 +692,7 @@ static int __init process_fadump(const struct fadump_mem_struct *fdm_active)
692 return -EINVAL; 692 return -EINVAL;
693 693
694 /* Check if the dump data is valid. */ 694 /* Check if the dump data is valid. */
695 if ((fdm_active->header.dump_status_flag == FADUMP_ERROR_FLAG) || 695 if ((be16_to_cpu(fdm_active->header.dump_status_flag) == FADUMP_ERROR_FLAG) ||
696 (fdm_active->cpu_state_data.error_flags != 0) || 696 (fdm_active->cpu_state_data.error_flags != 0) ||
697 (fdm_active->rmr_region.error_flags != 0)) { 697 (fdm_active->rmr_region.error_flags != 0)) {
698 printk(KERN_ERR "Dump taken by platform is not valid\n"); 698 printk(KERN_ERR "Dump taken by platform is not valid\n");
@@ -828,7 +828,7 @@ static void fadump_setup_crash_memory_ranges(void)
828static inline unsigned long fadump_relocate(unsigned long paddr) 828static inline unsigned long fadump_relocate(unsigned long paddr)
829{ 829{
830 if (paddr > RMA_START && paddr < fw_dump.boot_memory_size) 830 if (paddr > RMA_START && paddr < fw_dump.boot_memory_size)
831 return fdm.rmr_region.destination_address + paddr; 831 return be64_to_cpu(fdm.rmr_region.destination_address) + paddr;
832 else 832 else
833 return paddr; 833 return paddr;
834} 834}
@@ -902,7 +902,7 @@ static int fadump_create_elfcore_headers(char *bufp)
902 * to the specified destination_address. Hence set 902 * to the specified destination_address. Hence set
903 * the correct offset. 903 * the correct offset.
904 */ 904 */
905 phdr->p_offset = fdm.rmr_region.destination_address; 905 phdr->p_offset = be64_to_cpu(fdm.rmr_region.destination_address);
906 } 906 }
907 907
908 phdr->p_paddr = mbase; 908 phdr->p_paddr = mbase;
@@ -951,7 +951,7 @@ static void register_fadump(void)
951 951
952 fadump_setup_crash_memory_ranges(); 952 fadump_setup_crash_memory_ranges();
953 953
954 addr = fdm.rmr_region.destination_address + fdm.rmr_region.source_len; 954 addr = be64_to_cpu(fdm.rmr_region.destination_address) + be64_to_cpu(fdm.rmr_region.source_len);
955 /* Initialize fadump crash info header. */ 955 /* Initialize fadump crash info header. */
956 addr = init_fadump_header(addr); 956 addr = init_fadump_header(addr);
957 vaddr = __va(addr); 957 vaddr = __va(addr);
@@ -1023,7 +1023,7 @@ void fadump_cleanup(void)
1023 /* Invalidate the registration only if dump is active. */ 1023 /* Invalidate the registration only if dump is active. */
1024 if (fw_dump.dump_active) { 1024 if (fw_dump.dump_active) {
1025 init_fadump_mem_struct(&fdm, 1025 init_fadump_mem_struct(&fdm,
1026 fdm_active->cpu_state_data.destination_address); 1026 be64_to_cpu(fdm_active->cpu_state_data.destination_address));
1027 fadump_invalidate_dump(&fdm); 1027 fadump_invalidate_dump(&fdm);
1028 } 1028 }
1029} 1029}
@@ -1063,7 +1063,7 @@ static void fadump_invalidate_release_mem(void)
1063 return; 1063 return;
1064 } 1064 }
1065 1065
1066 destination_address = fdm_active->cpu_state_data.destination_address; 1066 destination_address = be64_to_cpu(fdm_active->cpu_state_data.destination_address);
1067 fadump_cleanup(); 1067 fadump_cleanup();
1068 mutex_unlock(&fadump_mutex); 1068 mutex_unlock(&fadump_mutex);
1069 1069
@@ -1183,31 +1183,31 @@ static int fadump_region_show(struct seq_file *m, void *private)
1183 seq_printf(m, 1183 seq_printf(m,
1184 "CPU : [%#016llx-%#016llx] %#llx bytes, " 1184 "CPU : [%#016llx-%#016llx] %#llx bytes, "
1185 "Dumped: %#llx\n", 1185 "Dumped: %#llx\n",
1186 fdm_ptr->cpu_state_data.destination_address, 1186 be64_to_cpu(fdm_ptr->cpu_state_data.destination_address),
1187 fdm_ptr->cpu_state_data.destination_address + 1187 be64_to_cpu(fdm_ptr->cpu_state_data.destination_address) +
1188 fdm_ptr->cpu_state_data.source_len - 1, 1188 be64_to_cpu(fdm_ptr->cpu_state_data.source_len) - 1,
1189 fdm_ptr->cpu_state_data.source_len, 1189 be64_to_cpu(fdm_ptr->cpu_state_data.source_len),
1190 fdm_ptr->cpu_state_data.bytes_dumped); 1190 be64_to_cpu(fdm_ptr->cpu_state_data.bytes_dumped));
1191 seq_printf(m, 1191 seq_printf(m,
1192 "HPTE: [%#016llx-%#016llx] %#llx bytes, " 1192 "HPTE: [%#016llx-%#016llx] %#llx bytes, "
1193 "Dumped: %#llx\n", 1193 "Dumped: %#llx\n",
1194 fdm_ptr->hpte_region.destination_address, 1194 be64_to_cpu(fdm_ptr->hpte_region.destination_address),
1195 fdm_ptr->hpte_region.destination_address + 1195 be64_to_cpu(fdm_ptr->hpte_region.destination_address) +
1196 fdm_ptr->hpte_region.source_len - 1, 1196 be64_to_cpu(fdm_ptr->hpte_region.source_len) - 1,
1197 fdm_ptr->hpte_region.source_len, 1197 be64_to_cpu(fdm_ptr->hpte_region.source_len),
1198 fdm_ptr->hpte_region.bytes_dumped); 1198 be64_to_cpu(fdm_ptr->hpte_region.bytes_dumped));
1199 seq_printf(m, 1199 seq_printf(m,
1200 "DUMP: [%#016llx-%#016llx] %#llx bytes, " 1200 "DUMP: [%#016llx-%#016llx] %#llx bytes, "
1201 "Dumped: %#llx\n", 1201 "Dumped: %#llx\n",
1202 fdm_ptr->rmr_region.destination_address, 1202 be64_to_cpu(fdm_ptr->rmr_region.destination_address),
1203 fdm_ptr->rmr_region.destination_address + 1203 be64_to_cpu(fdm_ptr->rmr_region.destination_address) +
1204 fdm_ptr->rmr_region.source_len - 1, 1204 be64_to_cpu(fdm_ptr->rmr_region.source_len) - 1,
1205 fdm_ptr->rmr_region.source_len, 1205 be64_to_cpu(fdm_ptr->rmr_region.source_len),
1206 fdm_ptr->rmr_region.bytes_dumped); 1206 be64_to_cpu(fdm_ptr->rmr_region.bytes_dumped));
1207 1207
1208 if (!fdm_active || 1208 if (!fdm_active ||
1209 (fw_dump.reserve_dump_area_start == 1209 (fw_dump.reserve_dump_area_start ==
1210 fdm_ptr->cpu_state_data.destination_address)) 1210 be64_to_cpu(fdm_ptr->cpu_state_data.destination_address)))
1211 goto out; 1211 goto out;
1212 1212
1213 /* Dump is active. Show reserved memory region. */ 1213 /* Dump is active. Show reserved memory region. */
@@ -1215,10 +1215,10 @@ static int fadump_region_show(struct seq_file *m, void *private)
1215 " : [%#016llx-%#016llx] %#llx bytes, " 1215 " : [%#016llx-%#016llx] %#llx bytes, "
1216 "Dumped: %#llx\n", 1216 "Dumped: %#llx\n",
1217 (unsigned long long)fw_dump.reserve_dump_area_start, 1217 (unsigned long long)fw_dump.reserve_dump_area_start,
1218 fdm_ptr->cpu_state_data.destination_address - 1, 1218 be64_to_cpu(fdm_ptr->cpu_state_data.destination_address) - 1,
1219 fdm_ptr->cpu_state_data.destination_address - 1219 be64_to_cpu(fdm_ptr->cpu_state_data.destination_address) -
1220 fw_dump.reserve_dump_area_start, 1220 fw_dump.reserve_dump_area_start,
1221 fdm_ptr->cpu_state_data.destination_address - 1221 be64_to_cpu(fdm_ptr->cpu_state_data.destination_address) -
1222 fw_dump.reserve_dump_area_start); 1222 fw_dump.reserve_dump_area_start);
1223out: 1223out:
1224 if (fdm_active) 1224 if (fdm_active)
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index 155013da27e0..b15194e2c5fc 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -266,13 +266,3 @@ int pcibus_to_node(struct pci_bus *bus)
266} 266}
267EXPORT_SYMBOL(pcibus_to_node); 267EXPORT_SYMBOL(pcibus_to_node);
268#endif 268#endif
269
270static void quirk_radeon_32bit_msi(struct pci_dev *dev)
271{
272 struct pci_dn *pdn = pci_get_pdn(dev);
273
274 if (pdn)
275 pdn->force_32bit_msi = true;
276}
277DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x68f2, quirk_radeon_32bit_msi);
278DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0xaa68, quirk_radeon_32bit_msi);
diff --git a/arch/powerpc/kernel/vdso32/getcpu.S b/arch/powerpc/kernel/vdso32/getcpu.S
index 23eb9a9441bd..c62be60c7274 100644
--- a/arch/powerpc/kernel/vdso32/getcpu.S
+++ b/arch/powerpc/kernel/vdso32/getcpu.S
@@ -30,8 +30,8 @@
30V_FUNCTION_BEGIN(__kernel_getcpu) 30V_FUNCTION_BEGIN(__kernel_getcpu)
31 .cfi_startproc 31 .cfi_startproc
32 mfspr r5,SPRN_SPRG_VDSO_READ 32 mfspr r5,SPRN_SPRG_VDSO_READ
33 cmpdi cr0,r3,0 33 cmpwi cr0,r3,0
34 cmpdi cr1,r4,0 34 cmpwi cr1,r4,0
35 clrlwi r6,r5,16 35 clrlwi r6,r5,16
36 rlwinm r7,r5,16,31-15,31-0 36 rlwinm r7,r5,16,31-15,31-0
37 beq cr0,1f 37 beq cr0,1f
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index 7e70ae968e5f..6a4a5fcb9730 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -517,8 +517,6 @@ static void free_hugepd_range(struct mmu_gather *tlb, hugepd_t *hpdp, int pdshif
517 for (i = 0; i < num_hugepd; i++, hpdp++) 517 for (i = 0; i < num_hugepd; i++, hpdp++)
518 hpdp->pd = 0; 518 hpdp->pd = 0;
519 519
520 tlb->need_flush = 1;
521
522#ifdef CONFIG_PPC_FSL_BOOK3E 520#ifdef CONFIG_PPC_FSL_BOOK3E
523 hugepd_free(tlb, hugepte); 521 hugepd_free(tlb, hugepte);
524#else 522#else
diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index cad68ff8eca5..415a51b028b9 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -103,7 +103,7 @@ unsigned long __max_low_memory = MAX_LOW_MEM;
103/* 103/*
104 * Check for command-line options that affect what MMU_init will do. 104 * Check for command-line options that affect what MMU_init will do.
105 */ 105 */
106void MMU_setup(void) 106void __init MMU_setup(void)
107{ 107{
108 /* Check for nobats option (used in mapin_ram). */ 108 /* Check for nobats option (used in mapin_ram). */
109 if (strstr(boot_command_line, "nobats")) { 109 if (strstr(boot_command_line, "nobats")) {
diff --git a/arch/powerpc/platforms/powernv/opal-hmi.c b/arch/powerpc/platforms/powernv/opal-hmi.c
index 5e1ed1575aab..b322bfb51343 100644
--- a/arch/powerpc/platforms/powernv/opal-hmi.c
+++ b/arch/powerpc/platforms/powernv/opal-hmi.c
@@ -57,7 +57,7 @@ static void print_hmi_event_info(struct OpalHMIEvent *hmi_evt)
57 }; 57 };
58 58
59 /* Print things out */ 59 /* Print things out */
60 if (hmi_evt->version != OpalHMIEvt_V1) { 60 if (hmi_evt->version < OpalHMIEvt_V1) {
61 pr_err("HMI Interrupt, Unknown event version %d !\n", 61 pr_err("HMI Interrupt, Unknown event version %d !\n",
62 hmi_evt->version); 62 hmi_evt->version);
63 return; 63 return;
diff --git a/arch/powerpc/platforms/powernv/opal-lpc.c b/arch/powerpc/platforms/powernv/opal-lpc.c
index ad4b31df779a..e4169d68cb32 100644
--- a/arch/powerpc/platforms/powernv/opal-lpc.c
+++ b/arch/powerpc/platforms/powernv/opal-lpc.c
@@ -216,14 +216,54 @@ static ssize_t lpc_debug_read(struct file *filp, char __user *ubuf,
216 &data, len); 216 &data, len);
217 if (rc) 217 if (rc)
218 return -ENXIO; 218 return -ENXIO;
219
220 /*
221 * Now there is some trickery with the data returned by OPAL
222 * as it's the desired data right justified in a 32-bit BE
223 * word.
224 *
225 * This is a very bad interface and I'm to blame for it :-(
226 *
227 * So we can't just apply a 32-bit swap to what comes from OPAL,
228 * because user space expects the *bytes* to be in their proper
229 * respective positions (ie, LPC position).
230 *
231 * So what we really want to do here is to shift data right
232 * appropriately on a LE kernel.
233 *
234 * IE. If the LPC transaction has bytes B0, B1, B2 and B3 in that
235 * order, we have in memory written to by OPAL at the "data"
236 * pointer:
237 *
238 * Bytes: OPAL "data" LE "data"
239 * 32-bit: B0 B1 B2 B3 B0B1B2B3 B3B2B1B0
240 * 16-bit: B0 B1 0000B0B1 B1B00000
241 * 8-bit: B0 000000B0 B0000000
242 *
243 * So a BE kernel will have the leftmost of the above in the MSB
244 * and rightmost in the LSB and can just then "cast" the u32 "data"
245 * down to the appropriate quantity and write it.
246 *
247 * However, an LE kernel can't. It doesn't need to swap because a
248 * load from data followed by a store to user are going to preserve
249 * the byte ordering which is the wire byte order which is what the
250 * user wants, but in order to "crop" to the right size, we need to
251 * shift right first.
252 */
219 switch(len) { 253 switch(len) {
220 case 4: 254 case 4:
221 rc = __put_user((u32)data, (u32 __user *)ubuf); 255 rc = __put_user((u32)data, (u32 __user *)ubuf);
222 break; 256 break;
223 case 2: 257 case 2:
258#ifdef __LITTLE_ENDIAN__
259 data >>= 16;
260#endif
224 rc = __put_user((u16)data, (u16 __user *)ubuf); 261 rc = __put_user((u16)data, (u16 __user *)ubuf);
225 break; 262 break;
226 default: 263 default:
264#ifdef __LITTLE_ENDIAN__
265 data >>= 24;
266#endif
227 rc = __put_user((u8)data, (u8 __user *)ubuf); 267 rc = __put_user((u8)data, (u8 __user *)ubuf);
228 break; 268 break;
229 } 269 }
@@ -263,12 +303,31 @@ static ssize_t lpc_debug_write(struct file *filp, const char __user *ubuf,
263 else if (todo > 1 && (pos & 1) == 0) 303 else if (todo > 1 && (pos & 1) == 0)
264 len = 2; 304 len = 2;
265 } 305 }
306
307 /*
308 * Similarly to the read case, we have some trickery here but
309 * it's different to handle. We need to pass the value to OPAL in
310 * a register whose layout depends on the access size. We want
311 * to reproduce the memory layout of the user, however we aren't
312 * doing a load from user and a store to another memory location
313 * which would achieve that. Here we pass the value to OPAL via
314 * a register which is expected to contain the "BE" interpretation
315 * of the byte sequence. IE: for a 32-bit access, byte 0 should be
316 * in the MSB. So here we *do* need to byteswap on LE.
317 *
318 * User bytes: LE "data" OPAL "data"
319 * 32-bit: B0 B1 B2 B3 B3B2B1B0 B0B1B2B3
320 * 16-bit: B0 B1 0000B1B0 0000B0B1
321 * 8-bit: B0 000000B0 000000B0
322 */
266 switch(len) { 323 switch(len) {
267 case 4: 324 case 4:
268 rc = __get_user(data, (u32 __user *)ubuf); 325 rc = __get_user(data, (u32 __user *)ubuf);
326 data = cpu_to_be32(data);
269 break; 327 break;
270 case 2: 328 case 2:
271 rc = __get_user(data, (u16 __user *)ubuf); 329 rc = __get_user(data, (u16 __user *)ubuf);
330 data = cpu_to_be16(data);
272 break; 331 break;
273 default: 332 default:
274 rc = __get_user(data, (u8 __user *)ubuf); 333 rc = __get_user(data, (u8 __user *)ubuf);
diff --git a/arch/powerpc/platforms/powernv/opal-sensor.c b/arch/powerpc/platforms/powernv/opal-sensor.c
index 10271ad1fac4..4ab67ef7abc9 100644
--- a/arch/powerpc/platforms/powernv/opal-sensor.c
+++ b/arch/powerpc/platforms/powernv/opal-sensor.c
@@ -20,7 +20,9 @@
20 20
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/of_platform.h>
23#include <asm/opal.h> 24#include <asm/opal.h>
25#include <asm/machdep.h>
24 26
25static DEFINE_MUTEX(opal_sensor_mutex); 27static DEFINE_MUTEX(opal_sensor_mutex);
26 28
@@ -64,3 +66,21 @@ out:
64 return ret; 66 return ret;
65} 67}
66EXPORT_SYMBOL_GPL(opal_get_sensor_data); 68EXPORT_SYMBOL_GPL(opal_get_sensor_data);
69
70static __init int opal_sensor_init(void)
71{
72 struct platform_device *pdev;
73 struct device_node *sensor;
74
75 sensor = of_find_node_by_path("/ibm,opal/sensors");
76 if (!sensor) {
77 pr_err("Opal node 'sensors' not found\n");
78 return -ENODEV;
79 }
80
81 pdev = of_platform_device_create(sensor, "opal-sensor", NULL);
82 of_node_put(sensor);
83
84 return PTR_ERR_OR_ZERO(pdev);
85}
86machine_subsys_initcall(powernv, opal_sensor_init);
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 468a0f23c7f2..3ba435ec3dcd 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -1509,7 +1509,6 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,
1509 unsigned int is_64, struct msi_msg *msg) 1509 unsigned int is_64, struct msi_msg *msg)
1510{ 1510{
1511 struct pnv_ioda_pe *pe = pnv_ioda_get_pe(dev); 1511 struct pnv_ioda_pe *pe = pnv_ioda_get_pe(dev);
1512 struct pci_dn *pdn = pci_get_pdn(dev);
1513 unsigned int xive_num = hwirq - phb->msi_base; 1512 unsigned int xive_num = hwirq - phb->msi_base;
1514 __be32 data; 1513 __be32 data;
1515 int rc; 1514 int rc;
@@ -1523,7 +1522,7 @@ static int pnv_pci_ioda_msi_setup(struct pnv_phb *phb, struct pci_dev *dev,
1523 return -ENXIO; 1522 return -ENXIO;
1524 1523
1525 /* Force 32-bit MSI on some broken devices */ 1524 /* Force 32-bit MSI on some broken devices */
1526 if (pdn && pdn->force_32bit_msi) 1525 if (dev->no_64bit_msi)
1527 is_64 = 0; 1526 is_64 = 0;
1528 1527
1529 /* Assign XIVE to PE */ 1528 /* Assign XIVE to PE */
@@ -1997,7 +1996,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,
1997 if (is_kdump_kernel()) { 1996 if (is_kdump_kernel()) {
1998 pr_info(" Issue PHB reset ...\n"); 1997 pr_info(" Issue PHB reset ...\n");
1999 ioda_eeh_phb_reset(hose, EEH_RESET_FUNDAMENTAL); 1998 ioda_eeh_phb_reset(hose, EEH_RESET_FUNDAMENTAL);
2000 ioda_eeh_phb_reset(hose, OPAL_DEASSERT_RESET); 1999 ioda_eeh_phb_reset(hose, EEH_RESET_DEACTIVATE);
2001 } 2000 }
2002 2001
2003 /* Configure M64 window */ 2002 /* Configure M64 window */
diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c
index b2187d0068b8..4b20f2c6b3b2 100644
--- a/arch/powerpc/platforms/powernv/pci.c
+++ b/arch/powerpc/platforms/powernv/pci.c
@@ -50,7 +50,6 @@ static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
50{ 50{
51 struct pci_controller *hose = pci_bus_to_host(pdev->bus); 51 struct pci_controller *hose = pci_bus_to_host(pdev->bus);
52 struct pnv_phb *phb = hose->private_data; 52 struct pnv_phb *phb = hose->private_data;
53 struct pci_dn *pdn = pci_get_pdn(pdev);
54 struct msi_desc *entry; 53 struct msi_desc *entry;
55 struct msi_msg msg; 54 struct msi_msg msg;
56 int hwirq; 55 int hwirq;
@@ -60,7 +59,7 @@ static int pnv_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type)
60 if (WARN_ON(!phb) || !phb->msi_bmp.bitmap) 59 if (WARN_ON(!phb) || !phb->msi_bmp.bitmap)
61 return -ENODEV; 60 return -ENODEV;
62 61
63 if (pdn && pdn->force_32bit_msi && !phb->msi32_support) 62 if (pdev->no_64bit_msi && !phb->msi32_support)
64 return -ENODEV; 63 return -ENODEV;
65 64
66 list_for_each_entry(entry, &pdev->msi_list, list) { 65 list_for_each_entry(entry, &pdev->msi_list, list) {
diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c
index 6ad83bd11fe2..c22bb1b4beb8 100644
--- a/arch/powerpc/platforms/pseries/dlpar.c
+++ b/arch/powerpc/platforms/pseries/dlpar.c
@@ -382,7 +382,7 @@ static int dlpar_online_cpu(struct device_node *dn)
382 BUG_ON(get_cpu_current_state(cpu) 382 BUG_ON(get_cpu_current_state(cpu)
383 != CPU_STATE_OFFLINE); 383 != CPU_STATE_OFFLINE);
384 cpu_maps_update_done(); 384 cpu_maps_update_done();
385 rc = cpu_up(cpu); 385 rc = device_online(get_cpu_device(cpu));
386 if (rc) 386 if (rc)
387 goto out; 387 goto out;
388 cpu_maps_update_begin(); 388 cpu_maps_update_begin();
@@ -467,7 +467,7 @@ static int dlpar_offline_cpu(struct device_node *dn)
467 if (get_cpu_current_state(cpu) == CPU_STATE_ONLINE) { 467 if (get_cpu_current_state(cpu) == CPU_STATE_ONLINE) {
468 set_preferred_offline_state(cpu, CPU_STATE_OFFLINE); 468 set_preferred_offline_state(cpu, CPU_STATE_OFFLINE);
469 cpu_maps_update_done(); 469 cpu_maps_update_done();
470 rc = cpu_down(cpu); 470 rc = device_offline(get_cpu_device(cpu));
471 if (rc) 471 if (rc)
472 goto out; 472 goto out;
473 cpu_maps_update_begin(); 473 cpu_maps_update_begin();
diff --git a/arch/powerpc/platforms/pseries/lpar.c b/arch/powerpc/platforms/pseries/lpar.c
index 8c509d5397c6..f6880d2a40fb 100644
--- a/arch/powerpc/platforms/pseries/lpar.c
+++ b/arch/powerpc/platforms/pseries/lpar.c
@@ -43,6 +43,7 @@
43#include <asm/trace.h> 43#include <asm/trace.h>
44#include <asm/firmware.h> 44#include <asm/firmware.h>
45#include <asm/plpar_wrappers.h> 45#include <asm/plpar_wrappers.h>
46#include <asm/fadump.h>
46 47
47#include "pseries.h" 48#include "pseries.h"
48 49
@@ -247,8 +248,17 @@ static void pSeries_lpar_hptab_clear(void)
247 } 248 }
248 249
249#ifdef __LITTLE_ENDIAN__ 250#ifdef __LITTLE_ENDIAN__
250 /* Reset exceptions to big endian */ 251 /*
251 if (firmware_has_feature(FW_FEATURE_SET_MODE)) { 252 * Reset exceptions to big endian.
253 *
254 * FIXME this is a hack for kexec, we need to reset the exception
255 * endian before starting the new kernel and this is a convenient place
256 * to do it.
257 *
258 * This is also called on boot when a fadump happens. In that case we
259 * must not change the exception endian mode.
260 */
261 if (firmware_has_feature(FW_FEATURE_SET_MODE) && !is_fadump_active()) {
252 long rc; 262 long rc;
253 263
254 rc = pseries_big_endian_exceptions(); 264 rc = pseries_big_endian_exceptions();
diff --git a/arch/powerpc/platforms/pseries/msi.c b/arch/powerpc/platforms/pseries/msi.c
index 8ab5add4ac82..8b909e94fd9a 100644
--- a/arch/powerpc/platforms/pseries/msi.c
+++ b/arch/powerpc/platforms/pseries/msi.c
@@ -420,7 +420,7 @@ static int rtas_setup_msi_irqs(struct pci_dev *pdev, int nvec_in, int type)
420 */ 420 */
421again: 421again:
422 if (type == PCI_CAP_ID_MSI) { 422 if (type == PCI_CAP_ID_MSI) {
423 if (pdn->force_32bit_msi) { 423 if (pdev->no_64bit_msi) {
424 rc = rtas_change_msi(pdn, RTAS_CHANGE_32MSI_FN, nvec); 424 rc = rtas_change_msi(pdn, RTAS_CHANGE_32MSI_FN, nvec);
425 if (rc < 0) { 425 if (rc < 0) {
426 /* 426 /*
diff --git a/arch/powerpc/sysdev/fsl_msi.c b/arch/powerpc/sysdev/fsl_msi.c
index de40b48b460e..da08ed088157 100644
--- a/arch/powerpc/sysdev/fsl_msi.c
+++ b/arch/powerpc/sysdev/fsl_msi.c
@@ -361,7 +361,7 @@ static int fsl_msi_setup_hwirq(struct fsl_msi *msi, struct platform_device *dev,
361 cascade_data->virq = virt_msir; 361 cascade_data->virq = virt_msir;
362 msi->cascade_array[irq_index] = cascade_data; 362 msi->cascade_array[irq_index] = cascade_data;
363 363
364 ret = request_irq(virt_msir, fsl_msi_cascade, 0, 364 ret = request_irq(virt_msir, fsl_msi_cascade, IRQF_NO_THREAD,
365 "fsl-msi-cascade", cascade_data); 365 "fsl-msi-cascade", cascade_data);
366 if (ret) { 366 if (ret) {
367 dev_err(&dev->dev, "failed to request_irq(%d), ret = %d\n", 367 dev_err(&dev->dev, "failed to request_irq(%d), ret = %d\n",
diff --git a/arch/powerpc/xmon/xmon.c b/arch/powerpc/xmon/xmon.c
index b988b5addf86..c8efbb37d6e0 100644
--- a/arch/powerpc/xmon/xmon.c
+++ b/arch/powerpc/xmon/xmon.c
@@ -293,10 +293,10 @@ static inline void disable_surveillance(void)
293 args.token = rtas_token("set-indicator"); 293 args.token = rtas_token("set-indicator");
294 if (args.token == RTAS_UNKNOWN_SERVICE) 294 if (args.token == RTAS_UNKNOWN_SERVICE)
295 return; 295 return;
296 args.nargs = 3; 296 args.nargs = cpu_to_be32(3);
297 args.nret = 1; 297 args.nret = cpu_to_be32(1);
298 args.rets = &args.args[3]; 298 args.rets = &args.args[3];
299 args.args[0] = SURVEILLANCE_TOKEN; 299 args.args[0] = cpu_to_be32(SURVEILLANCE_TOKEN);
300 args.args[1] = 0; 300 args.args[1] = 0;
301 args.args[2] = 0; 301 args.args[2] = 0;
302 enter_rtas(__pa(&args)); 302 enter_rtas(__pa(&args));
diff --git a/arch/s390/configs/default_defconfig b/arch/s390/configs/default_defconfig
index 9d94fdd9f525..9432d0f202ef 100644
--- a/arch/s390/configs/default_defconfig
+++ b/arch/s390/configs/default_defconfig
@@ -35,7 +35,6 @@ CONFIG_MODULE_UNLOAD=y
35CONFIG_MODULE_FORCE_UNLOAD=y 35CONFIG_MODULE_FORCE_UNLOAD=y
36CONFIG_MODVERSIONS=y 36CONFIG_MODVERSIONS=y
37CONFIG_MODULE_SRCVERSION_ALL=y 37CONFIG_MODULE_SRCVERSION_ALL=y
38CONFIG_BLK_DEV_INTEGRITY=y
39CONFIG_BLK_DEV_THROTTLING=y 38CONFIG_BLK_DEV_THROTTLING=y
40CONFIG_PARTITION_ADVANCED=y 39CONFIG_PARTITION_ADVANCED=y
41CONFIG_IBM_PARTITION=y 40CONFIG_IBM_PARTITION=y
@@ -245,6 +244,7 @@ CONFIG_NF_TABLES_IPV4=m
245CONFIG_NFT_CHAIN_ROUTE_IPV4=m 244CONFIG_NFT_CHAIN_ROUTE_IPV4=m
246CONFIG_NFT_CHAIN_NAT_IPV4=m 245CONFIG_NFT_CHAIN_NAT_IPV4=m
247CONFIG_NF_TABLES_ARP=m 246CONFIG_NF_TABLES_ARP=m
247CONFIG_NF_NAT_IPV4=m
248CONFIG_IP_NF_IPTABLES=m 248CONFIG_IP_NF_IPTABLES=m
249CONFIG_IP_NF_MATCH_AH=m 249CONFIG_IP_NF_MATCH_AH=m
250CONFIG_IP_NF_MATCH_ECN=m 250CONFIG_IP_NF_MATCH_ECN=m
@@ -252,11 +252,6 @@ CONFIG_IP_NF_MATCH_RPFILTER=m
252CONFIG_IP_NF_MATCH_TTL=m 252CONFIG_IP_NF_MATCH_TTL=m
253CONFIG_IP_NF_FILTER=m 253CONFIG_IP_NF_FILTER=m
254CONFIG_IP_NF_TARGET_REJECT=m 254CONFIG_IP_NF_TARGET_REJECT=m
255CONFIG_IP_NF_TARGET_ULOG=m
256CONFIG_NF_NAT_IPV4=m
257CONFIG_IP_NF_TARGET_MASQUERADE=m
258CONFIG_IP_NF_TARGET_NETMAP=m
259CONFIG_IP_NF_TARGET_REDIRECT=m
260CONFIG_IP_NF_MANGLE=m 255CONFIG_IP_NF_MANGLE=m
261CONFIG_IP_NF_TARGET_CLUSTERIP=m 256CONFIG_IP_NF_TARGET_CLUSTERIP=m
262CONFIG_IP_NF_TARGET_ECN=m 257CONFIG_IP_NF_TARGET_ECN=m
@@ -270,6 +265,7 @@ CONFIG_NF_CONNTRACK_IPV6=m
270CONFIG_NF_TABLES_IPV6=m 265CONFIG_NF_TABLES_IPV6=m
271CONFIG_NFT_CHAIN_ROUTE_IPV6=m 266CONFIG_NFT_CHAIN_ROUTE_IPV6=m
272CONFIG_NFT_CHAIN_NAT_IPV6=m 267CONFIG_NFT_CHAIN_NAT_IPV6=m
268CONFIG_NF_NAT_IPV6=m
273CONFIG_IP6_NF_IPTABLES=m 269CONFIG_IP6_NF_IPTABLES=m
274CONFIG_IP6_NF_MATCH_AH=m 270CONFIG_IP6_NF_MATCH_AH=m
275CONFIG_IP6_NF_MATCH_EUI64=m 271CONFIG_IP6_NF_MATCH_EUI64=m
@@ -286,9 +282,6 @@ CONFIG_IP6_NF_TARGET_REJECT=m
286CONFIG_IP6_NF_MANGLE=m 282CONFIG_IP6_NF_MANGLE=m
287CONFIG_IP6_NF_RAW=m 283CONFIG_IP6_NF_RAW=m
288CONFIG_IP6_NF_SECURITY=m 284CONFIG_IP6_NF_SECURITY=m
289CONFIG_NF_NAT_IPV6=m
290CONFIG_IP6_NF_TARGET_MASQUERADE=m
291CONFIG_IP6_NF_TARGET_NPT=m
292CONFIG_NF_TABLES_BRIDGE=m 285CONFIG_NF_TABLES_BRIDGE=m
293CONFIG_NET_SCTPPROBE=m 286CONFIG_NET_SCTPPROBE=m
294CONFIG_RDS=m 287CONFIG_RDS=m
@@ -374,14 +367,13 @@ CONFIG_BLK_DEV_SR=m
374CONFIG_CHR_DEV_SG=y 367CONFIG_CHR_DEV_SG=y
375CONFIG_CHR_DEV_SCH=m 368CONFIG_CHR_DEV_SCH=m
376CONFIG_SCSI_ENCLOSURE=m 369CONFIG_SCSI_ENCLOSURE=m
377CONFIG_SCSI_MULTI_LUN=y
378CONFIG_SCSI_CONSTANTS=y 370CONFIG_SCSI_CONSTANTS=y
379CONFIG_SCSI_LOGGING=y 371CONFIG_SCSI_LOGGING=y
380CONFIG_SCSI_SPI_ATTRS=m 372CONFIG_SCSI_SPI_ATTRS=m
373CONFIG_SCSI_FC_ATTRS=y
381CONFIG_SCSI_SAS_LIBSAS=m 374CONFIG_SCSI_SAS_LIBSAS=m
382CONFIG_SCSI_SRP_ATTRS=m 375CONFIG_SCSI_SRP_ATTRS=m
383CONFIG_ISCSI_TCP=m 376CONFIG_ISCSI_TCP=m
384CONFIG_LIBFCOE=m
385CONFIG_SCSI_DEBUG=m 377CONFIG_SCSI_DEBUG=m
386CONFIG_ZFCP=y 378CONFIG_ZFCP=y
387CONFIG_SCSI_VIRTIO=m 379CONFIG_SCSI_VIRTIO=m
@@ -427,7 +419,6 @@ CONFIG_VIRTIO_NET=m
427CONFIG_NLMON=m 419CONFIG_NLMON=m
428CONFIG_VHOST_NET=m 420CONFIG_VHOST_NET=m
429# CONFIG_NET_VENDOR_ARC is not set 421# CONFIG_NET_VENDOR_ARC is not set
430# CONFIG_NET_CADENCE is not set
431# CONFIG_NET_VENDOR_CHELSIO is not set 422# CONFIG_NET_VENDOR_CHELSIO is not set
432# CONFIG_NET_VENDOR_INTEL is not set 423# CONFIG_NET_VENDOR_INTEL is not set
433# CONFIG_NET_VENDOR_MARVELL is not set 424# CONFIG_NET_VENDOR_MARVELL is not set
@@ -481,14 +472,14 @@ CONFIG_JFS_FS=m
481CONFIG_JFS_POSIX_ACL=y 472CONFIG_JFS_POSIX_ACL=y
482CONFIG_JFS_SECURITY=y 473CONFIG_JFS_SECURITY=y
483CONFIG_JFS_STATISTICS=y 474CONFIG_JFS_STATISTICS=y
484CONFIG_XFS_FS=m 475CONFIG_XFS_FS=y
485CONFIG_XFS_QUOTA=y 476CONFIG_XFS_QUOTA=y
486CONFIG_XFS_POSIX_ACL=y 477CONFIG_XFS_POSIX_ACL=y
487CONFIG_XFS_RT=y 478CONFIG_XFS_RT=y
488CONFIG_XFS_DEBUG=y 479CONFIG_XFS_DEBUG=y
489CONFIG_GFS2_FS=m 480CONFIG_GFS2_FS=m
490CONFIG_OCFS2_FS=m 481CONFIG_OCFS2_FS=m
491CONFIG_BTRFS_FS=m 482CONFIG_BTRFS_FS=y
492CONFIG_BTRFS_FS_POSIX_ACL=y 483CONFIG_BTRFS_FS_POSIX_ACL=y
493CONFIG_NILFS2_FS=m 484CONFIG_NILFS2_FS=m
494CONFIG_FANOTIFY=y 485CONFIG_FANOTIFY=y
@@ -574,7 +565,6 @@ CONFIG_DEBUG_SHIRQ=y
574CONFIG_DETECT_HUNG_TASK=y 565CONFIG_DETECT_HUNG_TASK=y
575CONFIG_TIMER_STATS=y 566CONFIG_TIMER_STATS=y
576CONFIG_DEBUG_RT_MUTEXES=y 567CONFIG_DEBUG_RT_MUTEXES=y
577CONFIG_RT_MUTEX_TESTER=y
578CONFIG_DEBUG_WW_MUTEX_SLOWPATH=y 568CONFIG_DEBUG_WW_MUTEX_SLOWPATH=y
579CONFIG_PROVE_LOCKING=y 569CONFIG_PROVE_LOCKING=y
580CONFIG_LOCK_STAT=y 570CONFIG_LOCK_STAT=y
@@ -600,8 +590,13 @@ CONFIG_FAULT_INJECTION_DEBUG_FS=y
600CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y 590CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y
601CONFIG_LATENCYTOP=y 591CONFIG_LATENCYTOP=y
602CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y 592CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y
593CONFIG_IRQSOFF_TRACER=y
594CONFIG_PREEMPT_TRACER=y
595CONFIG_SCHED_TRACER=y
596CONFIG_FTRACE_SYSCALLS=y
597CONFIG_STACK_TRACER=y
603CONFIG_BLK_DEV_IO_TRACE=y 598CONFIG_BLK_DEV_IO_TRACE=y
604# CONFIG_KPROBE_EVENT is not set 599CONFIG_UPROBE_EVENT=y
605CONFIG_LKDTM=m 600CONFIG_LKDTM=m
606CONFIG_TEST_LIST_SORT=y 601CONFIG_TEST_LIST_SORT=y
607CONFIG_KPROBES_SANITY_TEST=y 602CONFIG_KPROBES_SANITY_TEST=y
@@ -609,7 +604,10 @@ CONFIG_RBTREE_TEST=y
609CONFIG_INTERVAL_TREE_TEST=m 604CONFIG_INTERVAL_TREE_TEST=m
610CONFIG_PERCPU_TEST=m 605CONFIG_PERCPU_TEST=m
611CONFIG_ATOMIC64_SELFTEST=y 606CONFIG_ATOMIC64_SELFTEST=y
607CONFIG_TEST_STRING_HELPERS=y
608CONFIG_TEST_KSTRTOX=y
612CONFIG_DMA_API_DEBUG=y 609CONFIG_DMA_API_DEBUG=y
610CONFIG_TEST_BPF=m
613# CONFIG_STRICT_DEVMEM is not set 611# CONFIG_STRICT_DEVMEM is not set
614CONFIG_S390_PTDUMP=y 612CONFIG_S390_PTDUMP=y
615CONFIG_ENCRYPTED_KEYS=m 613CONFIG_ENCRYPTED_KEYS=m
@@ -673,12 +671,6 @@ CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m
673CONFIG_X509_CERTIFICATE_PARSER=m 671CONFIG_X509_CERTIFICATE_PARSER=m
674CONFIG_CRC7=m 672CONFIG_CRC7=m
675CONFIG_CRC8=m 673CONFIG_CRC8=m
676CONFIG_XZ_DEC_X86=y
677CONFIG_XZ_DEC_POWERPC=y
678CONFIG_XZ_DEC_IA64=y
679CONFIG_XZ_DEC_ARM=y
680CONFIG_XZ_DEC_ARMTHUMB=y
681CONFIG_XZ_DEC_SPARC=y
682CONFIG_CORDIC=m 674CONFIG_CORDIC=m
683CONFIG_CMM=m 675CONFIG_CMM=m
684CONFIG_APPLDATA_BASE=y 676CONFIG_APPLDATA_BASE=y
diff --git a/arch/s390/configs/gcov_defconfig b/arch/s390/configs/gcov_defconfig
index 90f514baa37d..219dca6ea926 100644
--- a/arch/s390/configs/gcov_defconfig
+++ b/arch/s390/configs/gcov_defconfig
@@ -35,7 +35,6 @@ CONFIG_MODULE_UNLOAD=y
35CONFIG_MODULE_FORCE_UNLOAD=y 35CONFIG_MODULE_FORCE_UNLOAD=y
36CONFIG_MODVERSIONS=y 36CONFIG_MODVERSIONS=y
37CONFIG_MODULE_SRCVERSION_ALL=y 37CONFIG_MODULE_SRCVERSION_ALL=y
38CONFIG_BLK_DEV_INTEGRITY=y
39CONFIG_BLK_DEV_THROTTLING=y 38CONFIG_BLK_DEV_THROTTLING=y
40CONFIG_PARTITION_ADVANCED=y 39CONFIG_PARTITION_ADVANCED=y
41CONFIG_IBM_PARTITION=y 40CONFIG_IBM_PARTITION=y
@@ -243,6 +242,7 @@ CONFIG_NF_TABLES_IPV4=m
243CONFIG_NFT_CHAIN_ROUTE_IPV4=m 242CONFIG_NFT_CHAIN_ROUTE_IPV4=m
244CONFIG_NFT_CHAIN_NAT_IPV4=m 243CONFIG_NFT_CHAIN_NAT_IPV4=m
245CONFIG_NF_TABLES_ARP=m 244CONFIG_NF_TABLES_ARP=m
245CONFIG_NF_NAT_IPV4=m
246CONFIG_IP_NF_IPTABLES=m 246CONFIG_IP_NF_IPTABLES=m
247CONFIG_IP_NF_MATCH_AH=m 247CONFIG_IP_NF_MATCH_AH=m
248CONFIG_IP_NF_MATCH_ECN=m 248CONFIG_IP_NF_MATCH_ECN=m
@@ -250,11 +250,6 @@ CONFIG_IP_NF_MATCH_RPFILTER=m
250CONFIG_IP_NF_MATCH_TTL=m 250CONFIG_IP_NF_MATCH_TTL=m
251CONFIG_IP_NF_FILTER=m 251CONFIG_IP_NF_FILTER=m
252CONFIG_IP_NF_TARGET_REJECT=m 252CONFIG_IP_NF_TARGET_REJECT=m
253CONFIG_IP_NF_TARGET_ULOG=m
254CONFIG_NF_NAT_IPV4=m
255CONFIG_IP_NF_TARGET_MASQUERADE=m
256CONFIG_IP_NF_TARGET_NETMAP=m
257CONFIG_IP_NF_TARGET_REDIRECT=m
258CONFIG_IP_NF_MANGLE=m 253CONFIG_IP_NF_MANGLE=m
259CONFIG_IP_NF_TARGET_CLUSTERIP=m 254CONFIG_IP_NF_TARGET_CLUSTERIP=m
260CONFIG_IP_NF_TARGET_ECN=m 255CONFIG_IP_NF_TARGET_ECN=m
@@ -268,6 +263,7 @@ CONFIG_NF_CONNTRACK_IPV6=m
268CONFIG_NF_TABLES_IPV6=m 263CONFIG_NF_TABLES_IPV6=m
269CONFIG_NFT_CHAIN_ROUTE_IPV6=m 264CONFIG_NFT_CHAIN_ROUTE_IPV6=m
270CONFIG_NFT_CHAIN_NAT_IPV6=m 265CONFIG_NFT_CHAIN_NAT_IPV6=m
266CONFIG_NF_NAT_IPV6=m
271CONFIG_IP6_NF_IPTABLES=m 267CONFIG_IP6_NF_IPTABLES=m
272CONFIG_IP6_NF_MATCH_AH=m 268CONFIG_IP6_NF_MATCH_AH=m
273CONFIG_IP6_NF_MATCH_EUI64=m 269CONFIG_IP6_NF_MATCH_EUI64=m
@@ -284,9 +280,6 @@ CONFIG_IP6_NF_TARGET_REJECT=m
284CONFIG_IP6_NF_MANGLE=m 280CONFIG_IP6_NF_MANGLE=m
285CONFIG_IP6_NF_RAW=m 281CONFIG_IP6_NF_RAW=m
286CONFIG_IP6_NF_SECURITY=m 282CONFIG_IP6_NF_SECURITY=m
287CONFIG_NF_NAT_IPV6=m
288CONFIG_IP6_NF_TARGET_MASQUERADE=m
289CONFIG_IP6_NF_TARGET_NPT=m
290CONFIG_NF_TABLES_BRIDGE=m 283CONFIG_NF_TABLES_BRIDGE=m
291CONFIG_NET_SCTPPROBE=m 284CONFIG_NET_SCTPPROBE=m
292CONFIG_RDS=m 285CONFIG_RDS=m
@@ -371,14 +364,13 @@ CONFIG_BLK_DEV_SR=m
371CONFIG_CHR_DEV_SG=y 364CONFIG_CHR_DEV_SG=y
372CONFIG_CHR_DEV_SCH=m 365CONFIG_CHR_DEV_SCH=m
373CONFIG_SCSI_ENCLOSURE=m 366CONFIG_SCSI_ENCLOSURE=m
374CONFIG_SCSI_MULTI_LUN=y
375CONFIG_SCSI_CONSTANTS=y 367CONFIG_SCSI_CONSTANTS=y
376CONFIG_SCSI_LOGGING=y 368CONFIG_SCSI_LOGGING=y
377CONFIG_SCSI_SPI_ATTRS=m 369CONFIG_SCSI_SPI_ATTRS=m
370CONFIG_SCSI_FC_ATTRS=y
378CONFIG_SCSI_SAS_LIBSAS=m 371CONFIG_SCSI_SAS_LIBSAS=m
379CONFIG_SCSI_SRP_ATTRS=m 372CONFIG_SCSI_SRP_ATTRS=m
380CONFIG_ISCSI_TCP=m 373CONFIG_ISCSI_TCP=m
381CONFIG_LIBFCOE=m
382CONFIG_SCSI_DEBUG=m 374CONFIG_SCSI_DEBUG=m
383CONFIG_ZFCP=y 375CONFIG_ZFCP=y
384CONFIG_SCSI_VIRTIO=m 376CONFIG_SCSI_VIRTIO=m
@@ -424,7 +416,6 @@ CONFIG_VIRTIO_NET=m
424CONFIG_NLMON=m 416CONFIG_NLMON=m
425CONFIG_VHOST_NET=m 417CONFIG_VHOST_NET=m
426# CONFIG_NET_VENDOR_ARC is not set 418# CONFIG_NET_VENDOR_ARC is not set
427# CONFIG_NET_CADENCE is not set
428# CONFIG_NET_VENDOR_CHELSIO is not set 419# CONFIG_NET_VENDOR_CHELSIO is not set
429# CONFIG_NET_VENDOR_INTEL is not set 420# CONFIG_NET_VENDOR_INTEL is not set
430# CONFIG_NET_VENDOR_MARVELL is not set 421# CONFIG_NET_VENDOR_MARVELL is not set
@@ -478,13 +469,13 @@ CONFIG_JFS_FS=m
478CONFIG_JFS_POSIX_ACL=y 469CONFIG_JFS_POSIX_ACL=y
479CONFIG_JFS_SECURITY=y 470CONFIG_JFS_SECURITY=y
480CONFIG_JFS_STATISTICS=y 471CONFIG_JFS_STATISTICS=y
481CONFIG_XFS_FS=m 472CONFIG_XFS_FS=y
482CONFIG_XFS_QUOTA=y 473CONFIG_XFS_QUOTA=y
483CONFIG_XFS_POSIX_ACL=y 474CONFIG_XFS_POSIX_ACL=y
484CONFIG_XFS_RT=y 475CONFIG_XFS_RT=y
485CONFIG_GFS2_FS=m 476CONFIG_GFS2_FS=m
486CONFIG_OCFS2_FS=m 477CONFIG_OCFS2_FS=m
487CONFIG_BTRFS_FS=m 478CONFIG_BTRFS_FS=y
488CONFIG_BTRFS_FS_POSIX_ACL=y 479CONFIG_BTRFS_FS_POSIX_ACL=y
489CONFIG_NILFS2_FS=m 480CONFIG_NILFS2_FS=m
490CONFIG_FANOTIFY=y 481CONFIG_FANOTIFY=y
@@ -626,12 +617,6 @@ CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m
626CONFIG_X509_CERTIFICATE_PARSER=m 617CONFIG_X509_CERTIFICATE_PARSER=m
627CONFIG_CRC7=m 618CONFIG_CRC7=m
628CONFIG_CRC8=m 619CONFIG_CRC8=m
629CONFIG_XZ_DEC_X86=y
630CONFIG_XZ_DEC_POWERPC=y
631CONFIG_XZ_DEC_IA64=y
632CONFIG_XZ_DEC_ARM=y
633CONFIG_XZ_DEC_ARMTHUMB=y
634CONFIG_XZ_DEC_SPARC=y
635CONFIG_CORDIC=m 620CONFIG_CORDIC=m
636CONFIG_CMM=m 621CONFIG_CMM=m
637CONFIG_APPLDATA_BASE=y 622CONFIG_APPLDATA_BASE=y
diff --git a/arch/s390/configs/performance_defconfig b/arch/s390/configs/performance_defconfig
index 13559d32af69..822c2f2e0c25 100644
--- a/arch/s390/configs/performance_defconfig
+++ b/arch/s390/configs/performance_defconfig
@@ -33,7 +33,6 @@ CONFIG_MODULE_UNLOAD=y
33CONFIG_MODULE_FORCE_UNLOAD=y 33CONFIG_MODULE_FORCE_UNLOAD=y
34CONFIG_MODVERSIONS=y 34CONFIG_MODVERSIONS=y
35CONFIG_MODULE_SRCVERSION_ALL=y 35CONFIG_MODULE_SRCVERSION_ALL=y
36CONFIG_BLK_DEV_INTEGRITY=y
37CONFIG_BLK_DEV_THROTTLING=y 36CONFIG_BLK_DEV_THROTTLING=y
38CONFIG_PARTITION_ADVANCED=y 37CONFIG_PARTITION_ADVANCED=y
39CONFIG_IBM_PARTITION=y 38CONFIG_IBM_PARTITION=y
@@ -241,6 +240,7 @@ CONFIG_NF_TABLES_IPV4=m
241CONFIG_NFT_CHAIN_ROUTE_IPV4=m 240CONFIG_NFT_CHAIN_ROUTE_IPV4=m
242CONFIG_NFT_CHAIN_NAT_IPV4=m 241CONFIG_NFT_CHAIN_NAT_IPV4=m
243CONFIG_NF_TABLES_ARP=m 242CONFIG_NF_TABLES_ARP=m
243CONFIG_NF_NAT_IPV4=m
244CONFIG_IP_NF_IPTABLES=m 244CONFIG_IP_NF_IPTABLES=m
245CONFIG_IP_NF_MATCH_AH=m 245CONFIG_IP_NF_MATCH_AH=m
246CONFIG_IP_NF_MATCH_ECN=m 246CONFIG_IP_NF_MATCH_ECN=m
@@ -248,11 +248,6 @@ CONFIG_IP_NF_MATCH_RPFILTER=m
248CONFIG_IP_NF_MATCH_TTL=m 248CONFIG_IP_NF_MATCH_TTL=m
249CONFIG_IP_NF_FILTER=m 249CONFIG_IP_NF_FILTER=m
250CONFIG_IP_NF_TARGET_REJECT=m 250CONFIG_IP_NF_TARGET_REJECT=m
251CONFIG_IP_NF_TARGET_ULOG=m
252CONFIG_NF_NAT_IPV4=m
253CONFIG_IP_NF_TARGET_MASQUERADE=m
254CONFIG_IP_NF_TARGET_NETMAP=m
255CONFIG_IP_NF_TARGET_REDIRECT=m
256CONFIG_IP_NF_MANGLE=m 251CONFIG_IP_NF_MANGLE=m
257CONFIG_IP_NF_TARGET_CLUSTERIP=m 252CONFIG_IP_NF_TARGET_CLUSTERIP=m
258CONFIG_IP_NF_TARGET_ECN=m 253CONFIG_IP_NF_TARGET_ECN=m
@@ -266,6 +261,7 @@ CONFIG_NF_CONNTRACK_IPV6=m
266CONFIG_NF_TABLES_IPV6=m 261CONFIG_NF_TABLES_IPV6=m
267CONFIG_NFT_CHAIN_ROUTE_IPV6=m 262CONFIG_NFT_CHAIN_ROUTE_IPV6=m
268CONFIG_NFT_CHAIN_NAT_IPV6=m 263CONFIG_NFT_CHAIN_NAT_IPV6=m
264CONFIG_NF_NAT_IPV6=m
269CONFIG_IP6_NF_IPTABLES=m 265CONFIG_IP6_NF_IPTABLES=m
270CONFIG_IP6_NF_MATCH_AH=m 266CONFIG_IP6_NF_MATCH_AH=m
271CONFIG_IP6_NF_MATCH_EUI64=m 267CONFIG_IP6_NF_MATCH_EUI64=m
@@ -282,9 +278,6 @@ CONFIG_IP6_NF_TARGET_REJECT=m
282CONFIG_IP6_NF_MANGLE=m 278CONFIG_IP6_NF_MANGLE=m
283CONFIG_IP6_NF_RAW=m 279CONFIG_IP6_NF_RAW=m
284CONFIG_IP6_NF_SECURITY=m 280CONFIG_IP6_NF_SECURITY=m
285CONFIG_NF_NAT_IPV6=m
286CONFIG_IP6_NF_TARGET_MASQUERADE=m
287CONFIG_IP6_NF_TARGET_NPT=m
288CONFIG_NF_TABLES_BRIDGE=m 281CONFIG_NF_TABLES_BRIDGE=m
289CONFIG_NET_SCTPPROBE=m 282CONFIG_NET_SCTPPROBE=m
290CONFIG_RDS=m 283CONFIG_RDS=m
@@ -369,14 +362,13 @@ CONFIG_BLK_DEV_SR=m
369CONFIG_CHR_DEV_SG=y 362CONFIG_CHR_DEV_SG=y
370CONFIG_CHR_DEV_SCH=m 363CONFIG_CHR_DEV_SCH=m
371CONFIG_SCSI_ENCLOSURE=m 364CONFIG_SCSI_ENCLOSURE=m
372CONFIG_SCSI_MULTI_LUN=y
373CONFIG_SCSI_CONSTANTS=y 365CONFIG_SCSI_CONSTANTS=y
374CONFIG_SCSI_LOGGING=y 366CONFIG_SCSI_LOGGING=y
375CONFIG_SCSI_SPI_ATTRS=m 367CONFIG_SCSI_SPI_ATTRS=m
368CONFIG_SCSI_FC_ATTRS=y
376CONFIG_SCSI_SAS_LIBSAS=m 369CONFIG_SCSI_SAS_LIBSAS=m
377CONFIG_SCSI_SRP_ATTRS=m 370CONFIG_SCSI_SRP_ATTRS=m
378CONFIG_ISCSI_TCP=m 371CONFIG_ISCSI_TCP=m
379CONFIG_LIBFCOE=m
380CONFIG_SCSI_DEBUG=m 372CONFIG_SCSI_DEBUG=m
381CONFIG_ZFCP=y 373CONFIG_ZFCP=y
382CONFIG_SCSI_VIRTIO=m 374CONFIG_SCSI_VIRTIO=m
@@ -422,7 +414,6 @@ CONFIG_VIRTIO_NET=m
422CONFIG_NLMON=m 414CONFIG_NLMON=m
423CONFIG_VHOST_NET=m 415CONFIG_VHOST_NET=m
424# CONFIG_NET_VENDOR_ARC is not set 416# CONFIG_NET_VENDOR_ARC is not set
425# CONFIG_NET_CADENCE is not set
426# CONFIG_NET_VENDOR_CHELSIO is not set 417# CONFIG_NET_VENDOR_CHELSIO is not set
427# CONFIG_NET_VENDOR_INTEL is not set 418# CONFIG_NET_VENDOR_INTEL is not set
428# CONFIG_NET_VENDOR_MARVELL is not set 419# CONFIG_NET_VENDOR_MARVELL is not set
@@ -476,13 +467,13 @@ CONFIG_JFS_FS=m
476CONFIG_JFS_POSIX_ACL=y 467CONFIG_JFS_POSIX_ACL=y
477CONFIG_JFS_SECURITY=y 468CONFIG_JFS_SECURITY=y
478CONFIG_JFS_STATISTICS=y 469CONFIG_JFS_STATISTICS=y
479CONFIG_XFS_FS=m 470CONFIG_XFS_FS=y
480CONFIG_XFS_QUOTA=y 471CONFIG_XFS_QUOTA=y
481CONFIG_XFS_POSIX_ACL=y 472CONFIG_XFS_POSIX_ACL=y
482CONFIG_XFS_RT=y 473CONFIG_XFS_RT=y
483CONFIG_GFS2_FS=m 474CONFIG_GFS2_FS=m
484CONFIG_OCFS2_FS=m 475CONFIG_OCFS2_FS=m
485CONFIG_BTRFS_FS=m 476CONFIG_BTRFS_FS=y
486CONFIG_BTRFS_FS_POSIX_ACL=y 477CONFIG_BTRFS_FS_POSIX_ACL=y
487CONFIG_NILFS2_FS=m 478CONFIG_NILFS2_FS=m
488CONFIG_FANOTIFY=y 479CONFIG_FANOTIFY=y
@@ -550,8 +541,11 @@ CONFIG_TIMER_STATS=y
550CONFIG_RCU_TORTURE_TEST=m 541CONFIG_RCU_TORTURE_TEST=m
551CONFIG_RCU_CPU_STALL_TIMEOUT=60 542CONFIG_RCU_CPU_STALL_TIMEOUT=60
552CONFIG_LATENCYTOP=y 543CONFIG_LATENCYTOP=y
544CONFIG_SCHED_TRACER=y
545CONFIG_FTRACE_SYSCALLS=y
546CONFIG_STACK_TRACER=y
553CONFIG_BLK_DEV_IO_TRACE=y 547CONFIG_BLK_DEV_IO_TRACE=y
554# CONFIG_KPROBE_EVENT is not set 548CONFIG_UPROBE_EVENT=y
555CONFIG_LKDTM=m 549CONFIG_LKDTM=m
556CONFIG_PERCPU_TEST=m 550CONFIG_PERCPU_TEST=m
557CONFIG_ATOMIC64_SELFTEST=y 551CONFIG_ATOMIC64_SELFTEST=y
@@ -618,12 +612,6 @@ CONFIG_ASYMMETRIC_PUBLIC_KEY_SUBTYPE=m
618CONFIG_X509_CERTIFICATE_PARSER=m 612CONFIG_X509_CERTIFICATE_PARSER=m
619CONFIG_CRC7=m 613CONFIG_CRC7=m
620CONFIG_CRC8=m 614CONFIG_CRC8=m
621CONFIG_XZ_DEC_X86=y
622CONFIG_XZ_DEC_POWERPC=y
623CONFIG_XZ_DEC_IA64=y
624CONFIG_XZ_DEC_ARM=y
625CONFIG_XZ_DEC_ARMTHUMB=y
626CONFIG_XZ_DEC_SPARC=y
627CONFIG_CORDIC=m 615CONFIG_CORDIC=m
628CONFIG_CMM=m 616CONFIG_CMM=m
629CONFIG_APPLDATA_BASE=y 617CONFIG_APPLDATA_BASE=y
diff --git a/arch/s390/configs/zfcpdump_defconfig b/arch/s390/configs/zfcpdump_defconfig
index e376789f2d8d..9d63051ebec4 100644
--- a/arch/s390/configs/zfcpdump_defconfig
+++ b/arch/s390/configs/zfcpdump_defconfig
@@ -22,8 +22,8 @@ CONFIG_HZ_100=y
22CONFIG_CRASH_DUMP=y 22CONFIG_CRASH_DUMP=y
23# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set 23# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
24# CONFIG_SECCOMP is not set 24# CONFIG_SECCOMP is not set
25# CONFIG_IUCV is not set
26CONFIG_NET=y 25CONFIG_NET=y
26# CONFIG_IUCV is not set
27CONFIG_ATM=y 27CONFIG_ATM=y
28CONFIG_ATM_LANE=y 28CONFIG_ATM_LANE=y
29CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug" 29CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
@@ -36,9 +36,9 @@ CONFIG_ENCLOSURE_SERVICES=y
36CONFIG_SCSI=y 36CONFIG_SCSI=y
37CONFIG_BLK_DEV_SD=y 37CONFIG_BLK_DEV_SD=y
38CONFIG_SCSI_ENCLOSURE=y 38CONFIG_SCSI_ENCLOSURE=y
39CONFIG_SCSI_MULTI_LUN=y
40CONFIG_SCSI_CONSTANTS=y 39CONFIG_SCSI_CONSTANTS=y
41CONFIG_SCSI_LOGGING=y 40CONFIG_SCSI_LOGGING=y
41CONFIG_SCSI_FC_ATTRS=y
42CONFIG_SCSI_SRP_ATTRS=y 42CONFIG_SCSI_SRP_ATTRS=y
43CONFIG_ZFCP=y 43CONFIG_ZFCP=y
44# CONFIG_INPUT_MOUSEDEV_PSAUX is not set 44# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
@@ -75,12 +75,6 @@ CONFIG_DEBUG_KERNEL=y
75CONFIG_RCU_CPU_STALL_TIMEOUT=60 75CONFIG_RCU_CPU_STALL_TIMEOUT=60
76# CONFIG_FTRACE is not set 76# CONFIG_FTRACE is not set
77# CONFIG_STRICT_DEVMEM is not set 77# CONFIG_STRICT_DEVMEM is not set
78CONFIG_XZ_DEC_X86=y
79CONFIG_XZ_DEC_POWERPC=y
80CONFIG_XZ_DEC_IA64=y
81CONFIG_XZ_DEC_ARM=y
82CONFIG_XZ_DEC_ARMTHUMB=y
83CONFIG_XZ_DEC_SPARC=y
84# CONFIG_PFAULT is not set 78# CONFIG_PFAULT is not set
85# CONFIG_S390_HYPFS_FS is not set 79# CONFIG_S390_HYPFS_FS is not set
86# CONFIG_VIRTUALIZATION is not set 80# CONFIG_VIRTUALIZATION is not set
diff --git a/arch/s390/defconfig b/arch/s390/defconfig
index fab35a8efa4f..785c5f24d6f9 100644
--- a/arch/s390/defconfig
+++ b/arch/s390/defconfig
@@ -92,10 +92,10 @@ CONFIG_CHR_DEV_ST=y
92CONFIG_BLK_DEV_SR=y 92CONFIG_BLK_DEV_SR=y
93CONFIG_BLK_DEV_SR_VENDOR=y 93CONFIG_BLK_DEV_SR_VENDOR=y
94CONFIG_CHR_DEV_SG=y 94CONFIG_CHR_DEV_SG=y
95CONFIG_SCSI_MULTI_LUN=y
96CONFIG_SCSI_CONSTANTS=y 95CONFIG_SCSI_CONSTANTS=y
97CONFIG_SCSI_LOGGING=y 96CONFIG_SCSI_LOGGING=y
98CONFIG_SCSI_SCAN_ASYNC=y 97CONFIG_SCSI_SCAN_ASYNC=y
98CONFIG_SCSI_FC_ATTRS=y
99CONFIG_ZFCP=y 99CONFIG_ZFCP=y
100CONFIG_SCSI_VIRTIO=y 100CONFIG_SCSI_VIRTIO=y
101CONFIG_NETDEVICES=y 101CONFIG_NETDEVICES=y
@@ -164,14 +164,13 @@ CONFIG_CRYPTO_CMAC=m
164CONFIG_CRYPTO_XCBC=m 164CONFIG_CRYPTO_XCBC=m
165CONFIG_CRYPTO_VMAC=m 165CONFIG_CRYPTO_VMAC=m
166CONFIG_CRYPTO_CRC32=m 166CONFIG_CRYPTO_CRC32=m
167CONFIG_CRYPTO_CRCT10DIF=m
168CONFIG_CRYPTO_MD4=m 167CONFIG_CRYPTO_MD4=m
169CONFIG_CRYPTO_MICHAEL_MIC=m 168CONFIG_CRYPTO_MICHAEL_MIC=m
170CONFIG_CRYPTO_RMD128=m 169CONFIG_CRYPTO_RMD128=m
171CONFIG_CRYPTO_RMD160=m 170CONFIG_CRYPTO_RMD160=m
172CONFIG_CRYPTO_RMD256=m 171CONFIG_CRYPTO_RMD256=m
173CONFIG_CRYPTO_RMD320=m 172CONFIG_CRYPTO_RMD320=m
174CONFIG_CRYPTO_SHA256=m 173CONFIG_CRYPTO_SHA256=y
175CONFIG_CRYPTO_SHA512=m 174CONFIG_CRYPTO_SHA512=m
176CONFIG_CRYPTO_TGR192=m 175CONFIG_CRYPTO_TGR192=m
177CONFIG_CRYPTO_WP512=m 176CONFIG_CRYPTO_WP512=m
diff --git a/arch/s390/kernel/ftrace.c b/arch/s390/kernel/ftrace.c
index 51d14fe5eb9a..ca1cabb3a96c 100644
--- a/arch/s390/kernel/ftrace.c
+++ b/arch/s390/kernel/ftrace.c
@@ -121,6 +121,8 @@ unsigned long __kprobes prepare_ftrace_return(unsigned long parent,
121{ 121{
122 struct ftrace_graph_ent trace; 122 struct ftrace_graph_ent trace;
123 123
124 if (unlikely(ftrace_graph_is_dead()))
125 goto out;
124 if (unlikely(atomic_read(&current->tracing_graph_pause))) 126 if (unlikely(atomic_read(&current->tracing_graph_pause)))
125 goto out; 127 goto out;
126 ip = (ip & PSW_ADDR_INSN) - MCOUNT_INSN_SIZE; 128 ip = (ip & PSW_ADDR_INSN) - MCOUNT_INSN_SIZE;
diff --git a/arch/s390/kernel/nmi.c b/arch/s390/kernel/nmi.c
index dd1c24ceda50..3f51cf4e8f02 100644
--- a/arch/s390/kernel/nmi.c
+++ b/arch/s390/kernel/nmi.c
@@ -54,12 +54,8 @@ void s390_handle_mcck(void)
54 */ 54 */
55 local_irq_save(flags); 55 local_irq_save(flags);
56 local_mcck_disable(); 56 local_mcck_disable();
57 /* 57 mcck = *this_cpu_ptr(&cpu_mcck);
58 * Ummm... Does this make sense at all? Copying the percpu struct 58 memset(this_cpu_ptr(&cpu_mcck), 0, sizeof(mcck));
59 * and then zapping it one statement later?
60 */
61 memcpy(&mcck, this_cpu_ptr(&cpu_mcck), sizeof(mcck));
62 memset(&mcck, 0, sizeof(struct mcck_struct));
63 clear_cpu_flag(CIF_MCCK_PENDING); 59 clear_cpu_flag(CIF_MCCK_PENDING);
64 local_mcck_enable(); 60 local_mcck_enable();
65 local_irq_restore(flags); 61 local_irq_restore(flags);
diff --git a/arch/s390/kernel/vdso32/clock_gettime.S b/arch/s390/kernel/vdso32/clock_gettime.S
index 48c2206a3956..5eec9afbb5b5 100644
--- a/arch/s390/kernel/vdso32/clock_gettime.S
+++ b/arch/s390/kernel/vdso32/clock_gettime.S
@@ -19,6 +19,7 @@
19 .type __kernel_clock_gettime,@function 19 .type __kernel_clock_gettime,@function
20__kernel_clock_gettime: 20__kernel_clock_gettime:
21 .cfi_startproc 21 .cfi_startproc
22 ahi %r15,-16
22 basr %r5,0 23 basr %r5,0
230: al %r5,21f-0b(%r5) /* get &_vdso_data */ 240: al %r5,21f-0b(%r5) /* get &_vdso_data */
24 chi %r2,__CLOCK_REALTIME_COARSE 25 chi %r2,__CLOCK_REALTIME_COARSE
@@ -34,8 +35,8 @@ __kernel_clock_gettime:
341: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */ 351: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
35 tml %r4,0x0001 /* pending update ? loop */ 36 tml %r4,0x0001 /* pending update ? loop */
36 jnz 1b 37 jnz 1b
37 stcke 24(%r15) /* Store TOD clock */ 38 stcke 0(%r15) /* Store TOD clock */
38 lm %r0,%r1,25(%r15) 39 lm %r0,%r1,1(%r15)
39 s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ 40 s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
40 sl %r1,__VDSO_XTIME_STAMP+4(%r5) 41 sl %r1,__VDSO_XTIME_STAMP+4(%r5)
41 brc 3,2f 42 brc 3,2f
@@ -70,6 +71,7 @@ __kernel_clock_gettime:
708: st %r2,0(%r3) /* store tp->tv_sec */ 718: st %r2,0(%r3) /* store tp->tv_sec */
71 st %r1,4(%r3) /* store tp->tv_nsec */ 72 st %r1,4(%r3) /* store tp->tv_nsec */
72 lhi %r2,0 73 lhi %r2,0
74 ahi %r15,16
73 br %r14 75 br %r14
74 76
75 /* CLOCK_MONOTONIC_COARSE */ 77 /* CLOCK_MONOTONIC_COARSE */
@@ -96,8 +98,8 @@ __kernel_clock_gettime:
9611: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */ 9811: l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
97 tml %r4,0x0001 /* pending update ? loop */ 99 tml %r4,0x0001 /* pending update ? loop */
98 jnz 11b 100 jnz 11b
99 stcke 24(%r15) /* Store TOD clock */ 101 stcke 0(%r15) /* Store TOD clock */
100 lm %r0,%r1,25(%r15) 102 lm %r0,%r1,1(%r15)
101 s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ 103 s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
102 sl %r1,__VDSO_XTIME_STAMP+4(%r5) 104 sl %r1,__VDSO_XTIME_STAMP+4(%r5)
103 brc 3,12f 105 brc 3,12f
@@ -132,11 +134,13 @@ __kernel_clock_gettime:
13217: st %r2,0(%r3) /* store tp->tv_sec */ 13417: st %r2,0(%r3) /* store tp->tv_sec */
133 st %r1,4(%r3) /* store tp->tv_nsec */ 135 st %r1,4(%r3) /* store tp->tv_nsec */
134 lhi %r2,0 136 lhi %r2,0
137 ahi %r15,16
135 br %r14 138 br %r14
136 139
137 /* Fallback to system call */ 140 /* Fallback to system call */
13819: lhi %r1,__NR_clock_gettime 14119: lhi %r1,__NR_clock_gettime
139 svc 0 142 svc 0
143 ahi %r15,16
140 br %r14 144 br %r14
141 145
14220: .long 1000000000 14620: .long 1000000000
diff --git a/arch/s390/kernel/vdso32/gettimeofday.S b/arch/s390/kernel/vdso32/gettimeofday.S
index 60def5f562db..719de6186b20 100644
--- a/arch/s390/kernel/vdso32/gettimeofday.S
+++ b/arch/s390/kernel/vdso32/gettimeofday.S
@@ -19,6 +19,7 @@
19 .type __kernel_gettimeofday,@function 19 .type __kernel_gettimeofday,@function
20__kernel_gettimeofday: 20__kernel_gettimeofday:
21 .cfi_startproc 21 .cfi_startproc
22 ahi %r15,-16
22 basr %r5,0 23 basr %r5,0
230: al %r5,13f-0b(%r5) /* get &_vdso_data */ 240: al %r5,13f-0b(%r5) /* get &_vdso_data */
241: ltr %r3,%r3 /* check if tz is NULL */ 251: ltr %r3,%r3 /* check if tz is NULL */
@@ -29,30 +30,30 @@ __kernel_gettimeofday:
29 l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */ 30 l %r4,__VDSO_UPD_COUNT+4(%r5) /* load update counter */
30 tml %r4,0x0001 /* pending update ? loop */ 31 tml %r4,0x0001 /* pending update ? loop */
31 jnz 1b 32 jnz 1b
32 stcke 24(%r15) /* Store TOD clock */ 33 stcke 0(%r15) /* Store TOD clock */
33 lm %r0,%r1,25(%r15) 34 lm %r0,%r1,1(%r15)
34 s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ 35 s %r0,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
35 sl %r1,__VDSO_XTIME_STAMP+4(%r5) 36 sl %r1,__VDSO_XTIME_STAMP+4(%r5)
36 brc 3,3f 37 brc 3,3f
37 ahi %r0,-1 38 ahi %r0,-1
383: ms %r0,__VDSO_TK_MULT(%r5) /* * tk->mult */ 393: ms %r0,__VDSO_TK_MULT(%r5) /* * tk->mult */
39 st %r0,24(%r15) 40 st %r0,0(%r15)
40 l %r0,__VDSO_TK_MULT(%r5) 41 l %r0,__VDSO_TK_MULT(%r5)
41 ltr %r1,%r1 42 ltr %r1,%r1
42 mr %r0,%r0 43 mr %r0,%r0
43 jnm 4f 44 jnm 4f
44 a %r0,__VDSO_TK_MULT(%r5) 45 a %r0,__VDSO_TK_MULT(%r5)
454: al %r0,24(%r15) 464: al %r0,0(%r15)
46 al %r0,__VDSO_XTIME_NSEC(%r5) /* + xtime */ 47 al %r0,__VDSO_XTIME_NSEC(%r5) /* + xtime */
47 al %r1,__VDSO_XTIME_NSEC+4(%r5) 48 al %r1,__VDSO_XTIME_NSEC+4(%r5)
48 brc 12,5f 49 brc 12,5f
49 ahi %r0,1 50 ahi %r0,1
505: mvc 24(4,%r15),__VDSO_XTIME_SEC+4(%r5) 515: mvc 0(4,%r15),__VDSO_XTIME_SEC+4(%r5)
51 cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */ 52 cl %r4,__VDSO_UPD_COUNT+4(%r5) /* check update counter */
52 jne 1b 53 jne 1b
53 l %r4,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */ 54 l %r4,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
54 srdl %r0,0(%r4) /* >> tk->shift */ 55 srdl %r0,0(%r4) /* >> tk->shift */
55 l %r4,24(%r15) /* get tv_sec from stack */ 56 l %r4,0(%r15) /* get tv_sec from stack */
56 basr %r5,0 57 basr %r5,0
576: ltr %r0,%r0 586: ltr %r0,%r0
58 jnz 7f 59 jnz 7f
@@ -71,6 +72,7 @@ __kernel_gettimeofday:
719: srl %r0,6 729: srl %r0,6
72 st %r0,4(%r2) /* store tv->tv_usec */ 73 st %r0,4(%r2) /* store tv->tv_usec */
7310: slr %r2,%r2 7410: slr %r2,%r2
75 ahi %r15,16
74 br %r14 76 br %r14
7511: .long 1000000000 7711: .long 1000000000
7612: .long 274877907 7812: .long 274877907
diff --git a/arch/s390/kernel/vdso64/clock_gettime.S b/arch/s390/kernel/vdso64/clock_gettime.S
index 9d9761f8e110..7699e735ae28 100644
--- a/arch/s390/kernel/vdso64/clock_gettime.S
+++ b/arch/s390/kernel/vdso64/clock_gettime.S
@@ -19,6 +19,7 @@
19 .type __kernel_clock_gettime,@function 19 .type __kernel_clock_gettime,@function
20__kernel_clock_gettime: 20__kernel_clock_gettime:
21 .cfi_startproc 21 .cfi_startproc
22 aghi %r15,-16
22 larl %r5,_vdso_data 23 larl %r5,_vdso_data
23 cghi %r2,__CLOCK_REALTIME_COARSE 24 cghi %r2,__CLOCK_REALTIME_COARSE
24 je 4f 25 je 4f
@@ -37,10 +38,10 @@ __kernel_clock_gettime:
370: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */ 380: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
38 tmll %r4,0x0001 /* pending update ? loop */ 39 tmll %r4,0x0001 /* pending update ? loop */
39 jnz 0b 40 jnz 0b
40 stcke 48(%r15) /* Store TOD clock */ 41 stcke 0(%r15) /* Store TOD clock */
41 lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */ 42 lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
42 lg %r0,__VDSO_WTOM_SEC(%r5) 43 lg %r0,__VDSO_WTOM_SEC(%r5)
43 lg %r1,49(%r15) 44 lg %r1,1(%r15)
44 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ 45 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
45 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */ 46 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */
46 alg %r1,__VDSO_WTOM_NSEC(%r5) 47 alg %r1,__VDSO_WTOM_NSEC(%r5)
@@ -56,6 +57,7 @@ __kernel_clock_gettime:
562: stg %r0,0(%r3) /* store tp->tv_sec */ 572: stg %r0,0(%r3) /* store tp->tv_sec */
57 stg %r1,8(%r3) /* store tp->tv_nsec */ 58 stg %r1,8(%r3) /* store tp->tv_nsec */
58 lghi %r2,0 59 lghi %r2,0
60 aghi %r15,16
59 br %r14 61 br %r14
60 62
61 /* CLOCK_MONOTONIC_COARSE */ 63 /* CLOCK_MONOTONIC_COARSE */
@@ -82,9 +84,9 @@ __kernel_clock_gettime:
825: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */ 845: lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
83 tmll %r4,0x0001 /* pending update ? loop */ 85 tmll %r4,0x0001 /* pending update ? loop */
84 jnz 5b 86 jnz 5b
85 stcke 48(%r15) /* Store TOD clock */ 87 stcke 0(%r15) /* Store TOD clock */
86 lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */ 88 lgf %r2,__VDSO_TK_SHIFT(%r5) /* Timekeeper shift */
87 lg %r1,49(%r15) 89 lg %r1,1(%r15)
88 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ 90 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
89 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */ 91 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */
90 alg %r1,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */ 92 alg %r1,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */
@@ -101,6 +103,7 @@ __kernel_clock_gettime:
1017: stg %r0,0(%r3) /* store tp->tv_sec */ 1037: stg %r0,0(%r3) /* store tp->tv_sec */
102 stg %r1,8(%r3) /* store tp->tv_nsec */ 104 stg %r1,8(%r3) /* store tp->tv_nsec */
103 lghi %r2,0 105 lghi %r2,0
106 aghi %r15,16
104 br %r14 107 br %r14
105 108
106 /* CLOCK_THREAD_CPUTIME_ID for this thread */ 109 /* CLOCK_THREAD_CPUTIME_ID for this thread */
@@ -134,11 +137,13 @@ __kernel_clock_gettime:
134 slgr %r4,%r0 /* r4 = tv_nsec */ 137 slgr %r4,%r0 /* r4 = tv_nsec */
135 stg %r4,8(%r3) 138 stg %r4,8(%r3)
136 lghi %r2,0 139 lghi %r2,0
140 aghi %r15,16
137 br %r14 141 br %r14
138 142
139 /* Fallback to system call */ 143 /* Fallback to system call */
14012: lghi %r1,__NR_clock_gettime 14412: lghi %r1,__NR_clock_gettime
141 svc 0 145 svc 0
146 aghi %r15,16
142 br %r14 147 br %r14
143 148
14413: .quad 1000000000 14913: .quad 1000000000
diff --git a/arch/s390/kernel/vdso64/gettimeofday.S b/arch/s390/kernel/vdso64/gettimeofday.S
index 7a344995a97f..6ce46707663c 100644
--- a/arch/s390/kernel/vdso64/gettimeofday.S
+++ b/arch/s390/kernel/vdso64/gettimeofday.S
@@ -19,6 +19,7 @@
19 .type __kernel_gettimeofday,@function 19 .type __kernel_gettimeofday,@function
20__kernel_gettimeofday: 20__kernel_gettimeofday:
21 .cfi_startproc 21 .cfi_startproc
22 aghi %r15,-16
22 larl %r5,_vdso_data 23 larl %r5,_vdso_data
230: ltgr %r3,%r3 /* check if tz is NULL */ 240: ltgr %r3,%r3 /* check if tz is NULL */
24 je 1f 25 je 1f
@@ -28,8 +29,8 @@ __kernel_gettimeofday:
28 lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */ 29 lg %r4,__VDSO_UPD_COUNT(%r5) /* load update counter */
29 tmll %r4,0x0001 /* pending update ? loop */ 30 tmll %r4,0x0001 /* pending update ? loop */
30 jnz 0b 31 jnz 0b
31 stcke 48(%r15) /* Store TOD clock */ 32 stcke 0(%r15) /* Store TOD clock */
32 lg %r1,49(%r15) 33 lg %r1,1(%r15)
33 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */ 34 sg %r1,__VDSO_XTIME_STAMP(%r5) /* TOD - cycle_last */
34 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */ 35 msgf %r1,__VDSO_TK_MULT(%r5) /* * tk->mult */
35 alg %r1,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */ 36 alg %r1,__VDSO_XTIME_NSEC(%r5) /* + tk->xtime_nsec */
@@ -50,6 +51,7 @@ __kernel_gettimeofday:
50 srlg %r0,%r0,6 51 srlg %r0,%r0,6
51 stg %r0,8(%r2) /* store tv->tv_usec */ 52 stg %r0,8(%r2) /* store tv->tv_usec */
524: lghi %r2,0 534: lghi %r2,0
54 aghi %r15,16
53 br %r14 55 br %r14
545: .quad 1000000000 565: .quad 1000000000
55 .long 274877907 57 .long 274877907
diff --git a/arch/s390/kernel/vtime.c b/arch/s390/kernel/vtime.c
index 416f2a323ba5..7f0089d9a4aa 100644
--- a/arch/s390/kernel/vtime.c
+++ b/arch/s390/kernel/vtime.c
@@ -66,7 +66,11 @@ static int do_account_vtime(struct task_struct *tsk, int hardirq_offset)
66 clock = S390_lowcore.last_update_clock; 66 clock = S390_lowcore.last_update_clock;
67 asm volatile( 67 asm volatile(
68 " stpt %0\n" /* Store current cpu timer value */ 68 " stpt %0\n" /* Store current cpu timer value */
69#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
70 " stckf %1" /* Store current tod clock value */
71#else
69 " stck %1" /* Store current tod clock value */ 72 " stck %1" /* Store current tod clock value */
73#endif
70 : "=m" (S390_lowcore.last_update_timer), 74 : "=m" (S390_lowcore.last_update_timer),
71 "=m" (S390_lowcore.last_update_clock)); 75 "=m" (S390_lowcore.last_update_clock));
72 S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer; 76 S390_lowcore.system_timer += timer - S390_lowcore.last_update_timer;
diff --git a/arch/sparc/include/asm/atomic_32.h b/arch/sparc/include/asm/atomic_32.h
index 765c1776ec9f..0e69b7e7a439 100644
--- a/arch/sparc/include/asm/atomic_32.h
+++ b/arch/sparc/include/asm/atomic_32.h
@@ -22,7 +22,7 @@
22 22
23int atomic_add_return(int, atomic_t *); 23int atomic_add_return(int, atomic_t *);
24int atomic_cmpxchg(atomic_t *, int, int); 24int atomic_cmpxchg(atomic_t *, int, int);
25#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) 25int atomic_xchg(atomic_t *, int);
26int __atomic_add_unless(atomic_t *, int, int); 26int __atomic_add_unless(atomic_t *, int, int);
27void atomic_set(atomic_t *, int); 27void atomic_set(atomic_t *, int);
28 28
diff --git a/arch/sparc/include/asm/cmpxchg_32.h b/arch/sparc/include/asm/cmpxchg_32.h
index 32c29a133f9d..d38b52dca216 100644
--- a/arch/sparc/include/asm/cmpxchg_32.h
+++ b/arch/sparc/include/asm/cmpxchg_32.h
@@ -11,22 +11,14 @@
11#ifndef __ARCH_SPARC_CMPXCHG__ 11#ifndef __ARCH_SPARC_CMPXCHG__
12#define __ARCH_SPARC_CMPXCHG__ 12#define __ARCH_SPARC_CMPXCHG__
13 13
14static inline unsigned long xchg_u32(__volatile__ unsigned long *m, unsigned long val) 14unsigned long __xchg_u32(volatile u32 *m, u32 new);
15{
16 __asm__ __volatile__("swap [%2], %0"
17 : "=&r" (val)
18 : "0" (val), "r" (m)
19 : "memory");
20 return val;
21}
22
23void __xchg_called_with_bad_pointer(void); 15void __xchg_called_with_bad_pointer(void);
24 16
25static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size) 17static inline unsigned long __xchg(unsigned long x, __volatile__ void * ptr, int size)
26{ 18{
27 switch (size) { 19 switch (size) {
28 case 4: 20 case 4:
29 return xchg_u32(ptr, x); 21 return __xchg_u32(ptr, x);
30 } 22 }
31 __xchg_called_with_bad_pointer(); 23 __xchg_called_with_bad_pointer();
32 return x; 24 return x;
diff --git a/arch/sparc/include/asm/dma-mapping.h b/arch/sparc/include/asm/dma-mapping.h
index 5b1b52a04ad6..7e064c68c5ec 100644
--- a/arch/sparc/include/asm/dma-mapping.h
+++ b/arch/sparc/include/asm/dma-mapping.h
@@ -12,6 +12,14 @@ int dma_supported(struct device *dev, u64 mask);
12#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f) 12#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
13#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h) 13#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
14 14
15static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,
16 enum dma_data_direction dir)
17{
18 /* Since dma_{alloc,free}_noncoherent() allocated coherent memory, this
19 * routine can be a nop.
20 */
21}
22
15extern struct dma_map_ops *dma_ops; 23extern struct dma_map_ops *dma_ops;
16extern struct dma_map_ops *leon_dma_ops; 24extern struct dma_map_ops *leon_dma_ops;
17extern struct dma_map_ops pci32_dma_ops; 25extern struct dma_map_ops pci32_dma_ops;
diff --git a/arch/sparc/include/uapi/asm/swab.h b/arch/sparc/include/uapi/asm/swab.h
index a34ad079487e..4c7c12d69bea 100644
--- a/arch/sparc/include/uapi/asm/swab.h
+++ b/arch/sparc/include/uapi/asm/swab.h
@@ -9,9 +9,9 @@ static inline __u16 __arch_swab16p(const __u16 *addr)
9{ 9{
10 __u16 ret; 10 __u16 ret;
11 11
12 __asm__ __volatile__ ("lduha [%1] %2, %0" 12 __asm__ __volatile__ ("lduha [%2] %3, %0"
13 : "=r" (ret) 13 : "=r" (ret)
14 : "r" (addr), "i" (ASI_PL)); 14 : "m" (*addr), "r" (addr), "i" (ASI_PL));
15 return ret; 15 return ret;
16} 16}
17#define __arch_swab16p __arch_swab16p 17#define __arch_swab16p __arch_swab16p
@@ -20,9 +20,9 @@ static inline __u32 __arch_swab32p(const __u32 *addr)
20{ 20{
21 __u32 ret; 21 __u32 ret;
22 22
23 __asm__ __volatile__ ("lduwa [%1] %2, %0" 23 __asm__ __volatile__ ("lduwa [%2] %3, %0"
24 : "=r" (ret) 24 : "=r" (ret)
25 : "r" (addr), "i" (ASI_PL)); 25 : "m" (*addr), "r" (addr), "i" (ASI_PL));
26 return ret; 26 return ret;
27} 27}
28#define __arch_swab32p __arch_swab32p 28#define __arch_swab32p __arch_swab32p
@@ -31,9 +31,9 @@ static inline __u64 __arch_swab64p(const __u64 *addr)
31{ 31{
32 __u64 ret; 32 __u64 ret;
33 33
34 __asm__ __volatile__ ("ldxa [%1] %2, %0" 34 __asm__ __volatile__ ("ldxa [%2] %3, %0"
35 : "=r" (ret) 35 : "=r" (ret)
36 : "r" (addr), "i" (ASI_PL)); 36 : "m" (*addr), "r" (addr), "i" (ASI_PL));
37 return ret; 37 return ret;
38} 38}
39#define __arch_swab64p __arch_swab64p 39#define __arch_swab64p __arch_swab64p
diff --git a/arch/sparc/kernel/pci_schizo.c b/arch/sparc/kernel/pci_schizo.c
index 8f76f23dac38..f9c6813c132d 100644
--- a/arch/sparc/kernel/pci_schizo.c
+++ b/arch/sparc/kernel/pci_schizo.c
@@ -581,7 +581,7 @@ static irqreturn_t schizo_pcierr_intr_other(struct pci_pbm_info *pbm)
581{ 581{
582 unsigned long csr_reg, csr, csr_error_bits; 582 unsigned long csr_reg, csr, csr_error_bits;
583 irqreturn_t ret = IRQ_NONE; 583 irqreturn_t ret = IRQ_NONE;
584 u16 stat; 584 u32 stat;
585 585
586 csr_reg = pbm->pbm_regs + SCHIZO_PCI_CTRL; 586 csr_reg = pbm->pbm_regs + SCHIZO_PCI_CTRL;
587 csr = upa_readq(csr_reg); 587 csr = upa_readq(csr_reg);
@@ -617,7 +617,7 @@ static irqreturn_t schizo_pcierr_intr_other(struct pci_pbm_info *pbm)
617 pbm->name); 617 pbm->name);
618 ret = IRQ_HANDLED; 618 ret = IRQ_HANDLED;
619 } 619 }
620 pci_read_config_word(pbm->pci_bus->self, PCI_STATUS, &stat); 620 pbm->pci_ops->read(pbm->pci_bus, 0, PCI_STATUS, 2, &stat);
621 if (stat & (PCI_STATUS_PARITY | 621 if (stat & (PCI_STATUS_PARITY |
622 PCI_STATUS_SIG_TARGET_ABORT | 622 PCI_STATUS_SIG_TARGET_ABORT |
623 PCI_STATUS_REC_TARGET_ABORT | 623 PCI_STATUS_REC_TARGET_ABORT |
@@ -625,7 +625,7 @@ static irqreturn_t schizo_pcierr_intr_other(struct pci_pbm_info *pbm)
625 PCI_STATUS_SIG_SYSTEM_ERROR)) { 625 PCI_STATUS_SIG_SYSTEM_ERROR)) {
626 printk("%s: PCI bus error, PCI_STATUS[%04x]\n", 626 printk("%s: PCI bus error, PCI_STATUS[%04x]\n",
627 pbm->name, stat); 627 pbm->name, stat);
628 pci_write_config_word(pbm->pci_bus->self, PCI_STATUS, 0xffff); 628 pbm->pci_ops->write(pbm->pci_bus, 0, PCI_STATUS, 2, 0xffff);
629 ret = IRQ_HANDLED; 629 ret = IRQ_HANDLED;
630 } 630 }
631 return ret; 631 return ret;
diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
index 302c476413d5..da6f1a7fc4db 100644
--- a/arch/sparc/kernel/smp_64.c
+++ b/arch/sparc/kernel/smp_64.c
@@ -816,13 +816,17 @@ void arch_send_call_function_single_ipi(int cpu)
816void __irq_entry smp_call_function_client(int irq, struct pt_regs *regs) 816void __irq_entry smp_call_function_client(int irq, struct pt_regs *regs)
817{ 817{
818 clear_softint(1 << irq); 818 clear_softint(1 << irq);
819 irq_enter();
819 generic_smp_call_function_interrupt(); 820 generic_smp_call_function_interrupt();
821 irq_exit();
820} 822}
821 823
822void __irq_entry smp_call_function_single_client(int irq, struct pt_regs *regs) 824void __irq_entry smp_call_function_single_client(int irq, struct pt_regs *regs)
823{ 825{
824 clear_softint(1 << irq); 826 clear_softint(1 << irq);
827 irq_enter();
825 generic_smp_call_function_single_interrupt(); 828 generic_smp_call_function_single_interrupt();
829 irq_exit();
826} 830}
827 831
828static void tsb_sync(void *info) 832static void tsb_sync(void *info)
diff --git a/arch/sparc/lib/atomic32.c b/arch/sparc/lib/atomic32.c
index a7c418ac26af..71cd65ab200c 100644
--- a/arch/sparc/lib/atomic32.c
+++ b/arch/sparc/lib/atomic32.c
@@ -45,6 +45,19 @@ ATOMIC_OP(add, +=)
45 45
46#undef ATOMIC_OP 46#undef ATOMIC_OP
47 47
48int atomic_xchg(atomic_t *v, int new)
49{
50 int ret;
51 unsigned long flags;
52
53 spin_lock_irqsave(ATOMIC_HASH(v), flags);
54 ret = v->counter;
55 v->counter = new;
56 spin_unlock_irqrestore(ATOMIC_HASH(v), flags);
57 return ret;
58}
59EXPORT_SYMBOL(atomic_xchg);
60
48int atomic_cmpxchg(atomic_t *v, int old, int new) 61int atomic_cmpxchg(atomic_t *v, int old, int new)
49{ 62{
50 int ret; 63 int ret;
@@ -137,3 +150,17 @@ unsigned long __cmpxchg_u32(volatile u32 *ptr, u32 old, u32 new)
137 return (unsigned long)prev; 150 return (unsigned long)prev;
138} 151}
139EXPORT_SYMBOL(__cmpxchg_u32); 152EXPORT_SYMBOL(__cmpxchg_u32);
153
154unsigned long __xchg_u32(volatile u32 *ptr, u32 new)
155{
156 unsigned long flags;
157 u32 prev;
158
159 spin_lock_irqsave(ATOMIC_HASH(ptr), flags);
160 prev = *ptr;
161 *ptr = new;
162 spin_unlock_irqrestore(ATOMIC_HASH(ptr), flags);
163
164 return (unsigned long)prev;
165}
166EXPORT_SYMBOL(__xchg_u32);
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index ded8a6774ac9..41a503c15862 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -144,7 +144,7 @@ config INSTRUCTION_DECODER
144 144
145config PERF_EVENTS_INTEL_UNCORE 145config PERF_EVENTS_INTEL_UNCORE
146 def_bool y 146 def_bool y
147 depends on PERF_EVENTS && SUP_SUP_INTEL && PCI 147 depends on PERF_EVENTS && CPU_SUP_INTEL && PCI
148 148
149config OUTPUT_FORMAT 149config OUTPUT_FORMAT
150 string 150 string
diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
index 704f58aa79cd..45abc363dd3e 100644
--- a/arch/x86/boot/compressed/Makefile
+++ b/arch/x86/boot/compressed/Makefile
@@ -76,8 +76,10 @@ suffix-$(CONFIG_KERNEL_XZ) := xz
76suffix-$(CONFIG_KERNEL_LZO) := lzo 76suffix-$(CONFIG_KERNEL_LZO) := lzo
77suffix-$(CONFIG_KERNEL_LZ4) := lz4 77suffix-$(CONFIG_KERNEL_LZ4) := lz4
78 78
79RUN_SIZE = $(shell $(OBJDUMP) -h vmlinux | \
80 perl $(srctree)/arch/x86/tools/calc_run_size.pl)
79quiet_cmd_mkpiggy = MKPIGGY $@ 81quiet_cmd_mkpiggy = MKPIGGY $@
80 cmd_mkpiggy = $(obj)/mkpiggy $< > $@ || ( rm -f $@ ; false ) 82 cmd_mkpiggy = $(obj)/mkpiggy $< $(RUN_SIZE) > $@ || ( rm -f $@ ; false )
81 83
82targets += piggy.S 84targets += piggy.S
83$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE 85$(obj)/piggy.S: $(obj)/vmlinux.bin.$(suffix-y) $(obj)/mkpiggy FORCE
diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
index cbed1407a5cd..1d7fbbcc196d 100644
--- a/arch/x86/boot/compressed/head_32.S
+++ b/arch/x86/boot/compressed/head_32.S
@@ -207,7 +207,8 @@ relocated:
207 * Do the decompression, and jump to the new kernel.. 207 * Do the decompression, and jump to the new kernel..
208 */ 208 */
209 /* push arguments for decompress_kernel: */ 209 /* push arguments for decompress_kernel: */
210 pushl $z_output_len /* decompressed length */ 210 pushl $z_run_size /* size of kernel with .bss and .brk */
211 pushl $z_output_len /* decompressed length, end of relocs */
211 leal z_extract_offset_negative(%ebx), %ebp 212 leal z_extract_offset_negative(%ebx), %ebp
212 pushl %ebp /* output address */ 213 pushl %ebp /* output address */
213 pushl $z_input_len /* input_len */ 214 pushl $z_input_len /* input_len */
@@ -217,7 +218,7 @@ relocated:
217 pushl %eax /* heap area */ 218 pushl %eax /* heap area */
218 pushl %esi /* real mode pointer */ 219 pushl %esi /* real mode pointer */
219 call decompress_kernel /* returns kernel location in %eax */ 220 call decompress_kernel /* returns kernel location in %eax */
220 addl $24, %esp 221 addl $28, %esp
221 222
222/* 223/*
223 * Jump to the decompressed kernel. 224 * Jump to the decompressed kernel.
diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
index 2884e0c3e8a5..6b1766c6c082 100644
--- a/arch/x86/boot/compressed/head_64.S
+++ b/arch/x86/boot/compressed/head_64.S
@@ -402,13 +402,16 @@ relocated:
402 * Do the decompression, and jump to the new kernel.. 402 * Do the decompression, and jump to the new kernel..
403 */ 403 */
404 pushq %rsi /* Save the real mode argument */ 404 pushq %rsi /* Save the real mode argument */
405 movq $z_run_size, %r9 /* size of kernel with .bss and .brk */
406 pushq %r9
405 movq %rsi, %rdi /* real mode address */ 407 movq %rsi, %rdi /* real mode address */
406 leaq boot_heap(%rip), %rsi /* malloc area for uncompression */ 408 leaq boot_heap(%rip), %rsi /* malloc area for uncompression */
407 leaq input_data(%rip), %rdx /* input_data */ 409 leaq input_data(%rip), %rdx /* input_data */
408 movl $z_input_len, %ecx /* input_len */ 410 movl $z_input_len, %ecx /* input_len */
409 movq %rbp, %r8 /* output target address */ 411 movq %rbp, %r8 /* output target address */
410 movq $z_output_len, %r9 /* decompressed length */ 412 movq $z_output_len, %r9 /* decompressed length, end of relocs */
411 call decompress_kernel /* returns kernel location in %rax */ 413 call decompress_kernel /* returns kernel location in %rax */
414 popq %r9
412 popq %rsi 415 popq %rsi
413 416
414/* 417/*
diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index 57ab74df7eea..30dd59a9f0b4 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -358,7 +358,8 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
358 unsigned char *input_data, 358 unsigned char *input_data,
359 unsigned long input_len, 359 unsigned long input_len,
360 unsigned char *output, 360 unsigned char *output,
361 unsigned long output_len) 361 unsigned long output_len,
362 unsigned long run_size)
362{ 363{
363 real_mode = rmode; 364 real_mode = rmode;
364 365
@@ -381,8 +382,14 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
381 free_mem_ptr = heap; /* Heap */ 382 free_mem_ptr = heap; /* Heap */
382 free_mem_end_ptr = heap + BOOT_HEAP_SIZE; 383 free_mem_end_ptr = heap + BOOT_HEAP_SIZE;
383 384
384 output = choose_kernel_location(input_data, input_len, 385 /*
385 output, output_len); 386 * The memory hole needed for the kernel is the larger of either
387 * the entire decompressed kernel plus relocation table, or the
388 * entire decompressed kernel plus .bss and .brk sections.
389 */
390 output = choose_kernel_location(input_data, input_len, output,
391 output_len > run_size ? output_len
392 : run_size);
386 393
387 /* Validate memory location choices. */ 394 /* Validate memory location choices. */
388 if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1)) 395 if ((unsigned long)output & (MIN_KERNEL_ALIGN - 1))
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index b669ab65bf6c..d8222f213182 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -36,11 +36,13 @@ int main(int argc, char *argv[])
36 uint32_t olen; 36 uint32_t olen;
37 long ilen; 37 long ilen;
38 unsigned long offs; 38 unsigned long offs;
39 unsigned long run_size;
39 FILE *f = NULL; 40 FILE *f = NULL;
40 int retval = 1; 41 int retval = 1;
41 42
42 if (argc < 2) { 43 if (argc < 3) {
43 fprintf(stderr, "Usage: %s compressed_file\n", argv[0]); 44 fprintf(stderr, "Usage: %s compressed_file run_size\n",
45 argv[0]);
44 goto bail; 46 goto bail;
45 } 47 }
46 48
@@ -74,6 +76,7 @@ int main(int argc, char *argv[])
74 offs += olen >> 12; /* Add 8 bytes for each 32K block */ 76 offs += olen >> 12; /* Add 8 bytes for each 32K block */
75 offs += 64*1024 + 128; /* Add 64K + 128 bytes slack */ 77 offs += 64*1024 + 128; /* Add 64K + 128 bytes slack */
76 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */ 78 offs = (offs+4095) & ~4095; /* Round to a 4K boundary */
79 run_size = atoi(argv[2]);
77 80
78 printf(".section \".rodata..compressed\",\"a\",@progbits\n"); 81 printf(".section \".rodata..compressed\",\"a\",@progbits\n");
79 printf(".globl z_input_len\n"); 82 printf(".globl z_input_len\n");
@@ -85,6 +88,8 @@ int main(int argc, char *argv[])
85 /* z_extract_offset_negative allows simplification of head_32.S */ 88 /* z_extract_offset_negative allows simplification of head_32.S */
86 printf(".globl z_extract_offset_negative\n"); 89 printf(".globl z_extract_offset_negative\n");
87 printf("z_extract_offset_negative = -0x%lx\n", offs); 90 printf("z_extract_offset_negative = -0x%lx\n", offs);
91 printf(".globl z_run_size\n");
92 printf("z_run_size = %lu\n", run_size);
88 93
89 printf(".globl input_data, input_data_end\n"); 94 printf(".globl input_data, input_data_end\n");
90 printf("input_data:\n"); 95 printf("input_data:\n");
diff --git a/arch/x86/include/asm/page_32_types.h b/arch/x86/include/asm/page_32_types.h
index f48b17df4224..3a52ee0e726d 100644
--- a/arch/x86/include/asm/page_32_types.h
+++ b/arch/x86/include/asm/page_32_types.h
@@ -20,7 +20,6 @@
20#define THREAD_SIZE_ORDER 1 20#define THREAD_SIZE_ORDER 1
21#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) 21#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
22 22
23#define STACKFAULT_STACK 0
24#define DOUBLEFAULT_STACK 1 23#define DOUBLEFAULT_STACK 1
25#define NMI_STACK 0 24#define NMI_STACK 0
26#define DEBUG_STACK 0 25#define DEBUG_STACK 0
diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
index 678205195ae1..75450b2c7be4 100644
--- a/arch/x86/include/asm/page_64_types.h
+++ b/arch/x86/include/asm/page_64_types.h
@@ -14,12 +14,11 @@
14#define IRQ_STACK_ORDER 2 14#define IRQ_STACK_ORDER 2
15#define IRQ_STACK_SIZE (PAGE_SIZE << IRQ_STACK_ORDER) 15#define IRQ_STACK_SIZE (PAGE_SIZE << IRQ_STACK_ORDER)
16 16
17#define STACKFAULT_STACK 1 17#define DOUBLEFAULT_STACK 1
18#define DOUBLEFAULT_STACK 2 18#define NMI_STACK 2
19#define NMI_STACK 3 19#define DEBUG_STACK 3
20#define DEBUG_STACK 4 20#define MCE_STACK 4
21#define MCE_STACK 5 21#define N_EXCEPTION_STACKS 4 /* hw limit: 7 */
22#define N_EXCEPTION_STACKS 5 /* hw limit: 7 */
23 22
24#define PUD_PAGE_SIZE (_AC(1, UL) << PUD_SHIFT) 23#define PUD_PAGE_SIZE (_AC(1, UL) << PUD_SHIFT)
25#define PUD_PAGE_MASK (~(PUD_PAGE_SIZE-1)) 24#define PUD_PAGE_MASK (~(PUD_PAGE_SIZE-1))
diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index 8cd27e08e23c..8cd1cc3bc835 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -150,6 +150,7 @@ static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
150} 150}
151 151
152void cpu_disable_common(void); 152void cpu_disable_common(void);
153void cpu_die_common(unsigned int cpu);
153void native_smp_prepare_boot_cpu(void); 154void native_smp_prepare_boot_cpu(void);
154void native_smp_prepare_cpus(unsigned int max_cpus); 155void native_smp_prepare_cpus(unsigned int max_cpus);
155void native_smp_cpus_done(unsigned int max_cpus); 156void native_smp_cpus_done(unsigned int max_cpus);
diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
index 854053889d4d..547e344a6dc6 100644
--- a/arch/x86/include/asm/thread_info.h
+++ b/arch/x86/include/asm/thread_info.h
@@ -141,7 +141,7 @@ struct thread_info {
141/* Only used for 64 bit */ 141/* Only used for 64 bit */
142#define _TIF_DO_NOTIFY_MASK \ 142#define _TIF_DO_NOTIFY_MASK \
143 (_TIF_SIGPENDING | _TIF_MCE_NOTIFY | _TIF_NOTIFY_RESUME | \ 143 (_TIF_SIGPENDING | _TIF_MCE_NOTIFY | _TIF_NOTIFY_RESUME | \
144 _TIF_USER_RETURN_NOTIFY) 144 _TIF_USER_RETURN_NOTIFY | _TIF_UPROBE)
145 145
146/* flags to check in __switch_to() */ 146/* flags to check in __switch_to() */
147#define _TIF_WORK_CTXSW \ 147#define _TIF_WORK_CTXSW \
diff --git a/arch/x86/include/asm/traps.h b/arch/x86/include/asm/traps.h
index bc8352e7010a..707adc6549d8 100644
--- a/arch/x86/include/asm/traps.h
+++ b/arch/x86/include/asm/traps.h
@@ -39,6 +39,7 @@ asmlinkage void simd_coprocessor_error(void);
39 39
40#ifdef CONFIG_TRACING 40#ifdef CONFIG_TRACING
41asmlinkage void trace_page_fault(void); 41asmlinkage void trace_page_fault(void);
42#define trace_stack_segment stack_segment
42#define trace_divide_error divide_error 43#define trace_divide_error divide_error
43#define trace_bounds bounds 44#define trace_bounds bounds
44#define trace_invalid_op invalid_op 45#define trace_invalid_op invalid_op
diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index f04dbb3069b8..5caed1dd7ccf 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -21,6 +21,7 @@ const struct pci_device_id amd_nb_misc_ids[] = {
21 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F3) }, 21 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F3) },
22 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M10H_F3) }, 22 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M10H_F3) },
23 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F3) }, 23 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F3) },
24 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M60H_NB_F3) },
24 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, 25 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) },
25 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) }, 26 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) },
26 {} 27 {}
@@ -30,6 +31,7 @@ EXPORT_SYMBOL(amd_nb_misc_ids);
30static const struct pci_device_id amd_nb_link_ids[] = { 31static const struct pci_device_id amd_nb_link_ids[] = {
31 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) }, 32 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) },
32 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F4) }, 33 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F4) },
34 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M60H_NB_F4) },
33 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F4) }, 35 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F4) },
34 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F4) }, 36 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F4) },
35 {} 37 {}
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index 4b4f78c9ba19..cfa9b5b2c27a 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -146,6 +146,8 @@ EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
146 146
147static int __init x86_xsave_setup(char *s) 147static int __init x86_xsave_setup(char *s)
148{ 148{
149 if (strlen(s))
150 return 0;
149 setup_clear_cpu_cap(X86_FEATURE_XSAVE); 151 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
150 setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT); 152 setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
151 setup_clear_cpu_cap(X86_FEATURE_XSAVES); 153 setup_clear_cpu_cap(X86_FEATURE_XSAVES);
diff --git a/arch/x86/kernel/cpu/microcode/amd_early.c b/arch/x86/kernel/cpu/microcode/amd_early.c
index 7aa1acc79789..06674473b0e6 100644
--- a/arch/x86/kernel/cpu/microcode/amd_early.c
+++ b/arch/x86/kernel/cpu/microcode/amd_early.c
@@ -108,12 +108,13 @@ static size_t compute_container_size(u8 *data, u32 total_size)
108 * load_microcode_amd() to save equivalent cpu table and microcode patches in 108 * load_microcode_amd() to save equivalent cpu table and microcode patches in
109 * kernel heap memory. 109 * kernel heap memory.
110 */ 110 */
111static void apply_ucode_in_initrd(void *ucode, size_t size) 111static void apply_ucode_in_initrd(void *ucode, size_t size, bool save_patch)
112{ 112{
113 struct equiv_cpu_entry *eq; 113 struct equiv_cpu_entry *eq;
114 size_t *cont_sz; 114 size_t *cont_sz;
115 u32 *header; 115 u32 *header;
116 u8 *data, **cont; 116 u8 *data, **cont;
117 u8 (*patch)[PATCH_MAX_SIZE];
117 u16 eq_id = 0; 118 u16 eq_id = 0;
118 int offset, left; 119 int offset, left;
119 u32 rev, eax, ebx, ecx, edx; 120 u32 rev, eax, ebx, ecx, edx;
@@ -123,10 +124,12 @@ static void apply_ucode_in_initrd(void *ucode, size_t size)
123 new_rev = (u32 *)__pa_nodebug(&ucode_new_rev); 124 new_rev = (u32 *)__pa_nodebug(&ucode_new_rev);
124 cont_sz = (size_t *)__pa_nodebug(&container_size); 125 cont_sz = (size_t *)__pa_nodebug(&container_size);
125 cont = (u8 **)__pa_nodebug(&container); 126 cont = (u8 **)__pa_nodebug(&container);
127 patch = (u8 (*)[PATCH_MAX_SIZE])__pa_nodebug(&amd_ucode_patch);
126#else 128#else
127 new_rev = &ucode_new_rev; 129 new_rev = &ucode_new_rev;
128 cont_sz = &container_size; 130 cont_sz = &container_size;
129 cont = &container; 131 cont = &container;
132 patch = &amd_ucode_patch;
130#endif 133#endif
131 134
132 data = ucode; 135 data = ucode;
@@ -213,9 +216,9 @@ static void apply_ucode_in_initrd(void *ucode, size_t size)
213 rev = mc->hdr.patch_id; 216 rev = mc->hdr.patch_id;
214 *new_rev = rev; 217 *new_rev = rev;
215 218
216 /* save ucode patch */ 219 if (save_patch)
217 memcpy(amd_ucode_patch, mc, 220 memcpy(patch, mc,
218 min_t(u32, header[1], PATCH_MAX_SIZE)); 221 min_t(u32, header[1], PATCH_MAX_SIZE));
219 } 222 }
220 } 223 }
221 224
@@ -246,7 +249,7 @@ void __init load_ucode_amd_bsp(void)
246 *data = cp.data; 249 *data = cp.data;
247 *size = cp.size; 250 *size = cp.size;
248 251
249 apply_ucode_in_initrd(cp.data, cp.size); 252 apply_ucode_in_initrd(cp.data, cp.size, true);
250} 253}
251 254
252#ifdef CONFIG_X86_32 255#ifdef CONFIG_X86_32
@@ -263,7 +266,7 @@ void load_ucode_amd_ap(void)
263 size_t *usize; 266 size_t *usize;
264 void **ucode; 267 void **ucode;
265 268
266 mc = (struct microcode_amd *)__pa(amd_ucode_patch); 269 mc = (struct microcode_amd *)__pa_nodebug(amd_ucode_patch);
267 if (mc->hdr.patch_id && mc->hdr.processor_rev_id) { 270 if (mc->hdr.patch_id && mc->hdr.processor_rev_id) {
268 __apply_microcode_amd(mc); 271 __apply_microcode_amd(mc);
269 return; 272 return;
@@ -275,7 +278,7 @@ void load_ucode_amd_ap(void)
275 if (!*ucode || !*usize) 278 if (!*ucode || !*usize)
276 return; 279 return;
277 280
278 apply_ucode_in_initrd(*ucode, *usize); 281 apply_ucode_in_initrd(*ucode, *usize, false);
279} 282}
280 283
281static void __init collect_cpu_sig_on_bsp(void *arg) 284static void __init collect_cpu_sig_on_bsp(void *arg)
@@ -339,7 +342,7 @@ void load_ucode_amd_ap(void)
339 * AP has a different equivalence ID than BSP, looks like 342 * AP has a different equivalence ID than BSP, looks like
340 * mixed-steppings silicon so go through the ucode blob anew. 343 * mixed-steppings silicon so go through the ucode blob anew.
341 */ 344 */
342 apply_ucode_in_initrd(ucode_cpio.data, ucode_cpio.size); 345 apply_ucode_in_initrd(ucode_cpio.data, ucode_cpio.size, false);
343 } 346 }
344} 347}
345#endif 348#endif
@@ -347,7 +350,9 @@ void load_ucode_amd_ap(void)
347int __init save_microcode_in_initrd_amd(void) 350int __init save_microcode_in_initrd_amd(void)
348{ 351{
349 unsigned long cont; 352 unsigned long cont;
353 int retval = 0;
350 enum ucode_state ret; 354 enum ucode_state ret;
355 u8 *cont_va;
351 u32 eax; 356 u32 eax;
352 357
353 if (!container) 358 if (!container)
@@ -355,13 +360,15 @@ int __init save_microcode_in_initrd_amd(void)
355 360
356#ifdef CONFIG_X86_32 361#ifdef CONFIG_X86_32
357 get_bsp_sig(); 362 get_bsp_sig();
358 cont = (unsigned long)container; 363 cont = (unsigned long)container;
364 cont_va = __va(container);
359#else 365#else
360 /* 366 /*
361 * We need the physical address of the container for both bitness since 367 * We need the physical address of the container for both bitness since
362 * boot_params.hdr.ramdisk_image is a physical address. 368 * boot_params.hdr.ramdisk_image is a physical address.
363 */ 369 */
364 cont = __pa(container); 370 cont = __pa(container);
371 cont_va = container;
365#endif 372#endif
366 373
367 /* 374 /*
@@ -372,6 +379,8 @@ int __init save_microcode_in_initrd_amd(void)
372 if (relocated_ramdisk) 379 if (relocated_ramdisk)
373 container = (u8 *)(__va(relocated_ramdisk) + 380 container = (u8 *)(__va(relocated_ramdisk) +
374 (cont - boot_params.hdr.ramdisk_image)); 381 (cont - boot_params.hdr.ramdisk_image));
382 else
383 container = cont_va;
375 384
376 if (ucode_new_rev) 385 if (ucode_new_rev)
377 pr_info("microcode: updated early to new patch_level=0x%08x\n", 386 pr_info("microcode: updated early to new patch_level=0x%08x\n",
@@ -382,7 +391,7 @@ int __init save_microcode_in_initrd_amd(void)
382 391
383 ret = load_microcode_amd(eax, container, container_size); 392 ret = load_microcode_amd(eax, container, container_size);
384 if (ret != UCODE_OK) 393 if (ret != UCODE_OK)
385 return -EINVAL; 394 retval = -EINVAL;
386 395
387 /* 396 /*
388 * This will be freed any msec now, stash patches for the current 397 * This will be freed any msec now, stash patches for the current
@@ -391,5 +400,5 @@ int __init save_microcode_in_initrd_amd(void)
391 container = NULL; 400 container = NULL;
392 container_size = 0; 401 container_size = 0;
393 402
394 return 0; 403 return retval;
395} 404}
diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index dd9d6190b08d..08fe6e8a726e 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -465,6 +465,16 @@ static void mc_bp_resume(void)
465 465
466 if (uci->valid && uci->mc) 466 if (uci->valid && uci->mc)
467 microcode_ops->apply_microcode(cpu); 467 microcode_ops->apply_microcode(cpu);
468#ifdef CONFIG_X86_64
469 else if (!uci->mc)
470 /*
471 * We might resume and not have applied late microcode but still
472 * have a newer patch stashed from the early loader. We don't
473 * have it in uci->mc so we have to load it the same way we're
474 * applying patches early on the APs.
475 */
476 load_ucode_ap();
477#endif
468} 478}
469 479
470static struct syscore_ops mc_syscore_ops = { 480static struct syscore_ops mc_syscore_ops = {
diff --git a/arch/x86/kernel/cpu/microcode/core_early.c b/arch/x86/kernel/cpu/microcode/core_early.c
index 5f28a64e71ea..2c017f242a78 100644
--- a/arch/x86/kernel/cpu/microcode/core_early.c
+++ b/arch/x86/kernel/cpu/microcode/core_early.c
@@ -124,7 +124,7 @@ void __init load_ucode_bsp(void)
124static bool check_loader_disabled_ap(void) 124static bool check_loader_disabled_ap(void)
125{ 125{
126#ifdef CONFIG_X86_32 126#ifdef CONFIG_X86_32
127 return __pa_nodebug(dis_ucode_ldr); 127 return *((bool *)__pa_nodebug(&dis_ucode_ldr));
128#else 128#else
129 return dis_ucode_ldr; 129 return dis_ucode_ldr;
130#endif 130#endif
diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c b/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c
index adf138eac85c..f9ed429d6e4f 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore_snbep.c
@@ -486,14 +486,17 @@ static struct attribute_group snbep_uncore_qpi_format_group = {
486 .attrs = snbep_uncore_qpi_formats_attr, 486 .attrs = snbep_uncore_qpi_formats_attr,
487}; 487};
488 488
489#define SNBEP_UNCORE_MSR_OPS_COMMON_INIT() \ 489#define __SNBEP_UNCORE_MSR_OPS_COMMON_INIT() \
490 .init_box = snbep_uncore_msr_init_box, \
491 .disable_box = snbep_uncore_msr_disable_box, \ 490 .disable_box = snbep_uncore_msr_disable_box, \
492 .enable_box = snbep_uncore_msr_enable_box, \ 491 .enable_box = snbep_uncore_msr_enable_box, \
493 .disable_event = snbep_uncore_msr_disable_event, \ 492 .disable_event = snbep_uncore_msr_disable_event, \
494 .enable_event = snbep_uncore_msr_enable_event, \ 493 .enable_event = snbep_uncore_msr_enable_event, \
495 .read_counter = uncore_msr_read_counter 494 .read_counter = uncore_msr_read_counter
496 495
496#define SNBEP_UNCORE_MSR_OPS_COMMON_INIT() \
497 __SNBEP_UNCORE_MSR_OPS_COMMON_INIT(), \
498 .init_box = snbep_uncore_msr_init_box \
499
497static struct intel_uncore_ops snbep_uncore_msr_ops = { 500static struct intel_uncore_ops snbep_uncore_msr_ops = {
498 SNBEP_UNCORE_MSR_OPS_COMMON_INIT(), 501 SNBEP_UNCORE_MSR_OPS_COMMON_INIT(),
499}; 502};
@@ -1919,6 +1922,30 @@ static struct intel_uncore_type hswep_uncore_cbox = {
1919 .format_group = &hswep_uncore_cbox_format_group, 1922 .format_group = &hswep_uncore_cbox_format_group,
1920}; 1923};
1921 1924
1925/*
1926 * Write SBOX Initialization register bit by bit to avoid spurious #GPs
1927 */
1928static void hswep_uncore_sbox_msr_init_box(struct intel_uncore_box *box)
1929{
1930 unsigned msr = uncore_msr_box_ctl(box);
1931
1932 if (msr) {
1933 u64 init = SNBEP_PMON_BOX_CTL_INT;
1934 u64 flags = 0;
1935 int i;
1936
1937 for_each_set_bit(i, (unsigned long *)&init, 64) {
1938 flags |= (1ULL << i);
1939 wrmsrl(msr, flags);
1940 }
1941 }
1942}
1943
1944static struct intel_uncore_ops hswep_uncore_sbox_msr_ops = {
1945 __SNBEP_UNCORE_MSR_OPS_COMMON_INIT(),
1946 .init_box = hswep_uncore_sbox_msr_init_box
1947};
1948
1922static struct attribute *hswep_uncore_sbox_formats_attr[] = { 1949static struct attribute *hswep_uncore_sbox_formats_attr[] = {
1923 &format_attr_event.attr, 1950 &format_attr_event.attr,
1924 &format_attr_umask.attr, 1951 &format_attr_umask.attr,
@@ -1944,7 +1971,7 @@ static struct intel_uncore_type hswep_uncore_sbox = {
1944 .event_mask = HSWEP_S_MSR_PMON_RAW_EVENT_MASK, 1971 .event_mask = HSWEP_S_MSR_PMON_RAW_EVENT_MASK,
1945 .box_ctl = HSWEP_S0_MSR_PMON_BOX_CTL, 1972 .box_ctl = HSWEP_S0_MSR_PMON_BOX_CTL,
1946 .msr_offset = HSWEP_SBOX_MSR_OFFSET, 1973 .msr_offset = HSWEP_SBOX_MSR_OFFSET,
1947 .ops = &snbep_uncore_msr_ops, 1974 .ops = &hswep_uncore_sbox_msr_ops,
1948 .format_group = &hswep_uncore_sbox_format_group, 1975 .format_group = &hswep_uncore_sbox_format_group,
1949}; 1976};
1950 1977
@@ -2025,13 +2052,27 @@ static struct intel_uncore_type hswep_uncore_imc = {
2025 SNBEP_UNCORE_PCI_COMMON_INIT(), 2052 SNBEP_UNCORE_PCI_COMMON_INIT(),
2026}; 2053};
2027 2054
2055static unsigned hswep_uncore_irp_ctrs[] = {0xa0, 0xa8, 0xb0, 0xb8};
2056
2057static u64 hswep_uncore_irp_read_counter(struct intel_uncore_box *box, struct perf_event *event)
2058{
2059 struct pci_dev *pdev = box->pci_dev;
2060 struct hw_perf_event *hwc = &event->hw;
2061 u64 count = 0;
2062
2063 pci_read_config_dword(pdev, hswep_uncore_irp_ctrs[hwc->idx], (u32 *)&count);
2064 pci_read_config_dword(pdev, hswep_uncore_irp_ctrs[hwc->idx] + 4, (u32 *)&count + 1);
2065
2066 return count;
2067}
2068
2028static struct intel_uncore_ops hswep_uncore_irp_ops = { 2069static struct intel_uncore_ops hswep_uncore_irp_ops = {
2029 .init_box = snbep_uncore_pci_init_box, 2070 .init_box = snbep_uncore_pci_init_box,
2030 .disable_box = snbep_uncore_pci_disable_box, 2071 .disable_box = snbep_uncore_pci_disable_box,
2031 .enable_box = snbep_uncore_pci_enable_box, 2072 .enable_box = snbep_uncore_pci_enable_box,
2032 .disable_event = ivbep_uncore_irp_disable_event, 2073 .disable_event = ivbep_uncore_irp_disable_event,
2033 .enable_event = ivbep_uncore_irp_enable_event, 2074 .enable_event = ivbep_uncore_irp_enable_event,
2034 .read_counter = ivbep_uncore_irp_read_counter, 2075 .read_counter = hswep_uncore_irp_read_counter,
2035}; 2076};
2036 2077
2037static struct intel_uncore_type hswep_uncore_irp = { 2078static struct intel_uncore_type hswep_uncore_irp = {
diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
index 1abcb50b48ae..ff86f19b5758 100644
--- a/arch/x86/kernel/dumpstack_64.c
+++ b/arch/x86/kernel/dumpstack_64.c
@@ -24,7 +24,6 @@ static char x86_stack_ids[][8] = {
24 [ DEBUG_STACK-1 ] = "#DB", 24 [ DEBUG_STACK-1 ] = "#DB",
25 [ NMI_STACK-1 ] = "NMI", 25 [ NMI_STACK-1 ] = "NMI",
26 [ DOUBLEFAULT_STACK-1 ] = "#DF", 26 [ DOUBLEFAULT_STACK-1 ] = "#DF",
27 [ STACKFAULT_STACK-1 ] = "#SS",
28 [ MCE_STACK-1 ] = "#MC", 27 [ MCE_STACK-1 ] = "#MC",
29#if DEBUG_STKSZ > EXCEPTION_STKSZ 28#if DEBUG_STKSZ > EXCEPTION_STKSZ
30 [ N_EXCEPTION_STACKS ... 29 [ N_EXCEPTION_STACKS ...
diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
index df088bb03fb3..c0226ab54106 100644
--- a/arch/x86/kernel/entry_64.S
+++ b/arch/x86/kernel/entry_64.S
@@ -828,9 +828,15 @@ ENTRY(native_iret)
828 jnz native_irq_return_ldt 828 jnz native_irq_return_ldt
829#endif 829#endif
830 830
831.global native_irq_return_iret
831native_irq_return_iret: 832native_irq_return_iret:
833 /*
834 * This may fault. Non-paranoid faults on return to userspace are
835 * handled by fixup_bad_iret. These include #SS, #GP, and #NP.
836 * Double-faults due to espfix64 are handled in do_double_fault.
837 * Other faults here are fatal.
838 */
832 iretq 839 iretq
833 _ASM_EXTABLE(native_irq_return_iret, bad_iret)
834 840
835#ifdef CONFIG_X86_ESPFIX64 841#ifdef CONFIG_X86_ESPFIX64
836native_irq_return_ldt: 842native_irq_return_ldt:
@@ -858,25 +864,6 @@ native_irq_return_ldt:
858 jmp native_irq_return_iret 864 jmp native_irq_return_iret
859#endif 865#endif
860 866
861 .section .fixup,"ax"
862bad_iret:
863 /*
864 * The iret traps when the %cs or %ss being restored is bogus.
865 * We've lost the original trap vector and error code.
866 * #GPF is the most likely one to get for an invalid selector.
867 * So pretend we completed the iret and took the #GPF in user mode.
868 *
869 * We are now running with the kernel GS after exception recovery.
870 * But error_entry expects us to have user GS to match the user %cs,
871 * so swap back.
872 */
873 pushq $0
874
875 SWAPGS
876 jmp general_protection
877
878 .previous
879
880 /* edi: workmask, edx: work */ 867 /* edi: workmask, edx: work */
881retint_careful: 868retint_careful:
882 CFI_RESTORE_STATE 869 CFI_RESTORE_STATE
@@ -922,37 +909,6 @@ ENTRY(retint_kernel)
922 CFI_ENDPROC 909 CFI_ENDPROC
923END(common_interrupt) 910END(common_interrupt)
924 911
925 /*
926 * If IRET takes a fault on the espfix stack, then we
927 * end up promoting it to a doublefault. In that case,
928 * modify the stack to make it look like we just entered
929 * the #GP handler from user space, similar to bad_iret.
930 */
931#ifdef CONFIG_X86_ESPFIX64
932 ALIGN
933__do_double_fault:
934 XCPT_FRAME 1 RDI+8
935 movq RSP(%rdi),%rax /* Trap on the espfix stack? */
936 sarq $PGDIR_SHIFT,%rax
937 cmpl $ESPFIX_PGD_ENTRY,%eax
938 jne do_double_fault /* No, just deliver the fault */
939 cmpl $__KERNEL_CS,CS(%rdi)
940 jne do_double_fault
941 movq RIP(%rdi),%rax
942 cmpq $native_irq_return_iret,%rax
943 jne do_double_fault /* This shouldn't happen... */
944 movq PER_CPU_VAR(kernel_stack),%rax
945 subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
946 movq %rax,RSP(%rdi)
947 movq $0,(%rax) /* Missing (lost) #GP error code */
948 movq $general_protection,RIP(%rdi)
949 retq
950 CFI_ENDPROC
951END(__do_double_fault)
952#else
953# define __do_double_fault do_double_fault
954#endif
955
956/* 912/*
957 * APIC interrupts. 913 * APIC interrupts.
958 */ 914 */
@@ -1124,7 +1080,7 @@ idtentry overflow do_overflow has_error_code=0
1124idtentry bounds do_bounds has_error_code=0 1080idtentry bounds do_bounds has_error_code=0
1125idtentry invalid_op do_invalid_op has_error_code=0 1081idtentry invalid_op do_invalid_op has_error_code=0
1126idtentry device_not_available do_device_not_available has_error_code=0 1082idtentry device_not_available do_device_not_available has_error_code=0
1127idtentry double_fault __do_double_fault has_error_code=1 paranoid=1 1083idtentry double_fault do_double_fault has_error_code=1 paranoid=1
1128idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0 1084idtentry coprocessor_segment_overrun do_coprocessor_segment_overrun has_error_code=0
1129idtentry invalid_TSS do_invalid_TSS has_error_code=1 1085idtentry invalid_TSS do_invalid_TSS has_error_code=1
1130idtentry segment_not_present do_segment_not_present has_error_code=1 1086idtentry segment_not_present do_segment_not_present has_error_code=1
@@ -1289,7 +1245,7 @@ apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
1289 1245
1290idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK 1246idtentry debug do_debug has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
1291idtentry int3 do_int3 has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK 1247idtentry int3 do_int3 has_error_code=0 paranoid=1 shift_ist=DEBUG_STACK
1292idtentry stack_segment do_stack_segment has_error_code=1 paranoid=1 1248idtentry stack_segment do_stack_segment has_error_code=1
1293#ifdef CONFIG_XEN 1249#ifdef CONFIG_XEN
1294idtentry xen_debug do_debug has_error_code=0 1250idtentry xen_debug do_debug has_error_code=0
1295idtentry xen_int3 do_int3 has_error_code=0 1251idtentry xen_int3 do_int3 has_error_code=0
@@ -1399,17 +1355,16 @@ error_sti:
1399 1355
1400/* 1356/*
1401 * There are two places in the kernel that can potentially fault with 1357 * There are two places in the kernel that can potentially fault with
1402 * usergs. Handle them here. The exception handlers after iret run with 1358 * usergs. Handle them here. B stepping K8s sometimes report a
1403 * kernel gs again, so don't set the user space flag. B stepping K8s 1359 * truncated RIP for IRET exceptions returning to compat mode. Check
1404 * sometimes report an truncated RIP for IRET exceptions returning to 1360 * for these here too.
1405 * compat mode. Check for these here too.
1406 */ 1361 */
1407error_kernelspace: 1362error_kernelspace:
1408 CFI_REL_OFFSET rcx, RCX+8 1363 CFI_REL_OFFSET rcx, RCX+8
1409 incl %ebx 1364 incl %ebx
1410 leaq native_irq_return_iret(%rip),%rcx 1365 leaq native_irq_return_iret(%rip),%rcx
1411 cmpq %rcx,RIP+8(%rsp) 1366 cmpq %rcx,RIP+8(%rsp)
1412 je error_swapgs 1367 je error_bad_iret
1413 movl %ecx,%eax /* zero extend */ 1368 movl %ecx,%eax /* zero extend */
1414 cmpq %rax,RIP+8(%rsp) 1369 cmpq %rax,RIP+8(%rsp)
1415 je bstep_iret 1370 je bstep_iret
@@ -1420,7 +1375,15 @@ error_kernelspace:
1420bstep_iret: 1375bstep_iret:
1421 /* Fix truncated RIP */ 1376 /* Fix truncated RIP */
1422 movq %rcx,RIP+8(%rsp) 1377 movq %rcx,RIP+8(%rsp)
1423 jmp error_swapgs 1378 /* fall through */
1379
1380error_bad_iret:
1381 SWAPGS
1382 mov %rsp,%rdi
1383 call fixup_bad_iret
1384 mov %rax,%rsp
1385 decl %ebx /* Return to usergs */
1386 jmp error_sti
1424 CFI_ENDPROC 1387 CFI_ENDPROC
1425END(error_entry) 1388END(error_entry)
1426 1389
diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
index 749b0e423419..e510618b2e91 100644
--- a/arch/x86/kernel/ptrace.c
+++ b/arch/x86/kernel/ptrace.c
@@ -1484,7 +1484,7 @@ unsigned long syscall_trace_enter_phase1(struct pt_regs *regs, u32 arch)
1484 */ 1484 */
1485 if (work & _TIF_NOHZ) { 1485 if (work & _TIF_NOHZ) {
1486 user_exit(); 1486 user_exit();
1487 work &= ~TIF_NOHZ; 1487 work &= ~_TIF_NOHZ;
1488 } 1488 }
1489 1489
1490#ifdef CONFIG_SECCOMP 1490#ifdef CONFIG_SECCOMP
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 4d2128ac70bd..668d8f2a8781 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -1303,10 +1303,14 @@ static void __ref remove_cpu_from_maps(int cpu)
1303 numa_remove_cpu(cpu); 1303 numa_remove_cpu(cpu);
1304} 1304}
1305 1305
1306static DEFINE_PER_CPU(struct completion, die_complete);
1307
1306void cpu_disable_common(void) 1308void cpu_disable_common(void)
1307{ 1309{
1308 int cpu = smp_processor_id(); 1310 int cpu = smp_processor_id();
1309 1311
1312 init_completion(&per_cpu(die_complete, smp_processor_id()));
1313
1310 remove_siblinginfo(cpu); 1314 remove_siblinginfo(cpu);
1311 1315
1312 /* It's now safe to remove this processor from the online map */ 1316 /* It's now safe to remove this processor from the online map */
@@ -1316,8 +1320,6 @@ void cpu_disable_common(void)
1316 fixup_irqs(); 1320 fixup_irqs();
1317} 1321}
1318 1322
1319static DEFINE_PER_CPU(struct completion, die_complete);
1320
1321int native_cpu_disable(void) 1323int native_cpu_disable(void)
1322{ 1324{
1323 int ret; 1325 int ret;
@@ -1327,16 +1329,21 @@ int native_cpu_disable(void)
1327 return ret; 1329 return ret;
1328 1330
1329 clear_local_APIC(); 1331 clear_local_APIC();
1330 init_completion(&per_cpu(die_complete, smp_processor_id()));
1331 cpu_disable_common(); 1332 cpu_disable_common();
1332 1333
1333 return 0; 1334 return 0;
1334} 1335}
1335 1336
1337void cpu_die_common(unsigned int cpu)
1338{
1339 wait_for_completion_timeout(&per_cpu(die_complete, cpu), HZ);
1340}
1341
1336void native_cpu_die(unsigned int cpu) 1342void native_cpu_die(unsigned int cpu)
1337{ 1343{
1338 /* We don't do anything here: idle task is faking death itself. */ 1344 /* We don't do anything here: idle task is faking death itself. */
1339 wait_for_completion_timeout(&per_cpu(die_complete, cpu), HZ); 1345
1346 cpu_die_common(cpu);
1340 1347
1341 /* They ack this in play_dead() by setting CPU_DEAD */ 1348 /* They ack this in play_dead() by setting CPU_DEAD */
1342 if (per_cpu(cpu_state, cpu) == CPU_DEAD) { 1349 if (per_cpu(cpu_state, cpu) == CPU_DEAD) {
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 0d0e922fafc1..de801f22128a 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -233,32 +233,40 @@ DO_ERROR(X86_TRAP_UD, SIGILL, "invalid opcode", invalid_op)
233DO_ERROR(X86_TRAP_OLD_MF, SIGFPE, "coprocessor segment overrun",coprocessor_segment_overrun) 233DO_ERROR(X86_TRAP_OLD_MF, SIGFPE, "coprocessor segment overrun",coprocessor_segment_overrun)
234DO_ERROR(X86_TRAP_TS, SIGSEGV, "invalid TSS", invalid_TSS) 234DO_ERROR(X86_TRAP_TS, SIGSEGV, "invalid TSS", invalid_TSS)
235DO_ERROR(X86_TRAP_NP, SIGBUS, "segment not present", segment_not_present) 235DO_ERROR(X86_TRAP_NP, SIGBUS, "segment not present", segment_not_present)
236#ifdef CONFIG_X86_32
237DO_ERROR(X86_TRAP_SS, SIGBUS, "stack segment", stack_segment) 236DO_ERROR(X86_TRAP_SS, SIGBUS, "stack segment", stack_segment)
238#endif
239DO_ERROR(X86_TRAP_AC, SIGBUS, "alignment check", alignment_check) 237DO_ERROR(X86_TRAP_AC, SIGBUS, "alignment check", alignment_check)
240 238
241#ifdef CONFIG_X86_64 239#ifdef CONFIG_X86_64
242/* Runs on IST stack */ 240/* Runs on IST stack */
243dotraplinkage void do_stack_segment(struct pt_regs *regs, long error_code)
244{
245 enum ctx_state prev_state;
246
247 prev_state = exception_enter();
248 if (notify_die(DIE_TRAP, "stack segment", regs, error_code,
249 X86_TRAP_SS, SIGBUS) != NOTIFY_STOP) {
250 preempt_conditional_sti(regs);
251 do_trap(X86_TRAP_SS, SIGBUS, "stack segment", regs, error_code, NULL);
252 preempt_conditional_cli(regs);
253 }
254 exception_exit(prev_state);
255}
256
257dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code) 241dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
258{ 242{
259 static const char str[] = "double fault"; 243 static const char str[] = "double fault";
260 struct task_struct *tsk = current; 244 struct task_struct *tsk = current;
261 245
246#ifdef CONFIG_X86_ESPFIX64
247 extern unsigned char native_irq_return_iret[];
248
249 /*
250 * If IRET takes a non-IST fault on the espfix64 stack, then we
251 * end up promoting it to a doublefault. In that case, modify
252 * the stack to make it look like we just entered the #GP
253 * handler from user space, similar to bad_iret.
254 */
255 if (((long)regs->sp >> PGDIR_SHIFT) == ESPFIX_PGD_ENTRY &&
256 regs->cs == __KERNEL_CS &&
257 regs->ip == (unsigned long)native_irq_return_iret)
258 {
259 struct pt_regs *normal_regs = task_pt_regs(current);
260
261 /* Fake a #GP(0) from userspace. */
262 memmove(&normal_regs->ip, (void *)regs->sp, 5*8);
263 normal_regs->orig_ax = 0; /* Missing (lost) #GP error code */
264 regs->ip = (unsigned long)general_protection;
265 regs->sp = (unsigned long)&normal_regs->orig_ax;
266 return;
267 }
268#endif
269
262 exception_enter(); 270 exception_enter();
263 /* Return not checked because double check cannot be ignored */ 271 /* Return not checked because double check cannot be ignored */
264 notify_die(DIE_TRAP, str, regs, error_code, X86_TRAP_DF, SIGSEGV); 272 notify_die(DIE_TRAP, str, regs, error_code, X86_TRAP_DF, SIGSEGV);
@@ -399,6 +407,35 @@ asmlinkage __visible struct pt_regs *sync_regs(struct pt_regs *eregs)
399 return regs; 407 return regs;
400} 408}
401NOKPROBE_SYMBOL(sync_regs); 409NOKPROBE_SYMBOL(sync_regs);
410
411struct bad_iret_stack {
412 void *error_entry_ret;
413 struct pt_regs regs;
414};
415
416asmlinkage __visible
417struct bad_iret_stack *fixup_bad_iret(struct bad_iret_stack *s)
418{
419 /*
420 * This is called from entry_64.S early in handling a fault
421 * caused by a bad iret to user mode. To handle the fault
422 * correctly, we want move our stack frame to task_pt_regs
423 * and we want to pretend that the exception came from the
424 * iret target.
425 */
426 struct bad_iret_stack *new_stack =
427 container_of(task_pt_regs(current),
428 struct bad_iret_stack, regs);
429
430 /* Copy the IRET target to the new stack. */
431 memmove(&new_stack->regs.ip, (void *)s->regs.sp, 5*8);
432
433 /* Copy the remainder of the stack from the current stack. */
434 memmove(new_stack, s, offsetof(struct bad_iret_stack, regs.ip));
435
436 BUG_ON(!user_mode_vm(&new_stack->regs));
437 return new_stack;
438}
402#endif 439#endif
403 440
404/* 441/*
@@ -778,7 +815,7 @@ void __init trap_init(void)
778 set_intr_gate(X86_TRAP_OLD_MF, coprocessor_segment_overrun); 815 set_intr_gate(X86_TRAP_OLD_MF, coprocessor_segment_overrun);
779 set_intr_gate(X86_TRAP_TS, invalid_TSS); 816 set_intr_gate(X86_TRAP_TS, invalid_TSS);
780 set_intr_gate(X86_TRAP_NP, segment_not_present); 817 set_intr_gate(X86_TRAP_NP, segment_not_present);
781 set_intr_gate_ist(X86_TRAP_SS, &stack_segment, STACKFAULT_STACK); 818 set_intr_gate(X86_TRAP_SS, stack_segment);
782 set_intr_gate(X86_TRAP_GP, general_protection); 819 set_intr_gate(X86_TRAP_GP, general_protection);
783 set_intr_gate(X86_TRAP_SPURIOUS, spurious_interrupt_bug); 820 set_intr_gate(X86_TRAP_SPURIOUS, spurious_interrupt_bug);
784 set_intr_gate(X86_TRAP_MF, coprocessor_error); 821 set_intr_gate(X86_TRAP_MF, coprocessor_error);
diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
index 5edf088ca51e..9f8a2faf5040 100644
--- a/arch/x86/kvm/emulate.c
+++ b/arch/x86/kvm/emulate.c
@@ -4287,6 +4287,7 @@ static int decode_operand(struct x86_emulate_ctxt *ctxt, struct operand *op,
4287 fetch_register_operand(op); 4287 fetch_register_operand(op);
4288 break; 4288 break;
4289 case OpCL: 4289 case OpCL:
4290 op->type = OP_IMM;
4290 op->bytes = 1; 4291 op->bytes = 1;
4291 op->val = reg_read(ctxt, VCPU_REGS_RCX) & 0xff; 4292 op->val = reg_read(ctxt, VCPU_REGS_RCX) & 0xff;
4292 break; 4293 break;
@@ -4294,6 +4295,7 @@ static int decode_operand(struct x86_emulate_ctxt *ctxt, struct operand *op,
4294 rc = decode_imm(ctxt, op, 1, true); 4295 rc = decode_imm(ctxt, op, 1, true);
4295 break; 4296 break;
4296 case OpOne: 4297 case OpOne:
4298 op->type = OP_IMM;
4297 op->bytes = 1; 4299 op->bytes = 1;
4298 op->val = 1; 4300 op->val = 1;
4299 break; 4301 break;
@@ -4352,21 +4354,27 @@ static int decode_operand(struct x86_emulate_ctxt *ctxt, struct operand *op,
4352 ctxt->memop.bytes = ctxt->op_bytes + 2; 4354 ctxt->memop.bytes = ctxt->op_bytes + 2;
4353 goto mem_common; 4355 goto mem_common;
4354 case OpES: 4356 case OpES:
4357 op->type = OP_IMM;
4355 op->val = VCPU_SREG_ES; 4358 op->val = VCPU_SREG_ES;
4356 break; 4359 break;
4357 case OpCS: 4360 case OpCS:
4361 op->type = OP_IMM;
4358 op->val = VCPU_SREG_CS; 4362 op->val = VCPU_SREG_CS;
4359 break; 4363 break;
4360 case OpSS: 4364 case OpSS:
4365 op->type = OP_IMM;
4361 op->val = VCPU_SREG_SS; 4366 op->val = VCPU_SREG_SS;
4362 break; 4367 break;
4363 case OpDS: 4368 case OpDS:
4369 op->type = OP_IMM;
4364 op->val = VCPU_SREG_DS; 4370 op->val = VCPU_SREG_DS;
4365 break; 4371 break;
4366 case OpFS: 4372 case OpFS:
4373 op->type = OP_IMM;
4367 op->val = VCPU_SREG_FS; 4374 op->val = VCPU_SREG_FS;
4368 break; 4375 break;
4369 case OpGS: 4376 case OpGS:
4377 op->type = OP_IMM;
4370 op->val = VCPU_SREG_GS; 4378 op->val = VCPU_SREG_GS;
4371 break; 4379 break;
4372 case OpImplicit: 4380 case OpImplicit:
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index ac1c4de3a484..978f402006ee 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -630,7 +630,7 @@ static int mmu_spte_clear_track_bits(u64 *sptep)
630 * kvm mmu, before reclaiming the page, we should 630 * kvm mmu, before reclaiming the page, we should
631 * unmap it from mmu first. 631 * unmap it from mmu first.
632 */ 632 */
633 WARN_ON(!kvm_is_mmio_pfn(pfn) && !page_count(pfn_to_page(pfn))); 633 WARN_ON(!kvm_is_reserved_pfn(pfn) && !page_count(pfn_to_page(pfn)));
634 634
635 if (!shadow_accessed_mask || old_spte & shadow_accessed_mask) 635 if (!shadow_accessed_mask || old_spte & shadow_accessed_mask)
636 kvm_set_pfn_accessed(pfn); 636 kvm_set_pfn_accessed(pfn);
@@ -2461,7 +2461,7 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
2461 spte |= PT_PAGE_SIZE_MASK; 2461 spte |= PT_PAGE_SIZE_MASK;
2462 if (tdp_enabled) 2462 if (tdp_enabled)
2463 spte |= kvm_x86_ops->get_mt_mask(vcpu, gfn, 2463 spte |= kvm_x86_ops->get_mt_mask(vcpu, gfn,
2464 kvm_is_mmio_pfn(pfn)); 2464 kvm_is_reserved_pfn(pfn));
2465 2465
2466 if (host_writable) 2466 if (host_writable)
2467 spte |= SPTE_HOST_WRITEABLE; 2467 spte |= SPTE_HOST_WRITEABLE;
@@ -2737,7 +2737,7 @@ static void transparent_hugepage_adjust(struct kvm_vcpu *vcpu,
2737 * PT_PAGE_TABLE_LEVEL and there would be no adjustment done 2737 * PT_PAGE_TABLE_LEVEL and there would be no adjustment done
2738 * here. 2738 * here.
2739 */ 2739 */
2740 if (!is_error_noslot_pfn(pfn) && !kvm_is_mmio_pfn(pfn) && 2740 if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn) &&
2741 level == PT_PAGE_TABLE_LEVEL && 2741 level == PT_PAGE_TABLE_LEVEL &&
2742 PageTransCompound(pfn_to_page(pfn)) && 2742 PageTransCompound(pfn_to_page(pfn)) &&
2743 !has_wrprotected_page(vcpu->kvm, gfn, PT_DIRECTORY_LEVEL)) { 2743 !has_wrprotected_page(vcpu->kvm, gfn, PT_DIRECTORY_LEVEL)) {
diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
index 7609e0e421ec..1318f75d56e4 100644
--- a/arch/x86/lib/csum-wrappers_64.c
+++ b/arch/x86/lib/csum-wrappers_64.c
@@ -41,9 +41,8 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
41 while (((unsigned long)src & 6) && len >= 2) { 41 while (((unsigned long)src & 6) && len >= 2) {
42 __u16 val16; 42 __u16 val16;
43 43
44 *errp = __get_user(val16, (const __u16 __user *)src); 44 if (__get_user(val16, (const __u16 __user *)src))
45 if (*errp) 45 goto out_err;
46 return isum;
47 46
48 *(__u16 *)dst = val16; 47 *(__u16 *)dst = val16;
49 isum = (__force __wsum)add32_with_carry( 48 isum = (__force __wsum)add32_with_carry(
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 4cb8763868fc..4e5dfec750fc 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -1123,7 +1123,7 @@ void mark_rodata_ro(void)
1123 unsigned long end = (unsigned long) &__end_rodata_hpage_align; 1123 unsigned long end = (unsigned long) &__end_rodata_hpage_align;
1124 unsigned long text_end = PFN_ALIGN(&__stop___ex_table); 1124 unsigned long text_end = PFN_ALIGN(&__stop___ex_table);
1125 unsigned long rodata_end = PFN_ALIGN(&__end_rodata); 1125 unsigned long rodata_end = PFN_ALIGN(&__end_rodata);
1126 unsigned long all_end = PFN_ALIGN(&_end); 1126 unsigned long all_end;
1127 1127
1128 printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n", 1128 printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
1129 (end - start) >> 10); 1129 (end - start) >> 10);
@@ -1134,7 +1134,16 @@ void mark_rodata_ro(void)
1134 /* 1134 /*
1135 * The rodata/data/bss/brk section (but not the kernel text!) 1135 * The rodata/data/bss/brk section (but not the kernel text!)
1136 * should also be not-executable. 1136 * should also be not-executable.
1137 *
1138 * We align all_end to PMD_SIZE because the existing mapping
1139 * is a full PMD. If we would align _brk_end to PAGE_SIZE we
1140 * split the PMD and the reminder between _brk_end and the end
1141 * of the PMD will remain mapped executable.
1142 *
1143 * Any PMD which was setup after the one which covers _brk_end
1144 * has been zapped already via cleanup_highmem().
1137 */ 1145 */
1146 all_end = roundup((unsigned long)_brk_end, PMD_SIZE);
1138 set_memory_nx(rodata_start, (all_end - rodata_start) >> PAGE_SHIFT); 1147 set_memory_nx(rodata_start, (all_end - rodata_start) >> PAGE_SHIFT);
1139 1148
1140 rodata_test(); 1149 rodata_test();
diff --git a/arch/x86/tools/calc_run_size.pl b/arch/x86/tools/calc_run_size.pl
new file mode 100644
index 000000000000..23210baade2d
--- /dev/null
+++ b/arch/x86/tools/calc_run_size.pl
@@ -0,0 +1,39 @@
1#!/usr/bin/perl
2#
3# Calculate the amount of space needed to run the kernel, including room for
4# the .bss and .brk sections.
5#
6# Usage:
7# objdump -h a.out | perl calc_run_size.pl
8use strict;
9
10my $mem_size = 0;
11my $file_offset = 0;
12
13my $sections=" *[0-9]+ \.(?:bss|brk) +";
14while (<>) {
15 if (/^$sections([0-9a-f]+) +(?:[0-9a-f]+ +){2}([0-9a-f]+)/) {
16 my $size = hex($1);
17 my $offset = hex($2);
18 $mem_size += $size;
19 if ($file_offset == 0) {
20 $file_offset = $offset;
21 } elsif ($file_offset != $offset) {
22 # BFD linker shows the same file offset in ELF.
23 # Gold linker shows them as consecutive.
24 next if ($file_offset + $mem_size == $offset + $size);
25
26 printf STDERR "file_offset: 0x%lx\n", $file_offset;
27 printf STDERR "mem_size: 0x%lx\n", $mem_size;
28 printf STDERR "offset: 0x%lx\n", $offset;
29 printf STDERR "size: 0x%lx\n", $size;
30
31 die ".bss and .brk are non-contiguous\n";
32 }
33 }
34}
35
36if ($file_offset == 0) {
37 die "Never found .bss or .brk file offset\n";
38}
39printf("%d\n", $mem_size + $file_offset);
diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
index 8650cdb53209..4c071aeb8417 100644
--- a/arch/x86/xen/smp.c
+++ b/arch/x86/xen/smp.c
@@ -510,6 +510,9 @@ static void xen_cpu_die(unsigned int cpu)
510 current->state = TASK_UNINTERRUPTIBLE; 510 current->state = TASK_UNINTERRUPTIBLE;
511 schedule_timeout(HZ/10); 511 schedule_timeout(HZ/10);
512 } 512 }
513
514 cpu_die_common(cpu);
515
513 xen_smp_intr_free(cpu); 516 xen_smp_intr_free(cpu);
514 xen_uninit_lock_cpu(cpu); 517 xen_uninit_lock_cpu(cpu);
515 xen_teardown_timer(cpu); 518 xen_teardown_timer(cpu);
diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig
index 49c6c3d94449..81f57e8c8f1b 100644
--- a/arch/xtensa/Kconfig
+++ b/arch/xtensa/Kconfig
@@ -319,8 +319,8 @@ config XTENSA_PLATFORM_S6105
319 319
320config XTENSA_PLATFORM_XTFPGA 320config XTENSA_PLATFORM_XTFPGA
321 bool "XTFPGA" 321 bool "XTFPGA"
322 select ETHOC if ETHERNET
322 select SERIAL_CONSOLE 323 select SERIAL_CONSOLE
323 select ETHOC
324 select XTENSA_CALIBRATE_CCOUNT 324 select XTENSA_CALIBRATE_CCOUNT
325 help 325 help
326 XTFPGA is the name of Tensilica board family (LX60, LX110, LX200, ML605). 326 XTFPGA is the name of Tensilica board family (LX60, LX110, LX200, ML605).
@@ -367,7 +367,7 @@ config BUILTIN_DTB
367config BLK_DEV_SIMDISK 367config BLK_DEV_SIMDISK
368 tristate "Host file-based simulated block device support" 368 tristate "Host file-based simulated block device support"
369 default n 369 default n
370 depends on XTENSA_PLATFORM_ISS 370 depends on XTENSA_PLATFORM_ISS && BLOCK
371 help 371 help
372 Create block devices that map to files in the host file system. 372 Create block devices that map to files in the host file system.
373 Device binding to host file may be changed at runtime via proc 373 Device binding to host file may be changed at runtime via proc
diff --git a/arch/xtensa/boot/dts/lx200mx.dts b/arch/xtensa/boot/dts/lx200mx.dts
new file mode 100644
index 000000000000..249822b99bd6
--- /dev/null
+++ b/arch/xtensa/boot/dts/lx200mx.dts
@@ -0,0 +1,16 @@
1/dts-v1/;
2/include/ "xtfpga.dtsi"
3/include/ "xtfpga-flash-16m.dtsi"
4
5/ {
6 compatible = "cdns,xtensa-lx200";
7 memory@0 {
8 device_type = "memory";
9 reg = <0x00000000 0x06000000>;
10 };
11 pic: pic {
12 compatible = "cdns,xtensa-mx";
13 #interrupt-cells = <2>;
14 interrupt-controller;
15 };
16};
diff --git a/arch/xtensa/configs/generic_kc705_defconfig b/arch/xtensa/configs/generic_kc705_defconfig
new file mode 100644
index 000000000000..f4b7b3888da8
--- /dev/null
+++ b/arch/xtensa/configs/generic_kc705_defconfig
@@ -0,0 +1,131 @@
1CONFIG_SYSVIPC=y
2CONFIG_POSIX_MQUEUE=y
3CONFIG_FHANDLE=y
4CONFIG_IRQ_DOMAIN_DEBUG=y
5CONFIG_NO_HZ_IDLE=y
6CONFIG_HIGH_RES_TIMERS=y
7CONFIG_IRQ_TIME_ACCOUNTING=y
8CONFIG_BSD_PROCESS_ACCT=y
9CONFIG_CGROUP_DEBUG=y
10CONFIG_CGROUP_FREEZER=y
11CONFIG_CGROUP_DEVICE=y
12CONFIG_CPUSETS=y
13CONFIG_CGROUP_CPUACCT=y
14CONFIG_RESOURCE_COUNTERS=y
15CONFIG_MEMCG=y
16CONFIG_NAMESPACES=y
17CONFIG_SCHED_AUTOGROUP=y
18CONFIG_RELAY=y
19CONFIG_BLK_DEV_INITRD=y
20CONFIG_EXPERT=y
21CONFIG_SYSCTL_SYSCALL=y
22CONFIG_KALLSYMS_ALL=y
23CONFIG_PROFILING=y
24CONFIG_OPROFILE=y
25CONFIG_MODULES=y
26CONFIG_MODULE_UNLOAD=y
27# CONFIG_IOSCHED_DEADLINE is not set
28# CONFIG_IOSCHED_CFQ is not set
29CONFIG_XTENSA_VARIANT_DC233C=y
30CONFIG_XTENSA_UNALIGNED_USER=y
31CONFIG_PREEMPT=y
32CONFIG_HIGHMEM=y
33# CONFIG_PCI is not set
34CONFIG_XTENSA_PLATFORM_XTFPGA=y
35CONFIG_CMDLINE_BOOL=y
36CONFIG_CMDLINE="earlycon=uart8250,mmio32,0xfd050020,115200n8 console=ttyS0,115200n8 ip=dhcp root=/dev/nfs rw debug"
37CONFIG_USE_OF=y
38CONFIG_BUILTIN_DTB="kc705"
39# CONFIG_COMPACTION is not set
40# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
41CONFIG_NET=y
42CONFIG_PACKET=y
43CONFIG_UNIX=y
44CONFIG_INET=y
45CONFIG_IP_MULTICAST=y
46CONFIG_IP_PNP=y
47CONFIG_IP_PNP_DHCP=y
48CONFIG_IP_PNP_BOOTP=y
49CONFIG_IP_PNP_RARP=y
50# CONFIG_IPV6 is not set
51CONFIG_NETFILTER=y
52# CONFIG_WIRELESS is not set
53CONFIG_DEVTMPFS=y
54CONFIG_DEVTMPFS_MOUNT=y
55# CONFIG_STANDALONE is not set
56CONFIG_MTD=y
57CONFIG_MTD_CFI=y
58CONFIG_MTD_JEDECPROBE=y
59CONFIG_MTD_CFI_INTELEXT=y
60CONFIG_MTD_CFI_AMDSTD=y
61CONFIG_MTD_CFI_STAA=y
62CONFIG_MTD_PHYSMAP_OF=y
63CONFIG_MTD_UBI=y
64CONFIG_BLK_DEV_LOOP=y
65CONFIG_BLK_DEV_RAM=y
66CONFIG_SCSI=y
67CONFIG_BLK_DEV_SD=y
68CONFIG_NETDEVICES=y
69# CONFIG_NET_VENDOR_ARC is not set
70# CONFIG_NET_VENDOR_BROADCOM is not set
71# CONFIG_NET_VENDOR_INTEL is not set
72# CONFIG_NET_VENDOR_MARVELL is not set
73# CONFIG_NET_VENDOR_MICREL is not set
74# CONFIG_NET_VENDOR_NATSEMI is not set
75# CONFIG_NET_VENDOR_SAMSUNG is not set
76# CONFIG_NET_VENDOR_SEEQ is not set
77# CONFIG_NET_VENDOR_SMSC is not set
78# CONFIG_NET_VENDOR_STMICRO is not set
79# CONFIG_NET_VENDOR_VIA is not set
80# CONFIG_NET_VENDOR_WIZNET is not set
81CONFIG_MARVELL_PHY=y
82# CONFIG_WLAN is not set
83# CONFIG_INPUT_MOUSEDEV is not set
84# CONFIG_INPUT_KEYBOARD is not set
85# CONFIG_INPUT_MOUSE is not set
86# CONFIG_SERIO is not set
87CONFIG_SERIAL_8250=y
88# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
89CONFIG_SERIAL_8250_CONSOLE=y
90CONFIG_SERIAL_OF_PLATFORM=y
91CONFIG_HW_RANDOM=y
92# CONFIG_HWMON is not set
93CONFIG_WATCHDOG=y
94CONFIG_WATCHDOG_NOWAYOUT=y
95CONFIG_SOFT_WATCHDOG=y
96# CONFIG_VGA_CONSOLE is not set
97# CONFIG_USB_SUPPORT is not set
98# CONFIG_IOMMU_SUPPORT is not set
99CONFIG_EXT3_FS=y
100CONFIG_EXT4_FS=y
101CONFIG_FANOTIFY=y
102CONFIG_VFAT_FS=y
103CONFIG_PROC_KCORE=y
104CONFIG_TMPFS=y
105CONFIG_TMPFS_POSIX_ACL=y
106CONFIG_UBIFS_FS=y
107CONFIG_NFS_FS=y
108CONFIG_NFS_V4=y
109CONFIG_NFS_SWAP=y
110CONFIG_ROOT_NFS=y
111CONFIG_SUNRPC_DEBUG=y
112CONFIG_NLS_CODEPAGE_437=y
113CONFIG_NLS_ISO8859_1=y
114CONFIG_PRINTK_TIME=y
115CONFIG_DYNAMIC_DEBUG=y
116CONFIG_DEBUG_INFO=y
117CONFIG_MAGIC_SYSRQ=y
118CONFIG_LOCKUP_DETECTOR=y
119# CONFIG_SCHED_DEBUG is not set
120CONFIG_SCHEDSTATS=y
121CONFIG_TIMER_STATS=y
122CONFIG_DEBUG_RT_MUTEXES=y
123CONFIG_DEBUG_SPINLOCK=y
124CONFIG_DEBUG_MUTEXES=y
125CONFIG_DEBUG_ATOMIC_SLEEP=y
126CONFIG_STACKTRACE=y
127CONFIG_RCU_TRACE=y
128# CONFIG_FTRACE is not set
129CONFIG_LD_NO_RELAX=y
130# CONFIG_S32C1I_SELFTEST is not set
131CONFIG_CRYPTO_ANSI_CPRNG=y
diff --git a/arch/xtensa/configs/smp_lx200_defconfig b/arch/xtensa/configs/smp_lx200_defconfig
new file mode 100644
index 000000000000..22eeacba37cc
--- /dev/null
+++ b/arch/xtensa/configs/smp_lx200_defconfig
@@ -0,0 +1,135 @@
1CONFIG_SYSVIPC=y
2CONFIG_POSIX_MQUEUE=y
3CONFIG_FHANDLE=y
4CONFIG_IRQ_DOMAIN_DEBUG=y
5CONFIG_NO_HZ_IDLE=y
6CONFIG_HIGH_RES_TIMERS=y
7CONFIG_IRQ_TIME_ACCOUNTING=y
8CONFIG_BSD_PROCESS_ACCT=y
9CONFIG_CGROUP_DEBUG=y
10CONFIG_CGROUP_FREEZER=y
11CONFIG_CGROUP_DEVICE=y
12CONFIG_CPUSETS=y
13CONFIG_CGROUP_CPUACCT=y
14CONFIG_RESOURCE_COUNTERS=y
15CONFIG_MEMCG=y
16CONFIG_NAMESPACES=y
17CONFIG_SCHED_AUTOGROUP=y
18CONFIG_RELAY=y
19CONFIG_BLK_DEV_INITRD=y
20CONFIG_EXPERT=y
21CONFIG_SYSCTL_SYSCALL=y
22CONFIG_KALLSYMS_ALL=y
23CONFIG_PROFILING=y
24CONFIG_OPROFILE=y
25CONFIG_MODULES=y
26CONFIG_MODULE_UNLOAD=y
27# CONFIG_IOSCHED_DEADLINE is not set
28# CONFIG_IOSCHED_CFQ is not set
29CONFIG_XTENSA_VARIANT_CUSTOM=y
30CONFIG_XTENSA_VARIANT_CUSTOM_NAME="test_mmuhifi_c3"
31CONFIG_XTENSA_UNALIGNED_USER=y
32CONFIG_PREEMPT=y
33CONFIG_HAVE_SMP=y
34CONFIG_SMP=y
35CONFIG_HOTPLUG_CPU=y
36# CONFIG_INITIALIZE_XTENSA_MMU_INSIDE_VMLINUX is not set
37# CONFIG_PCI is not set
38CONFIG_XTENSA_PLATFORM_XTFPGA=y
39CONFIG_CMDLINE_BOOL=y
40CONFIG_CMDLINE="earlycon=uart8250,mmio32,0xfd050020,115200n8 console=ttyS0,115200n8 ip=dhcp root=/dev/nfs rw debug"
41CONFIG_USE_OF=y
42CONFIG_BUILTIN_DTB="lx200mx"
43# CONFIG_COMPACTION is not set
44# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
45CONFIG_NET=y
46CONFIG_PACKET=y
47CONFIG_UNIX=y
48CONFIG_INET=y
49CONFIG_IP_MULTICAST=y
50CONFIG_IP_PNP=y
51CONFIG_IP_PNP_DHCP=y
52CONFIG_IP_PNP_BOOTP=y
53CONFIG_IP_PNP_RARP=y
54# CONFIG_IPV6 is not set
55CONFIG_NETFILTER=y
56# CONFIG_WIRELESS is not set
57CONFIG_DEVTMPFS=y
58CONFIG_DEVTMPFS_MOUNT=y
59# CONFIG_STANDALONE is not set
60CONFIG_MTD=y
61CONFIG_MTD_CFI=y
62CONFIG_MTD_JEDECPROBE=y
63CONFIG_MTD_CFI_INTELEXT=y
64CONFIG_MTD_CFI_AMDSTD=y
65CONFIG_MTD_CFI_STAA=y
66CONFIG_MTD_PHYSMAP_OF=y
67CONFIG_MTD_UBI=y
68CONFIG_BLK_DEV_LOOP=y
69CONFIG_BLK_DEV_RAM=y
70CONFIG_SCSI=y
71CONFIG_BLK_DEV_SD=y
72CONFIG_NETDEVICES=y
73# CONFIG_NET_VENDOR_ARC is not set
74# CONFIG_NET_VENDOR_BROADCOM is not set
75# CONFIG_NET_VENDOR_INTEL is not set
76# CONFIG_NET_VENDOR_MARVELL is not set
77# CONFIG_NET_VENDOR_MICREL is not set
78# CONFIG_NET_VENDOR_NATSEMI is not set
79# CONFIG_NET_VENDOR_SAMSUNG is not set
80# CONFIG_NET_VENDOR_SEEQ is not set
81# CONFIG_NET_VENDOR_SMSC is not set
82# CONFIG_NET_VENDOR_STMICRO is not set
83# CONFIG_NET_VENDOR_VIA is not set
84# CONFIG_NET_VENDOR_WIZNET is not set
85CONFIG_MARVELL_PHY=y
86# CONFIG_WLAN is not set
87# CONFIG_INPUT_MOUSEDEV is not set
88# CONFIG_INPUT_KEYBOARD is not set
89# CONFIG_INPUT_MOUSE is not set
90# CONFIG_SERIO is not set
91CONFIG_SERIAL_8250=y
92# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
93CONFIG_SERIAL_8250_CONSOLE=y
94CONFIG_SERIAL_OF_PLATFORM=y
95CONFIG_HW_RANDOM=y
96# CONFIG_HWMON is not set
97CONFIG_WATCHDOG=y
98CONFIG_WATCHDOG_NOWAYOUT=y
99CONFIG_SOFT_WATCHDOG=y
100# CONFIG_VGA_CONSOLE is not set
101# CONFIG_USB_SUPPORT is not set
102# CONFIG_IOMMU_SUPPORT is not set
103CONFIG_EXT3_FS=y
104CONFIG_EXT4_FS=y
105CONFIG_FANOTIFY=y
106CONFIG_VFAT_FS=y
107CONFIG_PROC_KCORE=y
108CONFIG_TMPFS=y
109CONFIG_TMPFS_POSIX_ACL=y
110CONFIG_UBIFS_FS=y
111CONFIG_NFS_FS=y
112CONFIG_NFS_V4=y
113CONFIG_NFS_SWAP=y
114CONFIG_ROOT_NFS=y
115CONFIG_SUNRPC_DEBUG=y
116CONFIG_NLS_CODEPAGE_437=y
117CONFIG_NLS_ISO8859_1=y
118CONFIG_PRINTK_TIME=y
119CONFIG_DYNAMIC_DEBUG=y
120CONFIG_DEBUG_INFO=y
121CONFIG_MAGIC_SYSRQ=y
122CONFIG_DEBUG_VM=y
123CONFIG_LOCKUP_DETECTOR=y
124CONFIG_SCHEDSTATS=y
125CONFIG_TIMER_STATS=y
126CONFIG_DEBUG_RT_MUTEXES=y
127CONFIG_DEBUG_SPINLOCK=y
128CONFIG_DEBUG_MUTEXES=y
129CONFIG_DEBUG_ATOMIC_SLEEP=y
130CONFIG_STACKTRACE=y
131CONFIG_RCU_TRACE=y
132# CONFIG_FTRACE is not set
133CONFIG_LD_NO_RELAX=y
134# CONFIG_S32C1I_SELFTEST is not set
135CONFIG_CRYPTO_ANSI_CPRNG=y
diff --git a/arch/xtensa/include/asm/pgtable.h b/arch/xtensa/include/asm/pgtable.h
index b2173e5da601..0383aed59121 100644
--- a/arch/xtensa/include/asm/pgtable.h
+++ b/arch/xtensa/include/asm/pgtable.h
@@ -277,6 +277,8 @@ static inline pte_t pte_mkwrite(pte_t pte)
277static inline pte_t pte_mkspecial(pte_t pte) 277static inline pte_t pte_mkspecial(pte_t pte)
278 { return pte; } 278 { return pte; }
279 279
280#define pgprot_noncached(prot) (__pgprot(pgprot_val(prot) & ~_PAGE_CA_MASK))
281
280/* 282/*
281 * Conversion functions: convert a page and protection to a page entry, 283 * Conversion functions: convert a page and protection to a page entry,
282 * and a page entry and page directory to the page they refer to. 284 * and a page entry and page directory to the page they refer to.
diff --git a/arch/xtensa/include/uapi/asm/unistd.h b/arch/xtensa/include/uapi/asm/unistd.h
index 8883fc877c5c..db5bb72e2f4e 100644
--- a/arch/xtensa/include/uapi/asm/unistd.h
+++ b/arch/xtensa/include/uapi/asm/unistd.h
@@ -384,7 +384,8 @@ __SYSCALL(174, sys_chroot, 1)
384#define __NR_pivot_root 175 384#define __NR_pivot_root 175
385__SYSCALL(175, sys_pivot_root, 2) 385__SYSCALL(175, sys_pivot_root, 2)
386#define __NR_umount 176 386#define __NR_umount 176
387__SYSCALL(176, sys_umount, 2) 387__SYSCALL(176, sys_oldumount, 1)
388#define __ARCH_WANT_SYS_OLDUMOUNT
388#define __NR_swapoff 177 389#define __NR_swapoff 177
389__SYSCALL(177, sys_swapoff, 1) 390__SYSCALL(177, sys_swapoff, 1)
390#define __NR_sync 178 391#define __NR_sync 178
@@ -742,7 +743,14 @@ __SYSCALL(335, sys_sched_getattr, 3)
742#define __NR_renameat2 336 743#define __NR_renameat2 336
743__SYSCALL(336, sys_renameat2, 5) 744__SYSCALL(336, sys_renameat2, 5)
744 745
745#define __NR_syscall_count 337 746#define __NR_seccomp 337
747__SYSCALL(337, sys_seccomp, 3)
748#define __NR_getrandom 338
749__SYSCALL(338, sys_getrandom, 3)
750#define __NR_memfd_create 339
751__SYSCALL(339, sys_memfd_create, 2)
752
753#define __NR_syscall_count 340
746 754
747/* 755/*
748 * sysxtensa syscall handler 756 * sysxtensa syscall handler
diff --git a/block/bio-integrity.c b/block/bio-integrity.c
index 0984232e429f..5cbd5d9ea61d 100644
--- a/block/bio-integrity.c
+++ b/block/bio-integrity.c
@@ -216,9 +216,10 @@ static int bio_integrity_process(struct bio *bio,
216{ 216{
217 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev); 217 struct blk_integrity *bi = bdev_get_integrity(bio->bi_bdev);
218 struct blk_integrity_iter iter; 218 struct blk_integrity_iter iter;
219 struct bio_vec *bv; 219 struct bvec_iter bviter;
220 struct bio_vec bv;
220 struct bio_integrity_payload *bip = bio_integrity(bio); 221 struct bio_integrity_payload *bip = bio_integrity(bio);
221 unsigned int i, ret = 0; 222 unsigned int ret = 0;
222 void *prot_buf = page_address(bip->bip_vec->bv_page) + 223 void *prot_buf = page_address(bip->bip_vec->bv_page) +
223 bip->bip_vec->bv_offset; 224 bip->bip_vec->bv_offset;
224 225
@@ -227,11 +228,11 @@ static int bio_integrity_process(struct bio *bio,
227 iter.seed = bip_get_seed(bip); 228 iter.seed = bip_get_seed(bip);
228 iter.prot_buf = prot_buf; 229 iter.prot_buf = prot_buf;
229 230
230 bio_for_each_segment_all(bv, bio, i) { 231 bio_for_each_segment(bv, bio, bviter) {
231 void *kaddr = kmap_atomic(bv->bv_page); 232 void *kaddr = kmap_atomic(bv.bv_page);
232 233
233 iter.data_buf = kaddr + bv->bv_offset; 234 iter.data_buf = kaddr + bv.bv_offset;
234 iter.data_size = bv->bv_len; 235 iter.data_size = bv.bv_len;
235 236
236 ret = proc_fn(&iter); 237 ret = proc_fn(&iter);
237 if (ret) { 238 if (ret) {
diff --git a/block/blk-core.c b/block/blk-core.c
index 0421b53e6431..2e7424b42947 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1266,7 +1266,7 @@ void blk_requeue_request(struct request_queue *q, struct request *rq)
1266 blk_clear_rq_complete(rq); 1266 blk_clear_rq_complete(rq);
1267 trace_block_rq_requeue(q, rq); 1267 trace_block_rq_requeue(q, rq);
1268 1268
1269 if (blk_rq_tagged(rq)) 1269 if (rq->cmd_flags & REQ_QUEUED)
1270 blk_queue_end_tag(q, rq); 1270 blk_queue_end_tag(q, rq);
1271 1271
1272 BUG_ON(blk_queued_rq(rq)); 1272 BUG_ON(blk_queued_rq(rq));
@@ -2554,7 +2554,7 @@ EXPORT_SYMBOL_GPL(blk_unprep_request);
2554 */ 2554 */
2555void blk_finish_request(struct request *req, int error) 2555void blk_finish_request(struct request *req, int error)
2556{ 2556{
2557 if (blk_rq_tagged(req)) 2557 if (req->cmd_flags & REQ_QUEUED)
2558 blk_queue_end_tag(req->q, req); 2558 blk_queue_end_tag(req->q, req);
2559 2559
2560 BUG_ON(blk_queued_rq(req)); 2560 BUG_ON(blk_queued_rq(req));
diff --git a/block/blk-merge.c b/block/blk-merge.c
index b3ac40aef46b..89b97b5e0881 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -97,19 +97,22 @@ void blk_recalc_rq_segments(struct request *rq)
97 97
98void blk_recount_segments(struct request_queue *q, struct bio *bio) 98void blk_recount_segments(struct request_queue *q, struct bio *bio)
99{ 99{
100 bool no_sg_merge = !!test_bit(QUEUE_FLAG_NO_SG_MERGE, 100 unsigned short seg_cnt;
101 &q->queue_flags); 101
102 bool merge_not_need = bio->bi_vcnt < queue_max_segments(q); 102 /* estimate segment number by bi_vcnt for non-cloned bio */
103 if (bio_flagged(bio, BIO_CLONED))
104 seg_cnt = bio_segments(bio);
105 else
106 seg_cnt = bio->bi_vcnt;
103 107
104 if (no_sg_merge && !bio_flagged(bio, BIO_CLONED) && 108 if (test_bit(QUEUE_FLAG_NO_SG_MERGE, &q->queue_flags) &&
105 merge_not_need) 109 (seg_cnt < queue_max_segments(q)))
106 bio->bi_phys_segments = bio->bi_vcnt; 110 bio->bi_phys_segments = seg_cnt;
107 else { 111 else {
108 struct bio *nxt = bio->bi_next; 112 struct bio *nxt = bio->bi_next;
109 113
110 bio->bi_next = NULL; 114 bio->bi_next = NULL;
111 bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio, 115 bio->bi_phys_segments = __blk_recalc_rq_segments(q, bio, false);
112 no_sg_merge && merge_not_need);
113 bio->bi_next = nxt; 116 bio->bi_next = nxt;
114 } 117 }
115 118
diff --git a/block/blk-mq-tag.c b/block/blk-mq-tag.c
index 8317175a3009..728b9a4d5f56 100644
--- a/block/blk-mq-tag.c
+++ b/block/blk-mq-tag.c
@@ -584,6 +584,34 @@ int blk_mq_tag_update_depth(struct blk_mq_tags *tags, unsigned int tdepth)
584 return 0; 584 return 0;
585} 585}
586 586
587/**
588 * blk_mq_unique_tag() - return a tag that is unique queue-wide
589 * @rq: request for which to compute a unique tag
590 *
591 * The tag field in struct request is unique per hardware queue but not over
592 * all hardware queues. Hence this function that returns a tag with the
593 * hardware context index in the upper bits and the per hardware queue tag in
594 * the lower bits.
595 *
596 * Note: When called for a request that is queued on a non-multiqueue request
597 * queue, the hardware context index is set to zero.
598 */
599u32 blk_mq_unique_tag(struct request *rq)
600{
601 struct request_queue *q = rq->q;
602 struct blk_mq_hw_ctx *hctx;
603 int hwq = 0;
604
605 if (q->mq_ops) {
606 hctx = q->mq_ops->map_queue(q, rq->mq_ctx->cpu);
607 hwq = hctx->queue_num;
608 }
609
610 return (hwq << BLK_MQ_UNIQUE_TAG_BITS) |
611 (rq->tag & BLK_MQ_UNIQUE_TAG_MASK);
612}
613EXPORT_SYMBOL(blk_mq_unique_tag);
614
587ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page) 615ssize_t blk_mq_tag_sysfs_show(struct blk_mq_tags *tags, char *page)
588{ 616{
589 char *orig_page = page; 617 char *orig_page = page;
diff --git a/block/blk-mq.c b/block/blk-mq.c
index 68929bad9a6a..92ceef0d2ab9 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -107,11 +107,7 @@ static void blk_mq_usage_counter_release(struct percpu_ref *ref)
107 wake_up_all(&q->mq_freeze_wq); 107 wake_up_all(&q->mq_freeze_wq);
108} 108}
109 109
110/* 110static void blk_mq_freeze_queue_start(struct request_queue *q)
111 * Guarantee no request is in use, so we can change any data structure of
112 * the queue afterward.
113 */
114void blk_mq_freeze_queue(struct request_queue *q)
115{ 111{
116 bool freeze; 112 bool freeze;
117 113
@@ -123,9 +119,23 @@ void blk_mq_freeze_queue(struct request_queue *q)
123 percpu_ref_kill(&q->mq_usage_counter); 119 percpu_ref_kill(&q->mq_usage_counter);
124 blk_mq_run_queues(q, false); 120 blk_mq_run_queues(q, false);
125 } 121 }
122}
123
124static void blk_mq_freeze_queue_wait(struct request_queue *q)
125{
126 wait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->mq_usage_counter)); 126 wait_event(q->mq_freeze_wq, percpu_ref_is_zero(&q->mq_usage_counter));
127} 127}
128 128
129/*
130 * Guarantee no request is in use, so we can change any data structure of
131 * the queue afterward.
132 */
133void blk_mq_freeze_queue(struct request_queue *q)
134{
135 blk_mq_freeze_queue_start(q);
136 blk_mq_freeze_queue_wait(q);
137}
138
129static void blk_mq_unfreeze_queue(struct request_queue *q) 139static void blk_mq_unfreeze_queue(struct request_queue *q)
130{ 140{
131 bool wake; 141 bool wake;
@@ -1921,7 +1931,7 @@ void blk_mq_free_queue(struct request_queue *q)
1921/* Basically redo blk_mq_init_queue with queue frozen */ 1931/* Basically redo blk_mq_init_queue with queue frozen */
1922static void blk_mq_queue_reinit(struct request_queue *q) 1932static void blk_mq_queue_reinit(struct request_queue *q)
1923{ 1933{
1924 blk_mq_freeze_queue(q); 1934 WARN_ON_ONCE(!q->mq_freeze_depth);
1925 1935
1926 blk_mq_sysfs_unregister(q); 1936 blk_mq_sysfs_unregister(q);
1927 1937
@@ -1936,8 +1946,6 @@ static void blk_mq_queue_reinit(struct request_queue *q)
1936 blk_mq_map_swqueue(q); 1946 blk_mq_map_swqueue(q);
1937 1947
1938 blk_mq_sysfs_register(q); 1948 blk_mq_sysfs_register(q);
1939
1940 blk_mq_unfreeze_queue(q);
1941} 1949}
1942 1950
1943static int blk_mq_queue_reinit_notify(struct notifier_block *nb, 1951static int blk_mq_queue_reinit_notify(struct notifier_block *nb,
@@ -1956,8 +1964,25 @@ static int blk_mq_queue_reinit_notify(struct notifier_block *nb,
1956 return NOTIFY_OK; 1964 return NOTIFY_OK;
1957 1965
1958 mutex_lock(&all_q_mutex); 1966 mutex_lock(&all_q_mutex);
1967
1968 /*
1969 * We need to freeze and reinit all existing queues. Freezing
1970 * involves synchronous wait for an RCU grace period and doing it
1971 * one by one may take a long time. Start freezing all queues in
1972 * one swoop and then wait for the completions so that freezing can
1973 * take place in parallel.
1974 */
1975 list_for_each_entry(q, &all_q_list, all_q_node)
1976 blk_mq_freeze_queue_start(q);
1977 list_for_each_entry(q, &all_q_list, all_q_node)
1978 blk_mq_freeze_queue_wait(q);
1979
1959 list_for_each_entry(q, &all_q_list, all_q_node) 1980 list_for_each_entry(q, &all_q_list, all_q_node)
1960 blk_mq_queue_reinit(q); 1981 blk_mq_queue_reinit(q);
1982
1983 list_for_each_entry(q, &all_q_list, all_q_node)
1984 blk_mq_unfreeze_queue(q);
1985
1961 mutex_unlock(&all_q_mutex); 1986 mutex_unlock(&all_q_mutex);
1962 return NOTIFY_OK; 1987 return NOTIFY_OK;
1963} 1988}
@@ -2024,6 +2049,8 @@ static int blk_mq_alloc_rq_maps(struct blk_mq_tag_set *set)
2024 */ 2049 */
2025int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set) 2050int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set)
2026{ 2051{
2052 BUILD_BUG_ON(BLK_MQ_MAX_DEPTH > 1 << BLK_MQ_UNIQUE_TAG_BITS);
2053
2027 if (!set->nr_hw_queues) 2054 if (!set->nr_hw_queues)
2028 return -EINVAL; 2055 return -EINVAL;
2029 if (!set->queue_depth) 2056 if (!set->queue_depth)
diff --git a/block/ioprio.c b/block/ioprio.c
index e50170ca7c33..31666c92b46a 100644
--- a/block/ioprio.c
+++ b/block/ioprio.c
@@ -157,14 +157,16 @@ out:
157 157
158int ioprio_best(unsigned short aprio, unsigned short bprio) 158int ioprio_best(unsigned short aprio, unsigned short bprio)
159{ 159{
160 unsigned short aclass = IOPRIO_PRIO_CLASS(aprio); 160 unsigned short aclass;
161 unsigned short bclass = IOPRIO_PRIO_CLASS(bprio); 161 unsigned short bclass;
162 162
163 if (aclass == IOPRIO_CLASS_NONE) 163 if (!ioprio_valid(aprio))
164 aclass = IOPRIO_CLASS_BE; 164 aprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
165 if (bclass == IOPRIO_CLASS_NONE) 165 if (!ioprio_valid(bprio))
166 bclass = IOPRIO_CLASS_BE; 166 bprio = IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, IOPRIO_NORM);
167 167
168 aclass = IOPRIO_PRIO_CLASS(aprio);
169 bclass = IOPRIO_PRIO_CLASS(bprio);
168 if (aclass == bclass) 170 if (aclass == bclass)
169 return min(aprio, bprio); 171 return min(aprio, bprio);
170 if (aclass > bclass) 172 if (aclass > bclass)
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 1e053d911240..28163fad3c5d 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -142,7 +142,7 @@ static void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter)
142 __set_bit(GPCMD_VERIFY_10, filter->read_ok); 142 __set_bit(GPCMD_VERIFY_10, filter->read_ok);
143 __set_bit(VERIFY_16, filter->read_ok); 143 __set_bit(VERIFY_16, filter->read_ok);
144 __set_bit(REPORT_LUNS, filter->read_ok); 144 __set_bit(REPORT_LUNS, filter->read_ok);
145 __set_bit(SERVICE_ACTION_IN, filter->read_ok); 145 __set_bit(SERVICE_ACTION_IN_16, filter->read_ok);
146 __set_bit(RECEIVE_DIAGNOSTIC, filter->read_ok); 146 __set_bit(RECEIVE_DIAGNOSTIC, filter->read_ok);
147 __set_bit(MAINTENANCE_IN, filter->read_ok); 147 __set_bit(MAINTENANCE_IN, filter->read_ok);
148 __set_bit(GPCMD_READ_BUFFER_CAPACITY, filter->read_ok); 148 __set_bit(GPCMD_READ_BUFFER_CAPACITY, filter->read_ok);
@@ -458,7 +458,7 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
458 rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT); 458 rq = blk_get_request(q, in_len ? WRITE : READ, __GFP_WAIT);
459 if (IS_ERR(rq)) { 459 if (IS_ERR(rq)) {
460 err = PTR_ERR(rq); 460 err = PTR_ERR(rq);
461 goto error; 461 goto error_free_buffer;
462 } 462 }
463 blk_rq_set_block_pc(rq); 463 blk_rq_set_block_pc(rq);
464 464
@@ -531,9 +531,11 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
531 } 531 }
532 532
533error: 533error:
534 blk_put_request(rq);
535
536error_free_buffer:
534 kfree(buffer); 537 kfree(buffer);
535 if (rq) 538
536 blk_put_request(rq);
537 return err; 539 return err;
538} 540}
539EXPORT_SYMBOL_GPL(sg_scsi_ioctl); 541EXPORT_SYMBOL_GPL(sg_scsi_ioctl);
diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
index ed122e17636e..7556e7c4a055 100644
--- a/drivers/acpi/blacklist.c
+++ b/drivers/acpi/blacklist.c
@@ -290,6 +290,14 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
290 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3446"), 290 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3446"),
291 }, 291 },
292 }, 292 },
293 {
294 .callback = dmi_disable_osi_win8,
295 .ident = "Dell Vostro 3546",
296 .matches = {
297 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
298 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3546"),
299 },
300 },
293 301
294 /* 302 /*
295 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug. 303 * BIOS invocation of _OSI(Linux) is almost always a BIOS bug.
diff --git a/drivers/acpi/device_pm.c b/drivers/acpi/device_pm.c
index 143ec6ea1468..7db193160766 100644
--- a/drivers/acpi/device_pm.c
+++ b/drivers/acpi/device_pm.c
@@ -878,7 +878,7 @@ int acpi_dev_suspend_late(struct device *dev)
878 return 0; 878 return 0;
879 879
880 target_state = acpi_target_system_state(); 880 target_state = acpi_target_system_state();
881 wakeup = device_may_wakeup(dev); 881 wakeup = device_may_wakeup(dev) && acpi_device_can_wakeup(adev);
882 error = acpi_device_wakeup(adev, target_state, wakeup); 882 error = acpi_device_wakeup(adev, target_state, wakeup);
883 if (wakeup && error) 883 if (wakeup && error)
884 return error; 884 return error;
diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
index 807a88a0f394..9d75ead2a1f9 100644
--- a/drivers/acpi/video.c
+++ b/drivers/acpi/video.c
@@ -1164,7 +1164,8 @@ static bool acpi_video_device_in_dod(struct acpi_video_device *device)
1164 return true; 1164 return true;
1165 1165
1166 for (i = 0; i < video->attached_count; i++) { 1166 for (i = 0; i < video->attached_count; i++) {
1167 if (video->attached_array[i].bind_info == device) 1167 if ((video->attached_array[i].value.int_val & 0xfff) ==
1168 (device->device_id & 0xfff))
1168 return true; 1169 return true;
1169 } 1170 }
1170 1171
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 5f039f191067..49f1e6890587 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -60,6 +60,7 @@ enum board_ids {
60 /* board IDs by feature in alphabetical order */ 60 /* board IDs by feature in alphabetical order */
61 board_ahci, 61 board_ahci,
62 board_ahci_ign_iferr, 62 board_ahci_ign_iferr,
63 board_ahci_nomsi,
63 board_ahci_noncq, 64 board_ahci_noncq,
64 board_ahci_nosntf, 65 board_ahci_nosntf,
65 board_ahci_yes_fbs, 66 board_ahci_yes_fbs,
@@ -121,6 +122,13 @@ static const struct ata_port_info ahci_port_info[] = {
121 .udma_mask = ATA_UDMA6, 122 .udma_mask = ATA_UDMA6,
122 .port_ops = &ahci_ops, 123 .port_ops = &ahci_ops,
123 }, 124 },
125 [board_ahci_nomsi] = {
126 AHCI_HFLAGS (AHCI_HFLAG_NO_MSI),
127 .flags = AHCI_FLAG_COMMON,
128 .pio_mask = ATA_PIO4,
129 .udma_mask = ATA_UDMA6,
130 .port_ops = &ahci_ops,
131 },
124 [board_ahci_noncq] = { 132 [board_ahci_noncq] = {
125 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ), 133 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ),
126 .flags = AHCI_FLAG_COMMON, 134 .flags = AHCI_FLAG_COMMON,
@@ -313,6 +321,14 @@ static const struct pci_device_id ahci_pci_tbl[] = {
313 { PCI_VDEVICE(INTEL, 0x8c87), board_ahci }, /* 9 Series RAID */ 321 { PCI_VDEVICE(INTEL, 0x8c87), board_ahci }, /* 9 Series RAID */
314 { PCI_VDEVICE(INTEL, 0x8c8e), board_ahci }, /* 9 Series RAID */ 322 { PCI_VDEVICE(INTEL, 0x8c8e), board_ahci }, /* 9 Series RAID */
315 { PCI_VDEVICE(INTEL, 0x8c8f), board_ahci }, /* 9 Series RAID */ 323 { PCI_VDEVICE(INTEL, 0x8c8f), board_ahci }, /* 9 Series RAID */
324 { PCI_VDEVICE(INTEL, 0x9d03), board_ahci }, /* Sunrise Point-LP AHCI */
325 { PCI_VDEVICE(INTEL, 0x9d05), board_ahci }, /* Sunrise Point-LP RAID */
326 { PCI_VDEVICE(INTEL, 0x9d07), board_ahci }, /* Sunrise Point-LP RAID */
327 { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H AHCI */
328 { PCI_VDEVICE(INTEL, 0xa103), board_ahci }, /* Sunrise Point-H RAID */
329 { PCI_VDEVICE(INTEL, 0xa105), board_ahci }, /* Sunrise Point-H RAID */
330 { PCI_VDEVICE(INTEL, 0xa107), board_ahci }, /* Sunrise Point-H RAID */
331 { PCI_VDEVICE(INTEL, 0xa10f), board_ahci }, /* Sunrise Point-H RAID */
316 332
317 /* JMicron 360/1/3/5/6, match class to avoid IDE function */ 333 /* JMicron 360/1/3/5/6, match class to avoid IDE function */
318 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 334 { PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
@@ -475,10 +491,11 @@ static const struct pci_device_id ahci_pci_tbl[] = {
475 { PCI_VDEVICE(ASMEDIA, 0x0612), board_ahci }, /* ASM1062 */ 491 { PCI_VDEVICE(ASMEDIA, 0x0612), board_ahci }, /* ASM1062 */
476 492
477 /* 493 /*
478 * Samsung SSDs found on some macbooks. NCQ times out. 494 * Samsung SSDs found on some macbooks. NCQ times out if MSI is
479 * https://bugzilla.kernel.org/show_bug.cgi?id=60731 495 * enabled. https://bugzilla.kernel.org/show_bug.cgi?id=60731
480 */ 496 */
481 { PCI_VDEVICE(SAMSUNG, 0x1600), board_ahci_noncq }, 497 { PCI_VDEVICE(SAMSUNG, 0x1600), board_ahci_nomsi },
498 { PCI_VDEVICE(SAMSUNG, 0xa800), board_ahci_nomsi },
482 499
483 /* Enmotus */ 500 /* Enmotus */
484 { PCI_DEVICE(0x1c44, 0x8000), board_ahci }, 501 { PCI_DEVICE(0x1c44, 0x8000), board_ahci },
@@ -514,12 +531,9 @@ MODULE_PARM_DESC(marvell_enable, "Marvell SATA via AHCI (1 = enabled)");
514static void ahci_pci_save_initial_config(struct pci_dev *pdev, 531static void ahci_pci_save_initial_config(struct pci_dev *pdev,
515 struct ahci_host_priv *hpriv) 532 struct ahci_host_priv *hpriv)
516{ 533{
517 unsigned int force_port_map = 0;
518 unsigned int mask_port_map = 0;
519
520 if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) { 534 if (pdev->vendor == PCI_VENDOR_ID_JMICRON && pdev->device == 0x2361) {
521 dev_info(&pdev->dev, "JMB361 has only one port\n"); 535 dev_info(&pdev->dev, "JMB361 has only one port\n");
522 force_port_map = 1; 536 hpriv->force_port_map = 1;
523 } 537 }
524 538
525 /* 539 /*
@@ -529,9 +543,9 @@ static void ahci_pci_save_initial_config(struct pci_dev *pdev,
529 */ 543 */
530 if (hpriv->flags & AHCI_HFLAG_MV_PATA) { 544 if (hpriv->flags & AHCI_HFLAG_MV_PATA) {
531 if (pdev->device == 0x6121) 545 if (pdev->device == 0x6121)
532 mask_port_map = 0x3; 546 hpriv->mask_port_map = 0x3;
533 else 547 else
534 mask_port_map = 0xf; 548 hpriv->mask_port_map = 0xf;
535 dev_info(&pdev->dev, 549 dev_info(&pdev->dev,
536 "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n"); 550 "Disabling your PATA port. Use the boot option 'ahci.marvell_enable=0' to avoid this.\n");
537 } 551 }
diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
index 5eb61c9e63da..97683e45ab04 100644
--- a/drivers/ata/libahci.c
+++ b/drivers/ata/libahci.c
@@ -1778,16 +1778,15 @@ static void ahci_handle_port_interrupt(struct ata_port *ap,
1778 } 1778 }
1779} 1779}
1780 1780
1781static void ahci_update_intr_status(struct ata_port *ap) 1781static void ahci_port_intr(struct ata_port *ap)
1782{ 1782{
1783 void __iomem *port_mmio = ahci_port_base(ap); 1783 void __iomem *port_mmio = ahci_port_base(ap);
1784 struct ahci_port_priv *pp = ap->private_data;
1785 u32 status; 1784 u32 status;
1786 1785
1787 status = readl(port_mmio + PORT_IRQ_STAT); 1786 status = readl(port_mmio + PORT_IRQ_STAT);
1788 writel(status, port_mmio + PORT_IRQ_STAT); 1787 writel(status, port_mmio + PORT_IRQ_STAT);
1789 1788
1790 atomic_or(status, &pp->intr_status); 1789 ahci_handle_port_interrupt(ap, port_mmio, status);
1791} 1790}
1792 1791
1793static irqreturn_t ahci_port_thread_fn(int irq, void *dev_instance) 1792static irqreturn_t ahci_port_thread_fn(int irq, void *dev_instance)
@@ -1808,34 +1807,6 @@ static irqreturn_t ahci_port_thread_fn(int irq, void *dev_instance)
1808 return IRQ_HANDLED; 1807 return IRQ_HANDLED;
1809} 1808}
1810 1809
1811irqreturn_t ahci_thread_fn(int irq, void *dev_instance)
1812{
1813 struct ata_host *host = dev_instance;
1814 struct ahci_host_priv *hpriv = host->private_data;
1815 u32 irq_masked = hpriv->port_map;
1816 unsigned int i;
1817
1818 for (i = 0; i < host->n_ports; i++) {
1819 struct ata_port *ap;
1820
1821 if (!(irq_masked & (1 << i)))
1822 continue;
1823
1824 ap = host->ports[i];
1825 if (ap) {
1826 ahci_port_thread_fn(irq, ap);
1827 VPRINTK("port %u\n", i);
1828 } else {
1829 VPRINTK("port %u (no irq)\n", i);
1830 if (ata_ratelimit())
1831 dev_warn(host->dev,
1832 "interrupt on disabled port %u\n", i);
1833 }
1834 }
1835
1836 return IRQ_HANDLED;
1837}
1838
1839static irqreturn_t ahci_multi_irqs_intr(int irq, void *dev_instance) 1810static irqreturn_t ahci_multi_irqs_intr(int irq, void *dev_instance)
1840{ 1811{
1841 struct ata_port *ap = dev_instance; 1812 struct ata_port *ap = dev_instance;
@@ -1875,6 +1846,8 @@ static irqreturn_t ahci_single_irq_intr(int irq, void *dev_instance)
1875 1846
1876 irq_masked = irq_stat & hpriv->port_map; 1847 irq_masked = irq_stat & hpriv->port_map;
1877 1848
1849 spin_lock(&host->lock);
1850
1878 for (i = 0; i < host->n_ports; i++) { 1851 for (i = 0; i < host->n_ports; i++) {
1879 struct ata_port *ap; 1852 struct ata_port *ap;
1880 1853
@@ -1883,7 +1856,7 @@ static irqreturn_t ahci_single_irq_intr(int irq, void *dev_instance)
1883 1856
1884 ap = host->ports[i]; 1857 ap = host->ports[i];
1885 if (ap) { 1858 if (ap) {
1886 ahci_update_intr_status(ap); 1859 ahci_port_intr(ap);
1887 VPRINTK("port %u\n", i); 1860 VPRINTK("port %u\n", i);
1888 } else { 1861 } else {
1889 VPRINTK("port %u (no irq)\n", i); 1862 VPRINTK("port %u (no irq)\n", i);
@@ -1906,9 +1879,11 @@ static irqreturn_t ahci_single_irq_intr(int irq, void *dev_instance)
1906 */ 1879 */
1907 writel(irq_stat, mmio + HOST_IRQ_STAT); 1880 writel(irq_stat, mmio + HOST_IRQ_STAT);
1908 1881
1882 spin_unlock(&host->lock);
1883
1909 VPRINTK("EXIT\n"); 1884 VPRINTK("EXIT\n");
1910 1885
1911 return handled ? IRQ_WAKE_THREAD : IRQ_NONE; 1886 return IRQ_RETVAL(handled);
1912} 1887}
1913 1888
1914unsigned int ahci_qc_issue(struct ata_queued_cmd *qc) 1889unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
@@ -2320,8 +2295,13 @@ static int ahci_port_start(struct ata_port *ap)
2320 */ 2295 */
2321 pp->intr_mask = DEF_PORT_IRQ; 2296 pp->intr_mask = DEF_PORT_IRQ;
2322 2297
2323 spin_lock_init(&pp->lock); 2298 /*
2324 ap->lock = &pp->lock; 2299 * Switch to per-port locking in case each port has its own MSI vector.
2300 */
2301 if ((hpriv->flags & AHCI_HFLAG_MULTI_MSI)) {
2302 spin_lock_init(&pp->lock);
2303 ap->lock = &pp->lock;
2304 }
2325 2305
2326 ap->private_data = pp; 2306 ap->private_data = pp;
2327 2307
@@ -2482,31 +2462,6 @@ out_free_irqs:
2482 return rc; 2462 return rc;
2483} 2463}
2484 2464
2485static int ahci_host_activate_single_irq(struct ata_host *host, int irq,
2486 struct scsi_host_template *sht)
2487{
2488 int i, rc;
2489
2490 rc = ata_host_start(host);
2491 if (rc)
2492 return rc;
2493
2494 rc = devm_request_threaded_irq(host->dev, irq, ahci_single_irq_intr,
2495 ahci_thread_fn, IRQF_SHARED,
2496 dev_driver_string(host->dev), host);
2497 if (rc)
2498 return rc;
2499
2500 for (i = 0; i < host->n_ports; i++)
2501 ata_port_desc(host->ports[i], "irq %d", irq);
2502
2503 rc = ata_host_register(host, sht);
2504 if (rc)
2505 devm_free_irq(host->dev, irq, host);
2506
2507 return rc;
2508}
2509
2510/** 2465/**
2511 * ahci_host_activate - start AHCI host, request IRQs and register it 2466 * ahci_host_activate - start AHCI host, request IRQs and register it
2512 * @host: target ATA host 2467 * @host: target ATA host
@@ -2532,7 +2487,8 @@ int ahci_host_activate(struct ata_host *host, int irq,
2532 if (hpriv->flags & AHCI_HFLAG_MULTI_MSI) 2487 if (hpriv->flags & AHCI_HFLAG_MULTI_MSI)
2533 rc = ahci_host_activate_multi_irqs(host, irq, sht); 2488 rc = ahci_host_activate_multi_irqs(host, irq, sht);
2534 else 2489 else
2535 rc = ahci_host_activate_single_irq(host, irq, sht); 2490 rc = ata_host_activate(host, irq, ahci_single_irq_intr,
2491 IRQF_SHARED, sht);
2536 return rc; 2492 return rc;
2537} 2493}
2538EXPORT_SYMBOL_GPL(ahci_host_activate); 2494EXPORT_SYMBOL_GPL(ahci_host_activate);
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 0586f66d70fa..dd45c6a03e5d 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1164,7 +1164,7 @@ static int ata_scsi_dev_config(struct scsi_device *sdev,
1164 1164
1165 depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id)); 1165 depth = min(sdev->host->can_queue, ata_id_queue_depth(dev->id));
1166 depth = min(ATA_MAX_QUEUE - 1, depth); 1166 depth = min(ATA_MAX_QUEUE - 1, depth);
1167 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth); 1167 scsi_change_queue_depth(sdev, depth);
1168 } 1168 }
1169 1169
1170 blk_queue_flush_queueable(q, false); 1170 blk_queue_flush_queueable(q, false);
@@ -1243,21 +1243,17 @@ void ata_scsi_slave_destroy(struct scsi_device *sdev)
1243 * @ap: ATA port to which the device change the queue depth 1243 * @ap: ATA port to which the device change the queue depth
1244 * @sdev: SCSI device to configure queue depth for 1244 * @sdev: SCSI device to configure queue depth for
1245 * @queue_depth: new queue depth 1245 * @queue_depth: new queue depth
1246 * @reason: calling context
1247 * 1246 *
1248 * libsas and libata have different approaches for associating a sdev to 1247 * libsas and libata have different approaches for associating a sdev to
1249 * its ata_port. 1248 * its ata_port.
1250 * 1249 *
1251 */ 1250 */
1252int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev, 1251int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1253 int queue_depth, int reason) 1252 int queue_depth)
1254{ 1253{
1255 struct ata_device *dev; 1254 struct ata_device *dev;
1256 unsigned long flags; 1255 unsigned long flags;
1257 1256
1258 if (reason != SCSI_QDEPTH_DEFAULT)
1259 return -EOPNOTSUPP;
1260
1261 if (queue_depth < 1 || queue_depth == sdev->queue_depth) 1257 if (queue_depth < 1 || queue_depth == sdev->queue_depth)
1262 return sdev->queue_depth; 1258 return sdev->queue_depth;
1263 1259
@@ -1282,15 +1278,13 @@ int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1282 if (sdev->queue_depth == queue_depth) 1278 if (sdev->queue_depth == queue_depth)
1283 return -EINVAL; 1279 return -EINVAL;
1284 1280
1285 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, queue_depth); 1281 return scsi_change_queue_depth(sdev, queue_depth);
1286 return queue_depth;
1287} 1282}
1288 1283
1289/** 1284/**
1290 * ata_scsi_change_queue_depth - SCSI callback for queue depth config 1285 * ata_scsi_change_queue_depth - SCSI callback for queue depth config
1291 * @sdev: SCSI device to configure queue depth for 1286 * @sdev: SCSI device to configure queue depth for
1292 * @queue_depth: new queue depth 1287 * @queue_depth: new queue depth
1293 * @reason: calling context
1294 * 1288 *
1295 * This is libata standard hostt->change_queue_depth callback. 1289 * This is libata standard hostt->change_queue_depth callback.
1296 * SCSI will call into this callback when user tries to set queue 1290 * SCSI will call into this callback when user tries to set queue
@@ -1302,12 +1296,11 @@ int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1302 * RETURNS: 1296 * RETURNS:
1303 * Newly configured queue depth. 1297 * Newly configured queue depth.
1304 */ 1298 */
1305int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth, 1299int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
1306 int reason)
1307{ 1300{
1308 struct ata_port *ap = ata_shost_to_port(sdev->host); 1301 struct ata_port *ap = ata_shost_to_port(sdev->host);
1309 1302
1310 return __ata_change_queue_depth(ap, sdev, queue_depth, reason); 1303 return __ata_change_queue_depth(ap, sdev, queue_depth);
1311} 1304}
1312 1305
1313/** 1306/**
@@ -3570,7 +3563,7 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd)
3570 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap); 3563 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap);
3571 break; 3564 break;
3572 3565
3573 case SERVICE_ACTION_IN: 3566 case SERVICE_ACTION_IN_16:
3574 if ((scsicmd[1] & 0x1f) == SAI_READ_CAPACITY_16) 3567 if ((scsicmd[1] & 0x1f) == SAI_READ_CAPACITY_16)
3575 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap); 3568 ata_scsi_rbuf_fill(&args, ata_scsiop_read_cap);
3576 else 3569 else
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index 07bc7e4dbd04..65071591b143 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -1488,7 +1488,7 @@ static int sata_fsl_probe(struct platform_device *ofdev)
1488 host_priv->csr_base = csr_base; 1488 host_priv->csr_base = csr_base;
1489 1489
1490 irq = irq_of_parse_and_map(ofdev->dev.of_node, 0); 1490 irq = irq_of_parse_and_map(ofdev->dev.of_node, 0);
1491 if (irq < 0) { 1491 if (!irq) {
1492 dev_err(&ofdev->dev, "invalid irq from platform\n"); 1492 dev_err(&ofdev->dev, "invalid irq from platform\n");
1493 goto error_exit_with_cleanup; 1493 goto error_exit_with_cleanup;
1494 } 1494 }
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index cdf99fac139a..1db6f5ce5e89 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -1951,7 +1951,7 @@ static int nv_swncq_slave_config(struct scsi_device *sdev)
1951 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num)); 1951 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
1952 1952
1953 if (strncmp(model_num, "Maxtor", 6) == 0) { 1953 if (strncmp(model_num, "Maxtor", 6) == 0) {
1954 ata_scsi_change_queue_depth(sdev, 1, SCSI_QDEPTH_DEFAULT); 1954 ata_scsi_change_queue_depth(sdev, 1);
1955 ata_dev_notice(dev, "Disabling SWNCQ mode (depth %x)\n", 1955 ata_dev_notice(dev, "Disabling SWNCQ mode (depth %x)\n",
1956 sdev->queue_depth); 1956 sdev->queue_depth);
1957 } 1957 }
diff --git a/drivers/ata/sata_rcar.c b/drivers/ata/sata_rcar.c
index 61eb6d77dac7..ea1fbc1d4c5f 100644
--- a/drivers/ata/sata_rcar.c
+++ b/drivers/ata/sata_rcar.c
@@ -146,6 +146,7 @@
146enum sata_rcar_type { 146enum sata_rcar_type {
147 RCAR_GEN1_SATA, 147 RCAR_GEN1_SATA,
148 RCAR_GEN2_SATA, 148 RCAR_GEN2_SATA,
149 RCAR_R8A7790_ES1_SATA,
149}; 150};
150 151
151struct sata_rcar_priv { 152struct sata_rcar_priv {
@@ -763,6 +764,9 @@ static void sata_rcar_setup_port(struct ata_host *host)
763 ap->udma_mask = ATA_UDMA6; 764 ap->udma_mask = ATA_UDMA6;
764 ap->flags |= ATA_FLAG_SATA; 765 ap->flags |= ATA_FLAG_SATA;
765 766
767 if (priv->type == RCAR_R8A7790_ES1_SATA)
768 ap->flags |= ATA_FLAG_NO_DIPM;
769
766 ioaddr->cmd_addr = base + SDATA_REG; 770 ioaddr->cmd_addr = base + SDATA_REG;
767 ioaddr->ctl_addr = base + SSDEVCON_REG; 771 ioaddr->ctl_addr = base + SSDEVCON_REG;
768 ioaddr->scr_addr = base + SCRSSTS_REG; 772 ioaddr->scr_addr = base + SCRSSTS_REG;
@@ -792,6 +796,7 @@ static void sata_rcar_init_controller(struct ata_host *host)
792 sata_rcar_gen1_phy_init(priv); 796 sata_rcar_gen1_phy_init(priv);
793 break; 797 break;
794 case RCAR_GEN2_SATA: 798 case RCAR_GEN2_SATA:
799 case RCAR_R8A7790_ES1_SATA:
795 sata_rcar_gen2_phy_init(priv); 800 sata_rcar_gen2_phy_init(priv);
796 break; 801 break;
797 default: 802 default:
@@ -838,9 +843,17 @@ static struct of_device_id sata_rcar_match[] = {
838 .data = (void *)RCAR_GEN2_SATA 843 .data = (void *)RCAR_GEN2_SATA
839 }, 844 },
840 { 845 {
846 .compatible = "renesas,sata-r8a7790-es1",
847 .data = (void *)RCAR_R8A7790_ES1_SATA
848 },
849 {
841 .compatible = "renesas,sata-r8a7791", 850 .compatible = "renesas,sata-r8a7791",
842 .data = (void *)RCAR_GEN2_SATA 851 .data = (void *)RCAR_GEN2_SATA
843 }, 852 },
853 {
854 .compatible = "renesas,sata-r8a7793",
855 .data = (void *)RCAR_GEN2_SATA
856 },
844 { }, 857 { },
845}; 858};
846MODULE_DEVICE_TABLE(of, sata_rcar_match); 859MODULE_DEVICE_TABLE(of, sata_rcar_match);
@@ -849,7 +862,9 @@ static const struct platform_device_id sata_rcar_id_table[] = {
849 { "sata_rcar", RCAR_GEN1_SATA }, /* Deprecated by "sata-r8a7779" */ 862 { "sata_rcar", RCAR_GEN1_SATA }, /* Deprecated by "sata-r8a7779" */
850 { "sata-r8a7779", RCAR_GEN1_SATA }, 863 { "sata-r8a7779", RCAR_GEN1_SATA },
851 { "sata-r8a7790", RCAR_GEN2_SATA }, 864 { "sata-r8a7790", RCAR_GEN2_SATA },
865 { "sata-r8a7790-es1", RCAR_R8A7790_ES1_SATA },
852 { "sata-r8a7791", RCAR_GEN2_SATA }, 866 { "sata-r8a7791", RCAR_GEN2_SATA },
867 { "sata-r8a7793", RCAR_GEN2_SATA },
853 { }, 868 { },
854}; 869};
855MODULE_DEVICE_TABLE(platform, sata_rcar_id_table); 870MODULE_DEVICE_TABLE(platform, sata_rcar_id_table);
diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
index 7652e8dc188f..21b0bc6a9c96 100644
--- a/drivers/atm/solos-pci.c
+++ b/drivers/atm/solos-pci.c
@@ -1225,11 +1225,13 @@ static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1225 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE); 1225 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
1226 if (!card->config_regs) { 1226 if (!card->config_regs) {
1227 dev_warn(&dev->dev, "Failed to ioremap config registers\n"); 1227 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
1228 err = -ENOMEM;
1228 goto out_release_regions; 1229 goto out_release_regions;
1229 } 1230 }
1230 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE); 1231 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
1231 if (!card->buffers) { 1232 if (!card->buffers) {
1232 dev_warn(&dev->dev, "Failed to ioremap data buffers\n"); 1233 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
1234 err = -ENOMEM;
1233 goto out_unmap_config; 1235 goto out_unmap_config;
1234 } 1236 }
1235 1237
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 61a33f4ba608..df04227d00cf 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -171,20 +171,23 @@ config WANT_DEV_COREDUMP
171 Drivers should "select" this option if they desire to use the 171 Drivers should "select" this option if they desire to use the
172 device coredump mechanism. 172 device coredump mechanism.
173 173
174config DISABLE_DEV_COREDUMP 174config ALLOW_DEV_COREDUMP
175 bool "Disable device coredump" if EXPERT 175 bool "Allow device coredump" if EXPERT
176 default y
176 help 177 help
177 Disable the device coredump mechanism despite drivers wanting to 178 This option controls if the device coredump mechanism is available or
178 use it; this allows for more sensitive systems or systems that 179 not; if disabled, the mechanism will be omitted even if drivers that
179 don't want to ever access the information to not have the code, 180 can use it are enabled.
180 nor keep any data. 181 Say 'N' for more sensitive systems or systems that don't want
182 to ever access the information to not have the code, nor keep any
183 data.
181 184
182 If unsure, say N. 185 If unsure, say Y.
183 186
184config DEV_COREDUMP 187config DEV_COREDUMP
185 bool 188 bool
186 default y if WANT_DEV_COREDUMP 189 default y if WANT_DEV_COREDUMP
187 depends on !DISABLE_DEV_COREDUMP 190 depends on ALLOW_DEV_COREDUMP
188 191
189config DEBUG_DRIVER 192config DEBUG_DRIVER
190 bool "Driver Core verbose debug messages" 193 bool "Driver Core verbose debug messages"
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 14d162952c3b..842d04707de6 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -724,12 +724,12 @@ class_dir_create_and_add(struct class *class, struct kobject *parent_kobj)
724 return &dir->kobj; 724 return &dir->kobj;
725} 725}
726 726
727static DEFINE_MUTEX(gdp_mutex);
727 728
728static struct kobject *get_device_parent(struct device *dev, 729static struct kobject *get_device_parent(struct device *dev,
729 struct device *parent) 730 struct device *parent)
730{ 731{
731 if (dev->class) { 732 if (dev->class) {
732 static DEFINE_MUTEX(gdp_mutex);
733 struct kobject *kobj = NULL; 733 struct kobject *kobj = NULL;
734 struct kobject *parent_kobj; 734 struct kobject *parent_kobj;
735 struct kobject *k; 735 struct kobject *k;
@@ -793,7 +793,9 @@ static void cleanup_glue_dir(struct device *dev, struct kobject *glue_dir)
793 glue_dir->kset != &dev->class->p->glue_dirs) 793 glue_dir->kset != &dev->class->p->glue_dirs)
794 return; 794 return;
795 795
796 mutex_lock(&gdp_mutex);
796 kobject_put(glue_dir); 797 kobject_put(glue_dir);
798 mutex_unlock(&gdp_mutex);
797} 799}
798 800
799static void cleanup_device_parent(struct device *dev) 801static void cleanup_device_parent(struct device *dev)
diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
index 40bc2f4072cc..fb83d4acd400 100644
--- a/drivers/base/power/domain.c
+++ b/drivers/base/power/domain.c
@@ -361,9 +361,19 @@ static int __pm_genpd_save_device(struct pm_domain_data *pdd,
361 struct device *dev = pdd->dev; 361 struct device *dev = pdd->dev;
362 int ret = 0; 362 int ret = 0;
363 363
364 if (gpd_data->need_restore) 364 if (gpd_data->need_restore > 0)
365 return 0; 365 return 0;
366 366
367 /*
368 * If the value of the need_restore flag is still unknown at this point,
369 * we trust that pm_genpd_poweroff() has verified that the device is
370 * already runtime PM suspended.
371 */
372 if (gpd_data->need_restore < 0) {
373 gpd_data->need_restore = 1;
374 return 0;
375 }
376
367 mutex_unlock(&genpd->lock); 377 mutex_unlock(&genpd->lock);
368 378
369 genpd_start_dev(genpd, dev); 379 genpd_start_dev(genpd, dev);
@@ -373,7 +383,7 @@ static int __pm_genpd_save_device(struct pm_domain_data *pdd,
373 mutex_lock(&genpd->lock); 383 mutex_lock(&genpd->lock);
374 384
375 if (!ret) 385 if (!ret)
376 gpd_data->need_restore = true; 386 gpd_data->need_restore = 1;
377 387
378 return ret; 388 return ret;
379} 389}
@@ -389,12 +399,17 @@ static void __pm_genpd_restore_device(struct pm_domain_data *pdd,
389{ 399{
390 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd); 400 struct generic_pm_domain_data *gpd_data = to_gpd_data(pdd);
391 struct device *dev = pdd->dev; 401 struct device *dev = pdd->dev;
392 bool need_restore = gpd_data->need_restore; 402 int need_restore = gpd_data->need_restore;
393 403
394 gpd_data->need_restore = false; 404 gpd_data->need_restore = 0;
395 mutex_unlock(&genpd->lock); 405 mutex_unlock(&genpd->lock);
396 406
397 genpd_start_dev(genpd, dev); 407 genpd_start_dev(genpd, dev);
408
409 /*
410 * Call genpd_restore_dev() for recently added devices too (need_restore
411 * is negative then).
412 */
398 if (need_restore) 413 if (need_restore)
399 genpd_restore_dev(genpd, dev); 414 genpd_restore_dev(genpd, dev);
400 415
@@ -603,6 +618,7 @@ static void genpd_power_off_work_fn(struct work_struct *work)
603static int pm_genpd_runtime_suspend(struct device *dev) 618static int pm_genpd_runtime_suspend(struct device *dev)
604{ 619{
605 struct generic_pm_domain *genpd; 620 struct generic_pm_domain *genpd;
621 struct generic_pm_domain_data *gpd_data;
606 bool (*stop_ok)(struct device *__dev); 622 bool (*stop_ok)(struct device *__dev);
607 int ret; 623 int ret;
608 624
@@ -628,6 +644,16 @@ static int pm_genpd_runtime_suspend(struct device *dev)
628 return 0; 644 return 0;
629 645
630 mutex_lock(&genpd->lock); 646 mutex_lock(&genpd->lock);
647
648 /*
649 * If we have an unknown state of the need_restore flag, it means none
650 * of the runtime PM callbacks has been invoked yet. Let's update the
651 * flag to reflect that the current state is active.
652 */
653 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
654 if (gpd_data->need_restore < 0)
655 gpd_data->need_restore = 0;
656
631 genpd->in_progress++; 657 genpd->in_progress++;
632 pm_genpd_poweroff(genpd); 658 pm_genpd_poweroff(genpd);
633 genpd->in_progress--; 659 genpd->in_progress--;
@@ -1437,12 +1463,12 @@ int __pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev,
1437 spin_unlock_irq(&dev->power.lock); 1463 spin_unlock_irq(&dev->power.lock);
1438 1464
1439 if (genpd->attach_dev) 1465 if (genpd->attach_dev)
1440 genpd->attach_dev(dev); 1466 genpd->attach_dev(genpd, dev);
1441 1467
1442 mutex_lock(&gpd_data->lock); 1468 mutex_lock(&gpd_data->lock);
1443 gpd_data->base.dev = dev; 1469 gpd_data->base.dev = dev;
1444 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list); 1470 list_add_tail(&gpd_data->base.list_node, &genpd->dev_list);
1445 gpd_data->need_restore = genpd->status == GPD_STATE_POWER_OFF; 1471 gpd_data->need_restore = -1;
1446 gpd_data->td.constraint_changed = true; 1472 gpd_data->td.constraint_changed = true;
1447 gpd_data->td.effective_constraint_ns = -1; 1473 gpd_data->td.effective_constraint_ns = -1;
1448 mutex_unlock(&gpd_data->lock); 1474 mutex_unlock(&gpd_data->lock);
@@ -1499,7 +1525,7 @@ int pm_genpd_remove_device(struct generic_pm_domain *genpd,
1499 genpd->max_off_time_changed = true; 1525 genpd->max_off_time_changed = true;
1500 1526
1501 if (genpd->detach_dev) 1527 if (genpd->detach_dev)
1502 genpd->detach_dev(dev); 1528 genpd->detach_dev(genpd, dev);
1503 1529
1504 spin_lock_irq(&dev->power.lock); 1530 spin_lock_irq(&dev->power.lock);
1505 1531
@@ -1546,7 +1572,7 @@ void pm_genpd_dev_need_restore(struct device *dev, bool val)
1546 1572
1547 psd = dev_to_psd(dev); 1573 psd = dev_to_psd(dev);
1548 if (psd && psd->domain_data) 1574 if (psd && psd->domain_data)
1549 to_gpd_data(psd->domain_data)->need_restore = val; 1575 to_gpd_data(psd->domain_data)->need_restore = val ? 1 : 0;
1550 1576
1551 spin_unlock_irqrestore(&dev->power.lock, flags); 1577 spin_unlock_irqrestore(&dev->power.lock, flags);
1552} 1578}
diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig
index 8a3f51f7b1b9..db9d00c36a3e 100644
--- a/drivers/base/regmap/Kconfig
+++ b/drivers/base/regmap/Kconfig
@@ -3,12 +3,15 @@
3# subsystems should select the appropriate symbols. 3# subsystems should select the appropriate symbols.
4 4
5config REGMAP 5config REGMAP
6 default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_MMIO || REGMAP_IRQ) 6 default y if (REGMAP_I2C || REGMAP_SPI || REGMAP_SPMI || REGMAP_AC97 || REGMAP_MMIO || REGMAP_IRQ)
7 select LZO_COMPRESS 7 select LZO_COMPRESS
8 select LZO_DECOMPRESS 8 select LZO_DECOMPRESS
9 select IRQ_DOMAIN if REGMAP_IRQ 9 select IRQ_DOMAIN if REGMAP_IRQ
10 bool 10 bool
11 11
12config REGMAP_AC97
13 tristate
14
12config REGMAP_I2C 15config REGMAP_I2C
13 tristate 16 tristate
14 depends on I2C 17 depends on I2C
diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile
index a7c670b4123a..0a533653ef3b 100644
--- a/drivers/base/regmap/Makefile
+++ b/drivers/base/regmap/Makefile
@@ -1,6 +1,7 @@
1obj-$(CONFIG_REGMAP) += regmap.o regcache.o 1obj-$(CONFIG_REGMAP) += regmap.o regcache.o
2obj-$(CONFIG_REGMAP) += regcache-rbtree.o regcache-lzo.o regcache-flat.o 2obj-$(CONFIG_REGMAP) += regcache-rbtree.o regcache-lzo.o regcache-flat.o
3obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o 3obj-$(CONFIG_DEBUG_FS) += regmap-debugfs.o
4obj-$(CONFIG_REGMAP_AC97) += regmap-ac97.o
4obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o 5obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
5obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o 6obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o
6obj-$(CONFIG_REGMAP_SPMI) += regmap-spmi.o 7obj-$(CONFIG_REGMAP_SPMI) += regmap-spmi.o
diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c
index d9762e41959b..0246f44ded74 100644
--- a/drivers/base/regmap/regcache-flat.c
+++ b/drivers/base/regmap/regcache-flat.c
@@ -10,9 +10,9 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/slab.h>
14#include <linux/device.h> 13#include <linux/device.h>
15#include <linux/seq_file.h> 14#include <linux/seq_file.h>
15#include <linux/slab.h>
16 16
17#include "internal.h" 17#include "internal.h"
18 18
diff --git a/drivers/base/regmap/regcache-lzo.c b/drivers/base/regmap/regcache-lzo.c
index e210a6d1406a..2d53f6f138e1 100644
--- a/drivers/base/regmap/regcache-lzo.c
+++ b/drivers/base/regmap/regcache-lzo.c
@@ -10,9 +10,9 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/slab.h>
14#include <linux/device.h> 13#include <linux/device.h>
15#include <linux/lzo.h> 14#include <linux/lzo.h>
15#include <linux/slab.h>
16 16
17#include "internal.h" 17#include "internal.h"
18 18
diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c
index f3e8fe0cc650..d453a2c98ad0 100644
--- a/drivers/base/regmap/regcache-rbtree.c
+++ b/drivers/base/regmap/regcache-rbtree.c
@@ -10,11 +10,11 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/slab.h>
14#include <linux/device.h>
15#include <linux/debugfs.h> 13#include <linux/debugfs.h>
14#include <linux/device.h>
16#include <linux/rbtree.h> 15#include <linux/rbtree.h>
17#include <linux/seq_file.h> 16#include <linux/seq_file.h>
17#include <linux/slab.h>
18 18
19#include "internal.h" 19#include "internal.h"
20 20
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index f1280dc356d0..f373c35f9e1d 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -10,12 +10,12 @@
10 * published by the Free Software Foundation. 10 * published by the Free Software Foundation.
11 */ 11 */
12 12
13#include <linux/slab.h>
14#include <linux/export.h>
15#include <linux/device.h>
16#include <trace/events/regmap.h>
17#include <linux/bsearch.h> 13#include <linux/bsearch.h>
14#include <linux/device.h>
15#include <linux/export.h>
16#include <linux/slab.h>
18#include <linux/sort.h> 17#include <linux/sort.h>
18#include <trace/events/regmap.h>
19 19
20#include "internal.h" 20#include "internal.h"
21 21
@@ -36,6 +36,23 @@ static int regcache_hw_init(struct regmap *map)
36 if (!map->num_reg_defaults_raw) 36 if (!map->num_reg_defaults_raw)
37 return -EINVAL; 37 return -EINVAL;
38 38
39 /* calculate the size of reg_defaults */
40 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++)
41 if (!regmap_volatile(map, i * map->reg_stride))
42 count++;
43
44 /* all registers are volatile, so just bypass */
45 if (!count) {
46 map->cache_bypass = true;
47 return 0;
48 }
49
50 map->num_reg_defaults = count;
51 map->reg_defaults = kmalloc_array(count, sizeof(struct reg_default),
52 GFP_KERNEL);
53 if (!map->reg_defaults)
54 return -ENOMEM;
55
39 if (!map->reg_defaults_raw) { 56 if (!map->reg_defaults_raw) {
40 u32 cache_bypass = map->cache_bypass; 57 u32 cache_bypass = map->cache_bypass;
41 dev_warn(map->dev, "No cache defaults, reading back from HW\n"); 58 dev_warn(map->dev, "No cache defaults, reading back from HW\n");
@@ -43,40 +60,25 @@ static int regcache_hw_init(struct regmap *map)
43 /* Bypass the cache access till data read from HW*/ 60 /* Bypass the cache access till data read from HW*/
44 map->cache_bypass = 1; 61 map->cache_bypass = 1;
45 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL); 62 tmp_buf = kmalloc(map->cache_size_raw, GFP_KERNEL);
46 if (!tmp_buf) 63 if (!tmp_buf) {
47 return -EINVAL; 64 ret = -ENOMEM;
65 goto err_free;
66 }
48 ret = regmap_raw_read(map, 0, tmp_buf, 67 ret = regmap_raw_read(map, 0, tmp_buf,
49 map->num_reg_defaults_raw); 68 map->num_reg_defaults_raw);
50 map->cache_bypass = cache_bypass; 69 map->cache_bypass = cache_bypass;
51 if (ret < 0) { 70 if (ret < 0)
52 kfree(tmp_buf); 71 goto err_cache_free;
53 return ret; 72
54 }
55 map->reg_defaults_raw = tmp_buf; 73 map->reg_defaults_raw = tmp_buf;
56 map->cache_free = 1; 74 map->cache_free = 1;
57 } 75 }
58 76
59 /* calculate the size of reg_defaults */
60 for (count = 0, i = 0; i < map->num_reg_defaults_raw; i++) {
61 val = regcache_get_val(map, map->reg_defaults_raw, i);
62 if (regmap_volatile(map, i * map->reg_stride))
63 continue;
64 count++;
65 }
66
67 map->reg_defaults = kmalloc(count * sizeof(struct reg_default),
68 GFP_KERNEL);
69 if (!map->reg_defaults) {
70 ret = -ENOMEM;
71 goto err_free;
72 }
73
74 /* fill the reg_defaults */ 77 /* fill the reg_defaults */
75 map->num_reg_defaults = count;
76 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) { 78 for (i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
77 val = regcache_get_val(map, map->reg_defaults_raw, i);
78 if (regmap_volatile(map, i * map->reg_stride)) 79 if (regmap_volatile(map, i * map->reg_stride))
79 continue; 80 continue;
81 val = regcache_get_val(map, map->reg_defaults_raw, i);
80 map->reg_defaults[j].reg = i * map->reg_stride; 82 map->reg_defaults[j].reg = i * map->reg_stride;
81 map->reg_defaults[j].def = val; 83 map->reg_defaults[j].def = val;
82 j++; 84 j++;
@@ -84,9 +86,10 @@ static int regcache_hw_init(struct regmap *map)
84 86
85 return 0; 87 return 0;
86 88
89err_cache_free:
90 kfree(tmp_buf);
87err_free: 91err_free:
88 if (map->cache_free) 92 kfree(map->reg_defaults);
89 kfree(map->reg_defaults_raw);
90 93
91 return ret; 94 return ret;
92} 95}
@@ -150,6 +153,8 @@ int regcache_init(struct regmap *map, const struct regmap_config *config)
150 ret = regcache_hw_init(map); 153 ret = regcache_hw_init(map);
151 if (ret < 0) 154 if (ret < 0)
152 return ret; 155 return ret;
156 if (map->cache_bypass)
157 return 0;
153 } 158 }
154 159
155 if (!map->max_register) 160 if (!map->max_register)
diff --git a/drivers/base/regmap/regmap-ac97.c b/drivers/base/regmap/regmap-ac97.c
new file mode 100644
index 000000000000..e4c45d2299c1
--- /dev/null
+++ b/drivers/base/regmap/regmap-ac97.c
@@ -0,0 +1,114 @@
1/*
2 * Register map access API - AC'97 support
3 *
4 * Copyright 2013 Linaro Ltd. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <linux/clk.h>
20#include <linux/err.h>
21#include <linux/init.h>
22#include <linux/io.h>
23#include <linux/module.h>
24#include <linux/regmap.h>
25#include <linux/slab.h>
26
27#include <sound/ac97_codec.h>
28
29bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg)
30{
31 switch (reg) {
32 case AC97_RESET:
33 case AC97_POWERDOWN:
34 case AC97_INT_PAGING:
35 case AC97_EXTENDED_ID:
36 case AC97_EXTENDED_STATUS:
37 case AC97_EXTENDED_MID:
38 case AC97_EXTENDED_MSTATUS:
39 case AC97_GPIO_STATUS:
40 case AC97_MISC_AFE:
41 case AC97_VENDOR_ID1:
42 case AC97_VENDOR_ID2:
43 case AC97_CODEC_CLASS_REV:
44 case AC97_PCI_SVID:
45 case AC97_PCI_SID:
46 case AC97_FUNC_SELECT:
47 case AC97_FUNC_INFO:
48 case AC97_SENSE_INFO:
49 return true;
50 default:
51 return false;
52 }
53}
54EXPORT_SYMBOL_GPL(regmap_ac97_default_volatile);
55
56static int regmap_ac97_reg_read(void *context, unsigned int reg,
57 unsigned int *val)
58{
59 struct snd_ac97 *ac97 = context;
60
61 *val = ac97->bus->ops->read(ac97, reg);
62
63 return 0;
64}
65
66static int regmap_ac97_reg_write(void *context, unsigned int reg,
67 unsigned int val)
68{
69 struct snd_ac97 *ac97 = context;
70
71 ac97->bus->ops->write(ac97, reg, val);
72
73 return 0;
74}
75
76static const struct regmap_bus ac97_regmap_bus = {
77 .reg_write = regmap_ac97_reg_write,
78 .reg_read = regmap_ac97_reg_read,
79};
80
81/**
82 * regmap_init_ac97(): Initialise AC'97 register map
83 *
84 * @ac97: Device that will be interacted with
85 * @config: Configuration for register map
86 *
87 * The return value will be an ERR_PTR() on error or a valid pointer to
88 * a struct regmap.
89 */
90struct regmap *regmap_init_ac97(struct snd_ac97 *ac97,
91 const struct regmap_config *config)
92{
93 return regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config);
94}
95EXPORT_SYMBOL_GPL(regmap_init_ac97);
96
97/**
98 * devm_regmap_init_ac97(): Initialise AC'97 register map
99 *
100 * @ac97: Device that will be interacted with
101 * @config: Configuration for register map
102 *
103 * The return value will be an ERR_PTR() on error or a valid pointer
104 * to a struct regmap. The regmap will be automatically freed by the
105 * device management code.
106 */
107struct regmap *devm_regmap_init_ac97(struct snd_ac97 *ac97,
108 const struct regmap_config *config)
109{
110 return devm_regmap_init(&ac97->dev, &ac97_regmap_bus, ac97, config);
111}
112EXPORT_SYMBOL_GPL(devm_regmap_init_ac97);
113
114MODULE_LICENSE("GPL v2");
diff --git a/drivers/block/nvme-scsi.c b/drivers/block/nvme-scsi.c
index a4cd6d691c63..0b4b2775600e 100644
--- a/drivers/block/nvme-scsi.c
+++ b/drivers/block/nvme-scsi.c
@@ -329,7 +329,7 @@ INQUIRY_EVPD_BIT_MASK) ? 1 : 0)
329(GET_U32_FROM_CDB(cdb, READ_CAP_16_CDB_ALLOC_LENGTH_OFFSET)) 329(GET_U32_FROM_CDB(cdb, READ_CAP_16_CDB_ALLOC_LENGTH_OFFSET))
330 330
331#define IS_READ_CAP_16(cdb) \ 331#define IS_READ_CAP_16(cdb) \
332((cdb[0] == SERVICE_ACTION_IN && cdb[1] == SAI_READ_CAPACITY_16) ? 1 : 0) 332((cdb[0] == SERVICE_ACTION_IN_16 && cdb[1] == SAI_READ_CAPACITY_16) ? 1 : 0)
333 333
334/* Request Sense Helper Macros */ 334/* Request Sense Helper Macros */
335#define GET_REQUEST_SENSE_ALLOC_LENGTH(cdb) \ 335#define GET_REQUEST_SENSE_ALLOC_LENGTH(cdb) \
@@ -2947,7 +2947,7 @@ static int nvme_scsi_translate(struct nvme_ns *ns, struct sg_io_hdr *hdr)
2947 case READ_CAPACITY: 2947 case READ_CAPACITY:
2948 retcode = nvme_trans_read_capacity(ns, hdr, cmd); 2948 retcode = nvme_trans_read_capacity(ns, hdr, cmd);
2949 break; 2949 break;
2950 case SERVICE_ACTION_IN: 2950 case SERVICE_ACTION_IN_16:
2951 if (IS_READ_CAP_16(cmd)) 2951 if (IS_READ_CAP_16(cmd))
2952 retcode = nvme_trans_read_capacity(ns, hdr, cmd); 2952 retcode = nvme_trans_read_capacity(ns, hdr, cmd);
2953 else 2953 else
diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 0a54c588e433..27b71a0b72d0 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -342,7 +342,6 @@ struct rbd_device {
342 342
343 struct list_head rq_queue; /* incoming rq queue */ 343 struct list_head rq_queue; /* incoming rq queue */
344 spinlock_t lock; /* queue, flags, open_count */ 344 spinlock_t lock; /* queue, flags, open_count */
345 struct workqueue_struct *rq_wq;
346 struct work_struct rq_work; 345 struct work_struct rq_work;
347 346
348 struct rbd_image_header header; 347 struct rbd_image_header header;
@@ -402,6 +401,8 @@ static struct kmem_cache *rbd_segment_name_cache;
402static int rbd_major; 401static int rbd_major;
403static DEFINE_IDA(rbd_dev_id_ida); 402static DEFINE_IDA(rbd_dev_id_ida);
404 403
404static struct workqueue_struct *rbd_wq;
405
405/* 406/*
406 * Default to false for now, as single-major requires >= 0.75 version of 407 * Default to false for now, as single-major requires >= 0.75 version of
407 * userspace rbd utility. 408 * userspace rbd utility.
@@ -3452,7 +3453,7 @@ static void rbd_request_fn(struct request_queue *q)
3452 } 3453 }
3453 3454
3454 if (queued) 3455 if (queued)
3455 queue_work(rbd_dev->rq_wq, &rbd_dev->rq_work); 3456 queue_work(rbd_wq, &rbd_dev->rq_work);
3456} 3457}
3457 3458
3458/* 3459/*
@@ -3532,7 +3533,7 @@ static int rbd_obj_read_sync(struct rbd_device *rbd_dev,
3532 page_count = (u32) calc_pages_for(offset, length); 3533 page_count = (u32) calc_pages_for(offset, length);
3533 pages = ceph_alloc_page_vector(page_count, GFP_KERNEL); 3534 pages = ceph_alloc_page_vector(page_count, GFP_KERNEL);
3534 if (IS_ERR(pages)) 3535 if (IS_ERR(pages))
3535 ret = PTR_ERR(pages); 3536 return PTR_ERR(pages);
3536 3537
3537 ret = -ENOMEM; 3538 ret = -ENOMEM;
3538 obj_request = rbd_obj_request_create(object_name, offset, length, 3539 obj_request = rbd_obj_request_create(object_name, offset, length,
@@ -5242,16 +5243,9 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev)
5242 set_capacity(rbd_dev->disk, rbd_dev->mapping.size / SECTOR_SIZE); 5243 set_capacity(rbd_dev->disk, rbd_dev->mapping.size / SECTOR_SIZE);
5243 set_disk_ro(rbd_dev->disk, rbd_dev->mapping.read_only); 5244 set_disk_ro(rbd_dev->disk, rbd_dev->mapping.read_only);
5244 5245
5245 rbd_dev->rq_wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 0,
5246 rbd_dev->disk->disk_name);
5247 if (!rbd_dev->rq_wq) {
5248 ret = -ENOMEM;
5249 goto err_out_mapping;
5250 }
5251
5252 ret = rbd_bus_add_dev(rbd_dev); 5246 ret = rbd_bus_add_dev(rbd_dev);
5253 if (ret) 5247 if (ret)
5254 goto err_out_workqueue; 5248 goto err_out_mapping;
5255 5249
5256 /* Everything's ready. Announce the disk to the world. */ 5250 /* Everything's ready. Announce the disk to the world. */
5257 5251
@@ -5263,9 +5257,6 @@ static int rbd_dev_device_setup(struct rbd_device *rbd_dev)
5263 5257
5264 return ret; 5258 return ret;
5265 5259
5266err_out_workqueue:
5267 destroy_workqueue(rbd_dev->rq_wq);
5268 rbd_dev->rq_wq = NULL;
5269err_out_mapping: 5260err_out_mapping:
5270 rbd_dev_mapping_clear(rbd_dev); 5261 rbd_dev_mapping_clear(rbd_dev);
5271err_out_disk: 5262err_out_disk:
@@ -5512,7 +5503,6 @@ static void rbd_dev_device_release(struct device *dev)
5512{ 5503{
5513 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); 5504 struct rbd_device *rbd_dev = dev_to_rbd_dev(dev);
5514 5505
5515 destroy_workqueue(rbd_dev->rq_wq);
5516 rbd_free_disk(rbd_dev); 5506 rbd_free_disk(rbd_dev);
5517 clear_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags); 5507 clear_bit(RBD_DEV_FLAG_EXISTS, &rbd_dev->flags);
5518 rbd_dev_mapping_clear(rbd_dev); 5508 rbd_dev_mapping_clear(rbd_dev);
@@ -5716,11 +5706,21 @@ static int __init rbd_init(void)
5716 if (rc) 5706 if (rc)
5717 return rc; 5707 return rc;
5718 5708
5709 /*
5710 * The number of active work items is limited by the number of
5711 * rbd devices, so leave @max_active at default.
5712 */
5713 rbd_wq = alloc_workqueue(RBD_DRV_NAME, WQ_MEM_RECLAIM, 0);
5714 if (!rbd_wq) {
5715 rc = -ENOMEM;
5716 goto err_out_slab;
5717 }
5718
5719 if (single_major) { 5719 if (single_major) {
5720 rbd_major = register_blkdev(0, RBD_DRV_NAME); 5720 rbd_major = register_blkdev(0, RBD_DRV_NAME);
5721 if (rbd_major < 0) { 5721 if (rbd_major < 0) {
5722 rc = rbd_major; 5722 rc = rbd_major;
5723 goto err_out_slab; 5723 goto err_out_wq;
5724 } 5724 }
5725 } 5725 }
5726 5726
@@ -5738,6 +5738,8 @@ static int __init rbd_init(void)
5738err_out_blkdev: 5738err_out_blkdev:
5739 if (single_major) 5739 if (single_major)
5740 unregister_blkdev(rbd_major, RBD_DRV_NAME); 5740 unregister_blkdev(rbd_major, RBD_DRV_NAME);
5741err_out_wq:
5742 destroy_workqueue(rbd_wq);
5741err_out_slab: 5743err_out_slab:
5742 rbd_slab_exit(); 5744 rbd_slab_exit();
5743 return rc; 5745 return rc;
@@ -5749,6 +5751,7 @@ static void __exit rbd_exit(void)
5749 rbd_sysfs_cleanup(); 5751 rbd_sysfs_cleanup();
5750 if (single_major) 5752 if (single_major)
5751 unregister_blkdev(rbd_major, RBD_DRV_NAME); 5753 unregister_blkdev(rbd_major, RBD_DRV_NAME);
5754 destroy_workqueue(rbd_wq);
5752 rbd_slab_exit(); 5755 rbd_slab_exit();
5753} 5756}
5754 5757
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 2ad0b5bce44b..3920ee45aa59 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -560,7 +560,8 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
560 } 560 }
561 561
562 if (page_zero_filled(uncmem)) { 562 if (page_zero_filled(uncmem)) {
563 kunmap_atomic(user_mem); 563 if (user_mem)
564 kunmap_atomic(user_mem);
564 /* Free memory associated with this sector now. */ 565 /* Free memory associated with this sector now. */
565 bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value); 566 bit_spin_lock(ZRAM_ACCESS, &meta->table[index].value);
566 zram_free_page(zram, index); 567 zram_free_page(zram, index);
diff --git a/drivers/bus/omap_l3_smx.c b/drivers/bus/omap_l3_smx.c
index acc216491b8a..597fdaee7315 100644
--- a/drivers/bus/omap_l3_smx.c
+++ b/drivers/bus/omap_l3_smx.c
@@ -27,6 +27,10 @@
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/io.h> 29#include <linux/io.h>
30#include <linux/module.h>
31#include <linux/of.h>
32#include <linux/of_device.h>
33
30#include "omap_l3_smx.h" 34#include "omap_l3_smx.h"
31 35
32static inline u64 omap3_l3_readll(void __iomem *base, u16 reg) 36static inline u64 omap3_l3_readll(void __iomem *base, u16 reg)
@@ -211,7 +215,17 @@ static irqreturn_t omap3_l3_app_irq(int irq, void *_l3)
211 return ret; 215 return ret;
212} 216}
213 217
214static int __init omap3_l3_probe(struct platform_device *pdev) 218#if IS_BUILTIN(CONFIG_OF)
219static const struct of_device_id omap3_l3_match[] = {
220 {
221 .compatible = "ti,omap3-l3-smx",
222 },
223 { },
224};
225MODULE_DEVICE_TABLE(of, omap3_l3_match);
226#endif
227
228static int omap3_l3_probe(struct platform_device *pdev)
215{ 229{
216 struct omap3_l3 *l3; 230 struct omap3_l3 *l3;
217 struct resource *res; 231 struct resource *res;
@@ -265,7 +279,7 @@ err0:
265 return ret; 279 return ret;
266} 280}
267 281
268static int __exit omap3_l3_remove(struct platform_device *pdev) 282static int omap3_l3_remove(struct platform_device *pdev)
269{ 283{
270 struct omap3_l3 *l3 = platform_get_drvdata(pdev); 284 struct omap3_l3 *l3 = platform_get_drvdata(pdev);
271 285
@@ -278,15 +292,17 @@ static int __exit omap3_l3_remove(struct platform_device *pdev)
278} 292}
279 293
280static struct platform_driver omap3_l3_driver = { 294static struct platform_driver omap3_l3_driver = {
281 .remove = __exit_p(omap3_l3_remove), 295 .probe = omap3_l3_probe,
296 .remove = omap3_l3_remove,
282 .driver = { 297 .driver = {
283 .name = "omap_l3_smx", 298 .name = "omap_l3_smx",
299 .of_match_table = of_match_ptr(omap3_l3_match),
284 }, 300 },
285}; 301};
286 302
287static int __init omap3_l3_init(void) 303static int __init omap3_l3_init(void)
288{ 304{
289 return platform_driver_probe(&omap3_l3_driver, omap3_l3_probe); 305 return platform_driver_register(&omap3_l3_driver);
290} 306}
291postcore_initcall_sync(omap3_l3_init); 307postcore_initcall_sync(omap3_l3_init);
292 308
diff --git a/drivers/char/hw_random/pseries-rng.c b/drivers/char/hw_random/pseries-rng.c
index 6226aa08c36a..bcf86f91800a 100644
--- a/drivers/char/hw_random/pseries-rng.c
+++ b/drivers/char/hw_random/pseries-rng.c
@@ -25,18 +25,21 @@
25#include <asm/vio.h> 25#include <asm/vio.h>
26 26
27 27
28static int pseries_rng_data_read(struct hwrng *rng, u32 *data) 28static int pseries_rng_read(struct hwrng *rng, void *data, size_t max, bool wait)
29{ 29{
30 u64 buffer[PLPAR_HCALL_BUFSIZE];
31 size_t size = max < 8 ? max : 8;
30 int rc; 32 int rc;
31 33
32 rc = plpar_hcall(H_RANDOM, (unsigned long *)data); 34 rc = plpar_hcall(H_RANDOM, (unsigned long *)buffer);
33 if (rc != H_SUCCESS) { 35 if (rc != H_SUCCESS) {
34 pr_err_ratelimited("H_RANDOM call failed %d\n", rc); 36 pr_err_ratelimited("H_RANDOM call failed %d\n", rc);
35 return -EIO; 37 return -EIO;
36 } 38 }
39 memcpy(data, buffer, size);
37 40
38 /* The hypervisor interface returns 64 bits */ 41 /* The hypervisor interface returns 64 bits */
39 return 8; 42 return size;
40} 43}
41 44
42/** 45/**
@@ -55,7 +58,7 @@ static unsigned long pseries_rng_get_desired_dma(struct vio_dev *vdev)
55 58
56static struct hwrng pseries_rng = { 59static struct hwrng pseries_rng = {
57 .name = KBUILD_MODNAME, 60 .name = KBUILD_MODNAME,
58 .data_read = pseries_rng_data_read, 61 .read = pseries_rng_read,
59}; 62};
60 63
61static int __init pseries_rng_probe(struct vio_dev *dev, 64static int __init pseries_rng_probe(struct vio_dev *dev,
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index bfa640023e64..cf7a561fad7c 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -1449,8 +1449,6 @@ static int add_port(struct ports_device *portdev, u32 id)
1449 spin_lock_init(&port->outvq_lock); 1449 spin_lock_init(&port->outvq_lock);
1450 init_waitqueue_head(&port->waitqueue); 1450 init_waitqueue_head(&port->waitqueue);
1451 1451
1452 virtio_device_ready(portdev->vdev);
1453
1454 /* Fill the in_vq with buffers so the host can send us data. */ 1452 /* Fill the in_vq with buffers so the host can send us data. */
1455 nr_added_bufs = fill_queue(port->in_vq, &port->inbuf_lock); 1453 nr_added_bufs = fill_queue(port->in_vq, &port->inbuf_lock);
1456 if (!nr_added_bufs) { 1454 if (!nr_added_bufs) {
@@ -2026,6 +2024,8 @@ static int virtcons_probe(struct virtio_device *vdev)
2026 spin_lock_init(&portdev->ports_lock); 2024 spin_lock_init(&portdev->ports_lock);
2027 INIT_LIST_HEAD(&portdev->ports); 2025 INIT_LIST_HEAD(&portdev->ports);
2028 2026
2027 virtio_device_ready(portdev->vdev);
2028
2029 if (multiport) { 2029 if (multiport) {
2030 unsigned int nr_added_bufs; 2030 unsigned int nr_added_bufs;
2031 2031
diff --git a/drivers/clk/at91/clk-usb.c b/drivers/clk/at91/clk-usb.c
index 24b5b020753a..a23ac0c724f0 100644
--- a/drivers/clk/at91/clk-usb.c
+++ b/drivers/clk/at91/clk-usb.c
@@ -52,29 +52,26 @@ static unsigned long at91sam9x5_clk_usb_recalc_rate(struct clk_hw *hw,
52 52
53 tmp = pmc_read(pmc, AT91_PMC_USB); 53 tmp = pmc_read(pmc, AT91_PMC_USB);
54 usbdiv = (tmp & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT; 54 usbdiv = (tmp & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT;
55 return parent_rate / (usbdiv + 1); 55
56 return DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1));
56} 57}
57 58
58static long at91sam9x5_clk_usb_round_rate(struct clk_hw *hw, unsigned long rate, 59static long at91sam9x5_clk_usb_round_rate(struct clk_hw *hw, unsigned long rate,
59 unsigned long *parent_rate) 60 unsigned long *parent_rate)
60{ 61{
61 unsigned long div; 62 unsigned long div;
62 unsigned long bestrate; 63
63 unsigned long tmp; 64 if (!rate)
65 return -EINVAL;
64 66
65 if (rate >= *parent_rate) 67 if (rate >= *parent_rate)
66 return *parent_rate; 68 return *parent_rate;
67 69
68 div = *parent_rate / rate; 70 div = DIV_ROUND_CLOSEST(*parent_rate, rate);
69 if (div >= SAM9X5_USB_MAX_DIV) 71 if (div > SAM9X5_USB_MAX_DIV + 1)
70 return *parent_rate / (SAM9X5_USB_MAX_DIV + 1); 72 div = SAM9X5_USB_MAX_DIV + 1;
71
72 bestrate = *parent_rate / div;
73 tmp = *parent_rate / (div + 1);
74 if (bestrate - rate > rate - tmp)
75 bestrate = tmp;
76 73
77 return bestrate; 74 return DIV_ROUND_CLOSEST(*parent_rate, div);
78} 75}
79 76
80static int at91sam9x5_clk_usb_set_parent(struct clk_hw *hw, u8 index) 77static int at91sam9x5_clk_usb_set_parent(struct clk_hw *hw, u8 index)
@@ -106,9 +103,13 @@ static int at91sam9x5_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate,
106 u32 tmp; 103 u32 tmp;
107 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw); 104 struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
108 struct at91_pmc *pmc = usb->pmc; 105 struct at91_pmc *pmc = usb->pmc;
109 unsigned long div = parent_rate / rate; 106 unsigned long div;
107
108 if (!rate)
109 return -EINVAL;
110 110
111 if (parent_rate % rate || div < 1 || div >= SAM9X5_USB_MAX_DIV) 111 div = DIV_ROUND_CLOSEST(parent_rate, rate);
112 if (div > SAM9X5_USB_MAX_DIV + 1 || !div)
112 return -EINVAL; 113 return -EINVAL;
113 114
114 tmp = pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_OHCIUSBDIV; 115 tmp = pmc_read(pmc, AT91_PMC_USB) & ~AT91_PMC_OHCIUSBDIV;
@@ -253,7 +254,7 @@ static long at91rm9200_clk_usb_round_rate(struct clk_hw *hw, unsigned long rate,
253 254
254 tmp_parent_rate = rate * usb->divisors[i]; 255 tmp_parent_rate = rate * usb->divisors[i];
255 tmp_parent_rate = __clk_round_rate(parent, tmp_parent_rate); 256 tmp_parent_rate = __clk_round_rate(parent, tmp_parent_rate);
256 tmprate = tmp_parent_rate / usb->divisors[i]; 257 tmprate = DIV_ROUND_CLOSEST(tmp_parent_rate, usb->divisors[i]);
257 if (tmprate < rate) 258 if (tmprate < rate)
258 tmpdiff = rate - tmprate; 259 tmpdiff = rate - tmprate;
259 else 260 else
@@ -281,10 +282,10 @@ static int at91rm9200_clk_usb_set_rate(struct clk_hw *hw, unsigned long rate,
281 struct at91_pmc *pmc = usb->pmc; 282 struct at91_pmc *pmc = usb->pmc;
282 unsigned long div; 283 unsigned long div;
283 284
284 if (!rate || parent_rate % rate) 285 if (!rate)
285 return -EINVAL; 286 return -EINVAL;
286 287
287 div = parent_rate / rate; 288 div = DIV_ROUND_CLOSEST(parent_rate, rate);
288 289
289 for (i = 0; i < RM9200_USB_DIV_TAB_SIZE; i++) { 290 for (i = 0; i < RM9200_USB_DIV_TAB_SIZE; i++) {
290 if (usb->divisors[i] == div) { 291 if (usb->divisors[i] == div) {
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index 18a9de29df0e..c0a842b335c5 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -263,6 +263,14 @@ static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
263 if (!rate) 263 if (!rate)
264 rate = 1; 264 rate = 1;
265 265
266 /* if read only, just return current value */
267 if (divider->flags & CLK_DIVIDER_READ_ONLY) {
268 bestdiv = readl(divider->reg) >> divider->shift;
269 bestdiv &= div_mask(divider);
270 bestdiv = _get_div(divider, bestdiv);
271 return bestdiv;
272 }
273
266 maxdiv = _get_maxdiv(divider); 274 maxdiv = _get_maxdiv(divider);
267 275
268 if (!(__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT)) { 276 if (!(__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT)) {
@@ -361,11 +369,6 @@ const struct clk_ops clk_divider_ops = {
361}; 369};
362EXPORT_SYMBOL_GPL(clk_divider_ops); 370EXPORT_SYMBOL_GPL(clk_divider_ops);
363 371
364const struct clk_ops clk_divider_ro_ops = {
365 .recalc_rate = clk_divider_recalc_rate,
366};
367EXPORT_SYMBOL_GPL(clk_divider_ro_ops);
368
369static struct clk *_register_divider(struct device *dev, const char *name, 372static struct clk *_register_divider(struct device *dev, const char *name,
370 const char *parent_name, unsigned long flags, 373 const char *parent_name, unsigned long flags,
371 void __iomem *reg, u8 shift, u8 width, 374 void __iomem *reg, u8 shift, u8 width,
@@ -391,10 +394,7 @@ static struct clk *_register_divider(struct device *dev, const char *name,
391 } 394 }
392 395
393 init.name = name; 396 init.name = name;
394 if (clk_divider_flags & CLK_DIVIDER_READ_ONLY) 397 init.ops = &clk_divider_ops;
395 init.ops = &clk_divider_ro_ops;
396 else
397 init.ops = &clk_divider_ops;
398 init.flags = flags | CLK_IS_BASIC; 398 init.flags = flags | CLK_IS_BASIC;
399 init.parent_names = (parent_name ? &parent_name: NULL); 399 init.parent_names = (parent_name ? &parent_name: NULL);
400 init.num_parents = (parent_name ? 1 : 0); 400 init.num_parents = (parent_name ? 1 : 0);
diff --git a/drivers/clk/clk-s2mps11.c b/drivers/clk/clk-s2mps11.c
index b7797fb12e12..7bb13af8e214 100644
--- a/drivers/clk/clk-s2mps11.c
+++ b/drivers/clk/clk-s2mps11.c
@@ -23,6 +23,7 @@
23#include <linux/clk-provider.h> 23#include <linux/clk-provider.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/mfd/samsung/s2mps11.h> 25#include <linux/mfd/samsung/s2mps11.h>
26#include <linux/mfd/samsung/s2mps13.h>
26#include <linux/mfd/samsung/s2mps14.h> 27#include <linux/mfd/samsung/s2mps14.h>
27#include <linux/mfd/samsung/s5m8767.h> 28#include <linux/mfd/samsung/s5m8767.h>
28#include <linux/mfd/samsung/core.h> 29#include <linux/mfd/samsung/core.h>
@@ -120,6 +121,24 @@ static struct clk_init_data s2mps11_clks_init[S2MPS11_CLKS_NUM] = {
120 }, 121 },
121}; 122};
122 123
124static struct clk_init_data s2mps13_clks_init[S2MPS11_CLKS_NUM] = {
125 [S2MPS11_CLK_AP] = {
126 .name = "s2mps13_ap",
127 .ops = &s2mps11_clk_ops,
128 .flags = CLK_IS_ROOT,
129 },
130 [S2MPS11_CLK_CP] = {
131 .name = "s2mps13_cp",
132 .ops = &s2mps11_clk_ops,
133 .flags = CLK_IS_ROOT,
134 },
135 [S2MPS11_CLK_BT] = {
136 .name = "s2mps13_bt",
137 .ops = &s2mps11_clk_ops,
138 .flags = CLK_IS_ROOT,
139 },
140};
141
123static struct clk_init_data s2mps14_clks_init[S2MPS11_CLKS_NUM] = { 142static struct clk_init_data s2mps14_clks_init[S2MPS11_CLKS_NUM] = {
124 [S2MPS11_CLK_AP] = { 143 [S2MPS11_CLK_AP] = {
125 .name = "s2mps14_ap", 144 .name = "s2mps14_ap",
@@ -184,6 +203,10 @@ static int s2mps11_clk_probe(struct platform_device *pdev)
184 s2mps11_reg = S2MPS11_REG_RTC_CTRL; 203 s2mps11_reg = S2MPS11_REG_RTC_CTRL;
185 clks_init = s2mps11_clks_init; 204 clks_init = s2mps11_clks_init;
186 break; 205 break;
206 case S2MPS13X:
207 s2mps11_reg = S2MPS13_REG_RTCCTRL;
208 clks_init = s2mps13_clks_init;
209 break;
187 case S2MPS14X: 210 case S2MPS14X:
188 s2mps11_reg = S2MPS14_REG_RTCCTRL; 211 s2mps11_reg = S2MPS14_REG_RTCCTRL;
189 clks_init = s2mps14_clks_init; 212 clks_init = s2mps14_clks_init;
@@ -279,6 +302,7 @@ static int s2mps11_clk_remove(struct platform_device *pdev)
279 302
280static const struct platform_device_id s2mps11_clk_id[] = { 303static const struct platform_device_id s2mps11_clk_id[] = {
281 { "s2mps11-clk", S2MPS11X}, 304 { "s2mps11-clk", S2MPS11X},
305 { "s2mps13-clk", S2MPS13X},
282 { "s2mps14-clk", S2MPS14X}, 306 { "s2mps14-clk", S2MPS14X},
283 { "s5m8767-clk", S5M8767X}, 307 { "s5m8767-clk", S5M8767X},
284 { }, 308 { },
diff --git a/drivers/clk/pxa/clk-pxa27x.c b/drivers/clk/pxa/clk-pxa27x.c
index b345cc791e5d..88b9fe13fa44 100644
--- a/drivers/clk/pxa/clk-pxa27x.c
+++ b/drivers/clk/pxa/clk-pxa27x.c
@@ -322,7 +322,7 @@ static unsigned long clk_pxa27x_memory_get_rate(struct clk_hw *hw,
322 unsigned long ccsr = CCSR; 322 unsigned long ccsr = CCSR;
323 323
324 osc_forced = ccsr & (1 << CCCR_CPDIS_BIT); 324 osc_forced = ccsr & (1 << CCCR_CPDIS_BIT);
325 a = cccr & CCCR_A_BIT; 325 a = cccr & (1 << CCCR_A_BIT);
326 l = ccsr & CCSR_L_MASK; 326 l = ccsr & CCSR_L_MASK;
327 327
328 if (osc_forced || a) 328 if (osc_forced || a)
@@ -341,7 +341,7 @@ static u8 clk_pxa27x_memory_get_parent(struct clk_hw *hw)
341 unsigned long ccsr = CCSR; 341 unsigned long ccsr = CCSR;
342 342
343 osc_forced = ccsr & (1 << CCCR_CPDIS_BIT); 343 osc_forced = ccsr & (1 << CCCR_CPDIS_BIT);
344 a = cccr & CCCR_A_BIT; 344 a = cccr & (1 << CCCR_A_BIT);
345 if (osc_forced) 345 if (osc_forced)
346 return PXA_MEM_13Mhz; 346 return PXA_MEM_13Mhz;
347 if (a) 347 if (a)
diff --git a/drivers/clk/qcom/mmcc-apq8084.c b/drivers/clk/qcom/mmcc-apq8084.c
index dab988ab8cf1..157139a5c1ca 100644
--- a/drivers/clk/qcom/mmcc-apq8084.c
+++ b/drivers/clk/qcom/mmcc-apq8084.c
@@ -3122,7 +3122,7 @@ static struct clk_regmap *mmcc_apq8084_clocks[] = {
3122 [ESC1_CLK_SRC] = &esc1_clk_src.clkr, 3122 [ESC1_CLK_SRC] = &esc1_clk_src.clkr,
3123 [HDMI_CLK_SRC] = &hdmi_clk_src.clkr, 3123 [HDMI_CLK_SRC] = &hdmi_clk_src.clkr,
3124 [VSYNC_CLK_SRC] = &vsync_clk_src.clkr, 3124 [VSYNC_CLK_SRC] = &vsync_clk_src.clkr,
3125 [RBCPR_CLK_SRC] = &rbcpr_clk_src.clkr, 3125 [MMSS_RBCPR_CLK_SRC] = &rbcpr_clk_src.clkr,
3126 [RBBMTIMER_CLK_SRC] = &rbbmtimer_clk_src.clkr, 3126 [RBBMTIMER_CLK_SRC] = &rbbmtimer_clk_src.clkr,
3127 [MAPLE_CLK_SRC] = &maple_clk_src.clkr, 3127 [MAPLE_CLK_SRC] = &maple_clk_src.clkr,
3128 [VDP_CLK_SRC] = &vdp_clk_src.clkr, 3128 [VDP_CLK_SRC] = &vdp_clk_src.clkr,
diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
index 1e68bff481b8..880a266f0143 100644
--- a/drivers/clk/rockchip/clk.c
+++ b/drivers/clk/rockchip/clk.c
@@ -90,9 +90,7 @@ static struct clk *rockchip_clk_register_branch(const char *name,
90 div->width = div_width; 90 div->width = div_width;
91 div->lock = lock; 91 div->lock = lock;
92 div->table = div_table; 92 div->table = div_table;
93 div_ops = (div_flags & CLK_DIVIDER_READ_ONLY) 93 div_ops = &clk_divider_ops;
94 ? &clk_divider_ro_ops
95 : &clk_divider_ops;
96 } 94 }
97 95
98 clk = clk_register_composite(NULL, name, parent_names, num_parents, 96 clk = clk_register_composite(NULL, name, parent_names, num_parents,
diff --git a/drivers/clk/versatile/Makefile b/drivers/clk/versatile/Makefile
index 162e519cb0f9..8ff03744fe98 100644
--- a/drivers/clk/versatile/Makefile
+++ b/drivers/clk/versatile/Makefile
@@ -2,6 +2,5 @@
2obj-$(CONFIG_ICST) += clk-icst.o clk-versatile.o 2obj-$(CONFIG_ICST) += clk-icst.o clk-versatile.o
3obj-$(CONFIG_INTEGRATOR_IMPD1) += clk-impd1.o 3obj-$(CONFIG_INTEGRATOR_IMPD1) += clk-impd1.o
4obj-$(CONFIG_ARCH_REALVIEW) += clk-realview.o 4obj-$(CONFIG_ARCH_REALVIEW) += clk-realview.o
5obj-$(CONFIG_ARCH_VEXPRESS) += clk-vexpress.o
6obj-$(CONFIG_CLK_SP810) += clk-sp810.o 5obj-$(CONFIG_CLK_SP810) += clk-sp810.o
7obj-$(CONFIG_CLK_VEXPRESS_OSC) += clk-vexpress-osc.o 6obj-$(CONFIG_CLK_VEXPRESS_OSC) += clk-vexpress-osc.o
diff --git a/drivers/clk/versatile/clk-vexpress-osc.c b/drivers/clk/versatile/clk-vexpress-osc.c
index 529a59c0fbfa..765f1e0eeeb2 100644
--- a/drivers/clk/versatile/clk-vexpress-osc.c
+++ b/drivers/clk/versatile/clk-vexpress-osc.c
@@ -70,7 +70,6 @@ static struct clk_ops vexpress_osc_ops = {
70 70
71static int vexpress_osc_probe(struct platform_device *pdev) 71static int vexpress_osc_probe(struct platform_device *pdev)
72{ 72{
73 struct clk_lookup *cl = pdev->dev.platform_data; /* Non-DT lookup */
74 struct clk_init_data init; 73 struct clk_init_data init;
75 struct vexpress_osc *osc; 74 struct vexpress_osc *osc;
76 struct clk *clk; 75 struct clk *clk;
@@ -106,12 +105,6 @@ static int vexpress_osc_probe(struct platform_device *pdev)
106 105
107 of_clk_add_provider(pdev->dev.of_node, of_clk_src_simple_get, clk); 106 of_clk_add_provider(pdev->dev.of_node, of_clk_src_simple_get, clk);
108 107
109 /* Only happens for non-DT cases */
110 if (cl) {
111 cl->clk = clk;
112 clkdev_add(cl);
113 }
114
115 dev_dbg(&pdev->dev, "Registered clock '%s'\n", init.name); 108 dev_dbg(&pdev->dev, "Registered clock '%s'\n", init.name);
116 109
117 return 0; 110 return 0;
diff --git a/drivers/clk/versatile/clk-vexpress.c b/drivers/clk/versatile/clk-vexpress.c
deleted file mode 100644
index 2d5e1b4820e0..000000000000
--- a/drivers/clk/versatile/clk-vexpress.c
+++ /dev/null
@@ -1,86 +0,0 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 * GNU General Public License for more details.
10 *
11 * Copyright (C) 2012 ARM Limited
12 */
13
14#include <linux/amba/sp810.h>
15#include <linux/clkdev.h>
16#include <linux/clk-provider.h>
17#include <linux/err.h>
18#include <linux/vexpress.h>
19
20static struct clk *vexpress_sp810_timerclken[4];
21static DEFINE_SPINLOCK(vexpress_sp810_lock);
22
23static void __init vexpress_sp810_init(void __iomem *base)
24{
25 int i;
26
27 if (WARN_ON(!base))
28 return;
29
30 for (i = 0; i < ARRAY_SIZE(vexpress_sp810_timerclken); i++) {
31 char name[12];
32 const char *parents[] = {
33 "v2m:refclk32khz", /* REFCLK */
34 "v2m:refclk1mhz" /* TIMCLK */
35 };
36
37 snprintf(name, ARRAY_SIZE(name), "timerclken%d", i);
38
39 vexpress_sp810_timerclken[i] = clk_register_mux(NULL, name,
40 parents, 2, CLK_SET_RATE_NO_REPARENT,
41 base + SCCTRL, SCCTRL_TIMERENnSEL_SHIFT(i), 1,
42 0, &vexpress_sp810_lock);
43
44 if (WARN_ON(IS_ERR(vexpress_sp810_timerclken[i])))
45 break;
46 }
47}
48
49
50static const char * const vexpress_clk_24mhz_periphs[] __initconst = {
51 "mb:uart0", "mb:uart1", "mb:uart2", "mb:uart3",
52 "mb:mmci", "mb:kmi0", "mb:kmi1"
53};
54
55void __init vexpress_clk_init(void __iomem *sp810_base)
56{
57 struct clk *clk;
58 int i;
59
60 clk = clk_register_fixed_rate(NULL, "dummy_apb_pclk", NULL,
61 CLK_IS_ROOT, 0);
62 WARN_ON(clk_register_clkdev(clk, "apb_pclk", NULL));
63
64 clk = clk_register_fixed_rate(NULL, "v2m:clk_24mhz", NULL,
65 CLK_IS_ROOT, 24000000);
66 for (i = 0; i < ARRAY_SIZE(vexpress_clk_24mhz_periphs); i++)
67 WARN_ON(clk_register_clkdev(clk, NULL,
68 vexpress_clk_24mhz_periphs[i]));
69
70 clk = clk_register_fixed_rate(NULL, "v2m:refclk32khz", NULL,
71 CLK_IS_ROOT, 32768);
72 WARN_ON(clk_register_clkdev(clk, NULL, "v2m:wdt"));
73
74 clk = clk_register_fixed_rate(NULL, "v2m:refclk1mhz", NULL,
75 CLK_IS_ROOT, 1000000);
76
77 vexpress_sp810_init(sp810_base);
78
79 for (i = 0; i < ARRAY_SIZE(vexpress_sp810_timerclken); i++)
80 WARN_ON(clk_set_parent(vexpress_sp810_timerclken[i], clk));
81
82 WARN_ON(clk_register_clkdev(vexpress_sp810_timerclken[0],
83 "v2m-timer0", "sp804"));
84 WARN_ON(clk_register_clkdev(vexpress_sp810_timerclken[1],
85 "v2m-timer1", "sp804"));
86}
diff --git a/drivers/clocksource/sun4i_timer.c b/drivers/clocksource/sun4i_timer.c
index efb17c3ee120..f4a9c0058b4d 100644
--- a/drivers/clocksource/sun4i_timer.c
+++ b/drivers/clocksource/sun4i_timer.c
@@ -182,6 +182,12 @@ static void __init sun4i_timer_init(struct device_node *node)
182 /* Make sure timer is stopped before playing with interrupts */ 182 /* Make sure timer is stopped before playing with interrupts */
183 sun4i_clkevt_time_stop(0); 183 sun4i_clkevt_time_stop(0);
184 184
185 sun4i_clockevent.cpumask = cpu_possible_mask;
186 sun4i_clockevent.irq = irq;
187
188 clockevents_config_and_register(&sun4i_clockevent, rate,
189 TIMER_SYNC_TICKS, 0xffffffff);
190
185 ret = setup_irq(irq, &sun4i_timer_irq); 191 ret = setup_irq(irq, &sun4i_timer_irq);
186 if (ret) 192 if (ret)
187 pr_warn("failed to setup irq %d\n", irq); 193 pr_warn("failed to setup irq %d\n", irq);
@@ -189,12 +195,6 @@ static void __init sun4i_timer_init(struct device_node *node)
189 /* Enable timer0 interrupt */ 195 /* Enable timer0 interrupt */
190 val = readl(timer_base + TIMER_IRQ_EN_REG); 196 val = readl(timer_base + TIMER_IRQ_EN_REG);
191 writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG); 197 writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG);
192
193 sun4i_clockevent.cpumask = cpu_possible_mask;
194 sun4i_clockevent.irq = irq;
195
196 clockevents_config_and_register(&sun4i_clockevent, rate,
197 TIMER_SYNC_TICKS, 0xffffffff);
198} 198}
199CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer", 199CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer",
200 sun4i_timer_init); 200 sun4i_timer_init);
diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
index d5289098b3df..b5b4d4585c9a 100644
--- a/drivers/clocksource/timer-atmel-pit.c
+++ b/drivers/clocksource/timer-atmel-pit.c
@@ -262,35 +262,3 @@ static void __init at91sam926x_pit_dt_init(struct device_node *node)
262} 262}
263CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit", 263CLOCKSOURCE_OF_DECLARE(at91sam926x_pit, "atmel,at91sam9260-pit",
264 at91sam926x_pit_dt_init); 264 at91sam926x_pit_dt_init);
265
266static void __iomem *pit_base_addr;
267
268void __init at91sam926x_pit_init(int irq)
269{
270 struct pit_data *data;
271
272 data = kzalloc(sizeof(*data), GFP_KERNEL);
273 if (!data)
274 panic(pr_fmt("Unable to allocate memory\n"));
275
276 data->base = pit_base_addr;
277
278 data->mck = clk_get(NULL, "mck");
279 if (IS_ERR(data->mck))
280 panic(pr_fmt("Unable to get mck clk\n"));
281
282 data->irq = irq;
283
284 at91sam926x_pit_common_init(data);
285}
286
287void __init at91sam926x_ioremap_pit(u32 addr)
288{
289 if (of_have_populated_dt())
290 return;
291
292 pit_base_addr = ioremap(addr, 16);
293
294 if (!pit_base_addr)
295 panic(pr_fmt("Impossible to ioremap PIT\n"));
296}
diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c
index 23aaf40cf37f..f657c571b18e 100644
--- a/drivers/cpufreq/cpufreq-dt.c
+++ b/drivers/cpufreq/cpufreq-dt.c
@@ -166,8 +166,8 @@ try_again:
166 if (ret == -EPROBE_DEFER) 166 if (ret == -EPROBE_DEFER)
167 dev_dbg(cpu_dev, "cpu%d clock not ready, retry\n", cpu); 167 dev_dbg(cpu_dev, "cpu%d clock not ready, retry\n", cpu);
168 else 168 else
169 dev_err(cpu_dev, "failed to get cpu%d clock: %d\n", ret, 169 dev_err(cpu_dev, "failed to get cpu%d clock: %d\n", cpu,
170 cpu); 170 ret);
171 } else { 171 } else {
172 *cdev = cpu_dev; 172 *cdev = cpu_dev;
173 *creg = cpu_reg; 173 *creg = cpu_reg;
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 644b54e1e7d1..4473eba1d6b0 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1022,7 +1022,8 @@ static struct cpufreq_policy *cpufreq_policy_restore(unsigned int cpu)
1022 1022
1023 read_unlock_irqrestore(&cpufreq_driver_lock, flags); 1023 read_unlock_irqrestore(&cpufreq_driver_lock, flags);
1024 1024
1025 policy->governor = NULL; 1025 if (policy)
1026 policy->governor = NULL;
1026 1027
1027 return policy; 1028 return policy;
1028} 1029}
diff --git a/drivers/crypto/caam/key_gen.c b/drivers/crypto/caam/key_gen.c
index 871703c49d2c..e1eaf4ff9762 100644
--- a/drivers/crypto/caam/key_gen.c
+++ b/drivers/crypto/caam/key_gen.c
@@ -48,23 +48,29 @@ int gen_split_key(struct device *jrdev, u8 *key_out, int split_key_len,
48 u32 *desc; 48 u32 *desc;
49 struct split_key_result result; 49 struct split_key_result result;
50 dma_addr_t dma_addr_in, dma_addr_out; 50 dma_addr_t dma_addr_in, dma_addr_out;
51 int ret = 0; 51 int ret = -ENOMEM;
52 52
53 desc = kmalloc(CAAM_CMD_SZ * 6 + CAAM_PTR_SZ * 2, GFP_KERNEL | GFP_DMA); 53 desc = kmalloc(CAAM_CMD_SZ * 6 + CAAM_PTR_SZ * 2, GFP_KERNEL | GFP_DMA);
54 if (!desc) { 54 if (!desc) {
55 dev_err(jrdev, "unable to allocate key input memory\n"); 55 dev_err(jrdev, "unable to allocate key input memory\n");
56 return -ENOMEM; 56 return ret;
57 } 57 }
58 58
59 init_job_desc(desc, 0);
60
61 dma_addr_in = dma_map_single(jrdev, (void *)key_in, keylen, 59 dma_addr_in = dma_map_single(jrdev, (void *)key_in, keylen,
62 DMA_TO_DEVICE); 60 DMA_TO_DEVICE);
63 if (dma_mapping_error(jrdev, dma_addr_in)) { 61 if (dma_mapping_error(jrdev, dma_addr_in)) {
64 dev_err(jrdev, "unable to map key input memory\n"); 62 dev_err(jrdev, "unable to map key input memory\n");
65 kfree(desc); 63 goto out_free;
66 return -ENOMEM;
67 } 64 }
65
66 dma_addr_out = dma_map_single(jrdev, key_out, split_key_pad_len,
67 DMA_FROM_DEVICE);
68 if (dma_mapping_error(jrdev, dma_addr_out)) {
69 dev_err(jrdev, "unable to map key output memory\n");
70 goto out_unmap_in;
71 }
72
73 init_job_desc(desc, 0);
68 append_key(desc, dma_addr_in, keylen, CLASS_2 | KEY_DEST_CLASS_REG); 74 append_key(desc, dma_addr_in, keylen, CLASS_2 | KEY_DEST_CLASS_REG);
69 75
70 /* Sets MDHA up into an HMAC-INIT */ 76 /* Sets MDHA up into an HMAC-INIT */
@@ -81,13 +87,6 @@ int gen_split_key(struct device *jrdev, u8 *key_out, int split_key_len,
81 * FIFO_STORE with the explicit split-key content store 87 * FIFO_STORE with the explicit split-key content store
82 * (0x26 output type) 88 * (0x26 output type)
83 */ 89 */
84 dma_addr_out = dma_map_single(jrdev, key_out, split_key_pad_len,
85 DMA_FROM_DEVICE);
86 if (dma_mapping_error(jrdev, dma_addr_out)) {
87 dev_err(jrdev, "unable to map key output memory\n");
88 kfree(desc);
89 return -ENOMEM;
90 }
91 append_fifo_store(desc, dma_addr_out, split_key_len, 90 append_fifo_store(desc, dma_addr_out, split_key_len,
92 LDST_CLASS_2_CCB | FIFOST_TYPE_SPLIT_KEK); 91 LDST_CLASS_2_CCB | FIFOST_TYPE_SPLIT_KEK);
93 92
@@ -115,10 +114,10 @@ int gen_split_key(struct device *jrdev, u8 *key_out, int split_key_len,
115 114
116 dma_unmap_single(jrdev, dma_addr_out, split_key_pad_len, 115 dma_unmap_single(jrdev, dma_addr_out, split_key_pad_len,
117 DMA_FROM_DEVICE); 116 DMA_FROM_DEVICE);
117out_unmap_in:
118 dma_unmap_single(jrdev, dma_addr_in, keylen, DMA_TO_DEVICE); 118 dma_unmap_single(jrdev, dma_addr_in, keylen, DMA_TO_DEVICE);
119 119out_free:
120 kfree(desc); 120 kfree(desc);
121
122 return ret; 121 return ret;
123} 122}
124EXPORT_SYMBOL(gen_split_key); 123EXPORT_SYMBOL(gen_split_key);
diff --git a/drivers/crypto/qat/qat_common/adf_accel_devices.h b/drivers/crypto/qat/qat_common/adf_accel_devices.h
index 9282381b03ce..fe7b3f06f6e6 100644
--- a/drivers/crypto/qat/qat_common/adf_accel_devices.h
+++ b/drivers/crypto/qat/qat_common/adf_accel_devices.h
@@ -198,8 +198,7 @@ struct adf_accel_dev {
198 struct dentry *debugfs_dir; 198 struct dentry *debugfs_dir;
199 struct list_head list; 199 struct list_head list;
200 struct module *owner; 200 struct module *owner;
201 uint8_t accel_id;
202 uint8_t numa_node;
203 struct adf_accel_pci accel_pci_dev; 201 struct adf_accel_pci accel_pci_dev;
202 uint8_t accel_id;
204} __packed; 203} __packed;
205#endif 204#endif
diff --git a/drivers/crypto/qat/qat_common/adf_transport.c b/drivers/crypto/qat/qat_common/adf_transport.c
index 5f3fa45348b4..9dd2cb72a4e8 100644
--- a/drivers/crypto/qat/qat_common/adf_transport.c
+++ b/drivers/crypto/qat/qat_common/adf_transport.c
@@ -419,9 +419,10 @@ static int adf_init_bank(struct adf_accel_dev *accel_dev,
419 WRITE_CSR_RING_BASE(csr_addr, bank_num, i, 0); 419 WRITE_CSR_RING_BASE(csr_addr, bank_num, i, 0);
420 ring = &bank->rings[i]; 420 ring = &bank->rings[i];
421 if (hw_data->tx_rings_mask & (1 << i)) { 421 if (hw_data->tx_rings_mask & (1 << i)) {
422 ring->inflights = kzalloc_node(sizeof(atomic_t), 422 ring->inflights =
423 GFP_KERNEL, 423 kzalloc_node(sizeof(atomic_t),
424 accel_dev->numa_node); 424 GFP_KERNEL,
425 dev_to_node(&GET_DEV(accel_dev)));
425 if (!ring->inflights) 426 if (!ring->inflights)
426 goto err; 427 goto err;
427 } else { 428 } else {
@@ -469,13 +470,14 @@ int adf_init_etr_data(struct adf_accel_dev *accel_dev)
469 int i, ret; 470 int i, ret;
470 471
471 etr_data = kzalloc_node(sizeof(*etr_data), GFP_KERNEL, 472 etr_data = kzalloc_node(sizeof(*etr_data), GFP_KERNEL,
472 accel_dev->numa_node); 473 dev_to_node(&GET_DEV(accel_dev)));
473 if (!etr_data) 474 if (!etr_data)
474 return -ENOMEM; 475 return -ENOMEM;
475 476
476 num_banks = GET_MAX_BANKS(accel_dev); 477 num_banks = GET_MAX_BANKS(accel_dev);
477 size = num_banks * sizeof(struct adf_etr_bank_data); 478 size = num_banks * sizeof(struct adf_etr_bank_data);
478 etr_data->banks = kzalloc_node(size, GFP_KERNEL, accel_dev->numa_node); 479 etr_data->banks = kzalloc_node(size, GFP_KERNEL,
480 dev_to_node(&GET_DEV(accel_dev)));
479 if (!etr_data->banks) { 481 if (!etr_data->banks) {
480 ret = -ENOMEM; 482 ret = -ENOMEM;
481 goto err_bank; 483 goto err_bank;
diff --git a/drivers/crypto/qat/qat_common/qat_algs.c b/drivers/crypto/qat/qat_common/qat_algs.c
index f2e2f158cfbe..9e9619cd4a79 100644
--- a/drivers/crypto/qat/qat_common/qat_algs.c
+++ b/drivers/crypto/qat/qat_common/qat_algs.c
@@ -596,7 +596,8 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst,
596 if (unlikely(!n)) 596 if (unlikely(!n))
597 return -EINVAL; 597 return -EINVAL;
598 598
599 bufl = kmalloc_node(sz, GFP_ATOMIC, inst->accel_dev->numa_node); 599 bufl = kmalloc_node(sz, GFP_ATOMIC,
600 dev_to_node(&GET_DEV(inst->accel_dev)));
600 if (unlikely(!bufl)) 601 if (unlikely(!bufl))
601 return -ENOMEM; 602 return -ENOMEM;
602 603
@@ -605,6 +606,8 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst,
605 goto err; 606 goto err;
606 607
607 for_each_sg(assoc, sg, assoc_n, i) { 608 for_each_sg(assoc, sg, assoc_n, i) {
609 if (!sg->length)
610 continue;
608 bufl->bufers[bufs].addr = dma_map_single(dev, 611 bufl->bufers[bufs].addr = dma_map_single(dev,
609 sg_virt(sg), 612 sg_virt(sg),
610 sg->length, 613 sg->length,
@@ -640,7 +643,7 @@ static int qat_alg_sgl_to_bufl(struct qat_crypto_instance *inst,
640 struct qat_alg_buf *bufers; 643 struct qat_alg_buf *bufers;
641 644
642 buflout = kmalloc_node(sz, GFP_ATOMIC, 645 buflout = kmalloc_node(sz, GFP_ATOMIC,
643 inst->accel_dev->numa_node); 646 dev_to_node(&GET_DEV(inst->accel_dev)));
644 if (unlikely(!buflout)) 647 if (unlikely(!buflout))
645 goto err; 648 goto err;
646 bloutp = dma_map_single(dev, buflout, sz, DMA_TO_DEVICE); 649 bloutp = dma_map_single(dev, buflout, sz, DMA_TO_DEVICE);
diff --git a/drivers/crypto/qat/qat_common/qat_crypto.c b/drivers/crypto/qat/qat_common/qat_crypto.c
index 0d59bcb50de1..828f2a686aab 100644
--- a/drivers/crypto/qat/qat_common/qat_crypto.c
+++ b/drivers/crypto/qat/qat_common/qat_crypto.c
@@ -109,12 +109,14 @@ struct qat_crypto_instance *qat_crypto_get_instance_node(int node)
109 109
110 list_for_each(itr, adf_devmgr_get_head()) { 110 list_for_each(itr, adf_devmgr_get_head()) {
111 accel_dev = list_entry(itr, struct adf_accel_dev, list); 111 accel_dev = list_entry(itr, struct adf_accel_dev, list);
112 if (accel_dev->numa_node == node && adf_dev_started(accel_dev)) 112 if ((node == dev_to_node(&GET_DEV(accel_dev)) ||
113 dev_to_node(&GET_DEV(accel_dev)) < 0)
114 && adf_dev_started(accel_dev))
113 break; 115 break;
114 accel_dev = NULL; 116 accel_dev = NULL;
115 } 117 }
116 if (!accel_dev) { 118 if (!accel_dev) {
117 pr_err("QAT: Could not find device on give node\n"); 119 pr_err("QAT: Could not find device on node %d\n", node);
118 accel_dev = adf_devmgr_get_first(); 120 accel_dev = adf_devmgr_get_first();
119 } 121 }
120 if (!accel_dev || !adf_dev_started(accel_dev)) 122 if (!accel_dev || !adf_dev_started(accel_dev))
@@ -164,7 +166,7 @@ static int qat_crypto_create_instances(struct adf_accel_dev *accel_dev)
164 166
165 for (i = 0; i < num_inst; i++) { 167 for (i = 0; i < num_inst; i++) {
166 inst = kzalloc_node(sizeof(*inst), GFP_KERNEL, 168 inst = kzalloc_node(sizeof(*inst), GFP_KERNEL,
167 accel_dev->numa_node); 169 dev_to_node(&GET_DEV(accel_dev)));
168 if (!inst) 170 if (!inst)
169 goto err; 171 goto err;
170 172
diff --git a/drivers/crypto/qat/qat_dh895xcc/adf_admin.c b/drivers/crypto/qat/qat_dh895xcc/adf_admin.c
index 978d6c56639d..53c491b59f07 100644
--- a/drivers/crypto/qat/qat_dh895xcc/adf_admin.c
+++ b/drivers/crypto/qat/qat_dh895xcc/adf_admin.c
@@ -108,7 +108,7 @@ int adf_init_admin_comms(struct adf_accel_dev *accel_dev)
108 uint64_t reg_val; 108 uint64_t reg_val;
109 109
110 admin = kzalloc_node(sizeof(*accel_dev->admin), GFP_KERNEL, 110 admin = kzalloc_node(sizeof(*accel_dev->admin), GFP_KERNEL,
111 accel_dev->numa_node); 111 dev_to_node(&GET_DEV(accel_dev)));
112 if (!admin) 112 if (!admin)
113 return -ENOMEM; 113 return -ENOMEM;
114 admin->virt_addr = dma_zalloc_coherent(&GET_DEV(accel_dev), PAGE_SIZE, 114 admin->virt_addr = dma_zalloc_coherent(&GET_DEV(accel_dev), PAGE_SIZE,
diff --git a/drivers/crypto/qat/qat_dh895xcc/adf_drv.c b/drivers/crypto/qat/qat_dh895xcc/adf_drv.c
index 0d0435a41be9..948f66be262b 100644
--- a/drivers/crypto/qat/qat_dh895xcc/adf_drv.c
+++ b/drivers/crypto/qat/qat_dh895xcc/adf_drv.c
@@ -119,21 +119,6 @@ static void adf_cleanup_accel(struct adf_accel_dev *accel_dev)
119 kfree(accel_dev); 119 kfree(accel_dev);
120} 120}
121 121
122static uint8_t adf_get_dev_node_id(struct pci_dev *pdev)
123{
124 unsigned int bus_per_cpu = 0;
125 struct cpuinfo_x86 *c = &cpu_data(num_online_cpus() - 1);
126
127 if (!c->phys_proc_id)
128 return 0;
129
130 bus_per_cpu = 256 / (c->phys_proc_id + 1);
131
132 if (bus_per_cpu != 0)
133 return pdev->bus->number / bus_per_cpu;
134 return 0;
135}
136
137static int qat_dev_start(struct adf_accel_dev *accel_dev) 122static int qat_dev_start(struct adf_accel_dev *accel_dev)
138{ 123{
139 int cpus = num_online_cpus(); 124 int cpus = num_online_cpus();
@@ -235,7 +220,6 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
235 void __iomem *pmisc_bar_addr = NULL; 220 void __iomem *pmisc_bar_addr = NULL;
236 char name[ADF_DEVICE_NAME_LENGTH]; 221 char name[ADF_DEVICE_NAME_LENGTH];
237 unsigned int i, bar_nr; 222 unsigned int i, bar_nr;
238 uint8_t node;
239 int ret; 223 int ret;
240 224
241 switch (ent->device) { 225 switch (ent->device) {
@@ -246,12 +230,19 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
246 return -ENODEV; 230 return -ENODEV;
247 } 231 }
248 232
249 node = adf_get_dev_node_id(pdev); 233 if (num_possible_nodes() > 1 && dev_to_node(&pdev->dev) < 0) {
250 accel_dev = kzalloc_node(sizeof(*accel_dev), GFP_KERNEL, node); 234 /* If the accelerator is connected to a node with no memory
235 * there is no point in using the accelerator since the remote
236 * memory transaction will be very slow. */
237 dev_err(&pdev->dev, "Invalid NUMA configuration.\n");
238 return -EINVAL;
239 }
240
241 accel_dev = kzalloc_node(sizeof(*accel_dev), GFP_KERNEL,
242 dev_to_node(&pdev->dev));
251 if (!accel_dev) 243 if (!accel_dev)
252 return -ENOMEM; 244 return -ENOMEM;
253 245
254 accel_dev->numa_node = node;
255 INIT_LIST_HEAD(&accel_dev->crypto_list); 246 INIT_LIST_HEAD(&accel_dev->crypto_list);
256 247
257 /* Add accel device to accel table. 248 /* Add accel device to accel table.
@@ -264,7 +255,8 @@ static int adf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
264 255
265 accel_dev->owner = THIS_MODULE; 256 accel_dev->owner = THIS_MODULE;
266 /* Allocate and configure device configuration structure */ 257 /* Allocate and configure device configuration structure */
267 hw_data = kzalloc_node(sizeof(*hw_data), GFP_KERNEL, node); 258 hw_data = kzalloc_node(sizeof(*hw_data), GFP_KERNEL,
259 dev_to_node(&pdev->dev));
268 if (!hw_data) { 260 if (!hw_data) {
269 ret = -ENOMEM; 261 ret = -ENOMEM;
270 goto out_err; 262 goto out_err;
diff --git a/drivers/crypto/qat/qat_dh895xcc/adf_isr.c b/drivers/crypto/qat/qat_dh895xcc/adf_isr.c
index 67ec61e51185..d96ee21b9b77 100644
--- a/drivers/crypto/qat/qat_dh895xcc/adf_isr.c
+++ b/drivers/crypto/qat/qat_dh895xcc/adf_isr.c
@@ -168,7 +168,7 @@ static int adf_isr_alloc_msix_entry_table(struct adf_accel_dev *accel_dev)
168 uint32_t msix_num_entries = hw_data->num_banks + 1; 168 uint32_t msix_num_entries = hw_data->num_banks + 1;
169 169
170 entries = kzalloc_node(msix_num_entries * sizeof(*entries), 170 entries = kzalloc_node(msix_num_entries * sizeof(*entries),
171 GFP_KERNEL, accel_dev->numa_node); 171 GFP_KERNEL, dev_to_node(&GET_DEV(accel_dev)));
172 if (!entries) 172 if (!entries)
173 return -ENOMEM; 173 return -ENOMEM;
174 174
diff --git a/drivers/dma/edma.c b/drivers/dma/edma.c
index 123f578d6dd3..4cfaaa5a49be 100644
--- a/drivers/dma/edma.c
+++ b/drivers/dma/edma.c
@@ -1107,52 +1107,14 @@ bool edma_filter_fn(struct dma_chan *chan, void *param)
1107} 1107}
1108EXPORT_SYMBOL(edma_filter_fn); 1108EXPORT_SYMBOL(edma_filter_fn);
1109 1109
1110static struct platform_device *pdev0, *pdev1;
1111
1112static const struct platform_device_info edma_dev_info0 = {
1113 .name = "edma-dma-engine",
1114 .id = 0,
1115 .dma_mask = DMA_BIT_MASK(32),
1116};
1117
1118static const struct platform_device_info edma_dev_info1 = {
1119 .name = "edma-dma-engine",
1120 .id = 1,
1121 .dma_mask = DMA_BIT_MASK(32),
1122};
1123
1124static int edma_init(void) 1110static int edma_init(void)
1125{ 1111{
1126 int ret = platform_driver_register(&edma_driver); 1112 return platform_driver_register(&edma_driver);
1127
1128 if (ret == 0) {
1129 pdev0 = platform_device_register_full(&edma_dev_info0);
1130 if (IS_ERR(pdev0)) {
1131 platform_driver_unregister(&edma_driver);
1132 ret = PTR_ERR(pdev0);
1133 goto out;
1134 }
1135 }
1136
1137 if (!of_have_populated_dt() && EDMA_CTLRS == 2) {
1138 pdev1 = platform_device_register_full(&edma_dev_info1);
1139 if (IS_ERR(pdev1)) {
1140 platform_driver_unregister(&edma_driver);
1141 platform_device_unregister(pdev0);
1142 ret = PTR_ERR(pdev1);
1143 }
1144 }
1145
1146out:
1147 return ret;
1148} 1113}
1149subsys_initcall(edma_init); 1114subsys_initcall(edma_init);
1150 1115
1151static void __exit edma_exit(void) 1116static void __exit edma_exit(void)
1152{ 1117{
1153 platform_device_unregister(pdev0);
1154 if (pdev1)
1155 platform_device_unregister(pdev1);
1156 platform_driver_unregister(&edma_driver); 1118 platform_driver_unregister(&edma_driver);
1157} 1119}
1158module_exit(edma_exit); 1120module_exit(edma_exit);
diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 4839bfa74a10..19a99743cf52 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -271,7 +271,7 @@ struct pl330_config {
271#define DMAC_MODE_NS (1 << 0) 271#define DMAC_MODE_NS (1 << 0)
272 unsigned int mode; 272 unsigned int mode;
273 unsigned int data_bus_width:10; /* In number of bits */ 273 unsigned int data_bus_width:10; /* In number of bits */
274 unsigned int data_buf_dep:10; 274 unsigned int data_buf_dep:11;
275 unsigned int num_chan:4; 275 unsigned int num_chan:4;
276 unsigned int num_peri:6; 276 unsigned int num_peri:6;
277 u32 peri_ns; 277 u32 peri_ns;
@@ -2336,7 +2336,7 @@ static inline int get_burst_len(struct dma_pl330_desc *desc, size_t len)
2336 int burst_len; 2336 int burst_len;
2337 2337
2338 burst_len = pl330->pcfg.data_bus_width / 8; 2338 burst_len = pl330->pcfg.data_bus_width / 8;
2339 burst_len *= pl330->pcfg.data_buf_dep; 2339 burst_len *= pl330->pcfg.data_buf_dep / pl330->pcfg.num_chan;
2340 burst_len >>= desc->rqcfg.brst_size; 2340 burst_len >>= desc->rqcfg.brst_size;
2341 2341
2342 /* src/dst_burst_len can't be more than 16 */ 2342 /* src/dst_burst_len can't be more than 16 */
@@ -2459,16 +2459,25 @@ pl330_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
2459 /* Select max possible burst size */ 2459 /* Select max possible burst size */
2460 burst = pl330->pcfg.data_bus_width / 8; 2460 burst = pl330->pcfg.data_bus_width / 8;
2461 2461
2462 while (burst > 1) { 2462 /*
2463 if (!(len % burst)) 2463 * Make sure we use a burst size that aligns with all the memcpy
2464 break; 2464 * parameters because our DMA programming algorithm doesn't cope with
2465 * transfers which straddle an entry in the DMA device's MFIFO.
2466 */
2467 while ((src | dst | len) & (burst - 1))
2465 burst /= 2; 2468 burst /= 2;
2466 }
2467 2469
2468 desc->rqcfg.brst_size = 0; 2470 desc->rqcfg.brst_size = 0;
2469 while (burst != (1 << desc->rqcfg.brst_size)) 2471 while (burst != (1 << desc->rqcfg.brst_size))
2470 desc->rqcfg.brst_size++; 2472 desc->rqcfg.brst_size++;
2471 2473
2474 /*
2475 * If burst size is smaller than bus width then make sure we only
2476 * transfer one at a time to avoid a burst stradling an MFIFO entry.
2477 */
2478 if (desc->rqcfg.brst_size * 8 < pl330->pcfg.data_bus_width)
2479 desc->rqcfg.brst_len = 1;
2480
2472 desc->rqcfg.brst_len = get_burst_len(desc, len); 2481 desc->rqcfg.brst_len = get_burst_len(desc, len);
2473 2482
2474 desc->txd.flags = flags; 2483 desc->txd.flags = flags;
@@ -2732,7 +2741,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
2732 2741
2733 2742
2734 dev_info(&adev->dev, 2743 dev_info(&adev->dev,
2735 "Loaded driver for PL330 DMAC-%d\n", adev->periphid); 2744 "Loaded driver for PL330 DMAC-%x\n", adev->periphid);
2736 dev_info(&adev->dev, 2745 dev_info(&adev->dev,
2737 "\tDBUFF-%ux%ubytes Num_Chans-%u Num_Peri-%u Num_Events-%u\n", 2746 "\tDBUFF-%ux%ubytes Num_Chans-%u Num_Peri-%u Num_Events-%u\n",
2738 pcfg->data_buf_dep, pcfg->data_bus_width / 8, pcfg->num_chan, 2747 pcfg->data_buf_dep, pcfg->data_bus_width / 8, pcfg->num_chan,
diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c
index 3aa10b328254..91292f5513ff 100644
--- a/drivers/dma/sun6i-dma.c
+++ b/drivers/dma/sun6i-dma.c
@@ -230,30 +230,25 @@ static inline void sun6i_dma_dump_chan_regs(struct sun6i_dma_dev *sdev,
230 readl(pchan->base + DMA_CHAN_CUR_PARA)); 230 readl(pchan->base + DMA_CHAN_CUR_PARA));
231} 231}
232 232
233static inline int convert_burst(u32 maxburst, u8 *burst) 233static inline s8 convert_burst(u32 maxburst)
234{ 234{
235 switch (maxburst) { 235 switch (maxburst) {
236 case 1: 236 case 1:
237 *burst = 0; 237 return 0;
238 break;
239 case 8: 238 case 8:
240 *burst = 2; 239 return 2;
241 break;
242 default: 240 default:
243 return -EINVAL; 241 return -EINVAL;
244 } 242 }
245
246 return 0;
247} 243}
248 244
249static inline int convert_buswidth(enum dma_slave_buswidth addr_width, u8 *width) 245static inline s8 convert_buswidth(enum dma_slave_buswidth addr_width)
250{ 246{
251 if ((addr_width < DMA_SLAVE_BUSWIDTH_1_BYTE) || 247 if ((addr_width < DMA_SLAVE_BUSWIDTH_1_BYTE) ||
252 (addr_width > DMA_SLAVE_BUSWIDTH_4_BYTES)) 248 (addr_width > DMA_SLAVE_BUSWIDTH_4_BYTES))
253 return -EINVAL; 249 return -EINVAL;
254 250
255 *width = addr_width >> 1; 251 return addr_width >> 1;
256 return 0;
257} 252}
258 253
259static void *sun6i_dma_lli_add(struct sun6i_dma_lli *prev, 254static void *sun6i_dma_lli_add(struct sun6i_dma_lli *prev,
@@ -284,26 +279,25 @@ static inline int sun6i_dma_cfg_lli(struct sun6i_dma_lli *lli,
284 struct dma_slave_config *config) 279 struct dma_slave_config *config)
285{ 280{
286 u8 src_width, dst_width, src_burst, dst_burst; 281 u8 src_width, dst_width, src_burst, dst_burst;
287 int ret;
288 282
289 if (!config) 283 if (!config)
290 return -EINVAL; 284 return -EINVAL;
291 285
292 ret = convert_burst(config->src_maxburst, &src_burst); 286 src_burst = convert_burst(config->src_maxburst);
293 if (ret) 287 if (src_burst)
294 return ret; 288 return src_burst;
295 289
296 ret = convert_burst(config->dst_maxburst, &dst_burst); 290 dst_burst = convert_burst(config->dst_maxburst);
297 if (ret) 291 if (dst_burst)
298 return ret; 292 return dst_burst;
299 293
300 ret = convert_buswidth(config->src_addr_width, &src_width); 294 src_width = convert_buswidth(config->src_addr_width);
301 if (ret) 295 if (src_width)
302 return ret; 296 return src_width;
303 297
304 ret = convert_buswidth(config->dst_addr_width, &dst_width); 298 dst_width = convert_buswidth(config->dst_addr_width);
305 if (ret) 299 if (dst_width)
306 return ret; 300 return dst_width;
307 301
308 lli->cfg = DMA_CHAN_CFG_SRC_BURST(src_burst) | 302 lli->cfg = DMA_CHAN_CFG_SRC_BURST(src_burst) |
309 DMA_CHAN_CFG_SRC_WIDTH(src_width) | 303 DMA_CHAN_CFG_SRC_WIDTH(src_width) |
@@ -542,11 +536,10 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_memcpy(
542{ 536{
543 struct sun6i_dma_dev *sdev = to_sun6i_dma_dev(chan->device); 537 struct sun6i_dma_dev *sdev = to_sun6i_dma_dev(chan->device);
544 struct sun6i_vchan *vchan = to_sun6i_vchan(chan); 538 struct sun6i_vchan *vchan = to_sun6i_vchan(chan);
545 struct dma_slave_config *sconfig = &vchan->cfg;
546 struct sun6i_dma_lli *v_lli; 539 struct sun6i_dma_lli *v_lli;
547 struct sun6i_desc *txd; 540 struct sun6i_desc *txd;
548 dma_addr_t p_lli; 541 dma_addr_t p_lli;
549 int ret; 542 s8 burst, width;
550 543
551 dev_dbg(chan2dev(chan), 544 dev_dbg(chan2dev(chan),
552 "%s; chan: %d, dest: %pad, src: %pad, len: %zu. flags: 0x%08lx\n", 545 "%s; chan: %d, dest: %pad, src: %pad, len: %zu. flags: 0x%08lx\n",
@@ -565,14 +558,21 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_memcpy(
565 goto err_txd_free; 558 goto err_txd_free;
566 } 559 }
567 560
568 ret = sun6i_dma_cfg_lli(v_lli, src, dest, len, sconfig); 561 v_lli->src = src;
569 if (ret) 562 v_lli->dst = dest;
570 goto err_dma_free; 563 v_lli->len = len;
564 v_lli->para = NORMAL_WAIT;
571 565
566 burst = convert_burst(8);
567 width = convert_buswidth(DMA_SLAVE_BUSWIDTH_4_BYTES);
572 v_lli->cfg |= DMA_CHAN_CFG_SRC_DRQ(DRQ_SDRAM) | 568 v_lli->cfg |= DMA_CHAN_CFG_SRC_DRQ(DRQ_SDRAM) |
573 DMA_CHAN_CFG_DST_DRQ(DRQ_SDRAM) | 569 DMA_CHAN_CFG_DST_DRQ(DRQ_SDRAM) |
574 DMA_CHAN_CFG_DST_LINEAR_MODE | 570 DMA_CHAN_CFG_DST_LINEAR_MODE |
575 DMA_CHAN_CFG_SRC_LINEAR_MODE; 571 DMA_CHAN_CFG_SRC_LINEAR_MODE |
572 DMA_CHAN_CFG_SRC_BURST(burst) |
573 DMA_CHAN_CFG_SRC_WIDTH(width) |
574 DMA_CHAN_CFG_DST_BURST(burst) |
575 DMA_CHAN_CFG_DST_WIDTH(width);
576 576
577 sun6i_dma_lli_add(NULL, v_lli, p_lli, txd); 577 sun6i_dma_lli_add(NULL, v_lli, p_lli, txd);
578 578
@@ -580,8 +580,6 @@ static struct dma_async_tx_descriptor *sun6i_dma_prep_dma_memcpy(
580 580
581 return vchan_tx_prep(&vchan->vc, &txd->vd, flags); 581 return vchan_tx_prep(&vchan->vc, &txd->vd, flags);
582 582
583err_dma_free:
584 dma_pool_free(sdev->pool, v_lli, p_lli);
585err_txd_free: 583err_txd_free:
586 kfree(txd); 584 kfree(txd);
587 return NULL; 585 return NULL;
@@ -915,6 +913,7 @@ static int sun6i_dma_probe(struct platform_device *pdev)
915 sdc->slave.device_prep_dma_memcpy = sun6i_dma_prep_dma_memcpy; 913 sdc->slave.device_prep_dma_memcpy = sun6i_dma_prep_dma_memcpy;
916 sdc->slave.device_control = sun6i_dma_control; 914 sdc->slave.device_control = sun6i_dma_control;
917 sdc->slave.chancnt = NR_MAX_VCHANS; 915 sdc->slave.chancnt = NR_MAX_VCHANS;
916 sdc->slave.copy_align = 4;
918 917
919 sdc->slave.dev = &pdev->dev; 918 sdc->slave.dev = &pdev->dev;
920 919
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 7072c2892d63..49c265255a07 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -61,14 +61,14 @@ config EDAC_DECODE_MCE
61 has been initialized. 61 has been initialized.
62 62
63config EDAC_MCE_INJ 63config EDAC_MCE_INJ
64 tristate "Simple MCE injection interface over /sysfs" 64 tristate "Simple MCE injection interface"
65 depends on EDAC_DECODE_MCE 65 depends on EDAC_DECODE_MCE && DEBUG_FS
66 default n 66 default n
67 help 67 help
68 This is a simple interface to inject MCEs over /sysfs and test 68 This is a simple debugfs interface to inject MCEs and test different
69 the MCE decoding code in EDAC. 69 aspects of the MCE handling code.
70 70
71 This is currently AMD-only. 71 WARNING: Do not even assume this interface is staying stable!
72 72
73config EDAC_MM_EDAC 73config EDAC_MM_EDAC
74 tristate "Main Memory EDAC (Error Detection And Correction) reporting" 74 tristate "Main Memory EDAC (Error Detection And Correction) reporting"
@@ -105,11 +105,11 @@ config EDAC_GHES
105 In doubt, say 'Y'. 105 In doubt, say 'Y'.
106 106
107config EDAC_AMD64 107config EDAC_AMD64
108 tristate "AMD64 (Opteron, Athlon64) K8, F10h" 108 tristate "AMD64 (Opteron, Athlon64)"
109 depends on EDAC_MM_EDAC && AMD_NB && X86_64 && EDAC_DECODE_MCE 109 depends on EDAC_MM_EDAC && AMD_NB && EDAC_DECODE_MCE
110 help 110 help
111 Support for error detection and correction of DRAM ECC errors on 111 Support for error detection and correction of DRAM ECC errors on
112 the AMD64 families of memory controllers (K8 and F10h) 112 the AMD64 families (>= K8) of memory controllers.
113 113
114config EDAC_AMD64_ERROR_INJECTION 114config EDAC_AMD64_ERROR_INJECTION
115 bool "Sysfs HW Error injection facilities" 115 bool "Sysfs HW Error injection facilities"
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index 359aa499b200..d40c69a04df7 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -9,7 +9,7 @@
9obj-$(CONFIG_EDAC) := edac_stub.o 9obj-$(CONFIG_EDAC) := edac_stub.o
10obj-$(CONFIG_EDAC_MM_EDAC) += edac_core.o 10obj-$(CONFIG_EDAC_MM_EDAC) += edac_core.o
11 11
12edac_core-y := edac_mc.o edac_device.o edac_mc_sysfs.o edac_pci_sysfs.o 12edac_core-y := edac_mc.o edac_device.o edac_mc_sysfs.o
13edac_core-y += edac_module.o edac_device_sysfs.o 13edac_core-y += edac_module.o edac_device_sysfs.o
14 14
15ifdef CONFIG_PCI 15ifdef CONFIG_PCI
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index bbd65149cdb2..17638d7cf5c2 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -692,9 +692,19 @@ static void debug_dump_dramcfg_low(struct amd64_pvt *pvt, u32 dclr, int chan)
692{ 692{
693 edac_dbg(1, "F2x%d90 (DRAM Cfg Low): 0x%08x\n", chan, dclr); 693 edac_dbg(1, "F2x%d90 (DRAM Cfg Low): 0x%08x\n", chan, dclr);
694 694
695 edac_dbg(1, " DIMM type: %sbuffered; all DIMMs support ECC: %s\n", 695 if (pvt->dram_type == MEM_LRDDR3) {
696 (dclr & BIT(16)) ? "un" : "", 696 u32 dcsm = pvt->csels[chan].csmasks[0];
697 (dclr & BIT(19)) ? "yes" : "no"); 697 /*
698 * It's assumed all LRDIMMs in a DCT are going to be of
699 * same 'type' until proven otherwise. So, use a cs
700 * value of '0' here to get dcsm value.
701 */
702 edac_dbg(1, " LRDIMM %dx rank multiply\n", (dcsm & 0x3));
703 }
704
705 edac_dbg(1, "All DIMMs support ECC:%s\n",
706 (dclr & BIT(19)) ? "yes" : "no");
707
698 708
699 edac_dbg(1, " PAR/ERR parity: %s\n", 709 edac_dbg(1, " PAR/ERR parity: %s\n",
700 (dclr & BIT(8)) ? "enabled" : "disabled"); 710 (dclr & BIT(8)) ? "enabled" : "disabled");
@@ -756,7 +766,7 @@ static void prep_chip_selects(struct amd64_pvt *pvt)
756 if (pvt->fam == 0xf && pvt->ext_model < K8_REV_F) { 766 if (pvt->fam == 0xf && pvt->ext_model < K8_REV_F) {
757 pvt->csels[0].b_cnt = pvt->csels[1].b_cnt = 8; 767 pvt->csels[0].b_cnt = pvt->csels[1].b_cnt = 8;
758 pvt->csels[0].m_cnt = pvt->csels[1].m_cnt = 8; 768 pvt->csels[0].m_cnt = pvt->csels[1].m_cnt = 8;
759 } else if (pvt->fam == 0x15 && pvt->model >= 0x30) { 769 } else if (pvt->fam == 0x15 && pvt->model == 0x30) {
760 pvt->csels[0].b_cnt = pvt->csels[1].b_cnt = 4; 770 pvt->csels[0].b_cnt = pvt->csels[1].b_cnt = 4;
761 pvt->csels[0].m_cnt = pvt->csels[1].m_cnt = 2; 771 pvt->csels[0].m_cnt = pvt->csels[1].m_cnt = 2;
762 } else { 772 } else {
@@ -813,25 +823,63 @@ static void read_dct_base_mask(struct amd64_pvt *pvt)
813 } 823 }
814} 824}
815 825
816static enum mem_type determine_memory_type(struct amd64_pvt *pvt, int cs) 826static void determine_memory_type(struct amd64_pvt *pvt)
817{ 827{
818 enum mem_type type; 828 u32 dram_ctrl, dcsm;
819 829
820 /* F15h supports only DDR3 */ 830 switch (pvt->fam) {
821 if (pvt->fam >= 0x15) 831 case 0xf:
822 type = (pvt->dclr0 & BIT(16)) ? MEM_DDR3 : MEM_RDDR3; 832 if (pvt->ext_model >= K8_REV_F)
823 else if (pvt->fam == 0x10 || pvt->ext_model >= K8_REV_F) { 833 goto ddr3;
834
835 pvt->dram_type = (pvt->dclr0 & BIT(18)) ? MEM_DDR : MEM_RDDR;
836 return;
837
838 case 0x10:
824 if (pvt->dchr0 & DDR3_MODE) 839 if (pvt->dchr0 & DDR3_MODE)
825 type = (pvt->dclr0 & BIT(16)) ? MEM_DDR3 : MEM_RDDR3; 840 goto ddr3;
841
842 pvt->dram_type = (pvt->dclr0 & BIT(16)) ? MEM_DDR2 : MEM_RDDR2;
843 return;
844
845 case 0x15:
846 if (pvt->model < 0x60)
847 goto ddr3;
848
849 /*
850 * Model 0x60h needs special handling:
851 *
852 * We use a Chip Select value of '0' to obtain dcsm.
853 * Theoretically, it is possible to populate LRDIMMs of different
854 * 'Rank' value on a DCT. But this is not the common case. So,
855 * it's reasonable to assume all DIMMs are going to be of same
856 * 'type' until proven otherwise.
857 */
858 amd64_read_dct_pci_cfg(pvt, 0, DRAM_CONTROL, &dram_ctrl);
859 dcsm = pvt->csels[0].csmasks[0];
860
861 if (((dram_ctrl >> 8) & 0x7) == 0x2)
862 pvt->dram_type = MEM_DDR4;
863 else if (pvt->dclr0 & BIT(16))
864 pvt->dram_type = MEM_DDR3;
865 else if (dcsm & 0x3)
866 pvt->dram_type = MEM_LRDDR3;
826 else 867 else
827 type = (pvt->dclr0 & BIT(16)) ? MEM_DDR2 : MEM_RDDR2; 868 pvt->dram_type = MEM_RDDR3;
828 } else {
829 type = (pvt->dclr0 & BIT(18)) ? MEM_DDR : MEM_RDDR;
830 }
831 869
832 amd64_info("CS%d: %s\n", cs, edac_mem_types[type]); 870 return;
833 871
834 return type; 872 case 0x16:
873 goto ddr3;
874
875 default:
876 WARN(1, KERN_ERR "%s: Family??? 0x%x\n", __func__, pvt->fam);
877 pvt->dram_type = MEM_EMPTY;
878 }
879 return;
880
881ddr3:
882 pvt->dram_type = (pvt->dclr0 & BIT(16)) ? MEM_DDR3 : MEM_RDDR3;
835} 883}
836 884
837/* Get the number of DCT channels the memory controller is using. */ 885/* Get the number of DCT channels the memory controller is using. */
@@ -958,8 +1006,12 @@ static void read_dram_base_limit_regs(struct amd64_pvt *pvt, unsigned range)
958 if (WARN_ON(!nb)) 1006 if (WARN_ON(!nb))
959 return; 1007 return;
960 1008
961 pci_func = (pvt->model == 0x30) ? PCI_DEVICE_ID_AMD_15H_M30H_NB_F1 1009 if (pvt->model == 0x60)
962 : PCI_DEVICE_ID_AMD_15H_NB_F1; 1010 pci_func = PCI_DEVICE_ID_AMD_15H_M60H_NB_F1;
1011 else if (pvt->model == 0x30)
1012 pci_func = PCI_DEVICE_ID_AMD_15H_M30H_NB_F1;
1013 else
1014 pci_func = PCI_DEVICE_ID_AMD_15H_NB_F1;
963 1015
964 f1 = pci_get_related_function(nb->misc->vendor, pci_func, nb->misc); 1016 f1 = pci_get_related_function(nb->misc->vendor, pci_func, nb->misc);
965 if (WARN_ON(!f1)) 1017 if (WARN_ON(!f1))
@@ -1049,7 +1101,7 @@ static int ddr2_cs_size(unsigned i, bool dct_width)
1049} 1101}
1050 1102
1051static int k8_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct, 1103static int k8_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct,
1052 unsigned cs_mode) 1104 unsigned cs_mode, int cs_mask_nr)
1053{ 1105{
1054 u32 dclr = dct ? pvt->dclr1 : pvt->dclr0; 1106 u32 dclr = dct ? pvt->dclr1 : pvt->dclr0;
1055 1107
@@ -1167,8 +1219,43 @@ static int ddr3_cs_size(unsigned i, bool dct_width)
1167 return cs_size; 1219 return cs_size;
1168} 1220}
1169 1221
1222static int ddr3_lrdimm_cs_size(unsigned i, unsigned rank_multiply)
1223{
1224 unsigned shift = 0;
1225 int cs_size = 0;
1226
1227 if (i < 4 || i == 6)
1228 cs_size = -1;
1229 else if (i == 12)
1230 shift = 7;
1231 else if (!(i & 0x1))
1232 shift = i >> 1;
1233 else
1234 shift = (i + 1) >> 1;
1235
1236 if (cs_size != -1)
1237 cs_size = rank_multiply * (128 << shift);
1238
1239 return cs_size;
1240}
1241
1242static int ddr4_cs_size(unsigned i)
1243{
1244 int cs_size = 0;
1245
1246 if (i == 0)
1247 cs_size = -1;
1248 else if (i == 1)
1249 cs_size = 1024;
1250 else
1251 /* Min cs_size = 1G */
1252 cs_size = 1024 * (1 << (i >> 1));
1253
1254 return cs_size;
1255}
1256
1170static int f10_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct, 1257static int f10_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct,
1171 unsigned cs_mode) 1258 unsigned cs_mode, int cs_mask_nr)
1172{ 1259{
1173 u32 dclr = dct ? pvt->dclr1 : pvt->dclr0; 1260 u32 dclr = dct ? pvt->dclr1 : pvt->dclr0;
1174 1261
@@ -1184,18 +1271,49 @@ static int f10_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct,
1184 * F15h supports only 64bit DCT interfaces 1271 * F15h supports only 64bit DCT interfaces
1185 */ 1272 */
1186static int f15_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct, 1273static int f15_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct,
1187 unsigned cs_mode) 1274 unsigned cs_mode, int cs_mask_nr)
1188{ 1275{
1189 WARN_ON(cs_mode > 12); 1276 WARN_ON(cs_mode > 12);
1190 1277
1191 return ddr3_cs_size(cs_mode, false); 1278 return ddr3_cs_size(cs_mode, false);
1192} 1279}
1193 1280
1281/* F15h M60h supports DDR4 mapping as well.. */
1282static int f15_m60h_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct,
1283 unsigned cs_mode, int cs_mask_nr)
1284{
1285 int cs_size;
1286 u32 dcsm = pvt->csels[dct].csmasks[cs_mask_nr];
1287
1288 WARN_ON(cs_mode > 12);
1289
1290 if (pvt->dram_type == MEM_DDR4) {
1291 if (cs_mode > 9)
1292 return -1;
1293
1294 cs_size = ddr4_cs_size(cs_mode);
1295 } else if (pvt->dram_type == MEM_LRDDR3) {
1296 unsigned rank_multiply = dcsm & 0xf;
1297
1298 if (rank_multiply == 3)
1299 rank_multiply = 4;
1300 cs_size = ddr3_lrdimm_cs_size(cs_mode, rank_multiply);
1301 } else {
1302 /* Minimum cs size is 512mb for F15hM60h*/
1303 if (cs_mode == 0x1)
1304 return -1;
1305
1306 cs_size = ddr3_cs_size(cs_mode, false);
1307 }
1308
1309 return cs_size;
1310}
1311
1194/* 1312/*
1195 * F16h and F15h model 30h have only limited cs_modes. 1313 * F16h and F15h model 30h have only limited cs_modes.
1196 */ 1314 */
1197static int f16_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct, 1315static int f16_dbam_to_chip_select(struct amd64_pvt *pvt, u8 dct,
1198 unsigned cs_mode) 1316 unsigned cs_mode, int cs_mask_nr)
1199{ 1317{
1200 WARN_ON(cs_mode > 12); 1318 WARN_ON(cs_mode > 12);
1201 1319
@@ -1757,13 +1875,20 @@ static void debug_display_dimm_sizes(struct amd64_pvt *pvt, u8 ctrl)
1757 1875
1758 size0 = 0; 1876 size0 = 0;
1759 if (dcsb[dimm*2] & DCSB_CS_ENABLE) 1877 if (dcsb[dimm*2] & DCSB_CS_ENABLE)
1878 /* For f15m60h, need multiplier for LRDIMM cs_size
1879 * calculation. We pass 'dimm' value to the dbam_to_cs
1880 * mapper so we can find the multiplier from the
1881 * corresponding DCSM.
1882 */
1760 size0 = pvt->ops->dbam_to_cs(pvt, ctrl, 1883 size0 = pvt->ops->dbam_to_cs(pvt, ctrl,
1761 DBAM_DIMM(dimm, dbam)); 1884 DBAM_DIMM(dimm, dbam),
1885 dimm);
1762 1886
1763 size1 = 0; 1887 size1 = 0;
1764 if (dcsb[dimm*2 + 1] & DCSB_CS_ENABLE) 1888 if (dcsb[dimm*2 + 1] & DCSB_CS_ENABLE)
1765 size1 = pvt->ops->dbam_to_cs(pvt, ctrl, 1889 size1 = pvt->ops->dbam_to_cs(pvt, ctrl,
1766 DBAM_DIMM(dimm, dbam)); 1890 DBAM_DIMM(dimm, dbam),
1891 dimm);
1767 1892
1768 amd64_info(EDAC_MC ": %d: %5dMB %d: %5dMB\n", 1893 amd64_info(EDAC_MC ": %d: %5dMB %d: %5dMB\n",
1769 dimm * 2, size0, 1894 dimm * 2, size0,
@@ -1812,6 +1937,16 @@ static struct amd64_family_type family_types[] = {
1812 .dbam_to_cs = f16_dbam_to_chip_select, 1937 .dbam_to_cs = f16_dbam_to_chip_select,
1813 } 1938 }
1814 }, 1939 },
1940 [F15_M60H_CPUS] = {
1941 .ctl_name = "F15h_M60h",
1942 .f1_id = PCI_DEVICE_ID_AMD_15H_M60H_NB_F1,
1943 .f3_id = PCI_DEVICE_ID_AMD_15H_M60H_NB_F3,
1944 .ops = {
1945 .early_channel_count = f1x_early_channel_count,
1946 .map_sysaddr_to_csrow = f1x_map_sysaddr_to_csrow,
1947 .dbam_to_cs = f15_m60h_dbam_to_chip_select,
1948 }
1949 },
1815 [F16_CPUS] = { 1950 [F16_CPUS] = {
1816 .ctl_name = "F16h", 1951 .ctl_name = "F16h",
1817 .f1_id = PCI_DEVICE_ID_AMD_16H_NB_F1, 1952 .f1_id = PCI_DEVICE_ID_AMD_16H_NB_F1,
@@ -2175,6 +2310,8 @@ static void read_mc_regs(struct amd64_pvt *pvt)
2175 } 2310 }
2176 2311
2177 pvt->ecc_sym_sz = 4; 2312 pvt->ecc_sym_sz = 4;
2313 determine_memory_type(pvt);
2314 edac_dbg(1, " DIMM type: %s\n", edac_mem_types[pvt->dram_type]);
2178 2315
2179 if (pvt->fam >= 0x10) { 2316 if (pvt->fam >= 0x10) {
2180 amd64_read_pci_cfg(pvt->F3, EXT_NB_MCA_CFG, &tmp); 2317 amd64_read_pci_cfg(pvt->F3, EXT_NB_MCA_CFG, &tmp);
@@ -2238,7 +2375,8 @@ static u32 get_csrow_nr_pages(struct amd64_pvt *pvt, u8 dct, int csrow_nr)
2238 */ 2375 */
2239 cs_mode = DBAM_DIMM(csrow_nr / 2, dbam); 2376 cs_mode = DBAM_DIMM(csrow_nr / 2, dbam);
2240 2377
2241 nr_pages = pvt->ops->dbam_to_cs(pvt, dct, cs_mode) << (20 - PAGE_SHIFT); 2378 nr_pages = pvt->ops->dbam_to_cs(pvt, dct, cs_mode, (csrow_nr / 2))
2379 << (20 - PAGE_SHIFT);
2242 2380
2243 edac_dbg(0, "csrow: %d, channel: %d, DBAM idx: %d\n", 2381 edac_dbg(0, "csrow: %d, channel: %d, DBAM idx: %d\n",
2244 csrow_nr, dct, cs_mode); 2382 csrow_nr, dct, cs_mode);
@@ -2257,7 +2395,6 @@ static int init_csrows(struct mem_ctl_info *mci)
2257 struct csrow_info *csrow; 2395 struct csrow_info *csrow;
2258 struct dimm_info *dimm; 2396 struct dimm_info *dimm;
2259 enum edac_type edac_mode; 2397 enum edac_type edac_mode;
2260 enum mem_type mtype;
2261 int i, j, empty = 1; 2398 int i, j, empty = 1;
2262 int nr_pages = 0; 2399 int nr_pages = 0;
2263 u32 val; 2400 u32 val;
@@ -2302,8 +2439,6 @@ static int init_csrows(struct mem_ctl_info *mci)
2302 nr_pages += row_dct1_pages; 2439 nr_pages += row_dct1_pages;
2303 } 2440 }
2304 2441
2305 mtype = determine_memory_type(pvt, i);
2306
2307 edac_dbg(1, "Total csrow%d pages: %u\n", i, nr_pages); 2442 edac_dbg(1, "Total csrow%d pages: %u\n", i, nr_pages);
2308 2443
2309 /* 2444 /*
@@ -2317,7 +2452,7 @@ static int init_csrows(struct mem_ctl_info *mci)
2317 2452
2318 for (j = 0; j < pvt->channel_count; j++) { 2453 for (j = 0; j < pvt->channel_count; j++) {
2319 dimm = csrow->channels[j]->dimm; 2454 dimm = csrow->channels[j]->dimm;
2320 dimm->mtype = mtype; 2455 dimm->mtype = pvt->dram_type;
2321 dimm->edac_mode = edac_mode; 2456 dimm->edac_mode = edac_mode;
2322 } 2457 }
2323 } 2458 }
@@ -2604,6 +2739,10 @@ static struct amd64_family_type *per_family_init(struct amd64_pvt *pvt)
2604 fam_type = &family_types[F15_M30H_CPUS]; 2739 fam_type = &family_types[F15_M30H_CPUS];
2605 pvt->ops = &family_types[F15_M30H_CPUS].ops; 2740 pvt->ops = &family_types[F15_M30H_CPUS].ops;
2606 break; 2741 break;
2742 } else if (pvt->model == 0x60) {
2743 fam_type = &family_types[F15_M60H_CPUS];
2744 pvt->ops = &family_types[F15_M60H_CPUS].ops;
2745 break;
2607 } 2746 }
2608 2747
2609 fam_type = &family_types[F15_CPUS]; 2748 fam_type = &family_types[F15_CPUS];
@@ -2828,55 +2967,13 @@ static void remove_one_instance(struct pci_dev *pdev)
2828 * inquiry this table to see if this driver is for a given device found. 2967 * inquiry this table to see if this driver is for a given device found.
2829 */ 2968 */
2830static const struct pci_device_id amd64_pci_table[] = { 2969static const struct pci_device_id amd64_pci_table[] = {
2831 { 2970 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_K8_NB_MEMCTL) },
2832 .vendor = PCI_VENDOR_ID_AMD, 2971 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_10H_NB_DRAM) },
2833 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL, 2972 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F2) },
2834 .subvendor = PCI_ANY_ID, 2973 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F2) },
2835 .subdevice = PCI_ANY_ID, 2974 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M60H_NB_F2) },
2836 .class = 0, 2975 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F2) },
2837 .class_mask = 0, 2976 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F2) },
2838 },
2839 {
2840 .vendor = PCI_VENDOR_ID_AMD,
2841 .device = PCI_DEVICE_ID_AMD_10H_NB_DRAM,
2842 .subvendor = PCI_ANY_ID,
2843 .subdevice = PCI_ANY_ID,
2844 .class = 0,
2845 .class_mask = 0,
2846 },
2847 {
2848 .vendor = PCI_VENDOR_ID_AMD,
2849 .device = PCI_DEVICE_ID_AMD_15H_NB_F2,
2850 .subvendor = PCI_ANY_ID,
2851 .subdevice = PCI_ANY_ID,
2852 .class = 0,
2853 .class_mask = 0,
2854 },
2855 {
2856 .vendor = PCI_VENDOR_ID_AMD,
2857 .device = PCI_DEVICE_ID_AMD_15H_M30H_NB_F2,
2858 .subvendor = PCI_ANY_ID,
2859 .subdevice = PCI_ANY_ID,
2860 .class = 0,
2861 .class_mask = 0,
2862 },
2863 {
2864 .vendor = PCI_VENDOR_ID_AMD,
2865 .device = PCI_DEVICE_ID_AMD_16H_NB_F2,
2866 .subvendor = PCI_ANY_ID,
2867 .subdevice = PCI_ANY_ID,
2868 .class = 0,
2869 .class_mask = 0,
2870 },
2871 {
2872 .vendor = PCI_VENDOR_ID_AMD,
2873 .device = PCI_DEVICE_ID_AMD_16H_M30H_NB_F2,
2874 .subvendor = PCI_ANY_ID,
2875 .subdevice = PCI_ANY_ID,
2876 .class = 0,
2877 .class_mask = 0,
2878 },
2879
2880 {0, } 2977 {0, }
2881}; 2978};
2882MODULE_DEVICE_TABLE(pci, amd64_pci_table); 2979MODULE_DEVICE_TABLE(pci, amd64_pci_table);
@@ -2938,6 +3035,11 @@ static int __init amd64_edac_init(void)
2938 goto err_no_instances; 3035 goto err_no_instances;
2939 3036
2940 setup_pci_device(); 3037 setup_pci_device();
3038
3039#ifdef CONFIG_X86_32
3040 amd64_err("%s on 32-bit is unsupported. USE AT YOUR OWN RISK!\n", EDAC_MOD_STR);
3041#endif
3042
2941 return 0; 3043 return 0;
2942 3044
2943err_no_instances: 3045err_no_instances:
diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h
index 55fb5941c6d4..d8468c667925 100644
--- a/drivers/edac/amd64_edac.h
+++ b/drivers/edac/amd64_edac.h
@@ -162,10 +162,12 @@
162/* 162/*
163 * PCI-defined configuration space registers 163 * PCI-defined configuration space registers
164 */ 164 */
165#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F1 0x141b
166#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F2 0x141c
167#define PCI_DEVICE_ID_AMD_15H_NB_F1 0x1601 165#define PCI_DEVICE_ID_AMD_15H_NB_F1 0x1601
168#define PCI_DEVICE_ID_AMD_15H_NB_F2 0x1602 166#define PCI_DEVICE_ID_AMD_15H_NB_F2 0x1602
167#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F1 0x141b
168#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F2 0x141c
169#define PCI_DEVICE_ID_AMD_15H_M60H_NB_F1 0x1571
170#define PCI_DEVICE_ID_AMD_15H_M60H_NB_F2 0x1572
169#define PCI_DEVICE_ID_AMD_16H_NB_F1 0x1531 171#define PCI_DEVICE_ID_AMD_16H_NB_F1 0x1531
170#define PCI_DEVICE_ID_AMD_16H_NB_F2 0x1532 172#define PCI_DEVICE_ID_AMD_16H_NB_F2 0x1532
171#define PCI_DEVICE_ID_AMD_16H_M30H_NB_F1 0x1581 173#define PCI_DEVICE_ID_AMD_16H_M30H_NB_F1 0x1581
@@ -221,6 +223,8 @@
221 223
222#define csrow_enabled(i, dct, pvt) ((pvt)->csels[(dct)].csbases[(i)] & DCSB_CS_ENABLE) 224#define csrow_enabled(i, dct, pvt) ((pvt)->csels[(dct)].csbases[(i)] & DCSB_CS_ENABLE)
223 225
226#define DRAM_CONTROL 0x78
227
224#define DBAM0 0x80 228#define DBAM0 0x80
225#define DBAM1 0x180 229#define DBAM1 0x180
226 230
@@ -301,6 +305,7 @@ enum amd_families {
301 F10_CPUS, 305 F10_CPUS,
302 F15_CPUS, 306 F15_CPUS,
303 F15_M30H_CPUS, 307 F15_M30H_CPUS,
308 F15_M60H_CPUS,
304 F16_CPUS, 309 F16_CPUS,
305 F16_M30H_CPUS, 310 F16_M30H_CPUS,
306 NUM_FAMILIES, 311 NUM_FAMILIES,
@@ -379,6 +384,9 @@ struct amd64_pvt {
379 384
380 /* place to store error injection parameters prior to issue */ 385 /* place to store error injection parameters prior to issue */
381 struct error_injection injection; 386 struct error_injection injection;
387
388 /* cache the dram_type */
389 enum mem_type dram_type;
382}; 390};
383 391
384enum err_codes { 392enum err_codes {
@@ -480,7 +488,8 @@ struct low_ops {
480 int (*early_channel_count) (struct amd64_pvt *pvt); 488 int (*early_channel_count) (struct amd64_pvt *pvt);
481 void (*map_sysaddr_to_csrow) (struct mem_ctl_info *mci, u64 sys_addr, 489 void (*map_sysaddr_to_csrow) (struct mem_ctl_info *mci, u64 sys_addr,
482 struct err_info *); 490 struct err_info *);
483 int (*dbam_to_cs) (struct amd64_pvt *pvt, u8 dct, unsigned cs_mode); 491 int (*dbam_to_cs) (struct amd64_pvt *pvt, u8 dct,
492 unsigned cs_mode, int cs_mask_nr);
484}; 493};
485 494
486struct amd64_family_type { 495struct amd64_family_type {
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index c3893b0ddb18..1747906f10ce 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -125,27 +125,27 @@ static void edac_mc_dump_mci(struct mem_ctl_info *mci)
125 125
126#endif /* CONFIG_EDAC_DEBUG */ 126#endif /* CONFIG_EDAC_DEBUG */
127 127
128/*
129 * keep those in sync with the enum mem_type
130 */
131const char * const edac_mem_types[] = { 128const char * const edac_mem_types[] = {
132 "Empty csrow", 129 [MEM_EMPTY] = "Empty csrow",
133 "Reserved csrow type", 130 [MEM_RESERVED] = "Reserved csrow type",
134 "Unknown csrow type", 131 [MEM_UNKNOWN] = "Unknown csrow type",
135 "Fast page mode RAM", 132 [MEM_FPM] = "Fast page mode RAM",
136 "Extended data out RAM", 133 [MEM_EDO] = "Extended data out RAM",
137 "Burst Extended data out RAM", 134 [MEM_BEDO] = "Burst Extended data out RAM",
138 "Single data rate SDRAM", 135 [MEM_SDR] = "Single data rate SDRAM",
139 "Registered single data rate SDRAM", 136 [MEM_RDR] = "Registered single data rate SDRAM",
140 "Double data rate SDRAM", 137 [MEM_DDR] = "Double data rate SDRAM",
141 "Registered Double data rate SDRAM", 138 [MEM_RDDR] = "Registered Double data rate SDRAM",
142 "Rambus DRAM", 139 [MEM_RMBS] = "Rambus DRAM",
143 "Unbuffered DDR2 RAM", 140 [MEM_DDR2] = "Unbuffered DDR2 RAM",
144 "Fully buffered DDR2", 141 [MEM_FB_DDR2] = "Fully buffered DDR2",
145 "Registered DDR2 RAM", 142 [MEM_RDDR2] = "Registered DDR2 RAM",
146 "Rambus XDR", 143 [MEM_XDR] = "Rambus XDR",
147 "Unbuffered DDR3 RAM", 144 [MEM_DDR3] = "Unbuffered DDR3 RAM",
148 "Registered DDR3 RAM", 145 [MEM_RDDR3] = "Registered DDR3 RAM",
146 [MEM_LRDDR3] = "Load-Reduced DDR3 RAM",
147 [MEM_DDR4] = "Unbuffered DDR4 RAM",
148 [MEM_RDDR4] = "Registered DDR4 RAM",
149}; 149};
150EXPORT_SYMBOL_GPL(edac_mem_types); 150EXPORT_SYMBOL_GPL(edac_mem_types);
151 151
diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
index e8658e451762..24d877f6e577 100644
--- a/drivers/edac/edac_pci_sysfs.c
+++ b/drivers/edac/edac_pci_sysfs.c
@@ -14,9 +14,6 @@
14#include "edac_core.h" 14#include "edac_core.h"
15#include "edac_module.h" 15#include "edac_module.h"
16 16
17/* Turn off this whole feature if PCI is not configured */
18#ifdef CONFIG_PCI
19
20#define EDAC_PCI_SYMLINK "device" 17#define EDAC_PCI_SYMLINK "device"
21 18
22/* data variables exported via sysfs */ 19/* data variables exported via sysfs */
@@ -761,5 +758,3 @@ MODULE_PARM_DESC(check_pci_errors,
761module_param(edac_pci_panic_on_pe, int, 0644); 758module_param(edac_pci_panic_on_pe, int, 0644);
762MODULE_PARM_DESC(edac_pci_panic_on_pe, 759MODULE_PARM_DESC(edac_pci_panic_on_pe,
763 "Panic on PCI Bus Parity error: 0=off 1=on"); 760 "Panic on PCI Bus Parity error: 0=off 1=on");
764
765#endif /* CONFIG_PCI */
diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c
index 8399b4e16fe0..b24681998740 100644
--- a/drivers/edac/ghes_edac.c
+++ b/drivers/edac/ghes_edac.c
@@ -413,8 +413,8 @@ void ghes_edac_report_mem_error(struct ghes *ghes, int sev,
413 413
414 /* Generate the trace event */ 414 /* Generate the trace event */
415 grain_bits = fls_long(e->grain); 415 grain_bits = fls_long(e->grain);
416 sprintf(pvt->detail_location, "APEI location: %s %s", 416 snprintf(pvt->detail_location, sizeof(pvt->detail_location),
417 e->location, e->other_detail); 417 "APEI location: %s %s", e->location, e->other_detail);
418 trace_mc_event(type, e->msg, e->label, e->error_count, 418 trace_mc_event(type, e->msg, e->label, e->error_count,
419 mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer, 419 mci->mc_idx, e->top_layer, e->mid_layer, e->low_layer,
420 PAGES_TO_MiB(e->page_frame_number) | e->offset_in_page, 420 PAGES_TO_MiB(e->page_frame_number) | e->offset_in_page,
diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
index cd28b968e5c7..5cb36a6022cc 100644
--- a/drivers/edac/i3000_edac.c
+++ b/drivers/edac/i3000_edac.c
@@ -542,8 +542,7 @@ fail1:
542 pci_unregister_driver(&i3000_driver); 542 pci_unregister_driver(&i3000_driver);
543 543
544fail0: 544fail0:
545 if (mci_pdev) 545 pci_dev_put(mci_pdev);
546 pci_dev_put(mci_pdev);
547 546
548 return pci_rc; 547 return pci_rc;
549} 548}
diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
index aa98b136f5d0..4ad062b0ef26 100644
--- a/drivers/edac/i3200_edac.c
+++ b/drivers/edac/i3200_edac.c
@@ -523,8 +523,7 @@ fail1:
523 pci_unregister_driver(&i3200_driver); 523 pci_unregister_driver(&i3200_driver);
524 524
525fail0: 525fail0:
526 if (mci_pdev) 526 pci_dev_put(mci_pdev);
527 pci_dev_put(mci_pdev);
528 527
529 return pci_rc; 528 return pci_rc;
530} 529}
diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
index d730e276d1a8..b4705d9366bf 100644
--- a/drivers/edac/i82443bxgx_edac.c
+++ b/drivers/edac/i82443bxgx_edac.c
@@ -458,8 +458,7 @@ static void __exit i82443bxgx_edacmc_exit(void)
458 if (!i82443bxgx_registered) 458 if (!i82443bxgx_registered)
459 i82443bxgx_edacmc_remove_one(mci_pdev); 459 i82443bxgx_edacmc_remove_one(mci_pdev);
460 460
461 if (mci_pdev) 461 pci_dev_put(mci_pdev);
462 pci_dev_put(mci_pdev);
463} 462}
464 463
465module_init(i82443bxgx_edacmc_init); 464module_init(i82443bxgx_edacmc_init);
diff --git a/drivers/edac/mce_amd.c b/drivers/edac/mce_amd.c
index f78c1c54dbd5..58586d59bf8e 100644
--- a/drivers/edac/mce_amd.c
+++ b/drivers/edac/mce_amd.c
@@ -138,6 +138,15 @@ static const char * const mc5_mce_desc[] = {
138 "Retire status queue" 138 "Retire status queue"
139}; 139};
140 140
141static const char * const mc6_mce_desc[] = {
142 "Hardware Assertion",
143 "Free List",
144 "Physical Register File",
145 "Retire Queue",
146 "Scheduler table",
147 "Status Register File",
148};
149
141static bool f12h_mc0_mce(u16 ec, u8 xec) 150static bool f12h_mc0_mce(u16 ec, u8 xec)
142{ 151{
143 bool ret = false; 152 bool ret = false;
@@ -432,8 +441,8 @@ static bool k8_mc2_mce(u16 ec, u8 xec)
432 pr_cont(": %s error in the L2 cache tags.\n", R4_MSG(ec)); 441 pr_cont(": %s error in the L2 cache tags.\n", R4_MSG(ec));
433 else if (xec == 0x0) { 442 else if (xec == 0x0) {
434 if (TLB_ERROR(ec)) 443 if (TLB_ERROR(ec))
435 pr_cont(": %s error in a Page Descriptor Cache or " 444 pr_cont("%s error in a Page Descriptor Cache or Guest TLB.\n",
436 "Guest TLB.\n", TT_MSG(ec)); 445 TT_MSG(ec));
437 else if (BUS_ERROR(ec)) 446 else if (BUS_ERROR(ec))
438 pr_cont(": %s/ECC error in data read from NB: %s.\n", 447 pr_cont(": %s/ECC error in data read from NB: %s.\n",
439 R4_MSG(ec), PP_MSG(ec)); 448 R4_MSG(ec), PP_MSG(ec));
@@ -672,38 +681,10 @@ static void decode_mc6_mce(struct mce *m)
672 681
673 pr_emerg(HW_ERR "MC6 Error: "); 682 pr_emerg(HW_ERR "MC6 Error: ");
674 683
675 switch (xec) { 684 if (xec > 0x5)
676 case 0x0:
677 pr_cont("Hardware Assertion");
678 break;
679
680 case 0x1:
681 pr_cont("Free List");
682 break;
683
684 case 0x2:
685 pr_cont("Physical Register File");
686 break;
687
688 case 0x3:
689 pr_cont("Retire Queue");
690 break;
691
692 case 0x4:
693 pr_cont("Scheduler table");
694 break;
695
696 case 0x5:
697 pr_cont("Status Register File");
698 break;
699
700 default:
701 goto wrong_mc6_mce; 685 goto wrong_mc6_mce;
702 break;
703 }
704
705 pr_cont(" parity error.\n");
706 686
687 pr_cont("%s parity error.\n", mc6_mce_desc[xec]);
707 return; 688 return;
708 689
709 wrong_mc6_mce: 690 wrong_mc6_mce:
@@ -800,7 +781,7 @@ int amd_decode_mce(struct notifier_block *nb, unsigned long val, void *data)
800 pr_cont("]: 0x%016llx\n", m->status); 781 pr_cont("]: 0x%016llx\n", m->status);
801 782
802 if (m->status & MCI_STATUS_ADDRV) 783 if (m->status & MCI_STATUS_ADDRV)
803 pr_emerg(HW_ERR "MC%d_ADDR: 0x%016llx\n", m->bank, m->addr); 784 pr_emerg(HW_ERR "MC%d Error Address: 0x%016llx\n", m->bank, m->addr);
804 785
805 if (!fam_ops) 786 if (!fam_ops)
806 goto err_code; 787 goto err_code;
diff --git a/drivers/edac/mce_amd_inj.c b/drivers/edac/mce_amd_inj.c
index 5e46a9fea31b..0bd91a802c67 100644
--- a/drivers/edac/mce_amd_inj.c
+++ b/drivers/edac/mce_amd_inj.c
@@ -1,173 +1,262 @@
1/* 1/*
2 * A simple MCE injection facility for testing the MCE decoding code. This 2 * A simple MCE injection facility for testing different aspects of the RAS
3 * driver should be built as module so that it can be loaded on production 3 * code. This driver should be built as module so that it can be loaded
4 * kernels for testing purposes. 4 * on production kernels for testing purposes.
5 * 5 *
6 * This file may be distributed under the terms of the GNU General Public 6 * This file may be distributed under the terms of the GNU General Public
7 * License version 2. 7 * License version 2.
8 * 8 *
9 * Copyright (c) 2010: Borislav Petkov <bp@alien8.de> 9 * Copyright (c) 2010-14: Borislav Petkov <bp@alien8.de>
10 * Advanced Micro Devices Inc. 10 * Advanced Micro Devices Inc.
11 */ 11 */
12 12
13#include <linux/kobject.h> 13#include <linux/kobject.h>
14#include <linux/debugfs.h>
14#include <linux/device.h> 15#include <linux/device.h>
15#include <linux/edac.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/cpu.h>
17#include <asm/mce.h> 18#include <asm/mce.h>
18 19
19#include "mce_amd.h" 20#include "mce_amd.h"
20 21
21struct edac_mce_attr {
22 struct attribute attr;
23 ssize_t (*show) (struct kobject *kobj, struct edac_mce_attr *attr, char *buf);
24 ssize_t (*store)(struct kobject *kobj, struct edac_mce_attr *attr,
25 const char *buf, size_t count);
26};
27
28#define EDAC_MCE_ATTR(_name, _mode, _show, _store) \
29static struct edac_mce_attr mce_attr_##_name = __ATTR(_name, _mode, _show, _store)
30
31static struct kobject *mce_kobj;
32
33/* 22/*
34 * Collect all the MCi_XXX settings 23 * Collect all the MCi_XXX settings
35 */ 24 */
36static struct mce i_mce; 25static struct mce i_mce;
26static struct dentry *dfs_inj;
37 27
38#define MCE_INJECT_STORE(reg) \ 28#define MCE_INJECT_SET(reg) \
39static ssize_t edac_inject_##reg##_store(struct kobject *kobj, \ 29static int inj_##reg##_set(void *data, u64 val) \
40 struct edac_mce_attr *attr, \
41 const char *data, size_t count)\
42{ \ 30{ \
43 int ret = 0; \ 31 struct mce *m = (struct mce *)data; \
44 unsigned long value; \
45 \
46 ret = kstrtoul(data, 16, &value); \
47 if (ret < 0) \
48 printk(KERN_ERR "Error writing MCE " #reg " field.\n"); \
49 \ 32 \
50 i_mce.reg = value; \ 33 m->reg = val; \
51 \ 34 return 0; \
52 return count; \
53} 35}
54 36
55MCE_INJECT_STORE(status); 37MCE_INJECT_SET(status);
56MCE_INJECT_STORE(misc); 38MCE_INJECT_SET(misc);
57MCE_INJECT_STORE(addr); 39MCE_INJECT_SET(addr);
58 40
59#define MCE_INJECT_SHOW(reg) \ 41#define MCE_INJECT_GET(reg) \
60static ssize_t edac_inject_##reg##_show(struct kobject *kobj, \ 42static int inj_##reg##_get(void *data, u64 *val) \
61 struct edac_mce_attr *attr, \
62 char *buf) \
63{ \ 43{ \
64 return sprintf(buf, "0x%016llx\n", i_mce.reg); \ 44 struct mce *m = (struct mce *)data; \
45 \
46 *val = m->reg; \
47 return 0; \
65} 48}
66 49
67MCE_INJECT_SHOW(status); 50MCE_INJECT_GET(status);
68MCE_INJECT_SHOW(misc); 51MCE_INJECT_GET(misc);
69MCE_INJECT_SHOW(addr); 52MCE_INJECT_GET(addr);
70 53
71EDAC_MCE_ATTR(status, 0644, edac_inject_status_show, edac_inject_status_store); 54DEFINE_SIMPLE_ATTRIBUTE(status_fops, inj_status_get, inj_status_set, "%llx\n");
72EDAC_MCE_ATTR(misc, 0644, edac_inject_misc_show, edac_inject_misc_store); 55DEFINE_SIMPLE_ATTRIBUTE(misc_fops, inj_misc_get, inj_misc_set, "%llx\n");
73EDAC_MCE_ATTR(addr, 0644, edac_inject_addr_show, edac_inject_addr_store); 56DEFINE_SIMPLE_ATTRIBUTE(addr_fops, inj_addr_get, inj_addr_set, "%llx\n");
74 57
75/* 58/*
76 * This denotes into which bank we're injecting and triggers 59 * Caller needs to be make sure this cpu doesn't disappear
77 * the injection, at the same time. 60 * from under us, i.e.: get_cpu/put_cpu.
78 */ 61 */
79static ssize_t edac_inject_bank_store(struct kobject *kobj, 62static int toggle_hw_mce_inject(unsigned int cpu, bool enable)
80 struct edac_mce_attr *attr,
81 const char *data, size_t count)
82{ 63{
83 int ret = 0; 64 u32 l, h;
84 unsigned long value; 65 int err;
85 66
86 ret = kstrtoul(data, 10, &value); 67 err = rdmsr_on_cpu(cpu, MSR_K7_HWCR, &l, &h);
87 if (ret < 0) { 68 if (err) {
88 printk(KERN_ERR "Invalid bank value!\n"); 69 pr_err("%s: error reading HWCR\n", __func__);
89 return -EINVAL; 70 return err;
90 } 71 }
91 72
92 if (value > 5) 73 enable ? (l |= BIT(18)) : (l &= ~BIT(18));
93 if (boot_cpu_data.x86 != 0x15 || value > 6) {
94 printk(KERN_ERR "Non-existent MCE bank: %lu\n", value);
95 return -EINVAL;
96 }
97 74
98 i_mce.bank = value; 75 err = wrmsr_on_cpu(cpu, MSR_K7_HWCR, l, h);
76 if (err)
77 pr_err("%s: error writing HWCR\n", __func__);
99 78
100 amd_decode_mce(NULL, 0, &i_mce); 79 return err;
80}
101 81
102 return count; 82static int flags_get(void *data, u64 *val)
83{
84 struct mce *m = (struct mce *)data;
85
86 *val = m->inject_flags;
87
88 return 0;
103} 89}
104 90
105static ssize_t edac_inject_bank_show(struct kobject *kobj, 91static int flags_set(void *data, u64 val)
106 struct edac_mce_attr *attr, char *buf)
107{ 92{
108 return sprintf(buf, "%d\n", i_mce.bank); 93 struct mce *m = (struct mce *)data;
94
95 m->inject_flags = (u8)val;
96 return 0;
109} 97}
110 98
111EDAC_MCE_ATTR(bank, 0644, edac_inject_bank_show, edac_inject_bank_store); 99DEFINE_SIMPLE_ATTRIBUTE(flags_fops, flags_get, flags_set, "%llu\n");
112 100
113static struct edac_mce_attr *sysfs_attrs[] = { &mce_attr_status, &mce_attr_misc, 101/*
114 &mce_attr_addr, &mce_attr_bank 102 * On which CPU to inject?
115}; 103 */
104MCE_INJECT_GET(extcpu);
116 105
117static int __init edac_init_mce_inject(void) 106static int inj_extcpu_set(void *data, u64 val)
118{ 107{
119 struct bus_type *edac_subsys = NULL; 108 struct mce *m = (struct mce *)data;
120 int i, err = 0;
121 109
122 edac_subsys = edac_get_sysfs_subsys(); 110 if (val >= nr_cpu_ids || !cpu_online(val)) {
123 if (!edac_subsys) 111 pr_err("%s: Invalid CPU: %llu\n", __func__, val);
124 return -EINVAL; 112 return -EINVAL;
113 }
114 m->extcpu = val;
115 return 0;
116}
117
118DEFINE_SIMPLE_ATTRIBUTE(extcpu_fops, inj_extcpu_get, inj_extcpu_set, "%llu\n");
125 119
126 mce_kobj = kobject_create_and_add("mce", &edac_subsys->dev_root->kobj); 120static void trigger_mce(void *info)
127 if (!mce_kobj) { 121{
128 printk(KERN_ERR "Error creating a mce kset.\n"); 122 asm volatile("int $18");
129 err = -ENOMEM; 123}
130 goto err_mce_kobj; 124
125static void do_inject(void)
126{
127 u64 mcg_status = 0;
128 unsigned int cpu = i_mce.extcpu;
129 u8 b = i_mce.bank;
130
131 if (!(i_mce.inject_flags & MCJ_EXCEPTION)) {
132 amd_decode_mce(NULL, 0, &i_mce);
133 return;
131 } 134 }
132 135
133 for (i = 0; i < ARRAY_SIZE(sysfs_attrs); i++) { 136 get_online_cpus();
134 err = sysfs_create_file(mce_kobj, &sysfs_attrs[i]->attr); 137 if (!cpu_online(cpu))
135 if (err) { 138 goto err;
136 printk(KERN_ERR "Error creating %s in sysfs.\n", 139
137 sysfs_attrs[i]->attr.name); 140 /* prep MCE global settings for the injection */
138 goto err_sysfs_create; 141 mcg_status = MCG_STATUS_MCIP | MCG_STATUS_EIPV;
142
143 if (!(i_mce.status & MCI_STATUS_PCC))
144 mcg_status |= MCG_STATUS_RIPV;
145
146 toggle_hw_mce_inject(cpu, true);
147
148 wrmsr_on_cpu(cpu, MSR_IA32_MCG_STATUS,
149 (u32)mcg_status, (u32)(mcg_status >> 32));
150
151 wrmsr_on_cpu(cpu, MSR_IA32_MCx_STATUS(b),
152 (u32)i_mce.status, (u32)(i_mce.status >> 32));
153
154 wrmsr_on_cpu(cpu, MSR_IA32_MCx_ADDR(b),
155 (u32)i_mce.addr, (u32)(i_mce.addr >> 32));
156
157 wrmsr_on_cpu(cpu, MSR_IA32_MCx_MISC(b),
158 (u32)i_mce.misc, (u32)(i_mce.misc >> 32));
159
160 toggle_hw_mce_inject(cpu, false);
161
162 smp_call_function_single(cpu, trigger_mce, NULL, 0);
163
164err:
165 put_online_cpus();
166
167}
168
169/*
170 * This denotes into which bank we're injecting and triggers
171 * the injection, at the same time.
172 */
173static int inj_bank_set(void *data, u64 val)
174{
175 struct mce *m = (struct mce *)data;
176
177 if (val > 5) {
178 if (boot_cpu_data.x86 != 0x15 || val > 6) {
179 pr_err("Non-existent MCE bank: %llu\n", val);
180 return -EINVAL;
139 } 181 }
140 } 182 }
141 return 0;
142 183
143err_sysfs_create: 184 m->bank = val;
144 while (--i >= 0) 185 do_inject();
145 sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr);
146 186
147 kobject_del(mce_kobj); 187 return 0;
188}
148 189
149err_mce_kobj: 190static int inj_bank_get(void *data, u64 *val)
150 edac_put_sysfs_subsys(); 191{
192 struct mce *m = (struct mce *)data;
151 193
152 return err; 194 *val = m->bank;
195 return 0;
153} 196}
154 197
155static void __exit edac_exit_mce_inject(void) 198DEFINE_SIMPLE_ATTRIBUTE(bank_fops, inj_bank_get, inj_bank_set, "%llu\n");
199
200struct dfs_node {
201 char *name;
202 struct dentry *d;
203 const struct file_operations *fops;
204} dfs_fls[] = {
205 { .name = "status", .fops = &status_fops },
206 { .name = "misc", .fops = &misc_fops },
207 { .name = "addr", .fops = &addr_fops },
208 { .name = "bank", .fops = &bank_fops },
209 { .name = "flags", .fops = &flags_fops },
210 { .name = "cpu", .fops = &extcpu_fops },
211};
212
213static int __init init_mce_inject(void)
156{ 214{
157 int i; 215 int i;
158 216
159 for (i = 0; i < ARRAY_SIZE(sysfs_attrs); i++) 217 dfs_inj = debugfs_create_dir("mce-inject", NULL);
160 sysfs_remove_file(mce_kobj, &sysfs_attrs[i]->attr); 218 if (!dfs_inj)
219 return -EINVAL;
220
221 for (i = 0; i < ARRAY_SIZE(dfs_fls); i++) {
222 dfs_fls[i].d = debugfs_create_file(dfs_fls[i].name,
223 S_IRUSR | S_IWUSR,
224 dfs_inj,
225 &i_mce,
226 dfs_fls[i].fops);
227
228 if (!dfs_fls[i].d)
229 goto err_dfs_add;
230 }
231
232 return 0;
233
234err_dfs_add:
235 while (--i >= 0)
236 debugfs_remove(dfs_fls[i].d);
161 237
162 kobject_del(mce_kobj); 238 debugfs_remove(dfs_inj);
239 dfs_inj = NULL;
163 240
164 edac_put_sysfs_subsys(); 241 return -ENOMEM;
165} 242}
166 243
167module_init(edac_init_mce_inject); 244static void __exit exit_mce_inject(void)
168module_exit(edac_exit_mce_inject); 245{
246 int i;
247
248 for (i = 0; i < ARRAY_SIZE(dfs_fls); i++)
249 debugfs_remove(dfs_fls[i].d);
250
251 memset(&dfs_fls, 0, sizeof(dfs_fls));
252
253 debugfs_remove(dfs_inj);
254 dfs_inj = NULL;
255}
256module_init(init_mce_inject);
257module_exit(exit_mce_inject);
169 258
170MODULE_LICENSE("GPL"); 259MODULE_LICENSE("GPL");
171MODULE_AUTHOR("Borislav Petkov <bp@alien8.de>"); 260MODULE_AUTHOR("Borislav Petkov <bp@alien8.de>");
172MODULE_AUTHOR("AMD Inc."); 261MODULE_AUTHOR("AMD Inc.");
173MODULE_DESCRIPTION("MCE injection facility for testing MCE decoding"); 262MODULE_DESCRIPTION("MCE injection facility for RAS testing");
diff --git a/drivers/edac/mv64x60_edac.c b/drivers/edac/mv64x60_edac.c
index 542fad70e360..6366e880f978 100644
--- a/drivers/edac/mv64x60_edac.c
+++ b/drivers/edac/mv64x60_edac.c
@@ -178,7 +178,7 @@ static int mv64x60_pci_err_probe(struct platform_device *pdev)
178 res = devm_request_irq(&pdev->dev, 178 res = devm_request_irq(&pdev->dev,
179 pdata->irq, 179 pdata->irq,
180 mv64x60_pci_isr, 180 mv64x60_pci_isr,
181 IRQF_DISABLED, 181 0,
182 "[EDAC] PCI err", 182 "[EDAC] PCI err",
183 pci); 183 pci);
184 if (res < 0) { 184 if (res < 0) {
@@ -345,7 +345,7 @@ static int mv64x60_sram_err_probe(struct platform_device *pdev)
345 res = devm_request_irq(&pdev->dev, 345 res = devm_request_irq(&pdev->dev,
346 pdata->irq, 346 pdata->irq,
347 mv64x60_sram_isr, 347 mv64x60_sram_isr,
348 IRQF_DISABLED, 348 0,
349 "[EDAC] SRAM err", 349 "[EDAC] SRAM err",
350 edac_dev); 350 edac_dev);
351 if (res < 0) { 351 if (res < 0) {
@@ -540,7 +540,7 @@ static int mv64x60_cpu_err_probe(struct platform_device *pdev)
540 res = devm_request_irq(&pdev->dev, 540 res = devm_request_irq(&pdev->dev,
541 pdata->irq, 541 pdata->irq,
542 mv64x60_cpu_isr, 542 mv64x60_cpu_isr,
543 IRQF_DISABLED, 543 0,
544 "[EDAC] CPU err", 544 "[EDAC] CPU err",
545 edac_dev); 545 edac_dev);
546 if (res < 0) { 546 if (res < 0) {
@@ -800,7 +800,7 @@ static int mv64x60_mc_err_probe(struct platform_device *pdev)
800 res = devm_request_irq(&pdev->dev, 800 res = devm_request_irq(&pdev->dev,
801 pdata->irq, 801 pdata->irq,
802 mv64x60_mc_isr, 802 mv64x60_mc_isr,
803 IRQF_DISABLED, 803 0,
804 "[EDAC] MC err", 804 "[EDAC] MC err",
805 mci); 805 mci);
806 if (res < 0) { 806 if (res < 0) {
diff --git a/drivers/edac/ppc4xx_edac.c b/drivers/edac/ppc4xx_edac.c
index 0f04d5ead521..41593539cec4 100644
--- a/drivers/edac/ppc4xx_edac.c
+++ b/drivers/edac/ppc4xx_edac.c
@@ -1120,7 +1120,7 @@ static int ppc4xx_edac_register_irq(struct platform_device *op,
1120 1120
1121 status = request_irq(ded_irq, 1121 status = request_irq(ded_irq,
1122 ppc4xx_edac_isr, 1122 ppc4xx_edac_isr,
1123 IRQF_DISABLED, 1123 0,
1124 "[EDAC] MC ECCDED", 1124 "[EDAC] MC ECCDED",
1125 mci); 1125 mci);
1126 1126
@@ -1134,7 +1134,7 @@ static int ppc4xx_edac_register_irq(struct platform_device *op,
1134 1134
1135 status = request_irq(sec_irq, 1135 status = request_irq(sec_irq,
1136 ppc4xx_edac_isr, 1136 ppc4xx_edac_isr,
1137 IRQF_DISABLED, 1137 0,
1138 "[EDAC] MC ECCSEC", 1138 "[EDAC] MC ECCSEC",
1139 mci); 1139 mci);
1140 1140
diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
index e644b52c287c..7c5cdc62f31c 100644
--- a/drivers/edac/x38_edac.c
+++ b/drivers/edac/x38_edac.c
@@ -500,8 +500,7 @@ fail1:
500 pci_unregister_driver(&x38_driver); 500 pci_unregister_driver(&x38_driver);
501 501
502fail0: 502fail0:
503 if (mci_pdev) 503 pci_dev_put(mci_pdev);
504 pci_dev_put(mci_pdev);
505 504
506 return pci_rc; 505 return pci_rc;
507} 506}
diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
index 5d997a33907e..2a3973a7c441 100644
--- a/drivers/firewire/core-cdev.c
+++ b/drivers/firewire/core-cdev.c
@@ -1637,8 +1637,7 @@ static int dispatch_ioctl(struct client *client,
1637 _IOC_SIZE(cmd) > sizeof(buffer)) 1637 _IOC_SIZE(cmd) > sizeof(buffer))
1638 return -ENOTTY; 1638 return -ENOTTY;
1639 1639
1640 if (_IOC_DIR(cmd) == _IOC_READ) 1640 memset(&buffer, 0, sizeof(buffer));
1641 memset(&buffer, 0, _IOC_SIZE(cmd));
1642 1641
1643 if (_IOC_DIR(cmd) & _IOC_WRITE) 1642 if (_IOC_DIR(cmd) & _IOC_WRITE)
1644 if (copy_from_user(&buffer, arg, _IOC_SIZE(cmd))) 1643 if (copy_from_user(&buffer, arg, _IOC_SIZE(cmd)))
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index 17afc51f3054..c5f7b4e9eb6c 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -93,6 +93,12 @@ static void dmi_table(u8 *buf, int len, int num,
93 const struct dmi_header *dm = (const struct dmi_header *)data; 93 const struct dmi_header *dm = (const struct dmi_header *)data;
94 94
95 /* 95 /*
96 * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0]
97 */
98 if (dm->type == DMI_ENTRY_END_OF_TABLE)
99 break;
100
101 /*
96 * We want to know the total length (formatted area and 102 * We want to know the total length (formatted area and
97 * strings) before decoding to make sure we won't run off the 103 * strings) before decoding to make sure we won't run off the
98 * table in dmi_decode or dmi_string 104 * table in dmi_decode or dmi_string
@@ -107,7 +113,7 @@ static void dmi_table(u8 *buf, int len, int num,
107 } 113 }
108} 114}
109 115
110static u32 dmi_base; 116static phys_addr_t dmi_base;
111static u16 dmi_len; 117static u16 dmi_len;
112static u16 dmi_num; 118static u16 dmi_num;
113 119
@@ -467,7 +473,7 @@ static int __init dmi_present(const u8 *buf)
467 473
468 if (memcmp(buf, "_SM_", 4) == 0 && 474 if (memcmp(buf, "_SM_", 4) == 0 &&
469 buf[5] < 32 && dmi_checksum(buf, buf[5])) { 475 buf[5] < 32 && dmi_checksum(buf, buf[5])) {
470 smbios_ver = (buf[6] << 8) + buf[7]; 476 smbios_ver = get_unaligned_be16(buf + 6);
471 477
472 /* Some BIOS report weird SMBIOS version, fix that up */ 478 /* Some BIOS report weird SMBIOS version, fix that up */
473 switch (smbios_ver) { 479 switch (smbios_ver) {
@@ -489,10 +495,9 @@ static int __init dmi_present(const u8 *buf)
489 buf += 16; 495 buf += 16;
490 496
491 if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) { 497 if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) {
492 dmi_num = (buf[13] << 8) | buf[12]; 498 dmi_num = get_unaligned_le16(buf + 12);
493 dmi_len = (buf[7] << 8) | buf[6]; 499 dmi_len = get_unaligned_le16(buf + 6);
494 dmi_base = (buf[11] << 24) | (buf[10] << 16) | 500 dmi_base = get_unaligned_le32(buf + 8);
495 (buf[9] << 8) | buf[8];
496 501
497 if (dmi_walk_early(dmi_decode) == 0) { 502 if (dmi_walk_early(dmi_decode) == 0) {
498 if (smbios_ver) { 503 if (smbios_ver) {
@@ -514,12 +519,72 @@ static int __init dmi_present(const u8 *buf)
514 return 1; 519 return 1;
515} 520}
516 521
522/*
523 * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy
524 * 32-bit entry point, there is no embedded DMI header (_DMI_) in here.
525 */
526static int __init dmi_smbios3_present(const u8 *buf)
527{
528 if (memcmp(buf, "_SM3_", 5) == 0 &&
529 buf[6] < 32 && dmi_checksum(buf, buf[6])) {
530 dmi_ver = get_unaligned_be16(buf + 7);
531 dmi_len = get_unaligned_le32(buf + 12);
532 dmi_base = get_unaligned_le64(buf + 16);
533
534 /*
535 * The 64-bit SMBIOS 3.0 entry point no longer has a field
536 * containing the number of structures present in the table.
537 * Instead, it defines the table size as a maximum size, and
538 * relies on the end-of-table structure type (#127) to be used
539 * to signal the end of the table.
540 * So let's define dmi_num as an upper bound as well: each
541 * structure has a 4 byte header, so dmi_len / 4 is an upper
542 * bound for the number of structures in the table.
543 */
544 dmi_num = dmi_len / 4;
545
546 if (dmi_walk_early(dmi_decode) == 0) {
547 pr_info("SMBIOS %d.%d present.\n",
548 dmi_ver >> 8, dmi_ver & 0xFF);
549 dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string));
550 pr_debug("DMI: %s\n", dmi_ids_string);
551 return 0;
552 }
553 }
554 return 1;
555}
556
517void __init dmi_scan_machine(void) 557void __init dmi_scan_machine(void)
518{ 558{
519 char __iomem *p, *q; 559 char __iomem *p, *q;
520 char buf[32]; 560 char buf[32];
521 561
522 if (efi_enabled(EFI_CONFIG_TABLES)) { 562 if (efi_enabled(EFI_CONFIG_TABLES)) {
563 /*
564 * According to the DMTF SMBIOS reference spec v3.0.0, it is
565 * allowed to define both the 64-bit entry point (smbios3) and
566 * the 32-bit entry point (smbios), in which case they should
567 * either both point to the same SMBIOS structure table, or the
568 * table pointed to by the 64-bit entry point should contain a
569 * superset of the table contents pointed to by the 32-bit entry
570 * point (section 5.2)
571 * This implies that the 64-bit entry point should have
572 * precedence if it is defined and supported by the OS. If we
573 * have the 64-bit entry point, but fail to decode it, fall
574 * back to the legacy one (if available)
575 */
576 if (efi.smbios3 != EFI_INVALID_TABLE_ADDR) {
577 p = dmi_early_remap(efi.smbios3, 32);
578 if (p == NULL)
579 goto error;
580 memcpy_fromio(buf, p, 32);
581 dmi_early_unmap(p, 32);
582
583 if (!dmi_smbios3_present(buf)) {
584 dmi_available = 1;
585 goto out;
586 }
587 }
523 if (efi.smbios == EFI_INVALID_TABLE_ADDR) 588 if (efi.smbios == EFI_INVALID_TABLE_ADDR)
524 goto error; 589 goto error;
525 590
@@ -552,7 +617,7 @@ void __init dmi_scan_machine(void)
552 memset(buf, 0, 16); 617 memset(buf, 0, 16);
553 for (q = p; q < p + 0x10000; q += 16) { 618 for (q = p; q < p + 0x10000; q += 16) {
554 memcpy_fromio(buf + 16, q, 16); 619 memcpy_fromio(buf + 16, q, 16);
555 if (!dmi_present(buf)) { 620 if (!dmi_smbios3_present(buf) || !dmi_present(buf)) {
556 dmi_available = 1; 621 dmi_available = 1;
557 dmi_early_unmap(p, 0x10000); 622 dmi_early_unmap(p, 0x10000);
558 goto out; 623 goto out;
diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
index 8590099ac148..9035c1b74d58 100644
--- a/drivers/firmware/efi/efi.c
+++ b/drivers/firmware/efi/efi.c
@@ -30,6 +30,7 @@ struct efi __read_mostly efi = {
30 .acpi = EFI_INVALID_TABLE_ADDR, 30 .acpi = EFI_INVALID_TABLE_ADDR,
31 .acpi20 = EFI_INVALID_TABLE_ADDR, 31 .acpi20 = EFI_INVALID_TABLE_ADDR,
32 .smbios = EFI_INVALID_TABLE_ADDR, 32 .smbios = EFI_INVALID_TABLE_ADDR,
33 .smbios3 = EFI_INVALID_TABLE_ADDR,
33 .sal_systab = EFI_INVALID_TABLE_ADDR, 34 .sal_systab = EFI_INVALID_TABLE_ADDR,
34 .boot_info = EFI_INVALID_TABLE_ADDR, 35 .boot_info = EFI_INVALID_TABLE_ADDR,
35 .hcdp = EFI_INVALID_TABLE_ADDR, 36 .hcdp = EFI_INVALID_TABLE_ADDR,
@@ -86,6 +87,8 @@ static ssize_t systab_show(struct kobject *kobj,
86 str += sprintf(str, "ACPI=0x%lx\n", efi.acpi); 87 str += sprintf(str, "ACPI=0x%lx\n", efi.acpi);
87 if (efi.smbios != EFI_INVALID_TABLE_ADDR) 88 if (efi.smbios != EFI_INVALID_TABLE_ADDR)
88 str += sprintf(str, "SMBIOS=0x%lx\n", efi.smbios); 89 str += sprintf(str, "SMBIOS=0x%lx\n", efi.smbios);
90 if (efi.smbios3 != EFI_INVALID_TABLE_ADDR)
91 str += sprintf(str, "SMBIOS3=0x%lx\n", efi.smbios3);
89 if (efi.hcdp != EFI_INVALID_TABLE_ADDR) 92 if (efi.hcdp != EFI_INVALID_TABLE_ADDR)
90 str += sprintf(str, "HCDP=0x%lx\n", efi.hcdp); 93 str += sprintf(str, "HCDP=0x%lx\n", efi.hcdp);
91 if (efi.boot_info != EFI_INVALID_TABLE_ADDR) 94 if (efi.boot_info != EFI_INVALID_TABLE_ADDR)
@@ -260,6 +263,7 @@ static __initdata efi_config_table_type_t common_tables[] = {
260 {MPS_TABLE_GUID, "MPS", &efi.mps}, 263 {MPS_TABLE_GUID, "MPS", &efi.mps},
261 {SAL_SYSTEM_TABLE_GUID, "SALsystab", &efi.sal_systab}, 264 {SAL_SYSTEM_TABLE_GUID, "SALsystab", &efi.sal_systab},
262 {SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios}, 265 {SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios},
266 {SMBIOS3_TABLE_GUID, "SMBIOS 3.0", &efi.smbios3},
263 {UGA_IO_PROTOCOL_GUID, "UGA", &efi.uga}, 267 {UGA_IO_PROTOCOL_GUID, "UGA", &efi.uga},
264 {NULL_GUID, NULL, NULL}, 268 {NULL_GUID, NULL, NULL},
265}; 269};
diff --git a/drivers/firmware/efi/libstub/arm-stub.c b/drivers/firmware/efi/libstub/arm-stub.c
index 75ee05964cbc..eb48a1a1a576 100644
--- a/drivers/firmware/efi/libstub/arm-stub.c
+++ b/drivers/firmware/efi/libstub/arm-stub.c
@@ -247,9 +247,18 @@ unsigned long __init efi_entry(void *handle, efi_system_table_t *sys_table,
247 goto fail_free_cmdline; 247 goto fail_free_cmdline;
248 } 248 }
249 } 249 }
250 if (!fdt_addr) 250
251 if (fdt_addr) {
252 pr_efi(sys_table, "Using DTB from command line\n");
253 } else {
251 /* Look for a device tree configuration table entry. */ 254 /* Look for a device tree configuration table entry. */
252 fdt_addr = (uintptr_t)get_fdt(sys_table); 255 fdt_addr = (uintptr_t)get_fdt(sys_table);
256 if (fdt_addr)
257 pr_efi(sys_table, "Using DTB from configuration table\n");
258 }
259
260 if (!fdt_addr)
261 pr_efi(sys_table, "Generating empty DTB\n");
253 262
254 status = handle_cmdline_files(sys_table, image, cmdline_ptr, 263 status = handle_cmdline_files(sys_table, image, cmdline_ptr,
255 "initrd=", dram_base + SZ_512M, 264 "initrd=", dram_base + SZ_512M,
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 0959ca9b6b27..23dfd5f59b39 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -905,4 +905,16 @@ config GPIO_VIPERBOARD
905 River Tech's viperboard.h for detailed meaning 905 River Tech's viperboard.h for detailed meaning
906 of the module parameters. 906 of the module parameters.
907 907
908config GPIO_DLN2
909 tristate "Diolan DLN2 GPIO support"
910 depends on MFD_DLN2
911 select GPIOLIB_IRQCHIP
912
913 help
914 Select this option to enable GPIO driver for the Diolan DLN2
915 board.
916
917 This driver can also be built as a module. If so, the module
918 will be called gpio-dln2.
919
908endif 920endif
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index e5d346cf3b6e..e60677b8ccb4 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_GPIO_CRYSTAL_COVE) += gpio-crystalcove.o
26obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o 26obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o
27obj-$(CONFIG_GPIO_DA9055) += gpio-da9055.o 27obj-$(CONFIG_GPIO_DA9055) += gpio-da9055.o
28obj-$(CONFIG_GPIO_DAVINCI) += gpio-davinci.o 28obj-$(CONFIG_GPIO_DAVINCI) += gpio-davinci.o
29obj-$(CONFIG_GPIO_DLN2) += gpio-dln2.o
29obj-$(CONFIG_GPIO_DWAPB) += gpio-dwapb.o 30obj-$(CONFIG_GPIO_DWAPB) += gpio-dwapb.o
30obj-$(CONFIG_GPIO_EM) += gpio-em.o 31obj-$(CONFIG_GPIO_EM) += gpio-em.o
31obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o 32obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o
diff --git a/drivers/gpio/gpio-dln2.c b/drivers/gpio/gpio-dln2.c
new file mode 100644
index 000000000000..978b51eae2ec
--- /dev/null
+++ b/drivers/gpio/gpio-dln2.c
@@ -0,0 +1,553 @@
1/*
2 * Driver for the Diolan DLN-2 USB-GPIO adapter
3 *
4 * Copyright (c) 2014 Intel Corporation
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13#include <linux/slab.h>
14#include <linux/types.h>
15#include <linux/irqdomain.h>
16#include <linux/irq.h>
17#include <linux/irqchip/chained_irq.h>
18#include <linux/gpio.h>
19#include <linux/gpio/driver.h>
20#include <linux/platform_device.h>
21#include <linux/mfd/dln2.h>
22
23#define DLN2_GPIO_ID 0x01
24
25#define DLN2_GPIO_GET_PIN_COUNT DLN2_CMD(0x01, DLN2_GPIO_ID)
26#define DLN2_GPIO_SET_DEBOUNCE DLN2_CMD(0x04, DLN2_GPIO_ID)
27#define DLN2_GPIO_GET_DEBOUNCE DLN2_CMD(0x05, DLN2_GPIO_ID)
28#define DLN2_GPIO_PORT_GET_VAL DLN2_CMD(0x06, DLN2_GPIO_ID)
29#define DLN2_GPIO_PIN_GET_VAL DLN2_CMD(0x0B, DLN2_GPIO_ID)
30#define DLN2_GPIO_PIN_SET_OUT_VAL DLN2_CMD(0x0C, DLN2_GPIO_ID)
31#define DLN2_GPIO_PIN_GET_OUT_VAL DLN2_CMD(0x0D, DLN2_GPIO_ID)
32#define DLN2_GPIO_CONDITION_MET_EV DLN2_CMD(0x0F, DLN2_GPIO_ID)
33#define DLN2_GPIO_PIN_ENABLE DLN2_CMD(0x10, DLN2_GPIO_ID)
34#define DLN2_GPIO_PIN_DISABLE DLN2_CMD(0x11, DLN2_GPIO_ID)
35#define DLN2_GPIO_PIN_SET_DIRECTION DLN2_CMD(0x13, DLN2_GPIO_ID)
36#define DLN2_GPIO_PIN_GET_DIRECTION DLN2_CMD(0x14, DLN2_GPIO_ID)
37#define DLN2_GPIO_PIN_SET_EVENT_CFG DLN2_CMD(0x1E, DLN2_GPIO_ID)
38#define DLN2_GPIO_PIN_GET_EVENT_CFG DLN2_CMD(0x1F, DLN2_GPIO_ID)
39
40#define DLN2_GPIO_EVENT_NONE 0
41#define DLN2_GPIO_EVENT_CHANGE 1
42#define DLN2_GPIO_EVENT_LVL_HIGH 2
43#define DLN2_GPIO_EVENT_LVL_LOW 3
44#define DLN2_GPIO_EVENT_CHANGE_RISING 0x11
45#define DLN2_GPIO_EVENT_CHANGE_FALLING 0x21
46#define DLN2_GPIO_EVENT_MASK 0x0F
47
48#define DLN2_GPIO_MAX_PINS 32
49
50struct dln2_irq_work {
51 struct work_struct work;
52 struct dln2_gpio *dln2;
53 int pin;
54 int type;
55};
56
57struct dln2_gpio {
58 struct platform_device *pdev;
59 struct gpio_chip gpio;
60
61 /*
62 * Cache pin direction to save us one transfer, since the hardware has
63 * separate commands to read the in and out values.
64 */
65 DECLARE_BITMAP(output_enabled, DLN2_GPIO_MAX_PINS);
66
67 DECLARE_BITMAP(irqs_masked, DLN2_GPIO_MAX_PINS);
68 DECLARE_BITMAP(irqs_enabled, DLN2_GPIO_MAX_PINS);
69 DECLARE_BITMAP(irqs_pending, DLN2_GPIO_MAX_PINS);
70 struct dln2_irq_work *irq_work;
71};
72
73struct dln2_gpio_pin {
74 __le16 pin;
75};
76
77struct dln2_gpio_pin_val {
78 __le16 pin __packed;
79 u8 value;
80};
81
82static int dln2_gpio_get_pin_count(struct platform_device *pdev)
83{
84 int ret;
85 __le16 count;
86 int len = sizeof(count);
87
88 ret = dln2_transfer_rx(pdev, DLN2_GPIO_GET_PIN_COUNT, &count, &len);
89 if (ret < 0)
90 return ret;
91 if (len < sizeof(count))
92 return -EPROTO;
93
94 return le16_to_cpu(count);
95}
96
97static int dln2_gpio_pin_cmd(struct dln2_gpio *dln2, int cmd, unsigned pin)
98{
99 struct dln2_gpio_pin req = {
100 .pin = cpu_to_le16(pin),
101 };
102
103 return dln2_transfer_tx(dln2->pdev, cmd, &req, sizeof(req));
104}
105
106static int dln2_gpio_pin_val(struct dln2_gpio *dln2, int cmd, unsigned int pin)
107{
108 int ret;
109 struct dln2_gpio_pin req = {
110 .pin = cpu_to_le16(pin),
111 };
112 struct dln2_gpio_pin_val rsp;
113 int len = sizeof(rsp);
114
115 ret = dln2_transfer(dln2->pdev, cmd, &req, sizeof(req), &rsp, &len);
116 if (ret < 0)
117 return ret;
118 if (len < sizeof(rsp) || req.pin != rsp.pin)
119 return -EPROTO;
120
121 return rsp.value;
122}
123
124static int dln2_gpio_pin_get_in_val(struct dln2_gpio *dln2, unsigned int pin)
125{
126 int ret;
127
128 ret = dln2_gpio_pin_val(dln2, DLN2_GPIO_PIN_GET_VAL, pin);
129 if (ret < 0)
130 return ret;
131 return !!ret;
132}
133
134static int dln2_gpio_pin_get_out_val(struct dln2_gpio *dln2, unsigned int pin)
135{
136 int ret;
137
138 ret = dln2_gpio_pin_val(dln2, DLN2_GPIO_PIN_GET_OUT_VAL, pin);
139 if (ret < 0)
140 return ret;
141 return !!ret;
142}
143
144static void dln2_gpio_pin_set_out_val(struct dln2_gpio *dln2,
145 unsigned int pin, int value)
146{
147 struct dln2_gpio_pin_val req = {
148 .pin = cpu_to_le16(pin),
149 .value = value,
150 };
151
152 dln2_transfer_tx(dln2->pdev, DLN2_GPIO_PIN_SET_OUT_VAL, &req,
153 sizeof(req));
154}
155
156#define DLN2_GPIO_DIRECTION_IN 0
157#define DLN2_GPIO_DIRECTION_OUT 1
158
159static int dln2_gpio_request(struct gpio_chip *chip, unsigned offset)
160{
161 struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio);
162 struct dln2_gpio_pin req = {
163 .pin = cpu_to_le16(offset),
164 };
165 struct dln2_gpio_pin_val rsp;
166 int len = sizeof(rsp);
167 int ret;
168
169 ret = dln2_gpio_pin_cmd(dln2, DLN2_GPIO_PIN_ENABLE, offset);
170 if (ret < 0)
171 return ret;
172
173 /* cache the pin direction */
174 ret = dln2_transfer(dln2->pdev, DLN2_GPIO_PIN_GET_DIRECTION,
175 &req, sizeof(req), &rsp, &len);
176 if (ret < 0)
177 return ret;
178 if (len < sizeof(rsp) || req.pin != rsp.pin) {
179 ret = -EPROTO;
180 goto out_disable;
181 }
182
183 switch (rsp.value) {
184 case DLN2_GPIO_DIRECTION_IN:
185 clear_bit(offset, dln2->output_enabled);
186 return 0;
187 case DLN2_GPIO_DIRECTION_OUT:
188 set_bit(offset, dln2->output_enabled);
189 return 0;
190 default:
191 ret = -EPROTO;
192 goto out_disable;
193 }
194
195out_disable:
196 dln2_gpio_pin_cmd(dln2, DLN2_GPIO_PIN_DISABLE, offset);
197 return ret;
198}
199
200static void dln2_gpio_free(struct gpio_chip *chip, unsigned offset)
201{
202 struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio);
203
204 dln2_gpio_pin_cmd(dln2, DLN2_GPIO_PIN_DISABLE, offset);
205}
206
207static int dln2_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
208{
209 struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio);
210
211 if (test_bit(offset, dln2->output_enabled))
212 return GPIOF_DIR_OUT;
213
214 return GPIOF_DIR_IN;
215}
216
217static int dln2_gpio_get(struct gpio_chip *chip, unsigned int offset)
218{
219 struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio);
220 int dir;
221
222 dir = dln2_gpio_get_direction(chip, offset);
223 if (dir < 0)
224 return dir;
225
226 if (dir == GPIOF_DIR_IN)
227 return dln2_gpio_pin_get_in_val(dln2, offset);
228
229 return dln2_gpio_pin_get_out_val(dln2, offset);
230}
231
232static void dln2_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
233{
234 struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio);
235
236 dln2_gpio_pin_set_out_val(dln2, offset, value);
237}
238
239static int dln2_gpio_set_direction(struct gpio_chip *chip, unsigned offset,
240 unsigned dir)
241{
242 struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio);
243 struct dln2_gpio_pin_val req = {
244 .pin = cpu_to_le16(offset),
245 .value = dir,
246 };
247 int ret;
248
249 ret = dln2_transfer_tx(dln2->pdev, DLN2_GPIO_PIN_SET_DIRECTION,
250 &req, sizeof(req));
251 if (ret < 0)
252 return ret;
253
254 if (dir == DLN2_GPIO_DIRECTION_OUT)
255 set_bit(offset, dln2->output_enabled);
256 else
257 clear_bit(offset, dln2->output_enabled);
258
259 return ret;
260}
261
262static int dln2_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
263{
264 return dln2_gpio_set_direction(chip, offset, DLN2_GPIO_DIRECTION_IN);
265}
266
267static int dln2_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
268 int value)
269{
270 return dln2_gpio_set_direction(chip, offset, DLN2_GPIO_DIRECTION_OUT);
271}
272
273static int dln2_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
274 unsigned debounce)
275{
276 struct dln2_gpio *dln2 = container_of(chip, struct dln2_gpio, gpio);
277 __le32 duration = cpu_to_le32(debounce);
278
279 return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_SET_DEBOUNCE,
280 &duration, sizeof(duration));
281}
282
283static int dln2_gpio_set_event_cfg(struct dln2_gpio *dln2, unsigned pin,
284 unsigned type, unsigned period)
285{
286 struct {
287 __le16 pin;
288 u8 type;
289 __le16 period;
290 } __packed req = {
291 .pin = cpu_to_le16(pin),
292 .type = type,
293 .period = cpu_to_le16(period),
294 };
295
296 return dln2_transfer_tx(dln2->pdev, DLN2_GPIO_PIN_SET_EVENT_CFG,
297 &req, sizeof(req));
298}
299
300static void dln2_irq_work(struct work_struct *w)
301{
302 struct dln2_irq_work *iw = container_of(w, struct dln2_irq_work, work);
303 struct dln2_gpio *dln2 = iw->dln2;
304 u8 type = iw->type & DLN2_GPIO_EVENT_MASK;
305
306 if (test_bit(iw->pin, dln2->irqs_enabled))
307 dln2_gpio_set_event_cfg(dln2, iw->pin, type, 0);
308 else
309 dln2_gpio_set_event_cfg(dln2, iw->pin, DLN2_GPIO_EVENT_NONE, 0);
310}
311
312static void dln2_irq_enable(struct irq_data *irqd)
313{
314 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
315 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
316 int pin = irqd_to_hwirq(irqd);
317
318 set_bit(pin, dln2->irqs_enabled);
319 schedule_work(&dln2->irq_work[pin].work);
320}
321
322static void dln2_irq_disable(struct irq_data *irqd)
323{
324 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
325 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
326 int pin = irqd_to_hwirq(irqd);
327
328 clear_bit(pin, dln2->irqs_enabled);
329 schedule_work(&dln2->irq_work[pin].work);
330}
331
332static void dln2_irq_mask(struct irq_data *irqd)
333{
334 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
335 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
336 int pin = irqd_to_hwirq(irqd);
337
338 set_bit(pin, dln2->irqs_masked);
339}
340
341static void dln2_irq_unmask(struct irq_data *irqd)
342{
343 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
344 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
345 struct device *dev = dln2->gpio.dev;
346 int pin = irqd_to_hwirq(irqd);
347
348 if (test_and_clear_bit(pin, dln2->irqs_pending)) {
349 int irq;
350
351 irq = irq_find_mapping(dln2->gpio.irqdomain, pin);
352 if (!irq) {
353 dev_err(dev, "pin %d not mapped to IRQ\n", pin);
354 return;
355 }
356
357 generic_handle_irq(irq);
358 }
359}
360
361static int dln2_irq_set_type(struct irq_data *irqd, unsigned type)
362{
363 struct gpio_chip *gc = irq_data_get_irq_chip_data(irqd);
364 struct dln2_gpio *dln2 = container_of(gc, struct dln2_gpio, gpio);
365 int pin = irqd_to_hwirq(irqd);
366
367 switch (type) {
368 case IRQ_TYPE_LEVEL_HIGH:
369 dln2->irq_work[pin].type = DLN2_GPIO_EVENT_LVL_HIGH;
370 break;
371 case IRQ_TYPE_LEVEL_LOW:
372 dln2->irq_work[pin].type = DLN2_GPIO_EVENT_LVL_LOW;
373 break;
374 case IRQ_TYPE_EDGE_BOTH:
375 dln2->irq_work[pin].type = DLN2_GPIO_EVENT_CHANGE;
376 break;
377 case IRQ_TYPE_EDGE_RISING:
378 dln2->irq_work[pin].type = DLN2_GPIO_EVENT_CHANGE_RISING;
379 break;
380 case IRQ_TYPE_EDGE_FALLING:
381 dln2->irq_work[pin].type = DLN2_GPIO_EVENT_CHANGE_FALLING;
382 break;
383 default:
384 return -EINVAL;
385 }
386
387 return 0;
388}
389
390static struct irq_chip dln2_gpio_irqchip = {
391 .name = "dln2-irq",
392 .irq_enable = dln2_irq_enable,
393 .irq_disable = dln2_irq_disable,
394 .irq_mask = dln2_irq_mask,
395 .irq_unmask = dln2_irq_unmask,
396 .irq_set_type = dln2_irq_set_type,
397};
398
399static void dln2_gpio_event(struct platform_device *pdev, u16 echo,
400 const void *data, int len)
401{
402 int pin, irq;
403 const struct {
404 __le16 count;
405 __u8 type;
406 __le16 pin;
407 __u8 value;
408 } __packed *event = data;
409 struct dln2_gpio *dln2 = platform_get_drvdata(pdev);
410
411 if (len < sizeof(*event)) {
412 dev_err(dln2->gpio.dev, "short event message\n");
413 return;
414 }
415
416 pin = le16_to_cpu(event->pin);
417 if (pin >= dln2->gpio.ngpio) {
418 dev_err(dln2->gpio.dev, "out of bounds pin %d\n", pin);
419 return;
420 }
421
422 irq = irq_find_mapping(dln2->gpio.irqdomain, pin);
423 if (!irq) {
424 dev_err(dln2->gpio.dev, "pin %d not mapped to IRQ\n", pin);
425 return;
426 }
427
428 if (!test_bit(pin, dln2->irqs_enabled))
429 return;
430 if (test_bit(pin, dln2->irqs_masked)) {
431 set_bit(pin, dln2->irqs_pending);
432 return;
433 }
434
435 switch (dln2->irq_work[pin].type) {
436 case DLN2_GPIO_EVENT_CHANGE_RISING:
437 if (event->value)
438 generic_handle_irq(irq);
439 break;
440 case DLN2_GPIO_EVENT_CHANGE_FALLING:
441 if (!event->value)
442 generic_handle_irq(irq);
443 break;
444 default:
445 generic_handle_irq(irq);
446 }
447}
448
449static int dln2_gpio_probe(struct platform_device *pdev)
450{
451 struct dln2_gpio *dln2;
452 struct device *dev = &pdev->dev;
453 int pins;
454 int i, ret;
455
456 pins = dln2_gpio_get_pin_count(pdev);
457 if (pins < 0) {
458 dev_err(dev, "failed to get pin count: %d\n", pins);
459 return pins;
460 }
461 if (pins > DLN2_GPIO_MAX_PINS) {
462 pins = DLN2_GPIO_MAX_PINS;
463 dev_warn(dev, "clamping pins to %d\n", DLN2_GPIO_MAX_PINS);
464 }
465
466 dln2 = devm_kzalloc(&pdev->dev, sizeof(*dln2), GFP_KERNEL);
467 if (!dln2)
468 return -ENOMEM;
469
470 dln2->irq_work = devm_kcalloc(&pdev->dev, pins,
471 sizeof(struct dln2_irq_work), GFP_KERNEL);
472 if (!dln2->irq_work)
473 return -ENOMEM;
474 for (i = 0; i < pins; i++) {
475 INIT_WORK(&dln2->irq_work[i].work, dln2_irq_work);
476 dln2->irq_work[i].pin = i;
477 dln2->irq_work[i].dln2 = dln2;
478 }
479
480 dln2->pdev = pdev;
481
482 dln2->gpio.label = "dln2";
483 dln2->gpio.dev = dev;
484 dln2->gpio.owner = THIS_MODULE;
485 dln2->gpio.base = -1;
486 dln2->gpio.ngpio = pins;
487 dln2->gpio.exported = true;
488 dln2->gpio.can_sleep = true;
489 dln2->gpio.irq_not_threaded = true;
490 dln2->gpio.set = dln2_gpio_set;
491 dln2->gpio.get = dln2_gpio_get;
492 dln2->gpio.request = dln2_gpio_request;
493 dln2->gpio.free = dln2_gpio_free;
494 dln2->gpio.get_direction = dln2_gpio_get_direction;
495 dln2->gpio.direction_input = dln2_gpio_direction_input;
496 dln2->gpio.direction_output = dln2_gpio_direction_output;
497 dln2->gpio.set_debounce = dln2_gpio_set_debounce;
498
499 platform_set_drvdata(pdev, dln2);
500
501 ret = gpiochip_add(&dln2->gpio);
502 if (ret < 0) {
503 dev_err(dev, "failed to add gpio chip: %d\n", ret);
504 goto out;
505 }
506
507 ret = gpiochip_irqchip_add(&dln2->gpio, &dln2_gpio_irqchip, 0,
508 handle_simple_irq, IRQ_TYPE_NONE);
509 if (ret < 0) {
510 dev_err(dev, "failed to add irq chip: %d\n", ret);
511 goto out_gpiochip_remove;
512 }
513
514 ret = dln2_register_event_cb(pdev, DLN2_GPIO_CONDITION_MET_EV,
515 dln2_gpio_event);
516 if (ret) {
517 dev_err(dev, "failed to register event cb: %d\n", ret);
518 goto out_gpiochip_remove;
519 }
520
521 return 0;
522
523out_gpiochip_remove:
524 gpiochip_remove(&dln2->gpio);
525out:
526 return ret;
527}
528
529static int dln2_gpio_remove(struct platform_device *pdev)
530{
531 struct dln2_gpio *dln2 = platform_get_drvdata(pdev);
532 int i;
533
534 dln2_unregister_event_cb(pdev, DLN2_GPIO_CONDITION_MET_EV);
535 for (i = 0; i < dln2->gpio.ngpio; i++)
536 flush_work(&dln2->irq_work[i].work);
537 gpiochip_remove(&dln2->gpio);
538
539 return 0;
540}
541
542static struct platform_driver dln2_gpio_driver = {
543 .driver.name = "dln2-gpio",
544 .probe = dln2_gpio_probe,
545 .remove = dln2_gpio_remove,
546};
547
548module_platform_driver(dln2_gpio_driver);
549
550MODULE_AUTHOR("Daniel Baluta <daniel.baluta@intel.com");
551MODULE_DESCRIPTION("Driver for the Diolan DLN2 GPIO interface");
552MODULE_LICENSE("GPL v2");
553MODULE_ALIAS("platform:dln2-gpio");
diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c
index ae0f6466eb09..abdcf58935f5 100644
--- a/drivers/gpio/gpio-tc3589x.c
+++ b/drivers/gpio/gpio-tc3589x.c
@@ -262,7 +262,7 @@ static int tc3589x_gpio_probe(struct platform_device *pdev)
262 tc3589x_gpio->chip = template_chip; 262 tc3589x_gpio->chip = template_chip;
263 tc3589x_gpio->chip.ngpio = tc3589x->num_gpio; 263 tc3589x_gpio->chip.ngpio = tc3589x->num_gpio;
264 tc3589x_gpio->chip.dev = &pdev->dev; 264 tc3589x_gpio->chip.dev = &pdev->dev;
265 tc3589x_gpio->chip.base = (pdata) ? pdata->gpio_base : -1; 265 tc3589x_gpio->chip.base = -1;
266 266
267#ifdef CONFIG_OF_GPIO 267#ifdef CONFIG_OF_GPIO
268 tc3589x_gpio->chip.of_node = np; 268 tc3589x_gpio->chip.of_node = np;
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index c57466edf45b..e5c4c6c8c967 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -495,6 +495,12 @@ static struct component_match *exynos_drm_match_add(struct device *dev)
495 495
496 mutex_lock(&drm_component_lock); 496 mutex_lock(&drm_component_lock);
497 497
498 /* Do not retry to probe if there is no any kms driver regitered. */
499 if (list_empty(&drm_component_list)) {
500 mutex_unlock(&drm_component_lock);
501 return ERR_PTR(-ENODEV);
502 }
503
498 list_for_each_entry(cdev, &drm_component_list, list) { 504 list_for_each_entry(cdev, &drm_component_list, list) {
499 /* 505 /*
500 * Add components to master only in case that crtc and 506 * Add components to master only in case that crtc and
@@ -585,10 +591,21 @@ static int exynos_drm_platform_probe(struct platform_device *pdev)
585 goto err_unregister_mixer_drv; 591 goto err_unregister_mixer_drv;
586#endif 592#endif
587 593
594 match = exynos_drm_match_add(&pdev->dev);
595 if (IS_ERR(match)) {
596 ret = PTR_ERR(match);
597 goto err_unregister_hdmi_drv;
598 }
599
600 ret = component_master_add_with_match(&pdev->dev, &exynos_drm_ops,
601 match);
602 if (ret < 0)
603 goto err_unregister_hdmi_drv;
604
588#ifdef CONFIG_DRM_EXYNOS_G2D 605#ifdef CONFIG_DRM_EXYNOS_G2D
589 ret = platform_driver_register(&g2d_driver); 606 ret = platform_driver_register(&g2d_driver);
590 if (ret < 0) 607 if (ret < 0)
591 goto err_unregister_hdmi_drv; 608 goto err_del_component_master;
592#endif 609#endif
593 610
594#ifdef CONFIG_DRM_EXYNOS_FIMC 611#ifdef CONFIG_DRM_EXYNOS_FIMC
@@ -619,23 +636,9 @@ static int exynos_drm_platform_probe(struct platform_device *pdev)
619 goto err_unregister_ipp_drv; 636 goto err_unregister_ipp_drv;
620#endif 637#endif
621 638
622 match = exynos_drm_match_add(&pdev->dev);
623 if (IS_ERR(match)) {
624 ret = PTR_ERR(match);
625 goto err_unregister_resources;
626 }
627
628 ret = component_master_add_with_match(&pdev->dev, &exynos_drm_ops,
629 match);
630 if (ret < 0)
631 goto err_unregister_resources;
632
633 return ret; 639 return ret;
634 640
635err_unregister_resources:
636
637#ifdef CONFIG_DRM_EXYNOS_IPP 641#ifdef CONFIG_DRM_EXYNOS_IPP
638 exynos_platform_device_ipp_unregister();
639err_unregister_ipp_drv: 642err_unregister_ipp_drv:
640 platform_driver_unregister(&ipp_driver); 643 platform_driver_unregister(&ipp_driver);
641err_unregister_gsc_drv: 644err_unregister_gsc_drv:
@@ -658,9 +661,11 @@ err_unregister_g2d_drv:
658 661
659#ifdef CONFIG_DRM_EXYNOS_G2D 662#ifdef CONFIG_DRM_EXYNOS_G2D
660 platform_driver_unregister(&g2d_driver); 663 platform_driver_unregister(&g2d_driver);
661err_unregister_hdmi_drv: 664err_del_component_master:
662#endif 665#endif
666 component_master_del(&pdev->dev, &exynos_drm_ops);
663 667
668err_unregister_hdmi_drv:
664#ifdef CONFIG_DRM_EXYNOS_HDMI 669#ifdef CONFIG_DRM_EXYNOS_HDMI
665 platform_driver_unregister(&hdmi_driver); 670 platform_driver_unregister(&hdmi_driver);
666err_unregister_mixer_drv: 671err_unregister_mixer_drv:
@@ -741,6 +746,18 @@ static int exynos_drm_init(void)
741{ 746{
742 int ret; 747 int ret;
743 748
749 /*
750 * Register device object only in case of Exynos SoC.
751 *
752 * Below codes resolves temporarily infinite loop issue incurred
753 * by Exynos drm driver when using multi-platform kernel.
754 * So these codes will be replaced with more generic way later.
755 */
756 if (!of_machine_is_compatible("samsung,exynos3") &&
757 !of_machine_is_compatible("samsung,exynos4") &&
758 !of_machine_is_compatible("samsung,exynos5"))
759 return -ENODEV;
760
744 exynos_drm_pdev = platform_device_register_simple("exynos-drm", -1, 761 exynos_drm_pdev = platform_device_register_simple("exynos-drm", -1,
745 NULL, 0); 762 NULL, 0);
746 if (IS_ERR(exynos_drm_pdev)) 763 if (IS_ERR(exynos_drm_pdev))
diff --git a/drivers/gpu/drm/exynos/exynos_drm_g2d.c b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
index df7a77d3eff8..6ff8599f6cbf 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_g2d.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_g2d.c
@@ -302,9 +302,12 @@ static void g2d_fini_cmdlist(struct g2d_data *g2d)
302 struct exynos_drm_subdrv *subdrv = &g2d->subdrv; 302 struct exynos_drm_subdrv *subdrv = &g2d->subdrv;
303 303
304 kfree(g2d->cmdlist_node); 304 kfree(g2d->cmdlist_node);
305 dma_free_attrs(subdrv->drm_dev->dev, G2D_CMDLIST_POOL_SIZE, 305
306 g2d->cmdlist_pool_virt, 306 if (g2d->cmdlist_pool_virt && g2d->cmdlist_pool) {
307 g2d->cmdlist_pool, &g2d->cmdlist_dma_attrs); 307 dma_free_attrs(subdrv->drm_dev->dev, G2D_CMDLIST_POOL_SIZE,
308 g2d->cmdlist_pool_virt,
309 g2d->cmdlist_pool, &g2d->cmdlist_dma_attrs);
310 }
308} 311}
309 312
310static struct g2d_cmdlist_node *g2d_get_cmdlist(struct g2d_data *g2d) 313static struct g2d_cmdlist_node *g2d_get_cmdlist(struct g2d_data *g2d)
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 1403b01e8216..318ade9bb5af 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1670,15 +1670,17 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
1670 goto out_regs; 1670 goto out_regs;
1671 1671
1672 if (drm_core_check_feature(dev, DRIVER_MODESET)) { 1672 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
1673 ret = i915_kick_out_vgacon(dev_priv); 1673 /* WARNING: Apparently we must kick fbdev drivers before vgacon,
1674 * otherwise the vga fbdev driver falls over. */
1675 ret = i915_kick_out_firmware_fb(dev_priv);
1674 if (ret) { 1676 if (ret) {
1675 DRM_ERROR("failed to remove conflicting VGA console\n"); 1677 DRM_ERROR("failed to remove conflicting framebuffer drivers\n");
1676 goto out_gtt; 1678 goto out_gtt;
1677 } 1679 }
1678 1680
1679 ret = i915_kick_out_firmware_fb(dev_priv); 1681 ret = i915_kick_out_vgacon(dev_priv);
1680 if (ret) { 1682 if (ret) {
1681 DRM_ERROR("failed to remove conflicting framebuffer drivers\n"); 1683 DRM_ERROR("failed to remove conflicting VGA console\n");
1682 goto out_gtt; 1684 goto out_gtt;
1683 } 1685 }
1684 } 1686 }
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 055d5e7fbf12..2318b4c7a8f8 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -986,6 +986,15 @@ static int i915_pm_freeze(struct device *dev)
986 return i915_drm_freeze(drm_dev); 986 return i915_drm_freeze(drm_dev);
987} 987}
988 988
989static int i915_pm_freeze_late(struct device *dev)
990{
991 struct pci_dev *pdev = to_pci_dev(dev);
992 struct drm_device *drm_dev = pci_get_drvdata(pdev);
993 struct drm_i915_private *dev_priv = drm_dev->dev_private;
994
995 return intel_suspend_complete(dev_priv);
996}
997
989static int i915_pm_thaw_early(struct device *dev) 998static int i915_pm_thaw_early(struct device *dev)
990{ 999{
991 struct pci_dev *pdev = to_pci_dev(dev); 1000 struct pci_dev *pdev = to_pci_dev(dev);
@@ -1570,6 +1579,7 @@ static const struct dev_pm_ops i915_pm_ops = {
1570 .resume_early = i915_pm_resume_early, 1579 .resume_early = i915_pm_resume_early,
1571 .resume = i915_pm_resume, 1580 .resume = i915_pm_resume,
1572 .freeze = i915_pm_freeze, 1581 .freeze = i915_pm_freeze,
1582 .freeze_late = i915_pm_freeze_late,
1573 .thaw_early = i915_pm_thaw_early, 1583 .thaw_early = i915_pm_thaw_early,
1574 .thaw = i915_pm_thaw, 1584 .thaw = i915_pm_thaw,
1575 .poweroff = i915_pm_poweroff, 1585 .poweroff = i915_pm_poweroff,
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
index b672b843fd5e..728938f02341 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
@@ -1902,6 +1902,22 @@ static void bdw_setup_private_ppat(struct drm_i915_private *dev_priv)
1902 GEN8_PPAT(6, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2)) | 1902 GEN8_PPAT(6, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2)) |
1903 GEN8_PPAT(7, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3)); 1903 GEN8_PPAT(7, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3));
1904 1904
1905 if (!USES_PPGTT(dev_priv->dev))
1906 /* Spec: "For GGTT, there is NO pat_sel[2:0] from the entry,
1907 * so RTL will always use the value corresponding to
1908 * pat_sel = 000".
1909 * So let's disable cache for GGTT to avoid screen corruptions.
1910 * MOCS still can be used though.
1911 * - System agent ggtt writes (i.e. cpu gtt mmaps) already work
1912 * before this patch, i.e. the same uncached + snooping access
1913 * like on gen6/7 seems to be in effect.
1914 * - So this just fixes blitter/render access. Again it looks
1915 * like it's not just uncached access, but uncached + snooping.
1916 * So we can still hold onto all our assumptions wrt cpu
1917 * clflushing on LLC machines.
1918 */
1919 pat = GEN8_PPAT(0, GEN8_PPAT_UC);
1920
1905 /* XXX: spec defines this as 2 distinct registers. It's unclear if a 64b 1921 /* XXX: spec defines this as 2 distinct registers. It's unclear if a 64b
1906 * write would work. */ 1922 * write would work. */
1907 I915_WRITE(GEN8_PRIVATE_PAT, pat); 1923 I915_WRITE(GEN8_PRIVATE_PAT, pat);
diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c
index 2cefb597df6d..2b1eaa29ada4 100644
--- a/drivers/gpu/drm/i915/i915_gem_tiling.c
+++ b/drivers/gpu/drm/i915/i915_gem_tiling.c
@@ -364,22 +364,9 @@ i915_gem_set_tiling(struct drm_device *dev, void *data,
364 * has to also include the unfenced register the GPU uses 364 * has to also include the unfenced register the GPU uses
365 * whilst executing a fenced command for an untiled object. 365 * whilst executing a fenced command for an untiled object.
366 */ 366 */
367 367 if (obj->map_and_fenceable &&
368 obj->map_and_fenceable = 368 !i915_gem_object_fence_ok(obj, args->tiling_mode))
369 !i915_gem_obj_ggtt_bound(obj) || 369 ret = i915_gem_object_ggtt_unbind(obj);
370 (i915_gem_obj_ggtt_offset(obj) +
371 obj->base.size <= dev_priv->gtt.mappable_end &&
372 i915_gem_object_fence_ok(obj, args->tiling_mode));
373
374 /* Rebind if we need a change of alignment */
375 if (!obj->map_and_fenceable) {
376 u32 unfenced_align =
377 i915_gem_get_gtt_alignment(dev, obj->base.size,
378 args->tiling_mode,
379 false);
380 if (i915_gem_obj_ggtt_offset(obj) & (unfenced_align - 1))
381 ret = i915_gem_object_ggtt_unbind(obj);
382 }
383 370
384 if (ret == 0) { 371 if (ret == 0) {
385 obj->fence_dirty = 372 obj->fence_dirty =
diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index f0a1a56406eb..9cb5c95d5898 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -4325,7 +4325,6 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
4325 ironlake_fdi_disable(crtc); 4325 ironlake_fdi_disable(crtc);
4326 4326
4327 ironlake_disable_pch_transcoder(dev_priv, pipe); 4327 ironlake_disable_pch_transcoder(dev_priv, pipe);
4328 intel_set_pch_fifo_underrun_reporting(dev, pipe, true);
4329 4328
4330 if (HAS_PCH_CPT(dev)) { 4329 if (HAS_PCH_CPT(dev)) {
4331 /* disable TRANS_DP_CTL */ 4330 /* disable TRANS_DP_CTL */
@@ -4389,7 +4388,6 @@ static void haswell_crtc_disable(struct drm_crtc *crtc)
4389 4388
4390 if (intel_crtc->config.has_pch_encoder) { 4389 if (intel_crtc->config.has_pch_encoder) {
4391 lpt_disable_pch_transcoder(dev_priv); 4390 lpt_disable_pch_transcoder(dev_priv);
4392 intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true);
4393 intel_ddi_fdi_disable(crtc); 4391 intel_ddi_fdi_disable(crtc);
4394 } 4392 }
4395 4393
@@ -9408,6 +9406,10 @@ static bool page_flip_finished(struct intel_crtc *crtc)
9408 struct drm_device *dev = crtc->base.dev; 9406 struct drm_device *dev = crtc->base.dev;
9409 struct drm_i915_private *dev_priv = dev->dev_private; 9407 struct drm_i915_private *dev_priv = dev->dev_private;
9410 9408
9409 if (i915_reset_in_progress(&dev_priv->gpu_error) ||
9410 crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
9411 return true;
9412
9411 /* 9413 /*
9412 * The relevant registers doen't exist on pre-ctg. 9414 * The relevant registers doen't exist on pre-ctg.
9413 * As the flip done interrupt doesn't trigger for mmio 9415 * As the flip done interrupt doesn't trigger for mmio
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index 5ad45bfff3fe..4bcd91757321 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -4450,6 +4450,7 @@ static void intel_dp_encoder_suspend(struct intel_encoder *intel_encoder)
4450 * vdd might still be enabled do to the delayed vdd off. 4450 * vdd might still be enabled do to the delayed vdd off.
4451 * Make sure vdd is actually turned off here. 4451 * Make sure vdd is actually turned off here.
4452 */ 4452 */
4453 cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
4453 pps_lock(intel_dp); 4454 pps_lock(intel_dp);
4454 edp_panel_vdd_off_sync(intel_dp); 4455 edp_panel_vdd_off_sync(intel_dp);
4455 pps_unlock(intel_dp); 4456 pps_unlock(intel_dp);
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index a6bd1422e38f..c0bbf2172446 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -899,6 +899,17 @@ void intel_lvds_init(struct drm_device *dev)
899 int pipe; 899 int pipe;
900 u8 pin; 900 u8 pin;
901 901
902 /*
903 * Unlock registers and just leave them unlocked. Do this before
904 * checking quirk lists to avoid bogus WARNINGs.
905 */
906 if (HAS_PCH_SPLIT(dev)) {
907 I915_WRITE(PCH_PP_CONTROL,
908 I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
909 } else {
910 I915_WRITE(PP_CONTROL,
911 I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
912 }
902 if (!intel_lvds_supported(dev)) 913 if (!intel_lvds_supported(dev))
903 return; 914 return;
904 915
@@ -1097,17 +1108,6 @@ out:
1097 lvds_encoder->a3_power = I915_READ(lvds_encoder->reg) & 1108 lvds_encoder->a3_power = I915_READ(lvds_encoder->reg) &
1098 LVDS_A3_POWER_MASK; 1109 LVDS_A3_POWER_MASK;
1099 1110
1100 /*
1101 * Unlock registers and just
1102 * leave them unlocked
1103 */
1104 if (HAS_PCH_SPLIT(dev)) {
1105 I915_WRITE(PCH_PP_CONTROL,
1106 I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
1107 } else {
1108 I915_WRITE(PP_CONTROL,
1109 I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
1110 }
1111 lvds_connector->lid_notifier.notifier_call = intel_lid_notify; 1111 lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
1112 if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) { 1112 if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
1113 DRM_DEBUG_KMS("lid notifier registration failed\n"); 1113 DRM_DEBUG_KMS("lid notifier registration failed\n");
diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
index 0e018cb49147..41b3be217493 100644
--- a/drivers/gpu/drm/i915/intel_panel.c
+++ b/drivers/gpu/drm/i915/intel_panel.c
@@ -1098,12 +1098,25 @@ static u32 get_backlight_min_vbt(struct intel_connector *connector)
1098 struct drm_device *dev = connector->base.dev; 1098 struct drm_device *dev = connector->base.dev;
1099 struct drm_i915_private *dev_priv = dev->dev_private; 1099 struct drm_i915_private *dev_priv = dev->dev_private;
1100 struct intel_panel *panel = &connector->panel; 1100 struct intel_panel *panel = &connector->panel;
1101 int min;
1101 1102
1102 WARN_ON(panel->backlight.max == 0); 1103 WARN_ON(panel->backlight.max == 0);
1103 1104
1105 /*
1106 * XXX: If the vbt value is 255, it makes min equal to max, which leads
1107 * to problems. There are such machines out there. Either our
1108 * interpretation is wrong or the vbt has bogus data. Or both. Safeguard
1109 * against this by letting the minimum be at most (arbitrarily chosen)
1110 * 25% of the max.
1111 */
1112 min = clamp_t(int, dev_priv->vbt.backlight.min_brightness, 0, 64);
1113 if (min != dev_priv->vbt.backlight.min_brightness) {
1114 DRM_DEBUG_KMS("clamping VBT min backlight %d/255 to %d/255\n",
1115 dev_priv->vbt.backlight.min_brightness, min);
1116 }
1117
1104 /* vbt value is a coefficient in range [0..255] */ 1118 /* vbt value is a coefficient in range [0..255] */
1105 return scale(dev_priv->vbt.backlight.min_brightness, 0, 255, 1119 return scale(min, 0, 255, 0, panel->backlight.max);
1106 0, panel->backlight.max);
1107} 1120}
1108 1121
1109static int bdw_setup_backlight(struct intel_connector *connector) 1122static int bdw_setup_backlight(struct intel_connector *connector)
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
index c27b6140bfd1..ad2fd605f76b 100644
--- a/drivers/gpu/drm/i915/intel_pm.c
+++ b/drivers/gpu/drm/i915/intel_pm.c
@@ -5469,11 +5469,6 @@ static void gen6_init_clock_gating(struct drm_device *dev)
5469 I915_WRITE(_3D_CHICKEN, 5469 I915_WRITE(_3D_CHICKEN,
5470 _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB)); 5470 _MASKED_BIT_ENABLE(_3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB));
5471 5471
5472 /* WaSetupGtModeTdRowDispatch:snb */
5473 if (IS_SNB_GT1(dev))
5474 I915_WRITE(GEN6_GT_MODE,
5475 _MASKED_BIT_ENABLE(GEN6_TD_FOUR_ROW_DISPATCH_DISABLE));
5476
5477 /* WaDisable_RenderCache_OperationalFlush:snb */ 5472 /* WaDisable_RenderCache_OperationalFlush:snb */
5478 I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE)); 5473 I915_WRITE(CACHE_MODE_0, _MASKED_BIT_DISABLE(RC_OP_FLUSH_ENABLE));
5479 5474
diff --git a/drivers/gpu/drm/nouveau/core/engine/device/nvc0.c b/drivers/gpu/drm/nouveau/core/engine/device/nvc0.c
index cd05677ad4b7..72a40f95d048 100644
--- a/drivers/gpu/drm/nouveau/core/engine/device/nvc0.c
+++ b/drivers/gpu/drm/nouveau/core/engine/device/nvc0.c
@@ -218,7 +218,6 @@ nvc0_identify(struct nouveau_device *device)
218 device->oclass[NVDEV_ENGINE_BSP ] = &nvc0_bsp_oclass; 218 device->oclass[NVDEV_ENGINE_BSP ] = &nvc0_bsp_oclass;
219 device->oclass[NVDEV_ENGINE_PPP ] = &nvc0_ppp_oclass; 219 device->oclass[NVDEV_ENGINE_PPP ] = &nvc0_ppp_oclass;
220 device->oclass[NVDEV_ENGINE_COPY0 ] = &nvc0_copy0_oclass; 220 device->oclass[NVDEV_ENGINE_COPY0 ] = &nvc0_copy0_oclass;
221 device->oclass[NVDEV_ENGINE_COPY1 ] = &nvc0_copy1_oclass;
222 device->oclass[NVDEV_ENGINE_DISP ] = nva3_disp_oclass; 221 device->oclass[NVDEV_ENGINE_DISP ] = nva3_disp_oclass;
223 device->oclass[NVDEV_ENGINE_PERFMON] = &nvc0_perfmon_oclass; 222 device->oclass[NVDEV_ENGINE_PERFMON] = &nvc0_perfmon_oclass;
224 break; 223 break;
diff --git a/drivers/gpu/drm/nouveau/core/engine/fifo/nv04.c b/drivers/gpu/drm/nouveau/core/engine/fifo/nv04.c
index 5ae6a43893b5..1931057f9962 100644
--- a/drivers/gpu/drm/nouveau/core/engine/fifo/nv04.c
+++ b/drivers/gpu/drm/nouveau/core/engine/fifo/nv04.c
@@ -551,8 +551,8 @@ nv04_fifo_intr(struct nouveau_subdev *subdev)
551 } 551 }
552 552
553 if (status & 0x40000000) { 553 if (status & 0x40000000) {
554 nouveau_fifo_uevent(&priv->base);
555 nv_wr32(priv, 0x002100, 0x40000000); 554 nv_wr32(priv, 0x002100, 0x40000000);
555 nouveau_fifo_uevent(&priv->base);
556 status &= ~0x40000000; 556 status &= ~0x40000000;
557 } 557 }
558 } 558 }
diff --git a/drivers/gpu/drm/nouveau/core/engine/fifo/nvc0.c b/drivers/gpu/drm/nouveau/core/engine/fifo/nvc0.c
index 1fe1f8fbda0c..074d434c3077 100644
--- a/drivers/gpu/drm/nouveau/core/engine/fifo/nvc0.c
+++ b/drivers/gpu/drm/nouveau/core/engine/fifo/nvc0.c
@@ -740,6 +740,8 @@ nvc0_fifo_intr_engine_unit(struct nvc0_fifo_priv *priv, int engn)
740 u32 inte = nv_rd32(priv, 0x002628); 740 u32 inte = nv_rd32(priv, 0x002628);
741 u32 unkn; 741 u32 unkn;
742 742
743 nv_wr32(priv, 0x0025a8 + (engn * 0x04), intr);
744
743 for (unkn = 0; unkn < 8; unkn++) { 745 for (unkn = 0; unkn < 8; unkn++) {
744 u32 ints = (intr >> (unkn * 0x04)) & inte; 746 u32 ints = (intr >> (unkn * 0x04)) & inte;
745 if (ints & 0x1) { 747 if (ints & 0x1) {
@@ -751,8 +753,6 @@ nvc0_fifo_intr_engine_unit(struct nvc0_fifo_priv *priv, int engn)
751 nv_mask(priv, 0x002628, ints, 0); 753 nv_mask(priv, 0x002628, ints, 0);
752 } 754 }
753 } 755 }
754
755 nv_wr32(priv, 0x0025a8 + (engn * 0x04), intr);
756} 756}
757 757
758static void 758static void
diff --git a/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c b/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c
index d2f0fd39c145..f8734eb74eaa 100644
--- a/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c
+++ b/drivers/gpu/drm/nouveau/core/engine/fifo/nve0.c
@@ -952,8 +952,8 @@ nve0_fifo_intr(struct nouveau_subdev *subdev)
952 } 952 }
953 953
954 if (stat & 0x80000000) { 954 if (stat & 0x80000000) {
955 nve0_fifo_intr_engine(priv);
956 nv_wr32(priv, 0x002100, 0x80000000); 955 nv_wr32(priv, 0x002100, 0x80000000);
956 nve0_fifo_intr_engine(priv);
957 stat &= ~0x80000000; 957 stat &= ~0x80000000;
958 } 958 }
959 959
diff --git a/drivers/gpu/drm/nouveau/core/subdev/fb/gk20a.c b/drivers/gpu/drm/nouveau/core/subdev/fb/gk20a.c
index a16024a74771..fde42e4d1b56 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/fb/gk20a.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/fb/gk20a.c
@@ -27,6 +27,20 @@ struct gk20a_fb_priv {
27}; 27};
28 28
29static int 29static int
30gk20a_fb_init(struct nouveau_object *object)
31{
32 struct gk20a_fb_priv *priv = (void *)object;
33 int ret;
34
35 ret = nouveau_fb_init(&priv->base);
36 if (ret)
37 return ret;
38
39 nv_mask(priv, 0x100c80, 0x00000001, 0x00000000); /* 128KiB lpg */
40 return 0;
41}
42
43static int
30gk20a_fb_ctor(struct nouveau_object *parent, struct nouveau_object *engine, 44gk20a_fb_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
31 struct nouveau_oclass *oclass, void *data, u32 size, 45 struct nouveau_oclass *oclass, void *data, u32 size,
32 struct nouveau_object **pobject) 46 struct nouveau_object **pobject)
@@ -48,7 +62,7 @@ gk20a_fb_oclass = &(struct nouveau_fb_impl) {
48 .base.ofuncs = &(struct nouveau_ofuncs) { 62 .base.ofuncs = &(struct nouveau_ofuncs) {
49 .ctor = gk20a_fb_ctor, 63 .ctor = gk20a_fb_ctor,
50 .dtor = _nouveau_fb_dtor, 64 .dtor = _nouveau_fb_dtor,
51 .init = _nouveau_fb_init, 65 .init = gk20a_fb_init,
52 .fini = _nouveau_fb_fini, 66 .fini = _nouveau_fb_fini,
53 }, 67 },
54 .memtype = nvc0_fb_memtype_valid, 68 .memtype = nvc0_fb_memtype_valid,
diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c
index 57238076049f..62b97c4eef8d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drm.c
@@ -629,7 +629,6 @@ int nouveau_pmops_suspend(struct device *dev)
629 629
630 pci_save_state(pdev); 630 pci_save_state(pdev);
631 pci_disable_device(pdev); 631 pci_disable_device(pdev);
632 pci_ignore_hotplug(pdev);
633 pci_set_power_state(pdev, PCI_D3hot); 632 pci_set_power_state(pdev, PCI_D3hot);
634 return 0; 633 return 0;
635} 634}
@@ -933,6 +932,7 @@ static int nouveau_pmops_runtime_suspend(struct device *dev)
933 ret = nouveau_do_suspend(drm_dev, true); 932 ret = nouveau_do_suspend(drm_dev, true);
934 pci_save_state(pdev); 933 pci_save_state(pdev);
935 pci_disable_device(pdev); 934 pci_disable_device(pdev);
935 pci_ignore_hotplug(pdev);
936 pci_set_power_state(pdev, PCI_D3cold); 936 pci_set_power_state(pdev, PCI_D3cold);
937 drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF; 937 drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
938 return ret; 938 return ret;
diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
index 515cd9aebb99..f32a434724e3 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fence.c
+++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
@@ -52,20 +52,24 @@ nouveau_fctx(struct nouveau_fence *fence)
52 return container_of(fence->base.lock, struct nouveau_fence_chan, lock); 52 return container_of(fence->base.lock, struct nouveau_fence_chan, lock);
53} 53}
54 54
55static void 55static int
56nouveau_fence_signal(struct nouveau_fence *fence) 56nouveau_fence_signal(struct nouveau_fence *fence)
57{ 57{
58 int drop = 0;
59
58 fence_signal_locked(&fence->base); 60 fence_signal_locked(&fence->base);
59 list_del(&fence->head); 61 list_del(&fence->head);
62 rcu_assign_pointer(fence->channel, NULL);
60 63
61 if (test_bit(FENCE_FLAG_USER_BITS, &fence->base.flags)) { 64 if (test_bit(FENCE_FLAG_USER_BITS, &fence->base.flags)) {
62 struct nouveau_fence_chan *fctx = nouveau_fctx(fence); 65 struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
63 66
64 if (!--fctx->notify_ref) 67 if (!--fctx->notify_ref)
65 nvif_notify_put(&fctx->notify); 68 drop = 1;
66 } 69 }
67 70
68 fence_put(&fence->base); 71 fence_put(&fence->base);
72 return drop;
69} 73}
70 74
71static struct nouveau_fence * 75static struct nouveau_fence *
@@ -88,16 +92,23 @@ nouveau_fence_context_del(struct nouveau_fence_chan *fctx)
88{ 92{
89 struct nouveau_fence *fence; 93 struct nouveau_fence *fence;
90 94
91 nvif_notify_fini(&fctx->notify);
92
93 spin_lock_irq(&fctx->lock); 95 spin_lock_irq(&fctx->lock);
94 while (!list_empty(&fctx->pending)) { 96 while (!list_empty(&fctx->pending)) {
95 fence = list_entry(fctx->pending.next, typeof(*fence), head); 97 fence = list_entry(fctx->pending.next, typeof(*fence), head);
96 98
97 nouveau_fence_signal(fence); 99 if (nouveau_fence_signal(fence))
98 fence->channel = NULL; 100 nvif_notify_put(&fctx->notify);
99 } 101 }
100 spin_unlock_irq(&fctx->lock); 102 spin_unlock_irq(&fctx->lock);
103
104 nvif_notify_fini(&fctx->notify);
105 fctx->dead = 1;
106
107 /*
108 * Ensure that all accesses to fence->channel complete before freeing
109 * the channel.
110 */
111 synchronize_rcu();
101} 112}
102 113
103static void 114static void
@@ -112,21 +123,23 @@ nouveau_fence_context_free(struct nouveau_fence_chan *fctx)
112 kref_put(&fctx->fence_ref, nouveau_fence_context_put); 123 kref_put(&fctx->fence_ref, nouveau_fence_context_put);
113} 124}
114 125
115static void 126static int
116nouveau_fence_update(struct nouveau_channel *chan, struct nouveau_fence_chan *fctx) 127nouveau_fence_update(struct nouveau_channel *chan, struct nouveau_fence_chan *fctx)
117{ 128{
118 struct nouveau_fence *fence; 129 struct nouveau_fence *fence;
119 130 int drop = 0;
120 u32 seq = fctx->read(chan); 131 u32 seq = fctx->read(chan);
121 132
122 while (!list_empty(&fctx->pending)) { 133 while (!list_empty(&fctx->pending)) {
123 fence = list_entry(fctx->pending.next, typeof(*fence), head); 134 fence = list_entry(fctx->pending.next, typeof(*fence), head);
124 135
125 if ((int)(seq - fence->base.seqno) < 0) 136 if ((int)(seq - fence->base.seqno) < 0)
126 return; 137 break;
127 138
128 nouveau_fence_signal(fence); 139 drop |= nouveau_fence_signal(fence);
129 } 140 }
141
142 return drop;
130} 143}
131 144
132static int 145static int
@@ -135,18 +148,21 @@ nouveau_fence_wait_uevent_handler(struct nvif_notify *notify)
135 struct nouveau_fence_chan *fctx = 148 struct nouveau_fence_chan *fctx =
136 container_of(notify, typeof(*fctx), notify); 149 container_of(notify, typeof(*fctx), notify);
137 unsigned long flags; 150 unsigned long flags;
151 int ret = NVIF_NOTIFY_KEEP;
138 152
139 spin_lock_irqsave(&fctx->lock, flags); 153 spin_lock_irqsave(&fctx->lock, flags);
140 if (!list_empty(&fctx->pending)) { 154 if (!list_empty(&fctx->pending)) {
141 struct nouveau_fence *fence; 155 struct nouveau_fence *fence;
156 struct nouveau_channel *chan;
142 157
143 fence = list_entry(fctx->pending.next, typeof(*fence), head); 158 fence = list_entry(fctx->pending.next, typeof(*fence), head);
144 nouveau_fence_update(fence->channel, fctx); 159 chan = rcu_dereference_protected(fence->channel, lockdep_is_held(&fctx->lock));
160 if (nouveau_fence_update(fence->channel, fctx))
161 ret = NVIF_NOTIFY_DROP;
145 } 162 }
146 spin_unlock_irqrestore(&fctx->lock, flags); 163 spin_unlock_irqrestore(&fctx->lock, flags);
147 164
148 /* Always return keep here. NVIF refcount is handled with nouveau_fence_update */ 165 return ret;
149 return NVIF_NOTIFY_KEEP;
150} 166}
151 167
152void 168void
@@ -262,7 +278,10 @@ nouveau_fence_emit(struct nouveau_fence *fence, struct nouveau_channel *chan)
262 if (!ret) { 278 if (!ret) {
263 fence_get(&fence->base); 279 fence_get(&fence->base);
264 spin_lock_irq(&fctx->lock); 280 spin_lock_irq(&fctx->lock);
265 nouveau_fence_update(chan, fctx); 281
282 if (nouveau_fence_update(chan, fctx))
283 nvif_notify_put(&fctx->notify);
284
266 list_add_tail(&fence->head, &fctx->pending); 285 list_add_tail(&fence->head, &fctx->pending);
267 spin_unlock_irq(&fctx->lock); 286 spin_unlock_irq(&fctx->lock);
268 } 287 }
@@ -276,13 +295,16 @@ nouveau_fence_done(struct nouveau_fence *fence)
276 if (fence->base.ops == &nouveau_fence_ops_legacy || 295 if (fence->base.ops == &nouveau_fence_ops_legacy ||
277 fence->base.ops == &nouveau_fence_ops_uevent) { 296 fence->base.ops == &nouveau_fence_ops_uevent) {
278 struct nouveau_fence_chan *fctx = nouveau_fctx(fence); 297 struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
298 struct nouveau_channel *chan;
279 unsigned long flags; 299 unsigned long flags;
280 300
281 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->base.flags)) 301 if (test_bit(FENCE_FLAG_SIGNALED_BIT, &fence->base.flags))
282 return true; 302 return true;
283 303
284 spin_lock_irqsave(&fctx->lock, flags); 304 spin_lock_irqsave(&fctx->lock, flags);
285 nouveau_fence_update(fence->channel, fctx); 305 chan = rcu_dereference_protected(fence->channel, lockdep_is_held(&fctx->lock));
306 if (chan && nouveau_fence_update(chan, fctx))
307 nvif_notify_put(&fctx->notify);
286 spin_unlock_irqrestore(&fctx->lock, flags); 308 spin_unlock_irqrestore(&fctx->lock, flags);
287 } 309 }
288 return fence_is_signaled(&fence->base); 310 return fence_is_signaled(&fence->base);
@@ -387,12 +409,18 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e
387 409
388 if (fence && (!exclusive || !fobj || !fobj->shared_count)) { 410 if (fence && (!exclusive || !fobj || !fobj->shared_count)) {
389 struct nouveau_channel *prev = NULL; 411 struct nouveau_channel *prev = NULL;
412 bool must_wait = true;
390 413
391 f = nouveau_local_fence(fence, chan->drm); 414 f = nouveau_local_fence(fence, chan->drm);
392 if (f) 415 if (f) {
393 prev = f->channel; 416 rcu_read_lock();
417 prev = rcu_dereference(f->channel);
418 if (prev && (prev == chan || fctx->sync(f, prev, chan) == 0))
419 must_wait = false;
420 rcu_read_unlock();
421 }
394 422
395 if (!prev || (prev != chan && (ret = fctx->sync(f, prev, chan)))) 423 if (must_wait)
396 ret = fence_wait(fence, intr); 424 ret = fence_wait(fence, intr);
397 425
398 return ret; 426 return ret;
@@ -403,19 +431,22 @@ nouveau_fence_sync(struct nouveau_bo *nvbo, struct nouveau_channel *chan, bool e
403 431
404 for (i = 0; i < fobj->shared_count && !ret; ++i) { 432 for (i = 0; i < fobj->shared_count && !ret; ++i) {
405 struct nouveau_channel *prev = NULL; 433 struct nouveau_channel *prev = NULL;
434 bool must_wait = true;
406 435
407 fence = rcu_dereference_protected(fobj->shared[i], 436 fence = rcu_dereference_protected(fobj->shared[i],
408 reservation_object_held(resv)); 437 reservation_object_held(resv));
409 438
410 f = nouveau_local_fence(fence, chan->drm); 439 f = nouveau_local_fence(fence, chan->drm);
411 if (f) 440 if (f) {
412 prev = f->channel; 441 rcu_read_lock();
442 prev = rcu_dereference(f->channel);
443 if (prev && (prev == chan || fctx->sync(f, prev, chan) == 0))
444 must_wait = false;
445 rcu_read_unlock();
446 }
413 447
414 if (!prev || (prev != chan && (ret = fctx->sync(f, prev, chan)))) 448 if (must_wait)
415 ret = fence_wait(fence, intr); 449 ret = fence_wait(fence, intr);
416
417 if (ret)
418 break;
419 } 450 }
420 451
421 return ret; 452 return ret;
@@ -463,7 +494,7 @@ static const char *nouveau_fence_get_timeline_name(struct fence *f)
463 struct nouveau_fence *fence = from_fence(f); 494 struct nouveau_fence *fence = from_fence(f);
464 struct nouveau_fence_chan *fctx = nouveau_fctx(fence); 495 struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
465 496
466 return fence->channel ? fctx->name : "dead channel"; 497 return !fctx->dead ? fctx->name : "dead channel";
467} 498}
468 499
469/* 500/*
@@ -476,9 +507,16 @@ static bool nouveau_fence_is_signaled(struct fence *f)
476{ 507{
477 struct nouveau_fence *fence = from_fence(f); 508 struct nouveau_fence *fence = from_fence(f);
478 struct nouveau_fence_chan *fctx = nouveau_fctx(fence); 509 struct nouveau_fence_chan *fctx = nouveau_fctx(fence);
479 struct nouveau_channel *chan = fence->channel; 510 struct nouveau_channel *chan;
511 bool ret = false;
512
513 rcu_read_lock();
514 chan = rcu_dereference(fence->channel);
515 if (chan)
516 ret = (int)(fctx->read(chan) - fence->base.seqno) >= 0;
517 rcu_read_unlock();
480 518
481 return (int)(fctx->read(chan) - fence->base.seqno) >= 0; 519 return ret;
482} 520}
483 521
484static bool nouveau_fence_no_signaling(struct fence *f) 522static bool nouveau_fence_no_signaling(struct fence *f)
diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
index 943b0b17b1fc..96e461c6f68f 100644
--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
@@ -14,7 +14,7 @@ struct nouveau_fence {
14 14
15 bool sysmem; 15 bool sysmem;
16 16
17 struct nouveau_channel *channel; 17 struct nouveau_channel __rcu *channel;
18 unsigned long timeout; 18 unsigned long timeout;
19}; 19};
20 20
@@ -47,7 +47,7 @@ struct nouveau_fence_chan {
47 char name[32]; 47 char name[32];
48 48
49 struct nvif_notify notify; 49 struct nvif_notify notify;
50 int notify_ref; 50 int notify_ref, dead;
51}; 51};
52 52
53struct nouveau_fence_priv { 53struct nouveau_fence_priv {
diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c
index ae873d1a8d46..eb8b36714fa1 100644
--- a/drivers/gpu/drm/nouveau/nv50_display.c
+++ b/drivers/gpu/drm/nouveau/nv50_display.c
@@ -791,6 +791,22 @@ nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
791} 791}
792 792
793static int 793static int
794nv50_crtc_set_raster_vblank_dmi(struct nouveau_crtc *nv_crtc, u32 usec)
795{
796 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
797 u32 *push;
798
799 push = evo_wait(mast, 8);
800 if (!push)
801 return -ENOMEM;
802
803 evo_mthd(push, 0x0828 + (nv_crtc->index * 0x400), 1);
804 evo_data(push, usec);
805 evo_kick(push, mast);
806 return 0;
807}
808
809static int
794nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update) 810nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
795{ 811{
796 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); 812 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
@@ -1104,14 +1120,14 @@ nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
1104 evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2); 1120 evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2);
1105 evo_data(push, 0x00800000 | mode->clock); 1121 evo_data(push, 0x00800000 | mode->clock);
1106 evo_data(push, (ilace == 2) ? 2 : 0); 1122 evo_data(push, (ilace == 2) ? 2 : 0);
1107 evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 8); 1123 evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6);
1108 evo_data(push, 0x00000000); 1124 evo_data(push, 0x00000000);
1109 evo_data(push, (vactive << 16) | hactive); 1125 evo_data(push, (vactive << 16) | hactive);
1110 evo_data(push, ( vsynce << 16) | hsynce); 1126 evo_data(push, ( vsynce << 16) | hsynce);
1111 evo_data(push, (vblanke << 16) | hblanke); 1127 evo_data(push, (vblanke << 16) | hblanke);
1112 evo_data(push, (vblanks << 16) | hblanks); 1128 evo_data(push, (vblanks << 16) | hblanks);
1113 evo_data(push, (vblan2e << 16) | vblan2s); 1129 evo_data(push, (vblan2e << 16) | vblan2s);
1114 evo_data(push, vblankus); 1130 evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1);
1115 evo_data(push, 0x00000000); 1131 evo_data(push, 0x00000000);
1116 evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2); 1132 evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2);
1117 evo_data(push, 0x00000311); 1133 evo_data(push, 0x00000311);
@@ -1141,6 +1157,11 @@ nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
1141 nv_connector = nouveau_crtc_connector_get(nv_crtc); 1157 nv_connector = nouveau_crtc_connector_get(nv_crtc);
1142 nv50_crtc_set_dither(nv_crtc, false); 1158 nv50_crtc_set_dither(nv_crtc, false);
1143 nv50_crtc_set_scale(nv_crtc, false); 1159 nv50_crtc_set_scale(nv_crtc, false);
1160
1161 /* G94 only accepts this after setting scale */
1162 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA)
1163 nv50_crtc_set_raster_vblank_dmi(nv_crtc, vblankus);
1164
1144 nv50_crtc_set_color_vibrance(nv_crtc, false); 1165 nv50_crtc_set_color_vibrance(nv_crtc, false);
1145 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false); 1166 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
1146 return 0; 1167 return 0;
diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c
index 15da7ef344a4..ec1593a6a561 100644
--- a/drivers/gpu/drm/radeon/atom.c
+++ b/drivers/gpu/drm/radeon/atom.c
@@ -1217,7 +1217,7 @@ free:
1217 return ret; 1217 return ret;
1218} 1218}
1219 1219
1220int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params) 1220int atom_execute_table_scratch_unlocked(struct atom_context *ctx, int index, uint32_t * params)
1221{ 1221{
1222 int r; 1222 int r;
1223 1223
@@ -1238,6 +1238,15 @@ int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params)
1238 return r; 1238 return r;
1239} 1239}
1240 1240
1241int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params)
1242{
1243 int r;
1244 mutex_lock(&ctx->scratch_mutex);
1245 r = atom_execute_table_scratch_unlocked(ctx, index, params);
1246 mutex_unlock(&ctx->scratch_mutex);
1247 return r;
1248}
1249
1241static int atom_iio_len[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 }; 1250static int atom_iio_len[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 };
1242 1251
1243static void atom_index_iio(struct atom_context *ctx, int base) 1252static void atom_index_iio(struct atom_context *ctx, int base)
diff --git a/drivers/gpu/drm/radeon/atom.h b/drivers/gpu/drm/radeon/atom.h
index feba6b8d36b3..6d014ddb6b78 100644
--- a/drivers/gpu/drm/radeon/atom.h
+++ b/drivers/gpu/drm/radeon/atom.h
@@ -125,6 +125,7 @@ struct card_info {
125struct atom_context { 125struct atom_context {
126 struct card_info *card; 126 struct card_info *card;
127 struct mutex mutex; 127 struct mutex mutex;
128 struct mutex scratch_mutex;
128 void *bios; 129 void *bios;
129 uint32_t cmd_table, data_table; 130 uint32_t cmd_table, data_table;
130 uint16_t *iio; 131 uint16_t *iio;
@@ -145,6 +146,7 @@ extern int atom_debug;
145 146
146struct atom_context *atom_parse(struct card_info *, void *); 147struct atom_context *atom_parse(struct card_info *, void *);
147int atom_execute_table(struct atom_context *, int, uint32_t *); 148int atom_execute_table(struct atom_context *, int, uint32_t *);
149int atom_execute_table_scratch_unlocked(struct atom_context *, int, uint32_t *);
148int atom_asic_init(struct atom_context *); 150int atom_asic_init(struct atom_context *);
149void atom_destroy(struct atom_context *); 151void atom_destroy(struct atom_context *);
150bool atom_parse_data_header(struct atom_context *ctx, int index, uint16_t *size, 152bool atom_parse_data_header(struct atom_context *ctx, int index, uint16_t *size,
diff --git a/drivers/gpu/drm/radeon/atombios_dp.c b/drivers/gpu/drm/radeon/atombios_dp.c
index 95d5d4ab3335..11ba9d21b89b 100644
--- a/drivers/gpu/drm/radeon/atombios_dp.c
+++ b/drivers/gpu/drm/radeon/atombios_dp.c
@@ -100,6 +100,7 @@ static int radeon_process_aux_ch(struct radeon_i2c_chan *chan,
100 memset(&args, 0, sizeof(args)); 100 memset(&args, 0, sizeof(args));
101 101
102 mutex_lock(&chan->mutex); 102 mutex_lock(&chan->mutex);
103 mutex_lock(&rdev->mode_info.atom_context->scratch_mutex);
103 104
104 base = (unsigned char *)(rdev->mode_info.atom_context->scratch + 1); 105 base = (unsigned char *)(rdev->mode_info.atom_context->scratch + 1);
105 106
@@ -113,7 +114,7 @@ static int radeon_process_aux_ch(struct radeon_i2c_chan *chan,
113 if (ASIC_IS_DCE4(rdev)) 114 if (ASIC_IS_DCE4(rdev))
114 args.v2.ucHPD_ID = chan->rec.hpd; 115 args.v2.ucHPD_ID = chan->rec.hpd;
115 116
116 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 117 atom_execute_table_scratch_unlocked(rdev->mode_info.atom_context, index, (uint32_t *)&args);
117 118
118 *ack = args.v1.ucReplyStatus; 119 *ack = args.v1.ucReplyStatus;
119 120
@@ -147,6 +148,7 @@ static int radeon_process_aux_ch(struct radeon_i2c_chan *chan,
147 148
148 r = recv_bytes; 149 r = recv_bytes;
149done: 150done:
151 mutex_unlock(&rdev->mode_info.atom_context->scratch_mutex);
150 mutex_unlock(&chan->mutex); 152 mutex_unlock(&chan->mutex);
151 153
152 return r; 154 return r;
diff --git a/drivers/gpu/drm/radeon/atombios_i2c.c b/drivers/gpu/drm/radeon/atombios_i2c.c
index 9c570fb15b8c..4157780585a0 100644
--- a/drivers/gpu/drm/radeon/atombios_i2c.c
+++ b/drivers/gpu/drm/radeon/atombios_i2c.c
@@ -48,6 +48,7 @@ static int radeon_process_i2c_ch(struct radeon_i2c_chan *chan,
48 memset(&args, 0, sizeof(args)); 48 memset(&args, 0, sizeof(args));
49 49
50 mutex_lock(&chan->mutex); 50 mutex_lock(&chan->mutex);
51 mutex_lock(&rdev->mode_info.atom_context->scratch_mutex);
51 52
52 base = (unsigned char *)rdev->mode_info.atom_context->scratch; 53 base = (unsigned char *)rdev->mode_info.atom_context->scratch;
53 54
@@ -82,7 +83,7 @@ static int radeon_process_i2c_ch(struct radeon_i2c_chan *chan,
82 args.ucSlaveAddr = slave_addr << 1; 83 args.ucSlaveAddr = slave_addr << 1;
83 args.ucLineNumber = chan->rec.i2c_id; 84 args.ucLineNumber = chan->rec.i2c_id;
84 85
85 atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); 86 atom_execute_table_scratch_unlocked(rdev->mode_info.atom_context, index, (uint32_t *)&args);
86 87
87 /* error */ 88 /* error */
88 if (args.ucStatus != HW_ASSISTED_I2C_STATUS_SUCCESS) { 89 if (args.ucStatus != HW_ASSISTED_I2C_STATUS_SUCCESS) {
@@ -95,6 +96,7 @@ static int radeon_process_i2c_ch(struct radeon_i2c_chan *chan,
95 radeon_atom_copy_swap(buf, base, num, false); 96 radeon_atom_copy_swap(buf, base, num, false);
96 97
97done: 98done:
99 mutex_unlock(&rdev->mode_info.atom_context->scratch_mutex);
98 mutex_unlock(&chan->mutex); 100 mutex_unlock(&chan->mutex);
99 101
100 return r; 102 return r;
diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c
index 377afa504d2b..89c01fa6dd8e 100644
--- a/drivers/gpu/drm/radeon/cik.c
+++ b/drivers/gpu/drm/radeon/cik.c
@@ -4313,8 +4313,8 @@ static int cik_cp_gfx_start(struct radeon_device *rdev)
4313 /* init the CE partitions. CE only used for gfx on CIK */ 4313 /* init the CE partitions. CE only used for gfx on CIK */
4314 radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2)); 4314 radeon_ring_write(ring, PACKET3(PACKET3_SET_BASE, 2));
4315 radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE)); 4315 radeon_ring_write(ring, PACKET3_BASE_INDEX(CE_PARTITION_BASE));
4316 radeon_ring_write(ring, 0xc000); 4316 radeon_ring_write(ring, 0x8000);
4317 radeon_ring_write(ring, 0xc000); 4317 radeon_ring_write(ring, 0x8000);
4318 4318
4319 /* setup clear context state */ 4319 /* setup clear context state */
4320 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0)); 4320 radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
@@ -9447,6 +9447,9 @@ void dce8_bandwidth_update(struct radeon_device *rdev)
9447 u32 num_heads = 0, lb_size; 9447 u32 num_heads = 0, lb_size;
9448 int i; 9448 int i;
9449 9449
9450 if (!rdev->mode_info.mode_config_initialized)
9451 return;
9452
9450 radeon_update_display_priority(rdev); 9453 radeon_update_display_priority(rdev);
9451 9454
9452 for (i = 0; i < rdev->num_crtc; i++) { 9455 for (i = 0; i < rdev->num_crtc; i++) {
diff --git a/drivers/gpu/drm/radeon/cik_sdma.c b/drivers/gpu/drm/radeon/cik_sdma.c
index 4e8432d07f15..d748963af08b 100644
--- a/drivers/gpu/drm/radeon/cik_sdma.c
+++ b/drivers/gpu/drm/radeon/cik_sdma.c
@@ -667,17 +667,20 @@ int cik_sdma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
667{ 667{
668 struct radeon_ib ib; 668 struct radeon_ib ib;
669 unsigned i; 669 unsigned i;
670 unsigned index;
670 int r; 671 int r;
671 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
672 u32 tmp = 0; 672 u32 tmp = 0;
673 u64 gpu_addr;
673 674
674 if (!ptr) { 675 if (ring->idx == R600_RING_TYPE_DMA_INDEX)
675 DRM_ERROR("invalid vram scratch pointer\n"); 676 index = R600_WB_DMA_RING_TEST_OFFSET;
676 return -EINVAL; 677 else
677 } 678 index = CAYMAN_WB_DMA1_RING_TEST_OFFSET;
679
680 gpu_addr = rdev->wb.gpu_addr + index;
678 681
679 tmp = 0xCAFEDEAD; 682 tmp = 0xCAFEDEAD;
680 writel(tmp, ptr); 683 rdev->wb.wb[index/4] = cpu_to_le32(tmp);
681 684
682 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256); 685 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
683 if (r) { 686 if (r) {
@@ -686,8 +689,8 @@ int cik_sdma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
686 } 689 }
687 690
688 ib.ptr[0] = SDMA_PACKET(SDMA_OPCODE_WRITE, SDMA_WRITE_SUB_OPCODE_LINEAR, 0); 691 ib.ptr[0] = SDMA_PACKET(SDMA_OPCODE_WRITE, SDMA_WRITE_SUB_OPCODE_LINEAR, 0);
689 ib.ptr[1] = rdev->vram_scratch.gpu_addr & 0xfffffffc; 692 ib.ptr[1] = lower_32_bits(gpu_addr);
690 ib.ptr[2] = upper_32_bits(rdev->vram_scratch.gpu_addr); 693 ib.ptr[2] = upper_32_bits(gpu_addr);
691 ib.ptr[3] = 1; 694 ib.ptr[3] = 1;
692 ib.ptr[4] = 0xDEADBEEF; 695 ib.ptr[4] = 0xDEADBEEF;
693 ib.length_dw = 5; 696 ib.length_dw = 5;
@@ -704,7 +707,7 @@ int cik_sdma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
704 return r; 707 return r;
705 } 708 }
706 for (i = 0; i < rdev->usec_timeout; i++) { 709 for (i = 0; i < rdev->usec_timeout; i++) {
707 tmp = readl(ptr); 710 tmp = le32_to_cpu(rdev->wb.wb[index/4]);
708 if (tmp == 0xDEADBEEF) 711 if (tmp == 0xDEADBEEF)
709 break; 712 break;
710 DRM_UDELAY(1); 713 DRM_UDELAY(1);
diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c
index f37d39d2bbbc..85995b4e3338 100644
--- a/drivers/gpu/drm/radeon/evergreen.c
+++ b/drivers/gpu/drm/radeon/evergreen.c
@@ -2345,6 +2345,9 @@ void evergreen_bandwidth_update(struct radeon_device *rdev)
2345 u32 num_heads = 0, lb_size; 2345 u32 num_heads = 0, lb_size;
2346 int i; 2346 int i;
2347 2347
2348 if (!rdev->mode_info.mode_config_initialized)
2349 return;
2350
2348 radeon_update_display_priority(rdev); 2351 radeon_update_display_priority(rdev);
2349 2352
2350 for (i = 0; i < rdev->num_crtc; i++) { 2353 for (i = 0; i < rdev->num_crtc; i++) {
@@ -2552,6 +2555,7 @@ void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *sav
2552 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1); 2555 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 1);
2553 tmp |= EVERGREEN_CRTC_BLANK_DATA_EN; 2556 tmp |= EVERGREEN_CRTC_BLANK_DATA_EN;
2554 WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp); 2557 WREG32(EVERGREEN_CRTC_BLANK_CONTROL + crtc_offsets[i], tmp);
2558 WREG32(EVERGREEN_CRTC_UPDATE_LOCK + crtc_offsets[i], 0);
2555 } 2559 }
2556 } else { 2560 } else {
2557 tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]); 2561 tmp = RREG32(EVERGREEN_CRTC_CONTROL + crtc_offsets[i]);
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index 10f8be0ee173..b53b31a7b76f 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -3207,6 +3207,9 @@ void r100_bandwidth_update(struct radeon_device *rdev)
3207 uint32_t pixel_bytes1 = 0; 3207 uint32_t pixel_bytes1 = 0;
3208 uint32_t pixel_bytes2 = 0; 3208 uint32_t pixel_bytes2 = 0;
3209 3209
3210 if (!rdev->mode_info.mode_config_initialized)
3211 return;
3212
3210 radeon_update_display_priority(rdev); 3213 radeon_update_display_priority(rdev);
3211 3214
3212 if (rdev->mode_info.crtcs[0]->base.enabled) { 3215 if (rdev->mode_info.crtcs[0]->base.enabled) {
diff --git a/drivers/gpu/drm/radeon/r600_dma.c b/drivers/gpu/drm/radeon/r600_dma.c
index aabc343b9a8f..cf0df45d455e 100644
--- a/drivers/gpu/drm/radeon/r600_dma.c
+++ b/drivers/gpu/drm/radeon/r600_dma.c
@@ -338,17 +338,17 @@ int r600_dma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
338{ 338{
339 struct radeon_ib ib; 339 struct radeon_ib ib;
340 unsigned i; 340 unsigned i;
341 unsigned index;
341 int r; 342 int r;
342 void __iomem *ptr = (void *)rdev->vram_scratch.ptr;
343 u32 tmp = 0; 343 u32 tmp = 0;
344 u64 gpu_addr;
344 345
345 if (!ptr) { 346 if (ring->idx == R600_RING_TYPE_DMA_INDEX)
346 DRM_ERROR("invalid vram scratch pointer\n"); 347 index = R600_WB_DMA_RING_TEST_OFFSET;
347 return -EINVAL; 348 else
348 } 349 index = CAYMAN_WB_DMA1_RING_TEST_OFFSET;
349 350
350 tmp = 0xCAFEDEAD; 351 gpu_addr = rdev->wb.gpu_addr + index;
351 writel(tmp, ptr);
352 352
353 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256); 353 r = radeon_ib_get(rdev, ring->idx, &ib, NULL, 256);
354 if (r) { 354 if (r) {
@@ -357,8 +357,8 @@ int r600_dma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
357 } 357 }
358 358
359 ib.ptr[0] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1); 359 ib.ptr[0] = DMA_PACKET(DMA_PACKET_WRITE, 0, 0, 1);
360 ib.ptr[1] = rdev->vram_scratch.gpu_addr & 0xfffffffc; 360 ib.ptr[1] = lower_32_bits(gpu_addr);
361 ib.ptr[2] = upper_32_bits(rdev->vram_scratch.gpu_addr) & 0xff; 361 ib.ptr[2] = upper_32_bits(gpu_addr) & 0xff;
362 ib.ptr[3] = 0xDEADBEEF; 362 ib.ptr[3] = 0xDEADBEEF;
363 ib.length_dw = 4; 363 ib.length_dw = 4;
364 364
@@ -374,7 +374,7 @@ int r600_dma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
374 return r; 374 return r;
375 } 375 }
376 for (i = 0; i < rdev->usec_timeout; i++) { 376 for (i = 0; i < rdev->usec_timeout; i++) {
377 tmp = readl(ptr); 377 tmp = le32_to_cpu(rdev->wb.wb[index/4]);
378 if (tmp == 0xDEADBEEF) 378 if (tmp == 0xDEADBEEF)
379 break; 379 break;
380 DRM_UDELAY(1); 380 DRM_UDELAY(1);
diff --git a/drivers/gpu/drm/radeon/r600_dpm.c b/drivers/gpu/drm/radeon/r600_dpm.c
index f6309bd23e01..b5c73df8e202 100644
--- a/drivers/gpu/drm/radeon/r600_dpm.c
+++ b/drivers/gpu/drm/radeon/r600_dpm.c
@@ -1256,7 +1256,7 @@ int r600_parse_extended_power_table(struct radeon_device *rdev)
1256 (mode_info->atom_context->bios + data_offset + 1256 (mode_info->atom_context->bios + data_offset +
1257 le16_to_cpu(ext_hdr->usPowerTuneTableOffset)); 1257 le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
1258 rdev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit = 1258 rdev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit =
1259 ppt->usMaximumPowerDeliveryLimit; 1259 le16_to_cpu(ppt->usMaximumPowerDeliveryLimit);
1260 pt = &ppt->power_tune_table; 1260 pt = &ppt->power_tune_table;
1261 } else { 1261 } else {
1262 ATOM_PPLIB_POWERTUNE_Table *ppt = (ATOM_PPLIB_POWERTUNE_Table *) 1262 ATOM_PPLIB_POWERTUNE_Table *ppt = (ATOM_PPLIB_POWERTUNE_Table *)
diff --git a/drivers/gpu/drm/radeon/radeon_connectors.c b/drivers/gpu/drm/radeon/radeon_connectors.c
index 300c4b3d4669..26baa9c05f6c 100644
--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -322,6 +322,12 @@ static void radeon_connector_get_edid(struct drm_connector *connector)
322 } 322 }
323 323
324 if (!radeon_connector->edid) { 324 if (!radeon_connector->edid) {
325 /* don't fetch the edid from the vbios if ddc fails and runpm is
326 * enabled so we report disconnected.
327 */
328 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
329 return;
330
325 if (rdev->is_atom_bios) { 331 if (rdev->is_atom_bios) {
326 /* some laptops provide a hardcoded edid in rom for LCDs */ 332 /* some laptops provide a hardcoded edid in rom for LCDs */
327 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) || 333 if (((connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ||
@@ -826,6 +832,8 @@ static int radeon_lvds_mode_valid(struct drm_connector *connector,
826static enum drm_connector_status 832static enum drm_connector_status
827radeon_lvds_detect(struct drm_connector *connector, bool force) 833radeon_lvds_detect(struct drm_connector *connector, bool force)
828{ 834{
835 struct drm_device *dev = connector->dev;
836 struct radeon_device *rdev = dev->dev_private;
829 struct radeon_connector *radeon_connector = to_radeon_connector(connector); 837 struct radeon_connector *radeon_connector = to_radeon_connector(connector);
830 struct drm_encoder *encoder = radeon_best_single_encoder(connector); 838 struct drm_encoder *encoder = radeon_best_single_encoder(connector);
831 enum drm_connector_status ret = connector_status_disconnected; 839 enum drm_connector_status ret = connector_status_disconnected;
@@ -842,7 +850,11 @@ radeon_lvds_detect(struct drm_connector *connector, bool force)
842 /* check if panel is valid */ 850 /* check if panel is valid */
843 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240) 851 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
844 ret = connector_status_connected; 852 ret = connector_status_connected;
845 853 /* don't fetch the edid from the vbios if ddc fails and runpm is
854 * enabled so we report disconnected.
855 */
856 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
857 ret = connector_status_disconnected;
846 } 858 }
847 859
848 /* check for edid as well */ 860 /* check for edid as well */
@@ -1589,6 +1601,11 @@ radeon_dp_detect(struct drm_connector *connector, bool force)
1589 /* check if panel is valid */ 1601 /* check if panel is valid */
1590 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240) 1602 if (native_mode->hdisplay >= 320 && native_mode->vdisplay >= 240)
1591 ret = connector_status_connected; 1603 ret = connector_status_connected;
1604 /* don't fetch the edid from the vbios if ddc fails and runpm is
1605 * enabled so we report disconnected.
1606 */
1607 if ((rdev->flags & RADEON_IS_PX) && (radeon_runtime_pm != 0))
1608 ret = connector_status_disconnected;
1592 } 1609 }
1593 /* eDP is always DP */ 1610 /* eDP is always DP */
1594 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT; 1611 radeon_dig_connector->dp_sink_type = CONNECTOR_OBJECT_ID_DISPLAYPORT;
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index a3e7aed7e680..6f377de099f9 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -251,22 +251,19 @@ static int radeon_cs_get_ring(struct radeon_cs_parser *p, u32 ring, s32 priority
251 251
252static int radeon_cs_sync_rings(struct radeon_cs_parser *p) 252static int radeon_cs_sync_rings(struct radeon_cs_parser *p)
253{ 253{
254 int i, r = 0; 254 struct radeon_cs_reloc *reloc;
255 int r;
255 256
256 for (i = 0; i < p->nrelocs; i++) { 257 list_for_each_entry(reloc, &p->validated, tv.head) {
257 struct reservation_object *resv; 258 struct reservation_object *resv;
258 259
259 if (!p->relocs[i].robj) 260 resv = reloc->robj->tbo.resv;
260 continue;
261
262 resv = p->relocs[i].robj->tbo.resv;
263 r = radeon_semaphore_sync_resv(p->rdev, p->ib.semaphore, resv, 261 r = radeon_semaphore_sync_resv(p->rdev, p->ib.semaphore, resv,
264 p->relocs[i].tv.shared); 262 reloc->tv.shared);
265
266 if (r) 263 if (r)
267 break; 264 return r;
268 } 265 }
269 return r; 266 return 0;
270} 267}
271 268
272/* XXX: note that this is called from the legacy UMS CS ioctl as well */ 269/* XXX: note that this is called from the legacy UMS CS ioctl as well */
diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
index ea2676954dde..995a8b1770dd 100644
--- a/drivers/gpu/drm/radeon/radeon_device.c
+++ b/drivers/gpu/drm/radeon/radeon_device.c
@@ -952,6 +952,7 @@ int radeon_atombios_init(struct radeon_device *rdev)
952 } 952 }
953 953
954 mutex_init(&rdev->mode_info.atom_context->mutex); 954 mutex_init(&rdev->mode_info.atom_context->mutex);
955 mutex_init(&rdev->mode_info.atom_context->scratch_mutex);
955 radeon_atom_initialize_bios_scratch_regs(rdev->ddev); 956 radeon_atom_initialize_bios_scratch_regs(rdev->ddev);
956 atom_allocate_fb_scratch(rdev->mode_info.atom_context); 957 atom_allocate_fb_scratch(rdev->mode_info.atom_context);
957 return 0; 958 return 0;
diff --git a/drivers/gpu/drm/radeon/radeon_encoders.c b/drivers/gpu/drm/radeon/radeon_encoders.c
index 9a19e52cc655..6b670b0bc47b 100644
--- a/drivers/gpu/drm/radeon/radeon_encoders.c
+++ b/drivers/gpu/drm/radeon/radeon_encoders.c
@@ -179,6 +179,9 @@ static void radeon_encoder_add_backlight(struct radeon_encoder *radeon_encoder,
179 (rdev->pdev->subsystem_vendor == 0x1734) && 179 (rdev->pdev->subsystem_vendor == 0x1734) &&
180 (rdev->pdev->subsystem_device == 0x1107)) 180 (rdev->pdev->subsystem_device == 0x1107))
181 use_bl = false; 181 use_bl = false;
182 /* disable native backlight control on older asics */
183 else if (rdev->family < CHIP_R600)
184 use_bl = false;
182 else 185 else
183 use_bl = true; 186 use_bl = true;
184 } 187 }
diff --git a/drivers/gpu/drm/radeon/radeon_irq_kms.c b/drivers/gpu/drm/radeon/radeon_irq_kms.c
index 7784911d78ef..00fc59762e0d 100644
--- a/drivers/gpu/drm/radeon/radeon_irq_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_irq_kms.c
@@ -185,6 +185,16 @@ static bool radeon_msi_ok(struct radeon_device *rdev)
185 if (rdev->flags & RADEON_IS_AGP) 185 if (rdev->flags & RADEON_IS_AGP)
186 return false; 186 return false;
187 187
188 /*
189 * Older chips have a HW limitation, they can only generate 40 bits
190 * of address for "64-bit" MSIs which breaks on some platforms, notably
191 * IBM POWER servers, so we limit them
192 */
193 if (rdev->family < CHIP_BONAIRE) {
194 dev_info(rdev->dev, "radeon: MSI limited to 32-bit\n");
195 rdev->pdev->no_64bit_msi = 1;
196 }
197
188 /* force MSI on */ 198 /* force MSI on */
189 if (radeon_msi == 1) 199 if (radeon_msi == 1)
190 return true; 200 return true;
diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c
index 8309b11e674d..03586763ee86 100644
--- a/drivers/gpu/drm/radeon/radeon_kms.c
+++ b/drivers/gpu/drm/radeon/radeon_kms.c
@@ -795,6 +795,8 @@ int radeon_get_vblank_timestamp_kms(struct drm_device *dev, int crtc,
795 795
796 /* Get associated drm_crtc: */ 796 /* Get associated drm_crtc: */
797 drmcrtc = &rdev->mode_info.crtcs[crtc]->base; 797 drmcrtc = &rdev->mode_info.crtcs[crtc]->base;
798 if (!drmcrtc)
799 return -EINVAL;
798 800
799 /* Helper routine in DRM core does all the work: */ 801 /* Helper routine in DRM core does all the work: */
800 return drm_calc_vbltimestamp_from_scanoutpos(dev, crtc, max_error, 802 return drm_calc_vbltimestamp_from_scanoutpos(dev, crtc, max_error,
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index 99a960a4f302..4c0d786d5c7a 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -213,6 +213,13 @@ int radeon_bo_create(struct radeon_device *rdev,
213 if (!(rdev->flags & RADEON_IS_PCIE)) 213 if (!(rdev->flags & RADEON_IS_PCIE))
214 bo->flags &= ~(RADEON_GEM_GTT_WC | RADEON_GEM_GTT_UC); 214 bo->flags &= ~(RADEON_GEM_GTT_WC | RADEON_GEM_GTT_UC);
215 215
216#ifdef CONFIG_X86_32
217 /* XXX: Write-combined CPU mappings of GTT seem broken on 32-bit
218 * See https://bugs.freedesktop.org/show_bug.cgi?id=84627
219 */
220 bo->flags &= ~RADEON_GEM_GTT_WC;
221#endif
222
216 radeon_ttm_placement_from_domain(bo, domain); 223 radeon_ttm_placement_from_domain(bo, domain);
217 /* Kernel allocation are uninterruptible */ 224 /* Kernel allocation are uninterruptible */
218 down_read(&rdev->pm.mclk_lock); 225 down_read(&rdev->pm.mclk_lock);
diff --git a/drivers/gpu/drm/radeon/rs600.c b/drivers/gpu/drm/radeon/rs600.c
index 5f6db4629aaa..9acb1c3c005b 100644
--- a/drivers/gpu/drm/radeon/rs600.c
+++ b/drivers/gpu/drm/radeon/rs600.c
@@ -879,6 +879,9 @@ void rs600_bandwidth_update(struct radeon_device *rdev)
879 u32 d1mode_priority_a_cnt, d2mode_priority_a_cnt; 879 u32 d1mode_priority_a_cnt, d2mode_priority_a_cnt;
880 /* FIXME: implement full support */ 880 /* FIXME: implement full support */
881 881
882 if (!rdev->mode_info.mode_config_initialized)
883 return;
884
882 radeon_update_display_priority(rdev); 885 radeon_update_display_priority(rdev);
883 886
884 if (rdev->mode_info.crtcs[0]->base.enabled) 887 if (rdev->mode_info.crtcs[0]->base.enabled)
diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
index 3462b64369bf..0a2d36e81108 100644
--- a/drivers/gpu/drm/radeon/rs690.c
+++ b/drivers/gpu/drm/radeon/rs690.c
@@ -579,6 +579,9 @@ void rs690_bandwidth_update(struct radeon_device *rdev)
579 u32 d1mode_priority_a_cnt, d1mode_priority_b_cnt; 579 u32 d1mode_priority_a_cnt, d1mode_priority_b_cnt;
580 u32 d2mode_priority_a_cnt, d2mode_priority_b_cnt; 580 u32 d2mode_priority_a_cnt, d2mode_priority_b_cnt;
581 581
582 if (!rdev->mode_info.mode_config_initialized)
583 return;
584
582 radeon_update_display_priority(rdev); 585 radeon_update_display_priority(rdev);
583 586
584 if (rdev->mode_info.crtcs[0]->base.enabled) 587 if (rdev->mode_info.crtcs[0]->base.enabled)
diff --git a/drivers/gpu/drm/radeon/rv515.c b/drivers/gpu/drm/radeon/rv515.c
index 8a477bf1fdb3..c55d653aaf5f 100644
--- a/drivers/gpu/drm/radeon/rv515.c
+++ b/drivers/gpu/drm/radeon/rv515.c
@@ -1277,6 +1277,9 @@ void rv515_bandwidth_update(struct radeon_device *rdev)
1277 struct drm_display_mode *mode0 = NULL; 1277 struct drm_display_mode *mode0 = NULL;
1278 struct drm_display_mode *mode1 = NULL; 1278 struct drm_display_mode *mode1 = NULL;
1279 1279
1280 if (!rdev->mode_info.mode_config_initialized)
1281 return;
1282
1280 radeon_update_display_priority(rdev); 1283 radeon_update_display_priority(rdev);
1281 1284
1282 if (rdev->mode_info.crtcs[0]->base.enabled) 1285 if (rdev->mode_info.crtcs[0]->base.enabled)
diff --git a/drivers/gpu/drm/radeon/si.c b/drivers/gpu/drm/radeon/si.c
index eeea5b6a1775..7d5083dc4acb 100644
--- a/drivers/gpu/drm/radeon/si.c
+++ b/drivers/gpu/drm/radeon/si.c
@@ -2384,6 +2384,9 @@ void dce6_bandwidth_update(struct radeon_device *rdev)
2384 u32 num_heads = 0, lb_size; 2384 u32 num_heads = 0, lb_size;
2385 int i; 2385 int i;
2386 2386
2387 if (!rdev->mode_info.mode_config_initialized)
2388 return;
2389
2387 radeon_update_display_priority(rdev); 2390 radeon_update_display_priority(rdev);
2388 2391
2389 for (i = 0; i < rdev->num_crtc; i++) { 2392 for (i = 0; i < rdev->num_crtc; i++) {
diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
index 6553fd238685..054a79f143ae 100644
--- a/drivers/gpu/drm/tegra/dc.c
+++ b/drivers/gpu/drm/tegra/dc.c
@@ -736,7 +736,6 @@ static const struct drm_crtc_funcs tegra_crtc_funcs = {
736 736
737static void tegra_crtc_disable(struct drm_crtc *crtc) 737static void tegra_crtc_disable(struct drm_crtc *crtc)
738{ 738{
739 struct tegra_dc *dc = to_tegra_dc(crtc);
740 struct drm_device *drm = crtc->dev; 739 struct drm_device *drm = crtc->dev;
741 struct drm_plane *plane; 740 struct drm_plane *plane;
742 741
@@ -752,7 +751,7 @@ static void tegra_crtc_disable(struct drm_crtc *crtc)
752 } 751 }
753 } 752 }
754 753
755 drm_vblank_off(drm, dc->pipe); 754 drm_crtc_vblank_off(crtc);
756} 755}
757 756
758static bool tegra_crtc_mode_fixup(struct drm_crtc *crtc, 757static bool tegra_crtc_mode_fixup(struct drm_crtc *crtc,
@@ -841,8 +840,6 @@ static int tegra_crtc_mode_set(struct drm_crtc *crtc,
841 u32 value; 840 u32 value;
842 int err; 841 int err;
843 842
844 drm_vblank_pre_modeset(crtc->dev, dc->pipe);
845
846 err = tegra_crtc_setup_clk(crtc, mode); 843 err = tegra_crtc_setup_clk(crtc, mode);
847 if (err) { 844 if (err) {
848 dev_err(dc->dev, "failed to setup clock for CRTC: %d\n", err); 845 dev_err(dc->dev, "failed to setup clock for CRTC: %d\n", err);
@@ -896,6 +893,8 @@ static void tegra_crtc_prepare(struct drm_crtc *crtc)
896 unsigned int syncpt; 893 unsigned int syncpt;
897 unsigned long value; 894 unsigned long value;
898 895
896 drm_crtc_vblank_off(crtc);
897
899 /* hardware initialization */ 898 /* hardware initialization */
900 reset_control_deassert(dc->rst); 899 reset_control_deassert(dc->rst);
901 usleep_range(10000, 20000); 900 usleep_range(10000, 20000);
@@ -943,7 +942,7 @@ static void tegra_crtc_commit(struct drm_crtc *crtc)
943 value = GENERAL_ACT_REQ | WIN_A_ACT_REQ; 942 value = GENERAL_ACT_REQ | WIN_A_ACT_REQ;
944 tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL); 943 tegra_dc_writel(dc, value, DC_CMD_STATE_CONTROL);
945 944
946 drm_vblank_post_modeset(crtc->dev, dc->pipe); 945 drm_crtc_vblank_on(crtc);
947} 946}
948 947
949static void tegra_crtc_load_lut(struct drm_crtc *crtc) 948static void tegra_crtc_load_lut(struct drm_crtc *crtc)
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 73bd9e2e42bc..3402033fa52a 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1659,6 +1659,7 @@ void hid_disconnect(struct hid_device *hdev)
1659 hdev->hiddev_disconnect(hdev); 1659 hdev->hiddev_disconnect(hdev);
1660 if (hdev->claimed & HID_CLAIMED_HIDRAW) 1660 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1661 hidraw_disconnect(hdev); 1661 hidraw_disconnect(hdev);
1662 hdev->claimed = 0;
1662} 1663}
1663EXPORT_SYMBOL_GPL(hid_disconnect); 1664EXPORT_SYMBOL_GPL(hid_disconnect);
1664 1665
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index e23ab8b30626..7c863738e419 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -299,6 +299,7 @@
299#define USB_VENDOR_ID_ELAN 0x04f3 299#define USB_VENDOR_ID_ELAN 0x04f3
300#define USB_DEVICE_ID_ELAN_TOUCHSCREEN 0x0089 300#define USB_DEVICE_ID_ELAN_TOUCHSCREEN 0x0089
301#define USB_DEVICE_ID_ELAN_TOUCHSCREEN_009B 0x009b 301#define USB_DEVICE_ID_ELAN_TOUCHSCREEN_009B 0x009b
302#define USB_DEVICE_ID_ELAN_TOUCHSCREEN_0103 0x0103
302#define USB_DEVICE_ID_ELAN_TOUCHSCREEN_016F 0x016f 303#define USB_DEVICE_ID_ELAN_TOUCHSCREEN_016F 0x016f
303 304
304#define USB_VENDOR_ID_ELECOM 0x056e 305#define USB_VENDOR_ID_ELECOM 0x056e
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index e6d8e18dae97..6a58b6c723aa 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -641,9 +641,6 @@ static int sensor_hub_probe(struct hid_device *hdev,
641 goto err_stop_hw; 641 goto err_stop_hw;
642 } 642 }
643 sd->hid_sensor_hub_client_devs[ 643 sd->hid_sensor_hub_client_devs[
644 sd->hid_sensor_client_cnt].id =
645 PLATFORM_DEVID_AUTO;
646 sd->hid_sensor_hub_client_devs[
647 sd->hid_sensor_client_cnt].name = name; 644 sd->hid_sensor_client_cnt].name = name;
648 sd->hid_sensor_hub_client_devs[ 645 sd->hid_sensor_hub_client_devs[
649 sd->hid_sensor_client_cnt].platform_data = 646 sd->hid_sensor_client_cnt].platform_data =
@@ -659,8 +656,9 @@ static int sensor_hub_probe(struct hid_device *hdev,
659 if (last_hsdev) 656 if (last_hsdev)
660 last_hsdev->end_collection_index = i; 657 last_hsdev->end_collection_index = i;
661 658
662 ret = mfd_add_devices(&hdev->dev, 0, sd->hid_sensor_hub_client_devs, 659 ret = mfd_add_hotplug_devices(&hdev->dev,
663 sd->hid_sensor_client_cnt, NULL, 0, NULL); 660 sd->hid_sensor_hub_client_devs,
661 sd->hid_sensor_client_cnt);
664 if (ret < 0) 662 if (ret < 0)
665 goto err_stop_hw; 663 goto err_stop_hw;
666 664
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 5014bb567b29..552671ee7c5d 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -72,6 +72,7 @@ static const struct hid_blacklist {
72 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET }, 72 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET },
73 { USB_VENDOR_ID_ELAN, USB_DEVICE_ID_ELAN_TOUCHSCREEN, HID_QUIRK_ALWAYS_POLL }, 73 { USB_VENDOR_ID_ELAN, USB_DEVICE_ID_ELAN_TOUCHSCREEN, HID_QUIRK_ALWAYS_POLL },
74 { USB_VENDOR_ID_ELAN, USB_DEVICE_ID_ELAN_TOUCHSCREEN_009B, HID_QUIRK_ALWAYS_POLL }, 74 { USB_VENDOR_ID_ELAN, USB_DEVICE_ID_ELAN_TOUCHSCREEN_009B, HID_QUIRK_ALWAYS_POLL },
75 { USB_VENDOR_ID_ELAN, USB_DEVICE_ID_ELAN_TOUCHSCREEN_0103, HID_QUIRK_ALWAYS_POLL },
75 { USB_VENDOR_ID_ELAN, USB_DEVICE_ID_ELAN_TOUCHSCREEN_016F, HID_QUIRK_ALWAYS_POLL }, 76 { USB_VENDOR_ID_ELAN, USB_DEVICE_ID_ELAN_TOUCHSCREEN_016F, HID_QUIRK_ALWAYS_POLL },
76 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, 77 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET },
77 { USB_VENDOR_ID_FORMOSA, USB_DEVICE_ID_FORMOSA_IR_RECEIVER, HID_QUIRK_NO_INIT_REPORTS }, 78 { USB_VENDOR_ID_FORMOSA, USB_DEVICE_ID_FORMOSA_IR_RECEIVER, HID_QUIRK_NO_INIT_REPORTS },
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 5286d7ce1f9e..6529c09c46f0 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1028,11 +1028,11 @@ config SENSORS_LM93
1028 will be called lm93. 1028 will be called lm93.
1029 1029
1030config SENSORS_LM95234 1030config SENSORS_LM95234
1031 tristate "National Semiconductor LM95234" 1031 tristate "National Semiconductor LM95234 and compatibles"
1032 depends on I2C 1032 depends on I2C
1033 help 1033 help
1034 If you say yes here you get support for the LM95234 temperature 1034 If you say yes here you get support for the LM95233 and LM95234
1035 sensor. 1035 temperature sensor chips.
1036 1036
1037 This driver can also be built as a module. If so, the module 1037 This driver can also be built as a module. If so, the module
1038 will be called lm95234. 1038 will be called lm95234.
@@ -1048,10 +1048,11 @@ config SENSORS_LM95241
1048 will be called lm95241. 1048 will be called lm95241.
1049 1049
1050config SENSORS_LM95245 1050config SENSORS_LM95245
1051 tristate "National Semiconductor LM95245 sensor chip" 1051 tristate "National Semiconductor LM95245 and compatibles"
1052 depends on I2C 1052 depends on I2C
1053 help 1053 help
1054 If you say yes here you get support for LM95245 sensor chip. 1054 If you say yes here you get support for LM95235 and LM95245
1055 temperature sensor chips.
1055 1056
1056 This driver can also be built as a module. If so, the module 1057 This driver can also be built as a module. If so, the module
1057 will be called lm95245. 1058 will be called lm95245.
@@ -1117,12 +1118,23 @@ config SENSORS_NCT6775
1117 help 1118 help
1118 If you say yes here you get support for the hardware monitoring 1119 If you say yes here you get support for the hardware monitoring
1119 functionality of the Nuvoton NCT6106D, NCT6775F, NCT6776F, NCT6779D, 1120 functionality of the Nuvoton NCT6106D, NCT6775F, NCT6776F, NCT6779D,
1120 NCT6791D and compatible Super-I/O chips. This driver replaces the 1121 NCT6791D, NCT6792D and compatible Super-I/O chips. This driver
1121 w83627ehf driver for NCT6775F and NCT6776F. 1122 replaces the w83627ehf driver for NCT6775F and NCT6776F.
1122 1123
1123 This driver can also be built as a module. If so, the module 1124 This driver can also be built as a module. If so, the module
1124 will be called nct6775. 1125 will be called nct6775.
1125 1126
1127config SENSORS_NCT7802
1128 tristate "Nuvoton NCT7802Y"
1129 depends on I2C
1130 select REGMAP_I2C
1131 help
1132 If you say yes here you get support for the Nuvoton NCT7802Y
1133 hardware monitoring chip.
1134
1135 This driver can also be built as a module. If so, the module
1136 will be called nct7802.
1137
1126config SENSORS_PCF8591 1138config SENSORS_PCF8591
1127 tristate "Philips PCF8591 ADC/DAC" 1139 tristate "Philips PCF8591 ADC/DAC"
1128 depends on I2C 1140 depends on I2C
@@ -1454,7 +1466,7 @@ config SENSORS_TMP401
1454 depends on I2C 1466 depends on I2C
1455 help 1467 help
1456 If you say yes here you get support for Texas Instruments TMP401, 1468 If you say yes here you get support for Texas Instruments TMP401,
1457 TMP411, TMP431, and TMP432 temperature sensor chips. 1469 TMP411, TMP431, TMP432 and TMP435 temperature sensor chips.
1458 1470
1459 This driver can also be built as a module. If so, the module 1471 This driver can also be built as a module. If so, the module
1460 will be called tmp401. 1472 will be called tmp401.
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index c90a7611efaa..67280643bcf0 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -118,6 +118,7 @@ obj-$(CONFIG_SENSORS_MCP3021) += mcp3021.o
118obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o 118obj-$(CONFIG_SENSORS_MENF21BMC_HWMON) += menf21bmc_hwmon.o
119obj-$(CONFIG_SENSORS_NCT6683) += nct6683.o 119obj-$(CONFIG_SENSORS_NCT6683) += nct6683.o
120obj-$(CONFIG_SENSORS_NCT6775) += nct6775.o 120obj-$(CONFIG_SENSORS_NCT6775) += nct6775.o
121obj-$(CONFIG_SENSORS_NCT7802) += nct7802.o
121obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o 122obj-$(CONFIG_SENSORS_NTC_THERMISTOR) += ntc_thermistor.o
122obj-$(CONFIG_SENSORS_PC87360) += pc87360.o 123obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
123obj-$(CONFIG_SENSORS_PC87427) += pc87427.o 124obj-$(CONFIG_SENSORS_PC87427) += pc87427.o
diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index fcdbde4ec692..3057dfc7e3bc 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -234,7 +234,7 @@ static const struct pci_device_id fam15h_power_id_table[] = {
234 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) }, 234 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) },
235 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F4) }, 235 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F4) },
236 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F4) }, 236 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_NB_F4) },
237 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) }, 237 { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F4) },
238 {} 238 {}
239}; 239};
240MODULE_DEVICE_TABLE(pci, fam15h_power_id_table); 240MODULE_DEVICE_TABLE(pci, fam15h_power_id_table);
diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c
index 6aac695b1688..9b55e673b67c 100644
--- a/drivers/hwmon/g762.c
+++ b/drivers/hwmon/g762.c
@@ -1084,10 +1084,8 @@ static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id)
1084 if (ret) 1084 if (ret)
1085 goto clock_dis; 1085 goto clock_dis;
1086 1086
1087 data->hwmon_dev = devm_hwmon_device_register_with_groups(dev, 1087 data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name,
1088 client->name, 1088 data, g762_groups);
1089 data,
1090 g762_groups);
1091 if (IS_ERR(data->hwmon_dev)) { 1089 if (IS_ERR(data->hwmon_dev)) {
1092 ret = PTR_ERR(data->hwmon_dev); 1090 ret = PTR_ERR(data->hwmon_dev);
1093 goto clock_dis; 1091 goto clock_dis;
diff --git a/drivers/hwmon/gpio-fan.c b/drivers/hwmon/gpio-fan.c
index 4efa1734bdad..36abf814b8c7 100644
--- a/drivers/hwmon/gpio-fan.c
+++ b/drivers/hwmon/gpio-fan.c
@@ -79,7 +79,7 @@ static ssize_t show_fan_alarm(struct device *dev,
79{ 79{
80 struct gpio_fan_data *fan_data = dev_get_drvdata(dev); 80 struct gpio_fan_data *fan_data = dev_get_drvdata(dev);
81 struct gpio_fan_alarm *alarm = fan_data->alarm; 81 struct gpio_fan_alarm *alarm = fan_data->alarm;
82 int value = gpio_get_value(alarm->gpio); 82 int value = gpio_get_value_cansleep(alarm->gpio);
83 83
84 if (alarm->active_low) 84 if (alarm->active_low)
85 value = !value; 85 value = !value;
@@ -131,7 +131,7 @@ static void __set_fan_ctrl(struct gpio_fan_data *fan_data, int ctrl_val)
131 int i; 131 int i;
132 132
133 for (i = 0; i < fan_data->num_ctrl; i++) 133 for (i = 0; i < fan_data->num_ctrl; i++)
134 gpio_set_value(fan_data->ctrl[i], (ctrl_val >> i) & 1); 134 gpio_set_value_cansleep(fan_data->ctrl[i], (ctrl_val >> i) & 1);
135} 135}
136 136
137static int __get_fan_ctrl(struct gpio_fan_data *fan_data) 137static int __get_fan_ctrl(struct gpio_fan_data *fan_data)
@@ -142,7 +142,7 @@ static int __get_fan_ctrl(struct gpio_fan_data *fan_data)
142 for (i = 0; i < fan_data->num_ctrl; i++) { 142 for (i = 0; i < fan_data->num_ctrl; i++) {
143 int value; 143 int value;
144 144
145 value = gpio_get_value(fan_data->ctrl[i]); 145 value = gpio_get_value_cansleep(fan_data->ctrl[i]);
146 ctrl_val |= (value << i); 146 ctrl_val |= (value << i);
147 } 147 }
148 return ctrl_val; 148 return ctrl_val;
@@ -369,7 +369,8 @@ static int fan_ctrl_init(struct gpio_fan_data *fan_data,
369 if (err) 369 if (err)
370 return err; 370 return err;
371 371
372 err = gpio_direction_output(ctrl[i], gpio_get_value(ctrl[i])); 372 err = gpio_direction_output(ctrl[i],
373 gpio_get_value_cansleep(ctrl[i]));
373 if (err) 374 if (err)
374 return err; 375 return err;
375 } 376 }
@@ -549,6 +550,14 @@ static int gpio_fan_probe(struct platform_device *pdev)
549 return 0; 550 return 0;
550} 551}
551 552
553static void gpio_fan_shutdown(struct platform_device *pdev)
554{
555 struct gpio_fan_data *fan_data = dev_get_drvdata(&pdev->dev);
556
557 if (fan_data->ctrl)
558 set_fan_speed(fan_data, 0);
559}
560
552#ifdef CONFIG_PM_SLEEP 561#ifdef CONFIG_PM_SLEEP
553static int gpio_fan_suspend(struct device *dev) 562static int gpio_fan_suspend(struct device *dev)
554{ 563{
@@ -580,6 +589,7 @@ static SIMPLE_DEV_PM_OPS(gpio_fan_pm, gpio_fan_suspend, gpio_fan_resume);
580 589
581static struct platform_driver gpio_fan_driver = { 590static struct platform_driver gpio_fan_driver = {
582 .probe = gpio_fan_probe, 591 .probe = gpio_fan_probe,
592 .shutdown = gpio_fan_shutdown,
583 .driver = { 593 .driver = {
584 .name = "gpio-fan", 594 .name = "gpio-fan",
585 .pm = GPIO_FAN_PM, 595 .pm = GPIO_FAN_PM,
diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
index d2bf2c97ae70..7c2c7be182f2 100644
--- a/drivers/hwmon/ibmpowernv.c
+++ b/drivers/hwmon/ibmpowernv.c
@@ -74,9 +74,6 @@ struct platform_data {
74 u32 sensors_count; /* Total count of sensors from each group */ 74 u32 sensors_count; /* Total count of sensors from each group */
75}; 75};
76 76
77/* Platform device representing all the ibmpowernv sensors */
78static struct platform_device *pdevice;
79
80static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr, 77static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr,
81 char *buf) 78 char *buf)
82{ 79{
@@ -99,7 +96,7 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *devattr,
99 return sprintf(buf, "%u\n", x); 96 return sprintf(buf, "%u\n", x);
100} 97}
101 98
102static int __init get_sensor_index_attr(const char *name, u32 *index, 99static int get_sensor_index_attr(const char *name, u32 *index,
103 char *attr) 100 char *attr)
104{ 101{
105 char *hash_pos = strchr(name, '#'); 102 char *hash_pos = strchr(name, '#');
@@ -136,7 +133,7 @@ static int __init get_sensor_index_attr(const char *name, u32 *index,
136 * which need to be mapped as fan2_input, temp1_max respectively before 133 * which need to be mapped as fan2_input, temp1_max respectively before
137 * populating them inside hwmon device class. 134 * populating them inside hwmon device class.
138 */ 135 */
139static int __init create_hwmon_attr_name(struct device *dev, enum sensors type, 136static int create_hwmon_attr_name(struct device *dev, enum sensors type,
140 const char *node_name, 137 const char *node_name,
141 char *hwmon_attr_name) 138 char *hwmon_attr_name)
142{ 139{
@@ -172,7 +169,7 @@ static int __init create_hwmon_attr_name(struct device *dev, enum sensors type,
172 return 0; 169 return 0;
173} 170}
174 171
175static int __init populate_attr_groups(struct platform_device *pdev) 172static int populate_attr_groups(struct platform_device *pdev)
176{ 173{
177 struct platform_data *pdata = platform_get_drvdata(pdev); 174 struct platform_data *pdata = platform_get_drvdata(pdev);
178 const struct attribute_group **pgroups = pdata->attr_groups; 175 const struct attribute_group **pgroups = pdata->attr_groups;
@@ -180,11 +177,6 @@ static int __init populate_attr_groups(struct platform_device *pdev)
180 enum sensors type; 177 enum sensors type;
181 178
182 opal = of_find_node_by_path("/ibm,opal/sensors"); 179 opal = of_find_node_by_path("/ibm,opal/sensors");
183 if (!opal) {
184 dev_err(&pdev->dev, "Opal node 'sensors' not found\n");
185 return -ENODEV;
186 }
187
188 for_each_child_of_node(opal, np) { 180 for_each_child_of_node(opal, np) {
189 if (np->name == NULL) 181 if (np->name == NULL)
190 continue; 182 continue;
@@ -221,7 +213,7 @@ static int __init populate_attr_groups(struct platform_device *pdev)
221 * to the name required by the higher 'hwmon' driver like fan1_input, temp1_max 213 * to the name required by the higher 'hwmon' driver like fan1_input, temp1_max
222 * etc.. 214 * etc..
223 */ 215 */
224static int __init create_device_attrs(struct platform_device *pdev) 216static int create_device_attrs(struct platform_device *pdev)
225{ 217{
226 struct platform_data *pdata = platform_get_drvdata(pdev); 218 struct platform_data *pdata = platform_get_drvdata(pdev);
227 const struct attribute_group **pgroups = pdata->attr_groups; 219 const struct attribute_group **pgroups = pdata->attr_groups;
@@ -280,7 +272,7 @@ exit_put_node:
280 return err; 272 return err;
281} 273}
282 274
283static int __init ibmpowernv_probe(struct platform_device *pdev) 275static int ibmpowernv_probe(struct platform_device *pdev)
284{ 276{
285 struct platform_data *pdata; 277 struct platform_data *pdata;
286 struct device *hwmon_dev; 278 struct device *hwmon_dev;
@@ -309,55 +301,25 @@ static int __init ibmpowernv_probe(struct platform_device *pdev)
309 return PTR_ERR_OR_ZERO(hwmon_dev); 301 return PTR_ERR_OR_ZERO(hwmon_dev);
310} 302}
311 303
312static struct platform_driver ibmpowernv_driver = { 304static const struct platform_device_id opal_sensor_driver_ids[] = {
313 .driver = { 305 {
314 .owner = THIS_MODULE, 306 .name = "opal-sensor",
315 .name = DRVNAME,
316 }, 307 },
308 { }
317}; 309};
310MODULE_DEVICE_TABLE(platform, opal_sensor_driver_ids);
318 311
319static int __init ibmpowernv_init(void) 312static struct platform_driver ibmpowernv_driver = {
320{ 313 .probe = ibmpowernv_probe,
321 int err; 314 .id_table = opal_sensor_driver_ids,
322 315 .driver = {
323 pdevice = platform_device_alloc(DRVNAME, 0); 316 .owner = THIS_MODULE,
324 if (!pdevice) { 317 .name = DRVNAME,
325 pr_err("Device allocation failed\n"); 318 },
326 err = -ENOMEM; 319};
327 goto exit;
328 }
329
330 err = platform_device_add(pdevice);
331 if (err) {
332 pr_err("Device addition failed (%d)\n", err);
333 goto exit_device_put;
334 }
335
336 err = platform_driver_probe(&ibmpowernv_driver, ibmpowernv_probe);
337 if (err) {
338 pr_err("Platfrom driver probe failed\n");
339 goto exit_device_del;
340 }
341
342 return 0;
343
344exit_device_del:
345 platform_device_del(pdevice);
346exit_device_put:
347 platform_device_put(pdevice);
348exit:
349 return err;
350}
351 320
352static void __exit ibmpowernv_exit(void) 321module_platform_driver(ibmpowernv_driver);
353{
354 platform_driver_unregister(&ibmpowernv_driver);
355 platform_device_unregister(pdevice);
356}
357 322
358MODULE_AUTHOR("Neelesh Gupta <neelegup@linux.vnet.ibm.com>"); 323MODULE_AUTHOR("Neelesh Gupta <neelegup@linux.vnet.ibm.com>");
359MODULE_DESCRIPTION("IBM POWERNV platform sensors"); 324MODULE_DESCRIPTION("IBM POWERNV platform sensors");
360MODULE_LICENSE("GPL"); 325MODULE_LICENSE("GPL");
361
362module_init(ibmpowernv_init);
363module_exit(ibmpowernv_exit);
diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
index 14c82daab019..980175628563 100644
--- a/drivers/hwmon/iio_hwmon.c
+++ b/drivers/hwmon/iio_hwmon.c
@@ -63,7 +63,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
63 struct iio_hwmon_state *st; 63 struct iio_hwmon_state *st;
64 struct sensor_device_attribute *a; 64 struct sensor_device_attribute *a;
65 int ret, i; 65 int ret, i;
66 int in_i = 1, temp_i = 1, curr_i = 1; 66 int in_i = 1, temp_i = 1, curr_i = 1, humidity_i = 1;
67 enum iio_chan_type type; 67 enum iio_chan_type type;
68 struct iio_channel *channels; 68 struct iio_channel *channels;
69 const char *name = "iio_hwmon"; 69 const char *name = "iio_hwmon";
@@ -123,6 +123,11 @@ static int iio_hwmon_probe(struct platform_device *pdev)
123 "curr%d_input", 123 "curr%d_input",
124 curr_i++); 124 curr_i++);
125 break; 125 break;
126 case IIO_HUMIDITYRELATIVE:
127 a->dev_attr.attr.name = kasprintf(GFP_KERNEL,
128 "humidity%d_input",
129 humidity_i++);
130 break;
126 default: 131 default:
127 ret = -EINVAL; 132 ret = -EINVAL;
128 goto error_release_channels; 133 goto error_release_channels;
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index bfd3f3eeabcd..e01feba909c3 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -223,6 +223,7 @@ static int ina2xx_probe(struct i2c_client *client,
223 struct device *hwmon_dev; 223 struct device *hwmon_dev;
224 long shunt = 10000; /* default shunt value 10mOhms */ 224 long shunt = 10000; /* default shunt value 10mOhms */
225 u32 val; 225 u32 val;
226 int ret;
226 227
227 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) 228 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA))
228 return -ENODEV; 229 return -ENODEV;
@@ -247,12 +248,25 @@ static int ina2xx_probe(struct i2c_client *client,
247 data->config = &ina2xx_config[data->kind]; 248 data->config = &ina2xx_config[data->kind];
248 249
249 /* device configuration */ 250 /* device configuration */
250 i2c_smbus_write_word_swapped(client, INA2XX_CONFIG, 251 ret = i2c_smbus_write_word_swapped(client, INA2XX_CONFIG,
251 data->config->config_default); 252 data->config->config_default);
252 /* set current LSB to 1mA, shunt is in uOhms */ 253 if (ret < 0) {
253 /* (equation 13 in datasheet) */ 254 dev_err(dev,
254 i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION, 255 "error writing to the config register: %d", ret);
255 data->config->calibration_factor / shunt); 256 return -ENODEV;
257 }
258
259 /*
260 * Set current LSB to 1mA, shunt is in uOhms
261 * (equation 13 in datasheet).
262 */
263 ret = i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION,
264 data->config->calibration_factor / shunt);
265 if (ret < 0) {
266 dev_err(dev,
267 "error writing to the calibration register: %d", ret);
268 return -ENODEV;
269 }
256 270
257 data->client = client; 271 data->client = client;
258 mutex_init(&data->update_lock); 272 mutex_init(&data->update_lock);
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index d16dbb33a531..6753fd940c76 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -44,6 +44,7 @@ enum lm75_type { /* keep sorted in alphabetical order */
44 g751, 44 g751,
45 lm75, 45 lm75,
46 lm75a, 46 lm75a,
47 lm75b,
47 max6625, 48 max6625,
48 max6626, 49 max6626,
49 mcp980x, 50 mcp980x,
@@ -233,6 +234,10 @@ lm75_probe(struct i2c_client *client, const struct i2c_device_id *id)
233 data->resolution = 9; 234 data->resolution = 9;
234 data->sample_time = HZ / 2; 235 data->sample_time = HZ / 2;
235 break; 236 break;
237 case lm75b:
238 data->resolution = 11;
239 data->sample_time = HZ / 4;
240 break;
236 case max6625: 241 case max6625:
237 data->resolution = 9; 242 data->resolution = 9;
238 data->sample_time = HZ / 4; 243 data->sample_time = HZ / 4;
@@ -322,6 +327,7 @@ static const struct i2c_device_id lm75_ids[] = {
322 { "g751", g751, }, 327 { "g751", g751, },
323 { "lm75", lm75, }, 328 { "lm75", lm75, },
324 { "lm75a", lm75a, }, 329 { "lm75a", lm75a, },
330 { "lm75b", lm75b, },
325 { "max6625", max6625, }, 331 { "max6625", max6625, },
326 { "max6626", max6626, }, 332 { "max6626", max6626, },
327 { "mcp980x", mcp980x, }, 333 { "mcp980x", mcp980x, },
@@ -409,6 +415,12 @@ static int lm75_detect(struct i2c_client *new_client,
409 || i2c_smbus_read_byte_data(new_client, 7) != os) 415 || i2c_smbus_read_byte_data(new_client, 7) != os)
410 return -ENODEV; 416 return -ENODEV;
411 } 417 }
418 /*
419 * It is very unlikely that this is a LM75 if both
420 * hysteresis and temperature limit registers are 0.
421 */
422 if (hyst == 0 && os == 0)
423 return -ENODEV;
412 424
413 /* Addresses cycling */ 425 /* Addresses cycling */
414 for (i = 8; i <= 248; i += 40) { 426 for (i = 8; i <= 248; i += 40) {
diff --git a/drivers/hwmon/lm95234.c b/drivers/hwmon/lm95234.c
index 411202bdaf6b..8796de39ff9b 100644
--- a/drivers/hwmon/lm95234.c
+++ b/drivers/hwmon/lm95234.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for Texas Instruments / National Semiconductor LM95234 2 * Driver for Texas Instruments / National Semiconductor LM95234
3 * 3 *
4 * Copyright (c) 2013 Guenter Roeck <linux@roeck-us.net> 4 * Copyright (c) 2013, 2014 Guenter Roeck <linux@roeck-us.net>
5 * 5 *
6 * Derived from lm95241.c 6 * Derived from lm95241.c
7 * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com> 7 * Copyright (C) 2008, 2010 Davide Rizzo <elpa.rizzo@gmail.com>
@@ -30,7 +30,10 @@
30 30
31#define DRVNAME "lm95234" 31#define DRVNAME "lm95234"
32 32
33static const unsigned short normal_i2c[] = { 0x18, 0x4d, 0x4e, I2C_CLIENT_END }; 33enum chips { lm95233, lm95234 };
34
35static const unsigned short normal_i2c[] = {
36 0x18, 0x2a, 0x2b, 0x4d, 0x4e, I2C_CLIENT_END };
34 37
35/* LM95234 registers */ 38/* LM95234 registers */
36#define LM95234_REG_MAN_ID 0xFE 39#define LM95234_REG_MAN_ID 0xFE
@@ -53,11 +56,13 @@ static const unsigned short normal_i2c[] = { 0x18, 0x4d, 0x4e, I2C_CLIENT_END };
53#define LM95234_REG_TCRIT_HYST 0x5a 56#define LM95234_REG_TCRIT_HYST 0x5a
54 57
55#define NATSEMI_MAN_ID 0x01 58#define NATSEMI_MAN_ID 0x01
59#define LM95233_CHIP_ID 0x89
56#define LM95234_CHIP_ID 0x79 60#define LM95234_CHIP_ID 0x79
57 61
58/* Client data (each client gets its own) */ 62/* Client data (each client gets its own) */
59struct lm95234_data { 63struct lm95234_data {
60 struct i2c_client *client; 64 struct i2c_client *client;
65 const struct attribute_group *groups[3];
61 struct mutex update_lock; 66 struct mutex update_lock;
62 unsigned long last_updated, interval; /* in jiffies */ 67 unsigned long last_updated, interval; /* in jiffies */
63 bool valid; /* false until following fields are valid */ 68 bool valid; /* false until following fields are valid */
@@ -564,35 +569,23 @@ static SENSOR_DEVICE_ATTR(temp5_offset, S_IWUSR | S_IRUGO, show_offset,
564static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval, 569static DEVICE_ATTR(update_interval, S_IWUSR | S_IRUGO, show_interval,
565 set_interval); 570 set_interval);
566 571
567static struct attribute *lm95234_attrs[] = { 572static struct attribute *lm95234_common_attrs[] = {
568 &sensor_dev_attr_temp1_input.dev_attr.attr, 573 &sensor_dev_attr_temp1_input.dev_attr.attr,
569 &sensor_dev_attr_temp2_input.dev_attr.attr, 574 &sensor_dev_attr_temp2_input.dev_attr.attr,
570 &sensor_dev_attr_temp3_input.dev_attr.attr, 575 &sensor_dev_attr_temp3_input.dev_attr.attr,
571 &sensor_dev_attr_temp4_input.dev_attr.attr,
572 &sensor_dev_attr_temp5_input.dev_attr.attr,
573 &sensor_dev_attr_temp2_fault.dev_attr.attr, 576 &sensor_dev_attr_temp2_fault.dev_attr.attr,
574 &sensor_dev_attr_temp3_fault.dev_attr.attr, 577 &sensor_dev_attr_temp3_fault.dev_attr.attr,
575 &sensor_dev_attr_temp4_fault.dev_attr.attr,
576 &sensor_dev_attr_temp5_fault.dev_attr.attr,
577 &sensor_dev_attr_temp2_type.dev_attr.attr, 578 &sensor_dev_attr_temp2_type.dev_attr.attr,
578 &sensor_dev_attr_temp3_type.dev_attr.attr, 579 &sensor_dev_attr_temp3_type.dev_attr.attr,
579 &sensor_dev_attr_temp4_type.dev_attr.attr,
580 &sensor_dev_attr_temp5_type.dev_attr.attr,
581 &sensor_dev_attr_temp1_max.dev_attr.attr, 580 &sensor_dev_attr_temp1_max.dev_attr.attr,
582 &sensor_dev_attr_temp2_max.dev_attr.attr, 581 &sensor_dev_attr_temp2_max.dev_attr.attr,
583 &sensor_dev_attr_temp3_max.dev_attr.attr, 582 &sensor_dev_attr_temp3_max.dev_attr.attr,
584 &sensor_dev_attr_temp4_max.dev_attr.attr,
585 &sensor_dev_attr_temp5_max.dev_attr.attr,
586 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr, 583 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
587 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr, 584 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
588 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr, 585 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
589 &sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
590 &sensor_dev_attr_temp5_max_hyst.dev_attr.attr,
591 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr, 586 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
592 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr, 587 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
593 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr, 588 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
594 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
595 &sensor_dev_attr_temp5_max_alarm.dev_attr.attr,
596 &sensor_dev_attr_temp2_crit.dev_attr.attr, 589 &sensor_dev_attr_temp2_crit.dev_attr.attr,
597 &sensor_dev_attr_temp3_crit.dev_attr.attr, 590 &sensor_dev_attr_temp3_crit.dev_attr.attr,
598 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr, 591 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
@@ -601,18 +594,44 @@ static struct attribute *lm95234_attrs[] = {
601 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr, 594 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
602 &sensor_dev_attr_temp2_offset.dev_attr.attr, 595 &sensor_dev_attr_temp2_offset.dev_attr.attr,
603 &sensor_dev_attr_temp3_offset.dev_attr.attr, 596 &sensor_dev_attr_temp3_offset.dev_attr.attr,
597 &dev_attr_update_interval.attr,
598 NULL
599};
600
601static const struct attribute_group lm95234_common_group = {
602 .attrs = lm95234_common_attrs,
603};
604
605static struct attribute *lm95234_attrs[] = {
606 &sensor_dev_attr_temp4_input.dev_attr.attr,
607 &sensor_dev_attr_temp5_input.dev_attr.attr,
608 &sensor_dev_attr_temp4_fault.dev_attr.attr,
609 &sensor_dev_attr_temp5_fault.dev_attr.attr,
610 &sensor_dev_attr_temp4_type.dev_attr.attr,
611 &sensor_dev_attr_temp5_type.dev_attr.attr,
612 &sensor_dev_attr_temp4_max.dev_attr.attr,
613 &sensor_dev_attr_temp5_max.dev_attr.attr,
614 &sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
615 &sensor_dev_attr_temp5_max_hyst.dev_attr.attr,
616 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
617 &sensor_dev_attr_temp5_max_alarm.dev_attr.attr,
604 &sensor_dev_attr_temp4_offset.dev_attr.attr, 618 &sensor_dev_attr_temp4_offset.dev_attr.attr,
605 &sensor_dev_attr_temp5_offset.dev_attr.attr, 619 &sensor_dev_attr_temp5_offset.dev_attr.attr,
606 &dev_attr_update_interval.attr,
607 NULL 620 NULL
608}; 621};
609ATTRIBUTE_GROUPS(lm95234); 622
623static const struct attribute_group lm95234_group = {
624 .attrs = lm95234_attrs,
625};
610 626
611static int lm95234_detect(struct i2c_client *client, 627static int lm95234_detect(struct i2c_client *client,
612 struct i2c_board_info *info) 628 struct i2c_board_info *info)
613{ 629{
614 struct i2c_adapter *adapter = client->adapter; 630 struct i2c_adapter *adapter = client->adapter;
631 int address = client->addr;
632 u8 config_mask, model_mask;
615 int mfg_id, chip_id, val; 633 int mfg_id, chip_id, val;
634 const char *name;
616 635
617 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 636 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
618 return -ENODEV; 637 return -ENODEV;
@@ -622,15 +641,31 @@ static int lm95234_detect(struct i2c_client *client,
622 return -ENODEV; 641 return -ENODEV;
623 642
624 chip_id = i2c_smbus_read_byte_data(client, LM95234_REG_CHIP_ID); 643 chip_id = i2c_smbus_read_byte_data(client, LM95234_REG_CHIP_ID);
625 if (chip_id != LM95234_CHIP_ID) 644 switch (chip_id) {
645 case LM95233_CHIP_ID:
646 if (address != 0x18 && address != 0x2a && address != 0x2b)
647 return -ENODEV;
648 config_mask = 0xbf;
649 model_mask = 0xf9;
650 name = "lm95233";
651 break;
652 case LM95234_CHIP_ID:
653 if (address != 0x18 && address != 0x4d && address != 0x4e)
654 return -ENODEV;
655 config_mask = 0xbc;
656 model_mask = 0xe1;
657 name = "lm95234";
658 break;
659 default:
626 return -ENODEV; 660 return -ENODEV;
661 }
627 662
628 val = i2c_smbus_read_byte_data(client, LM95234_REG_STATUS); 663 val = i2c_smbus_read_byte_data(client, LM95234_REG_STATUS);
629 if (val & 0x30) 664 if (val & 0x30)
630 return -ENODEV; 665 return -ENODEV;
631 666
632 val = i2c_smbus_read_byte_data(client, LM95234_REG_CONFIG); 667 val = i2c_smbus_read_byte_data(client, LM95234_REG_CONFIG);
633 if (val & 0xbc) 668 if (val & config_mask)
634 return -ENODEV; 669 return -ENODEV;
635 670
636 val = i2c_smbus_read_byte_data(client, LM95234_REG_CONVRATE); 671 val = i2c_smbus_read_byte_data(client, LM95234_REG_CONVRATE);
@@ -638,14 +673,14 @@ static int lm95234_detect(struct i2c_client *client,
638 return -ENODEV; 673 return -ENODEV;
639 674
640 val = i2c_smbus_read_byte_data(client, LM95234_REG_REM_MODEL); 675 val = i2c_smbus_read_byte_data(client, LM95234_REG_REM_MODEL);
641 if (val & 0xe1) 676 if (val & model_mask)
642 return -ENODEV; 677 return -ENODEV;
643 678
644 val = i2c_smbus_read_byte_data(client, LM95234_REG_REM_MODEL_STS); 679 val = i2c_smbus_read_byte_data(client, LM95234_REG_REM_MODEL_STS);
645 if (val & 0xe1) 680 if (val & model_mask)
646 return -ENODEV; 681 return -ENODEV;
647 682
648 strlcpy(info->type, "lm95234", I2C_NAME_SIZE); 683 strlcpy(info->type, name, I2C_NAME_SIZE);
649 return 0; 684 return 0;
650} 685}
651 686
@@ -698,15 +733,19 @@ static int lm95234_probe(struct i2c_client *client,
698 if (err < 0) 733 if (err < 0)
699 return err; 734 return err;
700 735
736 data->groups[0] = &lm95234_common_group;
737 if (id->driver_data == lm95234)
738 data->groups[1] = &lm95234_group;
739
701 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, 740 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
702 data, 741 data, data->groups);
703 lm95234_groups);
704 return PTR_ERR_OR_ZERO(hwmon_dev); 742 return PTR_ERR_OR_ZERO(hwmon_dev);
705} 743}
706 744
707/* Driver data (common to all clients) */ 745/* Driver data (common to all clients) */
708static const struct i2c_device_id lm95234_id[] = { 746static const struct i2c_device_id lm95234_id[] = {
709 { "lm95234", 0 }, 747 { "lm95233", lm95233 },
748 { "lm95234", lm95234 },
710 { } 749 { }
711}; 750};
712MODULE_DEVICE_TABLE(i2c, lm95234_id); 751MODULE_DEVICE_TABLE(i2c, lm95234_id);
@@ -725,5 +764,5 @@ static struct i2c_driver lm95234_driver = {
725module_i2c_driver(lm95234_driver); 764module_i2c_driver(lm95234_driver);
726 765
727MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>"); 766MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
728MODULE_DESCRIPTION("LM95234 sensor driver"); 767MODULE_DESCRIPTION("LM95233/LM95234 sensor driver");
729MODULE_LICENSE("GPL"); 768MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c
index 0ae0dfdafdff..e7aef4561c83 100644
--- a/drivers/hwmon/lm95245.c
+++ b/drivers/hwmon/lm95245.c
@@ -1,10 +1,8 @@
1/* 1/*
2 * Copyright (C) 2011 Alexander Stein <alexander.stein@systec-electronic.com> 2 * Copyright (C) 2011 Alexander Stein <alexander.stein@systec-electronic.com>
3 * 3 *
4 * The LM95245 is a sensor chip made by National Semiconductors. 4 * The LM95245 is a sensor chip made by TI / National Semiconductor.
5 * It reports up to two temperatures (its own plus an external one). 5 * It reports up to two temperatures (its own plus an external one).
6 * Complete datasheet can be obtained from National's website at:
7 * http://www.national.com/ds.cgi/LM/LM95245.pdf
8 * 6 *
9 * This driver is based on lm95241.c 7 * This driver is based on lm95241.c
10 * 8 *
@@ -34,8 +32,6 @@
34#include <linux/mutex.h> 32#include <linux/mutex.h>
35#include <linux/sysfs.h> 33#include <linux/sysfs.h>
36 34
37#define DEVNAME "lm95245"
38
39static const unsigned short normal_i2c[] = { 35static const unsigned short normal_i2c[] = {
40 0x18, 0x19, 0x29, 0x4c, 0x4d, I2C_CLIENT_END }; 36 0x18, 0x19, 0x29, 0x4c, 0x4d, I2C_CLIENT_END };
41 37
@@ -98,7 +94,8 @@ static const unsigned short normal_i2c[] = {
98#define STATUS1_LOC 0x01 94#define STATUS1_LOC 0x01
99 95
100#define MANUFACTURER_ID 0x01 96#define MANUFACTURER_ID 0x01
101#define DEFAULT_REVISION 0xB3 97#define LM95235_REVISION 0xB1
98#define LM95245_REVISION 0xB3
102 99
103static const u8 lm95245_reg_address[] = { 100static const u8 lm95245_reg_address[] = {
104 LM95245_REG_R_LOCAL_TEMPH_S, 101 LM95245_REG_R_LOCAL_TEMPH_S,
@@ -427,17 +424,32 @@ static int lm95245_detect(struct i2c_client *new_client,
427 struct i2c_board_info *info) 424 struct i2c_board_info *info)
428{ 425{
429 struct i2c_adapter *adapter = new_client->adapter; 426 struct i2c_adapter *adapter = new_client->adapter;
427 int address = new_client->addr;
428 const char *name;
429 int rev, id;
430 430
431 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 431 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
432 return -ENODEV; 432 return -ENODEV;
433 433
434 if (i2c_smbus_read_byte_data(new_client, LM95245_REG_R_MAN_ID) 434 id = i2c_smbus_read_byte_data(new_client, LM95245_REG_R_MAN_ID);
435 != MANUFACTURER_ID 435 if (id != MANUFACTURER_ID)
436 || i2c_smbus_read_byte_data(new_client, LM95245_REG_R_CHIP_ID)
437 != DEFAULT_REVISION)
438 return -ENODEV; 436 return -ENODEV;
439 437
440 strlcpy(info->type, DEVNAME, I2C_NAME_SIZE); 438 rev = i2c_smbus_read_byte_data(new_client, LM95245_REG_R_CHIP_ID);
439 switch (rev) {
440 case LM95235_REVISION:
441 if (address != 0x18 && address != 0x29 && address != 0x4c)
442 return -ENODEV;
443 name = "lm95235";
444 break;
445 case LM95245_REVISION:
446 name = "lm95245";
447 break;
448 default:
449 return -ENODEV;
450 }
451
452 strlcpy(info->type, name, I2C_NAME_SIZE);
441 return 0; 453 return 0;
442} 454}
443 455
@@ -484,7 +496,8 @@ static int lm95245_probe(struct i2c_client *client,
484 496
485/* Driver data (common to all clients) */ 497/* Driver data (common to all clients) */
486static const struct i2c_device_id lm95245_id[] = { 498static const struct i2c_device_id lm95245_id[] = {
487 { DEVNAME, 0 }, 499 { "lm95235", 0 },
500 { "lm95245", 0 },
488 { } 501 { }
489}; 502};
490MODULE_DEVICE_TABLE(i2c, lm95245_id); 503MODULE_DEVICE_TABLE(i2c, lm95245_id);
@@ -492,7 +505,7 @@ MODULE_DEVICE_TABLE(i2c, lm95245_id);
492static struct i2c_driver lm95245_driver = { 505static struct i2c_driver lm95245_driver = {
493 .class = I2C_CLASS_HWMON, 506 .class = I2C_CLASS_HWMON,
494 .driver = { 507 .driver = {
495 .name = DEVNAME, 508 .name = "lm95245",
496 }, 509 },
497 .probe = lm95245_probe, 510 .probe = lm95245_probe,
498 .id_table = lm95245_id, 511 .id_table = lm95245_id,
@@ -503,5 +516,5 @@ static struct i2c_driver lm95245_driver = {
503module_i2c_driver(lm95245_driver); 516module_i2c_driver(lm95245_driver);
504 517
505MODULE_AUTHOR("Alexander Stein <alexander.stein@systec-electronic.com>"); 518MODULE_AUTHOR("Alexander Stein <alexander.stein@systec-electronic.com>");
506MODULE_DESCRIPTION("LM95245 sensor driver"); 519MODULE_DESCRIPTION("LM95235/LM95245 sensor driver");
507MODULE_LICENSE("GPL"); 520MODULE_LICENSE("GPL");
diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
index 504cbddbdd90..dc0df57200cd 100644
--- a/drivers/hwmon/nct6775.c
+++ b/drivers/hwmon/nct6775.c
@@ -38,6 +38,7 @@
38 * nct6776f 9 5 3 6+3 0xc330 0xc1 0x5ca3 38 * nct6776f 9 5 3 6+3 0xc330 0xc1 0x5ca3
39 * nct6779d 15 5 5 2+6 0xc560 0xc1 0x5ca3 39 * nct6779d 15 5 5 2+6 0xc560 0xc1 0x5ca3
40 * nct6791d 15 6 6 2+6 0xc800 0xc1 0x5ca3 40 * nct6791d 15 6 6 2+6 0xc800 0xc1 0x5ca3
41 * nct6792d 15 6 6 2+6 0xc910 0xc1 0x5ca3
41 * 42 *
42 * #temp lists the number of monitored temperature sources (first value) plus 43 * #temp lists the number of monitored temperature sources (first value) plus
43 * the number of directly connectable temperature sensors (second value). 44 * the number of directly connectable temperature sensors (second value).
@@ -61,7 +62,7 @@
61 62
62#define USE_ALTERNATE 63#define USE_ALTERNATE
63 64
64enum kinds { nct6106, nct6775, nct6776, nct6779, nct6791 }; 65enum kinds { nct6106, nct6775, nct6776, nct6779, nct6791, nct6792 };
65 66
66/* used to set data->name = nct6775_device_names[data->sio_kind] */ 67/* used to set data->name = nct6775_device_names[data->sio_kind] */
67static const char * const nct6775_device_names[] = { 68static const char * const nct6775_device_names[] = {
@@ -70,6 +71,7 @@ static const char * const nct6775_device_names[] = {
70 "nct6776", 71 "nct6776",
71 "nct6779", 72 "nct6779",
72 "nct6791", 73 "nct6791",
74 "nct6792",
73}; 75};
74 76
75static unsigned short force_id; 77static unsigned short force_id;
@@ -100,6 +102,7 @@ MODULE_PARM_DESC(fan_debounce, "Enable debouncing for fan RPM signal");
100#define SIO_NCT6776_ID 0xc330 102#define SIO_NCT6776_ID 0xc330
101#define SIO_NCT6779_ID 0xc560 103#define SIO_NCT6779_ID 0xc560
102#define SIO_NCT6791_ID 0xc800 104#define SIO_NCT6791_ID 0xc800
105#define SIO_NCT6792_ID 0xc910
103#define SIO_ID_MASK 0xFFF0 106#define SIO_ID_MASK 0xFFF0
104 107
105enum pwm_enable { off, manual, thermal_cruise, speed_cruise, sf3, sf4 }; 108enum pwm_enable { off, manual, thermal_cruise, speed_cruise, sf3, sf4 };
@@ -529,6 +532,12 @@ static const s8 NCT6791_ALARM_BITS[] = {
529 4, 5, 13, -1, -1, -1, /* temp1..temp6 */ 532 4, 5, 13, -1, -1, -1, /* temp1..temp6 */
530 12, 9 }; /* intrusion0, intrusion1 */ 533 12, 9 }; /* intrusion0, intrusion1 */
531 534
535/* NCT6792 specific data */
536
537static const u16 NCT6792_REG_TEMP_MON[] = {
538 0x73, 0x75, 0x77, 0x79, 0x7b, 0x7d };
539static const u16 NCT6792_REG_BEEP[NUM_REG_BEEP] = {
540 0xb2, 0xb3, 0xb4, 0xb5, 0xbf };
532 541
533/* NCT6102D/NCT6106D specific data */ 542/* NCT6102D/NCT6106D specific data */
534 543
@@ -1043,13 +1052,14 @@ static bool is_word_sized(struct nct6775_data *data, u16 reg)
1043 reg == 0x73 || reg == 0x75 || reg == 0x77; 1052 reg == 0x73 || reg == 0x75 || reg == 0x77;
1044 case nct6779: 1053 case nct6779:
1045 case nct6791: 1054 case nct6791:
1055 case nct6792:
1046 return reg == 0x150 || reg == 0x153 || reg == 0x155 || 1056 return reg == 0x150 || reg == 0x153 || reg == 0x155 ||
1047 ((reg & 0xfff0) == 0x4b0 && (reg & 0x000f) < 0x0b) || 1057 ((reg & 0xfff0) == 0x4b0 && (reg & 0x000f) < 0x0b) ||
1048 reg == 0x402 || 1058 reg == 0x402 ||
1049 reg == 0x63a || reg == 0x63c || reg == 0x63e || 1059 reg == 0x63a || reg == 0x63c || reg == 0x63e ||
1050 reg == 0x640 || reg == 0x642 || 1060 reg == 0x640 || reg == 0x642 ||
1051 reg == 0x73 || reg == 0x75 || reg == 0x77 || reg == 0x79 || 1061 reg == 0x73 || reg == 0x75 || reg == 0x77 || reg == 0x79 ||
1052 reg == 0x7b; 1062 reg == 0x7b || reg == 0x7d;
1053 } 1063 }
1054 return false; 1064 return false;
1055} 1065}
@@ -1063,6 +1073,7 @@ static bool is_word_sized(struct nct6775_data *data, u16 reg)
1063static inline void nct6775_set_bank(struct nct6775_data *data, u16 reg) 1073static inline void nct6775_set_bank(struct nct6775_data *data, u16 reg)
1064{ 1074{
1065 u8 bank = reg >> 8; 1075 u8 bank = reg >> 8;
1076
1066 if (data->bank != bank) { 1077 if (data->bank != bank) {
1067 outb_p(NCT6775_REG_BANK, data->addr + ADDR_REG_OFFSET); 1078 outb_p(NCT6775_REG_BANK, data->addr + ADDR_REG_OFFSET);
1068 outb_p(bank, data->addr + DATA_REG_OFFSET); 1079 outb_p(bank, data->addr + DATA_REG_OFFSET);
@@ -1300,6 +1311,7 @@ static void nct6775_update_pwm(struct device *dev)
1300 if (!data->target_speed_tolerance[i] || 1311 if (!data->target_speed_tolerance[i] ||
1301 data->pwm_enable[i] == speed_cruise) { 1312 data->pwm_enable[i] == speed_cruise) {
1302 u8 t = fanmodecfg & 0x0f; 1313 u8 t = fanmodecfg & 0x0f;
1314
1303 if (data->REG_TOLERANCE_H) { 1315 if (data->REG_TOLERANCE_H) {
1304 t |= (nct6775_read_value(data, 1316 t |= (nct6775_read_value(data,
1305 data->REG_TOLERANCE_H[i]) & 0x70) >> 1; 1317 data->REG_TOLERANCE_H[i]) & 0x70) >> 1;
@@ -1391,6 +1403,7 @@ static void nct6775_update_pwm_limits(struct device *dev)
1391 case nct6106: 1403 case nct6106:
1392 case nct6779: 1404 case nct6779:
1393 case nct6791: 1405 case nct6791:
1406 case nct6792:
1394 reg = nct6775_read_value(data, 1407 reg = nct6775_read_value(data,
1395 data->REG_CRITICAL_PWM_ENABLE[i]); 1408 data->REG_CRITICAL_PWM_ENABLE[i]);
1396 if (reg & data->CRITICAL_PWM_ENABLE_MASK) 1409 if (reg & data->CRITICAL_PWM_ENABLE_MASK)
@@ -1473,6 +1486,7 @@ static struct nct6775_data *nct6775_update_device(struct device *dev)
1473 data->alarms = 0; 1486 data->alarms = 0;
1474 for (i = 0; i < NUM_REG_ALARM; i++) { 1487 for (i = 0; i < NUM_REG_ALARM; i++) {
1475 u8 alarm; 1488 u8 alarm;
1489
1476 if (!data->REG_ALARM[i]) 1490 if (!data->REG_ALARM[i])
1477 continue; 1491 continue;
1478 alarm = nct6775_read_value(data, data->REG_ALARM[i]); 1492 alarm = nct6775_read_value(data, data->REG_ALARM[i]);
@@ -1482,6 +1496,7 @@ static struct nct6775_data *nct6775_update_device(struct device *dev)
1482 data->beeps = 0; 1496 data->beeps = 0;
1483 for (i = 0; i < NUM_REG_BEEP; i++) { 1497 for (i = 0; i < NUM_REG_BEEP; i++) {
1484 u8 beep; 1498 u8 beep;
1499
1485 if (!data->REG_BEEP[i]) 1500 if (!data->REG_BEEP[i])
1486 continue; 1501 continue;
1487 beep = nct6775_read_value(data, data->REG_BEEP[i]); 1502 beep = nct6775_read_value(data, data->REG_BEEP[i]);
@@ -1504,8 +1519,9 @@ show_in_reg(struct device *dev, struct device_attribute *attr, char *buf)
1504{ 1519{
1505 struct nct6775_data *data = nct6775_update_device(dev); 1520 struct nct6775_data *data = nct6775_update_device(dev);
1506 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 1521 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1507 int nr = sattr->nr;
1508 int index = sattr->index; 1522 int index = sattr->index;
1523 int nr = sattr->nr;
1524
1509 return sprintf(buf, "%ld\n", in_from_reg(data->in[nr][index], nr)); 1525 return sprintf(buf, "%ld\n", in_from_reg(data->in[nr][index], nr));
1510} 1526}
1511 1527
@@ -1515,10 +1531,12 @@ store_in_reg(struct device *dev, struct device_attribute *attr, const char *buf,
1515{ 1531{
1516 struct nct6775_data *data = dev_get_drvdata(dev); 1532 struct nct6775_data *data = dev_get_drvdata(dev);
1517 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); 1533 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
1518 int nr = sattr->nr;
1519 int index = sattr->index; 1534 int index = sattr->index;
1535 int nr = sattr->nr;
1520 unsigned long val; 1536 unsigned long val;
1521 int err = kstrtoul(buf, 10, &val); 1537 int err;
1538
1539 err = kstrtoul(buf, 10, &val);
1522 if (err < 0) 1540 if (err < 0)
1523 return err; 1541 return err;
1524 mutex_lock(&data->update_lock); 1542 mutex_lock(&data->update_lock);
@@ -1535,6 +1553,7 @@ show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
1535 struct nct6775_data *data = nct6775_update_device(dev); 1553 struct nct6775_data *data = nct6775_update_device(dev);
1536 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); 1554 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
1537 int nr = data->ALARM_BITS[sattr->index]; 1555 int nr = data->ALARM_BITS[sattr->index];
1556
1538 return sprintf(buf, "%u\n", 1557 return sprintf(buf, "%u\n",
1539 (unsigned int)((data->alarms >> nr) & 0x01)); 1558 (unsigned int)((data->alarms >> nr) & 0x01));
1540} 1559}
@@ -1570,6 +1589,7 @@ show_temp_alarm(struct device *dev, struct device_attribute *attr, char *buf)
1570 nr = find_temp_source(data, sattr->index, data->num_temp_alarms); 1589 nr = find_temp_source(data, sattr->index, data->num_temp_alarms);
1571 if (nr >= 0) { 1590 if (nr >= 0) {
1572 int bit = data->ALARM_BITS[nr + TEMP_ALARM_BASE]; 1591 int bit = data->ALARM_BITS[nr + TEMP_ALARM_BASE];
1592
1573 alarm = (data->alarms >> bit) & 0x01; 1593 alarm = (data->alarms >> bit) & 0x01;
1574 } 1594 }
1575 return sprintf(buf, "%u\n", alarm); 1595 return sprintf(buf, "%u\n", alarm);
@@ -1595,8 +1615,9 @@ store_beep(struct device *dev, struct device_attribute *attr, const char *buf,
1595 int nr = data->BEEP_BITS[sattr->index]; 1615 int nr = data->BEEP_BITS[sattr->index];
1596 int regindex = nr >> 3; 1616 int regindex = nr >> 3;
1597 unsigned long val; 1617 unsigned long val;
1618 int err;
1598 1619
1599 int err = kstrtoul(buf, 10, &val); 1620 err = kstrtoul(buf, 10, &val);
1600 if (err < 0) 1621 if (err < 0)
1601 return err; 1622 return err;
1602 if (val > 1) 1623 if (val > 1)
@@ -1629,6 +1650,7 @@ show_temp_beep(struct device *dev, struct device_attribute *attr, char *buf)
1629 nr = find_temp_source(data, sattr->index, data->num_temp_beeps); 1650 nr = find_temp_source(data, sattr->index, data->num_temp_beeps);
1630 if (nr >= 0) { 1651 if (nr >= 0) {
1631 int bit = data->BEEP_BITS[nr + TEMP_ALARM_BASE]; 1652 int bit = data->BEEP_BITS[nr + TEMP_ALARM_BASE];
1653
1632 beep = (data->beeps >> bit) & 0x01; 1654 beep = (data->beeps >> bit) & 0x01;
1633 } 1655 }
1634 return sprintf(buf, "%u\n", beep); 1656 return sprintf(buf, "%u\n", beep);
@@ -1642,8 +1664,9 @@ store_temp_beep(struct device *dev, struct device_attribute *attr,
1642 struct nct6775_data *data = dev_get_drvdata(dev); 1664 struct nct6775_data *data = dev_get_drvdata(dev);
1643 int nr, bit, regindex; 1665 int nr, bit, regindex;
1644 unsigned long val; 1666 unsigned long val;
1667 int err;
1645 1668
1646 int err = kstrtoul(buf, 10, &val); 1669 err = kstrtoul(buf, 10, &val);
1647 if (err < 0) 1670 if (err < 0)
1648 return err; 1671 return err;
1649 if (val > 1) 1672 if (val > 1)
@@ -1715,6 +1738,7 @@ show_fan(struct device *dev, struct device_attribute *attr, char *buf)
1715 struct nct6775_data *data = nct6775_update_device(dev); 1738 struct nct6775_data *data = nct6775_update_device(dev);
1716 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); 1739 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
1717 int nr = sattr->index; 1740 int nr = sattr->index;
1741
1718 return sprintf(buf, "%d\n", data->rpm[nr]); 1742 return sprintf(buf, "%d\n", data->rpm[nr]);
1719} 1743}
1720 1744
@@ -1724,6 +1748,7 @@ show_fan_min(struct device *dev, struct device_attribute *attr, char *buf)
1724 struct nct6775_data *data = nct6775_update_device(dev); 1748 struct nct6775_data *data = nct6775_update_device(dev);
1725 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); 1749 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
1726 int nr = sattr->index; 1750 int nr = sattr->index;
1751
1727 return sprintf(buf, "%d\n", 1752 return sprintf(buf, "%d\n",
1728 data->fan_from_reg_min(data->fan_min[nr], 1753 data->fan_from_reg_min(data->fan_min[nr],
1729 data->fan_div[nr])); 1754 data->fan_div[nr]));
@@ -1735,6 +1760,7 @@ show_fan_div(struct device *dev, struct device_attribute *attr, char *buf)
1735 struct nct6775_data *data = nct6775_update_device(dev); 1760 struct nct6775_data *data = nct6775_update_device(dev);
1736 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); 1761 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
1737 int nr = sattr->index; 1762 int nr = sattr->index;
1763
1738 return sprintf(buf, "%u\n", div_from_reg(data->fan_div[nr])); 1764 return sprintf(buf, "%u\n", div_from_reg(data->fan_div[nr]));
1739} 1765}
1740 1766
@@ -1746,9 +1772,9 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
1746 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); 1772 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
1747 int nr = sattr->index; 1773 int nr = sattr->index;
1748 unsigned long val; 1774 unsigned long val;
1749 int err;
1750 unsigned int reg; 1775 unsigned int reg;
1751 u8 new_div; 1776 u8 new_div;
1777 int err;
1752 1778
1753 err = kstrtoul(buf, 10, &val); 1779 err = kstrtoul(buf, 10, &val);
1754 if (err < 0) 1780 if (err < 0)
@@ -1932,6 +1958,7 @@ show_temp_label(struct device *dev, struct device_attribute *attr, char *buf)
1932 struct nct6775_data *data = nct6775_update_device(dev); 1958 struct nct6775_data *data = nct6775_update_device(dev);
1933 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); 1959 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
1934 int nr = sattr->index; 1960 int nr = sattr->index;
1961
1935 return sprintf(buf, "%s\n", data->temp_label[data->temp_src[nr]]); 1962 return sprintf(buf, "%s\n", data->temp_label[data->temp_src[nr]]);
1936} 1963}
1937 1964
@@ -2008,6 +2035,7 @@ show_temp_type(struct device *dev, struct device_attribute *attr, char *buf)
2008 struct nct6775_data *data = nct6775_update_device(dev); 2035 struct nct6775_data *data = nct6775_update_device(dev);
2009 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); 2036 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
2010 int nr = sattr->index; 2037 int nr = sattr->index;
2038
2011 return sprintf(buf, "%d\n", (int)data->temp_type[nr]); 2039 return sprintf(buf, "%d\n", (int)data->temp_type[nr]);
2012} 2040}
2013 2041
@@ -2790,6 +2818,7 @@ store_auto_pwm(struct device *dev, struct device_attribute *attr,
2790 case nct6106: 2818 case nct6106:
2791 case nct6779: 2819 case nct6779:
2792 case nct6791: 2820 case nct6791:
2821 case nct6792:
2793 nct6775_write_value(data, data->REG_CRITICAL_PWM[nr], 2822 nct6775_write_value(data, data->REG_CRITICAL_PWM[nr],
2794 val); 2823 val);
2795 reg = nct6775_read_value(data, 2824 reg = nct6775_read_value(data,
@@ -2997,6 +3026,7 @@ static ssize_t
2997show_vid(struct device *dev, struct device_attribute *attr, char *buf) 3026show_vid(struct device *dev, struct device_attribute *attr, char *buf)
2998{ 3027{
2999 struct nct6775_data *data = dev_get_drvdata(dev); 3028 struct nct6775_data *data = dev_get_drvdata(dev);
3029
3000 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); 3030 return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
3001} 3031}
3002 3032
@@ -3202,7 +3232,7 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
3202 pwm4pin = false; 3232 pwm4pin = false;
3203 pwm5pin = false; 3233 pwm5pin = false;
3204 pwm6pin = false; 3234 pwm6pin = false;
3205 } else { /* NCT6779D or NCT6791D */ 3235 } else { /* NCT6779D, NCT6791D, or NCT6792D */
3206 regval = superio_inb(sioreg, 0x1c); 3236 regval = superio_inb(sioreg, 0x1c);
3207 3237
3208 fan3pin = !(regval & (1 << 5)); 3238 fan3pin = !(regval & (1 << 5));
@@ -3215,7 +3245,7 @@ nct6775_check_fan_inputs(struct nct6775_data *data)
3215 3245
3216 fan4min = fan4pin; 3246 fan4min = fan4pin;
3217 3247
3218 if (data->kind == nct6791) { 3248 if (data->kind == nct6791 || data->kind == nct6792) {
3219 regval = superio_inb(sioreg, 0x2d); 3249 regval = superio_inb(sioreg, 0x2d);
3220 fan6pin = (regval & (1 << 1)); 3250 fan6pin = (regval & (1 << 1));
3221 pwm6pin = (regval & (1 << 0)); 3251 pwm6pin = (regval & (1 << 0));
@@ -3588,6 +3618,7 @@ static int nct6775_probe(struct platform_device *pdev)
3588 3618
3589 break; 3619 break;
3590 case nct6791: 3620 case nct6791:
3621 case nct6792:
3591 data->in_num = 15; 3622 data->in_num = 15;
3592 data->pwm_num = 6; 3623 data->pwm_num = 6;
3593 data->auto_pwm_num = 4; 3624 data->auto_pwm_num = 4;
@@ -3650,12 +3681,20 @@ static int nct6775_probe(struct platform_device *pdev)
3650 data->REG_WEIGHT_TEMP[1] = NCT6791_REG_WEIGHT_TEMP_STEP_TOL; 3681 data->REG_WEIGHT_TEMP[1] = NCT6791_REG_WEIGHT_TEMP_STEP_TOL;
3651 data->REG_WEIGHT_TEMP[2] = NCT6791_REG_WEIGHT_TEMP_BASE; 3682 data->REG_WEIGHT_TEMP[2] = NCT6791_REG_WEIGHT_TEMP_BASE;
3652 data->REG_ALARM = NCT6791_REG_ALARM; 3683 data->REG_ALARM = NCT6791_REG_ALARM;
3653 data->REG_BEEP = NCT6776_REG_BEEP; 3684 if (data->kind == nct6791)
3685 data->REG_BEEP = NCT6776_REG_BEEP;
3686 else
3687 data->REG_BEEP = NCT6792_REG_BEEP;
3654 3688
3655 reg_temp = NCT6779_REG_TEMP; 3689 reg_temp = NCT6779_REG_TEMP;
3656 reg_temp_mon = NCT6779_REG_TEMP_MON;
3657 num_reg_temp = ARRAY_SIZE(NCT6779_REG_TEMP); 3690 num_reg_temp = ARRAY_SIZE(NCT6779_REG_TEMP);
3658 num_reg_temp_mon = ARRAY_SIZE(NCT6779_REG_TEMP_MON); 3691 if (data->kind == nct6791) {
3692 reg_temp_mon = NCT6779_REG_TEMP_MON;
3693 num_reg_temp_mon = ARRAY_SIZE(NCT6779_REG_TEMP_MON);
3694 } else {
3695 reg_temp_mon = NCT6792_REG_TEMP_MON;
3696 num_reg_temp_mon = ARRAY_SIZE(NCT6792_REG_TEMP_MON);
3697 }
3659 reg_temp_over = NCT6779_REG_TEMP_OVER; 3698 reg_temp_over = NCT6779_REG_TEMP_OVER;
3660 reg_temp_hyst = NCT6779_REG_TEMP_HYST; 3699 reg_temp_hyst = NCT6779_REG_TEMP_HYST;
3661 reg_temp_config = NCT6779_REG_TEMP_CONFIG; 3700 reg_temp_config = NCT6779_REG_TEMP_CONFIG;
@@ -3854,6 +3893,7 @@ static int nct6775_probe(struct platform_device *pdev)
3854 case nct6106: 3893 case nct6106:
3855 case nct6779: 3894 case nct6779:
3856 case nct6791: 3895 case nct6791:
3896 case nct6792:
3857 break; 3897 break;
3858 } 3898 }
3859 3899
@@ -3885,6 +3925,7 @@ static int nct6775_probe(struct platform_device *pdev)
3885 tmp |= 0x3e; 3925 tmp |= 0x3e;
3886 break; 3926 break;
3887 case nct6791: 3927 case nct6791:
3928 case nct6792:
3888 tmp |= 0x7e; 3929 tmp |= 0x7e;
3889 break; 3930 break;
3890 } 3931 }
@@ -3972,7 +4013,7 @@ static int nct6775_resume(struct device *dev)
3972 mutex_lock(&data->update_lock); 4013 mutex_lock(&data->update_lock);
3973 data->bank = 0xff; /* Force initial bank selection */ 4014 data->bank = 0xff; /* Force initial bank selection */
3974 4015
3975 if (data->kind == nct6791) { 4016 if (data->kind == nct6791 || data->kind == nct6792) {
3976 err = superio_enter(data->sioreg); 4017 err = superio_enter(data->sioreg);
3977 if (err) 4018 if (err)
3978 goto abort; 4019 goto abort;
@@ -4052,6 +4093,7 @@ static const char * const nct6775_sio_names[] __initconst = {
4052 "NCT6776D/F", 4093 "NCT6776D/F",
4053 "NCT6779D", 4094 "NCT6779D",
4054 "NCT6791D", 4095 "NCT6791D",
4096 "NCT6792D",
4055}; 4097};
4056 4098
4057/* nct6775_find() looks for a '627 in the Super-I/O config space */ 4099/* nct6775_find() looks for a '627 in the Super-I/O config space */
@@ -4086,6 +4128,9 @@ static int __init nct6775_find(int sioaddr, struct nct6775_sio_data *sio_data)
4086 case SIO_NCT6791_ID: 4128 case SIO_NCT6791_ID:
4087 sio_data->kind = nct6791; 4129 sio_data->kind = nct6791;
4088 break; 4130 break;
4131 case SIO_NCT6792_ID:
4132 sio_data->kind = nct6792;
4133 break;
4089 default: 4134 default:
4090 if (val != 0xffff) 4135 if (val != 0xffff)
4091 pr_debug("unsupported chip ID: 0x%04x\n", val); 4136 pr_debug("unsupported chip ID: 0x%04x\n", val);
@@ -4111,7 +4156,7 @@ static int __init nct6775_find(int sioaddr, struct nct6775_sio_data *sio_data)
4111 superio_outb(sioaddr, SIO_REG_ENABLE, val | 0x01); 4156 superio_outb(sioaddr, SIO_REG_ENABLE, val | 0x01);
4112 } 4157 }
4113 4158
4114 if (sio_data->kind == nct6791) 4159 if (sio_data->kind == nct6791 || sio_data->kind == nct6792)
4115 nct6791_enable_io_mapping(sioaddr); 4160 nct6791_enable_io_mapping(sioaddr);
4116 4161
4117 superio_exit(sioaddr); 4162 superio_exit(sioaddr);
@@ -4221,7 +4266,7 @@ static void __exit sensors_nct6775_exit(void)
4221} 4266}
4222 4267
4223MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>"); 4268MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
4224MODULE_DESCRIPTION("NCT6106D/NCT6775F/NCT6776F/NCT6779D/NCT6791D driver"); 4269MODULE_DESCRIPTION("NCT6106D/NCT6775F/NCT6776F/NCT6779D/NCT6791D/NCT6792D driver");
4225MODULE_LICENSE("GPL"); 4270MODULE_LICENSE("GPL");
4226 4271
4227module_init(sensors_nct6775_init); 4272module_init(sensors_nct6775_init);
diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
new file mode 100644
index 000000000000..ec5678289e4a
--- /dev/null
+++ b/drivers/hwmon/nct7802.c
@@ -0,0 +1,860 @@
1/*
2 * nct7802 - Driver for Nuvoton NCT7802Y
3 *
4 * Copyright (C) 2014 Guenter Roeck <linux@roeck-us.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
19#include <linux/err.h>
20#include <linux/i2c.h>
21#include <linux/init.h>
22#include <linux/hwmon.h>
23#include <linux/hwmon-sysfs.h>
24#include <linux/jiffies.h>
25#include <linux/module.h>
26#include <linux/mutex.h>
27#include <linux/regmap.h>
28#include <linux/slab.h>
29
30#define DRVNAME "nct7802"
31
32static const u8 REG_VOLTAGE[5] = { 0x09, 0x0a, 0x0c, 0x0d, 0x0e };
33
34static const u8 REG_VOLTAGE_LIMIT_LSB[2][5] = {
35 { 0x40, 0x00, 0x42, 0x44, 0x46 },
36 { 0x3f, 0x00, 0x41, 0x43, 0x45 },
37};
38
39static const u8 REG_VOLTAGE_LIMIT_MSB[5] = { 0x48, 0x00, 0x47, 0x47, 0x48 };
40
41static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = {
42 { 0, 0, 4, 0, 4 },
43 { 2, 0, 6, 2, 6 },
44};
45
46#define REG_BANK 0x00
47#define REG_TEMP_LSB 0x05
48#define REG_TEMP_PECI_LSB 0x08
49#define REG_VOLTAGE_LOW 0x0f
50#define REG_FANCOUNT_LOW 0x13
51#define REG_START 0x21
52#define REG_MODE 0x22
53#define REG_PECI_ENABLE 0x23
54#define REG_FAN_ENABLE 0x24
55#define REG_VMON_ENABLE 0x25
56#define REG_VENDOR_ID 0xfd
57#define REG_CHIP_ID 0xfe
58#define REG_VERSION_ID 0xff
59
60/*
61 * Data structures and manipulation thereof
62 */
63
64struct nct7802_data {
65 struct regmap *regmap;
66 struct mutex access_lock; /* for multi-byte read and write operations */
67};
68
69static int nct7802_read_temp(struct nct7802_data *data,
70 u8 reg_temp, u8 reg_temp_low, int *temp)
71{
72 unsigned int t1, t2 = 0;
73 int err;
74
75 *temp = 0;
76
77 mutex_lock(&data->access_lock);
78 err = regmap_read(data->regmap, reg_temp, &t1);
79 if (err < 0)
80 goto abort;
81 t1 <<= 8;
82 if (reg_temp_low) { /* 11 bit data */
83 err = regmap_read(data->regmap, reg_temp_low, &t2);
84 if (err < 0)
85 goto abort;
86 }
87 t1 |= t2 & 0xe0;
88 *temp = (s16)t1 / 32 * 125;
89abort:
90 mutex_unlock(&data->access_lock);
91 return err;
92}
93
94static int nct7802_read_fan(struct nct7802_data *data, u8 reg_fan)
95{
96 unsigned int f1, f2;
97 int ret;
98
99 mutex_lock(&data->access_lock);
100 ret = regmap_read(data->regmap, reg_fan, &f1);
101 if (ret < 0)
102 goto abort;
103 ret = regmap_read(data->regmap, REG_FANCOUNT_LOW, &f2);
104 if (ret < 0)
105 goto abort;
106 ret = (f1 << 5) | (f2 >> 3);
107 /* convert fan count to rpm */
108 if (ret == 0x1fff) /* maximum value, assume fan is stopped */
109 ret = 0;
110 else if (ret)
111 ret = DIV_ROUND_CLOSEST(1350000U, ret);
112abort:
113 mutex_unlock(&data->access_lock);
114 return ret;
115}
116
117static int nct7802_read_fan_min(struct nct7802_data *data, u8 reg_fan_low,
118 u8 reg_fan_high)
119{
120 unsigned int f1, f2;
121 int ret;
122
123 mutex_lock(&data->access_lock);
124 ret = regmap_read(data->regmap, reg_fan_low, &f1);
125 if (ret < 0)
126 goto abort;
127 ret = regmap_read(data->regmap, reg_fan_high, &f2);
128 if (ret < 0)
129 goto abort;
130 ret = f1 | ((f2 & 0xf8) << 5);
131 /* convert fan count to rpm */
132 if (ret == 0x1fff) /* maximum value, assume no limit */
133 ret = 0;
134 else if (ret)
135 ret = DIV_ROUND_CLOSEST(1350000U, ret);
136abort:
137 mutex_unlock(&data->access_lock);
138 return ret;
139}
140
141static int nct7802_write_fan_min(struct nct7802_data *data, u8 reg_fan_low,
142 u8 reg_fan_high, unsigned int limit)
143{
144 int err;
145
146 if (limit)
147 limit = DIV_ROUND_CLOSEST(1350000U, limit);
148 else
149 limit = 0x1fff;
150 limit = clamp_val(limit, 0, 0x1fff);
151
152 mutex_lock(&data->access_lock);
153 err = regmap_write(data->regmap, reg_fan_low, limit & 0xff);
154 if (err < 0)
155 goto abort;
156
157 err = regmap_write(data->regmap, reg_fan_high, (limit & 0x1f00) >> 5);
158abort:
159 mutex_unlock(&data->access_lock);
160 return err;
161}
162
163static u8 nct7802_vmul[] = { 4, 2, 2, 2, 2 };
164
165static int nct7802_read_voltage(struct nct7802_data *data, int nr, int index)
166{
167 unsigned int v1, v2;
168 int ret;
169
170 mutex_lock(&data->access_lock);
171 if (index == 0) { /* voltage */
172 ret = regmap_read(data->regmap, REG_VOLTAGE[nr], &v1);
173 if (ret < 0)
174 goto abort;
175 ret = regmap_read(data->regmap, REG_VOLTAGE_LOW, &v2);
176 if (ret < 0)
177 goto abort;
178 ret = ((v1 << 2) | (v2 >> 6)) * nct7802_vmul[nr];
179 } else { /* limit */
180 int shift = 8 - REG_VOLTAGE_LIMIT_MSB_SHIFT[index - 1][nr];
181
182 ret = regmap_read(data->regmap,
183 REG_VOLTAGE_LIMIT_LSB[index - 1][nr], &v1);
184 if (ret < 0)
185 goto abort;
186 ret = regmap_read(data->regmap, REG_VOLTAGE_LIMIT_MSB[nr],
187 &v2);
188 if (ret < 0)
189 goto abort;
190 ret = (v1 | ((v2 << shift) & 0x300)) * nct7802_vmul[nr];
191 }
192abort:
193 mutex_unlock(&data->access_lock);
194 return ret;
195}
196
197static int nct7802_write_voltage(struct nct7802_data *data, int nr, int index,
198 unsigned int voltage)
199{
200 int shift = 8 - REG_VOLTAGE_LIMIT_MSB_SHIFT[index - 1][nr];
201 int err;
202
203 voltage = DIV_ROUND_CLOSEST(voltage, nct7802_vmul[nr]);
204 voltage = clamp_val(voltage, 0, 0x3ff);
205
206 mutex_lock(&data->access_lock);
207 err = regmap_write(data->regmap,
208 REG_VOLTAGE_LIMIT_LSB[index - 1][nr],
209 voltage & 0xff);
210 if (err < 0)
211 goto abort;
212
213 err = regmap_update_bits(data->regmap, REG_VOLTAGE_LIMIT_MSB[nr],
214 0x0300 >> shift, (voltage & 0x0300) >> shift);
215abort:
216 mutex_unlock(&data->access_lock);
217 return err;
218}
219
220static ssize_t show_in(struct device *dev, struct device_attribute *attr,
221 char *buf)
222{
223 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
224 struct nct7802_data *data = dev_get_drvdata(dev);
225 int voltage;
226
227 voltage = nct7802_read_voltage(data, sattr->nr, sattr->index);
228 if (voltage < 0)
229 return voltage;
230
231 return sprintf(buf, "%d\n", voltage);
232}
233
234static ssize_t store_in(struct device *dev, struct device_attribute *attr,
235 const char *buf, size_t count)
236{
237 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
238 struct nct7802_data *data = dev_get_drvdata(dev);
239 int index = sattr->index;
240 int nr = sattr->nr;
241 unsigned long val;
242 int err;
243
244 err = kstrtoul(buf, 10, &val);
245 if (err < 0)
246 return err;
247
248 err = nct7802_write_voltage(data, nr, index, val);
249 return err ? : count;
250}
251
252static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
253 char *buf)
254{
255 struct nct7802_data *data = dev_get_drvdata(dev);
256 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
257 int err, temp;
258
259 err = nct7802_read_temp(data, sattr->nr, sattr->index, &temp);
260 if (err < 0)
261 return err;
262
263 return sprintf(buf, "%d\n", temp);
264}
265
266static ssize_t store_temp(struct device *dev, struct device_attribute *attr,
267 const char *buf, size_t count)
268{
269 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
270 struct nct7802_data *data = dev_get_drvdata(dev);
271 int nr = sattr->nr;
272 long val;
273 int err;
274
275 err = kstrtol(buf, 10, &val);
276 if (err < 0)
277 return err;
278
279 val = clamp_val(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
280
281 err = regmap_write(data->regmap, nr, val & 0xff);
282 return err ? : count;
283}
284
285static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
286 char *buf)
287{
288 struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr);
289 struct nct7802_data *data = dev_get_drvdata(dev);
290 int speed;
291
292 speed = nct7802_read_fan(data, sattr->index);
293 if (speed < 0)
294 return speed;
295
296 return sprintf(buf, "%d\n", speed);
297}
298
299static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
300 char *buf)
301{
302 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
303 struct nct7802_data *data = dev_get_drvdata(dev);
304 int speed;
305
306 speed = nct7802_read_fan_min(data, sattr->nr, sattr->index);
307 if (speed < 0)
308 return speed;
309
310 return sprintf(buf, "%d\n", speed);
311}
312
313static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr,
314 const char *buf, size_t count)
315{
316 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
317 struct nct7802_data *data = dev_get_drvdata(dev);
318 unsigned long val;
319 int err;
320
321 err = kstrtoul(buf, 10, &val);
322 if (err < 0)
323 return err;
324
325 err = nct7802_write_fan_min(data, sattr->nr, sattr->index, val);
326 return err ? : count;
327}
328
329static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
330 char *buf)
331{
332 struct nct7802_data *data = dev_get_drvdata(dev);
333 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
334 int bit = sattr->index;
335 unsigned int val;
336 int ret;
337
338 ret = regmap_read(data->regmap, sattr->nr, &val);
339 if (ret < 0)
340 return ret;
341
342 return sprintf(buf, "%u\n", !!(val & (1 << bit)));
343}
344
345static ssize_t
346show_beep(struct device *dev, struct device_attribute *attr, char *buf)
347{
348 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
349 struct nct7802_data *data = dev_get_drvdata(dev);
350 unsigned int regval;
351 int err;
352
353 err = regmap_read(data->regmap, sattr->nr, &regval);
354 if (err)
355 return err;
356
357 return sprintf(buf, "%u\n", !!(regval & (1 << sattr->index)));
358}
359
360static ssize_t
361store_beep(struct device *dev, struct device_attribute *attr, const char *buf,
362 size_t count)
363{
364 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
365 struct nct7802_data *data = dev_get_drvdata(dev);
366 unsigned long val;
367 int err;
368
369 err = kstrtoul(buf, 10, &val);
370 if (err < 0)
371 return err;
372 if (val > 1)
373 return -EINVAL;
374
375 err = regmap_update_bits(data->regmap, sattr->nr, 1 << sattr->index,
376 val ? 1 << sattr->index : 0);
377 return err ? : count;
378}
379
380static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0x01,
381 REG_TEMP_LSB);
382static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp,
383 store_temp, 0x31, 0);
384static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp,
385 store_temp, 0x30, 0);
386static SENSOR_DEVICE_ATTR_2(temp1_crit, S_IRUGO | S_IWUSR, show_temp,
387 store_temp, 0x3a, 0);
388
389static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0x02,
390 REG_TEMP_LSB);
391static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp,
392 store_temp, 0x33, 0);
393static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp,
394 store_temp, 0x32, 0);
395static SENSOR_DEVICE_ATTR_2(temp2_crit, S_IRUGO | S_IWUSR, show_temp,
396 store_temp, 0x3b, 0);
397
398static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0x03,
399 REG_TEMP_LSB);
400static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp,
401 store_temp, 0x35, 0);
402static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp,
403 store_temp, 0x34, 0);
404static SENSOR_DEVICE_ATTR_2(temp3_crit, S_IRUGO | S_IWUSR, show_temp,
405 store_temp, 0x3c, 0);
406
407static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 0x04, 0);
408static SENSOR_DEVICE_ATTR_2(temp4_min, S_IRUGO | S_IWUSR, show_temp,
409 store_temp, 0x37, 0);
410static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp,
411 store_temp, 0x36, 0);
412static SENSOR_DEVICE_ATTR_2(temp4_crit, S_IRUGO | S_IWUSR, show_temp,
413 store_temp, 0x3d, 0);
414
415static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 0x06,
416 REG_TEMP_PECI_LSB);
417static SENSOR_DEVICE_ATTR_2(temp5_min, S_IRUGO | S_IWUSR, show_temp,
418 store_temp, 0x39, 0);
419static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp,
420 store_temp, 0x38, 0);
421static SENSOR_DEVICE_ATTR_2(temp5_crit, S_IRUGO | S_IWUSR, show_temp,
422 store_temp, 0x3e, 0);
423
424static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 0x07,
425 REG_TEMP_PECI_LSB);
426
427static SENSOR_DEVICE_ATTR_2(temp1_min_alarm, S_IRUGO, show_alarm, NULL,
428 0x18, 0);
429static SENSOR_DEVICE_ATTR_2(temp2_min_alarm, S_IRUGO, show_alarm, NULL,
430 0x18, 1);
431static SENSOR_DEVICE_ATTR_2(temp3_min_alarm, S_IRUGO, show_alarm, NULL,
432 0x18, 2);
433static SENSOR_DEVICE_ATTR_2(temp4_min_alarm, S_IRUGO, show_alarm, NULL,
434 0x18, 3);
435static SENSOR_DEVICE_ATTR_2(temp5_min_alarm, S_IRUGO, show_alarm, NULL,
436 0x18, 4);
437
438static SENSOR_DEVICE_ATTR_2(temp1_max_alarm, S_IRUGO, show_alarm, NULL,
439 0x19, 0);
440static SENSOR_DEVICE_ATTR_2(temp2_max_alarm, S_IRUGO, show_alarm, NULL,
441 0x19, 1);
442static SENSOR_DEVICE_ATTR_2(temp3_max_alarm, S_IRUGO, show_alarm, NULL,
443 0x19, 2);
444static SENSOR_DEVICE_ATTR_2(temp4_max_alarm, S_IRUGO, show_alarm, NULL,
445 0x19, 3);
446static SENSOR_DEVICE_ATTR_2(temp5_max_alarm, S_IRUGO, show_alarm, NULL,
447 0x19, 4);
448
449static SENSOR_DEVICE_ATTR_2(temp1_crit_alarm, S_IRUGO, show_alarm, NULL,
450 0x1b, 0);
451static SENSOR_DEVICE_ATTR_2(temp2_crit_alarm, S_IRUGO, show_alarm, NULL,
452 0x1b, 1);
453static SENSOR_DEVICE_ATTR_2(temp3_crit_alarm, S_IRUGO, show_alarm, NULL,
454 0x1b, 2);
455static SENSOR_DEVICE_ATTR_2(temp4_crit_alarm, S_IRUGO, show_alarm, NULL,
456 0x1b, 3);
457static SENSOR_DEVICE_ATTR_2(temp5_crit_alarm, S_IRUGO, show_alarm, NULL,
458 0x1b, 4);
459
460static SENSOR_DEVICE_ATTR_2(temp1_fault, S_IRUGO, show_alarm, NULL, 0x17, 0);
461static SENSOR_DEVICE_ATTR_2(temp2_fault, S_IRUGO, show_alarm, NULL, 0x17, 1);
462static SENSOR_DEVICE_ATTR_2(temp3_fault, S_IRUGO, show_alarm, NULL, 0x17, 2);
463
464static SENSOR_DEVICE_ATTR_2(temp1_beep, S_IRUGO | S_IWUSR, show_beep,
465 store_beep, 0x5c, 0);
466static SENSOR_DEVICE_ATTR_2(temp2_beep, S_IRUGO | S_IWUSR, show_beep,
467 store_beep, 0x5c, 1);
468static SENSOR_DEVICE_ATTR_2(temp3_beep, S_IRUGO | S_IWUSR, show_beep,
469 store_beep, 0x5c, 2);
470static SENSOR_DEVICE_ATTR_2(temp4_beep, S_IRUGO | S_IWUSR, show_beep,
471 store_beep, 0x5c, 3);
472static SENSOR_DEVICE_ATTR_2(temp5_beep, S_IRUGO | S_IWUSR, show_beep,
473 store_beep, 0x5c, 4);
474static SENSOR_DEVICE_ATTR_2(temp6_beep, S_IRUGO | S_IWUSR, show_beep,
475 store_beep, 0x5c, 5);
476
477static struct attribute *nct7802_temp_attrs[] = {
478 &sensor_dev_attr_temp1_input.dev_attr.attr,
479 &sensor_dev_attr_temp1_min.dev_attr.attr,
480 &sensor_dev_attr_temp1_max.dev_attr.attr,
481 &sensor_dev_attr_temp1_crit.dev_attr.attr,
482 &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
483 &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
484 &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
485 &sensor_dev_attr_temp1_fault.dev_attr.attr,
486 &sensor_dev_attr_temp1_beep.dev_attr.attr,
487
488 &sensor_dev_attr_temp2_input.dev_attr.attr, /* 9 */
489 &sensor_dev_attr_temp2_min.dev_attr.attr,
490 &sensor_dev_attr_temp2_max.dev_attr.attr,
491 &sensor_dev_attr_temp2_crit.dev_attr.attr,
492 &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
493 &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
494 &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
495 &sensor_dev_attr_temp2_fault.dev_attr.attr,
496 &sensor_dev_attr_temp2_beep.dev_attr.attr,
497
498 &sensor_dev_attr_temp3_input.dev_attr.attr, /* 18 */
499 &sensor_dev_attr_temp3_min.dev_attr.attr,
500 &sensor_dev_attr_temp3_max.dev_attr.attr,
501 &sensor_dev_attr_temp3_crit.dev_attr.attr,
502 &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
503 &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
504 &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
505 &sensor_dev_attr_temp3_fault.dev_attr.attr,
506 &sensor_dev_attr_temp3_beep.dev_attr.attr,
507
508 &sensor_dev_attr_temp4_input.dev_attr.attr, /* 27 */
509 &sensor_dev_attr_temp4_min.dev_attr.attr,
510 &sensor_dev_attr_temp4_max.dev_attr.attr,
511 &sensor_dev_attr_temp4_crit.dev_attr.attr,
512 &sensor_dev_attr_temp4_min_alarm.dev_attr.attr,
513 &sensor_dev_attr_temp4_max_alarm.dev_attr.attr,
514 &sensor_dev_attr_temp4_crit_alarm.dev_attr.attr,
515 &sensor_dev_attr_temp4_beep.dev_attr.attr,
516
517 &sensor_dev_attr_temp5_input.dev_attr.attr, /* 35 */
518 &sensor_dev_attr_temp5_min.dev_attr.attr,
519 &sensor_dev_attr_temp5_max.dev_attr.attr,
520 &sensor_dev_attr_temp5_crit.dev_attr.attr,
521 &sensor_dev_attr_temp5_min_alarm.dev_attr.attr,
522 &sensor_dev_attr_temp5_max_alarm.dev_attr.attr,
523 &sensor_dev_attr_temp5_crit_alarm.dev_attr.attr,
524 &sensor_dev_attr_temp5_beep.dev_attr.attr,
525
526 &sensor_dev_attr_temp6_input.dev_attr.attr, /* 43 */
527 &sensor_dev_attr_temp6_beep.dev_attr.attr,
528
529 NULL
530};
531
532static umode_t nct7802_temp_is_visible(struct kobject *kobj,
533 struct attribute *attr, int index)
534{
535 struct device *dev = container_of(kobj, struct device, kobj);
536 struct nct7802_data *data = dev_get_drvdata(dev);
537 unsigned int reg;
538 int err;
539
540 err = regmap_read(data->regmap, REG_MODE, &reg);
541 if (err < 0)
542 return 0;
543
544 if (index < 9 &&
545 (reg & 03) != 0x01 && (reg & 0x03) != 0x02) /* RD1 */
546 return 0;
547 if (index >= 9 && index < 18 &&
548 (reg & 0x0c) != 0x04 && (reg & 0x0c) != 0x08) /* RD2 */
549 return 0;
550 if (index >= 18 && index < 27 && (reg & 0x30) != 0x10) /* RD3 */
551 return 0;
552 if (index >= 27 && index < 35) /* local */
553 return attr->mode;
554
555 err = regmap_read(data->regmap, REG_PECI_ENABLE, &reg);
556 if (err < 0)
557 return 0;
558
559 if (index >= 35 && index < 43 && !(reg & 0x01)) /* PECI 0 */
560 return 0;
561
562 if (index >= 0x43 && (!(reg & 0x02))) /* PECI 1 */
563 return 0;
564
565 return attr->mode;
566}
567
568static struct attribute_group nct7802_temp_group = {
569 .attrs = nct7802_temp_attrs,
570 .is_visible = nct7802_temp_is_visible,
571};
572
573static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
574static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, store_in,
575 0, 1);
576static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, store_in,
577 0, 2);
578static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, show_alarm, NULL, 0x1e, 3);
579static SENSOR_DEVICE_ATTR_2(in0_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
580 0x5a, 3);
581
582static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
583
584static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
585static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, store_in,
586 2, 1);
587static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, store_in,
588 2, 2);
589static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, show_alarm, NULL, 0x1e, 0);
590static SENSOR_DEVICE_ATTR_2(in2_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
591 0x5a, 0);
592
593static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
594static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, store_in,
595 3, 1);
596static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, store_in,
597 3, 2);
598static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, show_alarm, NULL, 0x1e, 1);
599static SENSOR_DEVICE_ATTR_2(in3_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
600 0x5a, 1);
601
602static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
603static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, store_in,
604 4, 1);
605static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, store_in,
606 4, 2);
607static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, show_alarm, NULL, 0x1e, 2);
608static SENSOR_DEVICE_ATTR_2(in4_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
609 0x5a, 2);
610
611static struct attribute *nct7802_in_attrs[] = {
612 &sensor_dev_attr_in0_input.dev_attr.attr,
613 &sensor_dev_attr_in0_min.dev_attr.attr,
614 &sensor_dev_attr_in0_max.dev_attr.attr,
615 &sensor_dev_attr_in0_alarm.dev_attr.attr,
616 &sensor_dev_attr_in0_beep.dev_attr.attr,
617
618 &sensor_dev_attr_in1_input.dev_attr.attr, /* 5 */
619
620 &sensor_dev_attr_in2_input.dev_attr.attr, /* 6 */
621 &sensor_dev_attr_in2_min.dev_attr.attr,
622 &sensor_dev_attr_in2_max.dev_attr.attr,
623 &sensor_dev_attr_in2_alarm.dev_attr.attr,
624 &sensor_dev_attr_in2_beep.dev_attr.attr,
625
626 &sensor_dev_attr_in3_input.dev_attr.attr, /* 11 */
627 &sensor_dev_attr_in3_min.dev_attr.attr,
628 &sensor_dev_attr_in3_max.dev_attr.attr,
629 &sensor_dev_attr_in3_alarm.dev_attr.attr,
630 &sensor_dev_attr_in3_beep.dev_attr.attr,
631
632 &sensor_dev_attr_in4_input.dev_attr.attr, /* 17 */
633 &sensor_dev_attr_in4_min.dev_attr.attr,
634 &sensor_dev_attr_in4_max.dev_attr.attr,
635 &sensor_dev_attr_in4_alarm.dev_attr.attr,
636 &sensor_dev_attr_in4_beep.dev_attr.attr,
637
638 NULL,
639};
640
641static umode_t nct7802_in_is_visible(struct kobject *kobj,
642 struct attribute *attr, int index)
643{
644 struct device *dev = container_of(kobj, struct device, kobj);
645 struct nct7802_data *data = dev_get_drvdata(dev);
646 unsigned int reg;
647 int err;
648
649 if (index < 6) /* VCC, VCORE */
650 return attr->mode;
651
652 err = regmap_read(data->regmap, REG_MODE, &reg);
653 if (err < 0)
654 return 0;
655
656 if (index >= 6 && index < 11 && (reg & 0x03) != 0x03) /* VSEN1 */
657 return 0;
658 if (index >= 11 && index < 17 && (reg & 0x0c) != 0x0c) /* VSEN2 */
659 return 0;
660 if (index >= 17 && (reg & 0x30) != 0x30) /* VSEN3 */
661 return 0;
662
663 return attr->mode;
664}
665
666static struct attribute_group nct7802_in_group = {
667 .attrs = nct7802_in_attrs,
668 .is_visible = nct7802_in_is_visible,
669};
670
671static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0x10);
672static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan_min,
673 store_fan_min, 0x49, 0x4c);
674static SENSOR_DEVICE_ATTR_2(fan1_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 0);
675static SENSOR_DEVICE_ATTR_2(fan1_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
676 0x5b, 0);
677static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 0x11);
678static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan_min,
679 store_fan_min, 0x4a, 0x4d);
680static SENSOR_DEVICE_ATTR_2(fan2_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 1);
681static SENSOR_DEVICE_ATTR_2(fan2_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
682 0x5b, 1);
683static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 0x12);
684static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan_min,
685 store_fan_min, 0x4b, 0x4e);
686static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 2);
687static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, store_beep,
688 0x5b, 2);
689
690static struct attribute *nct7802_fan_attrs[] = {
691 &sensor_dev_attr_fan1_input.dev_attr.attr,
692 &sensor_dev_attr_fan1_min.dev_attr.attr,
693 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
694 &sensor_dev_attr_fan1_beep.dev_attr.attr,
695 &sensor_dev_attr_fan2_input.dev_attr.attr,
696 &sensor_dev_attr_fan2_min.dev_attr.attr,
697 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
698 &sensor_dev_attr_fan2_beep.dev_attr.attr,
699 &sensor_dev_attr_fan3_input.dev_attr.attr,
700 &sensor_dev_attr_fan3_min.dev_attr.attr,
701 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
702 &sensor_dev_attr_fan3_beep.dev_attr.attr,
703
704 NULL
705};
706
707static umode_t nct7802_fan_is_visible(struct kobject *kobj,
708 struct attribute *attr, int index)
709{
710 struct device *dev = container_of(kobj, struct device, kobj);
711 struct nct7802_data *data = dev_get_drvdata(dev);
712 int fan = index / 4; /* 4 attributes per fan */
713 unsigned int reg;
714 int err;
715
716 err = regmap_read(data->regmap, REG_FAN_ENABLE, &reg);
717 if (err < 0 || !(reg & (1 << fan)))
718 return 0;
719
720 return attr->mode;
721}
722
723static struct attribute_group nct7802_fan_group = {
724 .attrs = nct7802_fan_attrs,
725 .is_visible = nct7802_fan_is_visible,
726};
727
728static const struct attribute_group *nct7802_groups[] = {
729 &nct7802_temp_group,
730 &nct7802_in_group,
731 &nct7802_fan_group,
732 NULL
733};
734
735static int nct7802_detect(struct i2c_client *client,
736 struct i2c_board_info *info)
737{
738 int reg;
739
740 /*
741 * Chip identification registers are only available in bank 0,
742 * so only attempt chip detection if bank 0 is selected
743 */
744 reg = i2c_smbus_read_byte_data(client, REG_BANK);
745 if (reg != 0x00)
746 return -ENODEV;
747
748 reg = i2c_smbus_read_byte_data(client, REG_VENDOR_ID);
749 if (reg != 0x50)
750 return -ENODEV;
751
752 reg = i2c_smbus_read_byte_data(client, REG_CHIP_ID);
753 if (reg != 0xc3)
754 return -ENODEV;
755
756 reg = i2c_smbus_read_byte_data(client, REG_VERSION_ID);
757 if (reg < 0 || (reg & 0xf0) != 0x20)
758 return -ENODEV;
759
760 /* Also validate lower bits of voltage and temperature registers */
761 reg = i2c_smbus_read_byte_data(client, REG_TEMP_LSB);
762 if (reg < 0 || (reg & 0x1f))
763 return -ENODEV;
764
765 reg = i2c_smbus_read_byte_data(client, REG_TEMP_PECI_LSB);
766 if (reg < 0 || (reg & 0x3f))
767 return -ENODEV;
768
769 reg = i2c_smbus_read_byte_data(client, REG_VOLTAGE_LOW);
770 if (reg < 0 || (reg & 0x3f))
771 return -ENODEV;
772
773 strlcpy(info->type, "nct7802", I2C_NAME_SIZE);
774 return 0;
775}
776
777static bool nct7802_regmap_is_volatile(struct device *dev, unsigned int reg)
778{
779 return reg != REG_BANK && reg <= 0x20;
780}
781
782static struct regmap_config nct7802_regmap_config = {
783 .reg_bits = 8,
784 .val_bits = 8,
785 .cache_type = REGCACHE_RBTREE,
786 .volatile_reg = nct7802_regmap_is_volatile,
787};
788
789static int nct7802_init_chip(struct nct7802_data *data)
790{
791 int err;
792
793 /* Enable ADC */
794 err = regmap_update_bits(data->regmap, REG_START, 0x01, 0x01);
795 if (err)
796 return err;
797
798 /* Enable local temperature sensor */
799 err = regmap_update_bits(data->regmap, REG_MODE, 0x40, 0x40);
800 if (err)
801 return err;
802
803 /* Enable Vcore and VCC voltage monitoring */
804 return regmap_update_bits(data->regmap, REG_VMON_ENABLE, 0x03, 0x03);
805}
806
807static int nct7802_probe(struct i2c_client *client,
808 const struct i2c_device_id *id)
809{
810 struct device *dev = &client->dev;
811 struct nct7802_data *data;
812 struct device *hwmon_dev;
813 int ret;
814
815 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
816 if (data == NULL)
817 return -ENOMEM;
818
819 data->regmap = devm_regmap_init_i2c(client, &nct7802_regmap_config);
820 if (IS_ERR(data->regmap))
821 return PTR_ERR(data->regmap);
822
823 mutex_init(&data->access_lock);
824
825 ret = nct7802_init_chip(data);
826 if (ret < 0)
827 return ret;
828
829 hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
830 data,
831 nct7802_groups);
832 return PTR_ERR_OR_ZERO(hwmon_dev);
833}
834
835static const unsigned short nct7802_address_list[] = {
836 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END
837};
838
839static const struct i2c_device_id nct7802_idtable[] = {
840 { "nct7802", 0 },
841 { }
842};
843MODULE_DEVICE_TABLE(i2c, nct7802_idtable);
844
845static struct i2c_driver nct7802_driver = {
846 .class = I2C_CLASS_HWMON,
847 .driver = {
848 .name = DRVNAME,
849 },
850 .detect = nct7802_detect,
851 .probe = nct7802_probe,
852 .id_table = nct7802_idtable,
853 .address_list = nct7802_address_list,
854};
855
856module_i2c_driver(nct7802_driver);
857
858MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
859MODULE_DESCRIPTION("NCT7802Y Hardware Monitoring Driver");
860MODULE_LICENSE("GPL v2");
diff --git a/drivers/hwmon/pmbus/Kconfig b/drivers/hwmon/pmbus/Kconfig
index 6e1e4935fc62..a674cd83a4e2 100644
--- a/drivers/hwmon/pmbus/Kconfig
+++ b/drivers/hwmon/pmbus/Kconfig
@@ -47,15 +47,22 @@ config SENSORS_LM25066
47 be called lm25066. 47 be called lm25066.
48 48
49config SENSORS_LTC2978 49config SENSORS_LTC2978
50 tristate "Linear Technologies LTC2974, LTC2978, LTC3880, and LTC3883" 50 tristate "Linear Technologies LTC2978 and compatibles"
51 default n 51 default n
52 help 52 help
53 If you say yes here you get hardware monitoring support for Linear 53 If you say yes here you get hardware monitoring support for Linear
54 Technology LTC2974, LTC2978, LTC3880, and LTC3883. 54 Technology LTC2974, LTC2977, LTC2978, LTC3880, LTC3883, and LTM4676.
55 55
56 This driver can also be built as a module. If so, the module will 56 This driver can also be built as a module. If so, the module will
57 be called ltc2978. 57 be called ltc2978.
58 58
59config SENSORS_LTC2978_REGULATOR
60 boolean "Regulator support for LTC2978 and compatibles"
61 depends on SENSORS_LTC2978 && REGULATOR
62 help
63 If you say yes here you get regulator support for Linear
64 Technology LTC2974, LTC2977, LTC2978, LTC3880, LTC3883, and LTM4676.
65
59config SENSORS_MAX16064 66config SENSORS_MAX16064
60 tristate "Maxim MAX16064" 67 tristate "Maxim MAX16064"
61 default n 68 default n
diff --git a/drivers/hwmon/pmbus/ltc2978.c b/drivers/hwmon/pmbus/ltc2978.c
index e24ed521051a..0835050ec245 100644
--- a/drivers/hwmon/pmbus/ltc2978.c
+++ b/drivers/hwmon/pmbus/ltc2978.c
@@ -22,6 +22,7 @@
22#include <linux/err.h> 22#include <linux/err.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/regulator/driver.h>
25#include "pmbus.h" 26#include "pmbus.h"
26 27
27enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883, ltm4676 }; 28enum chips { ltc2974, ltc2977, ltc2978, ltc3880, ltc3883, ltm4676 };
@@ -374,6 +375,19 @@ static const struct i2c_device_id ltc2978_id[] = {
374}; 375};
375MODULE_DEVICE_TABLE(i2c, ltc2978_id); 376MODULE_DEVICE_TABLE(i2c, ltc2978_id);
376 377
378#if IS_ENABLED(CONFIG_SENSORS_LTC2978_REGULATOR)
379static const struct regulator_desc ltc2978_reg_desc[] = {
380 PMBUS_REGULATOR("vout", 0),
381 PMBUS_REGULATOR("vout", 1),
382 PMBUS_REGULATOR("vout", 2),
383 PMBUS_REGULATOR("vout", 3),
384 PMBUS_REGULATOR("vout", 4),
385 PMBUS_REGULATOR("vout", 5),
386 PMBUS_REGULATOR("vout", 6),
387 PMBUS_REGULATOR("vout", 7),
388};
389#endif /* CONFIG_SENSORS_LTC2978_REGULATOR */
390
377static int ltc2978_probe(struct i2c_client *client, 391static int ltc2978_probe(struct i2c_client *client,
378 const struct i2c_device_id *id) 392 const struct i2c_device_id *id)
379{ 393{
@@ -487,13 +501,36 @@ static int ltc2978_probe(struct i2c_client *client,
487 default: 501 default:
488 return -ENODEV; 502 return -ENODEV;
489 } 503 }
504
505#if IS_ENABLED(CONFIG_SENSORS_LTC2978_REGULATOR)
506 info->num_regulators = info->pages;
507 info->reg_desc = ltc2978_reg_desc;
508 if (info->num_regulators > ARRAY_SIZE(ltc2978_reg_desc)) {
509 dev_err(&client->dev, "num_regulators too large!");
510 info->num_regulators = ARRAY_SIZE(ltc2978_reg_desc);
511 }
512#endif
513
490 return pmbus_do_probe(client, id, info); 514 return pmbus_do_probe(client, id, info);
491} 515}
492 516
493/* This is the driver that will be inserted */ 517#ifdef CONFIG_OF
518static const struct of_device_id ltc2978_of_match[] = {
519 { .compatible = "lltc,ltc2974" },
520 { .compatible = "lltc,ltc2977" },
521 { .compatible = "lltc,ltc2978" },
522 { .compatible = "lltc,ltc3880" },
523 { .compatible = "lltc,ltc3883" },
524 { .compatible = "lltc,ltm4676" },
525 { }
526};
527MODULE_DEVICE_TABLE(of, ltc2978_of_match);
528#endif
529
494static struct i2c_driver ltc2978_driver = { 530static struct i2c_driver ltc2978_driver = {
495 .driver = { 531 .driver = {
496 .name = "ltc2978", 532 .name = "ltc2978",
533 .of_match_table = of_match_ptr(ltc2978_of_match),
497 }, 534 },
498 .probe = ltc2978_probe, 535 .probe = ltc2978_probe,
499 .remove = pmbus_do_remove, 536 .remove = pmbus_do_remove,
diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h
index fa9beb3eb60c..89a23ff836e7 100644
--- a/drivers/hwmon/pmbus/pmbus.h
+++ b/drivers/hwmon/pmbus/pmbus.h
@@ -19,6 +19,8 @@
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#include <linux/regulator/driver.h>
23
22#ifndef PMBUS_H 24#ifndef PMBUS_H
23#define PMBUS_H 25#define PMBUS_H
24 26
@@ -186,6 +188,11 @@
186#define PMBUS_VIRT_STATUS_VMON (PMBUS_VIRT_BASE + 35) 188#define PMBUS_VIRT_STATUS_VMON (PMBUS_VIRT_BASE + 35)
187 189
188/* 190/*
191 * OPERATION
192 */
193#define PB_OPERATION_CONTROL_ON (1<<7)
194
195/*
189 * CAPABILITY 196 * CAPABILITY
190 */ 197 */
191#define PB_CAPABILITY_SMBALERT (1<<4) 198#define PB_CAPABILITY_SMBALERT (1<<4)
@@ -365,8 +372,27 @@ struct pmbus_driver_info {
365 */ 372 */
366 int (*identify)(struct i2c_client *client, 373 int (*identify)(struct i2c_client *client,
367 struct pmbus_driver_info *info); 374 struct pmbus_driver_info *info);
375
376 /* Regulator functionality, if supported by this chip driver. */
377 int num_regulators;
378 const struct regulator_desc *reg_desc;
368}; 379};
369 380
381/* Regulator ops */
382
383extern struct regulator_ops pmbus_regulator_ops;
384
385/* Macro for filling in array of struct regulator_desc */
386#define PMBUS_REGULATOR(_name, _id) \
387 [_id] = { \
388 .name = (_name # _id), \
389 .id = (_id), \
390 .of_match = of_match_ptr(_name # _id), \
391 .regulators_node = of_match_ptr("regulators"), \
392 .ops = &pmbus_regulator_ops, \
393 .owner = THIS_MODULE, \
394 }
395
370/* Function declarations */ 396/* Function declarations */
371 397
372void pmbus_clear_cache(struct i2c_client *client); 398void pmbus_clear_cache(struct i2c_client *client);
@@ -375,6 +401,10 @@ int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg);
375int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word); 401int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word);
376int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg); 402int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
377int pmbus_write_byte(struct i2c_client *client, int page, u8 value); 403int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
404int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg,
405 u8 value);
406int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
407 u8 mask, u8 value);
378void pmbus_clear_faults(struct i2c_client *client); 408void pmbus_clear_faults(struct i2c_client *client);
379bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg); 409bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
380bool pmbus_check_word_register(struct i2c_client *client, int page, int reg); 410bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 291d11fe93e7..f2e47c7dd808 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -29,6 +29,8 @@
29#include <linux/hwmon-sysfs.h> 29#include <linux/hwmon-sysfs.h>
30#include <linux/jiffies.h> 30#include <linux/jiffies.h>
31#include <linux/i2c/pmbus.h> 31#include <linux/i2c/pmbus.h>
32#include <linux/regulator/driver.h>
33#include <linux/regulator/machine.h>
32#include "pmbus.h" 34#include "pmbus.h"
33 35
34/* 36/*
@@ -253,6 +255,37 @@ int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg)
253} 255}
254EXPORT_SYMBOL_GPL(pmbus_read_byte_data); 256EXPORT_SYMBOL_GPL(pmbus_read_byte_data);
255 257
258int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg, u8 value)
259{
260 int rv;
261
262 rv = pmbus_set_page(client, page);
263 if (rv < 0)
264 return rv;
265
266 return i2c_smbus_write_byte_data(client, reg, value);
267}
268EXPORT_SYMBOL_GPL(pmbus_write_byte_data);
269
270int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
271 u8 mask, u8 value)
272{
273 unsigned int tmp;
274 int rv;
275
276 rv = pmbus_read_byte_data(client, page, reg);
277 if (rv < 0)
278 return rv;
279
280 tmp = (rv & ~mask) | (value & mask);
281
282 if (tmp != rv)
283 rv = pmbus_write_byte_data(client, page, reg, tmp);
284
285 return rv;
286}
287EXPORT_SYMBOL_GPL(pmbus_update_byte_data);
288
256/* 289/*
257 * _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if 290 * _pmbus_read_byte_data() is similar to pmbus_read_byte_data(), but checks if
258 * a device specific mapping function exists and calls it if necessary. 291 * a device specific mapping function exists and calls it if necessary.
@@ -1727,6 +1760,84 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
1727 return 0; 1760 return 0;
1728} 1761}
1729 1762
1763#if IS_ENABLED(CONFIG_REGULATOR)
1764static int pmbus_regulator_is_enabled(struct regulator_dev *rdev)
1765{
1766 struct device *dev = rdev_get_dev(rdev);
1767 struct i2c_client *client = to_i2c_client(dev->parent);
1768 u8 page = rdev_get_id(rdev);
1769 int ret;
1770
1771 ret = pmbus_read_byte_data(client, page, PMBUS_OPERATION);
1772 if (ret < 0)
1773 return ret;
1774
1775 return !!(ret & PB_OPERATION_CONTROL_ON);
1776}
1777
1778static int _pmbus_regulator_on_off(struct regulator_dev *rdev, bool enable)
1779{
1780 struct device *dev = rdev_get_dev(rdev);
1781 struct i2c_client *client = to_i2c_client(dev->parent);
1782 u8 page = rdev_get_id(rdev);
1783
1784 return pmbus_update_byte_data(client, page, PMBUS_OPERATION,
1785 PB_OPERATION_CONTROL_ON,
1786 enable ? PB_OPERATION_CONTROL_ON : 0);
1787}
1788
1789static int pmbus_regulator_enable(struct regulator_dev *rdev)
1790{
1791 return _pmbus_regulator_on_off(rdev, 1);
1792}
1793
1794static int pmbus_regulator_disable(struct regulator_dev *rdev)
1795{
1796 return _pmbus_regulator_on_off(rdev, 0);
1797}
1798
1799struct regulator_ops pmbus_regulator_ops = {
1800 .enable = pmbus_regulator_enable,
1801 .disable = pmbus_regulator_disable,
1802 .is_enabled = pmbus_regulator_is_enabled,
1803};
1804EXPORT_SYMBOL_GPL(pmbus_regulator_ops);
1805
1806static int pmbus_regulator_register(struct pmbus_data *data)
1807{
1808 struct device *dev = data->dev;
1809 const struct pmbus_driver_info *info = data->info;
1810 const struct pmbus_platform_data *pdata = dev_get_platdata(dev);
1811 struct regulator_dev *rdev;
1812 int i;
1813
1814 for (i = 0; i < info->num_regulators; i++) {
1815 struct regulator_config config = { };
1816
1817 config.dev = dev;
1818 config.driver_data = data;
1819
1820 if (pdata && pdata->reg_init_data)
1821 config.init_data = &pdata->reg_init_data[i];
1822
1823 rdev = devm_regulator_register(dev, &info->reg_desc[i],
1824 &config);
1825 if (IS_ERR(rdev)) {
1826 dev_err(dev, "Failed to register %s regulator\n",
1827 info->reg_desc[i].name);
1828 return PTR_ERR(rdev);
1829 }
1830 }
1831
1832 return 0;
1833}
1834#else
1835static int pmbus_regulator_register(struct pmbus_data *data)
1836{
1837 return 0;
1838}
1839#endif
1840
1730int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id, 1841int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
1731 struct pmbus_driver_info *info) 1842 struct pmbus_driver_info *info)
1732{ 1843{
@@ -1781,8 +1892,15 @@ int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
1781 dev_err(dev, "Failed to register hwmon device\n"); 1892 dev_err(dev, "Failed to register hwmon device\n");
1782 goto out_kfree; 1893 goto out_kfree;
1783 } 1894 }
1895
1896 ret = pmbus_regulator_register(data);
1897 if (ret)
1898 goto out_unregister;
1899
1784 return 0; 1900 return 0;
1785 1901
1902out_unregister:
1903 hwmon_device_unregister(data->hwmon_dev);
1786out_kfree: 1904out_kfree:
1787 kfree(data->group.attrs); 1905 kfree(data->group.attrs);
1788 return ret; 1906 return ret;
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 823c877a1ec0..1991d9032c38 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -161,10 +161,17 @@ static int pwm_fan_suspend(struct device *dev)
161static int pwm_fan_resume(struct device *dev) 161static int pwm_fan_resume(struct device *dev)
162{ 162{
163 struct pwm_fan_ctx *ctx = dev_get_drvdata(dev); 163 struct pwm_fan_ctx *ctx = dev_get_drvdata(dev);
164 unsigned long duty;
165 int ret;
164 166
165 if (ctx->pwm_value) 167 if (ctx->pwm_value == 0)
166 return pwm_enable(ctx->pwm); 168 return 0;
167 return 0; 169
170 duty = DIV_ROUND_UP(ctx->pwm_value * (ctx->pwm->period - 1), MAX_PWM);
171 ret = pwm_config(ctx->pwm, duty, ctx->pwm->period);
172 if (ret)
173 return ret;
174 return pwm_enable(ctx->pwm);
168} 175}
169#endif 176#endif
170 177
diff --git a/drivers/hwmon/tmp401.c b/drivers/hwmon/tmp401.c
index 7fa6e7d0b9b6..99664ebc738d 100644
--- a/drivers/hwmon/tmp401.c
+++ b/drivers/hwmon/tmp401.c
@@ -44,9 +44,10 @@
44#include <linux/sysfs.h> 44#include <linux/sysfs.h>
45 45
46/* Addresses to scan */ 46/* Addresses to scan */
47static const unsigned short normal_i2c[] = { 0x4c, 0x4d, 0x4e, I2C_CLIENT_END }; 47static const unsigned short normal_i2c[] = { 0x37, 0x48, 0x49, 0x4a, 0x4c, 0x4d,
48 0x4e, 0x4f, I2C_CLIENT_END };
48 49
49enum chips { tmp401, tmp411, tmp431, tmp432 }; 50enum chips { tmp401, tmp411, tmp431, tmp432, tmp435 };
50 51
51/* 52/*
52 * The TMP401 registers, note some registers have different addresses for 53 * The TMP401 registers, note some registers have different addresses for
@@ -136,6 +137,7 @@ static const u8 TMP432_STATUS_REG[] = {
136#define TMP411C_DEVICE_ID 0x10 137#define TMP411C_DEVICE_ID 0x10
137#define TMP431_DEVICE_ID 0x31 138#define TMP431_DEVICE_ID 0x31
138#define TMP432_DEVICE_ID 0x32 139#define TMP432_DEVICE_ID 0x32
140#define TMP435_DEVICE_ID 0x35
139 141
140/* 142/*
141 * Driver data (common to all clients) 143 * Driver data (common to all clients)
@@ -146,6 +148,7 @@ static const struct i2c_device_id tmp401_id[] = {
146 { "tmp411", tmp411 }, 148 { "tmp411", tmp411 },
147 { "tmp431", tmp431 }, 149 { "tmp431", tmp431 },
148 { "tmp432", tmp432 }, 150 { "tmp432", tmp432 },
151 { "tmp435", tmp435 },
149 { } 152 { }
150}; 153};
151MODULE_DEVICE_TABLE(i2c, tmp401_id); 154MODULE_DEVICE_TABLE(i2c, tmp401_id);
@@ -613,10 +616,10 @@ static const struct attribute_group tmp432_group = {
613 * Begin non sysfs callback code (aka Real code) 616 * Begin non sysfs callback code (aka Real code)
614 */ 617 */
615 618
616static void tmp401_init_client(struct tmp401_data *data, 619static int tmp401_init_client(struct tmp401_data *data,
617 struct i2c_client *client) 620 struct i2c_client *client)
618{ 621{
619 int config, config_orig; 622 int config, config_orig, status = 0;
620 623
621 /* Set the conversion rate to 2 Hz */ 624 /* Set the conversion rate to 2 Hz */
622 i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5); 625 i2c_smbus_write_byte_data(client, TMP401_CONVERSION_RATE_WRITE, 5);
@@ -624,16 +627,18 @@ static void tmp401_init_client(struct tmp401_data *data,
624 627
625 /* Start conversions (disable shutdown if necessary) */ 628 /* Start conversions (disable shutdown if necessary) */
626 config = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ); 629 config = i2c_smbus_read_byte_data(client, TMP401_CONFIG_READ);
627 if (config < 0) { 630 if (config < 0)
628 dev_warn(&client->dev, "Initialization failed!\n"); 631 return config;
629 return;
630 }
631 632
632 config_orig = config; 633 config_orig = config;
633 config &= ~TMP401_CONFIG_SHUTDOWN; 634 config &= ~TMP401_CONFIG_SHUTDOWN;
634 635
635 if (config != config_orig) 636 if (config != config_orig)
636 i2c_smbus_write_byte_data(client, TMP401_CONFIG_WRITE, config); 637 status = i2c_smbus_write_byte_data(client,
638 TMP401_CONFIG_WRITE,
639 config);
640
641 return status;
637} 642}
638 643
639static int tmp401_detect(struct i2c_client *client, 644static int tmp401_detect(struct i2c_client *client,
@@ -675,15 +680,18 @@ static int tmp401_detect(struct i2c_client *client,
675 kind = tmp411; 680 kind = tmp411;
676 break; 681 break;
677 case TMP431_DEVICE_ID: 682 case TMP431_DEVICE_ID:
678 if (client->addr == 0x4e) 683 if (client->addr != 0x4c && client->addr != 0x4d)
679 return -ENODEV; 684 return -ENODEV;
680 kind = tmp431; 685 kind = tmp431;
681 break; 686 break;
682 case TMP432_DEVICE_ID: 687 case TMP432_DEVICE_ID:
683 if (client->addr == 0x4e) 688 if (client->addr != 0x4c && client->addr != 0x4d)
684 return -ENODEV; 689 return -ENODEV;
685 kind = tmp432; 690 kind = tmp432;
686 break; 691 break;
692 case TMP435_DEVICE_ID:
693 kind = tmp435;
694 break;
687 default: 695 default:
688 return -ENODEV; 696 return -ENODEV;
689 } 697 }
@@ -705,11 +713,13 @@ static int tmp401_detect(struct i2c_client *client,
705static int tmp401_probe(struct i2c_client *client, 713static int tmp401_probe(struct i2c_client *client,
706 const struct i2c_device_id *id) 714 const struct i2c_device_id *id)
707{ 715{
708 const char *names[] = { "TMP401", "TMP411", "TMP431", "TMP432" }; 716 static const char * const names[] = {
717 "TMP401", "TMP411", "TMP431", "TMP432", "TMP435"
718 };
709 struct device *dev = &client->dev; 719 struct device *dev = &client->dev;
710 struct device *hwmon_dev; 720 struct device *hwmon_dev;
711 struct tmp401_data *data; 721 struct tmp401_data *data;
712 int groups = 0; 722 int groups = 0, status;
713 723
714 data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL); 724 data = devm_kzalloc(dev, sizeof(struct tmp401_data), GFP_KERNEL);
715 if (!data) 725 if (!data)
@@ -720,7 +730,9 @@ static int tmp401_probe(struct i2c_client *client,
720 data->kind = id->driver_data; 730 data->kind = id->driver_data;
721 731
722 /* Initialize the TMP401 chip */ 732 /* Initialize the TMP401 chip */
723 tmp401_init_client(data, client); 733 status = tmp401_init_client(data, client);
734 if (status < 0)
735 return status;
724 736
725 /* Register sysfs hooks */ 737 /* Register sysfs hooks */
726 data->groups[groups++] = &tmp401_group; 738 data->groups[groups++] = &tmp401_group;
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 65ef9664d5da..899bede81b31 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -12,11 +12,6 @@
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 MA 02110-1301 USA.
20 * ------------------------------------------------------------------------- */ 15 * ------------------------------------------------------------------------- */
21 16
22/* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki 17/* With some changes from Frodo Looijaard <frodol@dds.nl>, Kyösti Mälkki
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index 8b10f88b13d9..580dbf05c148 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -12,11 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301 USA.
20 */ 15 */
21 16
22#include <linux/kernel.h> 17#include <linux/kernel.h>
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 34370090b753..270d84bfc2c6 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -14,11 +14,6 @@
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 15 * GNU General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301 USA.
21 *
22 * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and 17 * With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
23 * Frodo Looijaard <frodol@dds.nl>, and also from Martin Bailey 18 * Frodo Looijaard <frodol@dds.nl>, and also from Martin Bailey
24 * <mbailey@littlefeet-inc.com> 19 * <mbailey@littlefeet-inc.com>
diff --git a/drivers/i2c/algos/i2c-algo-pcf.h b/drivers/i2c/algos/i2c-algo-pcf.h
index 1ec703ee788d..262ee801975b 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.h
+++ b/drivers/i2c/algos/i2c-algo-pcf.h
@@ -12,12 +12,7 @@
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 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., 51 Franklin Street, Fifth Floor, Boston,
20 MA 02110-1301 USA. */
21/* -------------------------------------------------------------------- */ 16/* -------------------------------------------------------------------- */
22 17
23/* With some changes from Frodo Looijaard <frodol@dds.nl> */ 18/* With some changes from Frodo Looijaard <frodol@dds.nl> */
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 917c3585f45b..b4d135cc2f39 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -881,6 +881,16 @@ config I2C_DIOLAN_U2C
881 This driver can also be built as a module. If so, the module 881 This driver can also be built as a module. If so, the module
882 will be called i2c-diolan-u2c. 882 will be called i2c-diolan-u2c.
883 883
884config I2C_DLN2
885 tristate "Diolan DLN-2 USB I2C adapter"
886 depends on MFD_DLN2
887 help
888 If you say yes to this option, support will be included for Diolan
889 DLN2, a USB to I2C interface.
890
891 This driver can also be built as a module. If so, the module
892 will be called i2c-dln2.
893
884config I2C_PARPORT 894config I2C_PARPORT
885 tristate "Parallel port adapter" 895 tristate "Parallel port adapter"
886 depends on PARPORT 896 depends on PARPORT
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 78d56c54ba2b..cdac7f15eab5 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -87,6 +87,7 @@ obj-$(CONFIG_I2C_RCAR) += i2c-rcar.o
87 87
88# External I2C/SMBus adapter drivers 88# External I2C/SMBus adapter drivers
89obj-$(CONFIG_I2C_DIOLAN_U2C) += i2c-diolan-u2c.o 89obj-$(CONFIG_I2C_DIOLAN_U2C) += i2c-diolan-u2c.o
90obj-$(CONFIG_I2C_DLN2) += i2c-dln2.o
90obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o 91obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
91obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o 92obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
92obj-$(CONFIG_I2C_ROBOTFUZZ_OSIF) += i2c-robotfuzz-osif.o 93obj-$(CONFIG_I2C_ROBOTFUZZ_OSIF) += i2c-robotfuzz-osif.o
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index 451e305f7971..4f2d78868281 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -14,10 +14,6 @@
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/ 17*/
22 18
23/* 19/*
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 2fa21ce9682b..45c5c4883022 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -12,10 +12,6 @@
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 15*/
20 16
21/* 17/*
diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
index 41fc6837fb8b..65e324054970 100644
--- a/drivers/i2c/busses/i2c-amd756-s4882.c
+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 15 */
20 16
21/* 17/*
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index a16f72891358..6c7113d990f8 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -15,10 +15,6 @@
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/ 18*/
23 19
24/* 20/*
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 917d54588d95..e05a672db3e5 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -434,7 +434,7 @@ static int at91_do_twi_transfer(struct at91_twi_dev *dev)
434 } 434 }
435 } 435 }
436 436
437 ret = wait_for_completion_io_timeout(&dev->cmd_complete, 437 ret = wait_for_completion_timeout(&dev->cmd_complete,
438 dev->adapter.timeout); 438 dev->adapter.timeout);
439 if (ret == 0) { 439 if (ret == 0) {
440 dev_err(dev->dev, "controller timed out\n"); 440 dev_err(dev->dev, "controller timed out\n");
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index 8762458ca7da..6f8c0756e350 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -21,10 +21,6 @@
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details. 23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 */ 24 */
29 25
30#include <linux/delay.h> 26#include <linux/delay.h>
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 63f3f03ecc9b..c604f4c3ac0d 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -111,6 +111,8 @@
111#define CDNS_I2C_DIVA_MAX 4 111#define CDNS_I2C_DIVA_MAX 4
112#define CDNS_I2C_DIVB_MAX 64 112#define CDNS_I2C_DIVB_MAX 64
113 113
114#define CDNS_I2C_TIMEOUT_MAX 0xFF
115
114#define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset) 116#define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset)
115#define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset) 117#define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset)
116 118
@@ -852,6 +854,15 @@ static int cdns_i2c_probe(struct platform_device *pdev)
852 goto err_clk_dis; 854 goto err_clk_dis;
853 } 855 }
854 856
857 /*
858 * Cadence I2C controller has a bug wherein it generates
859 * invalid read transaction after HW timeout in master receiver mode.
860 * HW timeout is not used by this driver and the interrupt is disabled.
861 * But the feature itself cannot be disabled. Hence maximum value
862 * is written to this register to reduce the chances of error.
863 */
864 cdns_i2c_writereg(CDNS_I2C_TIMEOUT_MAX, CDNS_I2C_TIME_OUT_OFFSET);
865
855 dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n", 866 dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n",
856 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq); 867 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq);
857 868
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
index f3b89a4698b6..5bdbc71698d0 100644
--- a/drivers/i2c/busses/i2c-cpm.c
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -23,10 +23,6 @@
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details. 25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 */ 26 */
31 27
32#include <linux/kernel.h> 28#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 4d9614719128..01f0cd87a4a5 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -17,10 +17,6 @@
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details. 19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * ---------------------------------------------------------------------------- 20 * ----------------------------------------------------------------------------
25 * 21 *
26 */ 22 */
@@ -411,11 +407,9 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
411 if (dev->cmd_err & DAVINCI_I2C_STR_NACK) { 407 if (dev->cmd_err & DAVINCI_I2C_STR_NACK) {
412 if (msg->flags & I2C_M_IGNORE_NAK) 408 if (msg->flags & I2C_M_IGNORE_NAK)
413 return msg->len; 409 return msg->len;
414 if (stop) { 410 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
415 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); 411 w |= DAVINCI_I2C_MDR_STP;
416 w |= DAVINCI_I2C_MDR_STP; 412 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
417 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
418 }
419 return -EREMOTEIO; 413 return -EREMOTEIO;
420 } 414 }
421 return -EIO; 415 return -EIO;
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index 3c20e4bd6dd1..23628b7bfb8d 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -18,10 +18,6 @@
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details. 20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * ---------------------------------------------------------------------------- 21 * ----------------------------------------------------------------------------
26 * 22 *
27 */ 23 */
@@ -363,7 +359,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
363 } 359 }
364 360
365 /* Configure Tx/Rx FIFO threshold levels */ 361 /* Configure Tx/Rx FIFO threshold levels */
366 dw_writel(dev, dev->tx_fifo_depth - 1, DW_IC_TX_TL); 362 dw_writel(dev, dev->tx_fifo_depth / 2, DW_IC_TX_TL);
367 dw_writel(dev, 0, DW_IC_RX_TL); 363 dw_writel(dev, 0, DW_IC_RX_TL);
368 364
369 /* configure the i2c master */ 365 /* configure the i2c master */
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index d66b6cbc9edc..5a410ef17abd 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -18,10 +18,6 @@
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details. 20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * ---------------------------------------------------------------------------- 21 * ----------------------------------------------------------------------------
26 * 22 *
27 */ 23 */
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index d31d313ab4f7..acb40f95db78 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -19,10 +19,6 @@
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details. 21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * ---------------------------------------------------------------------------- 22 * ----------------------------------------------------------------------------
27 * 23 *
28 */ 24 */
diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c
index a7431150acf7..373dd4d47765 100644
--- a/drivers/i2c/busses/i2c-designware-platdrv.c
+++ b/drivers/i2c/busses/i2c-designware-platdrv.c
@@ -18,10 +18,6 @@
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details. 20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * ---------------------------------------------------------------------------- 21 * ----------------------------------------------------------------------------
26 * 22 *
27 */ 23 */
diff --git a/drivers/i2c/busses/i2c-dln2.c b/drivers/i2c/busses/i2c-dln2.c
new file mode 100644
index 000000000000..b3fb86af4cbb
--- /dev/null
+++ b/drivers/i2c/busses/i2c-dln2.c
@@ -0,0 +1,262 @@
1/*
2 * Driver for the Diolan DLN-2 USB-I2C adapter
3 *
4 * Copyright (c) 2014 Intel Corporation
5 *
6 * Derived from:
7 * i2c-diolan-u2c.c
8 * Copyright (c) 2010-2011 Ericsson AB
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation, version 2.
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/slab.h>
19#include <linux/i2c.h>
20#include <linux/platform_device.h>
21#include <linux/mfd/dln2.h>
22
23#define DLN2_I2C_MODULE_ID 0x03
24#define DLN2_I2C_CMD(cmd) DLN2_CMD(cmd, DLN2_I2C_MODULE_ID)
25
26/* I2C commands */
27#define DLN2_I2C_GET_PORT_COUNT DLN2_I2C_CMD(0x00)
28#define DLN2_I2C_ENABLE DLN2_I2C_CMD(0x01)
29#define DLN2_I2C_DISABLE DLN2_I2C_CMD(0x02)
30#define DLN2_I2C_IS_ENABLED DLN2_I2C_CMD(0x03)
31#define DLN2_I2C_WRITE DLN2_I2C_CMD(0x06)
32#define DLN2_I2C_READ DLN2_I2C_CMD(0x07)
33#define DLN2_I2C_SCAN_DEVICES DLN2_I2C_CMD(0x08)
34#define DLN2_I2C_PULLUP_ENABLE DLN2_I2C_CMD(0x09)
35#define DLN2_I2C_PULLUP_DISABLE DLN2_I2C_CMD(0x0A)
36#define DLN2_I2C_PULLUP_IS_ENABLED DLN2_I2C_CMD(0x0B)
37#define DLN2_I2C_TRANSFER DLN2_I2C_CMD(0x0C)
38#define DLN2_I2C_SET_MAX_REPLY_COUNT DLN2_I2C_CMD(0x0D)
39#define DLN2_I2C_GET_MAX_REPLY_COUNT DLN2_I2C_CMD(0x0E)
40
41#define DLN2_I2C_MAX_XFER_SIZE 256
42#define DLN2_I2C_BUF_SIZE (DLN2_I2C_MAX_XFER_SIZE + 16)
43
44struct dln2_i2c {
45 struct platform_device *pdev;
46 struct i2c_adapter adapter;
47 u8 port;
48 /*
49 * Buffer to hold the packet for read or write transfers. One is enough
50 * since we can't have multiple transfers in parallel on the i2c bus.
51 */
52 void *buf;
53};
54
55static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
56{
57 u16 cmd;
58 struct {
59 u8 port;
60 } tx;
61
62 tx.port = dln2->port;
63
64 if (enable)
65 cmd = DLN2_I2C_ENABLE;
66 else
67 cmd = DLN2_I2C_DISABLE;
68
69 return dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
70}
71
72static int dln2_i2c_write(struct dln2_i2c *dln2, u8 addr,
73 u8 *data, u16 data_len)
74{
75 int ret;
76 struct {
77 u8 port;
78 u8 addr;
79 u8 mem_addr_len;
80 __le32 mem_addr;
81 __le16 buf_len;
82 u8 buf[DLN2_I2C_MAX_XFER_SIZE];
83 } __packed *tx = dln2->buf;
84 unsigned len;
85
86 BUILD_BUG_ON(sizeof(*tx) > DLN2_I2C_BUF_SIZE);
87
88 tx->port = dln2->port;
89 tx->addr = addr;
90 tx->mem_addr_len = 0;
91 tx->mem_addr = 0;
92 tx->buf_len = cpu_to_le16(data_len);
93 memcpy(tx->buf, data, data_len);
94
95 len = sizeof(*tx) + data_len - DLN2_I2C_MAX_XFER_SIZE;
96 ret = dln2_transfer_tx(dln2->pdev, DLN2_I2C_WRITE, tx, len);
97 if (ret < 0)
98 return ret;
99
100 return data_len;
101}
102
103static int dln2_i2c_read(struct dln2_i2c *dln2, u16 addr, u8 *data,
104 u16 data_len)
105{
106 int ret;
107 struct {
108 u8 port;
109 u8 addr;
110 u8 mem_addr_len;
111 __le32 mem_addr;
112 __le16 buf_len;
113 } __packed tx;
114 struct {
115 __le16 buf_len;
116 u8 buf[DLN2_I2C_MAX_XFER_SIZE];
117 } __packed *rx = dln2->buf;
118 unsigned rx_len = sizeof(*rx);
119
120 BUILD_BUG_ON(sizeof(*rx) > DLN2_I2C_BUF_SIZE);
121
122 tx.port = dln2->port;
123 tx.addr = addr;
124 tx.mem_addr_len = 0;
125 tx.mem_addr = 0;
126 tx.buf_len = cpu_to_le16(data_len);
127
128 ret = dln2_transfer(dln2->pdev, DLN2_I2C_READ, &tx, sizeof(tx),
129 rx, &rx_len);
130 if (ret < 0)
131 return ret;
132 if (rx_len < sizeof(rx->buf_len) + data_len)
133 return -EPROTO;
134 if (le16_to_cpu(rx->buf_len) != data_len)
135 return -EPROTO;
136
137 memcpy(data, rx->buf, data_len);
138
139 return data_len;
140}
141
142static int dln2_i2c_xfer(struct i2c_adapter *adapter,
143 struct i2c_msg *msgs, int num)
144{
145 struct dln2_i2c *dln2 = i2c_get_adapdata(adapter);
146 struct i2c_msg *pmsg;
147 struct device *dev = &dln2->adapter.dev;
148 int i;
149
150 for (i = 0; i < num; i++) {
151 int ret;
152
153 pmsg = &msgs[i];
154
155 if (pmsg->len > DLN2_I2C_MAX_XFER_SIZE) {
156 dev_warn(dev, "maximum transfer size exceeded\n");
157 return -EOPNOTSUPP;
158 }
159
160 if (pmsg->flags & I2C_M_RD) {
161 ret = dln2_i2c_read(dln2, pmsg->addr, pmsg->buf,
162 pmsg->len);
163 if (ret < 0)
164 return ret;
165
166 pmsg->len = ret;
167 } else {
168 ret = dln2_i2c_write(dln2, pmsg->addr, pmsg->buf,
169 pmsg->len);
170 if (ret != pmsg->len)
171 return -EPROTO;
172 }
173 }
174
175 return num;
176}
177
178static u32 dln2_i2c_func(struct i2c_adapter *a)
179{
180 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA |
181 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
182 I2C_FUNC_SMBUS_I2C_BLOCK;
183}
184
185static const struct i2c_algorithm dln2_i2c_usb_algorithm = {
186 .master_xfer = dln2_i2c_xfer,
187 .functionality = dln2_i2c_func,
188};
189
190static int dln2_i2c_probe(struct platform_device *pdev)
191{
192 int ret;
193 struct dln2_i2c *dln2;
194 struct device *dev = &pdev->dev;
195 struct dln2_platform_data *pdata = dev_get_platdata(&pdev->dev);
196
197 dln2 = devm_kzalloc(dev, sizeof(*dln2), GFP_KERNEL);
198 if (!dln2)
199 return -ENOMEM;
200
201 dln2->buf = devm_kmalloc(dev, DLN2_I2C_BUF_SIZE, GFP_KERNEL);
202 if (!dln2->buf)
203 return -ENOMEM;
204
205 dln2->pdev = pdev;
206 dln2->port = pdata->port;
207
208 /* setup i2c adapter description */
209 dln2->adapter.owner = THIS_MODULE;
210 dln2->adapter.class = I2C_CLASS_HWMON;
211 dln2->adapter.algo = &dln2_i2c_usb_algorithm;
212 dln2->adapter.dev.parent = dev;
213 i2c_set_adapdata(&dln2->adapter, dln2);
214 snprintf(dln2->adapter.name, sizeof(dln2->adapter.name), "%s-%s-%d",
215 "dln2-i2c", dev_name(pdev->dev.parent), dln2->port);
216
217 platform_set_drvdata(pdev, dln2);
218
219 /* initialize the i2c interface */
220 ret = dln2_i2c_enable(dln2, true);
221 if (ret < 0) {
222 dev_err(dev, "failed to initialize adapter: %d\n", ret);
223 return ret;
224 }
225
226 /* and finally attach to i2c layer */
227 ret = i2c_add_adapter(&dln2->adapter);
228 if (ret < 0) {
229 dev_err(dev, "failed to add I2C adapter: %d\n", ret);
230 goto out_disable;
231 }
232
233 return 0;
234
235out_disable:
236 dln2_i2c_enable(dln2, false);
237
238 return ret;
239}
240
241static int dln2_i2c_remove(struct platform_device *pdev)
242{
243 struct dln2_i2c *dln2 = platform_get_drvdata(pdev);
244
245 i2c_del_adapter(&dln2->adapter);
246 dln2_i2c_enable(dln2, false);
247
248 return 0;
249}
250
251static struct platform_driver dln2_i2c_driver = {
252 .driver.name = "dln2-i2c",
253 .probe = dln2_i2c_probe,
254 .remove = dln2_i2c_remove,
255};
256
257module_platform_driver(dln2_i2c_driver);
258
259MODULE_AUTHOR("Laurentiu Palcu <laurentiu.palcu@intel.com>");
260MODULE_DESCRIPTION("Driver for the Diolan DLN2 I2C master interface");
261MODULE_LICENSE("GPL v2");
262MODULE_ALIAS("platform:dln2-i2c");
diff --git a/drivers/i2c/busses/i2c-eg20t.c b/drivers/i2c/busses/i2c-eg20t.c
index a44ea13d1434..76e699f9ed97 100644
--- a/drivers/i2c/busses/i2c-eg20t.c
+++ b/drivers/i2c/busses/i2c-eg20t.c
@@ -9,10 +9,6 @@
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details. 11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */ 12 */
17 13
18#include <linux/module.h> 14#include <linux/module.h>
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 485497066ed7..92e8c0ce1625 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -12,11 +12,7 @@
12 This program is distributed in the hope that it will be useful, 12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
20/* ------------------------------------------------------------------------- */ 16/* ------------------------------------------------------------------------- */
21 17
22/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even 18/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index 14d2b76de25f..b7864cf42a72 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -15,10 +15,6 @@
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/ 18*/
23 19
24#include <linux/kernel.h> 20#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 7cfc183b3d63..6ab4f1cb21f3 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -15,10 +15,6 @@
15 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details. 17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22*/ 18*/
23 19
24/* 20/*
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index c48e46af670a..e9fb7cf78612 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -11,11 +11,6 @@
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 *
19 * Author: 14 * Author:
20 * Darius Augulis, Teltonika Inc. 15 * Darius Augulis, Teltonika Inc.
21 * 16 *
diff --git a/drivers/i2c/busses/i2c-iop3xx.h b/drivers/i2c/busses/i2c-iop3xx.h
index 097e270955d0..2d6929c2bd92 100644
--- a/drivers/i2c/busses/i2c-iop3xx.h
+++ b/drivers/i2c/busses/i2c-iop3xx.h
@@ -11,11 +11,7 @@
11 This program is distributed in the hope that it will be useful, 11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details. */
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19/* ------------------------------------------------------------------------- */ 15/* ------------------------------------------------------------------------- */
20 16
21 17
diff --git a/drivers/i2c/busses/i2c-isch.c b/drivers/i2c/busses/i2c-isch.c
index cf99dbf21fd1..113293d275f6 100644
--- a/drivers/i2c/busses/i2c-isch.c
+++ b/drivers/i2c/busses/i2c-isch.c
@@ -14,10 +14,6 @@
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/ 17*/
22 18
23/* 19/*
diff --git a/drivers/i2c/busses/i2c-ismt.c b/drivers/i2c/busses/i2c-ismt.c
index 3f6ecbfb9a56..f2b0ff011631 100644
--- a/drivers/i2c/busses/i2c-ismt.c
+++ b/drivers/i2c/busses/i2c-ismt.c
@@ -14,10 +14,6 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution 17 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL. 18 * in the file called LICENSE.GPL.
23 * 19 *
diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
index b170bdffb5de..88eda09e73c0 100644
--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 15 */
20 16
21/* 17/*
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index ee3a76c7ae97..70b3c9158509 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -17,10 +17,6 @@
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details. 19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/ 20*/
25 21
26/* 22/*
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 0dffb0e62c3b..277a2288d4a8 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -22,10 +22,6 @@
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details. 24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 */ 25 */
30 26
31#include <linux/module.h> 27#include <linux/module.h>
@@ -926,14 +922,12 @@ omap_i2c_isr_thread(int this_irq, void *dev_id)
926 if (stat & OMAP_I2C_STAT_NACK) { 922 if (stat & OMAP_I2C_STAT_NACK) {
927 err |= OMAP_I2C_STAT_NACK; 923 err |= OMAP_I2C_STAT_NACK;
928 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_NACK); 924 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_NACK);
929 break;
930 } 925 }
931 926
932 if (stat & OMAP_I2C_STAT_AL) { 927 if (stat & OMAP_I2C_STAT_AL) {
933 dev_err(dev->dev, "Arbitration lost\n"); 928 dev_err(dev->dev, "Arbitration lost\n");
934 err |= OMAP_I2C_STAT_AL; 929 err |= OMAP_I2C_STAT_AL;
935 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_AL); 930 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_AL);
936 break;
937 } 931 }
938 932
939 /* 933 /*
@@ -958,11 +952,13 @@ omap_i2c_isr_thread(int this_irq, void *dev_id)
958 if (dev->fifo_size) 952 if (dev->fifo_size)
959 num_bytes = dev->buf_len; 953 num_bytes = dev->buf_len;
960 954
961 omap_i2c_receive_data(dev, num_bytes, true); 955 if (dev->errata & I2C_OMAP_ERRATA_I207) {
962
963 if (dev->errata & I2C_OMAP_ERRATA_I207)
964 i2c_omap_errata_i207(dev, stat); 956 i2c_omap_errata_i207(dev, stat);
957 num_bytes = (omap_i2c_read_reg(dev,
958 OMAP_I2C_BUFSTAT_REG) >> 8) & 0x3F;
959 }
965 960
961 omap_i2c_receive_data(dev, num_bytes, true);
966 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR); 962 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR);
967 continue; 963 continue;
968 } 964 }
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index 62f55fe624cb..d1f625f923c7 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -18,10 +18,6 @@
18 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details. 20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * ------------------------------------------------------------------------ */ 21 * ------------------------------------------------------------------------ */
26 22
27#include <linux/kernel.h> 23#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index a27aae2d6757..a1fac5aa9bae 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -18,10 +18,6 @@
18 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details. 20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * ------------------------------------------------------------------------ */ 21 * ------------------------------------------------------------------------ */
26 22
27#include <linux/kernel.h> 23#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-parport.h b/drivers/i2c/busses/i2c-parport.h
index e572f3aac0f7..4e1294536805 100644
--- a/drivers/i2c/busses/i2c-parport.h
+++ b/drivers/i2c/busses/i2c-parport.h
@@ -12,10 +12,6 @@
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * ------------------------------------------------------------------------ */ 15 * ------------------------------------------------------------------------ */
20 16
21#define PORT_DATA 0 17#define PORT_DATA 0
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index 7a9dce43e115..df1dbc92a024 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -11,10 +11,6 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 14 */
19 15
20#include <linux/module.h> 16#include <linux/module.h>
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index 323f061a3163..e0eb4ca0102e 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 15 */
20 16
21#include <linux/kernel.h> 17#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index a6f54ba27e2a..67cbec6796a0 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -11,10 +11,6 @@
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 14*/
19 15
20/* 16/*
diff --git a/drivers/i2c/busses/i2c-pmcmsp.c b/drivers/i2c/busses/i2c-pmcmsp.c
index 8564768fee32..177834e2d841 100644
--- a/drivers/i2c/busses/i2c-pmcmsp.c
+++ b/drivers/i2c/busses/i2c-pmcmsp.c
@@ -18,10 +18,6 @@
18 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 18 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 19 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
20 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 20 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 675 Mass Ave, Cambridge, MA 02139, USA.
25 */ 21 */
26 22
27#include <linux/kernel.h> 23#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 01e967763c2a..60a53c169ed2 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -14,10 +14,6 @@
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 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., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21*/ 17*/
22 18
23#include <linux/module.h> 19#include <linux/module.h>
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index e3b0337faeb7..65244774bfa3 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -14,10 +14,6 @@
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/ 17*/
22 18
23#include <linux/kernel.h> 19#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 8b5e79cb4468..4855188747c9 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -14,10 +14,6 @@
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */ 17 */
22 18
23#include <linux/kernel.h> 19#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-sibyte.c b/drivers/i2c/busses/i2c-sibyte.c
index 0fe505d7abe9..2b6219d86b0f 100644
--- a/drivers/i2c/busses/i2c-sibyte.c
+++ b/drivers/i2c/busses/i2c-sibyte.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */ 15 */
20 16
21#include <linux/kernel.h> 17#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-simtec.c b/drivers/i2c/busses/i2c-simtec.c
index 964e5c6f84ab..15ac8395dcd3 100644
--- a/drivers/i2c/busses/i2c-simtec.c
+++ b/drivers/i2c/busses/i2c-simtec.c
@@ -12,10 +12,6 @@
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/ 15*/
20 16
21#include <linux/kernel.h> 17#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index ac9bc33acef4..7d58a40faf2d 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -11,10 +11,6 @@
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/ 14*/
19 15
20/* Note: we assume there can only be one SIS5595 with one SMBus interface */ 16/* Note: we assume there can only be one SIS5595 with one SMBus interface */
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index c6366733008d..1e6805b5cef2 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -10,10 +10,6 @@
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*/ 13*/
18 14
19/* 15/*
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 8dc2fc5f74ff..44b904426073 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -10,10 +10,6 @@
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*/ 13*/
18 14
19/* 15/*
diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
index 10855a0b7e7f..4c7fc2d47014 100644
--- a/drivers/i2c/busses/i2c-taos-evm.c
+++ b/drivers/i2c/busses/i2c-taos-evm.c
@@ -13,10 +13,6 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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 */ 16 */
21 17
22#include <linux/delay.h> 18#include <linux/delay.h>
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index f4a1ed757612..59b1d233ca7b 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -12,10 +12,6 @@
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 15*/
20 16
21#include <linux/kernel.h> 17#include <linux/kernel.h>
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 6841200b6e50..0ee2646f3b00 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -13,10 +13,6 @@
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 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., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 16*/
21 17
22/* 18/*
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index ade9223912d3..cc65ea0b818f 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -12,10 +12,6 @@
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * 15 *
20 * This code was implemented by Mocean Laboratories AB when porting linux 16 * This code was implemented by Mocean Laboratories AB when porting linux
21 * to the automotive development board Russellville. The copyright holder 17 * to the automotive development board Russellville. The copyright holder
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index ff3f5747e43b..5153354b1a6b 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -17,10 +17,6 @@
17 but WITHOUT ANY WARRANTY; without even the implied warranty of 17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details. 19 General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24*/ 20*/
25 21
26#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
diff --git a/drivers/i2c/i2c-boardinfo.c b/drivers/i2c/i2c-boardinfo.c
index f24cc64e2e8c..90e322959303 100644
--- a/drivers/i2c/i2c-boardinfo.c
+++ b/drivers/i2c/i2c-boardinfo.c
@@ -10,11 +10,6 @@
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA.
18 */ 13 */
19 14
20#include <linux/kernel.h> 15#include <linux/kernel.h>
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 2f90ac6a7f79..f43b4e11647a 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -10,12 +10,7 @@
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details. */
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 MA 02110-1301 USA. */
19/* ------------------------------------------------------------------------- */ 14/* ------------------------------------------------------------------------- */
20 15
21/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. 16/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
@@ -670,6 +665,9 @@ static int i2c_device_remove(struct device *dev)
670 status = driver->remove(client); 665 status = driver->remove(client);
671 } 666 }
672 667
668 if (dev->of_node)
669 irq_dispose_mapping(client->irq);
670
673 dev_pm_domain_detach(&client->dev, true); 671 dev_pm_domain_detach(&client->dev, true);
674 return status; 672 return status;
675} 673}
diff --git a/drivers/i2c/i2c-core.h b/drivers/i2c/i2c-core.h
index 18a8fd21d2c2..17700bfddcf5 100644
--- a/drivers/i2c/i2c-core.h
+++ b/drivers/i2c/i2c-core.h
@@ -10,11 +10,6 @@
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA.
18 */ 13 */
19 14
20#include <linux/rwsem.h> 15#include <linux/rwsem.h>
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 80b47e8ce030..71c7a3975b62 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -14,11 +14,6 @@
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 MA 02110-1301 USA.
22*/ 17*/
23 18
24/* Note that this is a complete rewrite of Simon Vogl's i2c-dev module. 19/* Note that this is a complete rewrite of Simon Vogl's i2c-dev module.
diff --git a/drivers/i2c/i2c-smbus.c b/drivers/i2c/i2c-smbus.c
index fc99f0d6b4a5..9ebf9cb4ad7a 100644
--- a/drivers/i2c/i2c-smbus.c
+++ b/drivers/i2c/i2c-smbus.c
@@ -13,11 +13,6 @@
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details. 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., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301 USA.
21 */ 16 */
22 17
23#include <linux/kernel.h> 18#include <linux/kernel.h>
diff --git a/drivers/i2c/i2c-stub.c b/drivers/i2c/i2c-stub.c
index d241aa295d96..af2a94e1140b 100644
--- a/drivers/i2c/i2c-stub.c
+++ b/drivers/i2c/i2c-stub.c
@@ -13,10 +13,6 @@
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 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., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 16*/
21 17
22#define DEBUG 1 18#define DEBUG 1
diff --git a/drivers/iio/accel/bmc150-accel.c b/drivers/iio/accel/bmc150-accel.c
index 22c096ce39ad..513bd6d14293 100644
--- a/drivers/iio/accel/bmc150-accel.c
+++ b/drivers/iio/accel/bmc150-accel.c
@@ -44,6 +44,9 @@
44 44
45#define BMC150_ACCEL_REG_INT_STATUS_2 0x0B 45#define BMC150_ACCEL_REG_INT_STATUS_2 0x0B
46#define BMC150_ACCEL_ANY_MOTION_MASK 0x07 46#define BMC150_ACCEL_ANY_MOTION_MASK 0x07
47#define BMC150_ACCEL_ANY_MOTION_BIT_X BIT(0)
48#define BMC150_ACCEL_ANY_MOTION_BIT_Y BIT(1)
49#define BMC150_ACCEL_ANY_MOTION_BIT_Z BIT(2)
47#define BMC150_ACCEL_ANY_MOTION_BIT_SIGN BIT(3) 50#define BMC150_ACCEL_ANY_MOTION_BIT_SIGN BIT(3)
48 51
49#define BMC150_ACCEL_REG_PMU_LPW 0x11 52#define BMC150_ACCEL_REG_PMU_LPW 0x11
@@ -92,9 +95,9 @@
92#define BMC150_ACCEL_SLOPE_THRES_MASK 0xFF 95#define BMC150_ACCEL_SLOPE_THRES_MASK 0xFF
93 96
94/* Slope duration in terms of number of samples */ 97/* Slope duration in terms of number of samples */
95#define BMC150_ACCEL_DEF_SLOPE_DURATION 2 98#define BMC150_ACCEL_DEF_SLOPE_DURATION 1
96/* in terms of multiples of g's/LSB, based on range */ 99/* in terms of multiples of g's/LSB, based on range */
97#define BMC150_ACCEL_DEF_SLOPE_THRESHOLD 5 100#define BMC150_ACCEL_DEF_SLOPE_THRESHOLD 1
98 101
99#define BMC150_ACCEL_REG_XOUT_L 0x02 102#define BMC150_ACCEL_REG_XOUT_L 0x02
100 103
@@ -536,6 +539,9 @@ static int bmc150_accel_set_power_state(struct bmc150_accel_data *data, bool on)
536 if (ret < 0) { 539 if (ret < 0) {
537 dev_err(&data->client->dev, 540 dev_err(&data->client->dev,
538 "Failed: bmc150_accel_set_power_state for %d\n", on); 541 "Failed: bmc150_accel_set_power_state for %d\n", on);
542 if (on)
543 pm_runtime_put_noidle(&data->client->dev);
544
539 return ret; 545 return ret;
540 } 546 }
541 547
@@ -811,6 +817,7 @@ static int bmc150_accel_write_event_config(struct iio_dev *indio_dev,
811 817
812 ret = bmc150_accel_setup_any_motion_interrupt(data, state); 818 ret = bmc150_accel_setup_any_motion_interrupt(data, state);
813 if (ret < 0) { 819 if (ret < 0) {
820 bmc150_accel_set_power_state(data, false);
814 mutex_unlock(&data->mutex); 821 mutex_unlock(&data->mutex);
815 return ret; 822 return ret;
816 } 823 }
@@ -846,7 +853,7 @@ static const struct attribute_group bmc150_accel_attrs_group = {
846 853
847static const struct iio_event_spec bmc150_accel_event = { 854static const struct iio_event_spec bmc150_accel_event = {
848 .type = IIO_EV_TYPE_ROC, 855 .type = IIO_EV_TYPE_ROC,
849 .dir = IIO_EV_DIR_RISING | IIO_EV_DIR_FALLING, 856 .dir = IIO_EV_DIR_EITHER,
850 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 857 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
851 BIT(IIO_EV_INFO_ENABLE) | 858 BIT(IIO_EV_INFO_ENABLE) |
852 BIT(IIO_EV_INFO_PERIOD) 859 BIT(IIO_EV_INFO_PERIOD)
@@ -1054,6 +1061,7 @@ static int bmc150_accel_data_rdy_trigger_set_state(struct iio_trigger *trig,
1054 else 1061 else
1055 ret = bmc150_accel_setup_new_data_interrupt(data, state); 1062 ret = bmc150_accel_setup_new_data_interrupt(data, state);
1056 if (ret < 0) { 1063 if (ret < 0) {
1064 bmc150_accel_set_power_state(data, false);
1057 mutex_unlock(&data->mutex); 1065 mutex_unlock(&data->mutex);
1058 return ret; 1066 return ret;
1059 } 1067 }
@@ -1092,12 +1100,26 @@ static irqreturn_t bmc150_accel_event_handler(int irq, void *private)
1092 else 1100 else
1093 dir = IIO_EV_DIR_RISING; 1101 dir = IIO_EV_DIR_RISING;
1094 1102
1095 if (ret & BMC150_ACCEL_ANY_MOTION_MASK) 1103 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_X)
1104 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
1105 0,
1106 IIO_MOD_X,
1107 IIO_EV_TYPE_ROC,
1108 dir),
1109 data->timestamp);
1110 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Y)
1096 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL, 1111 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
1097 0, 1112 0,
1098 IIO_MOD_X_OR_Y_OR_Z, 1113 IIO_MOD_Y,
1099 IIO_EV_TYPE_ROC, 1114 IIO_EV_TYPE_ROC,
1100 IIO_EV_DIR_EITHER), 1115 dir),
1116 data->timestamp);
1117 if (ret & BMC150_ACCEL_ANY_MOTION_BIT_Z)
1118 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ACCEL,
1119 0,
1120 IIO_MOD_Z,
1121 IIO_EV_TYPE_ROC,
1122 dir),
1101 data->timestamp); 1123 data->timestamp);
1102ack_intr_status: 1124ack_intr_status:
1103 if (!data->dready_trigger_on) 1125 if (!data->dready_trigger_on)
@@ -1354,10 +1376,14 @@ static int bmc150_accel_runtime_suspend(struct device *dev)
1354{ 1376{
1355 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 1377 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
1356 struct bmc150_accel_data *data = iio_priv(indio_dev); 1378 struct bmc150_accel_data *data = iio_priv(indio_dev);
1379 int ret;
1357 1380
1358 dev_dbg(&data->client->dev, __func__); 1381 dev_dbg(&data->client->dev, __func__);
1382 ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_SUSPEND, 0);
1383 if (ret < 0)
1384 return -EAGAIN;
1359 1385
1360 return bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_SUSPEND, 0); 1386 return 0;
1361} 1387}
1362 1388
1363static int bmc150_accel_runtime_resume(struct device *dev) 1389static int bmc150_accel_runtime_resume(struct device *dev)
diff --git a/drivers/iio/accel/kxcjk-1013.c b/drivers/iio/accel/kxcjk-1013.c
index 98909a9e284e..320aa72c0349 100644
--- a/drivers/iio/accel/kxcjk-1013.c
+++ b/drivers/iio/accel/kxcjk-1013.c
@@ -269,6 +269,8 @@ static int kxcjk1013_set_range(struct kxcjk1013_data *data, int range_index)
269 return ret; 269 return ret;
270 } 270 }
271 271
272 ret &= ~(KXCJK1013_REG_CTRL1_BIT_GSEL0 |
273 KXCJK1013_REG_CTRL1_BIT_GSEL1);
272 ret |= (KXCJK1013_scale_table[range_index].gsel_0 << 3); 274 ret |= (KXCJK1013_scale_table[range_index].gsel_0 << 3);
273 ret |= (KXCJK1013_scale_table[range_index].gsel_1 << 4); 275 ret |= (KXCJK1013_scale_table[range_index].gsel_1 << 4);
274 276
@@ -894,7 +896,7 @@ static const struct attribute_group kxcjk1013_attrs_group = {
894 896
895static const struct iio_event_spec kxcjk1013_event = { 897static const struct iio_event_spec kxcjk1013_event = {
896 .type = IIO_EV_TYPE_THRESH, 898 .type = IIO_EV_TYPE_THRESH,
897 .dir = IIO_EV_DIR_RISING | IIO_EV_DIR_FALLING, 899 .dir = IIO_EV_DIR_EITHER,
898 .mask_separate = BIT(IIO_EV_INFO_VALUE) | 900 .mask_separate = BIT(IIO_EV_INFO_VALUE) |
899 BIT(IIO_EV_INFO_ENABLE) | 901 BIT(IIO_EV_INFO_ENABLE) |
900 BIT(IIO_EV_INFO_PERIOD) 902 BIT(IIO_EV_INFO_PERIOD)
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 88bdc8f612e2..bc4e787096e8 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -127,6 +127,14 @@ config AT91_ADC
127 help 127 help
128 Say yes here to build support for Atmel AT91 ADC. 128 Say yes here to build support for Atmel AT91 ADC.
129 129
130config AXP288_ADC
131 tristate "X-Powers AXP288 ADC driver"
132 depends on MFD_AXP20X
133 help
134 Say yes here to have support for X-Powers power management IC (PMIC) ADC
135 device. Depending on platform configuration, this general purpose ADC can
136 be used for sampling sensors such as thermal resistors.
137
130config EXYNOS_ADC 138config EXYNOS_ADC
131 tristate "Exynos ADC driver support" 139 tristate "Exynos ADC driver support"
132 depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || (OF && COMPILE_TEST) 140 depends on ARCH_EXYNOS || ARCH_S3C24XX || ARCH_S3C64XX || (OF && COMPILE_TEST)
diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile
index cb88a6a23b8f..f30093f5b67a 100644
--- a/drivers/iio/adc/Makefile
+++ b/drivers/iio/adc/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_AD7793) += ad7793.o
14obj-$(CONFIG_AD7887) += ad7887.o 14obj-$(CONFIG_AD7887) += ad7887.o
15obj-$(CONFIG_AD799X) += ad799x.o 15obj-$(CONFIG_AD799X) += ad799x.o
16obj-$(CONFIG_AT91_ADC) += at91_adc.o 16obj-$(CONFIG_AT91_ADC) += at91_adc.o
17obj-$(CONFIG_AXP288_ADC) += axp288_adc.o
17obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o 18obj-$(CONFIG_EXYNOS_ADC) += exynos_adc.o
18obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o 19obj-$(CONFIG_LP8788_ADC) += lp8788_adc.o
19obj-$(CONFIG_MAX1027) += max1027.o 20obj-$(CONFIG_MAX1027) += max1027.o
diff --git a/drivers/iio/adc/axp288_adc.c b/drivers/iio/adc/axp288_adc.c
new file mode 100644
index 000000000000..08bcfb061ca5
--- /dev/null
+++ b/drivers/iio/adc/axp288_adc.c
@@ -0,0 +1,261 @@
1/*
2 * axp288_adc.c - X-Powers AXP288 PMIC ADC Driver
3 *
4 * Copyright (C) 2014 Intel Corporation
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 */
18
19#include <linux/module.h>
20#include <linux/kernel.h>
21#include <linux/device.h>
22#include <linux/regmap.h>
23#include <linux/mfd/axp20x.h>
24#include <linux/platform_device.h>
25
26#include <linux/iio/iio.h>
27#include <linux/iio/machine.h>
28#include <linux/iio/driver.h>
29
30#define AXP288_ADC_EN_MASK 0xF1
31#define AXP288_ADC_TS_PIN_GPADC 0xF2
32#define AXP288_ADC_TS_PIN_ON 0xF3
33
34enum axp288_adc_id {
35 AXP288_ADC_TS,
36 AXP288_ADC_PMIC,
37 AXP288_ADC_GP,
38 AXP288_ADC_BATT_CHRG_I,
39 AXP288_ADC_BATT_DISCHRG_I,
40 AXP288_ADC_BATT_V,
41 AXP288_ADC_NR_CHAN,
42};
43
44struct axp288_adc_info {
45 int irq;
46 struct regmap *regmap;
47};
48
49static const struct iio_chan_spec const axp288_adc_channels[] = {
50 {
51 .indexed = 1,
52 .type = IIO_TEMP,
53 .channel = 0,
54 .address = AXP288_TS_ADC_H,
55 .datasheet_name = "TS_PIN",
56 }, {
57 .indexed = 1,
58 .type = IIO_TEMP,
59 .channel = 1,
60 .address = AXP288_PMIC_ADC_H,
61 .datasheet_name = "PMIC_TEMP",
62 }, {
63 .indexed = 1,
64 .type = IIO_TEMP,
65 .channel = 2,
66 .address = AXP288_GP_ADC_H,
67 .datasheet_name = "GPADC",
68 }, {
69 .indexed = 1,
70 .type = IIO_CURRENT,
71 .channel = 3,
72 .address = AXP20X_BATT_CHRG_I_H,
73 .datasheet_name = "BATT_CHG_I",
74 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
75 }, {
76 .indexed = 1,
77 .type = IIO_CURRENT,
78 .channel = 4,
79 .address = AXP20X_BATT_DISCHRG_I_H,
80 .datasheet_name = "BATT_DISCHRG_I",
81 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
82 }, {
83 .indexed = 1,
84 .type = IIO_VOLTAGE,
85 .channel = 5,
86 .address = AXP20X_BATT_V_H,
87 .datasheet_name = "BATT_V",
88 .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
89 },
90};
91
92#define AXP288_ADC_MAP(_adc_channel_label, _consumer_dev_name, \
93 _consumer_channel) \
94 { \
95 .adc_channel_label = _adc_channel_label, \
96 .consumer_dev_name = _consumer_dev_name, \
97 .consumer_channel = _consumer_channel, \
98 }
99
100/* for consumer drivers */
101static struct iio_map axp288_adc_default_maps[] = {
102 AXP288_ADC_MAP("TS_PIN", "axp288-batt", "axp288-batt-temp"),
103 AXP288_ADC_MAP("PMIC_TEMP", "axp288-pmic", "axp288-pmic-temp"),
104 AXP288_ADC_MAP("GPADC", "axp288-gpadc", "axp288-system-temp"),
105 AXP288_ADC_MAP("BATT_CHG_I", "axp288-chrg", "axp288-chrg-curr"),
106 AXP288_ADC_MAP("BATT_DISCHRG_I", "axp288-chrg", "axp288-chrg-d-curr"),
107 AXP288_ADC_MAP("BATT_V", "axp288-batt", "axp288-batt-volt"),
108 {},
109};
110
111static int axp288_adc_read_channel(int *val, unsigned long address,
112 struct regmap *regmap)
113{
114 u8 buf[2];
115
116 if (regmap_bulk_read(regmap, address, buf, 2))
117 return -EIO;
118 *val = (buf[0] << 4) + ((buf[1] >> 4) & 0x0F);
119
120 return IIO_VAL_INT;
121}
122
123static int axp288_adc_set_ts(struct regmap *regmap, unsigned int mode,
124 unsigned long address)
125{
126 /* channels other than GPADC do not need to switch TS pin */
127 if (address != AXP288_GP_ADC_H)
128 return 0;
129
130 return regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, mode);
131}
132
133static int axp288_adc_read_raw(struct iio_dev *indio_dev,
134 struct iio_chan_spec const *chan,
135 int *val, int *val2, long mask)
136{
137 int ret;
138 struct axp288_adc_info *info = iio_priv(indio_dev);
139
140 mutex_lock(&indio_dev->mlock);
141 switch (mask) {
142 case IIO_CHAN_INFO_RAW:
143 if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_GPADC,
144 chan->address)) {
145 dev_err(&indio_dev->dev, "GPADC mode\n");
146 ret = -EINVAL;
147 break;
148 }
149 ret = axp288_adc_read_channel(val, chan->address, info->regmap);
150 if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_ON,
151 chan->address))
152 dev_err(&indio_dev->dev, "TS pin restore\n");
153 break;
154 case IIO_CHAN_INFO_PROCESSED:
155 ret = axp288_adc_read_channel(val, chan->address, info->regmap);
156 break;
157 default:
158 ret = -EINVAL;
159 }
160 mutex_unlock(&indio_dev->mlock);
161
162 return ret;
163}
164
165static int axp288_adc_set_state(struct regmap *regmap)
166{
167 /* ADC should be always enabled for internal FG to function */
168 if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, AXP288_ADC_TS_PIN_ON))
169 return -EIO;
170
171 return regmap_write(regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
172}
173
174static const struct iio_info axp288_adc_iio_info = {
175 .read_raw = &axp288_adc_read_raw,
176 .driver_module = THIS_MODULE,
177};
178
179static int axp288_adc_probe(struct platform_device *pdev)
180{
181 int ret;
182 struct axp288_adc_info *info;
183 struct iio_dev *indio_dev;
184 struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
185
186 indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*info));
187 if (!indio_dev)
188 return -ENOMEM;
189
190 info = iio_priv(indio_dev);
191 info->irq = platform_get_irq(pdev, 0);
192 if (info->irq < 0) {
193 dev_err(&pdev->dev, "no irq resource?\n");
194 return info->irq;
195 }
196 platform_set_drvdata(pdev, indio_dev);
197 info->regmap = axp20x->regmap;
198 /*
199 * Set ADC to enabled state at all time, including system suspend.
200 * otherwise internal fuel gauge functionality may be affected.
201 */
202 ret = axp288_adc_set_state(axp20x->regmap);
203 if (ret) {
204 dev_err(&pdev->dev, "unable to enable ADC device\n");
205 return ret;
206 }
207
208 indio_dev->dev.parent = &pdev->dev;
209 indio_dev->name = pdev->name;
210 indio_dev->channels = axp288_adc_channels;
211 indio_dev->num_channels = ARRAY_SIZE(axp288_adc_channels);
212 indio_dev->info = &axp288_adc_iio_info;
213 indio_dev->modes = INDIO_DIRECT_MODE;
214 ret = iio_map_array_register(indio_dev, axp288_adc_default_maps);
215 if (ret < 0)
216 return ret;
217
218 ret = iio_device_register(indio_dev);
219 if (ret < 0) {
220 dev_err(&pdev->dev, "unable to register iio device\n");
221 goto err_array_unregister;
222 }
223 return 0;
224
225err_array_unregister:
226 iio_map_array_unregister(indio_dev);
227
228 return ret;
229}
230
231static int axp288_adc_remove(struct platform_device *pdev)
232{
233 struct iio_dev *indio_dev = platform_get_drvdata(pdev);
234
235 iio_device_unregister(indio_dev);
236 iio_map_array_unregister(indio_dev);
237
238 return 0;
239}
240
241static struct platform_device_id axp288_adc_id_table[] = {
242 { .name = "axp288_adc" },
243 {},
244};
245
246static struct platform_driver axp288_adc_driver = {
247 .probe = axp288_adc_probe,
248 .remove = axp288_adc_remove,
249 .id_table = axp288_adc_id_table,
250 .driver = {
251 .name = "axp288_adc",
252 },
253};
254
255MODULE_DEVICE_TABLE(platform, axp288_adc_id_table);
256
257module_platform_driver(axp288_adc_driver);
258
259MODULE_AUTHOR("Jacob Pan <jacob.jun.pan@linux.intel.com>");
260MODULE_DESCRIPTION("X-Powers AXP288 ADC Driver");
261MODULE_LICENSE("GPL");
diff --git a/drivers/iio/adc/men_z188_adc.c b/drivers/iio/adc/men_z188_adc.c
index b58d6302521f..d095efe1ba14 100644
--- a/drivers/iio/adc/men_z188_adc.c
+++ b/drivers/iio/adc/men_z188_adc.c
@@ -152,6 +152,7 @@ static void men_z188_remove(struct mcb_device *dev)
152 152
153static const struct mcb_device_id men_z188_ids[] = { 153static const struct mcb_device_id men_z188_ids[] = {
154 { .device = 0xbc }, 154 { .device = 0xbc },
155 { }
155}; 156};
156MODULE_DEVICE_TABLE(mcb, men_z188_ids); 157MODULE_DEVICE_TABLE(mcb, men_z188_ids);
157 158
diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
index 1f967e0d688e..d2fa526740ca 100644
--- a/drivers/iio/gyro/bmg160.c
+++ b/drivers/iio/gyro/bmg160.c
@@ -67,6 +67,9 @@
67#define BMG160_REG_INT_EN_0 0x15 67#define BMG160_REG_INT_EN_0 0x15
68#define BMG160_DATA_ENABLE_INT BIT(7) 68#define BMG160_DATA_ENABLE_INT BIT(7)
69 69
70#define BMG160_REG_INT_EN_1 0x16
71#define BMG160_INT1_BIT_OD BIT(1)
72
70#define BMG160_REG_XOUT_L 0x02 73#define BMG160_REG_XOUT_L 0x02
71#define BMG160_AXIS_TO_REG(axis) (BMG160_REG_XOUT_L + (axis * 2)) 74#define BMG160_AXIS_TO_REG(axis) (BMG160_REG_XOUT_L + (axis * 2))
72 75
@@ -82,6 +85,9 @@
82 85
83#define BMG160_REG_INT_STATUS_2 0x0B 86#define BMG160_REG_INT_STATUS_2 0x0B
84#define BMG160_ANY_MOTION_MASK 0x07 87#define BMG160_ANY_MOTION_MASK 0x07
88#define BMG160_ANY_MOTION_BIT_X BIT(0)
89#define BMG160_ANY_MOTION_BIT_Y BIT(1)
90#define BMG160_ANY_MOTION_BIT_Z BIT(2)
85 91
86#define BMG160_REG_TEMP 0x08 92#define BMG160_REG_TEMP 0x08
87#define BMG160_TEMP_CENTER_VAL 23 93#define BMG160_TEMP_CENTER_VAL 23
@@ -222,6 +228,19 @@ static int bmg160_chip_init(struct bmg160_data *data)
222 data->slope_thres = ret; 228 data->slope_thres = ret;
223 229
224 /* Set default interrupt mode */ 230 /* Set default interrupt mode */
231 ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_EN_1);
232 if (ret < 0) {
233 dev_err(&data->client->dev, "Error reading reg_int_en_1\n");
234 return ret;
235 }
236 ret &= ~BMG160_INT1_BIT_OD;
237 ret = i2c_smbus_write_byte_data(data->client,
238 BMG160_REG_INT_EN_1, ret);
239 if (ret < 0) {
240 dev_err(&data->client->dev, "Error writing reg_int_en_1\n");
241 return ret;
242 }
243
225 ret = i2c_smbus_write_byte_data(data->client, 244 ret = i2c_smbus_write_byte_data(data->client,
226 BMG160_REG_INT_RST_LATCH, 245 BMG160_REG_INT_RST_LATCH,
227 BMG160_INT_MODE_LATCH_INT | 246 BMG160_INT_MODE_LATCH_INT |
@@ -250,6 +269,9 @@ static int bmg160_set_power_state(struct bmg160_data *data, bool on)
250 if (ret < 0) { 269 if (ret < 0) {
251 dev_err(&data->client->dev, 270 dev_err(&data->client->dev,
252 "Failed: bmg160_set_power_state for %d\n", on); 271 "Failed: bmg160_set_power_state for %d\n", on);
272 if (on)
273 pm_runtime_put_noidle(&data->client->dev);
274
253 return ret; 275 return ret;
254 } 276 }
255#endif 277#endif
@@ -705,6 +727,7 @@ static int bmg160_write_event_config(struct iio_dev *indio_dev,
705 727
706 ret = bmg160_setup_any_motion_interrupt(data, state); 728 ret = bmg160_setup_any_motion_interrupt(data, state);
707 if (ret < 0) { 729 if (ret < 0) {
730 bmg160_set_power_state(data, false);
708 mutex_unlock(&data->mutex); 731 mutex_unlock(&data->mutex);
709 return ret; 732 return ret;
710 } 733 }
@@ -743,7 +766,7 @@ static const struct attribute_group bmg160_attrs_group = {
743 766
744static const struct iio_event_spec bmg160_event = { 767static const struct iio_event_spec bmg160_event = {
745 .type = IIO_EV_TYPE_ROC, 768 .type = IIO_EV_TYPE_ROC,
746 .dir = IIO_EV_DIR_RISING | IIO_EV_DIR_FALLING, 769 .dir = IIO_EV_DIR_EITHER,
747 .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) | 770 .mask_shared_by_type = BIT(IIO_EV_INFO_VALUE) |
748 BIT(IIO_EV_INFO_ENABLE) 771 BIT(IIO_EV_INFO_ENABLE)
749}; 772};
@@ -871,6 +894,7 @@ static int bmg160_data_rdy_trigger_set_state(struct iio_trigger *trig,
871 else 894 else
872 ret = bmg160_setup_new_data_interrupt(data, state); 895 ret = bmg160_setup_new_data_interrupt(data, state);
873 if (ret < 0) { 896 if (ret < 0) {
897 bmg160_set_power_state(data, false);
874 mutex_unlock(&data->mutex); 898 mutex_unlock(&data->mutex);
875 return ret; 899 return ret;
876 } 900 }
@@ -908,10 +932,24 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
908 else 932 else
909 dir = IIO_EV_DIR_FALLING; 933 dir = IIO_EV_DIR_FALLING;
910 934
911 if (ret & BMG160_ANY_MOTION_MASK) 935 if (ret & BMG160_ANY_MOTION_BIT_X)
912 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL, 936 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
913 0, 937 0,
914 IIO_MOD_X_OR_Y_OR_Z, 938 IIO_MOD_X,
939 IIO_EV_TYPE_ROC,
940 dir),
941 data->timestamp);
942 if (ret & BMG160_ANY_MOTION_BIT_Y)
943 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
944 0,
945 IIO_MOD_Y,
946 IIO_EV_TYPE_ROC,
947 dir),
948 data->timestamp);
949 if (ret & BMG160_ANY_MOTION_BIT_Z)
950 iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
951 0,
952 IIO_MOD_Z,
915 IIO_EV_TYPE_ROC, 953 IIO_EV_TYPE_ROC,
916 dir), 954 dir),
917 data->timestamp); 955 data->timestamp);
@@ -1169,8 +1207,15 @@ static int bmg160_runtime_suspend(struct device *dev)
1169{ 1207{
1170 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev)); 1208 struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
1171 struct bmg160_data *data = iio_priv(indio_dev); 1209 struct bmg160_data *data = iio_priv(indio_dev);
1210 int ret;
1211
1212 ret = bmg160_set_mode(data, BMG160_MODE_SUSPEND);
1213 if (ret < 0) {
1214 dev_err(&data->client->dev, "set mode failed\n");
1215 return -EAGAIN;
1216 }
1172 1217
1173 return bmg160_set_mode(data, BMG160_MODE_SUSPEND); 1218 return 0;
1174} 1219}
1175 1220
1176static int bmg160_runtime_resume(struct device *dev) 1221static int bmg160_runtime_resume(struct device *dev)
diff --git a/drivers/iio/light/tsl4531.c b/drivers/iio/light/tsl4531.c
index a15006efa137..0763b8632573 100644
--- a/drivers/iio/light/tsl4531.c
+++ b/drivers/iio/light/tsl4531.c
@@ -230,9 +230,12 @@ static int tsl4531_resume(struct device *dev)
230 return i2c_smbus_write_byte_data(to_i2c_client(dev), TSL4531_CONTROL, 230 return i2c_smbus_write_byte_data(to_i2c_client(dev), TSL4531_CONTROL,
231 TSL4531_MODE_NORMAL); 231 TSL4531_MODE_NORMAL);
232} 232}
233#endif
234 233
235static SIMPLE_DEV_PM_OPS(tsl4531_pm_ops, tsl4531_suspend, tsl4531_resume); 234static SIMPLE_DEV_PM_OPS(tsl4531_pm_ops, tsl4531_suspend, tsl4531_resume);
235#define TSL4531_PM_OPS (&tsl4531_pm_ops)
236#else
237#define TSL4531_PM_OPS NULL
238#endif
236 239
237static const struct i2c_device_id tsl4531_id[] = { 240static const struct i2c_device_id tsl4531_id[] = {
238 { "tsl4531", 0 }, 241 { "tsl4531", 0 },
@@ -243,7 +246,7 @@ MODULE_DEVICE_TABLE(i2c, tsl4531_id);
243static struct i2c_driver tsl4531_driver = { 246static struct i2c_driver tsl4531_driver = {
244 .driver = { 247 .driver = {
245 .name = TSL4531_DRV_NAME, 248 .name = TSL4531_DRV_NAME,
246 .pm = &tsl4531_pm_ops, 249 .pm = TSL4531_PM_OPS,
247 .owner = THIS_MODULE, 250 .owner = THIS_MODULE,
248 }, 251 },
249 .probe = tsl4531_probe, 252 .probe = tsl4531_probe,
diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index 5e780ef206f3..8349cc0fdf66 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -330,7 +330,7 @@ static int as3935_probe(struct spi_device *spi)
330 return -EINVAL; 330 return -EINVAL;
331 } 331 }
332 332
333 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(st)); 333 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
334 if (!indio_dev) 334 if (!indio_dev)
335 return -ENOMEM; 335 return -ENOMEM;
336 336
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
index f42ab14105ac..20ca6a619476 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.c
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
@@ -911,7 +911,7 @@ static struct scsi_host_template iscsi_iser_sht = {
911 .module = THIS_MODULE, 911 .module = THIS_MODULE,
912 .name = "iSCSI Initiator over iSER", 912 .name = "iSCSI Initiator over iSER",
913 .queuecommand = iscsi_queuecommand, 913 .queuecommand = iscsi_queuecommand,
914 .change_queue_depth = iscsi_change_queue_depth, 914 .change_queue_depth = scsi_change_queue_depth,
915 .sg_tablesize = ISCSI_ISER_SG_TABLESIZE, 915 .sg_tablesize = ISCSI_ISER_SG_TABLESIZE,
916 .max_sectors = 1024, 916 .max_sectors = 1024,
917 .cmd_per_lun = ISER_DEF_CMD_PER_LUN, 917 .cmd_per_lun = ISER_DEF_CMD_PER_LUN,
@@ -922,6 +922,7 @@ static struct scsi_host_template iscsi_iser_sht = {
922 .use_clustering = DISABLE_CLUSTERING, 922 .use_clustering = DISABLE_CLUSTERING,
923 .proc_name = "iscsi_iser", 923 .proc_name = "iscsi_iser",
924 .this_id = -1, 924 .this_id = -1,
925 .track_queue_depth = 1,
925}; 926};
926 927
927static struct iscsi_transport iscsi_iser_transport = { 928static struct iscsi_transport iscsi_iser_transport = {
diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c
index 3effa931fce2..10641b7816f4 100644
--- a/drivers/infiniband/ulp/isert/ib_isert.c
+++ b/drivers/infiniband/ulp/isert/ib_isert.c
@@ -115,9 +115,12 @@ isert_conn_setup_qp(struct isert_conn *isert_conn, struct rdma_cm_id *cma_id,
115 attr.cap.max_recv_wr = ISERT_QP_MAX_RECV_DTOS; 115 attr.cap.max_recv_wr = ISERT_QP_MAX_RECV_DTOS;
116 /* 116 /*
117 * FIXME: Use devattr.max_sge - 2 for max_send_sge as 117 * FIXME: Use devattr.max_sge - 2 for max_send_sge as
118 * work-around for RDMA_READ.. 118 * work-around for RDMA_READs with ConnectX-2.
119 *
120 * Also, still make sure to have at least two SGEs for
121 * outgoing control PDU responses.
119 */ 122 */
120 attr.cap.max_send_sge = device->dev_attr.max_sge - 2; 123 attr.cap.max_send_sge = max(2, device->dev_attr.max_sge - 2);
121 isert_conn->max_sge = attr.cap.max_send_sge; 124 isert_conn->max_sge = attr.cap.max_send_sge;
122 125
123 attr.cap.max_recv_sge = 1; 126 attr.cap.max_recv_sge = 1;
@@ -225,12 +228,16 @@ isert_create_device_ib_res(struct isert_device *device)
225 struct isert_cq_desc *cq_desc; 228 struct isert_cq_desc *cq_desc;
226 struct ib_device_attr *dev_attr; 229 struct ib_device_attr *dev_attr;
227 int ret = 0, i, j; 230 int ret = 0, i, j;
231 int max_rx_cqe, max_tx_cqe;
228 232
229 dev_attr = &device->dev_attr; 233 dev_attr = &device->dev_attr;
230 ret = isert_query_device(ib_dev, dev_attr); 234 ret = isert_query_device(ib_dev, dev_attr);
231 if (ret) 235 if (ret)
232 return ret; 236 return ret;
233 237
238 max_rx_cqe = min(ISER_MAX_RX_CQ_LEN, dev_attr->max_cqe);
239 max_tx_cqe = min(ISER_MAX_TX_CQ_LEN, dev_attr->max_cqe);
240
234 /* asign function handlers */ 241 /* asign function handlers */
235 if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS && 242 if (dev_attr->device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS &&
236 dev_attr->device_cap_flags & IB_DEVICE_SIGNATURE_HANDOVER) { 243 dev_attr->device_cap_flags & IB_DEVICE_SIGNATURE_HANDOVER) {
@@ -272,7 +279,7 @@ isert_create_device_ib_res(struct isert_device *device)
272 isert_cq_rx_callback, 279 isert_cq_rx_callback,
273 isert_cq_event_callback, 280 isert_cq_event_callback,
274 (void *)&cq_desc[i], 281 (void *)&cq_desc[i],
275 ISER_MAX_RX_CQ_LEN, i); 282 max_rx_cqe, i);
276 if (IS_ERR(device->dev_rx_cq[i])) { 283 if (IS_ERR(device->dev_rx_cq[i])) {
277 ret = PTR_ERR(device->dev_rx_cq[i]); 284 ret = PTR_ERR(device->dev_rx_cq[i]);
278 device->dev_rx_cq[i] = NULL; 285 device->dev_rx_cq[i] = NULL;
@@ -284,7 +291,7 @@ isert_create_device_ib_res(struct isert_device *device)
284 isert_cq_tx_callback, 291 isert_cq_tx_callback,
285 isert_cq_event_callback, 292 isert_cq_event_callback,
286 (void *)&cq_desc[i], 293 (void *)&cq_desc[i],
287 ISER_MAX_TX_CQ_LEN, i); 294 max_tx_cqe, i);
288 if (IS_ERR(device->dev_tx_cq[i])) { 295 if (IS_ERR(device->dev_tx_cq[i])) {
289 ret = PTR_ERR(device->dev_tx_cq[i]); 296 ret = PTR_ERR(device->dev_tx_cq[i]);
290 device->dev_tx_cq[i] = NULL; 297 device->dev_tx_cq[i] = NULL;
@@ -803,14 +810,25 @@ wake_up:
803 complete(&isert_conn->conn_wait); 810 complete(&isert_conn->conn_wait);
804} 811}
805 812
806static void 813static int
807isert_disconnected_handler(struct rdma_cm_id *cma_id, bool disconnect) 814isert_disconnected_handler(struct rdma_cm_id *cma_id, bool disconnect)
808{ 815{
809 struct isert_conn *isert_conn = (struct isert_conn *)cma_id->context; 816 struct isert_conn *isert_conn;
817
818 if (!cma_id->qp) {
819 struct isert_np *isert_np = cma_id->context;
820
821 isert_np->np_cm_id = NULL;
822 return -1;
823 }
824
825 isert_conn = (struct isert_conn *)cma_id->context;
810 826
811 isert_conn->disconnect = disconnect; 827 isert_conn->disconnect = disconnect;
812 INIT_WORK(&isert_conn->conn_logout_work, isert_disconnect_work); 828 INIT_WORK(&isert_conn->conn_logout_work, isert_disconnect_work);
813 schedule_work(&isert_conn->conn_logout_work); 829 schedule_work(&isert_conn->conn_logout_work);
830
831 return 0;
814} 832}
815 833
816static int 834static int
@@ -825,6 +843,9 @@ isert_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
825 switch (event->event) { 843 switch (event->event) {
826 case RDMA_CM_EVENT_CONNECT_REQUEST: 844 case RDMA_CM_EVENT_CONNECT_REQUEST:
827 ret = isert_connect_request(cma_id, event); 845 ret = isert_connect_request(cma_id, event);
846 if (ret)
847 pr_err("isert_cma_handler failed RDMA_CM_EVENT: 0x%08x %d\n",
848 event->event, ret);
828 break; 849 break;
829 case RDMA_CM_EVENT_ESTABLISHED: 850 case RDMA_CM_EVENT_ESTABLISHED:
830 isert_connected_handler(cma_id); 851 isert_connected_handler(cma_id);
@@ -834,7 +855,7 @@ isert_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
834 case RDMA_CM_EVENT_DEVICE_REMOVAL: /* FALLTHRU */ 855 case RDMA_CM_EVENT_DEVICE_REMOVAL: /* FALLTHRU */
835 disconnect = true; 856 disconnect = true;
836 case RDMA_CM_EVENT_TIMEWAIT_EXIT: /* FALLTHRU */ 857 case RDMA_CM_EVENT_TIMEWAIT_EXIT: /* FALLTHRU */
837 isert_disconnected_handler(cma_id, disconnect); 858 ret = isert_disconnected_handler(cma_id, disconnect);
838 break; 859 break;
839 case RDMA_CM_EVENT_CONNECT_ERROR: 860 case RDMA_CM_EVENT_CONNECT_ERROR:
840 default: 861 default:
@@ -842,12 +863,6 @@ isert_cma_handler(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
842 break; 863 break;
843 } 864 }
844 865
845 if (ret != 0) {
846 pr_err("isert_cma_handler failed RDMA_CM_EVENT: 0x%08x %d\n",
847 event->event, ret);
848 dump_stack();
849 }
850
851 return ret; 866 return ret;
852} 867}
853 868
@@ -3190,7 +3205,8 @@ isert_free_np(struct iscsi_np *np)
3190{ 3205{
3191 struct isert_np *isert_np = (struct isert_np *)np->np_context; 3206 struct isert_np *isert_np = (struct isert_np *)np->np_context;
3192 3207
3193 rdma_destroy_id(isert_np->np_cm_id); 3208 if (isert_np->np_cm_id)
3209 rdma_destroy_id(isert_np->np_cm_id);
3194 3210
3195 np->np_context = NULL; 3211 np->np_context = NULL;
3196 kfree(isert_np); 3212 kfree(isert_np);
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 62d2a18e1b41..5461924c9f10 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -123,10 +123,15 @@ MODULE_PARM_DESC(dev_loss_tmo,
123 " if fast_io_fail_tmo has not been set. \"off\" means that" 123 " if fast_io_fail_tmo has not been set. \"off\" means that"
124 " this functionality is disabled."); 124 " this functionality is disabled.");
125 125
126static unsigned ch_count;
127module_param(ch_count, uint, 0444);
128MODULE_PARM_DESC(ch_count,
129 "Number of RDMA channels to use for communication with an SRP target. Using more than one channel improves performance if the HCA supports multiple completion vectors. The default value is the minimum of four times the number of online CPU sockets and the number of completion vectors supported by the HCA.");
130
126static void srp_add_one(struct ib_device *device); 131static void srp_add_one(struct ib_device *device);
127static void srp_remove_one(struct ib_device *device); 132static void srp_remove_one(struct ib_device *device);
128static void srp_recv_completion(struct ib_cq *cq, void *target_ptr); 133static void srp_recv_completion(struct ib_cq *cq, void *ch_ptr);
129static void srp_send_completion(struct ib_cq *cq, void *target_ptr); 134static void srp_send_completion(struct ib_cq *cq, void *ch_ptr);
130static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event); 135static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event);
131 136
132static struct scsi_transport_template *ib_srp_transport_template; 137static struct scsi_transport_template *ib_srp_transport_template;
@@ -262,7 +267,7 @@ static int srp_init_qp(struct srp_target_port *target,
262 267
263 ret = ib_find_pkey(target->srp_host->srp_dev->dev, 268 ret = ib_find_pkey(target->srp_host->srp_dev->dev,
264 target->srp_host->port, 269 target->srp_host->port,
265 be16_to_cpu(target->path.pkey), 270 be16_to_cpu(target->pkey),
266 &attr->pkey_index); 271 &attr->pkey_index);
267 if (ret) 272 if (ret)
268 goto out; 273 goto out;
@@ -283,18 +288,23 @@ out:
283 return ret; 288 return ret;
284} 289}
285 290
286static int srp_new_cm_id(struct srp_target_port *target) 291static int srp_new_cm_id(struct srp_rdma_ch *ch)
287{ 292{
293 struct srp_target_port *target = ch->target;
288 struct ib_cm_id *new_cm_id; 294 struct ib_cm_id *new_cm_id;
289 295
290 new_cm_id = ib_create_cm_id(target->srp_host->srp_dev->dev, 296 new_cm_id = ib_create_cm_id(target->srp_host->srp_dev->dev,
291 srp_cm_handler, target); 297 srp_cm_handler, ch);
292 if (IS_ERR(new_cm_id)) 298 if (IS_ERR(new_cm_id))
293 return PTR_ERR(new_cm_id); 299 return PTR_ERR(new_cm_id);
294 300
295 if (target->cm_id) 301 if (ch->cm_id)
296 ib_destroy_cm_id(target->cm_id); 302 ib_destroy_cm_id(ch->cm_id);
297 target->cm_id = new_cm_id; 303 ch->cm_id = new_cm_id;
304 ch->path.sgid = target->sgid;
305 ch->path.dgid = target->orig_dgid;
306 ch->path.pkey = target->pkey;
307 ch->path.service_id = target->service_id;
298 308
299 return 0; 309 return 0;
300} 310}
@@ -443,8 +453,44 @@ static struct srp_fr_pool *srp_alloc_fr_pool(struct srp_target_port *target)
443 dev->max_pages_per_mr); 453 dev->max_pages_per_mr);
444} 454}
445 455
446static int srp_create_target_ib(struct srp_target_port *target) 456/**
457 * srp_destroy_qp() - destroy an RDMA queue pair
458 * @ch: SRP RDMA channel.
459 *
460 * Change a queue pair into the error state and wait until all receive
461 * completions have been processed before destroying it. This avoids that
462 * the receive completion handler can access the queue pair while it is
463 * being destroyed.
464 */
465static void srp_destroy_qp(struct srp_rdma_ch *ch)
466{
467 struct srp_target_port *target = ch->target;
468 static struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR };
469 static struct ib_recv_wr wr = { .wr_id = SRP_LAST_WR_ID };
470 struct ib_recv_wr *bad_wr;
471 int ret;
472
473 /* Destroying a QP and reusing ch->done is only safe if not connected */
474 WARN_ON_ONCE(target->connected);
475
476 ret = ib_modify_qp(ch->qp, &attr, IB_QP_STATE);
477 WARN_ONCE(ret, "ib_cm_init_qp_attr() returned %d\n", ret);
478 if (ret)
479 goto out;
480
481 init_completion(&ch->done);
482 ret = ib_post_recv(ch->qp, &wr, &bad_wr);
483 WARN_ONCE(ret, "ib_post_recv() returned %d\n", ret);
484 if (ret == 0)
485 wait_for_completion(&ch->done);
486
487out:
488 ib_destroy_qp(ch->qp);
489}
490
491static int srp_create_ch_ib(struct srp_rdma_ch *ch)
447{ 492{
493 struct srp_target_port *target = ch->target;
448 struct srp_device *dev = target->srp_host->srp_dev; 494 struct srp_device *dev = target->srp_host->srp_dev;
449 struct ib_qp_init_attr *init_attr; 495 struct ib_qp_init_attr *init_attr;
450 struct ib_cq *recv_cq, *send_cq; 496 struct ib_cq *recv_cq, *send_cq;
@@ -458,15 +504,16 @@ static int srp_create_target_ib(struct srp_target_port *target)
458 if (!init_attr) 504 if (!init_attr)
459 return -ENOMEM; 505 return -ENOMEM;
460 506
461 recv_cq = ib_create_cq(dev->dev, srp_recv_completion, NULL, target, 507 /* + 1 for SRP_LAST_WR_ID */
462 target->queue_size, target->comp_vector); 508 recv_cq = ib_create_cq(dev->dev, srp_recv_completion, NULL, ch,
509 target->queue_size + 1, ch->comp_vector);
463 if (IS_ERR(recv_cq)) { 510 if (IS_ERR(recv_cq)) {
464 ret = PTR_ERR(recv_cq); 511 ret = PTR_ERR(recv_cq);
465 goto err; 512 goto err;
466 } 513 }
467 514
468 send_cq = ib_create_cq(dev->dev, srp_send_completion, NULL, target, 515 send_cq = ib_create_cq(dev->dev, srp_send_completion, NULL, ch,
469 m * target->queue_size, target->comp_vector); 516 m * target->queue_size, ch->comp_vector);
470 if (IS_ERR(send_cq)) { 517 if (IS_ERR(send_cq)) {
471 ret = PTR_ERR(send_cq); 518 ret = PTR_ERR(send_cq);
472 goto err_recv_cq; 519 goto err_recv_cq;
@@ -476,7 +523,7 @@ static int srp_create_target_ib(struct srp_target_port *target)
476 523
477 init_attr->event_handler = srp_qp_event; 524 init_attr->event_handler = srp_qp_event;
478 init_attr->cap.max_send_wr = m * target->queue_size; 525 init_attr->cap.max_send_wr = m * target->queue_size;
479 init_attr->cap.max_recv_wr = target->queue_size; 526 init_attr->cap.max_recv_wr = target->queue_size + 1;
480 init_attr->cap.max_recv_sge = 1; 527 init_attr->cap.max_recv_sge = 1;
481 init_attr->cap.max_send_sge = 1; 528 init_attr->cap.max_send_sge = 1;
482 init_attr->sq_sig_type = IB_SIGNAL_REQ_WR; 529 init_attr->sq_sig_type = IB_SIGNAL_REQ_WR;
@@ -502,9 +549,9 @@ static int srp_create_target_ib(struct srp_target_port *target)
502 "FR pool allocation failed (%d)\n", ret); 549 "FR pool allocation failed (%d)\n", ret);
503 goto err_qp; 550 goto err_qp;
504 } 551 }
505 if (target->fr_pool) 552 if (ch->fr_pool)
506 srp_destroy_fr_pool(target->fr_pool); 553 srp_destroy_fr_pool(ch->fr_pool);
507 target->fr_pool = fr_pool; 554 ch->fr_pool = fr_pool;
508 } else if (!dev->use_fast_reg && dev->has_fmr) { 555 } else if (!dev->use_fast_reg && dev->has_fmr) {
509 fmr_pool = srp_alloc_fmr_pool(target); 556 fmr_pool = srp_alloc_fmr_pool(target);
510 if (IS_ERR(fmr_pool)) { 557 if (IS_ERR(fmr_pool)) {
@@ -513,21 +560,21 @@ static int srp_create_target_ib(struct srp_target_port *target)
513 "FMR pool allocation failed (%d)\n", ret); 560 "FMR pool allocation failed (%d)\n", ret);
514 goto err_qp; 561 goto err_qp;
515 } 562 }
516 if (target->fmr_pool) 563 if (ch->fmr_pool)
517 ib_destroy_fmr_pool(target->fmr_pool); 564 ib_destroy_fmr_pool(ch->fmr_pool);
518 target->fmr_pool = fmr_pool; 565 ch->fmr_pool = fmr_pool;
519 } 566 }
520 567
521 if (target->qp) 568 if (ch->qp)
522 ib_destroy_qp(target->qp); 569 srp_destroy_qp(ch);
523 if (target->recv_cq) 570 if (ch->recv_cq)
524 ib_destroy_cq(target->recv_cq); 571 ib_destroy_cq(ch->recv_cq);
525 if (target->send_cq) 572 if (ch->send_cq)
526 ib_destroy_cq(target->send_cq); 573 ib_destroy_cq(ch->send_cq);
527 574
528 target->qp = qp; 575 ch->qp = qp;
529 target->recv_cq = recv_cq; 576 ch->recv_cq = recv_cq;
530 target->send_cq = send_cq; 577 ch->send_cq = send_cq;
531 578
532 kfree(init_attr); 579 kfree(init_attr);
533 return 0; 580 return 0;
@@ -548,93 +595,117 @@ err:
548 595
549/* 596/*
550 * Note: this function may be called without srp_alloc_iu_bufs() having been 597 * Note: this function may be called without srp_alloc_iu_bufs() having been
551 * invoked. Hence the target->[rt]x_ring checks. 598 * invoked. Hence the ch->[rt]x_ring checks.
552 */ 599 */
553static void srp_free_target_ib(struct srp_target_port *target) 600static void srp_free_ch_ib(struct srp_target_port *target,
601 struct srp_rdma_ch *ch)
554{ 602{
555 struct srp_device *dev = target->srp_host->srp_dev; 603 struct srp_device *dev = target->srp_host->srp_dev;
556 int i; 604 int i;
557 605
606 if (!ch->target)
607 return;
608
609 if (ch->cm_id) {
610 ib_destroy_cm_id(ch->cm_id);
611 ch->cm_id = NULL;
612 }
613
614 /* If srp_new_cm_id() succeeded but srp_create_ch_ib() not, return. */
615 if (!ch->qp)
616 return;
617
558 if (dev->use_fast_reg) { 618 if (dev->use_fast_reg) {
559 if (target->fr_pool) 619 if (ch->fr_pool)
560 srp_destroy_fr_pool(target->fr_pool); 620 srp_destroy_fr_pool(ch->fr_pool);
561 } else { 621 } else {
562 if (target->fmr_pool) 622 if (ch->fmr_pool)
563 ib_destroy_fmr_pool(target->fmr_pool); 623 ib_destroy_fmr_pool(ch->fmr_pool);
564 } 624 }
565 ib_destroy_qp(target->qp); 625 srp_destroy_qp(ch);
566 ib_destroy_cq(target->send_cq); 626 ib_destroy_cq(ch->send_cq);
567 ib_destroy_cq(target->recv_cq); 627 ib_destroy_cq(ch->recv_cq);
628
629 /*
630 * Avoid that the SCSI error handler tries to use this channel after
631 * it has been freed. The SCSI error handler can namely continue
632 * trying to perform recovery actions after scsi_remove_host()
633 * returned.
634 */
635 ch->target = NULL;
568 636
569 target->qp = NULL; 637 ch->qp = NULL;
570 target->send_cq = target->recv_cq = NULL; 638 ch->send_cq = ch->recv_cq = NULL;
571 639
572 if (target->rx_ring) { 640 if (ch->rx_ring) {
573 for (i = 0; i < target->queue_size; ++i) 641 for (i = 0; i < target->queue_size; ++i)
574 srp_free_iu(target->srp_host, target->rx_ring[i]); 642 srp_free_iu(target->srp_host, ch->rx_ring[i]);
575 kfree(target->rx_ring); 643 kfree(ch->rx_ring);
576 target->rx_ring = NULL; 644 ch->rx_ring = NULL;
577 } 645 }
578 if (target->tx_ring) { 646 if (ch->tx_ring) {
579 for (i = 0; i < target->queue_size; ++i) 647 for (i = 0; i < target->queue_size; ++i)
580 srp_free_iu(target->srp_host, target->tx_ring[i]); 648 srp_free_iu(target->srp_host, ch->tx_ring[i]);
581 kfree(target->tx_ring); 649 kfree(ch->tx_ring);
582 target->tx_ring = NULL; 650 ch->tx_ring = NULL;
583 } 651 }
584} 652}
585 653
586static void srp_path_rec_completion(int status, 654static void srp_path_rec_completion(int status,
587 struct ib_sa_path_rec *pathrec, 655 struct ib_sa_path_rec *pathrec,
588 void *target_ptr) 656 void *ch_ptr)
589{ 657{
590 struct srp_target_port *target = target_ptr; 658 struct srp_rdma_ch *ch = ch_ptr;
659 struct srp_target_port *target = ch->target;
591 660
592 target->status = status; 661 ch->status = status;
593 if (status) 662 if (status)
594 shost_printk(KERN_ERR, target->scsi_host, 663 shost_printk(KERN_ERR, target->scsi_host,
595 PFX "Got failed path rec status %d\n", status); 664 PFX "Got failed path rec status %d\n", status);
596 else 665 else
597 target->path = *pathrec; 666 ch->path = *pathrec;
598 complete(&target->done); 667 complete(&ch->done);
599} 668}
600 669
601static int srp_lookup_path(struct srp_target_port *target) 670static int srp_lookup_path(struct srp_rdma_ch *ch)
602{ 671{
672 struct srp_target_port *target = ch->target;
603 int ret; 673 int ret;
604 674
605 target->path.numb_path = 1; 675 ch->path.numb_path = 1;
606 676
607 init_completion(&target->done); 677 init_completion(&ch->done);
608 678
609 target->path_query_id = ib_sa_path_rec_get(&srp_sa_client, 679 ch->path_query_id = ib_sa_path_rec_get(&srp_sa_client,
610 target->srp_host->srp_dev->dev, 680 target->srp_host->srp_dev->dev,
611 target->srp_host->port, 681 target->srp_host->port,
612 &target->path, 682 &ch->path,
613 IB_SA_PATH_REC_SERVICE_ID | 683 IB_SA_PATH_REC_SERVICE_ID |
614 IB_SA_PATH_REC_DGID | 684 IB_SA_PATH_REC_DGID |
615 IB_SA_PATH_REC_SGID | 685 IB_SA_PATH_REC_SGID |
616 IB_SA_PATH_REC_NUMB_PATH | 686 IB_SA_PATH_REC_NUMB_PATH |
617 IB_SA_PATH_REC_PKEY, 687 IB_SA_PATH_REC_PKEY,
618 SRP_PATH_REC_TIMEOUT_MS, 688 SRP_PATH_REC_TIMEOUT_MS,
619 GFP_KERNEL, 689 GFP_KERNEL,
620 srp_path_rec_completion, 690 srp_path_rec_completion,
621 target, &target->path_query); 691 ch, &ch->path_query);
622 if (target->path_query_id < 0) 692 if (ch->path_query_id < 0)
623 return target->path_query_id; 693 return ch->path_query_id;
624 694
625 ret = wait_for_completion_interruptible(&target->done); 695 ret = wait_for_completion_interruptible(&ch->done);
626 if (ret < 0) 696 if (ret < 0)
627 return ret; 697 return ret;
628 698
629 if (target->status < 0) 699 if (ch->status < 0)
630 shost_printk(KERN_WARNING, target->scsi_host, 700 shost_printk(KERN_WARNING, target->scsi_host,
631 PFX "Path record query failed\n"); 701 PFX "Path record query failed\n");
632 702
633 return target->status; 703 return ch->status;
634} 704}
635 705
636static int srp_send_req(struct srp_target_port *target) 706static int srp_send_req(struct srp_rdma_ch *ch, bool multich)
637{ 707{
708 struct srp_target_port *target = ch->target;
638 struct { 709 struct {
639 struct ib_cm_req_param param; 710 struct ib_cm_req_param param;
640 struct srp_login_req priv; 711 struct srp_login_req priv;
@@ -645,11 +716,11 @@ static int srp_send_req(struct srp_target_port *target)
645 if (!req) 716 if (!req)
646 return -ENOMEM; 717 return -ENOMEM;
647 718
648 req->param.primary_path = &target->path; 719 req->param.primary_path = &ch->path;
649 req->param.alternate_path = NULL; 720 req->param.alternate_path = NULL;
650 req->param.service_id = target->service_id; 721 req->param.service_id = target->service_id;
651 req->param.qp_num = target->qp->qp_num; 722 req->param.qp_num = ch->qp->qp_num;
652 req->param.qp_type = target->qp->qp_type; 723 req->param.qp_type = ch->qp->qp_type;
653 req->param.private_data = &req->priv; 724 req->param.private_data = &req->priv;
654 req->param.private_data_len = sizeof req->priv; 725 req->param.private_data_len = sizeof req->priv;
655 req->param.flow_control = 1; 726 req->param.flow_control = 1;
@@ -673,6 +744,8 @@ static int srp_send_req(struct srp_target_port *target)
673 req->priv.req_it_iu_len = cpu_to_be32(target->max_iu_len); 744 req->priv.req_it_iu_len = cpu_to_be32(target->max_iu_len);
674 req->priv.req_buf_fmt = cpu_to_be16(SRP_BUF_FORMAT_DIRECT | 745 req->priv.req_buf_fmt = cpu_to_be16(SRP_BUF_FORMAT_DIRECT |
675 SRP_BUF_FORMAT_INDIRECT); 746 SRP_BUF_FORMAT_INDIRECT);
747 req->priv.req_flags = (multich ? SRP_MULTICHAN_MULTI :
748 SRP_MULTICHAN_SINGLE);
676 /* 749 /*
677 * In the published SRP specification (draft rev. 16a), the 750 * In the published SRP specification (draft rev. 16a), the
678 * port identifier format is 8 bytes of ID extension followed 751 * port identifier format is 8 bytes of ID extension followed
@@ -684,7 +757,7 @@ static int srp_send_req(struct srp_target_port *target)
684 */ 757 */
685 if (target->io_class == SRP_REV10_IB_IO_CLASS) { 758 if (target->io_class == SRP_REV10_IB_IO_CLASS) {
686 memcpy(req->priv.initiator_port_id, 759 memcpy(req->priv.initiator_port_id,
687 &target->path.sgid.global.interface_id, 8); 760 &target->sgid.global.interface_id, 8);
688 memcpy(req->priv.initiator_port_id + 8, 761 memcpy(req->priv.initiator_port_id + 8,
689 &target->initiator_ext, 8); 762 &target->initiator_ext, 8);
690 memcpy(req->priv.target_port_id, &target->ioc_guid, 8); 763 memcpy(req->priv.target_port_id, &target->ioc_guid, 8);
@@ -693,7 +766,7 @@ static int srp_send_req(struct srp_target_port *target)
693 memcpy(req->priv.initiator_port_id, 766 memcpy(req->priv.initiator_port_id,
694 &target->initiator_ext, 8); 767 &target->initiator_ext, 8);
695 memcpy(req->priv.initiator_port_id + 8, 768 memcpy(req->priv.initiator_port_id + 8,
696 &target->path.sgid.global.interface_id, 8); 769 &target->sgid.global.interface_id, 8);
697 memcpy(req->priv.target_port_id, &target->id_ext, 8); 770 memcpy(req->priv.target_port_id, &target->id_ext, 8);
698 memcpy(req->priv.target_port_id + 8, &target->ioc_guid, 8); 771 memcpy(req->priv.target_port_id + 8, &target->ioc_guid, 8);
699 } 772 }
@@ -713,7 +786,7 @@ static int srp_send_req(struct srp_target_port *target)
713 &target->srp_host->srp_dev->dev->node_guid, 8); 786 &target->srp_host->srp_dev->dev->node_guid, 8);
714 } 787 }
715 788
716 status = ib_send_cm_req(target->cm_id, &req->param); 789 status = ib_send_cm_req(ch->cm_id, &req->param);
717 790
718 kfree(req); 791 kfree(req);
719 792
@@ -754,28 +827,35 @@ static bool srp_change_conn_state(struct srp_target_port *target,
754 827
755static void srp_disconnect_target(struct srp_target_port *target) 828static void srp_disconnect_target(struct srp_target_port *target)
756{ 829{
830 struct srp_rdma_ch *ch;
831 int i;
832
757 if (srp_change_conn_state(target, false)) { 833 if (srp_change_conn_state(target, false)) {
758 /* XXX should send SRP_I_LOGOUT request */ 834 /* XXX should send SRP_I_LOGOUT request */
759 835
760 if (ib_send_cm_dreq(target->cm_id, NULL, 0)) { 836 for (i = 0; i < target->ch_count; i++) {
761 shost_printk(KERN_DEBUG, target->scsi_host, 837 ch = &target->ch[i];
762 PFX "Sending CM DREQ failed\n"); 838 if (ch->cm_id && ib_send_cm_dreq(ch->cm_id, NULL, 0)) {
839 shost_printk(KERN_DEBUG, target->scsi_host,
840 PFX "Sending CM DREQ failed\n");
841 }
763 } 842 }
764 } 843 }
765} 844}
766 845
767static void srp_free_req_data(struct srp_target_port *target) 846static void srp_free_req_data(struct srp_target_port *target,
847 struct srp_rdma_ch *ch)
768{ 848{
769 struct srp_device *dev = target->srp_host->srp_dev; 849 struct srp_device *dev = target->srp_host->srp_dev;
770 struct ib_device *ibdev = dev->dev; 850 struct ib_device *ibdev = dev->dev;
771 struct srp_request *req; 851 struct srp_request *req;
772 int i; 852 int i;
773 853
774 if (!target->req_ring) 854 if (!ch->target || !ch->req_ring)
775 return; 855 return;
776 856
777 for (i = 0; i < target->req_ring_size; ++i) { 857 for (i = 0; i < target->req_ring_size; ++i) {
778 req = &target->req_ring[i]; 858 req = &ch->req_ring[i];
779 if (dev->use_fast_reg) 859 if (dev->use_fast_reg)
780 kfree(req->fr_list); 860 kfree(req->fr_list);
781 else 861 else
@@ -789,12 +869,13 @@ static void srp_free_req_data(struct srp_target_port *target)
789 kfree(req->indirect_desc); 869 kfree(req->indirect_desc);
790 } 870 }
791 871
792 kfree(target->req_ring); 872 kfree(ch->req_ring);
793 target->req_ring = NULL; 873 ch->req_ring = NULL;
794} 874}
795 875
796static int srp_alloc_req_data(struct srp_target_port *target) 876static int srp_alloc_req_data(struct srp_rdma_ch *ch)
797{ 877{
878 struct srp_target_port *target = ch->target;
798 struct srp_device *srp_dev = target->srp_host->srp_dev; 879 struct srp_device *srp_dev = target->srp_host->srp_dev;
799 struct ib_device *ibdev = srp_dev->dev; 880 struct ib_device *ibdev = srp_dev->dev;
800 struct srp_request *req; 881 struct srp_request *req;
@@ -802,15 +883,13 @@ static int srp_alloc_req_data(struct srp_target_port *target)
802 dma_addr_t dma_addr; 883 dma_addr_t dma_addr;
803 int i, ret = -ENOMEM; 884 int i, ret = -ENOMEM;
804 885
805 INIT_LIST_HEAD(&target->free_reqs); 886 ch->req_ring = kcalloc(target->req_ring_size, sizeof(*ch->req_ring),
806 887 GFP_KERNEL);
807 target->req_ring = kzalloc(target->req_ring_size * 888 if (!ch->req_ring)
808 sizeof(*target->req_ring), GFP_KERNEL);
809 if (!target->req_ring)
810 goto out; 889 goto out;
811 890
812 for (i = 0; i < target->req_ring_size; ++i) { 891 for (i = 0; i < target->req_ring_size; ++i) {
813 req = &target->req_ring[i]; 892 req = &ch->req_ring[i];
814 mr_list = kmalloc(target->cmd_sg_cnt * sizeof(void *), 893 mr_list = kmalloc(target->cmd_sg_cnt * sizeof(void *),
815 GFP_KERNEL); 894 GFP_KERNEL);
816 if (!mr_list) 895 if (!mr_list)
@@ -834,8 +913,6 @@ static int srp_alloc_req_data(struct srp_target_port *target)
834 goto out; 913 goto out;
835 914
836 req->indirect_dma_addr = dma_addr; 915 req->indirect_dma_addr = dma_addr;
837 req->index = i;
838 list_add_tail(&req->list, &target->free_reqs);
839 } 916 }
840 ret = 0; 917 ret = 0;
841 918
@@ -860,6 +937,9 @@ static void srp_del_scsi_host_attr(struct Scsi_Host *shost)
860 937
861static void srp_remove_target(struct srp_target_port *target) 938static void srp_remove_target(struct srp_target_port *target)
862{ 939{
940 struct srp_rdma_ch *ch;
941 int i;
942
863 WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED); 943 WARN_ON_ONCE(target->state != SRP_TARGET_REMOVED);
864 944
865 srp_del_scsi_host_attr(target->scsi_host); 945 srp_del_scsi_host_attr(target->scsi_host);
@@ -868,11 +948,18 @@ static void srp_remove_target(struct srp_target_port *target)
868 scsi_remove_host(target->scsi_host); 948 scsi_remove_host(target->scsi_host);
869 srp_stop_rport_timers(target->rport); 949 srp_stop_rport_timers(target->rport);
870 srp_disconnect_target(target); 950 srp_disconnect_target(target);
871 ib_destroy_cm_id(target->cm_id); 951 for (i = 0; i < target->ch_count; i++) {
872 srp_free_target_ib(target); 952 ch = &target->ch[i];
953 srp_free_ch_ib(target, ch);
954 }
873 cancel_work_sync(&target->tl_err_work); 955 cancel_work_sync(&target->tl_err_work);
874 srp_rport_put(target->rport); 956 srp_rport_put(target->rport);
875 srp_free_req_data(target); 957 for (i = 0; i < target->ch_count; i++) {
958 ch = &target->ch[i];
959 srp_free_req_data(target, ch);
960 }
961 kfree(target->ch);
962 target->ch = NULL;
876 963
877 spin_lock(&target->srp_host->target_lock); 964 spin_lock(&target->srp_host->target_lock);
878 list_del(&target->list); 965 list_del(&target->list);
@@ -898,25 +985,25 @@ static void srp_rport_delete(struct srp_rport *rport)
898 srp_queue_remove_work(target); 985 srp_queue_remove_work(target);
899} 986}
900 987
901static int srp_connect_target(struct srp_target_port *target) 988static int srp_connect_ch(struct srp_rdma_ch *ch, bool multich)
902{ 989{
903 int retries = 3; 990 struct srp_target_port *target = ch->target;
904 int ret; 991 int ret;
905 992
906 WARN_ON_ONCE(target->connected); 993 WARN_ON_ONCE(!multich && target->connected);
907 994
908 target->qp_in_error = false; 995 target->qp_in_error = false;
909 996
910 ret = srp_lookup_path(target); 997 ret = srp_lookup_path(ch);
911 if (ret) 998 if (ret)
912 return ret; 999 return ret;
913 1000
914 while (1) { 1001 while (1) {
915 init_completion(&target->done); 1002 init_completion(&ch->done);
916 ret = srp_send_req(target); 1003 ret = srp_send_req(ch, multich);
917 if (ret) 1004 if (ret)
918 return ret; 1005 return ret;
919 ret = wait_for_completion_interruptible(&target->done); 1006 ret = wait_for_completion_interruptible(&ch->done);
920 if (ret < 0) 1007 if (ret < 0)
921 return ret; 1008 return ret;
922 1009
@@ -926,13 +1013,13 @@ static int srp_connect_target(struct srp_target_port *target)
926 * back, or SRP_DLID_REDIRECT if we get a lid/qp 1013 * back, or SRP_DLID_REDIRECT if we get a lid/qp
927 * redirect REJ back. 1014 * redirect REJ back.
928 */ 1015 */
929 switch (target->status) { 1016 switch (ch->status) {
930 case 0: 1017 case 0:
931 srp_change_conn_state(target, true); 1018 srp_change_conn_state(target, true);
932 return 0; 1019 return 0;
933 1020
934 case SRP_PORT_REDIRECT: 1021 case SRP_PORT_REDIRECT:
935 ret = srp_lookup_path(target); 1022 ret = srp_lookup_path(ch);
936 if (ret) 1023 if (ret)
937 return ret; 1024 return ret;
938 break; 1025 break;
@@ -941,27 +1028,18 @@ static int srp_connect_target(struct srp_target_port *target)
941 break; 1028 break;
942 1029
943 case SRP_STALE_CONN: 1030 case SRP_STALE_CONN:
944 /* Our current CM id was stale, and is now in timewait.
945 * Try to reconnect with a new one.
946 */
947 if (!retries-- || srp_new_cm_id(target)) {
948 shost_printk(KERN_ERR, target->scsi_host, PFX
949 "giving up on stale connection\n");
950 target->status = -ECONNRESET;
951 return target->status;
952 }
953
954 shost_printk(KERN_ERR, target->scsi_host, PFX 1031 shost_printk(KERN_ERR, target->scsi_host, PFX
955 "retrying stale connection\n"); 1032 "giving up on stale connection\n");
956 break; 1033 ch->status = -ECONNRESET;
1034 return ch->status;
957 1035
958 default: 1036 default:
959 return target->status; 1037 return ch->status;
960 } 1038 }
961 } 1039 }
962} 1040}
963 1041
964static int srp_inv_rkey(struct srp_target_port *target, u32 rkey) 1042static int srp_inv_rkey(struct srp_rdma_ch *ch, u32 rkey)
965{ 1043{
966 struct ib_send_wr *bad_wr; 1044 struct ib_send_wr *bad_wr;
967 struct ib_send_wr wr = { 1045 struct ib_send_wr wr = {
@@ -973,13 +1051,14 @@ static int srp_inv_rkey(struct srp_target_port *target, u32 rkey)
973 .ex.invalidate_rkey = rkey, 1051 .ex.invalidate_rkey = rkey,
974 }; 1052 };
975 1053
976 return ib_post_send(target->qp, &wr, &bad_wr); 1054 return ib_post_send(ch->qp, &wr, &bad_wr);
977} 1055}
978 1056
979static void srp_unmap_data(struct scsi_cmnd *scmnd, 1057static void srp_unmap_data(struct scsi_cmnd *scmnd,
980 struct srp_target_port *target, 1058 struct srp_rdma_ch *ch,
981 struct srp_request *req) 1059 struct srp_request *req)
982{ 1060{
1061 struct srp_target_port *target = ch->target;
983 struct srp_device *dev = target->srp_host->srp_dev; 1062 struct srp_device *dev = target->srp_host->srp_dev;
984 struct ib_device *ibdev = dev->dev; 1063 struct ib_device *ibdev = dev->dev;
985 int i, res; 1064 int i, res;
@@ -993,7 +1072,7 @@ static void srp_unmap_data(struct scsi_cmnd *scmnd,
993 struct srp_fr_desc **pfr; 1072 struct srp_fr_desc **pfr;
994 1073
995 for (i = req->nmdesc, pfr = req->fr_list; i > 0; i--, pfr++) { 1074 for (i = req->nmdesc, pfr = req->fr_list; i > 0; i--, pfr++) {
996 res = srp_inv_rkey(target, (*pfr)->mr->rkey); 1075 res = srp_inv_rkey(ch, (*pfr)->mr->rkey);
997 if (res < 0) { 1076 if (res < 0) {
998 shost_printk(KERN_ERR, target->scsi_host, PFX 1077 shost_printk(KERN_ERR, target->scsi_host, PFX
999 "Queueing INV WR for rkey %#x failed (%d)\n", 1078 "Queueing INV WR for rkey %#x failed (%d)\n",
@@ -1003,7 +1082,7 @@ static void srp_unmap_data(struct scsi_cmnd *scmnd,
1003 } 1082 }
1004 } 1083 }
1005 if (req->nmdesc) 1084 if (req->nmdesc)
1006 srp_fr_pool_put(target->fr_pool, req->fr_list, 1085 srp_fr_pool_put(ch->fr_pool, req->fr_list,
1007 req->nmdesc); 1086 req->nmdesc);
1008 } else { 1087 } else {
1009 struct ib_pool_fmr **pfmr; 1088 struct ib_pool_fmr **pfmr;
@@ -1018,7 +1097,7 @@ static void srp_unmap_data(struct scsi_cmnd *scmnd,
1018 1097
1019/** 1098/**
1020 * srp_claim_req - Take ownership of the scmnd associated with a request. 1099 * srp_claim_req - Take ownership of the scmnd associated with a request.
1021 * @target: SRP target port. 1100 * @ch: SRP RDMA channel.
1022 * @req: SRP request. 1101 * @req: SRP request.
1023 * @sdev: If not NULL, only take ownership for this SCSI device. 1102 * @sdev: If not NULL, only take ownership for this SCSI device.
1024 * @scmnd: If NULL, take ownership of @req->scmnd. If not NULL, only take 1103 * @scmnd: If NULL, take ownership of @req->scmnd. If not NULL, only take
@@ -1027,14 +1106,14 @@ static void srp_unmap_data(struct scsi_cmnd *scmnd,
1027 * Return value: 1106 * Return value:
1028 * Either NULL or a pointer to the SCSI command the caller became owner of. 1107 * Either NULL or a pointer to the SCSI command the caller became owner of.
1029 */ 1108 */
1030static struct scsi_cmnd *srp_claim_req(struct srp_target_port *target, 1109static struct scsi_cmnd *srp_claim_req(struct srp_rdma_ch *ch,
1031 struct srp_request *req, 1110 struct srp_request *req,
1032 struct scsi_device *sdev, 1111 struct scsi_device *sdev,
1033 struct scsi_cmnd *scmnd) 1112 struct scsi_cmnd *scmnd)
1034{ 1113{
1035 unsigned long flags; 1114 unsigned long flags;
1036 1115
1037 spin_lock_irqsave(&target->lock, flags); 1116 spin_lock_irqsave(&ch->lock, flags);
1038 if (req->scmnd && 1117 if (req->scmnd &&
1039 (!sdev || req->scmnd->device == sdev) && 1118 (!sdev || req->scmnd->device == sdev) &&
1040 (!scmnd || req->scmnd == scmnd)) { 1119 (!scmnd || req->scmnd == scmnd)) {
@@ -1043,40 +1122,37 @@ static struct scsi_cmnd *srp_claim_req(struct srp_target_port *target,
1043 } else { 1122 } else {
1044 scmnd = NULL; 1123 scmnd = NULL;
1045 } 1124 }
1046 spin_unlock_irqrestore(&target->lock, flags); 1125 spin_unlock_irqrestore(&ch->lock, flags);
1047 1126
1048 return scmnd; 1127 return scmnd;
1049} 1128}
1050 1129
1051/** 1130/**
1052 * srp_free_req() - Unmap data and add request to the free request list. 1131 * srp_free_req() - Unmap data and add request to the free request list.
1053 * @target: SRP target port. 1132 * @ch: SRP RDMA channel.
1054 * @req: Request to be freed. 1133 * @req: Request to be freed.
1055 * @scmnd: SCSI command associated with @req. 1134 * @scmnd: SCSI command associated with @req.
1056 * @req_lim_delta: Amount to be added to @target->req_lim. 1135 * @req_lim_delta: Amount to be added to @target->req_lim.
1057 */ 1136 */
1058static void srp_free_req(struct srp_target_port *target, 1137static void srp_free_req(struct srp_rdma_ch *ch, struct srp_request *req,
1059 struct srp_request *req, struct scsi_cmnd *scmnd, 1138 struct scsi_cmnd *scmnd, s32 req_lim_delta)
1060 s32 req_lim_delta)
1061{ 1139{
1062 unsigned long flags; 1140 unsigned long flags;
1063 1141
1064 srp_unmap_data(scmnd, target, req); 1142 srp_unmap_data(scmnd, ch, req);
1065 1143
1066 spin_lock_irqsave(&target->lock, flags); 1144 spin_lock_irqsave(&ch->lock, flags);
1067 target->req_lim += req_lim_delta; 1145 ch->req_lim += req_lim_delta;
1068 list_add_tail(&req->list, &target->free_reqs); 1146 spin_unlock_irqrestore(&ch->lock, flags);
1069 spin_unlock_irqrestore(&target->lock, flags);
1070} 1147}
1071 1148
1072static void srp_finish_req(struct srp_target_port *target, 1149static void srp_finish_req(struct srp_rdma_ch *ch, struct srp_request *req,
1073 struct srp_request *req, struct scsi_device *sdev, 1150 struct scsi_device *sdev, int result)
1074 int result)
1075{ 1151{
1076 struct scsi_cmnd *scmnd = srp_claim_req(target, req, sdev, NULL); 1152 struct scsi_cmnd *scmnd = srp_claim_req(ch, req, sdev, NULL);
1077 1153
1078 if (scmnd) { 1154 if (scmnd) {
1079 srp_free_req(target, req, scmnd, 0); 1155 srp_free_req(ch, req, scmnd, 0);
1080 scmnd->result = result; 1156 scmnd->result = result;
1081 scmnd->scsi_done(scmnd); 1157 scmnd->scsi_done(scmnd);
1082 } 1158 }
@@ -1085,9 +1161,10 @@ static void srp_finish_req(struct srp_target_port *target,
1085static void srp_terminate_io(struct srp_rport *rport) 1161static void srp_terminate_io(struct srp_rport *rport)
1086{ 1162{
1087 struct srp_target_port *target = rport->lld_data; 1163 struct srp_target_port *target = rport->lld_data;
1164 struct srp_rdma_ch *ch;
1088 struct Scsi_Host *shost = target->scsi_host; 1165 struct Scsi_Host *shost = target->scsi_host;
1089 struct scsi_device *sdev; 1166 struct scsi_device *sdev;
1090 int i; 1167 int i, j;
1091 1168
1092 /* 1169 /*
1093 * Invoking srp_terminate_io() while srp_queuecommand() is running 1170 * Invoking srp_terminate_io() while srp_queuecommand() is running
@@ -1096,9 +1173,15 @@ static void srp_terminate_io(struct srp_rport *rport)
1096 shost_for_each_device(sdev, shost) 1173 shost_for_each_device(sdev, shost)
1097 WARN_ON_ONCE(sdev->request_queue->request_fn_active); 1174 WARN_ON_ONCE(sdev->request_queue->request_fn_active);
1098 1175
1099 for (i = 0; i < target->req_ring_size; ++i) { 1176 for (i = 0; i < target->ch_count; i++) {
1100 struct srp_request *req = &target->req_ring[i]; 1177 ch = &target->ch[i];
1101 srp_finish_req(target, req, NULL, DID_TRANSPORT_FAILFAST << 16); 1178
1179 for (j = 0; j < target->req_ring_size; ++j) {
1180 struct srp_request *req = &ch->req_ring[j];
1181
1182 srp_finish_req(ch, req, NULL,
1183 DID_TRANSPORT_FAILFAST << 16);
1184 }
1102 } 1185 }
1103} 1186}
1104 1187
@@ -1114,34 +1197,61 @@ static void srp_terminate_io(struct srp_rport *rport)
1114static int srp_rport_reconnect(struct srp_rport *rport) 1197static int srp_rport_reconnect(struct srp_rport *rport)
1115{ 1198{
1116 struct srp_target_port *target = rport->lld_data; 1199 struct srp_target_port *target = rport->lld_data;
1117 int i, ret; 1200 struct srp_rdma_ch *ch;
1201 int i, j, ret = 0;
1202 bool multich = false;
1118 1203
1119 srp_disconnect_target(target); 1204 srp_disconnect_target(target);
1205
1206 if (target->state == SRP_TARGET_SCANNING)
1207 return -ENODEV;
1208
1120 /* 1209 /*
1121 * Now get a new local CM ID so that we avoid confusing the target in 1210 * Now get a new local CM ID so that we avoid confusing the target in
1122 * case things are really fouled up. Doing so also ensures that all CM 1211 * case things are really fouled up. Doing so also ensures that all CM
1123 * callbacks will have finished before a new QP is allocated. 1212 * callbacks will have finished before a new QP is allocated.
1124 */ 1213 */
1125 ret = srp_new_cm_id(target); 1214 for (i = 0; i < target->ch_count; i++) {
1126 1215 ch = &target->ch[i];
1127 for (i = 0; i < target->req_ring_size; ++i) { 1216 if (!ch->target)
1128 struct srp_request *req = &target->req_ring[i]; 1217 break;
1129 srp_finish_req(target, req, NULL, DID_RESET << 16); 1218 ret += srp_new_cm_id(ch);
1130 } 1219 }
1220 for (i = 0; i < target->ch_count; i++) {
1221 ch = &target->ch[i];
1222 if (!ch->target)
1223 break;
1224 for (j = 0; j < target->req_ring_size; ++j) {
1225 struct srp_request *req = &ch->req_ring[j];
1131 1226
1132 /* 1227 srp_finish_req(ch, req, NULL, DID_RESET << 16);
1133 * Whether or not creating a new CM ID succeeded, create a new 1228 }
1134 * QP. This guarantees that all callback functions for the old QP have 1229 }
1135 * finished before any send requests are posted on the new QP. 1230 for (i = 0; i < target->ch_count; i++) {
1136 */ 1231 ch = &target->ch[i];
1137 ret += srp_create_target_ib(target); 1232 if (!ch->target)
1138 1233 break;
1139 INIT_LIST_HEAD(&target->free_tx); 1234 /*
1140 for (i = 0; i < target->queue_size; ++i) 1235 * Whether or not creating a new CM ID succeeded, create a new
1141 list_add(&target->tx_ring[i]->list, &target->free_tx); 1236 * QP. This guarantees that all completion callback function
1237 * invocations have finished before request resetting starts.
1238 */
1239 ret += srp_create_ch_ib(ch);
1142 1240
1143 if (ret == 0) 1241 INIT_LIST_HEAD(&ch->free_tx);
1144 ret = srp_connect_target(target); 1242 for (j = 0; j < target->queue_size; ++j)
1243 list_add(&ch->tx_ring[j]->list, &ch->free_tx);
1244 }
1245 for (i = 0; i < target->ch_count; i++) {
1246 ch = &target->ch[i];
1247 if (ret || !ch->target) {
1248 if (i > 1)
1249 ret = 0;
1250 break;
1251 }
1252 ret = srp_connect_ch(ch, multich);
1253 multich = true;
1254 }
1145 1255
1146 if (ret == 0) 1256 if (ret == 0)
1147 shost_printk(KERN_INFO, target->scsi_host, 1257 shost_printk(KERN_INFO, target->scsi_host,
@@ -1165,12 +1275,12 @@ static void srp_map_desc(struct srp_map_state *state, dma_addr_t dma_addr,
1165} 1275}
1166 1276
1167static int srp_map_finish_fmr(struct srp_map_state *state, 1277static int srp_map_finish_fmr(struct srp_map_state *state,
1168 struct srp_target_port *target) 1278 struct srp_rdma_ch *ch)
1169{ 1279{
1170 struct ib_pool_fmr *fmr; 1280 struct ib_pool_fmr *fmr;
1171 u64 io_addr = 0; 1281 u64 io_addr = 0;
1172 1282
1173 fmr = ib_fmr_pool_map_phys(target->fmr_pool, state->pages, 1283 fmr = ib_fmr_pool_map_phys(ch->fmr_pool, state->pages,
1174 state->npages, io_addr); 1284 state->npages, io_addr);
1175 if (IS_ERR(fmr)) 1285 if (IS_ERR(fmr))
1176 return PTR_ERR(fmr); 1286 return PTR_ERR(fmr);
@@ -1184,15 +1294,16 @@ static int srp_map_finish_fmr(struct srp_map_state *state,
1184} 1294}
1185 1295
1186static int srp_map_finish_fr(struct srp_map_state *state, 1296static int srp_map_finish_fr(struct srp_map_state *state,
1187 struct srp_target_port *target) 1297 struct srp_rdma_ch *ch)
1188{ 1298{
1299 struct srp_target_port *target = ch->target;
1189 struct srp_device *dev = target->srp_host->srp_dev; 1300 struct srp_device *dev = target->srp_host->srp_dev;
1190 struct ib_send_wr *bad_wr; 1301 struct ib_send_wr *bad_wr;
1191 struct ib_send_wr wr; 1302 struct ib_send_wr wr;
1192 struct srp_fr_desc *desc; 1303 struct srp_fr_desc *desc;
1193 u32 rkey; 1304 u32 rkey;
1194 1305
1195 desc = srp_fr_pool_get(target->fr_pool); 1306 desc = srp_fr_pool_get(ch->fr_pool);
1196 if (!desc) 1307 if (!desc)
1197 return -ENOMEM; 1308 return -ENOMEM;
1198 1309
@@ -1221,12 +1332,13 @@ static int srp_map_finish_fr(struct srp_map_state *state,
1221 srp_map_desc(state, state->base_dma_addr, state->dma_len, 1332 srp_map_desc(state, state->base_dma_addr, state->dma_len,
1222 desc->mr->rkey); 1333 desc->mr->rkey);
1223 1334
1224 return ib_post_send(target->qp, &wr, &bad_wr); 1335 return ib_post_send(ch->qp, &wr, &bad_wr);
1225} 1336}
1226 1337
1227static int srp_finish_mapping(struct srp_map_state *state, 1338static int srp_finish_mapping(struct srp_map_state *state,
1228 struct srp_target_port *target) 1339 struct srp_rdma_ch *ch)
1229{ 1340{
1341 struct srp_target_port *target = ch->target;
1230 int ret = 0; 1342 int ret = 0;
1231 1343
1232 if (state->npages == 0) 1344 if (state->npages == 0)
@@ -1237,8 +1349,8 @@ static int srp_finish_mapping(struct srp_map_state *state,
1237 target->rkey); 1349 target->rkey);
1238 else 1350 else
1239 ret = target->srp_host->srp_dev->use_fast_reg ? 1351 ret = target->srp_host->srp_dev->use_fast_reg ?
1240 srp_map_finish_fr(state, target) : 1352 srp_map_finish_fr(state, ch) :
1241 srp_map_finish_fmr(state, target); 1353 srp_map_finish_fmr(state, ch);
1242 1354
1243 if (ret == 0) { 1355 if (ret == 0) {
1244 state->npages = 0; 1356 state->npages = 0;
@@ -1258,10 +1370,11 @@ static void srp_map_update_start(struct srp_map_state *state,
1258} 1370}
1259 1371
1260static int srp_map_sg_entry(struct srp_map_state *state, 1372static int srp_map_sg_entry(struct srp_map_state *state,
1261 struct srp_target_port *target, 1373 struct srp_rdma_ch *ch,
1262 struct scatterlist *sg, int sg_index, 1374 struct scatterlist *sg, int sg_index,
1263 bool use_mr) 1375 bool use_mr)
1264{ 1376{
1377 struct srp_target_port *target = ch->target;
1265 struct srp_device *dev = target->srp_host->srp_dev; 1378 struct srp_device *dev = target->srp_host->srp_dev;
1266 struct ib_device *ibdev = dev->dev; 1379 struct ib_device *ibdev = dev->dev;
1267 dma_addr_t dma_addr = ib_sg_dma_address(ibdev, sg); 1380 dma_addr_t dma_addr = ib_sg_dma_address(ibdev, sg);
@@ -1290,7 +1403,7 @@ static int srp_map_sg_entry(struct srp_map_state *state,
1290 */ 1403 */
1291 if ((!dev->use_fast_reg && dma_addr & ~dev->mr_page_mask) || 1404 if ((!dev->use_fast_reg && dma_addr & ~dev->mr_page_mask) ||
1292 dma_len > dev->mr_max_size) { 1405 dma_len > dev->mr_max_size) {
1293 ret = srp_finish_mapping(state, target); 1406 ret = srp_finish_mapping(state, ch);
1294 if (ret) 1407 if (ret)
1295 return ret; 1408 return ret;
1296 1409
@@ -1311,7 +1424,7 @@ static int srp_map_sg_entry(struct srp_map_state *state,
1311 while (dma_len) { 1424 while (dma_len) {
1312 unsigned offset = dma_addr & ~dev->mr_page_mask; 1425 unsigned offset = dma_addr & ~dev->mr_page_mask;
1313 if (state->npages == dev->max_pages_per_mr || offset != 0) { 1426 if (state->npages == dev->max_pages_per_mr || offset != 0) {
1314 ret = srp_finish_mapping(state, target); 1427 ret = srp_finish_mapping(state, ch);
1315 if (ret) 1428 if (ret)
1316 return ret; 1429 return ret;
1317 1430
@@ -1335,17 +1448,18 @@ static int srp_map_sg_entry(struct srp_map_state *state,
1335 */ 1448 */
1336 ret = 0; 1449 ret = 0;
1337 if (len != dev->mr_page_size) { 1450 if (len != dev->mr_page_size) {
1338 ret = srp_finish_mapping(state, target); 1451 ret = srp_finish_mapping(state, ch);
1339 if (!ret) 1452 if (!ret)
1340 srp_map_update_start(state, NULL, 0, 0); 1453 srp_map_update_start(state, NULL, 0, 0);
1341 } 1454 }
1342 return ret; 1455 return ret;
1343} 1456}
1344 1457
1345static int srp_map_sg(struct srp_map_state *state, 1458static int srp_map_sg(struct srp_map_state *state, struct srp_rdma_ch *ch,
1346 struct srp_target_port *target, struct srp_request *req, 1459 struct srp_request *req, struct scatterlist *scat,
1347 struct scatterlist *scat, int count) 1460 int count)
1348{ 1461{
1462 struct srp_target_port *target = ch->target;
1349 struct srp_device *dev = target->srp_host->srp_dev; 1463 struct srp_device *dev = target->srp_host->srp_dev;
1350 struct ib_device *ibdev = dev->dev; 1464 struct ib_device *ibdev = dev->dev;
1351 struct scatterlist *sg; 1465 struct scatterlist *sg;
@@ -1356,14 +1470,14 @@ static int srp_map_sg(struct srp_map_state *state,
1356 state->pages = req->map_page; 1470 state->pages = req->map_page;
1357 if (dev->use_fast_reg) { 1471 if (dev->use_fast_reg) {
1358 state->next_fr = req->fr_list; 1472 state->next_fr = req->fr_list;
1359 use_mr = !!target->fr_pool; 1473 use_mr = !!ch->fr_pool;
1360 } else { 1474 } else {
1361 state->next_fmr = req->fmr_list; 1475 state->next_fmr = req->fmr_list;
1362 use_mr = !!target->fmr_pool; 1476 use_mr = !!ch->fmr_pool;
1363 } 1477 }
1364 1478
1365 for_each_sg(scat, sg, count, i) { 1479 for_each_sg(scat, sg, count, i) {
1366 if (srp_map_sg_entry(state, target, sg, i, use_mr)) { 1480 if (srp_map_sg_entry(state, ch, sg, i, use_mr)) {
1367 /* 1481 /*
1368 * Memory registration failed, so backtrack to the 1482 * Memory registration failed, so backtrack to the
1369 * first unmapped entry and continue on without using 1483 * first unmapped entry and continue on without using
@@ -1385,7 +1499,7 @@ backtrack:
1385 } 1499 }
1386 } 1500 }
1387 1501
1388 if (use_mr && srp_finish_mapping(state, target)) 1502 if (use_mr && srp_finish_mapping(state, ch))
1389 goto backtrack; 1503 goto backtrack;
1390 1504
1391 req->nmdesc = state->nmdesc; 1505 req->nmdesc = state->nmdesc;
@@ -1393,9 +1507,10 @@ backtrack:
1393 return 0; 1507 return 0;
1394} 1508}
1395 1509
1396static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_target_port *target, 1510static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_rdma_ch *ch,
1397 struct srp_request *req) 1511 struct srp_request *req)
1398{ 1512{
1513 struct srp_target_port *target = ch->target;
1399 struct scatterlist *scat; 1514 struct scatterlist *scat;
1400 struct srp_cmd *cmd = req->cmd->buf; 1515 struct srp_cmd *cmd = req->cmd->buf;
1401 int len, nents, count; 1516 int len, nents, count;
@@ -1457,7 +1572,7 @@ static int srp_map_data(struct scsi_cmnd *scmnd, struct srp_target_port *target,
1457 target->indirect_size, DMA_TO_DEVICE); 1572 target->indirect_size, DMA_TO_DEVICE);
1458 1573
1459 memset(&state, 0, sizeof(state)); 1574 memset(&state, 0, sizeof(state));
1460 srp_map_sg(&state, target, req, scat, count); 1575 srp_map_sg(&state, ch, req, scat, count);
1461 1576
1462 /* We've mapped the request, now pull as much of the indirect 1577 /* We've mapped the request, now pull as much of the indirect
1463 * descriptor table as we can into the command buffer. If this 1578 * descriptor table as we can into the command buffer. If this
@@ -1518,20 +1633,20 @@ map_complete:
1518/* 1633/*
1519 * Return an IU and possible credit to the free pool 1634 * Return an IU and possible credit to the free pool
1520 */ 1635 */
1521static void srp_put_tx_iu(struct srp_target_port *target, struct srp_iu *iu, 1636static void srp_put_tx_iu(struct srp_rdma_ch *ch, struct srp_iu *iu,
1522 enum srp_iu_type iu_type) 1637 enum srp_iu_type iu_type)
1523{ 1638{
1524 unsigned long flags; 1639 unsigned long flags;
1525 1640
1526 spin_lock_irqsave(&target->lock, flags); 1641 spin_lock_irqsave(&ch->lock, flags);
1527 list_add(&iu->list, &target->free_tx); 1642 list_add(&iu->list, &ch->free_tx);
1528 if (iu_type != SRP_IU_RSP) 1643 if (iu_type != SRP_IU_RSP)
1529 ++target->req_lim; 1644 ++ch->req_lim;
1530 spin_unlock_irqrestore(&target->lock, flags); 1645 spin_unlock_irqrestore(&ch->lock, flags);
1531} 1646}
1532 1647
1533/* 1648/*
1534 * Must be called with target->lock held to protect req_lim and free_tx. 1649 * Must be called with ch->lock held to protect req_lim and free_tx.
1535 * If IU is not sent, it must be returned using srp_put_tx_iu(). 1650 * If IU is not sent, it must be returned using srp_put_tx_iu().
1536 * 1651 *
1537 * Note: 1652 * Note:
@@ -1543,35 +1658,36 @@ static void srp_put_tx_iu(struct srp_target_port *target, struct srp_iu *iu,
1543 * - SRP_IU_RSP: 1, since a conforming SRP target never sends more than 1658 * - SRP_IU_RSP: 1, since a conforming SRP target never sends more than
1544 * one unanswered SRP request to an initiator. 1659 * one unanswered SRP request to an initiator.
1545 */ 1660 */
1546static struct srp_iu *__srp_get_tx_iu(struct srp_target_port *target, 1661static struct srp_iu *__srp_get_tx_iu(struct srp_rdma_ch *ch,
1547 enum srp_iu_type iu_type) 1662 enum srp_iu_type iu_type)
1548{ 1663{
1664 struct srp_target_port *target = ch->target;
1549 s32 rsv = (iu_type == SRP_IU_TSK_MGMT) ? 0 : SRP_TSK_MGMT_SQ_SIZE; 1665 s32 rsv = (iu_type == SRP_IU_TSK_MGMT) ? 0 : SRP_TSK_MGMT_SQ_SIZE;
1550 struct srp_iu *iu; 1666 struct srp_iu *iu;
1551 1667
1552 srp_send_completion(target->send_cq, target); 1668 srp_send_completion(ch->send_cq, ch);
1553 1669
1554 if (list_empty(&target->free_tx)) 1670 if (list_empty(&ch->free_tx))
1555 return NULL; 1671 return NULL;
1556 1672
1557 /* Initiator responses to target requests do not consume credits */ 1673 /* Initiator responses to target requests do not consume credits */
1558 if (iu_type != SRP_IU_RSP) { 1674 if (iu_type != SRP_IU_RSP) {
1559 if (target->req_lim <= rsv) { 1675 if (ch->req_lim <= rsv) {
1560 ++target->zero_req_lim; 1676 ++target->zero_req_lim;
1561 return NULL; 1677 return NULL;
1562 } 1678 }
1563 1679
1564 --target->req_lim; 1680 --ch->req_lim;
1565 } 1681 }
1566 1682
1567 iu = list_first_entry(&target->free_tx, struct srp_iu, list); 1683 iu = list_first_entry(&ch->free_tx, struct srp_iu, list);
1568 list_del(&iu->list); 1684 list_del(&iu->list);
1569 return iu; 1685 return iu;
1570} 1686}
1571 1687
1572static int srp_post_send(struct srp_target_port *target, 1688static int srp_post_send(struct srp_rdma_ch *ch, struct srp_iu *iu, int len)
1573 struct srp_iu *iu, int len)
1574{ 1689{
1690 struct srp_target_port *target = ch->target;
1575 struct ib_sge list; 1691 struct ib_sge list;
1576 struct ib_send_wr wr, *bad_wr; 1692 struct ib_send_wr wr, *bad_wr;
1577 1693
@@ -1586,11 +1702,12 @@ static int srp_post_send(struct srp_target_port *target,
1586 wr.opcode = IB_WR_SEND; 1702 wr.opcode = IB_WR_SEND;
1587 wr.send_flags = IB_SEND_SIGNALED; 1703 wr.send_flags = IB_SEND_SIGNALED;
1588 1704
1589 return ib_post_send(target->qp, &wr, &bad_wr); 1705 return ib_post_send(ch->qp, &wr, &bad_wr);
1590} 1706}
1591 1707
1592static int srp_post_recv(struct srp_target_port *target, struct srp_iu *iu) 1708static int srp_post_recv(struct srp_rdma_ch *ch, struct srp_iu *iu)
1593{ 1709{
1710 struct srp_target_port *target = ch->target;
1594 struct ib_recv_wr wr, *bad_wr; 1711 struct ib_recv_wr wr, *bad_wr;
1595 struct ib_sge list; 1712 struct ib_sge list;
1596 1713
@@ -1603,35 +1720,39 @@ static int srp_post_recv(struct srp_target_port *target, struct srp_iu *iu)
1603 wr.sg_list = &list; 1720 wr.sg_list = &list;
1604 wr.num_sge = 1; 1721 wr.num_sge = 1;
1605 1722
1606 return ib_post_recv(target->qp, &wr, &bad_wr); 1723 return ib_post_recv(ch->qp, &wr, &bad_wr);
1607} 1724}
1608 1725
1609static void srp_process_rsp(struct srp_target_port *target, struct srp_rsp *rsp) 1726static void srp_process_rsp(struct srp_rdma_ch *ch, struct srp_rsp *rsp)
1610{ 1727{
1728 struct srp_target_port *target = ch->target;
1611 struct srp_request *req; 1729 struct srp_request *req;
1612 struct scsi_cmnd *scmnd; 1730 struct scsi_cmnd *scmnd;
1613 unsigned long flags; 1731 unsigned long flags;
1614 1732
1615 if (unlikely(rsp->tag & SRP_TAG_TSK_MGMT)) { 1733 if (unlikely(rsp->tag & SRP_TAG_TSK_MGMT)) {
1616 spin_lock_irqsave(&target->lock, flags); 1734 spin_lock_irqsave(&ch->lock, flags);
1617 target->req_lim += be32_to_cpu(rsp->req_lim_delta); 1735 ch->req_lim += be32_to_cpu(rsp->req_lim_delta);
1618 spin_unlock_irqrestore(&target->lock, flags); 1736 spin_unlock_irqrestore(&ch->lock, flags);
1619 1737
1620 target->tsk_mgmt_status = -1; 1738 ch->tsk_mgmt_status = -1;
1621 if (be32_to_cpu(rsp->resp_data_len) >= 4) 1739 if (be32_to_cpu(rsp->resp_data_len) >= 4)
1622 target->tsk_mgmt_status = rsp->data[3]; 1740 ch->tsk_mgmt_status = rsp->data[3];
1623 complete(&target->tsk_mgmt_done); 1741 complete(&ch->tsk_mgmt_done);
1624 } else { 1742 } else {
1625 req = &target->req_ring[rsp->tag]; 1743 scmnd = scsi_host_find_tag(target->scsi_host, rsp->tag);
1626 scmnd = srp_claim_req(target, req, NULL, NULL); 1744 if (scmnd) {
1745 req = (void *)scmnd->host_scribble;
1746 scmnd = srp_claim_req(ch, req, NULL, scmnd);
1747 }
1627 if (!scmnd) { 1748 if (!scmnd) {
1628 shost_printk(KERN_ERR, target->scsi_host, 1749 shost_printk(KERN_ERR, target->scsi_host,
1629 "Null scmnd for RSP w/tag %016llx\n", 1750 "Null scmnd for RSP w/tag %#016llx received on ch %td / QP %#x\n",
1630 (unsigned long long) rsp->tag); 1751 rsp->tag, ch - target->ch, ch->qp->qp_num);
1631 1752
1632 spin_lock_irqsave(&target->lock, flags); 1753 spin_lock_irqsave(&ch->lock, flags);
1633 target->req_lim += be32_to_cpu(rsp->req_lim_delta); 1754 ch->req_lim += be32_to_cpu(rsp->req_lim_delta);
1634 spin_unlock_irqrestore(&target->lock, flags); 1755 spin_unlock_irqrestore(&ch->lock, flags);
1635 1756
1636 return; 1757 return;
1637 } 1758 }
@@ -1653,7 +1774,7 @@ static void srp_process_rsp(struct srp_target_port *target, struct srp_rsp *rsp)
1653 else if (unlikely(rsp->flags & SRP_RSP_FLAG_DOOVER)) 1774 else if (unlikely(rsp->flags & SRP_RSP_FLAG_DOOVER))
1654 scsi_set_resid(scmnd, -be32_to_cpu(rsp->data_out_res_cnt)); 1775 scsi_set_resid(scmnd, -be32_to_cpu(rsp->data_out_res_cnt));
1655 1776
1656 srp_free_req(target, req, scmnd, 1777 srp_free_req(ch, req, scmnd,
1657 be32_to_cpu(rsp->req_lim_delta)); 1778 be32_to_cpu(rsp->req_lim_delta));
1658 1779
1659 scmnd->host_scribble = NULL; 1780 scmnd->host_scribble = NULL;
@@ -1661,18 +1782,19 @@ static void srp_process_rsp(struct srp_target_port *target, struct srp_rsp *rsp)
1661 } 1782 }
1662} 1783}
1663 1784
1664static int srp_response_common(struct srp_target_port *target, s32 req_delta, 1785static int srp_response_common(struct srp_rdma_ch *ch, s32 req_delta,
1665 void *rsp, int len) 1786 void *rsp, int len)
1666{ 1787{
1788 struct srp_target_port *target = ch->target;
1667 struct ib_device *dev = target->srp_host->srp_dev->dev; 1789 struct ib_device *dev = target->srp_host->srp_dev->dev;
1668 unsigned long flags; 1790 unsigned long flags;
1669 struct srp_iu *iu; 1791 struct srp_iu *iu;
1670 int err; 1792 int err;
1671 1793
1672 spin_lock_irqsave(&target->lock, flags); 1794 spin_lock_irqsave(&ch->lock, flags);
1673 target->req_lim += req_delta; 1795 ch->req_lim += req_delta;
1674 iu = __srp_get_tx_iu(target, SRP_IU_RSP); 1796 iu = __srp_get_tx_iu(ch, SRP_IU_RSP);
1675 spin_unlock_irqrestore(&target->lock, flags); 1797 spin_unlock_irqrestore(&ch->lock, flags);
1676 1798
1677 if (!iu) { 1799 if (!iu) {
1678 shost_printk(KERN_ERR, target->scsi_host, PFX 1800 shost_printk(KERN_ERR, target->scsi_host, PFX
@@ -1684,17 +1806,17 @@ static int srp_response_common(struct srp_target_port *target, s32 req_delta,
1684 memcpy(iu->buf, rsp, len); 1806 memcpy(iu->buf, rsp, len);
1685 ib_dma_sync_single_for_device(dev, iu->dma, len, DMA_TO_DEVICE); 1807 ib_dma_sync_single_for_device(dev, iu->dma, len, DMA_TO_DEVICE);
1686 1808
1687 err = srp_post_send(target, iu, len); 1809 err = srp_post_send(ch, iu, len);
1688 if (err) { 1810 if (err) {
1689 shost_printk(KERN_ERR, target->scsi_host, PFX 1811 shost_printk(KERN_ERR, target->scsi_host, PFX
1690 "unable to post response: %d\n", err); 1812 "unable to post response: %d\n", err);
1691 srp_put_tx_iu(target, iu, SRP_IU_RSP); 1813 srp_put_tx_iu(ch, iu, SRP_IU_RSP);
1692 } 1814 }
1693 1815
1694 return err; 1816 return err;
1695} 1817}
1696 1818
1697static void srp_process_cred_req(struct srp_target_port *target, 1819static void srp_process_cred_req(struct srp_rdma_ch *ch,
1698 struct srp_cred_req *req) 1820 struct srp_cred_req *req)
1699{ 1821{
1700 struct srp_cred_rsp rsp = { 1822 struct srp_cred_rsp rsp = {
@@ -1703,14 +1825,15 @@ static void srp_process_cred_req(struct srp_target_port *target,
1703 }; 1825 };
1704 s32 delta = be32_to_cpu(req->req_lim_delta); 1826 s32 delta = be32_to_cpu(req->req_lim_delta);
1705 1827
1706 if (srp_response_common(target, delta, &rsp, sizeof rsp)) 1828 if (srp_response_common(ch, delta, &rsp, sizeof(rsp)))
1707 shost_printk(KERN_ERR, target->scsi_host, PFX 1829 shost_printk(KERN_ERR, ch->target->scsi_host, PFX
1708 "problems processing SRP_CRED_REQ\n"); 1830 "problems processing SRP_CRED_REQ\n");
1709} 1831}
1710 1832
1711static void srp_process_aer_req(struct srp_target_port *target, 1833static void srp_process_aer_req(struct srp_rdma_ch *ch,
1712 struct srp_aer_req *req) 1834 struct srp_aer_req *req)
1713{ 1835{
1836 struct srp_target_port *target = ch->target;
1714 struct srp_aer_rsp rsp = { 1837 struct srp_aer_rsp rsp = {
1715 .opcode = SRP_AER_RSP, 1838 .opcode = SRP_AER_RSP,
1716 .tag = req->tag, 1839 .tag = req->tag,
@@ -1720,19 +1843,20 @@ static void srp_process_aer_req(struct srp_target_port *target,
1720 shost_printk(KERN_ERR, target->scsi_host, PFX 1843 shost_printk(KERN_ERR, target->scsi_host, PFX
1721 "ignoring AER for LUN %llu\n", be64_to_cpu(req->lun)); 1844 "ignoring AER for LUN %llu\n", be64_to_cpu(req->lun));
1722 1845
1723 if (srp_response_common(target, delta, &rsp, sizeof rsp)) 1846 if (srp_response_common(ch, delta, &rsp, sizeof(rsp)))
1724 shost_printk(KERN_ERR, target->scsi_host, PFX 1847 shost_printk(KERN_ERR, target->scsi_host, PFX
1725 "problems processing SRP_AER_REQ\n"); 1848 "problems processing SRP_AER_REQ\n");
1726} 1849}
1727 1850
1728static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc) 1851static void srp_handle_recv(struct srp_rdma_ch *ch, struct ib_wc *wc)
1729{ 1852{
1853 struct srp_target_port *target = ch->target;
1730 struct ib_device *dev = target->srp_host->srp_dev->dev; 1854 struct ib_device *dev = target->srp_host->srp_dev->dev;
1731 struct srp_iu *iu = (struct srp_iu *) (uintptr_t) wc->wr_id; 1855 struct srp_iu *iu = (struct srp_iu *) (uintptr_t) wc->wr_id;
1732 int res; 1856 int res;
1733 u8 opcode; 1857 u8 opcode;
1734 1858
1735 ib_dma_sync_single_for_cpu(dev, iu->dma, target->max_ti_iu_len, 1859 ib_dma_sync_single_for_cpu(dev, iu->dma, ch->max_ti_iu_len,
1736 DMA_FROM_DEVICE); 1860 DMA_FROM_DEVICE);
1737 1861
1738 opcode = *(u8 *) iu->buf; 1862 opcode = *(u8 *) iu->buf;
@@ -1746,15 +1870,15 @@ static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc)
1746 1870
1747 switch (opcode) { 1871 switch (opcode) {
1748 case SRP_RSP: 1872 case SRP_RSP:
1749 srp_process_rsp(target, iu->buf); 1873 srp_process_rsp(ch, iu->buf);
1750 break; 1874 break;
1751 1875
1752 case SRP_CRED_REQ: 1876 case SRP_CRED_REQ:
1753 srp_process_cred_req(target, iu->buf); 1877 srp_process_cred_req(ch, iu->buf);
1754 break; 1878 break;
1755 1879
1756 case SRP_AER_REQ: 1880 case SRP_AER_REQ:
1757 srp_process_aer_req(target, iu->buf); 1881 srp_process_aer_req(ch, iu->buf);
1758 break; 1882 break;
1759 1883
1760 case SRP_T_LOGOUT: 1884 case SRP_T_LOGOUT:
@@ -1769,10 +1893,10 @@ static void srp_handle_recv(struct srp_target_port *target, struct ib_wc *wc)
1769 break; 1893 break;
1770 } 1894 }
1771 1895
1772 ib_dma_sync_single_for_device(dev, iu->dma, target->max_ti_iu_len, 1896 ib_dma_sync_single_for_device(dev, iu->dma, ch->max_ti_iu_len,
1773 DMA_FROM_DEVICE); 1897 DMA_FROM_DEVICE);
1774 1898
1775 res = srp_post_recv(target, iu); 1899 res = srp_post_recv(ch, iu);
1776 if (res != 0) 1900 if (res != 0)
1777 shost_printk(KERN_ERR, target->scsi_host, 1901 shost_printk(KERN_ERR, target->scsi_host,
1778 PFX "Recv failed with error code %d\n", res); 1902 PFX "Recv failed with error code %d\n", res);
@@ -1795,8 +1919,15 @@ static void srp_tl_err_work(struct work_struct *work)
1795} 1919}
1796 1920
1797static void srp_handle_qp_err(u64 wr_id, enum ib_wc_status wc_status, 1921static void srp_handle_qp_err(u64 wr_id, enum ib_wc_status wc_status,
1798 bool send_err, struct srp_target_port *target) 1922 bool send_err, struct srp_rdma_ch *ch)
1799{ 1923{
1924 struct srp_target_port *target = ch->target;
1925
1926 if (wr_id == SRP_LAST_WR_ID) {
1927 complete(&ch->done);
1928 return;
1929 }
1930
1800 if (target->connected && !target->qp_in_error) { 1931 if (target->connected && !target->qp_in_error) {
1801 if (wr_id & LOCAL_INV_WR_ID_MASK) { 1932 if (wr_id & LOCAL_INV_WR_ID_MASK) {
1802 shost_printk(KERN_ERR, target->scsi_host, PFX 1933 shost_printk(KERN_ERR, target->scsi_host, PFX
@@ -1817,33 +1948,33 @@ static void srp_handle_qp_err(u64 wr_id, enum ib_wc_status wc_status,
1817 target->qp_in_error = true; 1948 target->qp_in_error = true;
1818} 1949}
1819 1950
1820static void srp_recv_completion(struct ib_cq *cq, void *target_ptr) 1951static void srp_recv_completion(struct ib_cq *cq, void *ch_ptr)
1821{ 1952{
1822 struct srp_target_port *target = target_ptr; 1953 struct srp_rdma_ch *ch = ch_ptr;
1823 struct ib_wc wc; 1954 struct ib_wc wc;
1824 1955
1825 ib_req_notify_cq(cq, IB_CQ_NEXT_COMP); 1956 ib_req_notify_cq(cq, IB_CQ_NEXT_COMP);
1826 while (ib_poll_cq(cq, 1, &wc) > 0) { 1957 while (ib_poll_cq(cq, 1, &wc) > 0) {
1827 if (likely(wc.status == IB_WC_SUCCESS)) { 1958 if (likely(wc.status == IB_WC_SUCCESS)) {
1828 srp_handle_recv(target, &wc); 1959 srp_handle_recv(ch, &wc);
1829 } else { 1960 } else {
1830 srp_handle_qp_err(wc.wr_id, wc.status, false, target); 1961 srp_handle_qp_err(wc.wr_id, wc.status, false, ch);
1831 } 1962 }
1832 } 1963 }
1833} 1964}
1834 1965
1835static void srp_send_completion(struct ib_cq *cq, void *target_ptr) 1966static void srp_send_completion(struct ib_cq *cq, void *ch_ptr)
1836{ 1967{
1837 struct srp_target_port *target = target_ptr; 1968 struct srp_rdma_ch *ch = ch_ptr;
1838 struct ib_wc wc; 1969 struct ib_wc wc;
1839 struct srp_iu *iu; 1970 struct srp_iu *iu;
1840 1971
1841 while (ib_poll_cq(cq, 1, &wc) > 0) { 1972 while (ib_poll_cq(cq, 1, &wc) > 0) {
1842 if (likely(wc.status == IB_WC_SUCCESS)) { 1973 if (likely(wc.status == IB_WC_SUCCESS)) {
1843 iu = (struct srp_iu *) (uintptr_t) wc.wr_id; 1974 iu = (struct srp_iu *) (uintptr_t) wc.wr_id;
1844 list_add(&iu->list, &target->free_tx); 1975 list_add(&iu->list, &ch->free_tx);
1845 } else { 1976 } else {
1846 srp_handle_qp_err(wc.wr_id, wc.status, true, target); 1977 srp_handle_qp_err(wc.wr_id, wc.status, true, ch);
1847 } 1978 }
1848 } 1979 }
1849} 1980}
@@ -1852,11 +1983,14 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
1852{ 1983{
1853 struct srp_target_port *target = host_to_target(shost); 1984 struct srp_target_port *target = host_to_target(shost);
1854 struct srp_rport *rport = target->rport; 1985 struct srp_rport *rport = target->rport;
1986 struct srp_rdma_ch *ch;
1855 struct srp_request *req; 1987 struct srp_request *req;
1856 struct srp_iu *iu; 1988 struct srp_iu *iu;
1857 struct srp_cmd *cmd; 1989 struct srp_cmd *cmd;
1858 struct ib_device *dev; 1990 struct ib_device *dev;
1859 unsigned long flags; 1991 unsigned long flags;
1992 u32 tag;
1993 u16 idx;
1860 int len, ret; 1994 int len, ret;
1861 const bool in_scsi_eh = !in_interrupt() && current == shost->ehandler; 1995 const bool in_scsi_eh = !in_interrupt() && current == shost->ehandler;
1862 1996
@@ -1873,15 +2007,22 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
1873 if (unlikely(scmnd->result)) 2007 if (unlikely(scmnd->result))
1874 goto err; 2008 goto err;
1875 2009
1876 spin_lock_irqsave(&target->lock, flags); 2010 WARN_ON_ONCE(scmnd->request->tag < 0);
1877 iu = __srp_get_tx_iu(target, SRP_IU_CMD); 2011 tag = blk_mq_unique_tag(scmnd->request);
1878 if (!iu) 2012 ch = &target->ch[blk_mq_unique_tag_to_hwq(tag)];
1879 goto err_unlock; 2013 idx = blk_mq_unique_tag_to_tag(tag);
2014 WARN_ONCE(idx >= target->req_ring_size, "%s: tag %#x: idx %d >= %d\n",
2015 dev_name(&shost->shost_gendev), tag, idx,
2016 target->req_ring_size);
1880 2017
1881 req = list_first_entry(&target->free_reqs, struct srp_request, list); 2018 spin_lock_irqsave(&ch->lock, flags);
1882 list_del(&req->list); 2019 iu = __srp_get_tx_iu(ch, SRP_IU_CMD);
1883 spin_unlock_irqrestore(&target->lock, flags); 2020 spin_unlock_irqrestore(&ch->lock, flags);
1884 2021
2022 if (!iu)
2023 goto err;
2024
2025 req = &ch->req_ring[idx];
1885 dev = target->srp_host->srp_dev->dev; 2026 dev = target->srp_host->srp_dev->dev;
1886 ib_dma_sync_single_for_cpu(dev, iu->dma, target->max_iu_len, 2027 ib_dma_sync_single_for_cpu(dev, iu->dma, target->max_iu_len,
1887 DMA_TO_DEVICE); 2028 DMA_TO_DEVICE);
@@ -1893,13 +2034,13 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
1893 2034
1894 cmd->opcode = SRP_CMD; 2035 cmd->opcode = SRP_CMD;
1895 cmd->lun = cpu_to_be64((u64) scmnd->device->lun << 48); 2036 cmd->lun = cpu_to_be64((u64) scmnd->device->lun << 48);
1896 cmd->tag = req->index; 2037 cmd->tag = tag;
1897 memcpy(cmd->cdb, scmnd->cmnd, scmnd->cmd_len); 2038 memcpy(cmd->cdb, scmnd->cmnd, scmnd->cmd_len);
1898 2039
1899 req->scmnd = scmnd; 2040 req->scmnd = scmnd;
1900 req->cmd = iu; 2041 req->cmd = iu;
1901 2042
1902 len = srp_map_data(scmnd, target, req); 2043 len = srp_map_data(scmnd, ch, req);
1903 if (len < 0) { 2044 if (len < 0) {
1904 shost_printk(KERN_ERR, target->scsi_host, 2045 shost_printk(KERN_ERR, target->scsi_host,
1905 PFX "Failed to map data (%d)\n", len); 2046 PFX "Failed to map data (%d)\n", len);
@@ -1917,7 +2058,7 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
1917 ib_dma_sync_single_for_device(dev, iu->dma, target->max_iu_len, 2058 ib_dma_sync_single_for_device(dev, iu->dma, target->max_iu_len,
1918 DMA_TO_DEVICE); 2059 DMA_TO_DEVICE);
1919 2060
1920 if (srp_post_send(target, iu, len)) { 2061 if (srp_post_send(ch, iu, len)) {
1921 shost_printk(KERN_ERR, target->scsi_host, PFX "Send failed\n"); 2062 shost_printk(KERN_ERR, target->scsi_host, PFX "Send failed\n");
1922 goto err_unmap; 2063 goto err_unmap;
1923 } 2064 }
@@ -1931,10 +2072,10 @@ unlock_rport:
1931 return ret; 2072 return ret;
1932 2073
1933err_unmap: 2074err_unmap:
1934 srp_unmap_data(scmnd, target, req); 2075 srp_unmap_data(scmnd, ch, req);
1935 2076
1936err_iu: 2077err_iu:
1937 srp_put_tx_iu(target, iu, SRP_IU_CMD); 2078 srp_put_tx_iu(ch, iu, SRP_IU_CMD);
1938 2079
1939 /* 2080 /*
1940 * Avoid that the loops that iterate over the request ring can 2081 * Avoid that the loops that iterate over the request ring can
@@ -1942,12 +2083,6 @@ err_iu:
1942 */ 2083 */
1943 req->scmnd = NULL; 2084 req->scmnd = NULL;
1944 2085
1945 spin_lock_irqsave(&target->lock, flags);
1946 list_add(&req->list, &target->free_reqs);
1947
1948err_unlock:
1949 spin_unlock_irqrestore(&target->lock, flags);
1950
1951err: 2086err:
1952 if (scmnd->result) { 2087 if (scmnd->result) {
1953 scmnd->scsi_done(scmnd); 2088 scmnd->scsi_done(scmnd);
@@ -1961,53 +2096,54 @@ err:
1961 2096
1962/* 2097/*
1963 * Note: the resources allocated in this function are freed in 2098 * Note: the resources allocated in this function are freed in
1964 * srp_free_target_ib(). 2099 * srp_free_ch_ib().
1965 */ 2100 */
1966static int srp_alloc_iu_bufs(struct srp_target_port *target) 2101static int srp_alloc_iu_bufs(struct srp_rdma_ch *ch)
1967{ 2102{
2103 struct srp_target_port *target = ch->target;
1968 int i; 2104 int i;
1969 2105
1970 target->rx_ring = kzalloc(target->queue_size * sizeof(*target->rx_ring), 2106 ch->rx_ring = kcalloc(target->queue_size, sizeof(*ch->rx_ring),
1971 GFP_KERNEL); 2107 GFP_KERNEL);
1972 if (!target->rx_ring) 2108 if (!ch->rx_ring)
1973 goto err_no_ring; 2109 goto err_no_ring;
1974 target->tx_ring = kzalloc(target->queue_size * sizeof(*target->tx_ring), 2110 ch->tx_ring = kcalloc(target->queue_size, sizeof(*ch->tx_ring),
1975 GFP_KERNEL); 2111 GFP_KERNEL);
1976 if (!target->tx_ring) 2112 if (!ch->tx_ring)
1977 goto err_no_ring; 2113 goto err_no_ring;
1978 2114
1979 for (i = 0; i < target->queue_size; ++i) { 2115 for (i = 0; i < target->queue_size; ++i) {
1980 target->rx_ring[i] = srp_alloc_iu(target->srp_host, 2116 ch->rx_ring[i] = srp_alloc_iu(target->srp_host,
1981 target->max_ti_iu_len, 2117 ch->max_ti_iu_len,
1982 GFP_KERNEL, DMA_FROM_DEVICE); 2118 GFP_KERNEL, DMA_FROM_DEVICE);
1983 if (!target->rx_ring[i]) 2119 if (!ch->rx_ring[i])
1984 goto err; 2120 goto err;
1985 } 2121 }
1986 2122
1987 for (i = 0; i < target->queue_size; ++i) { 2123 for (i = 0; i < target->queue_size; ++i) {
1988 target->tx_ring[i] = srp_alloc_iu(target->srp_host, 2124 ch->tx_ring[i] = srp_alloc_iu(target->srp_host,
1989 target->max_iu_len, 2125 target->max_iu_len,
1990 GFP_KERNEL, DMA_TO_DEVICE); 2126 GFP_KERNEL, DMA_TO_DEVICE);
1991 if (!target->tx_ring[i]) 2127 if (!ch->tx_ring[i])
1992 goto err; 2128 goto err;
1993 2129
1994 list_add(&target->tx_ring[i]->list, &target->free_tx); 2130 list_add(&ch->tx_ring[i]->list, &ch->free_tx);
1995 } 2131 }
1996 2132
1997 return 0; 2133 return 0;
1998 2134
1999err: 2135err:
2000 for (i = 0; i < target->queue_size; ++i) { 2136 for (i = 0; i < target->queue_size; ++i) {
2001 srp_free_iu(target->srp_host, target->rx_ring[i]); 2137 srp_free_iu(target->srp_host, ch->rx_ring[i]);
2002 srp_free_iu(target->srp_host, target->tx_ring[i]); 2138 srp_free_iu(target->srp_host, ch->tx_ring[i]);
2003 } 2139 }
2004 2140
2005 2141
2006err_no_ring: 2142err_no_ring:
2007 kfree(target->tx_ring); 2143 kfree(ch->tx_ring);
2008 target->tx_ring = NULL; 2144 ch->tx_ring = NULL;
2009 kfree(target->rx_ring); 2145 kfree(ch->rx_ring);
2010 target->rx_ring = NULL; 2146 ch->rx_ring = NULL;
2011 2147
2012 return -ENOMEM; 2148 return -ENOMEM;
2013} 2149}
@@ -2041,23 +2177,24 @@ static uint32_t srp_compute_rq_tmo(struct ib_qp_attr *qp_attr, int attr_mask)
2041 2177
2042static void srp_cm_rep_handler(struct ib_cm_id *cm_id, 2178static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
2043 struct srp_login_rsp *lrsp, 2179 struct srp_login_rsp *lrsp,
2044 struct srp_target_port *target) 2180 struct srp_rdma_ch *ch)
2045{ 2181{
2182 struct srp_target_port *target = ch->target;
2046 struct ib_qp_attr *qp_attr = NULL; 2183 struct ib_qp_attr *qp_attr = NULL;
2047 int attr_mask = 0; 2184 int attr_mask = 0;
2048 int ret; 2185 int ret;
2049 int i; 2186 int i;
2050 2187
2051 if (lrsp->opcode == SRP_LOGIN_RSP) { 2188 if (lrsp->opcode == SRP_LOGIN_RSP) {
2052 target->max_ti_iu_len = be32_to_cpu(lrsp->max_ti_iu_len); 2189 ch->max_ti_iu_len = be32_to_cpu(lrsp->max_ti_iu_len);
2053 target->req_lim = be32_to_cpu(lrsp->req_lim_delta); 2190 ch->req_lim = be32_to_cpu(lrsp->req_lim_delta);
2054 2191
2055 /* 2192 /*
2056 * Reserve credits for task management so we don't 2193 * Reserve credits for task management so we don't
2057 * bounce requests back to the SCSI mid-layer. 2194 * bounce requests back to the SCSI mid-layer.
2058 */ 2195 */
2059 target->scsi_host->can_queue 2196 target->scsi_host->can_queue
2060 = min(target->req_lim - SRP_TSK_MGMT_SQ_SIZE, 2197 = min(ch->req_lim - SRP_TSK_MGMT_SQ_SIZE,
2061 target->scsi_host->can_queue); 2198 target->scsi_host->can_queue);
2062 target->scsi_host->cmd_per_lun 2199 target->scsi_host->cmd_per_lun
2063 = min_t(int, target->scsi_host->can_queue, 2200 = min_t(int, target->scsi_host->can_queue,
@@ -2069,8 +2206,8 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
2069 goto error; 2206 goto error;
2070 } 2207 }
2071 2208
2072 if (!target->rx_ring) { 2209 if (!ch->rx_ring) {
2073 ret = srp_alloc_iu_bufs(target); 2210 ret = srp_alloc_iu_bufs(ch);
2074 if (ret) 2211 if (ret)
2075 goto error; 2212 goto error;
2076 } 2213 }
@@ -2085,13 +2222,14 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
2085 if (ret) 2222 if (ret)
2086 goto error_free; 2223 goto error_free;
2087 2224
2088 ret = ib_modify_qp(target->qp, qp_attr, attr_mask); 2225 ret = ib_modify_qp(ch->qp, qp_attr, attr_mask);
2089 if (ret) 2226 if (ret)
2090 goto error_free; 2227 goto error_free;
2091 2228
2092 for (i = 0; i < target->queue_size; i++) { 2229 for (i = 0; i < target->queue_size; i++) {
2093 struct srp_iu *iu = target->rx_ring[i]; 2230 struct srp_iu *iu = ch->rx_ring[i];
2094 ret = srp_post_recv(target, iu); 2231
2232 ret = srp_post_recv(ch, iu);
2095 if (ret) 2233 if (ret)
2096 goto error_free; 2234 goto error_free;
2097 } 2235 }
@@ -2103,7 +2241,7 @@ static void srp_cm_rep_handler(struct ib_cm_id *cm_id,
2103 2241
2104 target->rq_tmo_jiffies = srp_compute_rq_tmo(qp_attr, attr_mask); 2242 target->rq_tmo_jiffies = srp_compute_rq_tmo(qp_attr, attr_mask);
2105 2243
2106 ret = ib_modify_qp(target->qp, qp_attr, attr_mask); 2244 ret = ib_modify_qp(ch->qp, qp_attr, attr_mask);
2107 if (ret) 2245 if (ret)
2108 goto error_free; 2246 goto error_free;
2109 2247
@@ -2113,13 +2251,14 @@ error_free:
2113 kfree(qp_attr); 2251 kfree(qp_attr);
2114 2252
2115error: 2253error:
2116 target->status = ret; 2254 ch->status = ret;
2117} 2255}
2118 2256
2119static void srp_cm_rej_handler(struct ib_cm_id *cm_id, 2257static void srp_cm_rej_handler(struct ib_cm_id *cm_id,
2120 struct ib_cm_event *event, 2258 struct ib_cm_event *event,
2121 struct srp_target_port *target) 2259 struct srp_rdma_ch *ch)
2122{ 2260{
2261 struct srp_target_port *target = ch->target;
2123 struct Scsi_Host *shost = target->scsi_host; 2262 struct Scsi_Host *shost = target->scsi_host;
2124 struct ib_class_port_info *cpi; 2263 struct ib_class_port_info *cpi;
2125 int opcode; 2264 int opcode;
@@ -2127,12 +2266,12 @@ static void srp_cm_rej_handler(struct ib_cm_id *cm_id,
2127 switch (event->param.rej_rcvd.reason) { 2266 switch (event->param.rej_rcvd.reason) {
2128 case IB_CM_REJ_PORT_CM_REDIRECT: 2267 case IB_CM_REJ_PORT_CM_REDIRECT:
2129 cpi = event->param.rej_rcvd.ari; 2268 cpi = event->param.rej_rcvd.ari;
2130 target->path.dlid = cpi->redirect_lid; 2269 ch->path.dlid = cpi->redirect_lid;
2131 target->path.pkey = cpi->redirect_pkey; 2270 ch->path.pkey = cpi->redirect_pkey;
2132 cm_id->remote_cm_qpn = be32_to_cpu(cpi->redirect_qp) & 0x00ffffff; 2271 cm_id->remote_cm_qpn = be32_to_cpu(cpi->redirect_qp) & 0x00ffffff;
2133 memcpy(target->path.dgid.raw, cpi->redirect_gid, 16); 2272 memcpy(ch->path.dgid.raw, cpi->redirect_gid, 16);
2134 2273
2135 target->status = target->path.dlid ? 2274 ch->status = ch->path.dlid ?
2136 SRP_DLID_REDIRECT : SRP_PORT_REDIRECT; 2275 SRP_DLID_REDIRECT : SRP_PORT_REDIRECT;
2137 break; 2276 break;
2138 2277
@@ -2143,26 +2282,26 @@ static void srp_cm_rej_handler(struct ib_cm_id *cm_id,
2143 * reject reason code 25 when they mean 24 2282 * reject reason code 25 when they mean 24
2144 * (port redirect). 2283 * (port redirect).
2145 */ 2284 */
2146 memcpy(target->path.dgid.raw, 2285 memcpy(ch->path.dgid.raw,
2147 event->param.rej_rcvd.ari, 16); 2286 event->param.rej_rcvd.ari, 16);
2148 2287
2149 shost_printk(KERN_DEBUG, shost, 2288 shost_printk(KERN_DEBUG, shost,
2150 PFX "Topspin/Cisco redirect to target port GID %016llx%016llx\n", 2289 PFX "Topspin/Cisco redirect to target port GID %016llx%016llx\n",
2151 (unsigned long long) be64_to_cpu(target->path.dgid.global.subnet_prefix), 2290 be64_to_cpu(ch->path.dgid.global.subnet_prefix),
2152 (unsigned long long) be64_to_cpu(target->path.dgid.global.interface_id)); 2291 be64_to_cpu(ch->path.dgid.global.interface_id));
2153 2292
2154 target->status = SRP_PORT_REDIRECT; 2293 ch->status = SRP_PORT_REDIRECT;
2155 } else { 2294 } else {
2156 shost_printk(KERN_WARNING, shost, 2295 shost_printk(KERN_WARNING, shost,
2157 " REJ reason: IB_CM_REJ_PORT_REDIRECT\n"); 2296 " REJ reason: IB_CM_REJ_PORT_REDIRECT\n");
2158 target->status = -ECONNRESET; 2297 ch->status = -ECONNRESET;
2159 } 2298 }
2160 break; 2299 break;
2161 2300
2162 case IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID: 2301 case IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID:
2163 shost_printk(KERN_WARNING, shost, 2302 shost_printk(KERN_WARNING, shost,
2164 " REJ reason: IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID\n"); 2303 " REJ reason: IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID\n");
2165 target->status = -ECONNRESET; 2304 ch->status = -ECONNRESET;
2166 break; 2305 break;
2167 2306
2168 case IB_CM_REJ_CONSUMER_DEFINED: 2307 case IB_CM_REJ_CONSUMER_DEFINED:
@@ -2177,30 +2316,31 @@ static void srp_cm_rej_handler(struct ib_cm_id *cm_id,
2177 else 2316 else
2178 shost_printk(KERN_WARNING, shost, PFX 2317 shost_printk(KERN_WARNING, shost, PFX
2179 "SRP LOGIN from %pI6 to %pI6 REJECTED, reason 0x%08x\n", 2318 "SRP LOGIN from %pI6 to %pI6 REJECTED, reason 0x%08x\n",
2180 target->path.sgid.raw, 2319 target->sgid.raw,
2181 target->orig_dgid, reason); 2320 target->orig_dgid.raw, reason);
2182 } else 2321 } else
2183 shost_printk(KERN_WARNING, shost, 2322 shost_printk(KERN_WARNING, shost,
2184 " REJ reason: IB_CM_REJ_CONSUMER_DEFINED," 2323 " REJ reason: IB_CM_REJ_CONSUMER_DEFINED,"
2185 " opcode 0x%02x\n", opcode); 2324 " opcode 0x%02x\n", opcode);
2186 target->status = -ECONNRESET; 2325 ch->status = -ECONNRESET;
2187 break; 2326 break;
2188 2327
2189 case IB_CM_REJ_STALE_CONN: 2328 case IB_CM_REJ_STALE_CONN:
2190 shost_printk(KERN_WARNING, shost, " REJ reason: stale connection\n"); 2329 shost_printk(KERN_WARNING, shost, " REJ reason: stale connection\n");
2191 target->status = SRP_STALE_CONN; 2330 ch->status = SRP_STALE_CONN;
2192 break; 2331 break;
2193 2332
2194 default: 2333 default:
2195 shost_printk(KERN_WARNING, shost, " REJ reason 0x%x\n", 2334 shost_printk(KERN_WARNING, shost, " REJ reason 0x%x\n",
2196 event->param.rej_rcvd.reason); 2335 event->param.rej_rcvd.reason);
2197 target->status = -ECONNRESET; 2336 ch->status = -ECONNRESET;
2198 } 2337 }
2199} 2338}
2200 2339
2201static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event) 2340static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
2202{ 2341{
2203 struct srp_target_port *target = cm_id->context; 2342 struct srp_rdma_ch *ch = cm_id->context;
2343 struct srp_target_port *target = ch->target;
2204 int comp = 0; 2344 int comp = 0;
2205 2345
2206 switch (event->event) { 2346 switch (event->event) {
@@ -2208,19 +2348,19 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
2208 shost_printk(KERN_DEBUG, target->scsi_host, 2348 shost_printk(KERN_DEBUG, target->scsi_host,
2209 PFX "Sending CM REQ failed\n"); 2349 PFX "Sending CM REQ failed\n");
2210 comp = 1; 2350 comp = 1;
2211 target->status = -ECONNRESET; 2351 ch->status = -ECONNRESET;
2212 break; 2352 break;
2213 2353
2214 case IB_CM_REP_RECEIVED: 2354 case IB_CM_REP_RECEIVED:
2215 comp = 1; 2355 comp = 1;
2216 srp_cm_rep_handler(cm_id, event->private_data, target); 2356 srp_cm_rep_handler(cm_id, event->private_data, ch);
2217 break; 2357 break;
2218 2358
2219 case IB_CM_REJ_RECEIVED: 2359 case IB_CM_REJ_RECEIVED:
2220 shost_printk(KERN_DEBUG, target->scsi_host, PFX "REJ received\n"); 2360 shost_printk(KERN_DEBUG, target->scsi_host, PFX "REJ received\n");
2221 comp = 1; 2361 comp = 1;
2222 2362
2223 srp_cm_rej_handler(cm_id, event, target); 2363 srp_cm_rej_handler(cm_id, event, ch);
2224 break; 2364 break;
2225 2365
2226 case IB_CM_DREQ_RECEIVED: 2366 case IB_CM_DREQ_RECEIVED:
@@ -2238,7 +2378,7 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
2238 PFX "connection closed\n"); 2378 PFX "connection closed\n");
2239 comp = 1; 2379 comp = 1;
2240 2380
2241 target->status = 0; 2381 ch->status = 0;
2242 break; 2382 break;
2243 2383
2244 case IB_CM_MRA_RECEIVED: 2384 case IB_CM_MRA_RECEIVED:
@@ -2253,65 +2393,30 @@ static int srp_cm_handler(struct ib_cm_id *cm_id, struct ib_cm_event *event)
2253 } 2393 }
2254 2394
2255 if (comp) 2395 if (comp)
2256 complete(&target->done); 2396 complete(&ch->done);
2257 2397
2258 return 0; 2398 return 0;
2259} 2399}
2260 2400
2261/** 2401/**
2262 * srp_change_queue_type - changing device queue tag type
2263 * @sdev: scsi device struct
2264 * @tag_type: requested tag type
2265 *
2266 * Returns queue tag type.
2267 */
2268static int
2269srp_change_queue_type(struct scsi_device *sdev, int tag_type)
2270{
2271 if (sdev->tagged_supported) {
2272 scsi_set_tag_type(sdev, tag_type);
2273 if (tag_type)
2274 scsi_activate_tcq(sdev, sdev->queue_depth);
2275 else
2276 scsi_deactivate_tcq(sdev, sdev->queue_depth);
2277 } else
2278 tag_type = 0;
2279
2280 return tag_type;
2281}
2282
2283/**
2284 * srp_change_queue_depth - setting device queue depth 2402 * srp_change_queue_depth - setting device queue depth
2285 * @sdev: scsi device struct 2403 * @sdev: scsi device struct
2286 * @qdepth: requested queue depth 2404 * @qdepth: requested queue depth
2287 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
2288 * (see include/scsi/scsi_host.h for definition)
2289 * 2405 *
2290 * Returns queue depth. 2406 * Returns queue depth.
2291 */ 2407 */
2292static int 2408static int
2293srp_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) 2409srp_change_queue_depth(struct scsi_device *sdev, int qdepth)
2294{ 2410{
2295 struct Scsi_Host *shost = sdev->host; 2411 if (!sdev->tagged_supported)
2296 int max_depth; 2412 qdepth = 1;
2297 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) { 2413 return scsi_change_queue_depth(sdev, qdepth);
2298 max_depth = shost->can_queue;
2299 if (!sdev->tagged_supported)
2300 max_depth = 1;
2301 if (qdepth > max_depth)
2302 qdepth = max_depth;
2303 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
2304 } else if (reason == SCSI_QDEPTH_QFULL)
2305 scsi_track_queue_full(sdev, qdepth);
2306 else
2307 return -EOPNOTSUPP;
2308
2309 return sdev->queue_depth;
2310} 2414}
2311 2415
2312static int srp_send_tsk_mgmt(struct srp_target_port *target, 2416static int srp_send_tsk_mgmt(struct srp_rdma_ch *ch, u64 req_tag,
2313 u64 req_tag, unsigned int lun, u8 func) 2417 unsigned int lun, u8 func)
2314{ 2418{
2419 struct srp_target_port *target = ch->target;
2315 struct srp_rport *rport = target->rport; 2420 struct srp_rport *rport = target->rport;
2316 struct ib_device *dev = target->srp_host->srp_dev->dev; 2421 struct ib_device *dev = target->srp_host->srp_dev->dev;
2317 struct srp_iu *iu; 2422 struct srp_iu *iu;
@@ -2320,16 +2425,16 @@ static int srp_send_tsk_mgmt(struct srp_target_port *target,
2320 if (!target->connected || target->qp_in_error) 2425 if (!target->connected || target->qp_in_error)
2321 return -1; 2426 return -1;
2322 2427
2323 init_completion(&target->tsk_mgmt_done); 2428 init_completion(&ch->tsk_mgmt_done);
2324 2429
2325 /* 2430 /*
2326 * Lock the rport mutex to avoid that srp_create_target_ib() is 2431 * Lock the rport mutex to avoid that srp_create_ch_ib() is
2327 * invoked while a task management function is being sent. 2432 * invoked while a task management function is being sent.
2328 */ 2433 */
2329 mutex_lock(&rport->mutex); 2434 mutex_lock(&rport->mutex);
2330 spin_lock_irq(&target->lock); 2435 spin_lock_irq(&ch->lock);
2331 iu = __srp_get_tx_iu(target, SRP_IU_TSK_MGMT); 2436 iu = __srp_get_tx_iu(ch, SRP_IU_TSK_MGMT);
2332 spin_unlock_irq(&target->lock); 2437 spin_unlock_irq(&ch->lock);
2333 2438
2334 if (!iu) { 2439 if (!iu) {
2335 mutex_unlock(&rport->mutex); 2440 mutex_unlock(&rport->mutex);
@@ -2350,15 +2455,15 @@ static int srp_send_tsk_mgmt(struct srp_target_port *target,
2350 2455
2351 ib_dma_sync_single_for_device(dev, iu->dma, sizeof *tsk_mgmt, 2456 ib_dma_sync_single_for_device(dev, iu->dma, sizeof *tsk_mgmt,
2352 DMA_TO_DEVICE); 2457 DMA_TO_DEVICE);
2353 if (srp_post_send(target, iu, sizeof *tsk_mgmt)) { 2458 if (srp_post_send(ch, iu, sizeof(*tsk_mgmt))) {
2354 srp_put_tx_iu(target, iu, SRP_IU_TSK_MGMT); 2459 srp_put_tx_iu(ch, iu, SRP_IU_TSK_MGMT);
2355 mutex_unlock(&rport->mutex); 2460 mutex_unlock(&rport->mutex);
2356 2461
2357 return -1; 2462 return -1;
2358 } 2463 }
2359 mutex_unlock(&rport->mutex); 2464 mutex_unlock(&rport->mutex);
2360 2465
2361 if (!wait_for_completion_timeout(&target->tsk_mgmt_done, 2466 if (!wait_for_completion_timeout(&ch->tsk_mgmt_done,
2362 msecs_to_jiffies(SRP_ABORT_TIMEOUT_MS))) 2467 msecs_to_jiffies(SRP_ABORT_TIMEOUT_MS)))
2363 return -1; 2468 return -1;
2364 2469
@@ -2369,20 +2474,32 @@ static int srp_abort(struct scsi_cmnd *scmnd)
2369{ 2474{
2370 struct srp_target_port *target = host_to_target(scmnd->device->host); 2475 struct srp_target_port *target = host_to_target(scmnd->device->host);
2371 struct srp_request *req = (struct srp_request *) scmnd->host_scribble; 2476 struct srp_request *req = (struct srp_request *) scmnd->host_scribble;
2477 u32 tag;
2478 u16 ch_idx;
2479 struct srp_rdma_ch *ch;
2372 int ret; 2480 int ret;
2373 2481
2374 shost_printk(KERN_ERR, target->scsi_host, "SRP abort called\n"); 2482 shost_printk(KERN_ERR, target->scsi_host, "SRP abort called\n");
2375 2483
2376 if (!req || !srp_claim_req(target, req, NULL, scmnd)) 2484 if (!req)
2485 return SUCCESS;
2486 tag = blk_mq_unique_tag(scmnd->request);
2487 ch_idx = blk_mq_unique_tag_to_hwq(tag);
2488 if (WARN_ON_ONCE(ch_idx >= target->ch_count))
2377 return SUCCESS; 2489 return SUCCESS;
2378 if (srp_send_tsk_mgmt(target, req->index, scmnd->device->lun, 2490 ch = &target->ch[ch_idx];
2491 if (!srp_claim_req(ch, req, NULL, scmnd))
2492 return SUCCESS;
2493 shost_printk(KERN_ERR, target->scsi_host,
2494 "Sending SRP abort for tag %#x\n", tag);
2495 if (srp_send_tsk_mgmt(ch, tag, scmnd->device->lun,
2379 SRP_TSK_ABORT_TASK) == 0) 2496 SRP_TSK_ABORT_TASK) == 0)
2380 ret = SUCCESS; 2497 ret = SUCCESS;
2381 else if (target->rport->state == SRP_RPORT_LOST) 2498 else if (target->rport->state == SRP_RPORT_LOST)
2382 ret = FAST_IO_FAIL; 2499 ret = FAST_IO_FAIL;
2383 else 2500 else
2384 ret = FAILED; 2501 ret = FAILED;
2385 srp_free_req(target, req, scmnd, 0); 2502 srp_free_req(ch, req, scmnd, 0);
2386 scmnd->result = DID_ABORT << 16; 2503 scmnd->result = DID_ABORT << 16;
2387 scmnd->scsi_done(scmnd); 2504 scmnd->scsi_done(scmnd);
2388 2505
@@ -2392,19 +2509,25 @@ static int srp_abort(struct scsi_cmnd *scmnd)
2392static int srp_reset_device(struct scsi_cmnd *scmnd) 2509static int srp_reset_device(struct scsi_cmnd *scmnd)
2393{ 2510{
2394 struct srp_target_port *target = host_to_target(scmnd->device->host); 2511 struct srp_target_port *target = host_to_target(scmnd->device->host);
2512 struct srp_rdma_ch *ch;
2395 int i; 2513 int i;
2396 2514
2397 shost_printk(KERN_ERR, target->scsi_host, "SRP reset_device called\n"); 2515 shost_printk(KERN_ERR, target->scsi_host, "SRP reset_device called\n");
2398 2516
2399 if (srp_send_tsk_mgmt(target, SRP_TAG_NO_REQ, scmnd->device->lun, 2517 ch = &target->ch[0];
2518 if (srp_send_tsk_mgmt(ch, SRP_TAG_NO_REQ, scmnd->device->lun,
2400 SRP_TSK_LUN_RESET)) 2519 SRP_TSK_LUN_RESET))
2401 return FAILED; 2520 return FAILED;
2402 if (target->tsk_mgmt_status) 2521 if (ch->tsk_mgmt_status)
2403 return FAILED; 2522 return FAILED;
2404 2523
2405 for (i = 0; i < target->req_ring_size; ++i) { 2524 for (i = 0; i < target->ch_count; i++) {
2406 struct srp_request *req = &target->req_ring[i]; 2525 ch = &target->ch[i];
2407 srp_finish_req(target, req, scmnd->device, DID_RESET << 16); 2526 for (i = 0; i < target->req_ring_size; ++i) {
2527 struct srp_request *req = &ch->req_ring[i];
2528
2529 srp_finish_req(ch, req, scmnd->device, DID_RESET << 16);
2530 }
2408 } 2531 }
2409 2532
2410 return SUCCESS; 2533 return SUCCESS;
@@ -2466,7 +2589,7 @@ static ssize_t show_pkey(struct device *dev, struct device_attribute *attr,
2466{ 2589{
2467 struct srp_target_port *target = host_to_target(class_to_shost(dev)); 2590 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2468 2591
2469 return sprintf(buf, "0x%04x\n", be16_to_cpu(target->path.pkey)); 2592 return sprintf(buf, "0x%04x\n", be16_to_cpu(target->pkey));
2470} 2593}
2471 2594
2472static ssize_t show_sgid(struct device *dev, struct device_attribute *attr, 2595static ssize_t show_sgid(struct device *dev, struct device_attribute *attr,
@@ -2474,15 +2597,16 @@ static ssize_t show_sgid(struct device *dev, struct device_attribute *attr,
2474{ 2597{
2475 struct srp_target_port *target = host_to_target(class_to_shost(dev)); 2598 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2476 2599
2477 return sprintf(buf, "%pI6\n", target->path.sgid.raw); 2600 return sprintf(buf, "%pI6\n", target->sgid.raw);
2478} 2601}
2479 2602
2480static ssize_t show_dgid(struct device *dev, struct device_attribute *attr, 2603static ssize_t show_dgid(struct device *dev, struct device_attribute *attr,
2481 char *buf) 2604 char *buf)
2482{ 2605{
2483 struct srp_target_port *target = host_to_target(class_to_shost(dev)); 2606 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2607 struct srp_rdma_ch *ch = &target->ch[0];
2484 2608
2485 return sprintf(buf, "%pI6\n", target->path.dgid.raw); 2609 return sprintf(buf, "%pI6\n", ch->path.dgid.raw);
2486} 2610}
2487 2611
2488static ssize_t show_orig_dgid(struct device *dev, 2612static ssize_t show_orig_dgid(struct device *dev,
@@ -2490,15 +2614,21 @@ static ssize_t show_orig_dgid(struct device *dev,
2490{ 2614{
2491 struct srp_target_port *target = host_to_target(class_to_shost(dev)); 2615 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2492 2616
2493 return sprintf(buf, "%pI6\n", target->orig_dgid); 2617 return sprintf(buf, "%pI6\n", target->orig_dgid.raw);
2494} 2618}
2495 2619
2496static ssize_t show_req_lim(struct device *dev, 2620static ssize_t show_req_lim(struct device *dev,
2497 struct device_attribute *attr, char *buf) 2621 struct device_attribute *attr, char *buf)
2498{ 2622{
2499 struct srp_target_port *target = host_to_target(class_to_shost(dev)); 2623 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2624 struct srp_rdma_ch *ch;
2625 int i, req_lim = INT_MAX;
2500 2626
2501 return sprintf(buf, "%d\n", target->req_lim); 2627 for (i = 0; i < target->ch_count; i++) {
2628 ch = &target->ch[i];
2629 req_lim = min(req_lim, ch->req_lim);
2630 }
2631 return sprintf(buf, "%d\n", req_lim);
2502} 2632}
2503 2633
2504static ssize_t show_zero_req_lim(struct device *dev, 2634static ssize_t show_zero_req_lim(struct device *dev,
@@ -2525,6 +2655,14 @@ static ssize_t show_local_ib_device(struct device *dev,
2525 return sprintf(buf, "%s\n", target->srp_host->srp_dev->dev->name); 2655 return sprintf(buf, "%s\n", target->srp_host->srp_dev->dev->name);
2526} 2656}
2527 2657
2658static ssize_t show_ch_count(struct device *dev, struct device_attribute *attr,
2659 char *buf)
2660{
2661 struct srp_target_port *target = host_to_target(class_to_shost(dev));
2662
2663 return sprintf(buf, "%d\n", target->ch_count);
2664}
2665
2528static ssize_t show_comp_vector(struct device *dev, 2666static ssize_t show_comp_vector(struct device *dev,
2529 struct device_attribute *attr, char *buf) 2667 struct device_attribute *attr, char *buf)
2530{ 2668{
@@ -2568,6 +2706,7 @@ static DEVICE_ATTR(req_lim, S_IRUGO, show_req_lim, NULL);
2568static DEVICE_ATTR(zero_req_lim, S_IRUGO, show_zero_req_lim, NULL); 2706static DEVICE_ATTR(zero_req_lim, S_IRUGO, show_zero_req_lim, NULL);
2569static DEVICE_ATTR(local_ib_port, S_IRUGO, show_local_ib_port, NULL); 2707static DEVICE_ATTR(local_ib_port, S_IRUGO, show_local_ib_port, NULL);
2570static DEVICE_ATTR(local_ib_device, S_IRUGO, show_local_ib_device, NULL); 2708static DEVICE_ATTR(local_ib_device, S_IRUGO, show_local_ib_device, NULL);
2709static DEVICE_ATTR(ch_count, S_IRUGO, show_ch_count, NULL);
2571static DEVICE_ATTR(comp_vector, S_IRUGO, show_comp_vector, NULL); 2710static DEVICE_ATTR(comp_vector, S_IRUGO, show_comp_vector, NULL);
2572static DEVICE_ATTR(tl_retry_count, S_IRUGO, show_tl_retry_count, NULL); 2711static DEVICE_ATTR(tl_retry_count, S_IRUGO, show_tl_retry_count, NULL);
2573static DEVICE_ATTR(cmd_sg_entries, S_IRUGO, show_cmd_sg_entries, NULL); 2712static DEVICE_ATTR(cmd_sg_entries, S_IRUGO, show_cmd_sg_entries, NULL);
@@ -2585,6 +2724,7 @@ static struct device_attribute *srp_host_attrs[] = {
2585 &dev_attr_zero_req_lim, 2724 &dev_attr_zero_req_lim,
2586 &dev_attr_local_ib_port, 2725 &dev_attr_local_ib_port,
2587 &dev_attr_local_ib_device, 2726 &dev_attr_local_ib_device,
2727 &dev_attr_ch_count,
2588 &dev_attr_comp_vector, 2728 &dev_attr_comp_vector,
2589 &dev_attr_tl_retry_count, 2729 &dev_attr_tl_retry_count,
2590 &dev_attr_cmd_sg_entries, 2730 &dev_attr_cmd_sg_entries,
@@ -2600,7 +2740,7 @@ static struct scsi_host_template srp_template = {
2600 .info = srp_target_info, 2740 .info = srp_target_info,
2601 .queuecommand = srp_queuecommand, 2741 .queuecommand = srp_queuecommand,
2602 .change_queue_depth = srp_change_queue_depth, 2742 .change_queue_depth = srp_change_queue_depth,
2603 .change_queue_type = srp_change_queue_type, 2743 .change_queue_type = scsi_change_queue_type,
2604 .eh_abort_handler = srp_abort, 2744 .eh_abort_handler = srp_abort,
2605 .eh_device_reset_handler = srp_reset_device, 2745 .eh_device_reset_handler = srp_reset_device,
2606 .eh_host_reset_handler = srp_reset_host, 2746 .eh_host_reset_handler = srp_reset_host,
@@ -2610,14 +2750,28 @@ static struct scsi_host_template srp_template = {
2610 .this_id = -1, 2750 .this_id = -1,
2611 .cmd_per_lun = SRP_DEFAULT_CMD_SQ_SIZE, 2751 .cmd_per_lun = SRP_DEFAULT_CMD_SQ_SIZE,
2612 .use_clustering = ENABLE_CLUSTERING, 2752 .use_clustering = ENABLE_CLUSTERING,
2613 .shost_attrs = srp_host_attrs 2753 .shost_attrs = srp_host_attrs,
2754 .use_blk_tags = 1,
2755 .track_queue_depth = 1,
2614}; 2756};
2615 2757
2758static int srp_sdev_count(struct Scsi_Host *host)
2759{
2760 struct scsi_device *sdev;
2761 int c = 0;
2762
2763 shost_for_each_device(sdev, host)
2764 c++;
2765
2766 return c;
2767}
2768
2616static int srp_add_target(struct srp_host *host, struct srp_target_port *target) 2769static int srp_add_target(struct srp_host *host, struct srp_target_port *target)
2617{ 2770{
2618 struct srp_rport_identifiers ids; 2771 struct srp_rport_identifiers ids;
2619 struct srp_rport *rport; 2772 struct srp_rport *rport;
2620 2773
2774 target->state = SRP_TARGET_SCANNING;
2621 sprintf(target->target_name, "SRP.T10:%016llX", 2775 sprintf(target->target_name, "SRP.T10:%016llX",
2622 (unsigned long long) be64_to_cpu(target->id_ext)); 2776 (unsigned long long) be64_to_cpu(target->id_ext));
2623 2777
@@ -2640,11 +2794,26 @@ static int srp_add_target(struct srp_host *host, struct srp_target_port *target)
2640 list_add_tail(&target->list, &host->target_list); 2794 list_add_tail(&target->list, &host->target_list);
2641 spin_unlock(&host->target_lock); 2795 spin_unlock(&host->target_lock);
2642 2796
2643 target->state = SRP_TARGET_LIVE;
2644
2645 scsi_scan_target(&target->scsi_host->shost_gendev, 2797 scsi_scan_target(&target->scsi_host->shost_gendev,
2646 0, target->scsi_id, SCAN_WILD_CARD, 0); 2798 0, target->scsi_id, SCAN_WILD_CARD, 0);
2647 2799
2800 if (!target->connected || target->qp_in_error) {
2801 shost_printk(KERN_INFO, target->scsi_host,
2802 PFX "SCSI scan failed - removing SCSI host\n");
2803 srp_queue_remove_work(target);
2804 goto out;
2805 }
2806
2807 pr_debug(PFX "%s: SCSI scan succeeded - detected %d LUNs\n",
2808 dev_name(&target->scsi_host->shost_gendev),
2809 srp_sdev_count(target->scsi_host));
2810
2811 spin_lock_irq(&target->lock);
2812 if (target->state == SRP_TARGET_SCANNING)
2813 target->state = SRP_TARGET_LIVE;
2814 spin_unlock_irq(&target->lock);
2815
2816out:
2648 return 0; 2817 return 0;
2649} 2818}
2650 2819
@@ -2801,11 +2970,15 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
2801 } 2970 }
2802 2971
2803 for (i = 0; i < 16; ++i) { 2972 for (i = 0; i < 16; ++i) {
2804 strlcpy(dgid, p + i * 2, 3); 2973 strlcpy(dgid, p + i * 2, sizeof(dgid));
2805 target->path.dgid.raw[i] = simple_strtoul(dgid, NULL, 16); 2974 if (sscanf(dgid, "%hhx",
2975 &target->orig_dgid.raw[i]) < 1) {
2976 ret = -EINVAL;
2977 kfree(p);
2978 goto out;
2979 }
2806 } 2980 }
2807 kfree(p); 2981 kfree(p);
2808 memcpy(target->orig_dgid, target->path.dgid.raw, 16);
2809 break; 2982 break;
2810 2983
2811 case SRP_OPT_PKEY: 2984 case SRP_OPT_PKEY:
@@ -2813,7 +2986,7 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
2813 pr_warn("bad P_Key parameter '%s'\n", p); 2986 pr_warn("bad P_Key parameter '%s'\n", p);
2814 goto out; 2987 goto out;
2815 } 2988 }
2816 target->path.pkey = cpu_to_be16(token); 2989 target->pkey = cpu_to_be16(token);
2817 break; 2990 break;
2818 2991
2819 case SRP_OPT_SERVICE_ID: 2992 case SRP_OPT_SERVICE_ID:
@@ -2823,7 +2996,6 @@ static int srp_parse_options(const char *buf, struct srp_target_port *target)
2823 goto out; 2996 goto out;
2824 } 2997 }
2825 target->service_id = cpu_to_be64(simple_strtoull(p, NULL, 16)); 2998 target->service_id = cpu_to_be64(simple_strtoull(p, NULL, 16));
2826 target->path.service_id = target->service_id;
2827 kfree(p); 2999 kfree(p);
2828 break; 3000 break;
2829 3001
@@ -2960,9 +3132,11 @@ static ssize_t srp_create_target(struct device *dev,
2960 container_of(dev, struct srp_host, dev); 3132 container_of(dev, struct srp_host, dev);
2961 struct Scsi_Host *target_host; 3133 struct Scsi_Host *target_host;
2962 struct srp_target_port *target; 3134 struct srp_target_port *target;
3135 struct srp_rdma_ch *ch;
2963 struct srp_device *srp_dev = host->srp_dev; 3136 struct srp_device *srp_dev = host->srp_dev;
2964 struct ib_device *ibdev = srp_dev->dev; 3137 struct ib_device *ibdev = srp_dev->dev;
2965 int ret; 3138 int ret, node_idx, node, cpu, i;
3139 bool multich = false;
2966 3140
2967 target_host = scsi_host_alloc(&srp_template, 3141 target_host = scsi_host_alloc(&srp_template,
2968 sizeof (struct srp_target_port)); 3142 sizeof (struct srp_target_port));
@@ -2988,12 +3162,22 @@ static ssize_t srp_create_target(struct device *dev,
2988 target->tl_retry_count = 7; 3162 target->tl_retry_count = 7;
2989 target->queue_size = SRP_DEFAULT_QUEUE_SIZE; 3163 target->queue_size = SRP_DEFAULT_QUEUE_SIZE;
2990 3164
3165 /*
3166 * Avoid that the SCSI host can be removed by srp_remove_target()
3167 * before this function returns.
3168 */
3169 scsi_host_get(target->scsi_host);
3170
2991 mutex_lock(&host->add_target_mutex); 3171 mutex_lock(&host->add_target_mutex);
2992 3172
2993 ret = srp_parse_options(buf, target); 3173 ret = srp_parse_options(buf, target);
2994 if (ret) 3174 if (ret)
2995 goto err; 3175 goto err;
2996 3176
3177 ret = scsi_init_shared_tag_map(target_host, target_host->can_queue);
3178 if (ret)
3179 goto err;
3180
2997 target->req_ring_size = target->queue_size - SRP_TSK_MGMT_SQ_SIZE; 3181 target->req_ring_size = target->queue_size - SRP_TSK_MGMT_SQ_SIZE;
2998 3182
2999 if (!srp_conn_unique(target->srp_host, target)) { 3183 if (!srp_conn_unique(target->srp_host, target)) {
@@ -3022,59 +3206,115 @@ static ssize_t srp_create_target(struct device *dev,
3022 INIT_WORK(&target->tl_err_work, srp_tl_err_work); 3206 INIT_WORK(&target->tl_err_work, srp_tl_err_work);
3023 INIT_WORK(&target->remove_work, srp_remove_work); 3207 INIT_WORK(&target->remove_work, srp_remove_work);
3024 spin_lock_init(&target->lock); 3208 spin_lock_init(&target->lock);
3025 INIT_LIST_HEAD(&target->free_tx); 3209 ret = ib_query_gid(ibdev, host->port, 0, &target->sgid);
3026 ret = srp_alloc_req_data(target);
3027 if (ret) 3210 if (ret)
3028 goto err_free_mem; 3211 goto err;
3029 3212
3030 ret = ib_query_gid(ibdev, host->port, 0, &target->path.sgid); 3213 ret = -ENOMEM;
3031 if (ret) 3214 target->ch_count = max_t(unsigned, num_online_nodes(),
3032 goto err_free_mem; 3215 min(ch_count ? :
3216 min(4 * num_online_nodes(),
3217 ibdev->num_comp_vectors),
3218 num_online_cpus()));
3219 target->ch = kcalloc(target->ch_count, sizeof(*target->ch),
3220 GFP_KERNEL);
3221 if (!target->ch)
3222 goto err;
3033 3223
3034 ret = srp_create_target_ib(target); 3224 node_idx = 0;
3035 if (ret) 3225 for_each_online_node(node) {
3036 goto err_free_mem; 3226 const int ch_start = (node_idx * target->ch_count /
3227 num_online_nodes());
3228 const int ch_end = ((node_idx + 1) * target->ch_count /
3229 num_online_nodes());
3230 const int cv_start = (node_idx * ibdev->num_comp_vectors /
3231 num_online_nodes() + target->comp_vector)
3232 % ibdev->num_comp_vectors;
3233 const int cv_end = ((node_idx + 1) * ibdev->num_comp_vectors /
3234 num_online_nodes() + target->comp_vector)
3235 % ibdev->num_comp_vectors;
3236 int cpu_idx = 0;
3237
3238 for_each_online_cpu(cpu) {
3239 if (cpu_to_node(cpu) != node)
3240 continue;
3241 if (ch_start + cpu_idx >= ch_end)
3242 continue;
3243 ch = &target->ch[ch_start + cpu_idx];
3244 ch->target = target;
3245 ch->comp_vector = cv_start == cv_end ? cv_start :
3246 cv_start + cpu_idx % (cv_end - cv_start);
3247 spin_lock_init(&ch->lock);
3248 INIT_LIST_HEAD(&ch->free_tx);
3249 ret = srp_new_cm_id(ch);
3250 if (ret)
3251 goto err_disconnect;
3037 3252
3038 ret = srp_new_cm_id(target); 3253 ret = srp_create_ch_ib(ch);
3039 if (ret) 3254 if (ret)
3040 goto err_free_ib; 3255 goto err_disconnect;
3041 3256
3042 ret = srp_connect_target(target); 3257 ret = srp_alloc_req_data(ch);
3043 if (ret) { 3258 if (ret)
3044 shost_printk(KERN_ERR, target->scsi_host, 3259 goto err_disconnect;
3045 PFX "Connection failed\n"); 3260
3046 goto err_cm_id; 3261 ret = srp_connect_ch(ch, multich);
3262 if (ret) {
3263 shost_printk(KERN_ERR, target->scsi_host,
3264 PFX "Connection %d/%d failed\n",
3265 ch_start + cpu_idx,
3266 target->ch_count);
3267 if (node_idx == 0 && cpu_idx == 0) {
3268 goto err_disconnect;
3269 } else {
3270 srp_free_ch_ib(target, ch);
3271 srp_free_req_data(target, ch);
3272 target->ch_count = ch - target->ch;
3273 break;
3274 }
3275 }
3276
3277 multich = true;
3278 cpu_idx++;
3279 }
3280 node_idx++;
3047 } 3281 }
3048 3282
3283 target->scsi_host->nr_hw_queues = target->ch_count;
3284
3049 ret = srp_add_target(host, target); 3285 ret = srp_add_target(host, target);
3050 if (ret) 3286 if (ret)
3051 goto err_disconnect; 3287 goto err_disconnect;
3052 3288
3053 shost_printk(KERN_DEBUG, target->scsi_host, PFX 3289 if (target->state != SRP_TARGET_REMOVED) {
3054 "new target: id_ext %016llx ioc_guid %016llx pkey %04x service_id %016llx sgid %pI6 dgid %pI6\n", 3290 shost_printk(KERN_DEBUG, target->scsi_host, PFX
3055 be64_to_cpu(target->id_ext), 3291 "new target: id_ext %016llx ioc_guid %016llx pkey %04x service_id %016llx sgid %pI6 dgid %pI6\n",
3056 be64_to_cpu(target->ioc_guid), 3292 be64_to_cpu(target->id_ext),
3057 be16_to_cpu(target->path.pkey), 3293 be64_to_cpu(target->ioc_guid),
3058 be64_to_cpu(target->service_id), 3294 be16_to_cpu(target->pkey),
3059 target->path.sgid.raw, target->path.dgid.raw); 3295 be64_to_cpu(target->service_id),
3296 target->sgid.raw, target->orig_dgid.raw);
3297 }
3060 3298
3061 ret = count; 3299 ret = count;
3062 3300
3063out: 3301out:
3064 mutex_unlock(&host->add_target_mutex); 3302 mutex_unlock(&host->add_target_mutex);
3303
3304 scsi_host_put(target->scsi_host);
3305
3065 return ret; 3306 return ret;
3066 3307
3067err_disconnect: 3308err_disconnect:
3068 srp_disconnect_target(target); 3309 srp_disconnect_target(target);
3069 3310
3070err_cm_id: 3311 for (i = 0; i < target->ch_count; i++) {
3071 ib_destroy_cm_id(target->cm_id); 3312 ch = &target->ch[i];
3072 3313 srp_free_ch_ib(target, ch);
3073err_free_ib: 3314 srp_free_req_data(target, ch);
3074 srp_free_target_ib(target); 3315 }
3075 3316
3076err_free_mem: 3317 kfree(target->ch);
3077 srp_free_req_data(target);
3078 3318
3079err: 3319err:
3080 scsi_host_put(target_host); 3320 scsi_host_put(target_host);
diff --git a/drivers/infiniband/ulp/srp/ib_srp.h b/drivers/infiniband/ulp/srp/ib_srp.h
index e46ecb15aa0d..a611556406ac 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.h
+++ b/drivers/infiniband/ulp/srp/ib_srp.h
@@ -70,9 +70,12 @@ enum {
70 70
71 LOCAL_INV_WR_ID_MASK = 1, 71 LOCAL_INV_WR_ID_MASK = 1,
72 FAST_REG_WR_ID_MASK = 2, 72 FAST_REG_WR_ID_MASK = 2,
73
74 SRP_LAST_WR_ID = 0xfffffffcU,
73}; 75};
74 76
75enum srp_target_state { 77enum srp_target_state {
78 SRP_TARGET_SCANNING,
76 SRP_TARGET_LIVE, 79 SRP_TARGET_LIVE,
77 SRP_TARGET_REMOVED, 80 SRP_TARGET_REMOVED,
78}; 81};
@@ -115,7 +118,6 @@ struct srp_host {
115}; 118};
116 119
117struct srp_request { 120struct srp_request {
118 struct list_head list;
119 struct scsi_cmnd *scmnd; 121 struct scsi_cmnd *scmnd;
120 struct srp_iu *cmd; 122 struct srp_iu *cmd;
121 union { 123 union {
@@ -126,24 +128,62 @@ struct srp_request {
126 struct srp_direct_buf *indirect_desc; 128 struct srp_direct_buf *indirect_desc;
127 dma_addr_t indirect_dma_addr; 129 dma_addr_t indirect_dma_addr;
128 short nmdesc; 130 short nmdesc;
129 short index;
130}; 131};
131 132
132struct srp_target_port { 133/**
134 * struct srp_rdma_ch
135 * @comp_vector: Completion vector used by this RDMA channel.
136 */
137struct srp_rdma_ch {
133 /* These are RW in the hot path, and commonly used together */ 138 /* These are RW in the hot path, and commonly used together */
134 struct list_head free_tx; 139 struct list_head free_tx;
135 struct list_head free_reqs;
136 spinlock_t lock; 140 spinlock_t lock;
137 s32 req_lim; 141 s32 req_lim;
138 142
139 /* These are read-only in the hot path */ 143 /* These are read-only in the hot path */
140 struct ib_cq *send_cq ____cacheline_aligned_in_smp; 144 struct srp_target_port *target ____cacheline_aligned_in_smp;
145 struct ib_cq *send_cq;
141 struct ib_cq *recv_cq; 146 struct ib_cq *recv_cq;
142 struct ib_qp *qp; 147 struct ib_qp *qp;
143 union { 148 union {
144 struct ib_fmr_pool *fmr_pool; 149 struct ib_fmr_pool *fmr_pool;
145 struct srp_fr_pool *fr_pool; 150 struct srp_fr_pool *fr_pool;
146 }; 151 };
152
153 /* Everything above this point is used in the hot path of
154 * command processing. Try to keep them packed into cachelines.
155 */
156
157 struct completion done;
158 int status;
159
160 struct ib_sa_path_rec path;
161 struct ib_sa_query *path_query;
162 int path_query_id;
163
164 struct ib_cm_id *cm_id;
165 struct srp_iu **tx_ring;
166 struct srp_iu **rx_ring;
167 struct srp_request *req_ring;
168 int max_ti_iu_len;
169 int comp_vector;
170
171 struct completion tsk_mgmt_done;
172 u8 tsk_mgmt_status;
173};
174
175/**
176 * struct srp_target_port
177 * @comp_vector: Completion vector used by the first RDMA channel created for
178 * this target port.
179 */
180struct srp_target_port {
181 /* read and written in the hot path */
182 spinlock_t lock;
183
184 /* read only in the hot path */
185 struct srp_rdma_ch *ch;
186 u32 ch_count;
147 u32 lkey; 187 u32 lkey;
148 u32 rkey; 188 u32 rkey;
149 enum srp_target_state state; 189 enum srp_target_state state;
@@ -152,10 +192,8 @@ struct srp_target_port {
152 unsigned int indirect_size; 192 unsigned int indirect_size;
153 bool allow_ext_sg; 193 bool allow_ext_sg;
154 194
155 /* Everything above this point is used in the hot path of 195 /* other member variables */
156 * command processing. Try to keep them packed into cachelines. 196 union ib_gid sgid;
157 */
158
159 __be64 id_ext; 197 __be64 id_ext;
160 __be64 ioc_guid; 198 __be64 ioc_guid;
161 __be64 service_id; 199 __be64 service_id;
@@ -172,34 +210,19 @@ struct srp_target_port {
172 int comp_vector; 210 int comp_vector;
173 int tl_retry_count; 211 int tl_retry_count;
174 212
175 struct ib_sa_path_rec path; 213 union ib_gid orig_dgid;
176 __be16 orig_dgid[8]; 214 __be16 pkey;
177 struct ib_sa_query *path_query;
178 int path_query_id;
179 215
180 u32 rq_tmo_jiffies; 216 u32 rq_tmo_jiffies;
181 bool connected; 217 bool connected;
182 218
183 struct ib_cm_id *cm_id;
184
185 int max_ti_iu_len;
186
187 int zero_req_lim; 219 int zero_req_lim;
188 220
189 struct srp_iu **tx_ring;
190 struct srp_iu **rx_ring;
191 struct srp_request *req_ring;
192
193 struct work_struct tl_err_work; 221 struct work_struct tl_err_work;
194 struct work_struct remove_work; 222 struct work_struct remove_work;
195 223
196 struct list_head list; 224 struct list_head list;
197 struct completion done;
198 int status;
199 bool qp_in_error; 225 bool qp_in_error;
200
201 struct completion tsk_mgmt_done;
202 u8 tsk_mgmt_status;
203}; 226};
204 227
205struct srp_iu { 228struct srp_iu {
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 7206547c13ce..dc829682701a 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -2092,6 +2092,7 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch)
2092 if (!qp_init) 2092 if (!qp_init)
2093 goto out; 2093 goto out;
2094 2094
2095retry:
2095 ch->cq = ib_create_cq(sdev->device, srpt_completion, NULL, ch, 2096 ch->cq = ib_create_cq(sdev->device, srpt_completion, NULL, ch,
2096 ch->rq_size + srp_sq_size, 0); 2097 ch->rq_size + srp_sq_size, 0);
2097 if (IS_ERR(ch->cq)) { 2098 if (IS_ERR(ch->cq)) {
@@ -2115,6 +2116,13 @@ static int srpt_create_ch_ib(struct srpt_rdma_ch *ch)
2115 ch->qp = ib_create_qp(sdev->pd, qp_init); 2116 ch->qp = ib_create_qp(sdev->pd, qp_init);
2116 if (IS_ERR(ch->qp)) { 2117 if (IS_ERR(ch->qp)) {
2117 ret = PTR_ERR(ch->qp); 2118 ret = PTR_ERR(ch->qp);
2119 if (ret == -ENOMEM) {
2120 srp_sq_size /= 2;
2121 if (srp_sq_size >= MIN_SRPT_SQ_SIZE) {
2122 ib_destroy_cq(ch->cq);
2123 goto retry;
2124 }
2125 }
2118 printk(KERN_ERR "failed to create_qp ret= %d\n", ret); 2126 printk(KERN_ERR "failed to create_qp ret= %d\n", ret);
2119 goto err_destroy_cq; 2127 goto err_destroy_cq;
2120 } 2128 }
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index bc203485716d..8afa28e4570e 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -421,7 +421,7 @@ static int evdev_open(struct inode *inode, struct file *file)
421 421
422 err_free_client: 422 err_free_client:
423 evdev_detach_client(evdev, client); 423 evdev_detach_client(evdev, client);
424 kfree(client); 424 kvfree(client);
425 return error; 425 return error;
426} 426}
427 427
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 2ed7905a068f..fc55f0d15b70 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -1179,9 +1179,19 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
1179 } 1179 }
1180 1180
1181 ep_irq_in = &intf->cur_altsetting->endpoint[1].desc; 1181 ep_irq_in = &intf->cur_altsetting->endpoint[1].desc;
1182 usb_fill_bulk_urb(xpad->bulk_out, udev, 1182 if (usb_endpoint_is_bulk_out(ep_irq_in)) {
1183 usb_sndbulkpipe(udev, ep_irq_in->bEndpointAddress), 1183 usb_fill_bulk_urb(xpad->bulk_out, udev,
1184 xpad->bdata, XPAD_PKT_LEN, xpad_bulk_out, xpad); 1184 usb_sndbulkpipe(udev,
1185 ep_irq_in->bEndpointAddress),
1186 xpad->bdata, XPAD_PKT_LEN,
1187 xpad_bulk_out, xpad);
1188 } else {
1189 usb_fill_int_urb(xpad->bulk_out, udev,
1190 usb_sndintpipe(udev,
1191 ep_irq_in->bEndpointAddress),
1192 xpad->bdata, XPAD_PKT_LEN,
1193 xpad_bulk_out, xpad, 0);
1194 }
1185 1195
1186 /* 1196 /*
1187 * Submit the int URB immediately rather than waiting for open 1197 * Submit the int URB immediately rather than waiting for open
diff --git a/drivers/input/misc/twl4030-pwrbutton.c b/drivers/input/misc/twl4030-pwrbutton.c
index fb3b63b2f85c..8400a1a34d87 100644
--- a/drivers/input/misc/twl4030-pwrbutton.c
+++ b/drivers/input/misc/twl4030-pwrbutton.c
@@ -85,6 +85,7 @@ static int twl4030_pwrbutton_probe(struct platform_device *pdev)
85 } 85 }
86 86
87 platform_set_drvdata(pdev, pwr); 87 platform_set_drvdata(pdev, pwr);
88 device_init_wakeup(&pdev->dev, true);
88 89
89 return 0; 90 return 0;
90} 91}
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 2b0ae8cc8e51..d125a019383f 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -1156,7 +1156,13 @@ static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
1156{ 1156{
1157 struct alps_data *priv = psmouse->private; 1157 struct alps_data *priv = psmouse->private;
1158 1158
1159 if ((psmouse->packet[0] & 0xc8) == 0x08) { /* PS/2 packet */ 1159 /*
1160 * Check if we are dealing with a bare PS/2 packet, presumably from
1161 * a device connected to the external PS/2 port. Because bare PS/2
1162 * protocol does not have enough constant bits to self-synchronize
1163 * properly we only do this if the device is fully synchronized.
1164 */
1165 if (!psmouse->out_of_sync_cnt && (psmouse->packet[0] & 0xc8) == 0x08) {
1160 if (psmouse->pktcnt == 3) { 1166 if (psmouse->pktcnt == 3) {
1161 alps_report_bare_ps2_packet(psmouse, psmouse->packet, 1167 alps_report_bare_ps2_packet(psmouse, psmouse->packet,
1162 true); 1168 true);
@@ -1180,12 +1186,27 @@ static psmouse_ret_t alps_process_byte(struct psmouse *psmouse)
1180 } 1186 }
1181 1187
1182 /* Bytes 2 - pktsize should have 0 in the highest bit */ 1188 /* Bytes 2 - pktsize should have 0 in the highest bit */
1183 if ((priv->proto_version < ALPS_PROTO_V5) && 1189 if (priv->proto_version < ALPS_PROTO_V5 &&
1184 psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize && 1190 psmouse->pktcnt >= 2 && psmouse->pktcnt <= psmouse->pktsize &&
1185 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) { 1191 (psmouse->packet[psmouse->pktcnt - 1] & 0x80)) {
1186 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n", 1192 psmouse_dbg(psmouse, "refusing packet[%i] = %x\n",
1187 psmouse->pktcnt - 1, 1193 psmouse->pktcnt - 1,
1188 psmouse->packet[psmouse->pktcnt - 1]); 1194 psmouse->packet[psmouse->pktcnt - 1]);
1195
1196 if (priv->proto_version == ALPS_PROTO_V3 &&
1197 psmouse->pktcnt == psmouse->pktsize) {
1198 /*
1199 * Some Dell boxes, such as Latitude E6440 or E7440
1200 * with closed lid, quite often smash last byte of
1201 * otherwise valid packet with 0xff. Given that the
1202 * next packet is very likely to be valid let's
1203 * report PSMOUSE_FULL_PACKET but not process data,
1204 * rather than reporting PSMOUSE_BAD_DATA and
1205 * filling the logs.
1206 */
1207 return PSMOUSE_FULL_PACKET;
1208 }
1209
1189 return PSMOUSE_BAD_DATA; 1210 return PSMOUSE_BAD_DATA;
1190 } 1211 }
1191 1212
@@ -2389,6 +2410,9 @@ int alps_init(struct psmouse *psmouse)
2389 /* We are having trouble resyncing ALPS touchpads so disable it for now */ 2410 /* We are having trouble resyncing ALPS touchpads so disable it for now */
2390 psmouse->resync_time = 0; 2411 psmouse->resync_time = 0;
2391 2412
2413 /* Allow 2 invalid packets without resetting device */
2414 psmouse->resetafter = psmouse->pktsize * 2;
2415
2392 return 0; 2416 return 0;
2393 2417
2394init_fail: 2418init_fail:
diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 06fc6e76ffbe..f2b978026407 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -428,14 +428,6 @@ static void elantech_report_trackpoint(struct psmouse *psmouse,
428 int x, y; 428 int x, y;
429 u32 t; 429 u32 t;
430 430
431 if (dev_WARN_ONCE(&psmouse->ps2dev.serio->dev,
432 !tp_dev,
433 psmouse_fmt("Unexpected trackpoint message\n"))) {
434 if (etd->debug == 1)
435 elantech_packet_dump(psmouse);
436 return;
437 }
438
439 t = get_unaligned_le32(&packet[0]); 431 t = get_unaligned_le32(&packet[0]);
440 432
441 switch (t & ~7U) { 433 switch (t & ~7U) {
@@ -563,6 +555,7 @@ static void elantech_input_sync_v4(struct psmouse *psmouse)
563 } else { 555 } else {
564 input_report_key(dev, BTN_LEFT, packet[0] & 0x01); 556 input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
565 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02); 557 input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
558 input_report_key(dev, BTN_MIDDLE, packet[0] & 0x04);
566 } 559 }
567 560
568 input_mt_report_pointer_emulation(dev, true); 561 input_mt_report_pointer_emulation(dev, true);
@@ -792,6 +785,9 @@ static int elantech_packet_check_v4(struct psmouse *psmouse)
792 unsigned char packet_type = packet[3] & 0x03; 785 unsigned char packet_type = packet[3] & 0x03;
793 bool sanity_check; 786 bool sanity_check;
794 787
788 if (etd->tp_dev && (packet[3] & 0x0f) == 0x06)
789 return PACKET_TRACKPOINT;
790
795 /* 791 /*
796 * Sanity check based on the constant bits of a packet. 792 * Sanity check based on the constant bits of a packet.
797 * The constant bits change depending on the value of 793 * The constant bits change depending on the value of
@@ -877,10 +873,19 @@ static psmouse_ret_t elantech_process_byte(struct psmouse *psmouse)
877 873
878 case 4: 874 case 4:
879 packet_type = elantech_packet_check_v4(psmouse); 875 packet_type = elantech_packet_check_v4(psmouse);
880 if (packet_type == PACKET_UNKNOWN) 876 switch (packet_type) {
877 case PACKET_UNKNOWN:
881 return PSMOUSE_BAD_DATA; 878 return PSMOUSE_BAD_DATA;
882 879
883 elantech_report_absolute_v4(psmouse, packet_type); 880 case PACKET_TRACKPOINT:
881 elantech_report_trackpoint(psmouse, packet_type);
882 break;
883
884 default:
885 elantech_report_absolute_v4(psmouse, packet_type);
886 break;
887 }
888
884 break; 889 break;
885 } 890 }
886 891
@@ -1120,6 +1125,22 @@ static void elantech_set_buttonpad_prop(struct psmouse *psmouse)
1120} 1125}
1121 1126
1122/* 1127/*
1128 * Some hw_version 4 models do have a middle button
1129 */
1130static const struct dmi_system_id elantech_dmi_has_middle_button[] = {
1131#if defined(CONFIG_DMI) && defined(CONFIG_X86)
1132 {
1133 /* Fujitsu H730 has a middle button */
1134 .matches = {
1135 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
1136 DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H730"),
1137 },
1138 },
1139#endif
1140 { }
1141};
1142
1143/*
1123 * Set the appropriate event bits for the input subsystem 1144 * Set the appropriate event bits for the input subsystem
1124 */ 1145 */
1125static int elantech_set_input_params(struct psmouse *psmouse) 1146static int elantech_set_input_params(struct psmouse *psmouse)
@@ -1138,6 +1159,8 @@ static int elantech_set_input_params(struct psmouse *psmouse)
1138 __clear_bit(EV_REL, dev->evbit); 1159 __clear_bit(EV_REL, dev->evbit);
1139 1160
1140 __set_bit(BTN_LEFT, dev->keybit); 1161 __set_bit(BTN_LEFT, dev->keybit);
1162 if (dmi_check_system(elantech_dmi_has_middle_button))
1163 __set_bit(BTN_MIDDLE, dev->keybit);
1141 __set_bit(BTN_RIGHT, dev->keybit); 1164 __set_bit(BTN_RIGHT, dev->keybit);
1142 1165
1143 __set_bit(BTN_TOUCH, dev->keybit); 1166 __set_bit(BTN_TOUCH, dev->keybit);
@@ -1299,6 +1322,7 @@ ELANTECH_INT_ATTR(reg_25, 0x25);
1299ELANTECH_INT_ATTR(reg_26, 0x26); 1322ELANTECH_INT_ATTR(reg_26, 0x26);
1300ELANTECH_INT_ATTR(debug, 0); 1323ELANTECH_INT_ATTR(debug, 0);
1301ELANTECH_INT_ATTR(paritycheck, 0); 1324ELANTECH_INT_ATTR(paritycheck, 0);
1325ELANTECH_INT_ATTR(crc_enabled, 0);
1302 1326
1303static struct attribute *elantech_attrs[] = { 1327static struct attribute *elantech_attrs[] = {
1304 &psmouse_attr_reg_07.dattr.attr, 1328 &psmouse_attr_reg_07.dattr.attr,
@@ -1313,6 +1337,7 @@ static struct attribute *elantech_attrs[] = {
1313 &psmouse_attr_reg_26.dattr.attr, 1337 &psmouse_attr_reg_26.dattr.attr,
1314 &psmouse_attr_debug.dattr.attr, 1338 &psmouse_attr_debug.dattr.attr,
1315 &psmouse_attr_paritycheck.dattr.attr, 1339 &psmouse_attr_paritycheck.dattr.attr,
1340 &psmouse_attr_crc_enabled.dattr.attr,
1316 NULL 1341 NULL
1317}; 1342};
1318 1343
@@ -1439,6 +1464,22 @@ static int elantech_reconnect(struct psmouse *psmouse)
1439} 1464}
1440 1465
1441/* 1466/*
1467 * Some hw_version 4 models do not work with crc_disabled
1468 */
1469static const struct dmi_system_id elantech_dmi_force_crc_enabled[] = {
1470#if defined(CONFIG_DMI) && defined(CONFIG_X86)
1471 {
1472 /* Fujitsu H730 does not work with crc_enabled == 0 */
1473 .matches = {
1474 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
1475 DMI_MATCH(DMI_PRODUCT_NAME, "CELSIUS H730"),
1476 },
1477 },
1478#endif
1479 { }
1480};
1481
1482/*
1442 * Some hw_version 3 models go into error state when we try to set 1483 * Some hw_version 3 models go into error state when we try to set
1443 * bit 3 and/or bit 1 of r10. 1484 * bit 3 and/or bit 1 of r10.
1444 */ 1485 */
@@ -1513,7 +1554,8 @@ static int elantech_set_properties(struct elantech_data *etd)
1513 * The signatures of v3 and v4 packets change depending on the 1554 * The signatures of v3 and v4 packets change depending on the
1514 * value of this hardware flag. 1555 * value of this hardware flag.
1515 */ 1556 */
1516 etd->crc_enabled = ((etd->fw_version & 0x4000) == 0x4000); 1557 etd->crc_enabled = (etd->fw_version & 0x4000) == 0x4000 ||
1558 dmi_check_system(elantech_dmi_force_crc_enabled);
1517 1559
1518 /* Enable real hardware resolution on hw_version 3 ? */ 1560 /* Enable real hardware resolution on hw_version 3 ? */
1519 etd->set_hw_resolution = !dmi_check_system(no_hw_res_dmi_table); 1561 etd->set_hw_resolution = !dmi_check_system(no_hw_res_dmi_table);
diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c
index 9031a0a28ea4..f9472920d986 100644
--- a/drivers/input/mouse/synaptics.c
+++ b/drivers/input/mouse/synaptics.c
@@ -135,14 +135,18 @@ static const struct min_max_quirk min_max_pnpid_table[] = {
135 1232, 5710, 1156, 4696 135 1232, 5710, 1156, 4696
136 }, 136 },
137 { 137 {
138 (const char * const []){"LEN0034", "LEN0036", "LEN2002", 138 (const char * const []){"LEN0034", "LEN0036", "LEN0039",
139 "LEN2004", NULL}, 139 "LEN2002", "LEN2004", NULL},
140 1024, 5112, 2024, 4832 140 1024, 5112, 2024, 4832
141 }, 141 },
142 { 142 {
143 (const char * const []){"LEN2001", NULL}, 143 (const char * const []){"LEN2001", NULL},
144 1024, 5022, 2508, 4832 144 1024, 5022, 2508, 4832
145 }, 145 },
146 {
147 (const char * const []){"LEN2006", NULL},
148 1264, 5675, 1171, 4688
149 },
146 { } 150 { }
147}; 151};
148 152
@@ -163,6 +167,7 @@ static const char * const topbuttonpad_pnp_ids[] = {
163 "LEN0036", /* T440 */ 167 "LEN0036", /* T440 */
164 "LEN0037", 168 "LEN0037",
165 "LEN0038", 169 "LEN0038",
170 "LEN0039", /* T440s */
166 "LEN0041", 171 "LEN0041",
167 "LEN0042", /* Yoga */ 172 "LEN0042", /* Yoga */
168 "LEN0045", 173 "LEN0045",
diff --git a/drivers/irqchip/irq-armada-370-xp.c b/drivers/irqchip/irq-armada-370-xp.c
index 4ec137bba7f6..b907550ae9a5 100644
--- a/drivers/irqchip/irq-armada-370-xp.c
+++ b/drivers/irqchip/irq-armada-370-xp.c
@@ -44,6 +44,7 @@
44#define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34) 44#define ARMADA_370_XP_INT_CLEAR_ENABLE_OFFS (0x34)
45#define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4) 45#define ARMADA_370_XP_INT_SOURCE_CTL(irq) (0x100 + irq*4)
46#define ARMADA_370_XP_INT_SOURCE_CPU_MASK 0xF 46#define ARMADA_370_XP_INT_SOURCE_CPU_MASK 0xF
47#define ARMADA_370_XP_INT_IRQ_FIQ_MASK(cpuid) ((BIT(0) | BIT(8)) << cpuid)
47 48
48#define ARMADA_370_XP_CPU_INTACK_OFFS (0x44) 49#define ARMADA_370_XP_CPU_INTACK_OFFS (0x44)
49#define ARMADA_375_PPI_CAUSE (0x10) 50#define ARMADA_375_PPI_CAUSE (0x10)
@@ -408,19 +409,29 @@ static void armada_370_xp_mpic_handle_cascade_irq(unsigned int irq,
408 struct irq_desc *desc) 409 struct irq_desc *desc)
409{ 410{
410 struct irq_chip *chip = irq_get_chip(irq); 411 struct irq_chip *chip = irq_get_chip(irq);
411 unsigned long irqmap, irqn; 412 unsigned long irqmap, irqn, irqsrc, cpuid;
412 unsigned int cascade_irq; 413 unsigned int cascade_irq;
413 414
414 chained_irq_enter(chip, desc); 415 chained_irq_enter(chip, desc);
415 416
416 irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE); 417 irqmap = readl_relaxed(per_cpu_int_base + ARMADA_375_PPI_CAUSE);
417 418 cpuid = cpu_logical_map(smp_processor_id());
418 if (irqmap & BIT(0)) {
419 armada_370_xp_handle_msi_irq(NULL, true);
420 irqmap &= ~BIT(0);
421 }
422 419
423 for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) { 420 for_each_set_bit(irqn, &irqmap, BITS_PER_LONG) {
421 irqsrc = readl_relaxed(main_int_base +
422 ARMADA_370_XP_INT_SOURCE_CTL(irqn));
423
424 /* Check if the interrupt is not masked on current CPU.
425 * Test IRQ (0-1) and FIQ (8-9) mask bits.
426 */
427 if (!(irqsrc & ARMADA_370_XP_INT_IRQ_FIQ_MASK(cpuid)))
428 continue;
429
430 if (irqn == 1) {
431 armada_370_xp_handle_msi_irq(NULL, true);
432 continue;
433 }
434
424 cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn); 435 cascade_irq = irq_find_mapping(armada_370_xp_mpic_domain, irqn);
425 generic_handle_irq(cascade_irq); 436 generic_handle_irq(cascade_irq);
426 } 437 }
diff --git a/drivers/irqchip/irq-atmel-aic-common.c b/drivers/irqchip/irq-atmel-aic-common.c
index 6ae3cdee0681..cc4f9d80122e 100644
--- a/drivers/irqchip/irq-atmel-aic-common.c
+++ b/drivers/irqchip/irq-atmel-aic-common.c
@@ -217,8 +217,9 @@ struct irq_domain *__init aic_common_of_init(struct device_node *node,
217 } 217 }
218 218
219 ret = irq_alloc_domain_generic_chips(domain, 32, 1, name, 219 ret = irq_alloc_domain_generic_chips(domain, 32, 1, name,
220 handle_level_irq, 0, 0, 220 handle_fasteoi_irq,
221 IRQCHIP_SKIP_SET_WAKE); 221 IRQ_NOREQUEST | IRQ_NOPROBE |
222 IRQ_NOAUTOEN, 0, 0);
222 if (ret) 223 if (ret)
223 goto err_domain_remove; 224 goto err_domain_remove;
224 225
@@ -230,7 +231,6 @@ struct irq_domain *__init aic_common_of_init(struct device_node *node,
230 gc->unused = 0; 231 gc->unused = 0;
231 gc->wake_enabled = ~0; 232 gc->wake_enabled = ~0;
232 gc->chip_types[0].type = IRQ_TYPE_SENSE_MASK; 233 gc->chip_types[0].type = IRQ_TYPE_SENSE_MASK;
233 gc->chip_types[0].handler = handle_fasteoi_irq;
234 gc->chip_types[0].chip.irq_eoi = irq_gc_eoi; 234 gc->chip_types[0].chip.irq_eoi = irq_gc_eoi;
235 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake; 235 gc->chip_types[0].chip.irq_set_wake = irq_gc_set_wake;
236 gc->chip_types[0].chip.irq_shutdown = aic_common_shutdown; 236 gc->chip_types[0].chip.irq_shutdown = aic_common_shutdown;
diff --git a/drivers/irqchip/irq-bcm7120-l2.c b/drivers/irqchip/irq-bcm7120-l2.c
index b9f4fb808e49..5fb38a2ac226 100644
--- a/drivers/irqchip/irq-bcm7120-l2.c
+++ b/drivers/irqchip/irq-bcm7120-l2.c
@@ -101,9 +101,9 @@ static int bcm7120_l2_intc_init_one(struct device_node *dn,
101 int parent_irq; 101 int parent_irq;
102 102
103 parent_irq = irq_of_parse_and_map(dn, irq); 103 parent_irq = irq_of_parse_and_map(dn, irq);
104 if (parent_irq < 0) { 104 if (!parent_irq) {
105 pr_err("failed to map interrupt %d\n", irq); 105 pr_err("failed to map interrupt %d\n", irq);
106 return parent_irq; 106 return -EINVAL;
107 } 107 }
108 108
109 data->irq_map_mask |= be32_to_cpup(map_mask + irq); 109 data->irq_map_mask |= be32_to_cpup(map_mask + irq);
diff --git a/drivers/irqchip/irq-brcmstb-l2.c b/drivers/irqchip/irq-brcmstb-l2.c
index c15c840987d2..14691a4cb84c 100644
--- a/drivers/irqchip/irq-brcmstb-l2.c
+++ b/drivers/irqchip/irq-brcmstb-l2.c
@@ -135,9 +135,9 @@ int __init brcmstb_l2_intc_of_init(struct device_node *np,
135 __raw_writel(0xffffffff, data->base + CPU_CLEAR); 135 __raw_writel(0xffffffff, data->base + CPU_CLEAR);
136 136
137 data->parent_irq = irq_of_parse_and_map(np, 0); 137 data->parent_irq = irq_of_parse_and_map(np, 0);
138 if (data->parent_irq < 0) { 138 if (!data->parent_irq) {
139 pr_err("failed to find parent interrupt\n"); 139 pr_err("failed to find parent interrupt\n");
140 ret = data->parent_irq; 140 ret = -EINVAL;
141 goto out_unmap; 141 goto out_unmap;
142 } 142 }
143 143
diff --git a/drivers/md/dm-bio-prison.c b/drivers/md/dm-bio-prison.c
index f752d12081ff..be065300e93c 100644
--- a/drivers/md/dm-bio-prison.c
+++ b/drivers/md/dm-bio-prison.c
@@ -14,68 +14,38 @@
14 14
15/*----------------------------------------------------------------*/ 15/*----------------------------------------------------------------*/
16 16
17struct bucket { 17#define MIN_CELLS 1024
18 spinlock_t lock;
19 struct hlist_head cells;
20};
21 18
22struct dm_bio_prison { 19struct dm_bio_prison {
20 spinlock_t lock;
23 mempool_t *cell_pool; 21 mempool_t *cell_pool;
24 22 struct rb_root cells;
25 unsigned nr_buckets;
26 unsigned hash_mask;
27 struct bucket *buckets;
28}; 23};
29 24
30/*----------------------------------------------------------------*/
31
32static uint32_t calc_nr_buckets(unsigned nr_cells)
33{
34 uint32_t n = 128;
35
36 nr_cells /= 4;
37 nr_cells = min(nr_cells, 8192u);
38
39 while (n < nr_cells)
40 n <<= 1;
41
42 return n;
43}
44
45static struct kmem_cache *_cell_cache; 25static struct kmem_cache *_cell_cache;
46 26
47static void init_bucket(struct bucket *b) 27/*----------------------------------------------------------------*/
48{
49 spin_lock_init(&b->lock);
50 INIT_HLIST_HEAD(&b->cells);
51}
52 28
53/* 29/*
54 * @nr_cells should be the number of cells you want in use _concurrently_. 30 * @nr_cells should be the number of cells you want in use _concurrently_.
55 * Don't confuse it with the number of distinct keys. 31 * Don't confuse it with the number of distinct keys.
56 */ 32 */
57struct dm_bio_prison *dm_bio_prison_create(unsigned nr_cells) 33struct dm_bio_prison *dm_bio_prison_create(void)
58{ 34{
59 unsigned i; 35 struct dm_bio_prison *prison = kmalloc(sizeof(*prison), GFP_KERNEL);
60 uint32_t nr_buckets = calc_nr_buckets(nr_cells);
61 size_t len = sizeof(struct dm_bio_prison) +
62 (sizeof(struct bucket) * nr_buckets);
63 struct dm_bio_prison *prison = kmalloc(len, GFP_KERNEL);
64 36
65 if (!prison) 37 if (!prison)
66 return NULL; 38 return NULL;
67 39
68 prison->cell_pool = mempool_create_slab_pool(nr_cells, _cell_cache); 40 spin_lock_init(&prison->lock);
41
42 prison->cell_pool = mempool_create_slab_pool(MIN_CELLS, _cell_cache);
69 if (!prison->cell_pool) { 43 if (!prison->cell_pool) {
70 kfree(prison); 44 kfree(prison);
71 return NULL; 45 return NULL;
72 } 46 }
73 47
74 prison->nr_buckets = nr_buckets; 48 prison->cells = RB_ROOT;
75 prison->hash_mask = nr_buckets - 1;
76 prison->buckets = (struct bucket *) (prison + 1);
77 for (i = 0; i < nr_buckets; i++)
78 init_bucket(prison->buckets + i);
79 49
80 return prison; 50 return prison;
81} 51}
@@ -101,68 +71,73 @@ void dm_bio_prison_free_cell(struct dm_bio_prison *prison,
101} 71}
102EXPORT_SYMBOL_GPL(dm_bio_prison_free_cell); 72EXPORT_SYMBOL_GPL(dm_bio_prison_free_cell);
103 73
104static uint32_t hash_key(struct dm_bio_prison *prison, struct dm_cell_key *key) 74static void __setup_new_cell(struct dm_cell_key *key,
75 struct bio *holder,
76 struct dm_bio_prison_cell *cell)
105{ 77{
106 const unsigned long BIG_PRIME = 4294967291UL; 78 memcpy(&cell->key, key, sizeof(cell->key));
107 uint64_t hash = key->block * BIG_PRIME; 79 cell->holder = holder;
108 80 bio_list_init(&cell->bios);
109 return (uint32_t) (hash & prison->hash_mask);
110} 81}
111 82
112static int keys_equal(struct dm_cell_key *lhs, struct dm_cell_key *rhs) 83static int cmp_keys(struct dm_cell_key *lhs,
84 struct dm_cell_key *rhs)
113{ 85{
114 return (lhs->virtual == rhs->virtual) && 86 if (lhs->virtual < rhs->virtual)
115 (lhs->dev == rhs->dev) && 87 return -1;
116 (lhs->block == rhs->block);
117}
118 88
119static struct bucket *get_bucket(struct dm_bio_prison *prison, 89 if (lhs->virtual > rhs->virtual)
120 struct dm_cell_key *key) 90 return 1;
121{
122 return prison->buckets + hash_key(prison, key);
123}
124 91
125static struct dm_bio_prison_cell *__search_bucket(struct bucket *b, 92 if (lhs->dev < rhs->dev)
126 struct dm_cell_key *key) 93 return -1;
127{
128 struct dm_bio_prison_cell *cell;
129 94
130 hlist_for_each_entry(cell, &b->cells, list) 95 if (lhs->dev > rhs->dev)
131 if (keys_equal(&cell->key, key)) 96 return 1;
132 return cell;
133 97
134 return NULL; 98 if (lhs->block_end <= rhs->block_begin)
135} 99 return -1;
136 100
137static void __setup_new_cell(struct bucket *b, 101 if (lhs->block_begin >= rhs->block_end)
138 struct dm_cell_key *key, 102 return 1;
139 struct bio *holder, 103
140 struct dm_bio_prison_cell *cell) 104 return 0;
141{
142 memcpy(&cell->key, key, sizeof(cell->key));
143 cell->holder = holder;
144 bio_list_init(&cell->bios);
145 hlist_add_head(&cell->list, &b->cells);
146} 105}
147 106
148static int __bio_detain(struct bucket *b, 107static int __bio_detain(struct dm_bio_prison *prison,
149 struct dm_cell_key *key, 108 struct dm_cell_key *key,
150 struct bio *inmate, 109 struct bio *inmate,
151 struct dm_bio_prison_cell *cell_prealloc, 110 struct dm_bio_prison_cell *cell_prealloc,
152 struct dm_bio_prison_cell **cell_result) 111 struct dm_bio_prison_cell **cell_result)
153{ 112{
154 struct dm_bio_prison_cell *cell; 113 int r;
155 114 struct rb_node **new = &prison->cells.rb_node, *parent = NULL;
156 cell = __search_bucket(b, key); 115
157 if (cell) { 116 while (*new) {
158 if (inmate) 117 struct dm_bio_prison_cell *cell =
159 bio_list_add(&cell->bios, inmate); 118 container_of(*new, struct dm_bio_prison_cell, node);
160 *cell_result = cell; 119
161 return 1; 120 r = cmp_keys(key, &cell->key);
121
122 parent = *new;
123 if (r < 0)
124 new = &((*new)->rb_left);
125 else if (r > 0)
126 new = &((*new)->rb_right);
127 else {
128 if (inmate)
129 bio_list_add(&cell->bios, inmate);
130 *cell_result = cell;
131 return 1;
132 }
162 } 133 }
163 134
164 __setup_new_cell(b, key, inmate, cell_prealloc); 135 __setup_new_cell(key, inmate, cell_prealloc);
165 *cell_result = cell_prealloc; 136 *cell_result = cell_prealloc;
137
138 rb_link_node(&cell_prealloc->node, parent, new);
139 rb_insert_color(&cell_prealloc->node, &prison->cells);
140
166 return 0; 141 return 0;
167} 142}
168 143
@@ -174,11 +149,10 @@ static int bio_detain(struct dm_bio_prison *prison,
174{ 149{
175 int r; 150 int r;
176 unsigned long flags; 151 unsigned long flags;
177 struct bucket *b = get_bucket(prison, key);
178 152
179 spin_lock_irqsave(&b->lock, flags); 153 spin_lock_irqsave(&prison->lock, flags);
180 r = __bio_detain(b, key, inmate, cell_prealloc, cell_result); 154 r = __bio_detain(prison, key, inmate, cell_prealloc, cell_result);
181 spin_unlock_irqrestore(&b->lock, flags); 155 spin_unlock_irqrestore(&prison->lock, flags);
182 156
183 return r; 157 return r;
184} 158}
@@ -205,10 +179,11 @@ EXPORT_SYMBOL_GPL(dm_get_cell);
205/* 179/*
206 * @inmates must have been initialised prior to this call 180 * @inmates must have been initialised prior to this call
207 */ 181 */
208static void __cell_release(struct dm_bio_prison_cell *cell, 182static void __cell_release(struct dm_bio_prison *prison,
183 struct dm_bio_prison_cell *cell,
209 struct bio_list *inmates) 184 struct bio_list *inmates)
210{ 185{
211 hlist_del(&cell->list); 186 rb_erase(&cell->node, &prison->cells);
212 187
213 if (inmates) { 188 if (inmates) {
214 if (cell->holder) 189 if (cell->holder)
@@ -222,21 +197,21 @@ void dm_cell_release(struct dm_bio_prison *prison,
222 struct bio_list *bios) 197 struct bio_list *bios)
223{ 198{
224 unsigned long flags; 199 unsigned long flags;
225 struct bucket *b = get_bucket(prison, &cell->key);
226 200
227 spin_lock_irqsave(&b->lock, flags); 201 spin_lock_irqsave(&prison->lock, flags);
228 __cell_release(cell, bios); 202 __cell_release(prison, cell, bios);
229 spin_unlock_irqrestore(&b->lock, flags); 203 spin_unlock_irqrestore(&prison->lock, flags);
230} 204}
231EXPORT_SYMBOL_GPL(dm_cell_release); 205EXPORT_SYMBOL_GPL(dm_cell_release);
232 206
233/* 207/*
234 * Sometimes we don't want the holder, just the additional bios. 208 * Sometimes we don't want the holder, just the additional bios.
235 */ 209 */
236static void __cell_release_no_holder(struct dm_bio_prison_cell *cell, 210static void __cell_release_no_holder(struct dm_bio_prison *prison,
211 struct dm_bio_prison_cell *cell,
237 struct bio_list *inmates) 212 struct bio_list *inmates)
238{ 213{
239 hlist_del(&cell->list); 214 rb_erase(&cell->node, &prison->cells);
240 bio_list_merge(inmates, &cell->bios); 215 bio_list_merge(inmates, &cell->bios);
241} 216}
242 217
@@ -245,11 +220,10 @@ void dm_cell_release_no_holder(struct dm_bio_prison *prison,
245 struct bio_list *inmates) 220 struct bio_list *inmates)
246{ 221{
247 unsigned long flags; 222 unsigned long flags;
248 struct bucket *b = get_bucket(prison, &cell->key);
249 223
250 spin_lock_irqsave(&b->lock, flags); 224 spin_lock_irqsave(&prison->lock, flags);
251 __cell_release_no_holder(cell, inmates); 225 __cell_release_no_holder(prison, cell, inmates);
252 spin_unlock_irqrestore(&b->lock, flags); 226 spin_unlock_irqrestore(&prison->lock, flags);
253} 227}
254EXPORT_SYMBOL_GPL(dm_cell_release_no_holder); 228EXPORT_SYMBOL_GPL(dm_cell_release_no_holder);
255 229
@@ -267,6 +241,20 @@ void dm_cell_error(struct dm_bio_prison *prison,
267} 241}
268EXPORT_SYMBOL_GPL(dm_cell_error); 242EXPORT_SYMBOL_GPL(dm_cell_error);
269 243
244void dm_cell_visit_release(struct dm_bio_prison *prison,
245 void (*visit_fn)(void *, struct dm_bio_prison_cell *),
246 void *context,
247 struct dm_bio_prison_cell *cell)
248{
249 unsigned long flags;
250
251 spin_lock_irqsave(&prison->lock, flags);
252 visit_fn(context, cell);
253 rb_erase(&cell->node, &prison->cells);
254 spin_unlock_irqrestore(&prison->lock, flags);
255}
256EXPORT_SYMBOL_GPL(dm_cell_visit_release);
257
270/*----------------------------------------------------------------*/ 258/*----------------------------------------------------------------*/
271 259
272#define DEFERRED_SET_SIZE 64 260#define DEFERRED_SET_SIZE 64
diff --git a/drivers/md/dm-bio-prison.h b/drivers/md/dm-bio-prison.h
index 6805a142b750..74cf01144b1f 100644
--- a/drivers/md/dm-bio-prison.h
+++ b/drivers/md/dm-bio-prison.h
@@ -10,8 +10,8 @@
10#include "persistent-data/dm-block-manager.h" /* FIXME: for dm_block_t */ 10#include "persistent-data/dm-block-manager.h" /* FIXME: for dm_block_t */
11#include "dm-thin-metadata.h" /* FIXME: for dm_thin_id */ 11#include "dm-thin-metadata.h" /* FIXME: for dm_thin_id */
12 12
13#include <linux/list.h>
14#include <linux/bio.h> 13#include <linux/bio.h>
14#include <linux/rbtree.h>
15 15
16/*----------------------------------------------------------------*/ 16/*----------------------------------------------------------------*/
17 17
@@ -23,11 +23,14 @@
23 */ 23 */
24struct dm_bio_prison; 24struct dm_bio_prison;
25 25
26/* FIXME: this needs to be more abstract */ 26/*
27 * Keys define a range of blocks within either a virtual or physical
28 * device.
29 */
27struct dm_cell_key { 30struct dm_cell_key {
28 int virtual; 31 int virtual;
29 dm_thin_id dev; 32 dm_thin_id dev;
30 dm_block_t block; 33 dm_block_t block_begin, block_end;
31}; 34};
32 35
33/* 36/*
@@ -35,13 +38,15 @@ struct dm_cell_key {
35 * themselves. 38 * themselves.
36 */ 39 */
37struct dm_bio_prison_cell { 40struct dm_bio_prison_cell {
38 struct hlist_node list; 41 struct list_head user_list; /* for client use */
42 struct rb_node node;
43
39 struct dm_cell_key key; 44 struct dm_cell_key key;
40 struct bio *holder; 45 struct bio *holder;
41 struct bio_list bios; 46 struct bio_list bios;
42}; 47};
43 48
44struct dm_bio_prison *dm_bio_prison_create(unsigned nr_cells); 49struct dm_bio_prison *dm_bio_prison_create(void);
45void dm_bio_prison_destroy(struct dm_bio_prison *prison); 50void dm_bio_prison_destroy(struct dm_bio_prison *prison);
46 51
47/* 52/*
@@ -57,7 +62,7 @@ void dm_bio_prison_free_cell(struct dm_bio_prison *prison,
57 struct dm_bio_prison_cell *cell); 62 struct dm_bio_prison_cell *cell);
58 63
59/* 64/*
60 * Creates, or retrieves a cell for the given key. 65 * Creates, or retrieves a cell that overlaps the given key.
61 * 66 *
62 * Returns 1 if pre-existing cell returned, zero if new cell created using 67 * Returns 1 if pre-existing cell returned, zero if new cell created using
63 * @cell_prealloc. 68 * @cell_prealloc.
@@ -68,7 +73,8 @@ int dm_get_cell(struct dm_bio_prison *prison,
68 struct dm_bio_prison_cell **cell_result); 73 struct dm_bio_prison_cell **cell_result);
69 74
70/* 75/*
71 * An atomic op that combines retrieving a cell, and adding a bio to it. 76 * An atomic op that combines retrieving or creating a cell, and adding a
77 * bio to it.
72 * 78 *
73 * Returns 1 if the cell was already held, 0 if @inmate is the new holder. 79 * Returns 1 if the cell was already held, 0 if @inmate is the new holder.
74 */ 80 */
@@ -87,6 +93,14 @@ void dm_cell_release_no_holder(struct dm_bio_prison *prison,
87void dm_cell_error(struct dm_bio_prison *prison, 93void dm_cell_error(struct dm_bio_prison *prison,
88 struct dm_bio_prison_cell *cell, int error); 94 struct dm_bio_prison_cell *cell, int error);
89 95
96/*
97 * Visits the cell and then releases. Guarantees no new inmates are
98 * inserted between the visit and release.
99 */
100void dm_cell_visit_release(struct dm_bio_prison *prison,
101 void (*visit_fn)(void *, struct dm_bio_prison_cell *),
102 void *context, struct dm_bio_prison_cell *cell);
103
90/*----------------------------------------------------------------*/ 104/*----------------------------------------------------------------*/
91 105
92/* 106/*
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 825ca1f87639..c33b49792b87 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -14,6 +14,7 @@
14#include <linux/vmalloc.h> 14#include <linux/vmalloc.h>
15#include <linux/shrinker.h> 15#include <linux/shrinker.h>
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/rbtree.h>
17 18
18#define DM_MSG_PREFIX "bufio" 19#define DM_MSG_PREFIX "bufio"
19 20
@@ -34,26 +35,23 @@
34/* 35/*
35 * Check buffer ages in this interval (seconds) 36 * Check buffer ages in this interval (seconds)
36 */ 37 */
37#define DM_BUFIO_WORK_TIMER_SECS 10 38#define DM_BUFIO_WORK_TIMER_SECS 30
38 39
39/* 40/*
40 * Free buffers when they are older than this (seconds) 41 * Free buffers when they are older than this (seconds)
41 */ 42 */
42#define DM_BUFIO_DEFAULT_AGE_SECS 60 43#define DM_BUFIO_DEFAULT_AGE_SECS 300
43 44
44/* 45/*
45 * The number of bvec entries that are embedded directly in the buffer. 46 * The nr of bytes of cached data to keep around.
46 * If the chunk size is larger, dm-io is used to do the io.
47 */ 47 */
48#define DM_BUFIO_INLINE_VECS 16 48#define DM_BUFIO_DEFAULT_RETAIN_BYTES (256 * 1024)
49 49
50/* 50/*
51 * Buffer hash 51 * The number of bvec entries that are embedded directly in the buffer.
52 * If the chunk size is larger, dm-io is used to do the io.
52 */ 53 */
53#define DM_BUFIO_HASH_BITS 20 54#define DM_BUFIO_INLINE_VECS 16
54#define DM_BUFIO_HASH(block) \
55 ((((block) >> DM_BUFIO_HASH_BITS) ^ (block)) & \
56 ((1 << DM_BUFIO_HASH_BITS) - 1))
57 55
58/* 56/*
59 * Don't try to use kmem_cache_alloc for blocks larger than this. 57 * Don't try to use kmem_cache_alloc for blocks larger than this.
@@ -106,7 +104,7 @@ struct dm_bufio_client {
106 104
107 unsigned minimum_buffers; 105 unsigned minimum_buffers;
108 106
109 struct hlist_head *cache_hash; 107 struct rb_root buffer_tree;
110 wait_queue_head_t free_buffer_wait; 108 wait_queue_head_t free_buffer_wait;
111 109
112 int async_write_error; 110 int async_write_error;
@@ -135,7 +133,7 @@ enum data_mode {
135}; 133};
136 134
137struct dm_buffer { 135struct dm_buffer {
138 struct hlist_node hash_list; 136 struct rb_node node;
139 struct list_head lru_list; 137 struct list_head lru_list;
140 sector_t block; 138 sector_t block;
141 void *data; 139 void *data;
@@ -223,6 +221,7 @@ static DEFINE_SPINLOCK(param_spinlock);
223 * Buffers are freed after this timeout 221 * Buffers are freed after this timeout
224 */ 222 */
225static unsigned dm_bufio_max_age = DM_BUFIO_DEFAULT_AGE_SECS; 223static unsigned dm_bufio_max_age = DM_BUFIO_DEFAULT_AGE_SECS;
224static unsigned dm_bufio_retain_bytes = DM_BUFIO_DEFAULT_RETAIN_BYTES;
226 225
227static unsigned long dm_bufio_peak_allocated; 226static unsigned long dm_bufio_peak_allocated;
228static unsigned long dm_bufio_allocated_kmem_cache; 227static unsigned long dm_bufio_allocated_kmem_cache;
@@ -253,6 +252,53 @@ static LIST_HEAD(dm_bufio_all_clients);
253 */ 252 */
254static DEFINE_MUTEX(dm_bufio_clients_lock); 253static DEFINE_MUTEX(dm_bufio_clients_lock);
255 254
255/*----------------------------------------------------------------
256 * A red/black tree acts as an index for all the buffers.
257 *--------------------------------------------------------------*/
258static struct dm_buffer *__find(struct dm_bufio_client *c, sector_t block)
259{
260 struct rb_node *n = c->buffer_tree.rb_node;
261 struct dm_buffer *b;
262
263 while (n) {
264 b = container_of(n, struct dm_buffer, node);
265
266 if (b->block == block)
267 return b;
268
269 n = (b->block < block) ? n->rb_left : n->rb_right;
270 }
271
272 return NULL;
273}
274
275static void __insert(struct dm_bufio_client *c, struct dm_buffer *b)
276{
277 struct rb_node **new = &c->buffer_tree.rb_node, *parent = NULL;
278 struct dm_buffer *found;
279
280 while (*new) {
281 found = container_of(*new, struct dm_buffer, node);
282
283 if (found->block == b->block) {
284 BUG_ON(found != b);
285 return;
286 }
287
288 parent = *new;
289 new = (found->block < b->block) ?
290 &((*new)->rb_left) : &((*new)->rb_right);
291 }
292
293 rb_link_node(&b->node, parent, new);
294 rb_insert_color(&b->node, &c->buffer_tree);
295}
296
297static void __remove(struct dm_bufio_client *c, struct dm_buffer *b)
298{
299 rb_erase(&b->node, &c->buffer_tree);
300}
301
256/*----------------------------------------------------------------*/ 302/*----------------------------------------------------------------*/
257 303
258static void adjust_total_allocated(enum data_mode data_mode, long diff) 304static void adjust_total_allocated(enum data_mode data_mode, long diff)
@@ -434,7 +480,7 @@ static void __link_buffer(struct dm_buffer *b, sector_t block, int dirty)
434 b->block = block; 480 b->block = block;
435 b->list_mode = dirty; 481 b->list_mode = dirty;
436 list_add(&b->lru_list, &c->lru[dirty]); 482 list_add(&b->lru_list, &c->lru[dirty]);
437 hlist_add_head(&b->hash_list, &c->cache_hash[DM_BUFIO_HASH(block)]); 483 __insert(b->c, b);
438 b->last_accessed = jiffies; 484 b->last_accessed = jiffies;
439} 485}
440 486
@@ -448,7 +494,7 @@ static void __unlink_buffer(struct dm_buffer *b)
448 BUG_ON(!c->n_buffers[b->list_mode]); 494 BUG_ON(!c->n_buffers[b->list_mode]);
449 495
450 c->n_buffers[b->list_mode]--; 496 c->n_buffers[b->list_mode]--;
451 hlist_del(&b->hash_list); 497 __remove(b->c, b);
452 list_del(&b->lru_list); 498 list_del(&b->lru_list);
453} 499}
454 500
@@ -532,6 +578,19 @@ static void use_dmio(struct dm_buffer *b, int rw, sector_t block,
532 end_io(&b->bio, r); 578 end_io(&b->bio, r);
533} 579}
534 580
581static void inline_endio(struct bio *bio, int error)
582{
583 bio_end_io_t *end_fn = bio->bi_private;
584
585 /*
586 * Reset the bio to free any attached resources
587 * (e.g. bio integrity profiles).
588 */
589 bio_reset(bio);
590
591 end_fn(bio, error);
592}
593
535static void use_inline_bio(struct dm_buffer *b, int rw, sector_t block, 594static void use_inline_bio(struct dm_buffer *b, int rw, sector_t block,
536 bio_end_io_t *end_io) 595 bio_end_io_t *end_io)
537{ 596{
@@ -543,7 +602,12 @@ static void use_inline_bio(struct dm_buffer *b, int rw, sector_t block,
543 b->bio.bi_max_vecs = DM_BUFIO_INLINE_VECS; 602 b->bio.bi_max_vecs = DM_BUFIO_INLINE_VECS;
544 b->bio.bi_iter.bi_sector = block << b->c->sectors_per_block_bits; 603 b->bio.bi_iter.bi_sector = block << b->c->sectors_per_block_bits;
545 b->bio.bi_bdev = b->c->bdev; 604 b->bio.bi_bdev = b->c->bdev;
546 b->bio.bi_end_io = end_io; 605 b->bio.bi_end_io = inline_endio;
606 /*
607 * Use of .bi_private isn't a problem here because
608 * the dm_buffer's inline bio is local to bufio.
609 */
610 b->bio.bi_private = end_io;
547 611
548 /* 612 /*
549 * We assume that if len >= PAGE_SIZE ptr is page-aligned. 613 * We assume that if len >= PAGE_SIZE ptr is page-aligned.
@@ -887,23 +951,6 @@ static void __check_watermark(struct dm_bufio_client *c,
887 __write_dirty_buffers_async(c, 1, write_list); 951 __write_dirty_buffers_async(c, 1, write_list);
888} 952}
889 953
890/*
891 * Find a buffer in the hash.
892 */
893static struct dm_buffer *__find(struct dm_bufio_client *c, sector_t block)
894{
895 struct dm_buffer *b;
896
897 hlist_for_each_entry(b, &c->cache_hash[DM_BUFIO_HASH(block)],
898 hash_list) {
899 dm_bufio_cond_resched();
900 if (b->block == block)
901 return b;
902 }
903
904 return NULL;
905}
906
907/*---------------------------------------------------------------- 954/*----------------------------------------------------------------
908 * Getting a buffer 955 * Getting a buffer
909 *--------------------------------------------------------------*/ 956 *--------------------------------------------------------------*/
@@ -1433,45 +1480,52 @@ static void drop_buffers(struct dm_bufio_client *c)
1433} 1480}
1434 1481
1435/* 1482/*
1436 * Test if the buffer is unused and too old, and commit it. 1483 * We may not be able to evict this buffer if IO pending or the client
1437 * At if noio is set, we must not do any I/O because we hold 1484 * is still using it. Caller is expected to know buffer is too old.
1438 * dm_bufio_clients_lock and we would risk deadlock if the I/O gets rerouted to 1485 *
1439 * different bufio client. 1486 * And if GFP_NOFS is used, we must not do any I/O because we hold
1487 * dm_bufio_clients_lock and we would risk deadlock if the I/O gets
1488 * rerouted to different bufio client.
1440 */ 1489 */
1441static int __cleanup_old_buffer(struct dm_buffer *b, gfp_t gfp, 1490static bool __try_evict_buffer(struct dm_buffer *b, gfp_t gfp)
1442 unsigned long max_jiffies)
1443{ 1491{
1444 if (jiffies - b->last_accessed < max_jiffies) 1492 if (!(gfp & __GFP_FS)) {
1445 return 0;
1446
1447 if (!(gfp & __GFP_IO)) {
1448 if (test_bit(B_READING, &b->state) || 1493 if (test_bit(B_READING, &b->state) ||
1449 test_bit(B_WRITING, &b->state) || 1494 test_bit(B_WRITING, &b->state) ||
1450 test_bit(B_DIRTY, &b->state)) 1495 test_bit(B_DIRTY, &b->state))
1451 return 0; 1496 return false;
1452 } 1497 }
1453 1498
1454 if (b->hold_count) 1499 if (b->hold_count)
1455 return 0; 1500 return false;
1456 1501
1457 __make_buffer_clean(b); 1502 __make_buffer_clean(b);
1458 __unlink_buffer(b); 1503 __unlink_buffer(b);
1459 __free_buffer_wake(b); 1504 __free_buffer_wake(b);
1460 1505
1461 return 1; 1506 return true;
1462} 1507}
1463 1508
1464static long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan, 1509static unsigned get_retain_buffers(struct dm_bufio_client *c)
1465 gfp_t gfp_mask) 1510{
1511 unsigned retain_bytes = ACCESS_ONCE(dm_bufio_retain_bytes);
1512 return retain_bytes / c->block_size;
1513}
1514
1515static unsigned long __scan(struct dm_bufio_client *c, unsigned long nr_to_scan,
1516 gfp_t gfp_mask)
1466{ 1517{
1467 int l; 1518 int l;
1468 struct dm_buffer *b, *tmp; 1519 struct dm_buffer *b, *tmp;
1469 long freed = 0; 1520 unsigned long freed = 0;
1521 unsigned long count = nr_to_scan;
1522 unsigned retain_target = get_retain_buffers(c);
1470 1523
1471 for (l = 0; l < LIST_SIZE; l++) { 1524 for (l = 0; l < LIST_SIZE; l++) {
1472 list_for_each_entry_safe_reverse(b, tmp, &c->lru[l], lru_list) { 1525 list_for_each_entry_safe_reverse(b, tmp, &c->lru[l], lru_list) {
1473 freed += __cleanup_old_buffer(b, gfp_mask, 0); 1526 if (__try_evict_buffer(b, gfp_mask))
1474 if (!--nr_to_scan) 1527 freed++;
1528 if (!--nr_to_scan || ((count - freed) <= retain_target))
1475 return freed; 1529 return freed;
1476 dm_bufio_cond_resched(); 1530 dm_bufio_cond_resched();
1477 } 1531 }
@@ -1486,7 +1540,7 @@ dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
1486 unsigned long freed; 1540 unsigned long freed;
1487 1541
1488 c = container_of(shrink, struct dm_bufio_client, shrinker); 1542 c = container_of(shrink, struct dm_bufio_client, shrinker);
1489 if (sc->gfp_mask & __GFP_IO) 1543 if (sc->gfp_mask & __GFP_FS)
1490 dm_bufio_lock(c); 1544 dm_bufio_lock(c);
1491 else if (!dm_bufio_trylock(c)) 1545 else if (!dm_bufio_trylock(c))
1492 return SHRINK_STOP; 1546 return SHRINK_STOP;
@@ -1503,7 +1557,7 @@ dm_bufio_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
1503 unsigned long count; 1557 unsigned long count;
1504 1558
1505 c = container_of(shrink, struct dm_bufio_client, shrinker); 1559 c = container_of(shrink, struct dm_bufio_client, shrinker);
1506 if (sc->gfp_mask & __GFP_IO) 1560 if (sc->gfp_mask & __GFP_FS)
1507 dm_bufio_lock(c); 1561 dm_bufio_lock(c);
1508 else if (!dm_bufio_trylock(c)) 1562 else if (!dm_bufio_trylock(c))
1509 return 0; 1563 return 0;
@@ -1533,11 +1587,7 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
1533 r = -ENOMEM; 1587 r = -ENOMEM;
1534 goto bad_client; 1588 goto bad_client;
1535 } 1589 }
1536 c->cache_hash = vmalloc(sizeof(struct hlist_head) << DM_BUFIO_HASH_BITS); 1590 c->buffer_tree = RB_ROOT;
1537 if (!c->cache_hash) {
1538 r = -ENOMEM;
1539 goto bad_hash;
1540 }
1541 1591
1542 c->bdev = bdev; 1592 c->bdev = bdev;
1543 c->block_size = block_size; 1593 c->block_size = block_size;
@@ -1556,9 +1606,6 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign
1556 c->n_buffers[i] = 0; 1606 c->n_buffers[i] = 0;
1557 } 1607 }
1558 1608
1559 for (i = 0; i < 1 << DM_BUFIO_HASH_BITS; i++)
1560 INIT_HLIST_HEAD(&c->cache_hash[i]);
1561
1562 mutex_init(&c->lock); 1609 mutex_init(&c->lock);
1563 INIT_LIST_HEAD(&c->reserved_buffers); 1610 INIT_LIST_HEAD(&c->reserved_buffers);
1564 c->need_reserved_buffers = reserved_buffers; 1611 c->need_reserved_buffers = reserved_buffers;
@@ -1632,8 +1679,6 @@ bad_cache:
1632 } 1679 }
1633 dm_io_client_destroy(c->dm_io); 1680 dm_io_client_destroy(c->dm_io);
1634bad_dm_io: 1681bad_dm_io:
1635 vfree(c->cache_hash);
1636bad_hash:
1637 kfree(c); 1682 kfree(c);
1638bad_client: 1683bad_client:
1639 return ERR_PTR(r); 1684 return ERR_PTR(r);
@@ -1660,9 +1705,7 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c)
1660 1705
1661 mutex_unlock(&dm_bufio_clients_lock); 1706 mutex_unlock(&dm_bufio_clients_lock);
1662 1707
1663 for (i = 0; i < 1 << DM_BUFIO_HASH_BITS; i++) 1708 BUG_ON(!RB_EMPTY_ROOT(&c->buffer_tree));
1664 BUG_ON(!hlist_empty(&c->cache_hash[i]));
1665
1666 BUG_ON(c->need_reserved_buffers); 1709 BUG_ON(c->need_reserved_buffers);
1667 1710
1668 while (!list_empty(&c->reserved_buffers)) { 1711 while (!list_empty(&c->reserved_buffers)) {
@@ -1680,36 +1723,60 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c)
1680 BUG_ON(c->n_buffers[i]); 1723 BUG_ON(c->n_buffers[i]);
1681 1724
1682 dm_io_client_destroy(c->dm_io); 1725 dm_io_client_destroy(c->dm_io);
1683 vfree(c->cache_hash);
1684 kfree(c); 1726 kfree(c);
1685} 1727}
1686EXPORT_SYMBOL_GPL(dm_bufio_client_destroy); 1728EXPORT_SYMBOL_GPL(dm_bufio_client_destroy);
1687 1729
1688static void cleanup_old_buffers(void) 1730static unsigned get_max_age_hz(void)
1689{ 1731{
1690 unsigned long max_age = ACCESS_ONCE(dm_bufio_max_age); 1732 unsigned max_age = ACCESS_ONCE(dm_bufio_max_age);
1691 struct dm_bufio_client *c;
1692 1733
1693 if (max_age > ULONG_MAX / HZ) 1734 if (max_age > UINT_MAX / HZ)
1694 max_age = ULONG_MAX / HZ; 1735 max_age = UINT_MAX / HZ;
1695 1736
1696 mutex_lock(&dm_bufio_clients_lock); 1737 return max_age * HZ;
1697 list_for_each_entry(c, &dm_bufio_all_clients, client_list) { 1738}
1698 if (!dm_bufio_trylock(c))
1699 continue;
1700 1739
1701 while (!list_empty(&c->lru[LIST_CLEAN])) { 1740static bool older_than(struct dm_buffer *b, unsigned long age_hz)
1702 struct dm_buffer *b; 1741{
1703 b = list_entry(c->lru[LIST_CLEAN].prev, 1742 return (jiffies - b->last_accessed) >= age_hz;
1704 struct dm_buffer, lru_list); 1743}
1705 if (!__cleanup_old_buffer(b, 0, max_age * HZ)) 1744
1706 break; 1745static void __evict_old_buffers(struct dm_bufio_client *c, unsigned long age_hz)
1707 dm_bufio_cond_resched(); 1746{
1708 } 1747 struct dm_buffer *b, *tmp;
1748 unsigned retain_target = get_retain_buffers(c);
1749 unsigned count;
1750
1751 dm_bufio_lock(c);
1752
1753 count = c->n_buffers[LIST_CLEAN] + c->n_buffers[LIST_DIRTY];
1754 list_for_each_entry_safe_reverse(b, tmp, &c->lru[LIST_CLEAN], lru_list) {
1755 if (count <= retain_target)
1756 break;
1757
1758 if (!older_than(b, age_hz))
1759 break;
1760
1761 if (__try_evict_buffer(b, 0))
1762 count--;
1709 1763
1710 dm_bufio_unlock(c);
1711 dm_bufio_cond_resched(); 1764 dm_bufio_cond_resched();
1712 } 1765 }
1766
1767 dm_bufio_unlock(c);
1768}
1769
1770static void cleanup_old_buffers(void)
1771{
1772 unsigned long max_age_hz = get_max_age_hz();
1773 struct dm_bufio_client *c;
1774
1775 mutex_lock(&dm_bufio_clients_lock);
1776
1777 list_for_each_entry(c, &dm_bufio_all_clients, client_list)
1778 __evict_old_buffers(c, max_age_hz);
1779
1713 mutex_unlock(&dm_bufio_clients_lock); 1780 mutex_unlock(&dm_bufio_clients_lock);
1714} 1781}
1715 1782
@@ -1834,6 +1901,9 @@ MODULE_PARM_DESC(max_cache_size_bytes, "Size of metadata cache");
1834module_param_named(max_age_seconds, dm_bufio_max_age, uint, S_IRUGO | S_IWUSR); 1901module_param_named(max_age_seconds, dm_bufio_max_age, uint, S_IRUGO | S_IWUSR);
1835MODULE_PARM_DESC(max_age_seconds, "Max age of a buffer in seconds"); 1902MODULE_PARM_DESC(max_age_seconds, "Max age of a buffer in seconds");
1836 1903
1904module_param_named(retain_bytes, dm_bufio_retain_bytes, uint, S_IRUGO | S_IWUSR);
1905MODULE_PARM_DESC(retain_bytes, "Try to keep at least this many bytes cached in memory");
1906
1837module_param_named(peak_allocated_bytes, dm_bufio_peak_allocated, ulong, S_IRUGO | S_IWUSR); 1907module_param_named(peak_allocated_bytes, dm_bufio_peak_allocated, ulong, S_IRUGO | S_IWUSR);
1838MODULE_PARM_DESC(peak_allocated_bytes, "Tracks the maximum allocated memory"); 1908MODULE_PARM_DESC(peak_allocated_bytes, "Tracks the maximum allocated memory");
1839 1909
diff --git a/drivers/md/dm-cache-block-types.h b/drivers/md/dm-cache-block-types.h
index aac0e2df06be..bed4ad4e1b7c 100644
--- a/drivers/md/dm-cache-block-types.h
+++ b/drivers/md/dm-cache-block-types.h
@@ -19,6 +19,7 @@
19 19
20typedef dm_block_t __bitwise__ dm_oblock_t; 20typedef dm_block_t __bitwise__ dm_oblock_t;
21typedef uint32_t __bitwise__ dm_cblock_t; 21typedef uint32_t __bitwise__ dm_cblock_t;
22typedef dm_block_t __bitwise__ dm_dblock_t;
22 23
23static inline dm_oblock_t to_oblock(dm_block_t b) 24static inline dm_oblock_t to_oblock(dm_block_t b)
24{ 25{
@@ -40,4 +41,14 @@ static inline uint32_t from_cblock(dm_cblock_t b)
40 return (__force uint32_t) b; 41 return (__force uint32_t) b;
41} 42}
42 43
44static inline dm_dblock_t to_dblock(dm_block_t b)
45{
46 return (__force dm_dblock_t) b;
47}
48
49static inline dm_block_t from_dblock(dm_dblock_t b)
50{
51 return (__force dm_block_t) b;
52}
53
43#endif /* DM_CACHE_BLOCK_TYPES_H */ 54#endif /* DM_CACHE_BLOCK_TYPES_H */
diff --git a/drivers/md/dm-cache-metadata.c b/drivers/md/dm-cache-metadata.c
index 06709257adde..9fc616c2755e 100644
--- a/drivers/md/dm-cache-metadata.c
+++ b/drivers/md/dm-cache-metadata.c
@@ -109,7 +109,7 @@ struct dm_cache_metadata {
109 dm_block_t discard_root; 109 dm_block_t discard_root;
110 110
111 sector_t discard_block_size; 111 sector_t discard_block_size;
112 dm_oblock_t discard_nr_blocks; 112 dm_dblock_t discard_nr_blocks;
113 113
114 sector_t data_block_size; 114 sector_t data_block_size;
115 dm_cblock_t cache_blocks; 115 dm_cblock_t cache_blocks;
@@ -329,7 +329,7 @@ static int __write_initial_superblock(struct dm_cache_metadata *cmd)
329 disk_super->hint_root = cpu_to_le64(cmd->hint_root); 329 disk_super->hint_root = cpu_to_le64(cmd->hint_root);
330 disk_super->discard_root = cpu_to_le64(cmd->discard_root); 330 disk_super->discard_root = cpu_to_le64(cmd->discard_root);
331 disk_super->discard_block_size = cpu_to_le64(cmd->discard_block_size); 331 disk_super->discard_block_size = cpu_to_le64(cmd->discard_block_size);
332 disk_super->discard_nr_blocks = cpu_to_le64(from_oblock(cmd->discard_nr_blocks)); 332 disk_super->discard_nr_blocks = cpu_to_le64(from_dblock(cmd->discard_nr_blocks));
333 disk_super->metadata_block_size = cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE); 333 disk_super->metadata_block_size = cpu_to_le32(DM_CACHE_METADATA_BLOCK_SIZE);
334 disk_super->data_block_size = cpu_to_le32(cmd->data_block_size); 334 disk_super->data_block_size = cpu_to_le32(cmd->data_block_size);
335 disk_super->cache_blocks = cpu_to_le32(0); 335 disk_super->cache_blocks = cpu_to_le32(0);
@@ -528,7 +528,7 @@ static void read_superblock_fields(struct dm_cache_metadata *cmd,
528 cmd->hint_root = le64_to_cpu(disk_super->hint_root); 528 cmd->hint_root = le64_to_cpu(disk_super->hint_root);
529 cmd->discard_root = le64_to_cpu(disk_super->discard_root); 529 cmd->discard_root = le64_to_cpu(disk_super->discard_root);
530 cmd->discard_block_size = le64_to_cpu(disk_super->discard_block_size); 530 cmd->discard_block_size = le64_to_cpu(disk_super->discard_block_size);
531 cmd->discard_nr_blocks = to_oblock(le64_to_cpu(disk_super->discard_nr_blocks)); 531 cmd->discard_nr_blocks = to_dblock(le64_to_cpu(disk_super->discard_nr_blocks));
532 cmd->data_block_size = le32_to_cpu(disk_super->data_block_size); 532 cmd->data_block_size = le32_to_cpu(disk_super->data_block_size);
533 cmd->cache_blocks = to_cblock(le32_to_cpu(disk_super->cache_blocks)); 533 cmd->cache_blocks = to_cblock(le32_to_cpu(disk_super->cache_blocks));
534 strncpy(cmd->policy_name, disk_super->policy_name, sizeof(cmd->policy_name)); 534 strncpy(cmd->policy_name, disk_super->policy_name, sizeof(cmd->policy_name));
@@ -626,7 +626,7 @@ static int __commit_transaction(struct dm_cache_metadata *cmd,
626 disk_super->hint_root = cpu_to_le64(cmd->hint_root); 626 disk_super->hint_root = cpu_to_le64(cmd->hint_root);
627 disk_super->discard_root = cpu_to_le64(cmd->discard_root); 627 disk_super->discard_root = cpu_to_le64(cmd->discard_root);
628 disk_super->discard_block_size = cpu_to_le64(cmd->discard_block_size); 628 disk_super->discard_block_size = cpu_to_le64(cmd->discard_block_size);
629 disk_super->discard_nr_blocks = cpu_to_le64(from_oblock(cmd->discard_nr_blocks)); 629 disk_super->discard_nr_blocks = cpu_to_le64(from_dblock(cmd->discard_nr_blocks));
630 disk_super->cache_blocks = cpu_to_le32(from_cblock(cmd->cache_blocks)); 630 disk_super->cache_blocks = cpu_to_le32(from_cblock(cmd->cache_blocks));
631 strncpy(disk_super->policy_name, cmd->policy_name, sizeof(disk_super->policy_name)); 631 strncpy(disk_super->policy_name, cmd->policy_name, sizeof(disk_super->policy_name));
632 disk_super->policy_version[0] = cpu_to_le32(cmd->policy_version[0]); 632 disk_super->policy_version[0] = cpu_to_le32(cmd->policy_version[0]);
@@ -797,15 +797,15 @@ out:
797 797
798int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd, 798int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd,
799 sector_t discard_block_size, 799 sector_t discard_block_size,
800 dm_oblock_t new_nr_entries) 800 dm_dblock_t new_nr_entries)
801{ 801{
802 int r; 802 int r;
803 803
804 down_write(&cmd->root_lock); 804 down_write(&cmd->root_lock);
805 r = dm_bitset_resize(&cmd->discard_info, 805 r = dm_bitset_resize(&cmd->discard_info,
806 cmd->discard_root, 806 cmd->discard_root,
807 from_oblock(cmd->discard_nr_blocks), 807 from_dblock(cmd->discard_nr_blocks),
808 from_oblock(new_nr_entries), 808 from_dblock(new_nr_entries),
809 false, &cmd->discard_root); 809 false, &cmd->discard_root);
810 if (!r) { 810 if (!r) {
811 cmd->discard_block_size = discard_block_size; 811 cmd->discard_block_size = discard_block_size;
@@ -818,28 +818,28 @@ int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd,
818 return r; 818 return r;
819} 819}
820 820
821static int __set_discard(struct dm_cache_metadata *cmd, dm_oblock_t b) 821static int __set_discard(struct dm_cache_metadata *cmd, dm_dblock_t b)
822{ 822{
823 return dm_bitset_set_bit(&cmd->discard_info, cmd->discard_root, 823 return dm_bitset_set_bit(&cmd->discard_info, cmd->discard_root,
824 from_oblock(b), &cmd->discard_root); 824 from_dblock(b), &cmd->discard_root);
825} 825}
826 826
827static int __clear_discard(struct dm_cache_metadata *cmd, dm_oblock_t b) 827static int __clear_discard(struct dm_cache_metadata *cmd, dm_dblock_t b)
828{ 828{
829 return dm_bitset_clear_bit(&cmd->discard_info, cmd->discard_root, 829 return dm_bitset_clear_bit(&cmd->discard_info, cmd->discard_root,
830 from_oblock(b), &cmd->discard_root); 830 from_dblock(b), &cmd->discard_root);
831} 831}
832 832
833static int __is_discarded(struct dm_cache_metadata *cmd, dm_oblock_t b, 833static int __is_discarded(struct dm_cache_metadata *cmd, dm_dblock_t b,
834 bool *is_discarded) 834 bool *is_discarded)
835{ 835{
836 return dm_bitset_test_bit(&cmd->discard_info, cmd->discard_root, 836 return dm_bitset_test_bit(&cmd->discard_info, cmd->discard_root,
837 from_oblock(b), &cmd->discard_root, 837 from_dblock(b), &cmd->discard_root,
838 is_discarded); 838 is_discarded);
839} 839}
840 840
841static int __discard(struct dm_cache_metadata *cmd, 841static int __discard(struct dm_cache_metadata *cmd,
842 dm_oblock_t dblock, bool discard) 842 dm_dblock_t dblock, bool discard)
843{ 843{
844 int r; 844 int r;
845 845
@@ -852,7 +852,7 @@ static int __discard(struct dm_cache_metadata *cmd,
852} 852}
853 853
854int dm_cache_set_discard(struct dm_cache_metadata *cmd, 854int dm_cache_set_discard(struct dm_cache_metadata *cmd,
855 dm_oblock_t dblock, bool discard) 855 dm_dblock_t dblock, bool discard)
856{ 856{
857 int r; 857 int r;
858 858
@@ -870,8 +870,8 @@ static int __load_discards(struct dm_cache_metadata *cmd,
870 dm_block_t b; 870 dm_block_t b;
871 bool discard; 871 bool discard;
872 872
873 for (b = 0; b < from_oblock(cmd->discard_nr_blocks); b++) { 873 for (b = 0; b < from_dblock(cmd->discard_nr_blocks); b++) {
874 dm_oblock_t dblock = to_oblock(b); 874 dm_dblock_t dblock = to_dblock(b);
875 875
876 if (cmd->clean_when_opened) { 876 if (cmd->clean_when_opened) {
877 r = __is_discarded(cmd, dblock, &discard); 877 r = __is_discarded(cmd, dblock, &discard);
diff --git a/drivers/md/dm-cache-metadata.h b/drivers/md/dm-cache-metadata.h
index 7383c90ccdb8..4ecc403be283 100644
--- a/drivers/md/dm-cache-metadata.h
+++ b/drivers/md/dm-cache-metadata.h
@@ -70,14 +70,14 @@ dm_cblock_t dm_cache_size(struct dm_cache_metadata *cmd);
70 70
71int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd, 71int dm_cache_discard_bitset_resize(struct dm_cache_metadata *cmd,
72 sector_t discard_block_size, 72 sector_t discard_block_size,
73 dm_oblock_t new_nr_entries); 73 dm_dblock_t new_nr_entries);
74 74
75typedef int (*load_discard_fn)(void *context, sector_t discard_block_size, 75typedef int (*load_discard_fn)(void *context, sector_t discard_block_size,
76 dm_oblock_t dblock, bool discarded); 76 dm_dblock_t dblock, bool discarded);
77int dm_cache_load_discards(struct dm_cache_metadata *cmd, 77int dm_cache_load_discards(struct dm_cache_metadata *cmd,
78 load_discard_fn fn, void *context); 78 load_discard_fn fn, void *context);
79 79
80int dm_cache_set_discard(struct dm_cache_metadata *cmd, dm_oblock_t dblock, bool discard); 80int dm_cache_set_discard(struct dm_cache_metadata *cmd, dm_dblock_t dblock, bool discard);
81 81
82int dm_cache_remove_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock); 82int dm_cache_remove_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock);
83int dm_cache_insert_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock, dm_oblock_t oblock); 83int dm_cache_insert_mapping(struct dm_cache_metadata *cmd, dm_cblock_t cblock, dm_oblock_t oblock);
diff --git a/drivers/md/dm-cache-policy-mq.c b/drivers/md/dm-cache-policy-mq.c
index 0e385e40909e..13f547a4eeb6 100644
--- a/drivers/md/dm-cache-policy-mq.c
+++ b/drivers/md/dm-cache-policy-mq.c
@@ -181,24 +181,30 @@ static void queue_shift_down(struct queue *q)
181 * Gives us the oldest entry of the lowest popoulated level. If the first 181 * Gives us the oldest entry of the lowest popoulated level. If the first
182 * level is emptied then we shift down one level. 182 * level is emptied then we shift down one level.
183 */ 183 */
184static struct list_head *queue_pop(struct queue *q) 184static struct list_head *queue_peek(struct queue *q)
185{ 185{
186 unsigned level; 186 unsigned level;
187 struct list_head *r;
188 187
189 for (level = 0; level < NR_QUEUE_LEVELS; level++) 188 for (level = 0; level < NR_QUEUE_LEVELS; level++)
190 if (!list_empty(q->qs + level)) { 189 if (!list_empty(q->qs + level))
191 r = q->qs[level].next; 190 return q->qs[level].next;
192 list_del(r);
193 191
194 /* have we just emptied the bottom level? */ 192 return NULL;
195 if (level == 0 && list_empty(q->qs)) 193}
196 queue_shift_down(q);
197 194
198 return r; 195static struct list_head *queue_pop(struct queue *q)
199 } 196{
197 struct list_head *r = queue_peek(q);
200 198
201 return NULL; 199 if (r) {
200 list_del(r);
201
202 /* have we just emptied the bottom level? */
203 if (list_empty(q->qs))
204 queue_shift_down(q);
205 }
206
207 return r;
202} 208}
203 209
204static struct list_head *list_pop(struct list_head *lh) 210static struct list_head *list_pop(struct list_head *lh)
@@ -383,13 +389,6 @@ struct mq_policy {
383 unsigned generation; 389 unsigned generation;
384 unsigned generation_period; /* in lookups (will probably change) */ 390 unsigned generation_period; /* in lookups (will probably change) */
385 391
386 /*
387 * Entries in the pre_cache whose hit count passes the promotion
388 * threshold move to the cache proper. Working out the correct
389 * value for the promotion_threshold is crucial to this policy.
390 */
391 unsigned promote_threshold;
392
393 unsigned discard_promote_adjustment; 392 unsigned discard_promote_adjustment;
394 unsigned read_promote_adjustment; 393 unsigned read_promote_adjustment;
395 unsigned write_promote_adjustment; 394 unsigned write_promote_adjustment;
@@ -406,6 +405,7 @@ struct mq_policy {
406#define DEFAULT_DISCARD_PROMOTE_ADJUSTMENT 1 405#define DEFAULT_DISCARD_PROMOTE_ADJUSTMENT 1
407#define DEFAULT_READ_PROMOTE_ADJUSTMENT 4 406#define DEFAULT_READ_PROMOTE_ADJUSTMENT 4
408#define DEFAULT_WRITE_PROMOTE_ADJUSTMENT 8 407#define DEFAULT_WRITE_PROMOTE_ADJUSTMENT 8
408#define DISCOURAGE_DEMOTING_DIRTY_THRESHOLD 128
409 409
410/*----------------------------------------------------------------*/ 410/*----------------------------------------------------------------*/
411 411
@@ -518,6 +518,12 @@ static struct entry *pop(struct mq_policy *mq, struct queue *q)
518 return e; 518 return e;
519} 519}
520 520
521static struct entry *peek(struct queue *q)
522{
523 struct list_head *h = queue_peek(q);
524 return h ? container_of(h, struct entry, list) : NULL;
525}
526
521/* 527/*
522 * Has this entry already been updated? 528 * Has this entry already been updated?
523 */ 529 */
@@ -570,10 +576,6 @@ static void check_generation(struct mq_policy *mq)
570 break; 576 break;
571 } 577 }
572 } 578 }
573
574 mq->promote_threshold = nr ? total / nr : 1;
575 if (mq->promote_threshold * nr < total)
576 mq->promote_threshold++;
577 } 579 }
578} 580}
579 581
@@ -641,6 +643,30 @@ static int demote_cblock(struct mq_policy *mq, dm_oblock_t *oblock)
641} 643}
642 644
643/* 645/*
646 * Entries in the pre_cache whose hit count passes the promotion
647 * threshold move to the cache proper. Working out the correct
648 * value for the promotion_threshold is crucial to this policy.
649 */
650static unsigned promote_threshold(struct mq_policy *mq)
651{
652 struct entry *e;
653
654 if (any_free_cblocks(mq))
655 return 0;
656
657 e = peek(&mq->cache_clean);
658 if (e)
659 return e->hit_count;
660
661 e = peek(&mq->cache_dirty);
662 if (e)
663 return e->hit_count + DISCOURAGE_DEMOTING_DIRTY_THRESHOLD;
664
665 /* This should never happen */
666 return 0;
667}
668
669/*
644 * We modify the basic promotion_threshold depending on the specific io. 670 * We modify the basic promotion_threshold depending on the specific io.
645 * 671 *
646 * If the origin block has been discarded then there's no cost to copy it 672 * If the origin block has been discarded then there's no cost to copy it
@@ -653,7 +679,7 @@ static unsigned adjusted_promote_threshold(struct mq_policy *mq,
653 bool discarded_oblock, int data_dir) 679 bool discarded_oblock, int data_dir)
654{ 680{
655 if (data_dir == READ) 681 if (data_dir == READ)
656 return mq->promote_threshold + mq->read_promote_adjustment; 682 return promote_threshold(mq) + mq->read_promote_adjustment;
657 683
658 if (discarded_oblock && (any_free_cblocks(mq) || any_clean_cblocks(mq))) { 684 if (discarded_oblock && (any_free_cblocks(mq) || any_clean_cblocks(mq))) {
659 /* 685 /*
@@ -663,7 +689,7 @@ static unsigned adjusted_promote_threshold(struct mq_policy *mq,
663 return mq->discard_promote_adjustment; 689 return mq->discard_promote_adjustment;
664 } 690 }
665 691
666 return mq->promote_threshold + mq->write_promote_adjustment; 692 return promote_threshold(mq) + mq->write_promote_adjustment;
667} 693}
668 694
669static bool should_promote(struct mq_policy *mq, struct entry *e, 695static bool should_promote(struct mq_policy *mq, struct entry *e,
@@ -839,7 +865,8 @@ static int map(struct mq_policy *mq, dm_oblock_t oblock,
839 if (e && in_cache(mq, e)) 865 if (e && in_cache(mq, e))
840 r = cache_entry_found(mq, e, result); 866 r = cache_entry_found(mq, e, result);
841 867
842 else if (iot_pattern(&mq->tracker) == PATTERN_SEQUENTIAL) 868 else if (mq->tracker.thresholds[PATTERN_SEQUENTIAL] &&
869 iot_pattern(&mq->tracker) == PATTERN_SEQUENTIAL)
843 result->op = POLICY_MISS; 870 result->op = POLICY_MISS;
844 871
845 else if (e) 872 else if (e)
@@ -1230,7 +1257,6 @@ static struct dm_cache_policy *mq_create(dm_cblock_t cache_size,
1230 mq->tick = 0; 1257 mq->tick = 0;
1231 mq->hit_count = 0; 1258 mq->hit_count = 0;
1232 mq->generation = 0; 1259 mq->generation = 0;
1233 mq->promote_threshold = 0;
1234 mq->discard_promote_adjustment = DEFAULT_DISCARD_PROMOTE_ADJUSTMENT; 1260 mq->discard_promote_adjustment = DEFAULT_DISCARD_PROMOTE_ADJUSTMENT;
1235 mq->read_promote_adjustment = DEFAULT_READ_PROMOTE_ADJUSTMENT; 1261 mq->read_promote_adjustment = DEFAULT_READ_PROMOTE_ADJUSTMENT;
1236 mq->write_promote_adjustment = DEFAULT_WRITE_PROMOTE_ADJUSTMENT; 1262 mq->write_promote_adjustment = DEFAULT_WRITE_PROMOTE_ADJUSTMENT;
@@ -1265,7 +1291,7 @@ bad_pre_cache_init:
1265 1291
1266static struct dm_cache_policy_type mq_policy_type = { 1292static struct dm_cache_policy_type mq_policy_type = {
1267 .name = "mq", 1293 .name = "mq",
1268 .version = {1, 2, 0}, 1294 .version = {1, 3, 0},
1269 .hint_size = 4, 1295 .hint_size = 4,
1270 .owner = THIS_MODULE, 1296 .owner = THIS_MODULE,
1271 .create = mq_create 1297 .create = mq_create
@@ -1273,7 +1299,7 @@ static struct dm_cache_policy_type mq_policy_type = {
1273 1299
1274static struct dm_cache_policy_type default_policy_type = { 1300static struct dm_cache_policy_type default_policy_type = {
1275 .name = "default", 1301 .name = "default",
1276 .version = {1, 2, 0}, 1302 .version = {1, 3, 0},
1277 .hint_size = 4, 1303 .hint_size = 4,
1278 .owner = THIS_MODULE, 1304 .owner = THIS_MODULE,
1279 .create = mq_create, 1305 .create = mq_create,
diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 7130505c2425..1e96d7889f51 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -95,7 +95,6 @@ static void dm_unhook_bio(struct dm_hook_info *h, struct bio *bio)
95 95
96/*----------------------------------------------------------------*/ 96/*----------------------------------------------------------------*/
97 97
98#define PRISON_CELLS 1024
99#define MIGRATION_POOL_SIZE 128 98#define MIGRATION_POOL_SIZE 128
100#define COMMIT_PERIOD HZ 99#define COMMIT_PERIOD HZ
101#define MIGRATION_COUNT_WINDOW 10 100#define MIGRATION_COUNT_WINDOW 10
@@ -237,8 +236,9 @@ struct cache {
237 /* 236 /*
238 * origin_blocks entries, discarded if set. 237 * origin_blocks entries, discarded if set.
239 */ 238 */
240 dm_oblock_t discard_nr_blocks; 239 dm_dblock_t discard_nr_blocks;
241 unsigned long *discard_bitset; 240 unsigned long *discard_bitset;
241 uint32_t discard_block_size; /* a power of 2 times sectors per block */
242 242
243 /* 243 /*
244 * Rather than reconstructing the table line for the status we just 244 * Rather than reconstructing the table line for the status we just
@@ -310,6 +310,7 @@ struct dm_cache_migration {
310 dm_cblock_t cblock; 310 dm_cblock_t cblock;
311 311
312 bool err:1; 312 bool err:1;
313 bool discard:1;
313 bool writeback:1; 314 bool writeback:1;
314 bool demote:1; 315 bool demote:1;
315 bool promote:1; 316 bool promote:1;
@@ -433,11 +434,12 @@ static void prealloc_put_cell(struct prealloc *p, struct dm_bio_prison_cell *cel
433 434
434/*----------------------------------------------------------------*/ 435/*----------------------------------------------------------------*/
435 436
436static void build_key(dm_oblock_t oblock, struct dm_cell_key *key) 437static void build_key(dm_oblock_t begin, dm_oblock_t end, struct dm_cell_key *key)
437{ 438{
438 key->virtual = 0; 439 key->virtual = 0;
439 key->dev = 0; 440 key->dev = 0;
440 key->block = from_oblock(oblock); 441 key->block_begin = from_oblock(begin);
442 key->block_end = from_oblock(end);
441} 443}
442 444
443/* 445/*
@@ -447,15 +449,15 @@ static void build_key(dm_oblock_t oblock, struct dm_cell_key *key)
447 */ 449 */
448typedef void (*cell_free_fn)(void *context, struct dm_bio_prison_cell *cell); 450typedef void (*cell_free_fn)(void *context, struct dm_bio_prison_cell *cell);
449 451
450static int bio_detain(struct cache *cache, dm_oblock_t oblock, 452static int bio_detain_range(struct cache *cache, dm_oblock_t oblock_begin, dm_oblock_t oblock_end,
451 struct bio *bio, struct dm_bio_prison_cell *cell_prealloc, 453 struct bio *bio, struct dm_bio_prison_cell *cell_prealloc,
452 cell_free_fn free_fn, void *free_context, 454 cell_free_fn free_fn, void *free_context,
453 struct dm_bio_prison_cell **cell_result) 455 struct dm_bio_prison_cell **cell_result)
454{ 456{
455 int r; 457 int r;
456 struct dm_cell_key key; 458 struct dm_cell_key key;
457 459
458 build_key(oblock, &key); 460 build_key(oblock_begin, oblock_end, &key);
459 r = dm_bio_detain(cache->prison, &key, bio, cell_prealloc, cell_result); 461 r = dm_bio_detain(cache->prison, &key, bio, cell_prealloc, cell_result);
460 if (r) 462 if (r)
461 free_fn(free_context, cell_prealloc); 463 free_fn(free_context, cell_prealloc);
@@ -463,6 +465,16 @@ static int bio_detain(struct cache *cache, dm_oblock_t oblock,
463 return r; 465 return r;
464} 466}
465 467
468static int bio_detain(struct cache *cache, dm_oblock_t oblock,
469 struct bio *bio, struct dm_bio_prison_cell *cell_prealloc,
470 cell_free_fn free_fn, void *free_context,
471 struct dm_bio_prison_cell **cell_result)
472{
473 dm_oblock_t end = to_oblock(from_oblock(oblock) + 1ULL);
474 return bio_detain_range(cache, oblock, end, bio,
475 cell_prealloc, free_fn, free_context, cell_result);
476}
477
466static int get_cell(struct cache *cache, 478static int get_cell(struct cache *cache,
467 dm_oblock_t oblock, 479 dm_oblock_t oblock,
468 struct prealloc *structs, 480 struct prealloc *structs,
@@ -474,7 +486,7 @@ static int get_cell(struct cache *cache,
474 486
475 cell_prealloc = prealloc_get_cell(structs); 487 cell_prealloc = prealloc_get_cell(structs);
476 488
477 build_key(oblock, &key); 489 build_key(oblock, to_oblock(from_oblock(oblock) + 1ULL), &key);
478 r = dm_get_cell(cache->prison, &key, cell_prealloc, cell_result); 490 r = dm_get_cell(cache->prison, &key, cell_prealloc, cell_result);
479 if (r) 491 if (r)
480 prealloc_put_cell(structs, cell_prealloc); 492 prealloc_put_cell(structs, cell_prealloc);
@@ -524,33 +536,57 @@ static dm_block_t block_div(dm_block_t b, uint32_t n)
524 return b; 536 return b;
525} 537}
526 538
527static void set_discard(struct cache *cache, dm_oblock_t b) 539static dm_block_t oblocks_per_dblock(struct cache *cache)
540{
541 dm_block_t oblocks = cache->discard_block_size;
542
543 if (block_size_is_power_of_two(cache))
544 oblocks >>= cache->sectors_per_block_shift;
545 else
546 oblocks = block_div(oblocks, cache->sectors_per_block);
547
548 return oblocks;
549}
550
551static dm_dblock_t oblock_to_dblock(struct cache *cache, dm_oblock_t oblock)
552{
553 return to_dblock(block_div(from_oblock(oblock),
554 oblocks_per_dblock(cache)));
555}
556
557static dm_oblock_t dblock_to_oblock(struct cache *cache, dm_dblock_t dblock)
558{
559 return to_oblock(from_dblock(dblock) * oblocks_per_dblock(cache));
560}
561
562static void set_discard(struct cache *cache, dm_dblock_t b)
528{ 563{
529 unsigned long flags; 564 unsigned long flags;
530 565
566 BUG_ON(from_dblock(b) >= from_dblock(cache->discard_nr_blocks));
531 atomic_inc(&cache->stats.discard_count); 567 atomic_inc(&cache->stats.discard_count);
532 568
533 spin_lock_irqsave(&cache->lock, flags); 569 spin_lock_irqsave(&cache->lock, flags);
534 set_bit(from_oblock(b), cache->discard_bitset); 570 set_bit(from_dblock(b), cache->discard_bitset);
535 spin_unlock_irqrestore(&cache->lock, flags); 571 spin_unlock_irqrestore(&cache->lock, flags);
536} 572}
537 573
538static void clear_discard(struct cache *cache, dm_oblock_t b) 574static void clear_discard(struct cache *cache, dm_dblock_t b)
539{ 575{
540 unsigned long flags; 576 unsigned long flags;
541 577
542 spin_lock_irqsave(&cache->lock, flags); 578 spin_lock_irqsave(&cache->lock, flags);
543 clear_bit(from_oblock(b), cache->discard_bitset); 579 clear_bit(from_dblock(b), cache->discard_bitset);
544 spin_unlock_irqrestore(&cache->lock, flags); 580 spin_unlock_irqrestore(&cache->lock, flags);
545} 581}
546 582
547static bool is_discarded(struct cache *cache, dm_oblock_t b) 583static bool is_discarded(struct cache *cache, dm_dblock_t b)
548{ 584{
549 int r; 585 int r;
550 unsigned long flags; 586 unsigned long flags;
551 587
552 spin_lock_irqsave(&cache->lock, flags); 588 spin_lock_irqsave(&cache->lock, flags);
553 r = test_bit(from_oblock(b), cache->discard_bitset); 589 r = test_bit(from_dblock(b), cache->discard_bitset);
554 spin_unlock_irqrestore(&cache->lock, flags); 590 spin_unlock_irqrestore(&cache->lock, flags);
555 591
556 return r; 592 return r;
@@ -562,7 +598,8 @@ static bool is_discarded_oblock(struct cache *cache, dm_oblock_t b)
562 unsigned long flags; 598 unsigned long flags;
563 599
564 spin_lock_irqsave(&cache->lock, flags); 600 spin_lock_irqsave(&cache->lock, flags);
565 r = test_bit(from_oblock(b), cache->discard_bitset); 601 r = test_bit(from_dblock(oblock_to_dblock(cache, b)),
602 cache->discard_bitset);
566 spin_unlock_irqrestore(&cache->lock, flags); 603 spin_unlock_irqrestore(&cache->lock, flags);
567 604
568 return r; 605 return r;
@@ -687,7 +724,7 @@ static void remap_to_origin_clear_discard(struct cache *cache, struct bio *bio,
687 check_if_tick_bio_needed(cache, bio); 724 check_if_tick_bio_needed(cache, bio);
688 remap_to_origin(cache, bio); 725 remap_to_origin(cache, bio);
689 if (bio_data_dir(bio) == WRITE) 726 if (bio_data_dir(bio) == WRITE)
690 clear_discard(cache, oblock); 727 clear_discard(cache, oblock_to_dblock(cache, oblock));
691} 728}
692 729
693static void remap_to_cache_dirty(struct cache *cache, struct bio *bio, 730static void remap_to_cache_dirty(struct cache *cache, struct bio *bio,
@@ -697,7 +734,7 @@ static void remap_to_cache_dirty(struct cache *cache, struct bio *bio,
697 remap_to_cache(cache, bio, cblock); 734 remap_to_cache(cache, bio, cblock);
698 if (bio_data_dir(bio) == WRITE) { 735 if (bio_data_dir(bio) == WRITE) {
699 set_dirty(cache, oblock, cblock); 736 set_dirty(cache, oblock, cblock);
700 clear_discard(cache, oblock); 737 clear_discard(cache, oblock_to_dblock(cache, oblock));
701 } 738 }
702} 739}
703 740
@@ -951,10 +988,14 @@ static void migration_success_post_commit(struct dm_cache_migration *mg)
951 } 988 }
952 989
953 } else { 990 } else {
954 clear_dirty(cache, mg->new_oblock, mg->cblock); 991 if (mg->requeue_holder) {
955 if (mg->requeue_holder) 992 clear_dirty(cache, mg->new_oblock, mg->cblock);
956 cell_defer(cache, mg->new_ocell, true); 993 cell_defer(cache, mg->new_ocell, true);
957 else { 994 } else {
995 /*
996 * The block was promoted via an overwrite, so it's dirty.
997 */
998 set_dirty(cache, mg->new_oblock, mg->cblock);
958 bio_endio(mg->new_ocell->holder, 0); 999 bio_endio(mg->new_ocell->holder, 0);
959 cell_defer(cache, mg->new_ocell, false); 1000 cell_defer(cache, mg->new_ocell, false);
960 } 1001 }
@@ -978,7 +1019,7 @@ static void copy_complete(int read_err, unsigned long write_err, void *context)
978 wake_worker(cache); 1019 wake_worker(cache);
979} 1020}
980 1021
981static void issue_copy_real(struct dm_cache_migration *mg) 1022static void issue_copy(struct dm_cache_migration *mg)
982{ 1023{
983 int r; 1024 int r;
984 struct dm_io_region o_region, c_region; 1025 struct dm_io_region o_region, c_region;
@@ -1057,11 +1098,46 @@ static void avoid_copy(struct dm_cache_migration *mg)
1057 migration_success_pre_commit(mg); 1098 migration_success_pre_commit(mg);
1058} 1099}
1059 1100
1060static void issue_copy(struct dm_cache_migration *mg) 1101static void calc_discard_block_range(struct cache *cache, struct bio *bio,
1102 dm_dblock_t *b, dm_dblock_t *e)
1103{
1104 sector_t sb = bio->bi_iter.bi_sector;
1105 sector_t se = bio_end_sector(bio);
1106
1107 *b = to_dblock(dm_sector_div_up(sb, cache->discard_block_size));
1108
1109 if (se - sb < cache->discard_block_size)
1110 *e = *b;
1111 else
1112 *e = to_dblock(block_div(se, cache->discard_block_size));
1113}
1114
1115static void issue_discard(struct dm_cache_migration *mg)
1116{
1117 dm_dblock_t b, e;
1118 struct bio *bio = mg->new_ocell->holder;
1119
1120 calc_discard_block_range(mg->cache, bio, &b, &e);
1121 while (b != e) {
1122 set_discard(mg->cache, b);
1123 b = to_dblock(from_dblock(b) + 1);
1124 }
1125
1126 bio_endio(bio, 0);
1127 cell_defer(mg->cache, mg->new_ocell, false);
1128 free_migration(mg);
1129}
1130
1131static void issue_copy_or_discard(struct dm_cache_migration *mg)
1061{ 1132{
1062 bool avoid; 1133 bool avoid;
1063 struct cache *cache = mg->cache; 1134 struct cache *cache = mg->cache;
1064 1135
1136 if (mg->discard) {
1137 issue_discard(mg);
1138 return;
1139 }
1140
1065 if (mg->writeback || mg->demote) 1141 if (mg->writeback || mg->demote)
1066 avoid = !is_dirty(cache, mg->cblock) || 1142 avoid = !is_dirty(cache, mg->cblock) ||
1067 is_discarded_oblock(cache, mg->old_oblock); 1143 is_discarded_oblock(cache, mg->old_oblock);
@@ -1070,13 +1146,14 @@ static void issue_copy(struct dm_cache_migration *mg)
1070 1146
1071 avoid = is_discarded_oblock(cache, mg->new_oblock); 1147 avoid = is_discarded_oblock(cache, mg->new_oblock);
1072 1148
1073 if (!avoid && bio_writes_complete_block(cache, bio)) { 1149 if (writeback_mode(&cache->features) &&
1150 !avoid && bio_writes_complete_block(cache, bio)) {
1074 issue_overwrite(mg, bio); 1151 issue_overwrite(mg, bio);
1075 return; 1152 return;
1076 } 1153 }
1077 } 1154 }
1078 1155
1079 avoid ? avoid_copy(mg) : issue_copy_real(mg); 1156 avoid ? avoid_copy(mg) : issue_copy(mg);
1080} 1157}
1081 1158
1082static void complete_migration(struct dm_cache_migration *mg) 1159static void complete_migration(struct dm_cache_migration *mg)
@@ -1161,6 +1238,7 @@ static void promote(struct cache *cache, struct prealloc *structs,
1161 struct dm_cache_migration *mg = prealloc_get_migration(structs); 1238 struct dm_cache_migration *mg = prealloc_get_migration(structs);
1162 1239
1163 mg->err = false; 1240 mg->err = false;
1241 mg->discard = false;
1164 mg->writeback = false; 1242 mg->writeback = false;
1165 mg->demote = false; 1243 mg->demote = false;
1166 mg->promote = true; 1244 mg->promote = true;
@@ -1184,6 +1262,7 @@ static void writeback(struct cache *cache, struct prealloc *structs,
1184 struct dm_cache_migration *mg = prealloc_get_migration(structs); 1262 struct dm_cache_migration *mg = prealloc_get_migration(structs);
1185 1263
1186 mg->err = false; 1264 mg->err = false;
1265 mg->discard = false;
1187 mg->writeback = true; 1266 mg->writeback = true;
1188 mg->demote = false; 1267 mg->demote = false;
1189 mg->promote = false; 1268 mg->promote = false;
@@ -1209,6 +1288,7 @@ static void demote_then_promote(struct cache *cache, struct prealloc *structs,
1209 struct dm_cache_migration *mg = prealloc_get_migration(structs); 1288 struct dm_cache_migration *mg = prealloc_get_migration(structs);
1210 1289
1211 mg->err = false; 1290 mg->err = false;
1291 mg->discard = false;
1212 mg->writeback = false; 1292 mg->writeback = false;
1213 mg->demote = true; 1293 mg->demote = true;
1214 mg->promote = true; 1294 mg->promote = true;
@@ -1237,6 +1317,7 @@ static void invalidate(struct cache *cache, struct prealloc *structs,
1237 struct dm_cache_migration *mg = prealloc_get_migration(structs); 1317 struct dm_cache_migration *mg = prealloc_get_migration(structs);
1238 1318
1239 mg->err = false; 1319 mg->err = false;
1320 mg->discard = false;
1240 mg->writeback = false; 1321 mg->writeback = false;
1241 mg->demote = true; 1322 mg->demote = true;
1242 mg->promote = false; 1323 mg->promote = false;
@@ -1253,6 +1334,26 @@ static void invalidate(struct cache *cache, struct prealloc *structs,
1253 quiesce_migration(mg); 1334 quiesce_migration(mg);
1254} 1335}
1255 1336
1337static void discard(struct cache *cache, struct prealloc *structs,
1338 struct dm_bio_prison_cell *cell)
1339{
1340 struct dm_cache_migration *mg = prealloc_get_migration(structs);
1341
1342 mg->err = false;
1343 mg->discard = true;
1344 mg->writeback = false;
1345 mg->demote = false;
1346 mg->promote = false;
1347 mg->requeue_holder = false;
1348 mg->invalidate = false;
1349 mg->cache = cache;
1350 mg->old_ocell = NULL;
1351 mg->new_ocell = cell;
1352 mg->start_jiffies = jiffies;
1353
1354 quiesce_migration(mg);
1355}
1356
1256/*---------------------------------------------------------------- 1357/*----------------------------------------------------------------
1257 * bio processing 1358 * bio processing
1258 *--------------------------------------------------------------*/ 1359 *--------------------------------------------------------------*/
@@ -1286,31 +1387,27 @@ static void process_flush_bio(struct cache *cache, struct bio *bio)
1286 issue(cache, bio); 1387 issue(cache, bio);
1287} 1388}
1288 1389
1289/* 1390static void process_discard_bio(struct cache *cache, struct prealloc *structs,
1290 * People generally discard large parts of a device, eg, the whole device 1391 struct bio *bio)
1291 * when formatting. Splitting these large discards up into cache block
1292 * sized ios and then quiescing (always neccessary for discard) takes too
1293 * long.
1294 *
1295 * We keep it simple, and allow any size of discard to come in, and just
1296 * mark off blocks on the discard bitset. No passdown occurs!
1297 *
1298 * To implement passdown we need to change the bio_prison such that a cell
1299 * can have a key that spans many blocks.
1300 */
1301static void process_discard_bio(struct cache *cache, struct bio *bio)
1302{ 1392{
1303 dm_block_t start_block = dm_sector_div_up(bio->bi_iter.bi_sector, 1393 int r;
1304 cache->sectors_per_block); 1394 dm_dblock_t b, e;
1305 dm_block_t end_block = bio_end_sector(bio); 1395 struct dm_bio_prison_cell *cell_prealloc, *new_ocell;
1306 dm_block_t b;
1307 1396
1308 end_block = block_div(end_block, cache->sectors_per_block); 1397 calc_discard_block_range(cache, bio, &b, &e);
1398 if (b == e) {
1399 bio_endio(bio, 0);
1400 return;
1401 }
1309 1402
1310 for (b = start_block; b < end_block; b++) 1403 cell_prealloc = prealloc_get_cell(structs);
1311 set_discard(cache, to_oblock(b)); 1404 r = bio_detain_range(cache, dblock_to_oblock(cache, b), dblock_to_oblock(cache, e), bio, cell_prealloc,
1405 (cell_free_fn) prealloc_put_cell,
1406 structs, &new_ocell);
1407 if (r > 0)
1408 return;
1312 1409
1313 bio_endio(bio, 0); 1410 discard(cache, structs, new_ocell);
1314} 1411}
1315 1412
1316static bool spare_migration_bandwidth(struct cache *cache) 1413static bool spare_migration_bandwidth(struct cache *cache)
@@ -1340,9 +1437,8 @@ static void process_bio(struct cache *cache, struct prealloc *structs,
1340 dm_oblock_t block = get_bio_block(cache, bio); 1437 dm_oblock_t block = get_bio_block(cache, bio);
1341 struct dm_bio_prison_cell *cell_prealloc, *old_ocell, *new_ocell; 1438 struct dm_bio_prison_cell *cell_prealloc, *old_ocell, *new_ocell;
1342 struct policy_result lookup_result; 1439 struct policy_result lookup_result;
1343 bool discarded_block = is_discarded_oblock(cache, block);
1344 bool passthrough = passthrough_mode(&cache->features); 1440 bool passthrough = passthrough_mode(&cache->features);
1345 bool can_migrate = !passthrough && (discarded_block || spare_migration_bandwidth(cache)); 1441 bool discarded_block, can_migrate;
1346 1442
1347 /* 1443 /*
1348 * Check to see if that block is currently migrating. 1444 * Check to see if that block is currently migrating.
@@ -1354,6 +1450,9 @@ static void process_bio(struct cache *cache, struct prealloc *structs,
1354 if (r > 0) 1450 if (r > 0)
1355 return; 1451 return;
1356 1452
1453 discarded_block = is_discarded_oblock(cache, block);
1454 can_migrate = !passthrough && (discarded_block || spare_migration_bandwidth(cache));
1455
1357 r = policy_map(cache->policy, block, true, can_migrate, discarded_block, 1456 r = policy_map(cache->policy, block, true, can_migrate, discarded_block,
1358 bio, &lookup_result); 1457 bio, &lookup_result);
1359 1458
@@ -1500,7 +1599,7 @@ static void process_deferred_bios(struct cache *cache)
1500 if (bio->bi_rw & REQ_FLUSH) 1599 if (bio->bi_rw & REQ_FLUSH)
1501 process_flush_bio(cache, bio); 1600 process_flush_bio(cache, bio);
1502 else if (bio->bi_rw & REQ_DISCARD) 1601 else if (bio->bi_rw & REQ_DISCARD)
1503 process_discard_bio(cache, bio); 1602 process_discard_bio(cache, &structs, bio);
1504 else 1603 else
1505 process_bio(cache, &structs, bio); 1604 process_bio(cache, &structs, bio);
1506 } 1605 }
@@ -1715,7 +1814,7 @@ static void do_worker(struct work_struct *ws)
1715 process_invalidation_requests(cache); 1814 process_invalidation_requests(cache);
1716 } 1815 }
1717 1816
1718 process_migrations(cache, &cache->quiesced_migrations, issue_copy); 1817 process_migrations(cache, &cache->quiesced_migrations, issue_copy_or_discard);
1719 process_migrations(cache, &cache->completed_migrations, complete_migration); 1818 process_migrations(cache, &cache->completed_migrations, complete_migration);
1720 1819
1721 if (commit_if_needed(cache)) { 1820 if (commit_if_needed(cache)) {
@@ -2180,6 +2279,45 @@ static int create_cache_policy(struct cache *cache, struct cache_args *ca,
2180 return 0; 2279 return 0;
2181} 2280}
2182 2281
2282/*
2283 * We want the discard block size to be at least the size of the cache
2284 * block size and have no more than 2^14 discard blocks across the origin.
2285 */
2286#define MAX_DISCARD_BLOCKS (1 << 14)
2287
2288static bool too_many_discard_blocks(sector_t discard_block_size,
2289 sector_t origin_size)
2290{
2291 (void) sector_div(origin_size, discard_block_size);
2292
2293 return origin_size > MAX_DISCARD_BLOCKS;
2294}
2295
2296static sector_t calculate_discard_block_size(sector_t cache_block_size,
2297 sector_t origin_size)
2298{
2299 sector_t discard_block_size = cache_block_size;
2300
2301 if (origin_size)
2302 while (too_many_discard_blocks(discard_block_size, origin_size))
2303 discard_block_size *= 2;
2304
2305 return discard_block_size;
2306}
2307
2308static void set_cache_size(struct cache *cache, dm_cblock_t size)
2309{
2310 dm_block_t nr_blocks = from_cblock(size);
2311
2312 if (nr_blocks > (1 << 20) && cache->cache_size != size)
2313 DMWARN_LIMIT("You have created a cache device with a lot of individual cache blocks (%llu)\n"
2314 "All these mappings can consume a lot of kernel memory, and take some time to read/write.\n"
2315 "Please consider increasing the cache block size to reduce the overall cache block count.",
2316 (unsigned long long) nr_blocks);
2317
2318 cache->cache_size = size;
2319}
2320
2183#define DEFAULT_MIGRATION_THRESHOLD 2048 2321#define DEFAULT_MIGRATION_THRESHOLD 2048
2184 2322
2185static int cache_create(struct cache_args *ca, struct cache **result) 2323static int cache_create(struct cache_args *ca, struct cache **result)
@@ -2204,8 +2342,7 @@ static int cache_create(struct cache_args *ca, struct cache **result)
2204 ti->num_discard_bios = 1; 2342 ti->num_discard_bios = 1;
2205 ti->discards_supported = true; 2343 ti->discards_supported = true;
2206 ti->discard_zeroes_data_unsupported = true; 2344 ti->discard_zeroes_data_unsupported = true;
2207 /* Discard bios must be split on a block boundary */ 2345 ti->split_discard_bios = false;
2208 ti->split_discard_bios = true;
2209 2346
2210 cache->features = ca->features; 2347 cache->features = ca->features;
2211 ti->per_bio_data_size = get_per_bio_data_size(cache); 2348 ti->per_bio_data_size = get_per_bio_data_size(cache);
@@ -2235,10 +2372,10 @@ static int cache_create(struct cache_args *ca, struct cache **result)
2235 2372
2236 cache->sectors_per_block_shift = -1; 2373 cache->sectors_per_block_shift = -1;
2237 cache_size = block_div(cache_size, ca->block_size); 2374 cache_size = block_div(cache_size, ca->block_size);
2238 cache->cache_size = to_cblock(cache_size); 2375 set_cache_size(cache, to_cblock(cache_size));
2239 } else { 2376 } else {
2240 cache->sectors_per_block_shift = __ffs(ca->block_size); 2377 cache->sectors_per_block_shift = __ffs(ca->block_size);
2241 cache->cache_size = to_cblock(ca->cache_sectors >> cache->sectors_per_block_shift); 2378 set_cache_size(cache, to_cblock(ca->cache_sectors >> cache->sectors_per_block_shift));
2242 } 2379 }
2243 2380
2244 r = create_cache_policy(cache, ca, error); 2381 r = create_cache_policy(cache, ca, error);
@@ -2303,13 +2440,17 @@ static int cache_create(struct cache_args *ca, struct cache **result)
2303 } 2440 }
2304 clear_bitset(cache->dirty_bitset, from_cblock(cache->cache_size)); 2441 clear_bitset(cache->dirty_bitset, from_cblock(cache->cache_size));
2305 2442
2306 cache->discard_nr_blocks = cache->origin_blocks; 2443 cache->discard_block_size =
2307 cache->discard_bitset = alloc_bitset(from_oblock(cache->discard_nr_blocks)); 2444 calculate_discard_block_size(cache->sectors_per_block,
2445 cache->origin_sectors);
2446 cache->discard_nr_blocks = to_dblock(dm_sector_div_up(cache->origin_sectors,
2447 cache->discard_block_size));
2448 cache->discard_bitset = alloc_bitset(from_dblock(cache->discard_nr_blocks));
2308 if (!cache->discard_bitset) { 2449 if (!cache->discard_bitset) {
2309 *error = "could not allocate discard bitset"; 2450 *error = "could not allocate discard bitset";
2310 goto bad; 2451 goto bad;
2311 } 2452 }
2312 clear_bitset(cache->discard_bitset, from_oblock(cache->discard_nr_blocks)); 2453 clear_bitset(cache->discard_bitset, from_dblock(cache->discard_nr_blocks));
2313 2454
2314 cache->copier = dm_kcopyd_client_create(&dm_kcopyd_throttle); 2455 cache->copier = dm_kcopyd_client_create(&dm_kcopyd_throttle);
2315 if (IS_ERR(cache->copier)) { 2456 if (IS_ERR(cache->copier)) {
@@ -2327,7 +2468,7 @@ static int cache_create(struct cache_args *ca, struct cache **result)
2327 INIT_DELAYED_WORK(&cache->waker, do_waker); 2468 INIT_DELAYED_WORK(&cache->waker, do_waker);
2328 cache->last_commit_jiffies = jiffies; 2469 cache->last_commit_jiffies = jiffies;
2329 2470
2330 cache->prison = dm_bio_prison_create(PRISON_CELLS); 2471 cache->prison = dm_bio_prison_create();
2331 if (!cache->prison) { 2472 if (!cache->prison) {
2332 *error = "could not create bio prison"; 2473 *error = "could not create bio prison";
2333 goto bad; 2474 goto bad;
@@ -2549,11 +2690,11 @@ static int __cache_map(struct cache *cache, struct bio *bio, struct dm_bio_priso
2549static int cache_map(struct dm_target *ti, struct bio *bio) 2690static int cache_map(struct dm_target *ti, struct bio *bio)
2550{ 2691{
2551 int r; 2692 int r;
2552 struct dm_bio_prison_cell *cell; 2693 struct dm_bio_prison_cell *cell = NULL;
2553 struct cache *cache = ti->private; 2694 struct cache *cache = ti->private;
2554 2695
2555 r = __cache_map(cache, bio, &cell); 2696 r = __cache_map(cache, bio, &cell);
2556 if (r == DM_MAPIO_REMAPPED) { 2697 if (r == DM_MAPIO_REMAPPED && cell) {
2557 inc_ds(cache, bio, cell); 2698 inc_ds(cache, bio, cell);
2558 cell_defer(cache, cell, false); 2699 cell_defer(cache, cell, false);
2559 } 2700 }
@@ -2599,16 +2740,16 @@ static int write_discard_bitset(struct cache *cache)
2599{ 2740{
2600 unsigned i, r; 2741 unsigned i, r;
2601 2742
2602 r = dm_cache_discard_bitset_resize(cache->cmd, cache->sectors_per_block, 2743 r = dm_cache_discard_bitset_resize(cache->cmd, cache->discard_block_size,
2603 cache->origin_blocks); 2744 cache->discard_nr_blocks);
2604 if (r) { 2745 if (r) {
2605 DMERR("could not resize on-disk discard bitset"); 2746 DMERR("could not resize on-disk discard bitset");
2606 return r; 2747 return r;
2607 } 2748 }
2608 2749
2609 for (i = 0; i < from_oblock(cache->discard_nr_blocks); i++) { 2750 for (i = 0; i < from_dblock(cache->discard_nr_blocks); i++) {
2610 r = dm_cache_set_discard(cache->cmd, to_oblock(i), 2751 r = dm_cache_set_discard(cache->cmd, to_dblock(i),
2611 is_discarded(cache, to_oblock(i))); 2752 is_discarded(cache, to_dblock(i)));
2612 if (r) 2753 if (r)
2613 return r; 2754 return r;
2614 } 2755 }
@@ -2680,15 +2821,86 @@ static int load_mapping(void *context, dm_oblock_t oblock, dm_cblock_t cblock,
2680 return 0; 2821 return 0;
2681} 2822}
2682 2823
2824/*
2825 * The discard block size in the on disk metadata is not
2826 * neccessarily the same as we're currently using. So we have to
2827 * be careful to only set the discarded attribute if we know it
2828 * covers a complete block of the new size.
2829 */
2830struct discard_load_info {
2831 struct cache *cache;
2832
2833 /*
2834 * These blocks are sized using the on disk dblock size, rather
2835 * than the current one.
2836 */
2837 dm_block_t block_size;
2838 dm_block_t discard_begin, discard_end;
2839};
2840
2841static void discard_load_info_init(struct cache *cache,
2842 struct discard_load_info *li)
2843{
2844 li->cache = cache;
2845 li->discard_begin = li->discard_end = 0;
2846}
2847
2848static void set_discard_range(struct discard_load_info *li)
2849{
2850 sector_t b, e;
2851
2852 if (li->discard_begin == li->discard_end)
2853 return;
2854
2855 /*
2856 * Convert to sectors.
2857 */
2858 b = li->discard_begin * li->block_size;
2859 e = li->discard_end * li->block_size;
2860
2861 /*
2862 * Then convert back to the current dblock size.
2863 */
2864 b = dm_sector_div_up(b, li->cache->discard_block_size);
2865 sector_div(e, li->cache->discard_block_size);
2866
2867 /*
2868 * The origin may have shrunk, so we need to check we're still in
2869 * bounds.
2870 */
2871 if (e > from_dblock(li->cache->discard_nr_blocks))
2872 e = from_dblock(li->cache->discard_nr_blocks);
2873
2874 for (; b < e; b++)
2875 set_discard(li->cache, to_dblock(b));
2876}
2877
2683static int load_discard(void *context, sector_t discard_block_size, 2878static int load_discard(void *context, sector_t discard_block_size,
2684 dm_oblock_t oblock, bool discard) 2879 dm_dblock_t dblock, bool discard)
2685{ 2880{
2686 struct cache *cache = context; 2881 struct discard_load_info *li = context;
2687 2882
2688 if (discard) 2883 li->block_size = discard_block_size;
2689 set_discard(cache, oblock); 2884
2690 else 2885 if (discard) {
2691 clear_discard(cache, oblock); 2886 if (from_dblock(dblock) == li->discard_end)
2887 /*
2888 * We're already in a discard range, just extend it.
2889 */
2890 li->discard_end = li->discard_end + 1ULL;
2891
2892 else {
2893 /*
2894 * Emit the old range and start a new one.
2895 */
2896 set_discard_range(li);
2897 li->discard_begin = from_dblock(dblock);
2898 li->discard_end = li->discard_begin + 1ULL;
2899 }
2900 } else {
2901 set_discard_range(li);
2902 li->discard_begin = li->discard_end = 0;
2903 }
2692 2904
2693 return 0; 2905 return 0;
2694} 2906}
@@ -2730,7 +2942,7 @@ static int resize_cache_dev(struct cache *cache, dm_cblock_t new_size)
2730 return r; 2942 return r;
2731 } 2943 }
2732 2944
2733 cache->cache_size = new_size; 2945 set_cache_size(cache, new_size);
2734 2946
2735 return 0; 2947 return 0;
2736} 2948}
@@ -2772,11 +2984,22 @@ static int cache_preresume(struct dm_target *ti)
2772 } 2984 }
2773 2985
2774 if (!cache->loaded_discards) { 2986 if (!cache->loaded_discards) {
2775 r = dm_cache_load_discards(cache->cmd, load_discard, cache); 2987 struct discard_load_info li;
2988
2989 /*
2990 * The discard bitset could have been resized, or the
2991 * discard block size changed. To be safe we start by
2992 * setting every dblock to not discarded.
2993 */
2994 clear_bitset(cache->discard_bitset, from_dblock(cache->discard_nr_blocks));
2995
2996 discard_load_info_init(cache, &li);
2997 r = dm_cache_load_discards(cache->cmd, load_discard, &li);
2776 if (r) { 2998 if (r) {
2777 DMERR("could not load origin discards"); 2999 DMERR("could not load origin discards");
2778 return r; 3000 return r;
2779 } 3001 }
3002 set_discard_range(&li);
2780 3003
2781 cache->loaded_discards = true; 3004 cache->loaded_discards = true;
2782 } 3005 }
@@ -3079,8 +3302,9 @@ static void set_discard_limits(struct cache *cache, struct queue_limits *limits)
3079 /* 3302 /*
3080 * FIXME: these limits may be incompatible with the cache device 3303 * FIXME: these limits may be incompatible with the cache device
3081 */ 3304 */
3082 limits->max_discard_sectors = cache->sectors_per_block; 3305 limits->max_discard_sectors = min_t(sector_t, cache->discard_block_size * 1024,
3083 limits->discard_granularity = cache->sectors_per_block << SECTOR_SHIFT; 3306 cache->origin_sectors);
3307 limits->discard_granularity = cache->discard_block_size << SECTOR_SHIFT;
3084} 3308}
3085 3309
3086static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits) 3310static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits)
@@ -3104,7 +3328,7 @@ static void cache_io_hints(struct dm_target *ti, struct queue_limits *limits)
3104 3328
3105static struct target_type cache_target = { 3329static struct target_type cache_target = {
3106 .name = "cache", 3330 .name = "cache",
3107 .version = {1, 5, 0}, 3331 .version = {1, 6, 0},
3108 .module = THIS_MODULE, 3332 .module = THIS_MODULE,
3109 .ctr = cache_ctr, 3333 .ctr = cache_ctr,
3110 .dtr = cache_dtr, 3334 .dtr = cache_dtr,
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index fc93b9330af4..08981be7baa1 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -705,7 +705,7 @@ static int crypt_iv_tcw_whitening(struct crypt_config *cc,
705 for (i = 0; i < ((1 << SECTOR_SHIFT) / 8); i++) 705 for (i = 0; i < ((1 << SECTOR_SHIFT) / 8); i++)
706 crypto_xor(data + i * 8, buf, 8); 706 crypto_xor(data + i * 8, buf, 8);
707out: 707out:
708 memset(buf, 0, sizeof(buf)); 708 memzero_explicit(buf, sizeof(buf));
709 return r; 709 return r;
710} 710}
711 711
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 0be9381365d7..73f791bb9ea4 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -684,11 +684,14 @@ static void __dev_status(struct mapped_device *md, struct dm_ioctl *param)
684 int srcu_idx; 684 int srcu_idx;
685 685
686 param->flags &= ~(DM_SUSPEND_FLAG | DM_READONLY_FLAG | 686 param->flags &= ~(DM_SUSPEND_FLAG | DM_READONLY_FLAG |
687 DM_ACTIVE_PRESENT_FLAG); 687 DM_ACTIVE_PRESENT_FLAG | DM_INTERNAL_SUSPEND_FLAG);
688 688
689 if (dm_suspended_md(md)) 689 if (dm_suspended_md(md))
690 param->flags |= DM_SUSPEND_FLAG; 690 param->flags |= DM_SUSPEND_FLAG;
691 691
692 if (dm_suspended_internally_md(md))
693 param->flags |= DM_INTERNAL_SUSPEND_FLAG;
694
692 if (dm_test_deferred_remove_flag(md)) 695 if (dm_test_deferred_remove_flag(md))
693 param->flags |= DM_DEFERRED_REMOVE; 696 param->flags |= DM_DEFERRED_REMOVE;
694 697
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 4857fa4a5484..07c0fa0fa284 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -789,8 +789,7 @@ struct dm_raid_superblock {
789 __le32 layout; 789 __le32 layout;
790 __le32 stripe_sectors; 790 __le32 stripe_sectors;
791 791
792 __u8 pad[452]; /* Round struct to 512 bytes. */ 792 /* Remainder of a logical block is zero-filled when writing (see super_sync()). */
793 /* Always set to 0 when writing. */
794} __packed; 793} __packed;
795 794
796static int read_disk_sb(struct md_rdev *rdev, int size) 795static int read_disk_sb(struct md_rdev *rdev, int size)
@@ -827,7 +826,7 @@ static void super_sync(struct mddev *mddev, struct md_rdev *rdev)
827 test_bit(Faulty, &(rs->dev[i].rdev.flags))) 826 test_bit(Faulty, &(rs->dev[i].rdev.flags)))
828 failed_devices |= (1ULL << i); 827 failed_devices |= (1ULL << i);
829 828
830 memset(sb, 0, sizeof(*sb)); 829 memset(sb + 1, 0, rdev->sb_size - sizeof(*sb));
831 830
832 sb->magic = cpu_to_le32(DM_RAID_MAGIC); 831 sb->magic = cpu_to_le32(DM_RAID_MAGIC);
833 sb->features = cpu_to_le32(0); /* No features yet */ 832 sb->features = cpu_to_le32(0); /* No features yet */
@@ -862,7 +861,11 @@ static int super_load(struct md_rdev *rdev, struct md_rdev *refdev)
862 uint64_t events_sb, events_refsb; 861 uint64_t events_sb, events_refsb;
863 862
864 rdev->sb_start = 0; 863 rdev->sb_start = 0;
865 rdev->sb_size = sizeof(*sb); 864 rdev->sb_size = bdev_logical_block_size(rdev->meta_bdev);
865 if (rdev->sb_size < sizeof(*sb) || rdev->sb_size > PAGE_SIZE) {
866 DMERR("superblock size of a logical block is no longer valid");
867 return -EINVAL;
868 }
866 869
867 ret = read_disk_sb(rdev, rdev->sb_size); 870 ret = read_disk_sb(rdev, rdev->sb_size);
868 if (ret) 871 if (ret)
@@ -1169,8 +1172,12 @@ static void configure_discard_support(struct dm_target *ti, struct raid_set *rs)
1169 raid456 = (rs->md.level == 4 || rs->md.level == 5 || rs->md.level == 6); 1172 raid456 = (rs->md.level == 4 || rs->md.level == 5 || rs->md.level == 6);
1170 1173
1171 for (i = 0; i < rs->md.raid_disks; i++) { 1174 for (i = 0; i < rs->md.raid_disks; i++) {
1172 struct request_queue *q = bdev_get_queue(rs->dev[i].rdev.bdev); 1175 struct request_queue *q;
1176
1177 if (!rs->dev[i].rdev.bdev)
1178 continue;
1173 1179
1180 q = bdev_get_queue(rs->dev[i].rdev.bdev);
1174 if (!q || !blk_queue_discard(q)) 1181 if (!q || !blk_queue_discard(q))
1175 return; 1182 return;
1176 1183
diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
index 87f86c77b094..f478a4c96d2f 100644
--- a/drivers/md/dm-stats.c
+++ b/drivers/md/dm-stats.c
@@ -824,7 +824,7 @@ static int message_stats_create(struct mapped_device *md,
824 return 1; 824 return 1;
825 825
826 id = dm_stats_create(dm_get_stats(md), start, end, step, program_id, aux_data, 826 id = dm_stats_create(dm_get_stats(md), start, end, step, program_id, aux_data,
827 dm_internal_suspend, dm_internal_resume, md); 827 dm_internal_suspend_fast, dm_internal_resume_fast, md);
828 if (id < 0) 828 if (id < 0)
829 return id; 829 return id;
830 830
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
index d1600d2aa2e2..f8b37d4c05d8 100644
--- a/drivers/md/dm-stripe.c
+++ b/drivers/md/dm-stripe.c
@@ -159,8 +159,10 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
159 sc->stripes_shift = __ffs(stripes); 159 sc->stripes_shift = __ffs(stripes);
160 160
161 r = dm_set_target_max_io_len(ti, chunk_size); 161 r = dm_set_target_max_io_len(ti, chunk_size);
162 if (r) 162 if (r) {
163 kfree(sc);
163 return r; 164 return r;
165 }
164 166
165 ti->num_flush_bios = stripes; 167 ti->num_flush_bios = stripes;
166 ti->num_discard_bios = stripes; 168 ti->num_discard_bios = stripes;
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index b2bd1ebf4562..3afae9e062f8 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -1521,18 +1521,32 @@ fmode_t dm_table_get_mode(struct dm_table *t)
1521} 1521}
1522EXPORT_SYMBOL(dm_table_get_mode); 1522EXPORT_SYMBOL(dm_table_get_mode);
1523 1523
1524static void suspend_targets(struct dm_table *t, unsigned postsuspend) 1524enum suspend_mode {
1525 PRESUSPEND,
1526 PRESUSPEND_UNDO,
1527 POSTSUSPEND,
1528};
1529
1530static void suspend_targets(struct dm_table *t, enum suspend_mode mode)
1525{ 1531{
1526 int i = t->num_targets; 1532 int i = t->num_targets;
1527 struct dm_target *ti = t->targets; 1533 struct dm_target *ti = t->targets;
1528 1534
1529 while (i--) { 1535 while (i--) {
1530 if (postsuspend) { 1536 switch (mode) {
1537 case PRESUSPEND:
1538 if (ti->type->presuspend)
1539 ti->type->presuspend(ti);
1540 break;
1541 case PRESUSPEND_UNDO:
1542 if (ti->type->presuspend_undo)
1543 ti->type->presuspend_undo(ti);
1544 break;
1545 case POSTSUSPEND:
1531 if (ti->type->postsuspend) 1546 if (ti->type->postsuspend)
1532 ti->type->postsuspend(ti); 1547 ti->type->postsuspend(ti);
1533 } else if (ti->type->presuspend) 1548 break;
1534 ti->type->presuspend(ti); 1549 }
1535
1536 ti++; 1550 ti++;
1537 } 1551 }
1538} 1552}
@@ -1542,7 +1556,15 @@ void dm_table_presuspend_targets(struct dm_table *t)
1542 if (!t) 1556 if (!t)
1543 return; 1557 return;
1544 1558
1545 suspend_targets(t, 0); 1559 suspend_targets(t, PRESUSPEND);
1560}
1561
1562void dm_table_presuspend_undo_targets(struct dm_table *t)
1563{
1564 if (!t)
1565 return;
1566
1567 suspend_targets(t, PRESUSPEND_UNDO);
1546} 1568}
1547 1569
1548void dm_table_postsuspend_targets(struct dm_table *t) 1570void dm_table_postsuspend_targets(struct dm_table *t)
@@ -1550,7 +1572,7 @@ void dm_table_postsuspend_targets(struct dm_table *t)
1550 if (!t) 1572 if (!t)
1551 return; 1573 return;
1552 1574
1553 suspend_targets(t, 1); 1575 suspend_targets(t, POSTSUSPEND);
1554} 1576}
1555 1577
1556int dm_table_resume_targets(struct dm_table *t) 1578int dm_table_resume_targets(struct dm_table *t)
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
index e9d33ad59df5..43adbb863f5a 100644
--- a/drivers/md/dm-thin-metadata.c
+++ b/drivers/md/dm-thin-metadata.c
@@ -1384,42 +1384,38 @@ static bool __snapshotted_since(struct dm_thin_device *td, uint32_t time)
1384} 1384}
1385 1385
1386int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block, 1386int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
1387 int can_block, struct dm_thin_lookup_result *result) 1387 int can_issue_io, struct dm_thin_lookup_result *result)
1388{ 1388{
1389 int r = -EINVAL; 1389 int r;
1390 uint64_t block_time = 0;
1391 __le64 value; 1390 __le64 value;
1392 struct dm_pool_metadata *pmd = td->pmd; 1391 struct dm_pool_metadata *pmd = td->pmd;
1393 dm_block_t keys[2] = { td->id, block }; 1392 dm_block_t keys[2] = { td->id, block };
1394 struct dm_btree_info *info; 1393 struct dm_btree_info *info;
1395 1394
1396 if (can_block) {
1397 down_read(&pmd->root_lock);
1398 info = &pmd->info;
1399 } else if (down_read_trylock(&pmd->root_lock))
1400 info = &pmd->nb_info;
1401 else
1402 return -EWOULDBLOCK;
1403
1404 if (pmd->fail_io) 1395 if (pmd->fail_io)
1405 goto out; 1396 return -EINVAL;
1406 1397
1407 r = dm_btree_lookup(info, pmd->root, keys, &value); 1398 down_read(&pmd->root_lock);
1408 if (!r)
1409 block_time = le64_to_cpu(value);
1410 1399
1411out: 1400 if (can_issue_io) {
1412 up_read(&pmd->root_lock); 1401 info = &pmd->info;
1402 } else
1403 info = &pmd->nb_info;
1413 1404
1405 r = dm_btree_lookup(info, pmd->root, keys, &value);
1414 if (!r) { 1406 if (!r) {
1407 uint64_t block_time = 0;
1415 dm_block_t exception_block; 1408 dm_block_t exception_block;
1416 uint32_t exception_time; 1409 uint32_t exception_time;
1410
1411 block_time = le64_to_cpu(value);
1417 unpack_block_time(block_time, &exception_block, 1412 unpack_block_time(block_time, &exception_block,
1418 &exception_time); 1413 &exception_time);
1419 result->block = exception_block; 1414 result->block = exception_block;
1420 result->shared = __snapshotted_since(td, exception_time); 1415 result->shared = __snapshotted_since(td, exception_time);
1421 } 1416 }
1422 1417
1418 up_read(&pmd->root_lock);
1423 return r; 1419 return r;
1424} 1420}
1425 1421
@@ -1813,3 +1809,8 @@ bool dm_pool_metadata_needs_check(struct dm_pool_metadata *pmd)
1813 1809
1814 return needs_check; 1810 return needs_check;
1815} 1811}
1812
1813void dm_pool_issue_prefetches(struct dm_pool_metadata *pmd)
1814{
1815 dm_tm_issue_prefetches(pmd->tm);
1816}
diff --git a/drivers/md/dm-thin-metadata.h b/drivers/md/dm-thin-metadata.h
index e3c857db195a..921d15ee56a0 100644
--- a/drivers/md/dm-thin-metadata.h
+++ b/drivers/md/dm-thin-metadata.h
@@ -139,12 +139,12 @@ struct dm_thin_lookup_result {
139 139
140/* 140/*
141 * Returns: 141 * Returns:
142 * -EWOULDBLOCK iff @can_block is set and would block. 142 * -EWOULDBLOCK iff @can_issue_io is set and would issue IO
143 * -ENODATA iff that mapping is not present. 143 * -ENODATA iff that mapping is not present.
144 * 0 success 144 * 0 success
145 */ 145 */
146int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block, 146int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
147 int can_block, struct dm_thin_lookup_result *result); 147 int can_issue_io, struct dm_thin_lookup_result *result);
148 148
149/* 149/*
150 * Obtain an unused block. 150 * Obtain an unused block.
@@ -213,6 +213,11 @@ int dm_pool_register_metadata_threshold(struct dm_pool_metadata *pmd,
213int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd); 213int dm_pool_metadata_set_needs_check(struct dm_pool_metadata *pmd);
214bool dm_pool_metadata_needs_check(struct dm_pool_metadata *pmd); 214bool dm_pool_metadata_needs_check(struct dm_pool_metadata *pmd);
215 215
216/*
217 * Issue any prefetches that may be useful.
218 */
219void dm_pool_issue_prefetches(struct dm_pool_metadata *pmd);
220
216/*----------------------------------------------------------------*/ 221/*----------------------------------------------------------------*/
217 222
218#endif 223#endif
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
index 4843801173fe..8735543eacdb 100644
--- a/drivers/md/dm-thin.c
+++ b/drivers/md/dm-thin.c
@@ -11,11 +11,13 @@
11#include <linux/device-mapper.h> 11#include <linux/device-mapper.h>
12#include <linux/dm-io.h> 12#include <linux/dm-io.h>
13#include <linux/dm-kcopyd.h> 13#include <linux/dm-kcopyd.h>
14#include <linux/log2.h>
14#include <linux/list.h> 15#include <linux/list.h>
15#include <linux/rculist.h> 16#include <linux/rculist.h>
16#include <linux/init.h> 17#include <linux/init.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/sort.h>
19#include <linux/rbtree.h> 21#include <linux/rbtree.h>
20 22
21#define DM_MSG_PREFIX "thin" 23#define DM_MSG_PREFIX "thin"
@@ -25,7 +27,6 @@
25 */ 27 */
26#define ENDIO_HOOK_POOL_SIZE 1024 28#define ENDIO_HOOK_POOL_SIZE 1024
27#define MAPPING_POOL_SIZE 1024 29#define MAPPING_POOL_SIZE 1024
28#define PRISON_CELLS 1024
29#define COMMIT_PERIOD HZ 30#define COMMIT_PERIOD HZ
30#define NO_SPACE_TIMEOUT_SECS 60 31#define NO_SPACE_TIMEOUT_SECS 60
31 32
@@ -114,7 +115,8 @@ static void build_data_key(struct dm_thin_device *td,
114{ 115{
115 key->virtual = 0; 116 key->virtual = 0;
116 key->dev = dm_thin_dev_id(td); 117 key->dev = dm_thin_dev_id(td);
117 key->block = b; 118 key->block_begin = b;
119 key->block_end = b + 1ULL;
118} 120}
119 121
120static void build_virtual_key(struct dm_thin_device *td, dm_block_t b, 122static void build_virtual_key(struct dm_thin_device *td, dm_block_t b,
@@ -122,7 +124,55 @@ static void build_virtual_key(struct dm_thin_device *td, dm_block_t b,
122{ 124{
123 key->virtual = 1; 125 key->virtual = 1;
124 key->dev = dm_thin_dev_id(td); 126 key->dev = dm_thin_dev_id(td);
125 key->block = b; 127 key->block_begin = b;
128 key->block_end = b + 1ULL;
129}
130
131/*----------------------------------------------------------------*/
132
133#define THROTTLE_THRESHOLD (1 * HZ)
134
135struct throttle {
136 struct rw_semaphore lock;
137 unsigned long threshold;
138 bool throttle_applied;
139};
140
141static void throttle_init(struct throttle *t)
142{
143 init_rwsem(&t->lock);
144 t->throttle_applied = false;
145}
146
147static void throttle_work_start(struct throttle *t)
148{
149 t->threshold = jiffies + THROTTLE_THRESHOLD;
150}
151
152static void throttle_work_update(struct throttle *t)
153{
154 if (!t->throttle_applied && jiffies > t->threshold) {
155 down_write(&t->lock);
156 t->throttle_applied = true;
157 }
158}
159
160static void throttle_work_complete(struct throttle *t)
161{
162 if (t->throttle_applied) {
163 t->throttle_applied = false;
164 up_write(&t->lock);
165 }
166}
167
168static void throttle_lock(struct throttle *t)
169{
170 down_read(&t->lock);
171}
172
173static void throttle_unlock(struct throttle *t)
174{
175 up_read(&t->lock);
126} 176}
127 177
128/*----------------------------------------------------------------*/ 178/*----------------------------------------------------------------*/
@@ -155,8 +205,11 @@ struct pool_features {
155 205
156struct thin_c; 206struct thin_c;
157typedef void (*process_bio_fn)(struct thin_c *tc, struct bio *bio); 207typedef void (*process_bio_fn)(struct thin_c *tc, struct bio *bio);
208typedef void (*process_cell_fn)(struct thin_c *tc, struct dm_bio_prison_cell *cell);
158typedef void (*process_mapping_fn)(struct dm_thin_new_mapping *m); 209typedef void (*process_mapping_fn)(struct dm_thin_new_mapping *m);
159 210
211#define CELL_SORT_ARRAY_SIZE 8192
212
160struct pool { 213struct pool {
161 struct list_head list; 214 struct list_head list;
162 struct dm_target *ti; /* Only set if a pool target is bound */ 215 struct dm_target *ti; /* Only set if a pool target is bound */
@@ -171,11 +224,13 @@ struct pool {
171 224
172 struct pool_features pf; 225 struct pool_features pf;
173 bool low_water_triggered:1; /* A dm event has been sent */ 226 bool low_water_triggered:1; /* A dm event has been sent */
227 bool suspended:1;
174 228
175 struct dm_bio_prison *prison; 229 struct dm_bio_prison *prison;
176 struct dm_kcopyd_client *copier; 230 struct dm_kcopyd_client *copier;
177 231
178 struct workqueue_struct *wq; 232 struct workqueue_struct *wq;
233 struct throttle throttle;
179 struct work_struct worker; 234 struct work_struct worker;
180 struct delayed_work waker; 235 struct delayed_work waker;
181 struct delayed_work no_space_timeout; 236 struct delayed_work no_space_timeout;
@@ -198,8 +253,13 @@ struct pool {
198 process_bio_fn process_bio; 253 process_bio_fn process_bio;
199 process_bio_fn process_discard; 254 process_bio_fn process_discard;
200 255
256 process_cell_fn process_cell;
257 process_cell_fn process_discard_cell;
258
201 process_mapping_fn process_prepared_mapping; 259 process_mapping_fn process_prepared_mapping;
202 process_mapping_fn process_prepared_discard; 260 process_mapping_fn process_prepared_discard;
261
262 struct dm_bio_prison_cell *cell_sort_array[CELL_SORT_ARRAY_SIZE];
203}; 263};
204 264
205static enum pool_mode get_pool_mode(struct pool *pool); 265static enum pool_mode get_pool_mode(struct pool *pool);
@@ -232,8 +292,11 @@ struct thin_c {
232 292
233 struct pool *pool; 293 struct pool *pool;
234 struct dm_thin_device *td; 294 struct dm_thin_device *td;
295 struct mapped_device *thin_md;
296
235 bool requeue_mode:1; 297 bool requeue_mode:1;
236 spinlock_t lock; 298 spinlock_t lock;
299 struct list_head deferred_cells;
237 struct bio_list deferred_bio_list; 300 struct bio_list deferred_bio_list;
238 struct bio_list retry_on_resume_list; 301 struct bio_list retry_on_resume_list;
239 struct rb_root sort_bio_list; /* sorted list of deferred bios */ 302 struct rb_root sort_bio_list; /* sorted list of deferred bios */
@@ -290,6 +353,15 @@ static void cell_release(struct pool *pool,
290 dm_bio_prison_free_cell(pool->prison, cell); 353 dm_bio_prison_free_cell(pool->prison, cell);
291} 354}
292 355
356static void cell_visit_release(struct pool *pool,
357 void (*fn)(void *, struct dm_bio_prison_cell *),
358 void *context,
359 struct dm_bio_prison_cell *cell)
360{
361 dm_cell_visit_release(pool->prison, fn, context, cell);
362 dm_bio_prison_free_cell(pool->prison, cell);
363}
364
293static void cell_release_no_holder(struct pool *pool, 365static void cell_release_no_holder(struct pool *pool,
294 struct dm_bio_prison_cell *cell, 366 struct dm_bio_prison_cell *cell,
295 struct bio_list *bios) 367 struct bio_list *bios)
@@ -298,19 +370,6 @@ static void cell_release_no_holder(struct pool *pool,
298 dm_bio_prison_free_cell(pool->prison, cell); 370 dm_bio_prison_free_cell(pool->prison, cell);
299} 371}
300 372
301static void cell_defer_no_holder_no_free(struct thin_c *tc,
302 struct dm_bio_prison_cell *cell)
303{
304 struct pool *pool = tc->pool;
305 unsigned long flags;
306
307 spin_lock_irqsave(&tc->lock, flags);
308 dm_cell_release_no_holder(pool->prison, cell, &tc->deferred_bio_list);
309 spin_unlock_irqrestore(&tc->lock, flags);
310
311 wake_worker(pool);
312}
313
314static void cell_error_with_code(struct pool *pool, 373static void cell_error_with_code(struct pool *pool,
315 struct dm_bio_prison_cell *cell, int error_code) 374 struct dm_bio_prison_cell *cell, int error_code)
316{ 375{
@@ -323,6 +382,16 @@ static void cell_error(struct pool *pool, struct dm_bio_prison_cell *cell)
323 cell_error_with_code(pool, cell, -EIO); 382 cell_error_with_code(pool, cell, -EIO);
324} 383}
325 384
385static void cell_success(struct pool *pool, struct dm_bio_prison_cell *cell)
386{
387 cell_error_with_code(pool, cell, 0);
388}
389
390static void cell_requeue(struct pool *pool, struct dm_bio_prison_cell *cell)
391{
392 cell_error_with_code(pool, cell, DM_ENDIO_REQUEUE);
393}
394
326/*----------------------------------------------------------------*/ 395/*----------------------------------------------------------------*/
327 396
328/* 397/*
@@ -393,44 +462,65 @@ struct dm_thin_endio_hook {
393 struct rb_node rb_node; 462 struct rb_node rb_node;
394}; 463};
395 464
396static void requeue_bio_list(struct thin_c *tc, struct bio_list *master) 465static void __merge_bio_list(struct bio_list *bios, struct bio_list *master)
466{
467 bio_list_merge(bios, master);
468 bio_list_init(master);
469}
470
471static void error_bio_list(struct bio_list *bios, int error)
397{ 472{
398 struct bio *bio; 473 struct bio *bio;
474
475 while ((bio = bio_list_pop(bios)))
476 bio_endio(bio, error);
477}
478
479static void error_thin_bio_list(struct thin_c *tc, struct bio_list *master, int error)
480{
399 struct bio_list bios; 481 struct bio_list bios;
400 unsigned long flags; 482 unsigned long flags;
401 483
402 bio_list_init(&bios); 484 bio_list_init(&bios);
403 485
404 spin_lock_irqsave(&tc->lock, flags); 486 spin_lock_irqsave(&tc->lock, flags);
405 bio_list_merge(&bios, master); 487 __merge_bio_list(&bios, master);
406 bio_list_init(master);
407 spin_unlock_irqrestore(&tc->lock, flags); 488 spin_unlock_irqrestore(&tc->lock, flags);
408 489
409 while ((bio = bio_list_pop(&bios))) 490 error_bio_list(&bios, error);
410 bio_endio(bio, DM_ENDIO_REQUEUE);
411} 491}
412 492
413static void requeue_io(struct thin_c *tc) 493static void requeue_deferred_cells(struct thin_c *tc)
414{ 494{
415 requeue_bio_list(tc, &tc->deferred_bio_list); 495 struct pool *pool = tc->pool;
416 requeue_bio_list(tc, &tc->retry_on_resume_list); 496 unsigned long flags;
497 struct list_head cells;
498 struct dm_bio_prison_cell *cell, *tmp;
499
500 INIT_LIST_HEAD(&cells);
501
502 spin_lock_irqsave(&tc->lock, flags);
503 list_splice_init(&tc->deferred_cells, &cells);
504 spin_unlock_irqrestore(&tc->lock, flags);
505
506 list_for_each_entry_safe(cell, tmp, &cells, user_list)
507 cell_requeue(pool, cell);
417} 508}
418 509
419static void error_thin_retry_list(struct thin_c *tc) 510static void requeue_io(struct thin_c *tc)
420{ 511{
421 struct bio *bio;
422 unsigned long flags;
423 struct bio_list bios; 512 struct bio_list bios;
513 unsigned long flags;
424 514
425 bio_list_init(&bios); 515 bio_list_init(&bios);
426 516
427 spin_lock_irqsave(&tc->lock, flags); 517 spin_lock_irqsave(&tc->lock, flags);
428 bio_list_merge(&bios, &tc->retry_on_resume_list); 518 __merge_bio_list(&bios, &tc->deferred_bio_list);
429 bio_list_init(&tc->retry_on_resume_list); 519 __merge_bio_list(&bios, &tc->retry_on_resume_list);
430 spin_unlock_irqrestore(&tc->lock, flags); 520 spin_unlock_irqrestore(&tc->lock, flags);
431 521
432 while ((bio = bio_list_pop(&bios))) 522 error_bio_list(&bios, DM_ENDIO_REQUEUE);
433 bio_io_error(bio); 523 requeue_deferred_cells(tc);
434} 524}
435 525
436static void error_retry_list(struct pool *pool) 526static void error_retry_list(struct pool *pool)
@@ -439,7 +529,7 @@ static void error_retry_list(struct pool *pool)
439 529
440 rcu_read_lock(); 530 rcu_read_lock();
441 list_for_each_entry_rcu(tc, &pool->active_thins, list) 531 list_for_each_entry_rcu(tc, &pool->active_thins, list)
442 error_thin_retry_list(tc); 532 error_thin_bio_list(tc, &tc->retry_on_resume_list, -EIO);
443 rcu_read_unlock(); 533 rcu_read_unlock();
444} 534}
445 535
@@ -629,33 +719,75 @@ static void overwrite_endio(struct bio *bio, int err)
629 */ 719 */
630 720
631/* 721/*
632 * This sends the bios in the cell back to the deferred_bios list. 722 * This sends the bios in the cell, except the original holder, back
723 * to the deferred_bios list.
633 */ 724 */
634static void cell_defer(struct thin_c *tc, struct dm_bio_prison_cell *cell) 725static void cell_defer_no_holder(struct thin_c *tc, struct dm_bio_prison_cell *cell)
635{ 726{
636 struct pool *pool = tc->pool; 727 struct pool *pool = tc->pool;
637 unsigned long flags; 728 unsigned long flags;
638 729
639 spin_lock_irqsave(&tc->lock, flags); 730 spin_lock_irqsave(&tc->lock, flags);
640 cell_release(pool, cell, &tc->deferred_bio_list); 731 cell_release_no_holder(pool, cell, &tc->deferred_bio_list);
641 spin_unlock_irqrestore(&tc->lock, flags); 732 spin_unlock_irqrestore(&tc->lock, flags);
642 733
643 wake_worker(pool); 734 wake_worker(pool);
644} 735}
645 736
646/* 737static void thin_defer_bio(struct thin_c *tc, struct bio *bio);
647 * Same as cell_defer above, except it omits the original holder of the cell. 738
648 */ 739struct remap_info {
649static void cell_defer_no_holder(struct thin_c *tc, struct dm_bio_prison_cell *cell) 740 struct thin_c *tc;
741 struct bio_list defer_bios;
742 struct bio_list issue_bios;
743};
744
745static void __inc_remap_and_issue_cell(void *context,
746 struct dm_bio_prison_cell *cell)
650{ 747{
651 struct pool *pool = tc->pool; 748 struct remap_info *info = context;
652 unsigned long flags; 749 struct bio *bio;
653 750
654 spin_lock_irqsave(&tc->lock, flags); 751 while ((bio = bio_list_pop(&cell->bios))) {
655 cell_release_no_holder(pool, cell, &tc->deferred_bio_list); 752 if (bio->bi_rw & (REQ_DISCARD | REQ_FLUSH | REQ_FUA))
656 spin_unlock_irqrestore(&tc->lock, flags); 753 bio_list_add(&info->defer_bios, bio);
754 else {
755 inc_all_io_entry(info->tc->pool, bio);
657 756
658 wake_worker(pool); 757 /*
758 * We can't issue the bios with the bio prison lock
759 * held, so we add them to a list to issue on
760 * return from this function.
761 */
762 bio_list_add(&info->issue_bios, bio);
763 }
764 }
765}
766
767static void inc_remap_and_issue_cell(struct thin_c *tc,
768 struct dm_bio_prison_cell *cell,
769 dm_block_t block)
770{
771 struct bio *bio;
772 struct remap_info info;
773
774 info.tc = tc;
775 bio_list_init(&info.defer_bios);
776 bio_list_init(&info.issue_bios);
777
778 /*
779 * We have to be careful to inc any bios we're about to issue
780 * before the cell is released, and avoid a race with new bios
781 * being added to the cell.
782 */
783 cell_visit_release(tc->pool, __inc_remap_and_issue_cell,
784 &info, cell);
785
786 while ((bio = bio_list_pop(&info.defer_bios)))
787 thin_defer_bio(tc, bio);
788
789 while ((bio = bio_list_pop(&info.issue_bios)))
790 remap_and_issue(info.tc, bio, block);
659} 791}
660 792
661static void process_prepared_mapping_fail(struct dm_thin_new_mapping *m) 793static void process_prepared_mapping_fail(struct dm_thin_new_mapping *m)
@@ -706,10 +838,13 @@ static void process_prepared_mapping(struct dm_thin_new_mapping *m)
706 * the bios in the cell. 838 * the bios in the cell.
707 */ 839 */
708 if (bio) { 840 if (bio) {
709 cell_defer_no_holder(tc, m->cell); 841 inc_remap_and_issue_cell(tc, m->cell, m->data_block);
710 bio_endio(bio, 0); 842 bio_endio(bio, 0);
711 } else 843 } else {
712 cell_defer(tc, m->cell); 844 inc_all_io_entry(tc->pool, m->cell->holder);
845 remap_and_issue(tc, m->cell->holder, m->data_block);
846 inc_remap_and_issue_cell(tc, m->cell, m->data_block);
847 }
713 848
714out: 849out:
715 list_del(&m->list); 850 list_del(&m->list);
@@ -842,6 +977,20 @@ static void ll_zero(struct thin_c *tc, struct dm_thin_new_mapping *m,
842 } 977 }
843} 978}
844 979
980static void remap_and_issue_overwrite(struct thin_c *tc, struct bio *bio,
981 dm_block_t data_block,
982 struct dm_thin_new_mapping *m)
983{
984 struct pool *pool = tc->pool;
985 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
986
987 h->overwrite_mapping = m;
988 m->bio = bio;
989 save_and_set_endio(bio, &m->saved_bi_end_io, overwrite_endio);
990 inc_all_io_entry(pool, bio);
991 remap_and_issue(tc, bio, data_block);
992}
993
845/* 994/*
846 * A partial copy also needs to zero the uncopied region. 995 * A partial copy also needs to zero the uncopied region.
847 */ 996 */
@@ -876,15 +1025,9 @@ static void schedule_copy(struct thin_c *tc, dm_block_t virt_block,
876 * If the whole block of data is being overwritten, we can issue the 1025 * If the whole block of data is being overwritten, we can issue the
877 * bio immediately. Otherwise we use kcopyd to clone the data first. 1026 * bio immediately. Otherwise we use kcopyd to clone the data first.
878 */ 1027 */
879 if (io_overwrites_block(pool, bio)) { 1028 if (io_overwrites_block(pool, bio))
880 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook)); 1029 remap_and_issue_overwrite(tc, bio, data_dest, m);
881 1030 else {
882 h->overwrite_mapping = m;
883 m->bio = bio;
884 save_and_set_endio(bio, &m->saved_bi_end_io, overwrite_endio);
885 inc_all_io_entry(pool, bio);
886 remap_and_issue(tc, bio, data_dest);
887 } else {
888 struct dm_io_region from, to; 1031 struct dm_io_region from, to;
889 1032
890 from.bdev = origin->bdev; 1033 from.bdev = origin->bdev;
@@ -953,16 +1096,10 @@ static void schedule_zero(struct thin_c *tc, dm_block_t virt_block,
953 if (!pool->pf.zero_new_blocks) 1096 if (!pool->pf.zero_new_blocks)
954 process_prepared_mapping(m); 1097 process_prepared_mapping(m);
955 1098
956 else if (io_overwrites_block(pool, bio)) { 1099 else if (io_overwrites_block(pool, bio))
957 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook)); 1100 remap_and_issue_overwrite(tc, bio, data_block, m);
958
959 h->overwrite_mapping = m;
960 m->bio = bio;
961 save_and_set_endio(bio, &m->saved_bi_end_io, overwrite_endio);
962 inc_all_io_entry(pool, bio);
963 remap_and_issue(tc, bio, data_block);
964 1101
965 } else 1102 else
966 ll_zero(tc, m, 1103 ll_zero(tc, m,
967 data_block * pool->sectors_per_block, 1104 data_block * pool->sectors_per_block,
968 (data_block + 1) * pool->sectors_per_block); 1105 (data_block + 1) * pool->sectors_per_block);
@@ -1134,29 +1271,25 @@ static void retry_bios_on_resume(struct pool *pool, struct dm_bio_prison_cell *c
1134 bio_list_init(&bios); 1271 bio_list_init(&bios);
1135 cell_release(pool, cell, &bios); 1272 cell_release(pool, cell, &bios);
1136 1273
1137 error = should_error_unserviceable_bio(pool); 1274 while ((bio = bio_list_pop(&bios)))
1138 if (error) 1275 retry_on_resume(bio);
1139 while ((bio = bio_list_pop(&bios)))
1140 bio_endio(bio, error);
1141 else
1142 while ((bio = bio_list_pop(&bios)))
1143 retry_on_resume(bio);
1144} 1276}
1145 1277
1146static void process_discard(struct thin_c *tc, struct bio *bio) 1278static void process_discard_cell(struct thin_c *tc, struct dm_bio_prison_cell *cell)
1147{ 1279{
1148 int r; 1280 int r;
1149 unsigned long flags; 1281 struct bio *bio = cell->holder;
1150 struct pool *pool = tc->pool; 1282 struct pool *pool = tc->pool;
1151 struct dm_bio_prison_cell *cell, *cell2; 1283 struct dm_bio_prison_cell *cell2;
1152 struct dm_cell_key key, key2; 1284 struct dm_cell_key key2;
1153 dm_block_t block = get_bio_block(tc, bio); 1285 dm_block_t block = get_bio_block(tc, bio);
1154 struct dm_thin_lookup_result lookup_result; 1286 struct dm_thin_lookup_result lookup_result;
1155 struct dm_thin_new_mapping *m; 1287 struct dm_thin_new_mapping *m;
1156 1288
1157 build_virtual_key(tc->td, block, &key); 1289 if (tc->requeue_mode) {
1158 if (bio_detain(tc->pool, &key, bio, &cell)) 1290 cell_requeue(pool, cell);
1159 return; 1291 return;
1292 }
1160 1293
1161 r = dm_thin_find_block(tc->td, block, 1, &lookup_result); 1294 r = dm_thin_find_block(tc->td, block, 1, &lookup_result);
1162 switch (r) { 1295 switch (r) {
@@ -1187,12 +1320,9 @@ static void process_discard(struct thin_c *tc, struct bio *bio)
1187 m->cell2 = cell2; 1320 m->cell2 = cell2;
1188 m->bio = bio; 1321 m->bio = bio;
1189 1322
1190 if (!dm_deferred_set_add_work(pool->all_io_ds, &m->list)) { 1323 if (!dm_deferred_set_add_work(pool->all_io_ds, &m->list))
1191 spin_lock_irqsave(&pool->lock, flags); 1324 pool->process_prepared_discard(m);
1192 list_add_tail(&m->list, &pool->prepared_discards); 1325
1193 spin_unlock_irqrestore(&pool->lock, flags);
1194 wake_worker(pool);
1195 }
1196 } else { 1326 } else {
1197 inc_all_io_entry(pool, bio); 1327 inc_all_io_entry(pool, bio);
1198 cell_defer_no_holder(tc, cell); 1328 cell_defer_no_holder(tc, cell);
@@ -1227,6 +1357,19 @@ static void process_discard(struct thin_c *tc, struct bio *bio)
1227 } 1357 }
1228} 1358}
1229 1359
1360static void process_discard_bio(struct thin_c *tc, struct bio *bio)
1361{
1362 struct dm_bio_prison_cell *cell;
1363 struct dm_cell_key key;
1364 dm_block_t block = get_bio_block(tc, bio);
1365
1366 build_virtual_key(tc->td, block, &key);
1367 if (bio_detain(tc->pool, &key, bio, &cell))
1368 return;
1369
1370 process_discard_cell(tc, cell);
1371}
1372
1230static void break_sharing(struct thin_c *tc, struct bio *bio, dm_block_t block, 1373static void break_sharing(struct thin_c *tc, struct bio *bio, dm_block_t block,
1231 struct dm_cell_key *key, 1374 struct dm_cell_key *key,
1232 struct dm_thin_lookup_result *lookup_result, 1375 struct dm_thin_lookup_result *lookup_result,
@@ -1255,11 +1398,53 @@ static void break_sharing(struct thin_c *tc, struct bio *bio, dm_block_t block,
1255 } 1398 }
1256} 1399}
1257 1400
1401static void __remap_and_issue_shared_cell(void *context,
1402 struct dm_bio_prison_cell *cell)
1403{
1404 struct remap_info *info = context;
1405 struct bio *bio;
1406
1407 while ((bio = bio_list_pop(&cell->bios))) {
1408 if ((bio_data_dir(bio) == WRITE) ||
1409 (bio->bi_rw & (REQ_DISCARD | REQ_FLUSH | REQ_FUA)))
1410 bio_list_add(&info->defer_bios, bio);
1411 else {
1412 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));;
1413
1414 h->shared_read_entry = dm_deferred_entry_inc(info->tc->pool->shared_read_ds);
1415 inc_all_io_entry(info->tc->pool, bio);
1416 bio_list_add(&info->issue_bios, bio);
1417 }
1418 }
1419}
1420
1421static void remap_and_issue_shared_cell(struct thin_c *tc,
1422 struct dm_bio_prison_cell *cell,
1423 dm_block_t block)
1424{
1425 struct bio *bio;
1426 struct remap_info info;
1427
1428 info.tc = tc;
1429 bio_list_init(&info.defer_bios);
1430 bio_list_init(&info.issue_bios);
1431
1432 cell_visit_release(tc->pool, __remap_and_issue_shared_cell,
1433 &info, cell);
1434
1435 while ((bio = bio_list_pop(&info.defer_bios)))
1436 thin_defer_bio(tc, bio);
1437
1438 while ((bio = bio_list_pop(&info.issue_bios)))
1439 remap_and_issue(tc, bio, block);
1440}
1441
1258static void process_shared_bio(struct thin_c *tc, struct bio *bio, 1442static void process_shared_bio(struct thin_c *tc, struct bio *bio,
1259 dm_block_t block, 1443 dm_block_t block,
1260 struct dm_thin_lookup_result *lookup_result) 1444 struct dm_thin_lookup_result *lookup_result,
1445 struct dm_bio_prison_cell *virt_cell)
1261{ 1446{
1262 struct dm_bio_prison_cell *cell; 1447 struct dm_bio_prison_cell *data_cell;
1263 struct pool *pool = tc->pool; 1448 struct pool *pool = tc->pool;
1264 struct dm_cell_key key; 1449 struct dm_cell_key key;
1265 1450
@@ -1268,19 +1453,23 @@ static void process_shared_bio(struct thin_c *tc, struct bio *bio,
1268 * of being broken so we have nothing further to do here. 1453 * of being broken so we have nothing further to do here.
1269 */ 1454 */
1270 build_data_key(tc->td, lookup_result->block, &key); 1455 build_data_key(tc->td, lookup_result->block, &key);
1271 if (bio_detain(pool, &key, bio, &cell)) 1456 if (bio_detain(pool, &key, bio, &data_cell)) {
1457 cell_defer_no_holder(tc, virt_cell);
1272 return; 1458 return;
1459 }
1273 1460
1274 if (bio_data_dir(bio) == WRITE && bio->bi_iter.bi_size) 1461 if (bio_data_dir(bio) == WRITE && bio->bi_iter.bi_size) {
1275 break_sharing(tc, bio, block, &key, lookup_result, cell); 1462 break_sharing(tc, bio, block, &key, lookup_result, data_cell);
1276 else { 1463 cell_defer_no_holder(tc, virt_cell);
1464 } else {
1277 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook)); 1465 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
1278 1466
1279 h->shared_read_entry = dm_deferred_entry_inc(pool->shared_read_ds); 1467 h->shared_read_entry = dm_deferred_entry_inc(pool->shared_read_ds);
1280 inc_all_io_entry(pool, bio); 1468 inc_all_io_entry(pool, bio);
1281 cell_defer_no_holder(tc, cell);
1282
1283 remap_and_issue(tc, bio, lookup_result->block); 1469 remap_and_issue(tc, bio, lookup_result->block);
1470
1471 remap_and_issue_shared_cell(tc, data_cell, lookup_result->block);
1472 remap_and_issue_shared_cell(tc, virt_cell, lookup_result->block);
1284 } 1473 }
1285} 1474}
1286 1475
@@ -1333,34 +1522,28 @@ static void provision_block(struct thin_c *tc, struct bio *bio, dm_block_t block
1333 } 1522 }
1334} 1523}
1335 1524
1336static void process_bio(struct thin_c *tc, struct bio *bio) 1525static void process_cell(struct thin_c *tc, struct dm_bio_prison_cell *cell)
1337{ 1526{
1338 int r; 1527 int r;
1339 struct pool *pool = tc->pool; 1528 struct pool *pool = tc->pool;
1529 struct bio *bio = cell->holder;
1340 dm_block_t block = get_bio_block(tc, bio); 1530 dm_block_t block = get_bio_block(tc, bio);
1341 struct dm_bio_prison_cell *cell;
1342 struct dm_cell_key key;
1343 struct dm_thin_lookup_result lookup_result; 1531 struct dm_thin_lookup_result lookup_result;
1344 1532
1345 /* 1533 if (tc->requeue_mode) {
1346 * If cell is already occupied, then the block is already 1534 cell_requeue(pool, cell);
1347 * being provisioned so we have nothing further to do here.
1348 */
1349 build_virtual_key(tc->td, block, &key);
1350 if (bio_detain(pool, &key, bio, &cell))
1351 return; 1535 return;
1536 }
1352 1537
1353 r = dm_thin_find_block(tc->td, block, 1, &lookup_result); 1538 r = dm_thin_find_block(tc->td, block, 1, &lookup_result);
1354 switch (r) { 1539 switch (r) {
1355 case 0: 1540 case 0:
1356 if (lookup_result.shared) { 1541 if (lookup_result.shared)
1357 process_shared_bio(tc, bio, block, &lookup_result); 1542 process_shared_bio(tc, bio, block, &lookup_result, cell);
1358 cell_defer_no_holder(tc, cell); /* FIXME: pass this cell into process_shared? */ 1543 else {
1359 } else {
1360 inc_all_io_entry(pool, bio); 1544 inc_all_io_entry(pool, bio);
1361 cell_defer_no_holder(tc, cell);
1362
1363 remap_and_issue(tc, bio, lookup_result.block); 1545 remap_and_issue(tc, bio, lookup_result.block);
1546 inc_remap_and_issue_cell(tc, cell, lookup_result.block);
1364 } 1547 }
1365 break; 1548 break;
1366 1549
@@ -1394,7 +1577,26 @@ static void process_bio(struct thin_c *tc, struct bio *bio)
1394 } 1577 }
1395} 1578}
1396 1579
1397static void process_bio_read_only(struct thin_c *tc, struct bio *bio) 1580static void process_bio(struct thin_c *tc, struct bio *bio)
1581{
1582 struct pool *pool = tc->pool;
1583 dm_block_t block = get_bio_block(tc, bio);
1584 struct dm_bio_prison_cell *cell;
1585 struct dm_cell_key key;
1586
1587 /*
1588 * If cell is already occupied, then the block is already
1589 * being provisioned so we have nothing further to do here.
1590 */
1591 build_virtual_key(tc->td, block, &key);
1592 if (bio_detain(pool, &key, bio, &cell))
1593 return;
1594
1595 process_cell(tc, cell);
1596}
1597
1598static void __process_bio_read_only(struct thin_c *tc, struct bio *bio,
1599 struct dm_bio_prison_cell *cell)
1398{ 1600{
1399 int r; 1601 int r;
1400 int rw = bio_data_dir(bio); 1602 int rw = bio_data_dir(bio);
@@ -1404,15 +1606,21 @@ static void process_bio_read_only(struct thin_c *tc, struct bio *bio)
1404 r = dm_thin_find_block(tc->td, block, 1, &lookup_result); 1606 r = dm_thin_find_block(tc->td, block, 1, &lookup_result);
1405 switch (r) { 1607 switch (r) {
1406 case 0: 1608 case 0:
1407 if (lookup_result.shared && (rw == WRITE) && bio->bi_iter.bi_size) 1609 if (lookup_result.shared && (rw == WRITE) && bio->bi_iter.bi_size) {
1408 handle_unserviceable_bio(tc->pool, bio); 1610 handle_unserviceable_bio(tc->pool, bio);
1409 else { 1611 if (cell)
1612 cell_defer_no_holder(tc, cell);
1613 } else {
1410 inc_all_io_entry(tc->pool, bio); 1614 inc_all_io_entry(tc->pool, bio);
1411 remap_and_issue(tc, bio, lookup_result.block); 1615 remap_and_issue(tc, bio, lookup_result.block);
1616 if (cell)
1617 inc_remap_and_issue_cell(tc, cell, lookup_result.block);
1412 } 1618 }
1413 break; 1619 break;
1414 1620
1415 case -ENODATA: 1621 case -ENODATA:
1622 if (cell)
1623 cell_defer_no_holder(tc, cell);
1416 if (rw != READ) { 1624 if (rw != READ) {
1417 handle_unserviceable_bio(tc->pool, bio); 1625 handle_unserviceable_bio(tc->pool, bio);
1418 break; 1626 break;
@@ -1431,11 +1639,23 @@ static void process_bio_read_only(struct thin_c *tc, struct bio *bio)
1431 default: 1639 default:
1432 DMERR_LIMIT("%s: dm_thin_find_block() failed: error = %d", 1640 DMERR_LIMIT("%s: dm_thin_find_block() failed: error = %d",
1433 __func__, r); 1641 __func__, r);
1642 if (cell)
1643 cell_defer_no_holder(tc, cell);
1434 bio_io_error(bio); 1644 bio_io_error(bio);
1435 break; 1645 break;
1436 } 1646 }
1437} 1647}
1438 1648
1649static void process_bio_read_only(struct thin_c *tc, struct bio *bio)
1650{
1651 __process_bio_read_only(tc, bio, NULL);
1652}
1653
1654static void process_cell_read_only(struct thin_c *tc, struct dm_bio_prison_cell *cell)
1655{
1656 __process_bio_read_only(tc, cell->holder, cell);
1657}
1658
1439static void process_bio_success(struct thin_c *tc, struct bio *bio) 1659static void process_bio_success(struct thin_c *tc, struct bio *bio)
1440{ 1660{
1441 bio_endio(bio, 0); 1661 bio_endio(bio, 0);
@@ -1446,6 +1666,16 @@ static void process_bio_fail(struct thin_c *tc, struct bio *bio)
1446 bio_io_error(bio); 1666 bio_io_error(bio);
1447} 1667}
1448 1668
1669static void process_cell_success(struct thin_c *tc, struct dm_bio_prison_cell *cell)
1670{
1671 cell_success(tc->pool, cell);
1672}
1673
1674static void process_cell_fail(struct thin_c *tc, struct dm_bio_prison_cell *cell)
1675{
1676 cell_error(tc->pool, cell);
1677}
1678
1449/* 1679/*
1450 * FIXME: should we also commit due to size of transaction, measured in 1680 * FIXME: should we also commit due to size of transaction, measured in
1451 * metadata blocks? 1681 * metadata blocks?
@@ -1527,9 +1757,10 @@ static void process_thin_deferred_bios(struct thin_c *tc)
1527 struct bio *bio; 1757 struct bio *bio;
1528 struct bio_list bios; 1758 struct bio_list bios;
1529 struct blk_plug plug; 1759 struct blk_plug plug;
1760 unsigned count = 0;
1530 1761
1531 if (tc->requeue_mode) { 1762 if (tc->requeue_mode) {
1532 requeue_bio_list(tc, &tc->deferred_bio_list); 1763 error_thin_bio_list(tc, &tc->deferred_bio_list, DM_ENDIO_REQUEUE);
1533 return; 1764 return;
1534 } 1765 }
1535 1766
@@ -1568,10 +1799,97 @@ static void process_thin_deferred_bios(struct thin_c *tc)
1568 pool->process_discard(tc, bio); 1799 pool->process_discard(tc, bio);
1569 else 1800 else
1570 pool->process_bio(tc, bio); 1801 pool->process_bio(tc, bio);
1802
1803 if ((count++ & 127) == 0) {
1804 throttle_work_update(&pool->throttle);
1805 dm_pool_issue_prefetches(pool->pmd);
1806 }
1571 } 1807 }
1572 blk_finish_plug(&plug); 1808 blk_finish_plug(&plug);
1573} 1809}
1574 1810
1811static int cmp_cells(const void *lhs, const void *rhs)
1812{
1813 struct dm_bio_prison_cell *lhs_cell = *((struct dm_bio_prison_cell **) lhs);
1814 struct dm_bio_prison_cell *rhs_cell = *((struct dm_bio_prison_cell **) rhs);
1815
1816 BUG_ON(!lhs_cell->holder);
1817 BUG_ON(!rhs_cell->holder);
1818
1819 if (lhs_cell->holder->bi_iter.bi_sector < rhs_cell->holder->bi_iter.bi_sector)
1820 return -1;
1821
1822 if (lhs_cell->holder->bi_iter.bi_sector > rhs_cell->holder->bi_iter.bi_sector)
1823 return 1;
1824
1825 return 0;
1826}
1827
1828static unsigned sort_cells(struct pool *pool, struct list_head *cells)
1829{
1830 unsigned count = 0;
1831 struct dm_bio_prison_cell *cell, *tmp;
1832
1833 list_for_each_entry_safe(cell, tmp, cells, user_list) {
1834 if (count >= CELL_SORT_ARRAY_SIZE)
1835 break;
1836
1837 pool->cell_sort_array[count++] = cell;
1838 list_del(&cell->user_list);
1839 }
1840
1841 sort(pool->cell_sort_array, count, sizeof(cell), cmp_cells, NULL);
1842
1843 return count;
1844}
1845
1846static void process_thin_deferred_cells(struct thin_c *tc)
1847{
1848 struct pool *pool = tc->pool;
1849 unsigned long flags;
1850 struct list_head cells;
1851 struct dm_bio_prison_cell *cell;
1852 unsigned i, j, count;
1853
1854 INIT_LIST_HEAD(&cells);
1855
1856 spin_lock_irqsave(&tc->lock, flags);
1857 list_splice_init(&tc->deferred_cells, &cells);
1858 spin_unlock_irqrestore(&tc->lock, flags);
1859
1860 if (list_empty(&cells))
1861 return;
1862
1863 do {
1864 count = sort_cells(tc->pool, &cells);
1865
1866 for (i = 0; i < count; i++) {
1867 cell = pool->cell_sort_array[i];
1868 BUG_ON(!cell->holder);
1869
1870 /*
1871 * If we've got no free new_mapping structs, and processing
1872 * this bio might require one, we pause until there are some
1873 * prepared mappings to process.
1874 */
1875 if (ensure_next_mapping(pool)) {
1876 for (j = i; j < count; j++)
1877 list_add(&pool->cell_sort_array[j]->user_list, &cells);
1878
1879 spin_lock_irqsave(&tc->lock, flags);
1880 list_splice(&cells, &tc->deferred_cells);
1881 spin_unlock_irqrestore(&tc->lock, flags);
1882 return;
1883 }
1884
1885 if (cell->holder->bi_rw & REQ_DISCARD)
1886 pool->process_discard_cell(tc, cell);
1887 else
1888 pool->process_cell(tc, cell);
1889 }
1890 } while (!list_empty(&cells));
1891}
1892
1575static void thin_get(struct thin_c *tc); 1893static void thin_get(struct thin_c *tc);
1576static void thin_put(struct thin_c *tc); 1894static void thin_put(struct thin_c *tc);
1577 1895
@@ -1620,6 +1938,7 @@ static void process_deferred_bios(struct pool *pool)
1620 1938
1621 tc = get_first_thin(pool); 1939 tc = get_first_thin(pool);
1622 while (tc) { 1940 while (tc) {
1941 process_thin_deferred_cells(tc);
1623 process_thin_deferred_bios(tc); 1942 process_thin_deferred_bios(tc);
1624 tc = get_next_thin(pool, tc); 1943 tc = get_next_thin(pool, tc);
1625 } 1944 }
@@ -1653,9 +1972,15 @@ static void do_worker(struct work_struct *ws)
1653{ 1972{
1654 struct pool *pool = container_of(ws, struct pool, worker); 1973 struct pool *pool = container_of(ws, struct pool, worker);
1655 1974
1975 throttle_work_start(&pool->throttle);
1976 dm_pool_issue_prefetches(pool->pmd);
1977 throttle_work_update(&pool->throttle);
1656 process_prepared(pool, &pool->prepared_mappings, &pool->process_prepared_mapping); 1978 process_prepared(pool, &pool->prepared_mappings, &pool->process_prepared_mapping);
1979 throttle_work_update(&pool->throttle);
1657 process_prepared(pool, &pool->prepared_discards, &pool->process_prepared_discard); 1980 process_prepared(pool, &pool->prepared_discards, &pool->process_prepared_discard);
1981 throttle_work_update(&pool->throttle);
1658 process_deferred_bios(pool); 1982 process_deferred_bios(pool);
1983 throttle_work_complete(&pool->throttle);
1659} 1984}
1660 1985
1661/* 1986/*
@@ -1792,6 +2117,8 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode)
1792 dm_pool_metadata_read_only(pool->pmd); 2117 dm_pool_metadata_read_only(pool->pmd);
1793 pool->process_bio = process_bio_fail; 2118 pool->process_bio = process_bio_fail;
1794 pool->process_discard = process_bio_fail; 2119 pool->process_discard = process_bio_fail;
2120 pool->process_cell = process_cell_fail;
2121 pool->process_discard_cell = process_cell_fail;
1795 pool->process_prepared_mapping = process_prepared_mapping_fail; 2122 pool->process_prepared_mapping = process_prepared_mapping_fail;
1796 pool->process_prepared_discard = process_prepared_discard_fail; 2123 pool->process_prepared_discard = process_prepared_discard_fail;
1797 2124
@@ -1804,6 +2131,8 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode)
1804 dm_pool_metadata_read_only(pool->pmd); 2131 dm_pool_metadata_read_only(pool->pmd);
1805 pool->process_bio = process_bio_read_only; 2132 pool->process_bio = process_bio_read_only;
1806 pool->process_discard = process_bio_success; 2133 pool->process_discard = process_bio_success;
2134 pool->process_cell = process_cell_read_only;
2135 pool->process_discard_cell = process_cell_success;
1807 pool->process_prepared_mapping = process_prepared_mapping_fail; 2136 pool->process_prepared_mapping = process_prepared_mapping_fail;
1808 pool->process_prepared_discard = process_prepared_discard_passdown; 2137 pool->process_prepared_discard = process_prepared_discard_passdown;
1809 2138
@@ -1822,7 +2151,9 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode)
1822 if (old_mode != new_mode) 2151 if (old_mode != new_mode)
1823 notify_of_pool_mode_change(pool, "out-of-data-space"); 2152 notify_of_pool_mode_change(pool, "out-of-data-space");
1824 pool->process_bio = process_bio_read_only; 2153 pool->process_bio = process_bio_read_only;
1825 pool->process_discard = process_discard; 2154 pool->process_discard = process_discard_bio;
2155 pool->process_cell = process_cell_read_only;
2156 pool->process_discard_cell = process_discard_cell;
1826 pool->process_prepared_mapping = process_prepared_mapping; 2157 pool->process_prepared_mapping = process_prepared_mapping;
1827 pool->process_prepared_discard = process_prepared_discard_passdown; 2158 pool->process_prepared_discard = process_prepared_discard_passdown;
1828 2159
@@ -1835,7 +2166,9 @@ static void set_pool_mode(struct pool *pool, enum pool_mode new_mode)
1835 notify_of_pool_mode_change(pool, "write"); 2166 notify_of_pool_mode_change(pool, "write");
1836 dm_pool_metadata_read_write(pool->pmd); 2167 dm_pool_metadata_read_write(pool->pmd);
1837 pool->process_bio = process_bio; 2168 pool->process_bio = process_bio;
1838 pool->process_discard = process_discard; 2169 pool->process_discard = process_discard_bio;
2170 pool->process_cell = process_cell;
2171 pool->process_discard_cell = process_discard_cell;
1839 pool->process_prepared_mapping = process_prepared_mapping; 2172 pool->process_prepared_mapping = process_prepared_mapping;
1840 pool->process_prepared_discard = process_prepared_discard; 2173 pool->process_prepared_discard = process_prepared_discard;
1841 break; 2174 break;
@@ -1895,6 +2228,29 @@ static void thin_defer_bio(struct thin_c *tc, struct bio *bio)
1895 wake_worker(pool); 2228 wake_worker(pool);
1896} 2229}
1897 2230
2231static void thin_defer_bio_with_throttle(struct thin_c *tc, struct bio *bio)
2232{
2233 struct pool *pool = tc->pool;
2234
2235 throttle_lock(&pool->throttle);
2236 thin_defer_bio(tc, bio);
2237 throttle_unlock(&pool->throttle);
2238}
2239
2240static void thin_defer_cell(struct thin_c *tc, struct dm_bio_prison_cell *cell)
2241{
2242 unsigned long flags;
2243 struct pool *pool = tc->pool;
2244
2245 throttle_lock(&pool->throttle);
2246 spin_lock_irqsave(&tc->lock, flags);
2247 list_add_tail(&cell->user_list, &tc->deferred_cells);
2248 spin_unlock_irqrestore(&tc->lock, flags);
2249 throttle_unlock(&pool->throttle);
2250
2251 wake_worker(pool);
2252}
2253
1898static void thin_hook_bio(struct thin_c *tc, struct bio *bio) 2254static void thin_hook_bio(struct thin_c *tc, struct bio *bio)
1899{ 2255{
1900 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook)); 2256 struct dm_thin_endio_hook *h = dm_per_bio_data(bio, sizeof(struct dm_thin_endio_hook));
@@ -1915,8 +2271,7 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)
1915 dm_block_t block = get_bio_block(tc, bio); 2271 dm_block_t block = get_bio_block(tc, bio);
1916 struct dm_thin_device *td = tc->td; 2272 struct dm_thin_device *td = tc->td;
1917 struct dm_thin_lookup_result result; 2273 struct dm_thin_lookup_result result;
1918 struct dm_bio_prison_cell cell1, cell2; 2274 struct dm_bio_prison_cell *virt_cell, *data_cell;
1919 struct dm_bio_prison_cell *cell_result;
1920 struct dm_cell_key key; 2275 struct dm_cell_key key;
1921 2276
1922 thin_hook_bio(tc, bio); 2277 thin_hook_bio(tc, bio);
@@ -1932,10 +2287,18 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)
1932 } 2287 }
1933 2288
1934 if (bio->bi_rw & (REQ_DISCARD | REQ_FLUSH | REQ_FUA)) { 2289 if (bio->bi_rw & (REQ_DISCARD | REQ_FLUSH | REQ_FUA)) {
1935 thin_defer_bio(tc, bio); 2290 thin_defer_bio_with_throttle(tc, bio);
1936 return DM_MAPIO_SUBMITTED; 2291 return DM_MAPIO_SUBMITTED;
1937 } 2292 }
1938 2293
2294 /*
2295 * We must hold the virtual cell before doing the lookup, otherwise
2296 * there's a race with discard.
2297 */
2298 build_virtual_key(tc->td, block, &key);
2299 if (bio_detain(tc->pool, &key, bio, &virt_cell))
2300 return DM_MAPIO_SUBMITTED;
2301
1939 r = dm_thin_find_block(td, block, 0, &result); 2302 r = dm_thin_find_block(td, block, 0, &result);
1940 2303
1941 /* 2304 /*
@@ -1958,23 +2321,19 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)
1958 * More distant ancestors are irrelevant. The 2321 * More distant ancestors are irrelevant. The
1959 * shared flag will be set in their case. 2322 * shared flag will be set in their case.
1960 */ 2323 */
1961 thin_defer_bio(tc, bio); 2324 thin_defer_cell(tc, virt_cell);
1962 return DM_MAPIO_SUBMITTED; 2325 return DM_MAPIO_SUBMITTED;
1963 } 2326 }
1964 2327
1965 build_virtual_key(tc->td, block, &key);
1966 if (dm_bio_detain(tc->pool->prison, &key, bio, &cell1, &cell_result))
1967 return DM_MAPIO_SUBMITTED;
1968
1969 build_data_key(tc->td, result.block, &key); 2328 build_data_key(tc->td, result.block, &key);
1970 if (dm_bio_detain(tc->pool->prison, &key, bio, &cell2, &cell_result)) { 2329 if (bio_detain(tc->pool, &key, bio, &data_cell)) {
1971 cell_defer_no_holder_no_free(tc, &cell1); 2330 cell_defer_no_holder(tc, virt_cell);
1972 return DM_MAPIO_SUBMITTED; 2331 return DM_MAPIO_SUBMITTED;
1973 } 2332 }
1974 2333
1975 inc_all_io_entry(tc->pool, bio); 2334 inc_all_io_entry(tc->pool, bio);
1976 cell_defer_no_holder_no_free(tc, &cell2); 2335 cell_defer_no_holder(tc, data_cell);
1977 cell_defer_no_holder_no_free(tc, &cell1); 2336 cell_defer_no_holder(tc, virt_cell);
1978 2337
1979 remap(tc, bio, result.block); 2338 remap(tc, bio, result.block);
1980 return DM_MAPIO_REMAPPED; 2339 return DM_MAPIO_REMAPPED;
@@ -1986,16 +2345,13 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)
1986 * of doing so. 2345 * of doing so.
1987 */ 2346 */
1988 handle_unserviceable_bio(tc->pool, bio); 2347 handle_unserviceable_bio(tc->pool, bio);
2348 cell_defer_no_holder(tc, virt_cell);
1989 return DM_MAPIO_SUBMITTED; 2349 return DM_MAPIO_SUBMITTED;
1990 } 2350 }
1991 /* fall through */ 2351 /* fall through */
1992 2352
1993 case -EWOULDBLOCK: 2353 case -EWOULDBLOCK:
1994 /* 2354 thin_defer_cell(tc, virt_cell);
1995 * In future, the failed dm_thin_find_block above could
1996 * provide the hint to load the metadata into cache.
1997 */
1998 thin_defer_bio(tc, bio);
1999 return DM_MAPIO_SUBMITTED; 2355 return DM_MAPIO_SUBMITTED;
2000 2356
2001 default: 2357 default:
@@ -2005,6 +2361,7 @@ static int thin_bio_map(struct dm_target *ti, struct bio *bio)
2005 * pool is switched to fail-io mode. 2361 * pool is switched to fail-io mode.
2006 */ 2362 */
2007 bio_io_error(bio); 2363 bio_io_error(bio);
2364 cell_defer_no_holder(tc, virt_cell);
2008 return DM_MAPIO_SUBMITTED; 2365 return DM_MAPIO_SUBMITTED;
2009 } 2366 }
2010} 2367}
@@ -2185,7 +2542,7 @@ static struct pool *pool_create(struct mapped_device *pool_md,
2185 pool->sectors_per_block_shift = __ffs(block_size); 2542 pool->sectors_per_block_shift = __ffs(block_size);
2186 pool->low_water_blocks = 0; 2543 pool->low_water_blocks = 0;
2187 pool_features_init(&pool->pf); 2544 pool_features_init(&pool->pf);
2188 pool->prison = dm_bio_prison_create(PRISON_CELLS); 2545 pool->prison = dm_bio_prison_create();
2189 if (!pool->prison) { 2546 if (!pool->prison) {
2190 *error = "Error creating pool's bio prison"; 2547 *error = "Error creating pool's bio prison";
2191 err_p = ERR_PTR(-ENOMEM); 2548 err_p = ERR_PTR(-ENOMEM);
@@ -2211,6 +2568,7 @@ static struct pool *pool_create(struct mapped_device *pool_md,
2211 goto bad_wq; 2568 goto bad_wq;
2212 } 2569 }
2213 2570
2571 throttle_init(&pool->throttle);
2214 INIT_WORK(&pool->worker, do_worker); 2572 INIT_WORK(&pool->worker, do_worker);
2215 INIT_DELAYED_WORK(&pool->waker, do_waker); 2573 INIT_DELAYED_WORK(&pool->waker, do_waker);
2216 INIT_DELAYED_WORK(&pool->no_space_timeout, do_no_space_timeout); 2574 INIT_DELAYED_WORK(&pool->no_space_timeout, do_no_space_timeout);
@@ -2220,6 +2578,7 @@ static struct pool *pool_create(struct mapped_device *pool_md,
2220 INIT_LIST_HEAD(&pool->prepared_discards); 2578 INIT_LIST_HEAD(&pool->prepared_discards);
2221 INIT_LIST_HEAD(&pool->active_thins); 2579 INIT_LIST_HEAD(&pool->active_thins);
2222 pool->low_water_triggered = false; 2580 pool->low_water_triggered = false;
2581 pool->suspended = true;
2223 2582
2224 pool->shared_read_ds = dm_deferred_set_create(); 2583 pool->shared_read_ds = dm_deferred_set_create();
2225 if (!pool->shared_read_ds) { 2584 if (!pool->shared_read_ds) {
@@ -2756,20 +3115,77 @@ static int pool_preresume(struct dm_target *ti)
2756 return 0; 3115 return 0;
2757} 3116}
2758 3117
3118static void pool_suspend_active_thins(struct pool *pool)
3119{
3120 struct thin_c *tc;
3121
3122 /* Suspend all active thin devices */
3123 tc = get_first_thin(pool);
3124 while (tc) {
3125 dm_internal_suspend_noflush(tc->thin_md);
3126 tc = get_next_thin(pool, tc);
3127 }
3128}
3129
3130static void pool_resume_active_thins(struct pool *pool)
3131{
3132 struct thin_c *tc;
3133
3134 /* Resume all active thin devices */
3135 tc = get_first_thin(pool);
3136 while (tc) {
3137 dm_internal_resume(tc->thin_md);
3138 tc = get_next_thin(pool, tc);
3139 }
3140}
3141
2759static void pool_resume(struct dm_target *ti) 3142static void pool_resume(struct dm_target *ti)
2760{ 3143{
2761 struct pool_c *pt = ti->private; 3144 struct pool_c *pt = ti->private;
2762 struct pool *pool = pt->pool; 3145 struct pool *pool = pt->pool;
2763 unsigned long flags; 3146 unsigned long flags;
2764 3147
3148 /*
3149 * Must requeue active_thins' bios and then resume
3150 * active_thins _before_ clearing 'suspend' flag.
3151 */
3152 requeue_bios(pool);
3153 pool_resume_active_thins(pool);
3154
2765 spin_lock_irqsave(&pool->lock, flags); 3155 spin_lock_irqsave(&pool->lock, flags);
2766 pool->low_water_triggered = false; 3156 pool->low_water_triggered = false;
3157 pool->suspended = false;
2767 spin_unlock_irqrestore(&pool->lock, flags); 3158 spin_unlock_irqrestore(&pool->lock, flags);
2768 requeue_bios(pool);
2769 3159
2770 do_waker(&pool->waker.work); 3160 do_waker(&pool->waker.work);
2771} 3161}
2772 3162
3163static void pool_presuspend(struct dm_target *ti)
3164{
3165 struct pool_c *pt = ti->private;
3166 struct pool *pool = pt->pool;
3167 unsigned long flags;
3168
3169 spin_lock_irqsave(&pool->lock, flags);
3170 pool->suspended = true;
3171 spin_unlock_irqrestore(&pool->lock, flags);
3172
3173 pool_suspend_active_thins(pool);
3174}
3175
3176static void pool_presuspend_undo(struct dm_target *ti)
3177{
3178 struct pool_c *pt = ti->private;
3179 struct pool *pool = pt->pool;
3180 unsigned long flags;
3181
3182 pool_resume_active_thins(pool);
3183
3184 spin_lock_irqsave(&pool->lock, flags);
3185 pool->suspended = false;
3186 spin_unlock_irqrestore(&pool->lock, flags);
3187}
3188
2773static void pool_postsuspend(struct dm_target *ti) 3189static void pool_postsuspend(struct dm_target *ti)
2774{ 3190{
2775 struct pool_c *pt = ti->private; 3191 struct pool_c *pt = ti->private;
@@ -2941,7 +3357,6 @@ static int process_release_metadata_snap_mesg(unsigned argc, char **argv, struct
2941 * create_thin <dev_id> 3357 * create_thin <dev_id>
2942 * create_snap <dev_id> <origin_id> 3358 * create_snap <dev_id> <origin_id>
2943 * delete <dev_id> 3359 * delete <dev_id>
2944 * trim <dev_id> <new_size_in_sectors>
2945 * set_transaction_id <current_trans_id> <new_trans_id> 3360 * set_transaction_id <current_trans_id> <new_trans_id>
2946 * reserve_metadata_snap 3361 * reserve_metadata_snap
2947 * release_metadata_snap 3362 * release_metadata_snap
@@ -3169,15 +3584,35 @@ static void pool_io_hints(struct dm_target *ti, struct queue_limits *limits)
3169{ 3584{
3170 struct pool_c *pt = ti->private; 3585 struct pool_c *pt = ti->private;
3171 struct pool *pool = pt->pool; 3586 struct pool *pool = pt->pool;
3172 uint64_t io_opt_sectors = limits->io_opt >> SECTOR_SHIFT; 3587 sector_t io_opt_sectors = limits->io_opt >> SECTOR_SHIFT;
3588
3589 /*
3590 * If max_sectors is smaller than pool->sectors_per_block adjust it
3591 * to the highest possible power-of-2 factor of pool->sectors_per_block.
3592 * This is especially beneficial when the pool's data device is a RAID
3593 * device that has a full stripe width that matches pool->sectors_per_block
3594 * -- because even though partial RAID stripe-sized IOs will be issued to a
3595 * single RAID stripe; when aggregated they will end on a full RAID stripe
3596 * boundary.. which avoids additional partial RAID stripe writes cascading
3597 */
3598 if (limits->max_sectors < pool->sectors_per_block) {
3599 while (!is_factor(pool->sectors_per_block, limits->max_sectors)) {
3600 if ((limits->max_sectors & (limits->max_sectors - 1)) == 0)
3601 limits->max_sectors--;
3602 limits->max_sectors = rounddown_pow_of_two(limits->max_sectors);
3603 }
3604 }
3173 3605
3174 /* 3606 /*
3175 * If the system-determined stacked limits are compatible with the 3607 * If the system-determined stacked limits are compatible with the
3176 * pool's blocksize (io_opt is a factor) do not override them. 3608 * pool's blocksize (io_opt is a factor) do not override them.
3177 */ 3609 */
3178 if (io_opt_sectors < pool->sectors_per_block || 3610 if (io_opt_sectors < pool->sectors_per_block ||
3179 do_div(io_opt_sectors, pool->sectors_per_block)) { 3611 !is_factor(io_opt_sectors, pool->sectors_per_block)) {
3180 blk_limits_io_min(limits, pool->sectors_per_block << SECTOR_SHIFT); 3612 if (is_factor(pool->sectors_per_block, limits->max_sectors))
3613 blk_limits_io_min(limits, limits->max_sectors << SECTOR_SHIFT);
3614 else
3615 blk_limits_io_min(limits, pool->sectors_per_block << SECTOR_SHIFT);
3181 blk_limits_io_opt(limits, pool->sectors_per_block << SECTOR_SHIFT); 3616 blk_limits_io_opt(limits, pool->sectors_per_block << SECTOR_SHIFT);
3182 } 3617 }
3183 3618
@@ -3206,11 +3641,13 @@ static struct target_type pool_target = {
3206 .name = "thin-pool", 3641 .name = "thin-pool",
3207 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE | 3642 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE |
3208 DM_TARGET_IMMUTABLE, 3643 DM_TARGET_IMMUTABLE,
3209 .version = {1, 13, 0}, 3644 .version = {1, 14, 0},
3210 .module = THIS_MODULE, 3645 .module = THIS_MODULE,
3211 .ctr = pool_ctr, 3646 .ctr = pool_ctr,
3212 .dtr = pool_dtr, 3647 .dtr = pool_dtr,
3213 .map = pool_map, 3648 .map = pool_map,
3649 .presuspend = pool_presuspend,
3650 .presuspend_undo = pool_presuspend_undo,
3214 .postsuspend = pool_postsuspend, 3651 .postsuspend = pool_postsuspend,
3215 .preresume = pool_preresume, 3652 .preresume = pool_preresume,
3216 .resume = pool_resume, 3653 .resume = pool_resume,
@@ -3240,14 +3677,14 @@ static void thin_dtr(struct dm_target *ti)
3240 struct thin_c *tc = ti->private; 3677 struct thin_c *tc = ti->private;
3241 unsigned long flags; 3678 unsigned long flags;
3242 3679
3243 thin_put(tc);
3244 wait_for_completion(&tc->can_destroy);
3245
3246 spin_lock_irqsave(&tc->pool->lock, flags); 3680 spin_lock_irqsave(&tc->pool->lock, flags);
3247 list_del_rcu(&tc->list); 3681 list_del_rcu(&tc->list);
3248 spin_unlock_irqrestore(&tc->pool->lock, flags); 3682 spin_unlock_irqrestore(&tc->pool->lock, flags);
3249 synchronize_rcu(); 3683 synchronize_rcu();
3250 3684
3685 thin_put(tc);
3686 wait_for_completion(&tc->can_destroy);
3687
3251 mutex_lock(&dm_thin_pool_table.mutex); 3688 mutex_lock(&dm_thin_pool_table.mutex);
3252 3689
3253 __pool_dec(tc->pool); 3690 __pool_dec(tc->pool);
@@ -3294,7 +3731,9 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
3294 r = -ENOMEM; 3731 r = -ENOMEM;
3295 goto out_unlock; 3732 goto out_unlock;
3296 } 3733 }
3734 tc->thin_md = dm_table_get_md(ti->table);
3297 spin_lock_init(&tc->lock); 3735 spin_lock_init(&tc->lock);
3736 INIT_LIST_HEAD(&tc->deferred_cells);
3298 bio_list_init(&tc->deferred_bio_list); 3737 bio_list_init(&tc->deferred_bio_list);
3299 bio_list_init(&tc->retry_on_resume_list); 3738 bio_list_init(&tc->retry_on_resume_list);
3300 tc->sort_bio_list = RB_ROOT; 3739 tc->sort_bio_list = RB_ROOT;
@@ -3339,18 +3778,18 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
3339 if (get_pool_mode(tc->pool) == PM_FAIL) { 3778 if (get_pool_mode(tc->pool) == PM_FAIL) {
3340 ti->error = "Couldn't open thin device, Pool is in fail mode"; 3779 ti->error = "Couldn't open thin device, Pool is in fail mode";
3341 r = -EINVAL; 3780 r = -EINVAL;
3342 goto bad_thin_open; 3781 goto bad_pool;
3343 } 3782 }
3344 3783
3345 r = dm_pool_open_thin_device(tc->pool->pmd, tc->dev_id, &tc->td); 3784 r = dm_pool_open_thin_device(tc->pool->pmd, tc->dev_id, &tc->td);
3346 if (r) { 3785 if (r) {
3347 ti->error = "Couldn't open thin internal device"; 3786 ti->error = "Couldn't open thin internal device";
3348 goto bad_thin_open; 3787 goto bad_pool;
3349 } 3788 }
3350 3789
3351 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block); 3790 r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block);
3352 if (r) 3791 if (r)
3353 goto bad_target_max_io_len; 3792 goto bad;
3354 3793
3355 ti->num_flush_bios = 1; 3794 ti->num_flush_bios = 1;
3356 ti->flush_supported = true; 3795 ti->flush_supported = true;
@@ -3365,14 +3804,16 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
3365 ti->split_discard_bios = true; 3804 ti->split_discard_bios = true;
3366 } 3805 }
3367 3806
3368 dm_put(pool_md);
3369
3370 mutex_unlock(&dm_thin_pool_table.mutex); 3807 mutex_unlock(&dm_thin_pool_table.mutex);
3371 3808
3372 atomic_set(&tc->refcount, 1);
3373 init_completion(&tc->can_destroy);
3374
3375 spin_lock_irqsave(&tc->pool->lock, flags); 3809 spin_lock_irqsave(&tc->pool->lock, flags);
3810 if (tc->pool->suspended) {
3811 spin_unlock_irqrestore(&tc->pool->lock, flags);
3812 mutex_lock(&dm_thin_pool_table.mutex); /* reacquire for __pool_dec */
3813 ti->error = "Unable to activate thin device while pool is suspended";
3814 r = -EINVAL;
3815 goto bad;
3816 }
3376 list_add_tail_rcu(&tc->list, &tc->pool->active_thins); 3817 list_add_tail_rcu(&tc->list, &tc->pool->active_thins);
3377 spin_unlock_irqrestore(&tc->pool->lock, flags); 3818 spin_unlock_irqrestore(&tc->pool->lock, flags);
3378 /* 3819 /*
@@ -3383,11 +3824,16 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
3383 */ 3824 */
3384 synchronize_rcu(); 3825 synchronize_rcu();
3385 3826
3827 dm_put(pool_md);
3828
3829 atomic_set(&tc->refcount, 1);
3830 init_completion(&tc->can_destroy);
3831
3386 return 0; 3832 return 0;
3387 3833
3388bad_target_max_io_len: 3834bad:
3389 dm_pool_close_thin_device(tc->td); 3835 dm_pool_close_thin_device(tc->td);
3390bad_thin_open: 3836bad_pool:
3391 __pool_dec(tc->pool); 3837 __pool_dec(tc->pool);
3392bad_pool_lookup: 3838bad_pool_lookup:
3393 dm_put(pool_md); 3839 dm_put(pool_md);
@@ -3533,6 +3979,21 @@ err:
3533 DMEMIT("Error"); 3979 DMEMIT("Error");
3534} 3980}
3535 3981
3982static int thin_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
3983 struct bio_vec *biovec, int max_size)
3984{
3985 struct thin_c *tc = ti->private;
3986 struct request_queue *q = bdev_get_queue(tc->pool_dev->bdev);
3987
3988 if (!q->merge_bvec_fn)
3989 return max_size;
3990
3991 bvm->bi_bdev = tc->pool_dev->bdev;
3992 bvm->bi_sector = dm_target_offset(ti, bvm->bi_sector);
3993
3994 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
3995}
3996
3536static int thin_iterate_devices(struct dm_target *ti, 3997static int thin_iterate_devices(struct dm_target *ti,
3537 iterate_devices_callout_fn fn, void *data) 3998 iterate_devices_callout_fn fn, void *data)
3538{ 3999{
@@ -3557,7 +4018,7 @@ static int thin_iterate_devices(struct dm_target *ti,
3557 4018
3558static struct target_type thin_target = { 4019static struct target_type thin_target = {
3559 .name = "thin", 4020 .name = "thin",
3560 .version = {1, 13, 0}, 4021 .version = {1, 14, 0},
3561 .module = THIS_MODULE, 4022 .module = THIS_MODULE,
3562 .ctr = thin_ctr, 4023 .ctr = thin_ctr,
3563 .dtr = thin_dtr, 4024 .dtr = thin_dtr,
@@ -3567,6 +4028,7 @@ static struct target_type thin_target = {
3567 .presuspend = thin_presuspend, 4028 .presuspend = thin_presuspend,
3568 .postsuspend = thin_postsuspend, 4029 .postsuspend = thin_postsuspend,
3569 .status = thin_status, 4030 .status = thin_status,
4031 .merge = thin_merge,
3570 .iterate_devices = thin_iterate_devices, 4032 .iterate_devices = thin_iterate_devices,
3571}; 4033};
3572 4034
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 58f3927fd7cc..8f37ed215b19 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -19,6 +19,7 @@
19#include <linux/idr.h> 19#include <linux/idr.h>
20#include <linux/hdreg.h> 20#include <linux/hdreg.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/wait.h>
22 23
23#include <trace/events/block.h> 24#include <trace/events/block.h>
24 25
@@ -117,6 +118,7 @@ EXPORT_SYMBOL_GPL(dm_get_rq_mapinfo);
117#define DMF_NOFLUSH_SUSPENDING 5 118#define DMF_NOFLUSH_SUSPENDING 5
118#define DMF_MERGE_IS_OPTIONAL 6 119#define DMF_MERGE_IS_OPTIONAL 6
119#define DMF_DEFERRED_REMOVE 7 120#define DMF_DEFERRED_REMOVE 7
121#define DMF_SUSPENDED_INTERNALLY 8
120 122
121/* 123/*
122 * A dummy definition to make RCU happy. 124 * A dummy definition to make RCU happy.
@@ -140,7 +142,7 @@ struct mapped_device {
140 * Use dm_get_live_table{_fast} or take suspend_lock for 142 * Use dm_get_live_table{_fast} or take suspend_lock for
141 * dereference. 143 * dereference.
142 */ 144 */
143 struct dm_table *map; 145 struct dm_table __rcu *map;
144 146
145 struct list_head table_devices; 147 struct list_head table_devices;
146 struct mutex table_devices_lock; 148 struct mutex table_devices_lock;
@@ -525,14 +527,15 @@ retry:
525 goto out; 527 goto out;
526 528
527 tgt = dm_table_get_target(map, 0); 529 tgt = dm_table_get_target(map, 0);
530 if (!tgt->type->ioctl)
531 goto out;
528 532
529 if (dm_suspended_md(md)) { 533 if (dm_suspended_md(md)) {
530 r = -EAGAIN; 534 r = -EAGAIN;
531 goto out; 535 goto out;
532 } 536 }
533 537
534 if (tgt->type->ioctl) 538 r = tgt->type->ioctl(tgt, cmd, arg);
535 r = tgt->type->ioctl(tgt, cmd, arg);
536 539
537out: 540out:
538 dm_put_live_table(md, srcu_idx); 541 dm_put_live_table(md, srcu_idx);
@@ -1607,9 +1610,9 @@ static int dm_merge_bvec(struct request_queue *q,
1607 * Find maximum amount of I/O that won't need splitting 1610 * Find maximum amount of I/O that won't need splitting
1608 */ 1611 */
1609 max_sectors = min(max_io_len(bvm->bi_sector, ti), 1612 max_sectors = min(max_io_len(bvm->bi_sector, ti),
1610 (sector_t) BIO_MAX_SECTORS); 1613 (sector_t) queue_max_sectors(q));
1611 max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size; 1614 max_size = (max_sectors << SECTOR_SHIFT) - bvm->bi_size;
1612 if (max_size < 0) 1615 if (unlikely(max_size < 0)) /* this shouldn't _ever_ happen */
1613 max_size = 0; 1616 max_size = 0;
1614 1617
1615 /* 1618 /*
@@ -1621,10 +1624,10 @@ static int dm_merge_bvec(struct request_queue *q,
1621 max_size = ti->type->merge(ti, bvm, biovec, max_size); 1624 max_size = ti->type->merge(ti, bvm, biovec, max_size);
1622 /* 1625 /*
1623 * If the target doesn't support merge method and some of the devices 1626 * If the target doesn't support merge method and some of the devices
1624 * provided their merge_bvec method (we know this by looking at 1627 * provided their merge_bvec method (we know this by looking for the
1625 * queue_max_hw_sectors), then we can't allow bios with multiple vector 1628 * max_hw_sectors that dm_set_device_limits may set), then we can't
1626 * entries. So always set max_size to 0, and the code below allows 1629 * allow bios with multiple vector entries. So always set max_size
1627 * just one page. 1630 * to 0, and the code below allows just one page.
1628 */ 1631 */
1629 else if (queue_max_hw_sectors(q) <= PAGE_SIZE >> 9) 1632 else if (queue_max_hw_sectors(q) <= PAGE_SIZE >> 9)
1630 max_size = 0; 1633 max_size = 0;
@@ -2332,7 +2335,7 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t,
2332 2335
2333 merge_is_optional = dm_table_merge_is_optional(t); 2336 merge_is_optional = dm_table_merge_is_optional(t);
2334 2337
2335 old_map = md->map; 2338 old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock));
2336 rcu_assign_pointer(md->map, t); 2339 rcu_assign_pointer(md->map, t);
2337 md->immutable_target_type = dm_table_get_immutable_target_type(t); 2340 md->immutable_target_type = dm_table_get_immutable_target_type(t);
2338 2341
@@ -2341,7 +2344,8 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t,
2341 set_bit(DMF_MERGE_IS_OPTIONAL, &md->flags); 2344 set_bit(DMF_MERGE_IS_OPTIONAL, &md->flags);
2342 else 2345 else
2343 clear_bit(DMF_MERGE_IS_OPTIONAL, &md->flags); 2346 clear_bit(DMF_MERGE_IS_OPTIONAL, &md->flags);
2344 dm_sync_table(md); 2347 if (old_map)
2348 dm_sync_table(md);
2345 2349
2346 return old_map; 2350 return old_map;
2347} 2351}
@@ -2351,7 +2355,7 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t,
2351 */ 2355 */
2352static struct dm_table *__unbind(struct mapped_device *md) 2356static struct dm_table *__unbind(struct mapped_device *md)
2353{ 2357{
2354 struct dm_table *map = md->map; 2358 struct dm_table *map = rcu_dereference_protected(md->map, 1);
2355 2359
2356 if (!map) 2360 if (!map)
2357 return NULL; 2361 return NULL;
@@ -2716,36 +2720,18 @@ static void unlock_fs(struct mapped_device *md)
2716} 2720}
2717 2721
2718/* 2722/*
2719 * We need to be able to change a mapping table under a mounted 2723 * If __dm_suspend returns 0, the device is completely quiescent
2720 * filesystem. For example we might want to move some data in 2724 * now. There is no request-processing activity. All new requests
2721 * the background. Before the table can be swapped with 2725 * are being added to md->deferred list.
2722 * dm_bind_table, dm_suspend must be called to flush any in
2723 * flight bios and ensure that any further io gets deferred.
2724 */
2725/*
2726 * Suspend mechanism in request-based dm.
2727 * 2726 *
2728 * 1. Flush all I/Os by lock_fs() if needed. 2727 * Caller must hold md->suspend_lock
2729 * 2. Stop dispatching any I/O by stopping the request_queue.
2730 * 3. Wait for all in-flight I/Os to be completed or requeued.
2731 *
2732 * To abort suspend, start the request_queue.
2733 */ 2728 */
2734int dm_suspend(struct mapped_device *md, unsigned suspend_flags) 2729static int __dm_suspend(struct mapped_device *md, struct dm_table *map,
2730 unsigned suspend_flags, int interruptible)
2735{ 2731{
2736 struct dm_table *map = NULL; 2732 bool do_lockfs = suspend_flags & DM_SUSPEND_LOCKFS_FLAG;
2737 int r = 0; 2733 bool noflush = suspend_flags & DM_SUSPEND_NOFLUSH_FLAG;
2738 int do_lockfs = suspend_flags & DM_SUSPEND_LOCKFS_FLAG ? 1 : 0; 2734 int r;
2739 int noflush = suspend_flags & DM_SUSPEND_NOFLUSH_FLAG ? 1 : 0;
2740
2741 mutex_lock(&md->suspend_lock);
2742
2743 if (dm_suspended_md(md)) {
2744 r = -EINVAL;
2745 goto out_unlock;
2746 }
2747
2748 map = md->map;
2749 2735
2750 /* 2736 /*
2751 * DMF_NOFLUSH_SUSPENDING must be set before presuspend. 2737 * DMF_NOFLUSH_SUSPENDING must be set before presuspend.
@@ -2754,7 +2740,10 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
2754 if (noflush) 2740 if (noflush)
2755 set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); 2741 set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
2756 2742
2757 /* This does not get reverted if there's an error later. */ 2743 /*
2744 * This gets reverted if there's an error later and the targets
2745 * provide the .presuspend_undo hook.
2746 */
2758 dm_table_presuspend_targets(map); 2747 dm_table_presuspend_targets(map);
2759 2748
2760 /* 2749 /*
@@ -2765,8 +2754,10 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
2765 */ 2754 */
2766 if (!noflush && do_lockfs) { 2755 if (!noflush && do_lockfs) {
2767 r = lock_fs(md); 2756 r = lock_fs(md);
2768 if (r) 2757 if (r) {
2769 goto out_unlock; 2758 dm_table_presuspend_undo_targets(map);
2759 return r;
2760 }
2770 } 2761 }
2771 2762
2772 /* 2763 /*
@@ -2782,7 +2773,8 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
2782 * flush_workqueue(md->wq). 2773 * flush_workqueue(md->wq).
2783 */ 2774 */
2784 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); 2775 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags);
2785 synchronize_srcu(&md->io_barrier); 2776 if (map)
2777 synchronize_srcu(&md->io_barrier);
2786 2778
2787 /* 2779 /*
2788 * Stop md->queue before flushing md->wq in case request-based 2780 * Stop md->queue before flushing md->wq in case request-based
@@ -2798,11 +2790,12 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
2798 * We call dm_wait_for_completion to wait for all existing requests 2790 * We call dm_wait_for_completion to wait for all existing requests
2799 * to finish. 2791 * to finish.
2800 */ 2792 */
2801 r = dm_wait_for_completion(md, TASK_INTERRUPTIBLE); 2793 r = dm_wait_for_completion(md, interruptible);
2802 2794
2803 if (noflush) 2795 if (noflush)
2804 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags); 2796 clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
2805 synchronize_srcu(&md->io_barrier); 2797 if (map)
2798 synchronize_srcu(&md->io_barrier);
2806 2799
2807 /* were we interrupted ? */ 2800 /* were we interrupted ? */
2808 if (r < 0) { 2801 if (r < 0) {
@@ -2812,14 +2805,56 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
2812 start_queue(md->queue); 2805 start_queue(md->queue);
2813 2806
2814 unlock_fs(md); 2807 unlock_fs(md);
2815 goto out_unlock; /* pushback list is already flushed, so skip flush */ 2808 dm_table_presuspend_undo_targets(map);
2809 /* pushback list is already flushed, so skip flush */
2816 } 2810 }
2817 2811
2818 /* 2812 return r;
2819 * If dm_wait_for_completion returned 0, the device is completely 2813}
2820 * quiescent now. There is no request-processing activity. All new 2814
2821 * requests are being added to md->deferred list. 2815/*
2822 */ 2816 * We need to be able to change a mapping table under a mounted
2817 * filesystem. For example we might want to move some data in
2818 * the background. Before the table can be swapped with
2819 * dm_bind_table, dm_suspend must be called to flush any in
2820 * flight bios and ensure that any further io gets deferred.
2821 */
2822/*
2823 * Suspend mechanism in request-based dm.
2824 *
2825 * 1. Flush all I/Os by lock_fs() if needed.
2826 * 2. Stop dispatching any I/O by stopping the request_queue.
2827 * 3. Wait for all in-flight I/Os to be completed or requeued.
2828 *
2829 * To abort suspend, start the request_queue.
2830 */
2831int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
2832{
2833 struct dm_table *map = NULL;
2834 int r = 0;
2835
2836retry:
2837 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING);
2838
2839 if (dm_suspended_md(md)) {
2840 r = -EINVAL;
2841 goto out_unlock;
2842 }
2843
2844 if (dm_suspended_internally_md(md)) {
2845 /* already internally suspended, wait for internal resume */
2846 mutex_unlock(&md->suspend_lock);
2847 r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE);
2848 if (r)
2849 return r;
2850 goto retry;
2851 }
2852
2853 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock));
2854
2855 r = __dm_suspend(md, map, suspend_flags, TASK_INTERRUPTIBLE);
2856 if (r)
2857 goto out_unlock;
2823 2858
2824 set_bit(DMF_SUSPENDED, &md->flags); 2859 set_bit(DMF_SUSPENDED, &md->flags);
2825 2860
@@ -2830,22 +2865,13 @@ out_unlock:
2830 return r; 2865 return r;
2831} 2866}
2832 2867
2833int dm_resume(struct mapped_device *md) 2868static int __dm_resume(struct mapped_device *md, struct dm_table *map)
2834{ 2869{
2835 int r = -EINVAL; 2870 if (map) {
2836 struct dm_table *map = NULL; 2871 int r = dm_table_resume_targets(map);
2837 2872 if (r)
2838 mutex_lock(&md->suspend_lock); 2873 return r;
2839 if (!dm_suspended_md(md)) 2874 }
2840 goto out;
2841
2842 map = md->map;
2843 if (!map || !dm_table_get_size(map))
2844 goto out;
2845
2846 r = dm_table_resume_targets(map);
2847 if (r)
2848 goto out;
2849 2875
2850 dm_queue_flush(md); 2876 dm_queue_flush(md);
2851 2877
@@ -2859,6 +2885,37 @@ int dm_resume(struct mapped_device *md)
2859 2885
2860 unlock_fs(md); 2886 unlock_fs(md);
2861 2887
2888 return 0;
2889}
2890
2891int dm_resume(struct mapped_device *md)
2892{
2893 int r = -EINVAL;
2894 struct dm_table *map = NULL;
2895
2896retry:
2897 mutex_lock_nested(&md->suspend_lock, SINGLE_DEPTH_NESTING);
2898
2899 if (!dm_suspended_md(md))
2900 goto out;
2901
2902 if (dm_suspended_internally_md(md)) {
2903 /* already internally suspended, wait for internal resume */
2904 mutex_unlock(&md->suspend_lock);
2905 r = wait_on_bit(&md->flags, DMF_SUSPENDED_INTERNALLY, TASK_INTERRUPTIBLE);
2906 if (r)
2907 return r;
2908 goto retry;
2909 }
2910
2911 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock));
2912 if (!map || !dm_table_get_size(map))
2913 goto out;
2914
2915 r = __dm_resume(md, map);
2916 if (r)
2917 goto out;
2918
2862 clear_bit(DMF_SUSPENDED, &md->flags); 2919 clear_bit(DMF_SUSPENDED, &md->flags);
2863 2920
2864 r = 0; 2921 r = 0;
@@ -2872,15 +2929,80 @@ out:
2872 * Internal suspend/resume works like userspace-driven suspend. It waits 2929 * Internal suspend/resume works like userspace-driven suspend. It waits
2873 * until all bios finish and prevents issuing new bios to the target drivers. 2930 * until all bios finish and prevents issuing new bios to the target drivers.
2874 * It may be used only from the kernel. 2931 * It may be used only from the kernel.
2875 *
2876 * Internal suspend holds md->suspend_lock, which prevents interaction with
2877 * userspace-driven suspend.
2878 */ 2932 */
2879 2933
2880void dm_internal_suspend(struct mapped_device *md) 2934static void __dm_internal_suspend(struct mapped_device *md, unsigned suspend_flags)
2881{ 2935{
2882 mutex_lock(&md->suspend_lock); 2936 struct dm_table *map = NULL;
2937
2938 if (dm_suspended_internally_md(md))
2939 return; /* nested internal suspend */
2940
2941 if (dm_suspended_md(md)) {
2942 set_bit(DMF_SUSPENDED_INTERNALLY, &md->flags);
2943 return; /* nest suspend */
2944 }
2945
2946 map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock));
2947
2948 /*
2949 * Using TASK_UNINTERRUPTIBLE because only NOFLUSH internal suspend is
2950 * supported. Properly supporting a TASK_INTERRUPTIBLE internal suspend
2951 * would require changing .presuspend to return an error -- avoid this
2952 * until there is a need for more elaborate variants of internal suspend.
2953 */
2954 (void) __dm_suspend(md, map, suspend_flags, TASK_UNINTERRUPTIBLE);
2955
2956 set_bit(DMF_SUSPENDED_INTERNALLY, &md->flags);
2957
2958 dm_table_postsuspend_targets(map);
2959}
2960
2961static void __dm_internal_resume(struct mapped_device *md)
2962{
2963 if (!dm_suspended_internally_md(md))
2964 return; /* resume from nested internal suspend */
2965
2883 if (dm_suspended_md(md)) 2966 if (dm_suspended_md(md))
2967 goto done; /* resume from nested suspend */
2968
2969 /*
2970 * NOTE: existing callers don't need to call dm_table_resume_targets
2971 * (which may fail -- so best to avoid it for now by passing NULL map)
2972 */
2973 (void) __dm_resume(md, NULL);
2974
2975done:
2976 clear_bit(DMF_SUSPENDED_INTERNALLY, &md->flags);
2977 smp_mb__after_atomic();
2978 wake_up_bit(&md->flags, DMF_SUSPENDED_INTERNALLY);
2979}
2980
2981void dm_internal_suspend_noflush(struct mapped_device *md)
2982{
2983 mutex_lock(&md->suspend_lock);
2984 __dm_internal_suspend(md, DM_SUSPEND_NOFLUSH_FLAG);
2985 mutex_unlock(&md->suspend_lock);
2986}
2987EXPORT_SYMBOL_GPL(dm_internal_suspend_noflush);
2988
2989void dm_internal_resume(struct mapped_device *md)
2990{
2991 mutex_lock(&md->suspend_lock);
2992 __dm_internal_resume(md);
2993 mutex_unlock(&md->suspend_lock);
2994}
2995EXPORT_SYMBOL_GPL(dm_internal_resume);
2996
2997/*
2998 * Fast variants of internal suspend/resume hold md->suspend_lock,
2999 * which prevents interaction with userspace-driven suspend.
3000 */
3001
3002void dm_internal_suspend_fast(struct mapped_device *md)
3003{
3004 mutex_lock(&md->suspend_lock);
3005 if (dm_suspended_md(md) || dm_suspended_internally_md(md))
2884 return; 3006 return;
2885 3007
2886 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags); 3008 set_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags);
@@ -2889,9 +3011,9 @@ void dm_internal_suspend(struct mapped_device *md)
2889 dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE); 3011 dm_wait_for_completion(md, TASK_UNINTERRUPTIBLE);
2890} 3012}
2891 3013
2892void dm_internal_resume(struct mapped_device *md) 3014void dm_internal_resume_fast(struct mapped_device *md)
2893{ 3015{
2894 if (dm_suspended_md(md)) 3016 if (dm_suspended_md(md) || dm_suspended_internally_md(md))
2895 goto done; 3017 goto done;
2896 3018
2897 dm_queue_flush(md); 3019 dm_queue_flush(md);
@@ -2977,6 +3099,11 @@ int dm_suspended_md(struct mapped_device *md)
2977 return test_bit(DMF_SUSPENDED, &md->flags); 3099 return test_bit(DMF_SUSPENDED, &md->flags);
2978} 3100}
2979 3101
3102int dm_suspended_internally_md(struct mapped_device *md)
3103{
3104 return test_bit(DMF_SUSPENDED_INTERNALLY, &md->flags);
3105}
3106
2980int dm_test_deferred_remove_flag(struct mapped_device *md) 3107int dm_test_deferred_remove_flag(struct mapped_device *md)
2981{ 3108{
2982 return test_bit(DMF_DEFERRED_REMOVE, &md->flags); 3109 return test_bit(DMF_DEFERRED_REMOVE, &md->flags);
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index 988c7fb7b145..84b0f9e4ba6c 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -65,6 +65,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
65 struct queue_limits *limits); 65 struct queue_limits *limits);
66struct list_head *dm_table_get_devices(struct dm_table *t); 66struct list_head *dm_table_get_devices(struct dm_table *t);
67void dm_table_presuspend_targets(struct dm_table *t); 67void dm_table_presuspend_targets(struct dm_table *t);
68void dm_table_presuspend_undo_targets(struct dm_table *t);
68void dm_table_postsuspend_targets(struct dm_table *t); 69void dm_table_postsuspend_targets(struct dm_table *t);
69int dm_table_resume_targets(struct dm_table *t); 70int dm_table_resume_targets(struct dm_table *t);
70int dm_table_any_congested(struct dm_table *t, int bdi_bits); 71int dm_table_any_congested(struct dm_table *t, int bdi_bits);
@@ -129,6 +130,15 @@ int dm_deleting_md(struct mapped_device *md);
129int dm_suspended_md(struct mapped_device *md); 130int dm_suspended_md(struct mapped_device *md);
130 131
131/* 132/*
133 * Internal suspend and resume methods.
134 */
135int dm_suspended_internally_md(struct mapped_device *md);
136void dm_internal_suspend_fast(struct mapped_device *md);
137void dm_internal_resume_fast(struct mapped_device *md);
138void dm_internal_suspend_noflush(struct mapped_device *md);
139void dm_internal_resume(struct mapped_device *md);
140
141/*
132 * Test if the device is scheduled for deferred remove. 142 * Test if the device is scheduled for deferred remove.
133 */ 143 */
134int dm_test_deferred_remove_flag(struct mapped_device *md); 144int dm_test_deferred_remove_flag(struct mapped_device *md);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 4dfa15da9cb8..9233c71138f1 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -5121,6 +5121,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
5121 printk("md: %s still in use.\n",mdname(mddev)); 5121 printk("md: %s still in use.\n",mdname(mddev));
5122 if (did_freeze) { 5122 if (did_freeze) {
5123 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); 5123 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
5124 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5124 md_wakeup_thread(mddev->thread); 5125 md_wakeup_thread(mddev->thread);
5125 } 5126 }
5126 err = -EBUSY; 5127 err = -EBUSY;
@@ -5135,6 +5136,8 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
5135 mddev->ro = 1; 5136 mddev->ro = 1;
5136 set_disk_ro(mddev->gendisk, 1); 5137 set_disk_ro(mddev->gendisk, 1);
5137 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); 5138 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
5139 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5140 md_wakeup_thread(mddev->thread);
5138 sysfs_notify_dirent_safe(mddev->sysfs_state); 5141 sysfs_notify_dirent_safe(mddev->sysfs_state);
5139 err = 0; 5142 err = 0;
5140 } 5143 }
@@ -5178,6 +5181,7 @@ static int do_md_stop(struct mddev *mddev, int mode,
5178 mutex_unlock(&mddev->open_mutex); 5181 mutex_unlock(&mddev->open_mutex);
5179 if (did_freeze) { 5182 if (did_freeze) {
5180 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery); 5183 clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
5184 set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
5181 md_wakeup_thread(mddev->thread); 5185 md_wakeup_thread(mddev->thread);
5182 } 5186 }
5183 return -EBUSY; 5187 return -EBUSY;
diff --git a/drivers/md/persistent-data/dm-array.c b/drivers/md/persistent-data/dm-array.c
index 1d75b1dc1e2e..e64b61ad0ef3 100644
--- a/drivers/md/persistent-data/dm-array.c
+++ b/drivers/md/persistent-data/dm-array.c
@@ -645,8 +645,10 @@ static int array_resize(struct dm_array_info *info, dm_block_t root,
645 int r; 645 int r;
646 struct resize resize; 646 struct resize resize;
647 647
648 if (old_size == new_size) 648 if (old_size == new_size) {
649 *new_root = root;
649 return 0; 650 return 0;
651 }
650 652
651 resize.info = info; 653 resize.info = info;
652 resize.root = root; 654 resize.root = root;
diff --git a/drivers/md/persistent-data/dm-btree-internal.h b/drivers/md/persistent-data/dm-btree-internal.h
index 37d367bb9aa8..bf2b80d5c470 100644
--- a/drivers/md/persistent-data/dm-btree-internal.h
+++ b/drivers/md/persistent-data/dm-btree-internal.h
@@ -42,6 +42,12 @@ struct btree_node {
42} __packed; 42} __packed;
43 43
44 44
45/*
46 * Locks a block using the btree node validator.
47 */
48int bn_read_lock(struct dm_btree_info *info, dm_block_t b,
49 struct dm_block **result);
50
45void inc_children(struct dm_transaction_manager *tm, struct btree_node *n, 51void inc_children(struct dm_transaction_manager *tm, struct btree_node *n,
46 struct dm_btree_value_type *vt); 52 struct dm_btree_value_type *vt);
47 53
diff --git a/drivers/md/persistent-data/dm-btree-spine.c b/drivers/md/persistent-data/dm-btree-spine.c
index cf9fd676ae44..1b5e13ec7f96 100644
--- a/drivers/md/persistent-data/dm-btree-spine.c
+++ b/drivers/md/persistent-data/dm-btree-spine.c
@@ -92,7 +92,7 @@ struct dm_block_validator btree_node_validator = {
92 92
93/*----------------------------------------------------------------*/ 93/*----------------------------------------------------------------*/
94 94
95static int bn_read_lock(struct dm_btree_info *info, dm_block_t b, 95int bn_read_lock(struct dm_btree_info *info, dm_block_t b,
96 struct dm_block **result) 96 struct dm_block **result)
97{ 97{
98 return dm_tm_read_lock(info->tm, b, &btree_node_validator, result); 98 return dm_tm_read_lock(info->tm, b, &btree_node_validator, result);
diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c
index 416060c25709..200ac12a1d40 100644
--- a/drivers/md/persistent-data/dm-btree.c
+++ b/drivers/md/persistent-data/dm-btree.c
@@ -847,22 +847,26 @@ EXPORT_SYMBOL_GPL(dm_btree_find_lowest_key);
847 * FIXME: We shouldn't use a recursive algorithm when we have limited stack 847 * FIXME: We shouldn't use a recursive algorithm when we have limited stack
848 * space. Also this only works for single level trees. 848 * space. Also this only works for single level trees.
849 */ 849 */
850static int walk_node(struct ro_spine *s, dm_block_t block, 850static int walk_node(struct dm_btree_info *info, dm_block_t block,
851 int (*fn)(void *context, uint64_t *keys, void *leaf), 851 int (*fn)(void *context, uint64_t *keys, void *leaf),
852 void *context) 852 void *context)
853{ 853{
854 int r; 854 int r;
855 unsigned i, nr; 855 unsigned i, nr;
856 struct dm_block *node;
856 struct btree_node *n; 857 struct btree_node *n;
857 uint64_t keys; 858 uint64_t keys;
858 859
859 r = ro_step(s, block); 860 r = bn_read_lock(info, block, &node);
860 n = ro_node(s); 861 if (r)
862 return r;
863
864 n = dm_block_data(node);
861 865
862 nr = le32_to_cpu(n->header.nr_entries); 866 nr = le32_to_cpu(n->header.nr_entries);
863 for (i = 0; i < nr; i++) { 867 for (i = 0; i < nr; i++) {
864 if (le32_to_cpu(n->header.flags) & INTERNAL_NODE) { 868 if (le32_to_cpu(n->header.flags) & INTERNAL_NODE) {
865 r = walk_node(s, value64(n, i), fn, context); 869 r = walk_node(info, value64(n, i), fn, context);
866 if (r) 870 if (r)
867 goto out; 871 goto out;
868 } else { 872 } else {
@@ -874,7 +878,7 @@ static int walk_node(struct ro_spine *s, dm_block_t block,
874 } 878 }
875 879
876out: 880out:
877 ro_pop(s); 881 dm_tm_unlock(info->tm, node);
878 return r; 882 return r;
879} 883}
880 884
@@ -882,15 +886,7 @@ int dm_btree_walk(struct dm_btree_info *info, dm_block_t root,
882 int (*fn)(void *context, uint64_t *keys, void *leaf), 886 int (*fn)(void *context, uint64_t *keys, void *leaf),
883 void *context) 887 void *context)
884{ 888{
885 int r;
886 struct ro_spine spine;
887
888 BUG_ON(info->levels > 1); 889 BUG_ON(info->levels > 1);
889 890 return walk_node(info, root, fn, context);
890 init_ro_spine(&spine, info);
891 r = walk_node(&spine, root, fn, context);
892 exit_ro_spine(&spine);
893
894 return r;
895} 891}
896EXPORT_SYMBOL_GPL(dm_btree_walk); 892EXPORT_SYMBOL_GPL(dm_btree_walk);
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
index 786b689bdfc7..e8a904298887 100644
--- a/drivers/md/persistent-data/dm-space-map-metadata.c
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -564,7 +564,9 @@ static int sm_bootstrap_get_nr_blocks(struct dm_space_map *sm, dm_block_t *count
564{ 564{
565 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm); 565 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
566 566
567 return smm->ll.nr_blocks; 567 *count = smm->ll.nr_blocks;
568
569 return 0;
568} 570}
569 571
570static int sm_bootstrap_get_nr_free(struct dm_space_map *sm, dm_block_t *count) 572static int sm_bootstrap_get_nr_free(struct dm_space_map *sm, dm_block_t *count)
@@ -581,7 +583,9 @@ static int sm_bootstrap_get_count(struct dm_space_map *sm, dm_block_t b,
581{ 583{
582 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm); 584 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
583 585
584 return b < smm->begin ? 1 : 0; 586 *result = (b < smm->begin) ? 1 : 0;
587
588 return 0;
585} 589}
586 590
587static int sm_bootstrap_count_is_more_than_one(struct dm_space_map *sm, 591static int sm_bootstrap_count_is_more_than_one(struct dm_space_map *sm,
diff --git a/drivers/md/persistent-data/dm-transaction-manager.c b/drivers/md/persistent-data/dm-transaction-manager.c
index 3bc30a0ae3d6..9cb797d800cf 100644
--- a/drivers/md/persistent-data/dm-transaction-manager.c
+++ b/drivers/md/persistent-data/dm-transaction-manager.c
@@ -10,6 +10,8 @@
10#include "dm-persistent-data-internal.h" 10#include "dm-persistent-data-internal.h"
11 11
12#include <linux/export.h> 12#include <linux/export.h>
13#include <linux/mutex.h>
14#include <linux/hash.h>
13#include <linux/slab.h> 15#include <linux/slab.h>
14#include <linux/device-mapper.h> 16#include <linux/device-mapper.h>
15 17
@@ -17,6 +19,61 @@
17 19
18/*----------------------------------------------------------------*/ 20/*----------------------------------------------------------------*/
19 21
22#define PREFETCH_SIZE 128
23#define PREFETCH_BITS 7
24#define PREFETCH_SENTINEL ((dm_block_t) -1ULL)
25
26struct prefetch_set {
27 struct mutex lock;
28 dm_block_t blocks[PREFETCH_SIZE];
29};
30
31static unsigned prefetch_hash(dm_block_t b)
32{
33 return hash_64(b, PREFETCH_BITS);
34}
35
36static void prefetch_wipe(struct prefetch_set *p)
37{
38 unsigned i;
39 for (i = 0; i < PREFETCH_SIZE; i++)
40 p->blocks[i] = PREFETCH_SENTINEL;
41}
42
43static void prefetch_init(struct prefetch_set *p)
44{
45 mutex_init(&p->lock);
46 prefetch_wipe(p);
47}
48
49static void prefetch_add(struct prefetch_set *p, dm_block_t b)
50{
51 unsigned h = prefetch_hash(b);
52
53 mutex_lock(&p->lock);
54 if (p->blocks[h] == PREFETCH_SENTINEL)
55 p->blocks[h] = b;
56
57 mutex_unlock(&p->lock);
58}
59
60static void prefetch_issue(struct prefetch_set *p, struct dm_block_manager *bm)
61{
62 unsigned i;
63
64 mutex_lock(&p->lock);
65
66 for (i = 0; i < PREFETCH_SIZE; i++)
67 if (p->blocks[i] != PREFETCH_SENTINEL) {
68 dm_bm_prefetch(bm, p->blocks[i]);
69 p->blocks[i] = PREFETCH_SENTINEL;
70 }
71
72 mutex_unlock(&p->lock);
73}
74
75/*----------------------------------------------------------------*/
76
20struct shadow_info { 77struct shadow_info {
21 struct hlist_node hlist; 78 struct hlist_node hlist;
22 dm_block_t where; 79 dm_block_t where;
@@ -37,6 +94,8 @@ struct dm_transaction_manager {
37 94
38 spinlock_t lock; 95 spinlock_t lock;
39 struct hlist_head buckets[DM_HASH_SIZE]; 96 struct hlist_head buckets[DM_HASH_SIZE];
97
98 struct prefetch_set prefetches;
40}; 99};
41 100
42/*----------------------------------------------------------------*/ 101/*----------------------------------------------------------------*/
@@ -117,6 +176,8 @@ static struct dm_transaction_manager *dm_tm_create(struct dm_block_manager *bm,
117 for (i = 0; i < DM_HASH_SIZE; i++) 176 for (i = 0; i < DM_HASH_SIZE; i++)
118 INIT_HLIST_HEAD(tm->buckets + i); 177 INIT_HLIST_HEAD(tm->buckets + i);
119 178
179 prefetch_init(&tm->prefetches);
180
120 return tm; 181 return tm;
121} 182}
122 183
@@ -268,8 +329,14 @@ int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b,
268 struct dm_block_validator *v, 329 struct dm_block_validator *v,
269 struct dm_block **blk) 330 struct dm_block **blk)
270{ 331{
271 if (tm->is_clone) 332 if (tm->is_clone) {
272 return dm_bm_read_try_lock(tm->real->bm, b, v, blk); 333 int r = dm_bm_read_try_lock(tm->real->bm, b, v, blk);
334
335 if (r == -EWOULDBLOCK)
336 prefetch_add(&tm->real->prefetches, b);
337
338 return r;
339 }
273 340
274 return dm_bm_read_lock(tm->bm, b, v, blk); 341 return dm_bm_read_lock(tm->bm, b, v, blk);
275} 342}
@@ -317,6 +384,12 @@ struct dm_block_manager *dm_tm_get_bm(struct dm_transaction_manager *tm)
317 return tm->bm; 384 return tm->bm;
318} 385}
319 386
387void dm_tm_issue_prefetches(struct dm_transaction_manager *tm)
388{
389 prefetch_issue(&tm->prefetches, tm->bm);
390}
391EXPORT_SYMBOL_GPL(dm_tm_issue_prefetches);
392
320/*----------------------------------------------------------------*/ 393/*----------------------------------------------------------------*/
321 394
322static int dm_tm_create_internal(struct dm_block_manager *bm, 395static int dm_tm_create_internal(struct dm_block_manager *bm,
diff --git a/drivers/md/persistent-data/dm-transaction-manager.h b/drivers/md/persistent-data/dm-transaction-manager.h
index 2772ed2a781a..2e0d4d66fb1b 100644
--- a/drivers/md/persistent-data/dm-transaction-manager.h
+++ b/drivers/md/persistent-data/dm-transaction-manager.h
@@ -109,6 +109,13 @@ int dm_tm_ref(struct dm_transaction_manager *tm, dm_block_t b,
109struct dm_block_manager *dm_tm_get_bm(struct dm_transaction_manager *tm); 109struct dm_block_manager *dm_tm_get_bm(struct dm_transaction_manager *tm);
110 110
111/* 111/*
112 * If you're using a non-blocking clone the tm will build up a list of
113 * requested blocks that weren't in core. This call will request those
114 * blocks to be prefetched.
115 */
116void dm_tm_issue_prefetches(struct dm_transaction_manager *tm);
117
118/*
112 * A little utility that ties the knot by producing a transaction manager 119 * A little utility that ties the knot by producing a transaction manager
113 * that has a space map managed by the transaction manager... 120 * that has a space map managed by the transaction manager...
114 * 121 *
diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index b8579ee68bd6..2cf30576bf39 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -962,6 +962,11 @@ static int dvb_frontend_clear_cache(struct dvb_frontend *fe)
962 case SYS_ATSC: 962 case SYS_ATSC:
963 c->modulation = VSB_8; 963 c->modulation = VSB_8;
964 break; 964 break;
965 case SYS_ISDBS:
966 c->symbol_rate = 28860000;
967 c->rolloff = ROLLOFF_35;
968 c->bandwidth_hz = c->symbol_rate / 100 * 135;
969 break;
965 default: 970 default:
966 c->modulation = QAM_AUTO; 971 c->modulation = QAM_AUTO;
967 break; 972 break;
@@ -2072,6 +2077,7 @@ static int dtv_set_frontend(struct dvb_frontend *fe)
2072 break; 2077 break;
2073 case SYS_DVBS: 2078 case SYS_DVBS:
2074 case SYS_TURBO: 2079 case SYS_TURBO:
2080 case SYS_ISDBS:
2075 rolloff = 135; 2081 rolloff = 135;
2076 break; 2082 break;
2077 case SYS_DVBS2: 2083 case SYS_DVBS2:
diff --git a/drivers/media/dvb-frontends/ds3000.c b/drivers/media/dvb-frontends/ds3000.c
index 335daeff91b9..9d0d0347758f 100644
--- a/drivers/media/dvb-frontends/ds3000.c
+++ b/drivers/media/dvb-frontends/ds3000.c
@@ -864,6 +864,13 @@ struct dvb_frontend *ds3000_attach(const struct ds3000_config *config,
864 memcpy(&state->frontend.ops, &ds3000_ops, 864 memcpy(&state->frontend.ops, &ds3000_ops,
865 sizeof(struct dvb_frontend_ops)); 865 sizeof(struct dvb_frontend_ops));
866 state->frontend.demodulator_priv = state; 866 state->frontend.demodulator_priv = state;
867
868 /*
869 * Some devices like T480 starts with voltage on. Be sure
870 * to turn voltage off during init, as this can otherwise
871 * interfere with Unicable SCR systems.
872 */
873 ds3000_set_voltage(&state->frontend, SEC_VOLTAGE_OFF);
867 return &state->frontend; 874 return &state->frontend;
868 875
869error3: 876error3:
diff --git a/drivers/media/dvb-frontends/sp2.c b/drivers/media/dvb-frontends/sp2.c
index 9b684d5c8f91..15bf4318cb74 100644
--- a/drivers/media/dvb-frontends/sp2.c
+++ b/drivers/media/dvb-frontends/sp2.c
@@ -266,7 +266,7 @@ int sp2_ci_poll_slot_status(struct dvb_ca_en50221 *en50221,
266 return s->status; 266 return s->status;
267} 267}
268 268
269int sp2_init(struct sp2 *s) 269static int sp2_init(struct sp2 *s)
270{ 270{
271 int ret = 0; 271 int ret = 0;
272 u8 buf; 272 u8 buf;
@@ -348,7 +348,7 @@ err:
348 return ret; 348 return ret;
349} 349}
350 350
351int sp2_exit(struct i2c_client *client) 351static int sp2_exit(struct i2c_client *client)
352{ 352{
353 struct sp2 *s; 353 struct sp2 *s;
354 354
diff --git a/drivers/media/dvb-frontends/tc90522.c b/drivers/media/dvb-frontends/tc90522.c
index d9905fb52f84..b35d65c9cc05 100644
--- a/drivers/media/dvb-frontends/tc90522.c
+++ b/drivers/media/dvb-frontends/tc90522.c
@@ -216,32 +216,30 @@ static int tc90522s_get_frontend(struct dvb_frontend *fe)
216 c->delivery_system = SYS_ISDBS; 216 c->delivery_system = SYS_ISDBS;
217 217
218 layers = 0; 218 layers = 0;
219 ret = reg_read(state, 0xe8, val, 3); 219 ret = reg_read(state, 0xe6, val, 5);
220 if (ret == 0) { 220 if (ret == 0) {
221 int slots;
222 u8 v; 221 u8 v;
223 222
223 c->stream_id = val[0] << 8 | val[1];
224
224 /* high/single layer */ 225 /* high/single layer */
225 v = (val[0] & 0x70) >> 4; 226 v = (val[2] & 0x70) >> 4;
226 c->modulation = (v == 7) ? PSK_8 : QPSK; 227 c->modulation = (v == 7) ? PSK_8 : QPSK;
227 c->fec_inner = fec_conv_sat[v]; 228 c->fec_inner = fec_conv_sat[v];
228 c->layer[0].fec = c->fec_inner; 229 c->layer[0].fec = c->fec_inner;
229 c->layer[0].modulation = c->modulation; 230 c->layer[0].modulation = c->modulation;
230 c->layer[0].segment_count = val[1] & 0x3f; /* slots */ 231 c->layer[0].segment_count = val[3] & 0x3f; /* slots */
231 232
232 /* low layer */ 233 /* low layer */
233 v = (val[0] & 0x07); 234 v = (val[2] & 0x07);
234 c->layer[1].fec = fec_conv_sat[v]; 235 c->layer[1].fec = fec_conv_sat[v];
235 if (v == 0) /* no low layer */ 236 if (v == 0) /* no low layer */
236 c->layer[1].segment_count = 0; 237 c->layer[1].segment_count = 0;
237 else 238 else
238 c->layer[1].segment_count = val[2] & 0x3f; /* slots */ 239 c->layer[1].segment_count = val[4] & 0x3f; /* slots */
239 /* actually, BPSK if v==1, but not defined in fe_modulation_t */ 240 /* actually, BPSK if v==1, but not defined in fe_modulation_t */
240 c->layer[1].modulation = QPSK; 241 c->layer[1].modulation = QPSK;
241 layers = (v > 0) ? 2 : 1; 242 layers = (v > 0) ? 2 : 1;
242
243 slots = c->layer[0].segment_count + c->layer[1].segment_count;
244 c->symbol_rate = 28860000 * slots / 48;
245 } 243 }
246 244
247 /* statistics */ 245 /* statistics */
@@ -363,7 +361,7 @@ static int tc90522t_get_frontend(struct dvb_frontend *fe)
363 u8 v; 361 u8 v;
364 362
365 c->isdbt_partial_reception = val[0] & 0x01; 363 c->isdbt_partial_reception = val[0] & 0x01;
366 c->isdbt_sb_mode = (val[0] & 0xc0) == 0x01; 364 c->isdbt_sb_mode = (val[0] & 0xc0) == 0x40;
367 365
368 /* layer A */ 366 /* layer A */
369 v = (val[2] & 0x78) >> 3; 367 v = (val[2] & 0x78) >> 3;
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 932ed9be9ff3..b10aaeda2bb4 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -2190,7 +2190,7 @@ static int smiapp_set_selection(struct v4l2_subdev *subdev,
2190 ret = smiapp_set_compose(subdev, fh, sel); 2190 ret = smiapp_set_compose(subdev, fh, sel);
2191 break; 2191 break;
2192 default: 2192 default:
2193 BUG(); 2193 ret = -EINVAL;
2194 } 2194 }
2195 2195
2196 mutex_unlock(&sensor->mutex); 2196 mutex_unlock(&sensor->mutex);
diff --git a/drivers/media/pci/cx23885/cx23885-core.c b/drivers/media/pci/cx23885/cx23885-core.c
index 331eddac7222..3bd386c371f7 100644
--- a/drivers/media/pci/cx23885/cx23885-core.c
+++ b/drivers/media/pci/cx23885/cx23885-core.c
@@ -1078,7 +1078,7 @@ static __le32 *cx23885_risc_field(__le32 *rp, struct scatterlist *sglist,
1078 for (line = 0; line < lines; line++) { 1078 for (line = 0; line < lines; line++) {
1079 while (offset && offset >= sg_dma_len(sg)) { 1079 while (offset && offset >= sg_dma_len(sg)) {
1080 offset -= sg_dma_len(sg); 1080 offset -= sg_dma_len(sg);
1081 sg++; 1081 sg = sg_next(sg);
1082 } 1082 }
1083 1083
1084 if (lpi && line > 0 && !(line % lpi)) 1084 if (lpi && line > 0 && !(line % lpi))
@@ -1101,14 +1101,14 @@ static __le32 *cx23885_risc_field(__le32 *rp, struct scatterlist *sglist,
1101 *(rp++) = cpu_to_le32(0); /* bits 63-32 */ 1101 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
1102 todo -= (sg_dma_len(sg)-offset); 1102 todo -= (sg_dma_len(sg)-offset);
1103 offset = 0; 1103 offset = 0;
1104 sg++; 1104 sg = sg_next(sg);
1105 while (todo > sg_dma_len(sg)) { 1105 while (todo > sg_dma_len(sg)) {
1106 *(rp++) = cpu_to_le32(RISC_WRITE| 1106 *(rp++) = cpu_to_le32(RISC_WRITE|
1107 sg_dma_len(sg)); 1107 sg_dma_len(sg));
1108 *(rp++) = cpu_to_le32(sg_dma_address(sg)); 1108 *(rp++) = cpu_to_le32(sg_dma_address(sg));
1109 *(rp++) = cpu_to_le32(0); /* bits 63-32 */ 1109 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
1110 todo -= sg_dma_len(sg); 1110 todo -= sg_dma_len(sg);
1111 sg++; 1111 sg = sg_next(sg);
1112 } 1112 }
1113 *(rp++) = cpu_to_le32(RISC_WRITE|RISC_EOL|todo); 1113 *(rp++) = cpu_to_le32(RISC_WRITE|RISC_EOL|todo);
1114 *(rp++) = cpu_to_le32(sg_dma_address(sg)); 1114 *(rp++) = cpu_to_le32(sg_dma_address(sg));
diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
index 172583d736fe..8cbe6b49f4c2 100644
--- a/drivers/media/pci/solo6x10/solo6x10-core.c
+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
@@ -105,11 +105,8 @@ static irqreturn_t solo_isr(int irq, void *data)
105 if (!status) 105 if (!status)
106 return IRQ_NONE; 106 return IRQ_NONE;
107 107
108 if (status & ~solo_dev->irq_mask) { 108 /* Acknowledge all interrupts immediately */
109 solo_reg_write(solo_dev, SOLO_IRQ_STAT, 109 solo_reg_write(solo_dev, SOLO_IRQ_STAT, status);
110 status & ~solo_dev->irq_mask);
111 status &= solo_dev->irq_mask;
112 }
113 110
114 if (status & SOLO_IRQ_PCI_ERR) 111 if (status & SOLO_IRQ_PCI_ERR)
115 solo_p2m_error_isr(solo_dev); 112 solo_p2m_error_isr(solo_dev);
@@ -132,9 +129,6 @@ static irqreturn_t solo_isr(int irq, void *data)
132 if (status & SOLO_IRQ_G723) 129 if (status & SOLO_IRQ_G723)
133 solo_g723_isr(solo_dev); 130 solo_g723_isr(solo_dev);
134 131
135 /* Clear all interrupts handled */
136 solo_reg_write(solo_dev, SOLO_IRQ_STAT, status);
137
138 return IRQ_HANDLED; 132 return IRQ_HANDLED;
139} 133}
140 134
diff --git a/drivers/media/platform/vivid/vivid-core.c b/drivers/media/platform/vivid/vivid-core.c
index 2c61a62ab48b..686c3c2ad05b 100644
--- a/drivers/media/platform/vivid/vivid-core.c
+++ b/drivers/media/platform/vivid/vivid-core.c
@@ -100,11 +100,9 @@ MODULE_PARM_DESC(ccs_out_mode, " output crop/compose/scale mode:\n"
100 "\t\t bit 0=crop, 1=compose, 2=scale,\n" 100 "\t\t bit 0=crop, 1=compose, 2=scale,\n"
101 "\t\t -1=user-controlled (default)"); 101 "\t\t -1=user-controlled (default)");
102 102
103static unsigned multiplanar[VIVID_MAX_DEVS]; 103static unsigned multiplanar[VIVID_MAX_DEVS] = { [0 ... (VIVID_MAX_DEVS - 1)] = 1 };
104module_param_array(multiplanar, uint, NULL, 0444); 104module_param_array(multiplanar, uint, NULL, 0444);
105MODULE_PARM_DESC(multiplanar, " 0 (default) is alternating single and multiplanar devices,\n" 105MODULE_PARM_DESC(multiplanar, " 1 (default) creates a single planar device, 2 creates a multiplanar device.");
106 "\t\t 1 is single planar devices,\n"
107 "\t\t 2 is multiplanar devices");
108 106
109/* Default: video + vbi-cap (raw and sliced) + radio rx + radio tx + sdr + vbi-out + vid-out */ 107/* Default: video + vbi-cap (raw and sliced) + radio rx + radio tx + sdr + vbi-out + vid-out */
110static unsigned node_types[VIVID_MAX_DEVS] = { [0 ... (VIVID_MAX_DEVS - 1)] = 0x1d3d }; 108static unsigned node_types[VIVID_MAX_DEVS] = { [0 ... (VIVID_MAX_DEVS - 1)] = 0x1d3d };
@@ -669,10 +667,7 @@ static int __init vivid_create_instance(int inst)
669 /* start detecting feature set */ 667 /* start detecting feature set */
670 668
671 /* do we use single- or multi-planar? */ 669 /* do we use single- or multi-planar? */
672 if (multiplanar[inst] == 0) 670 dev->multiplanar = multiplanar[inst] > 1;
673 dev->multiplanar = inst & 1;
674 else
675 dev->multiplanar = multiplanar[inst] > 1;
676 v4l2_info(&dev->v4l2_dev, "using %splanar format API\n", 671 v4l2_info(&dev->v4l2_dev, "using %splanar format API\n",
677 dev->multiplanar ? "multi" : "single "); 672 dev->multiplanar ? "multi" : "single ");
678 673
diff --git a/drivers/media/rc/imon.c b/drivers/media/rc/imon.c
index b8837dd39bb2..65f80b8b9f7a 100644
--- a/drivers/media/rc/imon.c
+++ b/drivers/media/rc/imon.c
@@ -1678,7 +1678,8 @@ static void imon_incoming_packet(struct imon_context *ictx,
1678 if (press_type == 0) 1678 if (press_type == 0)
1679 rc_keyup(ictx->rdev); 1679 rc_keyup(ictx->rdev);
1680 else { 1680 else {
1681 if (ictx->rc_type == RC_BIT_RC6_MCE) 1681 if (ictx->rc_type == RC_BIT_RC6_MCE ||
1682 ictx->rc_type == RC_BIT_OTHER)
1682 rc_keydown(ictx->rdev, 1683 rc_keydown(ictx->rdev,
1683 ictx->rc_type == RC_BIT_RC6_MCE ? RC_TYPE_RC6_MCE : RC_TYPE_OTHER, 1684 ictx->rc_type == RC_BIT_RC6_MCE ? RC_TYPE_RC6_MCE : RC_TYPE_OTHER,
1684 ictx->rc_scancode, ictx->rc_toggle); 1685 ictx->rc_scancode, ictx->rc_toggle);
diff --git a/drivers/media/rc/ir-hix5hd2.c b/drivers/media/rc/ir-hix5hd2.c
index 08bbd4f508cd..b0df62961c14 100644
--- a/drivers/media/rc/ir-hix5hd2.c
+++ b/drivers/media/rc/ir-hix5hd2.c
@@ -297,7 +297,7 @@ static int hix5hd2_ir_remove(struct platform_device *pdev)
297 return 0; 297 return 0;
298} 298}
299 299
300#ifdef CONFIG_PM 300#ifdef CONFIG_PM_SLEEP
301static int hix5hd2_ir_suspend(struct device *dev) 301static int hix5hd2_ir_suspend(struct device *dev)
302{ 302{
303 struct hix5hd2_ir_priv *priv = dev_get_drvdata(dev); 303 struct hix5hd2_ir_priv *priv = dev_get_drvdata(dev);
diff --git a/drivers/media/rc/ir-rc5-decoder.c b/drivers/media/rc/ir-rc5-decoder.c
index 2ef763928ca4..84fa6e9b59a1 100644
--- a/drivers/media/rc/ir-rc5-decoder.c
+++ b/drivers/media/rc/ir-rc5-decoder.c
@@ -53,7 +53,7 @@ static int ir_rc5_decode(struct rc_dev *dev, struct ir_raw_event ev)
53 u32 scancode; 53 u32 scancode;
54 enum rc_type protocol; 54 enum rc_type protocol;
55 55
56 if (!(dev->enabled_protocols & (RC_BIT_RC5 | RC_BIT_RC5X))) 56 if (!(dev->enabled_protocols & (RC_BIT_RC5 | RC_BIT_RC5X | RC_BIT_RC5_SZ)))
57 return 0; 57 return 0;
58 58
59 if (!is_timing_event(ev)) { 59 if (!is_timing_event(ev)) {
diff --git a/drivers/media/rc/ir-rc6-decoder.c b/drivers/media/rc/ir-rc6-decoder.c
index f1f098e22f7e..d16bc67af732 100644
--- a/drivers/media/rc/ir-rc6-decoder.c
+++ b/drivers/media/rc/ir-rc6-decoder.c
@@ -259,8 +259,8 @@ again:
259 case 32: 259 case 32:
260 if ((scancode & RC6_6A_LCC_MASK) == RC6_6A_MCE_CC) { 260 if ((scancode & RC6_6A_LCC_MASK) == RC6_6A_MCE_CC) {
261 protocol = RC_TYPE_RC6_MCE; 261 protocol = RC_TYPE_RC6_MCE;
262 scancode &= ~RC6_6A_MCE_TOGGLE_MASK;
263 toggle = !!(scancode & RC6_6A_MCE_TOGGLE_MASK); 262 toggle = !!(scancode & RC6_6A_MCE_TOGGLE_MASK);
263 scancode &= ~RC6_6A_MCE_TOGGLE_MASK;
264 } else { 264 } else {
265 protocol = RC_BIT_RC6_6A_32; 265 protocol = RC_BIT_RC6_6A_32;
266 toggle = 0; 266 toggle = 0;
diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c
index e8fff2add265..b732ac6a26d8 100644
--- a/drivers/media/rc/rc-ir-raw.c
+++ b/drivers/media/rc/rc-ir-raw.c
@@ -262,7 +262,6 @@ int ir_raw_event_register(struct rc_dev *dev)
262 return -ENOMEM; 262 return -ENOMEM;
263 263
264 dev->raw->dev = dev; 264 dev->raw->dev = dev;
265 dev->enabled_protocols = ~0;
266 dev->change_protocol = change_protocol; 265 dev->change_protocol = change_protocol;
267 rc = kfifo_alloc(&dev->raw->kfifo, 266 rc = kfifo_alloc(&dev->raw->kfifo,
268 sizeof(struct ir_raw_event) * MAX_IR_EVENT_SIZE, 267 sizeof(struct ir_raw_event) * MAX_IR_EVENT_SIZE,
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index a7991c7d010a..8d3b74c5a717 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1421,6 +1421,8 @@ int rc_register_device(struct rc_dev *dev)
1421 1421
1422 if (dev->change_protocol) { 1422 if (dev->change_protocol) {
1423 u64 rc_type = (1 << rc_map->rc_type); 1423 u64 rc_type = (1 << rc_map->rc_type);
1424 if (dev->driver_type == RC_DRIVER_IR_RAW)
1425 rc_type |= RC_BIT_LIRC;
1424 rc = dev->change_protocol(dev, &rc_type); 1426 rc = dev->change_protocol(dev, &rc_type);
1425 if (rc < 0) 1427 if (rc < 0)
1426 goto out_raw; 1428 goto out_raw;
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index ccc00099b261..1c0dbf428a3a 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -632,7 +632,7 @@ static void s2255_fillbuff(struct s2255_vc *vc,
632 break; 632 break;
633 case V4L2_PIX_FMT_JPEG: 633 case V4L2_PIX_FMT_JPEG:
634 case V4L2_PIX_FMT_MJPEG: 634 case V4L2_PIX_FMT_MJPEG:
635 buf->vb.v4l2_buf.length = jpgsize; 635 vb2_set_plane_payload(&buf->vb, 0, jpgsize);
636 memcpy(vbuf, tmpbuf, jpgsize); 636 memcpy(vbuf, tmpbuf, jpgsize);
637 break; 637 break;
638 case V4L2_PIX_FMT_YUV422P: 638 case V4L2_PIX_FMT_YUV422P:
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 0707fa2c701b..5bdaae15a742 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -1994,6 +1994,7 @@ static struct scsi_host_template mptsas_driver_template = {
1994 .cmd_per_lun = 7, 1994 .cmd_per_lun = 7,
1995 .use_clustering = ENABLE_CLUSTERING, 1995 .use_clustering = ENABLE_CLUSTERING,
1996 .shost_attrs = mptscsih_host_attrs, 1996 .shost_attrs = mptscsih_host_attrs,
1997 .use_blk_tags = 1,
1997}; 1998};
1998 1999
1999static int mptsas_get_linkerrors(struct sas_phy *phy) 2000static int mptsas_get_linkerrors(struct sas_phy *phy)
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index e7dcb2583369..6c9fc11efb87 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -2311,26 +2311,21 @@ mptscsih_slave_destroy(struct scsi_device *sdev)
2311 * mptscsih_change_queue_depth - This function will set a devices queue depth 2311 * mptscsih_change_queue_depth - This function will set a devices queue depth
2312 * @sdev: per scsi_device pointer 2312 * @sdev: per scsi_device pointer
2313 * @qdepth: requested queue depth 2313 * @qdepth: requested queue depth
2314 * @reason: calling context
2315 * 2314 *
2316 * Adding support for new 'change_queue_depth' api. 2315 * Adding support for new 'change_queue_depth' api.
2317*/ 2316*/
2318int 2317int
2319mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason) 2318mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
2320{ 2319{
2321 MPT_SCSI_HOST *hd = shost_priv(sdev->host); 2320 MPT_SCSI_HOST *hd = shost_priv(sdev->host);
2322 VirtTarget *vtarget; 2321 VirtTarget *vtarget;
2323 struct scsi_target *starget; 2322 struct scsi_target *starget;
2324 int max_depth; 2323 int max_depth;
2325 int tagged;
2326 MPT_ADAPTER *ioc = hd->ioc; 2324 MPT_ADAPTER *ioc = hd->ioc;
2327 2325
2328 starget = scsi_target(sdev); 2326 starget = scsi_target(sdev);
2329 vtarget = starget->hostdata; 2327 vtarget = starget->hostdata;
2330 2328
2331 if (reason != SCSI_QDEPTH_DEFAULT)
2332 return -EOPNOTSUPP;
2333
2334 if (ioc->bus_type == SPI) { 2329 if (ioc->bus_type == SPI) {
2335 if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)) 2330 if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
2336 max_depth = 1; 2331 max_depth = 1;
@@ -2347,13 +2342,8 @@ mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
2347 2342
2348 if (qdepth > max_depth) 2343 if (qdepth > max_depth)
2349 qdepth = max_depth; 2344 qdepth = max_depth;
2350 if (qdepth == 1)
2351 tagged = 0;
2352 else
2353 tagged = MSG_SIMPLE_TAG;
2354 2345
2355 scsi_adjust_queue_depth(sdev, tagged, qdepth); 2346 return scsi_change_queue_depth(sdev, qdepth);
2356 return sdev->queue_depth;
2357} 2347}
2358 2348
2359/* 2349/*
@@ -2397,12 +2387,10 @@ mptscsih_slave_configure(struct scsi_device *sdev)
2397 ioc->name, vtarget->negoFlags, vtarget->maxOffset, 2387 ioc->name, vtarget->negoFlags, vtarget->maxOffset,
2398 vtarget->minSyncFactor)); 2388 vtarget->minSyncFactor));
2399 2389
2400 mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH, 2390 mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH);
2401 SCSI_QDEPTH_DEFAULT);
2402 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT 2391 dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
2403 "tagged %d, simple %d, ordered %d\n", 2392 "tagged %d, simple %d\n",
2404 ioc->name,sdev->tagged_supported, sdev->simple_tags, 2393 ioc->name,sdev->tagged_supported, sdev->simple_tags));
2405 sdev->ordered_tags));
2406 2394
2407 blk_queue_dma_alignment (sdev->request_queue, 512 - 1); 2395 blk_queue_dma_alignment (sdev->request_queue, 512 - 1);
2408 2396
diff --git a/drivers/message/fusion/mptscsih.h b/drivers/message/fusion/mptscsih.h
index e1b1a198a62a..2baeefd9be7a 100644
--- a/drivers/message/fusion/mptscsih.h
+++ b/drivers/message/fusion/mptscsih.h
@@ -128,8 +128,7 @@ extern int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_F
128extern int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 128extern int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
129extern int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply); 129extern int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
130extern int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset); 130extern int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
131extern int mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth, 131extern int mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth);
132 int reason);
133extern u8 mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id); 132extern u8 mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id);
134extern int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id); 133extern int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id);
135extern struct device_attribute *mptscsih_host_attrs[]; 134extern struct device_attribute *mptscsih_host_attrs[];
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 1456ea70bbc7..2e6b7311fabc 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -59,6 +59,17 @@ config MFD_AAT2870_CORE
59 additional drivers must be enabled in order to use the 59 additional drivers must be enabled in order to use the
60 functionality of the device. 60 functionality of the device.
61 61
62config MFD_ATMEL_HLCDC
63 tristate "Atmel HLCDC (High-end LCD Controller)"
64 select MFD_CORE
65 select REGMAP_MMIO
66 depends on OF
67 help
68 If you say yes here you get support for the HLCDC block.
69 This driver provides common support for accessing the device,
70 additional drivers must be enabled in order to use the
71 functionality of the device.
72
62config MFD_BCM590XX 73config MFD_BCM590XX
63 tristate "Broadcom BCM590xx PMUs" 74 tristate "Broadcom BCM590xx PMUs"
64 select MFD_CORE 75 select MFD_CORE
@@ -74,7 +85,8 @@ config MFD_AXP20X
74 select REGMAP_IRQ 85 select REGMAP_IRQ
75 depends on I2C=y 86 depends on I2C=y
76 help 87 help
77 If you say Y here you get support for the X-Powers AXP202 and AXP209. 88 If you say Y here you get support for the X-Powers AXP202, AXP209 and
89 AXP288 power management IC (PMIC).
78 This driver include only the core APIs. You have to select individual 90 This driver include only the core APIs. You have to select individual
79 components like regulators or the PEK (Power Enable Key) under the 91 components like regulators or the PEK (Power Enable Key) under the
80 corresponding menus. 92 corresponding menus.
@@ -183,6 +195,16 @@ config MFD_DA9063
183 Additional drivers must be enabled in order to use the functionality 195 Additional drivers must be enabled in order to use the functionality
184 of the device. 196 of the device.
185 197
198config MFD_DLN2
199 tristate "Diolan DLN2 support"
200 select MFD_CORE
201 depends on USB
202 help
203 This adds support for Diolan USB-I2C/SPI/GPIO Master Adapter
204 DLN-2. Additional drivers such as I2C_DLN2, GPIO_DLN2,
205 etc. must be enabled in order to use the functionality of
206 the device.
207
186config MFD_MC13XXX 208config MFD_MC13XXX
187 tristate 209 tristate
188 depends on (SPI_MASTER || I2C) 210 depends on (SPI_MASTER || I2C)
@@ -655,7 +677,6 @@ config MFD_SEC_CORE
655 select MFD_CORE 677 select MFD_CORE
656 select REGMAP_I2C 678 select REGMAP_I2C
657 select REGMAP_IRQ 679 select REGMAP_IRQ
658 select REGULATOR
659 help 680 help
660 Support for the Samsung Electronics MFD series. 681 Support for the Samsung Electronics MFD series.
661 This driver provides common support for accessing the device, 682 This driver provides common support for accessing the device,
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 8bd54b1253af..53467e211381 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -13,7 +13,7 @@ obj-$(CONFIG_MFD_CROS_EC) += cros_ec.o
13obj-$(CONFIG_MFD_CROS_EC_I2C) += cros_ec_i2c.o 13obj-$(CONFIG_MFD_CROS_EC_I2C) += cros_ec_i2c.o
14obj-$(CONFIG_MFD_CROS_EC_SPI) += cros_ec_spi.o 14obj-$(CONFIG_MFD_CROS_EC_SPI) += cros_ec_spi.o
15 15
16rtsx_pci-objs := rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o 16rtsx_pci-objs := rtsx_pcr.o rtsx_gops.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o
17obj-$(CONFIG_MFD_RTSX_PCI) += rtsx_pci.o 17obj-$(CONFIG_MFD_RTSX_PCI) += rtsx_pci.o
18obj-$(CONFIG_MFD_RTSX_USB) += rtsx_usb.o 18obj-$(CONFIG_MFD_RTSX_USB) += rtsx_usb.o
19 19
@@ -157,6 +157,7 @@ obj-$(CONFIG_MFD_SPMI_PMIC) += qcom-spmi-pmic.o
157obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o 157obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o
158obj-$(CONFIG_MFD_TPS65090) += tps65090.o 158obj-$(CONFIG_MFD_TPS65090) += tps65090.o
159obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o 159obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o
160obj-$(CONFIG_MFD_ATMEL_HLCDC) += atmel-hlcdc.o
160obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o 161obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o
161obj-$(CONFIG_MFD_PALMAS) += palmas.o 162obj-$(CONFIG_MFD_PALMAS) += palmas.o
162obj-$(CONFIG_MFD_VIPERBOARD) += viperboard.o 163obj-$(CONFIG_MFD_VIPERBOARD) += viperboard.o
@@ -174,6 +175,7 @@ obj-$(CONFIG_MFD_STW481X) += stw481x.o
174obj-$(CONFIG_MFD_IPAQ_MICRO) += ipaq-micro.o 175obj-$(CONFIG_MFD_IPAQ_MICRO) += ipaq-micro.o
175obj-$(CONFIG_MFD_MENF21BMC) += menf21bmc.o 176obj-$(CONFIG_MFD_MENF21BMC) += menf21bmc.o
176obj-$(CONFIG_MFD_HI6421_PMIC) += hi6421-pmic-core.o 177obj-$(CONFIG_MFD_HI6421_PMIC) += hi6421-pmic-core.o
178obj-$(CONFIG_MFD_DLN2) += dln2.o
177 179
178intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o 180intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o
179obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o 181obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o
diff --git a/drivers/mfd/ab8500-sysctrl.c b/drivers/mfd/ab8500-sysctrl.c
index 8e0dae59844d..94dbcdd2a1ff 100644
--- a/drivers/mfd/ab8500-sysctrl.c
+++ b/drivers/mfd/ab8500-sysctrl.c
@@ -85,63 +85,6 @@ shutdown:
85 } 85 }
86} 86}
87 87
88/*
89 * Use the AB WD to reset the platform. It will perform a hard
90 * reset instead of a soft reset. Write the reset reason to
91 * the AB before reset, which can be read upon restart.
92 */
93void ab8500_restart(char mode, const char *cmd)
94{
95 struct ab8500_platform_data *plat;
96 struct ab8500_sysctrl_platform_data *pdata;
97 u16 reason = 0;
98 u8 val;
99
100 if (sysctrl_dev == NULL) {
101 pr_err("%s: sysctrl not initialized\n", __func__);
102 return;
103 }
104
105 plat = dev_get_platdata(sysctrl_dev->parent);
106 pdata = plat->sysctrl;
107 if (pdata && pdata->reboot_reason_code)
108 reason = pdata->reboot_reason_code(cmd);
109 else
110 pr_warn("[%s] No reboot reason set. Default reason %d\n",
111 __func__, reason);
112
113 /*
114 * Disable RTC alarm, just a precaution so that no alarm
115 * is running when WD reset is executed.
116 */
117 abx500_get_register_interruptible(sysctrl_dev, AB8500_RTC,
118 RTC_CTRL , &val);
119 abx500_set_register_interruptible(sysctrl_dev, AB8500_RTC,
120 RTC_CTRL , (val & ~RTC_ALARM_ENABLE));
121
122 /*
123 * Android is not using the RTC alarm registers during reboot
124 * so we borrow them for writing the reason of reset
125 */
126
127 /* reason[8 LSB] */
128 val = reason & 0xFF;
129 abx500_set_register_interruptible(sysctrl_dev, AB8500_RTC,
130 AB8500_ALARM_MIN_LOW , val);
131
132 /* reason[8 MSB] */
133 val = (reason>>8) & 0xFF;
134 abx500_set_register_interruptible(sysctrl_dev, AB8500_RTC,
135 AB8500_ALARM_MIN_MID , val);
136
137 /* Setting WD timeout to 0 */
138 ab8500_sysctrl_write(AB8500_MAINWDOGTIMER, 0xFF, 0x0);
139
140 /* Setting the parameters to AB8500 WD*/
141 ab8500_sysctrl_write(AB8500_MAINWDOGCTRL, 0xFF, (AB8500_ENABLE_WD |
142 AB8500_WD_RESTART_ON_EXPIRE | AB8500_KICK_WD));
143}
144
145static inline bool valid_bank(u8 bank) 88static inline bool valid_bank(u8 bank)
146{ 89{
147 return ((bank == AB8500_SYS_CTRL1_BLOCK) || 90 return ((bank == AB8500_SYS_CTRL1_BLOCK) ||
diff --git a/drivers/mfd/arizona-spi.c b/drivers/mfd/arizona-spi.c
index 5145d78bf07e..8ef58bcff193 100644
--- a/drivers/mfd/arizona-spi.c
+++ b/drivers/mfd/arizona-spi.c
@@ -75,7 +75,9 @@ static int arizona_spi_probe(struct spi_device *spi)
75static int arizona_spi_remove(struct spi_device *spi) 75static int arizona_spi_remove(struct spi_device *spi)
76{ 76{
77 struct arizona *arizona = spi_get_drvdata(spi); 77 struct arizona *arizona = spi_get_drvdata(spi);
78
78 arizona_dev_exit(arizona); 79 arizona_dev_exit(arizona);
80
79 return 0; 81 return 0;
80} 82}
81 83
diff --git a/drivers/mfd/atmel-hlcdc.c b/drivers/mfd/atmel-hlcdc.c
new file mode 100644
index 000000000000..cfd58f4cc5c3
--- /dev/null
+++ b/drivers/mfd/atmel-hlcdc.c
@@ -0,0 +1,122 @@
1/*
2 * Copyright (C) 2014 Free Electrons
3 * Copyright (C) 2014 Atmel
4 *
5 * Author: Boris BREZILLON <boris.brezillon@free-electrons.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 version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <linux/clk.h>
21#include <linux/mfd/atmel-hlcdc.h>
22#include <linux/mfd/core.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
25#include <linux/regmap.h>
26
27#define ATMEL_HLCDC_REG_MAX (0x4000 - 0x4)
28
29static const struct mfd_cell atmel_hlcdc_cells[] = {
30 {
31 .name = "atmel-hlcdc-pwm",
32 .of_compatible = "atmel,hlcdc-pwm",
33 },
34 {
35 .name = "atmel-hlcdc-dc",
36 .of_compatible = "atmel,hlcdc-display-controller",
37 },
38};
39
40static const struct regmap_config atmel_hlcdc_regmap_config = {
41 .reg_bits = 32,
42 .val_bits = 32,
43 .reg_stride = 4,
44 .max_register = ATMEL_HLCDC_REG_MAX,
45};
46
47static int atmel_hlcdc_probe(struct platform_device *pdev)
48{
49 struct device *dev = &pdev->dev;
50 struct atmel_hlcdc *hlcdc;
51 struct resource *res;
52 void __iomem *regs;
53
54 hlcdc = devm_kzalloc(dev, sizeof(*hlcdc), GFP_KERNEL);
55 if (!hlcdc)
56 return -ENOMEM;
57
58 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
59 regs = devm_ioremap_resource(dev, res);
60 if (IS_ERR(regs))
61 return PTR_ERR(regs);
62
63 hlcdc->irq = platform_get_irq(pdev, 0);
64 if (hlcdc->irq < 0)
65 return hlcdc->irq;
66
67 hlcdc->periph_clk = devm_clk_get(dev, "periph_clk");
68 if (IS_ERR(hlcdc->periph_clk)) {
69 dev_err(dev, "failed to get peripheral clock\n");
70 return PTR_ERR(hlcdc->periph_clk);
71 }
72
73 hlcdc->sys_clk = devm_clk_get(dev, "sys_clk");
74 if (IS_ERR(hlcdc->sys_clk)) {
75 dev_err(dev, "failed to get system clock\n");
76 return PTR_ERR(hlcdc->sys_clk);
77 }
78
79 hlcdc->slow_clk = devm_clk_get(dev, "slow_clk");
80 if (IS_ERR(hlcdc->slow_clk)) {
81 dev_err(dev, "failed to get slow clock\n");
82 return PTR_ERR(hlcdc->slow_clk);
83 }
84
85 hlcdc->regmap = devm_regmap_init_mmio(dev, regs,
86 &atmel_hlcdc_regmap_config);
87 if (IS_ERR(hlcdc->regmap))
88 return PTR_ERR(hlcdc->regmap);
89
90 dev_set_drvdata(dev, hlcdc);
91
92 return mfd_add_devices(dev, -1, atmel_hlcdc_cells,
93 ARRAY_SIZE(atmel_hlcdc_cells),
94 NULL, 0, NULL);
95}
96
97static int atmel_hlcdc_remove(struct platform_device *pdev)
98{
99 mfd_remove_devices(&pdev->dev);
100
101 return 0;
102}
103
104static const struct of_device_id atmel_hlcdc_match[] = {
105 { .compatible = "atmel,sama5d3-hlcdc" },
106 { /* sentinel */ },
107};
108
109static struct platform_driver atmel_hlcdc_driver = {
110 .probe = atmel_hlcdc_probe,
111 .remove = atmel_hlcdc_remove,
112 .driver = {
113 .name = "atmel-hlcdc",
114 .of_match_table = atmel_hlcdc_match,
115 },
116};
117module_platform_driver(atmel_hlcdc_driver);
118
119MODULE_ALIAS("platform:atmel-hlcdc");
120MODULE_AUTHOR("Boris Brezillon <boris.brezillon@free-electrons.com>");
121MODULE_DESCRIPTION("Atmel HLCDC driver");
122MODULE_LICENSE("GPL v2");
diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c
index 6231adbb295d..c522ee22b1c0 100644
--- a/drivers/mfd/axp20x.c
+++ b/drivers/mfd/axp20x.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * axp20x.c - MFD core driver for the X-Powers AXP202 and AXP209 2 * axp20x.c - MFD core driver for the X-Powers' Power Management ICs
3 * 3 *
4 * AXP20x comprises an adaptive USB-Compatible PWM charger, 2 BUCK DC-DC 4 * AXP20x typically comprises an adaptive USB-Compatible PWM charger, BUCK DC-DC
5 * converters, 5 LDOs, multiple 12-bit ADCs of voltage, current and temperature 5 * converters, LDOs, multiple 12-bit ADCs of voltage, current and temperature
6 * as well as 4 configurable GPIOs. 6 * as well as configurable GPIOs.
7 * 7 *
8 * Author: Carlo Caione <carlo@caione.org> 8 * Author: Carlo Caione <carlo@caione.org>
9 * 9 *
@@ -25,9 +25,16 @@
25#include <linux/mfd/core.h> 25#include <linux/mfd/core.h>
26#include <linux/of_device.h> 26#include <linux/of_device.h>
27#include <linux/of_irq.h> 27#include <linux/of_irq.h>
28#include <linux/acpi.h>
28 29
29#define AXP20X_OFF 0x80 30#define AXP20X_OFF 0x80
30 31
32static const char const *axp20x_model_names[] = {
33 "AXP202",
34 "AXP209",
35 "AXP288",
36};
37
31static const struct regmap_range axp20x_writeable_ranges[] = { 38static const struct regmap_range axp20x_writeable_ranges[] = {
32 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE), 39 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE),
33 regmap_reg_range(AXP20X_DCDC_MODE, AXP20X_FG_RES), 40 regmap_reg_range(AXP20X_DCDC_MODE, AXP20X_FG_RES),
@@ -47,6 +54,25 @@ static const struct regmap_access_table axp20x_volatile_table = {
47 .n_yes_ranges = ARRAY_SIZE(axp20x_volatile_ranges), 54 .n_yes_ranges = ARRAY_SIZE(axp20x_volatile_ranges),
48}; 55};
49 56
57static const struct regmap_range axp288_writeable_ranges[] = {
58 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ6_STATE),
59 regmap_reg_range(AXP20X_DCDC_MODE, AXP288_FG_TUNE5),
60};
61
62static const struct regmap_range axp288_volatile_ranges[] = {
63 regmap_reg_range(AXP20X_IRQ1_EN, AXP20X_IPSOUT_V_HIGH_L),
64};
65
66static const struct regmap_access_table axp288_writeable_table = {
67 .yes_ranges = axp288_writeable_ranges,
68 .n_yes_ranges = ARRAY_SIZE(axp288_writeable_ranges),
69};
70
71static const struct regmap_access_table axp288_volatile_table = {
72 .yes_ranges = axp288_volatile_ranges,
73 .n_yes_ranges = ARRAY_SIZE(axp288_volatile_ranges),
74};
75
50static struct resource axp20x_pek_resources[] = { 76static struct resource axp20x_pek_resources[] = {
51 { 77 {
52 .name = "PEK_DBR", 78 .name = "PEK_DBR",
@@ -61,6 +87,39 @@ static struct resource axp20x_pek_resources[] = {
61 }, 87 },
62}; 88};
63 89
90static struct resource axp288_battery_resources[] = {
91 {
92 .start = AXP288_IRQ_QWBTU,
93 .end = AXP288_IRQ_QWBTU,
94 .flags = IORESOURCE_IRQ,
95 },
96 {
97 .start = AXP288_IRQ_WBTU,
98 .end = AXP288_IRQ_WBTU,
99 .flags = IORESOURCE_IRQ,
100 },
101 {
102 .start = AXP288_IRQ_QWBTO,
103 .end = AXP288_IRQ_QWBTO,
104 .flags = IORESOURCE_IRQ,
105 },
106 {
107 .start = AXP288_IRQ_WBTO,
108 .end = AXP288_IRQ_WBTO,
109 .flags = IORESOURCE_IRQ,
110 },
111 {
112 .start = AXP288_IRQ_WL2,
113 .end = AXP288_IRQ_WL2,
114 .flags = IORESOURCE_IRQ,
115 },
116 {
117 .start = AXP288_IRQ_WL1,
118 .end = AXP288_IRQ_WL1,
119 .flags = IORESOURCE_IRQ,
120 },
121};
122
64static const struct regmap_config axp20x_regmap_config = { 123static const struct regmap_config axp20x_regmap_config = {
65 .reg_bits = 8, 124 .reg_bits = 8,
66 .val_bits = 8, 125 .val_bits = 8,
@@ -70,47 +129,96 @@ static const struct regmap_config axp20x_regmap_config = {
70 .cache_type = REGCACHE_RBTREE, 129 .cache_type = REGCACHE_RBTREE,
71}; 130};
72 131
73#define AXP20X_IRQ(_irq, _off, _mask) \ 132static const struct regmap_config axp288_regmap_config = {
74 [AXP20X_IRQ_##_irq] = { .reg_offset = (_off), .mask = BIT(_mask) } 133 .reg_bits = 8,
134 .val_bits = 8,
135 .wr_table = &axp288_writeable_table,
136 .volatile_table = &axp288_volatile_table,
137 .max_register = AXP288_FG_TUNE5,
138 .cache_type = REGCACHE_RBTREE,
139};
140
141#define INIT_REGMAP_IRQ(_variant, _irq, _off, _mask) \
142 [_variant##_IRQ_##_irq] = { .reg_offset = (_off), .mask = BIT(_mask) }
75 143
76static const struct regmap_irq axp20x_regmap_irqs[] = { 144static const struct regmap_irq axp20x_regmap_irqs[] = {
77 AXP20X_IRQ(ACIN_OVER_V, 0, 7), 145 INIT_REGMAP_IRQ(AXP20X, ACIN_OVER_V, 0, 7),
78 AXP20X_IRQ(ACIN_PLUGIN, 0, 6), 146 INIT_REGMAP_IRQ(AXP20X, ACIN_PLUGIN, 0, 6),
79 AXP20X_IRQ(ACIN_REMOVAL, 0, 5), 147 INIT_REGMAP_IRQ(AXP20X, ACIN_REMOVAL, 0, 5),
80 AXP20X_IRQ(VBUS_OVER_V, 0, 4), 148 INIT_REGMAP_IRQ(AXP20X, VBUS_OVER_V, 0, 4),
81 AXP20X_IRQ(VBUS_PLUGIN, 0, 3), 149 INIT_REGMAP_IRQ(AXP20X, VBUS_PLUGIN, 0, 3),
82 AXP20X_IRQ(VBUS_REMOVAL, 0, 2), 150 INIT_REGMAP_IRQ(AXP20X, VBUS_REMOVAL, 0, 2),
83 AXP20X_IRQ(VBUS_V_LOW, 0, 1), 151 INIT_REGMAP_IRQ(AXP20X, VBUS_V_LOW, 0, 1),
84 AXP20X_IRQ(BATT_PLUGIN, 1, 7), 152 INIT_REGMAP_IRQ(AXP20X, BATT_PLUGIN, 1, 7),
85 AXP20X_IRQ(BATT_REMOVAL, 1, 6), 153 INIT_REGMAP_IRQ(AXP20X, BATT_REMOVAL, 1, 6),
86 AXP20X_IRQ(BATT_ENT_ACT_MODE, 1, 5), 154 INIT_REGMAP_IRQ(AXP20X, BATT_ENT_ACT_MODE, 1, 5),
87 AXP20X_IRQ(BATT_EXIT_ACT_MODE, 1, 4), 155 INIT_REGMAP_IRQ(AXP20X, BATT_EXIT_ACT_MODE, 1, 4),
88 AXP20X_IRQ(CHARG, 1, 3), 156 INIT_REGMAP_IRQ(AXP20X, CHARG, 1, 3),
89 AXP20X_IRQ(CHARG_DONE, 1, 2), 157 INIT_REGMAP_IRQ(AXP20X, CHARG_DONE, 1, 2),
90 AXP20X_IRQ(BATT_TEMP_HIGH, 1, 1), 158 INIT_REGMAP_IRQ(AXP20X, BATT_TEMP_HIGH, 1, 1),
91 AXP20X_IRQ(BATT_TEMP_LOW, 1, 0), 159 INIT_REGMAP_IRQ(AXP20X, BATT_TEMP_LOW, 1, 0),
92 AXP20X_IRQ(DIE_TEMP_HIGH, 2, 7), 160 INIT_REGMAP_IRQ(AXP20X, DIE_TEMP_HIGH, 2, 7),
93 AXP20X_IRQ(CHARG_I_LOW, 2, 6), 161 INIT_REGMAP_IRQ(AXP20X, CHARG_I_LOW, 2, 6),
94 AXP20X_IRQ(DCDC1_V_LONG, 2, 5), 162 INIT_REGMAP_IRQ(AXP20X, DCDC1_V_LONG, 2, 5),
95 AXP20X_IRQ(DCDC2_V_LONG, 2, 4), 163 INIT_REGMAP_IRQ(AXP20X, DCDC2_V_LONG, 2, 4),
96 AXP20X_IRQ(DCDC3_V_LONG, 2, 3), 164 INIT_REGMAP_IRQ(AXP20X, DCDC3_V_LONG, 2, 3),
97 AXP20X_IRQ(PEK_SHORT, 2, 1), 165 INIT_REGMAP_IRQ(AXP20X, PEK_SHORT, 2, 1),
98 AXP20X_IRQ(PEK_LONG, 2, 0), 166 INIT_REGMAP_IRQ(AXP20X, PEK_LONG, 2, 0),
99 AXP20X_IRQ(N_OE_PWR_ON, 3, 7), 167 INIT_REGMAP_IRQ(AXP20X, N_OE_PWR_ON, 3, 7),
100 AXP20X_IRQ(N_OE_PWR_OFF, 3, 6), 168 INIT_REGMAP_IRQ(AXP20X, N_OE_PWR_OFF, 3, 6),
101 AXP20X_IRQ(VBUS_VALID, 3, 5), 169 INIT_REGMAP_IRQ(AXP20X, VBUS_VALID, 3, 5),
102 AXP20X_IRQ(VBUS_NOT_VALID, 3, 4), 170 INIT_REGMAP_IRQ(AXP20X, VBUS_NOT_VALID, 3, 4),
103 AXP20X_IRQ(VBUS_SESS_VALID, 3, 3), 171 INIT_REGMAP_IRQ(AXP20X, VBUS_SESS_VALID, 3, 3),
104 AXP20X_IRQ(VBUS_SESS_END, 3, 2), 172 INIT_REGMAP_IRQ(AXP20X, VBUS_SESS_END, 3, 2),
105 AXP20X_IRQ(LOW_PWR_LVL1, 3, 1), 173 INIT_REGMAP_IRQ(AXP20X, LOW_PWR_LVL1, 3, 1),
106 AXP20X_IRQ(LOW_PWR_LVL2, 3, 0), 174 INIT_REGMAP_IRQ(AXP20X, LOW_PWR_LVL2, 3, 0),
107 AXP20X_IRQ(TIMER, 4, 7), 175 INIT_REGMAP_IRQ(AXP20X, TIMER, 4, 7),
108 AXP20X_IRQ(PEK_RIS_EDGE, 4, 6), 176 INIT_REGMAP_IRQ(AXP20X, PEK_RIS_EDGE, 4, 6),
109 AXP20X_IRQ(PEK_FAL_EDGE, 4, 5), 177 INIT_REGMAP_IRQ(AXP20X, PEK_FAL_EDGE, 4, 5),
110 AXP20X_IRQ(GPIO3_INPUT, 4, 3), 178 INIT_REGMAP_IRQ(AXP20X, GPIO3_INPUT, 4, 3),
111 AXP20X_IRQ(GPIO2_INPUT, 4, 2), 179 INIT_REGMAP_IRQ(AXP20X, GPIO2_INPUT, 4, 2),
112 AXP20X_IRQ(GPIO1_INPUT, 4, 1), 180 INIT_REGMAP_IRQ(AXP20X, GPIO1_INPUT, 4, 1),
113 AXP20X_IRQ(GPIO0_INPUT, 4, 0), 181 INIT_REGMAP_IRQ(AXP20X, GPIO0_INPUT, 4, 0),
182};
183
184/* some IRQs are compatible with axp20x models */
185static const struct regmap_irq axp288_regmap_irqs[] = {
186 INIT_REGMAP_IRQ(AXP288, VBUS_FALL, 0, 2),
187 INIT_REGMAP_IRQ(AXP288, VBUS_RISE, 0, 3),
188 INIT_REGMAP_IRQ(AXP288, OV, 0, 4),
189
190 INIT_REGMAP_IRQ(AXP288, DONE, 1, 2),
191 INIT_REGMAP_IRQ(AXP288, CHARGING, 1, 3),
192 INIT_REGMAP_IRQ(AXP288, SAFE_QUIT, 1, 4),
193 INIT_REGMAP_IRQ(AXP288, SAFE_ENTER, 1, 5),
194 INIT_REGMAP_IRQ(AXP288, ABSENT, 1, 6),
195 INIT_REGMAP_IRQ(AXP288, APPEND, 1, 7),
196
197 INIT_REGMAP_IRQ(AXP288, QWBTU, 2, 0),
198 INIT_REGMAP_IRQ(AXP288, WBTU, 2, 1),
199 INIT_REGMAP_IRQ(AXP288, QWBTO, 2, 2),
200 INIT_REGMAP_IRQ(AXP288, WBTO, 2, 3),
201 INIT_REGMAP_IRQ(AXP288, QCBTU, 2, 4),
202 INIT_REGMAP_IRQ(AXP288, CBTU, 2, 5),
203 INIT_REGMAP_IRQ(AXP288, QCBTO, 2, 6),
204 INIT_REGMAP_IRQ(AXP288, CBTO, 2, 7),
205
206 INIT_REGMAP_IRQ(AXP288, WL2, 3, 0),
207 INIT_REGMAP_IRQ(AXP288, WL1, 3, 1),
208 INIT_REGMAP_IRQ(AXP288, GPADC, 3, 2),
209 INIT_REGMAP_IRQ(AXP288, OT, 3, 7),
210
211 INIT_REGMAP_IRQ(AXP288, GPIO0, 4, 0),
212 INIT_REGMAP_IRQ(AXP288, GPIO1, 4, 1),
213 INIT_REGMAP_IRQ(AXP288, POKO, 4, 2),
214 INIT_REGMAP_IRQ(AXP288, POKL, 4, 3),
215 INIT_REGMAP_IRQ(AXP288, POKS, 4, 4),
216 INIT_REGMAP_IRQ(AXP288, POKN, 4, 5),
217 INIT_REGMAP_IRQ(AXP288, POKP, 4, 6),
218 INIT_REGMAP_IRQ(AXP288, TIMER, 4, 7),
219
220 INIT_REGMAP_IRQ(AXP288, MV_CHNG, 5, 0),
221 INIT_REGMAP_IRQ(AXP288, BC_USB_CHNG, 5, 1),
114}; 222};
115 223
116static const struct of_device_id axp20x_of_match[] = { 224static const struct of_device_id axp20x_of_match[] = {
@@ -128,16 +236,39 @@ static const struct i2c_device_id axp20x_i2c_id[] = {
128}; 236};
129MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id); 237MODULE_DEVICE_TABLE(i2c, axp20x_i2c_id);
130 238
239static const struct acpi_device_id axp20x_acpi_match[] = {
240 {
241 .id = "INT33F4",
242 .driver_data = AXP288_ID,
243 },
244 { },
245};
246MODULE_DEVICE_TABLE(acpi, axp20x_acpi_match);
247
131static const struct regmap_irq_chip axp20x_regmap_irq_chip = { 248static const struct regmap_irq_chip axp20x_regmap_irq_chip = {
132 .name = "axp20x_irq_chip", 249 .name = "axp20x_irq_chip",
133 .status_base = AXP20X_IRQ1_STATE, 250 .status_base = AXP20X_IRQ1_STATE,
134 .ack_base = AXP20X_IRQ1_STATE, 251 .ack_base = AXP20X_IRQ1_STATE,
135 .mask_base = AXP20X_IRQ1_EN, 252 .mask_base = AXP20X_IRQ1_EN,
136 .num_regs = 5, 253 .mask_invert = true,
254 .init_ack_masked = true,
137 .irqs = axp20x_regmap_irqs, 255 .irqs = axp20x_regmap_irqs,
138 .num_irqs = ARRAY_SIZE(axp20x_regmap_irqs), 256 .num_irqs = ARRAY_SIZE(axp20x_regmap_irqs),
257 .num_regs = 5,
258
259};
260
261static const struct regmap_irq_chip axp288_regmap_irq_chip = {
262 .name = "axp288_irq_chip",
263 .status_base = AXP20X_IRQ1_STATE,
264 .ack_base = AXP20X_IRQ1_STATE,
265 .mask_base = AXP20X_IRQ1_EN,
139 .mask_invert = true, 266 .mask_invert = true,
140 .init_ack_masked = true, 267 .init_ack_masked = true,
268 .irqs = axp288_regmap_irqs,
269 .num_irqs = ARRAY_SIZE(axp288_regmap_irqs),
270 .num_regs = 6,
271
141}; 272};
142 273
143static struct mfd_cell axp20x_cells[] = { 274static struct mfd_cell axp20x_cells[] = {
@@ -150,36 +281,155 @@ static struct mfd_cell axp20x_cells[] = {
150 }, 281 },
151}; 282};
152 283
284static struct resource axp288_adc_resources[] = {
285 {
286 .name = "GPADC",
287 .start = AXP288_IRQ_GPADC,
288 .end = AXP288_IRQ_GPADC,
289 .flags = IORESOURCE_IRQ,
290 },
291};
292
293static struct resource axp288_charger_resources[] = {
294 {
295 .start = AXP288_IRQ_OV,
296 .end = AXP288_IRQ_OV,
297 .flags = IORESOURCE_IRQ,
298 },
299 {
300 .start = AXP288_IRQ_DONE,
301 .end = AXP288_IRQ_DONE,
302 .flags = IORESOURCE_IRQ,
303 },
304 {
305 .start = AXP288_IRQ_CHARGING,
306 .end = AXP288_IRQ_CHARGING,
307 .flags = IORESOURCE_IRQ,
308 },
309 {
310 .start = AXP288_IRQ_SAFE_QUIT,
311 .end = AXP288_IRQ_SAFE_QUIT,
312 .flags = IORESOURCE_IRQ,
313 },
314 {
315 .start = AXP288_IRQ_SAFE_ENTER,
316 .end = AXP288_IRQ_SAFE_ENTER,
317 .flags = IORESOURCE_IRQ,
318 },
319 {
320 .start = AXP288_IRQ_QCBTU,
321 .end = AXP288_IRQ_QCBTU,
322 .flags = IORESOURCE_IRQ,
323 },
324 {
325 .start = AXP288_IRQ_CBTU,
326 .end = AXP288_IRQ_CBTU,
327 .flags = IORESOURCE_IRQ,
328 },
329 {
330 .start = AXP288_IRQ_QCBTO,
331 .end = AXP288_IRQ_QCBTO,
332 .flags = IORESOURCE_IRQ,
333 },
334 {
335 .start = AXP288_IRQ_CBTO,
336 .end = AXP288_IRQ_CBTO,
337 .flags = IORESOURCE_IRQ,
338 },
339};
340
341static struct mfd_cell axp288_cells[] = {
342 {
343 .name = "axp288_adc",
344 .num_resources = ARRAY_SIZE(axp288_adc_resources),
345 .resources = axp288_adc_resources,
346 },
347 {
348 .name = "axp288_charger",
349 .num_resources = ARRAY_SIZE(axp288_charger_resources),
350 .resources = axp288_charger_resources,
351 },
352 {
353 .name = "axp288_battery",
354 .num_resources = ARRAY_SIZE(axp288_battery_resources),
355 .resources = axp288_battery_resources,
356 },
357};
358
153static struct axp20x_dev *axp20x_pm_power_off; 359static struct axp20x_dev *axp20x_pm_power_off;
154static void axp20x_power_off(void) 360static void axp20x_power_off(void)
155{ 361{
362 if (axp20x_pm_power_off->variant == AXP288_ID)
363 return;
364
156 regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL, 365 regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL,
157 AXP20X_OFF); 366 AXP20X_OFF);
158} 367}
159 368
369static int axp20x_match_device(struct axp20x_dev *axp20x, struct device *dev)
370{
371 const struct acpi_device_id *acpi_id;
372 const struct of_device_id *of_id;
373
374 if (dev->of_node) {
375 of_id = of_match_device(axp20x_of_match, dev);
376 if (!of_id) {
377 dev_err(dev, "Unable to match OF ID\n");
378 return -ENODEV;
379 }
380 axp20x->variant = (long) of_id->data;
381 } else {
382 acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
383 if (!acpi_id || !acpi_id->driver_data) {
384 dev_err(dev, "Unable to match ACPI ID and data\n");
385 return -ENODEV;
386 }
387 axp20x->variant = (long) acpi_id->driver_data;
388 }
389
390 switch (axp20x->variant) {
391 case AXP202_ID:
392 case AXP209_ID:
393 axp20x->nr_cells = ARRAY_SIZE(axp20x_cells);
394 axp20x->cells = axp20x_cells;
395 axp20x->regmap_cfg = &axp20x_regmap_config;
396 axp20x->regmap_irq_chip = &axp20x_regmap_irq_chip;
397 break;
398 case AXP288_ID:
399 axp20x->cells = axp288_cells;
400 axp20x->nr_cells = ARRAY_SIZE(axp288_cells);
401 axp20x->regmap_cfg = &axp288_regmap_config;
402 axp20x->regmap_irq_chip = &axp288_regmap_irq_chip;
403 break;
404 default:
405 dev_err(dev, "unsupported AXP20X ID %lu\n", axp20x->variant);
406 return -EINVAL;
407 }
408 dev_info(dev, "AXP20x variant %s found\n",
409 axp20x_model_names[axp20x->variant]);
410
411 return 0;
412}
413
160static int axp20x_i2c_probe(struct i2c_client *i2c, 414static int axp20x_i2c_probe(struct i2c_client *i2c,
161 const struct i2c_device_id *id) 415 const struct i2c_device_id *id)
162{ 416{
163 struct axp20x_dev *axp20x; 417 struct axp20x_dev *axp20x;
164 const struct of_device_id *of_id;
165 int ret; 418 int ret;
166 419
167 axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL); 420 axp20x = devm_kzalloc(&i2c->dev, sizeof(*axp20x), GFP_KERNEL);
168 if (!axp20x) 421 if (!axp20x)
169 return -ENOMEM; 422 return -ENOMEM;
170 423
171 of_id = of_match_device(axp20x_of_match, &i2c->dev); 424 ret = axp20x_match_device(axp20x, &i2c->dev);
172 if (!of_id) { 425 if (ret)
173 dev_err(&i2c->dev, "Unable to setup AXP20X data\n"); 426 return ret;
174 return -ENODEV;
175 }
176 axp20x->variant = (long) of_id->data;
177 427
178 axp20x->i2c_client = i2c; 428 axp20x->i2c_client = i2c;
179 axp20x->dev = &i2c->dev; 429 axp20x->dev = &i2c->dev;
180 dev_set_drvdata(axp20x->dev, axp20x); 430 dev_set_drvdata(axp20x->dev, axp20x);
181 431
182 axp20x->regmap = devm_regmap_init_i2c(i2c, &axp20x_regmap_config); 432 axp20x->regmap = devm_regmap_init_i2c(i2c, axp20x->regmap_cfg);
183 if (IS_ERR(axp20x->regmap)) { 433 if (IS_ERR(axp20x->regmap)) {
184 ret = PTR_ERR(axp20x->regmap); 434 ret = PTR_ERR(axp20x->regmap);
185 dev_err(&i2c->dev, "regmap init failed: %d\n", ret); 435 dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
@@ -188,15 +438,15 @@ static int axp20x_i2c_probe(struct i2c_client *i2c,
188 438
189 ret = regmap_add_irq_chip(axp20x->regmap, i2c->irq, 439 ret = regmap_add_irq_chip(axp20x->regmap, i2c->irq,
190 IRQF_ONESHOT | IRQF_SHARED, -1, 440 IRQF_ONESHOT | IRQF_SHARED, -1,
191 &axp20x_regmap_irq_chip, 441 axp20x->regmap_irq_chip,
192 &axp20x->regmap_irqc); 442 &axp20x->regmap_irqc);
193 if (ret) { 443 if (ret) {
194 dev_err(&i2c->dev, "failed to add irq chip: %d\n", ret); 444 dev_err(&i2c->dev, "failed to add irq chip: %d\n", ret);
195 return ret; 445 return ret;
196 } 446 }
197 447
198 ret = mfd_add_devices(axp20x->dev, -1, axp20x_cells, 448 ret = mfd_add_devices(axp20x->dev, -1, axp20x->cells,
199 ARRAY_SIZE(axp20x_cells), NULL, 0, NULL); 449 axp20x->nr_cells, NULL, 0, NULL);
200 450
201 if (ret) { 451 if (ret) {
202 dev_err(&i2c->dev, "failed to add MFD devices: %d\n", ret); 452 dev_err(&i2c->dev, "failed to add MFD devices: %d\n", ret);
@@ -234,6 +484,7 @@ static struct i2c_driver axp20x_i2c_driver = {
234 .name = "axp20x", 484 .name = "axp20x",
235 .owner = THIS_MODULE, 485 .owner = THIS_MODULE,
236 .of_match_table = of_match_ptr(axp20x_of_match), 486 .of_match_table = of_match_ptr(axp20x_of_match),
487 .acpi_match_table = ACPI_PTR(axp20x_acpi_match),
237 }, 488 },
238 .probe = axp20x_i2c_probe, 489 .probe = axp20x_i2c_probe,
239 .remove = axp20x_i2c_remove, 490 .remove = axp20x_i2c_remove,
diff --git a/drivers/mfd/da9063-core.c b/drivers/mfd/da9063-core.c
index 93db8bb8c8f0..f38bc98a3c57 100644
--- a/drivers/mfd/da9063-core.c
+++ b/drivers/mfd/da9063-core.c
@@ -118,7 +118,7 @@ int da9063_device_init(struct da9063 *da9063, unsigned int irq)
118 da9063->irq_base = pdata->irq_base; 118 da9063->irq_base = pdata->irq_base;
119 } else { 119 } else {
120 da9063->flags = 0; 120 da9063->flags = 0;
121 da9063->irq_base = 0; 121 da9063->irq_base = -1;
122 } 122 }
123 da9063->chip_irq = irq; 123 da9063->chip_irq = irq;
124 124
@@ -168,6 +168,8 @@ int da9063_device_init(struct da9063 *da9063, unsigned int irq)
168 return ret; 168 return ret;
169 } 169 }
170 170
171 da9063->irq_base = regmap_irq_chip_get_base(da9063->regmap_irq);
172
171 ret = mfd_add_devices(da9063->dev, -1, da9063_devs, 173 ret = mfd_add_devices(da9063->dev, -1, da9063_devs,
172 ARRAY_SIZE(da9063_devs), NULL, da9063->irq_base, 174 ARRAY_SIZE(da9063_devs), NULL, da9063->irq_base,
173 NULL); 175 NULL);
diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
index 193cf168ba84..a8204730f01c 100644
--- a/drivers/mfd/db8500-prcmu.c
+++ b/drivers/mfd/db8500-prcmu.c
@@ -3150,23 +3150,28 @@ static int db8500_prcmu_probe(struct platform_device *pdev)
3150 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "prcmu"); 3150 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "prcmu");
3151 if (!res) { 3151 if (!res) {
3152 dev_err(&pdev->dev, "no prcmu memory region provided\n"); 3152 dev_err(&pdev->dev, "no prcmu memory region provided\n");
3153 return -ENOENT; 3153 return -EINVAL;
3154 } 3154 }
3155 prcmu_base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); 3155 prcmu_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
3156 if (!prcmu_base) { 3156 if (!prcmu_base) {
3157 dev_err(&pdev->dev, 3157 dev_err(&pdev->dev,
3158 "failed to ioremap prcmu register memory\n"); 3158 "failed to ioremap prcmu register memory\n");
3159 return -ENOENT; 3159 return -ENOMEM;
3160 } 3160 }
3161 init_prcm_registers(); 3161 init_prcm_registers();
3162 dbx500_fw_version_init(pdev, pdata->version_offset); 3162 dbx500_fw_version_init(pdev, pdata->version_offset);
3163 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "prcmu-tcdm"); 3163 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "prcmu-tcdm");
3164 if (!res) { 3164 if (!res) {
3165 dev_err(&pdev->dev, "no prcmu tcdm region provided\n"); 3165 dev_err(&pdev->dev, "no prcmu tcdm region provided\n");
3166 return -ENOENT; 3166 return -EINVAL;
3167 } 3167 }
3168 tcdm_base = devm_ioremap(&pdev->dev, res->start, 3168 tcdm_base = devm_ioremap(&pdev->dev, res->start,
3169 resource_size(res)); 3169 resource_size(res));
3170 if (!tcdm_base) {
3171 dev_err(&pdev->dev,
3172 "failed to ioremap prcmu-tcdm register memory\n");
3173 return -ENOMEM;
3174 }
3170 3175
3171 /* Clean up the mailbox interrupts after pre-kernel code. */ 3176 /* Clean up the mailbox interrupts after pre-kernel code. */
3172 writel(ALL_MBOX_BITS, PRCM_ARM_IT1_CLR); 3177 writel(ALL_MBOX_BITS, PRCM_ARM_IT1_CLR);
@@ -3174,15 +3179,14 @@ static int db8500_prcmu_probe(struct platform_device *pdev)
3174 irq = platform_get_irq(pdev, 0); 3179 irq = platform_get_irq(pdev, 0);
3175 if (irq <= 0) { 3180 if (irq <= 0) {
3176 dev_err(&pdev->dev, "no prcmu irq provided\n"); 3181 dev_err(&pdev->dev, "no prcmu irq provided\n");
3177 return -ENOENT; 3182 return irq;
3178 } 3183 }
3179 3184
3180 err = request_threaded_irq(irq, prcmu_irq_handler, 3185 err = request_threaded_irq(irq, prcmu_irq_handler,
3181 prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL); 3186 prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL);
3182 if (err < 0) { 3187 if (err < 0) {
3183 pr_err("prcmu: Failed to allocate IRQ_DB8500_PRCMU1.\n"); 3188 pr_err("prcmu: Failed to allocate IRQ_DB8500_PRCMU1.\n");
3184 err = -EBUSY; 3189 return err;
3185 goto no_irq_return;
3186 } 3190 }
3187 3191
3188 db8500_irq_init(np); 3192 db8500_irq_init(np);
@@ -3206,7 +3210,7 @@ static int db8500_prcmu_probe(struct platform_device *pdev)
3206 if (err) { 3210 if (err) {
3207 mfd_remove_devices(&pdev->dev); 3211 mfd_remove_devices(&pdev->dev);
3208 pr_err("prcmu: Failed to add subdevices\n"); 3212 pr_err("prcmu: Failed to add subdevices\n");
3209 goto no_irq_return; 3213 return err;
3210 } 3214 }
3211 } 3215 }
3212 3216
@@ -3214,12 +3218,10 @@ static int db8500_prcmu_probe(struct platform_device *pdev)
3214 if (err) { 3218 if (err) {
3215 mfd_remove_devices(&pdev->dev); 3219 mfd_remove_devices(&pdev->dev);
3216 pr_err("prcmu: Failed to add ab8500 subdevice\n"); 3220 pr_err("prcmu: Failed to add ab8500 subdevice\n");
3217 goto no_irq_return; 3221 return err;
3218 } 3222 }
3219 3223
3220 pr_info("DB8500 PRCMU initialized\n"); 3224 pr_info("DB8500 PRCMU initialized\n");
3221
3222no_irq_return:
3223 return err; 3225 return err;
3224} 3226}
3225static const struct of_device_id db8500_prcmu_match[] = { 3227static const struct of_device_id db8500_prcmu_match[] = {
diff --git a/drivers/mfd/dln2.c b/drivers/mfd/dln2.c
new file mode 100644
index 000000000000..6d49685d4ee4
--- /dev/null
+++ b/drivers/mfd/dln2.c
@@ -0,0 +1,781 @@
1/*
2 * Driver for the Diolan DLN-2 USB adapter
3 *
4 * Copyright (c) 2014 Intel Corporation
5 *
6 * Derived from:
7 * i2c-diolan-u2c.c
8 * Copyright (c) 2010-2011 Ericsson AB
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation, version 2.
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/slab.h>
19#include <linux/usb.h>
20#include <linux/i2c.h>
21#include <linux/mutex.h>
22#include <linux/platform_device.h>
23#include <linux/mfd/core.h>
24#include <linux/mfd/dln2.h>
25#include <linux/rculist.h>
26
27struct dln2_header {
28 __le16 size;
29 __le16 id;
30 __le16 echo;
31 __le16 handle;
32};
33
34struct dln2_response {
35 struct dln2_header hdr;
36 __le16 result;
37};
38
39#define DLN2_GENERIC_MODULE_ID 0x00
40#define DLN2_GENERIC_CMD(cmd) DLN2_CMD(cmd, DLN2_GENERIC_MODULE_ID)
41#define CMD_GET_DEVICE_VER DLN2_GENERIC_CMD(0x30)
42#define CMD_GET_DEVICE_SN DLN2_GENERIC_CMD(0x31)
43
44#define DLN2_HW_ID 0x200
45#define DLN2_USB_TIMEOUT 200 /* in ms */
46#define DLN2_MAX_RX_SLOTS 16
47#define DLN2_MAX_URBS 16
48#define DLN2_RX_BUF_SIZE 512
49
50enum dln2_handle {
51 DLN2_HANDLE_EVENT = 0, /* don't change, hardware defined */
52 DLN2_HANDLE_CTRL,
53 DLN2_HANDLE_GPIO,
54 DLN2_HANDLE_I2C,
55 DLN2_HANDLE_SPI,
56 DLN2_HANDLES
57};
58
59/*
60 * Receive context used between the receive demultiplexer and the transfer
61 * routine. While sending a request the transfer routine will look for a free
62 * receive context and use it to wait for a response and to receive the URB and
63 * thus the response data.
64 */
65struct dln2_rx_context {
66 /* completion used to wait for a response */
67 struct completion done;
68
69 /* if non-NULL the URB contains the response */
70 struct urb *urb;
71
72 /* if true then this context is used to wait for a response */
73 bool in_use;
74};
75
76/*
77 * Receive contexts for a particular DLN2 module (i2c, gpio, etc.). We use the
78 * handle header field to identify the module in dln2_dev.mod_rx_slots and then
79 * the echo header field to index the slots field and find the receive context
80 * for a particular request.
81 */
82struct dln2_mod_rx_slots {
83 /* RX slots bitmap */
84 DECLARE_BITMAP(bmap, DLN2_MAX_RX_SLOTS);
85
86 /* used to wait for a free RX slot */
87 wait_queue_head_t wq;
88
89 /* used to wait for an RX operation to complete */
90 struct dln2_rx_context slots[DLN2_MAX_RX_SLOTS];
91
92 /* avoid races between alloc/free_rx_slot and dln2_rx_transfer */
93 spinlock_t lock;
94};
95
96struct dln2_dev {
97 struct usb_device *usb_dev;
98 struct usb_interface *interface;
99 u8 ep_in;
100 u8 ep_out;
101
102 struct urb *rx_urb[DLN2_MAX_URBS];
103 void *rx_buf[DLN2_MAX_URBS];
104
105 struct dln2_mod_rx_slots mod_rx_slots[DLN2_HANDLES];
106
107 struct list_head event_cb_list;
108 spinlock_t event_cb_lock;
109
110 bool disconnect;
111 int active_transfers;
112 wait_queue_head_t disconnect_wq;
113 spinlock_t disconnect_lock;
114};
115
116struct dln2_event_cb_entry {
117 struct list_head list;
118 u16 id;
119 struct platform_device *pdev;
120 dln2_event_cb_t callback;
121};
122
123int dln2_register_event_cb(struct platform_device *pdev, u16 id,
124 dln2_event_cb_t event_cb)
125{
126 struct dln2_dev *dln2 = dev_get_drvdata(pdev->dev.parent);
127 struct dln2_event_cb_entry *i, *entry;
128 unsigned long flags;
129 int ret = 0;
130
131 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
132 if (!entry)
133 return -ENOMEM;
134
135 entry->id = id;
136 entry->callback = event_cb;
137 entry->pdev = pdev;
138
139 spin_lock_irqsave(&dln2->event_cb_lock, flags);
140
141 list_for_each_entry(i, &dln2->event_cb_list, list) {
142 if (i->id == id) {
143 ret = -EBUSY;
144 break;
145 }
146 }
147
148 if (!ret)
149 list_add_rcu(&entry->list, &dln2->event_cb_list);
150
151 spin_unlock_irqrestore(&dln2->event_cb_lock, flags);
152
153 if (ret)
154 kfree(entry);
155
156 return ret;
157}
158EXPORT_SYMBOL(dln2_register_event_cb);
159
160void dln2_unregister_event_cb(struct platform_device *pdev, u16 id)
161{
162 struct dln2_dev *dln2 = dev_get_drvdata(pdev->dev.parent);
163 struct dln2_event_cb_entry *i;
164 unsigned long flags;
165 bool found = false;
166
167 spin_lock_irqsave(&dln2->event_cb_lock, flags);
168
169 list_for_each_entry(i, &dln2->event_cb_list, list) {
170 if (i->id == id) {
171 list_del_rcu(&i->list);
172 found = true;
173 break;
174 }
175 }
176
177 spin_unlock_irqrestore(&dln2->event_cb_lock, flags);
178
179 if (found) {
180 synchronize_rcu();
181 kfree(i);
182 }
183}
184EXPORT_SYMBOL(dln2_unregister_event_cb);
185
186/*
187 * Returns true if a valid transfer slot is found. In this case the URB must not
188 * be resubmitted immediately in dln2_rx as we need the data when dln2_transfer
189 * is woke up. It will be resubmitted there.
190 */
191static bool dln2_transfer_complete(struct dln2_dev *dln2, struct urb *urb,
192 u16 handle, u16 rx_slot)
193{
194 struct device *dev = &dln2->interface->dev;
195 struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[handle];
196 struct dln2_rx_context *rxc;
197 bool valid_slot = false;
198
199 if (rx_slot >= DLN2_MAX_RX_SLOTS)
200 goto out;
201
202 rxc = &rxs->slots[rx_slot];
203
204 /*
205 * No need to disable interrupts as this lock is not taken in interrupt
206 * context elsewhere in this driver. This function (or its callers) are
207 * also not exported to other modules.
208 */
209 spin_lock(&rxs->lock);
210 if (rxc->in_use && !rxc->urb) {
211 rxc->urb = urb;
212 complete(&rxc->done);
213 valid_slot = true;
214 }
215 spin_unlock(&rxs->lock);
216
217out:
218 if (!valid_slot)
219 dev_warn(dev, "bad/late response %d/%d\n", handle, rx_slot);
220
221 return valid_slot;
222}
223
224static void dln2_run_event_callbacks(struct dln2_dev *dln2, u16 id, u16 echo,
225 void *data, int len)
226{
227 struct dln2_event_cb_entry *i;
228
229 rcu_read_lock();
230
231 list_for_each_entry_rcu(i, &dln2->event_cb_list, list) {
232 if (i->id == id) {
233 i->callback(i->pdev, echo, data, len);
234 break;
235 }
236 }
237
238 rcu_read_unlock();
239}
240
241static void dln2_rx(struct urb *urb)
242{
243 struct dln2_dev *dln2 = urb->context;
244 struct dln2_header *hdr = urb->transfer_buffer;
245 struct device *dev = &dln2->interface->dev;
246 u16 id, echo, handle, size;
247 u8 *data;
248 int len;
249 int err;
250
251 switch (urb->status) {
252 case 0:
253 /* success */
254 break;
255 case -ECONNRESET:
256 case -ENOENT:
257 case -ESHUTDOWN:
258 case -EPIPE:
259 /* this urb is terminated, clean up */
260 dev_dbg(dev, "urb shutting down with status %d\n", urb->status);
261 return;
262 default:
263 dev_dbg(dev, "nonzero urb status received %d\n", urb->status);
264 goto out;
265 }
266
267 if (urb->actual_length < sizeof(struct dln2_header)) {
268 dev_err(dev, "short response: %d\n", urb->actual_length);
269 goto out;
270 }
271
272 handle = le16_to_cpu(hdr->handle);
273 id = le16_to_cpu(hdr->id);
274 echo = le16_to_cpu(hdr->echo);
275 size = le16_to_cpu(hdr->size);
276
277 if (size != urb->actual_length) {
278 dev_err(dev, "size mismatch: handle %x cmd %x echo %x size %d actual %d\n",
279 handle, id, echo, size, urb->actual_length);
280 goto out;
281 }
282
283 if (handle >= DLN2_HANDLES) {
284 dev_warn(dev, "invalid handle %d\n", handle);
285 goto out;
286 }
287
288 data = urb->transfer_buffer + sizeof(struct dln2_header);
289 len = urb->actual_length - sizeof(struct dln2_header);
290
291 if (handle == DLN2_HANDLE_EVENT) {
292 dln2_run_event_callbacks(dln2, id, echo, data, len);
293 } else {
294 /* URB will be re-submitted in _dln2_transfer (free_rx_slot) */
295 if (dln2_transfer_complete(dln2, urb, handle, echo))
296 return;
297 }
298
299out:
300 err = usb_submit_urb(urb, GFP_ATOMIC);
301 if (err < 0)
302 dev_err(dev, "failed to resubmit RX URB: %d\n", err);
303}
304
305static void *dln2_prep_buf(u16 handle, u16 cmd, u16 echo, const void *obuf,
306 int *obuf_len, gfp_t gfp)
307{
308 int len;
309 void *buf;
310 struct dln2_header *hdr;
311
312 len = *obuf_len + sizeof(*hdr);
313 buf = kmalloc(len, gfp);
314 if (!buf)
315 return NULL;
316
317 hdr = (struct dln2_header *)buf;
318 hdr->id = cpu_to_le16(cmd);
319 hdr->size = cpu_to_le16(len);
320 hdr->echo = cpu_to_le16(echo);
321 hdr->handle = cpu_to_le16(handle);
322
323 memcpy(buf + sizeof(*hdr), obuf, *obuf_len);
324
325 *obuf_len = len;
326
327 return buf;
328}
329
330static int dln2_send_wait(struct dln2_dev *dln2, u16 handle, u16 cmd, u16 echo,
331 const void *obuf, int obuf_len)
332{
333 int ret = 0;
334 int len = obuf_len;
335 void *buf;
336 int actual;
337
338 buf = dln2_prep_buf(handle, cmd, echo, obuf, &len, GFP_KERNEL);
339 if (!buf)
340 return -ENOMEM;
341
342 ret = usb_bulk_msg(dln2->usb_dev,
343 usb_sndbulkpipe(dln2->usb_dev, dln2->ep_out),
344 buf, len, &actual, DLN2_USB_TIMEOUT);
345
346 kfree(buf);
347
348 return ret;
349}
350
351static bool find_free_slot(struct dln2_dev *dln2, u16 handle, int *slot)
352{
353 struct dln2_mod_rx_slots *rxs;
354 unsigned long flags;
355
356 if (dln2->disconnect) {
357 *slot = -ENODEV;
358 return true;
359 }
360
361 rxs = &dln2->mod_rx_slots[handle];
362
363 spin_lock_irqsave(&rxs->lock, flags);
364
365 *slot = find_first_zero_bit(rxs->bmap, DLN2_MAX_RX_SLOTS);
366
367 if (*slot < DLN2_MAX_RX_SLOTS) {
368 struct dln2_rx_context *rxc = &rxs->slots[*slot];
369
370 set_bit(*slot, rxs->bmap);
371 rxc->in_use = true;
372 }
373
374 spin_unlock_irqrestore(&rxs->lock, flags);
375
376 return *slot < DLN2_MAX_RX_SLOTS;
377}
378
379static int alloc_rx_slot(struct dln2_dev *dln2, u16 handle)
380{
381 int ret;
382 int slot;
383
384 /*
385 * No need to timeout here, the wait is bounded by the timeout in
386 * _dln2_transfer.
387 */
388 ret = wait_event_interruptible(dln2->mod_rx_slots[handle].wq,
389 find_free_slot(dln2, handle, &slot));
390 if (ret < 0)
391 return ret;
392
393 return slot;
394}
395
396static void free_rx_slot(struct dln2_dev *dln2, u16 handle, int slot)
397{
398 struct dln2_mod_rx_slots *rxs;
399 struct urb *urb = NULL;
400 unsigned long flags;
401 struct dln2_rx_context *rxc;
402
403 rxs = &dln2->mod_rx_slots[handle];
404
405 spin_lock_irqsave(&rxs->lock, flags);
406
407 clear_bit(slot, rxs->bmap);
408
409 rxc = &rxs->slots[slot];
410 rxc->in_use = false;
411 urb = rxc->urb;
412 rxc->urb = NULL;
413 reinit_completion(&rxc->done);
414
415 spin_unlock_irqrestore(&rxs->lock, flags);
416
417 if (urb) {
418 int err;
419 struct device *dev = &dln2->interface->dev;
420
421 err = usb_submit_urb(urb, GFP_KERNEL);
422 if (err < 0)
423 dev_err(dev, "failed to resubmit RX URB: %d\n", err);
424 }
425
426 wake_up_interruptible(&rxs->wq);
427}
428
429static int _dln2_transfer(struct dln2_dev *dln2, u16 handle, u16 cmd,
430 const void *obuf, unsigned obuf_len,
431 void *ibuf, unsigned *ibuf_len)
432{
433 int ret = 0;
434 int rx_slot;
435 struct dln2_response *rsp;
436 struct dln2_rx_context *rxc;
437 struct device *dev = &dln2->interface->dev;
438 const unsigned long timeout = DLN2_USB_TIMEOUT * HZ / 1000;
439 struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[handle];
440 int size;
441
442 spin_lock(&dln2->disconnect_lock);
443 if (!dln2->disconnect)
444 dln2->active_transfers++;
445 else
446 ret = -ENODEV;
447 spin_unlock(&dln2->disconnect_lock);
448
449 if (ret)
450 return ret;
451
452 rx_slot = alloc_rx_slot(dln2, handle);
453 if (rx_slot < 0) {
454 ret = rx_slot;
455 goto out_decr;
456 }
457
458 ret = dln2_send_wait(dln2, handle, cmd, rx_slot, obuf, obuf_len);
459 if (ret < 0) {
460 dev_err(dev, "USB write failed: %d\n", ret);
461 goto out_free_rx_slot;
462 }
463
464 rxc = &rxs->slots[rx_slot];
465
466 ret = wait_for_completion_interruptible_timeout(&rxc->done, timeout);
467 if (ret <= 0) {
468 if (!ret)
469 ret = -ETIMEDOUT;
470 goto out_free_rx_slot;
471 } else {
472 ret = 0;
473 }
474
475 if (dln2->disconnect) {
476 ret = -ENODEV;
477 goto out_free_rx_slot;
478 }
479
480 /* if we got here we know that the response header has been checked */
481 rsp = rxc->urb->transfer_buffer;
482 size = le16_to_cpu(rsp->hdr.size);
483
484 if (size < sizeof(*rsp)) {
485 ret = -EPROTO;
486 goto out_free_rx_slot;
487 }
488
489 if (le16_to_cpu(rsp->result) > 0x80) {
490 dev_dbg(dev, "%d received response with error %d\n",
491 handle, le16_to_cpu(rsp->result));
492 ret = -EREMOTEIO;
493 goto out_free_rx_slot;
494 }
495
496 if (!ibuf)
497 goto out_free_rx_slot;
498
499 if (*ibuf_len > size - sizeof(*rsp))
500 *ibuf_len = size - sizeof(*rsp);
501
502 memcpy(ibuf, rsp + 1, *ibuf_len);
503
504out_free_rx_slot:
505 free_rx_slot(dln2, handle, rx_slot);
506out_decr:
507 spin_lock(&dln2->disconnect_lock);
508 dln2->active_transfers--;
509 spin_unlock(&dln2->disconnect_lock);
510 if (dln2->disconnect)
511 wake_up(&dln2->disconnect_wq);
512
513 return ret;
514}
515
516int dln2_transfer(struct platform_device *pdev, u16 cmd,
517 const void *obuf, unsigned obuf_len,
518 void *ibuf, unsigned *ibuf_len)
519{
520 struct dln2_platform_data *dln2_pdata;
521 struct dln2_dev *dln2;
522 u16 handle;
523
524 dln2 = dev_get_drvdata(pdev->dev.parent);
525 dln2_pdata = dev_get_platdata(&pdev->dev);
526 handle = dln2_pdata->handle;
527
528 return _dln2_transfer(dln2, handle, cmd, obuf, obuf_len, ibuf,
529 ibuf_len);
530}
531EXPORT_SYMBOL(dln2_transfer);
532
533static int dln2_check_hw(struct dln2_dev *dln2)
534{
535 int ret;
536 __le32 hw_type;
537 int len = sizeof(hw_type);
538
539 ret = _dln2_transfer(dln2, DLN2_HANDLE_CTRL, CMD_GET_DEVICE_VER,
540 NULL, 0, &hw_type, &len);
541 if (ret < 0)
542 return ret;
543 if (len < sizeof(hw_type))
544 return -EREMOTEIO;
545
546 if (le32_to_cpu(hw_type) != DLN2_HW_ID) {
547 dev_err(&dln2->interface->dev, "Device ID 0x%x not supported\n",
548 le32_to_cpu(hw_type));
549 return -ENODEV;
550 }
551
552 return 0;
553}
554
555static int dln2_print_serialno(struct dln2_dev *dln2)
556{
557 int ret;
558 __le32 serial_no;
559 int len = sizeof(serial_no);
560 struct device *dev = &dln2->interface->dev;
561
562 ret = _dln2_transfer(dln2, DLN2_HANDLE_CTRL, CMD_GET_DEVICE_SN, NULL, 0,
563 &serial_no, &len);
564 if (ret < 0)
565 return ret;
566 if (len < sizeof(serial_no))
567 return -EREMOTEIO;
568
569 dev_info(dev, "Diolan DLN2 serial %u\n", le32_to_cpu(serial_no));
570
571 return 0;
572}
573
574static int dln2_hw_init(struct dln2_dev *dln2)
575{
576 int ret;
577
578 ret = dln2_check_hw(dln2);
579 if (ret < 0)
580 return ret;
581
582 return dln2_print_serialno(dln2);
583}
584
585static void dln2_free_rx_urbs(struct dln2_dev *dln2)
586{
587 int i;
588
589 for (i = 0; i < DLN2_MAX_URBS; i++) {
590 usb_kill_urb(dln2->rx_urb[i]);
591 usb_free_urb(dln2->rx_urb[i]);
592 kfree(dln2->rx_buf[i]);
593 }
594}
595
596static void dln2_free(struct dln2_dev *dln2)
597{
598 dln2_free_rx_urbs(dln2);
599 usb_put_dev(dln2->usb_dev);
600 kfree(dln2);
601}
602
603static int dln2_setup_rx_urbs(struct dln2_dev *dln2,
604 struct usb_host_interface *hostif)
605{
606 int i;
607 int ret;
608 const int rx_max_size = DLN2_RX_BUF_SIZE;
609 struct device *dev = &dln2->interface->dev;
610
611 for (i = 0; i < DLN2_MAX_URBS; i++) {
612 dln2->rx_buf[i] = kmalloc(rx_max_size, GFP_KERNEL);
613 if (!dln2->rx_buf[i])
614 return -ENOMEM;
615
616 dln2->rx_urb[i] = usb_alloc_urb(0, GFP_KERNEL);
617 if (!dln2->rx_urb[i])
618 return -ENOMEM;
619
620 usb_fill_bulk_urb(dln2->rx_urb[i], dln2->usb_dev,
621 usb_rcvbulkpipe(dln2->usb_dev, dln2->ep_in),
622 dln2->rx_buf[i], rx_max_size, dln2_rx, dln2);
623
624 ret = usb_submit_urb(dln2->rx_urb[i], GFP_KERNEL);
625 if (ret < 0) {
626 dev_err(dev, "failed to submit RX URB: %d\n", ret);
627 return ret;
628 }
629 }
630
631 return 0;
632}
633
634static struct dln2_platform_data dln2_pdata_gpio = {
635 .handle = DLN2_HANDLE_GPIO,
636};
637
638/* Only one I2C port seems to be supported on current hardware */
639static struct dln2_platform_data dln2_pdata_i2c = {
640 .handle = DLN2_HANDLE_I2C,
641 .port = 0,
642};
643
644/* Only one SPI port supported */
645static struct dln2_platform_data dln2_pdata_spi = {
646 .handle = DLN2_HANDLE_SPI,
647 .port = 0,
648};
649
650static const struct mfd_cell dln2_devs[] = {
651 {
652 .name = "dln2-gpio",
653 .platform_data = &dln2_pdata_gpio,
654 .pdata_size = sizeof(struct dln2_platform_data),
655 },
656 {
657 .name = "dln2-i2c",
658 .platform_data = &dln2_pdata_i2c,
659 .pdata_size = sizeof(struct dln2_platform_data),
660 },
661 {
662 .name = "dln2-spi",
663 .platform_data = &dln2_pdata_spi,
664 .pdata_size = sizeof(struct dln2_platform_data),
665 },
666};
667
668static void dln2_disconnect(struct usb_interface *interface)
669{
670 struct dln2_dev *dln2 = usb_get_intfdata(interface);
671 int i, j;
672
673 /* don't allow starting new transfers */
674 spin_lock(&dln2->disconnect_lock);
675 dln2->disconnect = true;
676 spin_unlock(&dln2->disconnect_lock);
677
678 /* cancel in progress transfers */
679 for (i = 0; i < DLN2_HANDLES; i++) {
680 struct dln2_mod_rx_slots *rxs = &dln2->mod_rx_slots[i];
681 unsigned long flags;
682
683 spin_lock_irqsave(&rxs->lock, flags);
684
685 /* cancel all response waiters */
686 for (j = 0; j < DLN2_MAX_RX_SLOTS; j++) {
687 struct dln2_rx_context *rxc = &rxs->slots[j];
688
689 if (rxc->in_use)
690 complete(&rxc->done);
691 }
692
693 spin_unlock_irqrestore(&rxs->lock, flags);
694 }
695
696 /* wait for transfers to end */
697 wait_event(dln2->disconnect_wq, !dln2->active_transfers);
698
699 mfd_remove_devices(&interface->dev);
700
701 dln2_free(dln2);
702}
703
704static int dln2_probe(struct usb_interface *interface,
705 const struct usb_device_id *usb_id)
706{
707 struct usb_host_interface *hostif = interface->cur_altsetting;
708 struct device *dev = &interface->dev;
709 struct dln2_dev *dln2;
710 int ret;
711 int i, j;
712
713 if (hostif->desc.bInterfaceNumber != 0 ||
714 hostif->desc.bNumEndpoints < 2)
715 return -ENODEV;
716
717 dln2 = kzalloc(sizeof(*dln2), GFP_KERNEL);
718 if (!dln2)
719 return -ENOMEM;
720
721 dln2->ep_out = hostif->endpoint[0].desc.bEndpointAddress;
722 dln2->ep_in = hostif->endpoint[1].desc.bEndpointAddress;
723 dln2->usb_dev = usb_get_dev(interface_to_usbdev(interface));
724 dln2->interface = interface;
725 usb_set_intfdata(interface, dln2);
726 init_waitqueue_head(&dln2->disconnect_wq);
727
728 for (i = 0; i < DLN2_HANDLES; i++) {
729 init_waitqueue_head(&dln2->mod_rx_slots[i].wq);
730 spin_lock_init(&dln2->mod_rx_slots[i].lock);
731 for (j = 0; j < DLN2_MAX_RX_SLOTS; j++)
732 init_completion(&dln2->mod_rx_slots[i].slots[j].done);
733 }
734
735 spin_lock_init(&dln2->event_cb_lock);
736 spin_lock_init(&dln2->disconnect_lock);
737 INIT_LIST_HEAD(&dln2->event_cb_list);
738
739 ret = dln2_setup_rx_urbs(dln2, hostif);
740 if (ret)
741 goto out_cleanup;
742
743 ret = dln2_hw_init(dln2);
744 if (ret < 0) {
745 dev_err(dev, "failed to initialize hardware\n");
746 goto out_cleanup;
747 }
748
749 ret = mfd_add_hotplug_devices(dev, dln2_devs, ARRAY_SIZE(dln2_devs));
750 if (ret != 0) {
751 dev_err(dev, "failed to add mfd devices to core\n");
752 goto out_cleanup;
753 }
754
755 return 0;
756
757out_cleanup:
758 dln2_free(dln2);
759
760 return ret;
761}
762
763static const struct usb_device_id dln2_table[] = {
764 { USB_DEVICE(0xa257, 0x2013) },
765 { }
766};
767
768MODULE_DEVICE_TABLE(usb, dln2_table);
769
770static struct usb_driver dln2_driver = {
771 .name = "dln2",
772 .probe = dln2_probe,
773 .disconnect = dln2_disconnect,
774 .id_table = dln2_table,
775};
776
777module_usb_driver(dln2_driver);
778
779MODULE_AUTHOR("Octavian Purdila <octavian.purdila@intel.com>");
780MODULE_DESCRIPTION("Core driver for the Diolan DLN2 interface adapter");
781MODULE_LICENSE("GPL v2");
diff --git a/drivers/mfd/lpc_sch.c b/drivers/mfd/lpc_sch.c
index c980da479a35..5c38df35a84d 100644
--- a/drivers/mfd/lpc_sch.c
+++ b/drivers/mfd/lpc_sch.c
@@ -193,11 +193,7 @@ static int lpc_sch_probe(struct pci_dev *dev, const struct pci_device_id *id)
193 return -ENODEV; 193 return -ENODEV;
194 } 194 }
195 195
196 ret = mfd_add_devices(&dev->dev, 0, lpc_sch_cells, cells, NULL, 0, NULL); 196 return mfd_add_devices(&dev->dev, 0, lpc_sch_cells, cells, NULL, 0, NULL);
197 if (ret)
198 mfd_remove_devices(&dev->dev);
199
200 return ret;
201} 197}
202 198
203static void lpc_sch_remove(struct pci_dev *dev) 199static void lpc_sch_remove(struct pci_dev *dev)
diff --git a/drivers/mfd/max14577.c b/drivers/mfd/max14577.c
index de96b7fb1f6d..3bf8def82f1e 100644
--- a/drivers/mfd/max14577.c
+++ b/drivers/mfd/max14577.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * max14577.c - mfd core driver for the Maxim 14577/77836 2 * max14577.c - mfd core driver for the Maxim 14577/77836
3 * 3 *
4 * Copyright (C) 2014 Samsung Electrnoics 4 * Copyright (C) 2014 Samsung Electronics
5 * Chanwoo Choi <cw00.choi@samsung.com> 5 * Chanwoo Choi <cw00.choi@samsung.com>
6 * Krzysztof Kozlowski <k.kozlowski@samsung.com> 6 * Krzysztof Kozlowski <k.kozlowski@samsung.com>
7 * 7 *
diff --git a/drivers/mfd/max77693.c b/drivers/mfd/max77693.c
index cf008f45968c..a159593e27a0 100644
--- a/drivers/mfd/max77693.c
+++ b/drivers/mfd/max77693.c
@@ -43,9 +43,15 @@
43 43
44static const struct mfd_cell max77693_devs[] = { 44static const struct mfd_cell max77693_devs[] = {
45 { .name = "max77693-pmic", }, 45 { .name = "max77693-pmic", },
46 { .name = "max77693-charger", }, 46 {
47 .name = "max77693-charger",
48 .of_compatible = "maxim,max77693-charger",
49 },
47 { .name = "max77693-muic", }, 50 { .name = "max77693-muic", },
48 { .name = "max77693-haptic", }, 51 {
52 .name = "max77693-haptic",
53 .of_compatible = "maxim,max77693-haptic",
54 },
49 { 55 {
50 .name = "max77693-flash", 56 .name = "max77693-flash",
51 .of_compatible = "maxim,max77693-flash", 57 .of_compatible = "maxim,max77693-flash",
@@ -147,6 +153,12 @@ static const struct regmap_irq_chip max77693_muic_irq_chip = {
147 .num_irqs = ARRAY_SIZE(max77693_muic_irqs), 153 .num_irqs = ARRAY_SIZE(max77693_muic_irqs),
148}; 154};
149 155
156static const struct regmap_config max77693_regmap_haptic_config = {
157 .reg_bits = 8,
158 .val_bits = 8,
159 .max_register = MAX77693_HAPTIC_REG_END,
160};
161
150static int max77693_i2c_probe(struct i2c_client *i2c, 162static int max77693_i2c_probe(struct i2c_client *i2c,
151 const struct i2c_device_id *id) 163 const struct i2c_device_id *id)
152{ 164{
@@ -196,6 +208,15 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
196 } 208 }
197 i2c_set_clientdata(max77693->haptic, max77693); 209 i2c_set_clientdata(max77693->haptic, max77693);
198 210
211 max77693->regmap_haptic = devm_regmap_init_i2c(max77693->haptic,
212 &max77693_regmap_haptic_config);
213 if (IS_ERR(max77693->regmap_haptic)) {
214 ret = PTR_ERR(max77693->regmap_haptic);
215 dev_err(max77693->dev,
216 "failed to initialize haptic register map: %d\n", ret);
217 goto err_regmap;
218 }
219
199 /* 220 /*
200 * Initialize register map for MUIC device because use regmap-muic 221 * Initialize register map for MUIC device because use regmap-muic
201 * instance of MUIC device when irq of max77693 is initialized 222 * instance of MUIC device when irq of max77693 is initialized
@@ -207,7 +228,7 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
207 ret = PTR_ERR(max77693->regmap_muic); 228 ret = PTR_ERR(max77693->regmap_muic);
208 dev_err(max77693->dev, 229 dev_err(max77693->dev,
209 "failed to allocate register map: %d\n", ret); 230 "failed to allocate register map: %d\n", ret);
210 goto err_regmap_muic; 231 goto err_regmap;
211 } 232 }
212 233
213 ret = regmap_add_irq_chip(max77693->regmap, max77693->irq, 234 ret = regmap_add_irq_chip(max77693->regmap, max77693->irq,
@@ -217,7 +238,7 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
217 &max77693->irq_data_led); 238 &max77693->irq_data_led);
218 if (ret) { 239 if (ret) {
219 dev_err(max77693->dev, "failed to add irq chip: %d\n", ret); 240 dev_err(max77693->dev, "failed to add irq chip: %d\n", ret);
220 goto err_regmap_muic; 241 goto err_regmap;
221 } 242 }
222 243
223 ret = regmap_add_irq_chip(max77693->regmap, max77693->irq, 244 ret = regmap_add_irq_chip(max77693->regmap, max77693->irq,
@@ -240,7 +261,7 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
240 goto err_irq_charger; 261 goto err_irq_charger;
241 } 262 }
242 263
243 ret = regmap_add_irq_chip(max77693->regmap, max77693->irq, 264 ret = regmap_add_irq_chip(max77693->regmap_muic, max77693->irq,
244 IRQF_ONESHOT | IRQF_SHARED | 265 IRQF_ONESHOT | IRQF_SHARED |
245 IRQF_TRIGGER_FALLING, 0, 266 IRQF_TRIGGER_FALLING, 0,
246 &max77693_muic_irq_chip, 267 &max77693_muic_irq_chip,
@@ -250,6 +271,17 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
250 goto err_irq_muic; 271 goto err_irq_muic;
251 } 272 }
252 273
274 /* Unmask interrupts from all blocks in interrupt source register */
275 ret = regmap_update_bits(max77693->regmap,
276 MAX77693_PMIC_REG_INTSRC_MASK,
277 SRC_IRQ_ALL, (unsigned int)~SRC_IRQ_ALL);
278 if (ret < 0) {
279 dev_err(max77693->dev,
280 "Could not unmask interrupts in INTSRC: %d\n",
281 ret);
282 goto err_intsrc;
283 }
284
253 pm_runtime_set_active(max77693->dev); 285 pm_runtime_set_active(max77693->dev);
254 286
255 ret = mfd_add_devices(max77693->dev, -1, max77693_devs, 287 ret = mfd_add_devices(max77693->dev, -1, max77693_devs,
@@ -261,6 +293,7 @@ static int max77693_i2c_probe(struct i2c_client *i2c,
261 293
262err_mfd: 294err_mfd:
263 mfd_remove_devices(max77693->dev); 295 mfd_remove_devices(max77693->dev);
296err_intsrc:
264 regmap_del_irq_chip(max77693->irq, max77693->irq_data_muic); 297 regmap_del_irq_chip(max77693->irq, max77693->irq_data_muic);
265err_irq_muic: 298err_irq_muic:
266 regmap_del_irq_chip(max77693->irq, max77693->irq_data_charger); 299 regmap_del_irq_chip(max77693->irq, max77693->irq_data_charger);
@@ -268,7 +301,7 @@ err_irq_charger:
268 regmap_del_irq_chip(max77693->irq, max77693->irq_data_topsys); 301 regmap_del_irq_chip(max77693->irq, max77693->irq_data_topsys);
269err_irq_topsys: 302err_irq_topsys:
270 regmap_del_irq_chip(max77693->irq, max77693->irq_data_led); 303 regmap_del_irq_chip(max77693->irq, max77693->irq_data_led);
271err_regmap_muic: 304err_regmap:
272 i2c_unregister_device(max77693->haptic); 305 i2c_unregister_device(max77693->haptic);
273err_i2c_haptic: 306err_i2c_haptic:
274 i2c_unregister_device(max77693->muic); 307 i2c_unregister_device(max77693->muic);
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index f3338fe9d069..2a87f69be53d 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -125,9 +125,15 @@ static int mfd_add_device(struct device *parent, int id,
125 struct platform_device *pdev; 125 struct platform_device *pdev;
126 struct device_node *np = NULL; 126 struct device_node *np = NULL;
127 int ret = -ENOMEM; 127 int ret = -ENOMEM;
128 int platform_id;
128 int r; 129 int r;
129 130
130 pdev = platform_device_alloc(cell->name, id + cell->id); 131 if (id < 0)
132 platform_id = id;
133 else
134 platform_id = id + cell->id;
135
136 pdev = platform_device_alloc(cell->name, platform_id);
131 if (!pdev) 137 if (!pdev)
132 goto fail_alloc; 138 goto fail_alloc;
133 139
diff --git a/drivers/mfd/rts5227.c b/drivers/mfd/rts5227.c
index 9c8eec80ceed..32407404d838 100644
--- a/drivers/mfd/rts5227.c
+++ b/drivers/mfd/rts5227.c
@@ -130,6 +130,12 @@ static int rts5227_extra_init_hw(struct rtsx_pcr *pcr)
130 130
131static int rts5227_optimize_phy(struct rtsx_pcr *pcr) 131static int rts5227_optimize_phy(struct rtsx_pcr *pcr)
132{ 132{
133 int err;
134
135 err = rtsx_gops_pm_reset(pcr);
136 if (err < 0)
137 return err;
138
133 /* Optimize RX sensitivity */ 139 /* Optimize RX sensitivity */
134 return rtsx_pci_write_phy_register(pcr, 0x00, 0xBA42); 140 return rtsx_pci_write_phy_register(pcr, 0x00, 0xBA42);
135} 141}
diff --git a/drivers/mfd/rts5249.c b/drivers/mfd/rts5249.c
index 573de7bfcced..cf425cc959d5 100644
--- a/drivers/mfd/rts5249.c
+++ b/drivers/mfd/rts5249.c
@@ -130,6 +130,10 @@ static int rts5249_optimize_phy(struct rtsx_pcr *pcr)
130{ 130{
131 int err; 131 int err;
132 132
133 err = rtsx_gops_pm_reset(pcr);
134 if (err < 0)
135 return err;
136
133 err = rtsx_pci_write_phy_register(pcr, PHY_REG_REV, 137 err = rtsx_pci_write_phy_register(pcr, PHY_REG_REV,
134 PHY_REG_REV_RESV | PHY_REG_REV_RXIDLE_LATCHED | 138 PHY_REG_REV_RESV | PHY_REG_REV_RXIDLE_LATCHED |
135 PHY_REG_REV_P1_EN | PHY_REG_REV_RXIDLE_EN | 139 PHY_REG_REV_P1_EN | PHY_REG_REV_RXIDLE_EN |
diff --git a/drivers/mfd/rtsx_gops.c b/drivers/mfd/rtsx_gops.c
new file mode 100644
index 000000000000..b1a98c678593
--- /dev/null
+++ b/drivers/mfd/rtsx_gops.c
@@ -0,0 +1,37 @@
1/* Driver for Realtek PCI-Express card reader
2 *
3 * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
8 * later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses/>.
17 *
18 * Author:
19 * Micky Ching <micky_ching@realsil.com.cn>
20 */
21
22#include <linux/mfd/rtsx_pci.h>
23#include "rtsx_pcr.h"
24
25int rtsx_gops_pm_reset(struct rtsx_pcr *pcr)
26{
27 int err;
28
29 /* init aspm */
30 rtsx_pci_write_register(pcr, ASPM_FORCE_CTL, 0xFF, 0x00);
31 err = rtsx_pci_update_cfg_byte(pcr, LCTLR, ~LCTLR_ASPM_CTL_MASK, 0x00);
32 if (err < 0)
33 return err;
34
35 /* reset PM_CTRL3 before send buffer cmd */
36 return rtsx_pci_write_register(pcr, PM_CTRL3, D3_DELINK_MODE_EN, 0x00);
37}
diff --git a/drivers/mfd/rtsx_pcr.c b/drivers/mfd/rtsx_pcr.c
index f2643c221d34..30f7ca89a0e6 100644
--- a/drivers/mfd/rtsx_pcr.c
+++ b/drivers/mfd/rtsx_pcr.c
@@ -947,6 +947,7 @@ static void rtsx_pci_idle_work(struct work_struct *work)
947 mutex_unlock(&pcr->pcr_mutex); 947 mutex_unlock(&pcr->pcr_mutex);
948} 948}
949 949
950#ifdef CONFIG_PM
950static void rtsx_pci_power_off(struct rtsx_pcr *pcr, u8 pm_state) 951static void rtsx_pci_power_off(struct rtsx_pcr *pcr, u8 pm_state)
951{ 952{
952 if (pcr->ops->turn_off_led) 953 if (pcr->ops->turn_off_led)
@@ -961,6 +962,7 @@ static void rtsx_pci_power_off(struct rtsx_pcr *pcr, u8 pm_state)
961 if (pcr->ops->force_power_down) 962 if (pcr->ops->force_power_down)
962 pcr->ops->force_power_down(pcr, pm_state); 963 pcr->ops->force_power_down(pcr, pm_state);
963} 964}
965#endif
964 966
965static int rtsx_pci_init_hw(struct rtsx_pcr *pcr) 967static int rtsx_pci_init_hw(struct rtsx_pcr *pcr)
966{ 968{
diff --git a/drivers/mfd/rtsx_pcr.h b/drivers/mfd/rtsx_pcr.h
index 07e4c2ebf05a..fe2bbb67defc 100644
--- a/drivers/mfd/rtsx_pcr.h
+++ b/drivers/mfd/rtsx_pcr.h
@@ -72,4 +72,7 @@ do { \
72 pcr->ms_pull_ctl_disable_tbl = __device##_ms_pull_ctl_disable_tbl; \ 72 pcr->ms_pull_ctl_disable_tbl = __device##_ms_pull_ctl_disable_tbl; \
73} while (0) 73} while (0)
74 74
75/* generic operations */
76int rtsx_gops_pm_reset(struct rtsx_pcr *pcr);
77
75#endif 78#endif
diff --git a/drivers/mfd/rtsx_usb.c b/drivers/mfd/rtsx_usb.c
index 9cf98d142d9a..dbdd0faeb6ce 100644
--- a/drivers/mfd/rtsx_usb.c
+++ b/drivers/mfd/rtsx_usb.c
@@ -647,8 +647,8 @@ static int rtsx_usb_probe(struct usb_interface *intf,
647 /* initialize USB SG transfer timer */ 647 /* initialize USB SG transfer timer */
648 setup_timer(&ucr->sg_timer, rtsx_usb_sg_timed_out, (unsigned long) ucr); 648 setup_timer(&ucr->sg_timer, rtsx_usb_sg_timed_out, (unsigned long) ucr);
649 649
650 ret = mfd_add_devices(&intf->dev, usb_dev->devnum, rtsx_usb_cells, 650 ret = mfd_add_hotplug_devices(&intf->dev, rtsx_usb_cells,
651 ARRAY_SIZE(rtsx_usb_cells), NULL, 0, NULL); 651 ARRAY_SIZE(rtsx_usb_cells));
652 if (ret) 652 if (ret)
653 goto out_init_fail; 653 goto out_init_fail;
654 654
diff --git a/drivers/mfd/sec-core.c b/drivers/mfd/sec-core.c
index dba7e2b6f8e9..0a7bc43db4e4 100644
--- a/drivers/mfd/sec-core.c
+++ b/drivers/mfd/sec-core.c
@@ -27,11 +27,11 @@
27#include <linux/mfd/samsung/irq.h> 27#include <linux/mfd/samsung/irq.h>
28#include <linux/mfd/samsung/s2mpa01.h> 28#include <linux/mfd/samsung/s2mpa01.h>
29#include <linux/mfd/samsung/s2mps11.h> 29#include <linux/mfd/samsung/s2mps11.h>
30#include <linux/mfd/samsung/s2mps13.h>
30#include <linux/mfd/samsung/s2mps14.h> 31#include <linux/mfd/samsung/s2mps14.h>
31#include <linux/mfd/samsung/s2mpu02.h> 32#include <linux/mfd/samsung/s2mpu02.h>
32#include <linux/mfd/samsung/s5m8763.h> 33#include <linux/mfd/samsung/s5m8763.h>
33#include <linux/mfd/samsung/s5m8767.h> 34#include <linux/mfd/samsung/s5m8767.h>
34#include <linux/regulator/machine.h>
35#include <linux/regmap.h> 35#include <linux/regmap.h>
36 36
37static const struct mfd_cell s5m8751_devs[] = { 37static const struct mfd_cell s5m8751_devs[] = {
@@ -74,6 +74,15 @@ static const struct mfd_cell s2mps11_devs[] = {
74 } 74 }
75}; 75};
76 76
77static const struct mfd_cell s2mps13_devs[] = {
78 { .name = "s2mps13-pmic", },
79 { .name = "s2mps13-rtc", },
80 {
81 .name = "s2mps13-clk",
82 .of_compatible = "samsung,s2mps13-clk",
83 },
84};
85
77static const struct mfd_cell s2mps14_devs[] = { 86static const struct mfd_cell s2mps14_devs[] = {
78 { 87 {
79 .name = "s2mps14-pmic", 88 .name = "s2mps14-pmic",
@@ -108,6 +117,9 @@ static const struct of_device_id sec_dt_match[] = {
108 .compatible = "samsung,s2mps11-pmic", 117 .compatible = "samsung,s2mps11-pmic",
109 .data = (void *)S2MPS11X, 118 .data = (void *)S2MPS11X,
110 }, { 119 }, {
120 .compatible = "samsung,s2mps13-pmic",
121 .data = (void *)S2MPS13X,
122 }, {
111 .compatible = "samsung,s2mps14-pmic", 123 .compatible = "samsung,s2mps14-pmic",
112 .data = (void *)S2MPS14X, 124 .data = (void *)S2MPS14X,
113 }, { 125 }, {
@@ -194,6 +206,15 @@ static const struct regmap_config s2mps11_regmap_config = {
194 .cache_type = REGCACHE_FLAT, 206 .cache_type = REGCACHE_FLAT,
195}; 207};
196 208
209static const struct regmap_config s2mps13_regmap_config = {
210 .reg_bits = 8,
211 .val_bits = 8,
212
213 .max_register = S2MPS13_REG_LDODSCH5,
214 .volatile_reg = s2mps11_volatile,
215 .cache_type = REGCACHE_FLAT,
216};
217
197static const struct regmap_config s2mps14_regmap_config = { 218static const struct regmap_config s2mps14_regmap_config = {
198 .reg_bits = 8, 219 .reg_bits = 8,
199 .val_bits = 8, 220 .val_bits = 8,
@@ -325,6 +346,9 @@ static int sec_pmic_probe(struct i2c_client *i2c,
325 case S2MPS11X: 346 case S2MPS11X:
326 regmap = &s2mps11_regmap_config; 347 regmap = &s2mps11_regmap_config;
327 break; 348 break;
349 case S2MPS13X:
350 regmap = &s2mps13_regmap_config;
351 break;
328 case S2MPS14X: 352 case S2MPS14X:
329 regmap = &s2mps14_regmap_config; 353 regmap = &s2mps14_regmap_config;
330 break; 354 break;
@@ -378,6 +402,10 @@ static int sec_pmic_probe(struct i2c_client *i2c,
378 sec_devs = s2mps11_devs; 402 sec_devs = s2mps11_devs;
379 num_sec_devs = ARRAY_SIZE(s2mps11_devs); 403 num_sec_devs = ARRAY_SIZE(s2mps11_devs);
380 break; 404 break;
405 case S2MPS13X:
406 sec_devs = s2mps13_devs;
407 num_sec_devs = ARRAY_SIZE(s2mps13_devs);
408 break;
381 case S2MPS14X: 409 case S2MPS14X:
382 sec_devs = s2mps14_devs; 410 sec_devs = s2mps14_devs;
383 num_sec_devs = ARRAY_SIZE(s2mps14_devs); 411 num_sec_devs = ARRAY_SIZE(s2mps14_devs);
@@ -432,15 +460,6 @@ static int sec_pmic_suspend(struct device *dev)
432 */ 460 */
433 disable_irq(sec_pmic->irq); 461 disable_irq(sec_pmic->irq);
434 462
435 switch (sec_pmic->device_type) {
436 case S2MPS14X:
437 case S2MPU02:
438 regulator_suspend_prepare(PM_SUSPEND_MEM);
439 break;
440 default:
441 break;
442 }
443
444 return 0; 463 return 0;
445} 464}
446 465
diff --git a/drivers/mfd/sec-irq.c b/drivers/mfd/sec-irq.c
index f9a57869e3ec..ba86a918c2da 100644
--- a/drivers/mfd/sec-irq.c
+++ b/drivers/mfd/sec-irq.c
@@ -389,14 +389,22 @@ static const struct regmap_irq_chip s2mps11_irq_chip = {
389 .ack_base = S2MPS11_REG_INT1, 389 .ack_base = S2MPS11_REG_INT1,
390}; 390};
391 391
392#define S2MPS1X_IRQ_CHIP_COMMON_DATA \
393 .irqs = s2mps14_irqs, \
394 .num_irqs = ARRAY_SIZE(s2mps14_irqs), \
395 .num_regs = 3, \
396 .status_base = S2MPS14_REG_INT1, \
397 .mask_base = S2MPS14_REG_INT1M, \
398 .ack_base = S2MPS14_REG_INT1 \
399
400static const struct regmap_irq_chip s2mps13_irq_chip = {
401 .name = "s2mps13",
402 S2MPS1X_IRQ_CHIP_COMMON_DATA,
403};
404
392static const struct regmap_irq_chip s2mps14_irq_chip = { 405static const struct regmap_irq_chip s2mps14_irq_chip = {
393 .name = "s2mps14", 406 .name = "s2mps14",
394 .irqs = s2mps14_irqs, 407 S2MPS1X_IRQ_CHIP_COMMON_DATA,
395 .num_irqs = ARRAY_SIZE(s2mps14_irqs),
396 .num_regs = 3,
397 .status_base = S2MPS14_REG_INT1,
398 .mask_base = S2MPS14_REG_INT1M,
399 .ack_base = S2MPS14_REG_INT1,
400}; 408};
401 409
402static const struct regmap_irq_chip s2mpu02_irq_chip = { 410static const struct regmap_irq_chip s2mpu02_irq_chip = {
@@ -452,6 +460,9 @@ int sec_irq_init(struct sec_pmic_dev *sec_pmic)
452 case S2MPS11X: 460 case S2MPS11X:
453 sec_irq_chip = &s2mps11_irq_chip; 461 sec_irq_chip = &s2mps11_irq_chip;
454 break; 462 break;
463 case S2MPS13X:
464 sec_irq_chip = &s2mps13_irq_chip;
465 break;
455 case S2MPS14X: 466 case S2MPS14X:
456 sec_irq_chip = &s2mps14_irq_chip; 467 sec_irq_chip = &s2mps14_irq_chip;
457 break; 468 break;
diff --git a/drivers/mfd/stmpe.h b/drivers/mfd/stmpe.h
index 2d045f26f193..bee0abf82040 100644
--- a/drivers/mfd/stmpe.h
+++ b/drivers/mfd/stmpe.h
@@ -269,7 +269,7 @@ int stmpe_remove(struct stmpe *stmpe);
269#define STMPE24XX_REG_CHIP_ID 0x80 269#define STMPE24XX_REG_CHIP_ID 0x80
270#define STMPE24XX_REG_IEGPIOR_LSB 0x18 270#define STMPE24XX_REG_IEGPIOR_LSB 0x18
271#define STMPE24XX_REG_ISGPIOR_MSB 0x19 271#define STMPE24XX_REG_ISGPIOR_MSB 0x19
272#define STMPE24XX_REG_GPMR_LSB 0xA5 272#define STMPE24XX_REG_GPMR_LSB 0xA4
273#define STMPE24XX_REG_GPSR_LSB 0x85 273#define STMPE24XX_REG_GPSR_LSB 0x85
274#define STMPE24XX_REG_GPCR_LSB 0x88 274#define STMPE24XX_REG_GPCR_LSB 0x88
275#define STMPE24XX_REG_GPDR_LSB 0x8B 275#define STMPE24XX_REG_GPDR_LSB 0x8B
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index ca15878ce5c0..72373b113885 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -15,6 +15,7 @@
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/list.h>
18#include <linux/of.h> 19#include <linux/of.h>
19#include <linux/of_address.h> 20#include <linux/of_address.h>
20#include <linux/of_platform.h> 21#include <linux/of_platform.h>
@@ -22,31 +23,94 @@
22#include <linux/platform_device.h> 23#include <linux/platform_device.h>
23#include <linux/regmap.h> 24#include <linux/regmap.h>
24#include <linux/mfd/syscon.h> 25#include <linux/mfd/syscon.h>
26#include <linux/slab.h>
25 27
26static struct platform_driver syscon_driver; 28static struct platform_driver syscon_driver;
27 29
30static DEFINE_SPINLOCK(syscon_list_slock);
31static LIST_HEAD(syscon_list);
32
28struct syscon { 33struct syscon {
34 struct device_node *np;
29 struct regmap *regmap; 35 struct regmap *regmap;
36 struct list_head list;
37};
38
39static struct regmap_config syscon_regmap_config = {
40 .reg_bits = 32,
41 .val_bits = 32,
42 .reg_stride = 4,
30}; 43};
31 44
32static int syscon_match_node(struct device *dev, void *data) 45static struct syscon *of_syscon_register(struct device_node *np)
33{ 46{
34 struct device_node *dn = data; 47 struct syscon *syscon;
48 struct regmap *regmap;
49 void __iomem *base;
50 int ret;
51 struct regmap_config syscon_config = syscon_regmap_config;
52
53 if (!of_device_is_compatible(np, "syscon"))
54 return ERR_PTR(-EINVAL);
55
56 syscon = kzalloc(sizeof(*syscon), GFP_KERNEL);
57 if (!syscon)
58 return ERR_PTR(-ENOMEM);
59
60 base = of_iomap(np, 0);
61 if (!base) {
62 ret = -ENOMEM;
63 goto err_map;
64 }
65
66 /* Parse the device's DT node for an endianness specification */
67 if (of_property_read_bool(np, "big-endian"))
68 syscon_config.val_format_endian = REGMAP_ENDIAN_BIG;
69 else if (of_property_read_bool(np, "little-endian"))
70 syscon_config.val_format_endian = REGMAP_ENDIAN_LITTLE;
71
72 regmap = regmap_init_mmio(NULL, base, &syscon_config);
73 if (IS_ERR(regmap)) {
74 pr_err("regmap init failed\n");
75 ret = PTR_ERR(regmap);
76 goto err_regmap;
77 }
78
79 syscon->regmap = regmap;
80 syscon->np = np;
81
82 spin_lock(&syscon_list_slock);
83 list_add_tail(&syscon->list, &syscon_list);
84 spin_unlock(&syscon_list_slock);
35 85
36 return (dev->of_node == dn) ? 1 : 0; 86 return syscon;
87
88err_regmap:
89 iounmap(base);
90err_map:
91 kfree(syscon);
92 return ERR_PTR(ret);
37} 93}
38 94
39struct regmap *syscon_node_to_regmap(struct device_node *np) 95struct regmap *syscon_node_to_regmap(struct device_node *np)
40{ 96{
41 struct syscon *syscon; 97 struct syscon *entry, *syscon = NULL;
42 struct device *dev;
43 98
44 dev = driver_find_device(&syscon_driver.driver, NULL, np, 99 spin_lock(&syscon_list_slock);
45 syscon_match_node);
46 if (!dev)
47 return ERR_PTR(-EPROBE_DEFER);
48 100
49 syscon = dev_get_drvdata(dev); 101 list_for_each_entry(entry, &syscon_list, list)
102 if (entry->np == np) {
103 syscon = entry;
104 break;
105 }
106
107 spin_unlock(&syscon_list_slock);
108
109 if (!syscon)
110 syscon = of_syscon_register(np);
111
112 if (IS_ERR(syscon))
113 return ERR_CAST(syscon);
50 114
51 return syscon->regmap; 115 return syscon->regmap;
52} 116}
@@ -110,17 +174,6 @@ struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np,
110} 174}
111EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_phandle); 175EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_phandle);
112 176
113static const struct of_device_id of_syscon_match[] = {
114 { .compatible = "syscon", },
115 { },
116};
117
118static struct regmap_config syscon_regmap_config = {
119 .reg_bits = 32,
120 .val_bits = 32,
121 .reg_stride = 4,
122};
123
124static int syscon_probe(struct platform_device *pdev) 177static int syscon_probe(struct platform_device *pdev)
125{ 178{
126 struct device *dev = &pdev->dev; 179 struct device *dev = &pdev->dev;
@@ -167,7 +220,6 @@ static struct platform_driver syscon_driver = {
167 .driver = { 220 .driver = {
168 .name = "syscon", 221 .name = "syscon",
169 .owner = THIS_MODULE, 222 .owner = THIS_MODULE,
170 .of_match_table = of_syscon_match,
171 }, 223 },
172 .probe = syscon_probe, 224 .probe = syscon_probe,
173 .id_table = syscon_ids, 225 .id_table = syscon_ids,
diff --git a/drivers/mfd/t7l66xb.c b/drivers/mfd/t7l66xb.c
index 9e04a7485981..439d905bb219 100644
--- a/drivers/mfd/t7l66xb.c
+++ b/drivers/mfd/t7l66xb.c
@@ -87,7 +87,7 @@ static int t7l66xb_mmc_enable(struct platform_device *mmc)
87 unsigned long flags; 87 unsigned long flags;
88 u8 dev_ctl; 88 u8 dev_ctl;
89 89
90 clk_enable(t7l66xb->clk32k); 90 clk_prepare_enable(t7l66xb->clk32k);
91 91
92 spin_lock_irqsave(&t7l66xb->lock, flags); 92 spin_lock_irqsave(&t7l66xb->lock, flags);
93 93
@@ -118,7 +118,7 @@ static int t7l66xb_mmc_disable(struct platform_device *mmc)
118 118
119 spin_unlock_irqrestore(&t7l66xb->lock, flags); 119 spin_unlock_irqrestore(&t7l66xb->lock, flags);
120 120
121 clk_disable(t7l66xb->clk32k); 121 clk_disable_unprepare(t7l66xb->clk32k);
122 122
123 return 0; 123 return 0;
124} 124}
@@ -285,7 +285,7 @@ static int t7l66xb_suspend(struct platform_device *dev, pm_message_t state)
285 285
286 if (pdata && pdata->suspend) 286 if (pdata && pdata->suspend)
287 pdata->suspend(dev); 287 pdata->suspend(dev);
288 clk_disable(t7l66xb->clk48m); 288 clk_disable_unprepare(t7l66xb->clk48m);
289 289
290 return 0; 290 return 0;
291} 291}
@@ -295,7 +295,7 @@ static int t7l66xb_resume(struct platform_device *dev)
295 struct t7l66xb *t7l66xb = platform_get_drvdata(dev); 295 struct t7l66xb *t7l66xb = platform_get_drvdata(dev);
296 struct t7l66xb_platform_data *pdata = dev_get_platdata(&dev->dev); 296 struct t7l66xb_platform_data *pdata = dev_get_platdata(&dev->dev);
297 297
298 clk_enable(t7l66xb->clk48m); 298 clk_prepare_enable(t7l66xb->clk48m);
299 if (pdata && pdata->resume) 299 if (pdata && pdata->resume)
300 pdata->resume(dev); 300 pdata->resume(dev);
301 301
@@ -369,7 +369,7 @@ static int t7l66xb_probe(struct platform_device *dev)
369 goto err_ioremap; 369 goto err_ioremap;
370 } 370 }
371 371
372 clk_enable(t7l66xb->clk48m); 372 clk_prepare_enable(t7l66xb->clk48m);
373 373
374 if (pdata && pdata->enable) 374 if (pdata && pdata->enable)
375 pdata->enable(dev); 375 pdata->enable(dev);
@@ -414,9 +414,9 @@ static int t7l66xb_remove(struct platform_device *dev)
414 int ret; 414 int ret;
415 415
416 ret = pdata->disable(dev); 416 ret = pdata->disable(dev);
417 clk_disable(t7l66xb->clk48m); 417 clk_disable_unprepare(t7l66xb->clk48m);
418 clk_put(t7l66xb->clk48m); 418 clk_put(t7l66xb->clk48m);
419 clk_disable(t7l66xb->clk32k); 419 clk_disable_unprepare(t7l66xb->clk32k);
420 clk_put(t7l66xb->clk32k); 420 clk_put(t7l66xb->clk32k);
421 t7l66xb_detach_irq(dev); 421 t7l66xb_detach_irq(dev);
422 iounmap(t7l66xb->scr); 422 iounmap(t7l66xb->scr);
diff --git a/drivers/mfd/tc3589x.c b/drivers/mfd/tc3589x.c
index 0072e668c208..aacb3720065c 100644
--- a/drivers/mfd/tc3589x.c
+++ b/drivers/mfd/tc3589x.c
@@ -241,10 +241,8 @@ static struct irq_domain_ops tc3589x_irq_ops = {
241 241
242static int tc3589x_irq_init(struct tc3589x *tc3589x, struct device_node *np) 242static int tc3589x_irq_init(struct tc3589x *tc3589x, struct device_node *np)
243{ 243{
244 int base = tc3589x->irq_base;
245
246 tc3589x->domain = irq_domain_add_simple( 244 tc3589x->domain = irq_domain_add_simple(
247 np, TC3589x_NR_INTERNAL_IRQS, base, 245 np, TC3589x_NR_INTERNAL_IRQS, 0,
248 &tc3589x_irq_ops, tc3589x); 246 &tc3589x_irq_ops, tc3589x);
249 247
250 if (!tc3589x->domain) { 248 if (!tc3589x->domain) {
@@ -298,7 +296,7 @@ static int tc3589x_device_init(struct tc3589x *tc3589x)
298 if (blocks & TC3589x_BLOCK_GPIO) { 296 if (blocks & TC3589x_BLOCK_GPIO) {
299 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_gpio, 297 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_gpio,
300 ARRAY_SIZE(tc3589x_dev_gpio), NULL, 298 ARRAY_SIZE(tc3589x_dev_gpio), NULL,
301 tc3589x->irq_base, tc3589x->domain); 299 0, tc3589x->domain);
302 if (ret) { 300 if (ret) {
303 dev_err(tc3589x->dev, "failed to add gpio child\n"); 301 dev_err(tc3589x->dev, "failed to add gpio child\n");
304 return ret; 302 return ret;
@@ -309,7 +307,7 @@ static int tc3589x_device_init(struct tc3589x *tc3589x)
309 if (blocks & TC3589x_BLOCK_KEYPAD) { 307 if (blocks & TC3589x_BLOCK_KEYPAD) {
310 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_keypad, 308 ret = mfd_add_devices(tc3589x->dev, -1, tc3589x_dev_keypad,
311 ARRAY_SIZE(tc3589x_dev_keypad), NULL, 309 ARRAY_SIZE(tc3589x_dev_keypad), NULL,
312 tc3589x->irq_base, tc3589x->domain); 310 0, tc3589x->domain);
313 if (ret) { 311 if (ret) {
314 dev_err(tc3589x->dev, "failed to keypad child\n"); 312 dev_err(tc3589x->dev, "failed to keypad child\n");
315 return ret; 313 return ret;
@@ -404,7 +402,6 @@ static int tc3589x_probe(struct i2c_client *i2c,
404 tc3589x->dev = &i2c->dev; 402 tc3589x->dev = &i2c->dev;
405 tc3589x->i2c = i2c; 403 tc3589x->i2c = i2c;
406 tc3589x->pdata = pdata; 404 tc3589x->pdata = pdata;
407 tc3589x->irq_base = pdata->irq_base;
408 405
409 switch (version) { 406 switch (version) {
410 case TC3589X_TC35893: 407 case TC3589X_TC35893:
diff --git a/drivers/mfd/tc6387xb.c b/drivers/mfd/tc6387xb.c
index e71f88000ae5..85fab3729102 100644
--- a/drivers/mfd/tc6387xb.c
+++ b/drivers/mfd/tc6387xb.c
@@ -52,7 +52,7 @@ static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state)
52 52
53 if (pdata && pdata->suspend) 53 if (pdata && pdata->suspend)
54 pdata->suspend(dev); 54 pdata->suspend(dev);
55 clk_disable(tc6387xb->clk32k); 55 clk_disable_unprepare(tc6387xb->clk32k);
56 56
57 return 0; 57 return 0;
58} 58}
@@ -62,7 +62,7 @@ static int tc6387xb_resume(struct platform_device *dev)
62 struct tc6387xb *tc6387xb = platform_get_drvdata(dev); 62 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
63 struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev); 63 struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
64 64
65 clk_enable(tc6387xb->clk32k); 65 clk_prepare_enable(tc6387xb->clk32k);
66 if (pdata && pdata->resume) 66 if (pdata && pdata->resume)
67 pdata->resume(dev); 67 pdata->resume(dev);
68 68
@@ -100,7 +100,7 @@ static int tc6387xb_mmc_enable(struct platform_device *mmc)
100 struct platform_device *dev = to_platform_device(mmc->dev.parent); 100 struct platform_device *dev = to_platform_device(mmc->dev.parent);
101 struct tc6387xb *tc6387xb = platform_get_drvdata(dev); 101 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
102 102
103 clk_enable(tc6387xb->clk32k); 103 clk_prepare_enable(tc6387xb->clk32k);
104 104
105 tmio_core_mmc_enable(tc6387xb->scr + 0x200, 0, 105 tmio_core_mmc_enable(tc6387xb->scr + 0x200, 0,
106 tc6387xb_mmc_resources[0].start & 0xfffe); 106 tc6387xb_mmc_resources[0].start & 0xfffe);
@@ -113,7 +113,7 @@ static int tc6387xb_mmc_disable(struct platform_device *mmc)
113 struct platform_device *dev = to_platform_device(mmc->dev.parent); 113 struct platform_device *dev = to_platform_device(mmc->dev.parent);
114 struct tc6387xb *tc6387xb = platform_get_drvdata(dev); 114 struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
115 115
116 clk_disable(tc6387xb->clk32k); 116 clk_disable_unprepare(tc6387xb->clk32k);
117 117
118 return 0; 118 return 0;
119} 119}
@@ -214,7 +214,7 @@ static int tc6387xb_remove(struct platform_device *dev)
214 mfd_remove_devices(&dev->dev); 214 mfd_remove_devices(&dev->dev);
215 iounmap(tc6387xb->scr); 215 iounmap(tc6387xb->scr);
216 release_resource(&tc6387xb->rscr); 216 release_resource(&tc6387xb->rscr);
217 clk_disable(tc6387xb->clk32k); 217 clk_disable_unprepare(tc6387xb->clk32k);
218 clk_put(tc6387xb->clk32k); 218 clk_put(tc6387xb->clk32k);
219 kfree(tc6387xb); 219 kfree(tc6387xb);
220 220
diff --git a/drivers/mfd/tc6393xb.c b/drivers/mfd/tc6393xb.c
index 4fac16bcd732..d35f11fbeab7 100644
--- a/drivers/mfd/tc6393xb.c
+++ b/drivers/mfd/tc6393xb.c
@@ -263,6 +263,17 @@ static int tc6393xb_ohci_disable(struct platform_device *dev)
263 return 0; 263 return 0;
264} 264}
265 265
266static int tc6393xb_ohci_suspend(struct platform_device *dev)
267{
268 struct tc6393xb_platform_data *tcpd = dev_get_platdata(dev->dev.parent);
269
270 /* We can't properly store/restore OHCI state, so fail here */
271 if (tcpd->resume_restore)
272 return -EBUSY;
273
274 return tc6393xb_ohci_disable(dev);
275}
276
266static int tc6393xb_fb_enable(struct platform_device *dev) 277static int tc6393xb_fb_enable(struct platform_device *dev)
267{ 278{
268 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent); 279 struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
@@ -403,7 +414,7 @@ static struct mfd_cell tc6393xb_cells[] = {
403 .num_resources = ARRAY_SIZE(tc6393xb_ohci_resources), 414 .num_resources = ARRAY_SIZE(tc6393xb_ohci_resources),
404 .resources = tc6393xb_ohci_resources, 415 .resources = tc6393xb_ohci_resources,
405 .enable = tc6393xb_ohci_enable, 416 .enable = tc6393xb_ohci_enable,
406 .suspend = tc6393xb_ohci_disable, 417 .suspend = tc6393xb_ohci_suspend,
407 .resume = tc6393xb_ohci_enable, 418 .resume = tc6393xb_ohci_enable,
408 .disable = tc6393xb_ohci_disable, 419 .disable = tc6393xb_ohci_disable,
409 }, 420 },
@@ -654,7 +665,7 @@ static int tc6393xb_probe(struct platform_device *dev)
654 goto err_ioremap; 665 goto err_ioremap;
655 } 666 }
656 667
657 ret = clk_enable(tc6393xb->clk); 668 ret = clk_prepare_enable(tc6393xb->clk);
658 if (ret) 669 if (ret)
659 goto err_clk_enable; 670 goto err_clk_enable;
660 671
@@ -717,7 +728,7 @@ err_gpio_add:
717 gpiochip_remove(&tc6393xb->gpio); 728 gpiochip_remove(&tc6393xb->gpio);
718 tcpd->disable(dev); 729 tcpd->disable(dev);
719err_enable: 730err_enable:
720 clk_disable(tc6393xb->clk); 731 clk_disable_unprepare(tc6393xb->clk);
721err_clk_enable: 732err_clk_enable:
722 iounmap(tc6393xb->scr); 733 iounmap(tc6393xb->scr);
723err_ioremap: 734err_ioremap:
@@ -748,7 +759,7 @@ static int tc6393xb_remove(struct platform_device *dev)
748 gpiochip_remove(&tc6393xb->gpio); 759 gpiochip_remove(&tc6393xb->gpio);
749 760
750 ret = tcpd->disable(dev); 761 ret = tcpd->disable(dev);
751 clk_disable(tc6393xb->clk); 762 clk_disable_unprepare(tc6393xb->clk);
752 iounmap(tc6393xb->scr); 763 iounmap(tc6393xb->scr);
753 release_resource(&tc6393xb->rscr); 764 release_resource(&tc6393xb->rscr);
754 clk_put(tc6393xb->clk); 765 clk_put(tc6393xb->clk);
@@ -776,7 +787,7 @@ static int tc6393xb_suspend(struct platform_device *dev, pm_message_t state)
776 ioread8(tc6393xb->scr + SCR_GPI_BCR(i)); 787 ioread8(tc6393xb->scr + SCR_GPI_BCR(i));
777 } 788 }
778 ret = tcpd->suspend(dev); 789 ret = tcpd->suspend(dev);
779 clk_disable(tc6393xb->clk); 790 clk_disable_unprepare(tc6393xb->clk);
780 791
781 return ret; 792 return ret;
782} 793}
@@ -788,7 +799,7 @@ static int tc6393xb_resume(struct platform_device *dev)
788 int ret; 799 int ret;
789 int i; 800 int i;
790 801
791 clk_enable(tc6393xb->clk); 802 clk_prepare_enable(tc6393xb->clk);
792 803
793 ret = tcpd->resume(dev); 804 ret = tcpd->resume(dev);
794 if (ret) 805 if (ret)
diff --git a/drivers/mfd/tps65090.c b/drivers/mfd/tps65090.c
index 1c3e6e2efe41..14b62e11aff4 100644
--- a/drivers/mfd/tps65090.c
+++ b/drivers/mfd/tps65090.c
@@ -76,58 +76,58 @@ static struct mfd_cell tps65090s[] = {
76static const struct regmap_irq tps65090_irqs[] = { 76static const struct regmap_irq tps65090_irqs[] = {
77 /* INT1 IRQs*/ 77 /* INT1 IRQs*/
78 [TPS65090_IRQ_VAC_STATUS_CHANGE] = { 78 [TPS65090_IRQ_VAC_STATUS_CHANGE] = {
79 .mask = TPS65090_INT1_MASK_VAC_STATUS_CHANGE, 79 .mask = TPS65090_INT1_MASK_VAC_STATUS_CHANGE,
80 }, 80 },
81 [TPS65090_IRQ_VSYS_STATUS_CHANGE] = { 81 [TPS65090_IRQ_VSYS_STATUS_CHANGE] = {
82 .mask = TPS65090_INT1_MASK_VSYS_STATUS_CHANGE, 82 .mask = TPS65090_INT1_MASK_VSYS_STATUS_CHANGE,
83 }, 83 },
84 [TPS65090_IRQ_BAT_STATUS_CHANGE] = { 84 [TPS65090_IRQ_BAT_STATUS_CHANGE] = {
85 .mask = TPS65090_INT1_MASK_BAT_STATUS_CHANGE, 85 .mask = TPS65090_INT1_MASK_BAT_STATUS_CHANGE,
86 }, 86 },
87 [TPS65090_IRQ_CHARGING_STATUS_CHANGE] = { 87 [TPS65090_IRQ_CHARGING_STATUS_CHANGE] = {
88 .mask = TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE, 88 .mask = TPS65090_INT1_MASK_CHARGING_STATUS_CHANGE,
89 }, 89 },
90 [TPS65090_IRQ_CHARGING_COMPLETE] = { 90 [TPS65090_IRQ_CHARGING_COMPLETE] = {
91 .mask = TPS65090_INT1_MASK_CHARGING_COMPLETE, 91 .mask = TPS65090_INT1_MASK_CHARGING_COMPLETE,
92 }, 92 },
93 [TPS65090_IRQ_OVERLOAD_DCDC1] = { 93 [TPS65090_IRQ_OVERLOAD_DCDC1] = {
94 .mask = TPS65090_INT1_MASK_OVERLOAD_DCDC1, 94 .mask = TPS65090_INT1_MASK_OVERLOAD_DCDC1,
95 }, 95 },
96 [TPS65090_IRQ_OVERLOAD_DCDC2] = { 96 [TPS65090_IRQ_OVERLOAD_DCDC2] = {
97 .mask = TPS65090_INT1_MASK_OVERLOAD_DCDC2, 97 .mask = TPS65090_INT1_MASK_OVERLOAD_DCDC2,
98 }, 98 },
99 /* INT2 IRQs*/ 99 /* INT2 IRQs*/
100 [TPS65090_IRQ_OVERLOAD_DCDC3] = { 100 [TPS65090_IRQ_OVERLOAD_DCDC3] = {
101 .reg_offset = 1, 101 .reg_offset = 1,
102 .mask = TPS65090_INT2_MASK_OVERLOAD_DCDC3, 102 .mask = TPS65090_INT2_MASK_OVERLOAD_DCDC3,
103 }, 103 },
104 [TPS65090_IRQ_OVERLOAD_FET1] = { 104 [TPS65090_IRQ_OVERLOAD_FET1] = {
105 .reg_offset = 1, 105 .reg_offset = 1,
106 .mask = TPS65090_INT2_MASK_OVERLOAD_FET1, 106 .mask = TPS65090_INT2_MASK_OVERLOAD_FET1,
107 }, 107 },
108 [TPS65090_IRQ_OVERLOAD_FET2] = { 108 [TPS65090_IRQ_OVERLOAD_FET2] = {
109 .reg_offset = 1, 109 .reg_offset = 1,
110 .mask = TPS65090_INT2_MASK_OVERLOAD_FET2, 110 .mask = TPS65090_INT2_MASK_OVERLOAD_FET2,
111 }, 111 },
112 [TPS65090_IRQ_OVERLOAD_FET3] = { 112 [TPS65090_IRQ_OVERLOAD_FET3] = {
113 .reg_offset = 1, 113 .reg_offset = 1,
114 .mask = TPS65090_INT2_MASK_OVERLOAD_FET3, 114 .mask = TPS65090_INT2_MASK_OVERLOAD_FET3,
115 }, 115 },
116 [TPS65090_IRQ_OVERLOAD_FET4] = { 116 [TPS65090_IRQ_OVERLOAD_FET4] = {
117 .reg_offset = 1, 117 .reg_offset = 1,
118 .mask = TPS65090_INT2_MASK_OVERLOAD_FET4, 118 .mask = TPS65090_INT2_MASK_OVERLOAD_FET4,
119 }, 119 },
120 [TPS65090_IRQ_OVERLOAD_FET5] = { 120 [TPS65090_IRQ_OVERLOAD_FET5] = {
121 .reg_offset = 1, 121 .reg_offset = 1,
122 .mask = TPS65090_INT2_MASK_OVERLOAD_FET5, 122 .mask = TPS65090_INT2_MASK_OVERLOAD_FET5,
123 }, 123 },
124 [TPS65090_IRQ_OVERLOAD_FET6] = { 124 [TPS65090_IRQ_OVERLOAD_FET6] = {
125 .reg_offset = 1, 125 .reg_offset = 1,
126 .mask = TPS65090_INT2_MASK_OVERLOAD_FET6, 126 .mask = TPS65090_INT2_MASK_OVERLOAD_FET6,
127 }, 127 },
128 [TPS65090_IRQ_OVERLOAD_FET7] = { 128 [TPS65090_IRQ_OVERLOAD_FET7] = {
129 .reg_offset = 1, 129 .reg_offset = 1,
130 .mask = TPS65090_INT2_MASK_OVERLOAD_FET7, 130 .mask = TPS65090_INT2_MASK_OVERLOAD_FET7,
131 }, 131 },
132}; 132};
133 133
@@ -176,7 +176,7 @@ MODULE_DEVICE_TABLE(of, tps65090_of_match);
176#endif 176#endif
177 177
178static int tps65090_i2c_probe(struct i2c_client *client, 178static int tps65090_i2c_probe(struct i2c_client *client,
179 const struct i2c_device_id *id) 179 const struct i2c_device_id *id)
180{ 180{
181 struct tps65090_platform_data *pdata = dev_get_platdata(&client->dev); 181 struct tps65090_platform_data *pdata = dev_get_platdata(&client->dev);
182 int irq_base = 0; 182 int irq_base = 0;
@@ -210,11 +210,11 @@ static int tps65090_i2c_probe(struct i2c_client *client,
210 210
211 if (client->irq) { 211 if (client->irq) {
212 ret = regmap_add_irq_chip(tps65090->rmap, client->irq, 212 ret = regmap_add_irq_chip(tps65090->rmap, client->irq,
213 IRQF_ONESHOT | IRQF_TRIGGER_LOW, irq_base, 213 IRQF_ONESHOT | IRQF_TRIGGER_LOW, irq_base,
214 &tps65090_irq_chip, &tps65090->irq_data); 214 &tps65090_irq_chip, &tps65090->irq_data);
215 if (ret) { 215 if (ret) {
216 dev_err(&client->dev, 216 dev_err(&client->dev,
217 "IRQ init failed with err: %d\n", ret); 217 "IRQ init failed with err: %d\n", ret);
218 return ret; 218 return ret;
219 } 219 }
220 } else { 220 } else {
@@ -223,8 +223,8 @@ static int tps65090_i2c_probe(struct i2c_client *client,
223 } 223 }
224 224
225 ret = mfd_add_devices(tps65090->dev, -1, tps65090s, 225 ret = mfd_add_devices(tps65090->dev, -1, tps65090s,
226 ARRAY_SIZE(tps65090s), NULL, 226 ARRAY_SIZE(tps65090s), NULL,
227 0, regmap_irq_get_domain(tps65090->irq_data)); 227 0, regmap_irq_get_domain(tps65090->irq_data));
228 if (ret) { 228 if (ret) {
229 dev_err(&client->dev, "add mfd devices failed with err: %d\n", 229 dev_err(&client->dev, "add mfd devices failed with err: %d\n",
230 ret); 230 ret);
diff --git a/drivers/mfd/tps65217.c b/drivers/mfd/tps65217.c
index a8ee52c95f2f..80a919a8ca97 100644
--- a/drivers/mfd/tps65217.c
+++ b/drivers/mfd/tps65217.c
@@ -33,9 +33,11 @@
33static const struct mfd_cell tps65217s[] = { 33static const struct mfd_cell tps65217s[] = {
34 { 34 {
35 .name = "tps65217-pmic", 35 .name = "tps65217-pmic",
36 .of_compatible = "ti,tps65217-pmic",
36 }, 37 },
37 { 38 {
38 .name = "tps65217-bl", 39 .name = "tps65217-bl",
40 .of_compatible = "ti,tps65217-bl",
39 }, 41 },
40}; 42};
41 43
diff --git a/drivers/mfd/twl4030-power.c b/drivers/mfd/twl4030-power.c
index cf92a6d1c532..7d63e324e6a8 100644
--- a/drivers/mfd/twl4030-power.c
+++ b/drivers/mfd/twl4030-power.c
@@ -44,6 +44,15 @@ static u8 twl4030_start_script_address = 0x2b;
44#define PWR_DEVSLP BIT(1) 44#define PWR_DEVSLP BIT(1)
45#define PWR_DEVOFF BIT(0) 45#define PWR_DEVOFF BIT(0)
46 46
47/* Register bits for CFG_P1_TRANSITION (also for P2 and P3) */
48#define STARTON_SWBUG BIT(7) /* Start on watchdog */
49#define STARTON_VBUS BIT(5) /* Start on VBUS */
50#define STARTON_VBAT BIT(4) /* Start on battery insert */
51#define STARTON_RTC BIT(3) /* Start on RTC */
52#define STARTON_USB BIT(2) /* Start on USB host */
53#define STARTON_CHG BIT(1) /* Start on charger */
54#define STARTON_PWON BIT(0) /* Start on PWRON button */
55
47#define SEQ_OFFSYNC (1 << 0) 56#define SEQ_OFFSYNC (1 << 0)
48 57
49#define PHY_TO_OFF_PM_MASTER(p) (p - 0x36) 58#define PHY_TO_OFF_PM_MASTER(p) (p - 0x36)
@@ -606,6 +615,44 @@ twl4030_power_configure_resources(const struct twl4030_power_data *pdata)
606 return 0; 615 return 0;
607} 616}
608 617
618static int twl4030_starton_mask_and_set(u8 bitmask, u8 bitvalues)
619{
620 u8 regs[3] = { TWL4030_PM_MASTER_CFG_P1_TRANSITION,
621 TWL4030_PM_MASTER_CFG_P2_TRANSITION,
622 TWL4030_PM_MASTER_CFG_P3_TRANSITION, };
623 u8 val;
624 int i, err;
625
626 err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, TWL4030_PM_MASTER_KEY_CFG1,
627 TWL4030_PM_MASTER_PROTECT_KEY);
628 if (err)
629 goto relock;
630 err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
631 TWL4030_PM_MASTER_KEY_CFG2,
632 TWL4030_PM_MASTER_PROTECT_KEY);
633 if (err)
634 goto relock;
635
636 for (i = 0; i < sizeof(regs); i++) {
637 err = twl_i2c_read_u8(TWL_MODULE_PM_MASTER,
638 &val, regs[i]);
639 if (err)
640 break;
641 val = (~bitmask & val) | (bitmask & bitvalues);
642 err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER,
643 val, regs[i]);
644 if (err)
645 break;
646 }
647
648 if (err)
649 pr_err("TWL4030 Register access failed: %i\n", err);
650
651relock:
652 return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, 0,
653 TWL4030_PM_MASTER_PROTECT_KEY);
654}
655
609/* 656/*
610 * In master mode, start the power off sequence. 657 * In master mode, start the power off sequence.
611 * After a successful execution, TWL shuts down the power to the SoC 658 * After a successful execution, TWL shuts down the power to the SoC
@@ -615,6 +662,11 @@ void twl4030_power_off(void)
615{ 662{
616 int err; 663 int err;
617 664
665 /* Disable start on charger or VBUS as it can break poweroff */
666 err = twl4030_starton_mask_and_set(STARTON_VBUS | STARTON_CHG, 0);
667 if (err)
668 pr_err("TWL4030 Unable to configure start-up\n");
669
618 err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, PWR_DEVOFF, 670 err = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, PWR_DEVOFF,
619 TWL4030_PM_MASTER_P1_SW_EVENTS); 671 TWL4030_PM_MASTER_P1_SW_EVENTS);
620 if (err) 672 if (err)
@@ -779,6 +831,9 @@ static struct twl4030_power_data osc_off_idle = {
779 831
780static struct of_device_id twl4030_power_of_match[] = { 832static struct of_device_id twl4030_power_of_match[] = {
781 { 833 {
834 .compatible = "ti,twl4030-power",
835 },
836 {
782 .compatible = "ti,twl4030-power-reset", 837 .compatible = "ti,twl4030-power-reset",
783 .data = &omap3_reset, 838 .data = &omap3_reset,
784 }, 839 },
diff --git a/drivers/mfd/viperboard.c b/drivers/mfd/viperboard.c
index e00f5340ed87..e6b3c70aeb22 100644
--- a/drivers/mfd/viperboard.c
+++ b/drivers/mfd/viperboard.c
@@ -93,8 +93,8 @@ static int vprbrd_probe(struct usb_interface *interface,
93 version >> 8, version & 0xff, 93 version >> 8, version & 0xff,
94 vb->usb_dev->bus->busnum, vb->usb_dev->devnum); 94 vb->usb_dev->bus->busnum, vb->usb_dev->devnum);
95 95
96 ret = mfd_add_devices(&interface->dev, -1, vprbrd_devs, 96 ret = mfd_add_hotplug_devices(&interface->dev, vprbrd_devs,
97 ARRAY_SIZE(vprbrd_devs), NULL, 0, NULL); 97 ARRAY_SIZE(vprbrd_devs));
98 if (ret != 0) { 98 if (ret != 0) {
99 dev_err(&interface->dev, "Failed to add mfd devices to core."); 99 dev_err(&interface->dev, "Failed to add mfd devices to core.");
100 goto error; 100 goto error;
diff --git a/drivers/mfd/wm5102-tables.c b/drivers/mfd/wm5102-tables.c
index d6f35bbf795b..b326a82017ee 100644
--- a/drivers/mfd/wm5102-tables.c
+++ b/drivers/mfd/wm5102-tables.c
@@ -336,8 +336,6 @@ static const struct reg_default wm5102_reg_default[] = {
336 { 0x00000218, 0x01A6 }, /* R536 - Mic Bias Ctrl 1 */ 336 { 0x00000218, 0x01A6 }, /* R536 - Mic Bias Ctrl 1 */
337 { 0x00000219, 0x01A6 }, /* R537 - Mic Bias Ctrl 2 */ 337 { 0x00000219, 0x01A6 }, /* R537 - Mic Bias Ctrl 2 */
338 { 0x0000021A, 0x01A6 }, /* R538 - Mic Bias Ctrl 3 */ 338 { 0x0000021A, 0x01A6 }, /* R538 - Mic Bias Ctrl 3 */
339 { 0x00000225, 0x0400 }, /* R549 - HP Ctrl 1L */
340 { 0x00000226, 0x0400 }, /* R550 - HP Ctrl 1R */
341 { 0x00000293, 0x0000 }, /* R659 - Accessory Detect Mode 1 */ 339 { 0x00000293, 0x0000 }, /* R659 - Accessory Detect Mode 1 */
342 { 0x0000029B, 0x0020 }, /* R667 - Headphone Detect 1 */ 340 { 0x0000029B, 0x0020 }, /* R667 - Headphone Detect 1 */
343 { 0x0000029C, 0x0000 }, /* R668 - Headphone Detect 2 */ 341 { 0x0000029C, 0x0000 }, /* R668 - Headphone Detect 2 */
@@ -1112,6 +1110,8 @@ static bool wm5102_readable_register(struct device *dev, unsigned int reg)
1112 case ARIZONA_MIC_BIAS_CTRL_1: 1110 case ARIZONA_MIC_BIAS_CTRL_1:
1113 case ARIZONA_MIC_BIAS_CTRL_2: 1111 case ARIZONA_MIC_BIAS_CTRL_2:
1114 case ARIZONA_MIC_BIAS_CTRL_3: 1112 case ARIZONA_MIC_BIAS_CTRL_3:
1113 case ARIZONA_HP_CTRL_1L:
1114 case ARIZONA_HP_CTRL_1R:
1115 case ARIZONA_ACCESSORY_DETECT_MODE_1: 1115 case ARIZONA_ACCESSORY_DETECT_MODE_1:
1116 case ARIZONA_HEADPHONE_DETECT_1: 1116 case ARIZONA_HEADPHONE_DETECT_1:
1117 case ARIZONA_HEADPHONE_DETECT_2: 1117 case ARIZONA_HEADPHONE_DETECT_2:
@@ -1949,6 +1949,8 @@ static bool wm5102_volatile_register(struct device *dev, unsigned int reg)
1949 case ARIZONA_DSP1_SCRATCH_1: 1949 case ARIZONA_DSP1_SCRATCH_1:
1950 case ARIZONA_DSP1_SCRATCH_2: 1950 case ARIZONA_DSP1_SCRATCH_2:
1951 case ARIZONA_DSP1_SCRATCH_3: 1951 case ARIZONA_DSP1_SCRATCH_3:
1952 case ARIZONA_HP_CTRL_1L:
1953 case ARIZONA_HP_CTRL_1R:
1952 case ARIZONA_HEADPHONE_DETECT_2: 1954 case ARIZONA_HEADPHONE_DETECT_2:
1953 case ARIZONA_HP_DACVAL: 1955 case ARIZONA_HP_DACVAL:
1954 case ARIZONA_MIC_DETECT_3: 1956 case ARIZONA_MIC_DETECT_3:
diff --git a/drivers/mfd/wm5110-tables.c b/drivers/mfd/wm5110-tables.c
index 4642b5b816a0..12cad94b4035 100644
--- a/drivers/mfd/wm5110-tables.c
+++ b/drivers/mfd/wm5110-tables.c
@@ -895,8 +895,16 @@ static const struct reg_default wm5110_reg_default[] = {
895 { 0x00000548, 0x1818 }, /* R1352 - AIF2 Frame Ctrl 2 */ 895 { 0x00000548, 0x1818 }, /* R1352 - AIF2 Frame Ctrl 2 */
896 { 0x00000549, 0x0000 }, /* R1353 - AIF2 Frame Ctrl 3 */ 896 { 0x00000549, 0x0000 }, /* R1353 - AIF2 Frame Ctrl 3 */
897 { 0x0000054A, 0x0001 }, /* R1354 - AIF2 Frame Ctrl 4 */ 897 { 0x0000054A, 0x0001 }, /* R1354 - AIF2 Frame Ctrl 4 */
898 { 0x0000054B, 0x0002 }, /* R1355 - AIF2 Frame Ctrl 5 */
899 { 0x0000054C, 0x0003 }, /* R1356 - AIF2 Frame Ctrl 6 */
900 { 0x0000054D, 0x0004 }, /* R1357 - AIF2 Frame Ctrl 7 */
901 { 0x0000054E, 0x0005 }, /* R1358 - AIF2 Frame Ctrl 8 */
898 { 0x00000551, 0x0000 }, /* R1361 - AIF2 Frame Ctrl 11 */ 902 { 0x00000551, 0x0000 }, /* R1361 - AIF2 Frame Ctrl 11 */
899 { 0x00000552, 0x0001 }, /* R1362 - AIF2 Frame Ctrl 12 */ 903 { 0x00000552, 0x0001 }, /* R1362 - AIF2 Frame Ctrl 12 */
904 { 0x00000553, 0x0002 }, /* R1363 - AIF2 Frame Ctrl 13 */
905 { 0x00000554, 0x0003 }, /* R1364 - AIF2 Frame Ctrl 14 */
906 { 0x00000555, 0x0004 }, /* R1365 - AIF2 Frame Ctrl 15 */
907 { 0x00000556, 0x0005 }, /* R1366 - AIF2 Frame Ctrl 16 */
900 { 0x00000559, 0x0000 }, /* R1369 - AIF2 Tx Enables */ 908 { 0x00000559, 0x0000 }, /* R1369 - AIF2 Tx Enables */
901 { 0x0000055A, 0x0000 }, /* R1370 - AIF2 Rx Enables */ 909 { 0x0000055A, 0x0000 }, /* R1370 - AIF2 Rx Enables */
902 { 0x00000580, 0x000C }, /* R1408 - AIF3 BCLK Ctrl */ 910 { 0x00000580, 0x000C }, /* R1408 - AIF3 BCLK Ctrl */
@@ -1790,6 +1798,8 @@ static bool wm5110_readable_register(struct device *dev, unsigned int reg)
1790 case ARIZONA_MIC_BIAS_CTRL_1: 1798 case ARIZONA_MIC_BIAS_CTRL_1:
1791 case ARIZONA_MIC_BIAS_CTRL_2: 1799 case ARIZONA_MIC_BIAS_CTRL_2:
1792 case ARIZONA_MIC_BIAS_CTRL_3: 1800 case ARIZONA_MIC_BIAS_CTRL_3:
1801 case ARIZONA_HP_CTRL_1L:
1802 case ARIZONA_HP_CTRL_1R:
1793 case ARIZONA_ACCESSORY_DETECT_MODE_1: 1803 case ARIZONA_ACCESSORY_DETECT_MODE_1:
1794 case ARIZONA_HEADPHONE_DETECT_1: 1804 case ARIZONA_HEADPHONE_DETECT_1:
1795 case ARIZONA_HEADPHONE_DETECT_2: 1805 case ARIZONA_HEADPHONE_DETECT_2:
@@ -1934,8 +1944,16 @@ static bool wm5110_readable_register(struct device *dev, unsigned int reg)
1934 case ARIZONA_AIF2_FRAME_CTRL_2: 1944 case ARIZONA_AIF2_FRAME_CTRL_2:
1935 case ARIZONA_AIF2_FRAME_CTRL_3: 1945 case ARIZONA_AIF2_FRAME_CTRL_3:
1936 case ARIZONA_AIF2_FRAME_CTRL_4: 1946 case ARIZONA_AIF2_FRAME_CTRL_4:
1947 case ARIZONA_AIF2_FRAME_CTRL_5:
1948 case ARIZONA_AIF2_FRAME_CTRL_6:
1949 case ARIZONA_AIF2_FRAME_CTRL_7:
1950 case ARIZONA_AIF2_FRAME_CTRL_8:
1937 case ARIZONA_AIF2_FRAME_CTRL_11: 1951 case ARIZONA_AIF2_FRAME_CTRL_11:
1938 case ARIZONA_AIF2_FRAME_CTRL_12: 1952 case ARIZONA_AIF2_FRAME_CTRL_12:
1953 case ARIZONA_AIF2_FRAME_CTRL_13:
1954 case ARIZONA_AIF2_FRAME_CTRL_14:
1955 case ARIZONA_AIF2_FRAME_CTRL_15:
1956 case ARIZONA_AIF2_FRAME_CTRL_16:
1939 case ARIZONA_AIF2_TX_ENABLES: 1957 case ARIZONA_AIF2_TX_ENABLES:
1940 case ARIZONA_AIF2_RX_ENABLES: 1958 case ARIZONA_AIF2_RX_ENABLES:
1941 case ARIZONA_AIF3_BCLK_CTRL: 1959 case ARIZONA_AIF3_BCLK_CTRL:
@@ -2825,6 +2843,8 @@ static bool wm5110_volatile_register(struct device *dev, unsigned int reg)
2825 case ARIZONA_ASYNC_SAMPLE_RATE_1_STATUS: 2843 case ARIZONA_ASYNC_SAMPLE_RATE_1_STATUS:
2826 case ARIZONA_ASYNC_SAMPLE_RATE_2_STATUS: 2844 case ARIZONA_ASYNC_SAMPLE_RATE_2_STATUS:
2827 case ARIZONA_MIC_DETECT_3: 2845 case ARIZONA_MIC_DETECT_3:
2846 case ARIZONA_HP_CTRL_1L:
2847 case ARIZONA_HP_CTRL_1R:
2828 case ARIZONA_HEADPHONE_DETECT_2: 2848 case ARIZONA_HEADPHONE_DETECT_2:
2829 case ARIZONA_INPUT_ENABLES_STATUS: 2849 case ARIZONA_INPUT_ENABLES_STATUS:
2830 case ARIZONA_OUTPUT_STATUS_1: 2850 case ARIZONA_OUTPUT_STATUS_1:
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c
index 4ab527f5c53b..f5124a8acad8 100644
--- a/drivers/mfd/wm8350-core.c
+++ b/drivers/mfd/wm8350-core.c
@@ -308,7 +308,7 @@ int wm8350_device_init(struct wm8350 *wm8350, int irq,
308 goto err; 308 goto err;
309 } 309 }
310 310
311 mode = id2 & WM8350_CONF_STS_MASK >> 10; 311 mode = (id2 & WM8350_CONF_STS_MASK) >> 10;
312 cust_id = id2 & WM8350_CUST_ID_MASK; 312 cust_id = id2 & WM8350_CUST_ID_MASK;
313 chip_rev = (id2 & WM8350_CHIP_REV_MASK) >> 12; 313 chip_rev = (id2 & WM8350_CHIP_REV_MASK) >> 12;
314 dev_info(wm8350->dev, 314 dev_info(wm8350->dev,
diff --git a/drivers/mfd/wm8997-tables.c b/drivers/mfd/wm8997-tables.c
index 510da3b52324..c0c25d75aacc 100644
--- a/drivers/mfd/wm8997-tables.c
+++ b/drivers/mfd/wm8997-tables.c
@@ -670,6 +670,7 @@ static const struct reg_default wm8997_reg_default[] = {
670 { 0x00000C23, 0x0000 }, /* R3107 - Misc Pad Ctrl 4 */ 670 { 0x00000C23, 0x0000 }, /* R3107 - Misc Pad Ctrl 4 */
671 { 0x00000C24, 0x0000 }, /* R3108 - Misc Pad Ctrl 5 */ 671 { 0x00000C24, 0x0000 }, /* R3108 - Misc Pad Ctrl 5 */
672 { 0x00000D08, 0xFFFF }, /* R3336 - Interrupt Status 1 Mask */ 672 { 0x00000D08, 0xFFFF }, /* R3336 - Interrupt Status 1 Mask */
673 { 0x00000D09, 0xFFFF }, /* R3337 - Interrupt Status 2 Mask */
673 { 0x00000D0A, 0xFFFF }, /* R3338 - Interrupt Status 3 Mask */ 674 { 0x00000D0A, 0xFFFF }, /* R3338 - Interrupt Status 3 Mask */
674 { 0x00000D0B, 0xFFFF }, /* R3339 - Interrupt Status 4 Mask */ 675 { 0x00000D0B, 0xFFFF }, /* R3339 - Interrupt Status 4 Mask */
675 { 0x00000D0C, 0xFEFF }, /* R3340 - Interrupt Status 5 Mask */ 676 { 0x00000D0C, 0xFEFF }, /* R3340 - Interrupt Status 5 Mask */
@@ -886,6 +887,8 @@ static bool wm8997_readable_register(struct device *dev, unsigned int reg)
886 case ARIZONA_MIC_BIAS_CTRL_1: 887 case ARIZONA_MIC_BIAS_CTRL_1:
887 case ARIZONA_MIC_BIAS_CTRL_2: 888 case ARIZONA_MIC_BIAS_CTRL_2:
888 case ARIZONA_MIC_BIAS_CTRL_3: 889 case ARIZONA_MIC_BIAS_CTRL_3:
890 case ARIZONA_HP_CTRL_1L:
891 case ARIZONA_HP_CTRL_1R:
889 case ARIZONA_ACCESSORY_DETECT_MODE_1: 892 case ARIZONA_ACCESSORY_DETECT_MODE_1:
890 case ARIZONA_HEADPHONE_DETECT_1: 893 case ARIZONA_HEADPHONE_DETECT_1:
891 case ARIZONA_HEADPHONE_DETECT_2: 894 case ARIZONA_HEADPHONE_DETECT_2:
@@ -1328,6 +1331,7 @@ static bool wm8997_readable_register(struct device *dev, unsigned int reg)
1328 case ARIZONA_INTERRUPT_STATUS_4: 1331 case ARIZONA_INTERRUPT_STATUS_4:
1329 case ARIZONA_INTERRUPT_STATUS_5: 1332 case ARIZONA_INTERRUPT_STATUS_5:
1330 case ARIZONA_INTERRUPT_STATUS_1_MASK: 1333 case ARIZONA_INTERRUPT_STATUS_1_MASK:
1334 case ARIZONA_INTERRUPT_STATUS_2_MASK:
1331 case ARIZONA_INTERRUPT_STATUS_3_MASK: 1335 case ARIZONA_INTERRUPT_STATUS_3_MASK:
1332 case ARIZONA_INTERRUPT_STATUS_4_MASK: 1336 case ARIZONA_INTERRUPT_STATUS_4_MASK:
1333 case ARIZONA_INTERRUPT_STATUS_5_MASK: 1337 case ARIZONA_INTERRUPT_STATUS_5_MASK:
@@ -1477,6 +1481,8 @@ static bool wm8997_volatile_register(struct device *dev, unsigned int reg)
1477 case ARIZONA_SAMPLE_RATE_3_STATUS: 1481 case ARIZONA_SAMPLE_RATE_3_STATUS:
1478 case ARIZONA_ASYNC_SAMPLE_RATE_1_STATUS: 1482 case ARIZONA_ASYNC_SAMPLE_RATE_1_STATUS:
1479 case ARIZONA_MIC_DETECT_3: 1483 case ARIZONA_MIC_DETECT_3:
1484 case ARIZONA_HP_CTRL_1L:
1485 case ARIZONA_HP_CTRL_1R:
1480 case ARIZONA_HEADPHONE_DETECT_2: 1486 case ARIZONA_HEADPHONE_DETECT_2:
1481 case ARIZONA_INPUT_ENABLES_STATUS: 1487 case ARIZONA_INPUT_ENABLES_STATUS:
1482 case ARIZONA_OUTPUT_STATUS_1: 1488 case ARIZONA_OUTPUT_STATUS_1:
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index bbeb4516facf..006242c8bca0 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -75,7 +75,7 @@ config ATMEL_TCB_CLKSRC
75config ATMEL_TCB_CLKSRC_BLOCK 75config ATMEL_TCB_CLKSRC_BLOCK
76 int 76 int
77 depends on ATMEL_TCB_CLKSRC 77 depends on ATMEL_TCB_CLKSRC
78 prompt "TC Block" if ARCH_AT91RM9200 || ARCH_AT91SAM9260 || CPU_AT32AP700X 78 prompt "TC Block" if CPU_AT32AP700X
79 default 0 79 default 0
80 range 0 1 80 range 0 1
81 help 81 help
diff --git a/drivers/misc/eeprom/eeprom_93cx6.c b/drivers/misc/eeprom/eeprom_93cx6.c
index 0ff4b02177be..0cf2c9d676be 100644
--- a/drivers/misc/eeprom/eeprom_93cx6.c
+++ b/drivers/misc/eeprom/eeprom_93cx6.c
@@ -170,7 +170,7 @@ static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom,
170} 170}
171 171
172/** 172/**
173 * eeprom_93cx6_read - Read multiple words from eeprom 173 * eeprom_93cx6_read - Read a word from eeprom
174 * @eeprom: Pointer to eeprom structure 174 * @eeprom: Pointer to eeprom structure
175 * @word: Word index from where we should start reading 175 * @word: Word index from where we should start reading
176 * @data: target pointer where the information will have to be stored 176 * @data: target pointer where the information will have to be stored
@@ -235,6 +235,66 @@ void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word,
235EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread); 235EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);
236 236
237/** 237/**
238 * eeprom_93cx6_readb - Read a byte from eeprom
239 * @eeprom: Pointer to eeprom structure
240 * @word: Byte index from where we should start reading
241 * @data: target pointer where the information will have to be stored
242 *
243 * This function will read a byte of the eeprom data
244 * into the given data pointer.
245 */
246void eeprom_93cx6_readb(struct eeprom_93cx6 *eeprom, const u8 byte,
247 u8 *data)
248{
249 u16 command;
250 u16 tmp;
251
252 /*
253 * Initialize the eeprom register
254 */
255 eeprom_93cx6_startup(eeprom);
256
257 /*
258 * Select the read opcode and the byte to be read.
259 */
260 command = (PCI_EEPROM_READ_OPCODE << (eeprom->width + 1)) | byte;
261 eeprom_93cx6_write_bits(eeprom, command,
262 PCI_EEPROM_WIDTH_OPCODE + eeprom->width + 1);
263
264 /*
265 * Read the requested 8 bits.
266 */
267 eeprom_93cx6_read_bits(eeprom, &tmp, 8);
268 *data = tmp & 0xff;
269
270 /*
271 * Cleanup eeprom register.
272 */
273 eeprom_93cx6_cleanup(eeprom);
274}
275EXPORT_SYMBOL_GPL(eeprom_93cx6_readb);
276
277/**
278 * eeprom_93cx6_multireadb - Read multiple bytes from eeprom
279 * @eeprom: Pointer to eeprom structure
280 * @byte: Index from where we should start reading
281 * @data: target pointer where the information will have to be stored
282 * @words: Number of bytes that should be read.
283 *
284 * This function will read all requested bytes from the eeprom,
285 * this is done by calling eeprom_93cx6_readb() multiple times.
286 */
287void eeprom_93cx6_multireadb(struct eeprom_93cx6 *eeprom, const u8 byte,
288 u8 *data, const u16 bytes)
289{
290 unsigned int i;
291
292 for (i = 0; i < bytes; i++)
293 eeprom_93cx6_readb(eeprom, byte + i, &data[i]);
294}
295EXPORT_SYMBOL_GPL(eeprom_93cx6_multireadb);
296
297/**
238 * eeprom_93cx6_wren - set the write enable state 298 * eeprom_93cx6_wren - set the write enable state
239 * @eeprom: Pointer to eeprom structure 299 * @eeprom: Pointer to eeprom structure
240 * @enable: true to enable writes, otherwise disable writes 300 * @enable: true to enable writes, otherwise disable writes
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
index 2cf2bbc0b927..180a5442fd4b 100644
--- a/drivers/misc/enclosure.c
+++ b/drivers/misc/enclosure.c
@@ -187,6 +187,7 @@ void enclosure_unregister(struct enclosure_device *edev)
187EXPORT_SYMBOL_GPL(enclosure_unregister); 187EXPORT_SYMBOL_GPL(enclosure_unregister);
188 188
189#define ENCLOSURE_NAME_SIZE 64 189#define ENCLOSURE_NAME_SIZE 64
190#define COMPONENT_NAME_SIZE 64
190 191
191static void enclosure_link_name(struct enclosure_component *cdev, char *name) 192static void enclosure_link_name(struct enclosure_component *cdev, char *name)
192{ 193{
@@ -246,6 +247,29 @@ static void enclosure_component_release(struct device *dev)
246 put_device(dev->parent); 247 put_device(dev->parent);
247} 248}
248 249
250static struct enclosure_component *
251enclosure_component_find_by_name(struct enclosure_device *edev,
252 const char *name)
253{
254 int i;
255 const char *cname;
256 struct enclosure_component *ecomp;
257
258 if (!edev || !name || !name[0])
259 return NULL;
260
261 for (i = 0; i < edev->components; i++) {
262 ecomp = &edev->component[i];
263 cname = dev_name(&ecomp->cdev);
264 if (ecomp->number != -1 &&
265 cname && cname[0] &&
266 !strcmp(cname, name))
267 return ecomp;
268 }
269
270 return NULL;
271}
272
249static const struct attribute_group *enclosure_component_groups[]; 273static const struct attribute_group *enclosure_component_groups[];
250 274
251/** 275/**
@@ -269,7 +293,8 @@ enclosure_component_register(struct enclosure_device *edev,
269{ 293{
270 struct enclosure_component *ecomp; 294 struct enclosure_component *ecomp;
271 struct device *cdev; 295 struct device *cdev;
272 int err; 296 int err, i;
297 char newname[COMPONENT_NAME_SIZE];
273 298
274 if (number >= edev->components) 299 if (number >= edev->components)
275 return ERR_PTR(-EINVAL); 300 return ERR_PTR(-EINVAL);
@@ -283,9 +308,20 @@ enclosure_component_register(struct enclosure_device *edev,
283 ecomp->number = number; 308 ecomp->number = number;
284 cdev = &ecomp->cdev; 309 cdev = &ecomp->cdev;
285 cdev->parent = get_device(&edev->edev); 310 cdev->parent = get_device(&edev->edev);
286 if (name && name[0]) 311
287 dev_set_name(cdev, "%s", name); 312 if (name && name[0]) {
288 else 313 /* Some hardware (e.g. enclosure in RX300 S6) has components
314 * with non unique names. Registering duplicates in sysfs
315 * will lead to warnings during bootup. So make the names
316 * unique by appending consecutive numbers -1, -2, ... */
317 i = 1;
318 snprintf(newname, COMPONENT_NAME_SIZE,
319 "%s", name);
320 while (enclosure_component_find_by_name(edev, newname))
321 snprintf(newname, COMPONENT_NAME_SIZE,
322 "%s-%i", name, i++);
323 dev_set_name(cdev, "%s", newname);
324 } else
289 dev_set_name(cdev, "%u", number); 325 dev_set_name(cdev, "%u", number);
290 326
291 cdev->release = enclosure_component_release; 327 cdev->release = enclosure_component_release;
diff --git a/drivers/misc/vexpress-syscfg.c b/drivers/misc/vexpress-syscfg.c
index b3a812384a6f..c344483fa7d6 100644
--- a/drivers/misc/vexpress-syscfg.c
+++ b/drivers/misc/vexpress-syscfg.c
@@ -145,7 +145,7 @@ static struct regmap_config vexpress_syscfg_regmap_config = {
145static struct regmap *vexpress_syscfg_regmap_init(struct device *dev, 145static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
146 void *context) 146 void *context)
147{ 147{
148 struct platform_device *pdev = to_platform_device(dev); 148 int err;
149 struct vexpress_syscfg *syscfg = context; 149 struct vexpress_syscfg *syscfg = context;
150 struct vexpress_syscfg_func *func; 150 struct vexpress_syscfg_func *func;
151 struct property *prop; 151 struct property *prop;
@@ -155,32 +155,18 @@ static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
155 u32 site, position, dcc; 155 u32 site, position, dcc;
156 int i; 156 int i;
157 157
158 if (dev->of_node) { 158 err = vexpress_config_get_topo(dev->of_node, &site,
159 int err = vexpress_config_get_topo(dev->of_node, &site,
160 &position, &dcc); 159 &position, &dcc);
160 if (err)
161 return ERR_PTR(err);
161 162
162 if (err) 163 prop = of_find_property(dev->of_node,
163 return ERR_PTR(err); 164 "arm,vexpress-sysreg,func", NULL);
164 165 if (!prop)
165 prop = of_find_property(dev->of_node, 166 return ERR_PTR(-EINVAL);
166 "arm,vexpress-sysreg,func", NULL); 167
167 if (!prop) 168 num = prop->length / sizeof(u32) / 2;
168 return ERR_PTR(-EINVAL); 169 val = prop->value;
169
170 num = prop->length / sizeof(u32) / 2;
171 val = prop->value;
172 } else {
173 if (pdev->num_resources != 1 ||
174 pdev->resource[0].flags != IORESOURCE_BUS)
175 return ERR_PTR(-EFAULT);
176
177 site = pdev->resource[0].start;
178 if (site == VEXPRESS_SITE_MASTER)
179 site = vexpress_config_get_master();
180 position = 0;
181 dcc = 0;
182 num = 1;
183 }
184 170
185 /* 171 /*
186 * "arm,vexpress-energy" function used to be described 172 * "arm,vexpress-energy" function used to be described
@@ -207,13 +193,8 @@ static struct regmap *vexpress_syscfg_regmap_init(struct device *dev,
207 for (i = 0; i < num; i++) { 193 for (i = 0; i < num; i++) {
208 u32 function, device; 194 u32 function, device;
209 195
210 if (dev->of_node) { 196 function = be32_to_cpup(val++);
211 function = be32_to_cpup(val++); 197 device = be32_to_cpup(val++);
212 device = be32_to_cpup(val++);
213 } else {
214 function = pdev->resource[0].end;
215 device = pdev->id;
216 }
217 198
218 dev_dbg(dev, "func %p: %u/%u/%u/%u/%u\n", 199 dev_dbg(dev, "func %p: %u/%u/%u/%u/%u\n",
219 func, site, position, dcc, 200 func, site, position, dcc,
@@ -265,17 +246,6 @@ static struct vexpress_config_bridge_ops vexpress_syscfg_bridge_ops = {
265}; 246};
266 247
267 248
268/* Non-DT hack, to be gone... */
269static struct device *vexpress_syscfg_bridge;
270
271int vexpress_syscfg_device_register(struct platform_device *pdev)
272{
273 pdev->dev.parent = vexpress_syscfg_bridge;
274
275 return platform_device_register(pdev);
276}
277
278
279static int vexpress_syscfg_probe(struct platform_device *pdev) 249static int vexpress_syscfg_probe(struct platform_device *pdev)
280{ 250{
281 struct vexpress_syscfg *syscfg; 251 struct vexpress_syscfg *syscfg;
@@ -303,10 +273,6 @@ static int vexpress_syscfg_probe(struct platform_device *pdev)
303 if (IS_ERR(bridge)) 273 if (IS_ERR(bridge))
304 return PTR_ERR(bridge); 274 return PTR_ERR(bridge);
305 275
306 /* Non-DT case */
307 if (!pdev->dev.of_node)
308 vexpress_syscfg_bridge = bridge;
309
310 return 0; 276 return 0;
311} 277}
312 278
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 1fa4c80ff886..4409d79ed650 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -78,13 +78,16 @@ static int perdev_minors = CONFIG_MMC_BLOCK_MINORS;
78 78
79/* 79/*
80 * We've only got one major, so number of mmcblk devices is 80 * We've only got one major, so number of mmcblk devices is
81 * limited to 256 / number of minors per device. 81 * limited to (1 << 20) / number of minors per device. It is also
82 * currently limited by the size of the static bitmaps below.
82 */ 83 */
83static int max_devices; 84static int max_devices;
84 85
85/* 256 minors, so at most 256 separate devices */ 86#define MAX_DEVICES 256
86static DECLARE_BITMAP(dev_use, 256); 87
87static DECLARE_BITMAP(name_use, 256); 88/* TODO: Replace these with struct ida */
89static DECLARE_BITMAP(dev_use, MAX_DEVICES);
90static DECLARE_BITMAP(name_use, MAX_DEVICES);
88 91
89/* 92/*
90 * There is one mmc_blk_data per slot. 93 * There is one mmc_blk_data per slot.
@@ -112,7 +115,7 @@ struct mmc_blk_data {
112 115
113 /* 116 /*
114 * Only set in main mmc_blk_data associated 117 * Only set in main mmc_blk_data associated
115 * with mmc_card with mmc_set_drvdata, and keeps 118 * with mmc_card with dev_set_drvdata, and keeps
116 * track of the current selected device partition. 119 * track of the current selected device partition.
117 */ 120 */
118 unsigned int part_curr; 121 unsigned int part_curr;
@@ -260,7 +263,7 @@ static ssize_t force_ro_show(struct device *dev, struct device_attribute *attr,
260 int ret; 263 int ret;
261 struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev)); 264 struct mmc_blk_data *md = mmc_blk_get(dev_to_disk(dev));
262 265
263 ret = snprintf(buf, PAGE_SIZE, "%d", 266 ret = snprintf(buf, PAGE_SIZE, "%d\n",
264 get_disk_ro(dev_to_disk(dev)) ^ 267 get_disk_ro(dev_to_disk(dev)) ^
265 md->read_only); 268 md->read_only);
266 mmc_blk_put(md); 269 mmc_blk_put(md);
@@ -642,7 +645,7 @@ static inline int mmc_blk_part_switch(struct mmc_card *card,
642 struct mmc_blk_data *md) 645 struct mmc_blk_data *md)
643{ 646{
644 int ret; 647 int ret;
645 struct mmc_blk_data *main_md = mmc_get_drvdata(card); 648 struct mmc_blk_data *main_md = dev_get_drvdata(&card->dev);
646 649
647 if (main_md->part_curr == md->part_type) 650 if (main_md->part_curr == md->part_type)
648 return 0; 651 return 0;
@@ -1004,7 +1007,8 @@ static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host,
1004 err = mmc_hw_reset(host); 1007 err = mmc_hw_reset(host);
1005 /* Ensure we switch back to the correct partition */ 1008 /* Ensure we switch back to the correct partition */
1006 if (err != -EOPNOTSUPP) { 1009 if (err != -EOPNOTSUPP) {
1007 struct mmc_blk_data *main_md = mmc_get_drvdata(host->card); 1010 struct mmc_blk_data *main_md =
1011 dev_get_drvdata(&host->card->dev);
1008 int part_err; 1012 int part_err;
1009 1013
1010 main_md->part_curr = main_md->part_type; 1014 main_md->part_curr = main_md->part_type;
@@ -1308,19 +1312,11 @@ static int mmc_blk_packed_err_check(struct mmc_card *card,
1308 } 1312 }
1309 1313
1310 if (status & R1_EXCEPTION_EVENT) { 1314 if (status & R1_EXCEPTION_EVENT) {
1311 ext_csd = kzalloc(512, GFP_KERNEL); 1315 err = mmc_get_ext_csd(card, &ext_csd);
1312 if (!ext_csd) {
1313 pr_err("%s: unable to allocate buffer for ext_csd\n",
1314 req->rq_disk->disk_name);
1315 return -ENOMEM;
1316 }
1317
1318 err = mmc_send_ext_csd(card, ext_csd);
1319 if (err) { 1316 if (err) {
1320 pr_err("%s: error %d sending ext_csd\n", 1317 pr_err("%s: error %d sending ext_csd\n",
1321 req->rq_disk->disk_name, err); 1318 req->rq_disk->disk_name, err);
1322 check = MMC_BLK_ABORT; 1319 return MMC_BLK_ABORT;
1323 goto free;
1324 } 1320 }
1325 1321
1326 if ((ext_csd[EXT_CSD_EXP_EVENTS_STATUS] & 1322 if ((ext_csd[EXT_CSD_EXP_EVENTS_STATUS] &
@@ -1338,7 +1334,6 @@ static int mmc_blk_packed_err_check(struct mmc_card *card,
1338 req->rq_disk->disk_name, packed->nr_entries, 1334 req->rq_disk->disk_name, packed->nr_entries,
1339 packed->blocks, packed->idx_failure); 1335 packed->blocks, packed->idx_failure);
1340 } 1336 }
1341free:
1342 kfree(ext_csd); 1337 kfree(ext_csd);
1343 } 1338 }
1344 1339
@@ -2093,7 +2088,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
2093 2088
2094 /* 2089 /*
2095 * !subname implies we are creating main mmc_blk_data that will be 2090 * !subname implies we are creating main mmc_blk_data that will be
2096 * associated with mmc_card with mmc_set_drvdata. Due to device 2091 * associated with mmc_card with dev_set_drvdata. Due to device
2097 * partitions, devidx will not coincide with a per-physical card 2092 * partitions, devidx will not coincide with a per-physical card
2098 * index anymore so we keep track of a name index. 2093 * index anymore so we keep track of a name index.
2099 */ 2094 */
@@ -2425,8 +2420,9 @@ static const struct mmc_fixup blk_fixups[] =
2425 END_FIXUP 2420 END_FIXUP
2426}; 2421};
2427 2422
2428static int mmc_blk_probe(struct mmc_card *card) 2423static int mmc_blk_probe(struct device *dev)
2429{ 2424{
2425 struct mmc_card *card = mmc_dev_to_card(dev);
2430 struct mmc_blk_data *md, *part_md; 2426 struct mmc_blk_data *md, *part_md;
2431 char cap_str[10]; 2427 char cap_str[10];
2432 2428
@@ -2451,7 +2447,7 @@ static int mmc_blk_probe(struct mmc_card *card)
2451 if (mmc_blk_alloc_parts(card, md)) 2447 if (mmc_blk_alloc_parts(card, md))
2452 goto out; 2448 goto out;
2453 2449
2454 mmc_set_drvdata(card, md); 2450 dev_set_drvdata(dev, md);
2455 2451
2456 if (mmc_add_disk(md)) 2452 if (mmc_add_disk(md))
2457 goto out; 2453 goto out;
@@ -2481,9 +2477,10 @@ static int mmc_blk_probe(struct mmc_card *card)
2481 return 0; 2477 return 0;
2482} 2478}
2483 2479
2484static void mmc_blk_remove(struct mmc_card *card) 2480static int mmc_blk_remove(struct device *dev)
2485{ 2481{
2486 struct mmc_blk_data *md = mmc_get_drvdata(card); 2482 struct mmc_card *card = mmc_dev_to_card(dev);
2483 struct mmc_blk_data *md = dev_get_drvdata(dev);
2487 2484
2488 mmc_blk_remove_parts(card, md); 2485 mmc_blk_remove_parts(card, md);
2489 pm_runtime_get_sync(&card->dev); 2486 pm_runtime_get_sync(&card->dev);
@@ -2494,13 +2491,15 @@ static void mmc_blk_remove(struct mmc_card *card)
2494 pm_runtime_disable(&card->dev); 2491 pm_runtime_disable(&card->dev);
2495 pm_runtime_put_noidle(&card->dev); 2492 pm_runtime_put_noidle(&card->dev);
2496 mmc_blk_remove_req(md); 2493 mmc_blk_remove_req(md);
2497 mmc_set_drvdata(card, NULL); 2494 dev_set_drvdata(dev, NULL);
2495
2496 return 0;
2498} 2497}
2499 2498
2500static int _mmc_blk_suspend(struct mmc_card *card) 2499static int _mmc_blk_suspend(struct device *dev)
2501{ 2500{
2502 struct mmc_blk_data *part_md; 2501 struct mmc_blk_data *part_md;
2503 struct mmc_blk_data *md = mmc_get_drvdata(card); 2502 struct mmc_blk_data *md = dev_get_drvdata(dev);
2504 2503
2505 if (md) { 2504 if (md) {
2506 mmc_queue_suspend(&md->queue); 2505 mmc_queue_suspend(&md->queue);
@@ -2511,21 +2510,21 @@ static int _mmc_blk_suspend(struct mmc_card *card)
2511 return 0; 2510 return 0;
2512} 2511}
2513 2512
2514static void mmc_blk_shutdown(struct mmc_card *card) 2513static void mmc_blk_shutdown(struct device *dev)
2515{ 2514{
2516 _mmc_blk_suspend(card); 2515 _mmc_blk_suspend(dev);
2517} 2516}
2518 2517
2519#ifdef CONFIG_PM 2518#ifdef CONFIG_PM_SLEEP
2520static int mmc_blk_suspend(struct mmc_card *card) 2519static int mmc_blk_suspend(struct device *dev)
2521{ 2520{
2522 return _mmc_blk_suspend(card); 2521 return _mmc_blk_suspend(dev);
2523} 2522}
2524 2523
2525static int mmc_blk_resume(struct mmc_card *card) 2524static int mmc_blk_resume(struct device *dev)
2526{ 2525{
2527 struct mmc_blk_data *part_md; 2526 struct mmc_blk_data *part_md;
2528 struct mmc_blk_data *md = mmc_get_drvdata(card); 2527 struct mmc_blk_data *md = dev_get_drvdata(dev);
2529 2528
2530 if (md) { 2529 if (md) {
2531 /* 2530 /*
@@ -2540,19 +2539,15 @@ static int mmc_blk_resume(struct mmc_card *card)
2540 } 2539 }
2541 return 0; 2540 return 0;
2542} 2541}
2543#else
2544#define mmc_blk_suspend NULL
2545#define mmc_blk_resume NULL
2546#endif 2542#endif
2547 2543
2548static struct mmc_driver mmc_driver = { 2544static SIMPLE_DEV_PM_OPS(mmc_blk_pm_ops, mmc_blk_suspend, mmc_blk_resume);
2549 .drv = { 2545
2550 .name = "mmcblk", 2546static struct device_driver mmc_driver = {
2551 }, 2547 .name = "mmcblk",
2548 .pm = &mmc_blk_pm_ops,
2552 .probe = mmc_blk_probe, 2549 .probe = mmc_blk_probe,
2553 .remove = mmc_blk_remove, 2550 .remove = mmc_blk_remove,
2554 .suspend = mmc_blk_suspend,
2555 .resume = mmc_blk_resume,
2556 .shutdown = mmc_blk_shutdown, 2551 .shutdown = mmc_blk_shutdown,
2557}; 2552};
2558 2553
@@ -2563,7 +2558,7 @@ static int __init mmc_blk_init(void)
2563 if (perdev_minors != CONFIG_MMC_BLOCK_MINORS) 2558 if (perdev_minors != CONFIG_MMC_BLOCK_MINORS)
2564 pr_info("mmcblk: using %d minors per device\n", perdev_minors); 2559 pr_info("mmcblk: using %d minors per device\n", perdev_minors);
2565 2560
2566 max_devices = 256 / perdev_minors; 2561 max_devices = min(MAX_DEVICES, (1 << MINORBITS) / perdev_minors);
2567 2562
2568 res = register_blkdev(MMC_BLOCK_MAJOR, "mmc"); 2563 res = register_blkdev(MMC_BLOCK_MAJOR, "mmc");
2569 if (res) 2564 if (res)
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index 0c0fc52d42c5..0a7430f94d29 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -14,6 +14,7 @@
14#include <linux/mmc/host.h> 14#include <linux/mmc/host.h>
15#include <linux/mmc/mmc.h> 15#include <linux/mmc/mmc.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/device.h>
17 18
18#include <linux/scatterlist.h> 19#include <linux/scatterlist.h>
19#include <linux/swap.h> /* For nr_free_buffer_pages() */ 20#include <linux/swap.h> /* For nr_free_buffer_pages() */
@@ -32,6 +33,8 @@
32#define BUFFER_ORDER 2 33#define BUFFER_ORDER 2
33#define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER) 34#define BUFFER_SIZE (PAGE_SIZE << BUFFER_ORDER)
34 35
36#define TEST_ALIGN_END 8
37
35/* 38/*
36 * Limit the test area size to the maximum MMC HC erase group size. Note that 39 * Limit the test area size to the maximum MMC HC erase group size. Note that
37 * the maximum SD allocation unit size is just 4MiB. 40 * the maximum SD allocation unit size is just 4MiB.
@@ -1174,7 +1177,7 @@ static int mmc_test_align_write(struct mmc_test_card *test)
1174 int ret, i; 1177 int ret, i;
1175 struct scatterlist sg; 1178 struct scatterlist sg;
1176 1179
1177 for (i = 1;i < 4;i++) { 1180 for (i = 1; i < TEST_ALIGN_END; i++) {
1178 sg_init_one(&sg, test->buffer + i, 512); 1181 sg_init_one(&sg, test->buffer + i, 512);
1179 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1); 1182 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 1);
1180 if (ret) 1183 if (ret)
@@ -1189,7 +1192,7 @@ static int mmc_test_align_read(struct mmc_test_card *test)
1189 int ret, i; 1192 int ret, i;
1190 struct scatterlist sg; 1193 struct scatterlist sg;
1191 1194
1192 for (i = 1;i < 4;i++) { 1195 for (i = 1; i < TEST_ALIGN_END; i++) {
1193 sg_init_one(&sg, test->buffer + i, 512); 1196 sg_init_one(&sg, test->buffer + i, 512);
1194 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0); 1197 ret = mmc_test_transfer(test, &sg, 1, 0, 1, 512, 0);
1195 if (ret) 1198 if (ret)
@@ -1216,7 +1219,7 @@ static int mmc_test_align_multi_write(struct mmc_test_card *test)
1216 if (size < 1024) 1219 if (size < 1024)
1217 return RESULT_UNSUP_HOST; 1220 return RESULT_UNSUP_HOST;
1218 1221
1219 for (i = 1;i < 4;i++) { 1222 for (i = 1; i < TEST_ALIGN_END; i++) {
1220 sg_init_one(&sg, test->buffer + i, size); 1223 sg_init_one(&sg, test->buffer + i, size);
1221 ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 1); 1224 ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 1);
1222 if (ret) 1225 if (ret)
@@ -1243,7 +1246,7 @@ static int mmc_test_align_multi_read(struct mmc_test_card *test)
1243 if (size < 1024) 1246 if (size < 1024)
1244 return RESULT_UNSUP_HOST; 1247 return RESULT_UNSUP_HOST;
1245 1248
1246 for (i = 1;i < 4;i++) { 1249 for (i = 1; i < TEST_ALIGN_END; i++) {
1247 sg_init_one(&sg, test->buffer + i, size); 1250 sg_init_one(&sg, test->buffer + i, size);
1248 ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 0); 1251 ret = mmc_test_transfer(test, &sg, 1, 0, size/512, 512, 0);
1249 if (ret) 1252 if (ret)
@@ -2997,8 +3000,9 @@ err:
2997 return ret; 3000 return ret;
2998} 3001}
2999 3002
3000static int mmc_test_probe(struct mmc_card *card) 3003static int mmc_test_probe(struct device *dev)
3001{ 3004{
3005 struct mmc_card *card = mmc_dev_to_card(dev);
3002 int ret; 3006 int ret;
3003 3007
3004 if (!mmc_card_mmc(card) && !mmc_card_sd(card)) 3008 if (!mmc_card_mmc(card) && !mmc_card_sd(card))
@@ -3013,20 +3017,22 @@ static int mmc_test_probe(struct mmc_card *card)
3013 return 0; 3017 return 0;
3014} 3018}
3015 3019
3016static void mmc_test_remove(struct mmc_card *card) 3020static int mmc_test_remove(struct device *dev)
3017{ 3021{
3022 struct mmc_card *card = mmc_dev_to_card(dev);
3023
3018 mmc_test_free_result(card); 3024 mmc_test_free_result(card);
3019 mmc_test_free_dbgfs_file(card); 3025 mmc_test_free_dbgfs_file(card);
3026
3027 return 0;
3020} 3028}
3021 3029
3022static void mmc_test_shutdown(struct mmc_card *card) 3030static void mmc_test_shutdown(struct device *dev)
3023{ 3031{
3024} 3032}
3025 3033
3026static struct mmc_driver mmc_driver = { 3034static struct device_driver mmc_driver = {
3027 .drv = { 3035 .name = "mmc_test",
3028 .name = "mmc_test",
3029 },
3030 .probe = mmc_test_probe, 3036 .probe = mmc_test_probe,
3031 .remove = mmc_test_remove, 3037 .remove = mmc_test_remove,
3032 .shutdown = mmc_test_shutdown, 3038 .shutdown = mmc_test_shutdown,
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index cfa6110632c3..236d194c2883 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -232,13 +232,15 @@ int mmc_init_queue(struct mmc_queue *mq, struct mmc_card *card,
232 if (!mqrq_cur->bounce_buf) { 232 if (!mqrq_cur->bounce_buf) {
233 pr_warn("%s: unable to allocate bounce cur buffer\n", 233 pr_warn("%s: unable to allocate bounce cur buffer\n",
234 mmc_card_name(card)); 234 mmc_card_name(card));
235 } 235 } else {
236 mqrq_prev->bounce_buf = kmalloc(bouncesz, GFP_KERNEL); 236 mqrq_prev->bounce_buf =
237 if (!mqrq_prev->bounce_buf) { 237 kmalloc(bouncesz, GFP_KERNEL);
238 pr_warn("%s: unable to allocate bounce prev buffer\n", 238 if (!mqrq_prev->bounce_buf) {
239 mmc_card_name(card)); 239 pr_warn("%s: unable to allocate bounce prev buffer\n",
240 kfree(mqrq_cur->bounce_buf); 240 mmc_card_name(card));
241 mqrq_cur->bounce_buf = NULL; 241 kfree(mqrq_cur->bounce_buf);
242 mqrq_cur->bounce_buf = NULL;
243 }
242 } 244 }
243 } 245 }
244 246
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 8a1f1240e058..5ca562ccfcf3 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -25,8 +25,6 @@
25#include "sdio_cis.h" 25#include "sdio_cis.h"
26#include "bus.h" 26#include "bus.h"
27 27
28#define to_mmc_driver(d) container_of(d, struct mmc_driver, drv)
29
30static ssize_t type_show(struct device *dev, 28static ssize_t type_show(struct device *dev,
31 struct device_attribute *attr, char *buf) 29 struct device_attribute *attr, char *buf)
32{ 30{
@@ -106,33 +104,14 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
106 return retval; 104 return retval;
107} 105}
108 106
109static int mmc_bus_probe(struct device *dev)
110{
111 struct mmc_driver *drv = to_mmc_driver(dev->driver);
112 struct mmc_card *card = mmc_dev_to_card(dev);
113
114 return drv->probe(card);
115}
116
117static int mmc_bus_remove(struct device *dev)
118{
119 struct mmc_driver *drv = to_mmc_driver(dev->driver);
120 struct mmc_card *card = mmc_dev_to_card(dev);
121
122 drv->remove(card);
123
124 return 0;
125}
126
127static void mmc_bus_shutdown(struct device *dev) 107static void mmc_bus_shutdown(struct device *dev)
128{ 108{
129 struct mmc_driver *drv = to_mmc_driver(dev->driver);
130 struct mmc_card *card = mmc_dev_to_card(dev); 109 struct mmc_card *card = mmc_dev_to_card(dev);
131 struct mmc_host *host = card->host; 110 struct mmc_host *host = card->host;
132 int ret; 111 int ret;
133 112
134 if (dev->driver && drv->shutdown) 113 if (dev->driver && dev->driver->shutdown)
135 drv->shutdown(card); 114 dev->driver->shutdown(dev);
136 115
137 if (host->bus_ops->shutdown) { 116 if (host->bus_ops->shutdown) {
138 ret = host->bus_ops->shutdown(host); 117 ret = host->bus_ops->shutdown(host);
@@ -145,16 +124,13 @@ static void mmc_bus_shutdown(struct device *dev)
145#ifdef CONFIG_PM_SLEEP 124#ifdef CONFIG_PM_SLEEP
146static int mmc_bus_suspend(struct device *dev) 125static int mmc_bus_suspend(struct device *dev)
147{ 126{
148 struct mmc_driver *drv = to_mmc_driver(dev->driver);
149 struct mmc_card *card = mmc_dev_to_card(dev); 127 struct mmc_card *card = mmc_dev_to_card(dev);
150 struct mmc_host *host = card->host; 128 struct mmc_host *host = card->host;
151 int ret; 129 int ret;
152 130
153 if (dev->driver && drv->suspend) { 131 ret = pm_generic_suspend(dev);
154 ret = drv->suspend(card); 132 if (ret)
155 if (ret) 133 return ret;
156 return ret;
157 }
158 134
159 ret = host->bus_ops->suspend(host); 135 ret = host->bus_ops->suspend(host);
160 return ret; 136 return ret;
@@ -162,7 +138,6 @@ static int mmc_bus_suspend(struct device *dev)
162 138
163static int mmc_bus_resume(struct device *dev) 139static int mmc_bus_resume(struct device *dev)
164{ 140{
165 struct mmc_driver *drv = to_mmc_driver(dev->driver);
166 struct mmc_card *card = mmc_dev_to_card(dev); 141 struct mmc_card *card = mmc_dev_to_card(dev);
167 struct mmc_host *host = card->host; 142 struct mmc_host *host = card->host;
168 int ret; 143 int ret;
@@ -172,9 +147,7 @@ static int mmc_bus_resume(struct device *dev)
172 pr_warn("%s: error %d during resume (card was removed?)\n", 147 pr_warn("%s: error %d during resume (card was removed?)\n",
173 mmc_hostname(host), ret); 148 mmc_hostname(host), ret);
174 149
175 if (dev->driver && drv->resume) 150 ret = pm_generic_resume(dev);
176 ret = drv->resume(card);
177
178 return ret; 151 return ret;
179} 152}
180#endif 153#endif
@@ -207,8 +180,6 @@ static struct bus_type mmc_bus_type = {
207 .dev_groups = mmc_dev_groups, 180 .dev_groups = mmc_dev_groups,
208 .match = mmc_bus_match, 181 .match = mmc_bus_match,
209 .uevent = mmc_bus_uevent, 182 .uevent = mmc_bus_uevent,
210 .probe = mmc_bus_probe,
211 .remove = mmc_bus_remove,
212 .shutdown = mmc_bus_shutdown, 183 .shutdown = mmc_bus_shutdown,
213 .pm = &mmc_bus_pm_ops, 184 .pm = &mmc_bus_pm_ops,
214}; 185};
@@ -227,24 +198,22 @@ void mmc_unregister_bus(void)
227 * mmc_register_driver - register a media driver 198 * mmc_register_driver - register a media driver
228 * @drv: MMC media driver 199 * @drv: MMC media driver
229 */ 200 */
230int mmc_register_driver(struct mmc_driver *drv) 201int mmc_register_driver(struct device_driver *drv)
231{ 202{
232 drv->drv.bus = &mmc_bus_type; 203 drv->bus = &mmc_bus_type;
233 return driver_register(&drv->drv); 204 return driver_register(drv);
234} 205}
235
236EXPORT_SYMBOL(mmc_register_driver); 206EXPORT_SYMBOL(mmc_register_driver);
237 207
238/** 208/**
239 * mmc_unregister_driver - unregister a media driver 209 * mmc_unregister_driver - unregister a media driver
240 * @drv: MMC media driver 210 * @drv: MMC media driver
241 */ 211 */
242void mmc_unregister_driver(struct mmc_driver *drv) 212void mmc_unregister_driver(struct device_driver *drv)
243{ 213{
244 drv->drv.bus = &mmc_bus_type; 214 drv->bus = &mmc_bus_type;
245 driver_unregister(&drv->drv); 215 driver_unregister(drv);
246} 216}
247
248EXPORT_SYMBOL(mmc_unregister_driver); 217EXPORT_SYMBOL(mmc_unregister_driver);
249 218
250static void mmc_release_card(struct device *dev) 219static void mmc_release_card(struct device *dev)
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index f26a5f1d926d..9584bffa8b22 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -149,6 +149,14 @@ void mmc_request_done(struct mmc_host *host, struct mmc_request *mrq)
149 149
150 led_trigger_event(host->led, LED_OFF); 150 led_trigger_event(host->led, LED_OFF);
151 151
152 if (mrq->sbc) {
153 pr_debug("%s: req done <CMD%u>: %d: %08x %08x %08x %08x\n",
154 mmc_hostname(host), mrq->sbc->opcode,
155 mrq->sbc->error,
156 mrq->sbc->resp[0], mrq->sbc->resp[1],
157 mrq->sbc->resp[2], mrq->sbc->resp[3]);
158 }
159
152 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n", 160 pr_debug("%s: req done (CMD%u): %d: %08x %08x %08x %08x\n",
153 mmc_hostname(host), cmd->opcode, err, 161 mmc_hostname(host), cmd->opcode, err,
154 cmd->resp[0], cmd->resp[1], 162 cmd->resp[0], cmd->resp[1],
@@ -214,6 +222,10 @@ mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
214 222
215 mrq->cmd->error = 0; 223 mrq->cmd->error = 0;
216 mrq->cmd->mrq = mrq; 224 mrq->cmd->mrq = mrq;
225 if (mrq->sbc) {
226 mrq->sbc->error = 0;
227 mrq->sbc->mrq = mrq;
228 }
217 if (mrq->data) { 229 if (mrq->data) {
218 BUG_ON(mrq->data->blksz > host->max_blk_size); 230 BUG_ON(mrq->data->blksz > host->max_blk_size);
219 BUG_ON(mrq->data->blocks > host->max_blk_count); 231 BUG_ON(mrq->data->blocks > host->max_blk_count);
@@ -538,8 +550,18 @@ struct mmc_async_req *mmc_start_req(struct mmc_host *host,
538 if (host->card && mmc_card_mmc(host->card) && 550 if (host->card && mmc_card_mmc(host->card) &&
539 ((mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1) || 551 ((mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1) ||
540 (mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1B)) && 552 (mmc_resp_type(host->areq->mrq->cmd) == MMC_RSP_R1B)) &&
541 (host->areq->mrq->cmd->resp[0] & R1_EXCEPTION_EVENT)) 553 (host->areq->mrq->cmd->resp[0] & R1_EXCEPTION_EVENT)) {
554
555 /* Cancel the prepared request */
556 if (areq)
557 mmc_post_req(host, areq->mrq, -EINVAL);
558
542 mmc_start_bkops(host->card, true); 559 mmc_start_bkops(host->card, true);
560
561 /* prepare the request again */
562 if (areq)
563 mmc_pre_req(host, areq->mrq, !host->areq);
564 }
543 } 565 }
544 566
545 if (!err && areq) 567 if (!err && areq)
@@ -709,27 +731,16 @@ int mmc_read_bkops_status(struct mmc_card *card)
709 int err; 731 int err;
710 u8 *ext_csd; 732 u8 *ext_csd;
711 733
712 /*
713 * In future work, we should consider storing the entire ext_csd.
714 */
715 ext_csd = kmalloc(512, GFP_KERNEL);
716 if (!ext_csd) {
717 pr_err("%s: could not allocate buffer to receive the ext_csd.\n",
718 mmc_hostname(card->host));
719 return -ENOMEM;
720 }
721
722 mmc_claim_host(card->host); 734 mmc_claim_host(card->host);
723 err = mmc_send_ext_csd(card, ext_csd); 735 err = mmc_get_ext_csd(card, &ext_csd);
724 mmc_release_host(card->host); 736 mmc_release_host(card->host);
725 if (err) 737 if (err)
726 goto out; 738 return err;
727 739
728 card->ext_csd.raw_bkops_status = ext_csd[EXT_CSD_BKOPS_STATUS]; 740 card->ext_csd.raw_bkops_status = ext_csd[EXT_CSD_BKOPS_STATUS];
729 card->ext_csd.raw_exception_status = ext_csd[EXT_CSD_EXP_EVENTS_STATUS]; 741 card->ext_csd.raw_exception_status = ext_csd[EXT_CSD_EXP_EVENTS_STATUS];
730out:
731 kfree(ext_csd); 742 kfree(ext_csd);
732 return err; 743 return 0;
733} 744}
734EXPORT_SYMBOL(mmc_read_bkops_status); 745EXPORT_SYMBOL(mmc_read_bkops_status);
735 746
@@ -1088,6 +1099,22 @@ void mmc_set_bus_width(struct mmc_host *host, unsigned int width)
1088 mmc_host_clk_release(host); 1099 mmc_host_clk_release(host);
1089} 1100}
1090 1101
1102/*
1103 * Set initial state after a power cycle or a hw_reset.
1104 */
1105void mmc_set_initial_state(struct mmc_host *host)
1106{
1107 if (mmc_host_is_spi(host))
1108 host->ios.chip_select = MMC_CS_HIGH;
1109 else
1110 host->ios.chip_select = MMC_CS_DONTCARE;
1111 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
1112 host->ios.bus_width = MMC_BUS_WIDTH_1;
1113 host->ios.timing = MMC_TIMING_LEGACY;
1114
1115 mmc_set_ios(host);
1116}
1117
1091/** 1118/**
1092 * mmc_vdd_to_ocrbitnum - Convert a voltage to the OCR bit number 1119 * mmc_vdd_to_ocrbitnum - Convert a voltage to the OCR bit number
1093 * @vdd: voltage (mV) 1120 * @vdd: voltage (mV)
@@ -1420,18 +1447,20 @@ int mmc_set_signal_voltage(struct mmc_host *host, int signal_voltage, u32 ocr)
1420 pr_warn("%s: cannot verify signal voltage switch\n", 1447 pr_warn("%s: cannot verify signal voltage switch\n",
1421 mmc_hostname(host)); 1448 mmc_hostname(host));
1422 1449
1450 mmc_host_clk_hold(host);
1451
1423 cmd.opcode = SD_SWITCH_VOLTAGE; 1452 cmd.opcode = SD_SWITCH_VOLTAGE;
1424 cmd.arg = 0; 1453 cmd.arg = 0;
1425 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; 1454 cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
1426 1455
1427 err = mmc_wait_for_cmd(host, &cmd, 0); 1456 err = mmc_wait_for_cmd(host, &cmd, 0);
1428 if (err) 1457 if (err)
1429 return err; 1458 goto err_command;
1430 1459
1431 if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR)) 1460 if (!mmc_host_is_spi(host) && (cmd.resp[0] & R1_ERROR)) {
1432 return -EIO; 1461 err = -EIO;
1433 1462 goto err_command;
1434 mmc_host_clk_hold(host); 1463 }
1435 /* 1464 /*
1436 * The card should drive cmd and dat[0:3] low immediately 1465 * The card should drive cmd and dat[0:3] low immediately
1437 * after the response of cmd11, but wait 1 ms to be sure 1466 * after the response of cmd11, but wait 1 ms to be sure
@@ -1480,6 +1509,7 @@ power_cycle:
1480 mmc_power_cycle(host, ocr); 1509 mmc_power_cycle(host, ocr);
1481 } 1510 }
1482 1511
1512err_command:
1483 mmc_host_clk_release(host); 1513 mmc_host_clk_release(host);
1484 1514
1485 return err; 1515 return err;
@@ -1526,15 +1556,9 @@ void mmc_power_up(struct mmc_host *host, u32 ocr)
1526 mmc_host_clk_hold(host); 1556 mmc_host_clk_hold(host);
1527 1557
1528 host->ios.vdd = fls(ocr) - 1; 1558 host->ios.vdd = fls(ocr) - 1;
1529 if (mmc_host_is_spi(host))
1530 host->ios.chip_select = MMC_CS_HIGH;
1531 else
1532 host->ios.chip_select = MMC_CS_DONTCARE;
1533 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
1534 host->ios.power_mode = MMC_POWER_UP; 1559 host->ios.power_mode = MMC_POWER_UP;
1535 host->ios.bus_width = MMC_BUS_WIDTH_1; 1560 /* Set initial state and call mmc_set_ios */
1536 host->ios.timing = MMC_TIMING_LEGACY; 1561 mmc_set_initial_state(host);
1537 mmc_set_ios(host);
1538 1562
1539 /* Try to set signal voltage to 3.3V but fall back to 1.8v or 1.2v */ 1563 /* Try to set signal voltage to 3.3V but fall back to 1.8v or 1.2v */
1540 if (__mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330) == 0) 1564 if (__mmc_set_signal_voltage(host, MMC_SIGNAL_VOLTAGE_330) == 0)
@@ -1574,14 +1598,9 @@ void mmc_power_off(struct mmc_host *host)
1574 host->ios.clock = 0; 1598 host->ios.clock = 0;
1575 host->ios.vdd = 0; 1599 host->ios.vdd = 0;
1576 1600
1577 if (!mmc_host_is_spi(host)) {
1578 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
1579 host->ios.chip_select = MMC_CS_DONTCARE;
1580 }
1581 host->ios.power_mode = MMC_POWER_OFF; 1601 host->ios.power_mode = MMC_POWER_OFF;
1582 host->ios.bus_width = MMC_BUS_WIDTH_1; 1602 /* Set initial state and call mmc_set_ios */
1583 host->ios.timing = MMC_TIMING_LEGACY; 1603 mmc_set_initial_state(host);
1584 mmc_set_ios(host);
1585 1604
1586 /* 1605 /*
1587 * Some configurations, such as the 802.11 SDIO card in the OLPC 1606 * Some configurations, such as the 802.11 SDIO card in the OLPC
@@ -2259,30 +2278,16 @@ static int mmc_do_hw_reset(struct mmc_host *host, int check)
2259 2278
2260 /* If the reset has happened, then a status command will fail */ 2279 /* If the reset has happened, then a status command will fail */
2261 if (check) { 2280 if (check) {
2262 struct mmc_command cmd = {0}; 2281 u32 status;
2263 int err;
2264 2282
2265 cmd.opcode = MMC_SEND_STATUS; 2283 if (!mmc_send_status(card, &status)) {
2266 if (!mmc_host_is_spi(card->host))
2267 cmd.arg = card->rca << 16;
2268 cmd.flags = MMC_RSP_SPI_R2 | MMC_RSP_R1 | MMC_CMD_AC;
2269 err = mmc_wait_for_cmd(card->host, &cmd, 0);
2270 if (!err) {
2271 mmc_host_clk_release(host); 2284 mmc_host_clk_release(host);
2272 return -ENOSYS; 2285 return -ENOSYS;
2273 } 2286 }
2274 } 2287 }
2275 2288
2276 if (mmc_host_is_spi(host)) { 2289 /* Set initial state and call mmc_set_ios */
2277 host->ios.chip_select = MMC_CS_HIGH; 2290 mmc_set_initial_state(host);
2278 host->ios.bus_mode = MMC_BUSMODE_PUSHPULL;
2279 } else {
2280 host->ios.chip_select = MMC_CS_DONTCARE;
2281 host->ios.bus_mode = MMC_BUSMODE_OPENDRAIN;
2282 }
2283 host->ios.bus_width = MMC_BUS_WIDTH_1;
2284 host->ios.timing = MMC_TIMING_LEGACY;
2285 mmc_set_ios(host);
2286 2291
2287 mmc_host_clk_release(host); 2292 mmc_host_clk_release(host);
2288 2293
diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h
index 443a584660f0..d76597c65e3a 100644
--- a/drivers/mmc/core/core.h
+++ b/drivers/mmc/core/core.h
@@ -49,6 +49,7 @@ void mmc_set_driver_type(struct mmc_host *host, unsigned int drv_type);
49void mmc_power_up(struct mmc_host *host, u32 ocr); 49void mmc_power_up(struct mmc_host *host, u32 ocr);
50void mmc_power_off(struct mmc_host *host); 50void mmc_power_off(struct mmc_host *host);
51void mmc_power_cycle(struct mmc_host *host, u32 ocr); 51void mmc_power_cycle(struct mmc_host *host, u32 ocr);
52void mmc_set_initial_state(struct mmc_host *host);
52 53
53static inline void mmc_delay(unsigned int ms) 54static inline void mmc_delay(unsigned int ms)
54{ 55{
diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 91eb16223246..e9142108a6c6 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -291,14 +291,8 @@ static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
291 if (!buf) 291 if (!buf)
292 return -ENOMEM; 292 return -ENOMEM;
293 293
294 ext_csd = kmalloc(512, GFP_KERNEL);
295 if (!ext_csd) {
296 err = -ENOMEM;
297 goto out_free;
298 }
299
300 mmc_get_card(card); 294 mmc_get_card(card);
301 err = mmc_send_ext_csd(card, ext_csd); 295 err = mmc_get_ext_csd(card, &ext_csd);
302 mmc_put_card(card); 296 mmc_put_card(card);
303 if (err) 297 if (err)
304 goto out_free; 298 goto out_free;
@@ -314,7 +308,6 @@ static int mmc_ext_csd_open(struct inode *inode, struct file *filp)
314 308
315out_free: 309out_free:
316 kfree(buf); 310 kfree(buf);
317 kfree(ext_csd);
318 return err; 311 return err;
319} 312}
320 313
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index 03c53b72a2d6..270d58a4c43d 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -311,7 +311,8 @@ int mmc_of_parse(struct mmc_host *host)
311 struct device_node *np; 311 struct device_node *np;
312 u32 bus_width; 312 u32 bus_width;
313 int len, ret; 313 int len, ret;
314 bool cap_invert, gpio_invert; 314 bool cd_cap_invert, cd_gpio_invert = false;
315 bool ro_cap_invert, ro_gpio_invert = false;
315 316
316 if (!host->parent || !host->parent->of_node) 317 if (!host->parent || !host->parent->of_node)
317 return 0; 318 return 0;
@@ -359,16 +360,13 @@ int mmc_of_parse(struct mmc_host *host)
359 if (of_find_property(np, "non-removable", &len)) { 360 if (of_find_property(np, "non-removable", &len)) {
360 host->caps |= MMC_CAP_NONREMOVABLE; 361 host->caps |= MMC_CAP_NONREMOVABLE;
361 } else { 362 } else {
362 if (of_property_read_bool(np, "cd-inverted")) 363 cd_cap_invert = of_property_read_bool(np, "cd-inverted");
363 cap_invert = true;
364 else
365 cap_invert = false;
366 364
367 if (of_find_property(np, "broken-cd", &len)) 365 if (of_find_property(np, "broken-cd", &len))
368 host->caps |= MMC_CAP_NEEDS_POLL; 366 host->caps |= MMC_CAP_NEEDS_POLL;
369 367
370 ret = mmc_gpiod_request_cd(host, "cd", 0, true, 368 ret = mmc_gpiod_request_cd(host, "cd", 0, true,
371 0, &gpio_invert); 369 0, &cd_gpio_invert);
372 if (ret) { 370 if (ret) {
373 if (ret == -EPROBE_DEFER) 371 if (ret == -EPROBE_DEFER)
374 return ret; 372 return ret;
@@ -391,17 +389,14 @@ int mmc_of_parse(struct mmc_host *host)
391 * both inverted, the end result is that the CD line is 389 * both inverted, the end result is that the CD line is
392 * not inverted. 390 * not inverted.
393 */ 391 */
394 if (cap_invert ^ gpio_invert) 392 if (cd_cap_invert ^ cd_gpio_invert)
395 host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; 393 host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
396 } 394 }
397 395
398 /* Parse Write Protection */ 396 /* Parse Write Protection */
399 if (of_property_read_bool(np, "wp-inverted")) 397 ro_cap_invert = of_property_read_bool(np, "wp-inverted");
400 cap_invert = true;
401 else
402 cap_invert = false;
403 398
404 ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &gpio_invert); 399 ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &ro_gpio_invert);
405 if (ret) { 400 if (ret) {
406 if (ret == -EPROBE_DEFER) 401 if (ret == -EPROBE_DEFER)
407 goto out; 402 goto out;
@@ -414,7 +409,7 @@ int mmc_of_parse(struct mmc_host *host)
414 dev_info(host->parent, "Got WP GPIO\n"); 409 dev_info(host->parent, "Got WP GPIO\n");
415 410
416 /* See the comment on CD inversion above */ 411 /* See the comment on CD inversion above */
417 if (cap_invert ^ gpio_invert) 412 if (ro_cap_invert ^ ro_gpio_invert)
418 host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; 413 host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
419 414
420 if (of_find_property(np, "cap-sd-highspeed", &len)) 415 if (of_find_property(np, "cap-sd-highspeed", &len))
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index a301a78a2bd1..02ad79229f65 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -177,65 +177,6 @@ static int mmc_decode_csd(struct mmc_card *card)
177 return 0; 177 return 0;
178} 178}
179 179
180/*
181 * Read extended CSD.
182 */
183static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
184{
185 int err;
186 u8 *ext_csd;
187
188 BUG_ON(!card);
189 BUG_ON(!new_ext_csd);
190
191 *new_ext_csd = NULL;
192
193 if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
194 return 0;
195
196 /*
197 * As the ext_csd is so large and mostly unused, we don't store the
198 * raw block in mmc_card.
199 */
200 ext_csd = kmalloc(512, GFP_KERNEL);
201 if (!ext_csd) {
202 pr_err("%s: could not allocate a buffer to "
203 "receive the ext_csd.\n", mmc_hostname(card->host));
204 return -ENOMEM;
205 }
206
207 err = mmc_send_ext_csd(card, ext_csd);
208 if (err) {
209 kfree(ext_csd);
210 *new_ext_csd = NULL;
211
212 /* If the host or the card can't do the switch,
213 * fail more gracefully. */
214 if ((err != -EINVAL)
215 && (err != -ENOSYS)
216 && (err != -EFAULT))
217 return err;
218
219 /*
220 * High capacity cards should have this "magic" size
221 * stored in their CSD.
222 */
223 if (card->csd.capacity == (4096 * 512)) {
224 pr_err("%s: unable to read EXT_CSD "
225 "on a possible high capacity card. "
226 "Card will be ignored.\n",
227 mmc_hostname(card->host));
228 } else {
229 pr_warn("%s: unable to read EXT_CSD, performance might suffer\n",
230 mmc_hostname(card->host));
231 err = 0;
232 }
233 } else
234 *new_ext_csd = ext_csd;
235
236 return err;
237}
238
239static void mmc_select_card_type(struct mmc_card *card) 180static void mmc_select_card_type(struct mmc_card *card)
240{ 181{
241 struct mmc_host *host = card->host; 182 struct mmc_host *host = card->host;
@@ -391,16 +332,11 @@ static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
391/* 332/*
392 * Decode extended CSD. 333 * Decode extended CSD.
393 */ 334 */
394static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) 335static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
395{ 336{
396 int err = 0, idx; 337 int err = 0, idx;
397 unsigned int part_size; 338 unsigned int part_size;
398 339
399 BUG_ON(!card);
400
401 if (!ext_csd)
402 return 0;
403
404 /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */ 340 /* Version is coded in the CSD_STRUCTURE byte in the EXT_CSD register */
405 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; 341 card->ext_csd.raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE];
406 if (card->csd.structure == 3) { 342 if (card->csd.structure == 3) {
@@ -628,16 +564,56 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
628 card->ext_csd.data_sector_size = 512; 564 card->ext_csd.data_sector_size = 512;
629 } 565 }
630 566
567 /* eMMC v5 or later */
568 if (card->ext_csd.rev >= 7) {
569 memcpy(card->ext_csd.fwrev, &ext_csd[EXT_CSD_FIRMWARE_VERSION],
570 MMC_FIRMWARE_LEN);
571 card->ext_csd.ffu_capable =
572 (ext_csd[EXT_CSD_SUPPORTED_MODE] & 0x1) &&
573 !(ext_csd[EXT_CSD_FW_CONFIG] & 0x1);
574 }
631out: 575out:
632 return err; 576 return err;
633} 577}
634 578
635static inline void mmc_free_ext_csd(u8 *ext_csd) 579static int mmc_read_ext_csd(struct mmc_card *card)
636{ 580{
581 u8 *ext_csd;
582 int err;
583
584 if (!mmc_can_ext_csd(card))
585 return 0;
586
587 err = mmc_get_ext_csd(card, &ext_csd);
588 if (err) {
589 /* If the host or the card can't do the switch,
590 * fail more gracefully. */
591 if ((err != -EINVAL)
592 && (err != -ENOSYS)
593 && (err != -EFAULT))
594 return err;
595
596 /*
597 * High capacity cards should have this "magic" size
598 * stored in their CSD.
599 */
600 if (card->csd.capacity == (4096 * 512)) {
601 pr_err("%s: unable to read EXT_CSD on a possible high capacity card. Card will be ignored.\n",
602 mmc_hostname(card->host));
603 } else {
604 pr_warn("%s: unable to read EXT_CSD, performance might suffer\n",
605 mmc_hostname(card->host));
606 err = 0;
607 }
608
609 return err;
610 }
611
612 err = mmc_decode_ext_csd(card, ext_csd);
637 kfree(ext_csd); 613 kfree(ext_csd);
614 return err;
638} 615}
639 616
640
641static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width) 617static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width)
642{ 618{
643 u8 *bw_ext_csd; 619 u8 *bw_ext_csd;
@@ -647,11 +623,8 @@ static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width)
647 return 0; 623 return 0;
648 624
649 err = mmc_get_ext_csd(card, &bw_ext_csd); 625 err = mmc_get_ext_csd(card, &bw_ext_csd);
650 626 if (err)
651 if (err || bw_ext_csd == NULL) { 627 return err;
652 err = -EINVAL;
653 goto out;
654 }
655 628
656 /* only compare read only fields */ 629 /* only compare read only fields */
657 err = !((card->ext_csd.raw_partition_support == 630 err = !((card->ext_csd.raw_partition_support ==
@@ -710,8 +683,7 @@ static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width)
710 if (err) 683 if (err)
711 err = -EINVAL; 684 err = -EINVAL;
712 685
713out: 686 kfree(bw_ext_csd);
714 mmc_free_ext_csd(bw_ext_csd);
715 return err; 687 return err;
716} 688}
717 689
@@ -722,7 +694,7 @@ MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
722MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year); 694MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
723MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9); 695MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
724MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9); 696MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
725MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev); 697MMC_DEV_ATTR(ffu_capable, "%d\n", card->ext_csd.ffu_capable);
726MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev); 698MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
727MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid); 699MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
728MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name); 700MMC_DEV_ATTR(name, "%s\n", card->cid.prod_name);
@@ -735,6 +707,22 @@ MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size);
735MMC_DEV_ATTR(raw_rpmb_size_mult, "%#x\n", card->ext_csd.raw_rpmb_size_mult); 707MMC_DEV_ATTR(raw_rpmb_size_mult, "%#x\n", card->ext_csd.raw_rpmb_size_mult);
736MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors); 708MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors);
737 709
710static ssize_t mmc_fwrev_show(struct device *dev,
711 struct device_attribute *attr,
712 char *buf)
713{
714 struct mmc_card *card = mmc_dev_to_card(dev);
715
716 if (card->ext_csd.rev < 7) {
717 return sprintf(buf, "0x%x\n", card->cid.fwrev);
718 } else {
719 return sprintf(buf, "0x%*phN\n", MMC_FIRMWARE_LEN,
720 card->ext_csd.fwrev);
721 }
722}
723
724static DEVICE_ATTR(fwrev, S_IRUGO, mmc_fwrev_show, NULL);
725
738static struct attribute *mmc_std_attrs[] = { 726static struct attribute *mmc_std_attrs[] = {
739 &dev_attr_cid.attr, 727 &dev_attr_cid.attr,
740 &dev_attr_csd.attr, 728 &dev_attr_csd.attr,
@@ -742,6 +730,7 @@ static struct attribute *mmc_std_attrs[] = {
742 &dev_attr_erase_size.attr, 730 &dev_attr_erase_size.attr,
743 &dev_attr_preferred_erase_size.attr, 731 &dev_attr_preferred_erase_size.attr,
744 &dev_attr_fwrev.attr, 732 &dev_attr_fwrev.attr,
733 &dev_attr_ffu_capable.attr,
745 &dev_attr_hwrev.attr, 734 &dev_attr_hwrev.attr,
746 &dev_attr_manfid.attr, 735 &dev_attr_manfid.attr,
747 &dev_attr_name.attr, 736 &dev_attr_name.attr,
@@ -774,14 +763,6 @@ static int __mmc_select_powerclass(struct mmc_card *card,
774 unsigned int pwrclass_val = 0; 763 unsigned int pwrclass_val = 0;
775 int err = 0; 764 int err = 0;
776 765
777 /* Power class selection is supported for versions >= 4.0 */
778 if (card->csd.mmca_vsn < CSD_SPEC_VER_4)
779 return 0;
780
781 /* Power class values are defined only for 4/8 bit bus */
782 if (bus_width == EXT_CSD_BUS_WIDTH_1)
783 return 0;
784
785 switch (1 << host->ios.vdd) { 766 switch (1 << host->ios.vdd) {
786 case MMC_VDD_165_195: 767 case MMC_VDD_165_195:
787 if (host->ios.clock <= MMC_HIGH_26_MAX_DTR) 768 if (host->ios.clock <= MMC_HIGH_26_MAX_DTR)
@@ -844,7 +825,7 @@ static int mmc_select_powerclass(struct mmc_card *card)
844 int err, ddr; 825 int err, ddr;
845 826
846 /* Power class selection is supported for versions >= 4.0 */ 827 /* Power class selection is supported for versions >= 4.0 */
847 if (card->csd.mmca_vsn < CSD_SPEC_VER_4) 828 if (!mmc_can_ext_csd(card))
848 return 0; 829 return 0;
849 830
850 bus_width = host->ios.bus_width; 831 bus_width = host->ios.bus_width;
@@ -905,7 +886,7 @@ static int mmc_select_bus_width(struct mmc_card *card)
905 unsigned idx, bus_width = 0; 886 unsigned idx, bus_width = 0;
906 int err = 0; 887 int err = 0;
907 888
908 if ((card->csd.mmca_vsn < CSD_SPEC_VER_4) && 889 if (!mmc_can_ext_csd(card) &&
909 !(host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA))) 890 !(host->caps & (MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA)))
910 return 0; 891 return 0;
911 892
@@ -998,7 +979,7 @@ static int mmc_select_hs_ddr(struct mmc_card *card)
998 ext_csd_bits, 979 ext_csd_bits,
999 card->ext_csd.generic_cmd6_time); 980 card->ext_csd.generic_cmd6_time);
1000 if (err) { 981 if (err) {
1001 pr_warn("%s: switch to bus width %d ddr failed\n", 982 pr_err("%s: switch to bus width %d ddr failed\n",
1002 mmc_hostname(host), 1 << bus_width); 983 mmc_hostname(host), 1 << bus_width);
1003 return err; 984 return err;
1004 } 985 }
@@ -1069,7 +1050,7 @@ static int mmc_select_hs400(struct mmc_card *card)
1069 card->ext_csd.generic_cmd6_time, 1050 card->ext_csd.generic_cmd6_time,
1070 true, true, true); 1051 true, true, true);
1071 if (err) { 1052 if (err) {
1072 pr_warn("%s: switch to high-speed from hs200 failed, err:%d\n", 1053 pr_err("%s: switch to high-speed from hs200 failed, err:%d\n",
1073 mmc_hostname(host), err); 1054 mmc_hostname(host), err);
1074 return err; 1055 return err;
1075 } 1056 }
@@ -1079,7 +1060,7 @@ static int mmc_select_hs400(struct mmc_card *card)
1079 EXT_CSD_DDR_BUS_WIDTH_8, 1060 EXT_CSD_DDR_BUS_WIDTH_8,
1080 card->ext_csd.generic_cmd6_time); 1061 card->ext_csd.generic_cmd6_time);
1081 if (err) { 1062 if (err) {
1082 pr_warn("%s: switch to bus width for hs400 failed, err:%d\n", 1063 pr_err("%s: switch to bus width for hs400 failed, err:%d\n",
1083 mmc_hostname(host), err); 1064 mmc_hostname(host), err);
1084 return err; 1065 return err;
1085 } 1066 }
@@ -1089,7 +1070,7 @@ static int mmc_select_hs400(struct mmc_card *card)
1089 card->ext_csd.generic_cmd6_time, 1070 card->ext_csd.generic_cmd6_time,
1090 true, true, true); 1071 true, true, true);
1091 if (err) { 1072 if (err) {
1092 pr_warn("%s: switch to hs400 failed, err:%d\n", 1073 pr_err("%s: switch to hs400 failed, err:%d\n",
1093 mmc_hostname(host), err); 1074 mmc_hostname(host), err);
1094 return err; 1075 return err;
1095 } 1076 }
@@ -1146,8 +1127,7 @@ static int mmc_select_timing(struct mmc_card *card)
1146{ 1127{
1147 int err = 0; 1128 int err = 0;
1148 1129
1149 if ((card->csd.mmca_vsn < CSD_SPEC_VER_4 && 1130 if (!mmc_can_ext_csd(card))
1150 card->ext_csd.hs_max_dtr == 0))
1151 goto bus_speed; 1131 goto bus_speed;
1152 1132
1153 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200) 1133 if (card->mmc_avail_type & EXT_CSD_CARD_TYPE_HS200)
@@ -1232,7 +1212,7 @@ static int mmc_hs200_tuning(struct mmc_card *card)
1232 mmc_host_clk_release(host); 1212 mmc_host_clk_release(host);
1233 1213
1234 if (err) 1214 if (err)
1235 pr_warn("%s: tuning execution failed\n", 1215 pr_err("%s: tuning execution failed\n",
1236 mmc_hostname(host)); 1216 mmc_hostname(host));
1237 } 1217 }
1238 1218
@@ -1252,7 +1232,6 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1252 int err; 1232 int err;
1253 u32 cid[4]; 1233 u32 cid[4];
1254 u32 rocr; 1234 u32 rocr;
1255 u8 *ext_csd = NULL;
1256 1235
1257 BUG_ON(!host); 1236 BUG_ON(!host);
1258 WARN_ON(!host->claimed); 1237 WARN_ON(!host->claimed);
@@ -1361,14 +1340,8 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1361 } 1340 }
1362 1341
1363 if (!oldcard) { 1342 if (!oldcard) {
1364 /* 1343 /* Read extended CSD. */
1365 * Fetch and process extended CSD. 1344 err = mmc_read_ext_csd(card);
1366 */
1367
1368 err = mmc_get_ext_csd(card, &ext_csd);
1369 if (err)
1370 goto free_card;
1371 err = mmc_read_ext_csd(card, ext_csd);
1372 if (err) 1345 if (err)
1373 goto free_card; 1346 goto free_card;
1374 1347
@@ -1458,18 +1431,18 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1458 if (mmc_card_hs200(card)) { 1431 if (mmc_card_hs200(card)) {
1459 err = mmc_hs200_tuning(card); 1432 err = mmc_hs200_tuning(card);
1460 if (err) 1433 if (err)
1461 goto err; 1434 goto free_card;
1462 1435
1463 err = mmc_select_hs400(card); 1436 err = mmc_select_hs400(card);
1464 if (err) 1437 if (err)
1465 goto err; 1438 goto free_card;
1466 } else if (mmc_card_hs(card)) { 1439 } else if (mmc_card_hs(card)) {
1467 /* Select the desired bus width optionally */ 1440 /* Select the desired bus width optionally */
1468 err = mmc_select_bus_width(card); 1441 err = mmc_select_bus_width(card);
1469 if (!IS_ERR_VALUE(err)) { 1442 if (!IS_ERR_VALUE(err)) {
1470 err = mmc_select_hs_ddr(card); 1443 err = mmc_select_hs_ddr(card);
1471 if (err) 1444 if (err)
1472 goto err; 1445 goto free_card;
1473 } 1446 }
1474 } 1447 }
1475 1448
@@ -1545,15 +1518,12 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
1545 if (!oldcard) 1518 if (!oldcard)
1546 host->card = card; 1519 host->card = card;
1547 1520
1548 mmc_free_ext_csd(ext_csd);
1549 return 0; 1521 return 0;
1550 1522
1551free_card: 1523free_card:
1552 if (!oldcard) 1524 if (!oldcard)
1553 mmc_remove_card(card); 1525 mmc_remove_card(card);
1554err: 1526err:
1555 mmc_free_ext_csd(ext_csd);
1556
1557 return err; 1527 return err;
1558} 1528}
1559 1529
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 7911e0510a1d..3b044c5b029c 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -264,20 +264,6 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
264 struct mmc_command cmd = {0}; 264 struct mmc_command cmd = {0};
265 struct mmc_data data = {0}; 265 struct mmc_data data = {0};
266 struct scatterlist sg; 266 struct scatterlist sg;
267 void *data_buf;
268 int is_on_stack;
269
270 is_on_stack = object_is_on_stack(buf);
271 if (is_on_stack) {
272 /*
273 * dma onto stack is unsafe/nonportable, but callers to this
274 * routine normally provide temporary on-stack buffers ...
275 */
276 data_buf = kmalloc(len, GFP_KERNEL);
277 if (!data_buf)
278 return -ENOMEM;
279 } else
280 data_buf = buf;
281 267
282 mrq.cmd = &cmd; 268 mrq.cmd = &cmd;
283 mrq.data = &data; 269 mrq.data = &data;
@@ -298,7 +284,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
298 data.sg = &sg; 284 data.sg = &sg;
299 data.sg_len = 1; 285 data.sg_len = 1;
300 286
301 sg_init_one(&sg, data_buf, len); 287 sg_init_one(&sg, buf, len);
302 288
303 if (opcode == MMC_SEND_CSD || opcode == MMC_SEND_CID) { 289 if (opcode == MMC_SEND_CSD || opcode == MMC_SEND_CID) {
304 /* 290 /*
@@ -312,11 +298,6 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
312 298
313 mmc_wait_for_req(host, &mrq); 299 mmc_wait_for_req(host, &mrq);
314 300
315 if (is_on_stack) {
316 memcpy(buf, data_buf, len);
317 kfree(data_buf);
318 }
319
320 if (cmd.error) 301 if (cmd.error)
321 return cmd.error; 302 return cmd.error;
322 if (data.error) 303 if (data.error)
@@ -334,7 +315,7 @@ int mmc_send_csd(struct mmc_card *card, u32 *csd)
334 return mmc_send_cxd_native(card->host, card->rca << 16, 315 return mmc_send_cxd_native(card->host, card->rca << 16,
335 csd, MMC_SEND_CSD); 316 csd, MMC_SEND_CSD);
336 317
337 csd_tmp = kmalloc(16, GFP_KERNEL); 318 csd_tmp = kzalloc(16, GFP_KERNEL);
338 if (!csd_tmp) 319 if (!csd_tmp)
339 return -ENOMEM; 320 return -ENOMEM;
340 321
@@ -362,7 +343,7 @@ int mmc_send_cid(struct mmc_host *host, u32 *cid)
362 cid, MMC_SEND_CID); 343 cid, MMC_SEND_CID);
363 } 344 }
364 345
365 cid_tmp = kmalloc(16, GFP_KERNEL); 346 cid_tmp = kzalloc(16, GFP_KERNEL);
366 if (!cid_tmp) 347 if (!cid_tmp)
367 return -ENOMEM; 348 return -ENOMEM;
368 349
@@ -378,12 +359,35 @@ err:
378 return ret; 359 return ret;
379} 360}
380 361
381int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd) 362int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
382{ 363{
383 return mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD, 364 int err;
384 ext_csd, 512); 365 u8 *ext_csd;
366
367 if (!card || !new_ext_csd)
368 return -EINVAL;
369
370 if (!mmc_can_ext_csd(card))
371 return -EOPNOTSUPP;
372
373 /*
374 * As the ext_csd is so large and mostly unused, we don't store the
375 * raw block in mmc_card.
376 */
377 ext_csd = kzalloc(512, GFP_KERNEL);
378 if (!ext_csd)
379 return -ENOMEM;
380
381 err = mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD, ext_csd,
382 512);
383 if (err)
384 kfree(ext_csd);
385 else
386 *new_ext_csd = ext_csd;
387
388 return err;
385} 389}
386EXPORT_SYMBOL_GPL(mmc_send_ext_csd); 390EXPORT_SYMBOL_GPL(mmc_get_ext_csd);
387 391
388int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp) 392int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp)
389{ 393{
@@ -543,6 +547,75 @@ int mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
543} 547}
544EXPORT_SYMBOL_GPL(mmc_switch); 548EXPORT_SYMBOL_GPL(mmc_switch);
545 549
550int mmc_send_tuning(struct mmc_host *host)
551{
552 struct mmc_request mrq = {NULL};
553 struct mmc_command cmd = {0};
554 struct mmc_data data = {0};
555 struct scatterlist sg;
556 struct mmc_ios *ios = &host->ios;
557 const u8 *tuning_block_pattern;
558 int size, err = 0;
559 u8 *data_buf;
560 u32 opcode;
561
562 if (ios->bus_width == MMC_BUS_WIDTH_8) {
563 tuning_block_pattern = tuning_blk_pattern_8bit;
564 size = sizeof(tuning_blk_pattern_8bit);
565 opcode = MMC_SEND_TUNING_BLOCK_HS200;
566 } else if (ios->bus_width == MMC_BUS_WIDTH_4) {
567 tuning_block_pattern = tuning_blk_pattern_4bit;
568 size = sizeof(tuning_blk_pattern_4bit);
569 opcode = MMC_SEND_TUNING_BLOCK;
570 } else
571 return -EINVAL;
572
573 data_buf = kzalloc(size, GFP_KERNEL);
574 if (!data_buf)
575 return -ENOMEM;
576
577 mrq.cmd = &cmd;
578 mrq.data = &data;
579
580 cmd.opcode = opcode;
581 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
582
583 data.blksz = size;
584 data.blocks = 1;
585 data.flags = MMC_DATA_READ;
586
587 /*
588 * According to the tuning specs, Tuning process
589 * is normally shorter 40 executions of CMD19,
590 * and timeout value should be shorter than 150 ms
591 */
592 data.timeout_ns = 150 * NSEC_PER_MSEC;
593
594 data.sg = &sg;
595 data.sg_len = 1;
596 sg_init_one(&sg, data_buf, size);
597
598 mmc_wait_for_req(host, &mrq);
599
600 if (cmd.error) {
601 err = cmd.error;
602 goto out;
603 }
604
605 if (data.error) {
606 err = data.error;
607 goto out;
608 }
609
610 if (memcmp(data_buf, tuning_block_pattern, size))
611 err = -EIO;
612
613out:
614 kfree(data_buf);
615 return err;
616}
617EXPORT_SYMBOL_GPL(mmc_send_tuning);
618
546static int 619static int
547mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode, 620mmc_send_bus_test(struct mmc_card *card, struct mmc_host *host, u8 opcode,
548 u8 len) 621 u8 len)
@@ -675,3 +748,8 @@ int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status)
675 748
676 return 0; 749 return 0;
677} 750}
751
752int mmc_can_ext_csd(struct mmc_card *card)
753{
754 return (card && card->csd.mmca_vsn > CSD_SPEC_VER_3);
755}
diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
index 390dac665b2a..6f4b00ed93de 100644
--- a/drivers/mmc/core/mmc_ops.h
+++ b/drivers/mmc/core/mmc_ops.h
@@ -20,13 +20,13 @@ int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr);
20int mmc_all_send_cid(struct mmc_host *host, u32 *cid); 20int mmc_all_send_cid(struct mmc_host *host, u32 *cid);
21int mmc_set_relative_addr(struct mmc_card *card); 21int mmc_set_relative_addr(struct mmc_card *card);
22int mmc_send_csd(struct mmc_card *card, u32 *csd); 22int mmc_send_csd(struct mmc_card *card, u32 *csd);
23int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd);
24int mmc_send_status(struct mmc_card *card, u32 *status); 23int mmc_send_status(struct mmc_card *card, u32 *status);
25int mmc_send_cid(struct mmc_host *host, u32 *cid); 24int mmc_send_cid(struct mmc_host *host, u32 *cid);
26int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp); 25int mmc_spi_read_ocr(struct mmc_host *host, int highcap, u32 *ocrp);
27int mmc_spi_set_crc(struct mmc_host *host, int use_crc); 26int mmc_spi_set_crc(struct mmc_host *host, int use_crc);
28int mmc_bus_test(struct mmc_card *card, u8 bus_width); 27int mmc_bus_test(struct mmc_card *card, u8 bus_width);
29int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status); 28int mmc_send_hpi_cmd(struct mmc_card *card, u32 *status);
29int mmc_can_ext_csd(struct mmc_card *card);
30 30
31#endif 31#endif
32 32
diff --git a/drivers/mmc/core/sdio.c b/drivers/mmc/core/sdio.c
index 2439e717655b..fd0750b5a634 100644
--- a/drivers/mmc/core/sdio.c
+++ b/drivers/mmc/core/sdio.c
@@ -980,8 +980,12 @@ static int mmc_sdio_resume(struct mmc_host *host)
980 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) { 980 if (mmc_card_is_removable(host) || !mmc_card_keep_power(host)) {
981 sdio_reset(host); 981 sdio_reset(host);
982 mmc_go_idle(host); 982 mmc_go_idle(host);
983 err = mmc_sdio_init_card(host, host->card->ocr, host->card, 983 mmc_send_if_cond(host, host->card->ocr);
984 mmc_card_keep_power(host)); 984 err = mmc_send_io_op_cond(host, 0, NULL);
985 if (!err)
986 err = mmc_sdio_init_card(host, host->card->ocr,
987 host->card,
988 mmc_card_keep_power(host));
985 } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) { 989 } else if (mmc_card_keep_power(host) && mmc_card_wake_sdio_irq(host)) {
986 /* We may have switched to 1-bit mode during suspend */ 990 /* We may have switched to 1-bit mode during suspend */
987 err = sdio_enable_4bit_bus(host->card); 991 err = sdio_enable_4bit_bus(host->card);
@@ -1035,7 +1039,7 @@ static int mmc_sdio_power_restore(struct mmc_host *host)
1035 1039
1036 sdio_reset(host); 1040 sdio_reset(host);
1037 mmc_go_idle(host); 1041 mmc_go_idle(host);
1038 mmc_send_if_cond(host, host->ocr_avail); 1042 mmc_send_if_cond(host, host->card->ocr);
1039 1043
1040 ret = mmc_send_io_op_cond(host, 0, NULL); 1044 ret = mmc_send_io_op_cond(host, 0, NULL);
1041 if (ret) 1045 if (ret)
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index 6da97b170563..60885316afba 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -26,6 +26,8 @@
26#include "sdio_cis.h" 26#include "sdio_cis.h"
27#include "sdio_bus.h" 27#include "sdio_bus.h"
28 28
29#define to_sdio_driver(d) container_of(d, struct sdio_driver, drv)
30
29/* show configuration fields */ 31/* show configuration fields */
30#define sdio_config_attr(field, format_string) \ 32#define sdio_config_attr(field, format_string) \
31static ssize_t \ 33static ssize_t \
@@ -196,8 +198,6 @@ static int sdio_bus_remove(struct device *dev)
196 return ret; 198 return ret;
197} 199}
198 200
199#ifdef CONFIG_PM
200
201static const struct dev_pm_ops sdio_bus_pm_ops = { 201static const struct dev_pm_ops sdio_bus_pm_ops = {
202 SET_SYSTEM_SLEEP_PM_OPS(pm_generic_suspend, pm_generic_resume) 202 SET_SYSTEM_SLEEP_PM_OPS(pm_generic_suspend, pm_generic_resume)
203 SET_RUNTIME_PM_OPS( 203 SET_RUNTIME_PM_OPS(
@@ -207,14 +207,6 @@ static const struct dev_pm_ops sdio_bus_pm_ops = {
207 ) 207 )
208}; 208};
209 209
210#define SDIO_PM_OPS_PTR (&sdio_bus_pm_ops)
211
212#else /* !CONFIG_PM */
213
214#define SDIO_PM_OPS_PTR NULL
215
216#endif /* !CONFIG_PM */
217
218static struct bus_type sdio_bus_type = { 210static struct bus_type sdio_bus_type = {
219 .name = "sdio", 211 .name = "sdio",
220 .dev_groups = sdio_dev_groups, 212 .dev_groups = sdio_dev_groups,
@@ -222,7 +214,7 @@ static struct bus_type sdio_bus_type = {
222 .uevent = sdio_bus_uevent, 214 .uevent = sdio_bus_uevent,
223 .probe = sdio_bus_probe, 215 .probe = sdio_bus_probe,
224 .remove = sdio_bus_remove, 216 .remove = sdio_bus_remove,
225 .pm = SDIO_PM_OPS_PTR, 217 .pm = &sdio_bus_pm_ops,
226}; 218};
227 219
228int sdio_register_bus(void) 220int sdio_register_bus(void)
@@ -295,7 +287,7 @@ struct sdio_func *sdio_alloc_func(struct mmc_card *card)
295static void sdio_acpi_set_handle(struct sdio_func *func) 287static void sdio_acpi_set_handle(struct sdio_func *func)
296{ 288{
297 struct mmc_host *host = func->card->host; 289 struct mmc_host *host = func->card->host;
298 u64 addr = (host->slotno << 16) | func->num; 290 u64 addr = ((u64)host->slotno << 16) | func->num;
299 291
300 acpi_preset_companion(&func->dev, ACPI_COMPANION(host->parent), addr); 292 acpi_preset_companion(&func->dev, ACPI_COMPANION(host->parent), addr);
301} 293}
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 13860656104b..2d6fbdd11803 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -580,7 +580,7 @@ config SDH_BFIN_MISSING_CMD_PULLUP_WORKAROUND
580config MMC_DW 580config MMC_DW
581 tristate "Synopsys DesignWare Memory Card Interface" 581 tristate "Synopsys DesignWare Memory Card Interface"
582 depends on HAS_DMA 582 depends on HAS_DMA
583 depends on ARC || ARM || MIPS || COMPILE_TEST 583 depends on ARC || ARM || ARM64 || MIPS || COMPILE_TEST
584 help 584 help
585 This selects support for the Synopsys DesignWare Mobile Storage IP 585 This selects support for the Synopsys DesignWare Mobile Storage IP
586 block, this provides host support for SD and MMC interfaces, in both 586 block, this provides host support for SD and MMC interfaces, in both
@@ -748,3 +748,8 @@ config MMC_SUNXI
748 help 748 help
749 This selects support for the SD/MMC Host Controller on 749 This selects support for the SD/MMC Host Controller on
750 Allwinner sunxi SoCs. 750 Allwinner sunxi SoCs.
751
752config MMC_TOSHIBA_PCI
753 tristate "Toshiba Type A SD/MMC Card Interface Driver"
754 depends on PCI
755 help
diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile
index b09ecfb88269..f7b0a77cf419 100644
--- a/drivers/mmc/host/Makefile
+++ b/drivers/mmc/host/Makefile
@@ -55,6 +55,7 @@ obj-$(CONFIG_MMC_WMT) += wmt-sdmmc.o
55obj-$(CONFIG_MMC_MOXART) += moxart-mmc.o 55obj-$(CONFIG_MMC_MOXART) += moxart-mmc.o
56obj-$(CONFIG_MMC_SUNXI) += sunxi-mmc.o 56obj-$(CONFIG_MMC_SUNXI) += sunxi-mmc.o
57obj-$(CONFIG_MMC_USDHI6ROL0) += usdhi6rol0.o 57obj-$(CONFIG_MMC_USDHI6ROL0) += usdhi6rol0.o
58obj-$(CONFIG_MMC_TOSHIBA_PCI) += toshsd.o
58 59
59obj-$(CONFIG_MMC_REALTEK_PCI) += rtsx_pci_sdmmc.o 60obj-$(CONFIG_MMC_REALTEK_PCI) += rtsx_pci_sdmmc.o
60obj-$(CONFIG_MMC_REALTEK_USB) += rtsx_usb_sdmmc.o 61obj-$(CONFIG_MMC_REALTEK_USB) += rtsx_usb_sdmmc.o
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 77250d4b1979..62aba9af19f4 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -30,13 +30,16 @@
30#include <linux/stat.h> 30#include <linux/stat.h>
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/platform_data/atmel.h> 32#include <linux/platform_data/atmel.h>
33#include <linux/platform_data/mmc-atmel-mci.h>
33 34
34#include <linux/mmc/host.h> 35#include <linux/mmc/host.h>
35#include <linux/mmc/sdio.h> 36#include <linux/mmc/sdio.h>
36 37
37#include <mach/atmel-mci.h>
38#include <linux/atmel-mci.h> 38#include <linux/atmel-mci.h>
39#include <linux/atmel_pdc.h> 39#include <linux/atmel_pdc.h>
40#include <linux/pm.h>
41#include <linux/pm_runtime.h>
42#include <linux/pinctrl/consumer.h>
40 43
41#include <asm/cacheflush.h> 44#include <asm/cacheflush.h>
42#include <asm/io.h> 45#include <asm/io.h>
@@ -44,6 +47,8 @@
44 47
45#include "atmel-mci-regs.h" 48#include "atmel-mci-regs.h"
46 49
50#define AUTOSUSPEND_DELAY 50
51
47#define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | ATMCI_UNRE) 52#define ATMCI_DATA_ERROR_FLAGS (ATMCI_DCRCE | ATMCI_DTOE | ATMCI_OVRE | ATMCI_UNRE)
48#define ATMCI_DMA_THRESHOLD 16 53#define ATMCI_DMA_THRESHOLD 16
49 54
@@ -386,20 +391,19 @@ static int atmci_regs_show(struct seq_file *s, void *v)
386 if (!buf) 391 if (!buf)
387 return -ENOMEM; 392 return -ENOMEM;
388 393
394 pm_runtime_get_sync(&host->pdev->dev);
395
389 /* 396 /*
390 * Grab a more or less consistent snapshot. Note that we're 397 * Grab a more or less consistent snapshot. Note that we're
391 * not disabling interrupts, so IMR and SR may not be 398 * not disabling interrupts, so IMR and SR may not be
392 * consistent. 399 * consistent.
393 */ 400 */
394 ret = clk_prepare_enable(host->mck);
395 if (ret)
396 goto out;
397
398 spin_lock_bh(&host->lock); 401 spin_lock_bh(&host->lock);
399 memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE); 402 memcpy_fromio(buf, host->regs, ATMCI_REGS_SIZE);
400 spin_unlock_bh(&host->lock); 403 spin_unlock_bh(&host->lock);
401 404
402 clk_disable_unprepare(host->mck); 405 pm_runtime_mark_last_busy(&host->pdev->dev);
406 pm_runtime_put_autosuspend(&host->pdev->dev);
403 407
404 seq_printf(s, "MR:\t0x%08x%s%s ", 408 seq_printf(s, "MR:\t0x%08x%s%s ",
405 buf[ATMCI_MR / 4], 409 buf[ATMCI_MR / 4],
@@ -449,7 +453,6 @@ static int atmci_regs_show(struct seq_file *s, void *v)
449 val & ATMCI_CFG_LSYNC ? " LSYNC" : ""); 453 val & ATMCI_CFG_LSYNC ? " LSYNC" : "");
450 } 454 }
451 455
452out:
453 kfree(buf); 456 kfree(buf);
454 457
455 return ret; 458 return ret;
@@ -560,6 +563,9 @@ atmci_of_init(struct platform_device *pdev)
560 pdata->slot[slot_id].detect_is_active_high = 563 pdata->slot[slot_id].detect_is_active_high =
561 of_property_read_bool(cnp, "cd-inverted"); 564 of_property_read_bool(cnp, "cd-inverted");
562 565
566 pdata->slot[slot_id].non_removable =
567 of_property_read_bool(cnp, "non-removable");
568
563 pdata->slot[slot_id].wp_pin = 569 pdata->slot[slot_id].wp_pin =
564 of_get_named_gpio(cnp, "wp-gpios", 0); 570 of_get_named_gpio(cnp, "wp-gpios", 0);
565 } 571 }
@@ -1252,6 +1258,8 @@ static void atmci_request(struct mmc_host *mmc, struct mmc_request *mrq)
1252 WARN_ON(slot->mrq); 1258 WARN_ON(slot->mrq);
1253 dev_dbg(&host->pdev->dev, "MRQ: cmd %u\n", mrq->cmd->opcode); 1259 dev_dbg(&host->pdev->dev, "MRQ: cmd %u\n", mrq->cmd->opcode);
1254 1260
1261 pm_runtime_get_sync(&host->pdev->dev);
1262
1255 /* 1263 /*
1256 * We may "know" the card is gone even though there's still an 1264 * We may "know" the card is gone even though there's still an
1257 * electrical connection. If so, we really need to communicate 1265 * electrical connection. If so, we really need to communicate
@@ -1281,7 +1289,8 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1281 struct atmel_mci_slot *slot = mmc_priv(mmc); 1289 struct atmel_mci_slot *slot = mmc_priv(mmc);
1282 struct atmel_mci *host = slot->host; 1290 struct atmel_mci *host = slot->host;
1283 unsigned int i; 1291 unsigned int i;
1284 bool unprepare_clk; 1292
1293 pm_runtime_get_sync(&host->pdev->dev);
1285 1294
1286 slot->sdc_reg &= ~ATMCI_SDCBUS_MASK; 1295 slot->sdc_reg &= ~ATMCI_SDCBUS_MASK;
1287 switch (ios->bus_width) { 1296 switch (ios->bus_width) {
@@ -1297,13 +1306,8 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1297 unsigned int clock_min = ~0U; 1306 unsigned int clock_min = ~0U;
1298 u32 clkdiv; 1307 u32 clkdiv;
1299 1308
1300 clk_prepare(host->mck);
1301 unprepare_clk = true;
1302
1303 spin_lock_bh(&host->lock); 1309 spin_lock_bh(&host->lock);
1304 if (!host->mode_reg) { 1310 if (!host->mode_reg) {
1305 clk_enable(host->mck);
1306 unprepare_clk = false;
1307 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); 1311 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
1308 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN); 1312 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIEN);
1309 if (host->caps.has_cfg_reg) 1313 if (host->caps.has_cfg_reg)
@@ -1371,8 +1375,6 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1371 } else { 1375 } else {
1372 bool any_slot_active = false; 1376 bool any_slot_active = false;
1373 1377
1374 unprepare_clk = false;
1375
1376 spin_lock_bh(&host->lock); 1378 spin_lock_bh(&host->lock);
1377 slot->clock = 0; 1379 slot->clock = 0;
1378 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) { 1380 for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
@@ -1385,17 +1387,12 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1385 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS); 1387 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS);
1386 if (host->mode_reg) { 1388 if (host->mode_reg) {
1387 atmci_readl(host, ATMCI_MR); 1389 atmci_readl(host, ATMCI_MR);
1388 clk_disable(host->mck);
1389 unprepare_clk = true;
1390 } 1390 }
1391 host->mode_reg = 0; 1391 host->mode_reg = 0;
1392 } 1392 }
1393 spin_unlock_bh(&host->lock); 1393 spin_unlock_bh(&host->lock);
1394 } 1394 }
1395 1395
1396 if (unprepare_clk)
1397 clk_unprepare(host->mck);
1398
1399 switch (ios->power_mode) { 1396 switch (ios->power_mode) {
1400 case MMC_POWER_OFF: 1397 case MMC_POWER_OFF:
1401 if (!IS_ERR(mmc->supply.vmmc)) 1398 if (!IS_ERR(mmc->supply.vmmc))
@@ -1421,6 +1418,9 @@ static void atmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1421 */ 1418 */
1422 break; 1419 break;
1423 } 1420 }
1421
1422 pm_runtime_mark_last_busy(&host->pdev->dev);
1423 pm_runtime_put_autosuspend(&host->pdev->dev);
1424} 1424}
1425 1425
1426static int atmci_get_ro(struct mmc_host *mmc) 1426static int atmci_get_ro(struct mmc_host *mmc)
@@ -1512,6 +1512,9 @@ static void atmci_request_end(struct atmel_mci *host, struct mmc_request *mrq)
1512 spin_unlock(&host->lock); 1512 spin_unlock(&host->lock);
1513 mmc_request_done(prev_mmc, mrq); 1513 mmc_request_done(prev_mmc, mrq);
1514 spin_lock(&host->lock); 1514 spin_lock(&host->lock);
1515
1516 pm_runtime_mark_last_busy(&host->pdev->dev);
1517 pm_runtime_put_autosuspend(&host->pdev->dev);
1515} 1518}
1516 1519
1517static void atmci_command_complete(struct atmel_mci *host, 1520static void atmci_command_complete(struct atmel_mci *host,
@@ -2137,7 +2140,7 @@ static irqreturn_t atmci_detect_interrupt(int irq, void *dev_id)
2137 return IRQ_HANDLED; 2140 return IRQ_HANDLED;
2138} 2141}
2139 2142
2140static int __init atmci_init_slot(struct atmel_mci *host, 2143static int atmci_init_slot(struct atmel_mci *host,
2141 struct mci_slot_pdata *slot_data, unsigned int id, 2144 struct mci_slot_pdata *slot_data, unsigned int id,
2142 u32 sdc_reg, u32 sdio_irq) 2145 u32 sdc_reg, u32 sdio_irq)
2143{ 2146{
@@ -2206,8 +2209,12 @@ static int __init atmci_init_slot(struct atmel_mci *host,
2206 } 2209 }
2207 } 2210 }
2208 2211
2209 if (!gpio_is_valid(slot->detect_pin)) 2212 if (!gpio_is_valid(slot->detect_pin)) {
2210 mmc->caps |= MMC_CAP_NEEDS_POLL; 2213 if (slot_data->non_removable)
2214 mmc->caps |= MMC_CAP_NONREMOVABLE;
2215 else
2216 mmc->caps |= MMC_CAP_NEEDS_POLL;
2217 }
2211 2218
2212 if (gpio_is_valid(slot->wp_pin)) { 2219 if (gpio_is_valid(slot->wp_pin)) {
2213 if (devm_gpio_request(&host->pdev->dev, slot->wp_pin, 2220 if (devm_gpio_request(&host->pdev->dev, slot->wp_pin,
@@ -2265,55 +2272,25 @@ static void atmci_cleanup_slot(struct atmel_mci_slot *slot,
2265 mmc_free_host(slot->mmc); 2272 mmc_free_host(slot->mmc);
2266} 2273}
2267 2274
2268static bool atmci_filter(struct dma_chan *chan, void *pdata) 2275static int atmci_configure_dma(struct atmel_mci *host)
2269{ 2276{
2270 struct mci_platform_data *sl_pdata = pdata; 2277 host->dma.chan = dma_request_slave_channel_reason(&host->pdev->dev,
2271 struct mci_dma_data *sl; 2278 "rxtx");
2272 2279 if (IS_ERR(host->dma.chan))
2273 if (!sl_pdata) 2280 return PTR_ERR(host->dma.chan);
2274 return false; 2281
2282 dev_info(&host->pdev->dev, "using %s for DMA transfers\n",
2283 dma_chan_name(host->dma.chan));
2284
2285 host->dma_conf.src_addr = host->mapbase + ATMCI_RDR;
2286 host->dma_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
2287 host->dma_conf.src_maxburst = 1;
2288 host->dma_conf.dst_addr = host->mapbase + ATMCI_TDR;
2289 host->dma_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
2290 host->dma_conf.dst_maxburst = 1;
2291 host->dma_conf.device_fc = false;
2275 2292
2276 sl = sl_pdata->dma_slave; 2293 return 0;
2277 if (sl && find_slave_dev(sl) == chan->device->dev) {
2278 chan->private = slave_data_ptr(sl);
2279 return true;
2280 } else {
2281 return false;
2282 }
2283}
2284
2285static bool atmci_configure_dma(struct atmel_mci *host)
2286{
2287 struct mci_platform_data *pdata;
2288 dma_cap_mask_t mask;
2289
2290 if (host == NULL)
2291 return false;
2292
2293 pdata = host->pdev->dev.platform_data;
2294
2295 dma_cap_zero(mask);
2296 dma_cap_set(DMA_SLAVE, mask);
2297
2298 host->dma.chan = dma_request_slave_channel_compat(mask, atmci_filter, pdata,
2299 &host->pdev->dev, "rxtx");
2300 if (!host->dma.chan) {
2301 dev_warn(&host->pdev->dev, "no DMA channel available\n");
2302 return false;
2303 } else {
2304 dev_info(&host->pdev->dev,
2305 "using %s for DMA transfers\n",
2306 dma_chan_name(host->dma.chan));
2307
2308 host->dma_conf.src_addr = host->mapbase + ATMCI_RDR;
2309 host->dma_conf.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
2310 host->dma_conf.src_maxburst = 1;
2311 host->dma_conf.dst_addr = host->mapbase + ATMCI_TDR;
2312 host->dma_conf.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
2313 host->dma_conf.dst_maxburst = 1;
2314 host->dma_conf.device_fc = false;
2315 return true;
2316 }
2317} 2294}
2318 2295
2319/* 2296/*
@@ -2321,7 +2298,7 @@ static bool atmci_configure_dma(struct atmel_mci *host)
2321 * HSMCI provides DMA support and a new config register but no more supports 2298 * HSMCI provides DMA support and a new config register but no more supports
2322 * PDC. 2299 * PDC.
2323 */ 2300 */
2324static void __init atmci_get_cap(struct atmel_mci *host) 2301static void atmci_get_cap(struct atmel_mci *host)
2325{ 2302{
2326 unsigned int version; 2303 unsigned int version;
2327 2304
@@ -2370,7 +2347,7 @@ static void __init atmci_get_cap(struct atmel_mci *host)
2370 } 2347 }
2371} 2348}
2372 2349
2373static int __init atmci_probe(struct platform_device *pdev) 2350static int atmci_probe(struct platform_device *pdev)
2374{ 2351{
2375 struct mci_platform_data *pdata; 2352 struct mci_platform_data *pdata;
2376 struct atmel_mci *host; 2353 struct atmel_mci *host;
@@ -2417,19 +2394,23 @@ static int __init atmci_probe(struct platform_device *pdev)
2417 2394
2418 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST); 2395 atmci_writel(host, ATMCI_CR, ATMCI_CR_SWRST);
2419 host->bus_hz = clk_get_rate(host->mck); 2396 host->bus_hz = clk_get_rate(host->mck);
2420 clk_disable_unprepare(host->mck);
2421 2397
2422 host->mapbase = regs->start; 2398 host->mapbase = regs->start;
2423 2399
2424 tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)host); 2400 tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)host);
2425 2401
2426 ret = request_irq(irq, atmci_interrupt, 0, dev_name(&pdev->dev), host); 2402 ret = request_irq(irq, atmci_interrupt, 0, dev_name(&pdev->dev), host);
2427 if (ret) 2403 if (ret) {
2404 clk_disable_unprepare(host->mck);
2428 return ret; 2405 return ret;
2406 }
2429 2407
2430 /* Get MCI capabilities and set operations according to it */ 2408 /* Get MCI capabilities and set operations according to it */
2431 atmci_get_cap(host); 2409 atmci_get_cap(host);
2432 if (atmci_configure_dma(host)) { 2410 ret = atmci_configure_dma(host);
2411 if (ret == -EPROBE_DEFER)
2412 goto err_dma_probe_defer;
2413 if (ret == 0) {
2433 host->prepare_data = &atmci_prepare_data_dma; 2414 host->prepare_data = &atmci_prepare_data_dma;
2434 host->submit_data = &atmci_submit_data_dma; 2415 host->submit_data = &atmci_submit_data_dma;
2435 host->stop_transfer = &atmci_stop_transfer_dma; 2416 host->stop_transfer = &atmci_stop_transfer_dma;
@@ -2449,6 +2430,12 @@ static int __init atmci_probe(struct platform_device *pdev)
2449 2430
2450 setup_timer(&host->timer, atmci_timeout_timer, (unsigned long)host); 2431 setup_timer(&host->timer, atmci_timeout_timer, (unsigned long)host);
2451 2432
2433 pm_runtime_get_noresume(&pdev->dev);
2434 pm_runtime_set_active(&pdev->dev);
2435 pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_DELAY);
2436 pm_runtime_use_autosuspend(&pdev->dev);
2437 pm_runtime_enable(&pdev->dev);
2438
2452 /* We need at least one slot to succeed */ 2439 /* We need at least one slot to succeed */
2453 nr_slots = 0; 2440 nr_slots = 0;
2454 ret = -ENODEV; 2441 ret = -ENODEV;
@@ -2491,6 +2478,9 @@ static int __init atmci_probe(struct platform_device *pdev)
2491 "Atmel MCI controller at 0x%08lx irq %d, %u slots\n", 2478 "Atmel MCI controller at 0x%08lx irq %d, %u slots\n",
2492 host->mapbase, irq, nr_slots); 2479 host->mapbase, irq, nr_slots);
2493 2480
2481 pm_runtime_mark_last_busy(&host->pdev->dev);
2482 pm_runtime_put_autosuspend(&pdev->dev);
2483
2494 return 0; 2484 return 0;
2495 2485
2496err_dma_alloc: 2486err_dma_alloc:
@@ -2499,18 +2489,26 @@ err_dma_alloc:
2499 atmci_cleanup_slot(host->slot[i], i); 2489 atmci_cleanup_slot(host->slot[i], i);
2500 } 2490 }
2501err_init_slot: 2491err_init_slot:
2492 clk_disable_unprepare(host->mck);
2493
2494 pm_runtime_disable(&pdev->dev);
2495 pm_runtime_put_noidle(&pdev->dev);
2496
2502 del_timer_sync(&host->timer); 2497 del_timer_sync(&host->timer);
2503 if (host->dma.chan) 2498 if (!IS_ERR(host->dma.chan))
2504 dma_release_channel(host->dma.chan); 2499 dma_release_channel(host->dma.chan);
2500err_dma_probe_defer:
2505 free_irq(irq, host); 2501 free_irq(irq, host);
2506 return ret; 2502 return ret;
2507} 2503}
2508 2504
2509static int __exit atmci_remove(struct platform_device *pdev) 2505static int atmci_remove(struct platform_device *pdev)
2510{ 2506{
2511 struct atmel_mci *host = platform_get_drvdata(pdev); 2507 struct atmel_mci *host = platform_get_drvdata(pdev);
2512 unsigned int i; 2508 unsigned int i;
2513 2509
2510 pm_runtime_get_sync(&pdev->dev);
2511
2514 if (host->buffer) 2512 if (host->buffer)
2515 dma_free_coherent(&pdev->dev, host->buf_size, 2513 dma_free_coherent(&pdev->dev, host->buf_size,
2516 host->buffer, host->buf_phys_addr); 2514 host->buffer, host->buf_phys_addr);
@@ -2520,41 +2518,62 @@ static int __exit atmci_remove(struct platform_device *pdev)
2520 atmci_cleanup_slot(host->slot[i], i); 2518 atmci_cleanup_slot(host->slot[i], i);
2521 } 2519 }
2522 2520
2523 clk_prepare_enable(host->mck);
2524 atmci_writel(host, ATMCI_IDR, ~0UL); 2521 atmci_writel(host, ATMCI_IDR, ~0UL);
2525 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS); 2522 atmci_writel(host, ATMCI_CR, ATMCI_CR_MCIDIS);
2526 atmci_readl(host, ATMCI_SR); 2523 atmci_readl(host, ATMCI_SR);
2527 clk_disable_unprepare(host->mck);
2528 2524
2529 del_timer_sync(&host->timer); 2525 del_timer_sync(&host->timer);
2530 if (host->dma.chan) 2526 if (!IS_ERR(host->dma.chan))
2531 dma_release_channel(host->dma.chan); 2527 dma_release_channel(host->dma.chan);
2532 2528
2533 free_irq(platform_get_irq(pdev, 0), host); 2529 free_irq(platform_get_irq(pdev, 0), host);
2534 2530
2531 clk_disable_unprepare(host->mck);
2532
2533 pm_runtime_disable(&pdev->dev);
2534 pm_runtime_put_noidle(&pdev->dev);
2535
2535 return 0; 2536 return 0;
2536} 2537}
2537 2538
2538static struct platform_driver atmci_driver = { 2539#ifdef CONFIG_PM
2539 .remove = __exit_p(atmci_remove), 2540static int atmci_runtime_suspend(struct device *dev)
2540 .driver = {
2541 .name = "atmel_mci",
2542 .of_match_table = of_match_ptr(atmci_dt_ids),
2543 },
2544};
2545
2546static int __init atmci_init(void)
2547{ 2541{
2548 return platform_driver_probe(&atmci_driver, atmci_probe); 2542 struct atmel_mci *host = dev_get_drvdata(dev);
2543
2544 clk_disable_unprepare(host->mck);
2545
2546 pinctrl_pm_select_sleep_state(dev);
2547
2548 return 0;
2549} 2549}
2550 2550
2551static void __exit atmci_exit(void) 2551static int atmci_runtime_resume(struct device *dev)
2552{ 2552{
2553 platform_driver_unregister(&atmci_driver); 2553 struct atmel_mci *host = dev_get_drvdata(dev);
2554
2555 pinctrl_pm_select_default_state(dev);
2556
2557 return clk_prepare_enable(host->mck);
2554} 2558}
2559#endif
2555 2560
2556late_initcall(atmci_init); /* try to load after dma driver when built-in */ 2561static const struct dev_pm_ops atmci_dev_pm_ops = {
2557module_exit(atmci_exit); 2562 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
2563 pm_runtime_force_resume)
2564 SET_PM_RUNTIME_PM_OPS(atmci_runtime_suspend, atmci_runtime_resume, NULL)
2565};
2566
2567static struct platform_driver atmci_driver = {
2568 .probe = atmci_probe,
2569 .remove = atmci_remove,
2570 .driver = {
2571 .name = "atmel_mci",
2572 .of_match_table = of_match_ptr(atmci_dt_ids),
2573 .pm = &atmci_dev_pm_ops,
2574 },
2575};
2576module_platform_driver(atmci_driver);
2558 2577
2559MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver"); 2578MODULE_DESCRIPTION("Atmel Multimedia Card Interface driver");
2560MODULE_AUTHOR("Haavard Skinnemoen (Atmel)"); 2579MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c
index 0fbc53ac7eae..509365cb22c6 100644
--- a/drivers/mmc/host/dw_mmc-exynos.c
+++ b/drivers/mmc/host/dw_mmc-exynos.c
@@ -25,6 +25,7 @@
25#define NUM_PINS(x) (x + 2) 25#define NUM_PINS(x) (x + 2)
26 26
27#define SDMMC_CLKSEL 0x09C 27#define SDMMC_CLKSEL 0x09C
28#define SDMMC_CLKSEL64 0x0A8
28#define SDMMC_CLKSEL_CCLK_SAMPLE(x) (((x) & 7) << 0) 29#define SDMMC_CLKSEL_CCLK_SAMPLE(x) (((x) & 7) << 0)
29#define SDMMC_CLKSEL_CCLK_DRIVE(x) (((x) & 7) << 16) 30#define SDMMC_CLKSEL_CCLK_DRIVE(x) (((x) & 7) << 16)
30#define SDMMC_CLKSEL_CCLK_DIVIDER(x) (((x) & 7) << 24) 31#define SDMMC_CLKSEL_CCLK_DIVIDER(x) (((x) & 7) << 24)
@@ -65,6 +66,8 @@ enum dw_mci_exynos_type {
65 DW_MCI_TYPE_EXYNOS5250, 66 DW_MCI_TYPE_EXYNOS5250,
66 DW_MCI_TYPE_EXYNOS5420, 67 DW_MCI_TYPE_EXYNOS5420,
67 DW_MCI_TYPE_EXYNOS5420_SMU, 68 DW_MCI_TYPE_EXYNOS5420_SMU,
69 DW_MCI_TYPE_EXYNOS7,
70 DW_MCI_TYPE_EXYNOS7_SMU,
68}; 71};
69 72
70/* Exynos implementation specific driver private data */ 73/* Exynos implementation specific driver private data */
@@ -95,6 +98,12 @@ static struct dw_mci_exynos_compatible {
95 }, { 98 }, {
96 .compatible = "samsung,exynos5420-dw-mshc-smu", 99 .compatible = "samsung,exynos5420-dw-mshc-smu",
97 .ctrl_type = DW_MCI_TYPE_EXYNOS5420_SMU, 100 .ctrl_type = DW_MCI_TYPE_EXYNOS5420_SMU,
101 }, {
102 .compatible = "samsung,exynos7-dw-mshc",
103 .ctrl_type = DW_MCI_TYPE_EXYNOS7,
104 }, {
105 .compatible = "samsung,exynos7-dw-mshc-smu",
106 .ctrl_type = DW_MCI_TYPE_EXYNOS7_SMU,
98 }, 107 },
99}; 108};
100 109
@@ -102,7 +111,8 @@ static int dw_mci_exynos_priv_init(struct dw_mci *host)
102{ 111{
103 struct dw_mci_exynos_priv_data *priv = host->priv; 112 struct dw_mci_exynos_priv_data *priv = host->priv;
104 113
105 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420_SMU) { 114 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420_SMU ||
115 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) {
106 mci_writel(host, MPSBEGIN0, 0); 116 mci_writel(host, MPSBEGIN0, 0);
107 mci_writel(host, MPSEND0, DWMCI_BLOCK_NUM); 117 mci_writel(host, MPSEND0, DWMCI_BLOCK_NUM);
108 mci_writel(host, MPSCTRL0, DWMCI_MPSCTRL_SECURE_WRITE_BIT | 118 mci_writel(host, MPSCTRL0, DWMCI_MPSCTRL_SECURE_WRITE_BIT |
@@ -153,11 +163,22 @@ static int dw_mci_exynos_resume(struct device *dev)
153static int dw_mci_exynos_resume_noirq(struct device *dev) 163static int dw_mci_exynos_resume_noirq(struct device *dev)
154{ 164{
155 struct dw_mci *host = dev_get_drvdata(dev); 165 struct dw_mci *host = dev_get_drvdata(dev);
166 struct dw_mci_exynos_priv_data *priv = host->priv;
156 u32 clksel; 167 u32 clksel;
157 168
158 clksel = mci_readl(host, CLKSEL); 169 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
159 if (clksel & SDMMC_CLKSEL_WAKEUP_INT) 170 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
160 mci_writel(host, CLKSEL, clksel); 171 clksel = mci_readl(host, CLKSEL64);
172 else
173 clksel = mci_readl(host, CLKSEL);
174
175 if (clksel & SDMMC_CLKSEL_WAKEUP_INT) {
176 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
177 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
178 mci_writel(host, CLKSEL64, clksel);
179 else
180 mci_writel(host, CLKSEL, clksel);
181 }
161 182
162 return 0; 183 return 0;
163} 184}
@@ -169,6 +190,7 @@ static int dw_mci_exynos_resume_noirq(struct device *dev)
169 190
170static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr) 191static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr)
171{ 192{
193 struct dw_mci_exynos_priv_data *priv = host->priv;
172 /* 194 /*
173 * Exynos4412 and Exynos5250 extends the use of CMD register with the 195 * Exynos4412 and Exynos5250 extends the use of CMD register with the
174 * use of bit 29 (which is reserved on standard MSHC controllers) for 196 * use of bit 29 (which is reserved on standard MSHC controllers) for
@@ -176,8 +198,14 @@ static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr)
176 * HOLD register should be bypassed in case there is no phase shift 198 * HOLD register should be bypassed in case there is no phase shift
177 * applied on CMD/DATA that is sent to the card. 199 * applied on CMD/DATA that is sent to the card.
178 */ 200 */
179 if (SDMMC_CLKSEL_GET_DRV_WD3(mci_readl(host, CLKSEL))) 201 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
180 *cmdr |= SDMMC_CMD_USE_HOLD_REG; 202 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU) {
203 if (SDMMC_CLKSEL_GET_DRV_WD3(mci_readl(host, CLKSEL64)))
204 *cmdr |= SDMMC_CMD_USE_HOLD_REG;
205 } else {
206 if (SDMMC_CLKSEL_GET_DRV_WD3(mci_readl(host, CLKSEL)))
207 *cmdr |= SDMMC_CMD_USE_HOLD_REG;
208 }
181} 209}
182 210
183static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios) 211static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
@@ -188,12 +216,20 @@ static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios)
188 u8 div = priv->ciu_div + 1; 216 u8 div = priv->ciu_div + 1;
189 217
190 if (ios->timing == MMC_TIMING_MMC_DDR52) { 218 if (ios->timing == MMC_TIMING_MMC_DDR52) {
191 mci_writel(host, CLKSEL, priv->ddr_timing); 219 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
220 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
221 mci_writel(host, CLKSEL64, priv->ddr_timing);
222 else
223 mci_writel(host, CLKSEL, priv->ddr_timing);
192 /* Should be double rate for DDR mode */ 224 /* Should be double rate for DDR mode */
193 if (ios->bus_width == MMC_BUS_WIDTH_8) 225 if (ios->bus_width == MMC_BUS_WIDTH_8)
194 wanted <<= 1; 226 wanted <<= 1;
195 } else { 227 } else {
196 mci_writel(host, CLKSEL, priv->sdr_timing); 228 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
229 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
230 mci_writel(host, CLKSEL64, priv->sdr_timing);
231 else
232 mci_writel(host, CLKSEL, priv->sdr_timing);
197 } 233 }
198 234
199 /* Don't care if wanted clock is zero */ 235 /* Don't care if wanted clock is zero */
@@ -265,26 +301,51 @@ static int dw_mci_exynos_parse_dt(struct dw_mci *host)
265 301
266static inline u8 dw_mci_exynos_get_clksmpl(struct dw_mci *host) 302static inline u8 dw_mci_exynos_get_clksmpl(struct dw_mci *host)
267{ 303{
268 return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL)); 304 struct dw_mci_exynos_priv_data *priv = host->priv;
305
306 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
307 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
308 return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL64));
309 else
310 return SDMMC_CLKSEL_CCLK_SAMPLE(mci_readl(host, CLKSEL));
269} 311}
270 312
271static inline void dw_mci_exynos_set_clksmpl(struct dw_mci *host, u8 sample) 313static inline void dw_mci_exynos_set_clksmpl(struct dw_mci *host, u8 sample)
272{ 314{
273 u32 clksel; 315 u32 clksel;
274 clksel = mci_readl(host, CLKSEL); 316 struct dw_mci_exynos_priv_data *priv = host->priv;
317
318 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
319 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
320 clksel = mci_readl(host, CLKSEL64);
321 else
322 clksel = mci_readl(host, CLKSEL);
275 clksel = (clksel & ~0x7) | SDMMC_CLKSEL_CCLK_SAMPLE(sample); 323 clksel = (clksel & ~0x7) | SDMMC_CLKSEL_CCLK_SAMPLE(sample);
276 mci_writel(host, CLKSEL, clksel); 324 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
325 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
326 mci_writel(host, CLKSEL64, clksel);
327 else
328 mci_writel(host, CLKSEL, clksel);
277} 329}
278 330
279static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host) 331static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host)
280{ 332{
333 struct dw_mci_exynos_priv_data *priv = host->priv;
281 u32 clksel; 334 u32 clksel;
282 u8 sample; 335 u8 sample;
283 336
284 clksel = mci_readl(host, CLKSEL); 337 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
338 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
339 clksel = mci_readl(host, CLKSEL64);
340 else
341 clksel = mci_readl(host, CLKSEL);
285 sample = (clksel + 1) & 0x7; 342 sample = (clksel + 1) & 0x7;
286 clksel = (clksel & ~0x7) | sample; 343 clksel = (clksel & ~0x7) | sample;
287 mci_writel(host, CLKSEL, clksel); 344 if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
345 priv->ctrl_type == DW_MCI_TYPE_EXYNOS7_SMU)
346 mci_writel(host, CLKSEL64, clksel);
347 else
348 mci_writel(host, CLKSEL, clksel);
288 return sample; 349 return sample;
289} 350}
290 351
@@ -411,6 +472,10 @@ static const struct of_device_id dw_mci_exynos_match[] = {
411 .data = &exynos_drv_data, }, 472 .data = &exynos_drv_data, },
412 { .compatible = "samsung,exynos5420-dw-mshc-smu", 473 { .compatible = "samsung,exynos5420-dw-mshc-smu",
413 .data = &exynos_drv_data, }, 474 .data = &exynos_drv_data, },
475 { .compatible = "samsung,exynos7-dw-mshc",
476 .data = &exynos_drv_data, },
477 { .compatible = "samsung,exynos7-dw-mshc-smu",
478 .data = &exynos_drv_data, },
414 {}, 479 {},
415}; 480};
416MODULE_DEVICE_TABLE(of, dw_mci_exynos_match); 481MODULE_DEVICE_TABLE(of, dw_mci_exynos_match);
diff --git a/drivers/mmc/host/dw_mmc-pltfm.c b/drivers/mmc/host/dw_mmc-pltfm.c
index 8b6572162ed9..ec6dbcdec693 100644
--- a/drivers/mmc/host/dw_mmc-pltfm.c
+++ b/drivers/mmc/host/dw_mmc-pltfm.c
@@ -35,6 +35,10 @@ static const struct dw_mci_drv_data socfpga_drv_data = {
35 .prepare_command = dw_mci_pltfm_prepare_command, 35 .prepare_command = dw_mci_pltfm_prepare_command,
36}; 36};
37 37
38static const struct dw_mci_drv_data pistachio_drv_data = {
39 .prepare_command = dw_mci_pltfm_prepare_command,
40};
41
38int dw_mci_pltfm_register(struct platform_device *pdev, 42int dw_mci_pltfm_register(struct platform_device *pdev,
39 const struct dw_mci_drv_data *drv_data) 43 const struct dw_mci_drv_data *drv_data)
40{ 44{
@@ -90,6 +94,8 @@ static const struct of_device_id dw_mci_pltfm_match[] = {
90 { .compatible = "snps,dw-mshc", }, 94 { .compatible = "snps,dw-mshc", },
91 { .compatible = "altr,socfpga-dw-mshc", 95 { .compatible = "altr,socfpga-dw-mshc",
92 .data = &socfpga_drv_data }, 96 .data = &socfpga_drv_data },
97 { .compatible = "img,pistachio-dw-mshc",
98 .data = &pistachio_drv_data },
93 {}, 99 {},
94}; 100};
95MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match); 101MODULE_DEVICE_TABLE(of, dw_mci_pltfm_match);
diff --git a/drivers/mmc/host/dw_mmc-rockchip.c b/drivers/mmc/host/dw_mmc-rockchip.c
index f0c2cb1a210d..5650ac488cf3 100644
--- a/drivers/mmc/host/dw_mmc-rockchip.c
+++ b/drivers/mmc/host/dw_mmc-rockchip.c
@@ -37,6 +37,9 @@ static void dw_mci_rk3288_set_ios(struct dw_mci *host, struct mmc_ios *ios)
37 unsigned int cclkin; 37 unsigned int cclkin;
38 u32 bus_hz; 38 u32 bus_hz;
39 39
40 if (ios->clock == 0)
41 return;
42
40 /* 43 /*
41 * cclkin: source clock of mmc controller 44 * cclkin: source clock of mmc controller
42 * bus_hz: card interface clock generated by CLKGEN 45 * bus_hz: card interface clock generated by CLKGEN
@@ -65,14 +68,24 @@ static void dw_mci_rk3288_set_ios(struct dw_mci *host, struct mmc_ios *ios)
65 } 68 }
66} 69}
67 70
71static int dw_mci_rockchip_init(struct dw_mci *host)
72{
73 /* It is slot 8 on Rockchip SoCs */
74 host->sdio_id0 = 8;
75
76 return 0;
77}
78
68static const struct dw_mci_drv_data rk2928_drv_data = { 79static const struct dw_mci_drv_data rk2928_drv_data = {
69 .prepare_command = dw_mci_rockchip_prepare_command, 80 .prepare_command = dw_mci_rockchip_prepare_command,
81 .init = dw_mci_rockchip_init,
70}; 82};
71 83
72static const struct dw_mci_drv_data rk3288_drv_data = { 84static const struct dw_mci_drv_data rk3288_drv_data = {
73 .prepare_command = dw_mci_rockchip_prepare_command, 85 .prepare_command = dw_mci_rockchip_prepare_command,
74 .set_ios = dw_mci_rk3288_set_ios, 86 .set_ios = dw_mci_rk3288_set_ios,
75 .setup_clock = dw_mci_rk3288_setup_clock, 87 .setup_clock = dw_mci_rk3288_setup_clock,
88 .init = dw_mci_rockchip_init,
76}; 89};
77 90
78static const struct of_device_id dw_mci_rockchip_match[] = { 91static const struct of_device_id dw_mci_rockchip_match[] = {
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 69f0cc68d5b2..67c04518ec4c 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -34,7 +34,6 @@
34#include <linux/mmc/dw_mmc.h> 34#include <linux/mmc/dw_mmc.h>
35#include <linux/bitops.h> 35#include <linux/bitops.h>
36#include <linux/regulator/consumer.h> 36#include <linux/regulator/consumer.h>
37#include <linux/workqueue.h>
38#include <linux/of.h> 37#include <linux/of.h>
39#include <linux/of_gpio.h> 38#include <linux/of_gpio.h>
40#include <linux/mmc/slot-gpio.h> 39#include <linux/mmc/slot-gpio.h>
@@ -62,6 +61,24 @@
62 SDMMC_IDMAC_INT_FBE | SDMMC_IDMAC_INT_RI | \ 61 SDMMC_IDMAC_INT_FBE | SDMMC_IDMAC_INT_RI | \
63 SDMMC_IDMAC_INT_TI) 62 SDMMC_IDMAC_INT_TI)
64 63
64struct idmac_desc_64addr {
65 u32 des0; /* Control Descriptor */
66
67 u32 des1; /* Reserved */
68
69 u32 des2; /*Buffer sizes */
70#define IDMAC_64ADDR_SET_BUFFER1_SIZE(d, s) \
71 ((d)->des2 = ((d)->des2 & 0x03ffe000) | ((s) & 0x1fff))
72
73 u32 des3; /* Reserved */
74
75 u32 des4; /* Lower 32-bits of Buffer Address Pointer 1*/
76 u32 des5; /* Upper 32-bits of Buffer Address Pointer 1*/
77
78 u32 des6; /* Lower 32-bits of Next Descriptor Address */
79 u32 des7; /* Upper 32-bits of Next Descriptor Address */
80};
81
65struct idmac_desc { 82struct idmac_desc {
66 u32 des0; /* Control Descriptor */ 83 u32 des0; /* Control Descriptor */
67#define IDMAC_DES0_DIC BIT(1) 84#define IDMAC_DES0_DIC BIT(1)
@@ -83,6 +100,7 @@ struct idmac_desc {
83#endif /* CONFIG_MMC_DW_IDMAC */ 100#endif /* CONFIG_MMC_DW_IDMAC */
84 101
85static bool dw_mci_reset(struct dw_mci *host); 102static bool dw_mci_reset(struct dw_mci *host);
103static bool dw_mci_ctrl_reset(struct dw_mci *host, u32 reset);
86 104
87#if defined(CONFIG_DEBUG_FS) 105#if defined(CONFIG_DEBUG_FS)
88static int dw_mci_req_show(struct seq_file *s, void *v) 106static int dw_mci_req_show(struct seq_file *s, void *v)
@@ -414,30 +432,66 @@ static void dw_mci_translate_sglist(struct dw_mci *host, struct mmc_data *data,
414 unsigned int sg_len) 432 unsigned int sg_len)
415{ 433{
416 int i; 434 int i;
417 struct idmac_desc *desc = host->sg_cpu; 435 if (host->dma_64bit_address == 1) {
436 struct idmac_desc_64addr *desc = host->sg_cpu;
418 437
419 for (i = 0; i < sg_len; i++, desc++) { 438 for (i = 0; i < sg_len; i++, desc++) {
420 unsigned int length = sg_dma_len(&data->sg[i]); 439 unsigned int length = sg_dma_len(&data->sg[i]);
421 u32 mem_addr = sg_dma_address(&data->sg[i]); 440 u64 mem_addr = sg_dma_address(&data->sg[i]);
422 441
423 /* Set the OWN bit and disable interrupts for this descriptor */ 442 /*
424 desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC | IDMAC_DES0_CH; 443 * Set the OWN bit and disable interrupts for this
444 * descriptor
445 */
446 desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC |
447 IDMAC_DES0_CH;
448 /* Buffer length */
449 IDMAC_64ADDR_SET_BUFFER1_SIZE(desc, length);
450
451 /* Physical address to DMA to/from */
452 desc->des4 = mem_addr & 0xffffffff;
453 desc->des5 = mem_addr >> 32;
454 }
425 455
426 /* Buffer length */ 456 /* Set first descriptor */
427 IDMAC_SET_BUFFER1_SIZE(desc, length); 457 desc = host->sg_cpu;
458 desc->des0 |= IDMAC_DES0_FD;
428 459
429 /* Physical address to DMA to/from */ 460 /* Set last descriptor */
430 desc->des2 = mem_addr; 461 desc = host->sg_cpu + (i - 1) *
431 } 462 sizeof(struct idmac_desc_64addr);
463 desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC);
464 desc->des0 |= IDMAC_DES0_LD;
432 465
433 /* Set first descriptor */ 466 } else {
434 desc = host->sg_cpu; 467 struct idmac_desc *desc = host->sg_cpu;
435 desc->des0 |= IDMAC_DES0_FD; 468
469 for (i = 0; i < sg_len; i++, desc++) {
470 unsigned int length = sg_dma_len(&data->sg[i]);
471 u32 mem_addr = sg_dma_address(&data->sg[i]);
472
473 /*
474 * Set the OWN bit and disable interrupts for this
475 * descriptor
476 */
477 desc->des0 = IDMAC_DES0_OWN | IDMAC_DES0_DIC |
478 IDMAC_DES0_CH;
479 /* Buffer length */
480 IDMAC_SET_BUFFER1_SIZE(desc, length);
436 481
437 /* Set last descriptor */ 482 /* Physical address to DMA to/from */
438 desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc); 483 desc->des2 = mem_addr;
439 desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC); 484 }
440 desc->des0 |= IDMAC_DES0_LD; 485
486 /* Set first descriptor */
487 desc = host->sg_cpu;
488 desc->des0 |= IDMAC_DES0_FD;
489
490 /* Set last descriptor */
491 desc = host->sg_cpu + (i - 1) * sizeof(struct idmac_desc);
492 desc->des0 &= ~(IDMAC_DES0_CH | IDMAC_DES0_DIC);
493 desc->des0 |= IDMAC_DES0_LD;
494 }
441 495
442 wmb(); 496 wmb();
443} 497}
@@ -448,6 +502,10 @@ static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)
448 502
449 dw_mci_translate_sglist(host, host->data, sg_len); 503 dw_mci_translate_sglist(host, host->data, sg_len);
450 504
505 /* Make sure to reset DMA in case we did PIO before this */
506 dw_mci_ctrl_reset(host, SDMMC_CTRL_DMA_RESET);
507 dw_mci_idmac_reset(host);
508
451 /* Select IDMAC interface */ 509 /* Select IDMAC interface */
452 temp = mci_readl(host, CTRL); 510 temp = mci_readl(host, CTRL);
453 temp |= SDMMC_CTRL_USE_IDMAC; 511 temp |= SDMMC_CTRL_USE_IDMAC;
@@ -466,29 +524,71 @@ static void dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)
466 524
467static int dw_mci_idmac_init(struct dw_mci *host) 525static int dw_mci_idmac_init(struct dw_mci *host)
468{ 526{
469 struct idmac_desc *p;
470 int i; 527 int i;
471 528
472 /* Number of descriptors in the ring buffer */ 529 if (host->dma_64bit_address == 1) {
473 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc); 530 struct idmac_desc_64addr *p;
531 /* Number of descriptors in the ring buffer */
532 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc_64addr);
533
534 /* Forward link the descriptor list */
535 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1;
536 i++, p++) {
537 p->des6 = (host->sg_dma +
538 (sizeof(struct idmac_desc_64addr) *
539 (i + 1))) & 0xffffffff;
540
541 p->des7 = (u64)(host->sg_dma +
542 (sizeof(struct idmac_desc_64addr) *
543 (i + 1))) >> 32;
544 /* Initialize reserved and buffer size fields to "0" */
545 p->des1 = 0;
546 p->des2 = 0;
547 p->des3 = 0;
548 }
549
550 /* Set the last descriptor as the end-of-ring descriptor */
551 p->des6 = host->sg_dma & 0xffffffff;
552 p->des7 = (u64)host->sg_dma >> 32;
553 p->des0 = IDMAC_DES0_ER;
554
555 } else {
556 struct idmac_desc *p;
557 /* Number of descriptors in the ring buffer */
558 host->ring_size = PAGE_SIZE / sizeof(struct idmac_desc);
474 559
475 /* Forward link the descriptor list */ 560 /* Forward link the descriptor list */
476 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++) 561 for (i = 0, p = host->sg_cpu; i < host->ring_size - 1; i++, p++)
477 p->des3 = host->sg_dma + (sizeof(struct idmac_desc) * (i + 1)); 562 p->des3 = host->sg_dma + (sizeof(struct idmac_desc) *
563 (i + 1));
478 564
479 /* Set the last descriptor as the end-of-ring descriptor */ 565 /* Set the last descriptor as the end-of-ring descriptor */
480 p->des3 = host->sg_dma; 566 p->des3 = host->sg_dma;
481 p->des0 = IDMAC_DES0_ER; 567 p->des0 = IDMAC_DES0_ER;
568 }
482 569
483 dw_mci_idmac_reset(host); 570 dw_mci_idmac_reset(host);
484 571
485 /* Mask out interrupts - get Tx & Rx complete only */ 572 if (host->dma_64bit_address == 1) {
486 mci_writel(host, IDSTS, IDMAC_INT_CLR); 573 /* Mask out interrupts - get Tx & Rx complete only */
487 mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI | SDMMC_IDMAC_INT_RI | 574 mci_writel(host, IDSTS64, IDMAC_INT_CLR);
488 SDMMC_IDMAC_INT_TI); 575 mci_writel(host, IDINTEN64, SDMMC_IDMAC_INT_NI |
576 SDMMC_IDMAC_INT_RI | SDMMC_IDMAC_INT_TI);
577
578 /* Set the descriptor base address */
579 mci_writel(host, DBADDRL, host->sg_dma & 0xffffffff);
580 mci_writel(host, DBADDRU, (u64)host->sg_dma >> 32);
581
582 } else {
583 /* Mask out interrupts - get Tx & Rx complete only */
584 mci_writel(host, IDSTS, IDMAC_INT_CLR);
585 mci_writel(host, IDINTEN, SDMMC_IDMAC_INT_NI |
586 SDMMC_IDMAC_INT_RI | SDMMC_IDMAC_INT_TI);
587
588 /* Set the descriptor base address */
589 mci_writel(host, DBADDR, host->sg_dma);
590 }
489 591
490 /* Set the descriptor base address */
491 mci_writel(host, DBADDR, host->sg_dma);
492 return 0; 592 return 0;
493} 593}
494 594
@@ -626,6 +726,13 @@ static void dw_mci_ctrl_rd_thld(struct dw_mci *host, struct mmc_data *data)
626 726
627 WARN_ON(!(data->flags & MMC_DATA_READ)); 727 WARN_ON(!(data->flags & MMC_DATA_READ));
628 728
729 /*
730 * CDTHRCTL doesn't exist prior to 240A (in fact that register offset is
731 * in the FIFO region, so we really shouldn't access it).
732 */
733 if (host->verid < DW_MMC_240A)
734 return;
735
629 if (host->timing != MMC_TIMING_MMC_HS200 && 736 if (host->timing != MMC_TIMING_MMC_HS200 &&
630 host->timing != MMC_TIMING_UHS_SDR104) 737 host->timing != MMC_TIMING_UHS_SDR104)
631 goto disable; 738 goto disable;
@@ -819,7 +926,7 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)
819 926
820 /* enable clock; only low power if no SDIO */ 927 /* enable clock; only low power if no SDIO */
821 clk_en_a = SDMMC_CLKEN_ENABLE << slot->id; 928 clk_en_a = SDMMC_CLKEN_ENABLE << slot->id;
822 if (!(mci_readl(host, INTMASK) & SDMMC_INT_SDIO(slot->id))) 929 if (!(mci_readl(host, INTMASK) & SDMMC_INT_SDIO(slot->sdio_id)))
823 clk_en_a |= SDMMC_CLKEN_LOW_PWR << slot->id; 930 clk_en_a |= SDMMC_CLKEN_LOW_PWR << slot->id;
824 mci_writel(host, CLKENA, clk_en_a); 931 mci_writel(host, CLKENA, clk_en_a);
825 932
@@ -1075,7 +1182,7 @@ static int dw_mci_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios)
1075 ret = regulator_set_voltage(mmc->supply.vqmmc, min_uv, max_uv); 1182 ret = regulator_set_voltage(mmc->supply.vqmmc, min_uv, max_uv);
1076 1183
1077 if (ret) { 1184 if (ret) {
1078 dev_err(&mmc->class_dev, 1185 dev_dbg(&mmc->class_dev,
1079 "Regulator set error %d: %d - %d\n", 1186 "Regulator set error %d: %d - %d\n",
1080 ret, min_uv, max_uv); 1187 ret, min_uv, max_uv);
1081 return ret; 1188 return ret;
@@ -1180,10 +1287,10 @@ static void dw_mci_enable_sdio_irq(struct mmc_host *mmc, int enb)
1180 dw_mci_disable_low_power(slot); 1287 dw_mci_disable_low_power(slot);
1181 1288
1182 mci_writel(host, INTMASK, 1289 mci_writel(host, INTMASK,
1183 (int_mask | SDMMC_INT_SDIO(slot->id))); 1290 (int_mask | SDMMC_INT_SDIO(slot->sdio_id)));
1184 } else { 1291 } else {
1185 mci_writel(host, INTMASK, 1292 mci_writel(host, INTMASK,
1186 (int_mask & ~SDMMC_INT_SDIO(slot->id))); 1293 (int_mask & ~SDMMC_INT_SDIO(slot->sdio_id)));
1187 } 1294 }
1188} 1295}
1189 1296
@@ -1954,6 +2061,23 @@ static void dw_mci_cmd_interrupt(struct dw_mci *host, u32 status)
1954 tasklet_schedule(&host->tasklet); 2061 tasklet_schedule(&host->tasklet);
1955} 2062}
1956 2063
2064static void dw_mci_handle_cd(struct dw_mci *host)
2065{
2066 int i;
2067
2068 for (i = 0; i < host->num_slots; i++) {
2069 struct dw_mci_slot *slot = host->slot[i];
2070
2071 if (!slot)
2072 continue;
2073
2074 if (slot->mmc->ops->card_event)
2075 slot->mmc->ops->card_event(slot->mmc);
2076 mmc_detect_change(slot->mmc,
2077 msecs_to_jiffies(host->pdata->detect_delay_ms));
2078 }
2079}
2080
1957static irqreturn_t dw_mci_interrupt(int irq, void *dev_id) 2081static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
1958{ 2082{
1959 struct dw_mci *host = dev_id; 2083 struct dw_mci *host = dev_id;
@@ -2029,14 +2153,15 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
2029 2153
2030 if (pending & SDMMC_INT_CD) { 2154 if (pending & SDMMC_INT_CD) {
2031 mci_writel(host, RINTSTS, SDMMC_INT_CD); 2155 mci_writel(host, RINTSTS, SDMMC_INT_CD);
2032 queue_work(host->card_workqueue, &host->card_work); 2156 dw_mci_handle_cd(host);
2033 } 2157 }
2034 2158
2035 /* Handle SDIO Interrupts */ 2159 /* Handle SDIO Interrupts */
2036 for (i = 0; i < host->num_slots; i++) { 2160 for (i = 0; i < host->num_slots; i++) {
2037 struct dw_mci_slot *slot = host->slot[i]; 2161 struct dw_mci_slot *slot = host->slot[i];
2038 if (pending & SDMMC_INT_SDIO(i)) { 2162 if (pending & SDMMC_INT_SDIO(slot->sdio_id)) {
2039 mci_writel(host, RINTSTS, SDMMC_INT_SDIO(i)); 2163 mci_writel(host, RINTSTS,
2164 SDMMC_INT_SDIO(slot->sdio_id));
2040 mmc_signal_sdio_irq(slot->mmc); 2165 mmc_signal_sdio_irq(slot->mmc);
2041 } 2166 }
2042 } 2167 }
@@ -2045,99 +2170,28 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)
2045 2170
2046#ifdef CONFIG_MMC_DW_IDMAC 2171#ifdef CONFIG_MMC_DW_IDMAC
2047 /* Handle DMA interrupts */ 2172 /* Handle DMA interrupts */
2048 pending = mci_readl(host, IDSTS); 2173 if (host->dma_64bit_address == 1) {
2049 if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) { 2174 pending = mci_readl(host, IDSTS64);
2050 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI); 2175 if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
2051 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI); 2176 mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_TI |
2052 host->dma_ops->complete(host); 2177 SDMMC_IDMAC_INT_RI);
2178 mci_writel(host, IDSTS64, SDMMC_IDMAC_INT_NI);
2179 host->dma_ops->complete(host);
2180 }
2181 } else {
2182 pending = mci_readl(host, IDSTS);
2183 if (pending & (SDMMC_IDMAC_INT_TI | SDMMC_IDMAC_INT_RI)) {
2184 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_TI |
2185 SDMMC_IDMAC_INT_RI);
2186 mci_writel(host, IDSTS, SDMMC_IDMAC_INT_NI);
2187 host->dma_ops->complete(host);
2188 }
2053 } 2189 }
2054#endif 2190#endif
2055 2191
2056 return IRQ_HANDLED; 2192 return IRQ_HANDLED;
2057} 2193}
2058 2194
2059static void dw_mci_work_routine_card(struct work_struct *work)
2060{
2061 struct dw_mci *host = container_of(work, struct dw_mci, card_work);
2062 int i;
2063
2064 for (i = 0; i < host->num_slots; i++) {
2065 struct dw_mci_slot *slot = host->slot[i];
2066 struct mmc_host *mmc = slot->mmc;
2067 struct mmc_request *mrq;
2068 int present;
2069
2070 present = dw_mci_get_cd(mmc);
2071 while (present != slot->last_detect_state) {
2072 dev_dbg(&slot->mmc->class_dev, "card %s\n",
2073 present ? "inserted" : "removed");
2074
2075 spin_lock_bh(&host->lock);
2076
2077 /* Card change detected */
2078 slot->last_detect_state = present;
2079
2080 /* Clean up queue if present */
2081 mrq = slot->mrq;
2082 if (mrq) {
2083 if (mrq == host->mrq) {
2084 host->data = NULL;
2085 host->cmd = NULL;
2086
2087 switch (host->state) {
2088 case STATE_IDLE:
2089 case STATE_WAITING_CMD11_DONE:
2090 break;
2091 case STATE_SENDING_CMD11:
2092 case STATE_SENDING_CMD:
2093 mrq->cmd->error = -ENOMEDIUM;
2094 if (!mrq->data)
2095 break;
2096 /* fall through */
2097 case STATE_SENDING_DATA:
2098 mrq->data->error = -ENOMEDIUM;
2099 dw_mci_stop_dma(host);
2100 break;
2101 case STATE_DATA_BUSY:
2102 case STATE_DATA_ERROR:
2103 if (mrq->data->error == -EINPROGRESS)
2104 mrq->data->error = -ENOMEDIUM;
2105 /* fall through */
2106 case STATE_SENDING_STOP:
2107 if (mrq->stop)
2108 mrq->stop->error = -ENOMEDIUM;
2109 break;
2110 }
2111
2112 dw_mci_request_end(host, mrq);
2113 } else {
2114 list_del(&slot->queue_node);
2115 mrq->cmd->error = -ENOMEDIUM;
2116 if (mrq->data)
2117 mrq->data->error = -ENOMEDIUM;
2118 if (mrq->stop)
2119 mrq->stop->error = -ENOMEDIUM;
2120
2121 spin_unlock(&host->lock);
2122 mmc_request_done(slot->mmc, mrq);
2123 spin_lock(&host->lock);
2124 }
2125 }
2126
2127 /* Power down slot */
2128 if (present == 0)
2129 dw_mci_reset(host);
2130
2131 spin_unlock_bh(&host->lock);
2132
2133 present = dw_mci_get_cd(mmc);
2134 }
2135
2136 mmc_detect_change(slot->mmc,
2137 msecs_to_jiffies(host->pdata->detect_delay_ms));
2138 }
2139}
2140
2141#ifdef CONFIG_OF 2195#ifdef CONFIG_OF
2142/* given a slot id, find out the device node representing that slot */ 2196/* given a slot id, find out the device node representing that slot */
2143static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot) 2197static struct device_node *dw_mci_of_find_slot_node(struct device *dev, u8 slot)
@@ -2206,6 +2260,7 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
2206 2260
2207 slot = mmc_priv(mmc); 2261 slot = mmc_priv(mmc);
2208 slot->id = id; 2262 slot->id = id;
2263 slot->sdio_id = host->sdio_id0 + id;
2209 slot->mmc = mmc; 2264 slot->mmc = mmc;
2210 slot->host = host; 2265 slot->host = host;
2211 host->slot[id] = slot; 2266 host->slot[id] = slot;
@@ -2289,9 +2344,6 @@ static int dw_mci_init_slot(struct dw_mci *host, unsigned int id)
2289 dw_mci_init_debugfs(slot); 2344 dw_mci_init_debugfs(slot);
2290#endif 2345#endif
2291 2346
2292 /* Card initially undetected */
2293 slot->last_detect_state = 0;
2294
2295 return 0; 2347 return 0;
2296 2348
2297err_host_allocated: 2349err_host_allocated:
@@ -2309,6 +2361,22 @@ static void dw_mci_cleanup_slot(struct dw_mci_slot *slot, unsigned int id)
2309 2361
2310static void dw_mci_init_dma(struct dw_mci *host) 2362static void dw_mci_init_dma(struct dw_mci *host)
2311{ 2363{
2364 int addr_config;
2365 /* Check ADDR_CONFIG bit in HCON to find IDMAC address bus width */
2366 addr_config = (mci_readl(host, HCON) >> 27) & 0x01;
2367
2368 if (addr_config == 1) {
2369 /* host supports IDMAC in 64-bit address mode */
2370 host->dma_64bit_address = 1;
2371 dev_info(host->dev, "IDMAC supports 64-bit address mode.\n");
2372 if (!dma_set_mask(host->dev, DMA_BIT_MASK(64)))
2373 dma_set_coherent_mask(host->dev, DMA_BIT_MASK(64));
2374 } else {
2375 /* host supports IDMAC in 32-bit address mode */
2376 host->dma_64bit_address = 0;
2377 dev_info(host->dev, "IDMAC supports 32-bit address mode.\n");
2378 }
2379
2312 /* Alloc memory for sg translation */ 2380 /* Alloc memory for sg translation */
2313 host->sg_cpu = dmam_alloc_coherent(host->dev, PAGE_SIZE, 2381 host->sg_cpu = dmam_alloc_coherent(host->dev, PAGE_SIZE,
2314 &host->sg_dma, GFP_KERNEL); 2382 &host->sg_dma, GFP_KERNEL);
@@ -2672,17 +2740,10 @@ int dw_mci_probe(struct dw_mci *host)
2672 host->data_offset = DATA_240A_OFFSET; 2740 host->data_offset = DATA_240A_OFFSET;
2673 2741
2674 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host); 2742 tasklet_init(&host->tasklet, dw_mci_tasklet_func, (unsigned long)host);
2675 host->card_workqueue = alloc_workqueue("dw-mci-card",
2676 WQ_MEM_RECLAIM, 1);
2677 if (!host->card_workqueue) {
2678 ret = -ENOMEM;
2679 goto err_dmaunmap;
2680 }
2681 INIT_WORK(&host->card_work, dw_mci_work_routine_card);
2682 ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt, 2743 ret = devm_request_irq(host->dev, host->irq, dw_mci_interrupt,
2683 host->irq_flags, "dw-mci", host); 2744 host->irq_flags, "dw-mci", host);
2684 if (ret) 2745 if (ret)
2685 goto err_workqueue; 2746 goto err_dmaunmap;
2686 2747
2687 if (host->pdata->num_slots) 2748 if (host->pdata->num_slots)
2688 host->num_slots = host->pdata->num_slots; 2749 host->num_slots = host->pdata->num_slots;
@@ -2718,7 +2779,7 @@ int dw_mci_probe(struct dw_mci *host)
2718 } else { 2779 } else {
2719 dev_dbg(host->dev, "attempted to initialize %d slots, " 2780 dev_dbg(host->dev, "attempted to initialize %d slots, "
2720 "but failed on all\n", host->num_slots); 2781 "but failed on all\n", host->num_slots);
2721 goto err_workqueue; 2782 goto err_dmaunmap;
2722 } 2783 }
2723 2784
2724 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO) 2785 if (host->quirks & DW_MCI_QUIRK_IDMAC_DTO)
@@ -2726,9 +2787,6 @@ int dw_mci_probe(struct dw_mci *host)
2726 2787
2727 return 0; 2788 return 0;
2728 2789
2729err_workqueue:
2730 destroy_workqueue(host->card_workqueue);
2731
2732err_dmaunmap: 2790err_dmaunmap:
2733 if (host->use_dma && host->dma_ops->exit) 2791 if (host->use_dma && host->dma_ops->exit)
2734 host->dma_ops->exit(host); 2792 host->dma_ops->exit(host);
@@ -2762,8 +2820,6 @@ void dw_mci_remove(struct dw_mci *host)
2762 mci_writel(host, CLKENA, 0); 2820 mci_writel(host, CLKENA, 0);
2763 mci_writel(host, CLKSRC, 0); 2821 mci_writel(host, CLKSRC, 0);
2764 2822
2765 destroy_workqueue(host->card_workqueue);
2766
2767 if (host->use_dma && host->dma_ops->exit) 2823 if (host->use_dma && host->dma_ops->exit)
2768 host->dma_ops->exit(host); 2824 host->dma_ops->exit(host);
2769 2825
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index 01b99e8a9190..0d0f7a271d63 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -55,6 +55,17 @@
55#define SDMMC_BUFADDR 0x098 55#define SDMMC_BUFADDR 0x098
56#define SDMMC_CDTHRCTL 0x100 56#define SDMMC_CDTHRCTL 0x100
57#define SDMMC_DATA(x) (x) 57#define SDMMC_DATA(x) (x)
58/*
59* Registers to support idmac 64-bit address mode
60*/
61#define SDMMC_DBADDRL 0x088
62#define SDMMC_DBADDRU 0x08c
63#define SDMMC_IDSTS64 0x090
64#define SDMMC_IDINTEN64 0x094
65#define SDMMC_DSCADDRL 0x098
66#define SDMMC_DSCADDRU 0x09c
67#define SDMMC_BUFADDRL 0x0A0
68#define SDMMC_BUFADDRU 0x0A4
58 69
59/* 70/*
60 * Data offset is difference according to Version 71 * Data offset is difference according to Version
@@ -214,7 +225,7 @@ extern int dw_mci_resume(struct dw_mci *host);
214 * with CONFIG_MMC_CLKGATE. 225 * with CONFIG_MMC_CLKGATE.
215 * @flags: Random state bits associated with the slot. 226 * @flags: Random state bits associated with the slot.
216 * @id: Number of this slot. 227 * @id: Number of this slot.
217 * @last_detect_state: Most recently observed card detect state. 228 * @sdio_id: Number of this slot in the SDIO interrupt registers.
218 */ 229 */
219struct dw_mci_slot { 230struct dw_mci_slot {
220 struct mmc_host *mmc; 231 struct mmc_host *mmc;
@@ -234,7 +245,7 @@ struct dw_mci_slot {
234#define DW_MMC_CARD_PRESENT 0 245#define DW_MMC_CARD_PRESENT 0
235#define DW_MMC_CARD_NEED_INIT 1 246#define DW_MMC_CARD_NEED_INIT 1
236 int id; 247 int id;
237 int last_detect_state; 248 int sdio_id;
238}; 249};
239 250
240struct dw_mci_tuning_data { 251struct dw_mci_tuning_data {
diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
index 43af791e2e45..53bf7a4b5839 100644
--- a/drivers/mmc/host/mmci.c
+++ b/drivers/mmc/host/mmci.c
@@ -736,8 +736,15 @@ static void mmci_post_request(struct mmc_host *mmc, struct mmc_request *mrq,
736 chan = host->dma_tx_channel; 736 chan = host->dma_tx_channel;
737 dmaengine_terminate_all(chan); 737 dmaengine_terminate_all(chan);
738 738
739 if (host->dma_desc_current == next->dma_desc)
740 host->dma_desc_current = NULL;
741
742 if (host->dma_current == next->dma_chan)
743 host->dma_current = NULL;
744
739 next->dma_desc = NULL; 745 next->dma_desc = NULL;
740 next->dma_chan = NULL; 746 next->dma_chan = NULL;
747 data->host_cookie = 0;
741 } 748 }
742} 749}
743 750
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c
index 9405ecdaf6cf..90c60fd4ff6e 100644
--- a/drivers/mmc/host/msm_sdcc.c
+++ b/drivers/mmc/host/msm_sdcc.c
@@ -1360,7 +1360,7 @@ msmsdcc_probe(struct platform_device *pdev)
1360 if (ret) 1360 if (ret)
1361 goto cmd_irq_free; 1361 goto cmd_irq_free;
1362 1362
1363 mmc_set_drvdata(pdev, mmc); 1363 platform_set_drvdata(pdev, mmc);
1364 mmc_add_host(mmc); 1364 mmc_add_host(mmc);
1365 1365
1366 pr_info("%s: Qualcomm MSM SDCC at 0x%016llx irq %d,%d dma %d\n", 1366 pr_info("%s: Qualcomm MSM SDCC at 0x%016llx irq %d,%d dma %d\n",
@@ -1419,7 +1419,7 @@ ioremap_free:
1419static int 1419static int
1420msmsdcc_suspend(struct platform_device *dev, pm_message_t state) 1420msmsdcc_suspend(struct platform_device *dev, pm_message_t state)
1421{ 1421{
1422 struct mmc_host *mmc = mmc_get_drvdata(dev); 1422 struct mmc_host *mmc = platform_get_drvdata(dev);
1423 1423
1424 if (mmc) { 1424 if (mmc) {
1425 struct msmsdcc_host *host = mmc_priv(mmc); 1425 struct msmsdcc_host *host = mmc_priv(mmc);
@@ -1437,7 +1437,7 @@ msmsdcc_suspend(struct platform_device *dev, pm_message_t state)
1437static int 1437static int
1438msmsdcc_resume(struct platform_device *dev) 1438msmsdcc_resume(struct platform_device *dev)
1439{ 1439{
1440 struct mmc_host *mmc = mmc_get_drvdata(dev); 1440 struct mmc_host *mmc = platform_get_drvdata(dev);
1441 1441
1442 if (mmc) { 1442 if (mmc) {
1443 struct msmsdcc_host *host = mmc_priv(mmc); 1443 struct msmsdcc_host *host = mmc_priv(mmc);
diff --git a/drivers/mmc/host/mvsdio.c b/drivers/mmc/host/mvsdio.c
index 6b4c5ad3b393..4f8618f4522d 100644
--- a/drivers/mmc/host/mvsdio.c
+++ b/drivers/mmc/host/mvsdio.c
@@ -111,10 +111,15 @@ static int mvsd_setup_data(struct mvsd_host *host, struct mmc_data *data)
111 mvsd_write(MVSD_BLK_COUNT, data->blocks); 111 mvsd_write(MVSD_BLK_COUNT, data->blocks);
112 mvsd_write(MVSD_BLK_SIZE, data->blksz); 112 mvsd_write(MVSD_BLK_SIZE, data->blksz);
113 113
114 if (nodma || (data->blksz | data->sg->offset) & 3) { 114 if (nodma || (data->blksz | data->sg->offset) & 3 ||
115 ((!(data->flags & MMC_DATA_READ) && data->sg->offset & 0x3f))) {
115 /* 116 /*
116 * We cannot do DMA on a buffer which offset or size 117 * We cannot do DMA on a buffer which offset or size
117 * is not aligned on a 4-byte boundary. 118 * is not aligned on a 4-byte boundary.
119 *
120 * It also appears the host to card DMA can corrupt
121 * data when the buffer is not aligned on a 64 byte
122 * boundary.
118 */ 123 */
119 host->pio_size = data->blocks * data->blksz; 124 host->pio_size = data->blocks * data->blksz;
120 host->pio_ptr = sg_virt(data->sg); 125 host->pio_ptr = sg_virt(data->sg);
diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c
index ad111422ad55..5316d9b9e7b4 100644
--- a/drivers/mmc/host/mxcmmc.c
+++ b/drivers/mmc/host/mxcmmc.c
@@ -373,13 +373,9 @@ static void mxcmci_dma_callback(void *data)
373 del_timer(&host->watchdog); 373 del_timer(&host->watchdog);
374 374
375 stat = mxcmci_readl(host, MMC_REG_STATUS); 375 stat = mxcmci_readl(host, MMC_REG_STATUS);
376 mxcmci_writel(host, stat & ~STATUS_DATA_TRANS_DONE, MMC_REG_STATUS);
377 376
378 dev_dbg(mmc_dev(host->mmc), "%s: 0x%08x\n", __func__, stat); 377 dev_dbg(mmc_dev(host->mmc), "%s: 0x%08x\n", __func__, stat);
379 378
380 if (stat & STATUS_READ_OP_DONE)
381 mxcmci_writel(host, STATUS_READ_OP_DONE, MMC_REG_STATUS);
382
383 mxcmci_data_done(host, stat); 379 mxcmci_data_done(host, stat);
384} 380}
385 381
@@ -743,10 +739,8 @@ static irqreturn_t mxcmci_irq(int irq, void *devid)
743 sdio_irq = (stat & STATUS_SDIO_INT_ACTIVE) && host->use_sdio; 739 sdio_irq = (stat & STATUS_SDIO_INT_ACTIVE) && host->use_sdio;
744 spin_unlock_irqrestore(&host->lock, flags); 740 spin_unlock_irqrestore(&host->lock, flags);
745 741
746 if (mxcmci_use_dma(host) && 742 if (mxcmci_use_dma(host) && (stat & (STATUS_WRITE_OP_DONE)))
747 (stat & (STATUS_READ_OP_DONE | STATUS_WRITE_OP_DONE))) 743 mxcmci_writel(host, STATUS_WRITE_OP_DONE, MMC_REG_STATUS);
748 mxcmci_writel(host, STATUS_READ_OP_DONE | STATUS_WRITE_OP_DONE,
749 MMC_REG_STATUS);
750 744
751 if (sdio_irq) { 745 if (sdio_irq) {
752 mxcmci_writel(host, STATUS_SDIO_INT_ACTIVE, MMC_REG_STATUS); 746 mxcmci_writel(host, STATUS_SDIO_INT_ACTIVE, MMC_REG_STATUS);
@@ -756,8 +750,7 @@ static irqreturn_t mxcmci_irq(int irq, void *devid)
756 if (stat & STATUS_END_CMD_RESP) 750 if (stat & STATUS_END_CMD_RESP)
757 mxcmci_cmd_done(host, stat); 751 mxcmci_cmd_done(host, stat);
758 752
759 if (mxcmci_use_dma(host) && 753 if (mxcmci_use_dma(host) && (stat & STATUS_WRITE_OP_DONE)) {
760 (stat & (STATUS_DATA_TRANS_DONE | STATUS_WRITE_OP_DONE))) {
761 del_timer(&host->watchdog); 754 del_timer(&host->watchdog);
762 mxcmci_data_done(host, stat); 755 mxcmci_data_done(host, stat);
763 } 756 }
@@ -1084,12 +1077,14 @@ static int mxcmci_probe(struct platform_device *pdev)
1084 dat3_card_detect = true; 1077 dat3_card_detect = true;
1085 1078
1086 ret = mmc_regulator_get_supply(mmc); 1079 ret = mmc_regulator_get_supply(mmc);
1087 if (ret) { 1080 if (ret == -EPROBE_DEFER)
1088 if (pdata && ret != -EPROBE_DEFER) 1081 goto out_free;
1089 mmc->ocr_avail = pdata->ocr_avail ? : 1082
1090 MMC_VDD_32_33 | MMC_VDD_33_34; 1083 if (!mmc->ocr_avail) {
1084 if (pdata && pdata->ocr_avail)
1085 mmc->ocr_avail = pdata->ocr_avail;
1091 else 1086 else
1092 goto out_free; 1087 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
1093 } 1088 }
1094 1089
1095 if (dat3_card_detect) 1090 if (dat3_card_detect)
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c
index cd74e5143c36..60c4ca97a727 100644
--- a/drivers/mmc/host/mxs-mmc.c
+++ b/drivers/mmc/host/mxs-mmc.c
@@ -581,10 +581,9 @@ static int mxs_mmc_probe(struct platform_device *pdev)
581 struct regulator *reg_vmmc; 581 struct regulator *reg_vmmc;
582 struct mxs_ssp *ssp; 582 struct mxs_ssp *ssp;
583 583
584 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
585 irq_err = platform_get_irq(pdev, 0); 584 irq_err = platform_get_irq(pdev, 0);
586 if (!iores || irq_err < 0) 585 if (irq_err < 0)
587 return -EINVAL; 586 return irq_err;
588 587
589 mmc = mmc_alloc_host(sizeof(struct mxs_mmc_host), &pdev->dev); 588 mmc = mmc_alloc_host(sizeof(struct mxs_mmc_host), &pdev->dev);
590 if (!mmc) 589 if (!mmc)
@@ -593,6 +592,7 @@ static int mxs_mmc_probe(struct platform_device *pdev)
593 host = mmc_priv(mmc); 592 host = mmc_priv(mmc);
594 ssp = &host->ssp; 593 ssp = &host->ssp;
595 ssp->dev = &pdev->dev; 594 ssp->dev = &pdev->dev;
595 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
596 ssp->base = devm_ioremap_resource(&pdev->dev, iores); 596 ssp->base = devm_ioremap_resource(&pdev->dev, iores);
597 if (IS_ERR(ssp->base)) { 597 if (IS_ERR(ssp->base)) {
598 ret = PTR_ERR(ssp->base); 598 ret = PTR_ERR(ssp->base);
@@ -619,7 +619,9 @@ static int mxs_mmc_probe(struct platform_device *pdev)
619 ret = PTR_ERR(ssp->clk); 619 ret = PTR_ERR(ssp->clk);
620 goto out_mmc_free; 620 goto out_mmc_free;
621 } 621 }
622 clk_prepare_enable(ssp->clk); 622 ret = clk_prepare_enable(ssp->clk);
623 if (ret)
624 goto out_mmc_free;
623 625
624 ret = mxs_mmc_reset(host); 626 ret = mxs_mmc_reset(host);
625 if (ret) { 627 if (ret) {
@@ -660,7 +662,7 @@ static int mxs_mmc_probe(struct platform_device *pdev)
660 platform_set_drvdata(pdev, mmc); 662 platform_set_drvdata(pdev, mmc);
661 663
662 ret = devm_request_irq(&pdev->dev, irq_err, mxs_mmc_irq_handler, 0, 664 ret = devm_request_irq(&pdev->dev, irq_err, mxs_mmc_irq_handler, 0,
663 DRIVER_NAME, host); 665 dev_name(&pdev->dev), host);
664 if (ret) 666 if (ret)
665 goto out_free_dma; 667 goto out_free_dma;
666 668
@@ -702,7 +704,7 @@ static int mxs_mmc_remove(struct platform_device *pdev)
702 return 0; 704 return 0;
703} 705}
704 706
705#ifdef CONFIG_PM 707#ifdef CONFIG_PM_SLEEP
706static int mxs_mmc_suspend(struct device *dev) 708static int mxs_mmc_suspend(struct device *dev)
707{ 709{
708 struct mmc_host *mmc = dev_get_drvdata(dev); 710 struct mmc_host *mmc = dev_get_drvdata(dev);
@@ -719,25 +721,19 @@ static int mxs_mmc_resume(struct device *dev)
719 struct mxs_mmc_host *host = mmc_priv(mmc); 721 struct mxs_mmc_host *host = mmc_priv(mmc);
720 struct mxs_ssp *ssp = &host->ssp; 722 struct mxs_ssp *ssp = &host->ssp;
721 723
722 clk_prepare_enable(ssp->clk); 724 return clk_prepare_enable(ssp->clk);
723 return 0;
724} 725}
725
726static const struct dev_pm_ops mxs_mmc_pm_ops = {
727 .suspend = mxs_mmc_suspend,
728 .resume = mxs_mmc_resume,
729};
730#endif 726#endif
731 727
728static SIMPLE_DEV_PM_OPS(mxs_mmc_pm_ops, mxs_mmc_suspend, mxs_mmc_resume);
729
732static struct platform_driver mxs_mmc_driver = { 730static struct platform_driver mxs_mmc_driver = {
733 .probe = mxs_mmc_probe, 731 .probe = mxs_mmc_probe,
734 .remove = mxs_mmc_remove, 732 .remove = mxs_mmc_remove,
735 .id_table = mxs_ssp_ids, 733 .id_table = mxs_ssp_ids,
736 .driver = { 734 .driver = {
737 .name = DRIVER_NAME, 735 .name = DRIVER_NAME,
738#ifdef CONFIG_PM
739 .pm = &mxs_mmc_pm_ops, 736 .pm = &mxs_mmc_pm_ops,
740#endif
741 .of_match_table = mxs_mmc_dt_ids, 737 .of_match_table = mxs_mmc_dt_ids,
742 }, 738 },
743}; 739};
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index df27bb4fc098..7c71dcdcba8b 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -42,7 +42,7 @@
42#include <linux/regulator/consumer.h> 42#include <linux/regulator/consumer.h>
43#include <linux/pinctrl/consumer.h> 43#include <linux/pinctrl/consumer.h>
44#include <linux/pm_runtime.h> 44#include <linux/pm_runtime.h>
45#include <linux/platform_data/mmc-omap.h> 45#include <linux/platform_data/hsmmc-omap.h>
46 46
47/* OMAP HSMMC Host Controller Registers */ 47/* OMAP HSMMC Host Controller Registers */
48#define OMAP_HSMMC_SYSSTATUS 0x0014 48#define OMAP_HSMMC_SYSSTATUS 0x0014
@@ -155,7 +155,7 @@
155 * omap.c controller driver. Luckily this is not currently done on any known 155 * omap.c controller driver. Luckily this is not currently done on any known
156 * omap_hsmmc.c device. 156 * omap_hsmmc.c device.
157 */ 157 */
158#define mmc_slot(host) (host->pdata->slots[host->slot_id]) 158#define mmc_pdata(host) host->pdata
159 159
160/* 160/*
161 * MMC Host controller read/write API's 161 * MMC Host controller read/write API's
@@ -207,7 +207,6 @@ struct omap_hsmmc_host {
207 int use_dma, dma_ch; 207 int use_dma, dma_ch;
208 struct dma_chan *tx_chan; 208 struct dma_chan *tx_chan;
209 struct dma_chan *rx_chan; 209 struct dma_chan *rx_chan;
210 int slot_id;
211 int response_busy; 210 int response_busy;
212 int context_loss; 211 int context_loss;
213 int protect_card; 212 int protect_card;
@@ -220,7 +219,26 @@ struct omap_hsmmc_host {
220#define HSMMC_SDIO_IRQ_ENABLED (1 << 1) /* SDIO irq enabled */ 219#define HSMMC_SDIO_IRQ_ENABLED (1 << 1) /* SDIO irq enabled */
221#define HSMMC_WAKE_IRQ_ENABLED (1 << 2) 220#define HSMMC_WAKE_IRQ_ENABLED (1 << 2)
222 struct omap_hsmmc_next next_data; 221 struct omap_hsmmc_next next_data;
223 struct omap_mmc_platform_data *pdata; 222 struct omap_hsmmc_platform_data *pdata;
223
224 /* To handle board related suspend/resume functionality for MMC */
225 int (*suspend)(struct device *dev);
226 int (*resume)(struct device *dev);
227
228 /* return MMC cover switch state, can be NULL if not supported.
229 *
230 * possible return values:
231 * 0 - closed
232 * 1 - open
233 */
234 int (*get_cover_state)(struct device *dev);
235
236 /* Card detection IRQs */
237 int card_detect_irq;
238
239 int (*card_detect)(struct device *dev);
240 int (*get_ro)(struct device *dev);
241
224}; 242};
225 243
226struct omap_mmc_of_data { 244struct omap_mmc_of_data {
@@ -230,50 +248,48 @@ struct omap_mmc_of_data {
230 248
231static void omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host); 249static void omap_hsmmc_start_dma_transfer(struct omap_hsmmc_host *host);
232 250
233static int omap_hsmmc_card_detect(struct device *dev, int slot) 251static int omap_hsmmc_card_detect(struct device *dev)
234{ 252{
235 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 253 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
236 struct omap_mmc_platform_data *mmc = host->pdata; 254 struct omap_hsmmc_platform_data *mmc = host->pdata;
237 255
238 /* NOTE: assumes card detect signal is active-low */ 256 /* NOTE: assumes card detect signal is active-low */
239 return !gpio_get_value_cansleep(mmc->slots[0].switch_pin); 257 return !gpio_get_value_cansleep(mmc->switch_pin);
240} 258}
241 259
242static int omap_hsmmc_get_wp(struct device *dev, int slot) 260static int omap_hsmmc_get_wp(struct device *dev)
243{ 261{
244 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 262 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
245 struct omap_mmc_platform_data *mmc = host->pdata; 263 struct omap_hsmmc_platform_data *mmc = host->pdata;
246 264
247 /* NOTE: assumes write protect signal is active-high */ 265 /* NOTE: assumes write protect signal is active-high */
248 return gpio_get_value_cansleep(mmc->slots[0].gpio_wp); 266 return gpio_get_value_cansleep(mmc->gpio_wp);
249} 267}
250 268
251static int omap_hsmmc_get_cover_state(struct device *dev, int slot) 269static int omap_hsmmc_get_cover_state(struct device *dev)
252{ 270{
253 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 271 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
254 struct omap_mmc_platform_data *mmc = host->pdata; 272 struct omap_hsmmc_platform_data *mmc = host->pdata;
255 273
256 /* NOTE: assumes card detect signal is active-low */ 274 /* NOTE: assumes card detect signal is active-low */
257 return !gpio_get_value_cansleep(mmc->slots[0].switch_pin); 275 return !gpio_get_value_cansleep(mmc->switch_pin);
258} 276}
259 277
260#ifdef CONFIG_PM 278#ifdef CONFIG_PM
261 279
262static int omap_hsmmc_suspend_cdirq(struct device *dev, int slot) 280static int omap_hsmmc_suspend_cdirq(struct device *dev)
263{ 281{
264 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 282 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
265 struct omap_mmc_platform_data *mmc = host->pdata;
266 283
267 disable_irq(mmc->slots[0].card_detect_irq); 284 disable_irq(host->card_detect_irq);
268 return 0; 285 return 0;
269} 286}
270 287
271static int omap_hsmmc_resume_cdirq(struct device *dev, int slot) 288static int omap_hsmmc_resume_cdirq(struct device *dev)
272{ 289{
273 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 290 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
274 struct omap_mmc_platform_data *mmc = host->pdata;
275 291
276 enable_irq(mmc->slots[0].card_detect_irq); 292 enable_irq(host->card_detect_irq);
277 return 0; 293 return 0;
278} 294}
279 295
@@ -286,8 +302,7 @@ static int omap_hsmmc_resume_cdirq(struct device *dev, int slot)
286 302
287#ifdef CONFIG_REGULATOR 303#ifdef CONFIG_REGULATOR
288 304
289static int omap_hsmmc_set_power(struct device *dev, int slot, int power_on, 305static int omap_hsmmc_set_power(struct device *dev, int power_on, int vdd)
290 int vdd)
291{ 306{
292 struct omap_hsmmc_host *host = 307 struct omap_hsmmc_host *host =
293 platform_get_drvdata(to_platform_device(dev)); 308 platform_get_drvdata(to_platform_device(dev));
@@ -300,8 +315,8 @@ static int omap_hsmmc_set_power(struct device *dev, int slot, int power_on,
300 if (!host->vcc) 315 if (!host->vcc)
301 return 0; 316 return 0;
302 317
303 if (mmc_slot(host).before_set_reg) 318 if (mmc_pdata(host)->before_set_reg)
304 mmc_slot(host).before_set_reg(dev, slot, power_on, vdd); 319 mmc_pdata(host)->before_set_reg(dev, power_on, vdd);
305 320
306 if (host->pbias) { 321 if (host->pbias) {
307 if (host->pbias_enabled == 1) { 322 if (host->pbias_enabled == 1) {
@@ -363,8 +378,8 @@ static int omap_hsmmc_set_power(struct device *dev, int slot, int power_on,
363 } 378 }
364 } 379 }
365 380
366 if (mmc_slot(host).after_set_reg) 381 if (mmc_pdata(host)->after_set_reg)
367 mmc_slot(host).after_set_reg(dev, slot, power_on, vdd); 382 mmc_pdata(host)->after_set_reg(dev, power_on, vdd);
368 383
369error_set_power: 384error_set_power:
370 return ret; 385 return ret;
@@ -383,18 +398,18 @@ static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
383 } else { 398 } else {
384 host->vcc = reg; 399 host->vcc = reg;
385 ocr_value = mmc_regulator_get_ocrmask(reg); 400 ocr_value = mmc_regulator_get_ocrmask(reg);
386 if (!mmc_slot(host).ocr_mask) { 401 if (!mmc_pdata(host)->ocr_mask) {
387 mmc_slot(host).ocr_mask = ocr_value; 402 mmc_pdata(host)->ocr_mask = ocr_value;
388 } else { 403 } else {
389 if (!(mmc_slot(host).ocr_mask & ocr_value)) { 404 if (!(mmc_pdata(host)->ocr_mask & ocr_value)) {
390 dev_err(host->dev, "ocrmask %x is not supported\n", 405 dev_err(host->dev, "ocrmask %x is not supported\n",
391 mmc_slot(host).ocr_mask); 406 mmc_pdata(host)->ocr_mask);
392 mmc_slot(host).ocr_mask = 0; 407 mmc_pdata(host)->ocr_mask = 0;
393 return -EINVAL; 408 return -EINVAL;
394 } 409 }
395 } 410 }
396 } 411 }
397 mmc_slot(host).set_power = omap_hsmmc_set_power; 412 mmc_pdata(host)->set_power = omap_hsmmc_set_power;
398 413
399 /* Allow an aux regulator */ 414 /* Allow an aux regulator */
400 reg = devm_regulator_get_optional(host->dev, "vmmc_aux"); 415 reg = devm_regulator_get_optional(host->dev, "vmmc_aux");
@@ -404,7 +419,7 @@ static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
404 host->pbias = IS_ERR(reg) ? NULL : reg; 419 host->pbias = IS_ERR(reg) ? NULL : reg;
405 420
406 /* For eMMC do not power off when not in sleep state */ 421 /* For eMMC do not power off when not in sleep state */
407 if (mmc_slot(host).no_regulator_off_init) 422 if (mmc_pdata(host)->no_regulator_off_init)
408 return 0; 423 return 0;
409 /* 424 /*
410 * To disable boot_on regulator, enable regulator 425 * To disable boot_on regulator, enable regulator
@@ -412,10 +427,10 @@ static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
412 */ 427 */
413 if ((host->vcc && regulator_is_enabled(host->vcc) > 0) || 428 if ((host->vcc && regulator_is_enabled(host->vcc) > 0) ||
414 (host->vcc_aux && regulator_is_enabled(host->vcc_aux))) { 429 (host->vcc_aux && regulator_is_enabled(host->vcc_aux))) {
415 int vdd = ffs(mmc_slot(host).ocr_mask) - 1; 430 int vdd = ffs(mmc_pdata(host)->ocr_mask) - 1;
416 431
417 mmc_slot(host).set_power(host->dev, host->slot_id, 1, vdd); 432 mmc_pdata(host)->set_power(host->dev, 1, vdd);
418 mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); 433 mmc_pdata(host)->set_power(host->dev, 0, 0);
419 } 434 }
420 435
421 return 0; 436 return 0;
@@ -423,7 +438,7 @@ static int omap_hsmmc_reg_get(struct omap_hsmmc_host *host)
423 438
424static void omap_hsmmc_reg_put(struct omap_hsmmc_host *host) 439static void omap_hsmmc_reg_put(struct omap_hsmmc_host *host)
425{ 440{
426 mmc_slot(host).set_power = NULL; 441 mmc_pdata(host)->set_power = NULL;
427} 442}
428 443
429static inline int omap_hsmmc_have_reg(void) 444static inline int omap_hsmmc_have_reg(void)
@@ -449,55 +464,59 @@ static inline int omap_hsmmc_have_reg(void)
449 464
450#endif 465#endif
451 466
452static int omap_hsmmc_gpio_init(struct omap_mmc_platform_data *pdata) 467static int omap_hsmmc_gpio_init(struct omap_hsmmc_host *host,
468 struct omap_hsmmc_platform_data *pdata)
453{ 469{
454 int ret; 470 int ret;
455 471
456 if (gpio_is_valid(pdata->slots[0].switch_pin)) { 472 if (gpio_is_valid(pdata->switch_pin)) {
457 if (pdata->slots[0].cover) 473 if (pdata->cover)
458 pdata->slots[0].get_cover_state = 474 host->get_cover_state =
459 omap_hsmmc_get_cover_state; 475 omap_hsmmc_get_cover_state;
460 else 476 else
461 pdata->slots[0].card_detect = omap_hsmmc_card_detect; 477 host->card_detect = omap_hsmmc_card_detect;
462 pdata->slots[0].card_detect_irq = 478 host->card_detect_irq =
463 gpio_to_irq(pdata->slots[0].switch_pin); 479 gpio_to_irq(pdata->switch_pin);
464 ret = gpio_request(pdata->slots[0].switch_pin, "mmc_cd"); 480 ret = gpio_request(pdata->switch_pin, "mmc_cd");
465 if (ret) 481 if (ret)
466 return ret; 482 return ret;
467 ret = gpio_direction_input(pdata->slots[0].switch_pin); 483 ret = gpio_direction_input(pdata->switch_pin);
468 if (ret) 484 if (ret)
469 goto err_free_sp; 485 goto err_free_sp;
470 } else 486 } else {
471 pdata->slots[0].switch_pin = -EINVAL; 487 pdata->switch_pin = -EINVAL;
488 }
472 489
473 if (gpio_is_valid(pdata->slots[0].gpio_wp)) { 490 if (gpio_is_valid(pdata->gpio_wp)) {
474 pdata->slots[0].get_ro = omap_hsmmc_get_wp; 491 host->get_ro = omap_hsmmc_get_wp;
475 ret = gpio_request(pdata->slots[0].gpio_wp, "mmc_wp"); 492 ret = gpio_request(pdata->gpio_wp, "mmc_wp");
476 if (ret) 493 if (ret)
477 goto err_free_cd; 494 goto err_free_cd;
478 ret = gpio_direction_input(pdata->slots[0].gpio_wp); 495 ret = gpio_direction_input(pdata->gpio_wp);
479 if (ret) 496 if (ret)
480 goto err_free_wp; 497 goto err_free_wp;
481 } else 498 } else {
482 pdata->slots[0].gpio_wp = -EINVAL; 499 pdata->gpio_wp = -EINVAL;
500 }
483 501
484 return 0; 502 return 0;
485 503
486err_free_wp: 504err_free_wp:
487 gpio_free(pdata->slots[0].gpio_wp); 505 gpio_free(pdata->gpio_wp);
488err_free_cd: 506err_free_cd:
489 if (gpio_is_valid(pdata->slots[0].switch_pin)) 507 if (gpio_is_valid(pdata->switch_pin))
490err_free_sp: 508err_free_sp:
491 gpio_free(pdata->slots[0].switch_pin); 509 gpio_free(pdata->switch_pin);
492 return ret; 510 return ret;
493} 511}
494 512
495static void omap_hsmmc_gpio_free(struct omap_mmc_platform_data *pdata) 513static void omap_hsmmc_gpio_free(struct omap_hsmmc_host *host,
514 struct omap_hsmmc_platform_data *pdata)
496{ 515{
497 if (gpio_is_valid(pdata->slots[0].gpio_wp)) 516 if (gpio_is_valid(pdata->gpio_wp))
498 gpio_free(pdata->slots[0].gpio_wp); 517 gpio_free(pdata->gpio_wp);
499 if (gpio_is_valid(pdata->slots[0].switch_pin)) 518 if (gpio_is_valid(pdata->switch_pin))
500 gpio_free(pdata->slots[0].switch_pin); 519 gpio_free(pdata->switch_pin);
501} 520}
502 521
503/* 522/*
@@ -607,8 +626,9 @@ static void omap_hsmmc_set_clock(struct omap_hsmmc_host *host)
607 * in capabilities register 626 * in capabilities register
608 * - MMC/SD clock coming out of controller > 25MHz 627 * - MMC/SD clock coming out of controller > 25MHz
609 */ 628 */
610 if ((mmc_slot(host).features & HSMMC_HAS_HSPE_SUPPORT) && 629 if ((mmc_pdata(host)->features & HSMMC_HAS_HSPE_SUPPORT) &&
611 (ios->timing != MMC_TIMING_MMC_DDR52) && 630 (ios->timing != MMC_TIMING_MMC_DDR52) &&
631 (ios->timing != MMC_TIMING_UHS_DDR50) &&
612 ((OMAP_HSMMC_READ(host->base, CAPA) & HSS) == HSS)) { 632 ((OMAP_HSMMC_READ(host->base, CAPA) & HSS) == HSS)) {
613 regval = OMAP_HSMMC_READ(host->base, HCTL); 633 regval = OMAP_HSMMC_READ(host->base, HCTL);
614 if (clkdiv && (clk_get_rate(host->fclk)/clkdiv) > 25000000) 634 if (clkdiv && (clk_get_rate(host->fclk)/clkdiv) > 25000000)
@@ -628,7 +648,8 @@ static void omap_hsmmc_set_bus_width(struct omap_hsmmc_host *host)
628 u32 con; 648 u32 con;
629 649
630 con = OMAP_HSMMC_READ(host->base, CON); 650 con = OMAP_HSMMC_READ(host->base, CON);
631 if (ios->timing == MMC_TIMING_MMC_DDR52) 651 if (ios->timing == MMC_TIMING_MMC_DDR52 ||
652 ios->timing == MMC_TIMING_UHS_DDR50)
632 con |= DDR; /* configure in DDR mode */ 653 con |= DDR; /* configure in DDR mode */
633 else 654 else
634 con &= ~DDR; 655 con &= ~DDR;
@@ -791,8 +812,8 @@ int omap_hsmmc_cover_is_closed(struct omap_hsmmc_host *host)
791{ 812{
792 int r = 1; 813 int r = 1;
793 814
794 if (mmc_slot(host).get_cover_state) 815 if (host->get_cover_state)
795 r = mmc_slot(host).get_cover_state(host->dev, host->slot_id); 816 r = host->get_cover_state(host->dev);
796 return r; 817 return r;
797} 818}
798 819
@@ -816,7 +837,7 @@ omap_hsmmc_show_slot_name(struct device *dev, struct device_attribute *attr,
816 struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev); 837 struct mmc_host *mmc = container_of(dev, struct mmc_host, class_dev);
817 struct omap_hsmmc_host *host = mmc_priv(mmc); 838 struct omap_hsmmc_host *host = mmc_priv(mmc);
818 839
819 return sprintf(buf, "%s\n", mmc_slot(host).name); 840 return sprintf(buf, "%s\n", mmc_pdata(host)->name);
820} 841}
821 842
822static DEVICE_ATTR(slot_name, S_IRUGO, omap_hsmmc_show_slot_name, NULL); 843static DEVICE_ATTR(slot_name, S_IRUGO, omap_hsmmc_show_slot_name, NULL);
@@ -1061,7 +1082,7 @@ static inline void omap_hsmmc_reset_controller_fsm(struct omap_hsmmc_host *host,
1061 * OMAP4 ES2 and greater has an updated reset logic. 1082 * OMAP4 ES2 and greater has an updated reset logic.
1062 * Monitor a 0->1 transition first 1083 * Monitor a 0->1 transition first
1063 */ 1084 */
1064 if (mmc_slot(host).features & HSMMC_HAS_UPDATED_RESET) { 1085 if (mmc_pdata(host)->features & HSMMC_HAS_UPDATED_RESET) {
1065 while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit)) 1086 while ((!(OMAP_HSMMC_READ(host->base, SYSCTL) & bit))
1066 && (i++ < limit)) 1087 && (i++ < limit))
1067 udelay(1); 1088 udelay(1);
@@ -1210,12 +1231,11 @@ static int omap_hsmmc_switch_opcond(struct omap_hsmmc_host *host, int vdd)
1210 clk_disable_unprepare(host->dbclk); 1231 clk_disable_unprepare(host->dbclk);
1211 1232
1212 /* Turn the power off */ 1233 /* Turn the power off */
1213 ret = mmc_slot(host).set_power(host->dev, host->slot_id, 0, 0); 1234 ret = mmc_pdata(host)->set_power(host->dev, 0, 0);
1214 1235
1215 /* Turn the power ON with given VDD 1.8 or 3.0v */ 1236 /* Turn the power ON with given VDD 1.8 or 3.0v */
1216 if (!ret) 1237 if (!ret)
1217 ret = mmc_slot(host).set_power(host->dev, host->slot_id, 1, 1238 ret = mmc_pdata(host)->set_power(host->dev, 1, vdd);
1218 vdd);
1219 pm_runtime_get_sync(host->dev); 1239 pm_runtime_get_sync(host->dev);
1220 if (host->dbclk) 1240 if (host->dbclk)
1221 clk_prepare_enable(host->dbclk); 1241 clk_prepare_enable(host->dbclk);
@@ -1259,11 +1279,11 @@ err:
1259/* Protect the card while the cover is open */ 1279/* Protect the card while the cover is open */
1260static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host) 1280static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
1261{ 1281{
1262 if (!mmc_slot(host).get_cover_state) 1282 if (!host->get_cover_state)
1263 return; 1283 return;
1264 1284
1265 host->reqs_blocked = 0; 1285 host->reqs_blocked = 0;
1266 if (mmc_slot(host).get_cover_state(host->dev, host->slot_id)) { 1286 if (host->get_cover_state(host->dev)) {
1267 if (host->protect_card) { 1287 if (host->protect_card) {
1268 dev_info(host->dev, "%s: cover is closed, " 1288 dev_info(host->dev, "%s: cover is closed, "
1269 "card is now accessible\n", 1289 "card is now accessible\n",
@@ -1286,13 +1306,12 @@ static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
1286static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id) 1306static irqreturn_t omap_hsmmc_detect(int irq, void *dev_id)
1287{ 1307{
1288 struct omap_hsmmc_host *host = dev_id; 1308 struct omap_hsmmc_host *host = dev_id;
1289 struct omap_mmc_slot_data *slot = &mmc_slot(host);
1290 int carddetect; 1309 int carddetect;
1291 1310
1292 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch"); 1311 sysfs_notify(&host->mmc->class_dev.kobj, NULL, "cover_switch");
1293 1312
1294 if (slot->card_detect) 1313 if (host->card_detect)
1295 carddetect = slot->card_detect(host->dev, host->slot_id); 1314 carddetect = host->card_detect(host->dev);
1296 else { 1315 else {
1297 omap_hsmmc_protect_card(host); 1316 omap_hsmmc_protect_card(host);
1298 carddetect = -ENOSYS; 1317 carddetect = -ENOSYS;
@@ -1618,12 +1637,10 @@ static void omap_hsmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
1618 if (ios->power_mode != host->power_mode) { 1637 if (ios->power_mode != host->power_mode) {
1619 switch (ios->power_mode) { 1638 switch (ios->power_mode) {
1620 case MMC_POWER_OFF: 1639 case MMC_POWER_OFF:
1621 mmc_slot(host).set_power(host->dev, host->slot_id, 1640 mmc_pdata(host)->set_power(host->dev, 0, 0);
1622 0, 0);
1623 break; 1641 break;
1624 case MMC_POWER_UP: 1642 case MMC_POWER_UP:
1625 mmc_slot(host).set_power(host->dev, host->slot_id, 1643 mmc_pdata(host)->set_power(host->dev, 1, ios->vdd);
1626 1, ios->vdd);
1627 break; 1644 break;
1628 case MMC_POWER_ON: 1645 case MMC_POWER_ON:
1629 do_send_init_stream = 1; 1646 do_send_init_stream = 1;
@@ -1668,26 +1685,26 @@ static int omap_hsmmc_get_cd(struct mmc_host *mmc)
1668{ 1685{
1669 struct omap_hsmmc_host *host = mmc_priv(mmc); 1686 struct omap_hsmmc_host *host = mmc_priv(mmc);
1670 1687
1671 if (!mmc_slot(host).card_detect) 1688 if (!host->card_detect)
1672 return -ENOSYS; 1689 return -ENOSYS;
1673 return mmc_slot(host).card_detect(host->dev, host->slot_id); 1690 return host->card_detect(host->dev);
1674} 1691}
1675 1692
1676static int omap_hsmmc_get_ro(struct mmc_host *mmc) 1693static int omap_hsmmc_get_ro(struct mmc_host *mmc)
1677{ 1694{
1678 struct omap_hsmmc_host *host = mmc_priv(mmc); 1695 struct omap_hsmmc_host *host = mmc_priv(mmc);
1679 1696
1680 if (!mmc_slot(host).get_ro) 1697 if (!host->get_ro)
1681 return -ENOSYS; 1698 return -ENOSYS;
1682 return mmc_slot(host).get_ro(host->dev, 0); 1699 return host->get_ro(host->dev);
1683} 1700}
1684 1701
1685static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card) 1702static void omap_hsmmc_init_card(struct mmc_host *mmc, struct mmc_card *card)
1686{ 1703{
1687 struct omap_hsmmc_host *host = mmc_priv(mmc); 1704 struct omap_hsmmc_host *host = mmc_priv(mmc);
1688 1705
1689 if (mmc_slot(host).init_card) 1706 if (mmc_pdata(host)->init_card)
1690 mmc_slot(host).init_card(card); 1707 mmc_pdata(host)->init_card(card);
1691} 1708}
1692 1709
1693static void omap_hsmmc_enable_sdio_irq(struct mmc_host *mmc, int enable) 1710static void omap_hsmmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
@@ -1957,9 +1974,9 @@ static const struct of_device_id omap_mmc_of_match[] = {
1957}; 1974};
1958MODULE_DEVICE_TABLE(of, omap_mmc_of_match); 1975MODULE_DEVICE_TABLE(of, omap_mmc_of_match);
1959 1976
1960static struct omap_mmc_platform_data *of_get_hsmmc_pdata(struct device *dev) 1977static struct omap_hsmmc_platform_data *of_get_hsmmc_pdata(struct device *dev)
1961{ 1978{
1962 struct omap_mmc_platform_data *pdata; 1979 struct omap_hsmmc_platform_data *pdata;
1963 struct device_node *np = dev->of_node; 1980 struct device_node *np = dev->of_node;
1964 u32 bus_width, max_freq; 1981 u32 bus_width, max_freq;
1965 int cd_gpio, wp_gpio; 1982 int cd_gpio, wp_gpio;
@@ -1976,40 +1993,38 @@ static struct omap_mmc_platform_data *of_get_hsmmc_pdata(struct device *dev)
1976 if (of_find_property(np, "ti,dual-volt", NULL)) 1993 if (of_find_property(np, "ti,dual-volt", NULL))
1977 pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT; 1994 pdata->controller_flags |= OMAP_HSMMC_SUPPORTS_DUAL_VOLT;
1978 1995
1979 /* This driver only supports 1 slot */ 1996 pdata->switch_pin = cd_gpio;
1980 pdata->nr_slots = 1; 1997 pdata->gpio_wp = wp_gpio;
1981 pdata->slots[0].switch_pin = cd_gpio;
1982 pdata->slots[0].gpio_wp = wp_gpio;
1983 1998
1984 if (of_find_property(np, "ti,non-removable", NULL)) { 1999 if (of_find_property(np, "ti,non-removable", NULL)) {
1985 pdata->slots[0].nonremovable = true; 2000 pdata->nonremovable = true;
1986 pdata->slots[0].no_regulator_off_init = true; 2001 pdata->no_regulator_off_init = true;
1987 } 2002 }
1988 of_property_read_u32(np, "bus-width", &bus_width); 2003 of_property_read_u32(np, "bus-width", &bus_width);
1989 if (bus_width == 4) 2004 if (bus_width == 4)
1990 pdata->slots[0].caps |= MMC_CAP_4_BIT_DATA; 2005 pdata->caps |= MMC_CAP_4_BIT_DATA;
1991 else if (bus_width == 8) 2006 else if (bus_width == 8)
1992 pdata->slots[0].caps |= MMC_CAP_8_BIT_DATA; 2007 pdata->caps |= MMC_CAP_8_BIT_DATA;
1993 2008
1994 if (of_find_property(np, "ti,needs-special-reset", NULL)) 2009 if (of_find_property(np, "ti,needs-special-reset", NULL))
1995 pdata->slots[0].features |= HSMMC_HAS_UPDATED_RESET; 2010 pdata->features |= HSMMC_HAS_UPDATED_RESET;
1996 2011
1997 if (!of_property_read_u32(np, "max-frequency", &max_freq)) 2012 if (!of_property_read_u32(np, "max-frequency", &max_freq))
1998 pdata->max_freq = max_freq; 2013 pdata->max_freq = max_freq;
1999 2014
2000 if (of_find_property(np, "ti,needs-special-hs-handling", NULL)) 2015 if (of_find_property(np, "ti,needs-special-hs-handling", NULL))
2001 pdata->slots[0].features |= HSMMC_HAS_HSPE_SUPPORT; 2016 pdata->features |= HSMMC_HAS_HSPE_SUPPORT;
2002 2017
2003 if (of_find_property(np, "keep-power-in-suspend", NULL)) 2018 if (of_find_property(np, "keep-power-in-suspend", NULL))
2004 pdata->slots[0].pm_caps |= MMC_PM_KEEP_POWER; 2019 pdata->pm_caps |= MMC_PM_KEEP_POWER;
2005 2020
2006 if (of_find_property(np, "enable-sdio-wakeup", NULL)) 2021 if (of_find_property(np, "enable-sdio-wakeup", NULL))
2007 pdata->slots[0].pm_caps |= MMC_PM_WAKE_SDIO_IRQ; 2022 pdata->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
2008 2023
2009 return pdata; 2024 return pdata;
2010} 2025}
2011#else 2026#else
2012static inline struct omap_mmc_platform_data 2027static inline struct omap_hsmmc_platform_data
2013 *of_get_hsmmc_pdata(struct device *dev) 2028 *of_get_hsmmc_pdata(struct device *dev)
2014{ 2029{
2015 return ERR_PTR(-EINVAL); 2030 return ERR_PTR(-EINVAL);
@@ -2018,7 +2033,7 @@ static inline struct omap_mmc_platform_data
2018 2033
2019static int omap_hsmmc_probe(struct platform_device *pdev) 2034static int omap_hsmmc_probe(struct platform_device *pdev)
2020{ 2035{
2021 struct omap_mmc_platform_data *pdata = pdev->dev.platform_data; 2036 struct omap_hsmmc_platform_data *pdata = pdev->dev.platform_data;
2022 struct mmc_host *mmc; 2037 struct mmc_host *mmc;
2023 struct omap_hsmmc_host *host = NULL; 2038 struct omap_hsmmc_host *host = NULL;
2024 struct resource *res; 2039 struct resource *res;
@@ -2048,11 +2063,6 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2048 return -ENXIO; 2063 return -ENXIO;
2049 } 2064 }
2050 2065
2051 if (pdata->nr_slots == 0) {
2052 dev_err(&pdev->dev, "No Slots\n");
2053 return -ENXIO;
2054 }
2055
2056 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2066 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2057 irq = platform_get_irq(pdev, 0); 2067 irq = platform_get_irq(pdev, 0);
2058 if (res == NULL || irq < 0) 2068 if (res == NULL || irq < 0)
@@ -2062,14 +2072,10 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2062 if (IS_ERR(base)) 2072 if (IS_ERR(base))
2063 return PTR_ERR(base); 2073 return PTR_ERR(base);
2064 2074
2065 ret = omap_hsmmc_gpio_init(pdata);
2066 if (ret)
2067 goto err;
2068
2069 mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev); 2075 mmc = mmc_alloc_host(sizeof(struct omap_hsmmc_host), &pdev->dev);
2070 if (!mmc) { 2076 if (!mmc) {
2071 ret = -ENOMEM; 2077 ret = -ENOMEM;
2072 goto err_alloc; 2078 goto err;
2073 } 2079 }
2074 2080
2075 host = mmc_priv(mmc); 2081 host = mmc_priv(mmc);
@@ -2079,13 +2085,16 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2079 host->use_dma = 1; 2085 host->use_dma = 1;
2080 host->dma_ch = -1; 2086 host->dma_ch = -1;
2081 host->irq = irq; 2087 host->irq = irq;
2082 host->slot_id = 0;
2083 host->mapbase = res->start + pdata->reg_offset; 2088 host->mapbase = res->start + pdata->reg_offset;
2084 host->base = base + pdata->reg_offset; 2089 host->base = base + pdata->reg_offset;
2085 host->power_mode = MMC_POWER_OFF; 2090 host->power_mode = MMC_POWER_OFF;
2086 host->next_data.cookie = 1; 2091 host->next_data.cookie = 1;
2087 host->pbias_enabled = 0; 2092 host->pbias_enabled = 0;
2088 2093
2094 ret = omap_hsmmc_gpio_init(host, pdata);
2095 if (ret)
2096 goto err_gpio;
2097
2089 platform_set_drvdata(pdev, host); 2098 platform_set_drvdata(pdev, host);
2090 2099
2091 if (pdev->dev.of_node) 2100 if (pdev->dev.of_node)
@@ -2144,14 +2153,14 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2144 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED | 2153 mmc->caps |= MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED |
2145 MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE; 2154 MMC_CAP_WAIT_WHILE_BUSY | MMC_CAP_ERASE;
2146 2155
2147 mmc->caps |= mmc_slot(host).caps; 2156 mmc->caps |= mmc_pdata(host)->caps;
2148 if (mmc->caps & MMC_CAP_8_BIT_DATA) 2157 if (mmc->caps & MMC_CAP_8_BIT_DATA)
2149 mmc->caps |= MMC_CAP_4_BIT_DATA; 2158 mmc->caps |= MMC_CAP_4_BIT_DATA;
2150 2159
2151 if (mmc_slot(host).nonremovable) 2160 if (mmc_pdata(host)->nonremovable)
2152 mmc->caps |= MMC_CAP_NONREMOVABLE; 2161 mmc->caps |= MMC_CAP_NONREMOVABLE;
2153 2162
2154 mmc->pm_caps = mmc_slot(host).pm_caps; 2163 mmc->pm_caps = mmc_pdata(host)->pm_caps;
2155 2164
2156 omap_hsmmc_conf_bus_power(host); 2165 omap_hsmmc_conf_bus_power(host);
2157 2166
@@ -2204,27 +2213,19 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2204 goto err_irq; 2213 goto err_irq;
2205 } 2214 }
2206 2215
2207 if (pdata->init != NULL) { 2216 if (omap_hsmmc_have_reg() && !mmc_pdata(host)->set_power) {
2208 if (pdata->init(&pdev->dev) != 0) {
2209 dev_err(mmc_dev(host->mmc),
2210 "Unable to configure MMC IRQs\n");
2211 goto err_irq;
2212 }
2213 }
2214
2215 if (omap_hsmmc_have_reg() && !mmc_slot(host).set_power) {
2216 ret = omap_hsmmc_reg_get(host); 2217 ret = omap_hsmmc_reg_get(host);
2217 if (ret) 2218 if (ret)
2218 goto err_reg; 2219 goto err_irq;
2219 host->use_reg = 1; 2220 host->use_reg = 1;
2220 } 2221 }
2221 2222
2222 mmc->ocr_avail = mmc_slot(host).ocr_mask; 2223 mmc->ocr_avail = mmc_pdata(host)->ocr_mask;
2223 2224
2224 /* Request IRQ for card detect */ 2225 /* Request IRQ for card detect */
2225 if ((mmc_slot(host).card_detect_irq)) { 2226 if (host->card_detect_irq) {
2226 ret = devm_request_threaded_irq(&pdev->dev, 2227 ret = devm_request_threaded_irq(&pdev->dev,
2227 mmc_slot(host).card_detect_irq, 2228 host->card_detect_irq,
2228 NULL, omap_hsmmc_detect, 2229 NULL, omap_hsmmc_detect,
2229 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 2230 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
2230 mmc_hostname(mmc), host); 2231 mmc_hostname(mmc), host);
@@ -2233,8 +2234,8 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2233 "Unable to grab MMC CD IRQ\n"); 2234 "Unable to grab MMC CD IRQ\n");
2234 goto err_irq_cd; 2235 goto err_irq_cd;
2235 } 2236 }
2236 pdata->suspend = omap_hsmmc_suspend_cdirq; 2237 host->suspend = omap_hsmmc_suspend_cdirq;
2237 pdata->resume = omap_hsmmc_resume_cdirq; 2238 host->resume = omap_hsmmc_resume_cdirq;
2238 } 2239 }
2239 2240
2240 omap_hsmmc_disable_irq(host); 2241 omap_hsmmc_disable_irq(host);
@@ -2255,12 +2256,12 @@ static int omap_hsmmc_probe(struct platform_device *pdev)
2255 2256
2256 mmc_add_host(mmc); 2257 mmc_add_host(mmc);
2257 2258
2258 if (mmc_slot(host).name != NULL) { 2259 if (mmc_pdata(host)->name != NULL) {
2259 ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name); 2260 ret = device_create_file(&mmc->class_dev, &dev_attr_slot_name);
2260 if (ret < 0) 2261 if (ret < 0)
2261 goto err_slot_name; 2262 goto err_slot_name;
2262 } 2263 }
2263 if (mmc_slot(host).card_detect_irq && mmc_slot(host).get_cover_state) { 2264 if (host->card_detect_irq && host->get_cover_state) {
2264 ret = device_create_file(&mmc->class_dev, 2265 ret = device_create_file(&mmc->class_dev,
2265 &dev_attr_cover_switch); 2266 &dev_attr_cover_switch);
2266 if (ret < 0) 2267 if (ret < 0)
@@ -2278,9 +2279,6 @@ err_slot_name:
2278err_irq_cd: 2279err_irq_cd:
2279 if (host->use_reg) 2280 if (host->use_reg)
2280 omap_hsmmc_reg_put(host); 2281 omap_hsmmc_reg_put(host);
2281err_reg:
2282 if (host->pdata->cleanup)
2283 host->pdata->cleanup(&pdev->dev);
2284err_irq: 2282err_irq:
2285 if (host->tx_chan) 2283 if (host->tx_chan)
2286 dma_release_channel(host->tx_chan); 2284 dma_release_channel(host->tx_chan);
@@ -2291,9 +2289,9 @@ err_irq:
2291 if (host->dbclk) 2289 if (host->dbclk)
2292 clk_disable_unprepare(host->dbclk); 2290 clk_disable_unprepare(host->dbclk);
2293err1: 2291err1:
2292 omap_hsmmc_gpio_free(host, pdata);
2293err_gpio:
2294 mmc_free_host(mmc); 2294 mmc_free_host(mmc);
2295err_alloc:
2296 omap_hsmmc_gpio_free(pdata);
2297err: 2295err:
2298 return ret; 2296 return ret;
2299} 2297}
@@ -2306,8 +2304,6 @@ static int omap_hsmmc_remove(struct platform_device *pdev)
2306 mmc_remove_host(host->mmc); 2304 mmc_remove_host(host->mmc);
2307 if (host->use_reg) 2305 if (host->use_reg)
2308 omap_hsmmc_reg_put(host); 2306 omap_hsmmc_reg_put(host);
2309 if (host->pdata->cleanup)
2310 host->pdata->cleanup(&pdev->dev);
2311 2307
2312 if (host->tx_chan) 2308 if (host->tx_chan)
2313 dma_release_channel(host->tx_chan); 2309 dma_release_channel(host->tx_chan);
@@ -2319,7 +2315,7 @@ static int omap_hsmmc_remove(struct platform_device *pdev)
2319 if (host->dbclk) 2315 if (host->dbclk)
2320 clk_disable_unprepare(host->dbclk); 2316 clk_disable_unprepare(host->dbclk);
2321 2317
2322 omap_hsmmc_gpio_free(host->pdata); 2318 omap_hsmmc_gpio_free(host, host->pdata);
2323 mmc_free_host(host->mmc); 2319 mmc_free_host(host->mmc);
2324 2320
2325 return 0; 2321 return 0;
@@ -2330,8 +2326,8 @@ static int omap_hsmmc_prepare(struct device *dev)
2330{ 2326{
2331 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 2327 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
2332 2328
2333 if (host->pdata->suspend) 2329 if (host->suspend)
2334 return host->pdata->suspend(dev, host->slot_id); 2330 return host->suspend(dev);
2335 2331
2336 return 0; 2332 return 0;
2337} 2333}
@@ -2340,8 +2336,8 @@ static void omap_hsmmc_complete(struct device *dev)
2340{ 2336{
2341 struct omap_hsmmc_host *host = dev_get_drvdata(dev); 2337 struct omap_hsmmc_host *host = dev_get_drvdata(dev);
2342 2338
2343 if (host->pdata->resume) 2339 if (host->resume)
2344 host->pdata->resume(dev, host->slot_id); 2340 host->resume(dev);
2345 2341
2346} 2342}
2347 2343
diff --git a/drivers/mmc/host/sdhci-acpi.c b/drivers/mmc/host/sdhci-acpi.c
index 9cccc0e89b04..daba49ac1242 100644
--- a/drivers/mmc/host/sdhci-acpi.c
+++ b/drivers/mmc/host/sdhci-acpi.c
@@ -76,6 +76,7 @@ struct sdhci_acpi_host {
76 const struct sdhci_acpi_slot *slot; 76 const struct sdhci_acpi_slot *slot;
77 struct platform_device *pdev; 77 struct platform_device *pdev;
78 bool use_runtime_pm; 78 bool use_runtime_pm;
79 bool dma_setup;
79}; 80};
80 81
81static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag) 82static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag)
@@ -85,7 +86,29 @@ static inline bool sdhci_acpi_flag(struct sdhci_acpi_host *c, unsigned int flag)
85 86
86static int sdhci_acpi_enable_dma(struct sdhci_host *host) 87static int sdhci_acpi_enable_dma(struct sdhci_host *host)
87{ 88{
88 return 0; 89 struct sdhci_acpi_host *c = sdhci_priv(host);
90 struct device *dev = &c->pdev->dev;
91 int err = -1;
92
93 if (c->dma_setup)
94 return 0;
95
96 if (host->flags & SDHCI_USE_64_BIT_DMA) {
97 if (host->quirks2 & SDHCI_QUIRK2_BROKEN_64_BIT_DMA) {
98 host->flags &= ~SDHCI_USE_64_BIT_DMA;
99 } else {
100 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64));
101 if (err)
102 dev_warn(dev, "Failed to set 64-bit DMA mask\n");
103 }
104 }
105
106 if (err)
107 err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
108
109 c->dma_setup = !err;
110
111 return err;
89} 112}
90 113
91static void sdhci_acpi_int_hw_reset(struct sdhci_host *host) 114static void sdhci_acpi_int_hw_reset(struct sdhci_host *host)
@@ -180,17 +203,21 @@ static int sdhci_acpi_sd_probe_slot(struct platform_device *pdev,
180static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = { 203static const struct sdhci_acpi_slot sdhci_acpi_slot_int_emmc = {
181 .chip = &sdhci_acpi_chip_int, 204 .chip = &sdhci_acpi_chip_int,
182 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | 205 .caps = MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
183 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR, 206 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR |
207 MMC_CAP_BUS_WIDTH_TEST | MMC_CAP_WAIT_WHILE_BUSY,
184 .caps2 = MMC_CAP2_HC_ERASE_SZ, 208 .caps2 = MMC_CAP2_HC_ERASE_SZ,
185 .flags = SDHCI_ACPI_RUNTIME_PM, 209 .flags = SDHCI_ACPI_RUNTIME_PM,
210 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
186 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | SDHCI_QUIRK2_STOP_WITH_TC, 211 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | SDHCI_QUIRK2_STOP_WITH_TC,
187 .probe_slot = sdhci_acpi_emmc_probe_slot, 212 .probe_slot = sdhci_acpi_emmc_probe_slot,
188}; 213};
189 214
190static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = { 215static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = {
191 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION, 216 .quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
217 SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
192 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON, 218 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON,
193 .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD, 219 .caps = MMC_CAP_NONREMOVABLE | MMC_CAP_POWER_OFF_CARD |
220 MMC_CAP_BUS_WIDTH_TEST | MMC_CAP_WAIT_WHILE_BUSY,
194 .flags = SDHCI_ACPI_RUNTIME_PM, 221 .flags = SDHCI_ACPI_RUNTIME_PM,
195 .pm_caps = MMC_PM_KEEP_POWER, 222 .pm_caps = MMC_PM_KEEP_POWER,
196 .probe_slot = sdhci_acpi_sdio_probe_slot, 223 .probe_slot = sdhci_acpi_sdio_probe_slot,
@@ -199,8 +226,10 @@ static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sdio = {
199static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = { 226static const struct sdhci_acpi_slot sdhci_acpi_slot_int_sd = {
200 .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL | 227 .flags = SDHCI_ACPI_SD_CD | SDHCI_ACPI_SD_CD_OVERRIDE_LEVEL |
201 SDHCI_ACPI_RUNTIME_PM, 228 SDHCI_ACPI_RUNTIME_PM,
229 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
202 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON | 230 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON |
203 SDHCI_QUIRK2_STOP_WITH_TC, 231 SDHCI_QUIRK2_STOP_WITH_TC,
232 .caps = MMC_CAP_BUS_WIDTH_TEST | MMC_CAP_WAIT_WHILE_BUSY,
204 .probe_slot = sdhci_acpi_sd_probe_slot, 233 .probe_slot = sdhci_acpi_sd_probe_slot,
205}; 234};
206 235
@@ -305,21 +334,6 @@ static int sdhci_acpi_probe(struct platform_device *pdev)
305 goto err_free; 334 goto err_free;
306 } 335 }
307 336
308 if (!dev->dma_mask) {
309 u64 dma_mask;
310
311 if (sdhci_readl(host, SDHCI_CAPABILITIES) & SDHCI_CAN_64BIT) {
312 /* 64-bit DMA is not supported at present */
313 dma_mask = DMA_BIT_MASK(32);
314 } else {
315 dma_mask = DMA_BIT_MASK(32);
316 }
317
318 err = dma_coerce_mask_and_coherent(dev, dma_mask);
319 if (err)
320 goto err_free;
321 }
322
323 if (c->slot) { 337 if (c->slot) {
324 if (c->slot->probe_slot) { 338 if (c->slot->probe_slot) {
325 err = c->slot->probe_slot(pdev, hid, uid); 339 err = c->slot->probe_slot(pdev, hid, uid);
diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 587ee0edeb57..12711ab51aed 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -65,8 +65,6 @@
65/* NOTE: the minimum valid tuning start tap for mx6sl is 1 */ 65/* NOTE: the minimum valid tuning start tap for mx6sl is 1 */
66#define ESDHC_TUNING_START_TAP 0x1 66#define ESDHC_TUNING_START_TAP 0x1
67 67
68#define ESDHC_TUNING_BLOCK_PATTERN_LEN 64
69
70/* pinctrl state */ 68/* pinctrl state */
71#define ESDHC_PINCTRL_STATE_100MHZ "state_100mhz" 69#define ESDHC_PINCTRL_STATE_100MHZ "state_100mhz"
72#define ESDHC_PINCTRL_STATE_200MHZ "state_200mhz" 70#define ESDHC_PINCTRL_STATE_200MHZ "state_200mhz"
@@ -692,8 +690,6 @@ static void esdhc_prepare_tuning(struct sdhci_host *host, u32 val)
692 /* FIXME: delay a bit for card to be ready for next tuning due to errors */ 690 /* FIXME: delay a bit for card to be ready for next tuning due to errors */
693 mdelay(1); 691 mdelay(1);
694 692
695 /* This is balanced by the runtime put in sdhci_tasklet_finish */
696 pm_runtime_get_sync(host->mmc->parent);
697 reg = readl(host->ioaddr + ESDHC_MIX_CTRL); 693 reg = readl(host->ioaddr + ESDHC_MIX_CTRL);
698 reg |= ESDHC_MIX_CTRL_EXE_TUNE | ESDHC_MIX_CTRL_SMPCLK_SEL | 694 reg |= ESDHC_MIX_CTRL_EXE_TUNE | ESDHC_MIX_CTRL_SMPCLK_SEL |
699 ESDHC_MIX_CTRL_FBCLK_SEL; 695 ESDHC_MIX_CTRL_FBCLK_SEL;
@@ -704,54 +700,6 @@ static void esdhc_prepare_tuning(struct sdhci_host *host, u32 val)
704 val, readl(host->ioaddr + ESDHC_TUNE_CTRL_STATUS)); 700 val, readl(host->ioaddr + ESDHC_TUNE_CTRL_STATUS));
705} 701}
706 702
707static void esdhc_request_done(struct mmc_request *mrq)
708{
709 complete(&mrq->completion);
710}
711
712static int esdhc_send_tuning_cmd(struct sdhci_host *host, u32 opcode,
713 struct scatterlist *sg)
714{
715 struct mmc_command cmd = {0};
716 struct mmc_request mrq = {NULL};
717 struct mmc_data data = {0};
718
719 cmd.opcode = opcode;
720 cmd.arg = 0;
721 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
722
723 data.blksz = ESDHC_TUNING_BLOCK_PATTERN_LEN;
724 data.blocks = 1;
725 data.flags = MMC_DATA_READ;
726 data.sg = sg;
727 data.sg_len = 1;
728
729 mrq.cmd = &cmd;
730 mrq.cmd->mrq = &mrq;
731 mrq.data = &data;
732 mrq.data->mrq = &mrq;
733 mrq.cmd->data = mrq.data;
734
735 mrq.done = esdhc_request_done;
736 init_completion(&(mrq.completion));
737
738 spin_lock_irq(&host->lock);
739 host->mrq = &mrq;
740
741 sdhci_send_command(host, mrq.cmd);
742
743 spin_unlock_irq(&host->lock);
744
745 wait_for_completion(&mrq.completion);
746
747 if (cmd.error)
748 return cmd.error;
749 if (data.error)
750 return data.error;
751
752 return 0;
753}
754
755static void esdhc_post_tuning(struct sdhci_host *host) 703static void esdhc_post_tuning(struct sdhci_host *host)
756{ 704{
757 u32 reg; 705 u32 reg;
@@ -763,21 +711,13 @@ static void esdhc_post_tuning(struct sdhci_host *host)
763 711
764static int esdhc_executing_tuning(struct sdhci_host *host, u32 opcode) 712static int esdhc_executing_tuning(struct sdhci_host *host, u32 opcode)
765{ 713{
766 struct scatterlist sg;
767 char *tuning_pattern;
768 int min, max, avg, ret; 714 int min, max, avg, ret;
769 715
770 tuning_pattern = kmalloc(ESDHC_TUNING_BLOCK_PATTERN_LEN, GFP_KERNEL);
771 if (!tuning_pattern)
772 return -ENOMEM;
773
774 sg_init_one(&sg, tuning_pattern, ESDHC_TUNING_BLOCK_PATTERN_LEN);
775
776 /* find the mininum delay first which can pass tuning */ 716 /* find the mininum delay first which can pass tuning */
777 min = ESDHC_TUNE_CTRL_MIN; 717 min = ESDHC_TUNE_CTRL_MIN;
778 while (min < ESDHC_TUNE_CTRL_MAX) { 718 while (min < ESDHC_TUNE_CTRL_MAX) {
779 esdhc_prepare_tuning(host, min); 719 esdhc_prepare_tuning(host, min);
780 if (!esdhc_send_tuning_cmd(host, opcode, &sg)) 720 if (!mmc_send_tuning(host->mmc))
781 break; 721 break;
782 min += ESDHC_TUNE_CTRL_STEP; 722 min += ESDHC_TUNE_CTRL_STEP;
783 } 723 }
@@ -786,7 +726,7 @@ static int esdhc_executing_tuning(struct sdhci_host *host, u32 opcode)
786 max = min + ESDHC_TUNE_CTRL_STEP; 726 max = min + ESDHC_TUNE_CTRL_STEP;
787 while (max < ESDHC_TUNE_CTRL_MAX) { 727 while (max < ESDHC_TUNE_CTRL_MAX) {
788 esdhc_prepare_tuning(host, max); 728 esdhc_prepare_tuning(host, max);
789 if (esdhc_send_tuning_cmd(host, opcode, &sg)) { 729 if (mmc_send_tuning(host->mmc)) {
790 max -= ESDHC_TUNE_CTRL_STEP; 730 max -= ESDHC_TUNE_CTRL_STEP;
791 break; 731 break;
792 } 732 }
@@ -796,11 +736,9 @@ static int esdhc_executing_tuning(struct sdhci_host *host, u32 opcode)
796 /* use average delay to get the best timing */ 736 /* use average delay to get the best timing */
797 avg = (min + max) / 2; 737 avg = (min + max) / 2;
798 esdhc_prepare_tuning(host, avg); 738 esdhc_prepare_tuning(host, avg);
799 ret = esdhc_send_tuning_cmd(host, opcode, &sg); 739 ret = mmc_send_tuning(host->mmc);
800 esdhc_post_tuning(host); 740 esdhc_post_tuning(host);
801 741
802 kfree(tuning_pattern);
803
804 dev_dbg(mmc_dev(host->mmc), "tunning %s at 0x%x ret %d\n", 742 dev_dbg(mmc_dev(host->mmc), "tunning %s at 0x%x ret %d\n",
805 ret ? "failed" : "passed", avg, ret); 743 ret ? "failed" : "passed", avg, ret);
806 744
@@ -1031,11 +969,8 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
1031 969
1032 imx_data->pins_default = pinctrl_lookup_state(imx_data->pinctrl, 970 imx_data->pins_default = pinctrl_lookup_state(imx_data->pinctrl,
1033 PINCTRL_STATE_DEFAULT); 971 PINCTRL_STATE_DEFAULT);
1034 if (IS_ERR(imx_data->pins_default)) { 972 if (IS_ERR(imx_data->pins_default))
1035 err = PTR_ERR(imx_data->pins_default); 973 dev_warn(mmc_dev(host->mmc), "could not get default state\n");
1036 dev_err(mmc_dev(host->mmc), "could not get default state\n");
1037 goto disable_clk;
1038 }
1039 974
1040 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL; 975 host->quirks |= SDHCI_QUIRK_BROKEN_TIMEOUT_VAL;
1041 976
@@ -1123,7 +1058,8 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
1123 } 1058 }
1124 1059
1125 /* sdr50 and sdr104 needs work on 1.8v signal voltage */ 1060 /* sdr50 and sdr104 needs work on 1.8v signal voltage */
1126 if ((boarddata->support_vsel) && esdhc_is_usdhc(imx_data)) { 1061 if ((boarddata->support_vsel) && esdhc_is_usdhc(imx_data) &&
1062 !IS_ERR(imx_data->pins_default)) {
1127 imx_data->pins_100mhz = pinctrl_lookup_state(imx_data->pinctrl, 1063 imx_data->pins_100mhz = pinctrl_lookup_state(imx_data->pinctrl,
1128 ESDHC_PINCTRL_STATE_100MHZ); 1064 ESDHC_PINCTRL_STATE_100MHZ);
1129 imx_data->pins_200mhz = pinctrl_lookup_state(imx_data->pinctrl, 1065 imx_data->pins_200mhz = pinctrl_lookup_state(imx_data->pinctrl,
diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 30804385af6d..3d32ce896b09 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -339,9 +339,7 @@ static int msm_init_cm_dll(struct sdhci_host *host)
339static int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode) 339static int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode)
340{ 340{
341 int tuning_seq_cnt = 3; 341 int tuning_seq_cnt = 3;
342 u8 phase, *data_buf, tuned_phases[16], tuned_phase_cnt = 0; 342 u8 phase, tuned_phases[16], tuned_phase_cnt = 0;
343 const u8 *tuning_block_pattern = tuning_blk_pattern_4bit;
344 int size = sizeof(tuning_blk_pattern_4bit);
345 int rc; 343 int rc;
346 struct mmc_host *mmc = host->mmc; 344 struct mmc_host *mmc = host->mmc;
347 struct mmc_ios ios = host->mmc->ios; 345 struct mmc_ios ios = host->mmc->ios;
@@ -355,53 +353,21 @@ static int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode)
355 (ios.timing == MMC_TIMING_UHS_SDR104))) 353 (ios.timing == MMC_TIMING_UHS_SDR104)))
356 return 0; 354 return 0;
357 355
358 if ((opcode == MMC_SEND_TUNING_BLOCK_HS200) &&
359 (mmc->ios.bus_width == MMC_BUS_WIDTH_8)) {
360 tuning_block_pattern = tuning_blk_pattern_8bit;
361 size = sizeof(tuning_blk_pattern_8bit);
362 }
363
364 data_buf = kmalloc(size, GFP_KERNEL);
365 if (!data_buf)
366 return -ENOMEM;
367
368retry: 356retry:
369 /* First of all reset the tuning block */ 357 /* First of all reset the tuning block */
370 rc = msm_init_cm_dll(host); 358 rc = msm_init_cm_dll(host);
371 if (rc) 359 if (rc)
372 goto out; 360 return rc;
373 361
374 phase = 0; 362 phase = 0;
375 do { 363 do {
376 struct mmc_command cmd = { 0 };
377 struct mmc_data data = { 0 };
378 struct mmc_request mrq = {
379 .cmd = &cmd,
380 .data = &data
381 };
382 struct scatterlist sg;
383
384 /* Set the phase in delay line hw block */ 364 /* Set the phase in delay line hw block */
385 rc = msm_config_cm_dll_phase(host, phase); 365 rc = msm_config_cm_dll_phase(host, phase);
386 if (rc) 366 if (rc)
387 goto out; 367 return rc;
388 368
389 cmd.opcode = opcode; 369 rc = mmc_send_tuning(mmc);
390 cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; 370 if (!rc) {
391
392 data.blksz = size;
393 data.blocks = 1;
394 data.flags = MMC_DATA_READ;
395 data.timeout_ns = NSEC_PER_SEC; /* 1 second */
396
397 data.sg = &sg;
398 data.sg_len = 1;
399 sg_init_one(&sg, data_buf, size);
400 memset(data_buf, 0, size);
401 mmc_wait_for_req(mmc, &mrq);
402
403 if (!cmd.error && !data.error &&
404 !memcmp(data_buf, tuning_block_pattern, size)) {
405 /* Tuning is successful at this tuning point */ 371 /* Tuning is successful at this tuning point */
406 tuned_phases[tuned_phase_cnt++] = phase; 372 tuned_phases[tuned_phase_cnt++] = phase;
407 dev_dbg(mmc_dev(mmc), "%s: Found good phase = %d\n", 373 dev_dbg(mmc_dev(mmc), "%s: Found good phase = %d\n",
@@ -413,7 +379,7 @@ retry:
413 rc = msm_find_most_appropriate_phase(host, tuned_phases, 379 rc = msm_find_most_appropriate_phase(host, tuned_phases,
414 tuned_phase_cnt); 380 tuned_phase_cnt);
415 if (rc < 0) 381 if (rc < 0)
416 goto out; 382 return rc;
417 else 383 else
418 phase = rc; 384 phase = rc;
419 385
@@ -423,7 +389,7 @@ retry:
423 */ 389 */
424 rc = msm_config_cm_dll_phase(host, phase); 390 rc = msm_config_cm_dll_phase(host, phase);
425 if (rc) 391 if (rc)
426 goto out; 392 return rc;
427 dev_dbg(mmc_dev(mmc), "%s: Setting the tuning phase to %d\n", 393 dev_dbg(mmc_dev(mmc), "%s: Setting the tuning phase to %d\n",
428 mmc_hostname(mmc), phase); 394 mmc_hostname(mmc), phase);
429 } else { 395 } else {
@@ -435,8 +401,6 @@ retry:
435 rc = -EIO; 401 rc = -EIO;
436 } 402 }
437 403
438out:
439 kfree(data_buf);
440 return rc; 404 return rc;
441} 405}
442 406
diff --git a/drivers/mmc/host/sdhci-of-arasan.c b/drivers/mmc/host/sdhci-of-arasan.c
index 981d66e5c023..bcb51e9dfdcd 100644
--- a/drivers/mmc/host/sdhci-of-arasan.c
+++ b/drivers/mmc/host/sdhci-of-arasan.c
@@ -165,7 +165,6 @@ static int sdhci_arasan_probe(struct platform_device *pdev)
165 host = sdhci_pltfm_init(pdev, &sdhci_arasan_pdata, 0); 165 host = sdhci_pltfm_init(pdev, &sdhci_arasan_pdata, 0);
166 if (IS_ERR(host)) { 166 if (IS_ERR(host)) {
167 ret = PTR_ERR(host); 167 ret = PTR_ERR(host);
168 dev_err(&pdev->dev, "platform init failed (%u)\n", ret);
169 goto clk_disable_all; 168 goto clk_disable_all;
170 } 169 }
171 170
@@ -175,10 +174,8 @@ static int sdhci_arasan_probe(struct platform_device *pdev)
175 pltfm_host->clk = clk_xin; 174 pltfm_host->clk = clk_xin;
176 175
177 ret = sdhci_add_host(host); 176 ret = sdhci_add_host(host);
178 if (ret) { 177 if (ret)
179 dev_err(&pdev->dev, "platform register failed (%u)\n", ret);
180 goto err_pltfm_free; 178 goto err_pltfm_free;
181 }
182 179
183 return 0; 180 return 0;
184 181
diff --git a/drivers/mmc/host/sdhci-pci-o2micro.c b/drivers/mmc/host/sdhci-pci-o2micro.c
index 5670e381b0cf..e2ec108dba0e 100644
--- a/drivers/mmc/host/sdhci-pci-o2micro.c
+++ b/drivers/mmc/host/sdhci-pci-o2micro.c
@@ -127,8 +127,6 @@ void sdhci_pci_o2_fujin2_pci_init(struct sdhci_pci_chip *chip)
127 return; 127 return;
128 scratch_32 &= ~((1 << 21) | (1 << 30)); 128 scratch_32 &= ~((1 << 21) | (1 << 30));
129 129
130 /* Set RTD3 function disabled */
131 scratch_32 |= ((1 << 29) | (1 << 28));
132 pci_write_config_dword(chip->pdev, O2_SD_FUNC_REG3, scratch_32); 130 pci_write_config_dword(chip->pdev, O2_SD_FUNC_REG3, scratch_32);
133 131
134 /* Set L1 Entrance Timer */ 132 /* Set L1 Entrance Timer */
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 61192973e7cb..95f73007fccf 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -269,7 +269,9 @@ static void sdhci_pci_int_hw_reset(struct sdhci_host *host)
269static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot) 269static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
270{ 270{
271 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE | 271 slot->host->mmc->caps |= MMC_CAP_8_BIT_DATA | MMC_CAP_NONREMOVABLE |
272 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR; 272 MMC_CAP_HW_RESET | MMC_CAP_1_8V_DDR |
273 MMC_CAP_BUS_WIDTH_TEST |
274 MMC_CAP_WAIT_WHILE_BUSY;
273 slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ; 275 slot->host->mmc->caps2 |= MMC_CAP2_HC_ERASE_SZ;
274 slot->hw_reset = sdhci_pci_int_hw_reset; 276 slot->hw_reset = sdhci_pci_int_hw_reset;
275 if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BSW_EMMC) 277 if (slot->chip->pdev->device == PCI_DEVICE_ID_INTEL_BSW_EMMC)
@@ -279,12 +281,16 @@ static int byt_emmc_probe_slot(struct sdhci_pci_slot *slot)
279 281
280static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot) 282static int byt_sdio_probe_slot(struct sdhci_pci_slot *slot)
281{ 283{
282 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE; 284 slot->host->mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_NONREMOVABLE |
285 MMC_CAP_BUS_WIDTH_TEST |
286 MMC_CAP_WAIT_WHILE_BUSY;
283 return 0; 287 return 0;
284} 288}
285 289
286static int byt_sd_probe_slot(struct sdhci_pci_slot *slot) 290static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
287{ 291{
292 slot->host->mmc->caps |= MMC_CAP_BUS_WIDTH_TEST |
293 MMC_CAP_WAIT_WHILE_BUSY;
288 slot->cd_con_id = NULL; 294 slot->cd_con_id = NULL;
289 slot->cd_idx = 0; 295 slot->cd_idx = 0;
290 slot->cd_override_level = true; 296 slot->cd_override_level = true;
@@ -294,11 +300,13 @@ static int byt_sd_probe_slot(struct sdhci_pci_slot *slot)
294static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = { 300static const struct sdhci_pci_fixes sdhci_intel_byt_emmc = {
295 .allow_runtime_pm = true, 301 .allow_runtime_pm = true,
296 .probe_slot = byt_emmc_probe_slot, 302 .probe_slot = byt_emmc_probe_slot,
303 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
297 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN | 304 .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
298 SDHCI_QUIRK2_STOP_WITH_TC, 305 SDHCI_QUIRK2_STOP_WITH_TC,
299}; 306};
300 307
301static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = { 308static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
309 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
302 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON | 310 .quirks2 = SDHCI_QUIRK2_HOST_OFF_CARD_ON |
303 SDHCI_QUIRK2_PRESET_VALUE_BROKEN, 311 SDHCI_QUIRK2_PRESET_VALUE_BROKEN,
304 .allow_runtime_pm = true, 312 .allow_runtime_pm = true,
@@ -306,6 +314,7 @@ static const struct sdhci_pci_fixes sdhci_intel_byt_sdio = {
306}; 314};
307 315
308static const struct sdhci_pci_fixes sdhci_intel_byt_sd = { 316static const struct sdhci_pci_fixes sdhci_intel_byt_sd = {
317 .quirks = SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC,
309 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON | 318 .quirks2 = SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON |
310 SDHCI_QUIRK2_PRESET_VALUE_BROKEN | 319 SDHCI_QUIRK2_PRESET_VALUE_BROKEN |
311 SDHCI_QUIRK2_STOP_WITH_TC, 320 SDHCI_QUIRK2_STOP_WITH_TC,
@@ -645,6 +654,25 @@ static const struct sdhci_pci_fixes sdhci_rtsx = {
645 .probe_slot = rtsx_probe_slot, 654 .probe_slot = rtsx_probe_slot,
646}; 655};
647 656
657static int amd_probe(struct sdhci_pci_chip *chip)
658{
659 struct pci_dev *smbus_dev;
660
661 smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD,
662 PCI_DEVICE_ID_AMD_HUDSON2_SMBUS, NULL);
663
664 if (smbus_dev && (smbus_dev->revision < 0x51)) {
665 chip->quirks2 |= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD;
666 chip->quirks2 |= SDHCI_QUIRK2_BROKEN_HS200;
667 }
668
669 return 0;
670}
671
672static const struct sdhci_pci_fixes sdhci_amd = {
673 .probe = amd_probe,
674};
675
648static const struct pci_device_id pci_ids[] = { 676static const struct pci_device_id pci_ids[] = {
649 { 677 {
650 .vendor = PCI_VENDOR_ID_RICOH, 678 .vendor = PCI_VENDOR_ID_RICOH,
@@ -1044,7 +1072,15 @@ static const struct pci_device_id pci_ids[] = {
1044 .subdevice = PCI_ANY_ID, 1072 .subdevice = PCI_ANY_ID,
1045 .driver_data = (kernel_ulong_t)&sdhci_o2, 1073 .driver_data = (kernel_ulong_t)&sdhci_o2,
1046 }, 1074 },
1047 1075 {
1076 .vendor = PCI_VENDOR_ID_AMD,
1077 .device = PCI_ANY_ID,
1078 .class = PCI_CLASS_SYSTEM_SDHCI << 8,
1079 .class_mask = 0xFFFF00,
1080 .subvendor = PCI_ANY_ID,
1081 .subdevice = PCI_ANY_ID,
1082 .driver_data = (kernel_ulong_t)&sdhci_amd,
1083 },
1048 { /* Generic SD host controller */ 1084 { /* Generic SD host controller */
1049 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00) 1085 PCI_DEVICE_CLASS((PCI_CLASS_SYSTEM_SDHCI << 8), 0xFFFF00)
1050 }, 1086 },
@@ -1064,7 +1100,7 @@ static int sdhci_pci_enable_dma(struct sdhci_host *host)
1064{ 1100{
1065 struct sdhci_pci_slot *slot; 1101 struct sdhci_pci_slot *slot;
1066 struct pci_dev *pdev; 1102 struct pci_dev *pdev;
1067 int ret; 1103 int ret = -1;
1068 1104
1069 slot = sdhci_priv(host); 1105 slot = sdhci_priv(host);
1070 pdev = slot->chip->pdev; 1106 pdev = slot->chip->pdev;
@@ -1076,7 +1112,17 @@ static int sdhci_pci_enable_dma(struct sdhci_host *host)
1076 "doesn't fully claim to support it.\n"); 1112 "doesn't fully claim to support it.\n");
1077 } 1113 }
1078 1114
1079 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 1115 if (host->flags & SDHCI_USE_64_BIT_DMA) {
1116 if (host->quirks2 & SDHCI_QUIRK2_BROKEN_64_BIT_DMA) {
1117 host->flags &= ~SDHCI_USE_64_BIT_DMA;
1118 } else {
1119 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
1120 if (ret)
1121 dev_warn(&pdev->dev, "Failed to set 64-bit DMA mask\n");
1122 }
1123 }
1124 if (ret)
1125 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
1080 if (ret) 1126 if (ret)
1081 return ret; 1127 return ret;
1082 1128
diff --git a/drivers/mmc/host/sdhci-pxav2.c b/drivers/mmc/host/sdhci-pxav2.c
index b4c23e983baf..f98008b5ea77 100644
--- a/drivers/mmc/host/sdhci-pxav2.c
+++ b/drivers/mmc/host/sdhci-pxav2.c
@@ -167,23 +167,17 @@ static int sdhci_pxav2_probe(struct platform_device *pdev)
167 struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data; 167 struct sdhci_pxa_platdata *pdata = pdev->dev.platform_data;
168 struct device *dev = &pdev->dev; 168 struct device *dev = &pdev->dev;
169 struct sdhci_host *host = NULL; 169 struct sdhci_host *host = NULL;
170 struct sdhci_pxa *pxa = NULL;
171 const struct of_device_id *match; 170 const struct of_device_id *match;
172 171
173 int ret; 172 int ret;
174 struct clk *clk; 173 struct clk *clk;
175 174
176 pxa = kzalloc(sizeof(struct sdhci_pxa), GFP_KERNEL);
177 if (!pxa)
178 return -ENOMEM;
179
180 host = sdhci_pltfm_init(pdev, NULL, 0); 175 host = sdhci_pltfm_init(pdev, NULL, 0);
181 if (IS_ERR(host)) { 176 if (IS_ERR(host))
182 kfree(pxa);
183 return PTR_ERR(host); 177 return PTR_ERR(host);
184 } 178
185 pltfm_host = sdhci_priv(host); 179 pltfm_host = sdhci_priv(host);
186 pltfm_host->priv = pxa; 180 pltfm_host->priv = NULL;
187 181
188 clk = clk_get(dev, "PXA-SDHCLK"); 182 clk = clk_get(dev, "PXA-SDHCLK");
189 if (IS_ERR(clk)) { 183 if (IS_ERR(clk)) {
@@ -238,7 +232,6 @@ err_add_host:
238 clk_put(clk); 232 clk_put(clk);
239err_clk_get: 233err_clk_get:
240 sdhci_pltfm_free(pdev); 234 sdhci_pltfm_free(pdev);
241 kfree(pxa);
242 return ret; 235 return ret;
243} 236}
244 237
@@ -246,14 +239,12 @@ static int sdhci_pxav2_remove(struct platform_device *pdev)
246{ 239{
247 struct sdhci_host *host = platform_get_drvdata(pdev); 240 struct sdhci_host *host = platform_get_drvdata(pdev);
248 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 241 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
249 struct sdhci_pxa *pxa = pltfm_host->priv;
250 242
251 sdhci_remove_host(host, 1); 243 sdhci_remove_host(host, 1);
252 244
253 clk_disable_unprepare(pltfm_host->clk); 245 clk_disable_unprepare(pltfm_host->clk);
254 clk_put(pltfm_host->clk); 246 clk_put(pltfm_host->clk);
255 sdhci_pltfm_free(pdev); 247 sdhci_pltfm_free(pdev);
256 kfree(pxa);
257 248
258 return 0; 249 return 0;
259} 250}
diff --git a/drivers/mmc/host/sdhci-pxav3.c b/drivers/mmc/host/sdhci-pxav3.c
index 5036d7d39529..ad0badad0ebc 100644
--- a/drivers/mmc/host/sdhci-pxav3.c
+++ b/drivers/mmc/host/sdhci-pxav3.c
@@ -58,6 +58,12 @@
58#define SDCE_MISC_INT (1<<2) 58#define SDCE_MISC_INT (1<<2)
59#define SDCE_MISC_INT_EN (1<<1) 59#define SDCE_MISC_INT_EN (1<<1)
60 60
61struct sdhci_pxa {
62 struct clk *clk_core;
63 struct clk *clk_io;
64 u8 power_mode;
65};
66
61/* 67/*
62 * These registers are relative to the second register region, for the 68 * These registers are relative to the second register region, for the
63 * MBus bridge. 69 * MBus bridge.
@@ -211,6 +217,7 @@ static void pxav3_set_uhs_signaling(struct sdhci_host *host, unsigned int uhs)
211 case MMC_TIMING_UHS_SDR104: 217 case MMC_TIMING_UHS_SDR104:
212 ctrl_2 |= SDHCI_CTRL_UHS_SDR104 | SDHCI_CTRL_VDD_180; 218 ctrl_2 |= SDHCI_CTRL_UHS_SDR104 | SDHCI_CTRL_VDD_180;
213 break; 219 break;
220 case MMC_TIMING_MMC_DDR52:
214 case MMC_TIMING_UHS_DDR50: 221 case MMC_TIMING_UHS_DDR50:
215 ctrl_2 |= SDHCI_CTRL_UHS_DDR50 | SDHCI_CTRL_VDD_180; 222 ctrl_2 |= SDHCI_CTRL_UHS_DDR50 | SDHCI_CTRL_VDD_180;
216 break; 223 break;
@@ -283,9 +290,7 @@ static int sdhci_pxav3_probe(struct platform_device *pdev)
283 struct sdhci_host *host = NULL; 290 struct sdhci_host *host = NULL;
284 struct sdhci_pxa *pxa = NULL; 291 struct sdhci_pxa *pxa = NULL;
285 const struct of_device_id *match; 292 const struct of_device_id *match;
286
287 int ret; 293 int ret;
288 struct clk *clk;
289 294
290 pxa = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_pxa), GFP_KERNEL); 295 pxa = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_pxa), GFP_KERNEL);
291 if (!pxa) 296 if (!pxa)
@@ -305,14 +310,20 @@ static int sdhci_pxav3_probe(struct platform_device *pdev)
305 pltfm_host = sdhci_priv(host); 310 pltfm_host = sdhci_priv(host);
306 pltfm_host->priv = pxa; 311 pltfm_host->priv = pxa;
307 312
308 clk = devm_clk_get(dev, NULL); 313 pxa->clk_io = devm_clk_get(dev, "io");
309 if (IS_ERR(clk)) { 314 if (IS_ERR(pxa->clk_io))
315 pxa->clk_io = devm_clk_get(dev, NULL);
316 if (IS_ERR(pxa->clk_io)) {
310 dev_err(dev, "failed to get io clock\n"); 317 dev_err(dev, "failed to get io clock\n");
311 ret = PTR_ERR(clk); 318 ret = PTR_ERR(pxa->clk_io);
312 goto err_clk_get; 319 goto err_clk_get;
313 } 320 }
314 pltfm_host->clk = clk; 321 pltfm_host->clk = pxa->clk_io;
315 clk_prepare_enable(clk); 322 clk_prepare_enable(pxa->clk_io);
323
324 pxa->clk_core = devm_clk_get(dev, "core");
325 if (!IS_ERR(pxa->clk_core))
326 clk_prepare_enable(pxa->clk_core);
316 327
317 /* enable 1/8V DDR capable */ 328 /* enable 1/8V DDR capable */
318 host->mmc->caps |= MMC_CAP_1_8V_DDR; 329 host->mmc->caps |= MMC_CAP_1_8V_DDR;
@@ -385,7 +396,9 @@ err_add_host:
385 pm_runtime_disable(&pdev->dev); 396 pm_runtime_disable(&pdev->dev);
386err_of_parse: 397err_of_parse:
387err_cd_req: 398err_cd_req:
388 clk_disable_unprepare(clk); 399 clk_disable_unprepare(pxa->clk_io);
400 if (!IS_ERR(pxa->clk_core))
401 clk_disable_unprepare(pxa->clk_core);
389err_clk_get: 402err_clk_get:
390err_mbus_win: 403err_mbus_win:
391 sdhci_pltfm_free(pdev); 404 sdhci_pltfm_free(pdev);
@@ -396,12 +409,15 @@ static int sdhci_pxav3_remove(struct platform_device *pdev)
396{ 409{
397 struct sdhci_host *host = platform_get_drvdata(pdev); 410 struct sdhci_host *host = platform_get_drvdata(pdev);
398 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 411 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
412 struct sdhci_pxa *pxa = pltfm_host->priv;
399 413
400 pm_runtime_get_sync(&pdev->dev); 414 pm_runtime_get_sync(&pdev->dev);
401 sdhci_remove_host(host, 1); 415 sdhci_remove_host(host, 1);
402 pm_runtime_disable(&pdev->dev); 416 pm_runtime_disable(&pdev->dev);
403 417
404 clk_disable_unprepare(pltfm_host->clk); 418 clk_disable_unprepare(pxa->clk_io);
419 if (!IS_ERR(pxa->clk_core))
420 clk_disable_unprepare(pxa->clk_core);
405 421
406 sdhci_pltfm_free(pdev); 422 sdhci_pltfm_free(pdev);
407 423
@@ -441,15 +457,16 @@ static int sdhci_pxav3_runtime_suspend(struct device *dev)
441{ 457{
442 struct sdhci_host *host = dev_get_drvdata(dev); 458 struct sdhci_host *host = dev_get_drvdata(dev);
443 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 459 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
460 struct sdhci_pxa *pxa = pltfm_host->priv;
444 unsigned long flags; 461 unsigned long flags;
445 462
446 if (pltfm_host->clk) { 463 spin_lock_irqsave(&host->lock, flags);
447 spin_lock_irqsave(&host->lock, flags); 464 host->runtime_suspended = true;
448 host->runtime_suspended = true; 465 spin_unlock_irqrestore(&host->lock, flags);
449 spin_unlock_irqrestore(&host->lock, flags);
450 466
451 clk_disable_unprepare(pltfm_host->clk); 467 clk_disable_unprepare(pxa->clk_io);
452 } 468 if (!IS_ERR(pxa->clk_core))
469 clk_disable_unprepare(pxa->clk_core);
453 470
454 return 0; 471 return 0;
455} 472}
@@ -458,15 +475,16 @@ static int sdhci_pxav3_runtime_resume(struct device *dev)
458{ 475{
459 struct sdhci_host *host = dev_get_drvdata(dev); 476 struct sdhci_host *host = dev_get_drvdata(dev);
460 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); 477 struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
478 struct sdhci_pxa *pxa = pltfm_host->priv;
461 unsigned long flags; 479 unsigned long flags;
462 480
463 if (pltfm_host->clk) { 481 clk_prepare_enable(pxa->clk_io);
464 clk_prepare_enable(pltfm_host->clk); 482 if (!IS_ERR(pxa->clk_core))
483 clk_prepare_enable(pxa->clk_core);
465 484
466 spin_lock_irqsave(&host->lock, flags); 485 spin_lock_irqsave(&host->lock, flags);
467 host->runtime_suspended = false; 486 host->runtime_suspended = false;
468 spin_unlock_irqrestore(&host->lock, flags); 487 spin_unlock_irqrestore(&host->lock, flags);
469 }
470 488
471 return 0; 489 return 0;
472} 490}
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 0ce6eb17deaf..4f7a63213b33 100644
--- a/drivers/mmc/host/sdhci-s3c.c
+++ b/drivers/mmc/host/sdhci-s3c.c
@@ -300,6 +300,7 @@ static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock)
300 struct device *dev = &ourhost->pdev->dev; 300 struct device *dev = &ourhost->pdev->dev;
301 unsigned long timeout; 301 unsigned long timeout;
302 u16 clk = 0; 302 u16 clk = 0;
303 int ret;
303 304
304 host->mmc->actual_clock = 0; 305 host->mmc->actual_clock = 0;
305 306
@@ -311,7 +312,12 @@ static void sdhci_cmu_set_clock(struct sdhci_host *host, unsigned int clock)
311 312
312 sdhci_s3c_set_clock(host, clock); 313 sdhci_s3c_set_clock(host, clock);
313 314
314 clk_set_rate(ourhost->clk_bus[ourhost->cur_clk], clock); 315 ret = clk_set_rate(ourhost->clk_bus[ourhost->cur_clk], clock);
316 if (ret != 0) {
317 dev_err(dev, "%s: failed to set clock rate %uHz\n",
318 mmc_hostname(host->mmc), clock);
319 return;
320 }
315 321
316 clk = SDHCI_CLOCK_INT_EN; 322 clk = SDHCI_CLOCK_INT_EN;
317 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); 323 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index ada1a3ea3a87..73de62a58d70 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -44,8 +44,6 @@
44 44
45#define MAX_TUNING_LOOP 40 45#define MAX_TUNING_LOOP 40
46 46
47#define ADMA_SIZE ((128 * 2 + 1) * 4)
48
49static unsigned int debug_quirks = 0; 47static unsigned int debug_quirks = 0;
50static unsigned int debug_quirks2; 48static unsigned int debug_quirks2;
51 49
@@ -119,10 +117,17 @@ static void sdhci_dumpregs(struct sdhci_host *host)
119 pr_debug(DRIVER_NAME ": Host ctl2: 0x%08x\n", 117 pr_debug(DRIVER_NAME ": Host ctl2: 0x%08x\n",
120 sdhci_readw(host, SDHCI_HOST_CONTROL2)); 118 sdhci_readw(host, SDHCI_HOST_CONTROL2));
121 119
122 if (host->flags & SDHCI_USE_ADMA) 120 if (host->flags & SDHCI_USE_ADMA) {
123 pr_debug(DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n", 121 if (host->flags & SDHCI_USE_64_BIT_DMA)
124 readl(host->ioaddr + SDHCI_ADMA_ERROR), 122 pr_debug(DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x%08x\n",
125 readl(host->ioaddr + SDHCI_ADMA_ADDRESS)); 123 readl(host->ioaddr + SDHCI_ADMA_ERROR),
124 readl(host->ioaddr + SDHCI_ADMA_ADDRESS_HI),
125 readl(host->ioaddr + SDHCI_ADMA_ADDRESS));
126 else
127 pr_debug(DRIVER_NAME ": ADMA Err: 0x%08x | ADMA Ptr: 0x%08x\n",
128 readl(host->ioaddr + SDHCI_ADMA_ERROR),
129 readl(host->ioaddr + SDHCI_ADMA_ADDRESS));
130 }
126 131
127 pr_debug(DRIVER_NAME ": ===========================================\n"); 132 pr_debug(DRIVER_NAME ": ===========================================\n");
128} 133}
@@ -448,18 +453,26 @@ static void sdhci_kunmap_atomic(void *buffer, unsigned long *flags)
448 local_irq_restore(*flags); 453 local_irq_restore(*flags);
449} 454}
450 455
451static void sdhci_set_adma_desc(u8 *desc, u32 addr, int len, unsigned cmd) 456static void sdhci_adma_write_desc(struct sdhci_host *host, void *desc,
457 dma_addr_t addr, int len, unsigned cmd)
452{ 458{
453 __le32 *dataddr = (__le32 __force *)(desc + 4); 459 struct sdhci_adma2_64_desc *dma_desc = desc;
454 __le16 *cmdlen = (__le16 __force *)desc; 460
461 /* 32-bit and 64-bit descriptors have these members in same position */
462 dma_desc->cmd = cpu_to_le16(cmd);
463 dma_desc->len = cpu_to_le16(len);
464 dma_desc->addr_lo = cpu_to_le32((u32)addr);
455 465
456 /* SDHCI specification says ADMA descriptors should be 4 byte 466 if (host->flags & SDHCI_USE_64_BIT_DMA)
457 * aligned, so using 16 or 32bit operations should be safe. */ 467 dma_desc->addr_hi = cpu_to_le32((u64)addr >> 32);
468}
458 469
459 cmdlen[0] = cpu_to_le16(cmd); 470static void sdhci_adma_mark_end(void *desc)
460 cmdlen[1] = cpu_to_le16(len); 471{
472 struct sdhci_adma2_64_desc *dma_desc = desc;
461 473
462 dataddr[0] = cpu_to_le32(addr); 474 /* 32-bit and 64-bit descriptors have 'cmd' in same position */
475 dma_desc->cmd |= cpu_to_le16(ADMA2_END);
463} 476}
464 477
465static int sdhci_adma_table_pre(struct sdhci_host *host, 478static int sdhci_adma_table_pre(struct sdhci_host *host,
@@ -467,8 +480,8 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
467{ 480{
468 int direction; 481 int direction;
469 482
470 u8 *desc; 483 void *desc;
471 u8 *align; 484 void *align;
472 dma_addr_t addr; 485 dma_addr_t addr;
473 dma_addr_t align_addr; 486 dma_addr_t align_addr;
474 int len, offset; 487 int len, offset;
@@ -489,17 +502,17 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
489 direction = DMA_TO_DEVICE; 502 direction = DMA_TO_DEVICE;
490 503
491 host->align_addr = dma_map_single(mmc_dev(host->mmc), 504 host->align_addr = dma_map_single(mmc_dev(host->mmc),
492 host->align_buffer, 128 * 4, direction); 505 host->align_buffer, host->align_buffer_sz, direction);
493 if (dma_mapping_error(mmc_dev(host->mmc), host->align_addr)) 506 if (dma_mapping_error(mmc_dev(host->mmc), host->align_addr))
494 goto fail; 507 goto fail;
495 BUG_ON(host->align_addr & 0x3); 508 BUG_ON(host->align_addr & host->align_mask);
496 509
497 host->sg_count = dma_map_sg(mmc_dev(host->mmc), 510 host->sg_count = dma_map_sg(mmc_dev(host->mmc),
498 data->sg, data->sg_len, direction); 511 data->sg, data->sg_len, direction);
499 if (host->sg_count == 0) 512 if (host->sg_count == 0)
500 goto unmap_align; 513 goto unmap_align;
501 514
502 desc = host->adma_desc; 515 desc = host->adma_table;
503 align = host->align_buffer; 516 align = host->align_buffer;
504 517
505 align_addr = host->align_addr; 518 align_addr = host->align_addr;
@@ -515,24 +528,27 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
515 * the (up to three) bytes that screw up the 528 * the (up to three) bytes that screw up the
516 * alignment. 529 * alignment.
517 */ 530 */
518 offset = (4 - (addr & 0x3)) & 0x3; 531 offset = (host->align_sz - (addr & host->align_mask)) &
532 host->align_mask;
519 if (offset) { 533 if (offset) {
520 if (data->flags & MMC_DATA_WRITE) { 534 if (data->flags & MMC_DATA_WRITE) {
521 buffer = sdhci_kmap_atomic(sg, &flags); 535 buffer = sdhci_kmap_atomic(sg, &flags);
522 WARN_ON(((long)buffer & PAGE_MASK) > (PAGE_SIZE - 3)); 536 WARN_ON(((long)buffer & (PAGE_SIZE - 1)) >
537 (PAGE_SIZE - offset));
523 memcpy(align, buffer, offset); 538 memcpy(align, buffer, offset);
524 sdhci_kunmap_atomic(buffer, &flags); 539 sdhci_kunmap_atomic(buffer, &flags);
525 } 540 }
526 541
527 /* tran, valid */ 542 /* tran, valid */
528 sdhci_set_adma_desc(desc, align_addr, offset, 0x21); 543 sdhci_adma_write_desc(host, desc, align_addr, offset,
544 ADMA2_TRAN_VALID);
529 545
530 BUG_ON(offset > 65536); 546 BUG_ON(offset > 65536);
531 547
532 align += 4; 548 align += host->align_sz;
533 align_addr += 4; 549 align_addr += host->align_sz;
534 550
535 desc += 8; 551 desc += host->desc_sz;
536 552
537 addr += offset; 553 addr += offset;
538 len -= offset; 554 len -= offset;
@@ -541,23 +557,23 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
541 BUG_ON(len > 65536); 557 BUG_ON(len > 65536);
542 558
543 /* tran, valid */ 559 /* tran, valid */
544 sdhci_set_adma_desc(desc, addr, len, 0x21); 560 sdhci_adma_write_desc(host, desc, addr, len, ADMA2_TRAN_VALID);
545 desc += 8; 561 desc += host->desc_sz;
546 562
547 /* 563 /*
548 * If this triggers then we have a calculation bug 564 * If this triggers then we have a calculation bug
549 * somewhere. :/ 565 * somewhere. :/
550 */ 566 */
551 WARN_ON((desc - host->adma_desc) > ADMA_SIZE); 567 WARN_ON((desc - host->adma_table) >= host->adma_table_sz);
552 } 568 }
553 569
554 if (host->quirks & SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC) { 570 if (host->quirks & SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC) {
555 /* 571 /*
556 * Mark the last descriptor as the terminating descriptor 572 * Mark the last descriptor as the terminating descriptor
557 */ 573 */
558 if (desc != host->adma_desc) { 574 if (desc != host->adma_table) {
559 desc -= 8; 575 desc -= host->desc_sz;
560 desc[0] |= 0x2; /* end */ 576 sdhci_adma_mark_end(desc);
561 } 577 }
562 } else { 578 } else {
563 /* 579 /*
@@ -565,7 +581,7 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
565 */ 581 */
566 582
567 /* nop, end, valid */ 583 /* nop, end, valid */
568 sdhci_set_adma_desc(desc, 0, 0, 0x3); 584 sdhci_adma_write_desc(host, desc, 0, 0, ADMA2_NOP_END_VALID);
569 } 585 }
570 586
571 /* 587 /*
@@ -573,14 +589,14 @@ static int sdhci_adma_table_pre(struct sdhci_host *host,
573 */ 589 */
574 if (data->flags & MMC_DATA_WRITE) { 590 if (data->flags & MMC_DATA_WRITE) {
575 dma_sync_single_for_device(mmc_dev(host->mmc), 591 dma_sync_single_for_device(mmc_dev(host->mmc),
576 host->align_addr, 128 * 4, direction); 592 host->align_addr, host->align_buffer_sz, direction);
577 } 593 }
578 594
579 return 0; 595 return 0;
580 596
581unmap_align: 597unmap_align:
582 dma_unmap_single(mmc_dev(host->mmc), host->align_addr, 598 dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
583 128 * 4, direction); 599 host->align_buffer_sz, direction);
584fail: 600fail:
585 return -EINVAL; 601 return -EINVAL;
586} 602}
@@ -592,7 +608,7 @@ static void sdhci_adma_table_post(struct sdhci_host *host,
592 608
593 struct scatterlist *sg; 609 struct scatterlist *sg;
594 int i, size; 610 int i, size;
595 u8 *align; 611 void *align;
596 char *buffer; 612 char *buffer;
597 unsigned long flags; 613 unsigned long flags;
598 bool has_unaligned; 614 bool has_unaligned;
@@ -603,12 +619,12 @@ static void sdhci_adma_table_post(struct sdhci_host *host,
603 direction = DMA_TO_DEVICE; 619 direction = DMA_TO_DEVICE;
604 620
605 dma_unmap_single(mmc_dev(host->mmc), host->align_addr, 621 dma_unmap_single(mmc_dev(host->mmc), host->align_addr,
606 128 * 4, direction); 622 host->align_buffer_sz, direction);
607 623
608 /* Do a quick scan of the SG list for any unaligned mappings */ 624 /* Do a quick scan of the SG list for any unaligned mappings */
609 has_unaligned = false; 625 has_unaligned = false;
610 for_each_sg(data->sg, sg, host->sg_count, i) 626 for_each_sg(data->sg, sg, host->sg_count, i)
611 if (sg_dma_address(sg) & 3) { 627 if (sg_dma_address(sg) & host->align_mask) {
612 has_unaligned = true; 628 has_unaligned = true;
613 break; 629 break;
614 } 630 }
@@ -620,15 +636,17 @@ static void sdhci_adma_table_post(struct sdhci_host *host,
620 align = host->align_buffer; 636 align = host->align_buffer;
621 637
622 for_each_sg(data->sg, sg, host->sg_count, i) { 638 for_each_sg(data->sg, sg, host->sg_count, i) {
623 if (sg_dma_address(sg) & 0x3) { 639 if (sg_dma_address(sg) & host->align_mask) {
624 size = 4 - (sg_dma_address(sg) & 0x3); 640 size = host->align_sz -
641 (sg_dma_address(sg) & host->align_mask);
625 642
626 buffer = sdhci_kmap_atomic(sg, &flags); 643 buffer = sdhci_kmap_atomic(sg, &flags);
627 WARN_ON(((long)buffer & PAGE_MASK) > (PAGE_SIZE - 3)); 644 WARN_ON(((long)buffer & (PAGE_SIZE - 1)) >
645 (PAGE_SIZE - size));
628 memcpy(buffer, align, size); 646 memcpy(buffer, align, size);
629 sdhci_kunmap_atomic(buffer, &flags); 647 sdhci_kunmap_atomic(buffer, &flags);
630 648
631 align += 4; 649 align += host->align_sz;
632 } 650 }
633 } 651 }
634 } 652 }
@@ -822,6 +840,10 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
822 } else { 840 } else {
823 sdhci_writel(host, host->adma_addr, 841 sdhci_writel(host, host->adma_addr,
824 SDHCI_ADMA_ADDRESS); 842 SDHCI_ADMA_ADDRESS);
843 if (host->flags & SDHCI_USE_64_BIT_DMA)
844 sdhci_writel(host,
845 (u64)host->adma_addr >> 32,
846 SDHCI_ADMA_ADDRESS_HI);
825 } 847 }
826 } else { 848 } else {
827 int sg_cnt; 849 int sg_cnt;
@@ -855,10 +877,14 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
855 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); 877 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
856 ctrl &= ~SDHCI_CTRL_DMA_MASK; 878 ctrl &= ~SDHCI_CTRL_DMA_MASK;
857 if ((host->flags & SDHCI_REQ_USE_DMA) && 879 if ((host->flags & SDHCI_REQ_USE_DMA) &&
858 (host->flags & SDHCI_USE_ADMA)) 880 (host->flags & SDHCI_USE_ADMA)) {
859 ctrl |= SDHCI_CTRL_ADMA32; 881 if (host->flags & SDHCI_USE_64_BIT_DMA)
860 else 882 ctrl |= SDHCI_CTRL_ADMA64;
883 else
884 ctrl |= SDHCI_CTRL_ADMA32;
885 } else {
861 ctrl |= SDHCI_CTRL_SDMA; 886 ctrl |= SDHCI_CTRL_SDMA;
887 }
862 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); 888 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
863 } 889 }
864 890
@@ -889,10 +915,15 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,
889 struct mmc_data *data = cmd->data; 915 struct mmc_data *data = cmd->data;
890 916
891 if (data == NULL) { 917 if (data == NULL) {
918 if (host->quirks2 &
919 SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD) {
920 sdhci_writew(host, 0x0, SDHCI_TRANSFER_MODE);
921 } else {
892 /* clear Auto CMD settings for no data CMDs */ 922 /* clear Auto CMD settings for no data CMDs */
893 mode = sdhci_readw(host, SDHCI_TRANSFER_MODE); 923 mode = sdhci_readw(host, SDHCI_TRANSFER_MODE);
894 sdhci_writew(host, mode & ~(SDHCI_TRNS_AUTO_CMD12 | 924 sdhci_writew(host, mode & ~(SDHCI_TRNS_AUTO_CMD12 |
895 SDHCI_TRNS_AUTO_CMD23), SDHCI_TRANSFER_MODE); 925 SDHCI_TRNS_AUTO_CMD23), SDHCI_TRANSFER_MODE);
926 }
896 return; 927 return;
897 } 928 }
898 929
@@ -1117,6 +1148,9 @@ static u16 sdhci_get_preset_value(struct sdhci_host *host)
1117 case MMC_TIMING_UHS_DDR50: 1148 case MMC_TIMING_UHS_DDR50:
1118 preset = sdhci_readw(host, SDHCI_PRESET_FOR_DDR50); 1149 preset = sdhci_readw(host, SDHCI_PRESET_FOR_DDR50);
1119 break; 1150 break;
1151 case MMC_TIMING_MMC_HS400:
1152 preset = sdhci_readw(host, SDHCI_PRESET_FOR_HS400);
1153 break;
1120 default: 1154 default:
1121 pr_warn("%s: Invalid UHS-I mode selected\n", 1155 pr_warn("%s: Invalid UHS-I mode selected\n",
1122 mmc_hostname(host->mmc)); 1156 mmc_hostname(host->mmc));
@@ -1444,6 +1478,8 @@ void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing)
1444 else if ((timing == MMC_TIMING_UHS_DDR50) || 1478 else if ((timing == MMC_TIMING_UHS_DDR50) ||
1445 (timing == MMC_TIMING_MMC_DDR52)) 1479 (timing == MMC_TIMING_MMC_DDR52))
1446 ctrl_2 |= SDHCI_CTRL_UHS_DDR50; 1480 ctrl_2 |= SDHCI_CTRL_UHS_DDR50;
1481 else if (timing == MMC_TIMING_MMC_HS400)
1482 ctrl_2 |= SDHCI_CTRL_HS400; /* Non-standard */
1447 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); 1483 sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2);
1448} 1484}
1449EXPORT_SYMBOL_GPL(sdhci_set_uhs_signaling); 1485EXPORT_SYMBOL_GPL(sdhci_set_uhs_signaling);
@@ -1515,7 +1551,8 @@ static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
1515 u16 clk, ctrl_2; 1551 u16 clk, ctrl_2;
1516 1552
1517 /* In case of UHS-I modes, set High Speed Enable */ 1553 /* In case of UHS-I modes, set High Speed Enable */
1518 if ((ios->timing == MMC_TIMING_MMC_HS200) || 1554 if ((ios->timing == MMC_TIMING_MMC_HS400) ||
1555 (ios->timing == MMC_TIMING_MMC_HS200) ||
1519 (ios->timing == MMC_TIMING_MMC_DDR52) || 1556 (ios->timing == MMC_TIMING_MMC_DDR52) ||
1520 (ios->timing == MMC_TIMING_UHS_SDR50) || 1557 (ios->timing == MMC_TIMING_UHS_SDR50) ||
1521 (ios->timing == MMC_TIMING_UHS_SDR104) || 1558 (ios->timing == MMC_TIMING_UHS_SDR104) ||
@@ -1862,6 +1899,7 @@ static int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
1862 * tuning function has to be executed. 1899 * tuning function has to be executed.
1863 */ 1900 */
1864 switch (host->timing) { 1901 switch (host->timing) {
1902 case MMC_TIMING_MMC_HS400:
1865 case MMC_TIMING_MMC_HS200: 1903 case MMC_TIMING_MMC_HS200:
1866 case MMC_TIMING_UHS_SDR104: 1904 case MMC_TIMING_UHS_SDR104:
1867 break; 1905 break;
@@ -2144,9 +2182,10 @@ static void sdhci_tasklet_finish(unsigned long param)
2144 */ 2182 */
2145 if (!(host->flags & SDHCI_DEVICE_DEAD) && 2183 if (!(host->flags & SDHCI_DEVICE_DEAD) &&
2146 ((mrq->cmd && mrq->cmd->error) || 2184 ((mrq->cmd && mrq->cmd->error) ||
2147 (mrq->data && (mrq->data->error || 2185 (mrq->sbc && mrq->sbc->error) ||
2148 (mrq->data->stop && mrq->data->stop->error))) || 2186 (mrq->data && ((mrq->data->error && !mrq->data->stop) ||
2149 (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))) { 2187 (mrq->data->stop && mrq->data->stop->error))) ||
2188 (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))) {
2150 2189
2151 /* Some controllers need this kick or reset won't work here */ 2190 /* Some controllers need this kick or reset won't work here */
2152 if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET) 2191 if (host->quirks & SDHCI_QUIRK_CLOCK_BEFORE_RESET)
@@ -2282,32 +2321,36 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask, u32 *mask)
2282} 2321}
2283 2322
2284#ifdef CONFIG_MMC_DEBUG 2323#ifdef CONFIG_MMC_DEBUG
2285static void sdhci_show_adma_error(struct sdhci_host *host) 2324static void sdhci_adma_show_error(struct sdhci_host *host)
2286{ 2325{
2287 const char *name = mmc_hostname(host->mmc); 2326 const char *name = mmc_hostname(host->mmc);
2288 u8 *desc = host->adma_desc; 2327 void *desc = host->adma_table;
2289 __le32 *dma;
2290 __le16 *len;
2291 u8 attr;
2292 2328
2293 sdhci_dumpregs(host); 2329 sdhci_dumpregs(host);
2294 2330
2295 while (true) { 2331 while (true) {
2296 dma = (__le32 *)(desc + 4); 2332 struct sdhci_adma2_64_desc *dma_desc = desc;
2297 len = (__le16 *)(desc + 2); 2333
2298 attr = *desc; 2334 if (host->flags & SDHCI_USE_64_BIT_DMA)
2299 2335 DBG("%s: %p: DMA 0x%08x%08x, LEN 0x%04x, Attr=0x%02x\n",
2300 DBG("%s: %p: DMA 0x%08x, LEN 0x%04x, Attr=0x%02x\n", 2336 name, desc, le32_to_cpu(dma_desc->addr_hi),
2301 name, desc, le32_to_cpu(*dma), le16_to_cpu(*len), attr); 2337 le32_to_cpu(dma_desc->addr_lo),
2338 le16_to_cpu(dma_desc->len),
2339 le16_to_cpu(dma_desc->cmd));
2340 else
2341 DBG("%s: %p: DMA 0x%08x, LEN 0x%04x, Attr=0x%02x\n",
2342 name, desc, le32_to_cpu(dma_desc->addr_lo),
2343 le16_to_cpu(dma_desc->len),
2344 le16_to_cpu(dma_desc->cmd));
2302 2345
2303 desc += 8; 2346 desc += host->desc_sz;
2304 2347
2305 if (attr & 2) 2348 if (dma_desc->cmd & cpu_to_le16(ADMA2_END))
2306 break; 2349 break;
2307 } 2350 }
2308} 2351}
2309#else 2352#else
2310static void sdhci_show_adma_error(struct sdhci_host *host) { } 2353static void sdhci_adma_show_error(struct sdhci_host *host) { }
2311#endif 2354#endif
2312 2355
2313static void sdhci_data_irq(struct sdhci_host *host, u32 intmask) 2356static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
@@ -2370,7 +2413,7 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
2370 host->data->error = -EILSEQ; 2413 host->data->error = -EILSEQ;
2371 else if (intmask & SDHCI_INT_ADMA_ERROR) { 2414 else if (intmask & SDHCI_INT_ADMA_ERROR) {
2372 pr_err("%s: ADMA error\n", mmc_hostname(host->mmc)); 2415 pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
2373 sdhci_show_adma_error(host); 2416 sdhci_adma_show_error(host);
2374 host->data->error = -EIO; 2417 host->data->error = -EIO;
2375 if (host->ops->adma_workaround) 2418 if (host->ops->adma_workaround)
2376 host->ops->adma_workaround(host, intmask); 2419 host->ops->adma_workaround(host, intmask);
@@ -2849,6 +2892,16 @@ int sdhci_add_host(struct sdhci_host *host)
2849 host->flags &= ~SDHCI_USE_ADMA; 2892 host->flags &= ~SDHCI_USE_ADMA;
2850 } 2893 }
2851 2894
2895 /*
2896 * It is assumed that a 64-bit capable device has set a 64-bit DMA mask
2897 * and *must* do 64-bit DMA. A driver has the opportunity to change
2898 * that during the first call to ->enable_dma(). Similarly
2899 * SDHCI_QUIRK2_BROKEN_64_BIT_DMA must be left to the drivers to
2900 * implement.
2901 */
2902 if (sdhci_readl(host, SDHCI_CAPABILITIES) & SDHCI_CAN_64BIT)
2903 host->flags |= SDHCI_USE_64_BIT_DMA;
2904
2852 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { 2905 if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
2853 if (host->ops->enable_dma) { 2906 if (host->ops->enable_dma) {
2854 if (host->ops->enable_dma(host)) { 2907 if (host->ops->enable_dma(host)) {
@@ -2860,33 +2913,56 @@ int sdhci_add_host(struct sdhci_host *host)
2860 } 2913 }
2861 } 2914 }
2862 2915
2916 /* SDMA does not support 64-bit DMA */
2917 if (host->flags & SDHCI_USE_64_BIT_DMA)
2918 host->flags &= ~SDHCI_USE_SDMA;
2919
2863 if (host->flags & SDHCI_USE_ADMA) { 2920 if (host->flags & SDHCI_USE_ADMA) {
2864 /* 2921 /*
2865 * We need to allocate descriptors for all sg entries 2922 * The DMA descriptor table size is calculated as the maximum
2866 * (128) and potentially one alignment transfer for 2923 * number of segments times 2, to allow for an alignment
2867 * each of those entries. 2924 * descriptor for each segment, plus 1 for a nop end descriptor,
2925 * all multipled by the descriptor size.
2868 */ 2926 */
2869 host->adma_desc = dma_alloc_coherent(mmc_dev(mmc), 2927 if (host->flags & SDHCI_USE_64_BIT_DMA) {
2870 ADMA_SIZE, &host->adma_addr, 2928 host->adma_table_sz = (SDHCI_MAX_SEGS * 2 + 1) *
2871 GFP_KERNEL); 2929 SDHCI_ADMA2_64_DESC_SZ;
2872 host->align_buffer = kmalloc(128 * 4, GFP_KERNEL); 2930 host->align_buffer_sz = SDHCI_MAX_SEGS *
2873 if (!host->adma_desc || !host->align_buffer) { 2931 SDHCI_ADMA2_64_ALIGN;
2874 dma_free_coherent(mmc_dev(mmc), ADMA_SIZE, 2932 host->desc_sz = SDHCI_ADMA2_64_DESC_SZ;
2875 host->adma_desc, host->adma_addr); 2933 host->align_sz = SDHCI_ADMA2_64_ALIGN;
2934 host->align_mask = SDHCI_ADMA2_64_ALIGN - 1;
2935 } else {
2936 host->adma_table_sz = (SDHCI_MAX_SEGS * 2 + 1) *
2937 SDHCI_ADMA2_32_DESC_SZ;
2938 host->align_buffer_sz = SDHCI_MAX_SEGS *
2939 SDHCI_ADMA2_32_ALIGN;
2940 host->desc_sz = SDHCI_ADMA2_32_DESC_SZ;
2941 host->align_sz = SDHCI_ADMA2_32_ALIGN;
2942 host->align_mask = SDHCI_ADMA2_32_ALIGN - 1;
2943 }
2944 host->adma_table = dma_alloc_coherent(mmc_dev(mmc),
2945 host->adma_table_sz,
2946 &host->adma_addr,
2947 GFP_KERNEL);
2948 host->align_buffer = kmalloc(host->align_buffer_sz, GFP_KERNEL);
2949 if (!host->adma_table || !host->align_buffer) {
2950 dma_free_coherent(mmc_dev(mmc), host->adma_table_sz,
2951 host->adma_table, host->adma_addr);
2876 kfree(host->align_buffer); 2952 kfree(host->align_buffer);
2877 pr_warn("%s: Unable to allocate ADMA buffers - falling back to standard DMA\n", 2953 pr_warn("%s: Unable to allocate ADMA buffers - falling back to standard DMA\n",
2878 mmc_hostname(mmc)); 2954 mmc_hostname(mmc));
2879 host->flags &= ~SDHCI_USE_ADMA; 2955 host->flags &= ~SDHCI_USE_ADMA;
2880 host->adma_desc = NULL; 2956 host->adma_table = NULL;
2881 host->align_buffer = NULL; 2957 host->align_buffer = NULL;
2882 } else if (host->adma_addr & 3) { 2958 } else if (host->adma_addr & host->align_mask) {
2883 pr_warn("%s: unable to allocate aligned ADMA descriptor\n", 2959 pr_warn("%s: unable to allocate aligned ADMA descriptor\n",
2884 mmc_hostname(mmc)); 2960 mmc_hostname(mmc));
2885 host->flags &= ~SDHCI_USE_ADMA; 2961 host->flags &= ~SDHCI_USE_ADMA;
2886 dma_free_coherent(mmc_dev(mmc), ADMA_SIZE, 2962 dma_free_coherent(mmc_dev(mmc), host->adma_table_sz,
2887 host->adma_desc, host->adma_addr); 2963 host->adma_table, host->adma_addr);
2888 kfree(host->align_buffer); 2964 kfree(host->align_buffer);
2889 host->adma_desc = NULL; 2965 host->adma_table = NULL;
2890 host->align_buffer = NULL; 2966 host->align_buffer = NULL;
2891 } 2967 }
2892 } 2968 }
@@ -3027,7 +3103,7 @@ int sdhci_add_host(struct sdhci_host *host)
3027 if (ret) { 3103 if (ret) {
3028 pr_warn("%s: Failed to enable vqmmc regulator: %d\n", 3104 pr_warn("%s: Failed to enable vqmmc regulator: %d\n",
3029 mmc_hostname(mmc), ret); 3105 mmc_hostname(mmc), ret);
3030 mmc->supply.vqmmc = NULL; 3106 mmc->supply.vqmmc = ERR_PTR(-EINVAL);
3031 } 3107 }
3032 } 3108 }
3033 3109
@@ -3046,16 +3122,21 @@ int sdhci_add_host(struct sdhci_host *host)
3046 /* SD3.0: SDR104 is supported so (for eMMC) the caps2 3122 /* SD3.0: SDR104 is supported so (for eMMC) the caps2
3047 * field can be promoted to support HS200. 3123 * field can be promoted to support HS200.
3048 */ 3124 */
3049 if (!(host->quirks2 & SDHCI_QUIRK2_BROKEN_HS200)) { 3125 if (!(host->quirks2 & SDHCI_QUIRK2_BROKEN_HS200))
3050 mmc->caps2 |= MMC_CAP2_HS200; 3126 mmc->caps2 |= MMC_CAP2_HS200;
3051 if (IS_ERR(mmc->supply.vqmmc) ||
3052 !regulator_is_supported_voltage
3053 (mmc->supply.vqmmc, 1100000, 1300000))
3054 mmc->caps2 &= ~MMC_CAP2_HS200_1_2V_SDR;
3055 }
3056 } else if (caps[1] & SDHCI_SUPPORT_SDR50) 3127 } else if (caps[1] & SDHCI_SUPPORT_SDR50)
3057 mmc->caps |= MMC_CAP_UHS_SDR50; 3128 mmc->caps |= MMC_CAP_UHS_SDR50;
3058 3129
3130 if (host->quirks2 & SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 &&
3131 (caps[1] & SDHCI_SUPPORT_HS400))
3132 mmc->caps2 |= MMC_CAP2_HS400;
3133
3134 if ((mmc->caps2 & MMC_CAP2_HSX00_1_2V) &&
3135 (IS_ERR(mmc->supply.vqmmc) ||
3136 !regulator_is_supported_voltage(mmc->supply.vqmmc, 1100000,
3137 1300000)))
3138 mmc->caps2 &= ~MMC_CAP2_HSX00_1_2V;
3139
3059 if ((caps[1] & SDHCI_SUPPORT_DDR50) && 3140 if ((caps[1] & SDHCI_SUPPORT_DDR50) &&
3060 !(host->quirks2 & SDHCI_QUIRK2_BROKEN_DDR50)) 3141 !(host->quirks2 & SDHCI_QUIRK2_BROKEN_DDR50))
3061 mmc->caps |= MMC_CAP_UHS_DDR50; 3142 mmc->caps |= MMC_CAP_UHS_DDR50;
@@ -3175,11 +3256,11 @@ int sdhci_add_host(struct sdhci_host *host)
3175 * can do scatter/gather or not. 3256 * can do scatter/gather or not.
3176 */ 3257 */
3177 if (host->flags & SDHCI_USE_ADMA) 3258 if (host->flags & SDHCI_USE_ADMA)
3178 mmc->max_segs = 128; 3259 mmc->max_segs = SDHCI_MAX_SEGS;
3179 else if (host->flags & SDHCI_USE_SDMA) 3260 else if (host->flags & SDHCI_USE_SDMA)
3180 mmc->max_segs = 1; 3261 mmc->max_segs = 1;
3181 else /* PIO */ 3262 else /* PIO */
3182 mmc->max_segs = 128; 3263 mmc->max_segs = SDHCI_MAX_SEGS;
3183 3264
3184 /* 3265 /*
3185 * Maximum number of sectors in one transfer. Limited by DMA boundary 3266 * Maximum number of sectors in one transfer. Limited by DMA boundary
@@ -3277,7 +3358,8 @@ int sdhci_add_host(struct sdhci_host *host)
3277 3358
3278 pr_info("%s: SDHCI controller on %s [%s] using %s\n", 3359 pr_info("%s: SDHCI controller on %s [%s] using %s\n",
3279 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)), 3360 mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
3280 (host->flags & SDHCI_USE_ADMA) ? "ADMA" : 3361 (host->flags & SDHCI_USE_ADMA) ?
3362 (host->flags & SDHCI_USE_64_BIT_DMA) ? "ADMA 64-bit" : "ADMA" :
3281 (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO"); 3363 (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
3282 3364
3283 sdhci_enable_card_detection(host); 3365 sdhci_enable_card_detection(host);
@@ -3339,18 +3421,15 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
3339 3421
3340 tasklet_kill(&host->finish_tasklet); 3422 tasklet_kill(&host->finish_tasklet);
3341 3423
3342 if (!IS_ERR(mmc->supply.vmmc))
3343 regulator_disable(mmc->supply.vmmc);
3344
3345 if (!IS_ERR(mmc->supply.vqmmc)) 3424 if (!IS_ERR(mmc->supply.vqmmc))
3346 regulator_disable(mmc->supply.vqmmc); 3425 regulator_disable(mmc->supply.vqmmc);
3347 3426
3348 if (host->adma_desc) 3427 if (host->adma_table)
3349 dma_free_coherent(mmc_dev(mmc), ADMA_SIZE, 3428 dma_free_coherent(mmc_dev(mmc), host->adma_table_sz,
3350 host->adma_desc, host->adma_addr); 3429 host->adma_table, host->adma_addr);
3351 kfree(host->align_buffer); 3430 kfree(host->align_buffer);
3352 3431
3353 host->adma_desc = NULL; 3432 host->adma_table = NULL;
3354 host->align_buffer = NULL; 3433 host->align_buffer = NULL;
3355} 3434}
3356 3435
diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h
index 31896a779d4e..ddd31cda2370 100644
--- a/drivers/mmc/host/sdhci.h
+++ b/drivers/mmc/host/sdhci.h
@@ -161,7 +161,7 @@
161#define SDHCI_CTRL_UHS_SDR50 0x0002 161#define SDHCI_CTRL_UHS_SDR50 0x0002
162#define SDHCI_CTRL_UHS_SDR104 0x0003 162#define SDHCI_CTRL_UHS_SDR104 0x0003
163#define SDHCI_CTRL_UHS_DDR50 0x0004 163#define SDHCI_CTRL_UHS_DDR50 0x0004
164#define SDHCI_CTRL_HS_SDR200 0x0005 /* reserved value in SDIO spec */ 164#define SDHCI_CTRL_HS400 0x0005 /* Non-standard */
165#define SDHCI_CTRL_VDD_180 0x0008 165#define SDHCI_CTRL_VDD_180 0x0008
166#define SDHCI_CTRL_DRV_TYPE_MASK 0x0030 166#define SDHCI_CTRL_DRV_TYPE_MASK 0x0030
167#define SDHCI_CTRL_DRV_TYPE_B 0x0000 167#define SDHCI_CTRL_DRV_TYPE_B 0x0000
@@ -204,6 +204,7 @@
204#define SDHCI_RETUNING_MODE_SHIFT 14 204#define SDHCI_RETUNING_MODE_SHIFT 14
205#define SDHCI_CLOCK_MUL_MASK 0x00FF0000 205#define SDHCI_CLOCK_MUL_MASK 0x00FF0000
206#define SDHCI_CLOCK_MUL_SHIFT 16 206#define SDHCI_CLOCK_MUL_SHIFT 16
207#define SDHCI_SUPPORT_HS400 0x80000000 /* Non-standard */
207 208
208#define SDHCI_CAPABILITIES_1 0x44 209#define SDHCI_CAPABILITIES_1 0x44
209 210
@@ -227,6 +228,7 @@
227/* 55-57 reserved */ 228/* 55-57 reserved */
228 229
229#define SDHCI_ADMA_ADDRESS 0x58 230#define SDHCI_ADMA_ADDRESS 0x58
231#define SDHCI_ADMA_ADDRESS_HI 0x5C
230 232
231/* 60-FB reserved */ 233/* 60-FB reserved */
232 234
@@ -235,6 +237,7 @@
235#define SDHCI_PRESET_FOR_SDR50 0x6A 237#define SDHCI_PRESET_FOR_SDR50 0x6A
236#define SDHCI_PRESET_FOR_SDR104 0x6C 238#define SDHCI_PRESET_FOR_SDR104 0x6C
237#define SDHCI_PRESET_FOR_DDR50 0x6E 239#define SDHCI_PRESET_FOR_DDR50 0x6E
240#define SDHCI_PRESET_FOR_HS400 0x74 /* Non-standard */
238#define SDHCI_PRESET_DRV_MASK 0xC000 241#define SDHCI_PRESET_DRV_MASK 0xC000
239#define SDHCI_PRESET_DRV_SHIFT 14 242#define SDHCI_PRESET_DRV_SHIFT 14
240#define SDHCI_PRESET_CLKGEN_SEL_MASK 0x400 243#define SDHCI_PRESET_CLKGEN_SEL_MASK 0x400
@@ -266,6 +269,46 @@
266#define SDHCI_DEFAULT_BOUNDARY_SIZE (512 * 1024) 269#define SDHCI_DEFAULT_BOUNDARY_SIZE (512 * 1024)
267#define SDHCI_DEFAULT_BOUNDARY_ARG (ilog2(SDHCI_DEFAULT_BOUNDARY_SIZE) - 12) 270#define SDHCI_DEFAULT_BOUNDARY_ARG (ilog2(SDHCI_DEFAULT_BOUNDARY_SIZE) - 12)
268 271
272/* ADMA2 32-bit DMA descriptor size */
273#define SDHCI_ADMA2_32_DESC_SZ 8
274
275/* ADMA2 32-bit DMA alignment */
276#define SDHCI_ADMA2_32_ALIGN 4
277
278/* ADMA2 32-bit descriptor */
279struct sdhci_adma2_32_desc {
280 __le16 cmd;
281 __le16 len;
282 __le32 addr;
283} __packed __aligned(SDHCI_ADMA2_32_ALIGN);
284
285/* ADMA2 64-bit DMA descriptor size */
286#define SDHCI_ADMA2_64_DESC_SZ 12
287
288/* ADMA2 64-bit DMA alignment */
289#define SDHCI_ADMA2_64_ALIGN 8
290
291/*
292 * ADMA2 64-bit descriptor. Note 12-byte descriptor can't always be 8-byte
293 * aligned.
294 */
295struct sdhci_adma2_64_desc {
296 __le16 cmd;
297 __le16 len;
298 __le32 addr_lo;
299 __le32 addr_hi;
300} __packed __aligned(4);
301
302#define ADMA2_TRAN_VALID 0x21
303#define ADMA2_NOP_END_VALID 0x3
304#define ADMA2_END 0x2
305
306/*
307 * Maximum segments assuming a 512KiB maximum requisition size and a minimum
308 * 4KiB page size.
309 */
310#define SDHCI_MAX_SEGS 128
311
269struct sdhci_ops { 312struct sdhci_ops {
270#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS 313#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
271 u32 (*read_l)(struct sdhci_host *host, int reg); 314 u32 (*read_l)(struct sdhci_host *host, int reg);
diff --git a/drivers/mmc/host/sunxi-mmc.c b/drivers/mmc/host/sunxi-mmc.c
index d1663b3c4143..15cb8b7ffc34 100644
--- a/drivers/mmc/host/sunxi-mmc.c
+++ b/drivers/mmc/host/sunxi-mmc.c
@@ -21,7 +21,6 @@
21#include <linux/err.h> 21#include <linux/err.h>
22 22
23#include <linux/clk.h> 23#include <linux/clk.h>
24#include <linux/clk-private.h>
25#include <linux/clk/sunxi.h> 24#include <linux/clk/sunxi.h>
26 25
27#include <linux/gpio.h> 26#include <linux/gpio.h>
diff --git a/drivers/mmc/host/toshsd.c b/drivers/mmc/host/toshsd.c
new file mode 100644
index 000000000000..4666262edaca
--- /dev/null
+++ b/drivers/mmc/host/toshsd.c
@@ -0,0 +1,717 @@
1/*
2 * Toshiba PCI Secure Digital Host Controller Interface driver
3 *
4 * Copyright (C) 2014 Ondrej Zary
5 * Copyright (C) 2007 Richard Betts, All Rights Reserved.
6 *
7 * Based on asic3_mmc.c, copyright (c) 2005 SDG Systems, LLC and,
8 * sdhci.c, copyright (C) 2005-2006 Pierre Ossman
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or (at
13 * your option) any later version.
14 */
15
16#include <linux/delay.h>
17#include <linux/device.h>
18#include <linux/module.h>
19#include <linux/pci.h>
20#include <linux/scatterlist.h>
21#include <linux/interrupt.h>
22#include <linux/io.h>
23#include <linux/pm.h>
24#include <linux/mmc/host.h>
25#include <linux/mmc/mmc.h>
26
27#include "toshsd.h"
28
29#define DRIVER_NAME "toshsd"
30
31static const struct pci_device_id pci_ids[] = {
32 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA, 0x0805) },
33 { /* end: all zeroes */ },
34};
35
36MODULE_DEVICE_TABLE(pci, pci_ids);
37
38static void toshsd_init(struct toshsd_host *host)
39{
40 /* enable clock */
41 pci_write_config_byte(host->pdev, SD_PCICFG_CLKSTOP,
42 SD_PCICFG_CLKSTOP_ENABLE_ALL);
43 pci_write_config_byte(host->pdev, SD_PCICFG_CARDDETECT, 2);
44
45 /* reset */
46 iowrite16(0, host->ioaddr + SD_SOFTWARERESET); /* assert */
47 mdelay(2);
48 iowrite16(1, host->ioaddr + SD_SOFTWARERESET); /* deassert */
49 mdelay(2);
50
51 /* Clear card registers */
52 iowrite16(0, host->ioaddr + SD_CARDCLOCKCTRL);
53 iowrite32(0, host->ioaddr + SD_CARDSTATUS);
54 iowrite32(0, host->ioaddr + SD_ERRORSTATUS0);
55 iowrite16(0, host->ioaddr + SD_STOPINTERNAL);
56
57 /* SDIO clock? */
58 iowrite16(0x100, host->ioaddr + SDIO_BASE + SDIO_CLOCKNWAITCTRL);
59
60 /* enable LED */
61 pci_write_config_byte(host->pdev, SD_PCICFG_SDLED_ENABLE1,
62 SD_PCICFG_LED_ENABLE1_START);
63 pci_write_config_byte(host->pdev, SD_PCICFG_SDLED_ENABLE2,
64 SD_PCICFG_LED_ENABLE2_START);
65
66 /* set interrupt masks */
67 iowrite32(~(u32)(SD_CARD_RESP_END | SD_CARD_RW_END
68 | SD_CARD_CARD_REMOVED_0 | SD_CARD_CARD_INSERTED_0
69 | SD_BUF_READ_ENABLE | SD_BUF_WRITE_ENABLE
70 | SD_BUF_CMD_TIMEOUT),
71 host->ioaddr + SD_INTMASKCARD);
72
73 iowrite16(0x1000, host->ioaddr + SD_TRANSACTIONCTRL);
74}
75
76/* Set MMC clock / power.
77 * Note: This controller uses a simple divider scheme therefore it cannot run
78 * SD/MMC cards at full speed (24/20MHz). HCLK (=33MHz PCI clock?) is too high
79 * and the next slowest is 16MHz (div=2).
80 */
81static void __toshsd_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
82{
83 struct toshsd_host *host = mmc_priv(mmc);
84
85 if (ios->clock) {
86 u16 clk;
87 int div = 1;
88
89 while (ios->clock < HCLK / div)
90 div *= 2;
91
92 clk = div >> 2;
93
94 if (div == 1) { /* disable the divider */
95 pci_write_config_byte(host->pdev, SD_PCICFG_CLKMODE,
96 SD_PCICFG_CLKMODE_DIV_DISABLE);
97 clk |= SD_CARDCLK_DIV_DISABLE;
98 } else
99 pci_write_config_byte(host->pdev, SD_PCICFG_CLKMODE, 0);
100
101 clk |= SD_CARDCLK_ENABLE_CLOCK;
102 iowrite16(clk, host->ioaddr + SD_CARDCLOCKCTRL);
103
104 mdelay(10);
105 } else
106 iowrite16(0, host->ioaddr + SD_CARDCLOCKCTRL);
107
108 switch (ios->power_mode) {
109 case MMC_POWER_OFF:
110 pci_write_config_byte(host->pdev, SD_PCICFG_POWER1,
111 SD_PCICFG_PWR1_OFF);
112 mdelay(1);
113 break;
114 case MMC_POWER_UP:
115 break;
116 case MMC_POWER_ON:
117 pci_write_config_byte(host->pdev, SD_PCICFG_POWER1,
118 SD_PCICFG_PWR1_33V);
119 pci_write_config_byte(host->pdev, SD_PCICFG_POWER2,
120 SD_PCICFG_PWR2_AUTO);
121 mdelay(20);
122 break;
123 }
124
125 switch (ios->bus_width) {
126 case MMC_BUS_WIDTH_1:
127 iowrite16(SD_CARDOPT_REQUIRED | SD_CARDOPT_DATA_RESP_TIMEOUT(14)
128 | SD_CARDOPT_C2_MODULE_ABSENT
129 | SD_CARDOPT_DATA_XFR_WIDTH_1,
130 host->ioaddr + SD_CARDOPTIONSETUP);
131 break;
132 case MMC_BUS_WIDTH_4:
133 iowrite16(SD_CARDOPT_REQUIRED | SD_CARDOPT_DATA_RESP_TIMEOUT(14)
134 | SD_CARDOPT_C2_MODULE_ABSENT
135 | SD_CARDOPT_DATA_XFR_WIDTH_4,
136 host->ioaddr + SD_CARDOPTIONSETUP);
137 break;
138 }
139}
140
141static void toshsd_set_led(struct toshsd_host *host, unsigned char state)
142{
143 iowrite16(state, host->ioaddr + SDIO_BASE + SDIO_LEDCTRL);
144}
145
146static void toshsd_finish_request(struct toshsd_host *host)
147{
148 struct mmc_request *mrq = host->mrq;
149
150 /* Write something to end the command */
151 host->mrq = NULL;
152 host->cmd = NULL;
153 host->data = NULL;
154
155 toshsd_set_led(host, 0);
156 mmc_request_done(host->mmc, mrq);
157}
158
159static irqreturn_t toshsd_thread_irq(int irq, void *dev_id)
160{
161 struct toshsd_host *host = dev_id;
162 struct mmc_data *data = host->data;
163 struct sg_mapping_iter *sg_miter = &host->sg_miter;
164 unsigned short *buf;
165 int count;
166 unsigned long flags;
167
168 if (!data) {
169 dev_warn(&host->pdev->dev, "Spurious Data IRQ\n");
170 if (host->cmd) {
171 host->cmd->error = -EIO;
172 toshsd_finish_request(host);
173 }
174 return IRQ_NONE;
175 }
176 spin_lock_irqsave(&host->lock, flags);
177
178 if (!sg_miter_next(sg_miter))
179 return IRQ_HANDLED;
180 buf = sg_miter->addr;
181
182 /* Ensure we dont read more than one block. The chip will interrupt us
183 * When the next block is available.
184 */
185 count = sg_miter->length;
186 if (count > data->blksz)
187 count = data->blksz;
188
189 dev_dbg(&host->pdev->dev, "count: %08x, flags %08x\n", count,
190 data->flags);
191
192 /* Transfer the data */
193 if (data->flags & MMC_DATA_READ)
194 ioread32_rep(host->ioaddr + SD_DATAPORT, buf, count >> 2);
195 else
196 iowrite32_rep(host->ioaddr + SD_DATAPORT, buf, count >> 2);
197
198 sg_miter->consumed = count;
199 sg_miter_stop(sg_miter);
200
201 spin_unlock_irqrestore(&host->lock, flags);
202
203 return IRQ_HANDLED;
204}
205
206static void toshsd_cmd_irq(struct toshsd_host *host)
207{
208 struct mmc_command *cmd = host->cmd;
209 u8 *buf;
210 u16 data;
211
212 if (!host->cmd) {
213 dev_warn(&host->pdev->dev, "Spurious CMD irq\n");
214 return;
215 }
216 buf = (u8 *)cmd->resp;
217 host->cmd = NULL;
218
219 if (cmd->flags & MMC_RSP_PRESENT && cmd->flags & MMC_RSP_136) {
220 /* R2 */
221 buf[12] = 0xff;
222 data = ioread16(host->ioaddr + SD_RESPONSE0);
223 buf[13] = data & 0xff;
224 buf[14] = data >> 8;
225 data = ioread16(host->ioaddr + SD_RESPONSE1);
226 buf[15] = data & 0xff;
227 buf[8] = data >> 8;
228 data = ioread16(host->ioaddr + SD_RESPONSE2);
229 buf[9] = data & 0xff;
230 buf[10] = data >> 8;
231 data = ioread16(host->ioaddr + SD_RESPONSE3);
232 buf[11] = data & 0xff;
233 buf[4] = data >> 8;
234 data = ioread16(host->ioaddr + SD_RESPONSE4);
235 buf[5] = data & 0xff;
236 buf[6] = data >> 8;
237 data = ioread16(host->ioaddr + SD_RESPONSE5);
238 buf[7] = data & 0xff;
239 buf[0] = data >> 8;
240 data = ioread16(host->ioaddr + SD_RESPONSE6);
241 buf[1] = data & 0xff;
242 buf[2] = data >> 8;
243 data = ioread16(host->ioaddr + SD_RESPONSE7);
244 buf[3] = data & 0xff;
245 } else if (cmd->flags & MMC_RSP_PRESENT) {
246 /* R1, R1B, R3, R6, R7 */
247 data = ioread16(host->ioaddr + SD_RESPONSE0);
248 buf[0] = data & 0xff;
249 buf[1] = data >> 8;
250 data = ioread16(host->ioaddr + SD_RESPONSE1);
251 buf[2] = data & 0xff;
252 buf[3] = data >> 8;
253 }
254
255 dev_dbg(&host->pdev->dev, "Command IRQ complete %d %d %x\n",
256 cmd->opcode, cmd->error, cmd->flags);
257
258 /* If there is data to handle we will
259 * finish the request in the mmc_data_end_irq handler.*/
260 if (host->data)
261 return;
262
263 toshsd_finish_request(host);
264}
265
266static void toshsd_data_end_irq(struct toshsd_host *host)
267{
268 struct mmc_data *data = host->data;
269
270 host->data = NULL;
271
272 if (!data) {
273 dev_warn(&host->pdev->dev, "Spurious data end IRQ\n");
274 return;
275 }
276
277 if (data->error == 0)
278 data->bytes_xfered = data->blocks * data->blksz;
279 else
280 data->bytes_xfered = 0;
281
282 dev_dbg(&host->pdev->dev, "Completed data request xfr=%d\n",
283 data->bytes_xfered);
284
285 iowrite16(0, host->ioaddr + SD_STOPINTERNAL);
286
287 toshsd_finish_request(host);
288}
289
290static irqreturn_t toshsd_irq(int irq, void *dev_id)
291{
292 struct toshsd_host *host = dev_id;
293 u32 int_reg, int_mask, int_status, detail;
294 int error = 0, ret = IRQ_HANDLED;
295
296 spin_lock(&host->lock);
297 int_status = ioread32(host->ioaddr + SD_CARDSTATUS);
298 int_mask = ioread32(host->ioaddr + SD_INTMASKCARD);
299 int_reg = int_status & ~int_mask & ~IRQ_DONT_CARE_BITS;
300
301 dev_dbg(&host->pdev->dev, "IRQ status:%x mask:%x\n",
302 int_status, int_mask);
303
304 /* nothing to do: it's not our IRQ */
305 if (!int_reg) {
306 ret = IRQ_NONE;
307 goto irq_end;
308 }
309
310 if (int_reg & SD_BUF_CMD_TIMEOUT) {
311 error = -ETIMEDOUT;
312 dev_dbg(&host->pdev->dev, "Timeout\n");
313 } else if (int_reg & SD_BUF_CRC_ERR) {
314 error = -EILSEQ;
315 dev_err(&host->pdev->dev, "BadCRC\n");
316 } else if (int_reg & (SD_BUF_ILLEGAL_ACCESS
317 | SD_BUF_CMD_INDEX_ERR
318 | SD_BUF_STOP_BIT_END_ERR
319 | SD_BUF_OVERFLOW
320 | SD_BUF_UNDERFLOW
321 | SD_BUF_DATA_TIMEOUT)) {
322 dev_err(&host->pdev->dev, "Buffer status error: { %s%s%s%s%s%s}\n",
323 int_reg & SD_BUF_ILLEGAL_ACCESS ? "ILLEGAL_ACC " : "",
324 int_reg & SD_BUF_CMD_INDEX_ERR ? "CMD_INDEX " : "",
325 int_reg & SD_BUF_STOP_BIT_END_ERR ? "STOPBIT_END " : "",
326 int_reg & SD_BUF_OVERFLOW ? "OVERFLOW " : "",
327 int_reg & SD_BUF_UNDERFLOW ? "UNDERFLOW " : "",
328 int_reg & SD_BUF_DATA_TIMEOUT ? "DATA_TIMEOUT " : "");
329
330 detail = ioread32(host->ioaddr + SD_ERRORSTATUS0);
331 dev_err(&host->pdev->dev, "detail error status { %s%s%s%s%s%s%s%s%s%s%s%s%s}\n",
332 detail & SD_ERR0_RESP_CMD_ERR ? "RESP_CMD " : "",
333 detail & SD_ERR0_RESP_NON_CMD12_END_BIT_ERR ? "RESP_END_BIT " : "",
334 detail & SD_ERR0_RESP_CMD12_END_BIT_ERR ? "RESP_END_BIT " : "",
335 detail & SD_ERR0_READ_DATA_END_BIT_ERR ? "READ_DATA_END_BIT " : "",
336 detail & SD_ERR0_WRITE_CRC_STATUS_END_BIT_ERR ? "WRITE_CMD_END_BIT " : "",
337 detail & SD_ERR0_RESP_NON_CMD12_CRC_ERR ? "RESP_CRC " : "",
338 detail & SD_ERR0_RESP_CMD12_CRC_ERR ? "RESP_CRC " : "",
339 detail & SD_ERR0_READ_DATA_CRC_ERR ? "READ_DATA_CRC " : "",
340 detail & SD_ERR0_WRITE_CMD_CRC_ERR ? "WRITE_CMD_CRC " : "",
341 detail & SD_ERR1_NO_CMD_RESP ? "NO_CMD_RESP " : "",
342 detail & SD_ERR1_TIMEOUT_READ_DATA ? "READ_DATA_TIMEOUT " : "",
343 detail & SD_ERR1_TIMEOUT_CRS_STATUS ? "CRS_STATUS_TIMEOUT " : "",
344 detail & SD_ERR1_TIMEOUT_CRC_BUSY ? "CRC_BUSY_TIMEOUT " : "");
345 error = -EIO;
346 }
347
348 if (error) {
349 if (host->cmd)
350 host->cmd->error = error;
351
352 if (error == -ETIMEDOUT) {
353 iowrite32(int_status &
354 ~(SD_BUF_CMD_TIMEOUT | SD_CARD_RESP_END),
355 host->ioaddr + SD_CARDSTATUS);
356 } else {
357 toshsd_init(host);
358 __toshsd_set_ios(host->mmc, &host->mmc->ios);
359 goto irq_end;
360 }
361 }
362
363 /* Card insert/remove. The mmc controlling code is stateless. */
364 if (int_reg & (SD_CARD_CARD_INSERTED_0 | SD_CARD_CARD_REMOVED_0)) {
365 iowrite32(int_status &
366 ~(SD_CARD_CARD_REMOVED_0 | SD_CARD_CARD_INSERTED_0),
367 host->ioaddr + SD_CARDSTATUS);
368
369 if (int_reg & SD_CARD_CARD_INSERTED_0)
370 toshsd_init(host);
371
372 mmc_detect_change(host->mmc, 1);
373 }
374
375 /* Data transfer */
376 if (int_reg & (SD_BUF_READ_ENABLE | SD_BUF_WRITE_ENABLE)) {
377 iowrite32(int_status &
378 ~(SD_BUF_WRITE_ENABLE | SD_BUF_READ_ENABLE),
379 host->ioaddr + SD_CARDSTATUS);
380
381 ret = IRQ_WAKE_THREAD;
382 goto irq_end;
383 }
384
385 /* Command completion */
386 if (int_reg & SD_CARD_RESP_END) {
387 iowrite32(int_status & ~(SD_CARD_RESP_END),
388 host->ioaddr + SD_CARDSTATUS);
389 toshsd_cmd_irq(host);
390 }
391
392 /* Data transfer completion */
393 if (int_reg & SD_CARD_RW_END) {
394 iowrite32(int_status & ~(SD_CARD_RW_END),
395 host->ioaddr + SD_CARDSTATUS);
396 toshsd_data_end_irq(host);
397 }
398irq_end:
399 spin_unlock(&host->lock);
400 return ret;
401}
402
403static void toshsd_start_cmd(struct toshsd_host *host, struct mmc_command *cmd)
404{
405 struct mmc_data *data = host->data;
406 int c = cmd->opcode;
407
408 dev_dbg(&host->pdev->dev, "Command opcode: %d\n", cmd->opcode);
409
410 if (cmd->opcode == MMC_STOP_TRANSMISSION) {
411 iowrite16(SD_STOPINT_ISSUE_CMD12,
412 host->ioaddr + SD_STOPINTERNAL);
413
414 cmd->resp[0] = cmd->opcode;
415 cmd->resp[1] = 0;
416 cmd->resp[2] = 0;
417 cmd->resp[3] = 0;
418
419 toshsd_finish_request(host);
420 return;
421 }
422
423 switch (mmc_resp_type(cmd)) {
424 case MMC_RSP_NONE:
425 c |= SD_CMD_RESP_TYPE_NONE;
426 break;
427
428 case MMC_RSP_R1:
429 c |= SD_CMD_RESP_TYPE_EXT_R1;
430 break;
431 case MMC_RSP_R1B:
432 c |= SD_CMD_RESP_TYPE_EXT_R1B;
433 break;
434 case MMC_RSP_R2:
435 c |= SD_CMD_RESP_TYPE_EXT_R2;
436 break;
437 case MMC_RSP_R3:
438 c |= SD_CMD_RESP_TYPE_EXT_R3;
439 break;
440
441 default:
442 dev_err(&host->pdev->dev, "Unknown response type %d\n",
443 mmc_resp_type(cmd));
444 break;
445 }
446
447 host->cmd = cmd;
448
449 if (cmd->opcode == MMC_APP_CMD)
450 c |= SD_CMD_TYPE_ACMD;
451
452 if (cmd->opcode == MMC_GO_IDLE_STATE)
453 c |= (3 << 8); /* removed from ipaq-asic3.h for some reason */
454
455 if (data) {
456 c |= SD_CMD_DATA_PRESENT;
457
458 if (data->blocks > 1) {
459 iowrite16(SD_STOPINT_AUTO_ISSUE_CMD12,
460 host->ioaddr + SD_STOPINTERNAL);
461 c |= SD_CMD_MULTI_BLOCK;
462 }
463
464 if (data->flags & MMC_DATA_READ)
465 c |= SD_CMD_TRANSFER_READ;
466
467 /* MMC_DATA_WRITE does not require a bit to be set */
468 }
469
470 /* Send the command */
471 iowrite32(cmd->arg, host->ioaddr + SD_ARG0);
472 iowrite16(c, host->ioaddr + SD_CMD);
473}
474
475static void toshsd_start_data(struct toshsd_host *host, struct mmc_data *data)
476{
477 unsigned int flags = SG_MITER_ATOMIC;
478
479 dev_dbg(&host->pdev->dev, "setup data transfer: blocksize %08x nr_blocks %d, offset: %08x\n",
480 data->blksz, data->blocks, data->sg->offset);
481
482 host->data = data;
483
484 if (data->flags & MMC_DATA_READ)
485 flags |= SG_MITER_TO_SG;
486 else
487 flags |= SG_MITER_FROM_SG;
488
489 sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
490
491 /* Set transfer length and blocksize */
492 iowrite16(data->blocks, host->ioaddr + SD_BLOCKCOUNT);
493 iowrite16(data->blksz, host->ioaddr + SD_CARDXFERDATALEN);
494}
495
496/* Process requests from the MMC layer */
497static void toshsd_request(struct mmc_host *mmc, struct mmc_request *mrq)
498{
499 struct toshsd_host *host = mmc_priv(mmc);
500 unsigned long flags;
501
502 /* abort if card not present */
503 if (!(ioread16(host->ioaddr + SD_CARDSTATUS) & SD_CARD_PRESENT_0)) {
504 mrq->cmd->error = -ENOMEDIUM;
505 mmc_request_done(mmc, mrq);
506 return;
507 }
508
509 spin_lock_irqsave(&host->lock, flags);
510
511 WARN_ON(host->mrq != NULL);
512
513 host->mrq = mrq;
514
515 if (mrq->data)
516 toshsd_start_data(host, mrq->data);
517
518 toshsd_set_led(host, 1);
519
520 toshsd_start_cmd(host, mrq->cmd);
521
522 spin_unlock_irqrestore(&host->lock, flags);
523}
524
525static void toshsd_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
526{
527 struct toshsd_host *host = mmc_priv(mmc);
528 unsigned long flags;
529
530 spin_lock_irqsave(&host->lock, flags);
531 __toshsd_set_ios(mmc, ios);
532 spin_unlock_irqrestore(&host->lock, flags);
533}
534
535static int toshsd_get_ro(struct mmc_host *mmc)
536{
537 struct toshsd_host *host = mmc_priv(mmc);
538
539 /* active low */
540 return !(ioread16(host->ioaddr + SD_CARDSTATUS) & SD_CARD_WRITE_PROTECT);
541}
542
543static int toshsd_get_cd(struct mmc_host *mmc)
544{
545 struct toshsd_host *host = mmc_priv(mmc);
546
547 return !!(ioread16(host->ioaddr + SD_CARDSTATUS) & SD_CARD_PRESENT_0);
548}
549
550static struct mmc_host_ops toshsd_ops = {
551 .request = toshsd_request,
552 .set_ios = toshsd_set_ios,
553 .get_ro = toshsd_get_ro,
554 .get_cd = toshsd_get_cd,
555};
556
557
558static void toshsd_powerdown(struct toshsd_host *host)
559{
560 /* mask all interrupts */
561 iowrite32(0xffffffff, host->ioaddr + SD_INTMASKCARD);
562 /* disable card clock */
563 iowrite16(0x000, host->ioaddr + SDIO_BASE + SDIO_CLOCKNWAITCTRL);
564 iowrite16(0, host->ioaddr + SD_CARDCLOCKCTRL);
565 /* power down card */
566 pci_write_config_byte(host->pdev, SD_PCICFG_POWER1, SD_PCICFG_PWR1_OFF);
567 /* disable clock */
568 pci_write_config_byte(host->pdev, SD_PCICFG_CLKSTOP, 0);
569}
570
571#ifdef CONFIG_PM_SLEEP
572static int toshsd_pm_suspend(struct device *dev)
573{
574 struct pci_dev *pdev = to_pci_dev(dev);
575 struct toshsd_host *host = pci_get_drvdata(pdev);
576
577 toshsd_powerdown(host);
578
579 pci_save_state(pdev);
580 pci_enable_wake(pdev, PCI_D3hot, 0);
581 pci_disable_device(pdev);
582 pci_set_power_state(pdev, PCI_D3hot);
583
584 return 0;
585}
586
587static int toshsd_pm_resume(struct device *dev)
588{
589 struct pci_dev *pdev = to_pci_dev(dev);
590 struct toshsd_host *host = pci_get_drvdata(pdev);
591 int ret;
592
593 pci_set_power_state(pdev, PCI_D0);
594 pci_restore_state(pdev);
595 ret = pci_enable_device(pdev);
596 if (ret)
597 return ret;
598
599 toshsd_init(host);
600
601 return 0;
602}
603#endif /* CONFIG_PM_SLEEP */
604
605static int toshsd_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
606{
607 int ret;
608 struct toshsd_host *host;
609 struct mmc_host *mmc;
610 resource_size_t base;
611
612 ret = pci_enable_device(pdev);
613 if (ret)
614 return ret;
615
616 mmc = mmc_alloc_host(sizeof(struct toshsd_host), &pdev->dev);
617 if (!mmc) {
618 ret = -ENOMEM;
619 goto err;
620 }
621
622 host = mmc_priv(mmc);
623 host->mmc = mmc;
624
625 host->pdev = pdev;
626 pci_set_drvdata(pdev, host);
627
628 ret = pci_request_regions(pdev, DRIVER_NAME);
629 if (ret)
630 goto free;
631
632 host->ioaddr = pci_iomap(pdev, 0, 0);
633 if (!host->ioaddr) {
634 ret = -ENOMEM;
635 goto release;
636 }
637
638 /* Set MMC host parameters */
639 mmc->ops = &toshsd_ops;
640 mmc->caps = MMC_CAP_4_BIT_DATA;
641 mmc->ocr_avail = MMC_VDD_32_33;
642
643 mmc->f_min = HCLK / 512;
644 mmc->f_max = HCLK;
645
646 spin_lock_init(&host->lock);
647
648 toshsd_init(host);
649
650 ret = request_threaded_irq(pdev->irq, toshsd_irq, toshsd_thread_irq,
651 IRQF_SHARED, DRIVER_NAME, host);
652 if (ret)
653 goto unmap;
654
655 mmc_add_host(mmc);
656
657 base = pci_resource_start(pdev, 0);
658 dev_dbg(&pdev->dev, "MMIO %pa, IRQ %d\n", &base, pdev->irq);
659
660 pm_suspend_ignore_children(&pdev->dev, 1);
661
662 return 0;
663
664unmap:
665 pci_iounmap(pdev, host->ioaddr);
666release:
667 pci_release_regions(pdev);
668free:
669 mmc_free_host(mmc);
670 pci_set_drvdata(pdev, NULL);
671err:
672 pci_disable_device(pdev);
673 return ret;
674}
675
676static void toshsd_remove(struct pci_dev *pdev)
677{
678 struct toshsd_host *host = pci_get_drvdata(pdev);
679
680 mmc_remove_host(host->mmc);
681 toshsd_powerdown(host);
682 free_irq(pdev->irq, host);
683 pci_iounmap(pdev, host->ioaddr);
684 pci_release_regions(pdev);
685 mmc_free_host(host->mmc);
686 pci_set_drvdata(pdev, NULL);
687 pci_disable_device(pdev);
688}
689
690static const struct dev_pm_ops toshsd_pm_ops = {
691 SET_SYSTEM_SLEEP_PM_OPS(toshsd_pm_suspend, toshsd_pm_resume)
692};
693
694static struct pci_driver toshsd_driver = {
695 .name = DRIVER_NAME,
696 .id_table = pci_ids,
697 .probe = toshsd_probe,
698 .remove = toshsd_remove,
699 .driver.pm = &toshsd_pm_ops,
700};
701
702static int __init toshsd_drv_init(void)
703{
704 return pci_register_driver(&toshsd_driver);
705}
706
707static void __exit toshsd_drv_exit(void)
708{
709 pci_unregister_driver(&toshsd_driver);
710}
711
712module_init(toshsd_drv_init);
713module_exit(toshsd_drv_exit);
714
715MODULE_AUTHOR("Ondrej Zary, Richard Betts");
716MODULE_DESCRIPTION("Toshiba PCI Secure Digital Host Controller Interface driver");
717MODULE_LICENSE("GPL");
diff --git a/drivers/mmc/host/toshsd.h b/drivers/mmc/host/toshsd.h
new file mode 100644
index 000000000000..b6c0d89e53a6
--- /dev/null
+++ b/drivers/mmc/host/toshsd.h
@@ -0,0 +1,176 @@
1/*
2 * Toshiba PCI Secure Digital Host Controller Interface driver
3 *
4 * Copyright (C) 2014 Ondrej Zary
5 * Copyright (C) 2007 Richard Betts, All Rights Reserved.
6 *
7 * Based on asic3_mmc.c Copyright (c) 2005 SDG Systems, LLC
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
13 */
14
15#define HCLK 33000000 /* 33 MHz (PCI clock) */
16
17#define SD_PCICFG_CLKSTOP 0x40 /* 0x1f = clock controller, 0 = stop */
18#define SD_PCICFG_GATEDCLK 0x41 /* Gated clock */
19#define SD_PCICFG_CLKMODE 0x42 /* Control clock of SD controller */
20#define SD_PCICFG_PINSTATUS 0x44 /* R/O: read status of SD pins */
21#define SD_PCICFG_POWER1 0x48
22#define SD_PCICFG_POWER2 0x49
23#define SD_PCICFG_POWER3 0x4a
24#define SD_PCICFG_CARDDETECT 0x4c
25#define SD_PCICFG_SLOTS 0x50 /* R/O: define support slot number */
26#define SD_PCICFG_EXTGATECLK1 0xf0 /* Could be used for gated clock */
27#define SD_PCICFG_EXTGATECLK2 0xf1 /* Could be used for gated clock */
28#define SD_PCICFG_EXTGATECLK3 0xf9 /* Bit 1: double buffer/single buffer */
29#define SD_PCICFG_SDLED_ENABLE1 0xfa
30#define SD_PCICFG_SDLED_ENABLE2 0xfe
31
32#define SD_PCICFG_CLKMODE_DIV_DISABLE BIT(0)
33#define SD_PCICFG_CLKSTOP_ENABLE_ALL 0x1f
34#define SD_PCICFG_LED_ENABLE1_START 0x12
35#define SD_PCICFG_LED_ENABLE2_START 0x80
36
37#define SD_PCICFG_PWR1_33V 0x08 /* Set for 3.3 volts */
38#define SD_PCICFG_PWR1_OFF 0x00 /* Turn off power */
39#define SD_PCICFG_PWR2_AUTO 0x02
40
41#define SD_CMD 0x00 /* also for SDIO */
42#define SD_ARG0 0x04 /* also for SDIO */
43#define SD_ARG1 0x06 /* also for SDIO */
44#define SD_STOPINTERNAL 0x08
45#define SD_BLOCKCOUNT 0x0a /* also for SDIO */
46#define SD_RESPONSE0 0x0c /* also for SDIO */
47#define SD_RESPONSE1 0x0e /* also for SDIO */
48#define SD_RESPONSE2 0x10 /* also for SDIO */
49#define SD_RESPONSE3 0x12 /* also for SDIO */
50#define SD_RESPONSE4 0x14 /* also for SDIO */
51#define SD_RESPONSE5 0x16 /* also for SDIO */
52#define SD_RESPONSE6 0x18 /* also for SDIO */
53#define SD_RESPONSE7 0x1a /* also for SDIO */
54#define SD_CARDSTATUS 0x1c /* also for SDIO */
55#define SD_BUFFERCTRL 0x1e /* also for SDIO */
56#define SD_INTMASKCARD 0x20 /* also for SDIO */
57#define SD_INTMASKBUFFER 0x22 /* also for SDIO */
58#define SD_CARDCLOCKCTRL 0x24
59#define SD_CARDXFERDATALEN 0x26 /* also for SDIO */
60#define SD_CARDOPTIONSETUP 0x28 /* also for SDIO */
61#define SD_ERRORSTATUS0 0x2c /* also for SDIO */
62#define SD_ERRORSTATUS1 0x2e /* also for SDIO */
63#define SD_DATAPORT 0x30 /* also for SDIO */
64#define SD_TRANSACTIONCTRL 0x34 /* also for SDIO */
65#define SD_SOFTWARERESET 0xe0 /* also for SDIO */
66
67/* registers above marked "also for SDIO" and all SDIO registers below can be
68 * accessed at SDIO_BASE + reg address */
69#define SDIO_BASE 0x100
70
71#define SDIO_CARDPORTSEL 0x02
72#define SDIO_CARDINTCTRL 0x36
73#define SDIO_CLOCKNWAITCTRL 0x38
74#define SDIO_HOSTINFORMATION 0x3a
75#define SDIO_ERRORCTRL 0x3c
76#define SDIO_LEDCTRL 0x3e
77
78#define SD_TRANSCTL_SET BIT(8)
79
80#define SD_CARDCLK_DIV_DISABLE BIT(15)
81#define SD_CARDCLK_ENABLE_CLOCK BIT(8)
82#define SD_CARDCLK_CLK_DIV_512 BIT(7)
83#define SD_CARDCLK_CLK_DIV_256 BIT(6)
84#define SD_CARDCLK_CLK_DIV_128 BIT(5)
85#define SD_CARDCLK_CLK_DIV_64 BIT(4)
86#define SD_CARDCLK_CLK_DIV_32 BIT(3)
87#define SD_CARDCLK_CLK_DIV_16 BIT(2)
88#define SD_CARDCLK_CLK_DIV_8 BIT(1)
89#define SD_CARDCLK_CLK_DIV_4 BIT(0)
90#define SD_CARDCLK_CLK_DIV_2 0
91
92#define SD_CARDOPT_REQUIRED 0x000e
93#define SD_CARDOPT_DATA_RESP_TIMEOUT(x) (((x) & 0x0f) << 4) /* 4 bits */
94#define SD_CARDOPT_C2_MODULE_ABSENT BIT(14)
95#define SD_CARDOPT_DATA_XFR_WIDTH_1 (1 << 15)
96#define SD_CARDOPT_DATA_XFR_WIDTH_4 (0 << 15)
97
98#define SD_CMD_TYPE_CMD (0 << 6)
99#define SD_CMD_TYPE_ACMD (1 << 6)
100#define SD_CMD_TYPE_AUTHEN (2 << 6)
101#define SD_CMD_RESP_TYPE_NONE (3 << 8)
102#define SD_CMD_RESP_TYPE_EXT_R1 (4 << 8)
103#define SD_CMD_RESP_TYPE_EXT_R1B (5 << 8)
104#define SD_CMD_RESP_TYPE_EXT_R2 (6 << 8)
105#define SD_CMD_RESP_TYPE_EXT_R3 (7 << 8)
106#define SD_CMD_RESP_TYPE_EXT_R6 (4 << 8)
107#define SD_CMD_RESP_TYPE_EXT_R7 (4 << 8)
108#define SD_CMD_DATA_PRESENT BIT(11)
109#define SD_CMD_TRANSFER_READ BIT(12)
110#define SD_CMD_MULTI_BLOCK BIT(13)
111#define SD_CMD_SECURITY_CMD BIT(14)
112
113#define SD_STOPINT_ISSUE_CMD12 BIT(0)
114#define SD_STOPINT_AUTO_ISSUE_CMD12 BIT(8)
115
116#define SD_CARD_RESP_END BIT(0)
117#define SD_CARD_RW_END BIT(2)
118#define SD_CARD_CARD_REMOVED_0 BIT(3)
119#define SD_CARD_CARD_INSERTED_0 BIT(4)
120#define SD_CARD_PRESENT_0 BIT(5)
121#define SD_CARD_UNK6 BIT(6)
122#define SD_CARD_WRITE_PROTECT BIT(7)
123#define SD_CARD_CARD_REMOVED_3 BIT(8)
124#define SD_CARD_CARD_INSERTED_3 BIT(9)
125#define SD_CARD_PRESENT_3 BIT(10)
126
127#define SD_BUF_CMD_INDEX_ERR BIT(16)
128#define SD_BUF_CRC_ERR BIT(17)
129#define SD_BUF_STOP_BIT_END_ERR BIT(18)
130#define SD_BUF_DATA_TIMEOUT BIT(19)
131#define SD_BUF_OVERFLOW BIT(20)
132#define SD_BUF_UNDERFLOW BIT(21)
133#define SD_BUF_CMD_TIMEOUT BIT(22)
134#define SD_BUF_UNK7 BIT(23)
135#define SD_BUF_READ_ENABLE BIT(24)
136#define SD_BUF_WRITE_ENABLE BIT(25)
137#define SD_BUF_ILLEGAL_FUNCTION BIT(29)
138#define SD_BUF_CMD_BUSY BIT(30)
139#define SD_BUF_ILLEGAL_ACCESS BIT(31)
140
141#define SD_ERR0_RESP_CMD_ERR BIT(0)
142#define SD_ERR0_RESP_NON_CMD12_END_BIT_ERR BIT(2)
143#define SD_ERR0_RESP_CMD12_END_BIT_ERR BIT(3)
144#define SD_ERR0_READ_DATA_END_BIT_ERR BIT(4)
145#define SD_ERR0_WRITE_CRC_STATUS_END_BIT_ERR BIT(5)
146#define SD_ERR0_RESP_NON_CMD12_CRC_ERR BIT(8)
147#define SD_ERR0_RESP_CMD12_CRC_ERR BIT(9)
148#define SD_ERR0_READ_DATA_CRC_ERR BIT(10)
149#define SD_ERR0_WRITE_CMD_CRC_ERR BIT(11)
150
151#define SD_ERR1_NO_CMD_RESP BIT(16)
152#define SD_ERR1_TIMEOUT_READ_DATA BIT(20)
153#define SD_ERR1_TIMEOUT_CRS_STATUS BIT(21)
154#define SD_ERR1_TIMEOUT_CRC_BUSY BIT(22)
155
156#define IRQ_DONT_CARE_BITS (SD_CARD_PRESENT_3 \
157 | SD_CARD_WRITE_PROTECT \
158 | SD_CARD_UNK6 \
159 | SD_CARD_PRESENT_0 \
160 | SD_BUF_UNK7 \
161 | SD_BUF_CMD_BUSY)
162
163struct toshsd_host {
164 struct pci_dev *pdev;
165 struct mmc_host *mmc;
166
167 spinlock_t lock;
168
169 struct mmc_request *mrq;/* Current request */
170 struct mmc_command *cmd;/* Current command */
171 struct mmc_data *data; /* Current data request */
172
173 struct sg_mapping_iter sg_miter; /* for PIO */
174
175 void __iomem *ioaddr; /* mapped address */
176};
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index c9ac06cfe6b7..a5115fb7cf33 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -2471,7 +2471,8 @@ static void bond_loadbalance_arp_mon(struct work_struct *work)
2471 bond_slave_state_change(bond); 2471 bond_slave_state_change(bond);
2472 if (BOND_MODE(bond) == BOND_MODE_XOR) 2472 if (BOND_MODE(bond) == BOND_MODE_XOR)
2473 bond_update_slave_arr(bond, NULL); 2473 bond_update_slave_arr(bond, NULL);
2474 } else if (do_failover) { 2474 }
2475 if (do_failover) {
2475 block_netpoll_tx(); 2476 block_netpoll_tx();
2476 bond_select_active_slave(bond); 2477 bond_select_active_slave(bond);
2477 unblock_netpoll_tx(); 2478 unblock_netpoll_tx();
diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
index c13d83e15ace..45f09a66e6c9 100644
--- a/drivers/net/bonding/bond_netlink.c
+++ b/drivers/net/bonding/bond_netlink.c
@@ -225,7 +225,12 @@ static int bond_changelink(struct net_device *bond_dev,
225 225
226 bond_option_arp_ip_targets_clear(bond); 226 bond_option_arp_ip_targets_clear(bond);
227 nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) { 227 nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) {
228 __be32 target = nla_get_be32(attr); 228 __be32 target;
229
230 if (nla_len(attr) < sizeof(target))
231 return -EINVAL;
232
233 target = nla_get_be32(attr);
229 234
230 bond_opt_initval(&newval, (__force u64)target); 235 bond_opt_initval(&newval, (__force u64)target);
231 err = __bond_opt_set(bond, BOND_OPT_ARP_TARGETS, 236 err = __bond_opt_set(bond, BOND_OPT_ARP_TARGETS,
diff --git a/drivers/net/can/dev.c b/drivers/net/can/dev.c
index 02492d241e4c..2cfe5012e4e5 100644
--- a/drivers/net/can/dev.c
+++ b/drivers/net/can/dev.c
@@ -110,7 +110,7 @@ static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt,
110 long rate; 110 long rate;
111 u64 v64; 111 u64 v64;
112 112
113 /* Use CIA recommended sample points */ 113 /* Use CiA recommended sample points */
114 if (bt->sample_point) { 114 if (bt->sample_point) {
115 sampl_pt = bt->sample_point; 115 sampl_pt = bt->sample_point;
116 } else { 116 } else {
@@ -382,7 +382,7 @@ void can_free_echo_skb(struct net_device *dev, unsigned int idx)
382 BUG_ON(idx >= priv->echo_skb_max); 382 BUG_ON(idx >= priv->echo_skb_max);
383 383
384 if (priv->echo_skb[idx]) { 384 if (priv->echo_skb[idx]) {
385 kfree_skb(priv->echo_skb[idx]); 385 dev_kfree_skb_any(priv->echo_skb[idx]);
386 priv->echo_skb[idx] = NULL; 386 priv->echo_skb[idx] = NULL;
387 } 387 }
388} 388}
diff --git a/drivers/net/can/m_can/Kconfig b/drivers/net/can/m_can/Kconfig
index fca5482c09ac..04f20dd39007 100644
--- a/drivers/net/can/m_can/Kconfig
+++ b/drivers/net/can/m_can/Kconfig
@@ -1,4 +1,5 @@
1config CAN_M_CAN 1config CAN_M_CAN
2 depends on HAS_IOMEM
2 tristate "Bosch M_CAN devices" 3 tristate "Bosch M_CAN devices"
3 ---help--- 4 ---help---
4 Say Y here if you want to support for Bosch M_CAN controller. 5 Say Y here if you want to support for Bosch M_CAN controller.
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 10d571eaed85..d7bc462aafdc 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -105,14 +105,36 @@ enum m_can_mram_cfg {
105 MRAM_CFG_NUM, 105 MRAM_CFG_NUM,
106}; 106};
107 107
108/* Fast Bit Timing & Prescaler Register (FBTP) */
109#define FBTR_FBRP_MASK 0x1f
110#define FBTR_FBRP_SHIFT 16
111#define FBTR_FTSEG1_SHIFT 8
112#define FBTR_FTSEG1_MASK (0xf << FBTR_FTSEG1_SHIFT)
113#define FBTR_FTSEG2_SHIFT 4
114#define FBTR_FTSEG2_MASK (0x7 << FBTR_FTSEG2_SHIFT)
115#define FBTR_FSJW_SHIFT 0
116#define FBTR_FSJW_MASK 0x3
117
108/* Test Register (TEST) */ 118/* Test Register (TEST) */
109#define TEST_LBCK BIT(4) 119#define TEST_LBCK BIT(4)
110 120
111/* CC Control Register(CCCR) */ 121/* CC Control Register(CCCR) */
112#define CCCR_TEST BIT(7) 122#define CCCR_TEST BIT(7)
113#define CCCR_MON BIT(5) 123#define CCCR_CMR_MASK 0x3
114#define CCCR_CCE BIT(1) 124#define CCCR_CMR_SHIFT 10
115#define CCCR_INIT BIT(0) 125#define CCCR_CMR_CANFD 0x1
126#define CCCR_CMR_CANFD_BRS 0x2
127#define CCCR_CMR_CAN 0x3
128#define CCCR_CME_MASK 0x3
129#define CCCR_CME_SHIFT 8
130#define CCCR_CME_CAN 0
131#define CCCR_CME_CANFD 0x1
132#define CCCR_CME_CANFD_BRS 0x2
133#define CCCR_TEST BIT(7)
134#define CCCR_MON BIT(5)
135#define CCCR_CCE BIT(1)
136#define CCCR_INIT BIT(0)
137#define CCCR_CANFD 0x10
116 138
117/* Bit Timing & Prescaler Register (BTP) */ 139/* Bit Timing & Prescaler Register (BTP) */
118#define BTR_BRP_MASK 0x3ff 140#define BTR_BRP_MASK 0x3ff
@@ -204,6 +226,7 @@ enum m_can_mram_cfg {
204 226
205/* Rx Buffer / FIFO Element Size Configuration (RXESC) */ 227/* Rx Buffer / FIFO Element Size Configuration (RXESC) */
206#define M_CAN_RXESC_8BYTES 0x0 228#define M_CAN_RXESC_8BYTES 0x0
229#define M_CAN_RXESC_64BYTES 0x777
207 230
208/* Tx Buffer Configuration(TXBC) */ 231/* Tx Buffer Configuration(TXBC) */
209#define TXBC_NDTB_OFF 16 232#define TXBC_NDTB_OFF 16
@@ -211,6 +234,7 @@ enum m_can_mram_cfg {
211 234
212/* Tx Buffer Element Size Configuration(TXESC) */ 235/* Tx Buffer Element Size Configuration(TXESC) */
213#define TXESC_TBDS_8BYTES 0x0 236#define TXESC_TBDS_8BYTES 0x0
237#define TXESC_TBDS_64BYTES 0x7
214 238
215/* Tx Event FIFO Con.guration (TXEFC) */ 239/* Tx Event FIFO Con.guration (TXEFC) */
216#define TXEFC_EFS_OFF 16 240#define TXEFC_EFS_OFF 16
@@ -219,11 +243,11 @@ enum m_can_mram_cfg {
219/* Message RAM Configuration (in bytes) */ 243/* Message RAM Configuration (in bytes) */
220#define SIDF_ELEMENT_SIZE 4 244#define SIDF_ELEMENT_SIZE 4
221#define XIDF_ELEMENT_SIZE 8 245#define XIDF_ELEMENT_SIZE 8
222#define RXF0_ELEMENT_SIZE 16 246#define RXF0_ELEMENT_SIZE 72
223#define RXF1_ELEMENT_SIZE 16 247#define RXF1_ELEMENT_SIZE 72
224#define RXB_ELEMENT_SIZE 16 248#define RXB_ELEMENT_SIZE 16
225#define TXE_ELEMENT_SIZE 8 249#define TXE_ELEMENT_SIZE 8
226#define TXB_ELEMENT_SIZE 16 250#define TXB_ELEMENT_SIZE 72
227 251
228/* Message RAM Elements */ 252/* Message RAM Elements */
229#define M_CAN_FIFO_ID 0x0 253#define M_CAN_FIFO_ID 0x0
@@ -231,11 +255,17 @@ enum m_can_mram_cfg {
231#define M_CAN_FIFO_DATA(n) (0x8 + ((n) << 2)) 255#define M_CAN_FIFO_DATA(n) (0x8 + ((n) << 2))
232 256
233/* Rx Buffer Element */ 257/* Rx Buffer Element */
258/* R0 */
234#define RX_BUF_ESI BIT(31) 259#define RX_BUF_ESI BIT(31)
235#define RX_BUF_XTD BIT(30) 260#define RX_BUF_XTD BIT(30)
236#define RX_BUF_RTR BIT(29) 261#define RX_BUF_RTR BIT(29)
262/* R1 */
263#define RX_BUF_ANMF BIT(31)
264#define RX_BUF_EDL BIT(21)
265#define RX_BUF_BRS BIT(20)
237 266
238/* Tx Buffer Element */ 267/* Tx Buffer Element */
268/* R0 */
239#define TX_BUF_XTD BIT(30) 269#define TX_BUF_XTD BIT(30)
240#define TX_BUF_RTR BIT(29) 270#define TX_BUF_RTR BIT(29)
241 271
@@ -296,6 +326,7 @@ static inline void m_can_config_endisable(const struct m_can_priv *priv,
296 if (enable) { 326 if (enable) {
297 /* enable m_can configuration */ 327 /* enable m_can configuration */
298 m_can_write(priv, M_CAN_CCCR, cccr | CCCR_INIT); 328 m_can_write(priv, M_CAN_CCCR, cccr | CCCR_INIT);
329 udelay(5);
299 /* CCCR.CCE can only be set/reset while CCCR.INIT = '1' */ 330 /* CCCR.CCE can only be set/reset while CCCR.INIT = '1' */
300 m_can_write(priv, M_CAN_CCCR, cccr | CCCR_INIT | CCCR_CCE); 331 m_can_write(priv, M_CAN_CCCR, cccr | CCCR_INIT | CCCR_CCE);
301 } else { 332 } else {
@@ -326,41 +357,67 @@ static inline void m_can_disable_all_interrupts(const struct m_can_priv *priv)
326 m_can_write(priv, M_CAN_ILE, 0x0); 357 m_can_write(priv, M_CAN_ILE, 0x0);
327} 358}
328 359
329static void m_can_read_fifo(const struct net_device *dev, struct can_frame *cf, 360static void m_can_read_fifo(struct net_device *dev, u32 rxfs)
330 u32 rxfs)
331{ 361{
362 struct net_device_stats *stats = &dev->stats;
332 struct m_can_priv *priv = netdev_priv(dev); 363 struct m_can_priv *priv = netdev_priv(dev);
333 u32 id, fgi; 364 struct canfd_frame *cf;
365 struct sk_buff *skb;
366 u32 id, fgi, dlc;
367 int i;
334 368
335 /* calculate the fifo get index for where to read data */ 369 /* calculate the fifo get index for where to read data */
336 fgi = (rxfs & RXFS_FGI_MASK) >> RXFS_FGI_OFF; 370 fgi = (rxfs & RXFS_FGI_MASK) >> RXFS_FGI_OFF;
371 dlc = m_can_fifo_read(priv, fgi, M_CAN_FIFO_DLC);
372 if (dlc & RX_BUF_EDL)
373 skb = alloc_canfd_skb(dev, &cf);
374 else
375 skb = alloc_can_skb(dev, (struct can_frame **)&cf);
376 if (!skb) {
377 stats->rx_dropped++;
378 return;
379 }
380
381 if (dlc & RX_BUF_EDL)
382 cf->len = can_dlc2len((dlc >> 16) & 0x0F);
383 else
384 cf->len = get_can_dlc((dlc >> 16) & 0x0F);
385
337 id = m_can_fifo_read(priv, fgi, M_CAN_FIFO_ID); 386 id = m_can_fifo_read(priv, fgi, M_CAN_FIFO_ID);
338 if (id & RX_BUF_XTD) 387 if (id & RX_BUF_XTD)
339 cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG; 388 cf->can_id = (id & CAN_EFF_MASK) | CAN_EFF_FLAG;
340 else 389 else
341 cf->can_id = (id >> 18) & CAN_SFF_MASK; 390 cf->can_id = (id >> 18) & CAN_SFF_MASK;
342 391
343 if (id & RX_BUF_RTR) { 392 if (id & RX_BUF_ESI) {
393 cf->flags |= CANFD_ESI;
394 netdev_dbg(dev, "ESI Error\n");
395 }
396
397 if (!(dlc & RX_BUF_EDL) && (id & RX_BUF_RTR)) {
344 cf->can_id |= CAN_RTR_FLAG; 398 cf->can_id |= CAN_RTR_FLAG;
345 } else { 399 } else {
346 id = m_can_fifo_read(priv, fgi, M_CAN_FIFO_DLC); 400 if (dlc & RX_BUF_BRS)
347 cf->can_dlc = get_can_dlc((id >> 16) & 0x0F); 401 cf->flags |= CANFD_BRS;
348 *(u32 *)(cf->data + 0) = m_can_fifo_read(priv, fgi, 402
349 M_CAN_FIFO_DATA(0)); 403 for (i = 0; i < cf->len; i += 4)
350 *(u32 *)(cf->data + 4) = m_can_fifo_read(priv, fgi, 404 *(u32 *)(cf->data + i) =
351 M_CAN_FIFO_DATA(1)); 405 m_can_fifo_read(priv, fgi,
406 M_CAN_FIFO_DATA(i / 4));
352 } 407 }
353 408
354 /* acknowledge rx fifo 0 */ 409 /* acknowledge rx fifo 0 */
355 m_can_write(priv, M_CAN_RXF0A, fgi); 410 m_can_write(priv, M_CAN_RXF0A, fgi);
411
412 stats->rx_packets++;
413 stats->rx_bytes += cf->len;
414
415 netif_receive_skb(skb);
356} 416}
357 417
358static int m_can_do_rx_poll(struct net_device *dev, int quota) 418static int m_can_do_rx_poll(struct net_device *dev, int quota)
359{ 419{
360 struct m_can_priv *priv = netdev_priv(dev); 420 struct m_can_priv *priv = netdev_priv(dev);
361 struct net_device_stats *stats = &dev->stats;
362 struct sk_buff *skb;
363 struct can_frame *frame;
364 u32 pkts = 0; 421 u32 pkts = 0;
365 u32 rxfs; 422 u32 rxfs;
366 423
@@ -374,18 +431,7 @@ static int m_can_do_rx_poll(struct net_device *dev, int quota)
374 if (rxfs & RXFS_RFL) 431 if (rxfs & RXFS_RFL)
375 netdev_warn(dev, "Rx FIFO 0 Message Lost\n"); 432 netdev_warn(dev, "Rx FIFO 0 Message Lost\n");
376 433
377 skb = alloc_can_skb(dev, &frame); 434 m_can_read_fifo(dev, rxfs);
378 if (!skb) {
379 stats->rx_dropped++;
380 return pkts;
381 }
382
383 m_can_read_fifo(dev, frame, rxfs);
384
385 stats->rx_packets++;
386 stats->rx_bytes += frame->can_dlc;
387
388 netif_receive_skb(skb);
389 435
390 quota--; 436 quota--;
391 pkts++; 437 pkts++;
@@ -481,11 +527,23 @@ static int m_can_handle_lec_err(struct net_device *dev,
481 return 1; 527 return 1;
482} 528}
483 529
530static int __m_can_get_berr_counter(const struct net_device *dev,
531 struct can_berr_counter *bec)
532{
533 struct m_can_priv *priv = netdev_priv(dev);
534 unsigned int ecr;
535
536 ecr = m_can_read(priv, M_CAN_ECR);
537 bec->rxerr = (ecr & ECR_REC_MASK) >> ECR_REC_SHIFT;
538 bec->txerr = ecr & ECR_TEC_MASK;
539
540 return 0;
541}
542
484static int m_can_get_berr_counter(const struct net_device *dev, 543static int m_can_get_berr_counter(const struct net_device *dev,
485 struct can_berr_counter *bec) 544 struct can_berr_counter *bec)
486{ 545{
487 struct m_can_priv *priv = netdev_priv(dev); 546 struct m_can_priv *priv = netdev_priv(dev);
488 unsigned int ecr;
489 int err; 547 int err;
490 548
491 err = clk_prepare_enable(priv->hclk); 549 err = clk_prepare_enable(priv->hclk);
@@ -498,9 +556,7 @@ static int m_can_get_berr_counter(const struct net_device *dev,
498 return err; 556 return err;
499 } 557 }
500 558
501 ecr = m_can_read(priv, M_CAN_ECR); 559 __m_can_get_berr_counter(dev, bec);
502 bec->rxerr = (ecr & ECR_REC_MASK) >> ECR_REC_SHIFT;
503 bec->txerr = ecr & ECR_TEC_MASK;
504 560
505 clk_disable_unprepare(priv->cclk); 561 clk_disable_unprepare(priv->cclk);
506 clk_disable_unprepare(priv->hclk); 562 clk_disable_unprepare(priv->hclk);
@@ -544,7 +600,7 @@ static int m_can_handle_state_change(struct net_device *dev,
544 if (unlikely(!skb)) 600 if (unlikely(!skb))
545 return 0; 601 return 0;
546 602
547 m_can_get_berr_counter(dev, &bec); 603 __m_can_get_berr_counter(dev, &bec);
548 604
549 switch (new_state) { 605 switch (new_state) {
550 case CAN_STATE_ERROR_ACTIVE: 606 case CAN_STATE_ERROR_ACTIVE:
@@ -596,14 +652,14 @@ static int m_can_handle_state_errors(struct net_device *dev, u32 psr)
596 652
597 if ((psr & PSR_EP) && 653 if ((psr & PSR_EP) &&
598 (priv->can.state != CAN_STATE_ERROR_PASSIVE)) { 654 (priv->can.state != CAN_STATE_ERROR_PASSIVE)) {
599 netdev_dbg(dev, "entered error warning state\n"); 655 netdev_dbg(dev, "entered error passive state\n");
600 work_done += m_can_handle_state_change(dev, 656 work_done += m_can_handle_state_change(dev,
601 CAN_STATE_ERROR_PASSIVE); 657 CAN_STATE_ERROR_PASSIVE);
602 } 658 }
603 659
604 if ((psr & PSR_BO) && 660 if ((psr & PSR_BO) &&
605 (priv->can.state != CAN_STATE_BUS_OFF)) { 661 (priv->can.state != CAN_STATE_BUS_OFF)) {
606 netdev_dbg(dev, "entered error warning state\n"); 662 netdev_dbg(dev, "entered error bus off state\n");
607 work_done += m_can_handle_state_change(dev, 663 work_done += m_can_handle_state_change(dev,
608 CAN_STATE_BUS_OFF); 664 CAN_STATE_BUS_OFF);
609 } 665 }
@@ -615,7 +671,7 @@ static void m_can_handle_other_err(struct net_device *dev, u32 irqstatus)
615{ 671{
616 if (irqstatus & IR_WDI) 672 if (irqstatus & IR_WDI)
617 netdev_err(dev, "Message RAM Watchdog event due to missing READY\n"); 673 netdev_err(dev, "Message RAM Watchdog event due to missing READY\n");
618 if (irqstatus & IR_BEU) 674 if (irqstatus & IR_ELO)
619 netdev_err(dev, "Error Logging Overflow\n"); 675 netdev_err(dev, "Error Logging Overflow\n");
620 if (irqstatus & IR_BEU) 676 if (irqstatus & IR_BEU)
621 netdev_err(dev, "Bit Error Uncorrected\n"); 677 netdev_err(dev, "Bit Error Uncorrected\n");
@@ -733,10 +789,23 @@ static const struct can_bittiming_const m_can_bittiming_const = {
733 .brp_inc = 1, 789 .brp_inc = 1,
734}; 790};
735 791
792static const struct can_bittiming_const m_can_data_bittiming_const = {
793 .name = KBUILD_MODNAME,
794 .tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */
795 .tseg1_max = 16,
796 .tseg2_min = 1, /* Time segment 2 = phase_seg2 */
797 .tseg2_max = 8,
798 .sjw_max = 4,
799 .brp_min = 1,
800 .brp_max = 32,
801 .brp_inc = 1,
802};
803
736static int m_can_set_bittiming(struct net_device *dev) 804static int m_can_set_bittiming(struct net_device *dev)
737{ 805{
738 struct m_can_priv *priv = netdev_priv(dev); 806 struct m_can_priv *priv = netdev_priv(dev);
739 const struct can_bittiming *bt = &priv->can.bittiming; 807 const struct can_bittiming *bt = &priv->can.bittiming;
808 const struct can_bittiming *dbt = &priv->can.data_bittiming;
740 u16 brp, sjw, tseg1, tseg2; 809 u16 brp, sjw, tseg1, tseg2;
741 u32 reg_btp; 810 u32 reg_btp;
742 811
@@ -747,7 +816,17 @@ static int m_can_set_bittiming(struct net_device *dev)
747 reg_btp = (brp << BTR_BRP_SHIFT) | (sjw << BTR_SJW_SHIFT) | 816 reg_btp = (brp << BTR_BRP_SHIFT) | (sjw << BTR_SJW_SHIFT) |
748 (tseg1 << BTR_TSEG1_SHIFT) | (tseg2 << BTR_TSEG2_SHIFT); 817 (tseg1 << BTR_TSEG1_SHIFT) | (tseg2 << BTR_TSEG2_SHIFT);
749 m_can_write(priv, M_CAN_BTP, reg_btp); 818 m_can_write(priv, M_CAN_BTP, reg_btp);
750 netdev_dbg(dev, "setting BTP 0x%x\n", reg_btp); 819
820 if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
821 brp = dbt->brp - 1;
822 sjw = dbt->sjw - 1;
823 tseg1 = dbt->prop_seg + dbt->phase_seg1 - 1;
824 tseg2 = dbt->phase_seg2 - 1;
825 reg_btp = (brp << FBTR_FBRP_SHIFT) | (sjw << FBTR_FSJW_SHIFT) |
826 (tseg1 << FBTR_FTSEG1_SHIFT) |
827 (tseg2 << FBTR_FTSEG2_SHIFT);
828 m_can_write(priv, M_CAN_FBTP, reg_btp);
829 }
751 830
752 return 0; 831 return 0;
753} 832}
@@ -767,8 +846,8 @@ static void m_can_chip_config(struct net_device *dev)
767 846
768 m_can_config_endisable(priv, true); 847 m_can_config_endisable(priv, true);
769 848
770 /* RX Buffer/FIFO Element Size 8 bytes data field */ 849 /* RX Buffer/FIFO Element Size 64 bytes data field */
771 m_can_write(priv, M_CAN_RXESC, M_CAN_RXESC_8BYTES); 850 m_can_write(priv, M_CAN_RXESC, M_CAN_RXESC_64BYTES);
772 851
773 /* Accept Non-matching Frames Into FIFO 0 */ 852 /* Accept Non-matching Frames Into FIFO 0 */
774 m_can_write(priv, M_CAN_GFC, 0x0); 853 m_can_write(priv, M_CAN_GFC, 0x0);
@@ -777,8 +856,8 @@ static void m_can_chip_config(struct net_device *dev)
777 m_can_write(priv, M_CAN_TXBC, (1 << TXBC_NDTB_OFF) | 856 m_can_write(priv, M_CAN_TXBC, (1 << TXBC_NDTB_OFF) |
778 priv->mcfg[MRAM_TXB].off); 857 priv->mcfg[MRAM_TXB].off);
779 858
780 /* only support 8 bytes firstly */ 859 /* support 64 bytes payload */
781 m_can_write(priv, M_CAN_TXESC, TXESC_TBDS_8BYTES); 860 m_can_write(priv, M_CAN_TXESC, TXESC_TBDS_64BYTES);
782 861
783 m_can_write(priv, M_CAN_TXEFC, (1 << TXEFC_EFS_OFF) | 862 m_can_write(priv, M_CAN_TXEFC, (1 << TXEFC_EFS_OFF) |
784 priv->mcfg[MRAM_TXE].off); 863 priv->mcfg[MRAM_TXE].off);
@@ -793,7 +872,8 @@ static void m_can_chip_config(struct net_device *dev)
793 RXFC_FWM_1 | priv->mcfg[MRAM_RXF1].off); 872 RXFC_FWM_1 | priv->mcfg[MRAM_RXF1].off);
794 873
795 cccr = m_can_read(priv, M_CAN_CCCR); 874 cccr = m_can_read(priv, M_CAN_CCCR);
796 cccr &= ~(CCCR_TEST | CCCR_MON); 875 cccr &= ~(CCCR_TEST | CCCR_MON | (CCCR_CMR_MASK << CCCR_CMR_SHIFT) |
876 (CCCR_CME_MASK << CCCR_CME_SHIFT));
797 test = m_can_read(priv, M_CAN_TEST); 877 test = m_can_read(priv, M_CAN_TEST);
798 test &= ~TEST_LBCK; 878 test &= ~TEST_LBCK;
799 879
@@ -805,6 +885,9 @@ static void m_can_chip_config(struct net_device *dev)
805 test |= TEST_LBCK; 885 test |= TEST_LBCK;
806 } 886 }
807 887
888 if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
889 cccr |= CCCR_CME_CANFD_BRS << CCCR_CME_SHIFT;
890
808 m_can_write(priv, M_CAN_CCCR, cccr); 891 m_can_write(priv, M_CAN_CCCR, cccr);
809 m_can_write(priv, M_CAN_TEST, test); 892 m_can_write(priv, M_CAN_TEST, test);
810 893
@@ -869,11 +952,13 @@ static struct net_device *alloc_m_can_dev(void)
869 952
870 priv->dev = dev; 953 priv->dev = dev;
871 priv->can.bittiming_const = &m_can_bittiming_const; 954 priv->can.bittiming_const = &m_can_bittiming_const;
955 priv->can.data_bittiming_const = &m_can_data_bittiming_const;
872 priv->can.do_set_mode = m_can_set_mode; 956 priv->can.do_set_mode = m_can_set_mode;
873 priv->can.do_get_berr_counter = m_can_get_berr_counter; 957 priv->can.do_get_berr_counter = m_can_get_berr_counter;
874 priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | 958 priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
875 CAN_CTRLMODE_LISTENONLY | 959 CAN_CTRLMODE_LISTENONLY |
876 CAN_CTRLMODE_BERR_REPORTING; 960 CAN_CTRLMODE_BERR_REPORTING |
961 CAN_CTRLMODE_FD;
877 962
878 return dev; 963 return dev;
879} 964}
@@ -956,8 +1041,9 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
956 struct net_device *dev) 1041 struct net_device *dev)
957{ 1042{
958 struct m_can_priv *priv = netdev_priv(dev); 1043 struct m_can_priv *priv = netdev_priv(dev);
959 struct can_frame *cf = (struct can_frame *)skb->data; 1044 struct canfd_frame *cf = (struct canfd_frame *)skb->data;
960 u32 id; 1045 u32 id, cccr;
1046 int i;
961 1047
962 if (can_dropped_invalid_skb(dev, skb)) 1048 if (can_dropped_invalid_skb(dev, skb))
963 return NETDEV_TX_OK; 1049 return NETDEV_TX_OK;
@@ -976,11 +1062,28 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff *skb,
976 1062
977 /* message ram configuration */ 1063 /* message ram configuration */
978 m_can_fifo_write(priv, 0, M_CAN_FIFO_ID, id); 1064 m_can_fifo_write(priv, 0, M_CAN_FIFO_ID, id);
979 m_can_fifo_write(priv, 0, M_CAN_FIFO_DLC, cf->can_dlc << 16); 1065 m_can_fifo_write(priv, 0, M_CAN_FIFO_DLC, can_len2dlc(cf->len) << 16);
980 m_can_fifo_write(priv, 0, M_CAN_FIFO_DATA(0), *(u32 *)(cf->data + 0)); 1066
981 m_can_fifo_write(priv, 0, M_CAN_FIFO_DATA(1), *(u32 *)(cf->data + 4)); 1067 for (i = 0; i < cf->len; i += 4)
1068 m_can_fifo_write(priv, 0, M_CAN_FIFO_DATA(i / 4),
1069 *(u32 *)(cf->data + i));
1070
982 can_put_echo_skb(skb, dev, 0); 1071 can_put_echo_skb(skb, dev, 0);
983 1072
1073 if (priv->can.ctrlmode & CAN_CTRLMODE_FD) {
1074 cccr = m_can_read(priv, M_CAN_CCCR);
1075 cccr &= ~(CCCR_CMR_MASK << CCCR_CMR_SHIFT);
1076 if (can_is_canfd_skb(skb)) {
1077 if (cf->flags & CANFD_BRS)
1078 cccr |= CCCR_CMR_CANFD_BRS << CCCR_CMR_SHIFT;
1079 else
1080 cccr |= CCCR_CMR_CANFD << CCCR_CMR_SHIFT;
1081 } else {
1082 cccr |= CCCR_CMR_CAN << CCCR_CMR_SHIFT;
1083 }
1084 m_can_write(priv, M_CAN_CCCR, cccr);
1085 }
1086
984 /* enable first TX buffer to start transfer */ 1087 /* enable first TX buffer to start transfer */
985 m_can_write(priv, M_CAN_TXBTIE, 0x1); 1088 m_can_write(priv, M_CAN_TXBTIE, 0x1);
986 m_can_write(priv, M_CAN_TXBAR, 0x1); 1089 m_can_write(priv, M_CAN_TXBAR, 0x1);
@@ -992,6 +1095,7 @@ static const struct net_device_ops m_can_netdev_ops = {
992 .ndo_open = m_can_open, 1095 .ndo_open = m_can_open,
993 .ndo_stop = m_can_close, 1096 .ndo_stop = m_can_close,
994 .ndo_start_xmit = m_can_start_xmit, 1097 .ndo_start_xmit = m_can_start_xmit,
1098 .ndo_change_mtu = can_change_mtu,
995}; 1099};
996 1100
997static int register_m_can_dev(struct net_device *dev) 1101static int register_m_can_dev(struct net_device *dev)
@@ -1009,7 +1113,7 @@ static int m_can_of_parse_mram(struct platform_device *pdev,
1009 struct resource *res; 1113 struct resource *res;
1010 void __iomem *addr; 1114 void __iomem *addr;
1011 u32 out_val[MRAM_CFG_LEN]; 1115 u32 out_val[MRAM_CFG_LEN];
1012 int ret; 1116 int i, start, end, ret;
1013 1117
1014 /* message ram could be shared */ 1118 /* message ram could be shared */
1015 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "message_ram"); 1119 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "message_ram");
@@ -1060,6 +1164,15 @@ static int m_can_of_parse_mram(struct platform_device *pdev,
1060 priv->mcfg[MRAM_TXE].off, priv->mcfg[MRAM_TXE].num, 1164 priv->mcfg[MRAM_TXE].off, priv->mcfg[MRAM_TXE].num,
1061 priv->mcfg[MRAM_TXB].off, priv->mcfg[MRAM_TXB].num); 1165 priv->mcfg[MRAM_TXB].off, priv->mcfg[MRAM_TXB].num);
1062 1166
1167 /* initialize the entire Message RAM in use to avoid possible
1168 * ECC/parity checksum errors when reading an uninitialized buffer
1169 */
1170 start = priv->mcfg[MRAM_SIDF].off;
1171 end = priv->mcfg[MRAM_TXB].off +
1172 priv->mcfg[MRAM_TXB].num * TXB_ELEMENT_SIZE;
1173 for (i = start; i < end; i += 4)
1174 writel(0x0, priv->mram_base + i);
1175
1063 return 0; 1176 return 0;
1064} 1177}
1065 1178
diff --git a/drivers/net/can/rcar_can.c b/drivers/net/can/rcar_can.c
index 1abe133d1594..9718248e55f1 100644
--- a/drivers/net/can/rcar_can.c
+++ b/drivers/net/can/rcar_can.c
@@ -628,6 +628,7 @@ static const struct net_device_ops rcar_can_netdev_ops = {
628 .ndo_open = rcar_can_open, 628 .ndo_open = rcar_can_open,
629 .ndo_stop = rcar_can_close, 629 .ndo_stop = rcar_can_close,
630 .ndo_start_xmit = rcar_can_start_xmit, 630 .ndo_start_xmit = rcar_can_start_xmit,
631 .ndo_change_mtu = can_change_mtu,
631}; 632};
632 633
633static void rcar_can_rx_pkt(struct rcar_can_priv *priv) 634static void rcar_can_rx_pkt(struct rcar_can_priv *priv)
diff --git a/drivers/net/can/sja1000/kvaser_pci.c b/drivers/net/can/sja1000/kvaser_pci.c
index 8ff3424d5147..15c00faeec61 100644
--- a/drivers/net/can/sja1000/kvaser_pci.c
+++ b/drivers/net/can/sja1000/kvaser_pci.c
@@ -214,7 +214,7 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
214 struct net_device *dev; 214 struct net_device *dev;
215 struct sja1000_priv *priv; 215 struct sja1000_priv *priv;
216 struct kvaser_pci *board; 216 struct kvaser_pci *board;
217 int err, init_step; 217 int err;
218 218
219 dev = alloc_sja1000dev(sizeof(struct kvaser_pci)); 219 dev = alloc_sja1000dev(sizeof(struct kvaser_pci));
220 if (dev == NULL) 220 if (dev == NULL)
@@ -235,7 +235,6 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
235 if (channel == 0) { 235 if (channel == 0) {
236 board->xilinx_ver = 236 board->xilinx_ver =
237 ioread8(board->res_addr + XILINX_VERINT) >> 4; 237 ioread8(board->res_addr + XILINX_VERINT) >> 4;
238 init_step = 2;
239 238
240 /* Assert PTADR# - we're in passive mode so the other bits are 239 /* Assert PTADR# - we're in passive mode so the other bits are
241 not important */ 240 not important */
@@ -264,8 +263,6 @@ static int kvaser_pci_add_chan(struct pci_dev *pdev, int channel,
264 priv->irq_flags = IRQF_SHARED; 263 priv->irq_flags = IRQF_SHARED;
265 dev->irq = pdev->irq; 264 dev->irq = pdev->irq;
266 265
267 init_step = 4;
268
269 dev_info(&pdev->dev, "reg_base=%p conf_addr=%p irq=%d\n", 266 dev_info(&pdev->dev, "reg_base=%p conf_addr=%p irq=%d\n",
270 priv->reg_base, board->conf_addr, dev->irq); 267 priv->reg_base, board->conf_addr, dev->irq);
271 268
diff --git a/drivers/net/can/usb/ems_usb.c b/drivers/net/can/usb/ems_usb.c
index 00f2534dde73..29d3f0938eb8 100644
--- a/drivers/net/can/usb/ems_usb.c
+++ b/drivers/net/can/usb/ems_usb.c
@@ -434,10 +434,9 @@ static void ems_usb_read_bulk_callback(struct urb *urb)
434 if (urb->actual_length > CPC_HEADER_SIZE) { 434 if (urb->actual_length > CPC_HEADER_SIZE) {
435 struct ems_cpc_msg *msg; 435 struct ems_cpc_msg *msg;
436 u8 *ibuf = urb->transfer_buffer; 436 u8 *ibuf = urb->transfer_buffer;
437 u8 msg_count, again, start; 437 u8 msg_count, start;
438 438
439 msg_count = ibuf[0] & ~0x80; 439 msg_count = ibuf[0] & ~0x80;
440 again = ibuf[0] & 0x80;
441 440
442 start = CPC_HEADER_SIZE; 441 start = CPC_HEADER_SIZE;
443 442
diff --git a/drivers/net/can/usb/esd_usb2.c b/drivers/net/can/usb/esd_usb2.c
index b7c9e8b11460..c063a54ab8dd 100644
--- a/drivers/net/can/usb/esd_usb2.c
+++ b/drivers/net/can/usb/esd_usb2.c
@@ -464,7 +464,6 @@ static void esd_usb2_write_bulk_callback(struct urb *urb)
464{ 464{
465 struct esd_tx_urb_context *context = urb->context; 465 struct esd_tx_urb_context *context = urb->context;
466 struct esd_usb2_net_priv *priv; 466 struct esd_usb2_net_priv *priv;
467 struct esd_usb2 *dev;
468 struct net_device *netdev; 467 struct net_device *netdev;
469 size_t size = sizeof(struct esd_usb2_msg); 468 size_t size = sizeof(struct esd_usb2_msg);
470 469
@@ -472,7 +471,6 @@ static void esd_usb2_write_bulk_callback(struct urb *urb)
472 471
473 priv = context->priv; 472 priv = context->priv;
474 netdev = priv->netdev; 473 netdev = priv->netdev;
475 dev = priv->usb2;
476 474
477 /* free up our allocated buffer */ 475 /* free up our allocated buffer */
478 usb_free_coherent(urb->dev, size, 476 usb_free_coherent(urb->dev, size,
@@ -1143,6 +1141,7 @@ static void esd_usb2_disconnect(struct usb_interface *intf)
1143 } 1141 }
1144 } 1142 }
1145 unlink_all_urbs(dev); 1143 unlink_all_urbs(dev);
1144 kfree(dev);
1146 } 1145 }
1147} 1146}
1148 1147
diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
index 04b0f84612f0..009acc8641fc 100644
--- a/drivers/net/can/usb/gs_usb.c
+++ b/drivers/net/can/usb/gs_usb.c
@@ -718,6 +718,7 @@ static const struct net_device_ops gs_usb_netdev_ops = {
718 .ndo_open = gs_can_open, 718 .ndo_open = gs_can_open,
719 .ndo_stop = gs_can_close, 719 .ndo_stop = gs_can_close,
720 .ndo_start_xmit = gs_can_start_xmit, 720 .ndo_start_xmit = gs_can_start_xmit,
721 .ndo_change_mtu = can_change_mtu,
721}; 722};
722 723
723static struct gs_can *gs_make_candev(unsigned int channel, struct usb_interface *intf) 724static struct gs_can *gs_make_candev(unsigned int channel, struct usb_interface *intf)
diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c
index 5e8b5609c067..8a998e3884ce 100644
--- a/drivers/net/can/xilinx_can.c
+++ b/drivers/net/can/xilinx_can.c
@@ -300,7 +300,8 @@ static int xcan_set_bittiming(struct net_device *ndev)
300static int xcan_chip_start(struct net_device *ndev) 300static int xcan_chip_start(struct net_device *ndev)
301{ 301{
302 struct xcan_priv *priv = netdev_priv(ndev); 302 struct xcan_priv *priv = netdev_priv(ndev);
303 u32 err, reg_msr, reg_sr_mask; 303 u32 reg_msr, reg_sr_mask;
304 int err;
304 unsigned long timeout; 305 unsigned long timeout;
305 306
306 /* Check if it is in reset mode */ 307 /* Check if it is in reset mode */
@@ -961,6 +962,7 @@ static const struct net_device_ops xcan_netdev_ops = {
961 .ndo_open = xcan_open, 962 .ndo_open = xcan_open,
962 .ndo_stop = xcan_close, 963 .ndo_stop = xcan_close,
963 .ndo_start_xmit = xcan_start_xmit, 964 .ndo_start_xmit = xcan_start_xmit,
965 .ndo_change_mtu = can_change_mtu,
964}; 966};
965 967
966/** 968/**
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index b9625968daac..4f4c2a7888e5 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -377,6 +377,29 @@ static irqreturn_t bcm_sf2_switch_1_isr(int irq, void *dev_id)
377 return IRQ_HANDLED; 377 return IRQ_HANDLED;
378} 378}
379 379
380static int bcm_sf2_sw_rst(struct bcm_sf2_priv *priv)
381{
382 unsigned int timeout = 1000;
383 u32 reg;
384
385 reg = core_readl(priv, CORE_WATCHDOG_CTRL);
386 reg |= SOFTWARE_RESET | EN_CHIP_RST | EN_SW_RESET;
387 core_writel(priv, reg, CORE_WATCHDOG_CTRL);
388
389 do {
390 reg = core_readl(priv, CORE_WATCHDOG_CTRL);
391 if (!(reg & SOFTWARE_RESET))
392 break;
393
394 usleep_range(1000, 2000);
395 } while (timeout-- > 0);
396
397 if (timeout == 0)
398 return -ETIMEDOUT;
399
400 return 0;
401}
402
380static int bcm_sf2_sw_setup(struct dsa_switch *ds) 403static int bcm_sf2_sw_setup(struct dsa_switch *ds)
381{ 404{
382 const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME; 405 const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME;
@@ -404,11 +427,18 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)
404 *base = of_iomap(dn, i); 427 *base = of_iomap(dn, i);
405 if (*base == NULL) { 428 if (*base == NULL) {
406 pr_err("unable to find register: %s\n", reg_names[i]); 429 pr_err("unable to find register: %s\n", reg_names[i]);
407 return -ENODEV; 430 ret = -ENOMEM;
431 goto out_unmap;
408 } 432 }
409 base++; 433 base++;
410 } 434 }
411 435
436 ret = bcm_sf2_sw_rst(priv);
437 if (ret) {
438 pr_err("unable to software reset switch: %d\n", ret);
439 goto out_unmap;
440 }
441
412 /* Disable all interrupts and request them */ 442 /* Disable all interrupts and request them */
413 intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_MASK_SET); 443 intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_MASK_SET);
414 intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR); 444 intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR);
@@ -484,7 +514,8 @@ out_free_irq0:
484out_unmap: 514out_unmap:
485 base = &priv->core; 515 base = &priv->core;
486 for (i = 0; i < BCM_SF2_REGS_NUM; i++) { 516 for (i = 0; i < BCM_SF2_REGS_NUM; i++) {
487 iounmap(*base); 517 if (*base)
518 iounmap(*base);
488 base++; 519 base++;
489 } 520 }
490 return ret; 521 return ret;
@@ -733,29 +764,6 @@ static int bcm_sf2_sw_suspend(struct dsa_switch *ds)
733 return 0; 764 return 0;
734} 765}
735 766
736static int bcm_sf2_sw_rst(struct bcm_sf2_priv *priv)
737{
738 unsigned int timeout = 1000;
739 u32 reg;
740
741 reg = core_readl(priv, CORE_WATCHDOG_CTRL);
742 reg |= SOFTWARE_RESET | EN_CHIP_RST | EN_SW_RESET;
743 core_writel(priv, reg, CORE_WATCHDOG_CTRL);
744
745 do {
746 reg = core_readl(priv, CORE_WATCHDOG_CTRL);
747 if (!(reg & SOFTWARE_RESET))
748 break;
749
750 usleep_range(1000, 2000);
751 } while (timeout-- > 0);
752
753 if (timeout == 0)
754 return -ETIMEDOUT;
755
756 return 0;
757}
758
759static int bcm_sf2_sw_resume(struct dsa_switch *ds) 767static int bcm_sf2_sw_resume(struct dsa_switch *ds)
760{ 768{
761 struct bcm_sf2_priv *priv = ds_to_priv(ds); 769 struct bcm_sf2_priv *priv = ds_to_priv(ds);
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
index 63ea1941e973..7ba83ffb08ac 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c
@@ -575,10 +575,24 @@ static void xgene_gmac_tx_disable(struct xgene_enet_pdata *pdata)
575 xgene_enet_wr_mcx_mac(pdata, MAC_CONFIG_1_ADDR, data & ~TX_EN); 575 xgene_enet_wr_mcx_mac(pdata, MAC_CONFIG_1_ADDR, data & ~TX_EN);
576} 576}
577 577
578static void xgene_enet_reset(struct xgene_enet_pdata *pdata) 578bool xgene_ring_mgr_init(struct xgene_enet_pdata *p)
579{
580 if (!ioread32(p->ring_csr_addr + CLKEN_ADDR))
581 return false;
582
583 if (ioread32(p->ring_csr_addr + SRST_ADDR))
584 return false;
585
586 return true;
587}
588
589static int xgene_enet_reset(struct xgene_enet_pdata *pdata)
579{ 590{
580 u32 val; 591 u32 val;
581 592
593 if (!xgene_ring_mgr_init(pdata))
594 return -ENODEV;
595
582 clk_prepare_enable(pdata->clk); 596 clk_prepare_enable(pdata->clk);
583 clk_disable_unprepare(pdata->clk); 597 clk_disable_unprepare(pdata->clk);
584 clk_prepare_enable(pdata->clk); 598 clk_prepare_enable(pdata->clk);
@@ -590,6 +604,8 @@ static void xgene_enet_reset(struct xgene_enet_pdata *pdata)
590 val |= SCAN_AUTO_INCR; 604 val |= SCAN_AUTO_INCR;
591 MGMT_CLOCK_SEL_SET(&val, 1); 605 MGMT_CLOCK_SEL_SET(&val, 1);
592 xgene_enet_wr_mcx_mac(pdata, MII_MGMT_CONFIG_ADDR, val); 606 xgene_enet_wr_mcx_mac(pdata, MII_MGMT_CONFIG_ADDR, val);
607
608 return 0;
593} 609}
594 610
595static void xgene_gport_shutdown(struct xgene_enet_pdata *pdata) 611static void xgene_gport_shutdown(struct xgene_enet_pdata *pdata)
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h
index 38558584080e..ec45f3256f0e 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.h
@@ -104,6 +104,9 @@ enum xgene_enet_rm {
104#define BLOCK_ETH_MAC_OFFSET 0x0000 104#define BLOCK_ETH_MAC_OFFSET 0x0000
105#define BLOCK_ETH_MAC_CSR_OFFSET 0x2800 105#define BLOCK_ETH_MAC_CSR_OFFSET 0x2800
106 106
107#define CLKEN_ADDR 0xc208
108#define SRST_ADDR 0xc200
109
107#define MAC_ADDR_REG_OFFSET 0x00 110#define MAC_ADDR_REG_OFFSET 0x00
108#define MAC_COMMAND_REG_OFFSET 0x04 111#define MAC_COMMAND_REG_OFFSET 0x04
109#define MAC_WRITE_REG_OFFSET 0x08 112#define MAC_WRITE_REG_OFFSET 0x08
@@ -318,6 +321,7 @@ void xgene_enet_parse_error(struct xgene_enet_desc_ring *ring,
318 321
319int xgene_enet_mdio_config(struct xgene_enet_pdata *pdata); 322int xgene_enet_mdio_config(struct xgene_enet_pdata *pdata);
320void xgene_enet_mdio_remove(struct xgene_enet_pdata *pdata); 323void xgene_enet_mdio_remove(struct xgene_enet_pdata *pdata);
324bool xgene_ring_mgr_init(struct xgene_enet_pdata *p);
321 325
322extern struct xgene_mac_ops xgene_gmac_ops; 326extern struct xgene_mac_ops xgene_gmac_ops;
323extern struct xgene_port_ops xgene_gport_ops; 327extern struct xgene_port_ops xgene_gport_ops;
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
index 3c208cc6f6bb..123669696184 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c
@@ -639,9 +639,9 @@ static int xgene_enet_create_desc_rings(struct net_device *ndev)
639 struct device *dev = ndev_to_dev(ndev); 639 struct device *dev = ndev_to_dev(ndev);
640 struct xgene_enet_desc_ring *rx_ring, *tx_ring, *cp_ring; 640 struct xgene_enet_desc_ring *rx_ring, *tx_ring, *cp_ring;
641 struct xgene_enet_desc_ring *buf_pool = NULL; 641 struct xgene_enet_desc_ring *buf_pool = NULL;
642 u8 cpu_bufnum = 0, eth_bufnum = 0; 642 u8 cpu_bufnum = 0, eth_bufnum = START_ETH_BUFNUM;
643 u8 bp_bufnum = 0x20; 643 u8 bp_bufnum = START_BP_BUFNUM;
644 u16 ring_id, ring_num = 0; 644 u16 ring_id, ring_num = START_RING_NUM;
645 int ret; 645 int ret;
646 646
647 /* allocate rx descriptor ring */ 647 /* allocate rx descriptor ring */
@@ -852,7 +852,9 @@ static int xgene_enet_init_hw(struct xgene_enet_pdata *pdata)
852 u16 dst_ring_num; 852 u16 dst_ring_num;
853 int ret; 853 int ret;
854 854
855 pdata->port_ops->reset(pdata); 855 ret = pdata->port_ops->reset(pdata);
856 if (ret)
857 return ret;
856 858
857 ret = xgene_enet_create_desc_rings(ndev); 859 ret = xgene_enet_create_desc_rings(ndev);
858 if (ret) { 860 if (ret) {
@@ -954,6 +956,7 @@ static int xgene_enet_probe(struct platform_device *pdev)
954 956
955 return ret; 957 return ret;
956err: 958err:
959 unregister_netdev(ndev);
957 free_netdev(ndev); 960 free_netdev(ndev);
958 return ret; 961 return ret;
959} 962}
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.h b/drivers/net/ethernet/apm/xgene/xgene_enet_main.h
index 874e5a01161f..f9958fae6ffd 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.h
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.h
@@ -38,6 +38,9 @@
38#define SKB_BUFFER_SIZE (XGENE_ENET_MAX_MTU - NET_IP_ALIGN) 38#define SKB_BUFFER_SIZE (XGENE_ENET_MAX_MTU - NET_IP_ALIGN)
39#define NUM_PKT_BUF 64 39#define NUM_PKT_BUF 64
40#define NUM_BUFPOOL 32 40#define NUM_BUFPOOL 32
41#define START_ETH_BUFNUM 2
42#define START_BP_BUFNUM 0x22
43#define START_RING_NUM 8
41 44
42#define PHY_POLL_LINK_ON (10 * HZ) 45#define PHY_POLL_LINK_ON (10 * HZ)
43#define PHY_POLL_LINK_OFF (PHY_POLL_LINK_ON / 5) 46#define PHY_POLL_LINK_OFF (PHY_POLL_LINK_ON / 5)
@@ -83,7 +86,7 @@ struct xgene_mac_ops {
83}; 86};
84 87
85struct xgene_port_ops { 88struct xgene_port_ops {
86 void (*reset)(struct xgene_enet_pdata *pdata); 89 int (*reset)(struct xgene_enet_pdata *pdata);
87 void (*cle_bypass)(struct xgene_enet_pdata *pdata, 90 void (*cle_bypass)(struct xgene_enet_pdata *pdata,
88 u32 dst_ring_num, u16 bufpool_id); 91 u32 dst_ring_num, u16 bufpool_id);
89 void (*shutdown)(struct xgene_enet_pdata *pdata); 92 void (*shutdown)(struct xgene_enet_pdata *pdata);
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_sgmac.c b/drivers/net/ethernet/apm/xgene/xgene_enet_sgmac.c
index c22f32622fa9..f5d4f68c288c 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_sgmac.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_sgmac.c
@@ -311,14 +311,19 @@ static void xgene_sgmac_tx_disable(struct xgene_enet_pdata *p)
311 xgene_sgmac_rxtx(p, TX_EN, false); 311 xgene_sgmac_rxtx(p, TX_EN, false);
312} 312}
313 313
314static void xgene_enet_reset(struct xgene_enet_pdata *p) 314static int xgene_enet_reset(struct xgene_enet_pdata *p)
315{ 315{
316 if (!xgene_ring_mgr_init(p))
317 return -ENODEV;
318
316 clk_prepare_enable(p->clk); 319 clk_prepare_enable(p->clk);
317 clk_disable_unprepare(p->clk); 320 clk_disable_unprepare(p->clk);
318 clk_prepare_enable(p->clk); 321 clk_prepare_enable(p->clk);
319 322
320 xgene_enet_ecc_init(p); 323 xgene_enet_ecc_init(p);
321 xgene_enet_config_ring_if_assoc(p); 324 xgene_enet_config_ring_if_assoc(p);
325
326 return 0;
322} 327}
323 328
324static void xgene_enet_cle_bypass(struct xgene_enet_pdata *p, 329static void xgene_enet_cle_bypass(struct xgene_enet_pdata *p,
diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c b/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c
index 67d07206b3c7..a18a9d1f1143 100644
--- a/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c
+++ b/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c
@@ -252,14 +252,19 @@ static void xgene_xgmac_tx_disable(struct xgene_enet_pdata *pdata)
252 xgene_enet_wr_mac(pdata, AXGMAC_CONFIG_1, data & ~HSTTFEN); 252 xgene_enet_wr_mac(pdata, AXGMAC_CONFIG_1, data & ~HSTTFEN);
253} 253}
254 254
255static void xgene_enet_reset(struct xgene_enet_pdata *pdata) 255static int xgene_enet_reset(struct xgene_enet_pdata *pdata)
256{ 256{
257 if (!xgene_ring_mgr_init(pdata))
258 return -ENODEV;
259
257 clk_prepare_enable(pdata->clk); 260 clk_prepare_enable(pdata->clk);
258 clk_disable_unprepare(pdata->clk); 261 clk_disable_unprepare(pdata->clk);
259 clk_prepare_enable(pdata->clk); 262 clk_prepare_enable(pdata->clk);
260 263
261 xgene_enet_ecc_init(pdata); 264 xgene_enet_ecc_init(pdata);
262 xgene_enet_config_ring_if_assoc(pdata); 265 xgene_enet_config_ring_if_assoc(pdata);
266
267 return 0;
263} 268}
264 269
265static void xgene_enet_xgcle_bypass(struct xgene_enet_pdata *pdata, 270static void xgene_enet_xgcle_bypass(struct xgene_enet_pdata *pdata,
diff --git a/drivers/net/ethernet/broadcom/bcmsysport.c b/drivers/net/ethernet/broadcom/bcmsysport.c
index 3a6778a667f4..531bb7c57531 100644
--- a/drivers/net/ethernet/broadcom/bcmsysport.c
+++ b/drivers/net/ethernet/broadcom/bcmsysport.c
@@ -1110,7 +1110,8 @@ static int bcm_sysport_init_tx_ring(struct bcm_sysport_priv *priv,
1110 /* We just need one DMA descriptor which is DMA-able, since writing to 1110 /* We just need one DMA descriptor which is DMA-able, since writing to
1111 * the port will allocate a new descriptor in its internal linked-list 1111 * the port will allocate a new descriptor in its internal linked-list
1112 */ 1112 */
1113 p = dma_zalloc_coherent(kdev, 1, &ring->desc_dma, GFP_KERNEL); 1113 p = dma_zalloc_coherent(kdev, sizeof(struct dma_desc), &ring->desc_dma,
1114 GFP_KERNEL);
1114 if (!p) { 1115 if (!p) {
1115 netif_err(priv, hw, priv->netdev, "DMA alloc failed\n"); 1116 netif_err(priv, hw, priv->netdev, "DMA alloc failed\n");
1116 return -ENOMEM; 1117 return -ENOMEM;
@@ -1174,6 +1175,13 @@ static void bcm_sysport_fini_tx_ring(struct bcm_sysport_priv *priv,
1174 if (!(reg & TDMA_DISABLED)) 1175 if (!(reg & TDMA_DISABLED))
1175 netdev_warn(priv->netdev, "TDMA not stopped!\n"); 1176 netdev_warn(priv->netdev, "TDMA not stopped!\n");
1176 1177
1178 /* ring->cbs is the last part in bcm_sysport_init_tx_ring which could
1179 * fail, so by checking this pointer we know whether the TX ring was
1180 * fully initialized or not.
1181 */
1182 if (!ring->cbs)
1183 return;
1184
1177 napi_disable(&ring->napi); 1185 napi_disable(&ring->napi);
1178 netif_napi_del(&ring->napi); 1186 netif_napi_del(&ring->napi);
1179 1187
@@ -1183,7 +1191,8 @@ static void bcm_sysport_fini_tx_ring(struct bcm_sysport_priv *priv,
1183 ring->cbs = NULL; 1191 ring->cbs = NULL;
1184 1192
1185 if (ring->desc_dma) { 1193 if (ring->desc_dma) {
1186 dma_free_coherent(kdev, 1, ring->desc_cpu, ring->desc_dma); 1194 dma_free_coherent(kdev, sizeof(struct dma_desc),
1195 ring->desc_cpu, ring->desc_dma);
1187 ring->desc_dma = 0; 1196 ring->desc_dma = 0;
1188 } 1197 }
1189 ring->size = 0; 1198 ring->size = 0;
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index fdc9ec09e453..da1a2500c91c 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -2140,6 +2140,12 @@ static int bcmgenet_open(struct net_device *dev)
2140 goto err_irq0; 2140 goto err_irq0;
2141 } 2141 }
2142 2142
2143 /* Re-configure the port multiplexer towards the PHY device */
2144 bcmgenet_mii_config(priv->dev, false);
2145
2146 phy_connect_direct(dev, priv->phydev, bcmgenet_mii_setup,
2147 priv->phy_interface);
2148
2143 bcmgenet_netif_start(dev); 2149 bcmgenet_netif_start(dev);
2144 2150
2145 return 0; 2151 return 0;
@@ -2184,6 +2190,9 @@ static int bcmgenet_close(struct net_device *dev)
2184 2190
2185 bcmgenet_netif_stop(dev); 2191 bcmgenet_netif_stop(dev);
2186 2192
2193 /* Really kill the PHY state machine and disconnect from it */
2194 phy_disconnect(priv->phydev);
2195
2187 /* Disable MAC receive */ 2196 /* Disable MAC receive */
2188 umac_enable_set(priv, CMD_RX_EN, false); 2197 umac_enable_set(priv, CMD_RX_EN, false);
2189 2198
@@ -2685,7 +2694,7 @@ static int bcmgenet_resume(struct device *d)
2685 2694
2686 phy_init_hw(priv->phydev); 2695 phy_init_hw(priv->phydev);
2687 /* Speed settings must be restored */ 2696 /* Speed settings must be restored */
2688 bcmgenet_mii_config(priv->dev); 2697 bcmgenet_mii_config(priv->dev, false);
2689 2698
2690 /* disable ethernet MAC while updating its registers */ 2699 /* disable ethernet MAC while updating its registers */
2691 umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, false); 2700 umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, false);
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.h b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
index dbf524ea3b19..31b2da5f9b82 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.h
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.h
@@ -617,9 +617,10 @@ GENET_IO_MACRO(rbuf, GENET_RBUF_OFF);
617 617
618/* MDIO routines */ 618/* MDIO routines */
619int bcmgenet_mii_init(struct net_device *dev); 619int bcmgenet_mii_init(struct net_device *dev);
620int bcmgenet_mii_config(struct net_device *dev); 620int bcmgenet_mii_config(struct net_device *dev, bool init);
621void bcmgenet_mii_exit(struct net_device *dev); 621void bcmgenet_mii_exit(struct net_device *dev);
622void bcmgenet_mii_reset(struct net_device *dev); 622void bcmgenet_mii_reset(struct net_device *dev);
623void bcmgenet_mii_setup(struct net_device *dev);
623 624
624/* Wake-on-LAN routines */ 625/* Wake-on-LAN routines */
625void bcmgenet_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol); 626void bcmgenet_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol);
diff --git a/drivers/net/ethernet/broadcom/genet/bcmmii.c b/drivers/net/ethernet/broadcom/genet/bcmmii.c
index 9ff799a9f801..933cd7e7cd33 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmmii.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmmii.c
@@ -77,7 +77,7 @@ static int bcmgenet_mii_write(struct mii_bus *bus, int phy_id,
77/* setup netdev link state when PHY link status change and 77/* setup netdev link state when PHY link status change and
78 * update UMAC and RGMII block when link up 78 * update UMAC and RGMII block when link up
79 */ 79 */
80static void bcmgenet_mii_setup(struct net_device *dev) 80void bcmgenet_mii_setup(struct net_device *dev)
81{ 81{
82 struct bcmgenet_priv *priv = netdev_priv(dev); 82 struct bcmgenet_priv *priv = netdev_priv(dev);
83 struct phy_device *phydev = priv->phydev; 83 struct phy_device *phydev = priv->phydev;
@@ -211,7 +211,7 @@ static void bcmgenet_moca_phy_setup(struct bcmgenet_priv *priv)
211 bcmgenet_sys_writel(priv, reg, SYS_PORT_CTRL); 211 bcmgenet_sys_writel(priv, reg, SYS_PORT_CTRL);
212} 212}
213 213
214int bcmgenet_mii_config(struct net_device *dev) 214int bcmgenet_mii_config(struct net_device *dev, bool init)
215{ 215{
216 struct bcmgenet_priv *priv = netdev_priv(dev); 216 struct bcmgenet_priv *priv = netdev_priv(dev);
217 struct phy_device *phydev = priv->phydev; 217 struct phy_device *phydev = priv->phydev;
@@ -298,7 +298,8 @@ int bcmgenet_mii_config(struct net_device *dev)
298 return -EINVAL; 298 return -EINVAL;
299 } 299 }
300 300
301 dev_info(kdev, "configuring instance for %s\n", phy_name); 301 if (init)
302 dev_info(kdev, "configuring instance for %s\n", phy_name);
302 303
303 return 0; 304 return 0;
304} 305}
@@ -350,7 +351,7 @@ static int bcmgenet_mii_probe(struct net_device *dev)
350 * PHY speed which is needed for bcmgenet_mii_config() to configure 351 * PHY speed which is needed for bcmgenet_mii_config() to configure
351 * things appropriately. 352 * things appropriately.
352 */ 353 */
353 ret = bcmgenet_mii_config(dev); 354 ret = bcmgenet_mii_config(dev, true);
354 if (ret) { 355 if (ret) {
355 phy_disconnect(priv->phydev); 356 phy_disconnect(priv->phydev);
356 return ret; 357 return ret;
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index dbb41c1923e6..77f8f836cbbe 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -8563,7 +8563,8 @@ static int tg3_init_rings(struct tg3 *tp)
8563 if (tnapi->rx_rcb) 8563 if (tnapi->rx_rcb)
8564 memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp)); 8564 memset(tnapi->rx_rcb, 0, TG3_RX_RCB_RING_BYTES(tp));
8565 8565
8566 if (tg3_rx_prodring_alloc(tp, &tnapi->prodring)) { 8566 if (tnapi->prodring.rx_std &&
8567 tg3_rx_prodring_alloc(tp, &tnapi->prodring)) {
8567 tg3_free_rings(tp); 8568 tg3_free_rings(tp);
8568 return -ENOMEM; 8569 return -ENOMEM;
8569 } 8570 }
diff --git a/drivers/net/ethernet/cadence/Kconfig b/drivers/net/ethernet/cadence/Kconfig
index 9e089d24466e..3564fe9d3f69 100644
--- a/drivers/net/ethernet/cadence/Kconfig
+++ b/drivers/net/ethernet/cadence/Kconfig
@@ -22,7 +22,7 @@ if NET_CADENCE
22 22
23config ARM_AT91_ETHER 23config ARM_AT91_ETHER
24 tristate "AT91RM9200 Ethernet support" 24 tristate "AT91RM9200 Ethernet support"
25 depends on HAS_DMA && (ARCH_AT91RM9200 || COMPILE_TEST) 25 depends on HAS_DMA && (ARCH_AT91 || COMPILE_TEST)
26 select MACB 26 select MACB
27 ---help--- 27 ---help---
28 If you wish to compile a kernel for the AT91RM9200 and enable 28 If you wish to compile a kernel for the AT91RM9200 and enable
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c
index 6fe300e316c3..4fe33606f372 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_dcb.c
@@ -79,8 +79,9 @@ static void cxgb4_dcb_cleanup_apps(struct net_device *dev)
79 app.protocol = dcb->app_priority[i].protocolid; 79 app.protocol = dcb->app_priority[i].protocolid;
80 80
81 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE) { 81 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE) {
82 app.priority = dcb->app_priority[i].user_prio_map;
82 app.selector = dcb->app_priority[i].sel_field + 1; 83 app.selector = dcb->app_priority[i].sel_field + 1;
83 err = dcb_ieee_setapp(dev, &app); 84 err = dcb_ieee_delapp(dev, &app);
84 } else { 85 } else {
85 app.selector = !!(dcb->app_priority[i].sel_field); 86 app.selector = !!(dcb->app_priority[i].sel_field);
86 err = dcb_setapp(dev, &app); 87 err = dcb_setapp(dev, &app);
@@ -122,7 +123,11 @@ void cxgb4_dcb_state_fsm(struct net_device *dev,
122 case CXGB4_DCB_INPUT_FW_ENABLED: { 123 case CXGB4_DCB_INPUT_FW_ENABLED: {
123 /* we're going to use Firmware DCB */ 124 /* we're going to use Firmware DCB */
124 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE; 125 dcb->state = CXGB4_DCB_STATE_FW_INCOMPLETE;
125 dcb->supported = CXGB4_DCBX_FW_SUPPORT; 126 dcb->supported = DCB_CAP_DCBX_LLD_MANAGED;
127 if (dcb->dcb_version == FW_PORT_DCB_VER_IEEE)
128 dcb->supported |= DCB_CAP_DCBX_VER_IEEE;
129 else
130 dcb->supported |= DCB_CAP_DCBX_VER_CEE;
126 break; 131 break;
127 } 132 }
128 133
@@ -436,14 +441,17 @@ static void cxgb4_getpgtccfg(struct net_device *dev, int tc,
436 *up_tc_map = (1 << tc); 441 *up_tc_map = (1 << tc);
437 442
438 /* prio_type is link strict */ 443 /* prio_type is link strict */
439 *prio_type = 0x2; 444 if (*pgid != 0xF)
445 *prio_type = 0x2;
440} 446}
441 447
442static void cxgb4_getpgtccfg_tx(struct net_device *dev, int tc, 448static void cxgb4_getpgtccfg_tx(struct net_device *dev, int tc,
443 u8 *prio_type, u8 *pgid, u8 *bw_per, 449 u8 *prio_type, u8 *pgid, u8 *bw_per,
444 u8 *up_tc_map) 450 u8 *up_tc_map)
445{ 451{
446 return cxgb4_getpgtccfg(dev, tc, prio_type, pgid, bw_per, up_tc_map, 1); 452 /* tc 0 is written at MSB position */
453 return cxgb4_getpgtccfg(dev, (7 - tc), prio_type, pgid, bw_per,
454 up_tc_map, 1);
447} 455}
448 456
449 457
@@ -451,7 +459,9 @@ static void cxgb4_getpgtccfg_rx(struct net_device *dev, int tc,
451 u8 *prio_type, u8 *pgid, u8 *bw_per, 459 u8 *prio_type, u8 *pgid, u8 *bw_per,
452 u8 *up_tc_map) 460 u8 *up_tc_map)
453{ 461{
454 return cxgb4_getpgtccfg(dev, tc, prio_type, pgid, bw_per, up_tc_map, 0); 462 /* tc 0 is written at MSB position */
463 return cxgb4_getpgtccfg(dev, (7 - tc), prio_type, pgid, bw_per,
464 up_tc_map, 0);
455} 465}
456 466
457static void cxgb4_setpgtccfg_tx(struct net_device *dev, int tc, 467static void cxgb4_setpgtccfg_tx(struct net_device *dev, int tc,
@@ -461,6 +471,7 @@ static void cxgb4_setpgtccfg_tx(struct net_device *dev, int tc,
461 struct fw_port_cmd pcmd; 471 struct fw_port_cmd pcmd;
462 struct port_info *pi = netdev2pinfo(dev); 472 struct port_info *pi = netdev2pinfo(dev);
463 struct adapter *adap = pi->adapter; 473 struct adapter *adap = pi->adapter;
474 int fw_tc = 7 - tc;
464 u32 _pgid; 475 u32 _pgid;
465 int err; 476 int err;
466 477
@@ -479,8 +490,8 @@ static void cxgb4_setpgtccfg_tx(struct net_device *dev, int tc,
479 } 490 }
480 491
481 _pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid); 492 _pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
482 _pgid &= ~(0xF << (tc * 4)); 493 _pgid &= ~(0xF << (fw_tc * 4));
483 _pgid |= pgid << (tc * 4); 494 _pgid |= pgid << (fw_tc * 4);
484 pcmd.u.dcb.pgid.pgid = cpu_to_be32(_pgid); 495 pcmd.u.dcb.pgid.pgid = cpu_to_be32(_pgid);
485 496
486 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id); 497 INIT_PORT_DCB_WRITE_CMD(pcmd, pi->port_id);
@@ -593,7 +604,7 @@ static void cxgb4_getpfccfg(struct net_device *dev, int priority, u8 *pfccfg)
593 priority >= CXGB4_MAX_PRIORITY) 604 priority >= CXGB4_MAX_PRIORITY)
594 *pfccfg = 0; 605 *pfccfg = 0;
595 else 606 else
596 *pfccfg = (pi->dcb.pfcen >> priority) & 1; 607 *pfccfg = (pi->dcb.pfcen >> (7 - priority)) & 1;
597} 608}
598 609
599/* Enable/disable Priority Pause Frames for the specified Traffic Class 610/* Enable/disable Priority Pause Frames for the specified Traffic Class
@@ -618,9 +629,9 @@ static void cxgb4_setpfccfg(struct net_device *dev, int priority, u8 pfccfg)
618 pcmd.u.dcb.pfc.pfcen = pi->dcb.pfcen; 629 pcmd.u.dcb.pfc.pfcen = pi->dcb.pfcen;
619 630
620 if (pfccfg) 631 if (pfccfg)
621 pcmd.u.dcb.pfc.pfcen |= (1 << priority); 632 pcmd.u.dcb.pfc.pfcen |= (1 << (7 - priority));
622 else 633 else
623 pcmd.u.dcb.pfc.pfcen &= (~(1 << priority)); 634 pcmd.u.dcb.pfc.pfcen &= (~(1 << (7 - priority)));
624 635
625 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd); 636 err = t4_wr_mbox(adap, adap->mbox, &pcmd, sizeof(pcmd), &pcmd);
626 if (err != FW_PORT_DCB_CFG_SUCCESS) { 637 if (err != FW_PORT_DCB_CFG_SUCCESS) {
@@ -1071,7 +1082,7 @@ static int cxgb4_cee_peer_getpg(struct net_device *dev, struct cee_pg *pg)
1071 pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid); 1082 pgid = be32_to_cpu(pcmd.u.dcb.pgid.pgid);
1072 1083
1073 for (i = 0; i < CXGB4_MAX_PRIORITY; i++) 1084 for (i = 0; i < CXGB4_MAX_PRIORITY; i++)
1074 pg->prio_pg[i] = (pgid >> (i * 4)) & 0xF; 1085 pg->prio_pg[7 - i] = (pgid >> (i * 4)) & 0xF;
1075 1086
1076 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id); 1087 INIT_PORT_DCB_READ_PEER_CMD(pcmd, pi->port_id);
1077 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE; 1088 pcmd.u.dcb.pgrate.type = FW_PORT_DCB_TYPE_PGRATE;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
index 8520d5529df8..279873cb6e3a 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
@@ -2442,9 +2442,13 @@ static unsigned int from_fw_linkcaps(unsigned int type, unsigned int caps)
2442 SUPPORTED_10000baseKR_Full | SUPPORTED_1000baseKX_Full | 2442 SUPPORTED_10000baseKR_Full | SUPPORTED_1000baseKX_Full |
2443 SUPPORTED_10000baseKX4_Full; 2443 SUPPORTED_10000baseKX4_Full;
2444 else if (type == FW_PORT_TYPE_FIBER_XFI || 2444 else if (type == FW_PORT_TYPE_FIBER_XFI ||
2445 type == FW_PORT_TYPE_FIBER_XAUI || type == FW_PORT_TYPE_SFP) 2445 type == FW_PORT_TYPE_FIBER_XAUI || type == FW_PORT_TYPE_SFP) {
2446 v |= SUPPORTED_FIBRE; 2446 v |= SUPPORTED_FIBRE;
2447 else if (type == FW_PORT_TYPE_BP40_BA) 2447 if (caps & FW_PORT_CAP_SPEED_1G)
2448 v |= SUPPORTED_1000baseT_Full;
2449 if (caps & FW_PORT_CAP_SPEED_10G)
2450 v |= SUPPORTED_10000baseT_Full;
2451 } else if (type == FW_PORT_TYPE_BP40_BA)
2448 v |= SUPPORTED_40000baseSR4_Full; 2452 v |= SUPPORTED_40000baseSR4_Full;
2449 2453
2450 if (caps & FW_PORT_CAP_ANEG) 2454 if (caps & FW_PORT_CAP_ANEG)
diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
index 5e1b314e11af..39f2b13e66c7 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
@@ -2914,7 +2914,8 @@ static int t4_sge_init_hard(struct adapter *adap)
2914int t4_sge_init(struct adapter *adap) 2914int t4_sge_init(struct adapter *adap)
2915{ 2915{
2916 struct sge *s = &adap->sge; 2916 struct sge *s = &adap->sge;
2917 u32 sge_control, sge_conm_ctrl; 2917 u32 sge_control, sge_control2, sge_conm_ctrl;
2918 unsigned int ingpadboundary, ingpackboundary;
2918 int ret, egress_threshold; 2919 int ret, egress_threshold;
2919 2920
2920 /* 2921 /*
@@ -2924,8 +2925,31 @@ int t4_sge_init(struct adapter *adap)
2924 sge_control = t4_read_reg(adap, SGE_CONTROL); 2925 sge_control = t4_read_reg(adap, SGE_CONTROL);
2925 s->pktshift = PKTSHIFT_GET(sge_control); 2926 s->pktshift = PKTSHIFT_GET(sge_control);
2926 s->stat_len = (sge_control & EGRSTATUSPAGESIZE_MASK) ? 128 : 64; 2927 s->stat_len = (sge_control & EGRSTATUSPAGESIZE_MASK) ? 128 : 64;
2927 s->fl_align = 1 << (INGPADBOUNDARY_GET(sge_control) + 2928
2928 X_INGPADBOUNDARY_SHIFT); 2929 /* T4 uses a single control field to specify both the PCIe Padding and
2930 * Packing Boundary. T5 introduced the ability to specify these
2931 * separately. The actual Ingress Packet Data alignment boundary
2932 * within Packed Buffer Mode is the maximum of these two
2933 * specifications.
2934 */
2935 ingpadboundary = 1 << (INGPADBOUNDARY_GET(sge_control) +
2936 X_INGPADBOUNDARY_SHIFT);
2937 if (is_t4(adap->params.chip)) {
2938 s->fl_align = ingpadboundary;
2939 } else {
2940 /* T5 has a different interpretation of one of the PCIe Packing
2941 * Boundary values.
2942 */
2943 sge_control2 = t4_read_reg(adap, SGE_CONTROL2_A);
2944 ingpackboundary = INGPACKBOUNDARY_G(sge_control2);
2945 if (ingpackboundary == INGPACKBOUNDARY_16B_X)
2946 ingpackboundary = 16;
2947 else
2948 ingpackboundary = 1 << (ingpackboundary +
2949 INGPACKBOUNDARY_SHIFT_X);
2950
2951 s->fl_align = max(ingpadboundary, ingpackboundary);
2952 }
2929 2953
2930 if (adap->flags & USING_SOFT_PARAMS) 2954 if (adap->flags & USING_SOFT_PARAMS)
2931 ret = t4_sge_init_soft(adap); 2955 ret = t4_sge_init_soft(adap);
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
index a9d9d74e4f09..163a2a14948c 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_hw.c
@@ -3129,12 +3129,51 @@ int t4_fixup_host_params(struct adapter *adap, unsigned int page_size,
3129 HOSTPAGESIZEPF6(sge_hps) | 3129 HOSTPAGESIZEPF6(sge_hps) |
3130 HOSTPAGESIZEPF7(sge_hps)); 3130 HOSTPAGESIZEPF7(sge_hps));
3131 3131
3132 t4_set_reg_field(adap, SGE_CONTROL, 3132 if (is_t4(adap->params.chip)) {
3133 INGPADBOUNDARY_MASK | 3133 t4_set_reg_field(adap, SGE_CONTROL,
3134 EGRSTATUSPAGESIZE_MASK, 3134 INGPADBOUNDARY_MASK |
3135 INGPADBOUNDARY(fl_align_log - 5) | 3135 EGRSTATUSPAGESIZE_MASK,
3136 EGRSTATUSPAGESIZE(stat_len != 64)); 3136 INGPADBOUNDARY(fl_align_log - 5) |
3137 3137 EGRSTATUSPAGESIZE(stat_len != 64));
3138 } else {
3139 /* T5 introduced the separation of the Free List Padding and
3140 * Packing Boundaries. Thus, we can select a smaller Padding
3141 * Boundary to avoid uselessly chewing up PCIe Link and Memory
3142 * Bandwidth, and use a Packing Boundary which is large enough
3143 * to avoid false sharing between CPUs, etc.
3144 *
3145 * For the PCI Link, the smaller the Padding Boundary the
3146 * better. For the Memory Controller, a smaller Padding
3147 * Boundary is better until we cross under the Memory Line
3148 * Size (the minimum unit of transfer to/from Memory). If we
3149 * have a Padding Boundary which is smaller than the Memory
3150 * Line Size, that'll involve a Read-Modify-Write cycle on the
3151 * Memory Controller which is never good. For T5 the smallest
3152 * Padding Boundary which we can select is 32 bytes which is
3153 * larger than any known Memory Controller Line Size so we'll
3154 * use that.
3155 *
3156 * T5 has a different interpretation of the "0" value for the
3157 * Packing Boundary. This corresponds to 16 bytes instead of
3158 * the expected 32 bytes. We never have a Packing Boundary
3159 * less than 32 bytes so we can't use that special value but
3160 * on the other hand, if we wanted 32 bytes, the best we can
3161 * really do is 64 bytes.
3162 */
3163 if (fl_align <= 32) {
3164 fl_align = 64;
3165 fl_align_log = 6;
3166 }
3167 t4_set_reg_field(adap, SGE_CONTROL,
3168 INGPADBOUNDARY_MASK |
3169 EGRSTATUSPAGESIZE_MASK,
3170 INGPADBOUNDARY(INGPCIEBOUNDARY_32B_X) |
3171 EGRSTATUSPAGESIZE(stat_len != 64));
3172 t4_set_reg_field(adap, SGE_CONTROL2_A,
3173 INGPACKBOUNDARY_V(INGPACKBOUNDARY_M),
3174 INGPACKBOUNDARY_V(fl_align_log -
3175 INGPACKBOUNDARY_SHIFT_X));
3176 }
3138 /* 3177 /*
3139 * Adjust various SGE Free List Host Buffer Sizes. 3178 * Adjust various SGE Free List Host Buffer Sizes.
3140 * 3179 *
diff --git a/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h b/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h
index a1024db5dc13..8d2de1006b08 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/t4_regs.h
@@ -95,6 +95,7 @@
95#define X_INGPADBOUNDARY_SHIFT 5 95#define X_INGPADBOUNDARY_SHIFT 5
96 96
97#define SGE_CONTROL 0x1008 97#define SGE_CONTROL 0x1008
98#define SGE_CONTROL2_A 0x1124
98#define DCASYSTYPE 0x00080000U 99#define DCASYSTYPE 0x00080000U
99#define RXPKTCPLMODE_MASK 0x00040000U 100#define RXPKTCPLMODE_MASK 0x00040000U
100#define RXPKTCPLMODE_SHIFT 18 101#define RXPKTCPLMODE_SHIFT 18
@@ -106,6 +107,7 @@
106#define PKTSHIFT_SHIFT 10 107#define PKTSHIFT_SHIFT 10
107#define PKTSHIFT(x) ((x) << PKTSHIFT_SHIFT) 108#define PKTSHIFT(x) ((x) << PKTSHIFT_SHIFT)
108#define PKTSHIFT_GET(x) (((x) & PKTSHIFT_MASK) >> PKTSHIFT_SHIFT) 109#define PKTSHIFT_GET(x) (((x) & PKTSHIFT_MASK) >> PKTSHIFT_SHIFT)
110#define INGPCIEBOUNDARY_32B_X 0
109#define INGPCIEBOUNDARY_MASK 0x00000380U 111#define INGPCIEBOUNDARY_MASK 0x00000380U
110#define INGPCIEBOUNDARY_SHIFT 7 112#define INGPCIEBOUNDARY_SHIFT 7
111#define INGPCIEBOUNDARY(x) ((x) << INGPCIEBOUNDARY_SHIFT) 113#define INGPCIEBOUNDARY(x) ((x) << INGPCIEBOUNDARY_SHIFT)
@@ -114,6 +116,14 @@
114#define INGPADBOUNDARY(x) ((x) << INGPADBOUNDARY_SHIFT) 116#define INGPADBOUNDARY(x) ((x) << INGPADBOUNDARY_SHIFT)
115#define INGPADBOUNDARY_GET(x) (((x) & INGPADBOUNDARY_MASK) \ 117#define INGPADBOUNDARY_GET(x) (((x) & INGPADBOUNDARY_MASK) \
116 >> INGPADBOUNDARY_SHIFT) 118 >> INGPADBOUNDARY_SHIFT)
119#define INGPACKBOUNDARY_16B_X 0
120#define INGPACKBOUNDARY_SHIFT_X 5
121
122#define INGPACKBOUNDARY_S 16
123#define INGPACKBOUNDARY_M 0x7U
124#define INGPACKBOUNDARY_V(x) ((x) << INGPACKBOUNDARY_S)
125#define INGPACKBOUNDARY_G(x) (((x) >> INGPACKBOUNDARY_S) \
126 & INGPACKBOUNDARY_M)
117#define EGRPCIEBOUNDARY_MASK 0x0000000eU 127#define EGRPCIEBOUNDARY_MASK 0x0000000eU
118#define EGRPCIEBOUNDARY_SHIFT 1 128#define EGRPCIEBOUNDARY_SHIFT 1
119#define EGRPCIEBOUNDARY(x) ((x) << EGRPCIEBOUNDARY_SHIFT) 129#define EGRPCIEBOUNDARY(x) ((x) << EGRPCIEBOUNDARY_SHIFT)
diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/adapter.h b/drivers/net/ethernet/chelsio/cxgb4vf/adapter.h
index 68eaa9c88c7d..3d06e77d7121 100644
--- a/drivers/net/ethernet/chelsio/cxgb4vf/adapter.h
+++ b/drivers/net/ethernet/chelsio/cxgb4vf/adapter.h
@@ -299,6 +299,14 @@ struct sge {
299 u16 timer_val[SGE_NTIMERS]; /* interrupt holdoff timer array */ 299 u16 timer_val[SGE_NTIMERS]; /* interrupt holdoff timer array */
300 u8 counter_val[SGE_NCOUNTERS]; /* interrupt RX threshold array */ 300 u8 counter_val[SGE_NCOUNTERS]; /* interrupt RX threshold array */
301 301
302 /* Decoded Adapter Parameters.
303 */
304 u32 fl_pg_order; /* large page allocation size */
305 u32 stat_len; /* length of status page at ring end */
306 u32 pktshift; /* padding between CPL & packet data */
307 u32 fl_align; /* response queue message alignment */
308 u32 fl_starve_thres; /* Free List starvation threshold */
309
302 /* 310 /*
303 * Reverse maps from Absolute Queue IDs to associated queue pointers. 311 * Reverse maps from Absolute Queue IDs to associated queue pointers.
304 * The absolute Queue IDs are in a compact range which start at a 312 * The absolute Queue IDs are in a compact range which start at a
diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
index 85036e6b42c4..fdd078d7d82c 100644
--- a/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4vf/sge.c
@@ -51,14 +51,6 @@
51#include "../cxgb4/t4_msg.h" 51#include "../cxgb4/t4_msg.h"
52 52
53/* 53/*
54 * Decoded Adapter Parameters.
55 */
56static u32 FL_PG_ORDER; /* large page allocation size */
57static u32 STAT_LEN; /* length of status page at ring end */
58static u32 PKTSHIFT; /* padding between CPL and packet data */
59static u32 FL_ALIGN; /* response queue message alignment */
60
61/*
62 * Constants ... 54 * Constants ...
63 */ 55 */
64enum { 56enum {
@@ -102,12 +94,6 @@ enum {
102 MAX_TIMER_TX_RECLAIM = 100, 94 MAX_TIMER_TX_RECLAIM = 100,
103 95
104 /* 96 /*
105 * An FL with <= FL_STARVE_THRES buffers is starving and a periodic
106 * timer will attempt to refill it.
107 */
108 FL_STARVE_THRES = 4,
109
110 /*
111 * Suspend an Ethernet TX queue with fewer available descriptors than 97 * Suspend an Ethernet TX queue with fewer available descriptors than
112 * this. We always want to have room for a maximum sized packet: 98 * this. We always want to have room for a maximum sized packet:
113 * inline immediate data + MAX_SKB_FRAGS. This is the same as 99 * inline immediate data + MAX_SKB_FRAGS. This is the same as
@@ -264,15 +250,19 @@ static inline unsigned int fl_cap(const struct sge_fl *fl)
264 250
265/** 251/**
266 * fl_starving - return whether a Free List is starving. 252 * fl_starving - return whether a Free List is starving.
253 * @adapter: pointer to the adapter
267 * @fl: the Free List 254 * @fl: the Free List
268 * 255 *
269 * Tests specified Free List to see whether the number of buffers 256 * Tests specified Free List to see whether the number of buffers
270 * available to the hardware has falled below our "starvation" 257 * available to the hardware has falled below our "starvation"
271 * threshold. 258 * threshold.
272 */ 259 */
273static inline bool fl_starving(const struct sge_fl *fl) 260static inline bool fl_starving(const struct adapter *adapter,
261 const struct sge_fl *fl)
274{ 262{
275 return fl->avail - fl->pend_cred <= FL_STARVE_THRES; 263 const struct sge *s = &adapter->sge;
264
265 return fl->avail - fl->pend_cred <= s->fl_starve_thres;
276} 266}
277 267
278/** 268/**
@@ -457,13 +447,16 @@ static inline void reclaim_completed_tx(struct adapter *adapter,
457 447
458/** 448/**
459 * get_buf_size - return the size of an RX Free List buffer. 449 * get_buf_size - return the size of an RX Free List buffer.
450 * @adapter: pointer to the associated adapter
460 * @sdesc: pointer to the software buffer descriptor 451 * @sdesc: pointer to the software buffer descriptor
461 */ 452 */
462static inline int get_buf_size(const struct rx_sw_desc *sdesc) 453static inline int get_buf_size(const struct adapter *adapter,
454 const struct rx_sw_desc *sdesc)
463{ 455{
464 return FL_PG_ORDER > 0 && (sdesc->dma_addr & RX_LARGE_BUF) 456 const struct sge *s = &adapter->sge;
465 ? (PAGE_SIZE << FL_PG_ORDER) 457
466 : PAGE_SIZE; 458 return (s->fl_pg_order > 0 && (sdesc->dma_addr & RX_LARGE_BUF)
459 ? (PAGE_SIZE << s->fl_pg_order) : PAGE_SIZE);
467} 460}
468 461
469/** 462/**
@@ -483,7 +476,8 @@ static void free_rx_bufs(struct adapter *adapter, struct sge_fl *fl, int n)
483 476
484 if (is_buf_mapped(sdesc)) 477 if (is_buf_mapped(sdesc))
485 dma_unmap_page(adapter->pdev_dev, get_buf_addr(sdesc), 478 dma_unmap_page(adapter->pdev_dev, get_buf_addr(sdesc),
486 get_buf_size(sdesc), PCI_DMA_FROMDEVICE); 479 get_buf_size(adapter, sdesc),
480 PCI_DMA_FROMDEVICE);
487 put_page(sdesc->page); 481 put_page(sdesc->page);
488 sdesc->page = NULL; 482 sdesc->page = NULL;
489 if (++fl->cidx == fl->size) 483 if (++fl->cidx == fl->size)
@@ -511,7 +505,8 @@ static void unmap_rx_buf(struct adapter *adapter, struct sge_fl *fl)
511 505
512 if (is_buf_mapped(sdesc)) 506 if (is_buf_mapped(sdesc))
513 dma_unmap_page(adapter->pdev_dev, get_buf_addr(sdesc), 507 dma_unmap_page(adapter->pdev_dev, get_buf_addr(sdesc),
514 get_buf_size(sdesc), PCI_DMA_FROMDEVICE); 508 get_buf_size(adapter, sdesc),
509 PCI_DMA_FROMDEVICE);
515 sdesc->page = NULL; 510 sdesc->page = NULL;
516 if (++fl->cidx == fl->size) 511 if (++fl->cidx == fl->size)
517 fl->cidx = 0; 512 fl->cidx = 0;
@@ -589,6 +584,7 @@ static inline void poison_buf(struct page *page, size_t sz)
589static unsigned int refill_fl(struct adapter *adapter, struct sge_fl *fl, 584static unsigned int refill_fl(struct adapter *adapter, struct sge_fl *fl,
590 int n, gfp_t gfp) 585 int n, gfp_t gfp)
591{ 586{
587 struct sge *s = &adapter->sge;
592 struct page *page; 588 struct page *page;
593 dma_addr_t dma_addr; 589 dma_addr_t dma_addr;
594 unsigned int cred = fl->avail; 590 unsigned int cred = fl->avail;
@@ -608,12 +604,12 @@ static unsigned int refill_fl(struct adapter *adapter, struct sge_fl *fl,
608 * If we don't support large pages, drop directly into the small page 604 * If we don't support large pages, drop directly into the small page
609 * allocation code. 605 * allocation code.
610 */ 606 */
611 if (FL_PG_ORDER == 0) 607 if (s->fl_pg_order == 0)
612 goto alloc_small_pages; 608 goto alloc_small_pages;
613 609
614 while (n) { 610 while (n) {
615 page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN, 611 page = alloc_pages(gfp | __GFP_COMP | __GFP_NOWARN,
616 FL_PG_ORDER); 612 s->fl_pg_order);
617 if (unlikely(!page)) { 613 if (unlikely(!page)) {
618 /* 614 /*
619 * We've failed inour attempt to allocate a "large 615 * We've failed inour attempt to allocate a "large
@@ -623,10 +619,10 @@ static unsigned int refill_fl(struct adapter *adapter, struct sge_fl *fl,
623 fl->large_alloc_failed++; 619 fl->large_alloc_failed++;
624 break; 620 break;
625 } 621 }
626 poison_buf(page, PAGE_SIZE << FL_PG_ORDER); 622 poison_buf(page, PAGE_SIZE << s->fl_pg_order);
627 623
628 dma_addr = dma_map_page(adapter->pdev_dev, page, 0, 624 dma_addr = dma_map_page(adapter->pdev_dev, page, 0,
629 PAGE_SIZE << FL_PG_ORDER, 625 PAGE_SIZE << s->fl_pg_order,
630 PCI_DMA_FROMDEVICE); 626 PCI_DMA_FROMDEVICE);
631 if (unlikely(dma_mapping_error(adapter->pdev_dev, dma_addr))) { 627 if (unlikely(dma_mapping_error(adapter->pdev_dev, dma_addr))) {
632 /* 628 /*
@@ -637,7 +633,7 @@ static unsigned int refill_fl(struct adapter *adapter, struct sge_fl *fl,
637 * because DMA mapping resources are typically 633 * because DMA mapping resources are typically
638 * critical resources once they become scarse. 634 * critical resources once they become scarse.
639 */ 635 */
640 __free_pages(page, FL_PG_ORDER); 636 __free_pages(page, s->fl_pg_order);
641 goto out; 637 goto out;
642 } 638 }
643 dma_addr |= RX_LARGE_BUF; 639 dma_addr |= RX_LARGE_BUF;
@@ -693,7 +689,7 @@ out:
693 fl->pend_cred += cred; 689 fl->pend_cred += cred;
694 ring_fl_db(adapter, fl); 690 ring_fl_db(adapter, fl);
695 691
696 if (unlikely(fl_starving(fl))) { 692 if (unlikely(fl_starving(adapter, fl))) {
697 smp_wmb(); 693 smp_wmb();
698 set_bit(fl->cntxt_id, adapter->sge.starving_fl); 694 set_bit(fl->cntxt_id, adapter->sge.starving_fl);
699 } 695 }
@@ -1468,6 +1464,8 @@ static void t4vf_pktgl_free(const struct pkt_gl *gl)
1468static void do_gro(struct sge_eth_rxq *rxq, const struct pkt_gl *gl, 1464static void do_gro(struct sge_eth_rxq *rxq, const struct pkt_gl *gl,
1469 const struct cpl_rx_pkt *pkt) 1465 const struct cpl_rx_pkt *pkt)
1470{ 1466{
1467 struct adapter *adapter = rxq->rspq.adapter;
1468 struct sge *s = &adapter->sge;
1471 int ret; 1469 int ret;
1472 struct sk_buff *skb; 1470 struct sk_buff *skb;
1473 1471
@@ -1478,8 +1476,8 @@ static void do_gro(struct sge_eth_rxq *rxq, const struct pkt_gl *gl,
1478 return; 1476 return;
1479 } 1477 }
1480 1478
1481 copy_frags(skb, gl, PKTSHIFT); 1479 copy_frags(skb, gl, s->pktshift);
1482 skb->len = gl->tot_len - PKTSHIFT; 1480 skb->len = gl->tot_len - s->pktshift;
1483 skb->data_len = skb->len; 1481 skb->data_len = skb->len;
1484 skb->truesize += skb->data_len; 1482 skb->truesize += skb->data_len;
1485 skb->ip_summed = CHECKSUM_UNNECESSARY; 1483 skb->ip_summed = CHECKSUM_UNNECESSARY;
@@ -1516,6 +1514,8 @@ int t4vf_ethrx_handler(struct sge_rspq *rspq, const __be64 *rsp,
1516 bool csum_ok = pkt->csum_calc && !pkt->err_vec && 1514 bool csum_ok = pkt->csum_calc && !pkt->err_vec &&
1517 (rspq->netdev->features & NETIF_F_RXCSUM); 1515 (rspq->netdev->features & NETIF_F_RXCSUM);
1518 struct sge_eth_rxq *rxq = container_of(rspq, struct sge_eth_rxq, rspq); 1516 struct sge_eth_rxq *rxq = container_of(rspq, struct sge_eth_rxq, rspq);
1517 struct adapter *adapter = rspq->adapter;
1518 struct sge *s = &adapter->sge;
1519 1519
1520 /* 1520 /*
1521 * If this is a good TCP packet and we have Generic Receive Offload 1521 * If this is a good TCP packet and we have Generic Receive Offload
@@ -1537,7 +1537,7 @@ int t4vf_ethrx_handler(struct sge_rspq *rspq, const __be64 *rsp,
1537 rxq->stats.rx_drops++; 1537 rxq->stats.rx_drops++;
1538 return 0; 1538 return 0;
1539 } 1539 }
1540 __skb_pull(skb, PKTSHIFT); 1540 __skb_pull(skb, s->pktshift);
1541 skb->protocol = eth_type_trans(skb, rspq->netdev); 1541 skb->protocol = eth_type_trans(skb, rspq->netdev);
1542 skb_record_rx_queue(skb, rspq->idx); 1542 skb_record_rx_queue(skb, rspq->idx);
1543 rxq->stats.pkts++; 1543 rxq->stats.pkts++;
@@ -1648,6 +1648,8 @@ static inline void rspq_next(struct sge_rspq *rspq)
1648static int process_responses(struct sge_rspq *rspq, int budget) 1648static int process_responses(struct sge_rspq *rspq, int budget)
1649{ 1649{
1650 struct sge_eth_rxq *rxq = container_of(rspq, struct sge_eth_rxq, rspq); 1650 struct sge_eth_rxq *rxq = container_of(rspq, struct sge_eth_rxq, rspq);
1651 struct adapter *adapter = rspq->adapter;
1652 struct sge *s = &adapter->sge;
1651 int budget_left = budget; 1653 int budget_left = budget;
1652 1654
1653 while (likely(budget_left)) { 1655 while (likely(budget_left)) {
@@ -1697,7 +1699,7 @@ static int process_responses(struct sge_rspq *rspq, int budget)
1697 BUG_ON(frag >= MAX_SKB_FRAGS); 1699 BUG_ON(frag >= MAX_SKB_FRAGS);
1698 BUG_ON(rxq->fl.avail == 0); 1700 BUG_ON(rxq->fl.avail == 0);
1699 sdesc = &rxq->fl.sdesc[rxq->fl.cidx]; 1701 sdesc = &rxq->fl.sdesc[rxq->fl.cidx];
1700 bufsz = get_buf_size(sdesc); 1702 bufsz = get_buf_size(adapter, sdesc);
1701 fp->page = sdesc->page; 1703 fp->page = sdesc->page;
1702 fp->offset = rspq->offset; 1704 fp->offset = rspq->offset;
1703 fp->size = min(bufsz, len); 1705 fp->size = min(bufsz, len);
@@ -1726,7 +1728,7 @@ static int process_responses(struct sge_rspq *rspq, int budget)
1726 */ 1728 */
1727 ret = rspq->handler(rspq, rspq->cur_desc, &gl); 1729 ret = rspq->handler(rspq, rspq->cur_desc, &gl);
1728 if (likely(ret == 0)) 1730 if (likely(ret == 0))
1729 rspq->offset += ALIGN(fp->size, FL_ALIGN); 1731 rspq->offset += ALIGN(fp->size, s->fl_align);
1730 else 1732 else
1731 restore_rx_bufs(&gl, &rxq->fl, frag); 1733 restore_rx_bufs(&gl, &rxq->fl, frag);
1732 } else if (likely(rsp_type == RSP_TYPE_CPL)) { 1734 } else if (likely(rsp_type == RSP_TYPE_CPL)) {
@@ -1963,7 +1965,7 @@ static void sge_rx_timer_cb(unsigned long data)
1963 * schedule napi but the FL is no longer starving. 1965 * schedule napi but the FL is no longer starving.
1964 * No biggie. 1966 * No biggie.
1965 */ 1967 */
1966 if (fl_starving(fl)) { 1968 if (fl_starving(adapter, fl)) {
1967 struct sge_eth_rxq *rxq; 1969 struct sge_eth_rxq *rxq;
1968 1970
1969 rxq = container_of(fl, struct sge_eth_rxq, fl); 1971 rxq = container_of(fl, struct sge_eth_rxq, fl);
@@ -2047,6 +2049,7 @@ int t4vf_sge_alloc_rxq(struct adapter *adapter, struct sge_rspq *rspq,
2047 int intr_dest, 2049 int intr_dest,
2048 struct sge_fl *fl, rspq_handler_t hnd) 2050 struct sge_fl *fl, rspq_handler_t hnd)
2049{ 2051{
2052 struct sge *s = &adapter->sge;
2050 struct port_info *pi = netdev_priv(dev); 2053 struct port_info *pi = netdev_priv(dev);
2051 struct fw_iq_cmd cmd, rpl; 2054 struct fw_iq_cmd cmd, rpl;
2052 int ret, iqandst, flsz = 0; 2055 int ret, iqandst, flsz = 0;
@@ -2117,7 +2120,7 @@ int t4vf_sge_alloc_rxq(struct adapter *adapter, struct sge_rspq *rspq,
2117 fl->size = roundup(fl->size, FL_PER_EQ_UNIT); 2120 fl->size = roundup(fl->size, FL_PER_EQ_UNIT);
2118 fl->desc = alloc_ring(adapter->pdev_dev, fl->size, 2121 fl->desc = alloc_ring(adapter->pdev_dev, fl->size,
2119 sizeof(__be64), sizeof(struct rx_sw_desc), 2122 sizeof(__be64), sizeof(struct rx_sw_desc),
2120 &fl->addr, &fl->sdesc, STAT_LEN); 2123 &fl->addr, &fl->sdesc, s->stat_len);
2121 if (!fl->desc) { 2124 if (!fl->desc) {
2122 ret = -ENOMEM; 2125 ret = -ENOMEM;
2123 goto err; 2126 goto err;
@@ -2129,7 +2132,7 @@ int t4vf_sge_alloc_rxq(struct adapter *adapter, struct sge_rspq *rspq,
2129 * free list ring) in Egress Queue Units. 2132 * free list ring) in Egress Queue Units.
2130 */ 2133 */
2131 flsz = (fl->size / FL_PER_EQ_UNIT + 2134 flsz = (fl->size / FL_PER_EQ_UNIT +
2132 STAT_LEN / EQ_UNIT); 2135 s->stat_len / EQ_UNIT);
2133 2136
2134 /* 2137 /*
2135 * Fill in all the relevant firmware Ingress Queue Command 2138 * Fill in all the relevant firmware Ingress Queue Command
@@ -2217,6 +2220,7 @@ int t4vf_sge_alloc_eth_txq(struct adapter *adapter, struct sge_eth_txq *txq,
2217 struct net_device *dev, struct netdev_queue *devq, 2220 struct net_device *dev, struct netdev_queue *devq,
2218 unsigned int iqid) 2221 unsigned int iqid)
2219{ 2222{
2223 struct sge *s = &adapter->sge;
2220 int ret, nentries; 2224 int ret, nentries;
2221 struct fw_eq_eth_cmd cmd, rpl; 2225 struct fw_eq_eth_cmd cmd, rpl;
2222 struct port_info *pi = netdev_priv(dev); 2226 struct port_info *pi = netdev_priv(dev);
@@ -2225,7 +2229,7 @@ int t4vf_sge_alloc_eth_txq(struct adapter *adapter, struct sge_eth_txq *txq,
2225 * Calculate the size of the hardware TX Queue (including the Status 2229 * Calculate the size of the hardware TX Queue (including the Status
2226 * Page on the end of the TX Queue) in units of TX Descriptors. 2230 * Page on the end of the TX Queue) in units of TX Descriptors.
2227 */ 2231 */
2228 nentries = txq->q.size + STAT_LEN / sizeof(struct tx_desc); 2232 nentries = txq->q.size + s->stat_len / sizeof(struct tx_desc);
2229 2233
2230 /* 2234 /*
2231 * Allocate the hardware ring for the TX ring (with space for its 2235 * Allocate the hardware ring for the TX ring (with space for its
@@ -2234,7 +2238,7 @@ int t4vf_sge_alloc_eth_txq(struct adapter *adapter, struct sge_eth_txq *txq,
2234 txq->q.desc = alloc_ring(adapter->pdev_dev, txq->q.size, 2238 txq->q.desc = alloc_ring(adapter->pdev_dev, txq->q.size,
2235 sizeof(struct tx_desc), 2239 sizeof(struct tx_desc),
2236 sizeof(struct tx_sw_desc), 2240 sizeof(struct tx_sw_desc),
2237 &txq->q.phys_addr, &txq->q.sdesc, STAT_LEN); 2241 &txq->q.phys_addr, &txq->q.sdesc, s->stat_len);
2238 if (!txq->q.desc) 2242 if (!txq->q.desc)
2239 return -ENOMEM; 2243 return -ENOMEM;
2240 2244
@@ -2307,8 +2311,10 @@ int t4vf_sge_alloc_eth_txq(struct adapter *adapter, struct sge_eth_txq *txq,
2307 */ 2311 */
2308static void free_txq(struct adapter *adapter, struct sge_txq *tq) 2312static void free_txq(struct adapter *adapter, struct sge_txq *tq)
2309{ 2313{
2314 struct sge *s = &adapter->sge;
2315
2310 dma_free_coherent(adapter->pdev_dev, 2316 dma_free_coherent(adapter->pdev_dev,
2311 tq->size * sizeof(*tq->desc) + STAT_LEN, 2317 tq->size * sizeof(*tq->desc) + s->stat_len,
2312 tq->desc, tq->phys_addr); 2318 tq->desc, tq->phys_addr);
2313 tq->cntxt_id = 0; 2319 tq->cntxt_id = 0;
2314 tq->sdesc = NULL; 2320 tq->sdesc = NULL;
@@ -2322,6 +2328,7 @@ static void free_txq(struct adapter *adapter, struct sge_txq *tq)
2322static void free_rspq_fl(struct adapter *adapter, struct sge_rspq *rspq, 2328static void free_rspq_fl(struct adapter *adapter, struct sge_rspq *rspq,
2323 struct sge_fl *fl) 2329 struct sge_fl *fl)
2324{ 2330{
2331 struct sge *s = &adapter->sge;
2325 unsigned int flid = fl ? fl->cntxt_id : 0xffff; 2332 unsigned int flid = fl ? fl->cntxt_id : 0xffff;
2326 2333
2327 t4vf_iq_free(adapter, FW_IQ_TYPE_FL_INT_CAP, 2334 t4vf_iq_free(adapter, FW_IQ_TYPE_FL_INT_CAP,
@@ -2337,7 +2344,7 @@ static void free_rspq_fl(struct adapter *adapter, struct sge_rspq *rspq,
2337 if (fl) { 2344 if (fl) {
2338 free_rx_bufs(adapter, fl, fl->avail); 2345 free_rx_bufs(adapter, fl, fl->avail);
2339 dma_free_coherent(adapter->pdev_dev, 2346 dma_free_coherent(adapter->pdev_dev,
2340 fl->size * sizeof(*fl->desc) + STAT_LEN, 2347 fl->size * sizeof(*fl->desc) + s->stat_len,
2341 fl->desc, fl->addr); 2348 fl->desc, fl->addr);
2342 kfree(fl->sdesc); 2349 kfree(fl->sdesc);
2343 fl->sdesc = NULL; 2350 fl->sdesc = NULL;
@@ -2423,6 +2430,7 @@ int t4vf_sge_init(struct adapter *adapter)
2423 u32 fl0 = sge_params->sge_fl_buffer_size[0]; 2430 u32 fl0 = sge_params->sge_fl_buffer_size[0];
2424 u32 fl1 = sge_params->sge_fl_buffer_size[1]; 2431 u32 fl1 = sge_params->sge_fl_buffer_size[1];
2425 struct sge *s = &adapter->sge; 2432 struct sge *s = &adapter->sge;
2433 unsigned int ingpadboundary, ingpackboundary;
2426 2434
2427 /* 2435 /*
2428 * Start by vetting the basic SGE parameters which have been set up by 2436 * Start by vetting the basic SGE parameters which have been set up by
@@ -2443,12 +2451,48 @@ int t4vf_sge_init(struct adapter *adapter)
2443 * Now translate the adapter parameters into our internal forms. 2451 * Now translate the adapter parameters into our internal forms.
2444 */ 2452 */
2445 if (fl1) 2453 if (fl1)
2446 FL_PG_ORDER = ilog2(fl1) - PAGE_SHIFT; 2454 s->fl_pg_order = ilog2(fl1) - PAGE_SHIFT;
2447 STAT_LEN = ((sge_params->sge_control & EGRSTATUSPAGESIZE_MASK) 2455 s->stat_len = ((sge_params->sge_control & EGRSTATUSPAGESIZE_MASK)
2448 ? 128 : 64); 2456 ? 128 : 64);
2449 PKTSHIFT = PKTSHIFT_GET(sge_params->sge_control); 2457 s->pktshift = PKTSHIFT_GET(sge_params->sge_control);
2450 FL_ALIGN = 1 << (INGPADBOUNDARY_GET(sge_params->sge_control) + 2458
2451 SGE_INGPADBOUNDARY_SHIFT); 2459 /* T4 uses a single control field to specify both the PCIe Padding and
2460 * Packing Boundary. T5 introduced the ability to specify these
2461 * separately. The actual Ingress Packet Data alignment boundary
2462 * within Packed Buffer Mode is the maximum of these two
2463 * specifications. (Note that it makes no real practical sense to
2464 * have the Pading Boudary be larger than the Packing Boundary but you
2465 * could set the chip up that way and, in fact, legacy T4 code would
2466 * end doing this because it would initialize the Padding Boundary and
2467 * leave the Packing Boundary initialized to 0 (16 bytes).)
2468 */
2469 ingpadboundary = 1 << (INGPADBOUNDARY_GET(sge_params->sge_control) +
2470 X_INGPADBOUNDARY_SHIFT);
2471 if (is_t4(adapter->params.chip)) {
2472 s->fl_align = ingpadboundary;
2473 } else {
2474 /* T5 has a different interpretation of one of the PCIe Packing
2475 * Boundary values.
2476 */
2477 ingpackboundary = INGPACKBOUNDARY_G(sge_params->sge_control2);
2478 if (ingpackboundary == INGPACKBOUNDARY_16B_X)
2479 ingpackboundary = 16;
2480 else
2481 ingpackboundary = 1 << (ingpackboundary +
2482 INGPACKBOUNDARY_SHIFT_X);
2483
2484 s->fl_align = max(ingpadboundary, ingpackboundary);
2485 }
2486
2487 /* A FL with <= fl_starve_thres buffers is starving and a periodic
2488 * timer will attempt to refill it. This needs to be larger than the
2489 * SGE's Egress Congestion Threshold. If it isn't, then we can get
2490 * stuck waiting for new packets while the SGE is waiting for us to
2491 * give it more Free List entries. (Note that the SGE's Egress
2492 * Congestion Threshold is in units of 2 Free List pointers.)
2493 */
2494 s->fl_starve_thres
2495 = EGRTHRESHOLD_GET(sge_params->sge_congestion_control)*2 + 1;
2452 2496
2453 /* 2497 /*
2454 * Set up tasklet timers. 2498 * Set up tasklet timers.
diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_common.h b/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_common.h
index 95df61dcb4ce..4b6a6d14d86d 100644
--- a/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_common.h
+++ b/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_common.h
@@ -134,11 +134,13 @@ struct dev_params {
134 */ 134 */
135struct sge_params { 135struct sge_params {
136 u32 sge_control; /* padding, boundaries, lengths, etc. */ 136 u32 sge_control; /* padding, boundaries, lengths, etc. */
137 u32 sge_control2; /* T5: more of the same */
137 u32 sge_host_page_size; /* RDMA page sizes */ 138 u32 sge_host_page_size; /* RDMA page sizes */
138 u32 sge_queues_per_page; /* RDMA queues/page */ 139 u32 sge_queues_per_page; /* RDMA queues/page */
139 u32 sge_user_mode_limits; /* limits for BAR2 user mode accesses */ 140 u32 sge_user_mode_limits; /* limits for BAR2 user mode accesses */
140 u32 sge_fl_buffer_size[16]; /* free list buffer sizes */ 141 u32 sge_fl_buffer_size[16]; /* free list buffer sizes */
141 u32 sge_ingress_rx_threshold; /* RX counter interrupt threshold[4] */ 142 u32 sge_ingress_rx_threshold; /* RX counter interrupt threshold[4] */
143 u32 sge_congestion_control; /* congestion thresholds, etc. */
142 u32 sge_timer_value_0_and_1; /* interrupt coalescing timer values */ 144 u32 sge_timer_value_0_and_1; /* interrupt coalescing timer values */
143 u32 sge_timer_value_2_and_3; 145 u32 sge_timer_value_2_and_3;
144 u32 sge_timer_value_4_and_5; 146 u32 sge_timer_value_4_and_5;
diff --git a/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c b/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c
index e984fdc48ba2..1e896b923234 100644
--- a/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c
+++ b/drivers/net/ethernet/chelsio/cxgb4vf/t4vf_hw.c
@@ -468,12 +468,38 @@ int t4vf_get_sge_params(struct adapter *adapter)
468 sge_params->sge_timer_value_2_and_3 = vals[5]; 468 sge_params->sge_timer_value_2_and_3 = vals[5];
469 sge_params->sge_timer_value_4_and_5 = vals[6]; 469 sge_params->sge_timer_value_4_and_5 = vals[6];
470 470
471 /* T4 uses a single control field to specify both the PCIe Padding and
472 * Packing Boundary. T5 introduced the ability to specify these
473 * separately with the Padding Boundary in SGE_CONTROL and and Packing
474 * Boundary in SGE_CONTROL2. So for T5 and later we need to grab
475 * SGE_CONTROL in order to determine how ingress packet data will be
476 * laid out in Packed Buffer Mode. Unfortunately, older versions of
477 * the firmware won't let us retrieve SGE_CONTROL2 so if we get a
478 * failure grabbing it we throw an error since we can't figure out the
479 * right value.
480 */
481 if (!is_t4(adapter->params.chip)) {
482 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
483 FW_PARAMS_PARAM_XYZ(SGE_CONTROL2_A));
484 v = t4vf_query_params(adapter, 1, params, vals);
485 if (v != FW_SUCCESS) {
486 dev_err(adapter->pdev_dev,
487 "Unable to get SGE Control2; "
488 "probably old firmware.\n");
489 return v;
490 }
491 sge_params->sge_control2 = vals[0];
492 }
493
471 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) | 494 params[0] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
472 FW_PARAMS_PARAM_XYZ(SGE_INGRESS_RX_THRESHOLD)); 495 FW_PARAMS_PARAM_XYZ(SGE_INGRESS_RX_THRESHOLD));
473 v = t4vf_query_params(adapter, 1, params, vals); 496 params[1] = (FW_PARAMS_MNEM(FW_PARAMS_MNEM_REG) |
497 FW_PARAMS_PARAM_XYZ(SGE_CONM_CTRL));
498 v = t4vf_query_params(adapter, 2, params, vals);
474 if (v) 499 if (v)
475 return v; 500 return v;
476 sge_params->sge_ingress_rx_threshold = vals[0]; 501 sge_params->sge_ingress_rx_threshold = vals[0];
502 sge_params->sge_congestion_control = vals[1];
477 503
478 return 0; 504 return 0;
479} 505}
diff --git a/drivers/net/ethernet/cisco/enic/enic_main.c b/drivers/net/ethernet/cisco/enic/enic_main.c
index 180e53fa628f..73cf1653a4a3 100644
--- a/drivers/net/ethernet/cisco/enic/enic_main.c
+++ b/drivers/net/ethernet/cisco/enic/enic_main.c
@@ -940,18 +940,8 @@ static int enic_rq_alloc_buf(struct vnic_rq *rq)
940 struct vnic_rq_buf *buf = rq->to_use; 940 struct vnic_rq_buf *buf = rq->to_use;
941 941
942 if (buf->os_buf) { 942 if (buf->os_buf) {
943 buf = buf->next; 943 enic_queue_rq_desc(rq, buf->os_buf, os_buf_index, buf->dma_addr,
944 rq->to_use = buf; 944 buf->len);
945 rq->ring.desc_avail--;
946 if ((buf->index & VNIC_RQ_RETURN_RATE) == 0) {
947 /* Adding write memory barrier prevents compiler and/or
948 * CPU reordering, thus avoiding descriptor posting
949 * before descriptor is initialized. Otherwise, hardware
950 * can read stale descriptor fields.
951 */
952 wmb();
953 iowrite32(buf->index, &rq->ctrl->posted_index);
954 }
955 945
956 return 0; 946 return 0;
957 } 947 }
@@ -1037,7 +1027,10 @@ static void enic_rq_indicate_buf(struct vnic_rq *rq,
1037 enic->rq_truncated_pkts++; 1027 enic->rq_truncated_pkts++;
1038 } 1028 }
1039 1029
1030 pci_unmap_single(enic->pdev, buf->dma_addr, buf->len,
1031 PCI_DMA_FROMDEVICE);
1040 dev_kfree_skb_any(skb); 1032 dev_kfree_skb_any(skb);
1033 buf->os_buf = NULL;
1041 1034
1042 return; 1035 return;
1043 } 1036 }
@@ -1088,7 +1081,10 @@ static void enic_rq_indicate_buf(struct vnic_rq *rq,
1088 /* Buffer overflow 1081 /* Buffer overflow
1089 */ 1082 */
1090 1083
1084 pci_unmap_single(enic->pdev, buf->dma_addr, buf->len,
1085 PCI_DMA_FROMDEVICE);
1091 dev_kfree_skb_any(skb); 1086 dev_kfree_skb_any(skb);
1087 buf->os_buf = NULL;
1092 } 1088 }
1093} 1089}
1094 1090
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index 9a18e7930b31..597c463e384d 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -4309,11 +4309,16 @@ static int be_ndo_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh)
4309 return -EOPNOTSUPP; 4309 return -EOPNOTSUPP;
4310 4310
4311 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); 4311 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
4312 if (!br_spec)
4313 return -EINVAL;
4312 4314
4313 nla_for_each_nested(attr, br_spec, rem) { 4315 nla_for_each_nested(attr, br_spec, rem) {
4314 if (nla_type(attr) != IFLA_BRIDGE_MODE) 4316 if (nla_type(attr) != IFLA_BRIDGE_MODE)
4315 continue; 4317 continue;
4316 4318
4319 if (nla_len(attr) < sizeof(mode))
4320 return -EINVAL;
4321
4317 mode = nla_get_u16(attr); 4322 mode = nla_get_u16(attr);
4318 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB) 4323 if (mode != BRIDGE_MODE_VEPA && mode != BRIDGE_MODE_VEB)
4319 return -EINVAL; 4324 return -EINVAL;
@@ -4421,6 +4426,11 @@ static void be_del_vxlan_port(struct net_device *netdev, sa_family_t sa_family,
4421 "Disabled VxLAN offloads for UDP port %d\n", 4426 "Disabled VxLAN offloads for UDP port %d\n",
4422 be16_to_cpu(port)); 4427 be16_to_cpu(port));
4423} 4428}
4429
4430static bool be_gso_check(struct sk_buff *skb, struct net_device *dev)
4431{
4432 return vxlan_gso_check(skb);
4433}
4424#endif 4434#endif
4425 4435
4426static const struct net_device_ops be_netdev_ops = { 4436static const struct net_device_ops be_netdev_ops = {
@@ -4450,6 +4460,7 @@ static const struct net_device_ops be_netdev_ops = {
4450#ifdef CONFIG_BE2NET_VXLAN 4460#ifdef CONFIG_BE2NET_VXLAN
4451 .ndo_add_vxlan_port = be_add_vxlan_port, 4461 .ndo_add_vxlan_port = be_add_vxlan_port,
4452 .ndo_del_vxlan_port = be_del_vxlan_port, 4462 .ndo_del_vxlan_port = be_del_vxlan_port,
4463 .ndo_gso_check = be_gso_check,
4453#endif 4464#endif
4454}; 4465};
4455 4466
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 50a851db2852..3dca494797bd 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -298,6 +298,16 @@ static void *swap_buffer(void *bufaddr, int len)
298 return bufaddr; 298 return bufaddr;
299} 299}
300 300
301static void swap_buffer2(void *dst_buf, void *src_buf, int len)
302{
303 int i;
304 unsigned int *src = src_buf;
305 unsigned int *dst = dst_buf;
306
307 for (i = 0; i < len; i += 4, src++, dst++)
308 *dst = swab32p(src);
309}
310
301static void fec_dump(struct net_device *ndev) 311static void fec_dump(struct net_device *ndev)
302{ 312{
303 struct fec_enet_private *fep = netdev_priv(ndev); 313 struct fec_enet_private *fep = netdev_priv(ndev);
@@ -1307,7 +1317,7 @@ fec_enet_new_rxbdp(struct net_device *ndev, struct bufdesc *bdp, struct sk_buff
1307} 1317}
1308 1318
1309static bool fec_enet_copybreak(struct net_device *ndev, struct sk_buff **skb, 1319static bool fec_enet_copybreak(struct net_device *ndev, struct sk_buff **skb,
1310 struct bufdesc *bdp, u32 length) 1320 struct bufdesc *bdp, u32 length, bool swap)
1311{ 1321{
1312 struct fec_enet_private *fep = netdev_priv(ndev); 1322 struct fec_enet_private *fep = netdev_priv(ndev);
1313 struct sk_buff *new_skb; 1323 struct sk_buff *new_skb;
@@ -1322,7 +1332,10 @@ static bool fec_enet_copybreak(struct net_device *ndev, struct sk_buff **skb,
1322 dma_sync_single_for_cpu(&fep->pdev->dev, bdp->cbd_bufaddr, 1332 dma_sync_single_for_cpu(&fep->pdev->dev, bdp->cbd_bufaddr,
1323 FEC_ENET_RX_FRSIZE - fep->rx_align, 1333 FEC_ENET_RX_FRSIZE - fep->rx_align,
1324 DMA_FROM_DEVICE); 1334 DMA_FROM_DEVICE);
1325 memcpy(new_skb->data, (*skb)->data, length); 1335 if (!swap)
1336 memcpy(new_skb->data, (*skb)->data, length);
1337 else
1338 swap_buffer2(new_skb->data, (*skb)->data, length);
1326 *skb = new_skb; 1339 *skb = new_skb;
1327 1340
1328 return true; 1341 return true;
@@ -1352,6 +1365,7 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)
1352 u16 vlan_tag; 1365 u16 vlan_tag;
1353 int index = 0; 1366 int index = 0;
1354 bool is_copybreak; 1367 bool is_copybreak;
1368 bool need_swap = id_entry->driver_data & FEC_QUIRK_SWAP_FRAME;
1355 1369
1356#ifdef CONFIG_M532x 1370#ifdef CONFIG_M532x
1357 flush_cache_all(); 1371 flush_cache_all();
@@ -1415,7 +1429,8 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)
1415 * include that when passing upstream as it messes up 1429 * include that when passing upstream as it messes up
1416 * bridging applications. 1430 * bridging applications.
1417 */ 1431 */
1418 is_copybreak = fec_enet_copybreak(ndev, &skb, bdp, pkt_len - 4); 1432 is_copybreak = fec_enet_copybreak(ndev, &skb, bdp, pkt_len - 4,
1433 need_swap);
1419 if (!is_copybreak) { 1434 if (!is_copybreak) {
1420 skb_new = netdev_alloc_skb(ndev, FEC_ENET_RX_FRSIZE); 1435 skb_new = netdev_alloc_skb(ndev, FEC_ENET_RX_FRSIZE);
1421 if (unlikely(!skb_new)) { 1436 if (unlikely(!skb_new)) {
@@ -1430,7 +1445,7 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id)
1430 prefetch(skb->data - NET_IP_ALIGN); 1445 prefetch(skb->data - NET_IP_ALIGN);
1431 skb_put(skb, pkt_len - 4); 1446 skb_put(skb, pkt_len - 4);
1432 data = skb->data; 1447 data = skb->data;
1433 if (id_entry->driver_data & FEC_QUIRK_SWAP_FRAME) 1448 if (!is_copybreak && need_swap)
1434 swap_buffer(data, pkt_len); 1449 swap_buffer(data, pkt_len);
1435 1450
1436 /* Extract the enhanced buffer descriptor */ 1451 /* Extract the enhanced buffer descriptor */
@@ -3343,12 +3358,11 @@ static int __maybe_unused fec_suspend(struct device *dev)
3343 netif_device_detach(ndev); 3358 netif_device_detach(ndev);
3344 netif_tx_unlock_bh(ndev); 3359 netif_tx_unlock_bh(ndev);
3345 fec_stop(ndev); 3360 fec_stop(ndev);
3361 fec_enet_clk_enable(ndev, false);
3362 pinctrl_pm_select_sleep_state(&fep->pdev->dev);
3346 } 3363 }
3347 rtnl_unlock(); 3364 rtnl_unlock();
3348 3365
3349 fec_enet_clk_enable(ndev, false);
3350 pinctrl_pm_select_sleep_state(&fep->pdev->dev);
3351
3352 if (fep->reg_phy) 3366 if (fep->reg_phy)
3353 regulator_disable(fep->reg_phy); 3367 regulator_disable(fep->reg_phy);
3354 3368
@@ -3367,13 +3381,14 @@ static int __maybe_unused fec_resume(struct device *dev)
3367 return ret; 3381 return ret;
3368 } 3382 }
3369 3383
3370 pinctrl_pm_select_default_state(&fep->pdev->dev);
3371 ret = fec_enet_clk_enable(ndev, true);
3372 if (ret)
3373 goto failed_clk;
3374
3375 rtnl_lock(); 3384 rtnl_lock();
3376 if (netif_running(ndev)) { 3385 if (netif_running(ndev)) {
3386 pinctrl_pm_select_default_state(&fep->pdev->dev);
3387 ret = fec_enet_clk_enable(ndev, true);
3388 if (ret) {
3389 rtnl_unlock();
3390 goto failed_clk;
3391 }
3377 fec_restart(ndev); 3392 fec_restart(ndev);
3378 netif_tx_lock_bh(ndev); 3393 netif_tx_lock_bh(ndev);
3379 netif_device_attach(ndev); 3394 netif_device_attach(ndev);
diff --git a/drivers/net/ethernet/intel/igb/igb_main.c b/drivers/net/ethernet/intel/igb/igb_main.c
index a2d72a87cbde..487cd9c4ac0d 100644
--- a/drivers/net/ethernet/intel/igb/igb_main.c
+++ b/drivers/net/ethernet/intel/igb/igb_main.c
@@ -1012,7 +1012,8 @@ static void igb_free_q_vector(struct igb_adapter *adapter, int v_idx)
1012 /* igb_get_stats64() might access the rings on this vector, 1012 /* igb_get_stats64() might access the rings on this vector,
1013 * we must wait a grace period before freeing it. 1013 * we must wait a grace period before freeing it.
1014 */ 1014 */
1015 kfree_rcu(q_vector, rcu); 1015 if (q_vector)
1016 kfree_rcu(q_vector, rcu);
1016} 1017}
1017 1018
1018/** 1019/**
@@ -1792,8 +1793,10 @@ void igb_down(struct igb_adapter *adapter)
1792 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE; 1793 adapter->flags &= ~IGB_FLAG_NEED_LINK_UPDATE;
1793 1794
1794 for (i = 0; i < adapter->num_q_vectors; i++) { 1795 for (i = 0; i < adapter->num_q_vectors; i++) {
1795 napi_synchronize(&(adapter->q_vector[i]->napi)); 1796 if (adapter->q_vector[i]) {
1796 napi_disable(&(adapter->q_vector[i]->napi)); 1797 napi_synchronize(&adapter->q_vector[i]->napi);
1798 napi_disable(&adapter->q_vector[i]->napi);
1799 }
1797 } 1800 }
1798 1801
1799 1802
@@ -3717,7 +3720,8 @@ static void igb_free_all_tx_resources(struct igb_adapter *adapter)
3717 int i; 3720 int i;
3718 3721
3719 for (i = 0; i < adapter->num_tx_queues; i++) 3722 for (i = 0; i < adapter->num_tx_queues; i++)
3720 igb_free_tx_resources(adapter->tx_ring[i]); 3723 if (adapter->tx_ring[i])
3724 igb_free_tx_resources(adapter->tx_ring[i]);
3721} 3725}
3722 3726
3723void igb_unmap_and_free_tx_resource(struct igb_ring *ring, 3727void igb_unmap_and_free_tx_resource(struct igb_ring *ring,
@@ -3782,7 +3786,8 @@ static void igb_clean_all_tx_rings(struct igb_adapter *adapter)
3782 int i; 3786 int i;
3783 3787
3784 for (i = 0; i < adapter->num_tx_queues; i++) 3788 for (i = 0; i < adapter->num_tx_queues; i++)
3785 igb_clean_tx_ring(adapter->tx_ring[i]); 3789 if (adapter->tx_ring[i])
3790 igb_clean_tx_ring(adapter->tx_ring[i]);
3786} 3791}
3787 3792
3788/** 3793/**
@@ -3819,7 +3824,8 @@ static void igb_free_all_rx_resources(struct igb_adapter *adapter)
3819 int i; 3824 int i;
3820 3825
3821 for (i = 0; i < adapter->num_rx_queues; i++) 3826 for (i = 0; i < adapter->num_rx_queues; i++)
3822 igb_free_rx_resources(adapter->rx_ring[i]); 3827 if (adapter->rx_ring[i])
3828 igb_free_rx_resources(adapter->rx_ring[i]);
3823} 3829}
3824 3830
3825/** 3831/**
@@ -3874,7 +3880,8 @@ static void igb_clean_all_rx_rings(struct igb_adapter *adapter)
3874 int i; 3880 int i;
3875 3881
3876 for (i = 0; i < adapter->num_rx_queues; i++) 3882 for (i = 0; i < adapter->num_rx_queues; i++)
3877 igb_clean_rx_ring(adapter->rx_ring[i]); 3883 if (adapter->rx_ring[i])
3884 igb_clean_rx_ring(adapter->rx_ring[i]);
3878} 3885}
3879 3886
3880/** 3887/**
@@ -7404,6 +7411,8 @@ static int igb_resume(struct device *dev)
7404 pci_restore_state(pdev); 7411 pci_restore_state(pdev);
7405 pci_save_state(pdev); 7412 pci_save_state(pdev);
7406 7413
7414 if (!pci_device_is_present(pdev))
7415 return -ENODEV;
7407 err = pci_enable_device_mem(pdev); 7416 err = pci_enable_device_mem(pdev);
7408 if (err) { 7417 if (err) {
7409 dev_err(&pdev->dev, 7418 dev_err(&pdev->dev,
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index d2df4e3d1032..cc51554c9e99 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -3936,8 +3936,8 @@ void ixgbe_set_rx_mode(struct net_device *netdev)
3936 * if SR-IOV and VMDQ are disabled - otherwise ensure 3936 * if SR-IOV and VMDQ are disabled - otherwise ensure
3937 * that hardware VLAN filters remain enabled. 3937 * that hardware VLAN filters remain enabled.
3938 */ 3938 */
3939 if (!(adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED | 3939 if (adapter->flags & (IXGBE_FLAG_VMDQ_ENABLED |
3940 IXGBE_FLAG_SRIOV_ENABLED))) 3940 IXGBE_FLAG_SRIOV_ENABLED))
3941 vlnctrl |= (IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN); 3941 vlnctrl |= (IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3942 } else { 3942 } else {
3943 if (netdev->flags & IFF_ALLMULTI) { 3943 if (netdev->flags & IFF_ALLMULTI) {
@@ -7669,6 +7669,8 @@ static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7669 return -EOPNOTSUPP; 7669 return -EOPNOTSUPP;
7670 7670
7671 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); 7671 br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
7672 if (!br_spec)
7673 return -EINVAL;
7672 7674
7673 nla_for_each_nested(attr, br_spec, rem) { 7675 nla_for_each_nested(attr, br_spec, rem) {
7674 __u16 mode; 7676 __u16 mode;
@@ -7677,6 +7679,9 @@ static int ixgbe_ndo_bridge_setlink(struct net_device *dev,
7677 if (nla_type(attr) != IFLA_BRIDGE_MODE) 7679 if (nla_type(attr) != IFLA_BRIDGE_MODE)
7678 continue; 7680 continue;
7679 7681
7682 if (nla_len(attr) < sizeof(mode))
7683 return -EINVAL;
7684
7680 mode = nla_get_u16(attr); 7685 mode = nla_get_u16(attr);
7681 if (mode == BRIDGE_MODE_VEPA) { 7686 if (mode == BRIDGE_MODE_VEPA) {
7682 reg = 0; 7687 reg = 0;
@@ -7979,6 +7984,7 @@ static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
7979 int i, err, pci_using_dac, expected_gts; 7984 int i, err, pci_using_dac, expected_gts;
7980 unsigned int indices = MAX_TX_QUEUES; 7985 unsigned int indices = MAX_TX_QUEUES;
7981 u8 part_str[IXGBE_PBANUM_LENGTH]; 7986 u8 part_str[IXGBE_PBANUM_LENGTH];
7987 bool disable_dev = false;
7982#ifdef IXGBE_FCOE 7988#ifdef IXGBE_FCOE
7983 u16 device_caps; 7989 u16 device_caps;
7984#endif 7990#endif
@@ -8369,13 +8375,14 @@ err_sw_init:
8369 iounmap(adapter->io_addr); 8375 iounmap(adapter->io_addr);
8370 kfree(adapter->mac_table); 8376 kfree(adapter->mac_table);
8371err_ioremap: 8377err_ioremap:
8378 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
8372 free_netdev(netdev); 8379 free_netdev(netdev);
8373err_alloc_etherdev: 8380err_alloc_etherdev:
8374 pci_release_selected_regions(pdev, 8381 pci_release_selected_regions(pdev,
8375 pci_select_bars(pdev, IORESOURCE_MEM)); 8382 pci_select_bars(pdev, IORESOURCE_MEM));
8376err_pci_reg: 8383err_pci_reg:
8377err_dma: 8384err_dma:
8378 if (!adapter || !test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) 8385 if (!adapter || disable_dev)
8379 pci_disable_device(pdev); 8386 pci_disable_device(pdev);
8380 return err; 8387 return err;
8381} 8388}
@@ -8393,6 +8400,7 @@ static void ixgbe_remove(struct pci_dev *pdev)
8393{ 8400{
8394 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev); 8401 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8395 struct net_device *netdev = adapter->netdev; 8402 struct net_device *netdev = adapter->netdev;
8403 bool disable_dev;
8396 8404
8397 ixgbe_dbg_adapter_exit(adapter); 8405 ixgbe_dbg_adapter_exit(adapter);
8398 8406
@@ -8442,11 +8450,12 @@ static void ixgbe_remove(struct pci_dev *pdev)
8442 e_dev_info("complete\n"); 8450 e_dev_info("complete\n");
8443 8451
8444 kfree(adapter->mac_table); 8452 kfree(adapter->mac_table);
8453 disable_dev = !test_and_set_bit(__IXGBE_DISABLED, &adapter->state);
8445 free_netdev(netdev); 8454 free_netdev(netdev);
8446 8455
8447 pci_disable_pcie_error_reporting(pdev); 8456 pci_disable_pcie_error_reporting(pdev);
8448 8457
8449 if (!test_and_set_bit(__IXGBE_DISABLED, &adapter->state)) 8458 if (disable_dev)
8450 pci_disable_device(pdev); 8459 pci_disable_device(pdev);
8451} 8460}
8452 8461
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
index d47b19f27c35..28b81ae09b5a 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_phy.c
@@ -635,7 +635,6 @@ s32 ixgbe_check_phy_link_tnx(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
635 **/ 635 **/
636s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw) 636s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
637{ 637{
638 s32 status;
639 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG; 638 u16 autoneg_reg = IXGBE_MII_AUTONEG_REG;
640 bool autoneg = false; 639 bool autoneg = false;
641 ixgbe_link_speed speed; 640 ixgbe_link_speed speed;
@@ -700,8 +699,7 @@ s32 ixgbe_setup_phy_link_tnx(struct ixgbe_hw *hw)
700 699
701 hw->phy.ops.write_reg(hw, MDIO_CTRL1, 700 hw->phy.ops.write_reg(hw, MDIO_CTRL1,
702 MDIO_MMD_AN, autoneg_reg); 701 MDIO_MMD_AN, autoneg_reg);
703 702 return 0;
704 return status;
705} 703}
706 704
707/** 705/**
diff --git a/drivers/net/ethernet/marvell/mv643xx_eth.c b/drivers/net/ethernet/marvell/mv643xx_eth.c
index b151a949f352..d44560d1d268 100644
--- a/drivers/net/ethernet/marvell/mv643xx_eth.c
+++ b/drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -1047,7 +1047,6 @@ static int txq_reclaim(struct tx_queue *txq, int budget, int force)
1047 int tx_index; 1047 int tx_index;
1048 struct tx_desc *desc; 1048 struct tx_desc *desc;
1049 u32 cmd_sts; 1049 u32 cmd_sts;
1050 struct sk_buff *skb;
1051 1050
1052 tx_index = txq->tx_used_desc; 1051 tx_index = txq->tx_used_desc;
1053 desc = &txq->tx_desc_area[tx_index]; 1052 desc = &txq->tx_desc_area[tx_index];
@@ -1066,19 +1065,22 @@ static int txq_reclaim(struct tx_queue *txq, int budget, int force)
1066 reclaimed++; 1065 reclaimed++;
1067 txq->tx_desc_count--; 1066 txq->tx_desc_count--;
1068 1067
1069 skb = NULL; 1068 if (!IS_TSO_HEADER(txq, desc->buf_ptr))
1070 if (cmd_sts & TX_LAST_DESC) 1069 dma_unmap_single(mp->dev->dev.parent, desc->buf_ptr,
1071 skb = __skb_dequeue(&txq->tx_skb); 1070 desc->byte_cnt, DMA_TO_DEVICE);
1071
1072 if (cmd_sts & TX_ENABLE_INTERRUPT) {
1073 struct sk_buff *skb = __skb_dequeue(&txq->tx_skb);
1074
1075 if (!WARN_ON(!skb))
1076 dev_kfree_skb(skb);
1077 }
1072 1078
1073 if (cmd_sts & ERROR_SUMMARY) { 1079 if (cmd_sts & ERROR_SUMMARY) {
1074 netdev_info(mp->dev, "tx error\n"); 1080 netdev_info(mp->dev, "tx error\n");
1075 mp->dev->stats.tx_errors++; 1081 mp->dev->stats.tx_errors++;
1076 } 1082 }
1077 1083
1078 if (!IS_TSO_HEADER(txq, desc->buf_ptr))
1079 dma_unmap_single(mp->dev->dev.parent, desc->buf_ptr,
1080 desc->byte_cnt, DMA_TO_DEVICE);
1081 dev_kfree_skb(skb);
1082 } 1084 }
1083 1085
1084 __netif_tx_unlock_bh(nq); 1086 __netif_tx_unlock_bh(nq);
diff --git a/drivers/net/ethernet/marvell/mvpp2.c b/drivers/net/ethernet/marvell/mvpp2.c
index ece83f101526..fdf3e382e464 100644
--- a/drivers/net/ethernet/marvell/mvpp2.c
+++ b/drivers/net/ethernet/marvell/mvpp2.c
@@ -1692,6 +1692,7 @@ static int mvpp2_prs_vlan_add(struct mvpp2 *priv, unsigned short tpid, int ai,
1692{ 1692{
1693 struct mvpp2_prs_entry *pe; 1693 struct mvpp2_prs_entry *pe;
1694 int tid_aux, tid; 1694 int tid_aux, tid;
1695 int ret = 0;
1695 1696
1696 pe = mvpp2_prs_vlan_find(priv, tpid, ai); 1697 pe = mvpp2_prs_vlan_find(priv, tpid, ai);
1697 1698
@@ -1723,8 +1724,10 @@ static int mvpp2_prs_vlan_add(struct mvpp2 *priv, unsigned short tpid, int ai,
1723 break; 1724 break;
1724 } 1725 }
1725 1726
1726 if (tid <= tid_aux) 1727 if (tid <= tid_aux) {
1727 return -EINVAL; 1728 ret = -EINVAL;
1729 goto error;
1730 }
1728 1731
1729 memset(pe, 0 , sizeof(struct mvpp2_prs_entry)); 1732 memset(pe, 0 , sizeof(struct mvpp2_prs_entry));
1730 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN); 1733 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN);
@@ -1756,9 +1759,10 @@ static int mvpp2_prs_vlan_add(struct mvpp2 *priv, unsigned short tpid, int ai,
1756 1759
1757 mvpp2_prs_hw_write(priv, pe); 1760 mvpp2_prs_hw_write(priv, pe);
1758 1761
1762error:
1759 kfree(pe); 1763 kfree(pe);
1760 1764
1761 return 0; 1765 return ret;
1762} 1766}
1763 1767
1764/* Get first free double vlan ai number */ 1768/* Get first free double vlan ai number */
@@ -1821,7 +1825,7 @@ static int mvpp2_prs_double_vlan_add(struct mvpp2 *priv, unsigned short tpid1,
1821 unsigned int port_map) 1825 unsigned int port_map)
1822{ 1826{
1823 struct mvpp2_prs_entry *pe; 1827 struct mvpp2_prs_entry *pe;
1824 int tid_aux, tid, ai; 1828 int tid_aux, tid, ai, ret = 0;
1825 1829
1826 pe = mvpp2_prs_double_vlan_find(priv, tpid1, tpid2); 1830 pe = mvpp2_prs_double_vlan_find(priv, tpid1, tpid2);
1827 1831
@@ -1838,8 +1842,10 @@ static int mvpp2_prs_double_vlan_add(struct mvpp2 *priv, unsigned short tpid1,
1838 1842
1839 /* Set ai value for new double vlan entry */ 1843 /* Set ai value for new double vlan entry */
1840 ai = mvpp2_prs_double_vlan_ai_free_get(priv); 1844 ai = mvpp2_prs_double_vlan_ai_free_get(priv);
1841 if (ai < 0) 1845 if (ai < 0) {
1842 return ai; 1846 ret = ai;
1847 goto error;
1848 }
1843 1849
1844 /* Get first single/triple vlan tid */ 1850 /* Get first single/triple vlan tid */
1845 for (tid_aux = MVPP2_PE_FIRST_FREE_TID; 1851 for (tid_aux = MVPP2_PE_FIRST_FREE_TID;
@@ -1859,8 +1865,10 @@ static int mvpp2_prs_double_vlan_add(struct mvpp2 *priv, unsigned short tpid1,
1859 break; 1865 break;
1860 } 1866 }
1861 1867
1862 if (tid >= tid_aux) 1868 if (tid >= tid_aux) {
1863 return -ERANGE; 1869 ret = -ERANGE;
1870 goto error;
1871 }
1864 1872
1865 memset(pe, 0, sizeof(struct mvpp2_prs_entry)); 1873 memset(pe, 0, sizeof(struct mvpp2_prs_entry));
1866 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN); 1874 mvpp2_prs_tcam_lu_set(pe, MVPP2_PRS_LU_VLAN);
@@ -1887,8 +1895,9 @@ static int mvpp2_prs_double_vlan_add(struct mvpp2 *priv, unsigned short tpid1,
1887 mvpp2_prs_tcam_port_map_set(pe, port_map); 1895 mvpp2_prs_tcam_port_map_set(pe, port_map);
1888 mvpp2_prs_hw_write(priv, pe); 1896 mvpp2_prs_hw_write(priv, pe);
1889 1897
1898error:
1890 kfree(pe); 1899 kfree(pe);
1891 return 0; 1900 return ret;
1892} 1901}
1893 1902
1894/* IPv4 header parsing for fragmentation and L4 offset */ 1903/* IPv4 header parsing for fragmentation and L4 offset */
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
index f3032fec8fce..4d69e382b4e5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_netdev.c
@@ -1693,7 +1693,7 @@ int mlx4_en_start_port(struct net_device *dev)
1693 mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap); 1693 mlx4_set_stats_bitmap(mdev->dev, &priv->stats_bitmap);
1694 1694
1695#ifdef CONFIG_MLX4_EN_VXLAN 1695#ifdef CONFIG_MLX4_EN_VXLAN
1696 if (priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_VXLAN_OFFLOADS) 1696 if (priv->mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN)
1697 vxlan_get_rx_port(dev); 1697 vxlan_get_rx_port(dev);
1698#endif 1698#endif
1699 priv->port_up = true; 1699 priv->port_up = true;
@@ -2281,8 +2281,16 @@ static void mlx4_en_add_vxlan_offloads(struct work_struct *work)
2281 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port, 2281 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port,
2282 VXLAN_STEER_BY_OUTER_MAC, 1); 2282 VXLAN_STEER_BY_OUTER_MAC, 1);
2283out: 2283out:
2284 if (ret) 2284 if (ret) {
2285 en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret); 2285 en_err(priv, "failed setting L2 tunnel configuration ret %d\n", ret);
2286 return;
2287 }
2288
2289 /* set offloads */
2290 priv->dev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2291 NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL;
2292 priv->dev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
2293 priv->dev->features |= NETIF_F_GSO_UDP_TUNNEL;
2286} 2294}
2287 2295
2288static void mlx4_en_del_vxlan_offloads(struct work_struct *work) 2296static void mlx4_en_del_vxlan_offloads(struct work_struct *work)
@@ -2290,6 +2298,11 @@ static void mlx4_en_del_vxlan_offloads(struct work_struct *work)
2290 int ret; 2298 int ret;
2291 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv, 2299 struct mlx4_en_priv *priv = container_of(work, struct mlx4_en_priv,
2292 vxlan_del_task); 2300 vxlan_del_task);
2301 /* unset offloads */
2302 priv->dev->hw_enc_features &= ~(NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2303 NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL);
2304 priv->dev->hw_features &= ~NETIF_F_GSO_UDP_TUNNEL;
2305 priv->dev->features &= ~NETIF_F_GSO_UDP_TUNNEL;
2293 2306
2294 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port, 2307 ret = mlx4_SET_PORT_VXLAN(priv->mdev->dev, priv->port,
2295 VXLAN_STEER_BY_OUTER_MAC, 0); 2308 VXLAN_STEER_BY_OUTER_MAC, 0);
@@ -2342,6 +2355,11 @@ static void mlx4_en_del_vxlan_port(struct net_device *dev,
2342 2355
2343 queue_work(priv->mdev->workqueue, &priv->vxlan_del_task); 2356 queue_work(priv->mdev->workqueue, &priv->vxlan_del_task);
2344} 2357}
2358
2359static bool mlx4_en_gso_check(struct sk_buff *skb, struct net_device *dev)
2360{
2361 return vxlan_gso_check(skb);
2362}
2345#endif 2363#endif
2346 2364
2347static const struct net_device_ops mlx4_netdev_ops = { 2365static const struct net_device_ops mlx4_netdev_ops = {
@@ -2373,6 +2391,7 @@ static const struct net_device_ops mlx4_netdev_ops = {
2373#ifdef CONFIG_MLX4_EN_VXLAN 2391#ifdef CONFIG_MLX4_EN_VXLAN
2374 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port, 2392 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port,
2375 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port, 2393 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port,
2394 .ndo_gso_check = mlx4_en_gso_check,
2376#endif 2395#endif
2377}; 2396};
2378 2397
@@ -2403,6 +2422,11 @@ static const struct net_device_ops mlx4_netdev_ops_master = {
2403 .ndo_rx_flow_steer = mlx4_en_filter_rfs, 2422 .ndo_rx_flow_steer = mlx4_en_filter_rfs,
2404#endif 2423#endif
2405 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id, 2424 .ndo_get_phys_port_id = mlx4_en_get_phys_port_id,
2425#ifdef CONFIG_MLX4_EN_VXLAN
2426 .ndo_add_vxlan_port = mlx4_en_add_vxlan_port,
2427 .ndo_del_vxlan_port = mlx4_en_del_vxlan_port,
2428 .ndo_gso_check = mlx4_en_gso_check,
2429#endif
2406}; 2430};
2407 2431
2408int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port, 2432int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
@@ -2568,13 +2592,6 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
2568 if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_A0) 2592 if (mdev->dev->caps.steering_mode != MLX4_STEERING_MODE_A0)
2569 dev->priv_flags |= IFF_UNICAST_FLT; 2593 dev->priv_flags |= IFF_UNICAST_FLT;
2570 2594
2571 if (mdev->dev->caps.tunnel_offload_mode == MLX4_TUNNEL_OFFLOAD_MODE_VXLAN) {
2572 dev->hw_enc_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
2573 NETIF_F_TSO | NETIF_F_GSO_UDP_TUNNEL;
2574 dev->hw_features |= NETIF_F_GSO_UDP_TUNNEL;
2575 dev->features |= NETIF_F_GSO_UDP_TUNNEL;
2576 }
2577
2578 mdev->pndev[port] = dev; 2595 mdev->pndev[port] = dev;
2579 2596
2580 netif_carrier_off(dev); 2597 netif_carrier_off(dev);
diff --git a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
index 5d2498dcf536..cd5cf6d957c7 100644
--- a/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
+++ b/drivers/net/ethernet/mellanox/mlx4/resource_tracker.c
@@ -1546,7 +1546,7 @@ static int qp_alloc_res(struct mlx4_dev *dev, int slave, int op, int cmd,
1546 1546
1547 switch (op) { 1547 switch (op) {
1548 case RES_OP_RESERVE: 1548 case RES_OP_RESERVE:
1549 count = get_param_l(&in_param); 1549 count = get_param_l(&in_param) & 0xffffff;
1550 align = get_param_h(&in_param); 1550 align = get_param_h(&in_param);
1551 err = mlx4_grant_resource(dev, slave, RES_QP, count, 0); 1551 err = mlx4_grant_resource(dev, slave, RES_QP, count, 0);
1552 if (err) 1552 if (err)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eq.c b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
index a278238a2db6..ad2c96a02a53 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eq.c
@@ -374,15 +374,14 @@ int mlx5_create_map_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq, u8 vecidx,
374 snprintf(eq->name, MLX5_MAX_EQ_NAME, "%s@pci:%s", 374 snprintf(eq->name, MLX5_MAX_EQ_NAME, "%s@pci:%s",
375 name, pci_name(dev->pdev)); 375 name, pci_name(dev->pdev));
376 eq->eqn = out.eq_number; 376 eq->eqn = out.eq_number;
377 eq->irqn = vecidx;
378 eq->dev = dev;
379 eq->doorbell = uar->map + MLX5_EQ_DOORBEL_OFFSET;
377 err = request_irq(table->msix_arr[vecidx].vector, mlx5_msix_handler, 0, 380 err = request_irq(table->msix_arr[vecidx].vector, mlx5_msix_handler, 0,
378 eq->name, eq); 381 eq->name, eq);
379 if (err) 382 if (err)
380 goto err_eq; 383 goto err_eq;
381 384
382 eq->irqn = vecidx;
383 eq->dev = dev;
384 eq->doorbell = uar->map + MLX5_EQ_DOORBEL_OFFSET;
385
386 err = mlx5_debug_eq_add(dev, eq); 385 err = mlx5_debug_eq_add(dev, eq);
387 if (err) 386 if (err)
388 goto err_irq; 387 goto err_irq;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index 3d8e8e489b2d..71b10b210792 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -864,14 +864,14 @@ static int init_one(struct pci_dev *pdev,
864 dev->profile = &profile[prof_sel]; 864 dev->profile = &profile[prof_sel];
865 dev->event = mlx5_core_event; 865 dev->event = mlx5_core_event;
866 866
867 INIT_LIST_HEAD(&priv->ctx_list);
868 spin_lock_init(&priv->ctx_lock);
867 err = mlx5_dev_init(dev, pdev); 869 err = mlx5_dev_init(dev, pdev);
868 if (err) { 870 if (err) {
869 dev_err(&pdev->dev, "mlx5_dev_init failed %d\n", err); 871 dev_err(&pdev->dev, "mlx5_dev_init failed %d\n", err);
870 goto out; 872 goto out;
871 } 873 }
872 874
873 INIT_LIST_HEAD(&priv->ctx_list);
874 spin_lock_init(&priv->ctx_lock);
875 err = mlx5_register_device(dev); 875 err = mlx5_register_device(dev);
876 if (err) { 876 if (err) {
877 dev_err(&pdev->dev, "mlx5_register_device failed %d\n", err); 877 dev_err(&pdev->dev, "mlx5_register_device failed %d\n", err);
diff --git a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
index 0b2a1ccd276d..613037584d08 100644
--- a/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
+++ b/drivers/net/ethernet/qlogic/netxen/netxen_nic_main.c
@@ -2762,7 +2762,8 @@ netxen_fw_poll_work(struct work_struct *work)
2762 if (test_bit(__NX_RESETTING, &adapter->state)) 2762 if (test_bit(__NX_RESETTING, &adapter->state))
2763 goto reschedule; 2763 goto reschedule;
2764 2764
2765 if (test_bit(__NX_DEV_UP, &adapter->state)) { 2765 if (test_bit(__NX_DEV_UP, &adapter->state) &&
2766 !(adapter->capabilities & NX_FW_CAPABILITY_LINK_NOTIFICATION)) {
2766 if (!adapter->has_link_events) { 2767 if (!adapter->has_link_events) {
2767 2768
2768 netxen_nic_handle_phy_intr(adapter); 2769 netxen_nic_handle_phy_intr(adapter);
diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
index f5e29f7bdae3..a913b3ad2f89 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c
@@ -503,6 +503,11 @@ static void qlcnic_del_vxlan_port(struct net_device *netdev,
503 503
504 adapter->flags |= QLCNIC_DEL_VXLAN_PORT; 504 adapter->flags |= QLCNIC_DEL_VXLAN_PORT;
505} 505}
506
507static bool qlcnic_gso_check(struct sk_buff *skb, struct net_device *dev)
508{
509 return vxlan_gso_check(skb);
510}
506#endif 511#endif
507 512
508static const struct net_device_ops qlcnic_netdev_ops = { 513static const struct net_device_ops qlcnic_netdev_ops = {
@@ -526,6 +531,7 @@ static const struct net_device_ops qlcnic_netdev_ops = {
526#ifdef CONFIG_QLCNIC_VXLAN 531#ifdef CONFIG_QLCNIC_VXLAN
527 .ndo_add_vxlan_port = qlcnic_add_vxlan_port, 532 .ndo_add_vxlan_port = qlcnic_add_vxlan_port,
528 .ndo_del_vxlan_port = qlcnic_del_vxlan_port, 533 .ndo_del_vxlan_port = qlcnic_del_vxlan_port,
534 .ndo_gso_check = qlcnic_gso_check,
529#endif 535#endif
530#ifdef CONFIG_NET_POLL_CONTROLLER 536#ifdef CONFIG_NET_POLL_CONTROLLER
531 .ndo_poll_controller = qlcnic_poll_controller, 537 .ndo_poll_controller = qlcnic_poll_controller,
diff --git a/drivers/net/ethernet/qualcomm/Kconfig b/drivers/net/ethernet/qualcomm/Kconfig
index f3a47147937d..9a49f42ac2ba 100644
--- a/drivers/net/ethernet/qualcomm/Kconfig
+++ b/drivers/net/ethernet/qualcomm/Kconfig
@@ -5,7 +5,6 @@
5config NET_VENDOR_QUALCOMM 5config NET_VENDOR_QUALCOMM
6 bool "Qualcomm devices" 6 bool "Qualcomm devices"
7 default y 7 default y
8 depends on SPI_MASTER && OF_GPIO
9 ---help--- 8 ---help---
10 If you have a network (Ethernet) card belonging to this class, say Y 9 If you have a network (Ethernet) card belonging to this class, say Y
11 and read the Ethernet-HOWTO, available from 10 and read the Ethernet-HOWTO, available from
@@ -20,7 +19,7 @@ if NET_VENDOR_QUALCOMM
20 19
21config QCA7000 20config QCA7000
22 tristate "Qualcomm Atheros QCA7000 support" 21 tristate "Qualcomm Atheros QCA7000 support"
23 depends on SPI_MASTER && OF_GPIO 22 depends on SPI_MASTER && OF
24 ---help--- 23 ---help---
25 This SPI protocol driver supports the Qualcomm Atheros QCA7000. 24 This SPI protocol driver supports the Qualcomm Atheros QCA7000.
26 25
diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 60e9c2cd051e..b5db6b3f939f 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -917,21 +917,13 @@ static int sh_eth_reset(struct net_device *ndev)
917 return ret; 917 return ret;
918} 918}
919 919
920#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
921static void sh_eth_set_receive_align(struct sk_buff *skb) 920static void sh_eth_set_receive_align(struct sk_buff *skb)
922{ 921{
923 int reserve; 922 uintptr_t reserve = (uintptr_t)skb->data & (SH_ETH_RX_ALIGN - 1);
924 923
925 reserve = SH4_SKB_RX_ALIGN - ((u32)skb->data & (SH4_SKB_RX_ALIGN - 1));
926 if (reserve) 924 if (reserve)
927 skb_reserve(skb, reserve); 925 skb_reserve(skb, SH_ETH_RX_ALIGN - reserve);
928} 926}
929#else
930static void sh_eth_set_receive_align(struct sk_buff *skb)
931{
932 skb_reserve(skb, SH2_SH3_SKB_RX_ALIGN);
933}
934#endif
935 927
936 928
937/* CPU <-> EDMAC endian convert */ 929/* CPU <-> EDMAC endian convert */
@@ -1119,6 +1111,7 @@ static void sh_eth_ring_format(struct net_device *ndev)
1119 struct sh_eth_txdesc *txdesc = NULL; 1111 struct sh_eth_txdesc *txdesc = NULL;
1120 int rx_ringsize = sizeof(*rxdesc) * mdp->num_rx_ring; 1112 int rx_ringsize = sizeof(*rxdesc) * mdp->num_rx_ring;
1121 int tx_ringsize = sizeof(*txdesc) * mdp->num_tx_ring; 1113 int tx_ringsize = sizeof(*txdesc) * mdp->num_tx_ring;
1114 int skbuff_size = mdp->rx_buf_sz + SH_ETH_RX_ALIGN - 1;
1122 1115
1123 mdp->cur_rx = 0; 1116 mdp->cur_rx = 0;
1124 mdp->cur_tx = 0; 1117 mdp->cur_tx = 0;
@@ -1131,21 +1124,21 @@ static void sh_eth_ring_format(struct net_device *ndev)
1131 for (i = 0; i < mdp->num_rx_ring; i++) { 1124 for (i = 0; i < mdp->num_rx_ring; i++) {
1132 /* skb */ 1125 /* skb */
1133 mdp->rx_skbuff[i] = NULL; 1126 mdp->rx_skbuff[i] = NULL;
1134 skb = netdev_alloc_skb(ndev, mdp->rx_buf_sz); 1127 skb = netdev_alloc_skb(ndev, skbuff_size);
1135 mdp->rx_skbuff[i] = skb; 1128 mdp->rx_skbuff[i] = skb;
1136 if (skb == NULL) 1129 if (skb == NULL)
1137 break; 1130 break;
1138 dma_map_single(&ndev->dev, skb->data, mdp->rx_buf_sz,
1139 DMA_FROM_DEVICE);
1140 sh_eth_set_receive_align(skb); 1131 sh_eth_set_receive_align(skb);
1141 1132
1142 /* RX descriptor */ 1133 /* RX descriptor */
1143 rxdesc = &mdp->rx_ring[i]; 1134 rxdesc = &mdp->rx_ring[i];
1135 /* The size of the buffer is a multiple of 16 bytes. */
1136 rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16);
1137 dma_map_single(&ndev->dev, skb->data, rxdesc->buffer_length,
1138 DMA_FROM_DEVICE);
1144 rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4)); 1139 rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4));
1145 rxdesc->status = cpu_to_edmac(mdp, RD_RACT | RD_RFP); 1140 rxdesc->status = cpu_to_edmac(mdp, RD_RACT | RD_RFP);
1146 1141
1147 /* The size of the buffer is 16 byte boundary. */
1148 rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16);
1149 /* Rx descriptor address set */ 1142 /* Rx descriptor address set */
1150 if (i == 0) { 1143 if (i == 0) {
1151 sh_eth_write(ndev, mdp->rx_desc_dma, RDLAR); 1144 sh_eth_write(ndev, mdp->rx_desc_dma, RDLAR);
@@ -1397,6 +1390,7 @@ static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
1397 struct sk_buff *skb; 1390 struct sk_buff *skb;
1398 u16 pkt_len = 0; 1391 u16 pkt_len = 0;
1399 u32 desc_status; 1392 u32 desc_status;
1393 int skbuff_size = mdp->rx_buf_sz + SH_ETH_RX_ALIGN - 1;
1400 1394
1401 rxdesc = &mdp->rx_ring[entry]; 1395 rxdesc = &mdp->rx_ring[entry];
1402 while (!(rxdesc->status & cpu_to_edmac(mdp, RD_RACT))) { 1396 while (!(rxdesc->status & cpu_to_edmac(mdp, RD_RACT))) {
@@ -1448,7 +1442,7 @@ static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
1448 if (mdp->cd->rpadir) 1442 if (mdp->cd->rpadir)
1449 skb_reserve(skb, NET_IP_ALIGN); 1443 skb_reserve(skb, NET_IP_ALIGN);
1450 dma_sync_single_for_cpu(&ndev->dev, rxdesc->addr, 1444 dma_sync_single_for_cpu(&ndev->dev, rxdesc->addr,
1451 mdp->rx_buf_sz, 1445 ALIGN(mdp->rx_buf_sz, 16),
1452 DMA_FROM_DEVICE); 1446 DMA_FROM_DEVICE);
1453 skb_put(skb, pkt_len); 1447 skb_put(skb, pkt_len);
1454 skb->protocol = eth_type_trans(skb, ndev); 1448 skb->protocol = eth_type_trans(skb, ndev);
@@ -1468,13 +1462,13 @@ static int sh_eth_rx(struct net_device *ndev, u32 intr_status, int *quota)
1468 rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16); 1462 rxdesc->buffer_length = ALIGN(mdp->rx_buf_sz, 16);
1469 1463
1470 if (mdp->rx_skbuff[entry] == NULL) { 1464 if (mdp->rx_skbuff[entry] == NULL) {
1471 skb = netdev_alloc_skb(ndev, mdp->rx_buf_sz); 1465 skb = netdev_alloc_skb(ndev, skbuff_size);
1472 mdp->rx_skbuff[entry] = skb; 1466 mdp->rx_skbuff[entry] = skb;
1473 if (skb == NULL) 1467 if (skb == NULL)
1474 break; /* Better luck next round. */ 1468 break; /* Better luck next round. */
1475 dma_map_single(&ndev->dev, skb->data, mdp->rx_buf_sz,
1476 DMA_FROM_DEVICE);
1477 sh_eth_set_receive_align(skb); 1469 sh_eth_set_receive_align(skb);
1470 dma_map_single(&ndev->dev, skb->data,
1471 rxdesc->buffer_length, DMA_FROM_DEVICE);
1478 1472
1479 skb_checksum_none_assert(skb); 1473 skb_checksum_none_assert(skb);
1480 rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4)); 1474 rxdesc->addr = virt_to_phys(PTR_ALIGN(skb->data, 4));
@@ -2042,6 +2036,8 @@ static int sh_eth_open(struct net_device *ndev)
2042 if (ret) 2036 if (ret)
2043 goto out_free_irq; 2037 goto out_free_irq;
2044 2038
2039 mdp->is_opened = 1;
2040
2045 return ret; 2041 return ret;
2046 2042
2047out_free_irq: 2043out_free_irq:
@@ -2131,6 +2127,36 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
2131 return NETDEV_TX_OK; 2127 return NETDEV_TX_OK;
2132} 2128}
2133 2129
2130static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
2131{
2132 struct sh_eth_private *mdp = netdev_priv(ndev);
2133
2134 if (sh_eth_is_rz_fast_ether(mdp))
2135 return &ndev->stats;
2136
2137 if (!mdp->is_opened)
2138 return &ndev->stats;
2139
2140 ndev->stats.tx_dropped += sh_eth_read(ndev, TROCR);
2141 sh_eth_write(ndev, 0, TROCR); /* (write clear) */
2142 ndev->stats.collisions += sh_eth_read(ndev, CDCR);
2143 sh_eth_write(ndev, 0, CDCR); /* (write clear) */
2144 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, LCCR);
2145 sh_eth_write(ndev, 0, LCCR); /* (write clear) */
2146
2147 if (sh_eth_is_gether(mdp)) {
2148 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CERCR);
2149 sh_eth_write(ndev, 0, CERCR); /* (write clear) */
2150 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CEECR);
2151 sh_eth_write(ndev, 0, CEECR); /* (write clear) */
2152 } else {
2153 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CNDCR);
2154 sh_eth_write(ndev, 0, CNDCR); /* (write clear) */
2155 }
2156
2157 return &ndev->stats;
2158}
2159
2134/* device close function */ 2160/* device close function */
2135static int sh_eth_close(struct net_device *ndev) 2161static int sh_eth_close(struct net_device *ndev)
2136{ 2162{
@@ -2145,6 +2171,7 @@ static int sh_eth_close(struct net_device *ndev)
2145 sh_eth_write(ndev, 0, EDTRR); 2171 sh_eth_write(ndev, 0, EDTRR);
2146 sh_eth_write(ndev, 0, EDRRR); 2172 sh_eth_write(ndev, 0, EDRRR);
2147 2173
2174 sh_eth_get_stats(ndev);
2148 /* PHY Disconnect */ 2175 /* PHY Disconnect */
2149 if (mdp->phydev) { 2176 if (mdp->phydev) {
2150 phy_stop(mdp->phydev); 2177 phy_stop(mdp->phydev);
@@ -2163,36 +2190,9 @@ static int sh_eth_close(struct net_device *ndev)
2163 2190
2164 pm_runtime_put_sync(&mdp->pdev->dev); 2191 pm_runtime_put_sync(&mdp->pdev->dev);
2165 2192
2166 return 0; 2193 mdp->is_opened = 0;
2167}
2168
2169static struct net_device_stats *sh_eth_get_stats(struct net_device *ndev)
2170{
2171 struct sh_eth_private *mdp = netdev_priv(ndev);
2172
2173 if (sh_eth_is_rz_fast_ether(mdp))
2174 return &ndev->stats;
2175 2194
2176 pm_runtime_get_sync(&mdp->pdev->dev); 2195 return 0;
2177
2178 ndev->stats.tx_dropped += sh_eth_read(ndev, TROCR);
2179 sh_eth_write(ndev, 0, TROCR); /* (write clear) */
2180 ndev->stats.collisions += sh_eth_read(ndev, CDCR);
2181 sh_eth_write(ndev, 0, CDCR); /* (write clear) */
2182 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, LCCR);
2183 sh_eth_write(ndev, 0, LCCR); /* (write clear) */
2184 if (sh_eth_is_gether(mdp)) {
2185 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CERCR);
2186 sh_eth_write(ndev, 0, CERCR); /* (write clear) */
2187 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CEECR);
2188 sh_eth_write(ndev, 0, CEECR); /* (write clear) */
2189 } else {
2190 ndev->stats.tx_carrier_errors += sh_eth_read(ndev, CNDCR);
2191 sh_eth_write(ndev, 0, CNDCR); /* (write clear) */
2192 }
2193 pm_runtime_put_sync(&mdp->pdev->dev);
2194
2195 return &ndev->stats;
2196} 2196}
2197 2197
2198/* ioctl to device function */ 2198/* ioctl to device function */
diff --git a/drivers/net/ethernet/renesas/sh_eth.h b/drivers/net/ethernet/renesas/sh_eth.h
index b37c427144ee..22301bf9c21d 100644
--- a/drivers/net/ethernet/renesas/sh_eth.h
+++ b/drivers/net/ethernet/renesas/sh_eth.h
@@ -162,9 +162,9 @@ enum {
162 162
163/* Driver's parameters */ 163/* Driver's parameters */
164#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE) 164#if defined(CONFIG_CPU_SH4) || defined(CONFIG_ARCH_SHMOBILE)
165#define SH4_SKB_RX_ALIGN 32 165#define SH_ETH_RX_ALIGN 32
166#else 166#else
167#define SH2_SH3_SKB_RX_ALIGN 2 167#define SH_ETH_RX_ALIGN 2
168#endif 168#endif
169 169
170/* Register's bits 170/* Register's bits
@@ -522,6 +522,7 @@ struct sh_eth_private {
522 522
523 unsigned no_ether_link:1; 523 unsigned no_ether_link:1;
524 unsigned ether_link_active_low:1; 524 unsigned ether_link_active_low:1;
525 unsigned is_opened:1;
525}; 526};
526 527
527static inline void sh_eth_soft_swap(char *src, int len) 528static inline void sh_eth_soft_swap(char *src, int len)
diff --git a/drivers/net/ethernet/sfc/ef10.c b/drivers/net/ethernet/sfc/ef10.c
index 002d4cdc319f..a77f05ce8325 100644
--- a/drivers/net/ethernet/sfc/ef10.c
+++ b/drivers/net/ethernet/sfc/ef10.c
@@ -180,7 +180,8 @@ static int efx_ef10_probe(struct efx_nic *efx)
180 EFX_MAX_CHANNELS, 180 EFX_MAX_CHANNELS,
181 resource_size(&efx->pci_dev->resource[EFX_MEM_BAR]) / 181 resource_size(&efx->pci_dev->resource[EFX_MEM_BAR]) /
182 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES)); 182 (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES));
183 BUG_ON(efx->max_channels == 0); 183 if (WARN_ON(efx->max_channels == 0))
184 return -EIO;
184 185
185 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); 186 nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
186 if (!nic_data) 187 if (!nic_data)
diff --git a/drivers/net/ethernet/smsc/smc91x.c b/drivers/net/ethernet/smsc/smc91x.c
index 2c62208077fe..6cc3cf6f17c8 100644
--- a/drivers/net/ethernet/smsc/smc91x.c
+++ b/drivers/net/ethernet/smsc/smc91x.c
@@ -2243,9 +2243,10 @@ static int smc_drv_probe(struct platform_device *pdev)
2243 const struct of_device_id *match = NULL; 2243 const struct of_device_id *match = NULL;
2244 struct smc_local *lp; 2244 struct smc_local *lp;
2245 struct net_device *ndev; 2245 struct net_device *ndev;
2246 struct resource *res, *ires; 2246 struct resource *res;
2247 unsigned int __iomem *addr; 2247 unsigned int __iomem *addr;
2248 unsigned long irq_flags = SMC_IRQ_FLAGS; 2248 unsigned long irq_flags = SMC_IRQ_FLAGS;
2249 unsigned long irq_resflags;
2249 int ret; 2250 int ret;
2250 2251
2251 ndev = alloc_etherdev(sizeof(struct smc_local)); 2252 ndev = alloc_etherdev(sizeof(struct smc_local));
@@ -2337,16 +2338,19 @@ static int smc_drv_probe(struct platform_device *pdev)
2337 goto out_free_netdev; 2338 goto out_free_netdev;
2338 } 2339 }
2339 2340
2340 ires = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 2341 ndev->irq = platform_get_irq(pdev, 0);
2341 if (!ires) { 2342 if (ndev->irq <= 0) {
2342 ret = -ENODEV; 2343 ret = -ENODEV;
2343 goto out_release_io; 2344 goto out_release_io;
2344 } 2345 }
2345 2346 /*
2346 ndev->irq = ires->start; 2347 * If this platform does not specify any special irqflags, or if
2347 2348 * the resource supplies a trigger, override the irqflags with
2348 if (irq_flags == -1 || ires->flags & IRQF_TRIGGER_MASK) 2349 * the trigger flags from the resource.
2349 irq_flags = ires->flags & IRQF_TRIGGER_MASK; 2350 */
2351 irq_resflags = irqd_get_trigger_type(irq_get_irq_data(ndev->irq));
2352 if (irq_flags == -1 || irq_resflags & IRQF_TRIGGER_MASK)
2353 irq_flags = irq_resflags & IRQF_TRIGGER_MASK;
2350 2354
2351 ret = smc_request_attrib(pdev, ndev); 2355 ret = smc_request_attrib(pdev, ndev);
2352 if (ret) 2356 if (ret)
diff --git a/drivers/net/ethernet/smsc/smsc911x.c b/drivers/net/ethernet/smsc/smsc911x.c
index affb29da353e..77ed74561e5f 100644
--- a/drivers/net/ethernet/smsc/smsc911x.c
+++ b/drivers/net/ethernet/smsc/smsc911x.c
@@ -1342,6 +1342,42 @@ static void smsc911x_rx_multicast_update_workaround(struct smsc911x_data *pdata)
1342 spin_unlock(&pdata->mac_lock); 1342 spin_unlock(&pdata->mac_lock);
1343} 1343}
1344 1344
1345static int smsc911x_phy_general_power_up(struct smsc911x_data *pdata)
1346{
1347 int rc = 0;
1348
1349 if (!pdata->phy_dev)
1350 return rc;
1351
1352 /* If the internal PHY is in General Power-Down mode, all, except the
1353 * management interface, is powered-down and stays in that condition as
1354 * long as Phy register bit 0.11 is HIGH.
1355 *
1356 * In that case, clear the bit 0.11, so the PHY powers up and we can
1357 * access to the phy registers.
1358 */
1359 rc = phy_read(pdata->phy_dev, MII_BMCR);
1360 if (rc < 0) {
1361 SMSC_WARN(pdata, drv, "Failed reading PHY control reg");
1362 return rc;
1363 }
1364
1365 /* If the PHY general power-down bit is not set is not necessary to
1366 * disable the general power down-mode.
1367 */
1368 if (rc & BMCR_PDOWN) {
1369 rc = phy_write(pdata->phy_dev, MII_BMCR, rc & ~BMCR_PDOWN);
1370 if (rc < 0) {
1371 SMSC_WARN(pdata, drv, "Failed writing PHY control reg");
1372 return rc;
1373 }
1374
1375 usleep_range(1000, 1500);
1376 }
1377
1378 return 0;
1379}
1380
1345static int smsc911x_phy_disable_energy_detect(struct smsc911x_data *pdata) 1381static int smsc911x_phy_disable_energy_detect(struct smsc911x_data *pdata)
1346{ 1382{
1347 int rc = 0; 1383 int rc = 0;
@@ -1356,12 +1392,8 @@ static int smsc911x_phy_disable_energy_detect(struct smsc911x_data *pdata)
1356 return rc; 1392 return rc;
1357 } 1393 }
1358 1394
1359 /* 1395 /* Only disable if energy detect mode is already enabled */
1360 * If energy is detected the PHY is already awake so is not necessary 1396 if (rc & MII_LAN83C185_EDPWRDOWN) {
1361 * to disable the energy detect power-down mode.
1362 */
1363 if ((rc & MII_LAN83C185_EDPWRDOWN) &&
1364 !(rc & MII_LAN83C185_ENERGYON)) {
1365 /* Disable energy detect mode for this SMSC Transceivers */ 1397 /* Disable energy detect mode for this SMSC Transceivers */
1366 rc = phy_write(pdata->phy_dev, MII_LAN83C185_CTRL_STATUS, 1398 rc = phy_write(pdata->phy_dev, MII_LAN83C185_CTRL_STATUS,
1367 rc & (~MII_LAN83C185_EDPWRDOWN)); 1399 rc & (~MII_LAN83C185_EDPWRDOWN));
@@ -1370,8 +1402,8 @@ static int smsc911x_phy_disable_energy_detect(struct smsc911x_data *pdata)
1370 SMSC_WARN(pdata, drv, "Failed writing PHY control reg"); 1402 SMSC_WARN(pdata, drv, "Failed writing PHY control reg");
1371 return rc; 1403 return rc;
1372 } 1404 }
1373 1405 /* Allow PHY to wakeup */
1374 mdelay(1); 1406 mdelay(2);
1375 } 1407 }
1376 1408
1377 return 0; 1409 return 0;
@@ -1393,7 +1425,6 @@ static int smsc911x_phy_enable_energy_detect(struct smsc911x_data *pdata)
1393 1425
1394 /* Only enable if energy detect mode is already disabled */ 1426 /* Only enable if energy detect mode is already disabled */
1395 if (!(rc & MII_LAN83C185_EDPWRDOWN)) { 1427 if (!(rc & MII_LAN83C185_EDPWRDOWN)) {
1396 mdelay(100);
1397 /* Enable energy detect mode for this SMSC Transceivers */ 1428 /* Enable energy detect mode for this SMSC Transceivers */
1398 rc = phy_write(pdata->phy_dev, MII_LAN83C185_CTRL_STATUS, 1429 rc = phy_write(pdata->phy_dev, MII_LAN83C185_CTRL_STATUS,
1399 rc | MII_LAN83C185_EDPWRDOWN); 1430 rc | MII_LAN83C185_EDPWRDOWN);
@@ -1402,8 +1433,6 @@ static int smsc911x_phy_enable_energy_detect(struct smsc911x_data *pdata)
1402 SMSC_WARN(pdata, drv, "Failed writing PHY control reg"); 1433 SMSC_WARN(pdata, drv, "Failed writing PHY control reg");
1403 return rc; 1434 return rc;
1404 } 1435 }
1405
1406 mdelay(1);
1407 } 1436 }
1408 return 0; 1437 return 0;
1409} 1438}
@@ -1415,6 +1444,16 @@ static int smsc911x_soft_reset(struct smsc911x_data *pdata)
1415 int ret; 1444 int ret;
1416 1445
1417 /* 1446 /*
1447 * Make sure to power-up the PHY chip before doing a reset, otherwise
1448 * the reset fails.
1449 */
1450 ret = smsc911x_phy_general_power_up(pdata);
1451 if (ret) {
1452 SMSC_WARN(pdata, drv, "Failed to power-up the PHY chip");
1453 return ret;
1454 }
1455
1456 /*
1418 * LAN9210/LAN9211/LAN9220/LAN9221 chips have an internal PHY that 1457 * LAN9210/LAN9211/LAN9220/LAN9221 chips have an internal PHY that
1419 * are initialized in a Energy Detect Power-Down mode that prevents 1458 * are initialized in a Energy Detect Power-Down mode that prevents
1420 * the MAC chip to be software reseted. So we have to wakeup the PHY 1459 * the MAC chip to be software reseted. So we have to wakeup the PHY
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 6f77a46c7e2c..18c46bb0f3bf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -276,6 +276,7 @@ static void stmmac_eee_ctrl_timer(unsigned long arg)
276bool stmmac_eee_init(struct stmmac_priv *priv) 276bool stmmac_eee_init(struct stmmac_priv *priv)
277{ 277{
278 char *phy_bus_name = priv->plat->phy_bus_name; 278 char *phy_bus_name = priv->plat->phy_bus_name;
279 unsigned long flags;
279 bool ret = false; 280 bool ret = false;
280 281
281 /* Using PCS we cannot dial with the phy registers at this stage 282 /* Using PCS we cannot dial with the phy registers at this stage
@@ -300,6 +301,7 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
300 * changed). 301 * changed).
301 * In that case the driver disable own timers. 302 * In that case the driver disable own timers.
302 */ 303 */
304 spin_lock_irqsave(&priv->lock, flags);
303 if (priv->eee_active) { 305 if (priv->eee_active) {
304 pr_debug("stmmac: disable EEE\n"); 306 pr_debug("stmmac: disable EEE\n");
305 del_timer_sync(&priv->eee_ctrl_timer); 307 del_timer_sync(&priv->eee_ctrl_timer);
@@ -307,9 +309,11 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
307 tx_lpi_timer); 309 tx_lpi_timer);
308 } 310 }
309 priv->eee_active = 0; 311 priv->eee_active = 0;
312 spin_unlock_irqrestore(&priv->lock, flags);
310 goto out; 313 goto out;
311 } 314 }
312 /* Activate the EEE and start timers */ 315 /* Activate the EEE and start timers */
316 spin_lock_irqsave(&priv->lock, flags);
313 if (!priv->eee_active) { 317 if (!priv->eee_active) {
314 priv->eee_active = 1; 318 priv->eee_active = 1;
315 init_timer(&priv->eee_ctrl_timer); 319 init_timer(&priv->eee_ctrl_timer);
@@ -325,9 +329,10 @@ bool stmmac_eee_init(struct stmmac_priv *priv)
325 /* Set HW EEE according to the speed */ 329 /* Set HW EEE according to the speed */
326 priv->hw->mac->set_eee_pls(priv->hw, priv->phydev->link); 330 priv->hw->mac->set_eee_pls(priv->hw, priv->phydev->link);
327 331
328 pr_debug("stmmac: Energy-Efficient Ethernet initialized\n");
329
330 ret = true; 332 ret = true;
333 spin_unlock_irqrestore(&priv->lock, flags);
334
335 pr_debug("stmmac: Energy-Efficient Ethernet initialized\n");
331 } 336 }
332out: 337out:
333 return ret; 338 return ret;
@@ -760,12 +765,12 @@ static void stmmac_adjust_link(struct net_device *dev)
760 if (new_state && netif_msg_link(priv)) 765 if (new_state && netif_msg_link(priv))
761 phy_print_status(phydev); 766 phy_print_status(phydev);
762 767
768 spin_unlock_irqrestore(&priv->lock, flags);
769
763 /* At this stage, it could be needed to setup the EEE or adjust some 770 /* At this stage, it could be needed to setup the EEE or adjust some
764 * MAC related HW registers. 771 * MAC related HW registers.
765 */ 772 */
766 priv->eee_enabled = stmmac_eee_init(priv); 773 priv->eee_enabled = stmmac_eee_init(priv);
767
768 spin_unlock_irqrestore(&priv->lock, flags);
769} 774}
770 775
771/** 776/**
@@ -959,12 +964,12 @@ static void stmmac_clear_descriptors(struct stmmac_priv *priv)
959} 964}
960 965
961static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p, 966static int stmmac_init_rx_buffers(struct stmmac_priv *priv, struct dma_desc *p,
962 int i) 967 int i, gfp_t flags)
963{ 968{
964 struct sk_buff *skb; 969 struct sk_buff *skb;
965 970
966 skb = __netdev_alloc_skb(priv->dev, priv->dma_buf_sz + NET_IP_ALIGN, 971 skb = __netdev_alloc_skb(priv->dev, priv->dma_buf_sz + NET_IP_ALIGN,
967 GFP_KERNEL); 972 flags);
968 if (!skb) { 973 if (!skb) {
969 pr_err("%s: Rx init fails; skb is NULL\n", __func__); 974 pr_err("%s: Rx init fails; skb is NULL\n", __func__);
970 return -ENOMEM; 975 return -ENOMEM;
@@ -1006,7 +1011,7 @@ static void stmmac_free_rx_buffers(struct stmmac_priv *priv, int i)
1006 * and allocates the socket buffers. It suppors the chained and ring 1011 * and allocates the socket buffers. It suppors the chained and ring
1007 * modes. 1012 * modes.
1008 */ 1013 */
1009static int init_dma_desc_rings(struct net_device *dev) 1014static int init_dma_desc_rings(struct net_device *dev, gfp_t flags)
1010{ 1015{
1011 int i; 1016 int i;
1012 struct stmmac_priv *priv = netdev_priv(dev); 1017 struct stmmac_priv *priv = netdev_priv(dev);
@@ -1041,7 +1046,7 @@ static int init_dma_desc_rings(struct net_device *dev)
1041 else 1046 else
1042 p = priv->dma_rx + i; 1047 p = priv->dma_rx + i;
1043 1048
1044 ret = stmmac_init_rx_buffers(priv, p, i); 1049 ret = stmmac_init_rx_buffers(priv, p, i, flags);
1045 if (ret) 1050 if (ret)
1046 goto err_init_rx_buffers; 1051 goto err_init_rx_buffers;
1047 1052
@@ -1647,11 +1652,6 @@ static int stmmac_hw_setup(struct net_device *dev)
1647 struct stmmac_priv *priv = netdev_priv(dev); 1652 struct stmmac_priv *priv = netdev_priv(dev);
1648 int ret; 1653 int ret;
1649 1654
1650 ret = init_dma_desc_rings(dev);
1651 if (ret < 0) {
1652 pr_err("%s: DMA descriptors initialization failed\n", __func__);
1653 return ret;
1654 }
1655 /* DMA initialization and SW reset */ 1655 /* DMA initialization and SW reset */
1656 ret = stmmac_init_dma_engine(priv); 1656 ret = stmmac_init_dma_engine(priv);
1657 if (ret < 0) { 1657 if (ret < 0) {
@@ -1705,10 +1705,6 @@ static int stmmac_hw_setup(struct net_device *dev)
1705 } 1705 }
1706 priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS; 1706 priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS;
1707 1707
1708 priv->eee_enabled = stmmac_eee_init(priv);
1709
1710 stmmac_init_tx_coalesce(priv);
1711
1712 if ((priv->use_riwt) && (priv->hw->dma->rx_watchdog)) { 1708 if ((priv->use_riwt) && (priv->hw->dma->rx_watchdog)) {
1713 priv->rx_riwt = MAX_DMA_RIWT; 1709 priv->rx_riwt = MAX_DMA_RIWT;
1714 priv->hw->dma->rx_watchdog(priv->ioaddr, MAX_DMA_RIWT); 1710 priv->hw->dma->rx_watchdog(priv->ioaddr, MAX_DMA_RIWT);
@@ -1761,12 +1757,20 @@ static int stmmac_open(struct net_device *dev)
1761 goto dma_desc_error; 1757 goto dma_desc_error;
1762 } 1758 }
1763 1759
1760 ret = init_dma_desc_rings(dev, GFP_KERNEL);
1761 if (ret < 0) {
1762 pr_err("%s: DMA descriptors initialization failed\n", __func__);
1763 goto init_error;
1764 }
1765
1764 ret = stmmac_hw_setup(dev); 1766 ret = stmmac_hw_setup(dev);
1765 if (ret < 0) { 1767 if (ret < 0) {
1766 pr_err("%s: Hw setup failed\n", __func__); 1768 pr_err("%s: Hw setup failed\n", __func__);
1767 goto init_error; 1769 goto init_error;
1768 } 1770 }
1769 1771
1772 stmmac_init_tx_coalesce(priv);
1773
1770 if (priv->phydev) 1774 if (priv->phydev)
1771 phy_start(priv->phydev); 1775 phy_start(priv->phydev);
1772 1776
@@ -1894,7 +1898,10 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1894 unsigned int nopaged_len = skb_headlen(skb); 1898 unsigned int nopaged_len = skb_headlen(skb);
1895 unsigned int enh_desc = priv->plat->enh_desc; 1899 unsigned int enh_desc = priv->plat->enh_desc;
1896 1900
1901 spin_lock(&priv->tx_lock);
1902
1897 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) { 1903 if (unlikely(stmmac_tx_avail(priv) < nfrags + 1)) {
1904 spin_unlock(&priv->tx_lock);
1898 if (!netif_queue_stopped(dev)) { 1905 if (!netif_queue_stopped(dev)) {
1899 netif_stop_queue(dev); 1906 netif_stop_queue(dev);
1900 /* This is a hard error, log it. */ 1907 /* This is a hard error, log it. */
@@ -1903,8 +1910,6 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
1903 return NETDEV_TX_BUSY; 1910 return NETDEV_TX_BUSY;
1904 } 1911 }
1905 1912
1906 spin_lock(&priv->tx_lock);
1907
1908 if (priv->tx_path_in_lpi_mode) 1913 if (priv->tx_path_in_lpi_mode)
1909 stmmac_disable_eee_mode(priv); 1914 stmmac_disable_eee_mode(priv);
1910 1915
@@ -2025,6 +2030,7 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
2025 return NETDEV_TX_OK; 2030 return NETDEV_TX_OK;
2026 2031
2027dma_map_err: 2032dma_map_err:
2033 spin_unlock(&priv->tx_lock);
2028 dev_err(priv->device, "Tx dma map failed\n"); 2034 dev_err(priv->device, "Tx dma map failed\n");
2029 dev_kfree_skb(skb); 2035 dev_kfree_skb(skb);
2030 priv->dev->stats.tx_dropped++; 2036 priv->dev->stats.tx_dropped++;
@@ -2281,9 +2287,7 @@ static void stmmac_set_rx_mode(struct net_device *dev)
2281{ 2287{
2282 struct stmmac_priv *priv = netdev_priv(dev); 2288 struct stmmac_priv *priv = netdev_priv(dev);
2283 2289
2284 spin_lock(&priv->lock);
2285 priv->hw->mac->set_filter(priv->hw, dev); 2290 priv->hw->mac->set_filter(priv->hw, dev);
2286 spin_unlock(&priv->lock);
2287} 2291}
2288 2292
2289/** 2293/**
@@ -2950,7 +2954,7 @@ int stmmac_suspend(struct net_device *ndev)
2950 stmmac_set_mac(priv->ioaddr, false); 2954 stmmac_set_mac(priv->ioaddr, false);
2951 pinctrl_pm_select_sleep_state(priv->device); 2955 pinctrl_pm_select_sleep_state(priv->device);
2952 /* Disable clock in case of PWM is off */ 2956 /* Disable clock in case of PWM is off */
2953 clk_disable_unprepare(priv->stmmac_clk); 2957 clk_disable(priv->stmmac_clk);
2954 } 2958 }
2955 spin_unlock_irqrestore(&priv->lock, flags); 2959 spin_unlock_irqrestore(&priv->lock, flags);
2956 2960
@@ -2982,7 +2986,7 @@ int stmmac_resume(struct net_device *ndev)
2982 } else { 2986 } else {
2983 pinctrl_pm_select_default_state(priv->device); 2987 pinctrl_pm_select_default_state(priv->device);
2984 /* enable the clk prevously disabled */ 2988 /* enable the clk prevously disabled */
2985 clk_prepare_enable(priv->stmmac_clk); 2989 clk_enable(priv->stmmac_clk);
2986 /* reset the phy so that it's ready */ 2990 /* reset the phy so that it's ready */
2987 if (priv->mii) 2991 if (priv->mii)
2988 stmmac_mdio_reset(priv->mii); 2992 stmmac_mdio_reset(priv->mii);
@@ -2990,7 +2994,9 @@ int stmmac_resume(struct net_device *ndev)
2990 2994
2991 netif_device_attach(ndev); 2995 netif_device_attach(ndev);
2992 2996
2997 init_dma_desc_rings(ndev, GFP_ATOMIC);
2993 stmmac_hw_setup(ndev); 2998 stmmac_hw_setup(ndev);
2999 stmmac_init_tx_coalesce(priv);
2994 3000
2995 napi_enable(&priv->napi); 3001 napi_enable(&priv->napi);
2996 3002
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index db56fa7ce8f9..58a1a0a423d4 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -177,12 +177,6 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
177 */ 177 */
178 plat->maxmtu = JUMBO_LEN; 178 plat->maxmtu = JUMBO_LEN;
179 179
180 /* Set default value for multicast hash bins */
181 plat->multicast_filter_bins = HASH_TABLE_SIZE;
182
183 /* Set default value for unicast filter entries */
184 plat->unicast_filter_entries = 1;
185
186 /* 180 /*
187 * Currently only the properties needed on SPEAr600 181 * Currently only the properties needed on SPEAr600
188 * are provided. All other properties should be added 182 * are provided. All other properties should be added
@@ -270,16 +264,23 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
270 return PTR_ERR(addr); 264 return PTR_ERR(addr);
271 265
272 plat_dat = dev_get_platdata(&pdev->dev); 266 plat_dat = dev_get_platdata(&pdev->dev);
273 if (pdev->dev.of_node) { 267
274 if (!plat_dat) 268 if (!plat_dat)
275 plat_dat = devm_kzalloc(&pdev->dev, 269 plat_dat = devm_kzalloc(&pdev->dev,
276 sizeof(struct plat_stmmacenet_data), 270 sizeof(struct plat_stmmacenet_data),
277 GFP_KERNEL); 271 GFP_KERNEL);
278 if (!plat_dat) { 272 if (!plat_dat) {
279 pr_err("%s: ERROR: no memory", __func__); 273 pr_err("%s: ERROR: no memory", __func__);
280 return -ENOMEM; 274 return -ENOMEM;
281 } 275 }
276
277 /* Set default value for multicast hash bins */
278 plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
282 279
280 /* Set default value for unicast filter entries */
281 plat_dat->unicast_filter_entries = 1;
282
283 if (pdev->dev.of_node) {
283 ret = stmmac_probe_config_dt(pdev, plat_dat, &mac); 284 ret = stmmac_probe_config_dt(pdev, plat_dat, &mac);
284 if (ret) { 285 if (ret) {
285 pr_err("%s: main dt probe failed", __func__); 286 pr_err("%s: main dt probe failed", __func__);
diff --git a/drivers/net/ethernet/sun/sunhme.c b/drivers/net/ethernet/sun/sunhme.c
index 72c8525d5457..9c014803b03b 100644
--- a/drivers/net/ethernet/sun/sunhme.c
+++ b/drivers/net/ethernet/sun/sunhme.c
@@ -1262,6 +1262,7 @@ static void happy_meal_init_rings(struct happy_meal *hp)
1262 HMD(("init rxring, ")); 1262 HMD(("init rxring, "));
1263 for (i = 0; i < RX_RING_SIZE; i++) { 1263 for (i = 0; i < RX_RING_SIZE; i++) {
1264 struct sk_buff *skb; 1264 struct sk_buff *skb;
1265 u32 mapping;
1265 1266
1266 skb = happy_meal_alloc_skb(RX_BUF_ALLOC_SIZE, GFP_ATOMIC); 1267 skb = happy_meal_alloc_skb(RX_BUF_ALLOC_SIZE, GFP_ATOMIC);
1267 if (!skb) { 1268 if (!skb) {
@@ -1272,10 +1273,16 @@ static void happy_meal_init_rings(struct happy_meal *hp)
1272 1273
1273 /* Because we reserve afterwards. */ 1274 /* Because we reserve afterwards. */
1274 skb_put(skb, (ETH_FRAME_LEN + RX_OFFSET + 4)); 1275 skb_put(skb, (ETH_FRAME_LEN + RX_OFFSET + 4));
1276 mapping = dma_map_single(hp->dma_dev, skb->data, RX_BUF_ALLOC_SIZE,
1277 DMA_FROM_DEVICE);
1278 if (dma_mapping_error(hp->dma_dev, mapping)) {
1279 dev_kfree_skb_any(skb);
1280 hme_write_rxd(hp, &hb->happy_meal_rxd[i], 0, 0);
1281 continue;
1282 }
1275 hme_write_rxd(hp, &hb->happy_meal_rxd[i], 1283 hme_write_rxd(hp, &hb->happy_meal_rxd[i],
1276 (RXFLAG_OWN | ((RX_BUF_ALLOC_SIZE - RX_OFFSET) << 16)), 1284 (RXFLAG_OWN | ((RX_BUF_ALLOC_SIZE - RX_OFFSET) << 16)),
1277 dma_map_single(hp->dma_dev, skb->data, RX_BUF_ALLOC_SIZE, 1285 mapping);
1278 DMA_FROM_DEVICE));
1279 skb_reserve(skb, RX_OFFSET); 1286 skb_reserve(skb, RX_OFFSET);
1280 } 1287 }
1281 1288
@@ -2020,6 +2027,7 @@ static void happy_meal_rx(struct happy_meal *hp, struct net_device *dev)
2020 skb = hp->rx_skbs[elem]; 2027 skb = hp->rx_skbs[elem];
2021 if (len > RX_COPY_THRESHOLD) { 2028 if (len > RX_COPY_THRESHOLD) {
2022 struct sk_buff *new_skb; 2029 struct sk_buff *new_skb;
2030 u32 mapping;
2023 2031
2024 /* Now refill the entry, if we can. */ 2032 /* Now refill the entry, if we can. */
2025 new_skb = happy_meal_alloc_skb(RX_BUF_ALLOC_SIZE, GFP_ATOMIC); 2033 new_skb = happy_meal_alloc_skb(RX_BUF_ALLOC_SIZE, GFP_ATOMIC);
@@ -2027,13 +2035,21 @@ static void happy_meal_rx(struct happy_meal *hp, struct net_device *dev)
2027 drops++; 2035 drops++;
2028 goto drop_it; 2036 goto drop_it;
2029 } 2037 }
2038 skb_put(new_skb, (ETH_FRAME_LEN + RX_OFFSET + 4));
2039 mapping = dma_map_single(hp->dma_dev, new_skb->data,
2040 RX_BUF_ALLOC_SIZE,
2041 DMA_FROM_DEVICE);
2042 if (unlikely(dma_mapping_error(hp->dma_dev, mapping))) {
2043 dev_kfree_skb_any(new_skb);
2044 drops++;
2045 goto drop_it;
2046 }
2047
2030 dma_unmap_single(hp->dma_dev, dma_addr, RX_BUF_ALLOC_SIZE, DMA_FROM_DEVICE); 2048 dma_unmap_single(hp->dma_dev, dma_addr, RX_BUF_ALLOC_SIZE, DMA_FROM_DEVICE);
2031 hp->rx_skbs[elem] = new_skb; 2049 hp->rx_skbs[elem] = new_skb;
2032 skb_put(new_skb, (ETH_FRAME_LEN + RX_OFFSET + 4));
2033 hme_write_rxd(hp, this, 2050 hme_write_rxd(hp, this,
2034 (RXFLAG_OWN|((RX_BUF_ALLOC_SIZE-RX_OFFSET)<<16)), 2051 (RXFLAG_OWN|((RX_BUF_ALLOC_SIZE-RX_OFFSET)<<16)),
2035 dma_map_single(hp->dma_dev, new_skb->data, RX_BUF_ALLOC_SIZE, 2052 mapping);
2036 DMA_FROM_DEVICE));
2037 skb_reserve(new_skb, RX_OFFSET); 2053 skb_reserve(new_skb, RX_OFFSET);
2038 2054
2039 /* Trim the original skb for the netif. */ 2055 /* Trim the original skb for the netif. */
@@ -2248,6 +2264,25 @@ static void happy_meal_tx_timeout(struct net_device *dev)
2248 netif_wake_queue(dev); 2264 netif_wake_queue(dev);
2249} 2265}
2250 2266
2267static void unmap_partial_tx_skb(struct happy_meal *hp, u32 first_mapping,
2268 u32 first_len, u32 first_entry, u32 entry)
2269{
2270 struct happy_meal_txd *txbase = &hp->happy_block->happy_meal_txd[0];
2271
2272 dma_unmap_single(hp->dma_dev, first_mapping, first_len, DMA_TO_DEVICE);
2273
2274 first_entry = NEXT_TX(first_entry);
2275 while (first_entry != entry) {
2276 struct happy_meal_txd *this = &txbase[first_entry];
2277 u32 addr, len;
2278
2279 addr = hme_read_desc32(hp, &this->tx_addr);
2280 len = hme_read_desc32(hp, &this->tx_flags);
2281 len &= TXFLAG_SIZE;
2282 dma_unmap_page(hp->dma_dev, addr, len, DMA_TO_DEVICE);
2283 }
2284}
2285
2251static netdev_tx_t happy_meal_start_xmit(struct sk_buff *skb, 2286static netdev_tx_t happy_meal_start_xmit(struct sk_buff *skb,
2252 struct net_device *dev) 2287 struct net_device *dev)
2253{ 2288{
@@ -2284,6 +2319,8 @@ static netdev_tx_t happy_meal_start_xmit(struct sk_buff *skb,
2284 2319
2285 len = skb->len; 2320 len = skb->len;
2286 mapping = dma_map_single(hp->dma_dev, skb->data, len, DMA_TO_DEVICE); 2321 mapping = dma_map_single(hp->dma_dev, skb->data, len, DMA_TO_DEVICE);
2322 if (unlikely(dma_mapping_error(hp->dma_dev, mapping)))
2323 goto out_dma_error;
2287 tx_flags |= (TXFLAG_SOP | TXFLAG_EOP); 2324 tx_flags |= (TXFLAG_SOP | TXFLAG_EOP);
2288 hme_write_txd(hp, &hp->happy_block->happy_meal_txd[entry], 2325 hme_write_txd(hp, &hp->happy_block->happy_meal_txd[entry],
2289 (tx_flags | (len & TXFLAG_SIZE)), 2326 (tx_flags | (len & TXFLAG_SIZE)),
@@ -2299,6 +2336,8 @@ static netdev_tx_t happy_meal_start_xmit(struct sk_buff *skb,
2299 first_len = skb_headlen(skb); 2336 first_len = skb_headlen(skb);
2300 first_mapping = dma_map_single(hp->dma_dev, skb->data, first_len, 2337 first_mapping = dma_map_single(hp->dma_dev, skb->data, first_len,
2301 DMA_TO_DEVICE); 2338 DMA_TO_DEVICE);
2339 if (unlikely(dma_mapping_error(hp->dma_dev, first_mapping)))
2340 goto out_dma_error;
2302 entry = NEXT_TX(entry); 2341 entry = NEXT_TX(entry);
2303 2342
2304 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { 2343 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
@@ -2308,6 +2347,11 @@ static netdev_tx_t happy_meal_start_xmit(struct sk_buff *skb,
2308 len = skb_frag_size(this_frag); 2347 len = skb_frag_size(this_frag);
2309 mapping = skb_frag_dma_map(hp->dma_dev, this_frag, 2348 mapping = skb_frag_dma_map(hp->dma_dev, this_frag,
2310 0, len, DMA_TO_DEVICE); 2349 0, len, DMA_TO_DEVICE);
2350 if (unlikely(dma_mapping_error(hp->dma_dev, mapping))) {
2351 unmap_partial_tx_skb(hp, first_mapping, first_len,
2352 first_entry, entry);
2353 goto out_dma_error;
2354 }
2311 this_txflags = tx_flags; 2355 this_txflags = tx_flags;
2312 if (frag == skb_shinfo(skb)->nr_frags - 1) 2356 if (frag == skb_shinfo(skb)->nr_frags - 1)
2313 this_txflags |= TXFLAG_EOP; 2357 this_txflags |= TXFLAG_EOP;
@@ -2333,6 +2377,14 @@ static netdev_tx_t happy_meal_start_xmit(struct sk_buff *skb,
2333 2377
2334 tx_add_log(hp, TXLOG_ACTION_TXMIT, 0); 2378 tx_add_log(hp, TXLOG_ACTION_TXMIT, 0);
2335 return NETDEV_TX_OK; 2379 return NETDEV_TX_OK;
2380
2381out_dma_error:
2382 hp->tx_skbs[hp->tx_new] = NULL;
2383 spin_unlock_irq(&hp->happy_lock);
2384
2385 dev_kfree_skb_any(skb);
2386 dev->stats.tx_dropped++;
2387 return NETDEV_TX_OK;
2336} 2388}
2337 2389
2338static struct net_device_stats *happy_meal_get_stats(struct net_device *dev) 2390static struct net_device_stats *happy_meal_get_stats(struct net_device *dev)
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c
index d8794488f80a..c560f9aeb55d 100644
--- a/drivers/net/ethernet/ti/cpsw.c
+++ b/drivers/net/ethernet/ti/cpsw.c
@@ -129,9 +129,9 @@ do { \
129#define CPSW_VLAN_AWARE BIT(1) 129#define CPSW_VLAN_AWARE BIT(1)
130#define CPSW_ALE_VLAN_AWARE 1 130#define CPSW_ALE_VLAN_AWARE 1
131 131
132#define CPSW_FIFO_NORMAL_MODE (0 << 15) 132#define CPSW_FIFO_NORMAL_MODE (0 << 16)
133#define CPSW_FIFO_DUAL_MAC_MODE (1 << 15) 133#define CPSW_FIFO_DUAL_MAC_MODE (1 << 16)
134#define CPSW_FIFO_RATE_LIMIT_MODE (2 << 15) 134#define CPSW_FIFO_RATE_LIMIT_MODE (2 << 16)
135 135
136#define CPSW_INTPACEEN (0x3f << 16) 136#define CPSW_INTPACEEN (0x3f << 16)
137#define CPSW_INTPRESCALE_MASK (0x7FF << 0) 137#define CPSW_INTPRESCALE_MASK (0x7FF << 0)
diff --git a/drivers/net/ethernet/ti/cpsw_ale.c b/drivers/net/ethernet/ti/cpsw_ale.c
index 3ae83879a75f..097ebe7077ac 100644
--- a/drivers/net/ethernet/ti/cpsw_ale.c
+++ b/drivers/net/ethernet/ti/cpsw_ale.c
@@ -785,7 +785,6 @@ int cpsw_ale_destroy(struct cpsw_ale *ale)
785{ 785{
786 if (!ale) 786 if (!ale)
787 return -EINVAL; 787 return -EINVAL;
788 cpsw_ale_stop(ale);
789 cpsw_ale_control_set(ale, 0, ALE_ENABLE, 0); 788 cpsw_ale_control_set(ale, 0, ALE_ENABLE, 0);
790 kfree(ale); 789 kfree(ale);
791 return 0; 790 return 0;
diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index ab92f67da035..4a4388b813ac 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -264,7 +264,7 @@ static int cpts_match(struct sk_buff *skb, unsigned int ptp_class,
264 264
265 switch (ptp_class & PTP_CLASS_PMASK) { 265 switch (ptp_class & PTP_CLASS_PMASK) {
266 case PTP_CLASS_IPV4: 266 case PTP_CLASS_IPV4:
267 offset += ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN; 267 offset += ETH_HLEN + IPV4_HLEN(data + offset) + UDP_HLEN;
268 break; 268 break;
269 case PTP_CLASS_IPV6: 269 case PTP_CLASS_IPV6:
270 offset += ETH_HLEN + IP6_HLEN + UDP_HLEN; 270 offset += ETH_HLEN + IP6_HLEN + UDP_HLEN;
diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
index 9ce854f43917..6cbc56ad9ff4 100644
--- a/drivers/net/ieee802154/fakehard.c
+++ b/drivers/net/ieee802154/fakehard.c
@@ -377,17 +377,20 @@ static int ieee802154fake_probe(struct platform_device *pdev)
377 377
378 err = wpan_phy_register(phy); 378 err = wpan_phy_register(phy);
379 if (err) 379 if (err)
380 goto out; 380 goto err_phy_reg;
381 381
382 err = register_netdev(dev); 382 err = register_netdev(dev);
383 if (err < 0) 383 if (err)
384 goto out; 384 goto err_netdev_reg;
385 385
386 dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n"); 386 dev_info(&pdev->dev, "Added ieee802154 HardMAC hardware\n");
387 return 0; 387 return 0;
388 388
389out: 389err_netdev_reg:
390 unregister_netdev(dev); 390 wpan_phy_unregister(phy);
391err_phy_reg:
392 free_netdev(dev);
393 wpan_phy_free(phy);
391 return err; 394 return err;
392} 395}
393 396
diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
index 6f226de655a4..880cc090dc44 100644
--- a/drivers/net/macvtap.c
+++ b/drivers/net/macvtap.c
@@ -629,6 +629,8 @@ static void macvtap_skb_to_vnet_hdr(const struct sk_buff *skb,
629 if (skb->ip_summed == CHECKSUM_PARTIAL) { 629 if (skb->ip_summed == CHECKSUM_PARTIAL) {
630 vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; 630 vnet_hdr->flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
631 vnet_hdr->csum_start = skb_checksum_start_offset(skb); 631 vnet_hdr->csum_start = skb_checksum_start_offset(skb);
632 if (vlan_tx_tag_present(skb))
633 vnet_hdr->csum_start += VLAN_HLEN;
632 vnet_hdr->csum_offset = skb->csum_offset; 634 vnet_hdr->csum_offset = skb->csum_offset;
633 } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) { 635 } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
634 vnet_hdr->flags = VIRTIO_NET_HDR_F_DATA_VALID; 636 vnet_hdr->flags = VIRTIO_NET_HDR_F_DATA_VALID;
diff --git a/drivers/net/phy/dp83640.c b/drivers/net/phy/dp83640.c
index 2954052706e8..e22e602beef3 100644
--- a/drivers/net/phy/dp83640.c
+++ b/drivers/net/phy/dp83640.c
@@ -791,7 +791,7 @@ static int match(struct sk_buff *skb, unsigned int type, struct rxts *rxts)
791 791
792 switch (type & PTP_CLASS_PMASK) { 792 switch (type & PTP_CLASS_PMASK) {
793 case PTP_CLASS_IPV4: 793 case PTP_CLASS_IPV4:
794 offset += ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN; 794 offset += ETH_HLEN + IPV4_HLEN(data + offset) + UDP_HLEN;
795 break; 795 break;
796 case PTP_CLASS_IPV6: 796 case PTP_CLASS_IPV6:
797 offset += ETH_HLEN + IP6_HLEN + UDP_HLEN; 797 offset += ETH_HLEN + IP6_HLEN + UDP_HLEN;
@@ -934,7 +934,7 @@ static int is_sync(struct sk_buff *skb, int type)
934 934
935 switch (type & PTP_CLASS_PMASK) { 935 switch (type & PTP_CLASS_PMASK) {
936 case PTP_CLASS_IPV4: 936 case PTP_CLASS_IPV4:
937 offset += ETH_HLEN + IPV4_HLEN(data) + UDP_HLEN; 937 offset += ETH_HLEN + IPV4_HLEN(data + offset) + UDP_HLEN;
938 break; 938 break;
939 case PTP_CLASS_IPV6: 939 case PTP_CLASS_IPV6:
940 offset += ETH_HLEN + IP6_HLEN + UDP_HLEN; 940 offset += ETH_HLEN + IP6_HLEN + UDP_HLEN;
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 1dfffdc9dfc3..767cd110f496 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -352,6 +352,7 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
352{ 352{
353 struct mii_ioctl_data *mii_data = if_mii(ifr); 353 struct mii_ioctl_data *mii_data = if_mii(ifr);
354 u16 val = mii_data->val_in; 354 u16 val = mii_data->val_in;
355 bool change_autoneg = false;
355 356
356 switch (cmd) { 357 switch (cmd) {
357 case SIOCGMIIPHY: 358 case SIOCGMIIPHY:
@@ -367,22 +368,29 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
367 if (mii_data->phy_id == phydev->addr) { 368 if (mii_data->phy_id == phydev->addr) {
368 switch (mii_data->reg_num) { 369 switch (mii_data->reg_num) {
369 case MII_BMCR: 370 case MII_BMCR:
370 if ((val & (BMCR_RESET | BMCR_ANENABLE)) == 0) 371 if ((val & (BMCR_RESET | BMCR_ANENABLE)) == 0) {
372 if (phydev->autoneg == AUTONEG_ENABLE)
373 change_autoneg = true;
371 phydev->autoneg = AUTONEG_DISABLE; 374 phydev->autoneg = AUTONEG_DISABLE;
372 else 375 if (val & BMCR_FULLDPLX)
376 phydev->duplex = DUPLEX_FULL;
377 else
378 phydev->duplex = DUPLEX_HALF;
379 if (val & BMCR_SPEED1000)
380 phydev->speed = SPEED_1000;
381 else if (val & BMCR_SPEED100)
382 phydev->speed = SPEED_100;
383 else phydev->speed = SPEED_10;
384 }
385 else {
386 if (phydev->autoneg == AUTONEG_DISABLE)
387 change_autoneg = true;
373 phydev->autoneg = AUTONEG_ENABLE; 388 phydev->autoneg = AUTONEG_ENABLE;
374 if (!phydev->autoneg && (val & BMCR_FULLDPLX)) 389 }
375 phydev->duplex = DUPLEX_FULL;
376 else
377 phydev->duplex = DUPLEX_HALF;
378 if (!phydev->autoneg && (val & BMCR_SPEED1000))
379 phydev->speed = SPEED_1000;
380 else if (!phydev->autoneg &&
381 (val & BMCR_SPEED100))
382 phydev->speed = SPEED_100;
383 break; 390 break;
384 case MII_ADVERTISE: 391 case MII_ADVERTISE:
385 phydev->advertising = val; 392 phydev->advertising = mii_adv_to_ethtool_adv_t(val);
393 change_autoneg = true;
386 break; 394 break;
387 default: 395 default:
388 /* do nothing */ 396 /* do nothing */
@@ -396,6 +404,10 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
396 if (mii_data->reg_num == MII_BMCR && 404 if (mii_data->reg_num == MII_BMCR &&
397 val & BMCR_RESET) 405 val & BMCR_RESET)
398 return phy_init_hw(phydev); 406 return phy_init_hw(phydev);
407
408 if (change_autoneg)
409 return phy_start_aneg(phydev);
410
399 return 0; 411 return 0;
400 412
401 case SIOCSHWTSTAMP: 413 case SIOCSHWTSTAMP:
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index 68c3a3f4e0ab..794a47329368 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -755,23 +755,23 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
755 755
756 err = get_filter(argp, &code); 756 err = get_filter(argp, &code);
757 if (err >= 0) { 757 if (err >= 0) {
758 struct bpf_prog *pass_filter = NULL;
758 struct sock_fprog_kern fprog = { 759 struct sock_fprog_kern fprog = {
759 .len = err, 760 .len = err,
760 .filter = code, 761 .filter = code,
761 }; 762 };
762 763
763 ppp_lock(ppp); 764 err = 0;
764 if (ppp->pass_filter) { 765 if (fprog.filter)
765 bpf_prog_destroy(ppp->pass_filter); 766 err = bpf_prog_create(&pass_filter, &fprog);
766 ppp->pass_filter = NULL; 767 if (!err) {
768 ppp_lock(ppp);
769 if (ppp->pass_filter)
770 bpf_prog_destroy(ppp->pass_filter);
771 ppp->pass_filter = pass_filter;
772 ppp_unlock(ppp);
767 } 773 }
768 if (fprog.filter != NULL)
769 err = bpf_prog_create(&ppp->pass_filter,
770 &fprog);
771 else
772 err = 0;
773 kfree(code); 774 kfree(code);
774 ppp_unlock(ppp);
775 } 775 }
776 break; 776 break;
777 } 777 }
@@ -781,23 +781,23 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
781 781
782 err = get_filter(argp, &code); 782 err = get_filter(argp, &code);
783 if (err >= 0) { 783 if (err >= 0) {
784 struct bpf_prog *active_filter = NULL;
784 struct sock_fprog_kern fprog = { 785 struct sock_fprog_kern fprog = {
785 .len = err, 786 .len = err,
786 .filter = code, 787 .filter = code,
787 }; 788 };
788 789
789 ppp_lock(ppp); 790 err = 0;
790 if (ppp->active_filter) { 791 if (fprog.filter)
791 bpf_prog_destroy(ppp->active_filter); 792 err = bpf_prog_create(&active_filter, &fprog);
792 ppp->active_filter = NULL; 793 if (!err) {
794 ppp_lock(ppp);
795 if (ppp->active_filter)
796 bpf_prog_destroy(ppp->active_filter);
797 ppp->active_filter = active_filter;
798 ppp_unlock(ppp);
793 } 799 }
794 if (fprog.filter != NULL)
795 err = bpf_prog_create(&ppp->active_filter,
796 &fprog);
797 else
798 err = 0;
799 kfree(code); 800 kfree(code);
800 ppp_unlock(ppp);
801 } 801 }
802 break; 802 break;
803 } 803 }
diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
index 1aff970be33e..1dc628ffce2b 100644
--- a/drivers/net/ppp/pptp.c
+++ b/drivers/net/ppp/pptp.c
@@ -506,7 +506,9 @@ static int pptp_getname(struct socket *sock, struct sockaddr *uaddr,
506 int len = sizeof(struct sockaddr_pppox); 506 int len = sizeof(struct sockaddr_pppox);
507 struct sockaddr_pppox sp; 507 struct sockaddr_pppox sp;
508 508
509 sp.sa_family = AF_PPPOX; 509 memset(&sp.sa_addr, 0, sizeof(sp.sa_addr));
510
511 sp.sa_family = AF_PPPOX;
510 sp.sa_protocol = PX_PROTO_PPTP; 512 sp.sa_protocol = PX_PROTO_PPTP;
511 sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr; 513 sp.sa_addr.pptp = pppox_sk(sock->sk)->proto.pptp.src_addr;
512 514
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 7302398f0b1f..9dd3746994a4 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1235,12 +1235,20 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1235 struct tun_pi pi = { 0, skb->protocol }; 1235 struct tun_pi pi = { 0, skb->protocol };
1236 ssize_t total = 0; 1236 ssize_t total = 0;
1237 int vlan_offset = 0, copied; 1237 int vlan_offset = 0, copied;
1238 int vlan_hlen = 0;
1239 int vnet_hdr_sz = 0;
1240
1241 if (vlan_tx_tag_present(skb))
1242 vlan_hlen = VLAN_HLEN;
1243
1244 if (tun->flags & TUN_VNET_HDR)
1245 vnet_hdr_sz = tun->vnet_hdr_sz;
1238 1246
1239 if (!(tun->flags & TUN_NO_PI)) { 1247 if (!(tun->flags & TUN_NO_PI)) {
1240 if ((len -= sizeof(pi)) < 0) 1248 if ((len -= sizeof(pi)) < 0)
1241 return -EINVAL; 1249 return -EINVAL;
1242 1250
1243 if (len < skb->len) { 1251 if (len < skb->len + vlan_hlen + vnet_hdr_sz) {
1244 /* Packet will be striped */ 1252 /* Packet will be striped */
1245 pi.flags |= TUN_PKT_STRIP; 1253 pi.flags |= TUN_PKT_STRIP;
1246 } 1254 }
@@ -1250,9 +1258,9 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1250 total += sizeof(pi); 1258 total += sizeof(pi);
1251 } 1259 }
1252 1260
1253 if (tun->flags & TUN_VNET_HDR) { 1261 if (vnet_hdr_sz) {
1254 struct virtio_net_hdr gso = { 0 }; /* no info leak */ 1262 struct virtio_net_hdr gso = { 0 }; /* no info leak */
1255 if ((len -= tun->vnet_hdr_sz) < 0) 1263 if ((len -= vnet_hdr_sz) < 0)
1256 return -EINVAL; 1264 return -EINVAL;
1257 1265
1258 if (skb_is_gso(skb)) { 1266 if (skb_is_gso(skb)) {
@@ -1284,7 +1292,8 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1284 1292
1285 if (skb->ip_summed == CHECKSUM_PARTIAL) { 1293 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1286 gso.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM; 1294 gso.flags = VIRTIO_NET_HDR_F_NEEDS_CSUM;
1287 gso.csum_start = skb_checksum_start_offset(skb); 1295 gso.csum_start = skb_checksum_start_offset(skb) +
1296 vlan_hlen;
1288 gso.csum_offset = skb->csum_offset; 1297 gso.csum_offset = skb->csum_offset;
1289 } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) { 1298 } else if (skb->ip_summed == CHECKSUM_UNNECESSARY) {
1290 gso.flags = VIRTIO_NET_HDR_F_DATA_VALID; 1299 gso.flags = VIRTIO_NET_HDR_F_DATA_VALID;
@@ -1293,14 +1302,13 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1293 if (unlikely(memcpy_toiovecend(iv, (void *)&gso, total, 1302 if (unlikely(memcpy_toiovecend(iv, (void *)&gso, total,
1294 sizeof(gso)))) 1303 sizeof(gso))))
1295 return -EFAULT; 1304 return -EFAULT;
1296 total += tun->vnet_hdr_sz; 1305 total += vnet_hdr_sz;
1297 } 1306 }
1298 1307
1299 copied = total; 1308 copied = total;
1300 total += skb->len; 1309 len = min_t(int, skb->len + vlan_hlen, len);
1301 if (!vlan_tx_tag_present(skb)) { 1310 total += skb->len + vlan_hlen;
1302 len = min_t(int, skb->len, len); 1311 if (vlan_hlen) {
1303 } else {
1304 int copy, ret; 1312 int copy, ret;
1305 struct { 1313 struct {
1306 __be16 h_vlan_proto; 1314 __be16 h_vlan_proto;
@@ -1311,8 +1319,6 @@ static ssize_t tun_put_user(struct tun_struct *tun,
1311 veth.h_vlan_TCI = htons(vlan_tx_tag_get(skb)); 1319 veth.h_vlan_TCI = htons(vlan_tx_tag_get(skb));
1312 1320
1313 vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto); 1321 vlan_offset = offsetof(struct vlan_ethhdr, h_vlan_proto);
1314 len = min_t(int, skb->len + VLAN_HLEN, len);
1315 total += VLAN_HLEN;
1316 1322
1317 copy = min_t(int, vlan_offset, len); 1323 copy = min_t(int, vlan_offset, len);
1318 ret = skb_copy_datagram_const_iovec(skb, 0, iv, copied, copy); 1324 ret = skb_copy_datagram_const_iovec(skb, 0, iv, copied, copy);
diff --git a/drivers/net/usb/asix_devices.c b/drivers/net/usb/asix_devices.c
index 2c05f6cdb12f..816d511e34d3 100644
--- a/drivers/net/usb/asix_devices.c
+++ b/drivers/net/usb/asix_devices.c
@@ -465,19 +465,7 @@ static int ax88772_bind(struct usbnet *dev, struct usb_interface *intf)
465 return ret; 465 return ret;
466 } 466 }
467 467
468 ret = asix_sw_reset(dev, AX_SWRESET_IPPD | AX_SWRESET_PRL); 468 ax88772_reset(dev);
469 if (ret < 0)
470 return ret;
471
472 msleep(150);
473
474 ret = asix_sw_reset(dev, AX_SWRESET_CLEAR);
475 if (ret < 0)
476 return ret;
477
478 msleep(150);
479
480 ret = asix_sw_reset(dev, embd_phy ? AX_SWRESET_IPRL : AX_SWRESET_PRTE);
481 469
482 /* Read PHYID register *AFTER* the PHY was reset properly */ 470 /* Read PHYID register *AFTER* the PHY was reset properly */
483 phyid = asix_get_phyid(dev); 471 phyid = asix_get_phyid(dev);
diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 22756db53dca..b8a82b86f909 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -780,6 +780,7 @@ static const struct usb_device_id products[] = {
780 {QMI_FIXED_INTF(0x413c, 0x81a4, 8)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card */ 780 {QMI_FIXED_INTF(0x413c, 0x81a4, 8)}, /* Dell Wireless 5570e HSPA+ (42Mbps) Mobile Broadband Card */
781 {QMI_FIXED_INTF(0x413c, 0x81a8, 8)}, /* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card */ 781 {QMI_FIXED_INTF(0x413c, 0x81a8, 8)}, /* Dell Wireless 5808 Gobi(TM) 4G LTE Mobile Broadband Card */
782 {QMI_FIXED_INTF(0x413c, 0x81a9, 8)}, /* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card */ 782 {QMI_FIXED_INTF(0x413c, 0x81a9, 8)}, /* Dell Wireless 5808e Gobi(TM) 4G LTE Mobile Broadband Card */
783 {QMI_FIXED_INTF(0x03f0, 0x581d, 4)}, /* HP lt4112 LTE/HSPA+ Gobi 4G Module (Huawei me906e) */
783 784
784 /* 4. Gobi 1000 devices */ 785 /* 4. Gobi 1000 devices */
785 {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */ 786 {QMI_GOBI1K_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index ec2a8b41ed41..b0bc8ead47de 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -1673,6 +1673,40 @@ static const struct attribute_group virtio_net_mrg_rx_group = {
1673}; 1673};
1674#endif 1674#endif
1675 1675
1676static bool virtnet_fail_on_feature(struct virtio_device *vdev,
1677 unsigned int fbit,
1678 const char *fname, const char *dname)
1679{
1680 if (!virtio_has_feature(vdev, fbit))
1681 return false;
1682
1683 dev_err(&vdev->dev, "device advertises feature %s but not %s",
1684 fname, dname);
1685
1686 return true;
1687}
1688
1689#define VIRTNET_FAIL_ON(vdev, fbit, dbit) \
1690 virtnet_fail_on_feature(vdev, fbit, #fbit, dbit)
1691
1692static bool virtnet_validate_features(struct virtio_device *vdev)
1693{
1694 if (!virtio_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ) &&
1695 (VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_RX,
1696 "VIRTIO_NET_F_CTRL_VQ") ||
1697 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_VLAN,
1698 "VIRTIO_NET_F_CTRL_VQ") ||
1699 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_GUEST_ANNOUNCE,
1700 "VIRTIO_NET_F_CTRL_VQ") ||
1701 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_MQ, "VIRTIO_NET_F_CTRL_VQ") ||
1702 VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_CTRL_MAC_ADDR,
1703 "VIRTIO_NET_F_CTRL_VQ"))) {
1704 return false;
1705 }
1706
1707 return true;
1708}
1709
1676static int virtnet_probe(struct virtio_device *vdev) 1710static int virtnet_probe(struct virtio_device *vdev)
1677{ 1711{
1678 int i, err; 1712 int i, err;
@@ -1680,6 +1714,9 @@ static int virtnet_probe(struct virtio_device *vdev)
1680 struct virtnet_info *vi; 1714 struct virtnet_info *vi;
1681 u16 max_queue_pairs; 1715 u16 max_queue_pairs;
1682 1716
1717 if (!virtnet_validate_features(vdev))
1718 return -EINVAL;
1719
1683 /* Find if host supports multiqueue virtio_net device */ 1720 /* Find if host supports multiqueue virtio_net device */
1684 err = virtio_cread_feature(vdev, VIRTIO_NET_F_MQ, 1721 err = virtio_cread_feature(vdev, VIRTIO_NET_F_MQ,
1685 struct virtio_net_config, 1722 struct virtio_net_config,
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index ca309820d39e..be4649a49c5e 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -67,12 +67,6 @@
67 67
68#define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */ 68#define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */
69 69
70/* VXLAN protocol header */
71struct vxlanhdr {
72 __be32 vx_flags;
73 __be32 vx_vni;
74};
75
76/* UDP port for VXLAN traffic. 70/* UDP port for VXLAN traffic.
77 * The IANA assigned port is 4789, but the Linux default is 8472 71 * The IANA assigned port is 4789, but the Linux default is 8472
78 * for compatibility with early adopters. 72 * for compatibility with early adopters.
@@ -275,13 +269,15 @@ static inline struct vxlan_rdst *first_remote_rtnl(struct vxlan_fdb *fdb)
275 return list_first_entry(&fdb->remotes, struct vxlan_rdst, list); 269 return list_first_entry(&fdb->remotes, struct vxlan_rdst, list);
276} 270}
277 271
278/* Find VXLAN socket based on network namespace and UDP port */ 272/* Find VXLAN socket based on network namespace, address family and UDP port */
279static struct vxlan_sock *vxlan_find_sock(struct net *net, __be16 port) 273static struct vxlan_sock *vxlan_find_sock(struct net *net,
274 sa_family_t family, __be16 port)
280{ 275{
281 struct vxlan_sock *vs; 276 struct vxlan_sock *vs;
282 277
283 hlist_for_each_entry_rcu(vs, vs_head(net, port), hlist) { 278 hlist_for_each_entry_rcu(vs, vs_head(net, port), hlist) {
284 if (inet_sk(vs->sock->sk)->inet_sport == port) 279 if (inet_sk(vs->sock->sk)->inet_sport == port &&
280 inet_sk(vs->sock->sk)->sk.sk_family == family)
285 return vs; 281 return vs;
286 } 282 }
287 return NULL; 283 return NULL;
@@ -300,11 +296,12 @@ static struct vxlan_dev *vxlan_vs_find_vni(struct vxlan_sock *vs, u32 id)
300} 296}
301 297
302/* Look up VNI in a per net namespace table */ 298/* Look up VNI in a per net namespace table */
303static struct vxlan_dev *vxlan_find_vni(struct net *net, u32 id, __be16 port) 299static struct vxlan_dev *vxlan_find_vni(struct net *net, u32 id,
300 sa_family_t family, __be16 port)
304{ 301{
305 struct vxlan_sock *vs; 302 struct vxlan_sock *vs;
306 303
307 vs = vxlan_find_sock(net, port); 304 vs = vxlan_find_sock(net, family, port);
308 if (!vs) 305 if (!vs)
309 return NULL; 306 return NULL;
310 307
@@ -621,6 +618,8 @@ static int vxlan_gro_complete(struct sk_buff *skb, int nhoff)
621 int vxlan_len = sizeof(struct vxlanhdr) + sizeof(struct ethhdr); 618 int vxlan_len = sizeof(struct vxlanhdr) + sizeof(struct ethhdr);
622 int err = -ENOSYS; 619 int err = -ENOSYS;
623 620
621 udp_tunnel_gro_complete(skb, nhoff);
622
624 eh = (struct ethhdr *)(skb->data + nhoff + sizeof(struct vxlanhdr)); 623 eh = (struct ethhdr *)(skb->data + nhoff + sizeof(struct vxlanhdr));
625 type = eh->h_proto; 624 type = eh->h_proto;
626 625
@@ -1771,7 +1770,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1771 struct vxlan_dev *dst_vxlan; 1770 struct vxlan_dev *dst_vxlan;
1772 1771
1773 ip_rt_put(rt); 1772 ip_rt_put(rt);
1774 dst_vxlan = vxlan_find_vni(vxlan->net, vni, dst_port); 1773 dst_vxlan = vxlan_find_vni(vxlan->net, vni,
1774 dst->sa.sa_family, dst_port);
1775 if (!dst_vxlan) 1775 if (!dst_vxlan)
1776 goto tx_error; 1776 goto tx_error;
1777 vxlan_encap_bypass(skb, vxlan, dst_vxlan); 1777 vxlan_encap_bypass(skb, vxlan, dst_vxlan);
@@ -1825,7 +1825,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
1825 struct vxlan_dev *dst_vxlan; 1825 struct vxlan_dev *dst_vxlan;
1826 1826
1827 dst_release(ndst); 1827 dst_release(ndst);
1828 dst_vxlan = vxlan_find_vni(vxlan->net, vni, dst_port); 1828 dst_vxlan = vxlan_find_vni(vxlan->net, vni,
1829 dst->sa.sa_family, dst_port);
1829 if (!dst_vxlan) 1830 if (!dst_vxlan)
1830 goto tx_error; 1831 goto tx_error;
1831 vxlan_encap_bypass(skb, vxlan, dst_vxlan); 1832 vxlan_encap_bypass(skb, vxlan, dst_vxlan);
@@ -1985,13 +1986,15 @@ static int vxlan_init(struct net_device *dev)
1985 struct vxlan_dev *vxlan = netdev_priv(dev); 1986 struct vxlan_dev *vxlan = netdev_priv(dev);
1986 struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id); 1987 struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id);
1987 struct vxlan_sock *vs; 1988 struct vxlan_sock *vs;
1989 bool ipv6 = vxlan->flags & VXLAN_F_IPV6;
1988 1990
1989 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); 1991 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
1990 if (!dev->tstats) 1992 if (!dev->tstats)
1991 return -ENOMEM; 1993 return -ENOMEM;
1992 1994
1993 spin_lock(&vn->sock_lock); 1995 spin_lock(&vn->sock_lock);
1994 vs = vxlan_find_sock(vxlan->net, vxlan->dst_port); 1996 vs = vxlan_find_sock(vxlan->net, ipv6 ? AF_INET6 : AF_INET,
1997 vxlan->dst_port);
1995 if (vs) { 1998 if (vs) {
1996 /* If we have a socket with same port already, reuse it */ 1999 /* If we have a socket with same port already, reuse it */
1997 atomic_inc(&vs->refcnt); 2000 atomic_inc(&vs->refcnt);
@@ -2303,9 +2306,9 @@ static struct socket *vxlan_create_sock(struct net *net, bool ipv6,
2303 if (ipv6) { 2306 if (ipv6) {
2304 udp_conf.family = AF_INET6; 2307 udp_conf.family = AF_INET6;
2305 udp_conf.use_udp6_tx_checksums = 2308 udp_conf.use_udp6_tx_checksums =
2306 !!(flags & VXLAN_F_UDP_ZERO_CSUM6_TX); 2309 !(flags & VXLAN_F_UDP_ZERO_CSUM6_TX);
2307 udp_conf.use_udp6_rx_checksums = 2310 udp_conf.use_udp6_rx_checksums =
2308 !!(flags & VXLAN_F_UDP_ZERO_CSUM6_RX); 2311 !(flags & VXLAN_F_UDP_ZERO_CSUM6_RX);
2309 } else { 2312 } else {
2310 udp_conf.family = AF_INET; 2313 udp_conf.family = AF_INET;
2311 udp_conf.local_ip.s_addr = INADDR_ANY; 2314 udp_conf.local_ip.s_addr = INADDR_ANY;
@@ -2382,6 +2385,7 @@ struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
2382{ 2385{
2383 struct vxlan_net *vn = net_generic(net, vxlan_net_id); 2386 struct vxlan_net *vn = net_generic(net, vxlan_net_id);
2384 struct vxlan_sock *vs; 2387 struct vxlan_sock *vs;
2388 bool ipv6 = flags & VXLAN_F_IPV6;
2385 2389
2386 vs = vxlan_socket_create(net, port, rcv, data, flags); 2390 vs = vxlan_socket_create(net, port, rcv, data, flags);
2387 if (!IS_ERR(vs)) 2391 if (!IS_ERR(vs))
@@ -2391,7 +2395,7 @@ struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
2391 return vs; 2395 return vs;
2392 2396
2393 spin_lock(&vn->sock_lock); 2397 spin_lock(&vn->sock_lock);
2394 vs = vxlan_find_sock(net, port); 2398 vs = vxlan_find_sock(net, ipv6 ? AF_INET6 : AF_INET, port);
2395 if (vs) { 2399 if (vs) {
2396 if (vs->rcv == rcv) 2400 if (vs->rcv == rcv)
2397 atomic_inc(&vs->refcnt); 2401 atomic_inc(&vs->refcnt);
@@ -2550,7 +2554,8 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
2550 nla_get_u8(data[IFLA_VXLAN_UDP_ZERO_CSUM6_RX])) 2554 nla_get_u8(data[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]))
2551 vxlan->flags |= VXLAN_F_UDP_ZERO_CSUM6_RX; 2555 vxlan->flags |= VXLAN_F_UDP_ZERO_CSUM6_RX;
2552 2556
2553 if (vxlan_find_vni(net, vni, vxlan->dst_port)) { 2557 if (vxlan_find_vni(net, vni, use_ipv6 ? AF_INET6 : AF_INET,
2558 vxlan->dst_port)) {
2554 pr_info("duplicate VNI %u\n", vni); 2559 pr_info("duplicate VNI %u\n", vni);
2555 return -EEXIST; 2560 return -EEXIST;
2556 } 2561 }
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index 697c4ae90af0..1e8ea5e4d4ca 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -664,6 +664,19 @@ static void ar9003_hw_override_ini(struct ath_hw *ah)
664 ah->enabled_cals |= TX_CL_CAL; 664 ah->enabled_cals |= TX_CL_CAL;
665 else 665 else
666 ah->enabled_cals &= ~TX_CL_CAL; 666 ah->enabled_cals &= ~TX_CL_CAL;
667
668 if (AR_SREV_9340(ah) || AR_SREV_9531(ah) || AR_SREV_9550(ah)) {
669 if (ah->is_clk_25mhz) {
670 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
671 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
672 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
673 } else {
674 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
675 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
676 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
677 }
678 udelay(100);
679 }
667} 680}
668 681
669static void ar9003_hw_prog_ini(struct ath_hw *ah, 682static void ar9003_hw_prog_ini(struct ath_hw *ah,
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index 8be4b1453394..2ad605760e21 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -861,19 +861,6 @@ static void ath9k_hw_init_pll(struct ath_hw *ah,
861 udelay(RTC_PLL_SETTLE_DELAY); 861 udelay(RTC_PLL_SETTLE_DELAY);
862 862
863 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK); 863 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
864
865 if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
866 if (ah->is_clk_25mhz) {
867 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
868 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
869 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
870 } else {
871 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
872 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
873 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
874 }
875 udelay(100);
876 }
877} 864}
878 865
879static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah, 866static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
index 30c66dfcd7a0..4f18a6be0c7d 100644
--- a/drivers/net/wireless/ath/ath9k/main.c
+++ b/drivers/net/wireless/ath/ath9k/main.c
@@ -974,9 +974,8 @@ void ath9k_calculate_iter_data(struct ath_softc *sc,
974 struct ath_vif *avp; 974 struct ath_vif *avp;
975 975
976 /* 976 /*
977 * Pick the MAC address of the first interface as the new hardware 977 * The hardware will use primary station addr together with the
978 * MAC address. The hardware will use it together with the BSSID mask 978 * BSSID mask when matching addresses.
979 * when matching addresses.
980 */ 979 */
981 memset(iter_data, 0, sizeof(*iter_data)); 980 memset(iter_data, 0, sizeof(*iter_data));
982 memset(&iter_data->mask, 0xff, ETH_ALEN); 981 memset(&iter_data->mask, 0xff, ETH_ALEN);
@@ -1205,6 +1204,8 @@ static int ath9k_add_interface(struct ieee80211_hw *hw,
1205 list_add_tail(&avp->list, &avp->chanctx->vifs); 1204 list_add_tail(&avp->list, &avp->chanctx->vifs);
1206 } 1205 }
1207 1206
1207 ath9k_calculate_summary_state(sc, avp->chanctx);
1208
1208 ath9k_assign_hw_queues(hw, vif); 1209 ath9k_assign_hw_queues(hw, vif);
1209 1210
1210 an->sc = sc; 1211 an->sc = sc;
@@ -1274,6 +1275,8 @@ static void ath9k_remove_interface(struct ieee80211_hw *hw,
1274 1275
1275 ath_tx_node_cleanup(sc, &avp->mcast_node); 1276 ath_tx_node_cleanup(sc, &avp->mcast_node);
1276 1277
1278 ath9k_calculate_summary_state(sc, avp->chanctx);
1279
1277 mutex_unlock(&sc->mutex); 1280 mutex_unlock(&sc->mutex);
1278} 1281}
1279 1282
diff --git a/drivers/net/wireless/b43/phy_common.c b/drivers/net/wireless/b43/phy_common.c
index 1dfc682a8055..ee27b06074e1 100644
--- a/drivers/net/wireless/b43/phy_common.c
+++ b/drivers/net/wireless/b43/phy_common.c
@@ -300,9 +300,7 @@ void b43_phy_write(struct b43_wldev *dev, u16 reg, u16 value)
300 300
301void b43_phy_copy(struct b43_wldev *dev, u16 destreg, u16 srcreg) 301void b43_phy_copy(struct b43_wldev *dev, u16 destreg, u16 srcreg)
302{ 302{
303 assert_mac_suspended(dev); 303 b43_phy_write(dev, destreg, b43_phy_read(dev, srcreg));
304 dev->phy.ops->phy_write(dev, destreg,
305 dev->phy.ops->phy_read(dev, srcreg));
306} 304}
307 305
308void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask) 306void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask)
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/of.c b/drivers/net/wireless/brcm80211/brcmfmac/of.c
index f05f5270fec1..927bffd5be64 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/of.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/of.c
@@ -40,8 +40,8 @@ void brcmf_of_probe(struct brcmf_sdio_dev *sdiodev)
40 return; 40 return;
41 41
42 irq = irq_of_parse_and_map(np, 0); 42 irq = irq_of_parse_and_map(np, 0);
43 if (irq < 0) { 43 if (!irq) {
44 brcmf_err("interrupt could not be mapped: err=%d\n", irq); 44 brcmf_err("interrupt could not be mapped\n");
45 devm_kfree(dev, sdiodev->pdata); 45 devm_kfree(dev, sdiodev->pdata);
46 return; 46 return;
47 } 47 }
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
index 8c0632ec9f7a..16fef3382019 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/pcie.c
@@ -19,10 +19,10 @@
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/vmalloc.h> 20#include <linux/vmalloc.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/unaligned/access_ok.h>
23#include <linux/interrupt.h> 22#include <linux/interrupt.h>
24#include <linux/bcma/bcma.h> 23#include <linux/bcma/bcma.h>
25#include <linux/sched.h> 24#include <linux/sched.h>
25#include <asm/unaligned.h>
26 26
27#include <soc.h> 27#include <soc.h>
28#include <chipcommon.h> 28#include <chipcommon.h>
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/usb.c b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
index dc135915470d..875d1142c8b0 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/usb.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/usb.c
@@ -669,10 +669,12 @@ static int brcmf_usb_dl_cmd(struct brcmf_usbdev_info *devinfo, u8 cmd,
669 goto finalize; 669 goto finalize;
670 } 670 }
671 671
672 if (!brcmf_usb_ioctl_resp_wait(devinfo)) 672 if (!brcmf_usb_ioctl_resp_wait(devinfo)) {
673 usb_kill_urb(devinfo->ctl_urb);
673 ret = -ETIMEDOUT; 674 ret = -ETIMEDOUT;
674 else 675 } else {
675 memcpy(buffer, tmpbuf, buflen); 676 memcpy(buffer, tmpbuf, buflen);
677 }
676 678
677finalize: 679finalize:
678 kfree(tmpbuf); 680 kfree(tmpbuf);
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
index 28fa25b509db..39b45c038a93 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
@@ -299,6 +299,7 @@ static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
299 primary_offset = ch->center_freq1 - ch->chan->center_freq; 299 primary_offset = ch->center_freq1 - ch->chan->center_freq;
300 switch (ch->width) { 300 switch (ch->width) {
301 case NL80211_CHAN_WIDTH_20: 301 case NL80211_CHAN_WIDTH_20:
302 case NL80211_CHAN_WIDTH_20_NOHT:
302 ch_inf.bw = BRCMU_CHAN_BW_20; 303 ch_inf.bw = BRCMU_CHAN_BW_20;
303 WARN_ON(primary_offset != 0); 304 WARN_ON(primary_offset != 0);
304 break; 305 break;
@@ -323,6 +324,10 @@ static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
323 ch_inf.sb = BRCMU_CHAN_SB_LU; 324 ch_inf.sb = BRCMU_CHAN_SB_LU;
324 } 325 }
325 break; 326 break;
327 case NL80211_CHAN_WIDTH_80P80:
328 case NL80211_CHAN_WIDTH_160:
329 case NL80211_CHAN_WIDTH_5:
330 case NL80211_CHAN_WIDTH_10:
326 default: 331 default:
327 WARN_ON_ONCE(1); 332 WARN_ON_ONCE(1);
328 } 333 }
@@ -333,6 +338,7 @@ static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
333 case IEEE80211_BAND_5GHZ: 338 case IEEE80211_BAND_5GHZ:
334 ch_inf.band = BRCMU_CHAN_BAND_5G; 339 ch_inf.band = BRCMU_CHAN_BAND_5G;
335 break; 340 break;
341 case IEEE80211_BAND_60GHZ:
336 default: 342 default:
337 WARN_ON_ONCE(1); 343 WARN_ON_ONCE(1);
338 } 344 }
diff --git a/drivers/net/wireless/iwlwifi/iwl-fw.h b/drivers/net/wireless/iwlwifi/iwl-fw.h
index 4f6e66892acc..b894a84e8393 100644
--- a/drivers/net/wireless/iwlwifi/iwl-fw.h
+++ b/drivers/net/wireless/iwlwifi/iwl-fw.h
@@ -155,6 +155,7 @@ enum iwl_ucode_tlv_api {
155 * @IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT: supports Quiet Period requests 155 * @IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT: supports Quiet Period requests
156 * @IWL_UCODE_TLV_CAPA_DQA_SUPPORT: supports dynamic queue allocation (DQA), 156 * @IWL_UCODE_TLV_CAPA_DQA_SUPPORT: supports dynamic queue allocation (DQA),
157 * which also implies support for the scheduler configuration command 157 * which also implies support for the scheduler configuration command
158 * @IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT: supports Hot Spot Command
158 */ 159 */
159enum iwl_ucode_tlv_capa { 160enum iwl_ucode_tlv_capa {
160 IWL_UCODE_TLV_CAPA_D0I3_SUPPORT = BIT(0), 161 IWL_UCODE_TLV_CAPA_D0I3_SUPPORT = BIT(0),
@@ -163,6 +164,7 @@ enum iwl_ucode_tlv_capa {
163 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT = BIT(10), 164 IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT = BIT(10),
164 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT = BIT(11), 165 IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT = BIT(11),
165 IWL_UCODE_TLV_CAPA_DQA_SUPPORT = BIT(12), 166 IWL_UCODE_TLV_CAPA_DQA_SUPPORT = BIT(12),
167 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT = BIT(18),
166}; 168};
167 169
168/* The default calibrate table size if not specified by firmware file */ 170/* The default calibrate table size if not specified by firmware file */
diff --git a/drivers/net/wireless/iwlwifi/mvm/fw.c b/drivers/net/wireless/iwlwifi/mvm/fw.c
index e0d9f19650b0..eb03943f8463 100644
--- a/drivers/net/wireless/iwlwifi/mvm/fw.c
+++ b/drivers/net/wireless/iwlwifi/mvm/fw.c
@@ -284,7 +284,7 @@ int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
284 284
285 lockdep_assert_held(&mvm->mutex); 285 lockdep_assert_held(&mvm->mutex);
286 286
287 if (WARN_ON_ONCE(mvm->init_ucode_complete)) 287 if (WARN_ON_ONCE(mvm->init_ucode_complete || mvm->calibrating))
288 return 0; 288 return 0;
289 289
290 iwl_init_notification_wait(&mvm->notif_wait, 290 iwl_init_notification_wait(&mvm->notif_wait,
@@ -334,6 +334,8 @@ int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
334 goto out; 334 goto out;
335 } 335 }
336 336
337 mvm->calibrating = true;
338
337 /* Send TX valid antennas before triggering calibrations */ 339 /* Send TX valid antennas before triggering calibrations */
338 ret = iwl_send_tx_ant_cfg(mvm, mvm->fw->valid_tx_ant); 340 ret = iwl_send_tx_ant_cfg(mvm, mvm->fw->valid_tx_ant);
339 if (ret) 341 if (ret)
@@ -358,11 +360,17 @@ int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
358 MVM_UCODE_CALIB_TIMEOUT); 360 MVM_UCODE_CALIB_TIMEOUT);
359 if (!ret) 361 if (!ret)
360 mvm->init_ucode_complete = true; 362 mvm->init_ucode_complete = true;
363
364 if (ret && iwl_mvm_is_radio_killed(mvm)) {
365 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
366 ret = 1;
367 }
361 goto out; 368 goto out;
362 369
363error: 370error:
364 iwl_remove_notification(&mvm->notif_wait, &calib_wait); 371 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
365out: 372out:
373 mvm->calibrating = false;
366 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) { 374 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
367 /* we want to debug INIT and we have no NVM - fake */ 375 /* we want to debug INIT and we have no NVM - fake */
368 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) + 376 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
diff --git a/drivers/net/wireless/iwlwifi/mvm/mac80211.c b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
index 585fe5b7100f..b6d2683da3a9 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mac80211.c
+++ b/drivers/net/wireless/iwlwifi/mvm/mac80211.c
@@ -788,6 +788,7 @@ static void iwl_mvm_restart_cleanup(struct iwl_mvm *mvm)
788 788
789 mvm->scan_status = IWL_MVM_SCAN_NONE; 789 mvm->scan_status = IWL_MVM_SCAN_NONE;
790 mvm->ps_disabled = false; 790 mvm->ps_disabled = false;
791 mvm->calibrating = false;
791 792
792 /* just in case one was running */ 793 /* just in case one was running */
793 ieee80211_remain_on_channel_expired(mvm->hw); 794 ieee80211_remain_on_channel_expired(mvm->hw);
@@ -2447,9 +2448,15 @@ static int iwl_mvm_roc(struct ieee80211_hw *hw,
2447 2448
2448 switch (vif->type) { 2449 switch (vif->type) {
2449 case NL80211_IFTYPE_STATION: 2450 case NL80211_IFTYPE_STATION:
2450 /* Use aux roc framework (HS20) */ 2451 if (mvm->fw->ucode_capa.capa[0] &
2451 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel, 2452 IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT) {
2452 vif, duration); 2453 /* Use aux roc framework (HS20) */
2454 ret = iwl_mvm_send_aux_roc_cmd(mvm, channel,
2455 vif, duration);
2456 goto out_unlock;
2457 }
2458 IWL_ERR(mvm, "hotspot not supported\n");
2459 ret = -EINVAL;
2453 goto out_unlock; 2460 goto out_unlock;
2454 case NL80211_IFTYPE_P2P_DEVICE: 2461 case NL80211_IFTYPE_P2P_DEVICE:
2455 /* handle below */ 2462 /* handle below */
diff --git a/drivers/net/wireless/iwlwifi/mvm/mvm.h b/drivers/net/wireless/iwlwifi/mvm/mvm.h
index b153ced7015b..845429c88cf4 100644
--- a/drivers/net/wireless/iwlwifi/mvm/mvm.h
+++ b/drivers/net/wireless/iwlwifi/mvm/mvm.h
@@ -548,6 +548,7 @@ struct iwl_mvm {
548 enum iwl_ucode_type cur_ucode; 548 enum iwl_ucode_type cur_ucode;
549 bool ucode_loaded; 549 bool ucode_loaded;
550 bool init_ucode_complete; 550 bool init_ucode_complete;
551 bool calibrating;
551 u32 error_event_table; 552 u32 error_event_table;
552 u32 log_event_table; 553 u32 log_event_table;
553 u32 umac_error_event_table; 554 u32 umac_error_event_table;
diff --git a/drivers/net/wireless/iwlwifi/mvm/ops.c b/drivers/net/wireless/iwlwifi/mvm/ops.c
index 48cb25a93591..5b719ee8e789 100644
--- a/drivers/net/wireless/iwlwifi/mvm/ops.c
+++ b/drivers/net/wireless/iwlwifi/mvm/ops.c
@@ -424,6 +424,7 @@ iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
424 } 424 }
425 mvm->sf_state = SF_UNINIT; 425 mvm->sf_state = SF_UNINIT;
426 mvm->low_latency_agg_frame_limit = 6; 426 mvm->low_latency_agg_frame_limit = 6;
427 mvm->cur_ucode = IWL_UCODE_INIT;
427 428
428 mutex_init(&mvm->mutex); 429 mutex_init(&mvm->mutex);
429 mutex_init(&mvm->d0i3_suspend_mutex); 430 mutex_init(&mvm->d0i3_suspend_mutex);
@@ -752,6 +753,7 @@ void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state)
752static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state) 753static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
753{ 754{
754 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode); 755 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
756 bool calibrating = ACCESS_ONCE(mvm->calibrating);
755 757
756 if (state) 758 if (state)
757 set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status); 759 set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
@@ -760,7 +762,15 @@ static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
760 762
761 wiphy_rfkill_set_hw_state(mvm->hw->wiphy, iwl_mvm_is_radio_killed(mvm)); 763 wiphy_rfkill_set_hw_state(mvm->hw->wiphy, iwl_mvm_is_radio_killed(mvm));
762 764
763 return state && mvm->cur_ucode != IWL_UCODE_INIT; 765 /* iwl_run_init_mvm_ucode is waiting for results, abort it */
766 if (calibrating)
767 iwl_abort_notification_waits(&mvm->notif_wait);
768
769 /*
770 * Stop the device if we run OPERATIONAL firmware or if we are in the
771 * middle of the calibrations.
772 */
773 return state && (mvm->cur_ucode != IWL_UCODE_INIT || calibrating);
764} 774}
765 775
766static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb) 776static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
diff --git a/drivers/net/wireless/iwlwifi/mvm/scan.c b/drivers/net/wireless/iwlwifi/mvm/scan.c
index b280d5d87127..7554f7053830 100644
--- a/drivers/net/wireless/iwlwifi/mvm/scan.c
+++ b/drivers/net/wireless/iwlwifi/mvm/scan.c
@@ -602,16 +602,6 @@ static int iwl_mvm_cancel_regular_scan(struct iwl_mvm *mvm)
602 SCAN_COMPLETE_NOTIFICATION }; 602 SCAN_COMPLETE_NOTIFICATION };
603 int ret; 603 int ret;
604 604
605 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
606 return 0;
607
608 if (iwl_mvm_is_radio_killed(mvm)) {
609 ieee80211_scan_completed(mvm->hw, true);
610 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
611 mvm->scan_status = IWL_MVM_SCAN_NONE;
612 return 0;
613 }
614
615 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort, 605 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort,
616 scan_abort_notif, 606 scan_abort_notif,
617 ARRAY_SIZE(scan_abort_notif), 607 ARRAY_SIZE(scan_abort_notif),
@@ -1400,6 +1390,16 @@ int iwl_mvm_unified_sched_scan_lmac(struct iwl_mvm *mvm,
1400 1390
1401int iwl_mvm_cancel_scan(struct iwl_mvm *mvm) 1391int iwl_mvm_cancel_scan(struct iwl_mvm *mvm)
1402{ 1392{
1393 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
1394 return 0;
1395
1396 if (iwl_mvm_is_radio_killed(mvm)) {
1397 ieee80211_scan_completed(mvm->hw, true);
1398 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
1399 mvm->scan_status = IWL_MVM_SCAN_NONE;
1400 return 0;
1401 }
1402
1403 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) 1403 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
1404 return iwl_mvm_scan_offload_stop(mvm, true); 1404 return iwl_mvm_scan_offload_stop(mvm, true);
1405 return iwl_mvm_cancel_regular_scan(mvm); 1405 return iwl_mvm_cancel_regular_scan(mvm);
diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
index 3781b029e54a..dd2f3f8baa9d 100644
--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
@@ -915,7 +915,8 @@ static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
915 * restart. So don't process again if the device is 915 * restart. So don't process again if the device is
916 * already dead. 916 * already dead.
917 */ 917 */
918 if (test_bit(STATUS_DEVICE_ENABLED, &trans->status)) { 918 if (test_and_clear_bit(STATUS_DEVICE_ENABLED, &trans->status)) {
919 IWL_DEBUG_INFO(trans, "DEVICE_ENABLED bit was set and is now cleared\n");
919 iwl_pcie_tx_stop(trans); 920 iwl_pcie_tx_stop(trans);
920 iwl_pcie_rx_stop(trans); 921 iwl_pcie_rx_stop(trans);
921 922
@@ -945,7 +946,6 @@ static void iwl_trans_pcie_stop_device(struct iwl_trans *trans)
945 /* clear all status bits */ 946 /* clear all status bits */
946 clear_bit(STATUS_SYNC_HCMD_ACTIVE, &trans->status); 947 clear_bit(STATUS_SYNC_HCMD_ACTIVE, &trans->status);
947 clear_bit(STATUS_INT_ENABLED, &trans->status); 948 clear_bit(STATUS_INT_ENABLED, &trans->status);
948 clear_bit(STATUS_DEVICE_ENABLED, &trans->status);
949 clear_bit(STATUS_TPOWER_PMI, &trans->status); 949 clear_bit(STATUS_TPOWER_PMI, &trans->status);
950 clear_bit(STATUS_RFKILL, &trans->status); 950 clear_bit(STATUS_RFKILL, &trans->status);
951 951
@@ -1894,8 +1894,7 @@ static u32 iwl_trans_pcie_dump_prph(struct iwl_trans *trans,
1894 int reg; 1894 int reg;
1895 __le32 *val; 1895 __le32 *val;
1896 1896
1897 prph_len += sizeof(*data) + sizeof(*prph) + 1897 prph_len += sizeof(**data) + sizeof(*prph) + num_bytes_in_chunk;
1898 num_bytes_in_chunk;
1899 1898
1900 (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH); 1899 (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH);
1901 (*data)->len = cpu_to_le32(sizeof(*prph) + 1900 (*data)->len = cpu_to_le32(sizeof(*prph) +
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index babbdc1ce741..c9ad4cf1adfb 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -1987,7 +1987,7 @@ static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2,
1987 if (err != 0) { 1987 if (err != 0) {
1988 printk(KERN_DEBUG "mac80211_hwsim: device_bind_driver failed (%d)\n", 1988 printk(KERN_DEBUG "mac80211_hwsim: device_bind_driver failed (%d)\n",
1989 err); 1989 err);
1990 goto failed_hw; 1990 goto failed_bind;
1991 } 1991 }
1992 1992
1993 skb_queue_head_init(&data->pending); 1993 skb_queue_head_init(&data->pending);
@@ -2183,6 +2183,8 @@ static int mac80211_hwsim_create_radio(int channels, const char *reg_alpha2,
2183 return idx; 2183 return idx;
2184 2184
2185failed_hw: 2185failed_hw:
2186 device_release_driver(data->dev);
2187failed_bind:
2186 device_unregister(data->dev); 2188 device_unregister(data->dev);
2187failed_drvdata: 2189failed_drvdata:
2188 ieee80211_free_hw(hw); 2190 ieee80211_free_hw(hw);
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
index 8e68f87ab13c..66ff36447b94 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
@@ -158,55 +158,29 @@ void rt2x00queue_align_frame(struct sk_buff *skb)
158 skb_trim(skb, frame_length); 158 skb_trim(skb, frame_length);
159} 159}
160 160
161void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int header_length) 161/*
162 * H/W needs L2 padding between the header and the paylod if header size
163 * is not 4 bytes aligned.
164 */
165void rt2x00queue_insert_l2pad(struct sk_buff *skb, unsigned int hdr_len)
162{ 166{
163 unsigned int payload_length = skb->len - header_length; 167 unsigned int l2pad = (skb->len > hdr_len) ? L2PAD_SIZE(hdr_len) : 0;
164 unsigned int header_align = ALIGN_SIZE(skb, 0);
165 unsigned int payload_align = ALIGN_SIZE(skb, header_length);
166 unsigned int l2pad = payload_length ? L2PAD_SIZE(header_length) : 0;
167 168
168 /* 169 if (!l2pad)
169 * Adjust the header alignment if the payload needs to be moved more
170 * than the header.
171 */
172 if (payload_align > header_align)
173 header_align += 4;
174
175 /* There is nothing to do if no alignment is needed */
176 if (!header_align)
177 return; 170 return;
178 171
179 /* Reserve the amount of space needed in front of the frame */ 172 skb_push(skb, l2pad);
180 skb_push(skb, header_align); 173 memmove(skb->data, skb->data + l2pad, hdr_len);
181
182 /*
183 * Move the header.
184 */
185 memmove(skb->data, skb->data + header_align, header_length);
186
187 /* Move the payload, if present and if required */
188 if (payload_length && payload_align)
189 memmove(skb->data + header_length + l2pad,
190 skb->data + header_length + l2pad + payload_align,
191 payload_length);
192
193 /* Trim the skb to the correct size */
194 skb_trim(skb, header_length + l2pad + payload_length);
195} 174}
196 175
197void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int header_length) 176void rt2x00queue_remove_l2pad(struct sk_buff *skb, unsigned int hdr_len)
198{ 177{
199 /* 178 unsigned int l2pad = (skb->len > hdr_len) ? L2PAD_SIZE(hdr_len) : 0;
200 * L2 padding is only present if the skb contains more than just the
201 * IEEE 802.11 header.
202 */
203 unsigned int l2pad = (skb->len > header_length) ?
204 L2PAD_SIZE(header_length) : 0;
205 179
206 if (!l2pad) 180 if (!l2pad)
207 return; 181 return;
208 182
209 memmove(skb->data + l2pad, skb->data, header_length); 183 memmove(skb->data + l2pad, skb->data, hdr_len);
210 skb_pull(skb, l2pad); 184 skb_pull(skb, l2pad);
211} 185}
212 186
diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index 25daa8715219..846a2e6e34d8 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -842,7 +842,8 @@ static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
842 break; 842 break;
843 } 843 }
844 /* handle command packet here */ 844 /* handle command packet here */
845 if (rtlpriv->cfg->ops->rx_command_packet(hw, stats, skb)) { 845 if (rtlpriv->cfg->ops->rx_command_packet &&
846 rtlpriv->cfg->ops->rx_command_packet(hw, stats, skb)) {
846 dev_kfree_skb_any(skb); 847 dev_kfree_skb_any(skb);
847 goto end; 848 goto end;
848 } 849 }
@@ -1127,9 +1128,14 @@ static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw)
1127 1128
1128 __skb_queue_tail(&ring->queue, pskb); 1129 __skb_queue_tail(&ring->queue, pskb);
1129 1130
1130 rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, true, HW_DESC_OWN, 1131 if (rtlpriv->use_new_trx_flow) {
1131 &temp_one); 1132 temp_one = 4;
1132 1133 rtlpriv->cfg->ops->set_desc(hw, (u8 *)pbuffer_desc, true,
1134 HW_DESC_OWN, (u8 *)&temp_one);
1135 } else {
1136 rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, true, HW_DESC_OWN,
1137 &temp_one);
1138 }
1133 return; 1139 return;
1134} 1140}
1135 1141
@@ -1370,9 +1376,9 @@ static void _rtl_pci_free_tx_ring(struct ieee80211_hw *hw,
1370 ring->desc = NULL; 1376 ring->desc = NULL;
1371 if (rtlpriv->use_new_trx_flow) { 1377 if (rtlpriv->use_new_trx_flow) {
1372 pci_free_consistent(rtlpci->pdev, 1378 pci_free_consistent(rtlpci->pdev,
1373 sizeof(*ring->desc) * ring->entries, 1379 sizeof(*ring->buffer_desc) * ring->entries,
1374 ring->buffer_desc, ring->buffer_desc_dma); 1380 ring->buffer_desc, ring->buffer_desc_dma);
1375 ring->desc = NULL; 1381 ring->buffer_desc = NULL;
1376 } 1382 }
1377} 1383}
1378 1384
@@ -1543,7 +1549,6 @@ int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw)
1543 true, 1549 true,
1544 HW_DESC_TXBUFF_ADDR), 1550 HW_DESC_TXBUFF_ADDR),
1545 skb->len, PCI_DMA_TODEVICE); 1551 skb->len, PCI_DMA_TODEVICE);
1546 ring->idx = (ring->idx + 1) % ring->entries;
1547 kfree_skb(skb); 1552 kfree_skb(skb);
1548 ring->idx = (ring->idx + 1) % ring->entries; 1553 ring->idx = (ring->idx + 1) % ring->entries;
1549 } 1554 }
@@ -2244,6 +2249,16 @@ int rtl_pci_probe(struct pci_dev *pdev,
2244 /*like read eeprom and so on */ 2249 /*like read eeprom and so on */
2245 rtlpriv->cfg->ops->read_eeprom_info(hw); 2250 rtlpriv->cfg->ops->read_eeprom_info(hw);
2246 2251
2252 if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
2253 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Can't init_sw_vars\n");
2254 err = -ENODEV;
2255 goto fail3;
2256 }
2257 rtlpriv->cfg->ops->init_sw_leds(hw);
2258
2259 /*aspm */
2260 rtl_pci_init_aspm(hw);
2261
2247 /* Init mac80211 sw */ 2262 /* Init mac80211 sw */
2248 err = rtl_init_core(hw); 2263 err = rtl_init_core(hw);
2249 if (err) { 2264 if (err) {
@@ -2259,16 +2274,6 @@ int rtl_pci_probe(struct pci_dev *pdev,
2259 goto fail3; 2274 goto fail3;
2260 } 2275 }
2261 2276
2262 if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
2263 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Can't init_sw_vars\n");
2264 err = -ENODEV;
2265 goto fail3;
2266 }
2267 rtlpriv->cfg->ops->init_sw_leds(hw);
2268
2269 /*aspm */
2270 rtl_pci_init_aspm(hw);
2271
2272 err = ieee80211_register_hw(hw); 2277 err = ieee80211_register_hw(hw);
2273 if (err) { 2278 if (err) {
2274 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, 2279 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/hw.c b/drivers/net/wireless/rtlwifi/rtl8192se/hw.c
index 00e067044c08..5761d5b49e39 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192se/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192se/hw.c
@@ -1201,6 +1201,9 @@ static int _rtl92se_set_media_status(struct ieee80211_hw *hw,
1201 1201
1202 } 1202 }
1203 1203
1204 if (type != NL80211_IFTYPE_AP &&
1205 rtlpriv->mac80211.link_state < MAC80211_LINKED)
1206 bt_msr = rtl_read_byte(rtlpriv, MSR) & ~MSR_LINK_MASK;
1204 rtl_write_byte(rtlpriv, (MSR), bt_msr); 1207 rtl_write_byte(rtlpriv, (MSR), bt_msr);
1205 1208
1206 temp = rtl_read_dword(rtlpriv, TCR); 1209 temp = rtl_read_dword(rtlpriv, TCR);
@@ -1262,6 +1265,7 @@ void rtl92se_enable_interrupt(struct ieee80211_hw *hw)
1262 rtl_write_dword(rtlpriv, INTA_MASK, rtlpci->irq_mask[0]); 1265 rtl_write_dword(rtlpriv, INTA_MASK, rtlpci->irq_mask[0]);
1263 /* Support Bit 32-37(Assign as Bit 0-5) interrupt setting now */ 1266 /* Support Bit 32-37(Assign as Bit 0-5) interrupt setting now */
1264 rtl_write_dword(rtlpriv, INTA_MASK + 4, rtlpci->irq_mask[1] & 0x3F); 1267 rtl_write_dword(rtlpriv, INTA_MASK + 4, rtlpci->irq_mask[1] & 0x3F);
1268 rtlpci->irq_enabled = true;
1265} 1269}
1266 1270
1267void rtl92se_disable_interrupt(struct ieee80211_hw *hw) 1271void rtl92se_disable_interrupt(struct ieee80211_hw *hw)
@@ -1276,8 +1280,7 @@ void rtl92se_disable_interrupt(struct ieee80211_hw *hw)
1276 rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 1280 rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1277 rtl_write_dword(rtlpriv, INTA_MASK, 0); 1281 rtl_write_dword(rtlpriv, INTA_MASK, 0);
1278 rtl_write_dword(rtlpriv, INTA_MASK + 4, 0); 1282 rtl_write_dword(rtlpriv, INTA_MASK + 4, 0);
1279 1283 rtlpci->irq_enabled = false;
1280 synchronize_irq(rtlpci->pdev->irq);
1281} 1284}
1282 1285
1283static u8 _rtl92s_set_sysclk(struct ieee80211_hw *hw, u8 data) 1286static u8 _rtl92s_set_sysclk(struct ieee80211_hw *hw, u8 data)
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/phy.c b/drivers/net/wireless/rtlwifi/rtl8192se/phy.c
index 77c5b5f35244..4b4612fe2fdb 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192se/phy.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192se/phy.c
@@ -399,6 +399,8 @@ static bool _rtl92s_phy_sw_chnl_step_by_step(struct ieee80211_hw *hw,
399 case 2: 399 case 2:
400 currentcmd = &postcommoncmd[*step]; 400 currentcmd = &postcommoncmd[*step];
401 break; 401 break;
402 default:
403 return true;
402 } 404 }
403 405
404 if (currentcmd->cmdid == CMDID_END) { 406 if (currentcmd->cmdid == CMDID_END) {
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/sw.c b/drivers/net/wireless/rtlwifi/rtl8192se/sw.c
index aadba29c167a..fb003868bdef 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192se/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192se/sw.c
@@ -236,6 +236,19 @@ static void rtl92s_deinit_sw_vars(struct ieee80211_hw *hw)
236 } 236 }
237} 237}
238 238
239static bool rtl92se_is_tx_desc_closed(struct ieee80211_hw *hw, u8 hw_queue,
240 u16 index)
241{
242 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
243 struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
244 u8 *entry = (u8 *)(&ring->desc[ring->idx]);
245 u8 own = (u8)rtl92se_get_desc(entry, true, HW_DESC_OWN);
246
247 if (own)
248 return false;
249 return true;
250}
251
239static struct rtl_hal_ops rtl8192se_hal_ops = { 252static struct rtl_hal_ops rtl8192se_hal_ops = {
240 .init_sw_vars = rtl92s_init_sw_vars, 253 .init_sw_vars = rtl92s_init_sw_vars,
241 .deinit_sw_vars = rtl92s_deinit_sw_vars, 254 .deinit_sw_vars = rtl92s_deinit_sw_vars,
@@ -269,6 +282,7 @@ static struct rtl_hal_ops rtl8192se_hal_ops = {
269 .led_control = rtl92se_led_control, 282 .led_control = rtl92se_led_control,
270 .set_desc = rtl92se_set_desc, 283 .set_desc = rtl92se_set_desc,
271 .get_desc = rtl92se_get_desc, 284 .get_desc = rtl92se_get_desc,
285 .is_tx_desc_closed = rtl92se_is_tx_desc_closed,
272 .tx_polling = rtl92se_tx_polling, 286 .tx_polling = rtl92se_tx_polling,
273 .enable_hw_sec = rtl92se_enable_hw_security_config, 287 .enable_hw_sec = rtl92se_enable_hw_security_config,
274 .set_key = rtl92se_set_key, 288 .set_key = rtl92se_set_key,
@@ -306,6 +320,8 @@ static struct rtl_hal_cfg rtl92se_hal_cfg = {
306 .maps[MAC_RCR_ACRC32] = RCR_ACRC32, 320 .maps[MAC_RCR_ACRC32] = RCR_ACRC32,
307 .maps[MAC_RCR_ACF] = RCR_ACF, 321 .maps[MAC_RCR_ACF] = RCR_ACF,
308 .maps[MAC_RCR_AAP] = RCR_AAP, 322 .maps[MAC_RCR_AAP] = RCR_AAP,
323 .maps[MAC_HIMR] = INTA_MASK,
324 .maps[MAC_HIMRE] = INTA_MASK + 4,
309 325
310 .maps[EFUSE_TEST] = REG_EFUSE_TEST, 326 .maps[EFUSE_TEST] = REG_EFUSE_TEST,
311 .maps[EFUSE_CTRL] = REG_EFUSE_CTRL, 327 .maps[EFUSE_CTRL] = REG_EFUSE_CTRL,
diff --git a/drivers/net/wireless/rtlwifi/rtl8821ae/hw.c b/drivers/net/wireless/rtlwifi/rtl8821ae/hw.c
index 310d3163dc5b..8ec8200002c7 100644
--- a/drivers/net/wireless/rtlwifi/rtl8821ae/hw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8821ae/hw.c
@@ -3672,8 +3672,9 @@ static void rtl8821ae_update_hal_rate_mask(struct ieee80211_hw *hw,
3672 mac->opmode == NL80211_IFTYPE_ADHOC) 3672 mac->opmode == NL80211_IFTYPE_ADHOC)
3673 macid = sta->aid + 1; 3673 macid = sta->aid + 1;
3674 if (wirelessmode == WIRELESS_MODE_N_5G || 3674 if (wirelessmode == WIRELESS_MODE_N_5G ||
3675 wirelessmode == WIRELESS_MODE_AC_5G) 3675 wirelessmode == WIRELESS_MODE_AC_5G ||
3676 ratr_bitmap = sta->supp_rates[NL80211_BAND_5GHZ]; 3676 wirelessmode == WIRELESS_MODE_A)
3677 ratr_bitmap = sta->supp_rates[NL80211_BAND_5GHZ] << 4;
3677 else 3678 else
3678 ratr_bitmap = sta->supp_rates[NL80211_BAND_2GHZ]; 3679 ratr_bitmap = sta->supp_rates[NL80211_BAND_2GHZ];
3679 3680
diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c
index 4e56a27f9689..fab0d4b42f58 100644
--- a/drivers/net/xen-netback/xenbus.c
+++ b/drivers/net/xen-netback/xenbus.c
@@ -39,7 +39,7 @@ struct backend_info {
39static int connect_rings(struct backend_info *be, struct xenvif_queue *queue); 39static int connect_rings(struct backend_info *be, struct xenvif_queue *queue);
40static void connect(struct backend_info *be); 40static void connect(struct backend_info *be);
41static int read_xenbus_vif_flags(struct backend_info *be); 41static int read_xenbus_vif_flags(struct backend_info *be);
42static void backend_create_xenvif(struct backend_info *be); 42static int backend_create_xenvif(struct backend_info *be);
43static void unregister_hotplug_status_watch(struct backend_info *be); 43static void unregister_hotplug_status_watch(struct backend_info *be);
44static void set_backend_state(struct backend_info *be, 44static void set_backend_state(struct backend_info *be,
45 enum xenbus_state state); 45 enum xenbus_state state);
@@ -352,7 +352,9 @@ static int netback_probe(struct xenbus_device *dev,
352 be->state = XenbusStateInitWait; 352 be->state = XenbusStateInitWait;
353 353
354 /* This kicks hotplug scripts, so do it immediately. */ 354 /* This kicks hotplug scripts, so do it immediately. */
355 backend_create_xenvif(be); 355 err = backend_create_xenvif(be);
356 if (err)
357 goto fail;
356 358
357 return 0; 359 return 0;
358 360
@@ -397,19 +399,19 @@ static int netback_uevent(struct xenbus_device *xdev,
397} 399}
398 400
399 401
400static void backend_create_xenvif(struct backend_info *be) 402static int backend_create_xenvif(struct backend_info *be)
401{ 403{
402 int err; 404 int err;
403 long handle; 405 long handle;
404 struct xenbus_device *dev = be->dev; 406 struct xenbus_device *dev = be->dev;
405 407
406 if (be->vif != NULL) 408 if (be->vif != NULL)
407 return; 409 return 0;
408 410
409 err = xenbus_scanf(XBT_NIL, dev->nodename, "handle", "%li", &handle); 411 err = xenbus_scanf(XBT_NIL, dev->nodename, "handle", "%li", &handle);
410 if (err != 1) { 412 if (err != 1) {
411 xenbus_dev_fatal(dev, err, "reading handle"); 413 xenbus_dev_fatal(dev, err, "reading handle");
412 return; 414 return (err < 0) ? err : -EINVAL;
413 } 415 }
414 416
415 be->vif = xenvif_alloc(&dev->dev, dev->otherend_id, handle); 417 be->vif = xenvif_alloc(&dev->dev, dev->otherend_id, handle);
@@ -417,10 +419,11 @@ static void backend_create_xenvif(struct backend_info *be)
417 err = PTR_ERR(be->vif); 419 err = PTR_ERR(be->vif);
418 be->vif = NULL; 420 be->vif = NULL;
419 xenbus_dev_fatal(dev, err, "creating interface"); 421 xenbus_dev_fatal(dev, err, "creating interface");
420 return; 422 return err;
421 } 423 }
422 424
423 kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE); 425 kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE);
426 return 0;
424} 427}
425 428
426static void backend_disconnect(struct backend_info *be) 429static void backend_disconnect(struct backend_info *be)
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index cca871346a0f..ece8d1804d13 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -496,9 +496,6 @@ static void xennet_make_frags(struct sk_buff *skb, struct netfront_queue *queue,
496 len = skb_frag_size(frag); 496 len = skb_frag_size(frag);
497 offset = frag->page_offset; 497 offset = frag->page_offset;
498 498
499 /* Data must not cross a page boundary. */
500 BUG_ON(len + offset > PAGE_SIZE<<compound_order(page));
501
502 /* Skip unused frames from start of page */ 499 /* Skip unused frames from start of page */
503 page += offset >> PAGE_SHIFT; 500 page += offset >> PAGE_SHIFT;
504 offset &= ~PAGE_MASK; 501 offset &= ~PAGE_MASK;
@@ -506,8 +503,6 @@ static void xennet_make_frags(struct sk_buff *skb, struct netfront_queue *queue,
506 while (len > 0) { 503 while (len > 0) {
507 unsigned long bytes; 504 unsigned long bytes;
508 505
509 BUG_ON(offset >= PAGE_SIZE);
510
511 bytes = PAGE_SIZE - offset; 506 bytes = PAGE_SIZE - offset;
512 if (bytes > len) 507 if (bytes > len)
513 bytes = len; 508 bytes = len;
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 5066a7ef7b6c..3319cf19deeb 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -920,14 +920,10 @@ void __init nubus_probe_slot(int slot)
920 rp = nubus_rom_addr(slot); 920 rp = nubus_rom_addr(slot);
921 for(i = 4; i; i--) 921 for(i = 4; i; i--)
922 { 922 {
923 unsigned long flags;
924 int card_present; 923 int card_present;
925 924
926 rp--; 925 rp--;
927 local_irq_save(flags);
928 card_present = hwreg_present(rp); 926 card_present = hwreg_present(rp);
929 local_irq_restore(flags);
930
931 if (!card_present) 927 if (!card_present)
932 continue; 928 continue;
933 929
diff --git a/drivers/of/address.c b/drivers/of/address.c
index afdb78299f61..06af494184d6 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -450,6 +450,21 @@ static struct of_bus *of_match_bus(struct device_node *np)
450 return NULL; 450 return NULL;
451} 451}
452 452
453static int of_empty_ranges_quirk(void)
454{
455 if (IS_ENABLED(CONFIG_PPC)) {
456 /* To save cycles, we cache the result */
457 static int quirk_state = -1;
458
459 if (quirk_state < 0)
460 quirk_state =
461 of_machine_is_compatible("Power Macintosh") ||
462 of_machine_is_compatible("MacRISC");
463 return quirk_state;
464 }
465 return false;
466}
467
453static int of_translate_one(struct device_node *parent, struct of_bus *bus, 468static int of_translate_one(struct device_node *parent, struct of_bus *bus,
454 struct of_bus *pbus, __be32 *addr, 469 struct of_bus *pbus, __be32 *addr,
455 int na, int ns, int pna, const char *rprop) 470 int na, int ns, int pna, const char *rprop)
@@ -475,12 +490,10 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
475 * This code is only enabled on powerpc. --gcl 490 * This code is only enabled on powerpc. --gcl
476 */ 491 */
477 ranges = of_get_property(parent, rprop, &rlen); 492 ranges = of_get_property(parent, rprop, &rlen);
478#if !defined(CONFIG_PPC) 493 if (ranges == NULL && !of_empty_ranges_quirk()) {
479 if (ranges == NULL) {
480 pr_err("OF: no ranges; cannot translate\n"); 494 pr_err("OF: no ranges; cannot translate\n");
481 return 1; 495 return 1;
482 } 496 }
483#endif /* !defined(CONFIG_PPC) */
484 if (ranges == NULL || rlen == 0) { 497 if (ranges == NULL || rlen == 0) {
485 offset = of_read_number(addr, na); 498 offset = of_read_number(addr, na);
486 memset(addr, 0, pna * 4); 499 memset(addr, 0, pna * 4);
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 2305dc0382bc..3823edf2d012 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1280,52 +1280,6 @@ int of_property_read_string(struct device_node *np, const char *propname,
1280EXPORT_SYMBOL_GPL(of_property_read_string); 1280EXPORT_SYMBOL_GPL(of_property_read_string);
1281 1281
1282/** 1282/**
1283 * of_property_read_string_index - Find and read a string from a multiple
1284 * strings property.
1285 * @np: device node from which the property value is to be read.
1286 * @propname: name of the property to be searched.
1287 * @index: index of the string in the list of strings
1288 * @out_string: pointer to null terminated return string, modified only if
1289 * return value is 0.
1290 *
1291 * Search for a property in a device tree node and retrieve a null
1292 * terminated string value (pointer to data, not a copy) in the list of strings
1293 * contained in that property.
1294 * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
1295 * property does not have a value, and -EILSEQ if the string is not
1296 * null-terminated within the length of the property data.
1297 *
1298 * The out_string pointer is modified only if a valid string can be decoded.
1299 */
1300int of_property_read_string_index(struct device_node *np, const char *propname,
1301 int index, const char **output)
1302{
1303 struct property *prop = of_find_property(np, propname, NULL);
1304 int i = 0;
1305 size_t l = 0, total = 0;
1306 const char *p;
1307
1308 if (!prop)
1309 return -EINVAL;
1310 if (!prop->value)
1311 return -ENODATA;
1312 if (strnlen(prop->value, prop->length) >= prop->length)
1313 return -EILSEQ;
1314
1315 p = prop->value;
1316
1317 for (i = 0; total < prop->length; total += l, p += l) {
1318 l = strlen(p) + 1;
1319 if (i++ == index) {
1320 *output = p;
1321 return 0;
1322 }
1323 }
1324 return -ENODATA;
1325}
1326EXPORT_SYMBOL_GPL(of_property_read_string_index);
1327
1328/**
1329 * of_property_match_string() - Find string in a list and return index 1283 * of_property_match_string() - Find string in a list and return index
1330 * @np: pointer to node containing string list property 1284 * @np: pointer to node containing string list property
1331 * @propname: string list property name 1285 * @propname: string list property name
@@ -1351,7 +1305,7 @@ int of_property_match_string(struct device_node *np, const char *propname,
1351 end = p + prop->length; 1305 end = p + prop->length;
1352 1306
1353 for (i = 0; p < end; i++, p += l) { 1307 for (i = 0; p < end; i++, p += l) {
1354 l = strlen(p) + 1; 1308 l = strnlen(p, end - p) + 1;
1355 if (p + l > end) 1309 if (p + l > end)
1356 return -EILSEQ; 1310 return -EILSEQ;
1357 pr_debug("comparing %s with %s\n", string, p); 1311 pr_debug("comparing %s with %s\n", string, p);
@@ -1363,39 +1317,41 @@ int of_property_match_string(struct device_node *np, const char *propname,
1363EXPORT_SYMBOL_GPL(of_property_match_string); 1317EXPORT_SYMBOL_GPL(of_property_match_string);
1364 1318
1365/** 1319/**
1366 * of_property_count_strings - Find and return the number of strings from a 1320 * of_property_read_string_util() - Utility helper for parsing string properties
1367 * multiple strings property.
1368 * @np: device node from which the property value is to be read. 1321 * @np: device node from which the property value is to be read.
1369 * @propname: name of the property to be searched. 1322 * @propname: name of the property to be searched.
1323 * @out_strs: output array of string pointers.
1324 * @sz: number of array elements to read.
1325 * @skip: Number of strings to skip over at beginning of list.
1370 * 1326 *
1371 * Search for a property in a device tree node and retrieve the number of null 1327 * Don't call this function directly. It is a utility helper for the
1372 * terminated string contain in it. Returns the number of strings on 1328 * of_property_read_string*() family of functions.
1373 * success, -EINVAL if the property does not exist, -ENODATA if property
1374 * does not have a value, and -EILSEQ if the string is not null-terminated
1375 * within the length of the property data.
1376 */ 1329 */
1377int of_property_count_strings(struct device_node *np, const char *propname) 1330int of_property_read_string_helper(struct device_node *np, const char *propname,
1331 const char **out_strs, size_t sz, int skip)
1378{ 1332{
1379 struct property *prop = of_find_property(np, propname, NULL); 1333 struct property *prop = of_find_property(np, propname, NULL);
1380 int i = 0; 1334 int l = 0, i = 0;
1381 size_t l = 0, total = 0; 1335 const char *p, *end;
1382 const char *p;
1383 1336
1384 if (!prop) 1337 if (!prop)
1385 return -EINVAL; 1338 return -EINVAL;
1386 if (!prop->value) 1339 if (!prop->value)
1387 return -ENODATA; 1340 return -ENODATA;
1388 if (strnlen(prop->value, prop->length) >= prop->length)
1389 return -EILSEQ;
1390
1391 p = prop->value; 1341 p = prop->value;
1342 end = p + prop->length;
1392 1343
1393 for (i = 0; total < prop->length; total += l, p += l, i++) 1344 for (i = 0; p < end && (!out_strs || i < skip + sz); i++, p += l) {
1394 l = strlen(p) + 1; 1345 l = strnlen(p, end - p) + 1;
1395 1346 if (p + l > end)
1396 return i; 1347 return -EILSEQ;
1348 if (out_strs && i >= skip)
1349 *out_strs++ = p;
1350 }
1351 i -= skip;
1352 return i <= 0 ? -ENODATA : i;
1397} 1353}
1398EXPORT_SYMBOL_GPL(of_property_count_strings); 1354EXPORT_SYMBOL_GPL(of_property_read_string_helper);
1399 1355
1400void of_print_phandle_args(const char *msg, const struct of_phandle_args *args) 1356void of_print_phandle_args(const char *msg, const struct of_phandle_args *args)
1401{ 1357{
diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c
index f297891d8529..d4994177dec2 100644
--- a/drivers/of/dynamic.c
+++ b/drivers/of/dynamic.c
@@ -247,7 +247,7 @@ void of_node_release(struct kobject *kobj)
247 * @allocflags: Allocation flags (typically pass GFP_KERNEL) 247 * @allocflags: Allocation flags (typically pass GFP_KERNEL)
248 * 248 *
249 * Copy a property by dynamically allocating the memory of both the 249 * Copy a property by dynamically allocating the memory of both the
250 * property stucture and the property name & contents. The property's 250 * property structure and the property name & contents. The property's
251 * flags have the OF_DYNAMIC bit set so that we can differentiate between 251 * flags have the OF_DYNAMIC bit set so that we can differentiate between
252 * dynamically allocated properties and not. 252 * dynamically allocated properties and not.
253 * Returns the newly allocated property or NULL on out of memory error. 253 * Returns the newly allocated property or NULL on out of memory error.
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index d1ffca8b34ea..d134710de96d 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -773,7 +773,7 @@ int __init early_init_dt_scan_chosen_serial(void)
773 if (offset < 0) 773 if (offset < 0)
774 return -ENODEV; 774 return -ENODEV;
775 775
776 while (match->compatible) { 776 while (match->compatible[0]) {
777 unsigned long addr; 777 unsigned long addr;
778 if (fdt_node_check_compatible(fdt, offset, match->compatible)) { 778 if (fdt_node_check_compatible(fdt, offset, match->compatible)) {
779 match++; 779 match++;
@@ -964,8 +964,6 @@ void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
964int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base, 964int __init __weak early_init_dt_reserve_memory_arch(phys_addr_t base,
965 phys_addr_t size, bool nomap) 965 phys_addr_t size, bool nomap)
966{ 966{
967 if (memblock_is_region_reserved(base, size))
968 return -EBUSY;
969 if (nomap) 967 if (nomap)
970 return memblock_remove(base, size); 968 return memblock_remove(base, size);
971 return memblock_reserve(base, size); 969 return memblock_reserve(base, size);
diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c
index 78001270a598..e2d79afa9dc6 100644
--- a/drivers/of/selftest.c
+++ b/drivers/of/selftest.c
@@ -339,8 +339,9 @@ static void __init of_selftest_parse_phandle_with_args(void)
339 selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); 339 selftest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc);
340} 340}
341 341
342static void __init of_selftest_property_match_string(void) 342static void __init of_selftest_property_string(void)
343{ 343{
344 const char *strings[4];
344 struct device_node *np; 345 struct device_node *np;
345 int rc; 346 int rc;
346 347
@@ -357,13 +358,66 @@ static void __init of_selftest_property_match_string(void)
357 rc = of_property_match_string(np, "phandle-list-names", "third"); 358 rc = of_property_match_string(np, "phandle-list-names", "third");
358 selftest(rc == 2, "third expected:0 got:%i\n", rc); 359 selftest(rc == 2, "third expected:0 got:%i\n", rc);
359 rc = of_property_match_string(np, "phandle-list-names", "fourth"); 360 rc = of_property_match_string(np, "phandle-list-names", "fourth");
360 selftest(rc == -ENODATA, "unmatched string; rc=%i", rc); 361 selftest(rc == -ENODATA, "unmatched string; rc=%i\n", rc);
361 rc = of_property_match_string(np, "missing-property", "blah"); 362 rc = of_property_match_string(np, "missing-property", "blah");
362 selftest(rc == -EINVAL, "missing property; rc=%i", rc); 363 selftest(rc == -EINVAL, "missing property; rc=%i\n", rc);
363 rc = of_property_match_string(np, "empty-property", "blah"); 364 rc = of_property_match_string(np, "empty-property", "blah");
364 selftest(rc == -ENODATA, "empty property; rc=%i", rc); 365 selftest(rc == -ENODATA, "empty property; rc=%i\n", rc);
365 rc = of_property_match_string(np, "unterminated-string", "blah"); 366 rc = of_property_match_string(np, "unterminated-string", "blah");
366 selftest(rc == -EILSEQ, "unterminated string; rc=%i", rc); 367 selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
368
369 /* of_property_count_strings() tests */
370 rc = of_property_count_strings(np, "string-property");
371 selftest(rc == 1, "Incorrect string count; rc=%i\n", rc);
372 rc = of_property_count_strings(np, "phandle-list-names");
373 selftest(rc == 3, "Incorrect string count; rc=%i\n", rc);
374 rc = of_property_count_strings(np, "unterminated-string");
375 selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
376 rc = of_property_count_strings(np, "unterminated-string-list");
377 selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
378
379 /* of_property_read_string_index() tests */
380 rc = of_property_read_string_index(np, "string-property", 0, strings);
381 selftest(rc == 0 && !strcmp(strings[0], "foobar"), "of_property_read_string_index() failure; rc=%i\n", rc);
382 strings[0] = NULL;
383 rc = of_property_read_string_index(np, "string-property", 1, strings);
384 selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
385 rc = of_property_read_string_index(np, "phandle-list-names", 0, strings);
386 selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
387 rc = of_property_read_string_index(np, "phandle-list-names", 1, strings);
388 selftest(rc == 0 && !strcmp(strings[0], "second"), "of_property_read_string_index() failure; rc=%i\n", rc);
389 rc = of_property_read_string_index(np, "phandle-list-names", 2, strings);
390 selftest(rc == 0 && !strcmp(strings[0], "third"), "of_property_read_string_index() failure; rc=%i\n", rc);
391 strings[0] = NULL;
392 rc = of_property_read_string_index(np, "phandle-list-names", 3, strings);
393 selftest(rc == -ENODATA && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
394 strings[0] = NULL;
395 rc = of_property_read_string_index(np, "unterminated-string", 0, strings);
396 selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
397 rc = of_property_read_string_index(np, "unterminated-string-list", 0, strings);
398 selftest(rc == 0 && !strcmp(strings[0], "first"), "of_property_read_string_index() failure; rc=%i\n", rc);
399 strings[0] = NULL;
400 rc = of_property_read_string_index(np, "unterminated-string-list", 2, strings); /* should fail */
401 selftest(rc == -EILSEQ && strings[0] == NULL, "of_property_read_string_index() failure; rc=%i\n", rc);
402 strings[1] = NULL;
403
404 /* of_property_read_string_array() tests */
405 rc = of_property_read_string_array(np, "string-property", strings, 4);
406 selftest(rc == 1, "Incorrect string count; rc=%i\n", rc);
407 rc = of_property_read_string_array(np, "phandle-list-names", strings, 4);
408 selftest(rc == 3, "Incorrect string count; rc=%i\n", rc);
409 rc = of_property_read_string_array(np, "unterminated-string", strings, 4);
410 selftest(rc == -EILSEQ, "unterminated string; rc=%i\n", rc);
411 /* -- An incorrectly formed string should cause a failure */
412 rc = of_property_read_string_array(np, "unterminated-string-list", strings, 4);
413 selftest(rc == -EILSEQ, "unterminated string array; rc=%i\n", rc);
414 /* -- parsing the correctly formed strings should still work: */
415 strings[2] = NULL;
416 rc = of_property_read_string_array(np, "unterminated-string-list", strings, 2);
417 selftest(rc == 2 && strings[2] == NULL, "of_property_read_string_array() failure; rc=%i\n", rc);
418 strings[1] = NULL;
419 rc = of_property_read_string_array(np, "phandle-list-names", strings, 1);
420 selftest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]);
367} 421}
368 422
369#define propcmp(p1, p2) (((p1)->length == (p2)->length) && \ 423#define propcmp(p1, p2) (((p1)->length == (p2)->length) && \
@@ -842,10 +896,14 @@ static void selftest_data_remove(void)
842 return; 896 return;
843 } 897 }
844 898
845 while (last_node_index >= 0) { 899 while (last_node_index-- > 0) {
846 if (nodes[last_node_index]) { 900 if (nodes[last_node_index]) {
847 np = of_find_node_by_path(nodes[last_node_index]->full_name); 901 np = of_find_node_by_path(nodes[last_node_index]->full_name);
848 if (strcmp(np->full_name, "/aliases") != 0) { 902 if (np == nodes[last_node_index]) {
903 if (of_aliases == np) {
904 of_node_put(of_aliases);
905 of_aliases = NULL;
906 }
849 detach_node_and_children(np); 907 detach_node_and_children(np);
850 } else { 908 } else {
851 for_each_property_of_node(np, prop) { 909 for_each_property_of_node(np, prop) {
@@ -854,7 +912,6 @@ static void selftest_data_remove(void)
854 } 912 }
855 } 913 }
856 } 914 }
857 last_node_index--;
858 } 915 }
859} 916}
860 917
@@ -867,6 +924,8 @@ static int __init of_selftest(void)
867 res = selftest_data_add(); 924 res = selftest_data_add();
868 if (res) 925 if (res)
869 return res; 926 return res;
927 if (!of_aliases)
928 of_aliases = of_find_node_by_path("/aliases");
870 929
871 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a"); 930 np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-a");
872 if (!np) { 931 if (!np) {
@@ -881,7 +940,7 @@ static int __init of_selftest(void)
881 of_selftest_find_node_by_name(); 940 of_selftest_find_node_by_name();
882 of_selftest_dynamic(); 941 of_selftest_dynamic();
883 of_selftest_parse_phandle_with_args(); 942 of_selftest_parse_phandle_with_args();
884 of_selftest_property_match_string(); 943 of_selftest_property_string();
885 of_selftest_property_copy(); 944 of_selftest_property_copy();
886 of_selftest_changeset(); 945 of_selftest_changeset();
887 of_selftest_parse_interrupts(); 946 of_selftest_parse_interrupts();
diff --git a/drivers/of/testcase-data/tests-phandle.dtsi b/drivers/of/testcase-data/tests-phandle.dtsi
index ce0fe083d406..5b1527e8a7fb 100644
--- a/drivers/of/testcase-data/tests-phandle.dtsi
+++ b/drivers/of/testcase-data/tests-phandle.dtsi
@@ -39,7 +39,9 @@
39 phandle-list-bad-args = <&provider2 1 0>, 39 phandle-list-bad-args = <&provider2 1 0>,
40 <&provider3 0>; 40 <&provider3 0>;
41 empty-property; 41 empty-property;
42 string-property = "foobar";
42 unterminated-string = [40 41 42 43]; 43 unterminated-string = [40 41 42 43];
44 unterminated-string-list = "first", "second", [40 41 42 43];
43 }; 45 };
44 }; 46 };
45 }; 47 };
diff --git a/drivers/pci/access.c b/drivers/pci/access.c
index d292d7cb3417..49dd766852ba 100644
--- a/drivers/pci/access.c
+++ b/drivers/pci/access.c
@@ -444,7 +444,7 @@ static inline int pcie_cap_version(const struct pci_dev *dev)
444 return pcie_caps_reg(dev) & PCI_EXP_FLAGS_VERS; 444 return pcie_caps_reg(dev) & PCI_EXP_FLAGS_VERS;
445} 445}
446 446
447static inline bool pcie_cap_has_lnkctl(const struct pci_dev *dev) 447bool pcie_cap_has_lnkctl(const struct pci_dev *dev)
448{ 448{
449 int type = pci_pcie_type(dev); 449 int type = pci_pcie_type(dev);
450 450
diff --git a/drivers/pci/host/pci-tegra.c b/drivers/pci/host/pci-tegra.c
index 3d43874319be..19bb19c7db4a 100644
--- a/drivers/pci/host/pci-tegra.c
+++ b/drivers/pci/host/pci-tegra.c
@@ -276,6 +276,7 @@ struct tegra_pcie {
276 276
277 struct resource all; 277 struct resource all;
278 struct resource io; 278 struct resource io;
279 struct resource pio;
279 struct resource mem; 280 struct resource mem;
280 struct resource prefetch; 281 struct resource prefetch;
281 struct resource busn; 282 struct resource busn;
@@ -658,7 +659,6 @@ static int tegra_pcie_setup(int nr, struct pci_sys_data *sys)
658{ 659{
659 struct tegra_pcie *pcie = sys_to_pcie(sys); 660 struct tegra_pcie *pcie = sys_to_pcie(sys);
660 int err; 661 int err;
661 phys_addr_t io_start;
662 662
663 err = devm_request_resource(pcie->dev, &pcie->all, &pcie->mem); 663 err = devm_request_resource(pcie->dev, &pcie->all, &pcie->mem);
664 if (err < 0) 664 if (err < 0)
@@ -668,14 +668,12 @@ static int tegra_pcie_setup(int nr, struct pci_sys_data *sys)
668 if (err) 668 if (err)
669 return err; 669 return err;
670 670
671 io_start = pci_pio_to_address(pcie->io.start);
672
673 pci_add_resource_offset(&sys->resources, &pcie->mem, sys->mem_offset); 671 pci_add_resource_offset(&sys->resources, &pcie->mem, sys->mem_offset);
674 pci_add_resource_offset(&sys->resources, &pcie->prefetch, 672 pci_add_resource_offset(&sys->resources, &pcie->prefetch,
675 sys->mem_offset); 673 sys->mem_offset);
676 pci_add_resource(&sys->resources, &pcie->busn); 674 pci_add_resource(&sys->resources, &pcie->busn);
677 675
678 pci_ioremap_io(nr * SZ_64K, io_start); 676 pci_ioremap_io(pcie->pio.start, pcie->io.start);
679 677
680 return 1; 678 return 1;
681} 679}
@@ -786,7 +784,6 @@ static irqreturn_t tegra_pcie_isr(int irq, void *arg)
786static void tegra_pcie_setup_translations(struct tegra_pcie *pcie) 784static void tegra_pcie_setup_translations(struct tegra_pcie *pcie)
787{ 785{
788 u32 fpci_bar, size, axi_address; 786 u32 fpci_bar, size, axi_address;
789 phys_addr_t io_start = pci_pio_to_address(pcie->io.start);
790 787
791 /* Bar 0: type 1 extended configuration space */ 788 /* Bar 0: type 1 extended configuration space */
792 fpci_bar = 0xfe100000; 789 fpci_bar = 0xfe100000;
@@ -799,7 +796,7 @@ static void tegra_pcie_setup_translations(struct tegra_pcie *pcie)
799 /* Bar 1: downstream IO bar */ 796 /* Bar 1: downstream IO bar */
800 fpci_bar = 0xfdfc0000; 797 fpci_bar = 0xfdfc0000;
801 size = resource_size(&pcie->io); 798 size = resource_size(&pcie->io);
802 axi_address = io_start; 799 axi_address = pcie->io.start;
803 afi_writel(pcie, axi_address, AFI_AXI_BAR1_START); 800 afi_writel(pcie, axi_address, AFI_AXI_BAR1_START);
804 afi_writel(pcie, size >> 12, AFI_AXI_BAR1_SZ); 801 afi_writel(pcie, size >> 12, AFI_AXI_BAR1_SZ);
805 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR1); 802 afi_writel(pcie, fpci_bar, AFI_FPCI_BAR1);
@@ -1690,8 +1687,23 @@ static int tegra_pcie_parse_dt(struct tegra_pcie *pcie)
1690 1687
1691 switch (res.flags & IORESOURCE_TYPE_BITS) { 1688 switch (res.flags & IORESOURCE_TYPE_BITS) {
1692 case IORESOURCE_IO: 1689 case IORESOURCE_IO:
1693 memcpy(&pcie->io, &res, sizeof(res)); 1690 memcpy(&pcie->pio, &res, sizeof(res));
1694 pcie->io.name = np->full_name; 1691 pcie->pio.name = np->full_name;
1692
1693 /*
1694 * The Tegra PCIe host bridge uses this to program the
1695 * mapping of the I/O space to the physical address,
1696 * so we override the .start and .end fields here that
1697 * of_pci_range_to_resource() converted to I/O space.
1698 * We also set the IORESOURCE_MEM type to clarify that
1699 * the resource is in the physical memory space.
1700 */
1701 pcie->io.start = range.cpu_addr;
1702 pcie->io.end = range.cpu_addr + range.size - 1;
1703 pcie->io.flags = IORESOURCE_MEM;
1704 pcie->io.name = "I/O";
1705
1706 memcpy(&res, &pcie->io, sizeof(res));
1695 break; 1707 break;
1696 1708
1697 case IORESOURCE_MEM: 1709 case IORESOURCE_MEM:
diff --git a/drivers/pci/host/pci-xgene.c b/drivers/pci/host/pci-xgene.c
index 9ecabfa8c634..2988fe136c1e 100644
--- a/drivers/pci/host/pci-xgene.c
+++ b/drivers/pci/host/pci-xgene.c
@@ -631,10 +631,15 @@ static int xgene_pcie_probe_bridge(struct platform_device *pdev)
631 if (ret) 631 if (ret)
632 return ret; 632 return ret;
633 633
634 bus = pci_scan_root_bus(&pdev->dev, 0, &xgene_pcie_ops, port, &res); 634 bus = pci_create_root_bus(&pdev->dev, 0,
635 &xgene_pcie_ops, port, &res);
635 if (!bus) 636 if (!bus)
636 return -ENOMEM; 637 return -ENOMEM;
637 638
639 pci_scan_child_bus(bus);
640 pci_assign_unassigned_bus_resources(bus);
641 pci_bus_add_devices(bus);
642
638 platform_set_drvdata(pdev, port); 643 platform_set_drvdata(pdev, port);
639 return 0; 644 return 0;
640} 645}
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 9fab30af0e75..084587d7cd13 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -590,6 +590,20 @@ static struct msi_desc *msi_setup_entry(struct pci_dev *dev)
590 return entry; 590 return entry;
591} 591}
592 592
593static int msi_verify_entries(struct pci_dev *dev)
594{
595 struct msi_desc *entry;
596
597 list_for_each_entry(entry, &dev->msi_list, list) {
598 if (!dev->no_64bit_msi || !entry->msg.address_hi)
599 continue;
600 dev_err(&dev->dev, "Device has broken 64-bit MSI but arch"
601 " tried to assign one above 4G\n");
602 return -EIO;
603 }
604 return 0;
605}
606
593/** 607/**
594 * msi_capability_init - configure device's MSI capability structure 608 * msi_capability_init - configure device's MSI capability structure
595 * @dev: pointer to the pci_dev data structure of MSI device function 609 * @dev: pointer to the pci_dev data structure of MSI device function
@@ -627,6 +641,13 @@ static int msi_capability_init(struct pci_dev *dev, int nvec)
627 return ret; 641 return ret;
628 } 642 }
629 643
644 ret = msi_verify_entries(dev);
645 if (ret) {
646 msi_mask_irq(entry, mask, ~mask);
647 free_msi_irqs(dev);
648 return ret;
649 }
650
630 ret = populate_msi_sysfs(dev); 651 ret = populate_msi_sysfs(dev);
631 if (ret) { 652 if (ret) {
632 msi_mask_irq(entry, mask, ~mask); 653 msi_mask_irq(entry, mask, ~mask);
@@ -739,6 +760,11 @@ static int msix_capability_init(struct pci_dev *dev,
739 if (ret) 760 if (ret)
740 goto out_avail; 761 goto out_avail;
741 762
763 /* Check if all MSI entries honor device restrictions */
764 ret = msi_verify_entries(dev);
765 if (ret)
766 goto out_free;
767
742 /* 768 /*
743 * Some devices require MSI-X to be enabled before we can touch the 769 * Some devices require MSI-X to be enabled before we can touch the
744 * MSI-X registers. We need to mask all the vectors to prevent 770 * MSI-X registers. We need to mask all the vectors to prevent
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 0601890db22d..4a3902d8e6fe 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -6,6 +6,8 @@
6 6
7extern const unsigned char pcie_link_speed[]; 7extern const unsigned char pcie_link_speed[];
8 8
9bool pcie_cap_has_lnkctl(const struct pci_dev *dev);
10
9/* Functions internal to the PCI core code */ 11/* Functions internal to the PCI core code */
10 12
11int pci_create_sysfs_dev_files(struct pci_dev *pdev); 13int pci_create_sysfs_dev_files(struct pci_dev *pdev);
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 5ed99309c758..c8ca98c2b480 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -407,15 +407,16 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child)
407{ 407{
408 struct pci_dev *dev = child->self; 408 struct pci_dev *dev = child->self;
409 u16 mem_base_lo, mem_limit_lo; 409 u16 mem_base_lo, mem_limit_lo;
410 unsigned long base, limit; 410 u64 base64, limit64;
411 dma_addr_t base, limit;
411 struct pci_bus_region region; 412 struct pci_bus_region region;
412 struct resource *res; 413 struct resource *res;
413 414
414 res = child->resource[2]; 415 res = child->resource[2];
415 pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo); 416 pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo);
416 pci_read_config_word(dev, PCI_PREF_MEMORY_LIMIT, &mem_limit_lo); 417 pci_read_config_word(dev, PCI_PREF_MEMORY_LIMIT, &mem_limit_lo);
417 base = ((unsigned long) mem_base_lo & PCI_PREF_RANGE_MASK) << 16; 418 base64 = (mem_base_lo & PCI_PREF_RANGE_MASK) << 16;
418 limit = ((unsigned long) mem_limit_lo & PCI_PREF_RANGE_MASK) << 16; 419 limit64 = (mem_limit_lo & PCI_PREF_RANGE_MASK) << 16;
419 420
420 if ((mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) { 421 if ((mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) {
421 u32 mem_base_hi, mem_limit_hi; 422 u32 mem_base_hi, mem_limit_hi;
@@ -429,17 +430,20 @@ static void pci_read_bridge_mmio_pref(struct pci_bus *child)
429 * this, just assume they are not being used. 430 * this, just assume they are not being used.
430 */ 431 */
431 if (mem_base_hi <= mem_limit_hi) { 432 if (mem_base_hi <= mem_limit_hi) {
432#if BITS_PER_LONG == 64 433 base64 |= (u64) mem_base_hi << 32;
433 base |= ((unsigned long) mem_base_hi) << 32; 434 limit64 |= (u64) mem_limit_hi << 32;
434 limit |= ((unsigned long) mem_limit_hi) << 32;
435#else
436 if (mem_base_hi || mem_limit_hi) {
437 dev_err(&dev->dev, "can't handle 64-bit address space for bridge\n");
438 return;
439 }
440#endif
441 } 435 }
442 } 436 }
437
438 base = (dma_addr_t) base64;
439 limit = (dma_addr_t) limit64;
440
441 if (base != base64) {
442 dev_err(&dev->dev, "can't handle bridge window above 4GB (bus address %#010llx)\n",
443 (unsigned long long) base64);
444 return;
445 }
446
443 if (base <= limit) { 447 if (base <= limit) {
444 res->flags = (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) | 448 res->flags = (mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) |
445 IORESOURCE_MEM | IORESOURCE_PREFETCH; 449 IORESOURCE_MEM | IORESOURCE_PREFETCH;
@@ -1323,7 +1327,7 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
1323 ~hpp->pci_exp_devctl_and, hpp->pci_exp_devctl_or); 1327 ~hpp->pci_exp_devctl_and, hpp->pci_exp_devctl_or);
1324 1328
1325 /* Initialize Link Control Register */ 1329 /* Initialize Link Control Register */
1326 if (dev->subordinate) 1330 if (pcie_cap_has_lnkctl(dev))
1327 pcie_capability_clear_and_set_word(dev, PCI_EXP_LNKCTL, 1331 pcie_capability_clear_and_set_word(dev, PCI_EXP_LNKCTL,
1328 ~hpp->pci_exp_lnkctl_and, hpp->pci_exp_lnkctl_or); 1332 ~hpp->pci_exp_lnkctl_and, hpp->pci_exp_lnkctl_or);
1329 1333
diff --git a/drivers/phy/phy-omap-usb2.c b/drivers/phy/phy-omap-usb2.c
index 8c842980834a..f091576b6449 100644
--- a/drivers/phy/phy-omap-usb2.c
+++ b/drivers/phy/phy-omap-usb2.c
@@ -258,14 +258,16 @@ static int omap_usb2_probe(struct platform_device *pdev)
258 otg->phy = &phy->phy; 258 otg->phy = &phy->phy;
259 259
260 platform_set_drvdata(pdev, phy); 260 platform_set_drvdata(pdev, phy);
261 pm_runtime_enable(phy->dev);
261 262
262 generic_phy = devm_phy_create(phy->dev, NULL, &ops, NULL); 263 generic_phy = devm_phy_create(phy->dev, NULL, &ops, NULL);
263 if (IS_ERR(generic_phy)) 264 if (IS_ERR(generic_phy)) {
265 pm_runtime_disable(phy->dev);
264 return PTR_ERR(generic_phy); 266 return PTR_ERR(generic_phy);
267 }
265 268
266 phy_set_drvdata(generic_phy, phy); 269 phy_set_drvdata(generic_phy, phy);
267 270
268 pm_runtime_enable(phy->dev);
269 phy_provider = devm_of_phy_provider_register(phy->dev, 271 phy_provider = devm_of_phy_provider_register(phy->dev,
270 of_phy_simple_xlate); 272 of_phy_simple_xlate);
271 if (IS_ERR(phy_provider)) { 273 if (IS_ERR(phy_provider)) {
diff --git a/drivers/pinctrl/pinctrl-baytrail.c b/drivers/pinctrl/pinctrl-baytrail.c
index e12e5b07f6d7..9dc38140194b 100644
--- a/drivers/pinctrl/pinctrl-baytrail.c
+++ b/drivers/pinctrl/pinctrl-baytrail.c
@@ -227,10 +227,14 @@ static int byt_irq_type(struct irq_data *d, unsigned type)
227 spin_lock_irqsave(&vg->lock, flags); 227 spin_lock_irqsave(&vg->lock, flags);
228 value = readl(reg); 228 value = readl(reg);
229 229
230 WARN(value & BYT_DIRECT_IRQ_EN,
231 "Bad pad config for io mode, force direct_irq_en bit clearing");
232
230 /* For level trigges the BYT_TRIG_POS and BYT_TRIG_NEG bits 233 /* For level trigges the BYT_TRIG_POS and BYT_TRIG_NEG bits
231 * are used to indicate high and low level triggering 234 * are used to indicate high and low level triggering
232 */ 235 */
233 value &= ~(BYT_TRIG_POS | BYT_TRIG_NEG | BYT_TRIG_LVL); 236 value &= ~(BYT_DIRECT_IRQ_EN | BYT_TRIG_POS | BYT_TRIG_NEG |
237 BYT_TRIG_LVL);
234 238
235 switch (type) { 239 switch (type) {
236 case IRQ_TYPE_LEVEL_HIGH: 240 case IRQ_TYPE_LEVEL_HIGH:
@@ -318,7 +322,7 @@ static int byt_gpio_direction_output(struct gpio_chip *chip,
318 "Potential Error: Setting GPIO with direct_irq_en to output"); 322 "Potential Error: Setting GPIO with direct_irq_en to output");
319 323
320 reg_val = readl(reg) | BYT_DIR_MASK; 324 reg_val = readl(reg) | BYT_DIR_MASK;
321 reg_val &= ~BYT_OUTPUT_EN; 325 reg_val &= ~(BYT_OUTPUT_EN | BYT_INPUT_EN);
322 326
323 if (value) 327 if (value)
324 writel(reg_val | BYT_LEVEL, reg); 328 writel(reg_val | BYT_LEVEL, reg);
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 4dcfb7116a04..a2eabe6ff9ad 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -202,6 +202,7 @@ config TC1100_WMI
202config HP_ACCEL 202config HP_ACCEL
203 tristate "HP laptop accelerometer" 203 tristate "HP laptop accelerometer"
204 depends on INPUT && ACPI 204 depends on INPUT && ACPI
205 depends on SERIO_I8042
205 select SENSORS_LIS3LV02D 206 select SENSORS_LIS3LV02D
206 select NEW_LEDS 207 select NEW_LEDS
207 select LEDS_CLASS 208 select LEDS_CLASS
diff --git a/drivers/platform/x86/acer-wmi.c b/drivers/platform/x86/acer-wmi.c
index 96a0b75c52c9..26c4fd1394da 100644
--- a/drivers/platform/x86/acer-wmi.c
+++ b/drivers/platform/x86/acer-wmi.c
@@ -579,6 +579,17 @@ static const struct dmi_system_id video_vendor_dmi_table[] __initconst = {
579 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"), 579 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
580 }, 580 },
581 }, 581 },
582 {
583 /*
584 * Note no video_set_backlight_video_vendor, we must use the
585 * acer interface, as there is no native backlight interface.
586 */
587 .ident = "Acer KAV80",
588 .matches = {
589 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
590 DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
591 },
592 },
582 {} 593 {}
583}; 594};
584 595
diff --git a/drivers/platform/x86/asus-nb-wmi.c b/drivers/platform/x86/asus-nb-wmi.c
index 3a4951f46065..c1a6cd66af42 100644
--- a/drivers/platform/x86/asus-nb-wmi.c
+++ b/drivers/platform/x86/asus-nb-wmi.c
@@ -182,6 +182,15 @@ static const struct dmi_system_id asus_quirks[] = {
182 }, 182 },
183 { 183 {
184 .callback = dmi_matched, 184 .callback = dmi_matched,
185 .ident = "ASUSTeK COMPUTER INC. X550VB",
186 .matches = {
187 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
188 DMI_MATCH(DMI_PRODUCT_NAME, "X550VB"),
189 },
190 .driver_data = &quirk_asus_wapf4,
191 },
192 {
193 .callback = dmi_matched,
185 .ident = "ASUSTeK COMPUTER INC. X55A", 194 .ident = "ASUSTeK COMPUTER INC. X55A",
186 .matches = { 195 .matches = {
187 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."), 196 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
diff --git a/drivers/platform/x86/hp_accel.c b/drivers/platform/x86/hp_accel.c
index 13e14ec1d3d7..6bec745b6b92 100644
--- a/drivers/platform/x86/hp_accel.c
+++ b/drivers/platform/x86/hp_accel.c
@@ -37,6 +37,8 @@
37#include <linux/leds.h> 37#include <linux/leds.h>
38#include <linux/atomic.h> 38#include <linux/atomic.h>
39#include <linux/acpi.h> 39#include <linux/acpi.h>
40#include <linux/i8042.h>
41#include <linux/serio.h>
40#include "../../misc/lis3lv02d/lis3lv02d.h" 42#include "../../misc/lis3lv02d/lis3lv02d.h"
41 43
42#define DRIVER_NAME "hp_accel" 44#define DRIVER_NAME "hp_accel"
@@ -73,6 +75,13 @@ static inline void delayed_sysfs_set(struct led_classdev *led_cdev,
73 75
74/* HP-specific accelerometer driver ------------------------------------ */ 76/* HP-specific accelerometer driver ------------------------------------ */
75 77
78/* e0 25, e0 26, e0 27, e0 28 are scan codes that the accelerometer with acpi id
79 * HPQ6000 sends through the keyboard bus */
80#define ACCEL_1 0x25
81#define ACCEL_2 0x26
82#define ACCEL_3 0x27
83#define ACCEL_4 0x28
84
76/* For automatic insertion of the module */ 85/* For automatic insertion of the module */
77static const struct acpi_device_id lis3lv02d_device_ids[] = { 86static const struct acpi_device_id lis3lv02d_device_ids[] = {
78 {"HPQ0004", 0}, /* HP Mobile Data Protection System PNP */ 87 {"HPQ0004", 0}, /* HP Mobile Data Protection System PNP */
@@ -294,6 +303,35 @@ static void lis3lv02d_enum_resources(struct acpi_device *device)
294 printk(KERN_DEBUG DRIVER_NAME ": Error getting resources\n"); 303 printk(KERN_DEBUG DRIVER_NAME ": Error getting resources\n");
295} 304}
296 305
306static bool hp_accel_i8042_filter(unsigned char data, unsigned char str,
307 struct serio *port)
308{
309 static bool extended;
310
311 if (str & I8042_STR_AUXDATA)
312 return false;
313
314 if (data == 0xe0) {
315 extended = true;
316 return true;
317 } else if (unlikely(extended)) {
318 extended = false;
319
320 switch (data) {
321 case ACCEL_1:
322 case ACCEL_2:
323 case ACCEL_3:
324 case ACCEL_4:
325 return true;
326 default:
327 serio_interrupt(port, 0xe0, 0);
328 return false;
329 }
330 }
331
332 return false;
333}
334
297static int lis3lv02d_add(struct acpi_device *device) 335static int lis3lv02d_add(struct acpi_device *device)
298{ 336{
299 int ret; 337 int ret;
@@ -326,6 +364,11 @@ static int lis3lv02d_add(struct acpi_device *device)
326 if (ret) 364 if (ret)
327 return ret; 365 return ret;
328 366
367 /* filter to remove HPQ6000 accelerometer data
368 * from keyboard bus stream */
369 if (strstr(dev_name(&device->dev), "HPQ6000"))
370 i8042_install_filter(hp_accel_i8042_filter);
371
329 INIT_WORK(&hpled_led.work, delayed_set_status_worker); 372 INIT_WORK(&hpled_led.work, delayed_set_status_worker);
330 ret = led_classdev_register(NULL, &hpled_led.led_classdev); 373 ret = led_classdev_register(NULL, &hpled_led.led_classdev);
331 if (ret) { 374 if (ret) {
@@ -343,6 +386,7 @@ static int lis3lv02d_remove(struct acpi_device *device)
343 if (!device) 386 if (!device)
344 return -EINVAL; 387 return -EINVAL;
345 388
389 i8042_remove_filter(hp_accel_i8042_filter);
346 lis3lv02d_joystick_disable(&lis3_dev); 390 lis3lv02d_joystick_disable(&lis3_dev);
347 lis3lv02d_poweroff(&lis3_dev); 391 lis3lv02d_poweroff(&lis3_dev);
348 392
diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
index 02152de135b5..ed494f37c40f 100644
--- a/drivers/platform/x86/ideapad-laptop.c
+++ b/drivers/platform/x86/ideapad-laptop.c
@@ -837,6 +837,13 @@ static const struct dmi_system_id no_hw_rfkill_list[] = {
837 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Yoga 2"), 837 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo Yoga 2"),
838 }, 838 },
839 }, 839 },
840 {
841 .ident = "Lenovo Yoga 3 Pro 1370",
842 .matches = {
843 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
844 DMI_MATCH(DMI_PRODUCT_VERSION, "Lenovo YOGA 3 Pro-1370"),
845 },
846 },
840 {} 847 {}
841}; 848};
842 849
diff --git a/drivers/platform/x86/samsung-laptop.c b/drivers/platform/x86/samsung-laptop.c
index 5a5966512277..ff765d8e1a09 100644
--- a/drivers/platform/x86/samsung-laptop.c
+++ b/drivers/platform/x86/samsung-laptop.c
@@ -1561,6 +1561,16 @@ static struct dmi_system_id __initdata samsung_dmi_table[] = {
1561 }, 1561 },
1562 { 1562 {
1563 .callback = samsung_dmi_matched, 1563 .callback = samsung_dmi_matched,
1564 .ident = "NC210",
1565 .matches = {
1566 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
1567 DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
1568 DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
1569 },
1570 .driver_data = &samsung_broken_acpi_video,
1571 },
1572 {
1573 .callback = samsung_dmi_matched,
1564 .ident = "730U3E/740U3E", 1574 .ident = "730U3E/740U3E",
1565 .matches = { 1575 .matches = {
1566 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), 1576 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index ef3a1904e92f..ab6151f05420 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -240,6 +240,12 @@ static const struct dmi_system_id toshiba_alt_keymap_dmi[] = {
240 DMI_MATCH(DMI_PRODUCT_NAME, "Qosmio X75-A"), 240 DMI_MATCH(DMI_PRODUCT_NAME, "Qosmio X75-A"),
241 }, 241 },
242 }, 242 },
243 {
244 .matches = {
245 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
246 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A50-A"),
247 },
248 },
243 {} 249 {}
244}; 250};
245 251
diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c
index 217da4b2ca86..99a78d365ceb 100644
--- a/drivers/power/ab8500_fg.c
+++ b/drivers/power/ab8500_fg.c
@@ -25,6 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/time.h> 27#include <linux/time.h>
28#include <linux/time64.h>
28#include <linux/of.h> 29#include <linux/of.h>
29#include <linux/completion.h> 30#include <linux/completion.h>
30#include <linux/mfd/core.h> 31#include <linux/mfd/core.h>
@@ -108,7 +109,7 @@ enum ab8500_fg_calibration_state {
108struct ab8500_fg_avg_cap { 109struct ab8500_fg_avg_cap {
109 int avg; 110 int avg;
110 int samples[NBR_AVG_SAMPLES]; 111 int samples[NBR_AVG_SAMPLES];
111 __kernel_time_t time_stamps[NBR_AVG_SAMPLES]; 112 time64_t time_stamps[NBR_AVG_SAMPLES];
112 int pos; 113 int pos;
113 int nbr_samples; 114 int nbr_samples;
114 int sum; 115 int sum;
@@ -386,15 +387,15 @@ static int ab8500_fg_is_low_curr(struct ab8500_fg *di, int curr)
386 */ 387 */
387static int ab8500_fg_add_cap_sample(struct ab8500_fg *di, int sample) 388static int ab8500_fg_add_cap_sample(struct ab8500_fg *di, int sample)
388{ 389{
389 struct timespec ts; 390 struct timespec64 ts64;
390 struct ab8500_fg_avg_cap *avg = &di->avg_cap; 391 struct ab8500_fg_avg_cap *avg = &di->avg_cap;
391 392
392 getnstimeofday(&ts); 393 getnstimeofday64(&ts64);
393 394
394 do { 395 do {
395 avg->sum += sample - avg->samples[avg->pos]; 396 avg->sum += sample - avg->samples[avg->pos];
396 avg->samples[avg->pos] = sample; 397 avg->samples[avg->pos] = sample;
397 avg->time_stamps[avg->pos] = ts.tv_sec; 398 avg->time_stamps[avg->pos] = ts64.tv_sec;
398 avg->pos++; 399 avg->pos++;
399 400
400 if (avg->pos == NBR_AVG_SAMPLES) 401 if (avg->pos == NBR_AVG_SAMPLES)
@@ -407,7 +408,7 @@ static int ab8500_fg_add_cap_sample(struct ab8500_fg *di, int sample)
407 * Check the time stamp for each sample. If too old, 408 * Check the time stamp for each sample. If too old,
408 * replace with latest sample 409 * replace with latest sample
409 */ 410 */
410 } while (ts.tv_sec - VALID_CAPACITY_SEC > avg->time_stamps[avg->pos]); 411 } while (ts64.tv_sec - VALID_CAPACITY_SEC > avg->time_stamps[avg->pos]);
411 412
412 avg->avg = avg->sum / avg->nbr_samples; 413 avg->avg = avg->sum / avg->nbr_samples;
413 414
@@ -446,14 +447,14 @@ static void ab8500_fg_clear_cap_samples(struct ab8500_fg *di)
446static void ab8500_fg_fill_cap_sample(struct ab8500_fg *di, int sample) 447static void ab8500_fg_fill_cap_sample(struct ab8500_fg *di, int sample)
447{ 448{
448 int i; 449 int i;
449 struct timespec ts; 450 struct timespec64 ts64;
450 struct ab8500_fg_avg_cap *avg = &di->avg_cap; 451 struct ab8500_fg_avg_cap *avg = &di->avg_cap;
451 452
452 getnstimeofday(&ts); 453 getnstimeofday64(&ts64);
453 454
454 for (i = 0; i < NBR_AVG_SAMPLES; i++) { 455 for (i = 0; i < NBR_AVG_SAMPLES; i++) {
455 avg->samples[i] = sample; 456 avg->samples[i] = sample;
456 avg->time_stamps[i] = ts.tv_sec; 457 avg->time_stamps[i] = ts64.tv_sec;
457 } 458 }
458 459
459 avg->pos = 0; 460 avg->pos = 0;
diff --git a/drivers/power/bq2415x_charger.c b/drivers/power/bq2415x_charger.c
index e384844a1ae1..1f49986fc605 100644
--- a/drivers/power/bq2415x_charger.c
+++ b/drivers/power/bq2415x_charger.c
@@ -1579,8 +1579,15 @@ static int bq2415x_probe(struct i2c_client *client,
1579 if (np) { 1579 if (np) {
1580 bq->notify_psy = power_supply_get_by_phandle(np, "ti,usb-charger-detection"); 1580 bq->notify_psy = power_supply_get_by_phandle(np, "ti,usb-charger-detection");
1581 1581
1582 if (!bq->notify_psy) 1582 if (IS_ERR(bq->notify_psy)) {
1583 return -EPROBE_DEFER; 1583 dev_info(&client->dev,
1584 "no 'ti,usb-charger-detection' property (err=%ld)\n",
1585 PTR_ERR(bq->notify_psy));
1586 bq->notify_psy = NULL;
1587 } else if (!bq->notify_psy) {
1588 ret = -EPROBE_DEFER;
1589 goto error_2;
1590 }
1584 } 1591 }
1585 else if (pdata->notify_device) 1592 else if (pdata->notify_device)
1586 bq->notify_psy = power_supply_get_by_name(pdata->notify_device); 1593 bq->notify_psy = power_supply_get_by_name(pdata->notify_device);
@@ -1602,27 +1609,27 @@ static int bq2415x_probe(struct i2c_client *client,
1602 ret = of_property_read_u32(np, "ti,current-limit", 1609 ret = of_property_read_u32(np, "ti,current-limit",
1603 &bq->init_data.current_limit); 1610 &bq->init_data.current_limit);
1604 if (ret) 1611 if (ret)
1605 return ret; 1612 goto error_2;
1606 ret = of_property_read_u32(np, "ti,weak-battery-voltage", 1613 ret = of_property_read_u32(np, "ti,weak-battery-voltage",
1607 &bq->init_data.weak_battery_voltage); 1614 &bq->init_data.weak_battery_voltage);
1608 if (ret) 1615 if (ret)
1609 return ret; 1616 goto error_2;
1610 ret = of_property_read_u32(np, "ti,battery-regulation-voltage", 1617 ret = of_property_read_u32(np, "ti,battery-regulation-voltage",
1611 &bq->init_data.battery_regulation_voltage); 1618 &bq->init_data.battery_regulation_voltage);
1612 if (ret) 1619 if (ret)
1613 return ret; 1620 goto error_2;
1614 ret = of_property_read_u32(np, "ti,charge-current", 1621 ret = of_property_read_u32(np, "ti,charge-current",
1615 &bq->init_data.charge_current); 1622 &bq->init_data.charge_current);
1616 if (ret) 1623 if (ret)
1617 return ret; 1624 goto error_2;
1618 ret = of_property_read_u32(np, "ti,termination-current", 1625 ret = of_property_read_u32(np, "ti,termination-current",
1619 &bq->init_data.termination_current); 1626 &bq->init_data.termination_current);
1620 if (ret) 1627 if (ret)
1621 return ret; 1628 goto error_2;
1622 ret = of_property_read_u32(np, "ti,resistor-sense", 1629 ret = of_property_read_u32(np, "ti,resistor-sense",
1623 &bq->init_data.resistor_sense); 1630 &bq->init_data.resistor_sense);
1624 if (ret) 1631 if (ret)
1625 return ret; 1632 goto error_2;
1626 } else { 1633 } else {
1627 memcpy(&bq->init_data, pdata, sizeof(bq->init_data)); 1634 memcpy(&bq->init_data, pdata, sizeof(bq->init_data));
1628 } 1635 }
diff --git a/drivers/power/charger-manager.c b/drivers/power/charger-manager.c
index 7098a1ce2d3c..ef8094a61f1e 100644
--- a/drivers/power/charger-manager.c
+++ b/drivers/power/charger-manager.c
@@ -97,6 +97,7 @@ static struct charger_global_desc *g_desc; /* init with setup_charger_manager */
97static bool is_batt_present(struct charger_manager *cm) 97static bool is_batt_present(struct charger_manager *cm)
98{ 98{
99 union power_supply_propval val; 99 union power_supply_propval val;
100 struct power_supply *psy;
100 bool present = false; 101 bool present = false;
101 int i, ret; 102 int i, ret;
102 103
@@ -107,16 +108,27 @@ static bool is_batt_present(struct charger_manager *cm)
107 case CM_NO_BATTERY: 108 case CM_NO_BATTERY:
108 break; 109 break;
109 case CM_FUEL_GAUGE: 110 case CM_FUEL_GAUGE:
110 ret = cm->fuel_gauge->get_property(cm->fuel_gauge, 111 psy = power_supply_get_by_name(cm->desc->psy_fuel_gauge);
112 if (!psy)
113 break;
114
115 ret = psy->get_property(psy,
111 POWER_SUPPLY_PROP_PRESENT, &val); 116 POWER_SUPPLY_PROP_PRESENT, &val);
112 if (ret == 0 && val.intval) 117 if (ret == 0 && val.intval)
113 present = true; 118 present = true;
114 break; 119 break;
115 case CM_CHARGER_STAT: 120 case CM_CHARGER_STAT:
116 for (i = 0; cm->charger_stat[i]; i++) { 121 for (i = 0; cm->desc->psy_charger_stat[i]; i++) {
117 ret = cm->charger_stat[i]->get_property( 122 psy = power_supply_get_by_name(
118 cm->charger_stat[i], 123 cm->desc->psy_charger_stat[i]);
119 POWER_SUPPLY_PROP_PRESENT, &val); 124 if (!psy) {
125 dev_err(cm->dev, "Cannot find power supply \"%s\"\n",
126 cm->desc->psy_charger_stat[i]);
127 continue;
128 }
129
130 ret = psy->get_property(psy, POWER_SUPPLY_PROP_PRESENT,
131 &val);
120 if (ret == 0 && val.intval) { 132 if (ret == 0 && val.intval) {
121 present = true; 133 present = true;
122 break; 134 break;
@@ -139,14 +151,20 @@ static bool is_batt_present(struct charger_manager *cm)
139static bool is_ext_pwr_online(struct charger_manager *cm) 151static bool is_ext_pwr_online(struct charger_manager *cm)
140{ 152{
141 union power_supply_propval val; 153 union power_supply_propval val;
154 struct power_supply *psy;
142 bool online = false; 155 bool online = false;
143 int i, ret; 156 int i, ret;
144 157
145 /* If at least one of them has one, it's yes. */ 158 /* If at least one of them has one, it's yes. */
146 for (i = 0; cm->charger_stat[i]; i++) { 159 for (i = 0; cm->desc->psy_charger_stat[i]; i++) {
147 ret = cm->charger_stat[i]->get_property( 160 psy = power_supply_get_by_name(cm->desc->psy_charger_stat[i]);
148 cm->charger_stat[i], 161 if (!psy) {
149 POWER_SUPPLY_PROP_ONLINE, &val); 162 dev_err(cm->dev, "Cannot find power supply \"%s\"\n",
163 cm->desc->psy_charger_stat[i]);
164 continue;
165 }
166
167 ret = psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &val);
150 if (ret == 0 && val.intval) { 168 if (ret == 0 && val.intval) {
151 online = true; 169 online = true;
152 break; 170 break;
@@ -167,12 +185,14 @@ static bool is_ext_pwr_online(struct charger_manager *cm)
167static int get_batt_uV(struct charger_manager *cm, int *uV) 185static int get_batt_uV(struct charger_manager *cm, int *uV)
168{ 186{
169 union power_supply_propval val; 187 union power_supply_propval val;
188 struct power_supply *fuel_gauge;
170 int ret; 189 int ret;
171 190
172 if (!cm->fuel_gauge) 191 fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge);
192 if (!fuel_gauge)
173 return -ENODEV; 193 return -ENODEV;
174 194
175 ret = cm->fuel_gauge->get_property(cm->fuel_gauge, 195 ret = fuel_gauge->get_property(fuel_gauge,
176 POWER_SUPPLY_PROP_VOLTAGE_NOW, &val); 196 POWER_SUPPLY_PROP_VOLTAGE_NOW, &val);
177 if (ret) 197 if (ret)
178 return ret; 198 return ret;
@@ -189,6 +209,7 @@ static bool is_charging(struct charger_manager *cm)
189{ 209{
190 int i, ret; 210 int i, ret;
191 bool charging = false; 211 bool charging = false;
212 struct power_supply *psy;
192 union power_supply_propval val; 213 union power_supply_propval val;
193 214
194 /* If there is no battery, it cannot be charged */ 215 /* If there is no battery, it cannot be charged */
@@ -196,17 +217,22 @@ static bool is_charging(struct charger_manager *cm)
196 return false; 217 return false;
197 218
198 /* If at least one of the charger is charging, return yes */ 219 /* If at least one of the charger is charging, return yes */
199 for (i = 0; cm->charger_stat[i]; i++) { 220 for (i = 0; cm->desc->psy_charger_stat[i]; i++) {
200 /* 1. The charger sholuld not be DISABLED */ 221 /* 1. The charger sholuld not be DISABLED */
201 if (cm->emergency_stop) 222 if (cm->emergency_stop)
202 continue; 223 continue;
203 if (!cm->charger_enabled) 224 if (!cm->charger_enabled)
204 continue; 225 continue;
205 226
227 psy = power_supply_get_by_name(cm->desc->psy_charger_stat[i]);
228 if (!psy) {
229 dev_err(cm->dev, "Cannot find power supply \"%s\"\n",
230 cm->desc->psy_charger_stat[i]);
231 continue;
232 }
233
206 /* 2. The charger should be online (ext-power) */ 234 /* 2. The charger should be online (ext-power) */
207 ret = cm->charger_stat[i]->get_property( 235 ret = psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &val);
208 cm->charger_stat[i],
209 POWER_SUPPLY_PROP_ONLINE, &val);
210 if (ret) { 236 if (ret) {
211 dev_warn(cm->dev, "Cannot read ONLINE value from %s\n", 237 dev_warn(cm->dev, "Cannot read ONLINE value from %s\n",
212 cm->desc->psy_charger_stat[i]); 238 cm->desc->psy_charger_stat[i]);
@@ -219,9 +245,7 @@ static bool is_charging(struct charger_manager *cm)
219 * 3. The charger should not be FULL, DISCHARGING, 245 * 3. The charger should not be FULL, DISCHARGING,
220 * or NOT_CHARGING. 246 * or NOT_CHARGING.
221 */ 247 */
222 ret = cm->charger_stat[i]->get_property( 248 ret = psy->get_property(psy, POWER_SUPPLY_PROP_STATUS, &val);
223 cm->charger_stat[i],
224 POWER_SUPPLY_PROP_STATUS, &val);
225 if (ret) { 249 if (ret) {
226 dev_warn(cm->dev, "Cannot read STATUS value from %s\n", 250 dev_warn(cm->dev, "Cannot read STATUS value from %s\n",
227 cm->desc->psy_charger_stat[i]); 251 cm->desc->psy_charger_stat[i]);
@@ -248,6 +272,7 @@ static bool is_full_charged(struct charger_manager *cm)
248{ 272{
249 struct charger_desc *desc = cm->desc; 273 struct charger_desc *desc = cm->desc;
250 union power_supply_propval val; 274 union power_supply_propval val;
275 struct power_supply *fuel_gauge;
251 int ret = 0; 276 int ret = 0;
252 int uV; 277 int uV;
253 278
@@ -255,11 +280,15 @@ static bool is_full_charged(struct charger_manager *cm)
255 if (!is_batt_present(cm)) 280 if (!is_batt_present(cm))
256 return false; 281 return false;
257 282
258 if (cm->fuel_gauge && desc->fullbatt_full_capacity > 0) { 283 fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge);
284 if (!fuel_gauge)
285 return false;
286
287 if (desc->fullbatt_full_capacity > 0) {
259 val.intval = 0; 288 val.intval = 0;
260 289
261 /* Not full if capacity of fuel gauge isn't full */ 290 /* Not full if capacity of fuel gauge isn't full */
262 ret = cm->fuel_gauge->get_property(cm->fuel_gauge, 291 ret = fuel_gauge->get_property(fuel_gauge,
263 POWER_SUPPLY_PROP_CHARGE_FULL, &val); 292 POWER_SUPPLY_PROP_CHARGE_FULL, &val);
264 if (!ret && val.intval > desc->fullbatt_full_capacity) 293 if (!ret && val.intval > desc->fullbatt_full_capacity)
265 return true; 294 return true;
@@ -273,10 +302,10 @@ static bool is_full_charged(struct charger_manager *cm)
273 } 302 }
274 303
275 /* Full, if the capacity is more than fullbatt_soc */ 304 /* Full, if the capacity is more than fullbatt_soc */
276 if (cm->fuel_gauge && desc->fullbatt_soc > 0) { 305 if (desc->fullbatt_soc > 0) {
277 val.intval = 0; 306 val.intval = 0;
278 307
279 ret = cm->fuel_gauge->get_property(cm->fuel_gauge, 308 ret = fuel_gauge->get_property(fuel_gauge,
280 POWER_SUPPLY_PROP_CAPACITY, &val); 309 POWER_SUPPLY_PROP_CAPACITY, &val);
281 if (!ret && val.intval >= desc->fullbatt_soc) 310 if (!ret && val.intval >= desc->fullbatt_soc)
282 return true; 311 return true;
@@ -551,6 +580,20 @@ static int check_charging_duration(struct charger_manager *cm)
551 return ret; 580 return ret;
552} 581}
553 582
583static int cm_get_battery_temperature_by_psy(struct charger_manager *cm,
584 int *temp)
585{
586 struct power_supply *fuel_gauge;
587
588 fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge);
589 if (!fuel_gauge)
590 return -ENODEV;
591
592 return fuel_gauge->get_property(fuel_gauge,
593 POWER_SUPPLY_PROP_TEMP,
594 (union power_supply_propval *)temp);
595}
596
554static int cm_get_battery_temperature(struct charger_manager *cm, 597static int cm_get_battery_temperature(struct charger_manager *cm,
555 int *temp) 598 int *temp)
556{ 599{
@@ -560,15 +603,18 @@ static int cm_get_battery_temperature(struct charger_manager *cm,
560 return -ENODEV; 603 return -ENODEV;
561 604
562#ifdef CONFIG_THERMAL 605#ifdef CONFIG_THERMAL
563 ret = thermal_zone_get_temp(cm->tzd_batt, (unsigned long *)temp); 606 if (cm->tzd_batt) {
564 if (!ret) 607 ret = thermal_zone_get_temp(cm->tzd_batt, (unsigned long *)temp);
565 /* Calibrate temperature unit */ 608 if (!ret)
566 *temp /= 100; 609 /* Calibrate temperature unit */
567#else 610 *temp /= 100;
568 ret = cm->fuel_gauge->get_property(cm->fuel_gauge, 611 } else
569 POWER_SUPPLY_PROP_TEMP,
570 (union power_supply_propval *)temp);
571#endif 612#endif
613 {
614 /* if-else continued from CONFIG_THERMAL */
615 ret = cm_get_battery_temperature_by_psy(cm, temp);
616 }
617
572 return ret; 618 return ret;
573} 619}
574 620
@@ -827,6 +873,7 @@ static int charger_get_property(struct power_supply *psy,
827 struct charger_manager *cm = container_of(psy, 873 struct charger_manager *cm = container_of(psy,
828 struct charger_manager, charger_psy); 874 struct charger_manager, charger_psy);
829 struct charger_desc *desc = cm->desc; 875 struct charger_desc *desc = cm->desc;
876 struct power_supply *fuel_gauge;
830 int ret = 0; 877 int ret = 0;
831 int uV; 878 int uV;
832 879
@@ -857,14 +904,20 @@ static int charger_get_property(struct power_supply *psy,
857 ret = get_batt_uV(cm, &val->intval); 904 ret = get_batt_uV(cm, &val->intval);
858 break; 905 break;
859 case POWER_SUPPLY_PROP_CURRENT_NOW: 906 case POWER_SUPPLY_PROP_CURRENT_NOW:
860 ret = cm->fuel_gauge->get_property(cm->fuel_gauge, 907 fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge);
908 if (!fuel_gauge) {
909 ret = -ENODEV;
910 break;
911 }
912 ret = fuel_gauge->get_property(fuel_gauge,
861 POWER_SUPPLY_PROP_CURRENT_NOW, val); 913 POWER_SUPPLY_PROP_CURRENT_NOW, val);
862 break; 914 break;
863 case POWER_SUPPLY_PROP_TEMP: 915 case POWER_SUPPLY_PROP_TEMP:
864 case POWER_SUPPLY_PROP_TEMP_AMBIENT: 916 case POWER_SUPPLY_PROP_TEMP_AMBIENT:
865 return cm_get_battery_temperature(cm, &val->intval); 917 return cm_get_battery_temperature(cm, &val->intval);
866 case POWER_SUPPLY_PROP_CAPACITY: 918 case POWER_SUPPLY_PROP_CAPACITY:
867 if (!cm->fuel_gauge) { 919 fuel_gauge = power_supply_get_by_name(cm->desc->psy_fuel_gauge);
920 if (!fuel_gauge) {
868 ret = -ENODEV; 921 ret = -ENODEV;
869 break; 922 break;
870 } 923 }
@@ -875,7 +928,7 @@ static int charger_get_property(struct power_supply *psy,
875 break; 928 break;
876 } 929 }
877 930
878 ret = cm->fuel_gauge->get_property(cm->fuel_gauge, 931 ret = fuel_gauge->get_property(fuel_gauge,
879 POWER_SUPPLY_PROP_CAPACITY, val); 932 POWER_SUPPLY_PROP_CAPACITY, val);
880 if (ret) 933 if (ret)
881 break; 934 break;
@@ -924,7 +977,14 @@ static int charger_get_property(struct power_supply *psy,
924 break; 977 break;
925 case POWER_SUPPLY_PROP_CHARGE_NOW: 978 case POWER_SUPPLY_PROP_CHARGE_NOW:
926 if (is_charging(cm)) { 979 if (is_charging(cm)) {
927 ret = cm->fuel_gauge->get_property(cm->fuel_gauge, 980 fuel_gauge = power_supply_get_by_name(
981 cm->desc->psy_fuel_gauge);
982 if (!fuel_gauge) {
983 ret = -ENODEV;
984 break;
985 }
986
987 ret = fuel_gauge->get_property(fuel_gauge,
928 POWER_SUPPLY_PROP_CHARGE_NOW, 988 POWER_SUPPLY_PROP_CHARGE_NOW,
929 val); 989 val);
930 if (ret) { 990 if (ret) {
@@ -970,6 +1030,7 @@ static struct power_supply psy_default = {
970 .properties = default_charger_props, 1030 .properties = default_charger_props,
971 .num_properties = ARRAY_SIZE(default_charger_props), 1031 .num_properties = ARRAY_SIZE(default_charger_props),
972 .get_property = charger_get_property, 1032 .get_property = charger_get_property,
1033 .no_thermal = true,
973}; 1034};
974 1035
975/** 1036/**
@@ -1485,14 +1546,15 @@ err:
1485 return ret; 1546 return ret;
1486} 1547}
1487 1548
1488static int cm_init_thermal_data(struct charger_manager *cm) 1549static int cm_init_thermal_data(struct charger_manager *cm,
1550 struct power_supply *fuel_gauge)
1489{ 1551{
1490 struct charger_desc *desc = cm->desc; 1552 struct charger_desc *desc = cm->desc;
1491 union power_supply_propval val; 1553 union power_supply_propval val;
1492 int ret; 1554 int ret;
1493 1555
1494 /* Verify whether fuel gauge provides battery temperature */ 1556 /* Verify whether fuel gauge provides battery temperature */
1495 ret = cm->fuel_gauge->get_property(cm->fuel_gauge, 1557 ret = fuel_gauge->get_property(fuel_gauge,
1496 POWER_SUPPLY_PROP_TEMP, &val); 1558 POWER_SUPPLY_PROP_TEMP, &val);
1497 1559
1498 if (!ret) { 1560 if (!ret) {
@@ -1502,8 +1564,6 @@ static int cm_init_thermal_data(struct charger_manager *cm)
1502 cm->desc->measure_battery_temp = true; 1564 cm->desc->measure_battery_temp = true;
1503 } 1565 }
1504#ifdef CONFIG_THERMAL 1566#ifdef CONFIG_THERMAL
1505 cm->tzd_batt = cm->fuel_gauge->tzd;
1506
1507 if (ret && desc->thermal_zone) { 1567 if (ret && desc->thermal_zone) {
1508 cm->tzd_batt = 1568 cm->tzd_batt =
1509 thermal_zone_get_zone_by_name(desc->thermal_zone); 1569 thermal_zone_get_zone_by_name(desc->thermal_zone);
@@ -1666,6 +1726,7 @@ static int charger_manager_probe(struct platform_device *pdev)
1666 int ret = 0, i = 0; 1726 int ret = 0, i = 0;
1667 int j = 0; 1727 int j = 0;
1668 union power_supply_propval val; 1728 union power_supply_propval val;
1729 struct power_supply *fuel_gauge;
1669 1730
1670 if (g_desc && !rtc_dev && g_desc->rtc_name) { 1731 if (g_desc && !rtc_dev && g_desc->rtc_name) {
1671 rtc_dev = rtc_class_open(g_desc->rtc_name); 1732 rtc_dev = rtc_class_open(g_desc->rtc_name);
@@ -1729,23 +1790,20 @@ static int charger_manager_probe(struct platform_device *pdev)
1729 while (desc->psy_charger_stat[i]) 1790 while (desc->psy_charger_stat[i])
1730 i++; 1791 i++;
1731 1792
1732 cm->charger_stat = devm_kzalloc(&pdev->dev, 1793 /* Check if charger's supplies are present at probe */
1733 sizeof(struct power_supply *) * i, GFP_KERNEL);
1734 if (!cm->charger_stat)
1735 return -ENOMEM;
1736
1737 for (i = 0; desc->psy_charger_stat[i]; i++) { 1794 for (i = 0; desc->psy_charger_stat[i]; i++) {
1738 cm->charger_stat[i] = power_supply_get_by_name( 1795 struct power_supply *psy;
1739 desc->psy_charger_stat[i]); 1796
1740 if (!cm->charger_stat[i]) { 1797 psy = power_supply_get_by_name(desc->psy_charger_stat[i]);
1798 if (!psy) {
1741 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n", 1799 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
1742 desc->psy_charger_stat[i]); 1800 desc->psy_charger_stat[i]);
1743 return -ENODEV; 1801 return -ENODEV;
1744 } 1802 }
1745 } 1803 }
1746 1804
1747 cm->fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge); 1805 fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge);
1748 if (!cm->fuel_gauge) { 1806 if (!fuel_gauge) {
1749 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n", 1807 dev_err(&pdev->dev, "Cannot find power supply \"%s\"\n",
1750 desc->psy_fuel_gauge); 1808 desc->psy_fuel_gauge);
1751 return -ENODEV; 1809 return -ENODEV;
@@ -1788,13 +1846,13 @@ static int charger_manager_probe(struct platform_device *pdev)
1788 cm->charger_psy.num_properties = psy_default.num_properties; 1846 cm->charger_psy.num_properties = psy_default.num_properties;
1789 1847
1790 /* Find which optional psy-properties are available */ 1848 /* Find which optional psy-properties are available */
1791 if (!cm->fuel_gauge->get_property(cm->fuel_gauge, 1849 if (!fuel_gauge->get_property(fuel_gauge,
1792 POWER_SUPPLY_PROP_CHARGE_NOW, &val)) { 1850 POWER_SUPPLY_PROP_CHARGE_NOW, &val)) {
1793 cm->charger_psy.properties[cm->charger_psy.num_properties] = 1851 cm->charger_psy.properties[cm->charger_psy.num_properties] =
1794 POWER_SUPPLY_PROP_CHARGE_NOW; 1852 POWER_SUPPLY_PROP_CHARGE_NOW;
1795 cm->charger_psy.num_properties++; 1853 cm->charger_psy.num_properties++;
1796 } 1854 }
1797 if (!cm->fuel_gauge->get_property(cm->fuel_gauge, 1855 if (!fuel_gauge->get_property(fuel_gauge,
1798 POWER_SUPPLY_PROP_CURRENT_NOW, 1856 POWER_SUPPLY_PROP_CURRENT_NOW,
1799 &val)) { 1857 &val)) {
1800 cm->charger_psy.properties[cm->charger_psy.num_properties] = 1858 cm->charger_psy.properties[cm->charger_psy.num_properties] =
@@ -1802,7 +1860,7 @@ static int charger_manager_probe(struct platform_device *pdev)
1802 cm->charger_psy.num_properties++; 1860 cm->charger_psy.num_properties++;
1803 } 1861 }
1804 1862
1805 ret = cm_init_thermal_data(cm); 1863 ret = cm_init_thermal_data(cm, fuel_gauge);
1806 if (ret) { 1864 if (ret) {
1807 dev_err(&pdev->dev, "Failed to initialize thermal data\n"); 1865 dev_err(&pdev->dev, "Failed to initialize thermal data\n");
1808 cm->desc->measure_battery_temp = false; 1866 cm->desc->measure_battery_temp = false;
@@ -2066,8 +2124,8 @@ static bool find_power_supply(struct charger_manager *cm,
2066 int i; 2124 int i;
2067 bool found = false; 2125 bool found = false;
2068 2126
2069 for (i = 0; cm->charger_stat[i]; i++) { 2127 for (i = 0; cm->desc->psy_charger_stat[i]; i++) {
2070 if (psy == cm->charger_stat[i]) { 2128 if (!strcmp(psy->name, cm->desc->psy_charger_stat[i])) {
2071 found = true; 2129 found = true;
2072 break; 2130 break;
2073 } 2131 }
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index 6cb7fe5c022d..694e8cddd5c1 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -417,6 +417,9 @@ static int psy_register_thermal(struct power_supply *psy)
417{ 417{
418 int i; 418 int i;
419 419
420 if (psy->no_thermal)
421 return 0;
422
420 /* Register battery zone device psy reports temperature */ 423 /* Register battery zone device psy reports temperature */
421 for (i = 0; i < psy->num_properties; i++) { 424 for (i = 0; i < psy->num_properties; i++) {
422 if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) { 425 if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) {
diff --git a/drivers/power/reset/at91-reset.c b/drivers/power/reset/at91-reset.c
index 3cb36693343a..69a75d99ae92 100644
--- a/drivers/power/reset/at91-reset.c
+++ b/drivers/power/reset/at91-reset.c
@@ -19,8 +19,8 @@
19 19
20#include <asm/system_misc.h> 20#include <asm/system_misc.h>
21 21
22#include <mach/at91sam9_ddrsdr.h> 22#include <soc/at91/at91sam9_ddrsdr.h>
23#include <mach/at91sam9_sdramc.h> 23#include <soc/at91/at91sam9_sdramc.h>
24 24
25#define AT91_RSTC_CR 0x00 /* Reset Controller Control Register */ 25#define AT91_RSTC_CR 0x00 /* Reset Controller Control Register */
26#define AT91_RSTC_PROCRST BIT(0) /* Processor Reset */ 26#define AT91_RSTC_PROCRST BIT(0) /* Processor Reset */
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
index 6d77dcd7dcf6..3fe47bd66153 100644
--- a/drivers/regulator/88pm8607.c
+++ b/drivers/regulator/88pm8607.c
@@ -330,7 +330,8 @@ static int pm8607_regulator_dt_init(struct platform_device *pdev,
330 for_each_child_of_node(nproot, np) { 330 for_each_child_of_node(nproot, np) {
331 if (!of_node_cmp(np->name, info->desc.name)) { 331 if (!of_node_cmp(np->name, info->desc.name)) {
332 config->init_data = 332 config->init_data =
333 of_get_regulator_init_data(&pdev->dev, np); 333 of_get_regulator_init_data(&pdev->dev, np,
334 &info->desc);
334 config->of_node = np; 335 config->of_node = np;
335 break; 336 break;
336 } 337 }
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 55d7b7b0f2e0..c3a60b57a865 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -521,6 +521,14 @@ config REGULATOR_RN5T618
521 help 521 help
522 Say y here to support the regulators found on Ricoh RN5T618 PMIC. 522 Say y here to support the regulators found on Ricoh RN5T618 PMIC.
523 523
524config REGULATOR_RT5033
525 tristate "Richtek RT5033 Regulators"
526 depends on MFD_RT5033
527 help
528 This adds support for voltage and current regulators in Richtek
529 RT5033 PMIC. The device supports multiple regulators like
530 current source, LDO and Buck.
531
524config REGULATOR_S2MPA01 532config REGULATOR_S2MPA01
525 tristate "Samsung S2MPA01 voltage regulator" 533 tristate "Samsung S2MPA01 voltage regulator"
526 depends on MFD_SEC_CORE 534 depends on MFD_SEC_CORE
@@ -529,13 +537,13 @@ config REGULATOR_S2MPA01
529 via I2C bus. S2MPA01 has 10 Bucks and 26 LDO outputs. 537 via I2C bus. S2MPA01 has 10 Bucks and 26 LDO outputs.
530 538
531config REGULATOR_S2MPS11 539config REGULATOR_S2MPS11
532 tristate "Samsung S2MPS11/S2MPS14/S2MPU02 voltage regulator" 540 tristate "Samsung S2MPS11/S2MPS13/S2MPS14/S2MPU02 voltage regulator"
533 depends on MFD_SEC_CORE 541 depends on MFD_SEC_CORE
534 help 542 help
535 This driver supports a Samsung S2MPS11/S2MPS14/S2MPU02 voltage output 543 This driver supports a Samsung S2MPS11/S2MPS13/S2MPS14/S2MPU02 voltage
536 regulator via I2C bus. The chip is comprised of high efficient Buck 544 output regulator via I2C bus. The chip is comprised of high efficient
537 converters including Dual-Phase Buck converter, Buck-Boost converter, 545 Buck converters including Dual-Phase Buck converter, Buck-Boost
538 various LDOs. 546 converter, various LDOs.
539 547
540config REGULATOR_S5M8767 548config REGULATOR_S5M8767
541 tristate "Samsung S5M8767A voltage regulator" 549 tristate "Samsung S5M8767A voltage regulator"
@@ -547,7 +555,7 @@ config REGULATOR_S5M8767
547 555
548config REGULATOR_SKY81452 556config REGULATOR_SKY81452
549 tristate "Skyworks Solutions SKY81452 voltage regulator" 557 tristate "Skyworks Solutions SKY81452 voltage regulator"
550 depends on SKY81452 558 depends on MFD_SKY81452
551 help 559 help
552 This driver supports Skyworks SKY81452 voltage output regulator 560 This driver supports Skyworks SKY81452 voltage output regulator
553 via I2C bus. SKY81452 has one voltage linear regulator can be 561 via I2C bus. SKY81452 has one voltage linear regulator can be
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 1029ed39c512..1f28ebfc6f3a 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o
69obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o 69obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o
70obj-$(CONFIG_REGULATOR_RK808) += rk808-regulator.o 70obj-$(CONFIG_REGULATOR_RK808) += rk808-regulator.o
71obj-$(CONFIG_REGULATOR_RN5T618) += rn5t618-regulator.o 71obj-$(CONFIG_REGULATOR_RN5T618) += rn5t618-regulator.o
72obj-$(CONFIG_REGULATOR_RT5033) += rt5033-regulator.o
72obj-$(CONFIG_REGULATOR_S2MPA01) += s2mpa01.o 73obj-$(CONFIG_REGULATOR_S2MPA01) += s2mpa01.o
73obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o 74obj-$(CONFIG_REGULATOR_S2MPS11) += s2mps11.o
74obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o 75obj-$(CONFIG_REGULATOR_S5M8767) += s5m8767.o
diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c
index afd06f92dfdf..9eec453b745d 100644
--- a/drivers/regulator/act8865-regulator.c
+++ b/drivers/regulator/act8865-regulator.c
@@ -61,6 +61,8 @@
61#define ACT8846_REG12_VSET 0xa0 61#define ACT8846_REG12_VSET 0xa0
62#define ACT8846_REG12_CTRL 0xa1 62#define ACT8846_REG12_CTRL 0xa1
63#define ACT8846_REG13_CTRL 0xb1 63#define ACT8846_REG13_CTRL 0xb1
64#define ACT8846_GLB_OFF_CTRL 0xc3
65#define ACT8846_OFF_SYSMASK 0x18
64 66
65/* 67/*
66 * ACT8865 Global Register Map. 68 * ACT8865 Global Register Map.
@@ -84,6 +86,7 @@
84#define ACT8865_LDO3_CTRL 0x61 86#define ACT8865_LDO3_CTRL 0x61
85#define ACT8865_LDO4_VSET 0x64 87#define ACT8865_LDO4_VSET 0x64
86#define ACT8865_LDO4_CTRL 0x65 88#define ACT8865_LDO4_CTRL 0x65
89#define ACT8865_MSTROFF 0x20
87 90
88/* 91/*
89 * Field Definitions. 92 * Field Definitions.
@@ -98,6 +101,8 @@
98 101
99struct act8865 { 102struct act8865 {
100 struct regmap *regmap; 103 struct regmap *regmap;
104 int off_reg;
105 int off_mask;
101}; 106};
102 107
103static const struct regmap_config act8865_regmap_config = { 108static const struct regmap_config act8865_regmap_config = {
@@ -275,6 +280,16 @@ static struct regulator_init_data
275 return NULL; 280 return NULL;
276} 281}
277 282
283static struct i2c_client *act8865_i2c_client;
284static void act8865_power_off(void)
285{
286 struct act8865 *act8865;
287
288 act8865 = i2c_get_clientdata(act8865_i2c_client);
289 regmap_write(act8865->regmap, act8865->off_reg, act8865->off_mask);
290 while (1);
291}
292
278static int act8865_pmic_probe(struct i2c_client *client, 293static int act8865_pmic_probe(struct i2c_client *client,
279 const struct i2c_device_id *i2c_id) 294 const struct i2c_device_id *i2c_id)
280{ 295{
@@ -285,6 +300,7 @@ static int act8865_pmic_probe(struct i2c_client *client,
285 int i, ret, num_regulators; 300 int i, ret, num_regulators;
286 struct act8865 *act8865; 301 struct act8865 *act8865;
287 unsigned long type; 302 unsigned long type;
303 int off_reg, off_mask;
288 304
289 pdata = dev_get_platdata(dev); 305 pdata = dev_get_platdata(dev);
290 306
@@ -304,10 +320,14 @@ static int act8865_pmic_probe(struct i2c_client *client,
304 case ACT8846: 320 case ACT8846:
305 regulators = act8846_regulators; 321 regulators = act8846_regulators;
306 num_regulators = ARRAY_SIZE(act8846_regulators); 322 num_regulators = ARRAY_SIZE(act8846_regulators);
323 off_reg = ACT8846_GLB_OFF_CTRL;
324 off_mask = ACT8846_OFF_SYSMASK;
307 break; 325 break;
308 case ACT8865: 326 case ACT8865:
309 regulators = act8865_regulators; 327 regulators = act8865_regulators;
310 num_regulators = ARRAY_SIZE(act8865_regulators); 328 num_regulators = ARRAY_SIZE(act8865_regulators);
329 off_reg = ACT8865_SYS_CTRL;
330 off_mask = ACT8865_MSTROFF;
311 break; 331 break;
312 default: 332 default:
313 dev_err(dev, "invalid device id %lu\n", type); 333 dev_err(dev, "invalid device id %lu\n", type);
@@ -345,6 +365,17 @@ static int act8865_pmic_probe(struct i2c_client *client,
345 return ret; 365 return ret;
346 } 366 }
347 367
368 if (of_device_is_system_power_controller(dev->of_node)) {
369 if (!pm_power_off) {
370 act8865_i2c_client = client;
371 act8865->off_reg = off_reg;
372 act8865->off_mask = off_mask;
373 pm_power_off = act8865_power_off;
374 } else {
375 dev_err(dev, "Failed to set poweroff capability, already defined\n");
376 }
377 }
378
348 /* Finally register devices */ 379 /* Finally register devices */
349 for (i = 0; i < num_regulators; i++) { 380 for (i = 0; i < num_regulators; i++) {
350 const struct regulator_desc *desc = &regulators[i]; 381 const struct regulator_desc *desc = &regulators[i];
diff --git a/drivers/regulator/anatop-regulator.c b/drivers/regulator/anatop-regulator.c
index 4f730af70e7c..3586571814b2 100644
--- a/drivers/regulator/anatop-regulator.c
+++ b/drivers/regulator/anatop-regulator.c
@@ -189,17 +189,18 @@ static int anatop_regulator_probe(struct platform_device *pdev)
189 int ret = 0; 189 int ret = 0;
190 u32 val; 190 u32 val;
191 191
192 initdata = of_get_regulator_init_data(dev, np);
193 sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL); 192 sreg = devm_kzalloc(dev, sizeof(*sreg), GFP_KERNEL);
194 if (!sreg) 193 if (!sreg)
195 return -ENOMEM; 194 return -ENOMEM;
196 sreg->initdata = initdata;
197 sreg->name = of_get_property(np, "regulator-name", NULL); 195 sreg->name = of_get_property(np, "regulator-name", NULL);
198 rdesc = &sreg->rdesc; 196 rdesc = &sreg->rdesc;
199 rdesc->name = sreg->name; 197 rdesc->name = sreg->name;
200 rdesc->type = REGULATOR_VOLTAGE; 198 rdesc->type = REGULATOR_VOLTAGE;
201 rdesc->owner = THIS_MODULE; 199 rdesc->owner = THIS_MODULE;
202 200
201 initdata = of_get_regulator_init_data(dev, np, rdesc);
202 sreg->initdata = initdata;
203
203 anatop_np = of_get_parent(np); 204 anatop_np = of_get_parent(np);
204 if (!anatop_np) 205 if (!anatop_np)
205 return -ENODEV; 206 return -ENODEV;
@@ -283,6 +284,19 @@ static int anatop_regulator_probe(struct platform_device *pdev)
283 sreg->sel = 0; 284 sreg->sel = 0;
284 sreg->bypass = true; 285 sreg->bypass = true;
285 } 286 }
287
288 /*
289 * In case vddpu was disabled by the bootloader, we need to set
290 * a sane default until imx6-cpufreq was probed and changes the
291 * voltage to the correct value. In this case we set 1.25V.
292 */
293 if (!sreg->sel && !strcmp(sreg->name, "vddpu"))
294 sreg->sel = 22;
295
296 if (!sreg->sel) {
297 dev_err(&pdev->dev, "Failed to read a valid default voltage selector.\n");
298 return -EINVAL;
299 }
286 } else { 300 } else {
287 rdesc->ops = &anatop_rops; 301 rdesc->ops = &anatop_rops;
288 } 302 }
diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index 4c9db589f6c1..d071b2119a60 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -179,7 +179,8 @@ static const struct regulator_init_data arizona_ldo1_default = {
179}; 179};
180 180
181static int arizona_ldo1_of_get_pdata(struct arizona *arizona, 181static int arizona_ldo1_of_get_pdata(struct arizona *arizona,
182 struct regulator_config *config) 182 struct regulator_config *config,
183 const struct regulator_desc *desc)
183{ 184{
184 struct arizona_pdata *pdata = &arizona->pdata; 185 struct arizona_pdata *pdata = &arizona->pdata;
185 struct arizona_ldo1 *ldo1 = config->driver_data; 186 struct arizona_ldo1 *ldo1 = config->driver_data;
@@ -194,7 +195,8 @@ static int arizona_ldo1_of_get_pdata(struct arizona *arizona,
194 if (init_node) { 195 if (init_node) {
195 config->of_node = init_node; 196 config->of_node = init_node;
196 197
197 init_data = of_get_regulator_init_data(arizona->dev, init_node); 198 init_data = of_get_regulator_init_data(arizona->dev, init_node,
199 desc);
198 200
199 if (init_data) { 201 if (init_data) {
200 init_data->consumer_supplies = &ldo1->supply; 202 init_data->consumer_supplies = &ldo1->supply;
@@ -257,9 +259,11 @@ static int arizona_ldo1_probe(struct platform_device *pdev)
257 259
258 if (IS_ENABLED(CONFIG_OF)) { 260 if (IS_ENABLED(CONFIG_OF)) {
259 if (!dev_get_platdata(arizona->dev)) { 261 if (!dev_get_platdata(arizona->dev)) {
260 ret = arizona_ldo1_of_get_pdata(arizona, &config); 262 ret = arizona_ldo1_of_get_pdata(arizona, &config, desc);
261 if (ret < 0) 263 if (ret < 0)
262 return ret; 264 return ret;
265
266 config.ena_gpio_initialized = true;
263 } 267 }
264 } 268 }
265 269
diff --git a/drivers/regulator/arizona-micsupp.c b/drivers/regulator/arizona-micsupp.c
index ce9aca5f8ee7..c313ef4c3a2f 100644
--- a/drivers/regulator/arizona-micsupp.c
+++ b/drivers/regulator/arizona-micsupp.c
@@ -198,7 +198,8 @@ static const struct regulator_init_data arizona_micsupp_ext_default = {
198}; 198};
199 199
200static int arizona_micsupp_of_get_pdata(struct arizona *arizona, 200static int arizona_micsupp_of_get_pdata(struct arizona *arizona,
201 struct regulator_config *config) 201 struct regulator_config *config,
202 const struct regulator_desc *desc)
202{ 203{
203 struct arizona_pdata *pdata = &arizona->pdata; 204 struct arizona_pdata *pdata = &arizona->pdata;
204 struct arizona_micsupp *micsupp = config->driver_data; 205 struct arizona_micsupp *micsupp = config->driver_data;
@@ -210,7 +211,7 @@ static int arizona_micsupp_of_get_pdata(struct arizona *arizona,
210 if (np) { 211 if (np) {
211 config->of_node = np; 212 config->of_node = np;
212 213
213 init_data = of_get_regulator_init_data(arizona->dev, np); 214 init_data = of_get_regulator_init_data(arizona->dev, np, desc);
214 215
215 if (init_data) { 216 if (init_data) {
216 init_data->consumer_supplies = &micsupp->supply; 217 init_data->consumer_supplies = &micsupp->supply;
@@ -264,7 +265,8 @@ static int arizona_micsupp_probe(struct platform_device *pdev)
264 265
265 if (IS_ENABLED(CONFIG_OF)) { 266 if (IS_ENABLED(CONFIG_OF)) {
266 if (!dev_get_platdata(arizona->dev)) { 267 if (!dev_get_platdata(arizona->dev)) {
267 ret = arizona_micsupp_of_get_pdata(arizona, &config); 268 ret = arizona_micsupp_of_get_pdata(arizona, &config,
269 desc);
268 if (ret < 0) 270 if (ret < 0)
269 return ret; 271 return ret;
270 } 272 }
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index cd87c0c37034..e225711bb8bc 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -828,7 +828,7 @@ static void print_constraints(struct regulator_dev *rdev)
828 if (!count) 828 if (!count)
829 sprintf(buf, "no parameters"); 829 sprintf(buf, "no parameters");
830 830
831 rdev_info(rdev, "%s\n", buf); 831 rdev_dbg(rdev, "%s\n", buf);
832 832
833 if ((constraints->min_uV != constraints->max_uV) && 833 if ((constraints->min_uV != constraints->max_uV) &&
834 !(constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) 834 !(constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE))
@@ -1713,6 +1713,8 @@ static void regulator_ena_gpio_free(struct regulator_dev *rdev)
1713 gpiod_put(pin->gpiod); 1713 gpiod_put(pin->gpiod);
1714 list_del(&pin->list); 1714 list_del(&pin->list);
1715 kfree(pin); 1715 kfree(pin);
1716 rdev->ena_pin = NULL;
1717 return;
1716 } else { 1718 } else {
1717 pin->request_count--; 1719 pin->request_count--;
1718 } 1720 }
@@ -1976,9 +1978,18 @@ static int _regulator_disable(struct regulator_dev *rdev)
1976 1978
1977 /* we are last user */ 1979 /* we are last user */
1978 if (_regulator_can_change_status(rdev)) { 1980 if (_regulator_can_change_status(rdev)) {
1981 ret = _notifier_call_chain(rdev,
1982 REGULATOR_EVENT_PRE_DISABLE,
1983 NULL);
1984 if (ret & NOTIFY_STOP_MASK)
1985 return -EINVAL;
1986
1979 ret = _regulator_do_disable(rdev); 1987 ret = _regulator_do_disable(rdev);
1980 if (ret < 0) { 1988 if (ret < 0) {
1981 rdev_err(rdev, "failed to disable\n"); 1989 rdev_err(rdev, "failed to disable\n");
1990 _notifier_call_chain(rdev,
1991 REGULATOR_EVENT_ABORT_DISABLE,
1992 NULL);
1982 return ret; 1993 return ret;
1983 } 1994 }
1984 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, 1995 _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE,
@@ -2035,9 +2046,16 @@ static int _regulator_force_disable(struct regulator_dev *rdev)
2035{ 2046{
2036 int ret = 0; 2047 int ret = 0;
2037 2048
2049 ret = _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
2050 REGULATOR_EVENT_PRE_DISABLE, NULL);
2051 if (ret & NOTIFY_STOP_MASK)
2052 return -EINVAL;
2053
2038 ret = _regulator_do_disable(rdev); 2054 ret = _regulator_do_disable(rdev);
2039 if (ret < 0) { 2055 if (ret < 0) {
2040 rdev_err(rdev, "failed to force disable\n"); 2056 rdev_err(rdev, "failed to force disable\n");
2057 _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE |
2058 REGULATOR_EVENT_ABORT_DISABLE, NULL);
2041 return ret; 2059 return ret;
2042 } 2060 }
2043 2061
@@ -3650,7 +3668,8 @@ regulator_register(const struct regulator_desc *regulator_desc,
3650 3668
3651 dev_set_drvdata(&rdev->dev, rdev); 3669 dev_set_drvdata(&rdev->dev, rdev);
3652 3670
3653 if (config->ena_gpio && gpio_is_valid(config->ena_gpio)) { 3671 if ((config->ena_gpio || config->ena_gpio_initialized) &&
3672 gpio_is_valid(config->ena_gpio)) {
3654 ret = regulator_ena_gpio_request(rdev, config); 3673 ret = regulator_ena_gpio_request(rdev, config);
3655 if (ret != 0) { 3674 if (ret != 0) {
3656 rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", 3675 rdev_err(rdev, "Failed to request enable GPIO%d: %d\n",
diff --git a/drivers/regulator/da9052-regulator.c b/drivers/regulator/da9052-regulator.c
index 00033625a09c..3945f1006d23 100644
--- a/drivers/regulator/da9052-regulator.c
+++ b/drivers/regulator/da9052-regulator.c
@@ -436,7 +436,8 @@ static int da9052_regulator_probe(struct platform_device *pdev)
436 if (!of_node_cmp(np->name, 436 if (!of_node_cmp(np->name,
437 regulator->info->reg_desc.name)) { 437 regulator->info->reg_desc.name)) {
438 config.init_data = of_get_regulator_init_data( 438 config.init_data = of_get_regulator_init_data(
439 &pdev->dev, np); 439 &pdev->dev, np,
440 &regulator->info->reg_desc);
440 config.of_node = np; 441 config.of_node = np;
441 break; 442 break;
442 } 443 }
diff --git a/drivers/regulator/da9063-regulator.c b/drivers/regulator/da9063-regulator.c
index 7c9461d13313..37dd42759ca9 100644
--- a/drivers/regulator/da9063-regulator.c
+++ b/drivers/regulator/da9063-regulator.c
@@ -867,17 +867,14 @@ static int da9063_regulator_probe(struct platform_device *pdev)
867 return irq; 867 return irq;
868 } 868 }
869 869
870 regulators->irq_ldo_lim = regmap_irq_get_virq(da9063->regmap_irq, irq); 870 ret = request_threaded_irq(irq,
871 if (regulators->irq_ldo_lim >= 0) { 871 NULL, da9063_ldo_lim_event,
872 ret = request_threaded_irq(regulators->irq_ldo_lim, 872 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
873 NULL, da9063_ldo_lim_event, 873 "LDO_LIM", regulators);
874 IRQF_TRIGGER_LOW | IRQF_ONESHOT, 874 if (ret) {
875 "LDO_LIM", regulators); 875 dev_err(&pdev->dev,
876 if (ret) { 876 "Failed to request LDO_LIM IRQ.\n");
877 dev_err(&pdev->dev, 877 regulators->irq_ldo_lim = -ENXIO;
878 "Failed to request LDO_LIM IRQ.\n");
879 regulators->irq_ldo_lim = -ENXIO;
880 }
881 } 878 }
882 879
883 return 0; 880 return 0;
diff --git a/drivers/regulator/da9210-regulator.c b/drivers/regulator/da9210-regulator.c
index 7a320dd11c46..bc6100103f7f 100644
--- a/drivers/regulator/da9210-regulator.c
+++ b/drivers/regulator/da9210-regulator.c
@@ -147,7 +147,7 @@ static int da9210_i2c_probe(struct i2c_client *i2c,
147 147
148 config.dev = &i2c->dev; 148 config.dev = &i2c->dev;
149 config.init_data = pdata ? &pdata->da9210_constraints : 149 config.init_data = pdata ? &pdata->da9210_constraints :
150 of_get_regulator_init_data(dev, dev->of_node); 150 of_get_regulator_init_data(dev, dev->of_node, &da9210_reg);
151 config.driver_data = chip; 151 config.driver_data = chip;
152 config.regmap = chip->regmap; 152 config.regmap = chip->regmap;
153 config.of_node = dev->of_node; 153 config.of_node = dev->of_node;
diff --git a/drivers/regulator/dummy.c b/drivers/regulator/dummy.c
index 2436db9e2ca3..7aef9e4c6fbf 100644
--- a/drivers/regulator/dummy.c
+++ b/drivers/regulator/dummy.c
@@ -33,7 +33,7 @@ static struct regulator_init_data dummy_initdata = {
33 33
34static struct regulator_ops dummy_ops; 34static struct regulator_ops dummy_ops;
35 35
36static struct regulator_desc dummy_desc = { 36static const struct regulator_desc dummy_desc = {
37 .name = "regulator-dummy", 37 .name = "regulator-dummy",
38 .id = -1, 38 .id = -1,
39 .type = REGULATOR_VOLTAGE, 39 .type = REGULATOR_VOLTAGE,
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index f8e4257aef92..6c43ab2d5121 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -302,7 +302,8 @@ static struct regmap_config fan53555_regmap_config = {
302}; 302};
303 303
304static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev, 304static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
305 struct device_node *np) 305 struct device_node *np,
306 const struct regulator_desc *desc)
306{ 307{
307 struct fan53555_platform_data *pdata; 308 struct fan53555_platform_data *pdata;
308 int ret; 309 int ret;
@@ -312,7 +313,7 @@ static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
312 if (!pdata) 313 if (!pdata)
313 return NULL; 314 return NULL;
314 315
315 pdata->regulator = of_get_regulator_init_data(dev, np); 316 pdata->regulator = of_get_regulator_init_data(dev, np, desc);
316 317
317 ret = of_property_read_u32(np, "fcs,suspend-voltage-selector", 318 ret = of_property_read_u32(np, "fcs,suspend-voltage-selector",
318 &tmp); 319 &tmp);
@@ -347,20 +348,20 @@ static int fan53555_regulator_probe(struct i2c_client *client,
347 unsigned int val; 348 unsigned int val;
348 int ret; 349 int ret;
349 350
351 di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info),
352 GFP_KERNEL);
353 if (!di)
354 return -ENOMEM;
355
350 pdata = dev_get_platdata(&client->dev); 356 pdata = dev_get_platdata(&client->dev);
351 if (!pdata) 357 if (!pdata)
352 pdata = fan53555_parse_dt(&client->dev, np); 358 pdata = fan53555_parse_dt(&client->dev, np, &di->desc);
353 359
354 if (!pdata || !pdata->regulator) { 360 if (!pdata || !pdata->regulator) {
355 dev_err(&client->dev, "Platform data not found!\n"); 361 dev_err(&client->dev, "Platform data not found!\n");
356 return -ENODEV; 362 return -ENODEV;
357 } 363 }
358 364
359 di = devm_kzalloc(&client->dev, sizeof(struct fan53555_device_info),
360 GFP_KERNEL);
361 if (!di)
362 return -ENOMEM;
363
364 di->regulator = pdata->regulator; 365 di->regulator = pdata->regulator;
365 if (client->dev.of_node) { 366 if (client->dev.of_node) {
366 const struct of_device_id *match; 367 const struct of_device_id *match;
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 354105eff1f8..d21da27c0eb6 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -40,13 +40,15 @@ struct fixed_voltage_data {
40/** 40/**
41 * of_get_fixed_voltage_config - extract fixed_voltage_config structure info 41 * of_get_fixed_voltage_config - extract fixed_voltage_config structure info
42 * @dev: device requesting for fixed_voltage_config 42 * @dev: device requesting for fixed_voltage_config
43 * @desc: regulator description
43 * 44 *
44 * Populates fixed_voltage_config structure by extracting data from device 45 * Populates fixed_voltage_config structure by extracting data from device
45 * tree node, returns a pointer to the populated structure of NULL if memory 46 * tree node, returns a pointer to the populated structure of NULL if memory
46 * alloc fails. 47 * alloc fails.
47 */ 48 */
48static struct fixed_voltage_config * 49static struct fixed_voltage_config *
49of_get_fixed_voltage_config(struct device *dev) 50of_get_fixed_voltage_config(struct device *dev,
51 const struct regulator_desc *desc)
50{ 52{
51 struct fixed_voltage_config *config; 53 struct fixed_voltage_config *config;
52 struct device_node *np = dev->of_node; 54 struct device_node *np = dev->of_node;
@@ -57,7 +59,7 @@ of_get_fixed_voltage_config(struct device *dev)
57 if (!config) 59 if (!config)
58 return ERR_PTR(-ENOMEM); 60 return ERR_PTR(-ENOMEM);
59 61
60 config->init_data = of_get_regulator_init_data(dev, dev->of_node); 62 config->init_data = of_get_regulator_init_data(dev, dev->of_node, desc);
61 if (!config->init_data) 63 if (!config->init_data)
62 return ERR_PTR(-EINVAL); 64 return ERR_PTR(-EINVAL);
63 65
@@ -112,8 +114,14 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
112 struct regulator_config cfg = { }; 114 struct regulator_config cfg = { };
113 int ret; 115 int ret;
114 116
117 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data),
118 GFP_KERNEL);
119 if (!drvdata)
120 return -ENOMEM;
121
115 if (pdev->dev.of_node) { 122 if (pdev->dev.of_node) {
116 config = of_get_fixed_voltage_config(&pdev->dev); 123 config = of_get_fixed_voltage_config(&pdev->dev,
124 &drvdata->desc);
117 if (IS_ERR(config)) 125 if (IS_ERR(config))
118 return PTR_ERR(config); 126 return PTR_ERR(config);
119 } else { 127 } else {
@@ -123,11 +131,6 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
123 if (!config) 131 if (!config)
124 return -ENOMEM; 132 return -ENOMEM;
125 133
126 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data),
127 GFP_KERNEL);
128 if (!drvdata)
129 return -ENOMEM;
130
131 drvdata->desc.name = devm_kstrdup(&pdev->dev, 134 drvdata->desc.name = devm_kstrdup(&pdev->dev,
132 config->supply_name, 135 config->supply_name,
133 GFP_KERNEL); 136 GFP_KERNEL);
@@ -157,8 +160,11 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
157 160
158 drvdata->desc.fixed_uV = config->microvolts; 161 drvdata->desc.fixed_uV = config->microvolts;
159 162
160 if (config->gpio >= 0) 163 if (gpio_is_valid(config->gpio)) {
161 cfg.ena_gpio = config->gpio; 164 cfg.ena_gpio = config->gpio;
165 if (pdev->dev.of_node)
166 cfg.ena_gpio_initialized = true;
167 }
162 cfg.ena_gpio_invert = !config->enable_high; 168 cfg.ena_gpio_invert = !config->enable_high;
163 if (config->enabled_at_boot) { 169 if (config->enabled_at_boot) {
164 if (config->enable_high) 170 if (config->enable_high)
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
index 989b23b377c0..c888a9a9482c 100644
--- a/drivers/regulator/gpio-regulator.c
+++ b/drivers/regulator/gpio-regulator.c
@@ -133,7 +133,8 @@ static struct regulator_ops gpio_regulator_voltage_ops = {
133}; 133};
134 134
135static struct gpio_regulator_config * 135static struct gpio_regulator_config *
136of_get_gpio_regulator_config(struct device *dev, struct device_node *np) 136of_get_gpio_regulator_config(struct device *dev, struct device_node *np,
137 const struct regulator_desc *desc)
137{ 138{
138 struct gpio_regulator_config *config; 139 struct gpio_regulator_config *config;
139 const char *regtype; 140 const char *regtype;
@@ -146,7 +147,7 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np)
146 if (!config) 147 if (!config)
147 return ERR_PTR(-ENOMEM); 148 return ERR_PTR(-ENOMEM);
148 149
149 config->init_data = of_get_regulator_init_data(dev, np); 150 config->init_data = of_get_regulator_init_data(dev, np, desc);
150 if (!config->init_data) 151 if (!config->init_data)
151 return ERR_PTR(-EINVAL); 152 return ERR_PTR(-EINVAL);
152 153
@@ -162,34 +163,41 @@ of_get_gpio_regulator_config(struct device *dev, struct device_node *np)
162 163
163 config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); 164 config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0);
164 165
165 /* Fetch GPIOs. */ 166 /* Fetch GPIOs. - optional property*/
166 config->nr_gpios = of_gpio_count(np); 167 ret = of_gpio_count(np);
167 168 if ((ret < 0) && (ret != -ENOENT))
168 config->gpios = devm_kzalloc(dev, 169 return ERR_PTR(ret);
169 sizeof(struct gpio) * config->nr_gpios, 170
170 GFP_KERNEL); 171 if (ret > 0) {
171 if (!config->gpios) 172 config->nr_gpios = ret;
172 return ERR_PTR(-ENOMEM); 173 config->gpios = devm_kzalloc(dev,
173 174 sizeof(struct gpio) * config->nr_gpios,
174 proplen = of_property_count_u32_elems(np, "gpios-states"); 175 GFP_KERNEL);
175 /* optional property */ 176 if (!config->gpios)
176 if (proplen < 0) 177 return ERR_PTR(-ENOMEM);
177 proplen = 0; 178
178 179 proplen = of_property_count_u32_elems(np, "gpios-states");
179 if (proplen > 0 && proplen != config->nr_gpios) { 180 /* optional property */
180 dev_warn(dev, "gpios <-> gpios-states mismatch\n"); 181 if (proplen < 0)
181 proplen = 0; 182 proplen = 0;
182 } 183
184 if (proplen > 0 && proplen != config->nr_gpios) {
185 dev_warn(dev, "gpios <-> gpios-states mismatch\n");
186 proplen = 0;
187 }
183 188
184 for (i = 0; i < config->nr_gpios; i++) { 189 for (i = 0; i < config->nr_gpios; i++) {
185 gpio = of_get_named_gpio(np, "gpios", i); 190 gpio = of_get_named_gpio(np, "gpios", i);
186 if (gpio < 0) 191 if (gpio < 0)
187 break; 192 break;
188 config->gpios[i].gpio = gpio; 193 config->gpios[i].gpio = gpio;
189 if (proplen > 0) { 194 if (proplen > 0) {
190 of_property_read_u32_index(np, "gpios-states", i, &ret); 195 of_property_read_u32_index(np, "gpios-states",
191 if (ret) 196 i, &ret);
192 config->gpios[i].flags = GPIOF_OUT_INIT_HIGH; 197 if (ret)
198 config->gpios[i].flags =
199 GPIOF_OUT_INIT_HIGH;
200 }
193 } 201 }
194 } 202 }
195 203
@@ -243,17 +251,18 @@ static int gpio_regulator_probe(struct platform_device *pdev)
243 struct regulator_config cfg = { }; 251 struct regulator_config cfg = { };
244 int ptr, ret, state; 252 int ptr, ret, state;
245 253
246 if (np) {
247 config = of_get_gpio_regulator_config(&pdev->dev, np);
248 if (IS_ERR(config))
249 return PTR_ERR(config);
250 }
251
252 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), 254 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data),
253 GFP_KERNEL); 255 GFP_KERNEL);
254 if (drvdata == NULL) 256 if (drvdata == NULL)
255 return -ENOMEM; 257 return -ENOMEM;
256 258
259 if (np) {
260 config = of_get_gpio_regulator_config(&pdev->dev, np,
261 &drvdata->desc);
262 if (IS_ERR(config))
263 return PTR_ERR(config);
264 }
265
257 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); 266 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL);
258 if (drvdata->desc.name == NULL) { 267 if (drvdata->desc.name == NULL) {
259 dev_err(&pdev->dev, "Failed to allocate supply name\n"); 268 dev_err(&pdev->dev, "Failed to allocate supply name\n");
@@ -261,13 +270,23 @@ static int gpio_regulator_probe(struct platform_device *pdev)
261 goto err; 270 goto err;
262 } 271 }
263 272
264 drvdata->gpios = kmemdup(config->gpios, 273 if (config->nr_gpios != 0) {
265 config->nr_gpios * sizeof(struct gpio), 274 drvdata->gpios = kmemdup(config->gpios,
266 GFP_KERNEL); 275 config->nr_gpios * sizeof(struct gpio),
267 if (drvdata->gpios == NULL) { 276 GFP_KERNEL);
268 dev_err(&pdev->dev, "Failed to allocate gpio data\n"); 277 if (drvdata->gpios == NULL) {
269 ret = -ENOMEM; 278 dev_err(&pdev->dev, "Failed to allocate gpio data\n");
270 goto err_name; 279 ret = -ENOMEM;
280 goto err_name;
281 }
282
283 drvdata->nr_gpios = config->nr_gpios;
284 ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios);
285 if (ret) {
286 dev_err(&pdev->dev,
287 "Could not obtain regulator setting GPIOs: %d\n", ret);
288 goto err_memstate;
289 }
271 } 290 }
272 291
273 drvdata->states = kmemdup(config->states, 292 drvdata->states = kmemdup(config->states,
@@ -301,14 +320,6 @@ static int gpio_regulator_probe(struct platform_device *pdev)
301 goto err_memgpio; 320 goto err_memgpio;
302 } 321 }
303 322
304 drvdata->nr_gpios = config->nr_gpios;
305 ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios);
306 if (ret) {
307 dev_err(&pdev->dev,
308 "Could not obtain regulator setting GPIOs: %d\n", ret);
309 goto err_memstate;
310 }
311
312 /* build initial state from gpio init data. */ 323 /* build initial state from gpio init data. */
313 state = 0; 324 state = 0;
314 for (ptr = 0; ptr < drvdata->nr_gpios; ptr++) { 325 for (ptr = 0; ptr < drvdata->nr_gpios; ptr++) {
@@ -322,8 +333,10 @@ static int gpio_regulator_probe(struct platform_device *pdev)
322 cfg.driver_data = drvdata; 333 cfg.driver_data = drvdata;
323 cfg.of_node = np; 334 cfg.of_node = np;
324 335
325 if (config->enable_gpio >= 0) 336 if (gpio_is_valid(config->enable_gpio)) {
326 cfg.ena_gpio = config->enable_gpio; 337 cfg.ena_gpio = config->enable_gpio;
338 cfg.ena_gpio_initialized = true;
339 }
327 cfg.ena_gpio_invert = !config->enable_high; 340 cfg.ena_gpio_invert = !config->enable_high;
328 if (config->enabled_at_boot) { 341 if (config->enabled_at_boot) {
329 if (config->enable_high) 342 if (config->enable_high)
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c
index 86db310d5304..d2a8c64cae42 100644
--- a/drivers/regulator/max1586.c
+++ b/drivers/regulator/max1586.c
@@ -163,7 +163,7 @@ static int of_get_max1586_platform_data(struct device *dev,
163 struct max1586_platform_data *pdata) 163 struct max1586_platform_data *pdata)
164{ 164{
165 struct max1586_subdev_data *sub; 165 struct max1586_subdev_data *sub;
166 struct of_regulator_match rmatch[ARRAY_SIZE(max1586_reg)]; 166 struct of_regulator_match rmatch[ARRAY_SIZE(max1586_reg)] = { };
167 struct device_node *np = dev->of_node; 167 struct device_node *np = dev->of_node;
168 int i, matched; 168 int i, matched;
169 169
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c
index ef1af2debbd2..871b96bcd2d0 100644
--- a/drivers/regulator/max77686.c
+++ b/drivers/regulator/max77686.c
@@ -45,6 +45,23 @@
45#define MAX77686_DVS_MINUV 600000 45#define MAX77686_DVS_MINUV 600000
46#define MAX77686_DVS_UVSTEP 12500 46#define MAX77686_DVS_UVSTEP 12500
47 47
48/*
49 * Values used for configuring LDOs and bucks.
50 * Forcing low power mode: LDO1, 3-5, 9, 13, 17-26
51 */
52#define MAX77686_LDO_LOWPOWER 0x1
53/*
54 * On/off controlled by PWRREQ:
55 * - LDO2, 6-8, 10-12, 14-16
56 * - buck[1234]
57 */
58#define MAX77686_OFF_PWRREQ 0x1
59/* Low power mode controlled by PWRREQ: All LDOs */
60#define MAX77686_LDO_LOWPOWER_PWRREQ 0x2
61/* Forcing low power mode: buck[234] */
62#define MAX77686_BUCK_LOWPOWER 0x2
63#define MAX77686_NORMAL 0x3
64
48#define MAX77686_OPMODE_SHIFT 6 65#define MAX77686_OPMODE_SHIFT 6
49#define MAX77686_OPMODE_BUCK234_SHIFT 4 66#define MAX77686_OPMODE_BUCK234_SHIFT 4
50#define MAX77686_OPMODE_MASK 0x3 67#define MAX77686_OPMODE_MASK 0x3
@@ -65,23 +82,36 @@ enum max77686_ramp_rate {
65}; 82};
66 83
67struct max77686_data { 84struct max77686_data {
85 /* Array indexed by regulator id */
68 unsigned int opmode[MAX77686_REGULATORS]; 86 unsigned int opmode[MAX77686_REGULATORS];
69}; 87};
70 88
71/* Some BUCKS supports Normal[ON/OFF] mode during suspend */ 89static unsigned int max77686_get_opmode_shift(int id)
72static int max77686_buck_set_suspend_disable(struct regulator_dev *rdev)
73{ 90{
74 unsigned int val; 91 switch (id) {
92 case MAX77686_BUCK1:
93 case MAX77686_BUCK5 ... MAX77686_BUCK9:
94 return 0;
95 case MAX77686_BUCK2 ... MAX77686_BUCK4:
96 return MAX77686_OPMODE_BUCK234_SHIFT;
97 default:
98 /* all LDOs */
99 return MAX77686_OPMODE_SHIFT;
100 }
101}
102
103/* Some BUCKs and LDOs supports Normal[ON/OFF] mode during suspend */
104static int max77686_set_suspend_disable(struct regulator_dev *rdev)
105{
106 unsigned int val, shift;
75 struct max77686_data *max77686 = rdev_get_drvdata(rdev); 107 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
76 int ret, id = rdev_get_id(rdev); 108 int ret, id = rdev_get_id(rdev);
77 109
78 if (id == MAX77686_BUCK1) 110 shift = max77686_get_opmode_shift(id);
79 val = 0x1; 111 val = MAX77686_OFF_PWRREQ;
80 else
81 val = 0x1 << MAX77686_OPMODE_BUCK234_SHIFT;
82 112
83 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 113 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
84 rdev->desc->enable_mask, val); 114 rdev->desc->enable_mask, val << shift);
85 if (ret) 115 if (ret)
86 return ret; 116 return ret;
87 117
@@ -103,10 +133,10 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev,
103 133
104 switch (mode) { 134 switch (mode) {
105 case REGULATOR_MODE_IDLE: /* ON in LP Mode */ 135 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
106 val = 0x2 << MAX77686_OPMODE_SHIFT; 136 val = MAX77686_LDO_LOWPOWER_PWRREQ;
107 break; 137 break;
108 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ 138 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
109 val = 0x3 << MAX77686_OPMODE_SHIFT; 139 val = MAX77686_NORMAL;
110 break; 140 break;
111 default: 141 default:
112 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", 142 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
@@ -115,7 +145,8 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev,
115 } 145 }
116 146
117 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 147 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
118 rdev->desc->enable_mask, val); 148 rdev->desc->enable_mask,
149 val << MAX77686_OPMODE_SHIFT);
119 if (ret) 150 if (ret)
120 return ret; 151 return ret;
121 152
@@ -133,13 +164,13 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
133 164
134 switch (mode) { 165 switch (mode) {
135 case REGULATOR_MODE_STANDBY: /* switch off */ 166 case REGULATOR_MODE_STANDBY: /* switch off */
136 val = 0x1 << MAX77686_OPMODE_SHIFT; 167 val = MAX77686_OFF_PWRREQ;
137 break; 168 break;
138 case REGULATOR_MODE_IDLE: /* ON in LP Mode */ 169 case REGULATOR_MODE_IDLE: /* ON in LP Mode */
139 val = 0x2 << MAX77686_OPMODE_SHIFT; 170 val = MAX77686_LDO_LOWPOWER_PWRREQ;
140 break; 171 break;
141 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ 172 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */
142 val = 0x3 << MAX77686_OPMODE_SHIFT; 173 val = MAX77686_NORMAL;
143 break; 174 break;
144 default: 175 default:
145 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", 176 pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n",
@@ -148,7 +179,8 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
148 } 179 }
149 180
150 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 181 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
151 rdev->desc->enable_mask, val); 182 rdev->desc->enable_mask,
183 val << MAX77686_OPMODE_SHIFT);
152 if (ret) 184 if (ret)
153 return ret; 185 return ret;
154 186
@@ -159,10 +191,17 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev,
159static int max77686_enable(struct regulator_dev *rdev) 191static int max77686_enable(struct regulator_dev *rdev)
160{ 192{
161 struct max77686_data *max77686 = rdev_get_drvdata(rdev); 193 struct max77686_data *max77686 = rdev_get_drvdata(rdev);
194 unsigned int shift;
195 int id = rdev_get_id(rdev);
196
197 shift = max77686_get_opmode_shift(id);
198
199 if (max77686->opmode[id] == MAX77686_OFF_PWRREQ)
200 max77686->opmode[id] = MAX77686_NORMAL;
162 201
163 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 202 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
164 rdev->desc->enable_mask, 203 rdev->desc->enable_mask,
165 max77686->opmode[rdev_get_id(rdev)]); 204 max77686->opmode[id] << shift);
166} 205}
167 206
168static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) 207static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
@@ -212,6 +251,7 @@ static struct regulator_ops max77686_ldo_ops = {
212 .set_voltage_sel = regulator_set_voltage_sel_regmap, 251 .set_voltage_sel = regulator_set_voltage_sel_regmap,
213 .set_voltage_time_sel = regulator_set_voltage_time_sel, 252 .set_voltage_time_sel = regulator_set_voltage_time_sel,
214 .set_suspend_mode = max77686_ldo_set_suspend_mode, 253 .set_suspend_mode = max77686_ldo_set_suspend_mode,
254 .set_suspend_disable = max77686_set_suspend_disable,
215}; 255};
216 256
217static struct regulator_ops max77686_buck1_ops = { 257static struct regulator_ops max77686_buck1_ops = {
@@ -223,7 +263,7 @@ static struct regulator_ops max77686_buck1_ops = {
223 .get_voltage_sel = regulator_get_voltage_sel_regmap, 263 .get_voltage_sel = regulator_get_voltage_sel_regmap,
224 .set_voltage_sel = regulator_set_voltage_sel_regmap, 264 .set_voltage_sel = regulator_set_voltage_sel_regmap,
225 .set_voltage_time_sel = regulator_set_voltage_time_sel, 265 .set_voltage_time_sel = regulator_set_voltage_time_sel,
226 .set_suspend_disable = max77686_buck_set_suspend_disable, 266 .set_suspend_disable = max77686_set_suspend_disable,
227}; 267};
228 268
229static struct regulator_ops max77686_buck_dvs_ops = { 269static struct regulator_ops max77686_buck_dvs_ops = {
@@ -236,11 +276,13 @@ static struct regulator_ops max77686_buck_dvs_ops = {
236 .set_voltage_sel = regulator_set_voltage_sel_regmap, 276 .set_voltage_sel = regulator_set_voltage_sel_regmap,
237 .set_voltage_time_sel = regulator_set_voltage_time_sel, 277 .set_voltage_time_sel = regulator_set_voltage_time_sel,
238 .set_ramp_delay = max77686_set_ramp_delay, 278 .set_ramp_delay = max77686_set_ramp_delay,
239 .set_suspend_disable = max77686_buck_set_suspend_disable, 279 .set_suspend_disable = max77686_set_suspend_disable,
240}; 280};
241 281
242#define regulator_desc_ldo(num) { \ 282#define regulator_desc_ldo(num) { \
243 .name = "LDO"#num, \ 283 .name = "LDO"#num, \
284 .of_match = of_match_ptr("LDO"#num), \
285 .regulators_node = of_match_ptr("voltage-regulators"), \
244 .id = MAX77686_LDO##num, \ 286 .id = MAX77686_LDO##num, \
245 .ops = &max77686_ops, \ 287 .ops = &max77686_ops, \
246 .type = REGULATOR_VOLTAGE, \ 288 .type = REGULATOR_VOLTAGE, \
@@ -257,6 +299,8 @@ static struct regulator_ops max77686_buck_dvs_ops = {
257} 299}
258#define regulator_desc_lpm_ldo(num) { \ 300#define regulator_desc_lpm_ldo(num) { \
259 .name = "LDO"#num, \ 301 .name = "LDO"#num, \
302 .of_match = of_match_ptr("LDO"#num), \
303 .regulators_node = of_match_ptr("voltage-regulators"), \
260 .id = MAX77686_LDO##num, \ 304 .id = MAX77686_LDO##num, \
261 .ops = &max77686_ldo_ops, \ 305 .ops = &max77686_ldo_ops, \
262 .type = REGULATOR_VOLTAGE, \ 306 .type = REGULATOR_VOLTAGE, \
@@ -273,6 +317,8 @@ static struct regulator_ops max77686_buck_dvs_ops = {
273} 317}
274#define regulator_desc_ldo_low(num) { \ 318#define regulator_desc_ldo_low(num) { \
275 .name = "LDO"#num, \ 319 .name = "LDO"#num, \
320 .of_match = of_match_ptr("LDO"#num), \
321 .regulators_node = of_match_ptr("voltage-regulators"), \
276 .id = MAX77686_LDO##num, \ 322 .id = MAX77686_LDO##num, \
277 .ops = &max77686_ldo_ops, \ 323 .ops = &max77686_ldo_ops, \
278 .type = REGULATOR_VOLTAGE, \ 324 .type = REGULATOR_VOLTAGE, \
@@ -289,6 +335,8 @@ static struct regulator_ops max77686_buck_dvs_ops = {
289} 335}
290#define regulator_desc_ldo1_low(num) { \ 336#define regulator_desc_ldo1_low(num) { \
291 .name = "LDO"#num, \ 337 .name = "LDO"#num, \
338 .of_match = of_match_ptr("LDO"#num), \
339 .regulators_node = of_match_ptr("voltage-regulators"), \
292 .id = MAX77686_LDO##num, \ 340 .id = MAX77686_LDO##num, \
293 .ops = &max77686_ops, \ 341 .ops = &max77686_ops, \
294 .type = REGULATOR_VOLTAGE, \ 342 .type = REGULATOR_VOLTAGE, \
@@ -305,6 +353,8 @@ static struct regulator_ops max77686_buck_dvs_ops = {
305} 353}
306#define regulator_desc_buck(num) { \ 354#define regulator_desc_buck(num) { \
307 .name = "BUCK"#num, \ 355 .name = "BUCK"#num, \
356 .of_match = of_match_ptr("BUCK"#num), \
357 .regulators_node = of_match_ptr("voltage-regulators"), \
308 .id = MAX77686_BUCK##num, \ 358 .id = MAX77686_BUCK##num, \
309 .ops = &max77686_ops, \ 359 .ops = &max77686_ops, \
310 .type = REGULATOR_VOLTAGE, \ 360 .type = REGULATOR_VOLTAGE, \
@@ -320,6 +370,8 @@ static struct regulator_ops max77686_buck_dvs_ops = {
320} 370}
321#define regulator_desc_buck1(num) { \ 371#define regulator_desc_buck1(num) { \
322 .name = "BUCK"#num, \ 372 .name = "BUCK"#num, \
373 .of_match = of_match_ptr("BUCK"#num), \
374 .regulators_node = of_match_ptr("voltage-regulators"), \
323 .id = MAX77686_BUCK##num, \ 375 .id = MAX77686_BUCK##num, \
324 .ops = &max77686_buck1_ops, \ 376 .ops = &max77686_buck1_ops, \
325 .type = REGULATOR_VOLTAGE, \ 377 .type = REGULATOR_VOLTAGE, \
@@ -335,6 +387,8 @@ static struct regulator_ops max77686_buck_dvs_ops = {
335} 387}
336#define regulator_desc_buck_dvs(num) { \ 388#define regulator_desc_buck_dvs(num) { \
337 .name = "BUCK"#num, \ 389 .name = "BUCK"#num, \
390 .of_match = of_match_ptr("BUCK"#num), \
391 .regulators_node = of_match_ptr("voltage-regulators"), \
338 .id = MAX77686_BUCK##num, \ 392 .id = MAX77686_BUCK##num, \
339 .ops = &max77686_buck_dvs_ops, \ 393 .ops = &max77686_buck_dvs_ops, \
340 .type = REGULATOR_VOLTAGE, \ 394 .type = REGULATOR_VOLTAGE, \
@@ -350,7 +404,7 @@ static struct regulator_ops max77686_buck_dvs_ops = {
350 << MAX77686_OPMODE_BUCK234_SHIFT, \ 404 << MAX77686_OPMODE_BUCK234_SHIFT, \
351} 405}
352 406
353static struct regulator_desc regulators[] = { 407static const struct regulator_desc regulators[] = {
354 regulator_desc_ldo1_low(1), 408 regulator_desc_ldo1_low(1),
355 regulator_desc_ldo_low(2), 409 regulator_desc_ldo_low(2),
356 regulator_desc_ldo(3), 410 regulator_desc_ldo(3),
@@ -388,103 +442,37 @@ static struct regulator_desc regulators[] = {
388 regulator_desc_buck(9), 442 regulator_desc_buck(9),
389}; 443};
390 444
391#ifdef CONFIG_OF
392static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev,
393 struct max77686_platform_data *pdata)
394{
395 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
396 struct device_node *pmic_np, *regulators_np;
397 struct max77686_regulator_data *rdata;
398 struct of_regulator_match rmatch;
399 unsigned int i;
400
401 pmic_np = iodev->dev->of_node;
402 regulators_np = of_get_child_by_name(pmic_np, "voltage-regulators");
403 if (!regulators_np) {
404 dev_err(&pdev->dev, "could not find regulators sub-node\n");
405 return -EINVAL;
406 }
407
408 pdata->num_regulators = ARRAY_SIZE(regulators);
409 rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) *
410 pdata->num_regulators, GFP_KERNEL);
411 if (!rdata) {
412 of_node_put(regulators_np);
413 return -ENOMEM;
414 }
415
416 for (i = 0; i < pdata->num_regulators; i++) {
417 rmatch.name = regulators[i].name;
418 rmatch.init_data = NULL;
419 rmatch.of_node = NULL;
420 of_regulator_match(&pdev->dev, regulators_np, &rmatch, 1);
421 rdata[i].initdata = rmatch.init_data;
422 rdata[i].of_node = rmatch.of_node;
423 }
424
425 pdata->regulators = rdata;
426 of_node_put(regulators_np);
427
428 return 0;
429}
430#else
431static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev,
432 struct max77686_platform_data *pdata)
433{
434 return 0;
435}
436#endif /* CONFIG_OF */
437
438static int max77686_pmic_probe(struct platform_device *pdev) 445static int max77686_pmic_probe(struct platform_device *pdev)
439{ 446{
440 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); 447 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
441 struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev);
442 struct max77686_data *max77686; 448 struct max77686_data *max77686;
443 int i, ret = 0; 449 int i;
444 struct regulator_config config = { }; 450 struct regulator_config config = { };
445 451
446 dev_dbg(&pdev->dev, "%s\n", __func__); 452 dev_dbg(&pdev->dev, "%s\n", __func__);
447 453
448 if (!pdata) {
449 dev_err(&pdev->dev, "no platform data found for regulator\n");
450 return -ENODEV;
451 }
452
453 if (iodev->dev->of_node) {
454 ret = max77686_pmic_dt_parse_pdata(pdev, pdata);
455 if (ret)
456 return ret;
457 }
458
459 if (pdata->num_regulators != MAX77686_REGULATORS) {
460 dev_err(&pdev->dev,
461 "Invalid initial data for regulator's initialiation\n");
462 return -EINVAL;
463 }
464
465 max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data), 454 max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
466 GFP_KERNEL); 455 GFP_KERNEL);
467 if (!max77686) 456 if (!max77686)
468 return -ENOMEM; 457 return -ENOMEM;
469 458
470 config.dev = &pdev->dev; 459 config.dev = iodev->dev;
471 config.regmap = iodev->regmap; 460 config.regmap = iodev->regmap;
472 config.driver_data = max77686; 461 config.driver_data = max77686;
473 platform_set_drvdata(pdev, max77686); 462 platform_set_drvdata(pdev, max77686);
474 463
475 for (i = 0; i < MAX77686_REGULATORS; i++) { 464 for (i = 0; i < MAX77686_REGULATORS; i++) {
476 struct regulator_dev *rdev; 465 struct regulator_dev *rdev;
466 int id = regulators[i].id;
477 467
478 config.init_data = pdata->regulators[i].initdata; 468 max77686->opmode[id] = MAX77686_NORMAL;
479 config.of_node = pdata->regulators[i].of_node;
480
481 max77686->opmode[i] = regulators[i].enable_mask;
482 rdev = devm_regulator_register(&pdev->dev, 469 rdev = devm_regulator_register(&pdev->dev,
483 &regulators[i], &config); 470 &regulators[i], &config);
484 if (IS_ERR(rdev)) { 471 if (IS_ERR(rdev)) {
472 int ret = PTR_ERR(rdev);
485 dev_err(&pdev->dev, 473 dev_err(&pdev->dev,
486 "regulator init failed for %d\n", i); 474 "regulator init failed for %d: %d\n", i, ret);
487 return PTR_ERR(rdev); 475 return ret;
488 } 476 }
489 } 477 }
490 478
diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693.c
index c67ff05fc1dd..7b9755a6c3b5 100644
--- a/drivers/regulator/max77693.c
+++ b/drivers/regulator/max77693.c
@@ -139,7 +139,7 @@ static struct regulator_ops max77693_charger_ops = {
139 .enable_mask = SAFEOUT_CTRL_ENSAFEOUT##_num##_MASK , \ 139 .enable_mask = SAFEOUT_CTRL_ENSAFEOUT##_num##_MASK , \
140} 140}
141 141
142static struct regulator_desc regulators[] = { 142static const struct regulator_desc regulators[] = {
143 regulator_desc_esafeout(1), 143 regulator_desc_esafeout(1),
144 regulator_desc_esafeout(2), 144 regulator_desc_esafeout(2),
145 { 145 {
@@ -227,7 +227,7 @@ static int max77693_pmic_probe(struct platform_device *pdev)
227 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent); 227 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent);
228 struct max77693_regulator_data *rdata = NULL; 228 struct max77693_regulator_data *rdata = NULL;
229 int num_rdata, i; 229 int num_rdata, i;
230 struct regulator_config config; 230 struct regulator_config config = { };
231 231
232 num_rdata = max77693_pmic_init_rdata(&pdev->dev, &rdata); 232 num_rdata = max77693_pmic_init_rdata(&pdev->dev, &rdata);
233 if (!rdata || num_rdata <= 0) { 233 if (!rdata || num_rdata <= 0) {
diff --git a/drivers/regulator/max77802.c b/drivers/regulator/max77802.c
index d89792b084e9..0766615c60bc 100644
--- a/drivers/regulator/max77802.c
+++ b/drivers/regulator/max77802.c
@@ -33,6 +33,7 @@
33#include <linux/regulator/of_regulator.h> 33#include <linux/regulator/of_regulator.h>
34#include <linux/mfd/max77686.h> 34#include <linux/mfd/max77686.h>
35#include <linux/mfd/max77686-private.h> 35#include <linux/mfd/max77686-private.h>
36#include <dt-bindings/regulator/maxim,max77802.h>
36 37
37/* Default ramp delay in case it is not manually set */ 38/* Default ramp delay in case it is not manually set */
38#define MAX77802_RAMP_DELAY 100000 /* uV/us */ 39#define MAX77802_RAMP_DELAY 100000 /* uV/us */
@@ -49,6 +50,10 @@
49#define MAX77802_RAMP_RATE_MASK_4BIT 0xF0 50#define MAX77802_RAMP_RATE_MASK_4BIT 0xF0
50#define MAX77802_RAMP_RATE_SHIFT_4BIT 4 51#define MAX77802_RAMP_RATE_SHIFT_4BIT 4
51 52
53#define MAX77802_STATUS_OFF 0x0
54#define MAX77802_OFF_PWRREQ 0x1
55#define MAX77802_LP_PWRREQ 0x2
56
52/* MAX77802 has two register formats: 2-bit and 4-bit */ 57/* MAX77802 has two register formats: 2-bit and 4-bit */
53static const unsigned int ramp_table_77802_2bit[] = { 58static const unsigned int ramp_table_77802_2bit[] = {
54 12500, 59 12500,
@@ -65,9 +70,16 @@ static unsigned int ramp_table_77802_4bit[] = {
65}; 70};
66 71
67struct max77802_regulator_prv { 72struct max77802_regulator_prv {
73 /* Array indexed by regulator id */
68 unsigned int opmode[MAX77802_REG_MAX]; 74 unsigned int opmode[MAX77802_REG_MAX];
69}; 75};
70 76
77static inline unsigned int max77802_map_mode(unsigned int mode)
78{
79 return mode == MAX77802_OPMODE_NORMAL ?
80 REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY;
81}
82
71static int max77802_get_opmode_shift(int id) 83static int max77802_get_opmode_shift(int id)
72{ 84{
73 if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 && 85 if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 &&
@@ -83,17 +95,16 @@ static int max77802_get_opmode_shift(int id)
83 return -EINVAL; 95 return -EINVAL;
84} 96}
85 97
86/* 98/**
87 * Some BUCKS supports Normal[ON/OFF] mode during suspend 99 * max77802_set_suspend_disable - Disable the regulator during system suspend
100 * @rdev: regulator to mark as disabled
88 * 101 *
89 * BUCK 1, 6, 2-4, 5, 7-10 (all) 102 * All regulators expect LDO 1, 3, 20 and 21 support OFF by PWRREQ.
90 * 103 * Configure the regulator so the PMIC will turn it OFF during system suspend.
91 * The other mode (0x02) will make PWRREQ switch between normal
92 * and low power.
93 */ 104 */
94static int max77802_buck_set_suspend_disable(struct regulator_dev *rdev) 105static int max77802_set_suspend_disable(struct regulator_dev *rdev)
95{ 106{
96 unsigned int val = MAX77802_OPMODE_STANDBY; 107 unsigned int val = MAX77802_OFF_PWRREQ;
97 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); 108 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
98 int id = rdev_get_id(rdev); 109 int id = rdev_get_id(rdev);
99 int shift = max77802_get_opmode_shift(id); 110 int shift = max77802_get_opmode_shift(id);
@@ -104,14 +115,11 @@ static int max77802_buck_set_suspend_disable(struct regulator_dev *rdev)
104} 115}
105 116
106/* 117/*
107 * Some LDOs supports LPM-ON/OFF/Normal-ON mode during suspend state 118 * Some LDOs support Low Power Mode while the system is running.
108 * (Enable Control Logic1 by PWRREQ)
109 *
110 * LDOs 2, 4-19, 22-35.
111 * 119 *
120 * LDOs 1, 3, 20, 21.
112 */ 121 */
113static int max77802_ldo_set_suspend_mode_logic1(struct regulator_dev *rdev, 122static int max77802_set_mode(struct regulator_dev *rdev, unsigned int mode)
114 unsigned int mode)
115{ 123{
116 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); 124 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
117 int id = rdev_get_id(rdev); 125 int id = rdev_get_id(rdev);
@@ -119,14 +127,11 @@ static int max77802_ldo_set_suspend_mode_logic1(struct regulator_dev *rdev,
119 int shift = max77802_get_opmode_shift(id); 127 int shift = max77802_get_opmode_shift(id);
120 128
121 switch (mode) { 129 switch (mode) {
122 case REGULATOR_MODE_IDLE: /* ON in LP Mode */ 130 case REGULATOR_MODE_STANDBY:
123 val = MAX77802_OPMODE_LP; 131 val = MAX77802_OPMODE_LP; /* ON in Low Power Mode */
124 break; 132 break;
125 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ 133 case REGULATOR_MODE_NORMAL:
126 val = MAX77802_OPMODE_NORMAL; 134 val = MAX77802_OPMODE_NORMAL; /* ON in Normal Mode */
127 break;
128 case REGULATOR_MODE_STANDBY: /* ON/OFF by PWRREQ */
129 val = MAX77802_OPMODE_STANDBY;
130 break; 135 break;
131 default: 136 default:
132 dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n", 137 dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
@@ -139,35 +144,76 @@ static int max77802_ldo_set_suspend_mode_logic1(struct regulator_dev *rdev,
139 rdev->desc->enable_mask, val << shift); 144 rdev->desc->enable_mask, val << shift);
140} 145}
141 146
142/* 147static unsigned max77802_get_mode(struct regulator_dev *rdev)
143 * Mode 1 (Output[ON/OFF] by PWRREQ) is not supported on some LDOs 148{
144 * (Enable Control Logic2 by PWRREQ) 149 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
150 int id = rdev_get_id(rdev);
151
152 return max77802_map_mode(max77802->opmode[id]);
153}
154
155/**
156 * max77802_set_suspend_mode - set regulator opmode when the system is suspended
157 * @rdev: regulator to change mode
158 * @mode: operating mode to be set
145 * 159 *
146 * LDOs 1, 20, 21, and 3, 160 * Will set the operating mode for the regulators during system suspend.
161 * This function is valid for the three different enable control logics:
147 * 162 *
163 * Enable Control Logic1 by PWRREQ (BUCK 2-4 and LDOs 2, 4-19, 22-35)
164 * Enable Control Logic2 by PWRREQ (LDOs 1, 20, 21)
165 * Enable Control Logic3 by PWRREQ (LDO 3)
166 *
167 * If setting the regulator mode fails, the function only warns but does
168 * not return an error code to avoid the regulator core to stop setting
169 * the operating mode for the remaining regulators.
148 */ 170 */
149static int max77802_ldo_set_suspend_mode_logic2(struct regulator_dev *rdev, 171static int max77802_set_suspend_mode(struct regulator_dev *rdev,
150 unsigned int mode) 172 unsigned int mode)
151{ 173{
152 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); 174 struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev);
153 int id = rdev_get_id(rdev); 175 int id = rdev_get_id(rdev);
154 unsigned int val; 176 unsigned int val;
155 int shift = max77802_get_opmode_shift(id); 177 int shift = max77802_get_opmode_shift(id);
156 178
179 /*
180 * If the regulator has been disabled for suspend
181 * then is invalid to try setting a suspend mode.
182 */
183 if (max77802->opmode[id] == MAX77802_OFF_PWRREQ) {
184 dev_warn(&rdev->dev, "%s: is disabled, mode: 0x%x not set\n",
185 rdev->desc->name, mode);
186 return 0;
187 }
188
157 switch (mode) { 189 switch (mode) {
158 case REGULATOR_MODE_IDLE: /* ON in LP Mode */ 190 case REGULATOR_MODE_STANDBY:
159 val = MAX77802_OPMODE_LP; 191 /*
160 break; 192 * If the regulator opmode is normal then enable
161 case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ 193 * ON in Low Power Mode by PWRREQ. If the mode is
162 val = MAX77802_OPMODE_NORMAL; 194 * already Low Power then no action is required.
195 */
196 if (max77802->opmode[id] == MAX77802_OPMODE_NORMAL)
197 val = MAX77802_LP_PWRREQ;
198 else
199 return 0;
163 break; 200 break;
201 case REGULATOR_MODE_NORMAL:
202 /*
203 * If the regulator operating mode is Low Power then
204 * normal is not a valid opmode in suspend. If the
205 * mode is already normal then no action is required.
206 */
207 if (max77802->opmode[id] == MAX77802_OPMODE_LP)
208 dev_warn(&rdev->dev, "%s: in Low Power: 0x%x invalid\n",
209 rdev->desc->name, mode);
210 return 0;
164 default: 211 default:
165 dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n", 212 dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n",
166 rdev->desc->name, mode); 213 rdev->desc->name, mode);
167 return -EINVAL; 214 return -EINVAL;
168 } 215 }
169 216
170 max77802->opmode[id] = val;
171 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 217 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
172 rdev->desc->enable_mask, val << shift); 218 rdev->desc->enable_mask, val << shift);
173} 219}
@@ -178,6 +224,9 @@ static int max77802_enable(struct regulator_dev *rdev)
178 int id = rdev_get_id(rdev); 224 int id = rdev_get_id(rdev);
179 int shift = max77802_get_opmode_shift(id); 225 int shift = max77802_get_opmode_shift(id);
180 226
227 if (max77802->opmode[id] == MAX77802_OFF_PWRREQ)
228 max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
229
181 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 230 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
182 rdev->desc->enable_mask, 231 rdev->desc->enable_mask,
183 max77802->opmode[id] << shift); 232 max77802->opmode[id] << shift);
@@ -247,7 +296,8 @@ static struct regulator_ops max77802_ldo_ops_logic1 = {
247 .get_voltage_sel = regulator_get_voltage_sel_regmap, 296 .get_voltage_sel = regulator_get_voltage_sel_regmap,
248 .set_voltage_sel = regulator_set_voltage_sel_regmap, 297 .set_voltage_sel = regulator_set_voltage_sel_regmap,
249 .set_voltage_time_sel = regulator_set_voltage_time_sel, 298 .set_voltage_time_sel = regulator_set_voltage_time_sel,
250 .set_suspend_mode = max77802_ldo_set_suspend_mode_logic1, 299 .set_suspend_disable = max77802_set_suspend_disable,
300 .set_suspend_mode = max77802_set_suspend_mode,
251}; 301};
252 302
253/* 303/*
@@ -262,7 +312,9 @@ static struct regulator_ops max77802_ldo_ops_logic2 = {
262 .get_voltage_sel = regulator_get_voltage_sel_regmap, 312 .get_voltage_sel = regulator_get_voltage_sel_regmap,
263 .set_voltage_sel = regulator_set_voltage_sel_regmap, 313 .set_voltage_sel = regulator_set_voltage_sel_regmap,
264 .set_voltage_time_sel = regulator_set_voltage_time_sel, 314 .set_voltage_time_sel = regulator_set_voltage_time_sel,
265 .set_suspend_mode = max77802_ldo_set_suspend_mode_logic2, 315 .set_mode = max77802_set_mode,
316 .get_mode = max77802_get_mode,
317 .set_suspend_mode = max77802_set_suspend_mode,
266}; 318};
267 319
268/* BUCKS 1, 6 */ 320/* BUCKS 1, 6 */
@@ -276,10 +328,25 @@ static struct regulator_ops max77802_buck_16_dvs_ops = {
276 .set_voltage_sel = regulator_set_voltage_sel_regmap, 328 .set_voltage_sel = regulator_set_voltage_sel_regmap,
277 .set_voltage_time_sel = regulator_set_voltage_time_sel, 329 .set_voltage_time_sel = regulator_set_voltage_time_sel,
278 .set_ramp_delay = max77802_set_ramp_delay_4bit, 330 .set_ramp_delay = max77802_set_ramp_delay_4bit,
279 .set_suspend_disable = max77802_buck_set_suspend_disable, 331 .set_suspend_disable = max77802_set_suspend_disable,
280}; 332};
281 333
282/* BUCKs 2-4, 5, 7-10 */ 334/* BUCKs 2-4 */
335static struct regulator_ops max77802_buck_234_ops = {
336 .list_voltage = regulator_list_voltage_linear,
337 .map_voltage = regulator_map_voltage_linear,
338 .is_enabled = regulator_is_enabled_regmap,
339 .enable = max77802_enable,
340 .disable = regulator_disable_regmap,
341 .get_voltage_sel = regulator_get_voltage_sel_regmap,
342 .set_voltage_sel = regulator_set_voltage_sel_regmap,
343 .set_voltage_time_sel = regulator_set_voltage_time_sel,
344 .set_ramp_delay = max77802_set_ramp_delay_2bit,
345 .set_suspend_disable = max77802_set_suspend_disable,
346 .set_suspend_mode = max77802_set_suspend_mode,
347};
348
349/* BUCKs 5, 7-10 */
283static struct regulator_ops max77802_buck_dvs_ops = { 350static struct regulator_ops max77802_buck_dvs_ops = {
284 .list_voltage = regulator_list_voltage_linear, 351 .list_voltage = regulator_list_voltage_linear,
285 .map_voltage = regulator_map_voltage_linear, 352 .map_voltage = regulator_map_voltage_linear,
@@ -290,12 +357,14 @@ static struct regulator_ops max77802_buck_dvs_ops = {
290 .set_voltage_sel = regulator_set_voltage_sel_regmap, 357 .set_voltage_sel = regulator_set_voltage_sel_regmap,
291 .set_voltage_time_sel = regulator_set_voltage_time_sel, 358 .set_voltage_time_sel = regulator_set_voltage_time_sel,
292 .set_ramp_delay = max77802_set_ramp_delay_2bit, 359 .set_ramp_delay = max77802_set_ramp_delay_2bit,
293 .set_suspend_disable = max77802_buck_set_suspend_disable, 360 .set_suspend_disable = max77802_set_suspend_disable,
294}; 361};
295 362
296/* LDOs 3-7, 9-14, 18-26, 28, 29, 32-34 */ 363/* LDOs 3-7, 9-14, 18-26, 28, 29, 32-34 */
297#define regulator_77802_desc_p_ldo(num, supply, log) { \ 364#define regulator_77802_desc_p_ldo(num, supply, log) { \
298 .name = "LDO"#num, \ 365 .name = "LDO"#num, \
366 .of_match = of_match_ptr("LDO"#num), \
367 .regulators_node = of_match_ptr("regulators"), \
299 .id = MAX77802_LDO##num, \ 368 .id = MAX77802_LDO##num, \
300 .supply_name = "inl"#supply, \ 369 .supply_name = "inl"#supply, \
301 .ops = &max77802_ldo_ops_logic##log, \ 370 .ops = &max77802_ldo_ops_logic##log, \
@@ -309,11 +378,14 @@ static struct regulator_ops max77802_buck_dvs_ops = {
309 .vsel_mask = MAX77802_VSEL_MASK, \ 378 .vsel_mask = MAX77802_VSEL_MASK, \
310 .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \ 379 .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \
311 .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \ 380 .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \
381 .of_map_mode = max77802_map_mode, \
312} 382}
313 383
314/* LDOs 1, 2, 8, 15, 17, 27, 30, 35 */ 384/* LDOs 1, 2, 8, 15, 17, 27, 30, 35 */
315#define regulator_77802_desc_n_ldo(num, supply, log) { \ 385#define regulator_77802_desc_n_ldo(num, supply, log) { \
316 .name = "LDO"#num, \ 386 .name = "LDO"#num, \
387 .of_match = of_match_ptr("LDO"#num), \
388 .regulators_node = of_match_ptr("regulators"), \
317 .id = MAX77802_LDO##num, \ 389 .id = MAX77802_LDO##num, \
318 .supply_name = "inl"#supply, \ 390 .supply_name = "inl"#supply, \
319 .ops = &max77802_ldo_ops_logic##log, \ 391 .ops = &max77802_ldo_ops_logic##log, \
@@ -327,11 +399,14 @@ static struct regulator_ops max77802_buck_dvs_ops = {
327 .vsel_mask = MAX77802_VSEL_MASK, \ 399 .vsel_mask = MAX77802_VSEL_MASK, \
328 .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \ 400 .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \
329 .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \ 401 .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \
402 .of_map_mode = max77802_map_mode, \
330} 403}
331 404
332/* BUCKs 1, 6 */ 405/* BUCKs 1, 6 */
333#define regulator_77802_desc_16_buck(num) { \ 406#define regulator_77802_desc_16_buck(num) { \
334 .name = "BUCK"#num, \ 407 .name = "BUCK"#num, \
408 .of_match = of_match_ptr("BUCK"#num), \
409 .regulators_node = of_match_ptr("regulators"), \
335 .id = MAX77802_BUCK##num, \ 410 .id = MAX77802_BUCK##num, \
336 .supply_name = "inb"#num, \ 411 .supply_name = "inb"#num, \
337 .ops = &max77802_buck_16_dvs_ops, \ 412 .ops = &max77802_buck_16_dvs_ops, \
@@ -345,14 +420,17 @@ static struct regulator_ops max77802_buck_dvs_ops = {
345 .vsel_mask = MAX77802_DVS_VSEL_MASK, \ 420 .vsel_mask = MAX77802_DVS_VSEL_MASK, \
346 .enable_reg = MAX77802_REG_BUCK ## num ## CTRL, \ 421 .enable_reg = MAX77802_REG_BUCK ## num ## CTRL, \
347 .enable_mask = MAX77802_OPMODE_MASK, \ 422 .enable_mask = MAX77802_OPMODE_MASK, \
423 .of_map_mode = max77802_map_mode, \
348} 424}
349 425
350/* BUCKS 2-4 */ 426/* BUCKS 2-4 */
351#define regulator_77802_desc_234_buck(num) { \ 427#define regulator_77802_desc_234_buck(num) { \
352 .name = "BUCK"#num, \ 428 .name = "BUCK"#num, \
429 .of_match = of_match_ptr("BUCK"#num), \
430 .regulators_node = of_match_ptr("regulators"), \
353 .id = MAX77802_BUCK##num, \ 431 .id = MAX77802_BUCK##num, \
354 .supply_name = "inb"#num, \ 432 .supply_name = "inb"#num, \
355 .ops = &max77802_buck_dvs_ops, \ 433 .ops = &max77802_buck_234_ops, \
356 .type = REGULATOR_VOLTAGE, \ 434 .type = REGULATOR_VOLTAGE, \
357 .owner = THIS_MODULE, \ 435 .owner = THIS_MODULE, \
358 .min_uV = 600000, \ 436 .min_uV = 600000, \
@@ -364,11 +442,14 @@ static struct regulator_ops max77802_buck_dvs_ops = {
364 .enable_reg = MAX77802_REG_BUCK ## num ## CTRL1, \ 442 .enable_reg = MAX77802_REG_BUCK ## num ## CTRL1, \
365 .enable_mask = MAX77802_OPMODE_MASK << \ 443 .enable_mask = MAX77802_OPMODE_MASK << \
366 MAX77802_OPMODE_BUCK234_SHIFT, \ 444 MAX77802_OPMODE_BUCK234_SHIFT, \
445 .of_map_mode = max77802_map_mode, \
367} 446}
368 447
369/* BUCK 5 */ 448/* BUCK 5 */
370#define regulator_77802_desc_buck5(num) { \ 449#define regulator_77802_desc_buck5(num) { \
371 .name = "BUCK"#num, \ 450 .name = "BUCK"#num, \
451 .of_match = of_match_ptr("BUCK"#num), \
452 .regulators_node = of_match_ptr("regulators"), \
372 .id = MAX77802_BUCK##num, \ 453 .id = MAX77802_BUCK##num, \
373 .supply_name = "inb"#num, \ 454 .supply_name = "inb"#num, \
374 .ops = &max77802_buck_dvs_ops, \ 455 .ops = &max77802_buck_dvs_ops, \
@@ -382,11 +463,14 @@ static struct regulator_ops max77802_buck_dvs_ops = {
382 .vsel_mask = MAX77802_VSEL_MASK, \ 463 .vsel_mask = MAX77802_VSEL_MASK, \
383 .enable_reg = MAX77802_REG_BUCK5CTRL, \ 464 .enable_reg = MAX77802_REG_BUCK5CTRL, \
384 .enable_mask = MAX77802_OPMODE_MASK, \ 465 .enable_mask = MAX77802_OPMODE_MASK, \
466 .of_map_mode = max77802_map_mode, \
385} 467}
386 468
387/* BUCKs 7-10 */ 469/* BUCKs 7-10 */
388#define regulator_77802_desc_buck7_10(num) { \ 470#define regulator_77802_desc_buck7_10(num) { \
389 .name = "BUCK"#num, \ 471 .name = "BUCK"#num, \
472 .of_match = of_match_ptr("BUCK"#num), \
473 .regulators_node = of_match_ptr("regulators"), \
390 .id = MAX77802_BUCK##num, \ 474 .id = MAX77802_BUCK##num, \
391 .supply_name = "inb"#num, \ 475 .supply_name = "inb"#num, \
392 .ops = &max77802_buck_dvs_ops, \ 476 .ops = &max77802_buck_dvs_ops, \
@@ -400,9 +484,10 @@ static struct regulator_ops max77802_buck_dvs_ops = {
400 .vsel_mask = MAX77802_VSEL_MASK, \ 484 .vsel_mask = MAX77802_VSEL_MASK, \
401 .enable_reg = MAX77802_REG_BUCK7CTRL + (num - 7) * 3, \ 485 .enable_reg = MAX77802_REG_BUCK7CTRL + (num - 7) * 3, \
402 .enable_mask = MAX77802_OPMODE_MASK, \ 486 .enable_mask = MAX77802_OPMODE_MASK, \
487 .of_map_mode = max77802_map_mode, \
403} 488}
404 489
405static struct regulator_desc regulators[] = { 490static const struct regulator_desc regulators[] = {
406 regulator_77802_desc_16_buck(1), 491 regulator_77802_desc_16_buck(1),
407 regulator_77802_desc_234_buck(2), 492 regulator_77802_desc_234_buck(2),
408 regulator_77802_desc_234_buck(3), 493 regulator_77802_desc_234_buck(3),
@@ -447,85 +532,19 @@ static struct regulator_desc regulators[] = {
447 regulator_77802_desc_n_ldo(35, 2, 1), 532 regulator_77802_desc_n_ldo(35, 2, 1),
448}; 533};
449 534
450#ifdef CONFIG_OF
451static int max77802_pmic_dt_parse_pdata(struct platform_device *pdev,
452 struct max77686_platform_data *pdata)
453{
454 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
455 struct device_node *pmic_np, *regulators_np;
456 struct max77686_regulator_data *rdata;
457 struct of_regulator_match rmatch;
458 unsigned int i;
459
460 pmic_np = iodev->dev->of_node;
461 regulators_np = of_get_child_by_name(pmic_np, "regulators");
462 if (!regulators_np) {
463 dev_err(&pdev->dev, "could not find regulators sub-node\n");
464 return -EINVAL;
465 }
466
467 pdata->num_regulators = ARRAY_SIZE(regulators);
468 rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) *
469 pdata->num_regulators, GFP_KERNEL);
470 if (!rdata) {
471 of_node_put(regulators_np);
472 return -ENOMEM;
473 }
474
475 for (i = 0; i < pdata->num_regulators; i++) {
476 rmatch.name = regulators[i].name;
477 rmatch.init_data = NULL;
478 rmatch.of_node = NULL;
479 if (of_regulator_match(&pdev->dev, regulators_np, &rmatch,
480 1) != 1) {
481 dev_warn(&pdev->dev, "No matching regulator for '%s'\n",
482 rmatch.name);
483 continue;
484 }
485 rdata[i].initdata = rmatch.init_data;
486 rdata[i].of_node = rmatch.of_node;
487 rdata[i].id = regulators[i].id;
488 }
489
490 pdata->regulators = rdata;
491 of_node_put(regulators_np);
492
493 return 0;
494}
495#else
496static int max77802_pmic_dt_parse_pdata(struct platform_device *pdev,
497 struct max77686_platform_data *pdata)
498{
499 return 0;
500}
501#endif /* CONFIG_OF */
502
503static int max77802_pmic_probe(struct platform_device *pdev) 535static int max77802_pmic_probe(struct platform_device *pdev)
504{ 536{
505 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); 537 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
506 struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev);
507 struct max77802_regulator_prv *max77802; 538 struct max77802_regulator_prv *max77802;
508 int i, ret = 0, val; 539 int i, val;
509 struct regulator_config config = { }; 540 struct regulator_config config = { };
510 541
511 /* This is allocated by the MFD driver */
512 if (!pdata) {
513 dev_err(&pdev->dev, "no platform data found for regulator\n");
514 return -ENODEV;
515 }
516
517 max77802 = devm_kzalloc(&pdev->dev, 542 max77802 = devm_kzalloc(&pdev->dev,
518 sizeof(struct max77802_regulator_prv), 543 sizeof(struct max77802_regulator_prv),
519 GFP_KERNEL); 544 GFP_KERNEL);
520 if (!max77802) 545 if (!max77802)
521 return -ENOMEM; 546 return -ENOMEM;
522 547
523 if (iodev->dev->of_node) {
524 ret = max77802_pmic_dt_parse_pdata(pdev, pdata);
525 if (ret)
526 return ret;
527 }
528
529 config.dev = iodev->dev; 548 config.dev = iodev->dev;
530 config.regmap = iodev->regmap; 549 config.regmap = iodev->regmap;
531 config.driver_data = max77802; 550 config.driver_data = max77802;
@@ -533,21 +552,25 @@ static int max77802_pmic_probe(struct platform_device *pdev)
533 552
534 for (i = 0; i < MAX77802_REG_MAX; i++) { 553 for (i = 0; i < MAX77802_REG_MAX; i++) {
535 struct regulator_dev *rdev; 554 struct regulator_dev *rdev;
536 int id = pdata->regulators[i].id; 555 int id = regulators[i].id;
537 int shift = max77802_get_opmode_shift(id); 556 int shift = max77802_get_opmode_shift(id);
538 557 int ret;
539 config.init_data = pdata->regulators[i].initdata;
540 config.of_node = pdata->regulators[i].of_node;
541 558
542 ret = regmap_read(iodev->regmap, regulators[i].enable_reg, &val); 559 ret = regmap_read(iodev->regmap, regulators[i].enable_reg, &val);
543 val = val >> shift & MAX77802_OPMODE_MASK; 560 if (ret < 0) {
561 dev_warn(&pdev->dev,
562 "cannot read current mode for %d\n", i);
563 val = MAX77802_OPMODE_NORMAL;
564 } else {
565 val = val >> shift & MAX77802_OPMODE_MASK;
566 }
544 567
545 /* 568 /*
546 * If the regulator is disabled and the system warm rebooted, 569 * If the regulator is disabled and the system warm rebooted,
547 * the hardware reports OFF as the regulator operating mode. 570 * the hardware reports OFF as the regulator operating mode.
548 * Default to operating mode NORMAL in that case. 571 * Default to operating mode NORMAL in that case.
549 */ 572 */
550 if (val == MAX77802_OPMODE_OFF) 573 if (val == MAX77802_STATUS_OFF)
551 max77802->opmode[id] = MAX77802_OPMODE_NORMAL; 574 max77802->opmode[id] = MAX77802_OPMODE_NORMAL;
552 else 575 else
553 max77802->opmode[id] = val; 576 max77802->opmode[id] = val;
@@ -555,9 +578,10 @@ static int max77802_pmic_probe(struct platform_device *pdev)
555 rdev = devm_regulator_register(&pdev->dev, 578 rdev = devm_regulator_register(&pdev->dev,
556 &regulators[i], &config); 579 &regulators[i], &config);
557 if (IS_ERR(rdev)) { 580 if (IS_ERR(rdev)) {
581 ret = PTR_ERR(rdev);
558 dev_err(&pdev->dev, 582 dev_err(&pdev->dev,
559 "regulator init failed for %d\n", i); 583 "regulator init failed for %d: %d\n", i, ret);
560 return PTR_ERR(rdev); 584 return ret;
561 } 585 }
562 } 586 }
563 587
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
index 2fc411188794..7eee2ca18541 100644
--- a/drivers/regulator/max8660.c
+++ b/drivers/regulator/max8660.c
@@ -335,7 +335,7 @@ static int max8660_pdata_from_dt(struct device *dev,
335 int matched, i; 335 int matched, i;
336 struct device_node *np; 336 struct device_node *np;
337 struct max8660_subdev_data *sub; 337 struct max8660_subdev_data *sub;
338 struct of_regulator_match rmatch[ARRAY_SIZE(max8660_reg)]; 338 struct of_regulator_match rmatch[ARRAY_SIZE(max8660_reg)] = { };
339 339
340 np = of_get_child_by_name(dev->of_node, "regulators"); 340 np = of_get_child_by_name(dev->of_node, "regulators");
341 if (!np) { 341 if (!np) {
diff --git a/drivers/regulator/max8952.c b/drivers/regulator/max8952.c
index f7f9efcfedb7..1af8f4a2ab86 100644
--- a/drivers/regulator/max8952.c
+++ b/drivers/regulator/max8952.c
@@ -174,7 +174,7 @@ static struct max8952_platform_data *max8952_parse_dt(struct device *dev)
174 if (of_property_read_u32(np, "max8952,ramp-speed", &pd->ramp_speed)) 174 if (of_property_read_u32(np, "max8952,ramp-speed", &pd->ramp_speed))
175 dev_warn(dev, "max8952,ramp-speed property not specified, defaulting to 32mV/us\n"); 175 dev_warn(dev, "max8952,ramp-speed property not specified, defaulting to 32mV/us\n");
176 176
177 pd->reg_data = of_get_regulator_init_data(dev, np); 177 pd->reg_data = of_get_regulator_init_data(dev, np, &regulator);
178 if (!pd->reg_data) { 178 if (!pd->reg_data) {
179 dev_err(dev, "Failed to parse regulator init data\n"); 179 dev_err(dev, "Failed to parse regulator init data\n");
180 return NULL; 180 return NULL;
@@ -225,6 +225,8 @@ static int max8952_pmic_probe(struct i2c_client *client,
225 config.of_node = client->dev.of_node; 225 config.of_node = client->dev.of_node;
226 226
227 config.ena_gpio = pdata->gpio_en; 227 config.ena_gpio = pdata->gpio_en;
228 if (client->dev.of_node)
229 config.ena_gpio_initialized = true;
228 if (pdata->reg_data->constraints.boot_on) 230 if (pdata->reg_data->constraints.boot_on)
229 config.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH; 231 config.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
230 232
diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
index dbedf1768db0..c3d55c2db593 100644
--- a/drivers/regulator/max8973-regulator.c
+++ b/drivers/regulator/max8973-regulator.c
@@ -458,7 +458,8 @@ static int max8973_probe(struct i2c_client *client,
458 458
459 config.dev = &client->dev; 459 config.dev = &client->dev;
460 config.init_data = pdata ? pdata->reg_init_data : 460 config.init_data = pdata ? pdata->reg_init_data :
461 of_get_regulator_init_data(&client->dev, client->dev.of_node); 461 of_get_regulator_init_data(&client->dev, client->dev.of_node,
462 &max->desc);
462 config.driver_data = max; 463 config.driver_data = max;
463 config.of_node = client->dev.of_node; 464 config.of_node = client->dev.of_node;
464 config.regmap = max->regmap; 465 config.regmap = max->regmap;
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index 9c31e215a521..726fde1d883e 100644
--- a/drivers/regulator/max8997.c
+++ b/drivers/regulator/max8997.c
@@ -953,7 +953,8 @@ static int max8997_pmic_dt_parse_pdata(struct platform_device *pdev,
953 953
954 rdata->id = i; 954 rdata->id = i;
955 rdata->initdata = of_get_regulator_init_data(&pdev->dev, 955 rdata->initdata = of_get_regulator_init_data(&pdev->dev,
956 reg_np); 956 reg_np,
957 &regulators[i]);
957 rdata->reg_node = reg_np; 958 rdata->reg_node = reg_np;
958 rdata++; 959 rdata++;
959 } 960 }
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index 961091b46557..59e34a05a4a2 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -686,8 +686,9 @@ static int max8998_pmic_dt_parse_pdata(struct max8998_dev *iodev,
686 continue; 686 continue;
687 687
688 rdata->id = regulators[i].id; 688 rdata->id = regulators[i].id;
689 rdata->initdata = of_get_regulator_init_data( 689 rdata->initdata = of_get_regulator_init_data(iodev->dev,
690 iodev->dev, reg_np); 690 reg_np,
691 &regulators[i]);
691 rdata->reg_node = reg_np; 692 rdata->reg_node = reg_np;
692 ++rdata; 693 ++rdata;
693 } 694 }
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c
index afba024953e1..0281c31ae2ed 100644
--- a/drivers/regulator/mc13xxx-regulator-core.c
+++ b/drivers/regulator/mc13xxx-regulator-core.c
@@ -194,7 +194,8 @@ struct mc13xxx_regulator_init_data *mc13xxx_parse_regulators_dt(
194 regulators[i].desc.name)) { 194 regulators[i].desc.name)) {
195 p->id = i; 195 p->id = i;
196 p->init_data = of_get_regulator_init_data( 196 p->init_data = of_get_regulator_init_data(
197 &pdev->dev, child); 197 &pdev->dev, child,
198 &regulators[i].desc);
198 p->node = child; 199 p->node = child;
199 p++; 200 p++;
200 201
diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c
index 7a51814abdc5..91eaaf010524 100644
--- a/drivers/regulator/of_regulator.c
+++ b/drivers/regulator/of_regulator.c
@@ -19,12 +19,20 @@
19 19
20#include "internal.h" 20#include "internal.h"
21 21
22static const char *const regulator_states[PM_SUSPEND_MAX + 1] = {
23 [PM_SUSPEND_MEM] = "regulator-state-mem",
24 [PM_SUSPEND_MAX] = "regulator-state-disk",
25};
26
22static void of_get_regulation_constraints(struct device_node *np, 27static void of_get_regulation_constraints(struct device_node *np,
23 struct regulator_init_data **init_data) 28 struct regulator_init_data **init_data,
29 const struct regulator_desc *desc)
24{ 30{
25 const __be32 *min_uV, *max_uV; 31 const __be32 *min_uV, *max_uV;
26 struct regulation_constraints *constraints = &(*init_data)->constraints; 32 struct regulation_constraints *constraints = &(*init_data)->constraints;
27 int ret; 33 struct regulator_state *suspend_state;
34 struct device_node *suspend_np;
35 int ret, i;
28 u32 pval; 36 u32 pval;
29 37
30 constraints->name = of_get_property(np, "regulator-name", NULL); 38 constraints->name = of_get_property(np, "regulator-name", NULL);
@@ -73,18 +81,84 @@ static void of_get_regulation_constraints(struct device_node *np,
73 ret = of_property_read_u32(np, "regulator-enable-ramp-delay", &pval); 81 ret = of_property_read_u32(np, "regulator-enable-ramp-delay", &pval);
74 if (!ret) 82 if (!ret)
75 constraints->enable_time = pval; 83 constraints->enable_time = pval;
84
85 if (!of_property_read_u32(np, "regulator-initial-mode", &pval)) {
86 if (desc && desc->of_map_mode) {
87 ret = desc->of_map_mode(pval);
88 if (ret == -EINVAL)
89 pr_err("%s: invalid mode %u\n", np->name, pval);
90 else
91 constraints->initial_mode = ret;
92 } else {
93 pr_warn("%s: mapping for mode %d not defined\n",
94 np->name, pval);
95 }
96 }
97
98 for (i = 0; i < ARRAY_SIZE(regulator_states); i++) {
99 switch (i) {
100 case PM_SUSPEND_MEM:
101 suspend_state = &constraints->state_mem;
102 break;
103 case PM_SUSPEND_MAX:
104 suspend_state = &constraints->state_disk;
105 break;
106 case PM_SUSPEND_ON:
107 case PM_SUSPEND_FREEZE:
108 case PM_SUSPEND_STANDBY:
109 default:
110 continue;
111 };
112
113 suspend_np = of_get_child_by_name(np, regulator_states[i]);
114 if (!suspend_np || !suspend_state)
115 continue;
116
117 if (!of_property_read_u32(suspend_np, "regulator-mode",
118 &pval)) {
119 if (desc && desc->of_map_mode) {
120 ret = desc->of_map_mode(pval);
121 if (ret == -EINVAL)
122 pr_err("%s: invalid mode %u\n",
123 np->name, pval);
124 else
125 suspend_state->mode = ret;
126 } else {
127 pr_warn("%s: mapping for mode %d not defined\n",
128 np->name, pval);
129 }
130 }
131
132 if (of_property_read_bool(suspend_np,
133 "regulator-on-in-suspend"))
134 suspend_state->enabled = true;
135 else if (of_property_read_bool(suspend_np,
136 "regulator-off-in-suspend"))
137 suspend_state->disabled = true;
138
139 if (!of_property_read_u32(suspend_np,
140 "regulator-suspend-microvolt", &pval))
141 suspend_state->uV = pval;
142
143 of_node_put(suspend_np);
144 suspend_state = NULL;
145 suspend_np = NULL;
146 }
76} 147}
77 148
78/** 149/**
79 * of_get_regulator_init_data - extract regulator_init_data structure info 150 * of_get_regulator_init_data - extract regulator_init_data structure info
80 * @dev: device requesting for regulator_init_data 151 * @dev: device requesting for regulator_init_data
152 * @node: regulator device node
153 * @desc: regulator description
81 * 154 *
82 * Populates regulator_init_data structure by extracting data from device 155 * Populates regulator_init_data structure by extracting data from device
83 * tree node, returns a pointer to the populated struture or NULL if memory 156 * tree node, returns a pointer to the populated struture or NULL if memory
84 * alloc fails. 157 * alloc fails.
85 */ 158 */
86struct regulator_init_data *of_get_regulator_init_data(struct device *dev, 159struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
87 struct device_node *node) 160 struct device_node *node,
161 const struct regulator_desc *desc)
88{ 162{
89 struct regulator_init_data *init_data; 163 struct regulator_init_data *init_data;
90 164
@@ -95,7 +169,7 @@ struct regulator_init_data *of_get_regulator_init_data(struct device *dev,
95 if (!init_data) 169 if (!init_data)
96 return NULL; /* Out of memory? */ 170 return NULL; /* Out of memory? */
97 171
98 of_get_regulation_constraints(node, &init_data); 172 of_get_regulation_constraints(node, &init_data, desc);
99 return init_data; 173 return init_data;
100} 174}
101EXPORT_SYMBOL_GPL(of_get_regulator_init_data); 175EXPORT_SYMBOL_GPL(of_get_regulator_init_data);
@@ -176,7 +250,8 @@ int of_regulator_match(struct device *dev, struct device_node *node,
176 continue; 250 continue;
177 251
178 match->init_data = 252 match->init_data =
179 of_get_regulator_init_data(dev, child); 253 of_get_regulator_init_data(dev, child,
254 match->desc);
180 if (!match->init_data) { 255 if (!match->init_data) {
181 dev_err(dev, 256 dev_err(dev,
182 "failed to parse DT for regulator %s\n", 257 "failed to parse DT for regulator %s\n",
@@ -211,7 +286,8 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
211 search = dev->of_node; 286 search = dev->of_node;
212 287
213 if (!search) { 288 if (!search) {
214 dev_err(dev, "Failed to find regulator container node\n"); 289 dev_dbg(dev, "Failed to find regulator container node '%s'\n",
290 desc->regulators_node);
215 return NULL; 291 return NULL;
216 } 292 }
217 293
@@ -223,7 +299,7 @@ struct regulator_init_data *regulator_of_get_init_data(struct device *dev,
223 if (strcmp(desc->of_match, name)) 299 if (strcmp(desc->of_match, name))
224 continue; 300 continue;
225 301
226 init_data = of_get_regulator_init_data(dev, child); 302 init_data = of_get_regulator_init_data(dev, child, desc);
227 if (!init_data) { 303 if (!init_data) {
228 dev_err(dev, 304 dev_err(dev,
229 "failed to parse DT for regulator %s\n", 305 "failed to parse DT for regulator %s\n",
diff --git a/drivers/regulator/pwm-regulator.c b/drivers/regulator/pwm-regulator.c
index d3f55eaea058..91f34ca3a9ac 100644
--- a/drivers/regulator/pwm-regulator.c
+++ b/drivers/regulator/pwm-regulator.c
@@ -149,7 +149,8 @@ static int pwm_regulator_probe(struct platform_device *pdev)
149 return ret; 149 return ret;
150 } 150 }
151 151
152 config.init_data = of_get_regulator_init_data(&pdev->dev, np); 152 config.init_data = of_get_regulator_init_data(&pdev->dev, np,
153 &drvdata->desc);
153 if (!config.init_data) 154 if (!config.init_data)
154 return -ENOMEM; 155 return -ENOMEM;
155 156
diff --git a/drivers/regulator/qcom_rpm-regulator.c b/drivers/regulator/qcom_rpm-regulator.c
index b55cd5b50ebe..183598b111f9 100644
--- a/drivers/regulator/qcom_rpm-regulator.c
+++ b/drivers/regulator/qcom_rpm-regulator.c
@@ -183,6 +183,13 @@ static const struct regulator_linear_range ftsmps_ranges[] = {
183 REGULATOR_LINEAR_RANGE(1500000, 64, 100, 50000), 183 REGULATOR_LINEAR_RANGE(1500000, 64, 100, 50000),
184}; 184};
185 185
186static const struct regulator_linear_range smb208_ranges[] = {
187 REGULATOR_LINEAR_RANGE( 375000, 0, 29, 12500),
188 REGULATOR_LINEAR_RANGE( 750000, 30, 89, 12500),
189 REGULATOR_LINEAR_RANGE(1500000, 90, 153, 25000),
190 REGULATOR_LINEAR_RANGE(3100000, 154, 234, 25000),
191};
192
186static const struct regulator_linear_range ncp_ranges[] = { 193static const struct regulator_linear_range ncp_ranges[] = {
187 REGULATOR_LINEAR_RANGE(1500000, 0, 31, 50000), 194 REGULATOR_LINEAR_RANGE(1500000, 0, 31, 50000),
188}; 195};
@@ -559,6 +566,16 @@ static const struct qcom_rpm_reg pm8921_switch = {
559 .parts = &rpm8960_switch_parts, 566 .parts = &rpm8960_switch_parts,
560}; 567};
561 568
569static const struct qcom_rpm_reg smb208_smps = {
570 .desc.linear_ranges = smb208_ranges,
571 .desc.n_linear_ranges = ARRAY_SIZE(smb208_ranges),
572 .desc.n_voltages = 235,
573 .desc.ops = &uV_ops,
574 .parts = &rpm8960_smps_parts,
575 .supports_force_mode_auto = false,
576 .supports_force_mode_bypass = false,
577};
578
562static const struct of_device_id rpm_of_match[] = { 579static const struct of_device_id rpm_of_match[] = {
563 { .compatible = "qcom,rpm-pm8058-pldo", .data = &pm8058_pldo }, 580 { .compatible = "qcom,rpm-pm8058-pldo", .data = &pm8058_pldo },
564 { .compatible = "qcom,rpm-pm8058-nldo", .data = &pm8058_nldo }, 581 { .compatible = "qcom,rpm-pm8058-nldo", .data = &pm8058_nldo },
@@ -578,6 +595,8 @@ static const struct of_device_id rpm_of_match[] = {
578 { .compatible = "qcom,rpm-pm8921-ftsmps", .data = &pm8921_ftsmps }, 595 { .compatible = "qcom,rpm-pm8921-ftsmps", .data = &pm8921_ftsmps },
579 { .compatible = "qcom,rpm-pm8921-ncp", .data = &pm8921_ncp }, 596 { .compatible = "qcom,rpm-pm8921-ncp", .data = &pm8921_ncp },
580 { .compatible = "qcom,rpm-pm8921-switch", .data = &pm8921_switch }, 597 { .compatible = "qcom,rpm-pm8921-switch", .data = &pm8921_switch },
598
599 { .compatible = "qcom,rpm-smb208", .data = &smb208_smps },
581 { } 600 { }
582}; 601};
583MODULE_DEVICE_TABLE(of, rpm_of_match); 602MODULE_DEVICE_TABLE(of, rpm_of_match);
@@ -643,10 +662,6 @@ static int rpm_reg_probe(struct platform_device *pdev)
643 match = of_match_device(rpm_of_match, &pdev->dev); 662 match = of_match_device(rpm_of_match, &pdev->dev);
644 template = match->data; 663 template = match->data;
645 664
646 initdata = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node);
647 if (!initdata)
648 return -EINVAL;
649
650 vreg = devm_kmalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL); 665 vreg = devm_kmalloc(&pdev->dev, sizeof(*vreg), GFP_KERNEL);
651 if (!vreg) { 666 if (!vreg) {
652 dev_err(&pdev->dev, "failed to allocate vreg\n"); 667 dev_err(&pdev->dev, "failed to allocate vreg\n");
@@ -666,6 +681,11 @@ static int rpm_reg_probe(struct platform_device *pdev)
666 return -ENODEV; 681 return -ENODEV;
667 } 682 }
668 683
684 initdata = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node,
685 &vreg->desc);
686 if (!initdata)
687 return -EINVAL;
688
669 key = "reg"; 689 key = "reg";
670 ret = of_property_read_u32(pdev->dev.of_node, key, &val); 690 ret = of_property_read_u32(pdev->dev.of_node, key, &val);
671 if (ret) { 691 if (ret) {
diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c
index 196a5c8838c4..ea9d05eabd0a 100644
--- a/drivers/regulator/rk808-regulator.c
+++ b/drivers/regulator/rk808-regulator.c
@@ -36,6 +36,12 @@
36#define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET) 36#define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET)
37#define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET) 37#define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET)
38 38
39/* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */
40#define RK808_SLP_REG_OFFSET 1
41
42/* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */
43#define RK808_SLP_SET_OFF_REG_OFFSET 2
44
39static const int rk808_buck_config_regs[] = { 45static const int rk808_buck_config_regs[] = {
40 RK808_BUCK1_CONFIG_REG, 46 RK808_BUCK1_CONFIG_REG,
41 RK808_BUCK2_CONFIG_REG, 47 RK808_BUCK2_CONFIG_REG,
@@ -91,6 +97,43 @@ static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
91 RK808_RAMP_RATE_MASK, ramp_value); 97 RK808_RAMP_RATE_MASK, ramp_value);
92} 98}
93 99
100int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
101{
102 unsigned int reg;
103 int sel = regulator_map_voltage_linear_range(rdev, uv, uv);
104
105 if (sel < 0)
106 return -EINVAL;
107
108 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
109
110 return regmap_update_bits(rdev->regmap, reg,
111 rdev->desc->vsel_mask,
112 sel);
113}
114
115int rk808_set_suspend_enable(struct regulator_dev *rdev)
116{
117 unsigned int reg;
118
119 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
120
121 return regmap_update_bits(rdev->regmap, reg,
122 rdev->desc->enable_mask,
123 0);
124}
125
126int rk808_set_suspend_disable(struct regulator_dev *rdev)
127{
128 unsigned int reg;
129
130 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
131
132 return regmap_update_bits(rdev->regmap, reg,
133 rdev->desc->enable_mask,
134 rdev->desc->enable_mask);
135}
136
94static struct regulator_ops rk808_buck1_2_ops = { 137static struct regulator_ops rk808_buck1_2_ops = {
95 .list_voltage = regulator_list_voltage_linear_range, 138 .list_voltage = regulator_list_voltage_linear_range,
96 .map_voltage = regulator_map_voltage_linear_range, 139 .map_voltage = regulator_map_voltage_linear_range,
@@ -100,6 +143,9 @@ static struct regulator_ops rk808_buck1_2_ops = {
100 .disable = regulator_disable_regmap, 143 .disable = regulator_disable_regmap,
101 .is_enabled = regulator_is_enabled_regmap, 144 .is_enabled = regulator_is_enabled_regmap,
102 .set_ramp_delay = rk808_set_ramp_delay, 145 .set_ramp_delay = rk808_set_ramp_delay,
146 .set_suspend_voltage = rk808_set_suspend_voltage,
147 .set_suspend_enable = rk808_set_suspend_enable,
148 .set_suspend_disable = rk808_set_suspend_disable,
103}; 149};
104 150
105static struct regulator_ops rk808_reg_ops = { 151static struct regulator_ops rk808_reg_ops = {
@@ -110,12 +156,17 @@ static struct regulator_ops rk808_reg_ops = {
110 .enable = regulator_enable_regmap, 156 .enable = regulator_enable_regmap,
111 .disable = regulator_disable_regmap, 157 .disable = regulator_disable_regmap,
112 .is_enabled = regulator_is_enabled_regmap, 158 .is_enabled = regulator_is_enabled_regmap,
159 .set_suspend_voltage = rk808_set_suspend_voltage,
160 .set_suspend_enable = rk808_set_suspend_enable,
161 .set_suspend_disable = rk808_set_suspend_disable,
113}; 162};
114 163
115static struct regulator_ops rk808_switch_ops = { 164static struct regulator_ops rk808_switch_ops = {
116 .enable = regulator_enable_regmap, 165 .enable = regulator_enable_regmap,
117 .disable = regulator_disable_regmap, 166 .disable = regulator_disable_regmap,
118 .is_enabled = regulator_is_enabled_regmap, 167 .is_enabled = regulator_is_enabled_regmap,
168 .set_suspend_enable = rk808_set_suspend_enable,
169 .set_suspend_disable = rk808_set_suspend_disable,
119}; 170};
120 171
121static const struct regulator_desc rk808_reg[] = { 172static const struct regulator_desc rk808_reg[] = {
diff --git a/drivers/regulator/rn5t618-regulator.c b/drivers/regulator/rn5t618-regulator.c
index e58d79aeb393..b85ceb8ff911 100644
--- a/drivers/regulator/rn5t618-regulator.c
+++ b/drivers/regulator/rn5t618-regulator.c
@@ -31,6 +31,8 @@ static struct regulator_ops rn5t618_reg_ops = {
31#define REG(rid, ereg, emask, vreg, vmask, min, max, step) \ 31#define REG(rid, ereg, emask, vreg, vmask, min, max, step) \
32 [RN5T618_##rid] = { \ 32 [RN5T618_##rid] = { \
33 .name = #rid, \ 33 .name = #rid, \
34 .of_match = of_match_ptr(#rid), \
35 .regulators_node = of_match_ptr("regulators"), \
34 .id = RN5T618_##rid, \ 36 .id = RN5T618_##rid, \
35 .type = REGULATOR_VOLTAGE, \ 37 .type = REGULATOR_VOLTAGE, \
36 .owner = THIS_MODULE, \ 38 .owner = THIS_MODULE, \
@@ -60,60 +62,15 @@ static struct regulator_desc rn5t618_regulators[] = {
60 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000), 62 REG(LDORTC2, LDOEN2, BIT(5), LDORTC2DAC, 0x7f, 900000, 3500000, 25000),
61}; 63};
62 64
63static struct of_regulator_match rn5t618_matches[] = {
64 [RN5T618_DCDC1] = { .name = "DCDC1" },
65 [RN5T618_DCDC2] = { .name = "DCDC2" },
66 [RN5T618_DCDC3] = { .name = "DCDC3" },
67 [RN5T618_LDO1] = { .name = "LDO1" },
68 [RN5T618_LDO2] = { .name = "LDO2" },
69 [RN5T618_LDO3] = { .name = "LDO3" },
70 [RN5T618_LDO4] = { .name = "LDO4" },
71 [RN5T618_LDO5] = { .name = "LDO5" },
72 [RN5T618_LDORTC1] = { .name = "LDORTC1" },
73 [RN5T618_LDORTC2] = { .name = "LDORTC2" },
74};
75
76static int rn5t618_regulator_parse_dt(struct platform_device *pdev)
77{
78 struct device_node *np, *regulators;
79 int ret;
80
81 np = of_node_get(pdev->dev.parent->of_node);
82 if (!np)
83 return 0;
84
85 regulators = of_get_child_by_name(np, "regulators");
86 if (!regulators) {
87 dev_err(&pdev->dev, "regulators node not found\n");
88 return -EINVAL;
89 }
90
91 ret = of_regulator_match(&pdev->dev, regulators, rn5t618_matches,
92 ARRAY_SIZE(rn5t618_matches));
93 of_node_put(regulators);
94 if (ret < 0) {
95 dev_err(&pdev->dev, "error parsing regulator init data: %d\n",
96 ret);
97 }
98
99 return 0;
100}
101
102static int rn5t618_regulator_probe(struct platform_device *pdev) 65static int rn5t618_regulator_probe(struct platform_device *pdev)
103{ 66{
104 struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent); 67 struct rn5t618 *rn5t618 = dev_get_drvdata(pdev->dev.parent);
105 struct regulator_config config = { }; 68 struct regulator_config config = { };
106 struct regulator_dev *rdev; 69 struct regulator_dev *rdev;
107 int ret, i; 70 int i;
108
109 ret = rn5t618_regulator_parse_dt(pdev);
110 if (ret)
111 return ret;
112 71
113 for (i = 0; i < RN5T618_REG_NUM; i++) { 72 for (i = 0; i < RN5T618_REG_NUM; i++) {
114 config.dev = &pdev->dev; 73 config.dev = pdev->dev.parent;
115 config.init_data = rn5t618_matches[i].init_data;
116 config.of_node = rn5t618_matches[i].of_node;
117 config.regmap = rn5t618->regmap; 74 config.regmap = rn5t618->regmap;
118 75
119 rdev = devm_regulator_register(&pdev->dev, 76 rdev = devm_regulator_register(&pdev->dev,
diff --git a/drivers/regulator/rt5033-regulator.c b/drivers/regulator/rt5033-regulator.c
new file mode 100644
index 000000000000..870cc49438db
--- /dev/null
+++ b/drivers/regulator/rt5033-regulator.c
@@ -0,0 +1,123 @@
1/*
2 * Regulator driver for the Richtek RT5033
3 *
4 * Copyright (C) 2014 Samsung Electronics, Co., Ltd.
5 * Author: Beomho Seo <beomho.seo@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 bythe Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/platform_device.h>
14#include <linux/regulator/driver.h>
15#include <linux/mfd/rt5033.h>
16#include <linux/mfd/rt5033-private.h>
17#include <linux/regulator/of_regulator.h>
18
19static struct regulator_ops rt5033_safe_ldo_ops = {
20 .is_enabled = regulator_is_enabled_regmap,
21 .enable = regulator_enable_regmap,
22 .disable = regulator_disable_regmap,
23 .list_voltage = regulator_list_voltage_linear,
24};
25
26static struct regulator_ops rt5033_buck_ops = {
27 .is_enabled = regulator_is_enabled_regmap,
28 .enable = regulator_enable_regmap,
29 .disable = regulator_disable_regmap,
30 .list_voltage = regulator_list_voltage_linear,
31 .map_voltage = regulator_map_voltage_linear,
32 .get_voltage_sel = regulator_get_voltage_sel_regmap,
33 .set_voltage_sel = regulator_set_voltage_sel_regmap,
34};
35
36static const struct regulator_desc rt5033_supported_regulators[] = {
37 [RT5033_BUCK] = {
38 .name = "BUCK",
39 .id = RT5033_BUCK,
40 .ops = &rt5033_buck_ops,
41 .type = REGULATOR_VOLTAGE,
42 .owner = THIS_MODULE,
43 .n_voltages = RT5033_REGULATOR_BUCK_VOLTAGE_STEP_NUM,
44 .min_uV = RT5033_REGULATOR_BUCK_VOLTAGE_MIN,
45 .uV_step = RT5033_REGULATOR_BUCK_VOLTAGE_STEP,
46 .enable_reg = RT5033_REG_CTRL,
47 .enable_mask = RT5033_CTRL_EN_BUCK_MASK,
48 .vsel_reg = RT5033_REG_BUCK_CTRL,
49 .vsel_mask = RT5033_BUCK_CTRL_MASK,
50 },
51 [RT5033_LDO] = {
52 .name = "LDO",
53 .id = RT5033_LDO,
54 .ops = &rt5033_buck_ops,
55 .type = REGULATOR_VOLTAGE,
56 .owner = THIS_MODULE,
57 .n_voltages = RT5033_REGULATOR_LDO_VOLTAGE_STEP_NUM,
58 .min_uV = RT5033_REGULATOR_LDO_VOLTAGE_MIN,
59 .uV_step = RT5033_REGULATOR_LDO_VOLTAGE_STEP,
60 .enable_reg = RT5033_REG_CTRL,
61 .enable_mask = RT5033_CTRL_EN_LDO_MASK,
62 .vsel_reg = RT5033_REG_LDO_CTRL,
63 .vsel_mask = RT5033_LDO_CTRL_MASK,
64 },
65 [RT5033_SAFE_LDO] = {
66 .name = "SAFE_LDO",
67 .id = RT5033_SAFE_LDO,
68 .ops = &rt5033_safe_ldo_ops,
69 .type = REGULATOR_VOLTAGE,
70 .owner = THIS_MODULE,
71 .n_voltages = 1,
72 .min_uV = RT5033_REGULATOR_SAFE_LDO_VOLTAGE,
73 .enable_reg = RT5033_REG_CTRL,
74 .enable_mask = RT5033_CTRL_EN_SAFE_LDO_MASK,
75 },
76};
77
78static int rt5033_regulator_probe(struct platform_device *pdev)
79{
80 struct rt5033_dev *rt5033 = dev_get_drvdata(pdev->dev.parent);
81 int ret, i;
82 struct regulator_config config = {};
83
84 config.dev = &pdev->dev;
85 config.driver_data = rt5033;
86
87 for (i = 0; i < ARRAY_SIZE(rt5033_supported_regulators); i++) {
88 struct regulator_dev *regulator;
89
90 config.regmap = rt5033->regmap;
91
92 regulator = devm_regulator_register(&pdev->dev,
93 &rt5033_supported_regulators[i], &config);
94 if (IS_ERR(regulator)) {
95 ret = PTR_ERR(regulator);
96 dev_err(&pdev->dev,
97 "Regulator init failed %d: with error: %d\n",
98 i, ret);
99 return ret;
100 }
101 }
102
103 return 0;
104}
105
106static const struct platform_device_id rt5033_regulator_id[] = {
107 { "rt5033-regulator", },
108 { }
109};
110MODULE_DEVICE_TABLE(platform, rt5033_regulator_id);
111
112static struct platform_driver rt5033_regulator_driver = {
113 .driver = {
114 .name = "rt5033-regulator",
115 },
116 .probe = rt5033_regulator_probe,
117 .id_table = rt5033_regulator_id,
118};
119module_platform_driver(rt5033_regulator_driver);
120
121MODULE_DESCRIPTION("Richtek RT5033 Regulator driver");
122MODULE_AUTHOR("Beomho Seo <beomho.seo@samsung.com>");
123MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/s2mpa01.c b/drivers/regulator/s2mpa01.c
index 4acefa6b462e..5db4e12a7e04 100644
--- a/drivers/regulator/s2mpa01.c
+++ b/drivers/regulator/s2mpa01.c
@@ -298,7 +298,7 @@ static struct regulator_ops s2mpa01_buck_ops = {
298 .enable_mask = S2MPA01_ENABLE_MASK \ 298 .enable_mask = S2MPA01_ENABLE_MASK \
299} 299}
300 300
301static struct regulator_desc regulators[] = { 301static const struct regulator_desc regulators[] = {
302 regulator_desc_ldo(1, STEP_25_MV), 302 regulator_desc_ldo(1, STEP_25_MV),
303 regulator_desc_ldo(2, STEP_50_MV), 303 regulator_desc_ldo(2, STEP_50_MV),
304 regulator_desc_ldo(3, STEP_50_MV), 304 regulator_desc_ldo(3, STEP_50_MV),
@@ -341,7 +341,7 @@ static int s2mpa01_pmic_probe(struct platform_device *pdev)
341{ 341{
342 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent); 342 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
343 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev); 343 struct sec_platform_data *pdata = dev_get_platdata(iodev->dev);
344 struct of_regulator_match rdata[S2MPA01_REGULATOR_MAX]; 344 struct of_regulator_match rdata[S2MPA01_REGULATOR_MAX] = { };
345 struct device_node *reg_np = NULL; 345 struct device_node *reg_np = NULL;
346 struct regulator_config config = { }; 346 struct regulator_config config = { };
347 struct s2mpa01_info *s2mpa01; 347 struct s2mpa01_info *s2mpa01;
diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index adab82d5279f..b345cf51225a 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -30,6 +30,7 @@
30#include <linux/of_gpio.h> 30#include <linux/of_gpio.h>
31#include <linux/mfd/samsung/core.h> 31#include <linux/mfd/samsung/core.h>
32#include <linux/mfd/samsung/s2mps11.h> 32#include <linux/mfd/samsung/s2mps11.h>
33#include <linux/mfd/samsung/s2mps13.h>
33#include <linux/mfd/samsung/s2mps14.h> 34#include <linux/mfd/samsung/s2mps14.h>
34#include <linux/mfd/samsung/s2mpu02.h> 35#include <linux/mfd/samsung/s2mpu02.h>
35 36
@@ -45,10 +46,10 @@ struct s2mps11_info {
45 enum sec_device_type dev_type; 46 enum sec_device_type dev_type;
46 47
47 /* 48 /*
48 * One bit for each S2MPS14/S2MPU02 regulator whether the suspend mode 49 * One bit for each S2MPS13/S2MPS14/S2MPU02 regulator whether
49 * was enabled. 50 * the suspend mode was enabled.
50 */ 51 */
51 unsigned long long s2mps14_suspend_state:35; 52 unsigned long long s2mps14_suspend_state:50;
52 53
53 /* Array of size rdev_num with GPIO-s for external sleep control */ 54 /* Array of size rdev_num with GPIO-s for external sleep control */
54 int *ext_control_gpio; 55 int *ext_control_gpio;
@@ -369,12 +370,101 @@ static const struct regulator_desc s2mps11_regulators[] = {
369 regulator_desc_s2mps11_buck6_10(10, MIN_750_MV, STEP_12_5_MV), 370 regulator_desc_s2mps11_buck6_10(10, MIN_750_MV, STEP_12_5_MV),
370}; 371};
371 372
373static struct regulator_ops s2mps14_reg_ops;
374
375#define regulator_desc_s2mps13_ldo(num, min, step, min_sel) { \
376 .name = "LDO"#num, \
377 .id = S2MPS13_LDO##num, \
378 .ops = &s2mps14_reg_ops, \
379 .type = REGULATOR_VOLTAGE, \
380 .owner = THIS_MODULE, \
381 .min_uV = min, \
382 .uV_step = step, \
383 .linear_min_sel = min_sel, \
384 .n_voltages = S2MPS14_LDO_N_VOLTAGES, \
385 .vsel_reg = S2MPS13_REG_L1CTRL + num - 1, \
386 .vsel_mask = S2MPS14_LDO_VSEL_MASK, \
387 .enable_reg = S2MPS13_REG_L1CTRL + num - 1, \
388 .enable_mask = S2MPS14_ENABLE_MASK \
389}
390
391#define regulator_desc_s2mps13_buck(num, min, step, min_sel) { \
392 .name = "BUCK"#num, \
393 .id = S2MPS13_BUCK##num, \
394 .ops = &s2mps14_reg_ops, \
395 .type = REGULATOR_VOLTAGE, \
396 .owner = THIS_MODULE, \
397 .min_uV = min, \
398 .uV_step = step, \
399 .linear_min_sel = min_sel, \
400 .n_voltages = S2MPS14_BUCK_N_VOLTAGES, \
401 .ramp_delay = S2MPS13_BUCK_RAMP_DELAY, \
402 .vsel_reg = S2MPS13_REG_B1OUT + (num - 1) * 2, \
403 .vsel_mask = S2MPS14_BUCK_VSEL_MASK, \
404 .enable_reg = S2MPS13_REG_B1CTRL + (num - 1) * 2, \
405 .enable_mask = S2MPS14_ENABLE_MASK \
406}
407
408static const struct regulator_desc s2mps13_regulators[] = {
409 regulator_desc_s2mps13_ldo(1, MIN_800_MV, STEP_12_5_MV, 0x00),
410 regulator_desc_s2mps13_ldo(2, MIN_1400_MV, STEP_50_MV, 0x0C),
411 regulator_desc_s2mps13_ldo(3, MIN_1000_MV, STEP_25_MV, 0x08),
412 regulator_desc_s2mps13_ldo(4, MIN_800_MV, STEP_12_5_MV, 0x00),
413 regulator_desc_s2mps13_ldo(5, MIN_800_MV, STEP_12_5_MV, 0x00),
414 regulator_desc_s2mps13_ldo(6, MIN_800_MV, STEP_12_5_MV, 0x00),
415 regulator_desc_s2mps13_ldo(7, MIN_1000_MV, STEP_25_MV, 0x08),
416 regulator_desc_s2mps13_ldo(8, MIN_1000_MV, STEP_25_MV, 0x08),
417 regulator_desc_s2mps13_ldo(9, MIN_1000_MV, STEP_25_MV, 0x08),
418 regulator_desc_s2mps13_ldo(10, MIN_1400_MV, STEP_50_MV, 0x0C),
419 regulator_desc_s2mps13_ldo(11, MIN_800_MV, STEP_25_MV, 0x10),
420 regulator_desc_s2mps13_ldo(12, MIN_800_MV, STEP_25_MV, 0x10),
421 regulator_desc_s2mps13_ldo(13, MIN_800_MV, STEP_25_MV, 0x10),
422 regulator_desc_s2mps13_ldo(14, MIN_800_MV, STEP_12_5_MV, 0x00),
423 regulator_desc_s2mps13_ldo(15, MIN_800_MV, STEP_12_5_MV, 0x00),
424 regulator_desc_s2mps13_ldo(16, MIN_1400_MV, STEP_50_MV, 0x0C),
425 regulator_desc_s2mps13_ldo(17, MIN_1400_MV, STEP_50_MV, 0x0C),
426 regulator_desc_s2mps13_ldo(18, MIN_1000_MV, STEP_25_MV, 0x08),
427 regulator_desc_s2mps13_ldo(19, MIN_1000_MV, STEP_25_MV, 0x08),
428 regulator_desc_s2mps13_ldo(20, MIN_1400_MV, STEP_50_MV, 0x0C),
429 regulator_desc_s2mps13_ldo(21, MIN_1000_MV, STEP_25_MV, 0x08),
430 regulator_desc_s2mps13_ldo(22, MIN_1000_MV, STEP_25_MV, 0x08),
431 regulator_desc_s2mps13_ldo(23, MIN_800_MV, STEP_12_5_MV, 0x00),
432 regulator_desc_s2mps13_ldo(24, MIN_800_MV, STEP_12_5_MV, 0x00),
433 regulator_desc_s2mps13_ldo(25, MIN_1400_MV, STEP_50_MV, 0x0C),
434 regulator_desc_s2mps13_ldo(26, MIN_1400_MV, STEP_50_MV, 0x0C),
435 regulator_desc_s2mps13_ldo(27, MIN_1400_MV, STEP_50_MV, 0x0C),
436 regulator_desc_s2mps13_ldo(28, MIN_1000_MV, STEP_25_MV, 0x08),
437 regulator_desc_s2mps13_ldo(29, MIN_1400_MV, STEP_50_MV, 0x0C),
438 regulator_desc_s2mps13_ldo(30, MIN_1400_MV, STEP_50_MV, 0x0C),
439 regulator_desc_s2mps13_ldo(31, MIN_1000_MV, STEP_25_MV, 0x08),
440 regulator_desc_s2mps13_ldo(32, MIN_1000_MV, STEP_25_MV, 0x08),
441 regulator_desc_s2mps13_ldo(33, MIN_1400_MV, STEP_50_MV, 0x0C),
442 regulator_desc_s2mps13_ldo(34, MIN_1000_MV, STEP_25_MV, 0x08),
443 regulator_desc_s2mps13_ldo(35, MIN_1400_MV, STEP_50_MV, 0x0C),
444 regulator_desc_s2mps13_ldo(36, MIN_800_MV, STEP_12_5_MV, 0x00),
445 regulator_desc_s2mps13_ldo(37, MIN_1000_MV, STEP_25_MV, 0x08),
446 regulator_desc_s2mps13_ldo(38, MIN_1400_MV, STEP_50_MV, 0x0C),
447 regulator_desc_s2mps13_ldo(39, MIN_1000_MV, STEP_25_MV, 0x08),
448 regulator_desc_s2mps13_ldo(40, MIN_1400_MV, STEP_50_MV, 0x0C),
449 regulator_desc_s2mps13_buck(1, MIN_500_MV, STEP_6_25_MV, 0x10),
450 regulator_desc_s2mps13_buck(2, MIN_500_MV, STEP_6_25_MV, 0x10),
451 regulator_desc_s2mps13_buck(3, MIN_500_MV, STEP_6_25_MV, 0x10),
452 regulator_desc_s2mps13_buck(4, MIN_500_MV, STEP_6_25_MV, 0x10),
453 regulator_desc_s2mps13_buck(5, MIN_500_MV, STEP_6_25_MV, 0x10),
454 regulator_desc_s2mps13_buck(6, MIN_500_MV, STEP_6_25_MV, 0x10),
455 regulator_desc_s2mps13_buck(7, MIN_500_MV, STEP_6_25_MV, 0x10),
456 regulator_desc_s2mps13_buck(8, MIN_1000_MV, STEP_12_5_MV, 0x20),
457 regulator_desc_s2mps13_buck(9, MIN_1000_MV, STEP_12_5_MV, 0x20),
458 regulator_desc_s2mps13_buck(10, MIN_500_MV, STEP_6_25_MV, 0x10),
459};
460
372static int s2mps14_regulator_enable(struct regulator_dev *rdev) 461static int s2mps14_regulator_enable(struct regulator_dev *rdev)
373{ 462{
374 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev); 463 struct s2mps11_info *s2mps11 = rdev_get_drvdata(rdev);
375 unsigned int val; 464 unsigned int val;
376 465
377 switch (s2mps11->dev_type) { 466 switch (s2mps11->dev_type) {
467 case S2MPS13X:
378 case S2MPS14X: 468 case S2MPS14X:
379 if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev))) 469 if (s2mps11->s2mps14_suspend_state & (1 << rdev_get_id(rdev)))
380 val = S2MPS14_ENABLE_SUSPEND; 470 val = S2MPS14_ENABLE_SUSPEND;
@@ -406,6 +496,7 @@ static int s2mps14_regulator_set_suspend_disable(struct regulator_dev *rdev)
406 496
407 /* Below LDO should be always on or does not support suspend mode. */ 497 /* Below LDO should be always on or does not support suspend mode. */
408 switch (s2mps11->dev_type) { 498 switch (s2mps11->dev_type) {
499 case S2MPS13X:
409 case S2MPS14X: 500 case S2MPS14X:
410 switch (rdev_id) { 501 switch (rdev_id) {
411 case S2MPS14_LDO3: 502 case S2MPS14_LDO3:
@@ -831,6 +922,10 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
831 s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators); 922 s2mps11->rdev_num = ARRAY_SIZE(s2mps11_regulators);
832 regulators = s2mps11_regulators; 923 regulators = s2mps11_regulators;
833 break; 924 break;
925 case S2MPS13X:
926 s2mps11->rdev_num = ARRAY_SIZE(s2mps13_regulators);
927 regulators = s2mps13_regulators;
928 break;
834 case S2MPS14X: 929 case S2MPS14X:
835 s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators); 930 s2mps11->rdev_num = ARRAY_SIZE(s2mps14_regulators);
836 regulators = s2mps14_regulators; 931 regulators = s2mps14_regulators;
@@ -845,7 +940,7 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
845 return -EINVAL; 940 return -EINVAL;
846 }; 941 };
847 942
848 s2mps11->ext_control_gpio = devm_kzalloc(&pdev->dev, 943 s2mps11->ext_control_gpio = devm_kmalloc(&pdev->dev,
849 sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num, 944 sizeof(*s2mps11->ext_control_gpio) * s2mps11->rdev_num,
850 GFP_KERNEL); 945 GFP_KERNEL);
851 if (!s2mps11->ext_control_gpio) 946 if (!s2mps11->ext_control_gpio)
@@ -886,6 +981,7 @@ common_reg:
886 config.regmap = iodev->regmap_pmic; 981 config.regmap = iodev->regmap_pmic;
887 config.driver_data = s2mps11; 982 config.driver_data = s2mps11;
888 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH; 983 config.ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
984 config.ena_gpio_initialized = true;
889 for (i = 0; i < s2mps11->rdev_num; i++) { 985 for (i = 0; i < s2mps11->rdev_num; i++) {
890 struct regulator_dev *regulator; 986 struct regulator_dev *regulator;
891 987
@@ -927,6 +1023,7 @@ out:
927 1023
928static const struct platform_device_id s2mps11_pmic_id[] = { 1024static const struct platform_device_id s2mps11_pmic_id[] = {
929 { "s2mps11-pmic", S2MPS11X}, 1025 { "s2mps11-pmic", S2MPS11X},
1026 { "s2mps13-pmic", S2MPS13X},
930 { "s2mps14-pmic", S2MPS14X}, 1027 { "s2mps14-pmic", S2MPS14X},
931 { "s2mpu02-pmic", S2MPU02}, 1028 { "s2mpu02-pmic", S2MPU02},
932 { }, 1029 { },
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index 0ab5cbeeb797..dc1328c0c71c 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -581,7 +581,8 @@ static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,
581 581
582 rdata->id = i; 582 rdata->id = i;
583 rdata->initdata = of_get_regulator_init_data( 583 rdata->initdata = of_get_regulator_init_data(
584 &pdev->dev, reg_np); 584 &pdev->dev, reg_np,
585 &regulators[i]);
585 rdata->reg_node = reg_np; 586 rdata->reg_node = reg_np;
586 rdata++; 587 rdata++;
587 rmode->id = i; 588 rmode->id = i;
@@ -950,6 +951,7 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
950 config.of_node = pdata->regulators[i].reg_node; 951 config.of_node = pdata->regulators[i].reg_node;
951 config.ena_gpio = -EINVAL; 952 config.ena_gpio = -EINVAL;
952 config.ena_gpio_flags = 0; 953 config.ena_gpio_flags = 0;
954 config.ena_gpio_initialized = true;
953 if (gpio_is_valid(pdata->regulators[i].ext_control_gpio)) 955 if (gpio_is_valid(pdata->regulators[i].ext_control_gpio))
954 s5m8767_regulator_config_ext_control(s5m8767, 956 s5m8767_regulator_config_ext_control(s5m8767,
955 &pdata->regulators[i], &config); 957 &pdata->regulators[i], &config);
diff --git a/drivers/regulator/sky81452-regulator.c b/drivers/regulator/sky81452-regulator.c
index 97aff0ccd65f..647860611916 100644
--- a/drivers/regulator/sky81452-regulator.c
+++ b/drivers/regulator/sky81452-regulator.c
@@ -5,9 +5,8 @@
5 * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com> 5 * Author : Gyungoh Yoo <jack.yoo@skyworksinc.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 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 8 * under the terms of the GNU General Public License version 2
9 * Free Software Foundation; either version 2, or (at your option) any 9 * as published by the Free Software Foundation.
10 * later version.
11 * 10 *
12 * This program is distributed in the hope that it will be useful, but 11 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of 12 * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -52,6 +51,8 @@ static const struct regulator_linear_range sky81452_reg_ranges[] = {
52 51
53static const struct regulator_desc sky81452_reg = { 52static const struct regulator_desc sky81452_reg = {
54 .name = "LOUT", 53 .name = "LOUT",
54 .of_match = of_match_ptr("lout"),
55 .regulators_node = of_match_ptr("regulator"),
55 .ops = &sky81452_reg_ops, 56 .ops = &sky81452_reg_ops,
56 .type = REGULATOR_VOLTAGE, 57 .type = REGULATOR_VOLTAGE,
57 .owner = THIS_MODULE, 58 .owner = THIS_MODULE,
@@ -64,30 +65,6 @@ static const struct regulator_desc sky81452_reg = {
64 .enable_mask = SKY81452_LEN, 65 .enable_mask = SKY81452_LEN,
65}; 66};
66 67
67#ifdef CONFIG_OF
68static struct regulator_init_data *sky81452_reg_parse_dt(struct device *dev)
69{
70 struct regulator_init_data *init_data;
71 struct device_node *np;
72
73 np = of_get_child_by_name(dev->parent->of_node, "regulator");
74 if (unlikely(!np)) {
75 dev_err(dev, "regulator node not found");
76 return NULL;
77 }
78
79 init_data = of_get_regulator_init_data(dev, np);
80
81 of_node_put(np);
82 return init_data;
83}
84#else
85static struct regulator_init_data *sky81452_reg_parse_dt(struct device *dev)
86{
87 return ERR_PTR(-EINVAL);
88}
89#endif
90
91static int sky81452_reg_probe(struct platform_device *pdev) 68static int sky81452_reg_probe(struct platform_device *pdev)
92{ 69{
93 struct device *dev = &pdev->dev; 70 struct device *dev = &pdev->dev;
@@ -95,20 +72,16 @@ static int sky81452_reg_probe(struct platform_device *pdev)
95 struct regulator_config config = { }; 72 struct regulator_config config = { };
96 struct regulator_dev *rdev; 73 struct regulator_dev *rdev;
97 74
98 if (!init_data) { 75 config.dev = dev->parent;
99 init_data = sky81452_reg_parse_dt(dev);
100 if (IS_ERR(init_data))
101 return PTR_ERR(init_data);
102 }
103
104 config.dev = dev;
105 config.init_data = init_data; 76 config.init_data = init_data;
106 config.of_node = dev->of_node; 77 config.of_node = dev->of_node;
107 config.regmap = dev_get_drvdata(dev->parent); 78 config.regmap = dev_get_drvdata(dev->parent);
108 79
109 rdev = devm_regulator_register(dev, &sky81452_reg, &config); 80 rdev = devm_regulator_register(dev, &sky81452_reg, &config);
110 if (IS_ERR(rdev)) 81 if (IS_ERR(rdev)) {
82 dev_err(dev, "failed to register. err=%ld\n", PTR_ERR(rdev));
111 return PTR_ERR(rdev); 83 return PTR_ERR(rdev);
84 }
112 85
113 platform_set_drvdata(pdev, rdev); 86 platform_set_drvdata(pdev, rdev);
114 87
@@ -126,5 +99,4 @@ module_platform_driver(sky81452_reg_driver);
126 99
127MODULE_DESCRIPTION("Skyworks SKY81452 Regulator driver"); 100MODULE_DESCRIPTION("Skyworks SKY81452 Regulator driver");
128MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>"); 101MODULE_AUTHOR("Gyungoh Yoo <jack.yoo@skyworksinc.com>");
129MODULE_LICENSE("GPL"); 102MODULE_LICENSE("GPL v2");
130MODULE_VERSION("1.0");
diff --git a/drivers/regulator/stw481x-vmmc.c b/drivers/regulator/stw481x-vmmc.c
index a7e152696a02..b4f1696456a7 100644
--- a/drivers/regulator/stw481x-vmmc.c
+++ b/drivers/regulator/stw481x-vmmc.c
@@ -72,7 +72,8 @@ static int stw481x_vmmc_regulator_probe(struct platform_device *pdev)
72 config.regmap = stw481x->map; 72 config.regmap = stw481x->map;
73 config.of_node = pdev->dev.of_node; 73 config.of_node = pdev->dev.of_node;
74 config.init_data = of_get_regulator_init_data(&pdev->dev, 74 config.init_data = of_get_regulator_init_data(&pdev->dev,
75 pdev->dev.of_node); 75 pdev->dev.of_node,
76 &vmmc_regulator);
76 77
77 stw481x->vmmc_regulator = devm_regulator_register(&pdev->dev, 78 stw481x->vmmc_regulator = devm_regulator_register(&pdev->dev,
78 &vmmc_regulator, &config); 79 &vmmc_regulator, &config);
diff --git a/drivers/regulator/ti-abb-regulator.c b/drivers/regulator/ti-abb-regulator.c
index a2dabb575b97..1ef5aba96f17 100644
--- a/drivers/regulator/ti-abb-regulator.c
+++ b/drivers/regulator/ti-abb-regulator.c
@@ -837,7 +837,8 @@ skip_opt:
837 return -EINVAL; 837 return -EINVAL;
838 } 838 }
839 839
840 initdata = of_get_regulator_init_data(dev, pdev->dev.of_node); 840 initdata = of_get_regulator_init_data(dev, pdev->dev.of_node,
841 &abb->rdesc);
841 if (!initdata) { 842 if (!initdata) {
842 dev_err(dev, "%s: Unable to alloc regulator init data\n", 843 dev_err(dev, "%s: Unable to alloc regulator init data\n",
843 __func__); 844 __func__);
diff --git a/drivers/regulator/tps51632-regulator.c b/drivers/regulator/tps51632-regulator.c
index f31f22e3e1bd..c213e37eb69e 100644
--- a/drivers/regulator/tps51632-regulator.c
+++ b/drivers/regulator/tps51632-regulator.c
@@ -221,7 +221,8 @@ static const struct of_device_id tps51632_of_match[] = {
221MODULE_DEVICE_TABLE(of, tps51632_of_match); 221MODULE_DEVICE_TABLE(of, tps51632_of_match);
222 222
223static struct tps51632_regulator_platform_data * 223static struct tps51632_regulator_platform_data *
224 of_get_tps51632_platform_data(struct device *dev) 224 of_get_tps51632_platform_data(struct device *dev,
225 const struct regulator_desc *desc)
225{ 226{
226 struct tps51632_regulator_platform_data *pdata; 227 struct tps51632_regulator_platform_data *pdata;
227 struct device_node *np = dev->of_node; 228 struct device_node *np = dev->of_node;
@@ -230,7 +231,8 @@ static struct tps51632_regulator_platform_data *
230 if (!pdata) 231 if (!pdata)
231 return NULL; 232 return NULL;
232 233
233 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node); 234 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node,
235 desc);
234 if (!pdata->reg_init_data) { 236 if (!pdata->reg_init_data) {
235 dev_err(dev, "Not able to get OF regulator init data\n"); 237 dev_err(dev, "Not able to get OF regulator init data\n");
236 return NULL; 238 return NULL;
@@ -248,7 +250,8 @@ static struct tps51632_regulator_platform_data *
248} 250}
249#else 251#else
250static struct tps51632_regulator_platform_data * 252static struct tps51632_regulator_platform_data *
251 of_get_tps51632_platform_data(struct device *dev) 253 of_get_tps51632_platform_data(struct device *dev,
254 const struct regulator_desc *desc)
252{ 255{
253 return NULL; 256 return NULL;
254} 257}
@@ -273,9 +276,25 @@ static int tps51632_probe(struct i2c_client *client,
273 } 276 }
274 } 277 }
275 278
279 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
280 if (!tps)
281 return -ENOMEM;
282
283 tps->dev = &client->dev;
284 tps->desc.name = client->name;
285 tps->desc.id = 0;
286 tps->desc.ramp_delay = TPS51632_DEFAULT_RAMP_DELAY;
287 tps->desc.min_uV = TPS51632_MIN_VOLTAGE;
288 tps->desc.uV_step = TPS51632_VOLTAGE_STEP_10mV;
289 tps->desc.linear_min_sel = TPS51632_MIN_VSEL;
290 tps->desc.n_voltages = TPS51632_MAX_VSEL + 1;
291 tps->desc.ops = &tps51632_dcdc_ops;
292 tps->desc.type = REGULATOR_VOLTAGE;
293 tps->desc.owner = THIS_MODULE;
294
276 pdata = dev_get_platdata(&client->dev); 295 pdata = dev_get_platdata(&client->dev);
277 if (!pdata && client->dev.of_node) 296 if (!pdata && client->dev.of_node)
278 pdata = of_get_tps51632_platform_data(&client->dev); 297 pdata = of_get_tps51632_platform_data(&client->dev, &tps->desc);
279 if (!pdata) { 298 if (!pdata) {
280 dev_err(&client->dev, "No Platform data\n"); 299 dev_err(&client->dev, "No Platform data\n");
281 return -EINVAL; 300 return -EINVAL;
@@ -296,22 +315,6 @@ static int tps51632_probe(struct i2c_client *client,
296 } 315 }
297 } 316 }
298 317
299 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
300 if (!tps)
301 return -ENOMEM;
302
303 tps->dev = &client->dev;
304 tps->desc.name = client->name;
305 tps->desc.id = 0;
306 tps->desc.ramp_delay = TPS51632_DEFAULT_RAMP_DELAY;
307 tps->desc.min_uV = TPS51632_MIN_VOLTAGE;
308 tps->desc.uV_step = TPS51632_VOLTAGE_STEP_10mV;
309 tps->desc.linear_min_sel = TPS51632_MIN_VSEL;
310 tps->desc.n_voltages = TPS51632_MAX_VSEL + 1;
311 tps->desc.ops = &tps51632_dcdc_ops;
312 tps->desc.type = REGULATOR_VOLTAGE;
313 tps->desc.owner = THIS_MODULE;
314
315 if (pdata->enable_pwm_dvfs) 318 if (pdata->enable_pwm_dvfs)
316 tps->desc.vsel_reg = TPS51632_VOLTAGE_BASE_REG; 319 tps->desc.vsel_reg = TPS51632_VOLTAGE_BASE_REG;
317 else 320 else
diff --git a/drivers/regulator/tps62360-regulator.c b/drivers/regulator/tps62360-regulator.c
index a1672044e519..a1fd626c6c96 100644
--- a/drivers/regulator/tps62360-regulator.c
+++ b/drivers/regulator/tps62360-regulator.c
@@ -293,7 +293,8 @@ static const struct regmap_config tps62360_regmap_config = {
293}; 293};
294 294
295static struct tps62360_regulator_platform_data * 295static struct tps62360_regulator_platform_data *
296 of_get_tps62360_platform_data(struct device *dev) 296 of_get_tps62360_platform_data(struct device *dev,
297 const struct regulator_desc *desc)
297{ 298{
298 struct tps62360_regulator_platform_data *pdata; 299 struct tps62360_regulator_platform_data *pdata;
299 struct device_node *np = dev->of_node; 300 struct device_node *np = dev->of_node;
@@ -302,7 +303,8 @@ static struct tps62360_regulator_platform_data *
302 if (!pdata) 303 if (!pdata)
303 return NULL; 304 return NULL;
304 305
305 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node); 306 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node,
307 desc);
306 if (!pdata->reg_init_data) { 308 if (!pdata->reg_init_data) {
307 dev_err(dev, "Not able to get OF regulator init data\n"); 309 dev_err(dev, "Not able to get OF regulator init data\n");
308 return NULL; 310 return NULL;
@@ -350,6 +352,17 @@ static int tps62360_probe(struct i2c_client *client,
350 352
351 pdata = dev_get_platdata(&client->dev); 353 pdata = dev_get_platdata(&client->dev);
352 354
355 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
356 if (!tps)
357 return -ENOMEM;
358
359 tps->desc.name = client->name;
360 tps->desc.id = 0;
361 tps->desc.ops = &tps62360_dcdc_ops;
362 tps->desc.type = REGULATOR_VOLTAGE;
363 tps->desc.owner = THIS_MODULE;
364 tps->desc.uV_step = 10000;
365
353 if (client->dev.of_node) { 366 if (client->dev.of_node) {
354 const struct of_device_id *match; 367 const struct of_device_id *match;
355 match = of_match_device(of_match_ptr(tps62360_of_match), 368 match = of_match_device(of_match_ptr(tps62360_of_match),
@@ -360,7 +373,8 @@ static int tps62360_probe(struct i2c_client *client,
360 } 373 }
361 chip_id = (int)(long)match->data; 374 chip_id = (int)(long)match->data;
362 if (!pdata) 375 if (!pdata)
363 pdata = of_get_tps62360_platform_data(&client->dev); 376 pdata = of_get_tps62360_platform_data(&client->dev,
377 &tps->desc);
364 } else if (id) { 378 } else if (id) {
365 chip_id = id->driver_data; 379 chip_id = id->driver_data;
366 } else { 380 } else {
@@ -374,10 +388,6 @@ static int tps62360_probe(struct i2c_client *client,
374 return -EIO; 388 return -EIO;
375 } 389 }
376 390
377 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
378 if (!tps)
379 return -ENOMEM;
380
381 tps->en_discharge = pdata->en_discharge; 391 tps->en_discharge = pdata->en_discharge;
382 tps->en_internal_pulldn = pdata->en_internal_pulldn; 392 tps->en_internal_pulldn = pdata->en_internal_pulldn;
383 tps->vsel0_gpio = pdata->vsel0_gpio; 393 tps->vsel0_gpio = pdata->vsel0_gpio;
@@ -401,13 +411,6 @@ static int tps62360_probe(struct i2c_client *client,
401 return -ENODEV; 411 return -ENODEV;
402 } 412 }
403 413
404 tps->desc.name = client->name;
405 tps->desc.id = 0;
406 tps->desc.ops = &tps62360_dcdc_ops;
407 tps->desc.type = REGULATOR_VOLTAGE;
408 tps->desc.owner = THIS_MODULE;
409 tps->desc.uV_step = 10000;
410
411 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config); 414 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config);
412 if (IS_ERR(tps->regmap)) { 415 if (IS_ERR(tps->regmap)) {
413 ret = PTR_ERR(tps->regmap); 416 ret = PTR_ERR(tps->regmap);
diff --git a/drivers/regulator/tps65090-regulator.c b/drivers/regulator/tps65090-regulator.c
index d5df1e9ad1da..f1df4423d361 100644
--- a/drivers/regulator/tps65090-regulator.c
+++ b/drivers/regulator/tps65090-regulator.c
@@ -312,7 +312,11 @@ static void tps65090_configure_regulator_config(
312 gpio_flag = GPIOF_OUT_INIT_HIGH; 312 gpio_flag = GPIOF_OUT_INIT_HIGH;
313 313
314 config->ena_gpio = tps_pdata->gpio; 314 config->ena_gpio = tps_pdata->gpio;
315 config->ena_gpio_initialized = true;
315 config->ena_gpio_flags = gpio_flag; 316 config->ena_gpio_flags = gpio_flag;
317 } else {
318 config->ena_gpio = -EINVAL;
319 config->ena_gpio_initialized = false;
316 } 320 }
317} 321}
318 322
diff --git a/drivers/regulator/tps65218-regulator.c b/drivers/regulator/tps65218-regulator.c
index f0a40281b9c1..263cc85d6202 100644
--- a/drivers/regulator/tps65218-regulator.c
+++ b/drivers/regulator/tps65218-regulator.c
@@ -231,7 +231,8 @@ static int tps65218_regulator_probe(struct platform_device *pdev)
231 231
232 template = match->data; 232 template = match->data;
233 id = template->id; 233 id = template->id;
234 init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node); 234 init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node,
235 &regulators[id]);
235 236
236 platform_set_drvdata(pdev, tps); 237 platform_set_drvdata(pdev, tps);
237 238
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c
index 0b4f8660fdb4..dd727bca1983 100644
--- a/drivers/regulator/twl-regulator.c
+++ b/drivers/regulator/twl-regulator.c
@@ -1104,7 +1104,8 @@ static int twlreg_probe(struct platform_device *pdev)
1104 template = match->data; 1104 template = match->data;
1105 id = template->desc.id; 1105 id = template->desc.id;
1106 initdata = of_get_regulator_init_data(&pdev->dev, 1106 initdata = of_get_regulator_init_data(&pdev->dev,
1107 pdev->dev.of_node); 1107 pdev->dev.of_node,
1108 &template->desc);
1108 drvdata = NULL; 1109 drvdata = NULL;
1109 } else { 1110 } else {
1110 id = pdev->id; 1111 id = pdev->id;
diff --git a/drivers/regulator/vexpress.c b/drivers/regulator/vexpress.c
index 02e7267ccf92..5e7c789023a9 100644
--- a/drivers/regulator/vexpress.c
+++ b/drivers/regulator/vexpress.c
@@ -74,7 +74,8 @@ static int vexpress_regulator_probe(struct platform_device *pdev)
74 reg->desc.owner = THIS_MODULE; 74 reg->desc.owner = THIS_MODULE;
75 reg->desc.continuous_voltage_range = true; 75 reg->desc.continuous_voltage_range = true;
76 76
77 init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node); 77 init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node,
78 &reg->desc);
78 if (!init_data) 79 if (!init_data)
79 return -EINVAL; 80 return -EINVAL;
80 81
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c
index c24346db8a71..88f5064e412b 100644
--- a/drivers/regulator/wm8994-regulator.c
+++ b/drivers/regulator/wm8994-regulator.c
@@ -145,10 +145,12 @@ static int wm8994_ldo_probe(struct platform_device *pdev)
145 config.driver_data = ldo; 145 config.driver_data = ldo;
146 config.regmap = wm8994->regmap; 146 config.regmap = wm8994->regmap;
147 config.init_data = &ldo->init_data; 147 config.init_data = &ldo->init_data;
148 if (pdata) 148 if (pdata) {
149 config.ena_gpio = pdata->ldo[id].enable; 149 config.ena_gpio = pdata->ldo[id].enable;
150 else if (wm8994->dev->of_node) 150 } else if (wm8994->dev->of_node) {
151 config.ena_gpio = wm8994->pdata.ldo[id].enable; 151 config.ena_gpio = wm8994->pdata.ldo[id].enable;
152 config.ena_gpio_initialized = true;
153 }
152 154
153 /* Use default constraints if none set up */ 155 /* Use default constraints if none set up */
154 if (!pdata || !pdata->ldo[id].init_data || wm8994->dev->of_node) { 156 if (!pdata || !pdata->ldo[id].init_data || wm8994->dev->of_node) {
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 6dd12ddbabc6..da5a1c789f36 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1110,7 +1110,7 @@ config RTC_DRV_AT91RM9200
1110 1110
1111config RTC_DRV_AT91SAM9 1111config RTC_DRV_AT91SAM9
1112 tristate "AT91SAM9x/AT91CAP9 RTT as RTC" 1112 tristate "AT91SAM9x/AT91CAP9 RTT as RTC"
1113 depends on ARCH_AT91 && !(ARCH_AT91RM9200 || ARCH_AT91X40) 1113 depends on ARCH_AT91
1114 help 1114 help
1115 RTC driver for the Atmel AT91SAM9x and AT91CAP9 internal RTT 1115 RTC driver for the Atmel AT91SAM9x and AT91CAP9 internal RTT
1116 (Real Time Timer). These timers are powered by the backup power 1116 (Real Time Timer). These timers are powered by the backup power
@@ -1124,7 +1124,6 @@ config RTC_DRV_AT91SAM9_RTT
1124 int 1124 int
1125 range 0 1 1125 range 0 1
1126 default 0 1126 default 0
1127 prompt "RTT module Number" if ARCH_AT91SAM9263
1128 depends on RTC_DRV_AT91SAM9 1127 depends on RTC_DRV_AT91SAM9
1129 help 1128 help
1130 More than one RTT module is available. You can choose which 1129 More than one RTT module is available. You can choose which
@@ -1133,8 +1132,7 @@ config RTC_DRV_AT91SAM9_RTT
1133 1132
1134config RTC_DRV_AT91SAM9_GPBR 1133config RTC_DRV_AT91SAM9_GPBR
1135 int 1134 int
1136 range 0 3 if !ARCH_AT91SAM9263 1135 range 0 3
1137 range 0 15 if ARCH_AT91SAM9263
1138 default 0 1136 default 0
1139 prompt "Backup Register Number" 1137 prompt "Backup Register Number"
1140 depends on RTC_DRV_AT91SAM9 1138 depends on RTC_DRV_AT91SAM9
diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
index 6cbe6ef3c889..bda52f18e967 100644
--- a/drivers/s390/kvm/virtio_ccw.c
+++ b/drivers/s390/kvm/virtio_ccw.c
@@ -888,7 +888,6 @@ static void virtio_ccw_int_handler(struct ccw_device *cdev,
888 struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev); 888 struct virtio_ccw_device *vcdev = dev_get_drvdata(&cdev->dev);
889 int i; 889 int i;
890 struct virtqueue *vq; 890 struct virtqueue *vq;
891 struct virtio_driver *drv;
892 891
893 if (!vcdev) 892 if (!vcdev)
894 return; 893 return;
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 8004b071a9f2..01a73395a017 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -353,9 +353,11 @@ struct zfcp_adapter *zfcp_adapter_enqueue(struct ccw_device *ccw_device)
353 adapter->ccw_device = ccw_device; 353 adapter->ccw_device = ccw_device;
354 354
355 INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler); 355 INIT_WORK(&adapter->stat_work, _zfcp_status_read_scheduler);
356 INIT_WORK(&adapter->scan_work, zfcp_fc_scan_ports); 356 INIT_DELAYED_WORK(&adapter->scan_work, zfcp_fc_scan_ports);
357 INIT_WORK(&adapter->ns_up_work, zfcp_fc_sym_name_update); 357 INIT_WORK(&adapter->ns_up_work, zfcp_fc_sym_name_update);
358 358
359 adapter->next_port_scan = jiffies;
360
359 if (zfcp_qdio_setup(adapter)) 361 if (zfcp_qdio_setup(adapter))
360 goto failed; 362 goto failed;
361 363
@@ -420,7 +422,7 @@ void zfcp_adapter_unregister(struct zfcp_adapter *adapter)
420{ 422{
421 struct ccw_device *cdev = adapter->ccw_device; 423 struct ccw_device *cdev = adapter->ccw_device;
422 424
423 cancel_work_sync(&adapter->scan_work); 425 cancel_delayed_work_sync(&adapter->scan_work);
424 cancel_work_sync(&adapter->stat_work); 426 cancel_work_sync(&adapter->stat_work);
425 cancel_work_sync(&adapter->ns_up_work); 427 cancel_work_sync(&adapter->ns_up_work);
426 zfcp_destroy_adapter_work_queue(adapter); 428 zfcp_destroy_adapter_work_queue(adapter);
diff --git a/drivers/s390/scsi/zfcp_ccw.c b/drivers/s390/scsi/zfcp_ccw.c
index f9879d400d0e..54c7b48fdb46 100644
--- a/drivers/s390/scsi/zfcp_ccw.c
+++ b/drivers/s390/scsi/zfcp_ccw.c
@@ -56,8 +56,22 @@ static int zfcp_ccw_activate(struct ccw_device *cdev, int clear, char *tag)
56 zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING); 56 zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING);
57 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED, 57 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
58 tag); 58 tag);
59
60 /*
61 * We want to scan ports here, with some random backoff and without
62 * rate limit. Recovery has already scheduled a port scan for us,
63 * but with both random delay and rate limit. Nevertheless we get
64 * what we want here by flushing the scheduled work after sleeping
65 * an equivalent random time.
66 * Let the port scan random delay elapse first. If recovery finishes
67 * up to that point in time, that would be perfect for both recovery
68 * and port scan. If not, i.e. recovery takes ages, there was no
69 * point in waiting a random delay on top of the time consumed by
70 * recovery.
71 */
72 msleep(zfcp_fc_port_scan_backoff());
59 zfcp_erp_wait(adapter); 73 zfcp_erp_wait(adapter);
60 flush_work(&adapter->scan_work); /* ok to call even if nothing queued */ 74 flush_delayed_work(&adapter->scan_work);
61 75
62 zfcp_ccw_adapter_put(adapter); 76 zfcp_ccw_adapter_put(adapter);
63 77
@@ -162,11 +176,19 @@ static int zfcp_ccw_set_online(struct ccw_device *cdev)
162 adapter->req_no = 0; 176 adapter->req_no = 0;
163 177
164 zfcp_ccw_activate(cdev, 0, "ccsonl1"); 178 zfcp_ccw_activate(cdev, 0, "ccsonl1");
165 /* scan for remote ports 179
166 either at the end of any successful adapter recovery 180 /*
167 or only after the adapter recovery for setting a device online */ 181 * We want to scan ports here, always, with some random delay and
182 * without rate limit - basically what zfcp_ccw_activate() has
183 * achieved for us. Not quite! That port scan depended on
184 * !no_auto_port_rescan. So let's cover the no_auto_port_rescan
185 * case here to make sure a port scan is done unconditionally.
186 * Since zfcp_ccw_activate() has waited the desired random time,
187 * we can immediately schedule and flush a port scan for the
188 * remaining cases.
189 */
168 zfcp_fc_inverse_conditional_port_scan(adapter); 190 zfcp_fc_inverse_conditional_port_scan(adapter);
169 flush_work(&adapter->scan_work); /* ok to call even if nothing queued */ 191 flush_delayed_work(&adapter->scan_work);
170 zfcp_ccw_adapter_put(adapter); 192 zfcp_ccw_adapter_put(adapter);
171 return 0; 193 return 0;
172} 194}
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h
index d91173f326c5..b8e853e53546 100644
--- a/drivers/s390/scsi/zfcp_def.h
+++ b/drivers/s390/scsi/zfcp_def.h
@@ -186,12 +186,13 @@ struct zfcp_adapter {
186 struct fc_host_statistics *fc_stats; 186 struct fc_host_statistics *fc_stats;
187 struct fsf_qtcb_bottom_port *stats_reset_data; 187 struct fsf_qtcb_bottom_port *stats_reset_data;
188 unsigned long stats_reset; 188 unsigned long stats_reset;
189 struct work_struct scan_work; 189 struct delayed_work scan_work;
190 struct work_struct ns_up_work; 190 struct work_struct ns_up_work;
191 struct service_level service_level; 191 struct service_level service_level;
192 struct workqueue_struct *work_queue; 192 struct workqueue_struct *work_queue;
193 struct device_dma_parameters dma_parms; 193 struct device_dma_parameters dma_parms;
194 struct zfcp_fc_events events; 194 struct zfcp_fc_events events;
195 unsigned long next_port_scan;
195}; 196};
196 197
197struct zfcp_port { 198struct zfcp_port {
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
index c82fe65c4128..2c5d4567d1da 100644
--- a/drivers/s390/scsi/zfcp_erp.c
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -821,11 +821,6 @@ static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *act)
821 return ZFCP_ERP_CONTINUES; 821 return ZFCP_ERP_CONTINUES;
822} 822}
823 823
824static void zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
825{
826 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status);
827}
828
829static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action) 824static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
830{ 825{
831 struct zfcp_port *port = erp_action->port; 826 struct zfcp_port *port = erp_action->port;
@@ -833,7 +828,6 @@ static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
833 828
834 switch (erp_action->step) { 829 switch (erp_action->step) {
835 case ZFCP_ERP_STEP_UNINITIALIZED: 830 case ZFCP_ERP_STEP_UNINITIALIZED:
836 zfcp_erp_port_strategy_clearstati(port);
837 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) && 831 if ((status & ZFCP_STATUS_PORT_PHYS_OPEN) &&
838 (status & ZFCP_STATUS_COMMON_OPEN)) 832 (status & ZFCP_STATUS_COMMON_OPEN))
839 return zfcp_erp_port_forced_strategy_close(erp_action); 833 return zfcp_erp_port_forced_strategy_close(erp_action);
@@ -933,7 +927,6 @@ static int zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
933 927
934 switch (erp_action->step) { 928 switch (erp_action->step) {
935 case ZFCP_ERP_STEP_UNINITIALIZED: 929 case ZFCP_ERP_STEP_UNINITIALIZED:
936 zfcp_erp_port_strategy_clearstati(port);
937 if (p_status & ZFCP_STATUS_COMMON_OPEN) 930 if (p_status & ZFCP_STATUS_COMMON_OPEN)
938 return zfcp_erp_port_strategy_close(erp_action); 931 return zfcp_erp_port_strategy_close(erp_action);
939 break; 932 break;
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index a9c570a09b85..5b500652572b 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -85,6 +85,7 @@ extern void zfcp_fc_gs_destroy(struct zfcp_adapter *);
85extern int zfcp_fc_exec_bsg_job(struct fc_bsg_job *); 85extern int zfcp_fc_exec_bsg_job(struct fc_bsg_job *);
86extern int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *); 86extern int zfcp_fc_timeout_bsg_job(struct fc_bsg_job *);
87extern void zfcp_fc_sym_name_update(struct work_struct *); 87extern void zfcp_fc_sym_name_update(struct work_struct *);
88extern unsigned int zfcp_fc_port_scan_backoff(void);
88extern void zfcp_fc_conditional_port_scan(struct zfcp_adapter *); 89extern void zfcp_fc_conditional_port_scan(struct zfcp_adapter *);
89extern void zfcp_fc_inverse_conditional_port_scan(struct zfcp_adapter *); 90extern void zfcp_fc_inverse_conditional_port_scan(struct zfcp_adapter *);
90 91
diff --git a/drivers/s390/scsi/zfcp_fc.c b/drivers/s390/scsi/zfcp_fc.c
index ca28e1c66115..25d49f32ca63 100644
--- a/drivers/s390/scsi/zfcp_fc.c
+++ b/drivers/s390/scsi/zfcp_fc.c
@@ -12,6 +12,7 @@
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/utsname.h> 14#include <linux/utsname.h>
15#include <linux/random.h>
15#include <scsi/fc/fc_els.h> 16#include <scsi/fc/fc_els.h>
16#include <scsi/libfc.h> 17#include <scsi/libfc.h>
17#include "zfcp_ext.h" 18#include "zfcp_ext.h"
@@ -31,12 +32,54 @@ module_param_named(no_auto_port_rescan, no_auto_port_rescan, bool, 0600);
31MODULE_PARM_DESC(no_auto_port_rescan, 32MODULE_PARM_DESC(no_auto_port_rescan,
32 "no automatic port_rescan (default off)"); 33 "no automatic port_rescan (default off)");
33 34
35static unsigned int port_scan_backoff = 500;
36module_param(port_scan_backoff, uint, 0600);
37MODULE_PARM_DESC(port_scan_backoff,
38 "upper limit of port scan random backoff in msecs (default 500)");
39
40static unsigned int port_scan_ratelimit = 60000;
41module_param(port_scan_ratelimit, uint, 0600);
42MODULE_PARM_DESC(port_scan_ratelimit,
43 "minimum interval between port scans in msecs (default 60000)");
44
45unsigned int zfcp_fc_port_scan_backoff(void)
46{
47 if (!port_scan_backoff)
48 return 0;
49 return get_random_int() % port_scan_backoff;
50}
51
52static void zfcp_fc_port_scan_time(struct zfcp_adapter *adapter)
53{
54 unsigned long interval = msecs_to_jiffies(port_scan_ratelimit);
55 unsigned long backoff = msecs_to_jiffies(zfcp_fc_port_scan_backoff());
56
57 adapter->next_port_scan = jiffies + interval + backoff;
58}
59
60static void zfcp_fc_port_scan(struct zfcp_adapter *adapter)
61{
62 unsigned long now = jiffies;
63 unsigned long next = adapter->next_port_scan;
64 unsigned long delay = 0, max;
65
66 /* delay only needed within waiting period */
67 if (time_before(now, next)) {
68 delay = next - now;
69 /* paranoia: never ever delay scans longer than specified */
70 max = msecs_to_jiffies(port_scan_ratelimit + port_scan_backoff);
71 delay = min(delay, max);
72 }
73
74 queue_delayed_work(adapter->work_queue, &adapter->scan_work, delay);
75}
76
34void zfcp_fc_conditional_port_scan(struct zfcp_adapter *adapter) 77void zfcp_fc_conditional_port_scan(struct zfcp_adapter *adapter)
35{ 78{
36 if (no_auto_port_rescan) 79 if (no_auto_port_rescan)
37 return; 80 return;
38 81
39 queue_work(adapter->work_queue, &adapter->scan_work); 82 zfcp_fc_port_scan(adapter);
40} 83}
41 84
42void zfcp_fc_inverse_conditional_port_scan(struct zfcp_adapter *adapter) 85void zfcp_fc_inverse_conditional_port_scan(struct zfcp_adapter *adapter)
@@ -44,7 +87,7 @@ void zfcp_fc_inverse_conditional_port_scan(struct zfcp_adapter *adapter)
44 if (!no_auto_port_rescan) 87 if (!no_auto_port_rescan)
45 return; 88 return;
46 89
47 queue_work(adapter->work_queue, &adapter->scan_work); 90 zfcp_fc_port_scan(adapter);
48} 91}
49 92
50/** 93/**
@@ -680,12 +723,15 @@ static int zfcp_fc_eval_gpn_ft(struct zfcp_fc_req *fc_req,
680 */ 723 */
681void zfcp_fc_scan_ports(struct work_struct *work) 724void zfcp_fc_scan_ports(struct work_struct *work)
682{ 725{
683 struct zfcp_adapter *adapter = container_of(work, struct zfcp_adapter, 726 struct delayed_work *dw = to_delayed_work(work);
727 struct zfcp_adapter *adapter = container_of(dw, struct zfcp_adapter,
684 scan_work); 728 scan_work);
685 int ret, i; 729 int ret, i;
686 struct zfcp_fc_req *fc_req; 730 struct zfcp_fc_req *fc_req;
687 int chain, max_entries, buf_num, max_bytes; 731 int chain, max_entries, buf_num, max_bytes;
688 732
733 zfcp_fc_port_scan_time(adapter);
734
689 chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS; 735 chain = adapter->adapter_features & FSF_FEATURE_ELS_CT_CHAINED_SBALS;
690 buf_num = chain ? ZFCP_FC_GPN_FT_NUM_BUFS : 1; 736 buf_num = chain ? ZFCP_FC_GPN_FT_NUM_BUFS : 1;
691 max_entries = chain ? ZFCP_FC_GPN_FT_MAX_ENT : ZFCP_FC_GPN_FT_ENT_PAGE; 737 max_entries = chain ? ZFCP_FC_GPN_FT_MAX_ENT : ZFCP_FC_GPN_FT_ENT_PAGE;
diff --git a/drivers/s390/scsi/zfcp_fc.h b/drivers/s390/scsi/zfcp_fc.h
index b1d2024ed513..df2b541c8287 100644
--- a/drivers/s390/scsi/zfcp_fc.h
+++ b/drivers/s390/scsi/zfcp_fc.h
@@ -212,8 +212,6 @@ static inline
212void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi, 212void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi,
213 u8 tm_flags) 213 u8 tm_flags)
214{ 214{
215 char tag[2];
216
217 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun); 215 int_to_scsilun(scsi->device->lun, (struct scsi_lun *) &fcp->fc_lun);
218 216
219 if (unlikely(tm_flags)) { 217 if (unlikely(tm_flags)) {
@@ -221,17 +219,7 @@ void zfcp_fc_scsi_to_fcp(struct fcp_cmnd *fcp, struct scsi_cmnd *scsi,
221 return; 219 return;
222 } 220 }
223 221
224 if (scsi_populate_tag_msg(scsi, tag)) { 222 fcp->fc_pri_ta = FCP_PTA_SIMPLE;
225 switch (tag[0]) {
226 case MSG_ORDERED_TAG:
227 fcp->fc_pri_ta |= FCP_PTA_ORDERED;
228 break;
229 case MSG_SIMPLE_TAG:
230 fcp->fc_pri_ta |= FCP_PTA_SIMPLE;
231 break;
232 };
233 } else
234 fcp->fc_pri_ta = FCP_PTA_SIMPLE;
235 223
236 if (scsi->sc_data_direction == DMA_FROM_DEVICE) 224 if (scsi->sc_data_direction == DMA_FROM_DEVICE)
237 fcp->fc_flags |= FCP_CFL_RDDATA; 225 fcp->fc_flags |= FCP_CFL_RDDATA;
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index 0fe8d5d95119..21ec5e2f584c 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -1396,8 +1396,7 @@ static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
1396 port->handle = header->port_handle; 1396 port->handle = header->port_handle;
1397 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN | 1397 atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
1398 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status); 1398 ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
1399 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | 1399 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
1400 ZFCP_STATUS_COMMON_ACCESS_BOXED,
1401 &port->status); 1400 &port->status);
1402 /* check whether D_ID has changed during open */ 1401 /* check whether D_ID has changed during open */
1403 /* 1402 /*
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 7b353647cb90..75f4bfc2b98a 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -32,25 +32,6 @@ static bool allow_lun_scan = 1;
32module_param(allow_lun_scan, bool, 0600); 32module_param(allow_lun_scan, bool, 0600);
33MODULE_PARM_DESC(allow_lun_scan, "For NPIV, scan and attach all storage LUNs"); 33MODULE_PARM_DESC(allow_lun_scan, "For NPIV, scan and attach all storage LUNs");
34 34
35static int zfcp_scsi_change_queue_depth(struct scsi_device *sdev, int depth,
36 int reason)
37{
38 switch (reason) {
39 case SCSI_QDEPTH_DEFAULT:
40 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
41 break;
42 case SCSI_QDEPTH_QFULL:
43 scsi_track_queue_full(sdev, depth);
44 break;
45 case SCSI_QDEPTH_RAMP_UP:
46 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
47 break;
48 default:
49 return -EOPNOTSUPP;
50 }
51 return sdev->queue_depth;
52}
53
54static void zfcp_scsi_slave_destroy(struct scsi_device *sdev) 35static void zfcp_scsi_slave_destroy(struct scsi_device *sdev)
55{ 36{
56 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); 37 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
@@ -66,9 +47,7 @@ static void zfcp_scsi_slave_destroy(struct scsi_device *sdev)
66static int zfcp_scsi_slave_configure(struct scsi_device *sdp) 47static int zfcp_scsi_slave_configure(struct scsi_device *sdp)
67{ 48{
68 if (sdp->tagged_supported) 49 if (sdp->tagged_supported)
69 scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, default_depth); 50 scsi_change_queue_depth(sdp, default_depth);
70 else
71 scsi_adjust_queue_depth(sdp, 0, 1);
72 return 0; 51 return 0;
73} 52}
74 53
@@ -307,7 +286,7 @@ static struct scsi_host_template zfcp_scsi_host_template = {
307 .slave_alloc = zfcp_scsi_slave_alloc, 286 .slave_alloc = zfcp_scsi_slave_alloc,
308 .slave_configure = zfcp_scsi_slave_configure, 287 .slave_configure = zfcp_scsi_slave_configure,
309 .slave_destroy = zfcp_scsi_slave_destroy, 288 .slave_destroy = zfcp_scsi_slave_destroy,
310 .change_queue_depth = zfcp_scsi_change_queue_depth, 289 .change_queue_depth = scsi_change_queue_depth,
311 .proc_name = "zfcp", 290 .proc_name = "zfcp",
312 .can_queue = 4096, 291 .can_queue = 4096,
313 .this_id = -1, 292 .this_id = -1,
@@ -322,6 +301,7 @@ static struct scsi_host_template zfcp_scsi_host_template = {
322 .use_clustering = 1, 301 .use_clustering = 1,
323 .shost_attrs = zfcp_sysfs_shost_attrs, 302 .shost_attrs = zfcp_sysfs_shost_attrs,
324 .sdev_attrs = zfcp_sysfs_sdev_attrs, 303 .sdev_attrs = zfcp_sysfs_sdev_attrs,
304 .track_queue_depth = 1,
325}; 305};
326 306
327/** 307/**
diff --git a/drivers/s390/scsi/zfcp_sysfs.c b/drivers/s390/scsi/zfcp_sysfs.c
index 672b57219e11..96a0be13e841 100644
--- a/drivers/s390/scsi/zfcp_sysfs.c
+++ b/drivers/s390/scsi/zfcp_sysfs.c
@@ -73,9 +73,7 @@ ZFCP_DEFINE_ATTR(zfcp_port, port, status, "0x%08x\n",
73ZFCP_DEFINE_ATTR(zfcp_port, port, in_recovery, "%d\n", 73ZFCP_DEFINE_ATTR(zfcp_port, port, in_recovery, "%d\n",
74 (atomic_read(&port->status) & 74 (atomic_read(&port->status) &
75 ZFCP_STATUS_COMMON_ERP_INUSE) != 0); 75 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
76ZFCP_DEFINE_ATTR(zfcp_port, port, access_denied, "%d\n", 76ZFCP_DEFINE_ATTR_CONST(port, access_denied, "%d\n", 0);
77 (atomic_read(&port->status) &
78 ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0);
79 77
80ZFCP_DEFINE_ATTR(zfcp_unit, unit, status, "0x%08x\n", 78ZFCP_DEFINE_ATTR(zfcp_unit, unit, status, "0x%08x\n",
81 zfcp_unit_sdev_status(unit)); 79 zfcp_unit_sdev_status(unit));
@@ -223,9 +221,13 @@ static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev,
223 if (!adapter) 221 if (!adapter)
224 return -ENODEV; 222 return -ENODEV;
225 223
226 /* sync the user-space- with the kernel-invocation of scan_work */ 224 /*
227 queue_work(adapter->work_queue, &adapter->scan_work); 225 * Users wish is our command: immediately schedule and flush a
228 flush_work(&adapter->scan_work); 226 * worker to conduct a synchronous port scan, that is, neither
227 * a random delay nor a rate limit is applied here.
228 */
229 queue_delayed_work(adapter->work_queue, &adapter->scan_work, 0);
230 flush_delayed_work(&adapter->scan_work);
229 zfcp_ccw_adapter_put(adapter); 231 zfcp_ccw_adapter_put(adapter);
230 232
231 return (ssize_t) count; 233 return (ssize_t) count;
@@ -439,16 +441,15 @@ static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
439{ \ 441{ \
440 struct scsi_device *sdev = to_scsi_device(dev); \ 442 struct scsi_device *sdev = to_scsi_device(dev); \
441 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \ 443 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
442 struct zfcp_port *port = zfcp_sdev->port; \
443 \ 444 \
444 return sprintf(buf, _format, _value); \ 445 return sprintf(buf, _format, _value); \
445} \ 446} \
446static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL); 447static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
447 448
448ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n", 449ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n",
449 dev_name(&port->adapter->ccw_device->dev)); 450 dev_name(&zfcp_sdev->port->adapter->ccw_device->dev));
450ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n", 451ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n",
451 (unsigned long long) port->wwpn); 452 (unsigned long long) zfcp_sdev->port->wwpn);
452 453
453static ssize_t zfcp_sysfs_scsi_fcp_lun_show(struct device *dev, 454static ssize_t zfcp_sysfs_scsi_fcp_lun_show(struct device *dev,
454 struct device_attribute *attr, 455 struct device_attribute *attr,
@@ -460,6 +461,49 @@ static ssize_t zfcp_sysfs_scsi_fcp_lun_show(struct device *dev,
460} 461}
461static DEVICE_ATTR(fcp_lun, S_IRUGO, zfcp_sysfs_scsi_fcp_lun_show, NULL); 462static DEVICE_ATTR(fcp_lun, S_IRUGO, zfcp_sysfs_scsi_fcp_lun_show, NULL);
462 463
464ZFCP_DEFINE_SCSI_ATTR(zfcp_access_denied, "%d\n",
465 (atomic_read(&zfcp_sdev->status) &
466 ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0);
467
468static ssize_t zfcp_sysfs_scsi_zfcp_failed_show(struct device *dev,
469 struct device_attribute *attr,
470 char *buf)
471{
472 struct scsi_device *sdev = to_scsi_device(dev);
473 unsigned int status = atomic_read(&sdev_to_zfcp(sdev)->status);
474 unsigned int failed = status & ZFCP_STATUS_COMMON_ERP_FAILED ? 1 : 0;
475
476 return sprintf(buf, "%d\n", failed);
477}
478
479static ssize_t zfcp_sysfs_scsi_zfcp_failed_store(struct device *dev,
480 struct device_attribute *attr,
481 const char *buf, size_t count)
482{
483 struct scsi_device *sdev = to_scsi_device(dev);
484 unsigned long val;
485
486 if (kstrtoul(buf, 0, &val) || val != 0)
487 return -EINVAL;
488
489 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING);
490 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
491 "syufai3");
492 zfcp_erp_wait(sdev_to_zfcp(sdev)->port->adapter);
493
494 return count;
495}
496static DEVICE_ATTR(zfcp_failed, S_IWUSR | S_IRUGO,
497 zfcp_sysfs_scsi_zfcp_failed_show,
498 zfcp_sysfs_scsi_zfcp_failed_store);
499
500ZFCP_DEFINE_SCSI_ATTR(zfcp_in_recovery, "%d\n",
501 (atomic_read(&zfcp_sdev->status) &
502 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
503
504ZFCP_DEFINE_SCSI_ATTR(zfcp_status, "0x%08x\n",
505 atomic_read(&zfcp_sdev->status));
506
463struct device_attribute *zfcp_sysfs_sdev_attrs[] = { 507struct device_attribute *zfcp_sysfs_sdev_attrs[] = {
464 &dev_attr_fcp_lun, 508 &dev_attr_fcp_lun,
465 &dev_attr_wwpn, 509 &dev_attr_wwpn,
@@ -467,6 +511,10 @@ struct device_attribute *zfcp_sysfs_sdev_attrs[] = {
467 &dev_attr_read_latency, 511 &dev_attr_read_latency,
468 &dev_attr_write_latency, 512 &dev_attr_write_latency,
469 &dev_attr_cmd_latency, 513 &dev_attr_cmd_latency,
514 &dev_attr_zfcp_access_denied,
515 &dev_attr_zfcp_failed,
516 &dev_attr_zfcp_in_recovery,
517 &dev_attr_zfcp_status,
470 NULL 518 NULL
471}; 519};
472 520
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 0a7325361d29..cd4129ff7ae4 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -189,19 +189,6 @@ static ssize_t twa_show_stats(struct device *dev,
189 return len; 189 return len;
190} /* End twa_show_stats() */ 190} /* End twa_show_stats() */
191 191
192/* This function will set a devices queue depth */
193static int twa_change_queue_depth(struct scsi_device *sdev, int queue_depth,
194 int reason)
195{
196 if (reason != SCSI_QDEPTH_DEFAULT)
197 return -EOPNOTSUPP;
198
199 if (queue_depth > TW_Q_LENGTH-2)
200 queue_depth = TW_Q_LENGTH-2;
201 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
202 return queue_depth;
203} /* End twa_change_queue_depth() */
204
205/* Create sysfs 'stats' entry */ 192/* Create sysfs 'stats' entry */
206static struct device_attribute twa_host_stats_attr = { 193static struct device_attribute twa_host_stats_attr = {
207 .attr = { 194 .attr = {
@@ -2016,7 +2003,7 @@ static struct scsi_host_template driver_template = {
2016 .queuecommand = twa_scsi_queue, 2003 .queuecommand = twa_scsi_queue,
2017 .eh_host_reset_handler = twa_scsi_eh_reset, 2004 .eh_host_reset_handler = twa_scsi_eh_reset,
2018 .bios_param = twa_scsi_biosparam, 2005 .bios_param = twa_scsi_biosparam,
2019 .change_queue_depth = twa_change_queue_depth, 2006 .change_queue_depth = scsi_change_queue_depth,
2020 .can_queue = TW_Q_LENGTH-2, 2007 .can_queue = TW_Q_LENGTH-2,
2021 .slave_configure = twa_slave_configure, 2008 .slave_configure = twa_slave_configure,
2022 .this_id = -1, 2009 .this_id = -1,
diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index 6da6cec9a651..2361772d5909 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -191,19 +191,6 @@ static ssize_t twl_show_stats(struct device *dev,
191 return len; 191 return len;
192} /* End twl_show_stats() */ 192} /* End twl_show_stats() */
193 193
194/* This function will set a devices queue depth */
195static int twl_change_queue_depth(struct scsi_device *sdev, int queue_depth,
196 int reason)
197{
198 if (reason != SCSI_QDEPTH_DEFAULT)
199 return -EOPNOTSUPP;
200
201 if (queue_depth > TW_Q_LENGTH-2)
202 queue_depth = TW_Q_LENGTH-2;
203 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
204 return queue_depth;
205} /* End twl_change_queue_depth() */
206
207/* stats sysfs attribute initializer */ 194/* stats sysfs attribute initializer */
208static struct device_attribute twl_host_stats_attr = { 195static struct device_attribute twl_host_stats_attr = {
209 .attr = { 196 .attr = {
@@ -1590,7 +1577,7 @@ static struct scsi_host_template driver_template = {
1590 .queuecommand = twl_scsi_queue, 1577 .queuecommand = twl_scsi_queue,
1591 .eh_host_reset_handler = twl_scsi_eh_reset, 1578 .eh_host_reset_handler = twl_scsi_eh_reset,
1592 .bios_param = twl_scsi_biosparam, 1579 .bios_param = twl_scsi_biosparam,
1593 .change_queue_depth = twl_change_queue_depth, 1580 .change_queue_depth = scsi_change_queue_depth,
1594 .can_queue = TW_Q_LENGTH-2, 1581 .can_queue = TW_Q_LENGTH-2,
1595 .slave_configure = twl_slave_configure, 1582 .slave_configure = twl_slave_configure,
1596 .this_id = -1, 1583 .this_id = -1,
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 752624e6bc00..c75f2048319f 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -523,19 +523,6 @@ static ssize_t tw_show_stats(struct device *dev, struct device_attribute *attr,
523 return len; 523 return len;
524} /* End tw_show_stats() */ 524} /* End tw_show_stats() */
525 525
526/* This function will set a devices queue depth */
527static int tw_change_queue_depth(struct scsi_device *sdev, int queue_depth,
528 int reason)
529{
530 if (reason != SCSI_QDEPTH_DEFAULT)
531 return -EOPNOTSUPP;
532
533 if (queue_depth > TW_Q_LENGTH-2)
534 queue_depth = TW_Q_LENGTH-2;
535 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth);
536 return queue_depth;
537} /* End tw_change_queue_depth() */
538
539/* Create sysfs 'stats' entry */ 526/* Create sysfs 'stats' entry */
540static struct device_attribute tw_host_stats_attr = { 527static struct device_attribute tw_host_stats_attr = {
541 .attr = { 528 .attr = {
@@ -2270,7 +2257,7 @@ static struct scsi_host_template driver_template = {
2270 .queuecommand = tw_scsi_queue, 2257 .queuecommand = tw_scsi_queue,
2271 .eh_host_reset_handler = tw_scsi_eh_reset, 2258 .eh_host_reset_handler = tw_scsi_eh_reset,
2272 .bios_param = tw_scsi_biosparam, 2259 .bios_param = tw_scsi_biosparam,
2273 .change_queue_depth = tw_change_queue_depth, 2260 .change_queue_depth = scsi_change_queue_depth,
2274 .can_queue = TW_Q_LENGTH-2, 2261 .can_queue = TW_Q_LENGTH-2,
2275 .slave_configure = tw_slave_configure, 2262 .slave_configure = tw_slave_configure,
2276 .this_id = -1, 2263 .this_id = -1,
diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index fabd4be2c985..aa915da2a5e5 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -175,7 +175,7 @@ STATIC void NCR_700_chip_reset(struct Scsi_Host *host);
175STATIC int NCR_700_slave_alloc(struct scsi_device *SDpnt); 175STATIC int NCR_700_slave_alloc(struct scsi_device *SDpnt);
176STATIC int NCR_700_slave_configure(struct scsi_device *SDpnt); 176STATIC int NCR_700_slave_configure(struct scsi_device *SDpnt);
177STATIC void NCR_700_slave_destroy(struct scsi_device *SDpnt); 177STATIC void NCR_700_slave_destroy(struct scsi_device *SDpnt);
178static int NCR_700_change_queue_depth(struct scsi_device *SDpnt, int depth, int reason); 178static int NCR_700_change_queue_depth(struct scsi_device *SDpnt, int depth);
179static int NCR_700_change_queue_type(struct scsi_device *SDpnt, int depth); 179static int NCR_700_change_queue_type(struct scsi_device *SDpnt, int depth);
180 180
181STATIC struct device_attribute *NCR_700_dev_attrs[]; 181STATIC struct device_attribute *NCR_700_dev_attrs[];
@@ -327,6 +327,7 @@ NCR_700_detect(struct scsi_host_template *tpnt,
327 tpnt->slave_alloc = NCR_700_slave_alloc; 327 tpnt->slave_alloc = NCR_700_slave_alloc;
328 tpnt->change_queue_depth = NCR_700_change_queue_depth; 328 tpnt->change_queue_depth = NCR_700_change_queue_depth;
329 tpnt->change_queue_type = NCR_700_change_queue_type; 329 tpnt->change_queue_type = NCR_700_change_queue_type;
330 tpnt->use_blk_tags = 1;
330 331
331 if(tpnt->name == NULL) 332 if(tpnt->name == NULL)
332 tpnt->name = "53c700"; 333 tpnt->name = "53c700";
@@ -592,19 +593,14 @@ NCR_700_scsi_done(struct NCR_700_Host_Parameters *hostdata,
592 hostdata->cmd = NULL; 593 hostdata->cmd = NULL;
593 594
594 if(SCp != NULL) { 595 if(SCp != NULL) {
595 struct NCR_700_command_slot *slot = 596 struct NCR_700_command_slot *slot =
596 (struct NCR_700_command_slot *)SCp->host_scribble; 597 (struct NCR_700_command_slot *)SCp->host_scribble;
597 598
598 dma_unmap_single(hostdata->dev, slot->pCmd, 599 dma_unmap_single(hostdata->dev, slot->pCmd,
599 MAX_COMMAND_SIZE, DMA_TO_DEVICE); 600 MAX_COMMAND_SIZE, DMA_TO_DEVICE);
600 if (slot->flags == NCR_700_FLAG_AUTOSENSE) { 601 if (slot->flags == NCR_700_FLAG_AUTOSENSE) {
601 char *cmnd = NCR_700_get_sense_cmnd(SCp->device); 602 char *cmnd = NCR_700_get_sense_cmnd(SCp->device);
602#ifdef NCR_700_DEBUG
603 printk(" ORIGINAL CMD %p RETURNED %d, new return is %d sense is\n",
604 SCp, SCp->cmnd[7], result);
605 scsi_print_sense("53c700", SCp);
606 603
607#endif
608 dma_unmap_single(hostdata->dev, slot->dma_handle, 604 dma_unmap_single(hostdata->dev, slot->dma_handle,
609 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE); 605 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
610 /* restore the old result if the request sense was 606 /* restore the old result if the request sense was
@@ -906,8 +902,10 @@ process_message(struct Scsi_Host *host, struct NCR_700_Host_Parameters *hostdata
906 /* we're done negotiating */ 902 /* we're done negotiating */
907 NCR_700_set_tag_neg_state(SCp->device, NCR_700_FINISHED_TAG_NEGOTIATION); 903 NCR_700_set_tag_neg_state(SCp->device, NCR_700_FINISHED_TAG_NEGOTIATION);
908 hostdata->tag_negotiated &= ~(1<<scmd_id(SCp)); 904 hostdata->tag_negotiated &= ~(1<<scmd_id(SCp));
905
909 SCp->device->tagged_supported = 0; 906 SCp->device->tagged_supported = 0;
910 scsi_deactivate_tcq(SCp->device, host->cmd_per_lun); 907 scsi_change_queue_depth(SCp->device, host->cmd_per_lun);
908 scsi_set_tag_type(SCp->device, 0);
911 } else { 909 } else {
912 shost_printk(KERN_WARNING, host, 910 shost_printk(KERN_WARNING, host,
913 "(%d:%d) Unexpected REJECT Message %s\n", 911 "(%d:%d) Unexpected REJECT Message %s\n",
@@ -1432,7 +1430,7 @@ NCR_700_start_command(struct scsi_cmnd *SCp)
1432 if((hostdata->tag_negotiated & (1<<scmd_id(SCp))) 1430 if((hostdata->tag_negotiated & (1<<scmd_id(SCp)))
1433 && (slot->tag != SCSI_NO_TAG && SCp->cmnd[0] != REQUEST_SENSE && 1431 && (slot->tag != SCSI_NO_TAG && SCp->cmnd[0] != REQUEST_SENSE &&
1434 slot->flags != NCR_700_FLAG_AUTOSENSE)) { 1432 slot->flags != NCR_700_FLAG_AUTOSENSE)) {
1435 count += scsi_populate_tag_msg(SCp, &hostdata->msgout[count]); 1433 count += spi_populate_tag_msg(&hostdata->msgout[count], SCp);
1436 } 1434 }
1437 1435
1438 if(hostdata->fast && 1436 if(hostdata->fast &&
@@ -1772,7 +1770,7 @@ NCR_700_queuecommand_lck(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *)
1772 */ 1770 */
1773 if(NCR_700_get_depth(SCp->device) != 0 1771 if(NCR_700_get_depth(SCp->device) != 0
1774 && (!(hostdata->tag_negotiated & (1<<scmd_id(SCp))) 1772 && (!(hostdata->tag_negotiated & (1<<scmd_id(SCp)))
1775 || !blk_rq_tagged(SCp->request))) { 1773 || !(SCp->flags & SCMD_TAGGED))) {
1776 CDEBUG(KERN_ERR, SCp, "has non zero depth %d\n", 1774 CDEBUG(KERN_ERR, SCp, "has non zero depth %d\n",
1777 NCR_700_get_depth(SCp->device)); 1775 NCR_700_get_depth(SCp->device));
1778 return SCSI_MLQUEUE_DEVICE_BUSY; 1776 return SCSI_MLQUEUE_DEVICE_BUSY;
@@ -1800,7 +1798,7 @@ NCR_700_queuecommand_lck(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *)
1800 printk("53c700: scsi%d, command ", SCp->device->host->host_no); 1798 printk("53c700: scsi%d, command ", SCp->device->host->host_no);
1801 scsi_print_command(SCp); 1799 scsi_print_command(SCp);
1802#endif 1800#endif
1803 if(blk_rq_tagged(SCp->request) 1801 if ((SCp->flags & SCMD_TAGGED)
1804 && (hostdata->tag_negotiated &(1<<scmd_id(SCp))) == 0 1802 && (hostdata->tag_negotiated &(1<<scmd_id(SCp))) == 0
1805 && NCR_700_get_tag_neg_state(SCp->device) == NCR_700_START_TAG_NEGOTIATION) { 1803 && NCR_700_get_tag_neg_state(SCp->device) == NCR_700_START_TAG_NEGOTIATION) {
1806 scmd_printk(KERN_ERR, SCp, "Enabling Tag Command Queuing\n"); 1804 scmd_printk(KERN_ERR, SCp, "Enabling Tag Command Queuing\n");
@@ -1814,7 +1812,7 @@ NCR_700_queuecommand_lck(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *)
1814 * 1812 *
1815 * FIXME: This will royally screw up on multiple LUN devices 1813 * FIXME: This will royally screw up on multiple LUN devices
1816 * */ 1814 * */
1817 if(!blk_rq_tagged(SCp->request) 1815 if (!(SCp->flags & SCMD_TAGGED)
1818 && (hostdata->tag_negotiated &(1<<scmd_id(SCp)))) { 1816 && (hostdata->tag_negotiated &(1<<scmd_id(SCp)))) {
1819 scmd_printk(KERN_INFO, SCp, "Disabling Tag Command Queuing\n"); 1817 scmd_printk(KERN_INFO, SCp, "Disabling Tag Command Queuing\n");
1820 hostdata->tag_negotiated &= ~(1<<scmd_id(SCp)); 1818 hostdata->tag_negotiated &= ~(1<<scmd_id(SCp));
@@ -1911,9 +1909,7 @@ NCR_700_abort(struct scsi_cmnd * SCp)
1911{ 1909{
1912 struct NCR_700_command_slot *slot; 1910 struct NCR_700_command_slot *slot;
1913 1911
1914 scmd_printk(KERN_INFO, SCp, 1912 scmd_printk(KERN_INFO, SCp, "abort command\n");
1915 "New error handler wants to abort command\n\t");
1916 scsi_print_command(SCp);
1917 1913
1918 slot = (struct NCR_700_command_slot *)SCp->host_scribble; 1914 slot = (struct NCR_700_command_slot *)SCp->host_scribble;
1919 1915
@@ -2056,13 +2052,10 @@ NCR_700_slave_configure(struct scsi_device *SDp)
2056 2052
2057 /* to do here: allocate memory; build a queue_full list */ 2053 /* to do here: allocate memory; build a queue_full list */
2058 if(SDp->tagged_supported) { 2054 if(SDp->tagged_supported) {
2059 scsi_set_tag_type(SDp, MSG_ORDERED_TAG); 2055 scsi_change_queue_depth(SDp, NCR_700_DEFAULT_TAGS);
2060 scsi_activate_tcq(SDp, NCR_700_DEFAULT_TAGS);
2061 NCR_700_set_tag_neg_state(SDp, NCR_700_START_TAG_NEGOTIATION); 2056 NCR_700_set_tag_neg_state(SDp, NCR_700_START_TAG_NEGOTIATION);
2062 } else {
2063 /* initialise to default depth */
2064 scsi_adjust_queue_depth(SDp, 0, SDp->host->cmd_per_lun);
2065 } 2057 }
2058
2066 if(hostdata->fast) { 2059 if(hostdata->fast) {
2067 /* Find the correct offset and period via domain validation */ 2060 /* Find the correct offset and period via domain validation */
2068 if (!spi_initial_dv(SDp->sdev_target)) 2061 if (!spi_initial_dv(SDp->sdev_target))
@@ -2082,16 +2075,11 @@ NCR_700_slave_destroy(struct scsi_device *SDp)
2082} 2075}
2083 2076
2084static int 2077static int
2085NCR_700_change_queue_depth(struct scsi_device *SDp, int depth, int reason) 2078NCR_700_change_queue_depth(struct scsi_device *SDp, int depth)
2086{ 2079{
2087 if (reason != SCSI_QDEPTH_DEFAULT)
2088 return -EOPNOTSUPP;
2089
2090 if (depth > NCR_700_MAX_TAGS) 2080 if (depth > NCR_700_MAX_TAGS)
2091 depth = NCR_700_MAX_TAGS; 2081 depth = NCR_700_MAX_TAGS;
2092 2082 return scsi_change_queue_depth(SDp, depth);
2093 scsi_adjust_queue_depth(SDp, scsi_get_tag_type(SDp), depth);
2094 return depth;
2095} 2083}
2096 2084
2097static int NCR_700_change_queue_type(struct scsi_device *SDp, int tag_type) 2085static int NCR_700_change_queue_type(struct scsi_device *SDp, int tag_type)
@@ -2101,8 +2089,6 @@ static int NCR_700_change_queue_type(struct scsi_device *SDp, int tag_type)
2101 struct NCR_700_Host_Parameters *hostdata = 2089 struct NCR_700_Host_Parameters *hostdata =
2102 (struct NCR_700_Host_Parameters *)SDp->host->hostdata[0]; 2090 (struct NCR_700_Host_Parameters *)SDp->host->hostdata[0];
2103 2091
2104 scsi_set_tag_type(SDp, tag_type);
2105
2106 /* We have a global (per target) flag to track whether TCQ is 2092 /* We have a global (per target) flag to track whether TCQ is
2107 * enabled, so we'll be turning it off for the entire target here. 2093 * enabled, so we'll be turning it off for the entire target here.
2108 * our tag algorithm will fail if we mix tagged and untagged commands, 2094 * our tag algorithm will fail if we mix tagged and untagged commands,
@@ -2110,15 +2096,16 @@ static int NCR_700_change_queue_type(struct scsi_device *SDp, int tag_type)
2110 if (change_tag) 2096 if (change_tag)
2111 scsi_target_quiesce(SDp->sdev_target); 2097 scsi_target_quiesce(SDp->sdev_target);
2112 2098
2099 scsi_set_tag_type(SDp, tag_type);
2113 if (!tag_type) { 2100 if (!tag_type) {
2114 /* shift back to the default unqueued number of commands 2101 /* shift back to the default unqueued number of commands
2115 * (the user can still raise this) */ 2102 * (the user can still raise this) */
2116 scsi_deactivate_tcq(SDp, SDp->host->cmd_per_lun); 2103 scsi_change_queue_depth(SDp, SDp->host->cmd_per_lun);
2117 hostdata->tag_negotiated &= ~(1 << sdev_id(SDp)); 2104 hostdata->tag_negotiated &= ~(1 << sdev_id(SDp));
2118 } else { 2105 } else {
2119 /* Here, we cleared the negotiation flag above, so this 2106 /* Here, we cleared the negotiation flag above, so this
2120 * will force the driver to renegotiate */ 2107 * will force the driver to renegotiate */
2121 scsi_activate_tcq(SDp, SDp->queue_depth); 2108 scsi_change_queue_depth(SDp, SDp->queue_depth);
2122 if (change_tag) 2109 if (change_tag)
2123 NCR_700_set_tag_neg_state(SDp, NCR_700_START_TAG_NEGOTIATION); 2110 NCR_700_set_tag_neg_state(SDp, NCR_700_START_TAG_NEGOTIATION);
2124 } 2111 }
diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index 64c75143c89a..8d66a6469e29 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -2327,12 +2327,12 @@ static int blogic_slaveconfig(struct scsi_device *dev)
2327 if (qdepth == 0) 2327 if (qdepth == 0)
2328 qdepth = BLOGIC_MAX_AUTO_TAG_DEPTH; 2328 qdepth = BLOGIC_MAX_AUTO_TAG_DEPTH;
2329 adapter->qdepth[tgt_id] = qdepth; 2329 adapter->qdepth[tgt_id] = qdepth;
2330 scsi_adjust_queue_depth(dev, MSG_SIMPLE_TAG, qdepth); 2330 scsi_change_queue_depth(dev, qdepth);
2331 } else { 2331 } else {
2332 adapter->tagq_ok &= ~(1 << tgt_id); 2332 adapter->tagq_ok &= ~(1 << tgt_id);
2333 qdepth = adapter->untag_qdepth; 2333 qdepth = adapter->untag_qdepth;
2334 adapter->qdepth[tgt_id] = qdepth; 2334 adapter->qdepth[tgt_id] = qdepth;
2335 scsi_adjust_queue_depth(dev, 0, qdepth); 2335 scsi_change_queue_depth(dev, qdepth);
2336 } 2336 }
2337 qdepth = 0; 2337 qdepth = 0;
2338 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) 2338 for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 3a820f61ce65..86cf3d671eb9 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1341,13 +1341,15 @@ config SCSI_DC395x
1341 To compile this driver as a module, choose M here: the 1341 To compile this driver as a module, choose M here: the
1342 module will be called dc395x. 1342 module will be called dc395x.
1343 1343
1344config SCSI_DC390T 1344config SCSI_AM53C974
1345 tristate "Tekram DC390(T) and Am53/79C974 SCSI support" 1345 tristate "Tekram DC390(T) and Am53/79C974 SCSI support (new driver)"
1346 depends on PCI && SCSI 1346 depends on PCI && SCSI
1347 select SCSI_SPI_ATTRS
1347 ---help--- 1348 ---help---
1348 This driver supports PCI SCSI host adapters based on the Am53C974A 1349 This driver supports PCI SCSI host adapters based on the Am53C974A
1349 chip, e.g. Tekram DC390(T), DawiControl 2974 and some onboard 1350 chip, e.g. Tekram DC390(T), DawiControl 2974 and some onboard
1350 PCscsi/PCnet (Am53/79C974) solutions. 1351 PCscsi/PCnet (Am53/79C974) solutions.
1352 This is a new implementation base on the generic esp_scsi driver.
1351 1353
1352 Documentation can be found in <file:Documentation/scsi/tmscsim.txt>. 1354 Documentation can be found in <file:Documentation/scsi/tmscsim.txt>.
1353 1355
@@ -1355,7 +1357,7 @@ config SCSI_DC390T
1355 based on NCR/Symbios chips. Use "NCR53C8XX SCSI support" for those. 1357 based on NCR/Symbios chips. Use "NCR53C8XX SCSI support" for those.
1356 1358
1357 To compile this driver as a module, choose M here: the 1359 To compile this driver as a module, choose M here: the
1358 module will be called tmscsim. 1360 module will be called am53c974.
1359 1361
1360config SCSI_T128 1362config SCSI_T128
1361 tristate "Trantor T128/T128F/T228 SCSI support" 1363 tristate "Trantor T128/T128F/T228 SCSI support"
@@ -1451,6 +1453,14 @@ config SCSI_NSP32
1451 To compile this driver as a module, choose M here: the 1453 To compile this driver as a module, choose M here: the
1452 module will be called nsp32. 1454 module will be called nsp32.
1453 1455
1456config SCSI_WD719X
1457 tristate "Western Digital WD7193/7197/7296 support"
1458 depends on PCI && SCSI
1459 select EEPROM_93CX6
1460 ---help---
1461 This is a driver for Western Digital WD7193, WD7197 and WD7296 PCI
1462 SCSI controllers (based on WD33C296A chip).
1463
1454config SCSI_DEBUG 1464config SCSI_DEBUG
1455 tristate "SCSI debugging host simulator" 1465 tristate "SCSI debugging host simulator"
1456 depends on SCSI 1466 depends on SCSI
@@ -1615,7 +1625,7 @@ config ATARI_SCSI_RESET_BOOT
1615 that leave the devices with SCSI operations partway completed. 1625 that leave the devices with SCSI operations partway completed.
1616 1626
1617config MAC_SCSI 1627config MAC_SCSI
1618 bool "Macintosh NCR5380 SCSI" 1628 tristate "Macintosh NCR5380 SCSI"
1619 depends on MAC && SCSI=y 1629 depends on MAC && SCSI=y
1620 select SCSI_SPI_ATTRS 1630 select SCSI_SPI_ATTRS
1621 help 1631 help
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index 59f1ce6df2d6..58158f11ed7b 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -100,7 +100,7 @@ obj-$(CONFIG_SCSI_EATA_PIO) += eata_pio.o
100obj-$(CONFIG_SCSI_7000FASST) += wd7000.o 100obj-$(CONFIG_SCSI_7000FASST) += wd7000.o
101obj-$(CONFIG_SCSI_EATA) += eata.o 101obj-$(CONFIG_SCSI_EATA) += eata.o
102obj-$(CONFIG_SCSI_DC395x) += dc395x.o 102obj-$(CONFIG_SCSI_DC395x) += dc395x.o
103obj-$(CONFIG_SCSI_DC390T) += tmscsim.o 103obj-$(CONFIG_SCSI_AM53C974) += esp_scsi.o am53c974.o
104obj-$(CONFIG_MEGARAID_LEGACY) += megaraid.o 104obj-$(CONFIG_MEGARAID_LEGACY) += megaraid.o
105obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/ 105obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/
106obj-$(CONFIG_MEGARAID_SAS) += megaraid/ 106obj-$(CONFIG_MEGARAID_SAS) += megaraid/
@@ -143,6 +143,7 @@ obj-$(CONFIG_SCSI_VIRTIO) += virtio_scsi.o
143obj-$(CONFIG_VMWARE_PVSCSI) += vmw_pvscsi.o 143obj-$(CONFIG_VMWARE_PVSCSI) += vmw_pvscsi.o
144obj-$(CONFIG_XEN_SCSI_FRONTEND) += xen-scsifront.o 144obj-$(CONFIG_XEN_SCSI_FRONTEND) += xen-scsifront.o
145obj-$(CONFIG_HYPERV_STORAGE) += hv_storvsc.o 145obj-$(CONFIG_HYPERV_STORAGE) += hv_storvsc.o
146obj-$(CONFIG_SCSI_WD719X) += wd719x.o
146 147
147obj-$(CONFIG_ARM) += arm/ 148obj-$(CONFIG_ARM) += arm/
148 149
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 45da3c823322..36244d63def2 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -11,8 +11,6 @@
11 * drew@colorado.edu 11 * drew@colorado.edu
12 * +1 (303) 666-5836 12 * +1 (303) 666-5836
13 * 13 *
14 * DISTRIBUTION RELEASE 6.
15 *
16 * For more information, please consult 14 * For more information, please consult
17 * 15 *
18 * NCR 5380 Family 16 * NCR 5380 Family
@@ -279,7 +277,7 @@ static void do_reset(struct Scsi_Host *host);
279 * Set up the internal fields in the SCSI command. 277 * Set up the internal fields in the SCSI command.
280 */ 278 */
281 279
282static __inline__ void initialize_SCp(Scsi_Cmnd * cmd) 280static inline void initialize_SCp(struct scsi_cmnd *cmd)
283{ 281{
284 /* 282 /*
285 * Initialize the Scsi Pointer field so that all of the commands in the 283 * Initialize the Scsi Pointer field so that all of the commands in the
@@ -574,12 +572,12 @@ static int __init __maybe_unused NCR5380_probe_irq(struct Scsi_Host *instance,
574 int trying_irqs, i, mask; 572 int trying_irqs, i, mask;
575 NCR5380_setup(instance); 573 NCR5380_setup(instance);
576 574
577 for (trying_irqs = i = 0, mask = 1; i < 16; ++i, mask <<= 1) 575 for (trying_irqs = 0, i = 1, mask = 2; i < 16; ++i, mask <<= 1)
578 if ((mask & possible) && (request_irq(i, &probe_intr, 0, "NCR-probe", NULL) == 0)) 576 if ((mask & possible) && (request_irq(i, &probe_intr, 0, "NCR-probe", NULL) == 0))
579 trying_irqs |= mask; 577 trying_irqs |= mask;
580 578
581 timeout = jiffies + (250 * HZ / 1000); 579 timeout = jiffies + (250 * HZ / 1000);
582 probe_irq = SCSI_IRQ_NONE; 580 probe_irq = NO_IRQ;
583 581
584 /* 582 /*
585 * A interrupt is triggered whenever BSY = false, SEL = true 583 * A interrupt is triggered whenever BSY = false, SEL = true
@@ -596,13 +594,13 @@ static int __init __maybe_unused NCR5380_probe_irq(struct Scsi_Host *instance,
596 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask); 594 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
597 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA | ICR_ASSERT_SEL); 595 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA | ICR_ASSERT_SEL);
598 596
599 while (probe_irq == SCSI_IRQ_NONE && time_before(jiffies, timeout)) 597 while (probe_irq == NO_IRQ && time_before(jiffies, timeout))
600 schedule_timeout_uninterruptible(1); 598 schedule_timeout_uninterruptible(1);
601 599
602 NCR5380_write(SELECT_ENABLE_REG, 0); 600 NCR5380_write(SELECT_ENABLE_REG, 0);
603 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 601 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
604 602
605 for (i = 0, mask = 1; i < 16; ++i, mask <<= 1) 603 for (i = 1, mask = 2; i < 16; ++i, mask <<= 1)
606 if (trying_irqs & mask) 604 if (trying_irqs & mask)
607 free_irq(i, NULL); 605 free_irq(i, NULL);
608 606
@@ -610,50 +608,70 @@ static int __init __maybe_unused NCR5380_probe_irq(struct Scsi_Host *instance,
610} 608}
611 609
612/** 610/**
613 * NCR58380_print_options - show options 611 * NCR58380_info - report driver and host information
614 * @instance: unused for now 612 * @instance: relevant scsi host instance
615 * 613 *
616 * Called by probe code indicating the NCR5380 driver options that 614 * For use as the host template info() handler.
617 * were selected. At some point this will switch to runtime options
618 * read from the adapter in question
619 * 615 *
620 * Locks: none 616 * Locks: none
621 */ 617 */
622 618
623static void __init __maybe_unused 619static const char *NCR5380_info(struct Scsi_Host *instance)
624NCR5380_print_options(struct Scsi_Host *instance)
625{ 620{
626 printk(" generic options" 621 struct NCR5380_hostdata *hostdata = shost_priv(instance);
627#ifdef AUTOPROBE_IRQ 622
628 " AUTOPROBE_IRQ" 623 return hostdata->info;
624}
625
626static void prepare_info(struct Scsi_Host *instance)
627{
628 struct NCR5380_hostdata *hostdata = shost_priv(instance);
629
630 snprintf(hostdata->info, sizeof(hostdata->info),
631 "%s, io_port 0x%lx, n_io_port %d, "
632 "base 0x%lx, irq %d, "
633 "can_queue %d, cmd_per_lun %d, "
634 "sg_tablesize %d, this_id %d, "
635 "flags { %s%s%s}, "
636#if defined(USLEEP_POLL) && defined(USLEEP_WAITLONG)
637 "USLEEP_POLL %d, USLEEP_WAITLONG %d, "
629#endif 638#endif
630#ifdef AUTOSENSE 639 "options { %s} ",
631 " AUTOSENSE" 640 instance->hostt->name, instance->io_port, instance->n_io_port,
641 instance->base, instance->irq,
642 instance->can_queue, instance->cmd_per_lun,
643 instance->sg_tablesize, instance->this_id,
644 hostdata->flags & FLAG_NCR53C400 ? "NCR53C400 " : "",
645 hostdata->flags & FLAG_DTC3181E ? "DTC3181E " : "",
646 hostdata->flags & FLAG_NO_PSEUDO_DMA ? "NO_PSEUDO_DMA " : "",
647#if defined(USLEEP_POLL) && defined(USLEEP_WAITLONG)
648 USLEEP_POLL, USLEEP_WAITLONG,
649#endif
650#ifdef AUTOPROBE_IRQ
651 "AUTOPROBE_IRQ "
632#endif 652#endif
633#ifdef DIFFERENTIAL 653#ifdef DIFFERENTIAL
634 " DIFFERENTIAL" 654 "DIFFERENTIAL "
635#endif 655#endif
636#ifdef REAL_DMA 656#ifdef REAL_DMA
637 " REAL DMA" 657 "REAL_DMA "
638#endif 658#endif
639#ifdef REAL_DMA_POLL 659#ifdef REAL_DMA_POLL
640 " REAL DMA POLL" 660 "REAL_DMA_POLL "
641#endif 661#endif
642#ifdef PARITY 662#ifdef PARITY
643 " PARITY" 663 "PARITY "
644#endif 664#endif
645#ifdef PSEUDO_DMA 665#ifdef PSEUDO_DMA
646 " PSEUDO DMA" 666 "PSEUDO_DMA "
647#endif 667#endif
648#ifdef UNSAFE 668#ifdef UNSAFE
649 " UNSAFE " 669 "UNSAFE "
650#endif 670#endif
651 ); 671#ifdef NCR53C400
652 printk(" USLEEP, USLEEP_POLL=%d USLEEP_SLEEP=%d", USLEEP_POLL, USLEEP_SLEEP); 672 "NCR53C400 "
653 printk(" generic release=%d", NCR5380_PUBLIC_RELEASE); 673#endif
654 if (((struct NCR5380_hostdata *) instance->hostdata)->flags & FLAG_NCR53C400) { 674 "");
655 printk(" ncr53c400 release=%d", NCR53C400_PUBLIC_RELEASE);
656 }
657} 675}
658 676
659/** 677/**
@@ -672,6 +690,7 @@ static void NCR5380_print_status(struct Scsi_Host *instance)
672 NCR5380_dprint_phase(NDEBUG_ANY, instance); 690 NCR5380_dprint_phase(NDEBUG_ANY, instance);
673} 691}
674 692
693#ifdef PSEUDO_DMA
675/******************************************/ 694/******************************************/
676/* 695/*
677 * /proc/scsi/[dtc pas16 t128 generic]/[0-ASC_NUM_BOARD_SUPPORTED] 696 * /proc/scsi/[dtc pas16 t128 generic]/[0-ASC_NUM_BOARD_SUPPORTED]
@@ -689,19 +708,18 @@ static void NCR5380_print_status(struct Scsi_Host *instance)
689static int __maybe_unused NCR5380_write_info(struct Scsi_Host *instance, 708static int __maybe_unused NCR5380_write_info(struct Scsi_Host *instance,
690 char *buffer, int length) 709 char *buffer, int length)
691{ 710{
692#ifdef DTC_PUBLIC_RELEASE 711 struct NCR5380_hostdata *hostdata = shost_priv(instance);
693 dtc_wmaxi = dtc_maxi = 0; 712
694#endif 713 hostdata->spin_max_r = 0;
695#ifdef PAS16_PUBLIC_RELEASE 714 hostdata->spin_max_w = 0;
696 pas_wmaxi = pas_maxi = 0; 715 return 0;
697#endif
698 return (-ENOSYS); /* Currently this is a no-op */
699} 716}
717#endif
700 718
701#undef SPRINTF 719#undef SPRINTF
702#define SPRINTF(args...) seq_printf(m, ## args) 720#define SPRINTF(args...) seq_printf(m, ## args)
703static 721static
704void lprint_Scsi_Cmnd(Scsi_Cmnd * cmd, struct seq_file *m); 722void lprint_Scsi_Cmnd(struct scsi_cmnd *cmd, struct seq_file *m);
705static 723static
706void lprint_command(unsigned char *cmd, struct seq_file *m); 724void lprint_command(unsigned char *cmd, struct seq_file *m);
707static 725static
@@ -711,56 +729,31 @@ static int __maybe_unused NCR5380_show_info(struct seq_file *m,
711 struct Scsi_Host *instance) 729 struct Scsi_Host *instance)
712{ 730{
713 struct NCR5380_hostdata *hostdata; 731 struct NCR5380_hostdata *hostdata;
714 Scsi_Cmnd *ptr; 732 struct scsi_cmnd *ptr;
715 733
716 hostdata = (struct NCR5380_hostdata *) instance->hostdata; 734 hostdata = (struct NCR5380_hostdata *) instance->hostdata;
717 735
718 SPRINTF("NCR5380 core release=%d. ", NCR5380_PUBLIC_RELEASE); 736#ifdef PSEUDO_DMA
719 if (((struct NCR5380_hostdata *) instance->hostdata)->flags & FLAG_NCR53C400) 737 SPRINTF("Highwater I/O busy spin counts: write %d, read %d\n",
720 SPRINTF("ncr53c400 release=%d. ", NCR53C400_PUBLIC_RELEASE); 738 hostdata->spin_max_w, hostdata->spin_max_r);
721#ifdef DTC_PUBLIC_RELEASE
722 SPRINTF("DTC 3180/3280 release %d", DTC_PUBLIC_RELEASE);
723#endif
724#ifdef T128_PUBLIC_RELEASE
725 SPRINTF("T128 release %d", T128_PUBLIC_RELEASE);
726#endif
727#ifdef GENERIC_NCR5380_PUBLIC_RELEASE
728 SPRINTF("Generic5380 release %d", GENERIC_NCR5380_PUBLIC_RELEASE);
729#endif
730#ifdef PAS16_PUBLIC_RELEASE
731 SPRINTF("PAS16 release=%d", PAS16_PUBLIC_RELEASE);
732#endif
733
734 SPRINTF("\nBase Addr: 0x%05lX ", (long) instance->base);
735 SPRINTF("io_port: %04x ", (int) instance->io_port);
736 if (instance->irq == SCSI_IRQ_NONE)
737 SPRINTF("IRQ: None.\n");
738 else
739 SPRINTF("IRQ: %d.\n", instance->irq);
740
741#ifdef DTC_PUBLIC_RELEASE
742 SPRINTF("Highwater I/O busy_spin_counts -- write: %d read: %d\n", dtc_wmaxi, dtc_maxi);
743#endif
744#ifdef PAS16_PUBLIC_RELEASE
745 SPRINTF("Highwater I/O busy_spin_counts -- write: %d read: %d\n", pas_wmaxi, pas_maxi);
746#endif 739#endif
747 spin_lock_irq(instance->host_lock); 740 spin_lock_irq(instance->host_lock);
748 if (!hostdata->connected) 741 if (!hostdata->connected)
749 SPRINTF("scsi%d: no currently connected command\n", instance->host_no); 742 SPRINTF("scsi%d: no currently connected command\n", instance->host_no);
750 else 743 else
751 lprint_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected, m); 744 lprint_Scsi_Cmnd((struct scsi_cmnd *) hostdata->connected, m);
752 SPRINTF("scsi%d: issue_queue\n", instance->host_no); 745 SPRINTF("scsi%d: issue_queue\n", instance->host_no);
753 for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble) 746 for (ptr = (struct scsi_cmnd *) hostdata->issue_queue; ptr; ptr = (struct scsi_cmnd *) ptr->host_scribble)
754 lprint_Scsi_Cmnd(ptr, m); 747 lprint_Scsi_Cmnd(ptr, m);
755 748
756 SPRINTF("scsi%d: disconnected_queue\n", instance->host_no); 749 SPRINTF("scsi%d: disconnected_queue\n", instance->host_no);
757 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble) 750 for (ptr = (struct scsi_cmnd *) hostdata->disconnected_queue; ptr; ptr = (struct scsi_cmnd *) ptr->host_scribble)
758 lprint_Scsi_Cmnd(ptr, m); 751 lprint_Scsi_Cmnd(ptr, m);
759 spin_unlock_irq(instance->host_lock); 752 spin_unlock_irq(instance->host_lock);
760 return 0; 753 return 0;
761} 754}
762 755
763static void lprint_Scsi_Cmnd(Scsi_Cmnd * cmd, struct seq_file *m) 756static void lprint_Scsi_Cmnd(struct scsi_cmnd *cmd, struct seq_file *m)
764{ 757{
765 SPRINTF("scsi%d : destination target %d, lun %llu\n", cmd->device->host->host_no, cmd->device->id, cmd->device->lun); 758 SPRINTF("scsi%d : destination target %d, lun %llu\n", cmd->device->host->host_no, cmd->device->id, cmd->device->lun);
766 SPRINTF(" command = "); 759 SPRINTF(" command = ");
@@ -836,18 +829,6 @@ static int NCR5380_init(struct Scsi_Host *instance, int flags)
836 829
837 INIT_DELAYED_WORK(&hostdata->coroutine, NCR5380_main); 830 INIT_DELAYED_WORK(&hostdata->coroutine, NCR5380_main);
838 831
839#ifdef NCR5380_STATS
840 for (i = 0; i < 8; ++i) {
841 hostdata->time_read[i] = 0;
842 hostdata->time_write[i] = 0;
843 hostdata->bytes_read[i] = 0;
844 hostdata->bytes_write[i] = 0;
845 }
846 hostdata->timebase = 0;
847 hostdata->pendingw = 0;
848 hostdata->pendingr = 0;
849#endif
850
851 /* The CHECK code seems to break the 53C400. Will check it later maybe */ 832 /* The CHECK code seems to break the 53C400. Will check it later maybe */
852 if (flags & FLAG_NCR53C400) 833 if (flags & FLAG_NCR53C400)
853 hostdata->flags = FLAG_HAS_LAST_BYTE_SENT | flags; 834 hostdata->flags = FLAG_HAS_LAST_BYTE_SENT | flags;
@@ -857,11 +838,7 @@ static int NCR5380_init(struct Scsi_Host *instance, int flags)
857 hostdata->host = instance; 838 hostdata->host = instance;
858 hostdata->time_expires = 0; 839 hostdata->time_expires = 0;
859 840
860#ifndef AUTOSENSE 841 prepare_info(instance);
861 if ((instance->cmd_per_lun > 1) || instance->can_queue > 1)
862 printk(KERN_WARNING "scsi%d : WARNING : support for multiple outstanding commands enabled\n" " without AUTOSENSE option, contingent allegiance conditions may\n"
863 " be incorrectly cleared.\n", instance->host_no);
864#endif /* def AUTOSENSE */
865 842
866 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 843 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
867 NCR5380_write(MODE_REG, MR_BASE); 844 NCR5380_write(MODE_REG, MR_BASE);
@@ -935,11 +912,11 @@ static void NCR5380_exit(struct Scsi_Host *instance)
935 * Locks: host lock taken by caller 912 * Locks: host lock taken by caller
936 */ 913 */
937 914
938static int NCR5380_queue_command_lck(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)) 915static int NCR5380_queue_command_lck(struct scsi_cmnd *cmd, void (*done) (struct scsi_cmnd *))
939{ 916{
940 struct Scsi_Host *instance = cmd->device->host; 917 struct Scsi_Host *instance = cmd->device->host;
941 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata; 918 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata;
942 Scsi_Cmnd *tmp; 919 struct scsi_cmnd *tmp;
943 920
944#if (NDEBUG & NDEBUG_NO_WRITE) 921#if (NDEBUG & NDEBUG_NO_WRITE)
945 switch (cmd->cmnd[0]) { 922 switch (cmd->cmnd[0]) {
@@ -952,25 +929,6 @@ static int NCR5380_queue_command_lck(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)
952 } 929 }
953#endif /* (NDEBUG & NDEBUG_NO_WRITE) */ 930#endif /* (NDEBUG & NDEBUG_NO_WRITE) */
954 931
955#ifdef NCR5380_STATS
956 switch (cmd->cmnd[0]) {
957 case WRITE:
958 case WRITE_6:
959 case WRITE_10:
960 hostdata->time_write[cmd->device->id] -= (jiffies - hostdata->timebase);
961 hostdata->bytes_write[cmd->device->id] += scsi_bufflen(cmd);
962 hostdata->pendingw++;
963 break;
964 case READ:
965 case READ_6:
966 case READ_10:
967 hostdata->time_read[cmd->device->id] -= (jiffies - hostdata->timebase);
968 hostdata->bytes_read[cmd->device->id] += scsi_bufflen(cmd);
969 hostdata->pendingr++;
970 break;
971 }
972#endif
973
974 /* 932 /*
975 * We use the host_scribble field as a pointer to the next command 933 * We use the host_scribble field as a pointer to the next command
976 * in a queue 934 * in a queue
@@ -992,7 +950,7 @@ static int NCR5380_queue_command_lck(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *)
992 cmd->host_scribble = (unsigned char *) hostdata->issue_queue; 950 cmd->host_scribble = (unsigned char *) hostdata->issue_queue;
993 hostdata->issue_queue = cmd; 951 hostdata->issue_queue = cmd;
994 } else { 952 } else {
995 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue; tmp->host_scribble; tmp = (Scsi_Cmnd *) tmp->host_scribble); 953 for (tmp = (struct scsi_cmnd *) hostdata->issue_queue; tmp->host_scribble; tmp = (struct scsi_cmnd *) tmp->host_scribble);
996 LIST(cmd, tmp); 954 LIST(cmd, tmp);
997 tmp->host_scribble = (unsigned char *) cmd; 955 tmp->host_scribble = (unsigned char *) cmd;
998 } 956 }
@@ -1023,7 +981,7 @@ static void NCR5380_main(struct work_struct *work)
1023 struct NCR5380_hostdata *hostdata = 981 struct NCR5380_hostdata *hostdata =
1024 container_of(work, struct NCR5380_hostdata, coroutine.work); 982 container_of(work, struct NCR5380_hostdata, coroutine.work);
1025 struct Scsi_Host *instance = hostdata->host; 983 struct Scsi_Host *instance = hostdata->host;
1026 Scsi_Cmnd *tmp, *prev; 984 struct scsi_cmnd *tmp, *prev;
1027 int done; 985 int done;
1028 986
1029 spin_lock_irq(instance->host_lock); 987 spin_lock_irq(instance->host_lock);
@@ -1036,7 +994,7 @@ static void NCR5380_main(struct work_struct *work)
1036 * Search through the issue_queue for a command destined 994 * Search through the issue_queue for a command destined
1037 * for a target that's not busy. 995 * for a target that's not busy.
1038 */ 996 */
1039 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue, prev = NULL; tmp; prev = tmp, tmp = (Scsi_Cmnd *) tmp->host_scribble) 997 for (tmp = (struct scsi_cmnd *) hostdata->issue_queue, prev = NULL; tmp; prev = tmp, tmp = (struct scsi_cmnd *) tmp->host_scribble)
1040 { 998 {
1041 if (prev != tmp) 999 if (prev != tmp)
1042 dprintk(NDEBUG_LISTS, "MAIN tmp=%p target=%d busy=%d lun=%llu\n", tmp, tmp->device->id, hostdata->busy[tmp->device->id], tmp->device->lun); 1000 dprintk(NDEBUG_LISTS, "MAIN tmp=%p target=%d busy=%d lun=%llu\n", tmp, tmp->device->id, hostdata->busy[tmp->device->id], tmp->device->lun);
@@ -1048,7 +1006,7 @@ static void NCR5380_main(struct work_struct *work)
1048 prev->host_scribble = tmp->host_scribble; 1006 prev->host_scribble = tmp->host_scribble;
1049 } else { 1007 } else {
1050 REMOVE(-1, hostdata->issue_queue, tmp, tmp->host_scribble); 1008 REMOVE(-1, hostdata->issue_queue, tmp, tmp->host_scribble);
1051 hostdata->issue_queue = (Scsi_Cmnd *) tmp->host_scribble; 1009 hostdata->issue_queue = (struct scsi_cmnd *) tmp->host_scribble;
1052 } 1010 }
1053 tmp->host_scribble = NULL; 1011 tmp->host_scribble = NULL;
1054 1012
@@ -1073,14 +1031,14 @@ static void NCR5380_main(struct work_struct *work)
1073 hostdata->selecting = NULL; 1031 hostdata->selecting = NULL;
1074 /* RvC: have to preset this to indicate a new command is being performed */ 1032 /* RvC: have to preset this to indicate a new command is being performed */
1075 1033
1076 if (!NCR5380_select(instance, tmp, 1034 /*
1077 /* 1035 * REQUEST SENSE commands are issued without tagged
1078 * REQUEST SENSE commands are issued without tagged 1036 * queueing, even on SCSI-II devices because the
1079 * queueing, even on SCSI-II devices because the 1037 * contingent allegiance condition exists for the
1080 * contingent allegiance condition exists for the 1038 * entire unit.
1081 * entire unit. 1039 */
1082 */ 1040
1083 (tmp->cmnd[0] == REQUEST_SENSE) ? TAG_NONE : TAG_NEXT)) { 1041 if (!NCR5380_select(instance, tmp)) {
1084 break; 1042 break;
1085 } else { 1043 } else {
1086 LIST(tmp, hostdata->issue_queue); 1044 LIST(tmp, hostdata->issue_queue);
@@ -1095,9 +1053,9 @@ static void NCR5380_main(struct work_struct *work)
1095 /* exited locked */ 1053 /* exited locked */
1096 } /* if (!hostdata->connected) */ 1054 } /* if (!hostdata->connected) */
1097 if (hostdata->selecting) { 1055 if (hostdata->selecting) {
1098 tmp = (Scsi_Cmnd *) hostdata->selecting; 1056 tmp = (struct scsi_cmnd *) hostdata->selecting;
1099 /* Selection will drop and retake the lock */ 1057 /* Selection will drop and retake the lock */
1100 if (!NCR5380_select(instance, tmp, (tmp->cmnd[0] == REQUEST_SENSE) ? TAG_NONE : TAG_NEXT)) { 1058 if (!NCR5380_select(instance, tmp)) {
1101 /* Ok ?? */ 1059 /* Ok ?? */
1102 } else { 1060 } else {
1103 /* RvC: device failed, so we wait a long time 1061 /* RvC: device failed, so we wait a long time
@@ -1216,47 +1174,16 @@ static irqreturn_t NCR5380_intr(int dummy, void *dev_id)
1216 1174
1217#endif 1175#endif
1218 1176
1219/**
1220 * collect_stats - collect stats on a scsi command
1221 * @hostdata: adapter
1222 * @cmd: command being issued
1223 *
1224 * Update the statistical data by parsing the command in question
1225 */
1226
1227static void collect_stats(struct NCR5380_hostdata *hostdata, Scsi_Cmnd * cmd)
1228{
1229#ifdef NCR5380_STATS
1230 switch (cmd->cmnd[0]) {
1231 case WRITE:
1232 case WRITE_6:
1233 case WRITE_10:
1234 hostdata->time_write[scmd_id(cmd)] += (jiffies - hostdata->timebase);
1235 hostdata->pendingw--;
1236 break;
1237 case READ:
1238 case READ_6:
1239 case READ_10:
1240 hostdata->time_read[scmd_id(cmd)] += (jiffies - hostdata->timebase);
1241 hostdata->pendingr--;
1242 break;
1243 }
1244#endif
1245}
1246
1247
1248/* 1177/*
1249 * Function : int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, 1178 * Function : int NCR5380_select(struct Scsi_Host *instance,
1250 * int tag); 1179 * struct scsi_cmnd *cmd)
1251 * 1180 *
1252 * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command, 1181 * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command,
1253 * including ARBITRATION, SELECTION, and initial message out for 1182 * including ARBITRATION, SELECTION, and initial message out for
1254 * IDENTIFY and queue messages. 1183 * IDENTIFY and queue messages.
1255 * 1184 *
1256 * Inputs : instance - instantiation of the 5380 driver on which this 1185 * Inputs : instance - instantiation of the 5380 driver on which this
1257 * target lives, cmd - SCSI command to execute, tag - set to TAG_NEXT for 1186 * target lives, cmd - SCSI command to execute.
1258 * new tag, TAG_NONE for untagged queueing, otherwise set to the tag for
1259 * the command that is presently connected.
1260 * 1187 *
1261 * Returns : -1 if selection could not execute for some reason, 1188 * Returns : -1 if selection could not execute for some reason,
1262 * 0 if selection succeeded or failed because the target 1189 * 0 if selection succeeded or failed because the target
@@ -1278,7 +1205,7 @@ static void collect_stats(struct NCR5380_hostdata *hostdata, Scsi_Cmnd * cmd)
1278 * Locks: caller holds hostdata lock in IRQ mode 1205 * Locks: caller holds hostdata lock in IRQ mode
1279 */ 1206 */
1280 1207
1281static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd * cmd, int tag) 1208static int NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
1282{ 1209{
1283 NCR5380_local_declare(); 1210 NCR5380_local_declare();
1284 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata; 1211 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata;
@@ -1476,7 +1403,6 @@ part2:
1476 return -1; 1403 return -1;
1477 } 1404 }
1478 cmd->result = DID_BAD_TARGET << 16; 1405 cmd->result = DID_BAD_TARGET << 16;
1479 collect_stats(hostdata, cmd);
1480 cmd->scsi_done(cmd); 1406 cmd->scsi_done(cmd);
1481 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 1407 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1482 dprintk(NDEBUG_SELECTION, "scsi%d : target did not respond within 250ms\n", instance->host_no); 1408 dprintk(NDEBUG_SELECTION, "scsi%d : target did not respond within 250ms\n", instance->host_no);
@@ -1513,7 +1439,7 @@ part2:
1513 } 1439 }
1514 1440
1515 dprintk(NDEBUG_SELECTION, "scsi%d : target %d selected, going into MESSAGE OUT phase.\n", instance->host_no, cmd->device->id); 1441 dprintk(NDEBUG_SELECTION, "scsi%d : target %d selected, going into MESSAGE OUT phase.\n", instance->host_no, cmd->device->id);
1516 tmp[0] = IDENTIFY(((instance->irq == SCSI_IRQ_NONE) ? 0 : 1), cmd->device->lun); 1442 tmp[0] = IDENTIFY(((instance->irq == NO_IRQ) ? 0 : 1), cmd->device->lun);
1517 1443
1518 len = 1; 1444 len = 1;
1519 cmd->tag = 0; 1445 cmd->tag = 0;
@@ -2086,7 +2012,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
2086#endif 2012#endif
2087 unsigned char *data; 2013 unsigned char *data;
2088 unsigned char phase, tmp, extended_msg[10], old_phase = 0xff; 2014 unsigned char phase, tmp, extended_msg[10], old_phase = 0xff;
2089 Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected; 2015 struct scsi_cmnd *cmd = (struct scsi_cmnd *) hostdata->connected;
2090 /* RvC: we need to set the end of the polling time */ 2016 /* RvC: we need to set the end of the polling time */
2091 unsigned long poll_time = jiffies + USLEEP_POLL; 2017 unsigned long poll_time = jiffies + USLEEP_POLL;
2092 2018
@@ -2228,7 +2154,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
2228 cmd->next_link->tag = cmd->tag; 2154 cmd->next_link->tag = cmd->tag;
2229 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8); 2155 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2230 dprintk(NDEBUG_LINKED, "scsi%d : target %d lun %llu linked request done, calling scsi_done().\n", instance->host_no, cmd->device->id, cmd->device->lun); 2156 dprintk(NDEBUG_LINKED, "scsi%d : target %d lun %llu linked request done, calling scsi_done().\n", instance->host_no, cmd->device->id, cmd->device->lun);
2231 collect_stats(hostdata, cmd);
2232 cmd->scsi_done(cmd); 2157 cmd->scsi_done(cmd);
2233 cmd = hostdata->connected; 2158 cmd = hostdata->connected;
2234 break; 2159 break;
@@ -2263,7 +2188,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
2263 else if (status_byte(cmd->SCp.Status) != GOOD) 2188 else if (status_byte(cmd->SCp.Status) != GOOD)
2264 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16); 2189 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
2265 2190
2266#ifdef AUTOSENSE
2267 if ((cmd->cmnd[0] == REQUEST_SENSE) && 2191 if ((cmd->cmnd[0] == REQUEST_SENSE) &&
2268 hostdata->ses.cmd_len) { 2192 hostdata->ses.cmd_len) {
2269 scsi_eh_restore_cmnd(cmd, &hostdata->ses); 2193 scsi_eh_restore_cmnd(cmd, &hostdata->ses);
@@ -2278,12 +2202,9 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
2278 LIST(cmd, hostdata->issue_queue); 2202 LIST(cmd, hostdata->issue_queue);
2279 cmd->host_scribble = (unsigned char *) 2203 cmd->host_scribble = (unsigned char *)
2280 hostdata->issue_queue; 2204 hostdata->issue_queue;
2281 hostdata->issue_queue = (Scsi_Cmnd *) cmd; 2205 hostdata->issue_queue = (struct scsi_cmnd *) cmd;
2282 dprintk(NDEBUG_QUEUES, "scsi%d : REQUEST SENSE added to head of issue queue\n", instance->host_no); 2206 dprintk(NDEBUG_QUEUES, "scsi%d : REQUEST SENSE added to head of issue queue\n", instance->host_no);
2283 } else 2207 } else {
2284#endif /* def AUTOSENSE */
2285 {
2286 collect_stats(hostdata, cmd);
2287 cmd->scsi_done(cmd); 2208 cmd->scsi_done(cmd);
2288 } 2209 }
2289 2210
@@ -2430,7 +2351,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
2430 hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xFF)); 2351 hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xFF));
2431 hostdata->connected = NULL; 2352 hostdata->connected = NULL;
2432 cmd->result = DID_ERROR << 16; 2353 cmd->result = DID_ERROR << 16;
2433 collect_stats(hostdata, cmd);
2434 cmd->scsi_done(cmd); 2354 cmd->scsi_done(cmd);
2435 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 2355 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2436 return; 2356 return;
@@ -2479,7 +2399,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) {
2479 * Function : void NCR5380_reselect (struct Scsi_Host *instance) 2399 * Function : void NCR5380_reselect (struct Scsi_Host *instance)
2480 * 2400 *
2481 * Purpose : does reselection, initializing the instance->connected 2401 * Purpose : does reselection, initializing the instance->connected
2482 * field to point to the Scsi_Cmnd for which the I_T_L or I_T_L_Q 2402 * field to point to the scsi_cmnd for which the I_T_L or I_T_L_Q
2483 * nexus has been reestablished, 2403 * nexus has been reestablished,
2484 * 2404 *
2485 * Inputs : instance - this instance of the NCR5380. 2405 * Inputs : instance - this instance of the NCR5380.
@@ -2496,7 +2416,7 @@ static void NCR5380_reselect(struct Scsi_Host *instance) {
2496 int len; 2416 int len;
2497 unsigned char msg[3]; 2417 unsigned char msg[3];
2498 unsigned char *data; 2418 unsigned char *data;
2499 Scsi_Cmnd *tmp = NULL, *prev; 2419 struct scsi_cmnd *tmp = NULL, *prev;
2500 int abort = 0; 2420 int abort = 0;
2501 NCR5380_setup(instance); 2421 NCR5380_setup(instance);
2502 2422
@@ -2562,7 +2482,7 @@ static void NCR5380_reselect(struct Scsi_Host *instance) {
2562 */ 2482 */
2563 2483
2564 2484
2565 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue, prev = NULL; tmp; prev = tmp, tmp = (Scsi_Cmnd *) tmp->host_scribble) 2485 for (tmp = (struct scsi_cmnd *) hostdata->disconnected_queue, prev = NULL; tmp; prev = tmp, tmp = (struct scsi_cmnd *) tmp->host_scribble)
2566 if ((target_mask == (1 << tmp->device->id)) && (lun == (u8)tmp->device->lun) 2486 if ((target_mask == (1 << tmp->device->id)) && (lun == (u8)tmp->device->lun)
2567 ) { 2487 ) {
2568 if (prev) { 2488 if (prev) {
@@ -2570,7 +2490,7 @@ static void NCR5380_reselect(struct Scsi_Host *instance) {
2570 prev->host_scribble = tmp->host_scribble; 2490 prev->host_scribble = tmp->host_scribble;
2571 } else { 2491 } else {
2572 REMOVE(-1, hostdata->disconnected_queue, tmp, tmp->host_scribble); 2492 REMOVE(-1, hostdata->disconnected_queue, tmp, tmp->host_scribble);
2573 hostdata->disconnected_queue = (Scsi_Cmnd *) tmp->host_scribble; 2493 hostdata->disconnected_queue = (struct scsi_cmnd *) tmp->host_scribble;
2574 } 2494 }
2575 tmp->host_scribble = NULL; 2495 tmp->host_scribble = NULL;
2576 break; 2496 break;
@@ -2601,7 +2521,7 @@ static void NCR5380_reselect(struct Scsi_Host *instance) {
2601 * 2521 *
2602 * Inputs : instance - this instance of the NCR5380. 2522 * Inputs : instance - this instance of the NCR5380.
2603 * 2523 *
2604 * Returns : pointer to the Scsi_Cmnd structure for which the I_T_L 2524 * Returns : pointer to the scsi_cmnd structure for which the I_T_L
2605 * nexus has been reestablished, on failure NULL is returned. 2525 * nexus has been reestablished, on failure NULL is returned.
2606 */ 2526 */
2607 2527
@@ -2643,32 +2563,32 @@ static void NCR5380_dma_complete(NCR5380_instance * instance) {
2643#endif /* def REAL_DMA */ 2563#endif /* def REAL_DMA */
2644 2564
2645/* 2565/*
2646 * Function : int NCR5380_abort (Scsi_Cmnd *cmd) 2566 * Function : int NCR5380_abort (struct scsi_cmnd *cmd)
2647 * 2567 *
2648 * Purpose : abort a command 2568 * Purpose : abort a command
2649 * 2569 *
2650 * Inputs : cmd - the Scsi_Cmnd to abort, code - code to set the 2570 * Inputs : cmd - the scsi_cmnd to abort, code - code to set the
2651 * host byte of the result field to, if zero DID_ABORTED is 2571 * host byte of the result field to, if zero DID_ABORTED is
2652 * used. 2572 * used.
2653 * 2573 *
2654 * Returns : 0 - success, -1 on failure. 2574 * Returns : SUCCESS - success, FAILED on failure.
2655 * 2575 *
2656 * XXX - there is no way to abort the command that is currently 2576 * XXX - there is no way to abort the command that is currently
2657 * connected, you have to wait for it to complete. If this is 2577 * connected, you have to wait for it to complete. If this is
2658 * a problem, we could implement longjmp() / setjmp(), setjmp() 2578 * a problem, we could implement longjmp() / setjmp(), setjmp()
2659 * called where the loop started in NCR5380_main(). 2579 * called where the loop started in NCR5380_main().
2660 * 2580 *
2661 * Locks: host lock taken by caller 2581 * Locks: host lock taken by caller
2662 */ 2582 */
2663 2583
2664static int NCR5380_abort(Scsi_Cmnd * cmd) { 2584static int NCR5380_abort(struct scsi_cmnd *cmd)
2585{
2665 NCR5380_local_declare(); 2586 NCR5380_local_declare();
2666 struct Scsi_Host *instance = cmd->device->host; 2587 struct Scsi_Host *instance = cmd->device->host;
2667 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata; 2588 struct NCR5380_hostdata *hostdata = (struct NCR5380_hostdata *) instance->hostdata;
2668 Scsi_Cmnd *tmp, **prev; 2589 struct scsi_cmnd *tmp, **prev;
2669 2590
2670 printk(KERN_WARNING "scsi%d : aborting command\n", instance->host_no); 2591 scmd_printk(KERN_WARNING, cmd, "aborting command\n");
2671 scsi_print_command(cmd);
2672 2592
2673 NCR5380_print_status(instance); 2593 NCR5380_print_status(instance);
2674 2594
@@ -2704,7 +2624,7 @@ static int NCR5380_abort(Scsi_Cmnd * cmd) {
2704 * aborted flag and get back into our main loop. 2624 * aborted flag and get back into our main loop.
2705 */ 2625 */
2706 2626
2707 return 0; 2627 return SUCCESS;
2708 } 2628 }
2709#endif 2629#endif
2710 2630
@@ -2714,10 +2634,10 @@ static int NCR5380_abort(Scsi_Cmnd * cmd) {
2714 */ 2634 */
2715 2635
2716 dprintk(NDEBUG_ABORT, "scsi%d : abort going into loop.\n", instance->host_no); 2636 dprintk(NDEBUG_ABORT, "scsi%d : abort going into loop.\n", instance->host_no);
2717 for (prev = (Scsi_Cmnd **) & (hostdata->issue_queue), tmp = (Scsi_Cmnd *) hostdata->issue_queue; tmp; prev = (Scsi_Cmnd **) & (tmp->host_scribble), tmp = (Scsi_Cmnd *) tmp->host_scribble) 2637 for (prev = (struct scsi_cmnd **) &(hostdata->issue_queue), tmp = (struct scsi_cmnd *) hostdata->issue_queue; tmp; prev = (struct scsi_cmnd **) &(tmp->host_scribble), tmp = (struct scsi_cmnd *) tmp->host_scribble)
2718 if (cmd == tmp) { 2638 if (cmd == tmp) {
2719 REMOVE(5, *prev, tmp, tmp->host_scribble); 2639 REMOVE(5, *prev, tmp, tmp->host_scribble);
2720 (*prev) = (Scsi_Cmnd *) tmp->host_scribble; 2640 (*prev) = (struct scsi_cmnd *) tmp->host_scribble;
2721 tmp->host_scribble = NULL; 2641 tmp->host_scribble = NULL;
2722 tmp->result = DID_ABORT << 16; 2642 tmp->result = DID_ABORT << 16;
2723 dprintk(NDEBUG_ABORT, "scsi%d : abort removed command from issue queue.\n", instance->host_no); 2643 dprintk(NDEBUG_ABORT, "scsi%d : abort removed command from issue queue.\n", instance->host_no);
@@ -2770,20 +2690,20 @@ static int NCR5380_abort(Scsi_Cmnd * cmd) {
2770 * it from the disconnected queue. 2690 * it from the disconnected queue.
2771 */ 2691 */
2772 2692
2773 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp; tmp = (Scsi_Cmnd *) tmp->host_scribble) 2693 for (tmp = (struct scsi_cmnd *) hostdata->disconnected_queue; tmp; tmp = (struct scsi_cmnd *) tmp->host_scribble)
2774 if (cmd == tmp) { 2694 if (cmd == tmp) {
2775 dprintk(NDEBUG_ABORT, "scsi%d : aborting disconnected command.\n", instance->host_no); 2695 dprintk(NDEBUG_ABORT, "scsi%d : aborting disconnected command.\n", instance->host_no);
2776 2696
2777 if (NCR5380_select(instance, cmd, (int) cmd->tag)) 2697 if (NCR5380_select(instance, cmd))
2778 return FAILED; 2698 return FAILED;
2779 dprintk(NDEBUG_ABORT, "scsi%d : nexus reestablished.\n", instance->host_no); 2699 dprintk(NDEBUG_ABORT, "scsi%d : nexus reestablished.\n", instance->host_no);
2780 2700
2781 do_abort(instance); 2701 do_abort(instance);
2782 2702
2783 for (prev = (Scsi_Cmnd **) & (hostdata->disconnected_queue), tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp; prev = (Scsi_Cmnd **) & (tmp->host_scribble), tmp = (Scsi_Cmnd *) tmp->host_scribble) 2703 for (prev = (struct scsi_cmnd **) &(hostdata->disconnected_queue), tmp = (struct scsi_cmnd *) hostdata->disconnected_queue; tmp; prev = (struct scsi_cmnd **) &(tmp->host_scribble), tmp = (struct scsi_cmnd *) tmp->host_scribble)
2784 if (cmd == tmp) { 2704 if (cmd == tmp) {
2785 REMOVE(5, *prev, tmp, tmp->host_scribble); 2705 REMOVE(5, *prev, tmp, tmp->host_scribble);
2786 *prev = (Scsi_Cmnd *) tmp->host_scribble; 2706 *prev = (struct scsi_cmnd *) tmp->host_scribble;
2787 tmp->host_scribble = NULL; 2707 tmp->host_scribble = NULL;
2788 tmp->result = DID_ABORT << 16; 2708 tmp->result = DID_ABORT << 16;
2789 tmp->scsi_done(tmp); 2709 tmp->scsi_done(tmp);
@@ -2806,7 +2726,7 @@ static int NCR5380_abort(Scsi_Cmnd * cmd) {
2806 2726
2807 2727
2808/* 2728/*
2809 * Function : int NCR5380_bus_reset (Scsi_Cmnd *cmd) 2729 * Function : int NCR5380_bus_reset (struct scsi_cmnd *cmd)
2810 * 2730 *
2811 * Purpose : reset the SCSI bus. 2731 * Purpose : reset the SCSI bus.
2812 * 2732 *
@@ -2815,7 +2735,7 @@ static int NCR5380_abort(Scsi_Cmnd * cmd) {
2815 * Locks: host lock taken by caller 2735 * Locks: host lock taken by caller
2816 */ 2736 */
2817 2737
2818static int NCR5380_bus_reset(Scsi_Cmnd * cmd) 2738static int NCR5380_bus_reset(struct scsi_cmnd *cmd)
2819{ 2739{
2820 struct Scsi_Host *instance = cmd->device->host; 2740 struct Scsi_Host *instance = cmd->device->host;
2821 2741
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index c79ddfa6f53c..162112dd1bf8 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -7,8 +7,6 @@
7 * drew@colorado.edu 7 * drew@colorado.edu
8 * +1 (303) 666-5836 8 * +1 (303) 666-5836
9 * 9 *
10 * DISTRIBUTION RELEASE 7
11 *
12 * For more information, please consult 10 * For more information, please consult
13 * 11 *
14 * NCR 5380 Family 12 * NCR 5380 Family
@@ -25,13 +23,7 @@
25#define NCR5380_H 23#define NCR5380_H
26 24
27#include <linux/interrupt.h> 25#include <linux/interrupt.h>
28
29#ifdef AUTOSENSE
30#include <scsi/scsi_eh.h> 26#include <scsi/scsi_eh.h>
31#endif
32
33#define NCR5380_PUBLIC_RELEASE 7
34#define NCR53C400_PUBLIC_RELEASE 2
35 27
36#define NDEBUG_ARBITRATION 0x1 28#define NDEBUG_ARBITRATION 0x1
37#define NDEBUG_AUTOSENSE 0x2 29#define NDEBUG_AUTOSENSE 0x2
@@ -224,33 +216,44 @@
224#define DISCONNECT_LONG 2 216#define DISCONNECT_LONG 2
225 217
226/* 218/*
227 * These are "special" values for the tag parameter passed to NCR5380_select. 219 * "Special" value for the (unsigned char) command tag, to indicate
220 * I_T_L nexus instead of I_T_L_Q.
228 */ 221 */
229 222
230#define TAG_NEXT -1 /* Use next free tag */ 223#define TAG_NONE 0xff
231#define TAG_NONE -2 /*
232 * Establish I_T_L nexus instead of I_T_L_Q
233 * even on SCSI-II devices.
234 */
235 224
236/* 225/*
237 * These are "special" values for the irq and dma_channel fields of the 226 * These are "special" values for the irq and dma_channel fields of the
238 * Scsi_Host structure 227 * Scsi_Host structure
239 */ 228 */
240 229
241#define SCSI_IRQ_NONE 255
242#define DMA_NONE 255 230#define DMA_NONE 255
243#define IRQ_AUTO 254 231#define IRQ_AUTO 254
244#define DMA_AUTO 254 232#define DMA_AUTO 254
245#define PORT_AUTO 0xffff /* autoprobe io port for 53c400a */ 233#define PORT_AUTO 0xffff /* autoprobe io port for 53c400a */
246 234
235#ifndef NO_IRQ
236#define NO_IRQ 0
237#endif
238
247#define FLAG_HAS_LAST_BYTE_SENT 1 /* NCR53c81 or better */ 239#define FLAG_HAS_LAST_BYTE_SENT 1 /* NCR53c81 or better */
248#define FLAG_CHECK_LAST_BYTE_SENT 2 /* Only test once */ 240#define FLAG_CHECK_LAST_BYTE_SENT 2 /* Only test once */
249#define FLAG_NCR53C400 4 /* NCR53c400 */ 241#define FLAG_NCR53C400 4 /* NCR53c400 */
250#define FLAG_NO_PSEUDO_DMA 8 /* Inhibit DMA */ 242#define FLAG_NO_PSEUDO_DMA 8 /* Inhibit DMA */
251#define FLAG_DTC3181E 16 /* DTC3181E */ 243#define FLAG_DTC3181E 16 /* DTC3181E */
244#define FLAG_LATE_DMA_SETUP 32 /* Setup NCR before DMA H/W */
245#define FLAG_TAGGED_QUEUING 64 /* as X3T9.2 spelled it */
252 246
253#ifndef ASM 247#ifndef ASM
248
249#ifdef SUPPORT_TAGS
250struct tag_alloc {
251 DECLARE_BITMAP(allocated, MAX_TAGS);
252 int nr_allocated;
253 int queue_size;
254};
255#endif
256
254struct NCR5380_hostdata { 257struct NCR5380_hostdata {
255 NCR5380_implementation_fields; /* implementation specific */ 258 NCR5380_implementation_fields; /* implementation specific */
256 struct Scsi_Host *host; /* Host backpointer */ 259 struct Scsi_Host *host; /* Host backpointer */
@@ -263,9 +266,9 @@ struct NCR5380_hostdata {
263 volatile int dma_len; /* requested length of DMA */ 266 volatile int dma_len; /* requested length of DMA */
264#endif 267#endif
265 volatile unsigned char last_message; /* last message OUT */ 268 volatile unsigned char last_message; /* last message OUT */
266 volatile Scsi_Cmnd *connected; /* currently connected command */ 269 volatile struct scsi_cmnd *connected; /* currently connected command */
267 volatile Scsi_Cmnd *issue_queue; /* waiting to be issued */ 270 volatile struct scsi_cmnd *issue_queue; /* waiting to be issued */
268 volatile Scsi_Cmnd *disconnected_queue; /* waiting for reconnect */ 271 volatile struct scsi_cmnd *disconnected_queue; /* waiting for reconnect */
269 volatile int restart_select; /* we have disconnected, 272 volatile int restart_select; /* we have disconnected,
270 used to restart 273 used to restart
271 NCR5380_select() */ 274 NCR5380_select() */
@@ -273,19 +276,21 @@ struct NCR5380_hostdata {
273 int flags; 276 int flags;
274 unsigned long time_expires; /* in jiffies, set prior to sleeping */ 277 unsigned long time_expires; /* in jiffies, set prior to sleeping */
275 int select_time; /* timer in select for target response */ 278 int select_time; /* timer in select for target response */
276 volatile Scsi_Cmnd *selecting; 279 volatile struct scsi_cmnd *selecting;
277 struct delayed_work coroutine; /* our co-routine */ 280 struct delayed_work coroutine; /* our co-routine */
278#ifdef NCR5380_STATS
279 unsigned timebase; /* Base for time calcs */
280 long time_read[8]; /* time to do reads */
281 long time_write[8]; /* time to do writes */
282 unsigned long bytes_read[8]; /* bytes read */
283 unsigned long bytes_write[8]; /* bytes written */
284 unsigned pendingr;
285 unsigned pendingw;
286#endif
287#ifdef AUTOSENSE
288 struct scsi_eh_save ses; 281 struct scsi_eh_save ses;
282 char info[256];
283 int read_overruns; /* number of bytes to cut from a
284 * transfer to handle chip overruns */
285 int retain_dma_intr;
286 struct work_struct main_task;
287 volatile int main_running;
288#ifdef SUPPORT_TAGS
289 struct tag_alloc TagAlloc[8][8]; /* 8 targets and 8 LUNs */
290#endif
291#ifdef PSEUDO_DMA
292 unsigned spin_max_r;
293 unsigned spin_max_w;
289#endif 294#endif
290}; 295};
291 296
@@ -296,7 +301,8 @@ struct NCR5380_hostdata {
296#endif 301#endif
297 302
298#define dprintk(flg, fmt, ...) \ 303#define dprintk(flg, fmt, ...) \
299 do { if ((NDEBUG) & (flg)) pr_debug(fmt, ## __VA_ARGS__); } while (0) 304 do { if ((NDEBUG) & (flg)) \
305 printk(KERN_DEBUG fmt, ## __VA_ARGS__); } while (0)
300 306
301#if NDEBUG 307#if NDEBUG
302#define NCR5380_dprint(flg, arg) \ 308#define NCR5380_dprint(flg, arg) \
@@ -320,17 +326,9 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance);
320static irqreturn_t NCR5380_intr(int irq, void *dev_id); 326static irqreturn_t NCR5380_intr(int irq, void *dev_id);
321#endif 327#endif
322static void NCR5380_main(struct work_struct *work); 328static void NCR5380_main(struct work_struct *work);
323static void __maybe_unused NCR5380_print_options(struct Scsi_Host *instance); 329static const char *NCR5380_info(struct Scsi_Host *instance);
324static int NCR5380_abort(Scsi_Cmnd * cmd);
325static int NCR5380_bus_reset(Scsi_Cmnd * cmd);
326static int NCR5380_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
327static int __maybe_unused NCR5380_show_info(struct seq_file *,
328 struct Scsi_Host *);
329static int __maybe_unused NCR5380_write_info(struct Scsi_Host *instance,
330 char *buffer, int length);
331
332static void NCR5380_reselect(struct Scsi_Host *instance); 330static void NCR5380_reselect(struct Scsi_Host *instance);
333static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd * cmd, int tag); 331static int NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd);
334#if defined(PSEUDO_DMA) || defined(REAL_DMA) || defined(REAL_DMA_POLL) 332#if defined(PSEUDO_DMA) || defined(REAL_DMA) || defined(REAL_DMA_POLL)
335static int NCR5380_transfer_dma(struct Scsi_Host *instance, unsigned char *phase, int *count, unsigned char **data); 333static int NCR5380_transfer_dma(struct Scsi_Host *instance, unsigned char *phase, int *count, unsigned char **data);
336#endif 334#endif
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 681434e2dfe9..b32e77db0c48 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -2181,7 +2181,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2181 (fsa_dev_ptr[cid].sense_data.sense_key == 2181 (fsa_dev_ptr[cid].sense_data.sense_key ==
2182 NOT_READY)) { 2182 NOT_READY)) {
2183 switch (scsicmd->cmnd[0]) { 2183 switch (scsicmd->cmnd[0]) {
2184 case SERVICE_ACTION_IN: 2184 case SERVICE_ACTION_IN_16:
2185 if (!(dev->raw_io_interface) || 2185 if (!(dev->raw_io_interface) ||
2186 !(dev->raw_io_64) || 2186 !(dev->raw_io_64) ||
2187 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) 2187 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
@@ -2309,7 +2309,7 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
2309 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data)); 2309 scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
2310 return aac_get_container_name(scsicmd); 2310 return aac_get_container_name(scsicmd);
2311 } 2311 }
2312 case SERVICE_ACTION_IN: 2312 case SERVICE_ACTION_IN_16:
2313 if (!(dev->raw_io_interface) || 2313 if (!(dev->raw_io_interface) ||
2314 !(dev->raw_io_64) || 2314 !(dev->raw_io_64) ||
2315 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) 2315 ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index a759cb2d4b15..fdcdf9f781bc 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -462,9 +462,9 @@ static int aac_slave_configure(struct scsi_device *sdev)
462 depth = 256; 462 depth = 256;
463 else if (depth < 2) 463 else if (depth < 2)
464 depth = 2; 464 depth = 2;
465 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, depth); 465 scsi_change_queue_depth(sdev, depth);
466 } else 466 } else
467 scsi_adjust_queue_depth(sdev, 0, 1); 467 scsi_change_queue_depth(sdev, 1);
468 468
469 return 0; 469 return 0;
470} 470}
@@ -478,12 +478,8 @@ static int aac_slave_configure(struct scsi_device *sdev)
478 * total capacity and the queue depth supported by the target device. 478 * total capacity and the queue depth supported by the target device.
479 */ 479 */
480 480
481static int aac_change_queue_depth(struct scsi_device *sdev, int depth, 481static int aac_change_queue_depth(struct scsi_device *sdev, int depth)
482 int reason)
483{ 482{
484 if (reason != SCSI_QDEPTH_DEFAULT)
485 return -EOPNOTSUPP;
486
487 if (sdev->tagged_supported && (sdev->type == TYPE_DISK) && 483 if (sdev->tagged_supported && (sdev->type == TYPE_DISK) &&
488 (sdev_channel(sdev) == CONTAINER_CHANNEL)) { 484 (sdev_channel(sdev) == CONTAINER_CHANNEL)) {
489 struct scsi_device * dev; 485 struct scsi_device * dev;
@@ -504,10 +500,10 @@ static int aac_change_queue_depth(struct scsi_device *sdev, int depth,
504 depth = 256; 500 depth = 256;
505 else if (depth < 2) 501 else if (depth < 2)
506 depth = 2; 502 depth = 2;
507 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, depth); 503 return scsi_change_queue_depth(sdev, depth);
508 } else 504 }
509 scsi_adjust_queue_depth(sdev, 0, 1); 505
510 return sdev->queue_depth; 506 return scsi_change_queue_depth(sdev, 1);
511} 507}
512 508
513static ssize_t aac_show_raid_level(struct device *dev, struct device_attribute *attr, char *buf) 509static ssize_t aac_show_raid_level(struct device *dev, struct device_attribute *attr, char *buf)
@@ -555,7 +551,7 @@ static int aac_eh_abort(struct scsi_cmnd* cmd)
555 AAC_DRIVERNAME, 551 AAC_DRIVERNAME,
556 host->host_no, sdev_channel(dev), sdev_id(dev), dev->lun); 552 host->host_no, sdev_channel(dev), sdev_id(dev), dev->lun);
557 switch (cmd->cmnd[0]) { 553 switch (cmd->cmnd[0]) {
558 case SERVICE_ACTION_IN: 554 case SERVICE_ACTION_IN_16:
559 if (!(aac->raw_io_interface) || 555 if (!(aac->raw_io_interface) ||
560 !(aac->raw_io_64) || 556 !(aac->raw_io_64) ||
561 ((cmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16)) 557 ((cmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 43761c1c46f0..6719a3390ebd 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -7706,7 +7706,7 @@ advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
7706 asc_dvc->cfg->can_tagged_qng |= tid_bit; 7706 asc_dvc->cfg->can_tagged_qng |= tid_bit;
7707 asc_dvc->use_tagged_qng |= tid_bit; 7707 asc_dvc->use_tagged_qng |= tid_bit;
7708 } 7708 }
7709 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, 7709 scsi_change_queue_depth(sdev,
7710 asc_dvc->max_dvc_qng[sdev->id]); 7710 asc_dvc->max_dvc_qng[sdev->id]);
7711 } 7711 }
7712 } else { 7712 } else {
@@ -7714,7 +7714,6 @@ advansys_narrow_slave_configure(struct scsi_device *sdev, ASC_DVC_VAR *asc_dvc)
7714 asc_dvc->cfg->can_tagged_qng &= ~tid_bit; 7714 asc_dvc->cfg->can_tagged_qng &= ~tid_bit;
7715 asc_dvc->use_tagged_qng &= ~tid_bit; 7715 asc_dvc->use_tagged_qng &= ~tid_bit;
7716 } 7716 }
7717 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
7718 } 7717 }
7719 7718
7720 if ((sdev->lun == 0) && 7719 if ((sdev->lun == 0) &&
@@ -7848,12 +7847,8 @@ advansys_wide_slave_configure(struct scsi_device *sdev, ADV_DVC_VAR *adv_dvc)
7848 } 7847 }
7849 } 7848 }
7850 7849
7851 if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported) { 7850 if ((adv_dvc->tagqng_able & tidmask) && sdev->tagged_supported)
7852 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, 7851 scsi_change_queue_depth(sdev, adv_dvc->max_dvc_qng);
7853 adv_dvc->max_dvc_qng);
7854 } else {
7855 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
7856 }
7857} 7852}
7858 7853
7859/* 7854/*
diff --git a/drivers/scsi/aha152x.c b/drivers/scsi/aha152x.c
index e77b72f78006..2b960b326daf 100644
--- a/drivers/scsi/aha152x.c
+++ b/drivers/scsi/aha152x.c
@@ -230,7 +230,7 @@
230 * 230 *
231 * 231 *
232 ************************************************************************** 232 **************************************************************************
233 233
234 see Documentation/scsi/aha152x.txt for configuration details 234 see Documentation/scsi/aha152x.txt for configuration details
235 235
236 **************************************************************************/ 236 **************************************************************************/
@@ -279,45 +279,11 @@ static LIST_HEAD(aha152x_host_list);
279#error define AUTOCONF or SETUP0 279#error define AUTOCONF or SETUP0
280#endif 280#endif
281 281
282#if defined(AHA152X_DEBUG)
283#define DEBUG_DEFAULT debug_eh
284
285#define DPRINTK(when,msgs...) \
286 do { if(HOSTDATA(shpnt)->debug & (when)) printk(msgs); } while(0)
287
288#define DO_LOCK(flags) \
289 do { \
290 if(spin_is_locked(&QLOCK)) { \
291 DPRINTK(debug_intr, DEBUG_LEAD "(%s:%d) already locked at %s:%d\n", CMDINFO(CURRENT_SC), __func__, __LINE__, QLOCKER, QLOCKERL); \
292 } \
293 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) locking\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \
294 spin_lock_irqsave(&QLOCK,flags); \
295 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) locked\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \
296 QLOCKER=__func__; \
297 QLOCKERL=__LINE__; \
298 } while(0)
299
300#define DO_UNLOCK(flags) \
301 do { \
302 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) unlocking (locked at %s:%d)\n", CMDINFO(CURRENT_SC), __func__, __LINE__, QLOCKER, QLOCKERL); \
303 spin_unlock_irqrestore(&QLOCK,flags); \
304 DPRINTK(debug_locking, DEBUG_LEAD "(%s:%d) unlocked\n", CMDINFO(CURRENT_SC), __func__, __LINE__); \
305 QLOCKER="(not locked)"; \
306 QLOCKERL=0; \
307 } while(0)
308
309#else
310#define DPRINTK(when,msgs...)
311#define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags) 282#define DO_LOCK(flags) spin_lock_irqsave(&QLOCK,flags)
312#define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags) 283#define DO_UNLOCK(flags) spin_unlock_irqrestore(&QLOCK,flags)
313#endif
314 284
315#define LEAD "(scsi%d:%d:%d) " 285#define LEAD "(scsi%d:%d:%d) "
316#define WARN_LEAD KERN_WARNING LEAD
317#define INFO_LEAD KERN_INFO LEAD 286#define INFO_LEAD KERN_INFO LEAD
318#define NOTE_LEAD KERN_NOTICE LEAD
319#define ERR_LEAD KERN_ERR LEAD
320#define DEBUG_LEAD KERN_DEBUG LEAD
321#define CMDINFO(cmd) \ 287#define CMDINFO(cmd) \
322 (cmd) ? ((cmd)->device->host->host_no) : -1, \ 288 (cmd) ? ((cmd)->device->host->host_no) : -1, \
323 (cmd) ? ((cmd)->device->id & 0x0f) : -1, \ 289 (cmd) ? ((cmd)->device->id & 0x0f) : -1, \
@@ -345,10 +311,10 @@ CMD_INC_RESID(struct scsi_cmnd *cmd, int inc)
345 311
346enum { 312enum {
347 not_issued = 0x0001, /* command not yet issued */ 313 not_issued = 0x0001, /* command not yet issued */
348 selecting = 0x0002, /* target is beeing selected */ 314 selecting = 0x0002, /* target is being selected */
349 identified = 0x0004, /* IDENTIFY was sent */ 315 identified = 0x0004, /* IDENTIFY was sent */
350 disconnected = 0x0008, /* target disconnected */ 316 disconnected = 0x0008, /* target disconnected */
351 completed = 0x0010, /* target sent COMMAND COMPLETE */ 317 completed = 0x0010, /* target sent COMMAND COMPLETE */
352 aborted = 0x0020, /* ABORT was sent */ 318 aborted = 0x0020, /* ABORT was sent */
353 resetted = 0x0040, /* BUS DEVICE RESET was sent */ 319 resetted = 0x0040, /* BUS DEVICE RESET was sent */
354 spiordy = 0x0080, /* waiting for SPIORDY to raise */ 320 spiordy = 0x0080, /* waiting for SPIORDY to raise */
@@ -396,7 +362,6 @@ static int exttrans[] = {0, 0};
396module_param_array(exttrans, int, NULL, 0); 362module_param_array(exttrans, int, NULL, 0);
397MODULE_PARM_DESC(exttrans,"use extended translation"); 363MODULE_PARM_DESC(exttrans,"use extended translation");
398 364
399#if !defined(AHA152X_DEBUG)
400static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0}; 365static int aha152x[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
401module_param_array(aha152x, int, NULL, 0); 366module_param_array(aha152x, int, NULL, 0);
402MODULE_PARM_DESC(aha152x, "parameters for first controller"); 367MODULE_PARM_DESC(aha152x, "parameters for first controller");
@@ -404,19 +369,6 @@ MODULE_PARM_DESC(aha152x, "parameters for first controller");
404static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0}; 369static int aha152x1[] = {0, 11, 7, 1, 1, 0, DELAY_DEFAULT, 0};
405module_param_array(aha152x1, int, NULL, 0); 370module_param_array(aha152x1, int, NULL, 0);
406MODULE_PARM_DESC(aha152x1, "parameters for second controller"); 371MODULE_PARM_DESC(aha152x1, "parameters for second controller");
407#else
408static int debug[] = {DEBUG_DEFAULT, DEBUG_DEFAULT};
409module_param_array(debug, int, NULL, 0);
410MODULE_PARM_DESC(debug, "flags for driver debugging");
411
412static int aha152x[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
413module_param_array(aha152x, int, NULL, 0);
414MODULE_PARM_DESC(aha152x, "parameters for first controller");
415
416static int aha152x1[] = {0, 11, 7, 1, 1, 1, DELAY_DEFAULT, 0, DEBUG_DEFAULT};
417module_param_array(aha152x1, int, NULL, 0);
418MODULE_PARM_DESC(aha152x1, "parameters for second controller");
419#endif /* !defined(AHA152X_DEBUG) */
420#endif /* MODULE */ 372#endif /* MODULE */
421 373
422#ifdef __ISAPNP__ 374#ifdef __ISAPNP__
@@ -446,7 +398,7 @@ static struct scsi_host_template aha152x_driver_template;
446/* 398/*
447 * internal states of the host 399 * internal states of the host
448 * 400 *
449 */ 401 */
450enum aha152x_state { 402enum aha152x_state {
451 idle=0, 403 idle=0,
452 unknown, 404 unknown,
@@ -485,24 +437,16 @@ struct aha152x_hostdata {
485 spinlock_t lock; 437 spinlock_t lock;
486 /* host lock */ 438 /* host lock */
487 439
488#if defined(AHA152X_DEBUG)
489 const char *locker;
490 /* which function has the lock */
491 int lockerl; /* where did it get it */
492
493 int debug; /* current debugging setting */
494#endif
495
496#if defined(AHA152X_STAT) 440#if defined(AHA152X_STAT)
497 int total_commands; 441 int total_commands;
498 int disconnections; 442 int disconnections;
499 int busfree_without_any_action; 443 int busfree_without_any_action;
500 int busfree_without_old_command; 444 int busfree_without_old_command;
501 int busfree_without_new_command; 445 int busfree_without_new_command;
502 int busfree_without_done_command; 446 int busfree_without_done_command;
503 int busfree_with_check_condition; 447 int busfree_with_check_condition;
504 int count[maxstate]; 448 int count[maxstate];
505 int count_trans[maxstate]; 449 int count_trans[maxstate];
506 unsigned long time[maxstate]; 450 unsigned long time[maxstate];
507#endif 451#endif
508 452
@@ -514,7 +458,7 @@ struct aha152x_hostdata {
514 int delay; /* reset out delay */ 458 int delay; /* reset out delay */
515 int ext_trans; /* extended translation enabled */ 459 int ext_trans; /* extended translation enabled */
516 460
517 int swint; /* software-interrupt was fired during detect() */ 461 int swint; /* software-interrupt was fired during detect() */
518 int service; /* bh needs to be run */ 462 int service; /* bh needs to be run */
519 int in_intr; /* bh is running */ 463 int in_intr; /* bh is running */
520 464
@@ -543,7 +487,7 @@ struct aha152x_hostdata {
543 unsigned char msgi[256]; 487 unsigned char msgi[256];
544 /* received message bytes */ 488 /* received message bytes */
545 489
546 int msgo_i, msgo_len; 490 int msgo_i, msgo_len;
547 /* number of sent bytes and length of current messages */ 491 /* number of sent bytes and length of current messages */
548 unsigned char msgo[256]; 492 unsigned char msgo[256];
549 /* pending messages */ 493 /* pending messages */
@@ -689,7 +633,6 @@ static void aha152x_error(struct Scsi_Host *shpnt, char *msg);
689static void done(struct Scsi_Host *shpnt, int error); 633static void done(struct Scsi_Host *shpnt, int error);
690 634
691/* diagnostics */ 635/* diagnostics */
692static void disp_ports(struct Scsi_Host *shpnt);
693static void show_command(Scsi_Cmnd * ptr); 636static void show_command(Scsi_Cmnd * ptr);
694static void show_queues(struct Scsi_Host *shpnt); 637static void show_queues(struct Scsi_Host *shpnt);
695static void disp_enintr(struct Scsi_Host *shpnt); 638static void disp_enintr(struct Scsi_Host *shpnt);
@@ -812,10 +755,6 @@ struct Scsi_Host *aha152x_probe_one(struct aha152x_setup *setup)
812 DELAY = setup->delay; 755 DELAY = setup->delay;
813 EXT_TRANS = setup->ext_trans; 756 EXT_TRANS = setup->ext_trans;
814 757
815#if defined(AHA152X_DEBUG)
816 HOSTDATA(shpnt)->debug = setup->debug;
817#endif
818
819 SETPORT(SCSIID, setup->scsiid << 4); 758 SETPORT(SCSIID, setup->scsiid << 4);
820 shpnt->this_id = setup->scsiid; 759 shpnt->this_id = setup->scsiid;
821 760
@@ -941,31 +880,24 @@ void aha152x_release(struct Scsi_Host *shpnt)
941 * setup controller to generate interrupts depending 880 * setup controller to generate interrupts depending
942 * on current state (lock has to be acquired) 881 * on current state (lock has to be acquired)
943 * 882 *
944 */ 883 */
945static int setup_expected_interrupts(struct Scsi_Host *shpnt) 884static int setup_expected_interrupts(struct Scsi_Host *shpnt)
946{ 885{
947 if(CURRENT_SC) { 886 if(CURRENT_SC) {
948 CURRENT_SC->SCp.phase |= 1 << 16; 887 CURRENT_SC->SCp.phase |= 1 << 16;
949 888
950 if(CURRENT_SC->SCp.phase & selecting) { 889 if(CURRENT_SC->SCp.phase & selecting) {
951 DPRINTK(debug_intr, DEBUG_LEAD "expecting: (seldo) (seltimo) (seldi)\n", CMDINFO(CURRENT_SC));
952 SETPORT(SSTAT1, SELTO); 890 SETPORT(SSTAT1, SELTO);
953 SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0)); 891 SETPORT(SIMODE0, ENSELDO | (DISCONNECTED_SC ? ENSELDI : 0));
954 SETPORT(SIMODE1, ENSELTIMO); 892 SETPORT(SIMODE1, ENSELTIMO);
955 } else { 893 } else {
956 DPRINTK(debug_intr, DEBUG_LEAD "expecting: (phase change) (busfree) %s\n", CMDINFO(CURRENT_SC), CURRENT_SC->SCp.phase & spiordy ? "(spiordy)" : "");
957 SETPORT(SIMODE0, (CURRENT_SC->SCp.phase & spiordy) ? ENSPIORDY : 0); 894 SETPORT(SIMODE0, (CURRENT_SC->SCp.phase & spiordy) ? ENSPIORDY : 0);
958 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE); 895 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
959 } 896 }
960 } else if(STATE==seldi) { 897 } else if(STATE==seldi) {
961 DPRINTK(debug_intr, DEBUG_LEAD "expecting: (phase change) (identify)\n", CMDINFO(CURRENT_SC));
962 SETPORT(SIMODE0, 0); 898 SETPORT(SIMODE0, 0);
963 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE); 899 SETPORT(SIMODE1, ENPHASEMIS | ENSCSIRST | ENSCSIPERR | ENBUSFREE);
964 } else { 900 } else {
965 DPRINTK(debug_intr, DEBUG_LEAD "expecting: %s %s\n",
966 CMDINFO(CURRENT_SC),
967 DISCONNECTED_SC ? "(reselection)" : "",
968 ISSUE_SC ? "(busfree)" : "");
969 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0); 901 SETPORT(SIMODE0, DISCONNECTED_SC ? ENSELDI : 0);
970 SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0)); 902 SETPORT(SIMODE1, ENSCSIRST | ( (ISSUE_SC||DONE_SC) ? ENBUSFREE : 0));
971 } 903 }
@@ -977,7 +909,7 @@ static int setup_expected_interrupts(struct Scsi_Host *shpnt)
977} 909}
978 910
979 911
980/* 912/*
981 * Queue a command and setup interrupts for a free bus. 913 * Queue a command and setup interrupts for a free bus.
982 */ 914 */
983static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete, 915static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete,
@@ -986,15 +918,6 @@ static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete,
986 struct Scsi_Host *shpnt = SCpnt->device->host; 918 struct Scsi_Host *shpnt = SCpnt->device->host;
987 unsigned long flags; 919 unsigned long flags;
988 920
989#if defined(AHA152X_DEBUG)
990 if (HOSTDATA(shpnt)->debug & debug_queue) {
991 printk(INFO_LEAD "queue: %p; cmd_len=%d pieces=%d size=%u cmnd=",
992 CMDINFO(SCpnt), SCpnt, SCpnt->cmd_len,
993 scsi_sg_count(SCpnt), scsi_bufflen(SCpnt));
994 __scsi_print_command(SCpnt->cmnd);
995 }
996#endif
997
998 SCpnt->scsi_done = done; 921 SCpnt->scsi_done = done;
999 SCpnt->SCp.phase = not_issued | phase; 922 SCpnt->SCp.phase = not_issued | phase;
1000 SCpnt->SCp.Status = 0x1; /* Ilegal status by SCSI standard */ 923 SCpnt->SCp.Status = 0x1; /* Ilegal status by SCSI standard */
@@ -1004,13 +927,13 @@ static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete,
1004 927
1005 if(SCpnt->SCp.phase & (resetting|check_condition)) { 928 if(SCpnt->SCp.phase & (resetting|check_condition)) {
1006 if (!SCpnt->host_scribble || SCSEM(SCpnt) || SCNEXT(SCpnt)) { 929 if (!SCpnt->host_scribble || SCSEM(SCpnt) || SCNEXT(SCpnt)) {
1007 printk(ERR_LEAD "cannot reuse command\n", CMDINFO(SCpnt)); 930 scmd_printk(KERN_ERR, SCpnt, "cannot reuse command\n");
1008 return FAILED; 931 return FAILED;
1009 } 932 }
1010 } else { 933 } else {
1011 SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC); 934 SCpnt->host_scribble = kmalloc(sizeof(struct aha152x_scdata), GFP_ATOMIC);
1012 if(!SCpnt->host_scribble) { 935 if(!SCpnt->host_scribble) {
1013 printk(ERR_LEAD "allocation failed\n", CMDINFO(SCpnt)); 936 scmd_printk(KERN_ERR, SCpnt, "allocation failed\n");
1014 return FAILED; 937 return FAILED;
1015 } 938 }
1016 } 939 }
@@ -1066,15 +989,6 @@ static int aha152x_internal_queue(Scsi_Cmnd *SCpnt, struct completion *complete,
1066 */ 989 */
1067static int aha152x_queue_lck(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) 990static int aha152x_queue_lck(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
1068{ 991{
1069#if 0
1070 if(*SCpnt->cmnd == REQUEST_SENSE) {
1071 SCpnt->result = 0;
1072 done(SCpnt);
1073
1074 return 0;
1075 }
1076#endif
1077
1078 return aha152x_internal_queue(SCpnt, NULL, 0, done); 992 return aha152x_internal_queue(SCpnt, NULL, 0, done);
1079} 993}
1080 994
@@ -1082,15 +996,10 @@ static DEF_SCSI_QCMD(aha152x_queue)
1082 996
1083 997
1084/* 998/*
1085 *
1086 * 999 *
1087 */ 1000 */
1088static void reset_done(Scsi_Cmnd *SCpnt) 1001static void reset_done(Scsi_Cmnd *SCpnt)
1089{ 1002{
1090#if 0
1091 struct Scsi_Host *shpnt = SCpnt->host;
1092 DPRINTK(debug_eh, INFO_LEAD "reset_done called\n", CMDINFO(SCpnt));
1093#endif
1094 if(SCSEM(SCpnt)) { 1003 if(SCSEM(SCpnt)) {
1095 complete(SCSEM(SCpnt)); 1004 complete(SCSEM(SCpnt));
1096 } else { 1005 } else {
@@ -1108,20 +1017,11 @@ static int aha152x_abort(Scsi_Cmnd *SCpnt)
1108 Scsi_Cmnd *ptr; 1017 Scsi_Cmnd *ptr;
1109 unsigned long flags; 1018 unsigned long flags;
1110 1019
1111#if defined(AHA152X_DEBUG)
1112 if(HOSTDATA(shpnt)->debug & debug_eh) {
1113 printk(DEBUG_LEAD "abort(%p)", CMDINFO(SCpnt), SCpnt);
1114 show_queues(shpnt);
1115 }
1116#endif
1117
1118 DO_LOCK(flags); 1020 DO_LOCK(flags);
1119 1021
1120 ptr=remove_SC(&ISSUE_SC, SCpnt); 1022 ptr=remove_SC(&ISSUE_SC, SCpnt);
1121 1023
1122 if(ptr) { 1024 if(ptr) {
1123 DPRINTK(debug_eh, DEBUG_LEAD "not yet issued - SUCCESS\n", CMDINFO(SCpnt));
1124
1125 HOSTDATA(shpnt)->commands--; 1025 HOSTDATA(shpnt)->commands--;
1126 if (!HOSTDATA(shpnt)->commands) 1026 if (!HOSTDATA(shpnt)->commands)
1127 SETPORT(PORTA, 0); 1027 SETPORT(PORTA, 0);
@@ -1131,7 +1031,7 @@ static int aha152x_abort(Scsi_Cmnd *SCpnt)
1131 SCpnt->host_scribble=NULL; 1031 SCpnt->host_scribble=NULL;
1132 1032
1133 return SUCCESS; 1033 return SUCCESS;
1134 } 1034 }
1135 1035
1136 DO_UNLOCK(flags); 1036 DO_UNLOCK(flags);
1137 1037
@@ -1142,7 +1042,8 @@ static int aha152x_abort(Scsi_Cmnd *SCpnt)
1142 * 1042 *
1143 */ 1043 */
1144 1044
1145 printk(ERR_LEAD "cannot abort running or disconnected command\n", CMDINFO(SCpnt)); 1045 scmd_printk(KERN_ERR, SCpnt,
1046 "cannot abort running or disconnected command\n");
1146 1047
1147 return FAILED; 1048 return FAILED;
1148} 1049}
@@ -1160,15 +1061,8 @@ static int aha152x_device_reset(Scsi_Cmnd * SCpnt)
1160 unsigned long flags; 1061 unsigned long flags;
1161 unsigned long timeleft; 1062 unsigned long timeleft;
1162 1063
1163#if defined(AHA152X_DEBUG)
1164 if(HOSTDATA(shpnt)->debug & debug_eh) {
1165 printk(INFO_LEAD "aha152x_device_reset(%p)", CMDINFO(SCpnt), SCpnt);
1166 show_queues(shpnt);
1167 }
1168#endif
1169
1170 if(CURRENT_SC==SCpnt) { 1064 if(CURRENT_SC==SCpnt) {
1171 printk(ERR_LEAD "cannot reset current device\n", CMDINFO(SCpnt)); 1065 scmd_printk(KERN_ERR, SCpnt, "cannot reset current device\n");
1172 return FAILED; 1066 return FAILED;
1173 } 1067 }
1174 1068
@@ -1208,7 +1102,7 @@ static int aha152x_device_reset(Scsi_Cmnd * SCpnt)
1208 } else if(disconnected) { 1102 } else if(disconnected) {
1209 append_SC(&DISCONNECTED_SC, SCpnt); 1103 append_SC(&DISCONNECTED_SC, SCpnt);
1210 } 1104 }
1211 1105
1212 ret = FAILED; 1106 ret = FAILED;
1213 } 1107 }
1214 1108
@@ -1227,12 +1121,12 @@ static void free_hard_reset_SCs(struct Scsi_Host *shpnt, Scsi_Cmnd **SCs)
1227 if(SCDATA(ptr)) { 1121 if(SCDATA(ptr)) {
1228 next = SCNEXT(ptr); 1122 next = SCNEXT(ptr);
1229 } else { 1123 } else {
1230 printk(DEBUG_LEAD "queue corrupted at %p\n", CMDINFO(ptr), ptr); 1124 scmd_printk(KERN_DEBUG, ptr,
1125 "queue corrupted at %p\n", ptr);
1231 next = NULL; 1126 next = NULL;
1232 } 1127 }
1233 1128
1234 if (!ptr->device->soft_reset) { 1129 if (!ptr->device->soft_reset) {
1235 DPRINTK(debug_eh, DEBUG_LEAD "disconnected command %p removed\n", CMDINFO(ptr), ptr);
1236 remove_SC(SCs, ptr); 1130 remove_SC(SCs, ptr);
1237 HOSTDATA(shpnt)->commands--; 1131 HOSTDATA(shpnt)->commands--;
1238 kfree(ptr->host_scribble); 1132 kfree(ptr->host_scribble);
@@ -1253,25 +1147,14 @@ static int aha152x_bus_reset_host(struct Scsi_Host *shpnt)
1253 1147
1254 DO_LOCK(flags); 1148 DO_LOCK(flags);
1255 1149
1256#if defined(AHA152X_DEBUG)
1257 if(HOSTDATA(shpnt)->debug & debug_eh) {
1258 printk(KERN_DEBUG "scsi%d: bus reset", shpnt->host_no);
1259 show_queues(shpnt);
1260 }
1261#endif
1262
1263 free_hard_reset_SCs(shpnt, &ISSUE_SC); 1150 free_hard_reset_SCs(shpnt, &ISSUE_SC);
1264 free_hard_reset_SCs(shpnt, &DISCONNECTED_SC); 1151 free_hard_reset_SCs(shpnt, &DISCONNECTED_SC);
1265 1152
1266 DPRINTK(debug_eh, KERN_DEBUG "scsi%d: resetting bus\n", shpnt->host_no);
1267
1268 SETPORT(SCSISEQ, SCSIRSTO); 1153 SETPORT(SCSISEQ, SCSIRSTO);
1269 mdelay(256); 1154 mdelay(256);
1270 SETPORT(SCSISEQ, 0); 1155 SETPORT(SCSISEQ, 0);
1271 mdelay(DELAY); 1156 mdelay(DELAY);
1272 1157
1273 DPRINTK(debug_eh, KERN_DEBUG "scsi%d: bus resetted\n", shpnt->host_no);
1274
1275 setup_expected_interrupts(shpnt); 1158 setup_expected_interrupts(shpnt);
1276 if(HOSTDATA(shpnt)->commands==0) 1159 if(HOSTDATA(shpnt)->commands==0)
1277 SETPORT(PORTA, 0); 1160 SETPORT(PORTA, 0);
@@ -1333,11 +1216,7 @@ static void reset_ports(struct Scsi_Host *shpnt)
1333 */ 1216 */
1334int aha152x_host_reset_host(struct Scsi_Host *shpnt) 1217int aha152x_host_reset_host(struct Scsi_Host *shpnt)
1335{ 1218{
1336 DPRINTK(debug_eh, KERN_DEBUG "scsi%d: host reset\n", shpnt->host_no);
1337
1338 aha152x_bus_reset_host(shpnt); 1219 aha152x_bus_reset_host(shpnt);
1339
1340 DPRINTK(debug_eh, KERN_DEBUG "scsi%d: resetting ports\n", shpnt->host_no);
1341 reset_ports(shpnt); 1220 reset_ports(shpnt);
1342 1221
1343 return SUCCESS; 1222 return SUCCESS;
@@ -1345,7 +1224,7 @@ int aha152x_host_reset_host(struct Scsi_Host *shpnt)
1345 1224
1346/* 1225/*
1347 * Reset the host (bus and controller) 1226 * Reset the host (bus and controller)
1348 * 1227 *
1349 */ 1228 */
1350static int aha152x_host_reset(Scsi_Cmnd *SCpnt) 1229static int aha152x_host_reset(Scsi_Cmnd *SCpnt)
1351{ 1230{
@@ -1411,7 +1290,9 @@ static void done(struct Scsi_Host *shpnt, int error)
1411{ 1290{
1412 if (CURRENT_SC) { 1291 if (CURRENT_SC) {
1413 if(DONE_SC) 1292 if(DONE_SC)
1414 printk(ERR_LEAD "there's already a completed command %p - will cause abort\n", CMDINFO(CURRENT_SC), DONE_SC); 1293 scmd_printk(KERN_ERR, CURRENT_SC,
1294 "there's already a completed command %p "
1295 "- will cause abort\n", DONE_SC);
1415 1296
1416 DONE_SC = CURRENT_SC; 1297 DONE_SC = CURRENT_SC;
1417 CURRENT_SC = NULL; 1298 CURRENT_SC = NULL;
@@ -1466,7 +1347,7 @@ static irqreturn_t intr(int irqno, void *dev_id)
1466 return IRQ_NONE; 1347 return IRQ_NONE;
1467 1348
1468 if( TESTLO(DMASTAT, INTSTAT) ) 1349 if( TESTLO(DMASTAT, INTSTAT) )
1469 return IRQ_NONE; 1350 return IRQ_NONE;
1470 1351
1471 /* no more interrupts from the controller, while we're busy. 1352 /* no more interrupts from the controller, while we're busy.
1472 INTEN is restored by the BH handler */ 1353 INTEN is restored by the BH handler */
@@ -1501,7 +1382,7 @@ static void busfree_run(struct Scsi_Host *shpnt)
1501 SETPORT(SXFRCTL0, CH1); 1382 SETPORT(SXFRCTL0, CH1);
1502 1383
1503 SETPORT(SSTAT1, CLRBUSFREE); 1384 SETPORT(SSTAT1, CLRBUSFREE);
1504 1385
1505 if(CURRENT_SC) { 1386 if(CURRENT_SC) {
1506#if defined(AHA152X_STAT) 1387#if defined(AHA152X_STAT)
1507 action++; 1388 action++;
@@ -1513,19 +1394,13 @@ static void busfree_run(struct Scsi_Host *shpnt)
1513 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16)); 1394 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16));
1514 1395
1515 } else if(CURRENT_SC->SCp.phase & aborted) { 1396 } else if(CURRENT_SC->SCp.phase & aborted) {
1516 DPRINTK(debug_eh, DEBUG_LEAD "ABORT sent\n", CMDINFO(CURRENT_SC));
1517 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_ABORT << 16)); 1397 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_ABORT << 16));
1518 1398
1519 } else if(CURRENT_SC->SCp.phase & resetted) { 1399 } else if(CURRENT_SC->SCp.phase & resetted) {
1520 DPRINTK(debug_eh, DEBUG_LEAD "BUS DEVICE RESET sent\n", CMDINFO(CURRENT_SC));
1521 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_RESET << 16)); 1400 done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_RESET << 16));
1522 1401
1523 } else if(CURRENT_SC->SCp.phase & disconnected) { 1402 } else if(CURRENT_SC->SCp.phase & disconnected) {
1524 /* target sent DISCONNECT */ 1403 /* target sent DISCONNECT */
1525 DPRINTK(debug_selection, DEBUG_LEAD "target disconnected at %d/%d\n",
1526 CMDINFO(CURRENT_SC),
1527 scsi_get_resid(CURRENT_SC),
1528 scsi_bufflen(CURRENT_SC));
1529#if defined(AHA152X_STAT) 1404#if defined(AHA152X_STAT)
1530 HOSTDATA(shpnt)->disconnections++; 1405 HOSTDATA(shpnt)->disconnections++;
1531#endif 1406#endif
@@ -1553,13 +1428,6 @@ static void busfree_run(struct Scsi_Host *shpnt)
1553 struct scsi_cmnd *cmd = HOSTDATA(shpnt)->done_SC; 1428 struct scsi_cmnd *cmd = HOSTDATA(shpnt)->done_SC;
1554 struct aha152x_scdata *sc = SCDATA(cmd); 1429 struct aha152x_scdata *sc = SCDATA(cmd);
1555 1430
1556#if 0
1557 if(HOSTDATA(shpnt)->debug & debug_eh) {
1558 printk(ERR_LEAD "received sense: ", CMDINFO(DONE_SC));
1559 scsi_print_sense("bh", DONE_SC);
1560 }
1561#endif
1562
1563 scsi_eh_restore_cmnd(cmd, &sc->ses); 1431 scsi_eh_restore_cmnd(cmd, &sc->ses);
1564 1432
1565 cmd->SCp.Status = SAM_STAT_CHECK_CONDITION; 1433 cmd->SCp.Status = SAM_STAT_CHECK_CONDITION;
@@ -1571,17 +1439,11 @@ static void busfree_run(struct Scsi_Host *shpnt)
1571#if defined(AHA152X_STAT) 1439#if defined(AHA152X_STAT)
1572 HOSTDATA(shpnt)->busfree_with_check_condition++; 1440 HOSTDATA(shpnt)->busfree_with_check_condition++;
1573#endif 1441#endif
1574#if 0
1575 DPRINTK(debug_eh, ERR_LEAD "CHECK CONDITION found\n", CMDINFO(DONE_SC));
1576#endif
1577 1442
1578 if(!(DONE_SC->SCp.phase & not_issued)) { 1443 if(!(DONE_SC->SCp.phase & not_issued)) {
1579 struct aha152x_scdata *sc; 1444 struct aha152x_scdata *sc;
1580 Scsi_Cmnd *ptr = DONE_SC; 1445 Scsi_Cmnd *ptr = DONE_SC;
1581 DONE_SC=NULL; 1446 DONE_SC=NULL;
1582#if 0
1583 DPRINTK(debug_eh, ERR_LEAD "requesting sense\n", CMDINFO(ptr));
1584#endif
1585 1447
1586 sc = SCDATA(ptr); 1448 sc = SCDATA(ptr);
1587 /* It was allocated in aha152x_internal_queue? */ 1449 /* It was allocated in aha152x_internal_queue? */
@@ -1591,19 +1453,10 @@ static void busfree_run(struct Scsi_Host *shpnt)
1591 DO_UNLOCK(flags); 1453 DO_UNLOCK(flags);
1592 aha152x_internal_queue(ptr, NULL, check_condition, ptr->scsi_done); 1454 aha152x_internal_queue(ptr, NULL, check_condition, ptr->scsi_done);
1593 DO_LOCK(flags); 1455 DO_LOCK(flags);
1594#if 0
1595 } else {
1596 DPRINTK(debug_eh, ERR_LEAD "command not issued - CHECK CONDITION ignored\n", CMDINFO(DONE_SC));
1597#endif
1598 } 1456 }
1599 } 1457 }
1600 1458
1601 if(DONE_SC && DONE_SC->scsi_done) { 1459 if(DONE_SC && DONE_SC->scsi_done) {
1602#if defined(AHA152X_DEBUG)
1603 int hostno=DONE_SC->device->host->host_no;
1604 int id=DONE_SC->device->id & 0xf;
1605 int lun=((u8)DONE_SC->device->lun) & 0x7;
1606#endif
1607 Scsi_Cmnd *ptr = DONE_SC; 1460 Scsi_Cmnd *ptr = DONE_SC;
1608 DONE_SC=NULL; 1461 DONE_SC=NULL;
1609 1462
@@ -1618,9 +1471,7 @@ static void busfree_run(struct Scsi_Host *shpnt)
1618 } 1471 }
1619 1472
1620 DO_UNLOCK(flags); 1473 DO_UNLOCK(flags);
1621 DPRINTK(debug_done, DEBUG_LEAD "calling scsi_done(%p)\n", hostno, id, lun, ptr); 1474 ptr->scsi_done(ptr);
1622 ptr->scsi_done(ptr);
1623 DPRINTK(debug_done, DEBUG_LEAD "scsi_done(%p) returned\n", hostno, id, lun, ptr);
1624 DO_LOCK(flags); 1475 DO_LOCK(flags);
1625 } 1476 }
1626 1477
@@ -1640,9 +1491,7 @@ static void busfree_run(struct Scsi_Host *shpnt)
1640#if defined(AHA152X_STAT) 1491#if defined(AHA152X_STAT)
1641 action++; 1492 action++;
1642#endif 1493#endif
1643 CURRENT_SC->SCp.phase |= selecting; 1494 CURRENT_SC->SCp.phase |= selecting;
1644
1645 DPRINTK(debug_selection, DEBUG_LEAD "selecting target\n", CMDINFO(CURRENT_SC));
1646 1495
1647 /* clear selection timeout */ 1496 /* clear selection timeout */
1648 SETPORT(SSTAT1, SELTO); 1497 SETPORT(SSTAT1, SELTO);
@@ -1674,18 +1523,19 @@ static void seldo_run(struct Scsi_Host *shpnt)
1674 SETPORT(SSTAT1, CLRBUSFREE); 1523 SETPORT(SSTAT1, CLRBUSFREE);
1675 SETPORT(SSTAT1, CLRPHASECHG); 1524 SETPORT(SSTAT1, CLRPHASECHG);
1676 1525
1677 CURRENT_SC->SCp.phase &= ~(selecting|not_issued); 1526 CURRENT_SC->SCp.phase &= ~(selecting|not_issued);
1678 1527
1679 SETPORT(SCSISEQ, 0); 1528 SETPORT(SCSISEQ, 0);
1680 1529
1681 if (TESTLO(SSTAT0, SELDO)) { 1530 if (TESTLO(SSTAT0, SELDO)) {
1682 printk(ERR_LEAD "aha152x: passing bus free condition\n", CMDINFO(CURRENT_SC)); 1531 scmd_printk(KERN_ERR, CURRENT_SC,
1532 "aha152x: passing bus free condition\n");
1683 done(shpnt, DID_NO_CONNECT << 16); 1533 done(shpnt, DID_NO_CONNECT << 16);
1684 return; 1534 return;
1685 } 1535 }
1686 1536
1687 SETPORT(SSTAT0, CLRSELDO); 1537 SETPORT(SSTAT0, CLRSELDO);
1688 1538
1689 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun)); 1539 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
1690 1540
1691 if (CURRENT_SC->SCp.phase & aborting) { 1541 if (CURRENT_SC->SCp.phase & aborting) {
@@ -1693,7 +1543,7 @@ static void seldo_run(struct Scsi_Host *shpnt)
1693 } else if (CURRENT_SC->SCp.phase & resetting) { 1543 } else if (CURRENT_SC->SCp.phase & resetting) {
1694 ADDMSGO(BUS_DEVICE_RESET); 1544 ADDMSGO(BUS_DEVICE_RESET);
1695 } else if (SYNCNEG==0 && SYNCHRONOUS) { 1545 } else if (SYNCNEG==0 && SYNCHRONOUS) {
1696 CURRENT_SC->SCp.phase |= syncneg; 1546 CURRENT_SC->SCp.phase |= syncneg;
1697 MSGOLEN += spi_populate_sync_msg(&MSGO(MSGOLEN), 50, 8); 1547 MSGOLEN += spi_populate_sync_msg(&MSGO(MSGOLEN), 50, 8);
1698 SYNCNEG=1; /* negotiation in progress */ 1548 SYNCNEG=1; /* negotiation in progress */
1699 } 1549 }
@@ -1708,29 +1558,21 @@ static void seldo_run(struct Scsi_Host *shpnt)
1708 */ 1558 */
1709static void selto_run(struct Scsi_Host *shpnt) 1559static void selto_run(struct Scsi_Host *shpnt)
1710{ 1560{
1711 SETPORT(SCSISEQ, 0); 1561 SETPORT(SCSISEQ, 0);
1712 SETPORT(SSTAT1, CLRSELTIMO); 1562 SETPORT(SSTAT1, CLRSELTIMO);
1713 1563
1714 DPRINTK(debug_selection, DEBUG_LEAD "selection timeout\n", CMDINFO(CURRENT_SC)); 1564 if (!CURRENT_SC)
1715
1716 if(!CURRENT_SC) {
1717 DPRINTK(debug_selection, DEBUG_LEAD "!CURRENT_SC\n", CMDINFO(CURRENT_SC));
1718 return; 1565 return;
1719 }
1720 1566
1721 CURRENT_SC->SCp.phase &= ~selecting; 1567 CURRENT_SC->SCp.phase &= ~selecting;
1722 1568
1723 if (CURRENT_SC->SCp.phase & aborted) { 1569 if (CURRENT_SC->SCp.phase & aborted)
1724 DPRINTK(debug_selection, DEBUG_LEAD "aborted\n", CMDINFO(CURRENT_SC));
1725 done(shpnt, DID_ABORT << 16); 1570 done(shpnt, DID_ABORT << 16);
1726 } else if (TESTLO(SSTAT0, SELINGO)) { 1571 else if (TESTLO(SSTAT0, SELINGO))
1727 DPRINTK(debug_selection, DEBUG_LEAD "arbitration not won\n", CMDINFO(CURRENT_SC));
1728 done(shpnt, DID_BUS_BUSY << 16); 1572 done(shpnt, DID_BUS_BUSY << 16);
1729 } else { 1573 else
1730 /* ARBITRATION won, but SELECTION failed */ 1574 /* ARBITRATION won, but SELECTION failed */
1731 DPRINTK(debug_selection, DEBUG_LEAD "selection failed\n", CMDINFO(CURRENT_SC));
1732 done(shpnt, DID_NO_CONNECT << 16); 1575 done(shpnt, DID_NO_CONNECT << 16);
1733 }
1734} 1576}
1735 1577
1736/* 1578/*
@@ -1753,9 +1595,8 @@ static void seldi_run(struct Scsi_Host *shpnt)
1753 1595
1754 if(CURRENT_SC) { 1596 if(CURRENT_SC) {
1755 if(!(CURRENT_SC->SCp.phase & not_issued)) 1597 if(!(CURRENT_SC->SCp.phase & not_issued))
1756 printk(ERR_LEAD "command should not have been issued yet\n", CMDINFO(CURRENT_SC)); 1598 scmd_printk(KERN_ERR, CURRENT_SC,
1757 1599 "command should not have been issued yet\n");
1758 DPRINTK(debug_selection, ERR_LEAD "command requeued - reselection\n", CMDINFO(CURRENT_SC));
1759 1600
1760 DO_LOCK(flags); 1601 DO_LOCK(flags);
1761 append_SC(&ISSUE_SC, CURRENT_SC); 1602 append_SC(&ISSUE_SC, CURRENT_SC);
@@ -1764,17 +1605,16 @@ static void seldi_run(struct Scsi_Host *shpnt)
1764 CURRENT_SC = NULL; 1605 CURRENT_SC = NULL;
1765 } 1606 }
1766 1607
1767 if(!DISCONNECTED_SC) { 1608 if (!DISCONNECTED_SC)
1768 DPRINTK(debug_selection, DEBUG_LEAD "unexpected SELDI ", CMDINFO(CURRENT_SC));
1769 return; 1609 return;
1770 }
1771 1610
1772 RECONN_TARGET=-1; 1611 RECONN_TARGET=-1;
1773 1612
1774 selid = GETPORT(SELID) & ~(1 << shpnt->this_id); 1613 selid = GETPORT(SELID) & ~(1 << shpnt->this_id);
1775 1614
1776 if (selid==0) { 1615 if (selid==0) {
1777 printk("aha152x%d: target id unknown (%02x)\n", HOSTNO, selid); 1616 shost_printk(KERN_INFO, shpnt,
1617 "target id unknown (%02x)\n", selid);
1778 return; 1618 return;
1779 } 1619 }
1780 1620
@@ -1782,8 +1622,8 @@ static void seldi_run(struct Scsi_Host *shpnt)
1782 ; 1622 ;
1783 1623
1784 if(selid & ~(1 << target)) { 1624 if(selid & ~(1 << target)) {
1785 printk("aha152x%d: multiple targets reconnected (%02x)\n", 1625 shost_printk(KERN_INFO, shpnt,
1786 HOSTNO, selid); 1626 "multiple targets reconnected (%02x)\n", selid);
1787 } 1627 }
1788 1628
1789 1629
@@ -1793,7 +1633,6 @@ static void seldi_run(struct Scsi_Host *shpnt)
1793 SETRATE(HOSTDATA(shpnt)->syncrate[target]); 1633 SETRATE(HOSTDATA(shpnt)->syncrate[target]);
1794 1634
1795 RECONN_TARGET=target; 1635 RECONN_TARGET=target;
1796 DPRINTK(debug_selection, DEBUG_LEAD "target %d reselected (%02x).\n", CMDINFO(CURRENT_SC), target, selid);
1797} 1636}
1798 1637
1799/* 1638/*
@@ -1817,31 +1656,24 @@ static void msgi_run(struct Scsi_Host *shpnt)
1817 if(sstat1 & (PHASECHG|PHASEMIS|BUSFREE) || !(sstat1 & REQINIT)) 1656 if(sstat1 & (PHASECHG|PHASEMIS|BUSFREE) || !(sstat1 & REQINIT))
1818 return; 1657 return;
1819 1658
1820 if(TESTLO(SSTAT0,SPIORDY)) { 1659 if (TESTLO(SSTAT0, SPIORDY))
1821 DPRINTK(debug_msgi, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
1822 return; 1660 return;
1823 }
1824 1661
1825 ADDMSGI(GETPORT(SCSIDAT)); 1662 ADDMSGI(GETPORT(SCSIDAT));
1826 1663
1827#if defined(AHA152X_DEBUG)
1828 if (HOSTDATA(shpnt)->debug & debug_msgi) {
1829 printk(INFO_LEAD "inbound message %02x ", CMDINFO(CURRENT_SC), MSGI(0));
1830 spi_print_msg(&MSGI(0));
1831 printk("\n");
1832 }
1833#endif
1834
1835 if(!CURRENT_SC) { 1664 if(!CURRENT_SC) {
1836 if(LASTSTATE!=seldi) { 1665 if(LASTSTATE!=seldi) {
1837 printk(KERN_ERR "aha152x%d: message in w/o current command not after reselection\n", HOSTNO); 1666 shost_printk(KERN_ERR, shpnt,
1667 "message in w/o current command"
1668 " not after reselection\n");
1838 } 1669 }
1839 1670
1840 /* 1671 /*
1841 * Handle reselection 1672 * Handle reselection
1842 */ 1673 */
1843 if(!(MSGI(0) & IDENTIFY_BASE)) { 1674 if(!(MSGI(0) & IDENTIFY_BASE)) {
1844 printk(KERN_ERR "aha152x%d: target didn't identify after reselection\n", HOSTNO); 1675 shost_printk(KERN_ERR, shpnt,
1676 "target didn't identify after reselection\n");
1845 continue; 1677 continue;
1846 } 1678 }
1847 1679
@@ -1849,12 +1681,13 @@ static void msgi_run(struct Scsi_Host *shpnt)
1849 1681
1850 if (!CURRENT_SC) { 1682 if (!CURRENT_SC) {
1851 show_queues(shpnt); 1683 show_queues(shpnt);
1852 printk(KERN_ERR "aha152x%d: no disconnected command for target %d/%d\n", HOSTNO, RECONN_TARGET, MSGI(0) & 0x3f); 1684 shost_printk(KERN_ERR, shpnt,
1685 "no disconnected command"
1686 " for target %d/%d\n",
1687 RECONN_TARGET, MSGI(0) & 0x3f);
1853 continue; 1688 continue;
1854 } 1689 }
1855 1690
1856 DPRINTK(debug_msgi, DEBUG_LEAD "target reconnected\n", CMDINFO(CURRENT_SC));
1857
1858 CURRENT_SC->SCp.Message = MSGI(0); 1691 CURRENT_SC->SCp.Message = MSGI(0);
1859 CURRENT_SC->SCp.phase &= ~disconnected; 1692 CURRENT_SC->SCp.phase &= ~disconnected;
1860 1693
@@ -1862,31 +1695,32 @@ static void msgi_run(struct Scsi_Host *shpnt)
1862 1695
1863 /* next message if any */ 1696 /* next message if any */
1864 continue; 1697 continue;
1865 } 1698 }
1866 1699
1867 CURRENT_SC->SCp.Message = MSGI(0); 1700 CURRENT_SC->SCp.Message = MSGI(0);
1868 1701
1869 switch (MSGI(0)) { 1702 switch (MSGI(0)) {
1870 case DISCONNECT: 1703 case DISCONNECT:
1871 if (!RECONNECT) 1704 if (!RECONNECT)
1872 printk(WARN_LEAD "target was not allowed to disconnect\n", CMDINFO(CURRENT_SC)); 1705 scmd_printk(KERN_WARNING, CURRENT_SC,
1706 "target was not allowed to disconnect\n");
1873 1707
1874 CURRENT_SC->SCp.phase |= disconnected; 1708 CURRENT_SC->SCp.phase |= disconnected;
1875 break; 1709 break;
1876 1710
1877 case COMMAND_COMPLETE: 1711 case COMMAND_COMPLETE:
1878 if(CURRENT_SC->SCp.phase & completed)
1879 DPRINTK(debug_msgi, DEBUG_LEAD "again COMMAND COMPLETE\n", CMDINFO(CURRENT_SC));
1880
1881 CURRENT_SC->SCp.phase |= completed; 1712 CURRENT_SC->SCp.phase |= completed;
1882 break; 1713 break;
1883 1714
1884 case MESSAGE_REJECT: 1715 case MESSAGE_REJECT:
1885 if (SYNCNEG==1) { 1716 if (SYNCNEG==1) {
1886 printk(INFO_LEAD "Synchronous Data Transfer Request was rejected\n", CMDINFO(CURRENT_SC)); 1717 scmd_printk(KERN_INFO, CURRENT_SC,
1718 "Synchronous Data Transfer Request"
1719 " was rejected\n");
1887 SYNCNEG=2; /* negotiation completed */ 1720 SYNCNEG=2; /* negotiation completed */
1888 } else 1721 } else
1889 printk(INFO_LEAD "inbound message (MESSAGE REJECT)\n", CMDINFO(CURRENT_SC)); 1722 scmd_printk(KERN_INFO, CURRENT_SC,
1723 "inbound message (MESSAGE REJECT)\n");
1890 break; 1724 break;
1891 1725
1892 case SAVE_POINTERS: 1726 case SAVE_POINTERS:
@@ -1907,7 +1741,8 @@ static void msgi_run(struct Scsi_Host *shpnt)
1907 long ticks; 1741 long ticks;
1908 1742
1909 if (MSGI(1) != 3) { 1743 if (MSGI(1) != 3) {
1910 printk(ERR_LEAD "SDTR message length!=3\n", CMDINFO(CURRENT_SC)); 1744 scmd_printk(KERN_ERR, CURRENT_SC,
1745 "SDTR message length!=3\n");
1911 break; 1746 break;
1912 } 1747 }
1913 1748
@@ -1924,10 +1759,12 @@ static void msgi_run(struct Scsi_Host *shpnt)
1924 /* negotiation in progress */ 1759 /* negotiation in progress */
1925 if (ticks > 9 || MSGI(4) < 1 || MSGI(4) > 8) { 1760 if (ticks > 9 || MSGI(4) < 1 || MSGI(4) > 8) {
1926 ADDMSGO(MESSAGE_REJECT); 1761 ADDMSGO(MESSAGE_REJECT);
1927 printk(INFO_LEAD "received Synchronous Data Transfer Request invalid - rejected\n", CMDINFO(CURRENT_SC)); 1762 scmd_printk(KERN_INFO,
1763 CURRENT_SC,
1764 "received Synchronous Data Transfer Request invalid - rejected\n");
1928 break; 1765 break;
1929 } 1766 }
1930 1767
1931 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4); 1768 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
1932 } else if (ticks <= 9 && MSGI(4) >= 1) { 1769 } else if (ticks <= 9 && MSGI(4) >= 1) {
1933 ADDMSGO(EXTENDED_MESSAGE); 1770 ADDMSGO(EXTENDED_MESSAGE);
@@ -1947,11 +1784,14 @@ static void msgi_run(struct Scsi_Host *shpnt)
1947 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4); 1784 SYNCRATE |= ((ticks - 2) << 4) + MSGI(4);
1948 } else { 1785 } else {
1949 /* requested SDTR is too slow, do it asynchronously */ 1786 /* requested SDTR is too slow, do it asynchronously */
1950 printk(INFO_LEAD "Synchronous Data Transfer Request too slow - Rejecting\n", CMDINFO(CURRENT_SC)); 1787 scmd_printk(KERN_INFO,
1788 CURRENT_SC,
1789 "Synchronous Data Transfer Request too slow - Rejecting\n");
1951 ADDMSGO(MESSAGE_REJECT); 1790 ADDMSGO(MESSAGE_REJECT);
1952 } 1791 }
1953 1792
1954 SYNCNEG=2; /* negotiation completed */ 1793 /* negotiation completed */
1794 SYNCNEG=2;
1955 SETRATE(SYNCRATE); 1795 SETRATE(SYNCRATE);
1956 } 1796 }
1957 break; 1797 break;
@@ -1985,12 +1825,12 @@ static void msgi_run(struct Scsi_Host *shpnt)
1985static void msgi_end(struct Scsi_Host *shpnt) 1825static void msgi_end(struct Scsi_Host *shpnt)
1986{ 1826{
1987 if(MSGILEN>0) 1827 if(MSGILEN>0)
1988 printk(WARN_LEAD "target left before message completed (%d)\n", CMDINFO(CURRENT_SC), MSGILEN); 1828 scmd_printk(KERN_WARNING, CURRENT_SC,
1829 "target left before message completed (%d)\n",
1830 MSGILEN);
1989 1831
1990 if (MSGOLEN > 0 && !(GETPORT(SSTAT1) & BUSFREE)) { 1832 if (MSGOLEN > 0 && !(GETPORT(SSTAT1) & BUSFREE))
1991 DPRINTK(debug_msgi, DEBUG_LEAD "msgo pending\n", CMDINFO(CURRENT_SC));
1992 SETPORT(SCSISIG, P_MSGI | SIG_ATNO); 1833 SETPORT(SCSISIG, P_MSGI | SIG_ATNO);
1993 }
1994} 1834}
1995 1835
1996/* 1836/*
@@ -2003,21 +1843,12 @@ static void msgo_init(struct Scsi_Host *shpnt)
2003 if((CURRENT_SC->SCp.phase & syncneg) && SYNCNEG==2 && SYNCRATE==0) { 1843 if((CURRENT_SC->SCp.phase & syncneg) && SYNCNEG==2 && SYNCRATE==0) {
2004 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun)); 1844 ADDMSGO(IDENTIFY(RECONNECT, CURRENT_SC->device->lun));
2005 } else { 1845 } else {
2006 printk(INFO_LEAD "unexpected MESSAGE OUT phase; rejecting\n", CMDINFO(CURRENT_SC)); 1846 scmd_printk(KERN_INFO, CURRENT_SC,
1847 "unexpected MESSAGE OUT phase; rejecting\n");
2007 ADDMSGO(MESSAGE_REJECT); 1848 ADDMSGO(MESSAGE_REJECT);
2008 } 1849 }
2009 } 1850 }
2010 1851
2011#if defined(AHA152X_DEBUG)
2012 if(HOSTDATA(shpnt)->debug & debug_msgo) {
2013 int i;
2014
2015 printk(DEBUG_LEAD "messages( ", CMDINFO(CURRENT_SC));
2016 for (i=0; i<MSGOLEN; i+=spi_print_msg(&MSGO(i)), printk(" "))
2017 ;
2018 printk(")\n");
2019 }
2020#endif
2021} 1852}
2022 1853
2023/* 1854/*
@@ -2026,16 +1857,9 @@ static void msgo_init(struct Scsi_Host *shpnt)
2026 */ 1857 */
2027static void msgo_run(struct Scsi_Host *shpnt) 1858static void msgo_run(struct Scsi_Host *shpnt)
2028{ 1859{
2029 if(MSGO_I==MSGOLEN)
2030 DPRINTK(debug_msgo, DEBUG_LEAD "messages all sent (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO_I, MSGOLEN);
2031
2032 while(MSGO_I<MSGOLEN) { 1860 while(MSGO_I<MSGOLEN) {
2033 DPRINTK(debug_msgo, DEBUG_LEAD "message byte %02x (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO(MSGO_I), MSGO_I, MSGOLEN); 1861 if (TESTLO(SSTAT0, SPIORDY))
2034
2035 if(TESTLO(SSTAT0, SPIORDY)) {
2036 DPRINTK(debug_msgo, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
2037 return; 1862 return;
2038 }
2039 1863
2040 if (MSGO_I==MSGOLEN-1) { 1864 if (MSGO_I==MSGOLEN-1) {
2041 /* Leave MESSAGE OUT after transfer */ 1865 /* Leave MESSAGE OUT after transfer */
@@ -2059,36 +1883,33 @@ static void msgo_run(struct Scsi_Host *shpnt)
2059static void msgo_end(struct Scsi_Host *shpnt) 1883static void msgo_end(struct Scsi_Host *shpnt)
2060{ 1884{
2061 if(MSGO_I<MSGOLEN) { 1885 if(MSGO_I<MSGOLEN) {
2062 printk(ERR_LEAD "message sent incompletely (%d/%d)\n", CMDINFO(CURRENT_SC), MSGO_I, MSGOLEN); 1886 scmd_printk(KERN_ERR, CURRENT_SC,
1887 "message sent incompletely (%d/%d)\n",
1888 MSGO_I, MSGOLEN);
2063 if(SYNCNEG==1) { 1889 if(SYNCNEG==1) {
2064 printk(INFO_LEAD "Synchronous Data Transfer Request was rejected\n", CMDINFO(CURRENT_SC)); 1890 scmd_printk(KERN_INFO, CURRENT_SC,
1891 "Synchronous Data Transfer Request was rejected\n");
2065 SYNCNEG=2; 1892 SYNCNEG=2;
2066 } 1893 }
2067 } 1894 }
2068 1895
2069 MSGO_I = 0; 1896 MSGO_I = 0;
2070 MSGOLEN = 0; 1897 MSGOLEN = 0;
2071} 1898}
2072 1899
2073/* 1900/*
2074 * command phase 1901 * command phase
2075 * 1902 *
2076 */ 1903 */
2077static void cmd_init(struct Scsi_Host *shpnt) 1904static void cmd_init(struct Scsi_Host *shpnt)
2078{ 1905{
2079 if (CURRENT_SC->SCp.sent_command) { 1906 if (CURRENT_SC->SCp.sent_command) {
2080 printk(ERR_LEAD "command already sent\n", CMDINFO(CURRENT_SC)); 1907 scmd_printk(KERN_ERR, CURRENT_SC,
1908 "command already sent\n");
2081 done(shpnt, DID_ERROR << 16); 1909 done(shpnt, DID_ERROR << 16);
2082 return; 1910 return;
2083 } 1911 }
2084 1912
2085#if defined(AHA152X_DEBUG)
2086 if (HOSTDATA(shpnt)->debug & debug_cmd) {
2087 printk(DEBUG_LEAD "cmd_init: ", CMDINFO(CURRENT_SC));
2088 __scsi_print_command(CURRENT_SC->cmnd);
2089 }
2090#endif
2091
2092 CMD_I=0; 1913 CMD_I=0;
2093} 1914}
2094 1915
@@ -2098,18 +1919,9 @@ static void cmd_init(struct Scsi_Host *shpnt)
2098 */ 1919 */
2099static void cmd_run(struct Scsi_Host *shpnt) 1920static void cmd_run(struct Scsi_Host *shpnt)
2100{ 1921{
2101 if(CMD_I==CURRENT_SC->cmd_len) {
2102 DPRINTK(debug_cmd, DEBUG_LEAD "command already completely sent (%d/%d)", CMDINFO(CURRENT_SC), CMD_I, CURRENT_SC->cmd_len);
2103 disp_ports(shpnt);
2104 }
2105
2106 while(CMD_I<CURRENT_SC->cmd_len) { 1922 while(CMD_I<CURRENT_SC->cmd_len) {
2107 DPRINTK(debug_cmd, DEBUG_LEAD "command byte %02x (%d/%d)\n", CMDINFO(CURRENT_SC), CURRENT_SC->cmnd[CMD_I], CMD_I, CURRENT_SC->cmd_len); 1923 if (TESTLO(SSTAT0, SPIORDY))
2108
2109 if(TESTLO(SSTAT0, SPIORDY)) {
2110 DPRINTK(debug_cmd, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
2111 return; 1924 return;
2112 }
2113 1925
2114 SETPORT(SCSIDAT, CURRENT_SC->cmnd[CMD_I++]); 1926 SETPORT(SCSIDAT, CURRENT_SC->cmnd[CMD_I++]);
2115 } 1927 }
@@ -2118,7 +1930,9 @@ static void cmd_run(struct Scsi_Host *shpnt)
2118static void cmd_end(struct Scsi_Host *shpnt) 1930static void cmd_end(struct Scsi_Host *shpnt)
2119{ 1931{
2120 if(CMD_I<CURRENT_SC->cmd_len) 1932 if(CMD_I<CURRENT_SC->cmd_len)
2121 printk(ERR_LEAD "command sent incompletely (%d/%d)\n", CMDINFO(CURRENT_SC), CMD_I, CURRENT_SC->cmd_len); 1933 scmd_printk(KERN_ERR, CURRENT_SC,
1934 "command sent incompletely (%d/%d)\n",
1935 CMD_I, CURRENT_SC->cmd_len);
2122 else 1936 else
2123 CURRENT_SC->SCp.sent_command++; 1937 CURRENT_SC->SCp.sent_command++;
2124} 1938}
@@ -2129,20 +1943,11 @@ static void cmd_end(struct Scsi_Host *shpnt)
2129 */ 1943 */
2130static void status_run(struct Scsi_Host *shpnt) 1944static void status_run(struct Scsi_Host *shpnt)
2131{ 1945{
2132 if(TESTLO(SSTAT0,SPIORDY)) { 1946 if (TESTLO(SSTAT0, SPIORDY))
2133 DPRINTK(debug_status, DEBUG_LEAD "!SPIORDY\n", CMDINFO(CURRENT_SC));
2134 return; 1947 return;
2135 }
2136 1948
2137 CURRENT_SC->SCp.Status = GETPORT(SCSIDAT); 1949 CURRENT_SC->SCp.Status = GETPORT(SCSIDAT);
2138 1950
2139#if defined(AHA152X_DEBUG)
2140 if (HOSTDATA(shpnt)->debug & debug_status) {
2141 printk(DEBUG_LEAD "inbound status %02x ", CMDINFO(CURRENT_SC), CURRENT_SC->SCp.Status);
2142 scsi_print_status(CURRENT_SC->SCp.Status);
2143 printk("\n");
2144 }
2145#endif
2146} 1951}
2147 1952
2148/* 1953/*
@@ -2161,10 +1966,6 @@ static void datai_init(struct Scsi_Host *shpnt)
2161 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE); 1966 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE);
2162 1967
2163 DATA_LEN=0; 1968 DATA_LEN=0;
2164 DPRINTK(debug_datai,
2165 DEBUG_LEAD "datai_init: request_bufflen=%d resid=%d\n",
2166 CMDINFO(CURRENT_SC), scsi_bufflen(CURRENT_SC),
2167 scsi_get_resid(CURRENT_SC));
2168} 1969}
2169 1970
2170static void datai_run(struct Scsi_Host *shpnt) 1971static void datai_run(struct Scsi_Host *shpnt)
@@ -2186,8 +1987,7 @@ static void datai_run(struct Scsi_Host *shpnt)
2186 barrier(); 1987 barrier();
2187 1988
2188 if(TESTLO(DMASTAT, DFIFOFULL|INTSTAT)) { 1989 if(TESTLO(DMASTAT, DFIFOFULL|INTSTAT)) {
2189 printk(ERR_LEAD "datai timeout", CMDINFO(CURRENT_SC)); 1990 scmd_printk(KERN_ERR, CURRENT_SC, "datai timeout\n");
2190 disp_ports(shpnt);
2191 break; 1991 break;
2192 } 1992 }
2193 1993
@@ -2199,8 +1999,8 @@ static void datai_run(struct Scsi_Host *shpnt)
2199 barrier(); 1999 barrier();
2200 2000
2201 if(TESTLO(SSTAT2, SEMPTY)) { 2001 if(TESTLO(SSTAT2, SEMPTY)) {
2202 printk(ERR_LEAD "datai sempty timeout", CMDINFO(CURRENT_SC)); 2002 scmd_printk(KERN_ERR, CURRENT_SC,
2203 disp_ports(shpnt); 2003 "datai sempty timeout");
2204 break; 2004 break;
2205 } 2005 }
2206 2006
@@ -2209,48 +2009,49 @@ static void datai_run(struct Scsi_Host *shpnt)
2209 2009
2210 if(CURRENT_SC->SCp.this_residual>0) { 2010 if(CURRENT_SC->SCp.this_residual>0) {
2211 while(fifodata>0 && CURRENT_SC->SCp.this_residual>0) { 2011 while(fifodata>0 && CURRENT_SC->SCp.this_residual>0) {
2212 data_count = fifodata>CURRENT_SC->SCp.this_residual ? 2012 data_count = fifodata > CURRENT_SC->SCp.this_residual ?
2213 CURRENT_SC->SCp.this_residual : 2013 CURRENT_SC->SCp.this_residual :
2214 fifodata; 2014 fifodata;
2215 fifodata -= data_count; 2015 fifodata -= data_count;
2216 2016
2217 if(data_count & 1) { 2017 if (data_count & 1) {
2218 DPRINTK(debug_datai, DEBUG_LEAD "8bit\n", CMDINFO(CURRENT_SC)); 2018 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2219 SETPORT(DMACNTRL0, ENDMA|_8BIT); 2019 *CURRENT_SC->SCp.ptr++ = GETPORT(DATAPORT);
2220 *CURRENT_SC->SCp.ptr++ = GETPORT(DATAPORT); 2020 CURRENT_SC->SCp.this_residual--;
2221 CURRENT_SC->SCp.this_residual--; 2021 DATA_LEN++;
2222 DATA_LEN++; 2022 SETPORT(DMACNTRL0, ENDMA);
2223 SETPORT(DMACNTRL0, ENDMA); 2023 }
2224 } 2024
2225 2025 if (data_count > 1) {
2226 if(data_count > 1) { 2026 data_count >>= 1;
2227 DPRINTK(debug_datai, DEBUG_LEAD "16bit(%d)\n", CMDINFO(CURRENT_SC), data_count); 2027 insw(DATAPORT, CURRENT_SC->SCp.ptr, data_count);
2228 data_count >>= 1; 2028 CURRENT_SC->SCp.ptr += 2 * data_count;
2229 insw(DATAPORT, CURRENT_SC->SCp.ptr, data_count); 2029 CURRENT_SC->SCp.this_residual -= 2 * data_count;
2230 CURRENT_SC->SCp.ptr += 2 * data_count; 2030 DATA_LEN += 2 * data_count;
2231 CURRENT_SC->SCp.this_residual -= 2 * data_count; 2031 }
2232 DATA_LEN += 2 * data_count; 2032
2233 } 2033 if (CURRENT_SC->SCp.this_residual == 0 &&
2234 2034 CURRENT_SC->SCp.buffers_residual > 0) {
2235 if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) { 2035 /* advance to next buffer */
2236 /* advance to next buffer */ 2036 CURRENT_SC->SCp.buffers_residual--;
2237 CURRENT_SC->SCp.buffers_residual--; 2037 CURRENT_SC->SCp.buffer++;
2238 CURRENT_SC->SCp.buffer++; 2038 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer);
2239 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer); 2039 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
2240 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length; 2040 }
2241 } 2041 }
2242 } 2042 } else if (fifodata > 0) {
2243 } else if(fifodata>0) { 2043 scmd_printk(KERN_ERR, CURRENT_SC,
2244 printk(ERR_LEAD "no buffers left for %d(%d) bytes (data overrun!?)\n", CMDINFO(CURRENT_SC), fifodata, GETPORT(FIFOSTAT)); 2044 "no buffers left for %d(%d) bytes"
2245 SETPORT(DMACNTRL0, ENDMA|_8BIT); 2045 " (data overrun!?)\n",
2046 fifodata, GETPORT(FIFOSTAT));
2047 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2246 while(fifodata>0) { 2048 while(fifodata>0) {
2247 int data; 2049 int data;
2248 data=GETPORT(DATAPORT); 2050 data=GETPORT(DATAPORT);
2249 DPRINTK(debug_datai, DEBUG_LEAD "data=%02x\n", CMDINFO(CURRENT_SC), data);
2250 fifodata--; 2051 fifodata--;
2251 DATA_LEN++; 2052 DATA_LEN++;
2252 } 2053 }
2253 SETPORT(DMACNTRL0, ENDMA|_8BIT); 2054 SETPORT(DMACNTRL0, ENDMA|_8BIT);
2254 } 2055 }
2255 } 2056 }
2256 2057
@@ -2258,19 +2059,20 @@ static void datai_run(struct Scsi_Host *shpnt)
2258 TESTLO(DMASTAT, DFIFOEMP) || 2059 TESTLO(DMASTAT, DFIFOEMP) ||
2259 TESTLO(SSTAT2, SEMPTY) || 2060 TESTLO(SSTAT2, SEMPTY) ||
2260 GETPORT(FIFOSTAT)>0) { 2061 GETPORT(FIFOSTAT)>0) {
2261 /* 2062 /*
2262 * something went wrong, if there's something left in the fifos 2063 * something went wrong, if there's something left in the fifos
2263 * or the phase didn't change 2064 * or the phase didn't change
2264 */ 2065 */
2265 printk(ERR_LEAD "fifos should be empty and phase should have changed\n", CMDINFO(CURRENT_SC)); 2066 scmd_printk(KERN_ERR, CURRENT_SC,
2266 disp_ports(shpnt); 2067 "fifos should be empty and phase should have changed\n");
2267 } 2068 }
2268 2069
2269 if(DATA_LEN!=GETSTCNT()) { 2070 if(DATA_LEN!=GETSTCNT()) {
2270 printk(ERR_LEAD 2071 scmd_printk(KERN_ERR, CURRENT_SC,
2271 "manual transfer count differs from automatic (count=%d;stcnt=%d;diff=%d;fifostat=%d)", 2072 "manual transfer count differs from automatic "
2272 CMDINFO(CURRENT_SC), DATA_LEN, GETSTCNT(), GETSTCNT()-DATA_LEN, GETPORT(FIFOSTAT)); 2073 "(count=%d;stcnt=%d;diff=%d;fifostat=%d)",
2273 disp_ports(shpnt); 2074 DATA_LEN, GETSTCNT(), GETSTCNT()-DATA_LEN,
2075 GETPORT(FIFOSTAT));
2274 mdelay(10000); 2076 mdelay(10000);
2275 } 2077 }
2276} 2078}
@@ -2279,11 +2081,6 @@ static void datai_end(struct Scsi_Host *shpnt)
2279{ 2081{
2280 CMD_INC_RESID(CURRENT_SC, -GETSTCNT()); 2082 CMD_INC_RESID(CURRENT_SC, -GETSTCNT());
2281 2083
2282 DPRINTK(debug_datai,
2283 DEBUG_LEAD "datai_end: request_bufflen=%d resid=%d stcnt=%d\n",
2284 CMDINFO(CURRENT_SC), scsi_bufflen(CURRENT_SC),
2285 scsi_get_resid(CURRENT_SC), GETSTCNT());
2286
2287 SETPORT(SXFRCTL0, CH1|CLRSTCNT); 2084 SETPORT(SXFRCTL0, CH1|CLRSTCNT);
2288 SETPORT(DMACNTRL0, 0); 2085 SETPORT(DMACNTRL0, 0);
2289} 2086}
@@ -2304,11 +2101,6 @@ static void datao_init(struct Scsi_Host *shpnt)
2304 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE ); 2101 SETPORT(SIMODE1, ENSCSIPERR | ENSCSIRST | ENPHASEMIS | ENBUSFREE );
2305 2102
2306 DATA_LEN = scsi_get_resid(CURRENT_SC); 2103 DATA_LEN = scsi_get_resid(CURRENT_SC);
2307
2308 DPRINTK(debug_datao,
2309 DEBUG_LEAD "datao_init: request_bufflen=%d; resid=%d\n",
2310 CMDINFO(CURRENT_SC), scsi_bufflen(CURRENT_SC),
2311 scsi_get_resid(CURRENT_SC));
2312} 2104}
2313 2105
2314static void datao_run(struct Scsi_Host *shpnt) 2106static void datao_run(struct Scsi_Host *shpnt)
@@ -2323,8 +2115,9 @@ static void datao_run(struct Scsi_Host *shpnt)
2323 data_count=CURRENT_SC->SCp.this_residual; 2115 data_count=CURRENT_SC->SCp.this_residual;
2324 2116
2325 if(TESTLO(DMASTAT, DFIFOEMP)) { 2117 if(TESTLO(DMASTAT, DFIFOEMP)) {
2326 printk(ERR_LEAD "datao fifo not empty (%d)", CMDINFO(CURRENT_SC), GETPORT(FIFOSTAT)); 2118 scmd_printk(KERN_ERR, CURRENT_SC,
2327 disp_ports(shpnt); 2119 "datao fifo not empty (%d)",
2120 GETPORT(FIFOSTAT));
2328 break; 2121 break;
2329 } 2122 }
2330 2123
@@ -2342,7 +2135,7 @@ static void datao_run(struct Scsi_Host *shpnt)
2342 CURRENT_SC->SCp.ptr += 2 * data_count; 2135 CURRENT_SC->SCp.ptr += 2 * data_count;
2343 CURRENT_SC->SCp.this_residual -= 2 * data_count; 2136 CURRENT_SC->SCp.this_residual -= 2 * data_count;
2344 CMD_INC_RESID(CURRENT_SC, -2 * data_count); 2137 CMD_INC_RESID(CURRENT_SC, -2 * data_count);
2345 } 2138 }
2346 2139
2347 if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) { 2140 if(CURRENT_SC->SCp.this_residual==0 && CURRENT_SC->SCp.buffers_residual>0) {
2348 /* advance to next buffer */ 2141 /* advance to next buffer */
@@ -2357,8 +2150,7 @@ static void datao_run(struct Scsi_Host *shpnt)
2357 barrier(); 2150 barrier();
2358 2151
2359 if(TESTLO(DMASTAT, DFIFOEMP|INTSTAT)) { 2152 if(TESTLO(DMASTAT, DFIFOEMP|INTSTAT)) {
2360 printk(ERR_LEAD "dataout timeout", CMDINFO(CURRENT_SC)); 2153 scmd_printk(KERN_ERR, CURRENT_SC, "dataout timeout\n");
2361 disp_ports(shpnt);
2362 break; 2154 break;
2363 } 2155 }
2364 } 2156 }
@@ -2368,35 +2160,23 @@ static void datao_end(struct Scsi_Host *shpnt)
2368{ 2160{
2369 if(TESTLO(DMASTAT, DFIFOEMP)) { 2161 if(TESTLO(DMASTAT, DFIFOEMP)) {
2370 int data_count = (DATA_LEN - scsi_get_resid(CURRENT_SC)) - 2162 int data_count = (DATA_LEN - scsi_get_resid(CURRENT_SC)) -
2371 GETSTCNT(); 2163 GETSTCNT();
2372
2373 DPRINTK(debug_datao, DEBUG_LEAD "datao: %d bytes to resend (%d written, %d transferred)\n",
2374 CMDINFO(CURRENT_SC),
2375 data_count,
2376 DATA_LEN - scsi_get_resid(CURRENT_SC),
2377 GETSTCNT());
2378 2164
2379 CMD_INC_RESID(CURRENT_SC, data_count); 2165 CMD_INC_RESID(CURRENT_SC, data_count);
2380 2166
2381 data_count -= CURRENT_SC->SCp.ptr - 2167 data_count -= CURRENT_SC->SCp.ptr -
2382 SG_ADDRESS(CURRENT_SC->SCp.buffer); 2168 SG_ADDRESS(CURRENT_SC->SCp.buffer);
2383 while(data_count>0) { 2169 while(data_count>0) {
2384 CURRENT_SC->SCp.buffer--; 2170 CURRENT_SC->SCp.buffer--;
2385 CURRENT_SC->SCp.buffers_residual++; 2171 CURRENT_SC->SCp.buffers_residual++;
2386 data_count -= CURRENT_SC->SCp.buffer->length; 2172 data_count -= CURRENT_SC->SCp.buffer->length;
2387 } 2173 }
2388 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer) - 2174 CURRENT_SC->SCp.ptr = SG_ADDRESS(CURRENT_SC->SCp.buffer) -
2389 data_count; 2175 data_count;
2390 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length + 2176 CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length +
2391 data_count; 2177 data_count;
2392 } 2178 }
2393 2179
2394 DPRINTK(debug_datao, DEBUG_LEAD "datao_end: request_bufflen=%d; resid=%d; stcnt=%d\n",
2395 CMDINFO(CURRENT_SC),
2396 scsi_bufflen(CURRENT_SC),
2397 scsi_get_resid(CURRENT_SC),
2398 GETSTCNT());
2399
2400 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT); 2180 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
2401 SETPORT(SXFRCTL0, CH1); 2181 SETPORT(SXFRCTL0, CH1);
2402 2182
@@ -2420,7 +2200,7 @@ static int update_state(struct Scsi_Host *shpnt)
2420 STATE=rsti; 2200 STATE=rsti;
2421 SETPORT(SCSISEQ,0); 2201 SETPORT(SCSISEQ,0);
2422 SETPORT(SSTAT1,SCSIRSTI); 2202 SETPORT(SSTAT1,SCSIRSTI);
2423 } else if(stat0 & SELDI && PREVSTATE==busfree) { 2203 } else if (stat0 & SELDI && PREVSTATE == busfree) {
2424 STATE=seldi; 2204 STATE=seldi;
2425 } else if(stat0 & SELDO && CURRENT_SC && (CURRENT_SC->SCp.phase & selecting)) { 2205 } else if(stat0 & SELDO && CURRENT_SC && (CURRENT_SC->SCp.phase & selecting)) {
2426 STATE=seldo; 2206 STATE=seldo;
@@ -2445,8 +2225,7 @@ static int update_state(struct Scsi_Host *shpnt)
2445 } 2225 }
2446 2226
2447 if((stat0 & SELDI) && STATE!=seldi && !dataphase) { 2227 if((stat0 & SELDI) && STATE!=seldi && !dataphase) {
2448 printk(INFO_LEAD "reselection missed?", CMDINFO(CURRENT_SC)); 2228 scmd_printk(KERN_INFO, CURRENT_SC, "reselection missed?");
2449 disp_ports(shpnt);
2450 } 2229 }
2451 2230
2452 if(STATE!=PREVSTATE) { 2231 if(STATE!=PREVSTATE) {
@@ -2464,7 +2243,7 @@ static int update_state(struct Scsi_Host *shpnt)
2464 */ 2243 */
2465static void parerr_run(struct Scsi_Host *shpnt) 2244static void parerr_run(struct Scsi_Host *shpnt)
2466{ 2245{
2467 printk(ERR_LEAD "parity error\n", CMDINFO(CURRENT_SC)); 2246 scmd_printk(KERN_ERR, CURRENT_SC, "parity error\n");
2468 done(shpnt, DID_PARITY << 16); 2247 done(shpnt, DID_PARITY << 16);
2469} 2248}
2470 2249
@@ -2476,8 +2255,8 @@ static void rsti_run(struct Scsi_Host *shpnt)
2476{ 2255{
2477 Scsi_Cmnd *ptr; 2256 Scsi_Cmnd *ptr;
2478 2257
2479 printk(KERN_NOTICE "aha152x%d: scsi reset in\n", HOSTNO); 2258 shost_printk(KERN_NOTICE, shpnt, "scsi reset in\n");
2480 2259
2481 ptr=DISCONNECTED_SC; 2260 ptr=DISCONNECTED_SC;
2482 while(ptr) { 2261 while(ptr) {
2483 Scsi_Cmnd *next = SCNEXT(ptr); 2262 Scsi_Cmnd *next = SCNEXT(ptr);
@@ -2539,8 +2318,6 @@ static void is_complete(struct Scsi_Host *shpnt)
2539 2318
2540 dataphase=update_state(shpnt); 2319 dataphase=update_state(shpnt);
2541 2320
2542 DPRINTK(debug_phases, LEAD "start %s %s(%s)\n", CMDINFO(CURRENT_SC), states[STATE].name, states[PREVSTATE].name, states[LASTSTATE].name);
2543
2544 /* 2321 /*
2545 * end previous state 2322 * end previous state
2546 * 2323 *
@@ -2567,9 +2344,9 @@ static void is_complete(struct Scsi_Host *shpnt)
2567 if(dataphase) { 2344 if(dataphase) {
2568 SETPORT(SSTAT0, REQINIT); 2345 SETPORT(SSTAT0, REQINIT);
2569 SETPORT(SCSISIG, GETPORT(SCSISIG) & P_MASK); 2346 SETPORT(SCSISIG, GETPORT(SCSISIG) & P_MASK);
2570 SETPORT(SSTAT1, PHASECHG); 2347 SETPORT(SSTAT1, PHASECHG);
2571 } 2348 }
2572 2349
2573 /* 2350 /*
2574 * enable SPIO mode if previous didn't use it 2351 * enable SPIO mode if previous didn't use it
2575 * and this one does 2352 * and this one does
@@ -2581,14 +2358,14 @@ static void is_complete(struct Scsi_Host *shpnt)
2581 if(CURRENT_SC) 2358 if(CURRENT_SC)
2582 CURRENT_SC->SCp.phase |= spiordy; 2359 CURRENT_SC->SCp.phase |= spiordy;
2583 } 2360 }
2584 2361
2585 /* 2362 /*
2586 * initialize for new state 2363 * initialize for new state
2587 * 2364 *
2588 */ 2365 */
2589 if(PREVSTATE!=STATE && states[STATE].init) 2366 if(PREVSTATE!=STATE && states[STATE].init)
2590 states[STATE].init(shpnt); 2367 states[STATE].init(shpnt);
2591 2368
2592 /* 2369 /*
2593 * handle current state 2370 * handle current state
2594 * 2371 *
@@ -2596,8 +2373,9 @@ static void is_complete(struct Scsi_Host *shpnt)
2596 if(states[STATE].run) 2373 if(states[STATE].run)
2597 states[STATE].run(shpnt); 2374 states[STATE].run(shpnt);
2598 else 2375 else
2599 printk(ERR_LEAD "unexpected state (%x)\n", CMDINFO(CURRENT_SC), STATE); 2376 scmd_printk(KERN_ERR, CURRENT_SC,
2600 2377 "unexpected state (%x)\n", STATE);
2378
2601 /* 2379 /*
2602 * setup controller to interrupt on 2380 * setup controller to interrupt on
2603 * the next expected condition and 2381 * the next expected condition and
@@ -2613,7 +2391,6 @@ static void is_complete(struct Scsi_Host *shpnt)
2613 HOSTDATA(shpnt)->time[STATE] += jiffies-start; 2391 HOSTDATA(shpnt)->time[STATE] += jiffies-start;
2614#endif 2392#endif
2615 2393
2616 DPRINTK(debug_phases, LEAD "end %s %s(%s)\n", CMDINFO(CURRENT_SC), states[STATE].name, states[PREVSTATE].name, states[LASTSTATE].name);
2617 } while(pending); 2394 } while(pending);
2618 2395
2619 /* 2396 /*
@@ -2626,289 +2403,42 @@ static void is_complete(struct Scsi_Host *shpnt)
2626} 2403}
2627 2404
2628 2405
2629/* 2406/*
2630 * Dump the current driver status and panic 2407 * Dump the current driver status and panic
2631 */ 2408 */
2632static void aha152x_error(struct Scsi_Host *shpnt, char *msg) 2409static void aha152x_error(struct Scsi_Host *shpnt, char *msg)
2633{ 2410{
2634 printk(KERN_EMERG "\naha152x%d: %s\n", HOSTNO, msg); 2411 shost_printk(KERN_EMERG, shpnt, "%s\n", msg);
2635 show_queues(shpnt); 2412 show_queues(shpnt);
2636 panic("aha152x panic\n"); 2413 panic("aha152x panic\n");
2637} 2414}
2638 2415
2639/* 2416/*
2640 * Display registers of AIC-6260
2641 */
2642static void disp_ports(struct Scsi_Host *shpnt)
2643{
2644#if defined(AHA152X_DEBUG)
2645 int s;
2646
2647 printk("\n%s: %s(%s) ",
2648 CURRENT_SC ? "busy" : "waiting",
2649 states[STATE].name,
2650 states[PREVSTATE].name);
2651
2652 s = GETPORT(SCSISEQ);
2653 printk("SCSISEQ( ");
2654 if (s & TEMODEO)
2655 printk("TARGET MODE ");
2656 if (s & ENSELO)
2657 printk("SELO ");
2658 if (s & ENSELI)
2659 printk("SELI ");
2660 if (s & ENRESELI)
2661 printk("RESELI ");
2662 if (s & ENAUTOATNO)
2663 printk("AUTOATNO ");
2664 if (s & ENAUTOATNI)
2665 printk("AUTOATNI ");
2666 if (s & ENAUTOATNP)
2667 printk("AUTOATNP ");
2668 if (s & SCSIRSTO)
2669 printk("SCSIRSTO ");
2670 printk(");");
2671
2672 printk(" SCSISIG(");
2673 s = GETPORT(SCSISIG);
2674 switch (s & P_MASK) {
2675 case P_DATAO:
2676 printk("DATA OUT");
2677 break;
2678 case P_DATAI:
2679 printk("DATA IN");
2680 break;
2681 case P_CMD:
2682 printk("COMMAND");
2683 break;
2684 case P_STATUS:
2685 printk("STATUS");
2686 break;
2687 case P_MSGO:
2688 printk("MESSAGE OUT");
2689 break;
2690 case P_MSGI:
2691 printk("MESSAGE IN");
2692 break;
2693 default:
2694 printk("*invalid*");
2695 break;
2696 }
2697
2698 printk("); ");
2699
2700 printk("INTSTAT (%s); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
2701
2702 printk("SSTAT( ");
2703 s = GETPORT(SSTAT0);
2704 if (s & TARGET)
2705 printk("TARGET ");
2706 if (s & SELDO)
2707 printk("SELDO ");
2708 if (s & SELDI)
2709 printk("SELDI ");
2710 if (s & SELINGO)
2711 printk("SELINGO ");
2712 if (s & SWRAP)
2713 printk("SWRAP ");
2714 if (s & SDONE)
2715 printk("SDONE ");
2716 if (s & SPIORDY)
2717 printk("SPIORDY ");
2718 if (s & DMADONE)
2719 printk("DMADONE ");
2720
2721 s = GETPORT(SSTAT1);
2722 if (s & SELTO)
2723 printk("SELTO ");
2724 if (s & ATNTARG)
2725 printk("ATNTARG ");
2726 if (s & SCSIRSTI)
2727 printk("SCSIRSTI ");
2728 if (s & PHASEMIS)
2729 printk("PHASEMIS ");
2730 if (s & BUSFREE)
2731 printk("BUSFREE ");
2732 if (s & SCSIPERR)
2733 printk("SCSIPERR ");
2734 if (s & PHASECHG)
2735 printk("PHASECHG ");
2736 if (s & REQINIT)
2737 printk("REQINIT ");
2738 printk("); ");
2739
2740
2741 printk("SSTAT( ");
2742
2743 s = GETPORT(SSTAT0) & GETPORT(SIMODE0);
2744
2745 if (s & TARGET)
2746 printk("TARGET ");
2747 if (s & SELDO)
2748 printk("SELDO ");
2749 if (s & SELDI)
2750 printk("SELDI ");
2751 if (s & SELINGO)
2752 printk("SELINGO ");
2753 if (s & SWRAP)
2754 printk("SWRAP ");
2755 if (s & SDONE)
2756 printk("SDONE ");
2757 if (s & SPIORDY)
2758 printk("SPIORDY ");
2759 if (s & DMADONE)
2760 printk("DMADONE ");
2761
2762 s = GETPORT(SSTAT1) & GETPORT(SIMODE1);
2763
2764 if (s & SELTO)
2765 printk("SELTO ");
2766 if (s & ATNTARG)
2767 printk("ATNTARG ");
2768 if (s & SCSIRSTI)
2769 printk("SCSIRSTI ");
2770 if (s & PHASEMIS)
2771 printk("PHASEMIS ");
2772 if (s & BUSFREE)
2773 printk("BUSFREE ");
2774 if (s & SCSIPERR)
2775 printk("SCSIPERR ");
2776 if (s & PHASECHG)
2777 printk("PHASECHG ");
2778 if (s & REQINIT)
2779 printk("REQINIT ");
2780 printk("); ");
2781
2782 printk("SXFRCTL0( ");
2783
2784 s = GETPORT(SXFRCTL0);
2785 if (s & SCSIEN)
2786 printk("SCSIEN ");
2787 if (s & DMAEN)
2788 printk("DMAEN ");
2789 if (s & CH1)
2790 printk("CH1 ");
2791 if (s & CLRSTCNT)
2792 printk("CLRSTCNT ");
2793 if (s & SPIOEN)
2794 printk("SPIOEN ");
2795 if (s & CLRCH1)
2796 printk("CLRCH1 ");
2797 printk("); ");
2798
2799 printk("SIGNAL( ");
2800
2801 s = GETPORT(SCSISIG);
2802 if (s & SIG_ATNI)
2803 printk("ATNI ");
2804 if (s & SIG_SELI)
2805 printk("SELI ");
2806 if (s & SIG_BSYI)
2807 printk("BSYI ");
2808 if (s & SIG_REQI)
2809 printk("REQI ");
2810 if (s & SIG_ACKI)
2811 printk("ACKI ");
2812 printk("); ");
2813
2814 printk("SELID (%02x), ", GETPORT(SELID));
2815
2816 printk("STCNT (%d), ", GETSTCNT());
2817
2818 printk("SSTAT2( ");
2819
2820 s = GETPORT(SSTAT2);
2821 if (s & SOFFSET)
2822 printk("SOFFSET ");
2823 if (s & SEMPTY)
2824 printk("SEMPTY ");
2825 if (s & SFULL)
2826 printk("SFULL ");
2827 printk("); SFCNT (%d); ", s & (SFULL | SFCNT));
2828
2829 s = GETPORT(SSTAT3);
2830 printk("SCSICNT (%d), OFFCNT(%d), ", (s & 0xf0) >> 4, s & 0x0f);
2831
2832 printk("SSTAT4( ");
2833 s = GETPORT(SSTAT4);
2834 if (s & SYNCERR)
2835 printk("SYNCERR ");
2836 if (s & FWERR)
2837 printk("FWERR ");
2838 if (s & FRERR)
2839 printk("FRERR ");
2840 printk("); ");
2841
2842 printk("DMACNTRL0( ");
2843 s = GETPORT(DMACNTRL0);
2844 printk("%s ", s & _8BIT ? "8BIT" : "16BIT");
2845 printk("%s ", s & DMA ? "DMA" : "PIO");
2846 printk("%s ", s & WRITE_READ ? "WRITE" : "READ");
2847 if (s & ENDMA)
2848 printk("ENDMA ");
2849 if (s & INTEN)
2850 printk("INTEN ");
2851 if (s & RSTFIFO)
2852 printk("RSTFIFO ");
2853 if (s & SWINT)
2854 printk("SWINT ");
2855 printk("); ");
2856
2857 printk("DMASTAT( ");
2858 s = GETPORT(DMASTAT);
2859 if (s & ATDONE)
2860 printk("ATDONE ");
2861 if (s & WORDRDY)
2862 printk("WORDRDY ");
2863 if (s & DFIFOFULL)
2864 printk("DFIFOFULL ");
2865 if (s & DFIFOEMP)
2866 printk("DFIFOEMP ");
2867 printk(")\n");
2868#endif
2869}
2870
2871/*
2872 * display enabled interrupts 2417 * display enabled interrupts
2873 */ 2418 */
2874static void disp_enintr(struct Scsi_Host *shpnt) 2419static void disp_enintr(struct Scsi_Host *shpnt)
2875{ 2420{
2876 int s; 2421 int s0, s1;
2877 2422
2878 printk(KERN_DEBUG "enabled interrupts ( "); 2423 s0 = GETPORT(SIMODE0);
2879 2424 s1 = GETPORT(SIMODE1);
2880 s = GETPORT(SIMODE0); 2425
2881 if (s & ENSELDO) 2426 shost_printk(KERN_DEBUG, shpnt,
2882 printk("ENSELDO "); 2427 "enabled interrupts (%s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n",
2883 if (s & ENSELDI) 2428 (s0 & ENSELDO) ? "ENSELDO " : "",
2884 printk("ENSELDI "); 2429 (s0 & ENSELDI) ? "ENSELDI " : "",
2885 if (s & ENSELINGO) 2430 (s0 & ENSELINGO) ? "ENSELINGO " : "",
2886 printk("ENSELINGO "); 2431 (s0 & ENSWRAP) ? "ENSWRAP " : "",
2887 if (s & ENSWRAP) 2432 (s0 & ENSDONE) ? "ENSDONE " : "",
2888 printk("ENSWRAP "); 2433 (s0 & ENSPIORDY) ? "ENSPIORDY " : "",
2889 if (s & ENSDONE) 2434 (s0 & ENDMADONE) ? "ENDMADONE " : "",
2890 printk("ENSDONE "); 2435 (s1 & ENSELTIMO) ? "ENSELTIMO " : "",
2891 if (s & ENSPIORDY) 2436 (s1 & ENATNTARG) ? "ENATNTARG " : "",
2892 printk("ENSPIORDY "); 2437 (s1 & ENPHASEMIS) ? "ENPHASEMIS " : "",
2893 if (s & ENDMADONE) 2438 (s1 & ENBUSFREE) ? "ENBUSFREE " : "",
2894 printk("ENDMADONE "); 2439 (s1 & ENSCSIPERR) ? "ENSCSIPERR " : "",
2895 2440 (s1 & ENPHASECHG) ? "ENPHASECHG " : "",
2896 s = GETPORT(SIMODE1); 2441 (s1 & ENREQINIT) ? "ENREQINIT " : "");
2897 if (s & ENSELTIMO)
2898 printk("ENSELTIMO ");
2899 if (s & ENATNTARG)
2900 printk("ENATNTARG ");
2901 if (s & ENPHASEMIS)
2902 printk("ENPHASEMIS ");
2903 if (s & ENBUSFREE)
2904 printk("ENBUSFREE ");
2905 if (s & ENSCSIPERR)
2906 printk("ENSCSIPERR ");
2907 if (s & ENPHASECHG)
2908 printk("ENPHASECHG ");
2909 if (s & ENREQINIT)
2910 printk("ENREQINIT ");
2911 printk(")\n");
2912} 2442}
2913 2443
2914/* 2444/*
@@ -2916,36 +2446,21 @@ static void disp_enintr(struct Scsi_Host *shpnt)
2916 */ 2446 */
2917static void show_command(Scsi_Cmnd *ptr) 2447static void show_command(Scsi_Cmnd *ptr)
2918{ 2448{
2919 scmd_printk(KERN_DEBUG, ptr, "%p: cmnd=(", ptr); 2449 scsi_print_command(ptr);
2920 2450 scmd_printk(KERN_DEBUG, ptr,
2921 __scsi_print_command(ptr->cmnd); 2451 "request_bufflen=%d; resid=%d; "
2922 2452 "phase |%s%s%s%s%s%s%s%s%s; next=0x%p",
2923 printk(KERN_DEBUG "); request_bufflen=%d; resid=%d; phase |", 2453 scsi_bufflen(ptr), scsi_get_resid(ptr),
2924 scsi_bufflen(ptr), scsi_get_resid(ptr)); 2454 (ptr->SCp.phase & not_issued) ? "not issued|" : "",
2925 2455 (ptr->SCp.phase & selecting) ? "selecting|" : "",
2926 if (ptr->SCp.phase & not_issued) 2456 (ptr->SCp.phase & identified) ? "identified|" : "",
2927 printk("not issued|"); 2457 (ptr->SCp.phase & disconnected) ? "disconnected|" : "",
2928 if (ptr->SCp.phase & selecting) 2458 (ptr->SCp.phase & completed) ? "completed|" : "",
2929 printk("selecting|"); 2459 (ptr->SCp.phase & spiordy) ? "spiordy|" : "",
2930 if (ptr->SCp.phase & identified) 2460 (ptr->SCp.phase & syncneg) ? "syncneg|" : "",
2931 printk("identified|"); 2461 (ptr->SCp.phase & aborted) ? "aborted|" : "",
2932 if (ptr->SCp.phase & disconnected) 2462 (ptr->SCp.phase & resetted) ? "resetted|" : "",
2933 printk("disconnected|"); 2463 (SCDATA(ptr)) ? SCNEXT(ptr) : NULL);
2934 if (ptr->SCp.phase & completed)
2935 printk("completed|");
2936 if (ptr->SCp.phase & spiordy)
2937 printk("spiordy|");
2938 if (ptr->SCp.phase & syncneg)
2939 printk("syncneg|");
2940 if (ptr->SCp.phase & aborted)
2941 printk("aborted|");
2942 if (ptr->SCp.phase & resetted)
2943 printk("resetted|");
2944 if( SCDATA(ptr) ) {
2945 printk("; next=0x%p\n", SCNEXT(ptr));
2946 } else {
2947 printk("; next=(host scribble NULL)\n");
2948 }
2949} 2464}
2950 2465
2951/* 2466/*
@@ -2972,7 +2487,6 @@ static void show_queues(struct Scsi_Host *shpnt)
2972 for (ptr = DISCONNECTED_SC; ptr; ptr = SCDATA(ptr) ? SCNEXT(ptr) : NULL) 2487 for (ptr = DISCONNECTED_SC; ptr; ptr = SCDATA(ptr) ? SCNEXT(ptr) : NULL)
2973 show_command(ptr); 2488 show_command(ptr);
2974 2489
2975 disp_ports(shpnt);
2976 disp_enintr(shpnt); 2490 disp_enintr(shpnt);
2977} 2491}
2978 2492
@@ -3276,15 +2790,6 @@ static int aha152x_set_info(struct Scsi_Host *shpnt, char *buffer, int length)
3276 if(!shpnt || !buffer || length<8 || strncmp("aha152x ", buffer, 8)!=0) 2790 if(!shpnt || !buffer || length<8 || strncmp("aha152x ", buffer, 8)!=0)
3277 return -EINVAL; 2791 return -EINVAL;
3278 2792
3279#if defined(AHA152X_DEBUG)
3280 if(length>14 && strncmp("debug ", buffer+8, 6)==0) {
3281 int debug = HOSTDATA(shpnt)->debug;
3282
3283 HOSTDATA(shpnt)->debug = simple_strtoul(buffer+14, NULL, 0);
3284
3285 printk(KERN_INFO "aha152x%d: debugging options set to 0x%04x (were 0x%04x)\n", HOSTNO, HOSTDATA(shpnt)->debug, debug);
3286 } else
3287#endif
3288#if defined(AHA152X_STAT) 2793#if defined(AHA152X_STAT)
3289 if(length>13 && strncmp("reset", buffer+8, 5)==0) { 2794 if(length>13 && strncmp("reset", buffer+8, 5)==0) {
3290 int i; 2795 int i;
@@ -3302,7 +2807,7 @@ static int aha152x_set_info(struct Scsi_Host *shpnt, char *buffer, int length)
3302 HOSTDATA(shpnt)->time[i]=0; 2807 HOSTDATA(shpnt)->time[i]=0;
3303 } 2808 }
3304 2809
3305 printk(KERN_INFO "aha152x%d: stats reseted.\n", HOSTNO); 2810 shost_printk(KERN_INFO, shpnt, "aha152x: stats reset.\n");
3306 2811
3307 } else 2812 } else
3308#endif 2813#endif
@@ -3343,29 +2848,6 @@ static int aha152x_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
3343 (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2) * 50, 2848 (((HOSTDATA(shpnt)->syncrate[i] & 0x70) >> 4) + 2) * 50,
3344 HOSTDATA(shpnt)->syncrate[i] & 0x0f); 2849 HOSTDATA(shpnt)->syncrate[i] & 0x0f);
3345 } 2850 }
3346#if defined(AHA152X_DEBUG)
3347#define PDEBUG(flags,txt) \
3348 if(HOSTDATA(shpnt)->debug & flags) SPRINTF("(%s) ", txt);
3349
3350 SPRINTF("enabled debugging options: ");
3351
3352 PDEBUG(debug_procinfo, "procinfo");
3353 PDEBUG(debug_queue, "queue");
3354 PDEBUG(debug_intr, "interrupt");
3355 PDEBUG(debug_selection, "selection");
3356 PDEBUG(debug_msgo, "message out");
3357 PDEBUG(debug_msgi, "message in");
3358 PDEBUG(debug_status, "status");
3359 PDEBUG(debug_cmd, "command");
3360 PDEBUG(debug_datai, "data in");
3361 PDEBUG(debug_datao, "data out");
3362 PDEBUG(debug_eh, "eh");
3363 PDEBUG(debug_locking, "locks");
3364 PDEBUG(debug_phases, "phases");
3365
3366 SPRINTF("\n");
3367#endif
3368
3369 SPRINTF("\nqueue status:\n"); 2851 SPRINTF("\nqueue status:\n");
3370 DO_LOCK(flags); 2852 DO_LOCK(flags);
3371 if (ISSUE_SC) { 2853 if (ISSUE_SC) {
@@ -3393,8 +2875,8 @@ static int aha152x_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
3393 2875
3394#if defined(AHA152X_STAT) 2876#if defined(AHA152X_STAT)
3395 SPRINTF("statistics:\n" 2877 SPRINTF("statistics:\n"
3396 "total commands: %d\n" 2878 "total commands: %d\n"
3397 "disconnections: %d\n" 2879 "disconnections: %d\n"
3398 "busfree with check condition: %d\n" 2880 "busfree with check condition: %d\n"
3399 "busfree without old command: %d\n" 2881 "busfree without old command: %d\n"
3400 "busfree without new command: %d\n" 2882 "busfree without new command: %d\n"
@@ -3413,7 +2895,7 @@ static int aha152x_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
3413 HOSTDATA(shpnt)->busfree_without_any_action); 2895 HOSTDATA(shpnt)->busfree_without_any_action);
3414 for(i=0; i<maxstate; i++) { 2896 for(i=0; i<maxstate; i++) {
3415 SPRINTF("%-10s %-12d %-12d %-12ld\n", 2897 SPRINTF("%-10s %-12d %-12d %-12ld\n",
3416 states[i].name, 2898 states[i].name,
3417 HOSTDATA(shpnt)->count_trans[i], 2899 HOSTDATA(shpnt)->count_trans[i],
3418 HOSTDATA(shpnt)->count[i], 2900 HOSTDATA(shpnt)->count[i],
3419 HOSTDATA(shpnt)->time[i]); 2901 HOSTDATA(shpnt)->time[i]);
@@ -3671,25 +3153,19 @@ static int __init aha152x_init(void)
3671 setup[setup_count].synchronous = aha152x[5]; 3153 setup[setup_count].synchronous = aha152x[5];
3672 setup[setup_count].delay = aha152x[6]; 3154 setup[setup_count].delay = aha152x[6];
3673 setup[setup_count].ext_trans = aha152x[7]; 3155 setup[setup_count].ext_trans = aha152x[7];
3674#if defined(AHA152X_DEBUG) 3156 } else if (io[0] != 0 || irq[0] != 0) {
3675 setup[setup_count].debug = aha152x[8];
3676#endif
3677 } else if(io[0]!=0 || irq[0]!=0) {
3678 if(io[0]!=0) setup[setup_count].io_port = io[0]; 3157 if(io[0]!=0) setup[setup_count].io_port = io[0];
3679 if(irq[0]!=0) setup[setup_count].irq = irq[0]; 3158 if(irq[0]!=0) setup[setup_count].irq = irq[0];
3680 3159
3681 setup[setup_count].scsiid = scsiid[0]; 3160 setup[setup_count].scsiid = scsiid[0];
3682 setup[setup_count].reconnect = reconnect[0]; 3161 setup[setup_count].reconnect = reconnect[0];
3683 setup[setup_count].parity = parity[0]; 3162 setup[setup_count].parity = parity[0];
3684 setup[setup_count].synchronous = sync[0]; 3163 setup[setup_count].synchronous = sync[0];
3685 setup[setup_count].delay = delay[0]; 3164 setup[setup_count].delay = delay[0];
3686 setup[setup_count].ext_trans = exttrans[0]; 3165 setup[setup_count].ext_trans = exttrans[0];
3687#if defined(AHA152X_DEBUG)
3688 setup[setup_count].debug = debug[0];
3689#endif
3690 } 3166 }
3691 3167
3692 if (checksetup(&setup[setup_count])) 3168 if (checksetup(&setup[setup_count]))
3693 setup_count++; 3169 setup_count++;
3694 else 3170 else
3695 printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n", 3171 printk(KERN_ERR "aha152x: invalid module params io=0x%x, irq=%d,scsiid=%d,reconnect=%d,parity=%d,sync=%d,delay=%d,exttrans=%d\n",
@@ -3714,22 +3190,16 @@ static int __init aha152x_init(void)
3714 setup[setup_count].synchronous = aha152x1[5]; 3190 setup[setup_count].synchronous = aha152x1[5];
3715 setup[setup_count].delay = aha152x1[6]; 3191 setup[setup_count].delay = aha152x1[6];
3716 setup[setup_count].ext_trans = aha152x1[7]; 3192 setup[setup_count].ext_trans = aha152x1[7];
3717#if defined(AHA152X_DEBUG) 3193 } else if (io[1] != 0 || irq[1] != 0) {
3718 setup[setup_count].debug = aha152x1[8];
3719#endif
3720 } else if(io[1]!=0 || irq[1]!=0) {
3721 if(io[1]!=0) setup[setup_count].io_port = io[1]; 3194 if(io[1]!=0) setup[setup_count].io_port = io[1];
3722 if(irq[1]!=0) setup[setup_count].irq = irq[1]; 3195 if(irq[1]!=0) setup[setup_count].irq = irq[1];
3723 3196
3724 setup[setup_count].scsiid = scsiid[1]; 3197 setup[setup_count].scsiid = scsiid[1];
3725 setup[setup_count].reconnect = reconnect[1]; 3198 setup[setup_count].reconnect = reconnect[1];
3726 setup[setup_count].parity = parity[1]; 3199 setup[setup_count].parity = parity[1];
3727 setup[setup_count].synchronous = sync[1]; 3200 setup[setup_count].synchronous = sync[1];
3728 setup[setup_count].delay = delay[1]; 3201 setup[setup_count].delay = delay[1];
3729 setup[setup_count].ext_trans = exttrans[1]; 3202 setup[setup_count].ext_trans = exttrans[1];
3730#if defined(AHA152X_DEBUG)
3731 setup[setup_count].debug = debug[1];
3732#endif
3733 } 3203 }
3734 if (checksetup(&setup[setup_count])) 3204 if (checksetup(&setup[setup_count]))
3735 setup_count++; 3205 setup_count++;
@@ -3776,9 +3246,6 @@ static int __init aha152x_init(void)
3776 setup[setup_count].synchronous = 1; 3246 setup[setup_count].synchronous = 1;
3777 setup[setup_count].delay = DELAY_DEFAULT; 3247 setup[setup_count].delay = DELAY_DEFAULT;
3778 setup[setup_count].ext_trans = 0; 3248 setup[setup_count].ext_trans = 0;
3779#if defined(AHA152X_DEBUG)
3780 setup[setup_count].debug = DEBUG_DEFAULT;
3781#endif
3782#if defined(__ISAPNP__) 3249#if defined(__ISAPNP__)
3783 pnpdev[setup_count] = dev; 3250 pnpdev[setup_count] = dev;
3784#endif 3251#endif
@@ -3847,9 +3314,6 @@ static int __init aha152x_init(void)
3847 setup[setup_count].synchronous = conf.cf_syncneg; 3314 setup[setup_count].synchronous = conf.cf_syncneg;
3848 setup[setup_count].delay = DELAY_DEFAULT; 3315 setup[setup_count].delay = DELAY_DEFAULT;
3849 setup[setup_count].ext_trans = 0; 3316 setup[setup_count].ext_trans = 0;
3850#if defined(AHA152X_DEBUG)
3851 setup[setup_count].debug = DEBUG_DEFAULT;
3852#endif
3853 setup_count++; 3317 setup_count++;
3854 3318
3855 } 3319 }
@@ -3903,11 +3367,8 @@ module_exit(aha152x_exit);
3903#if !defined(MODULE) 3367#if !defined(MODULE)
3904static int __init aha152x_setup(char *str) 3368static int __init aha152x_setup(char *str)
3905{ 3369{
3906#if defined(AHA152X_DEBUG)
3907 int ints[11];
3908#else
3909 int ints[10]; 3370 int ints[10];
3910#endif 3371
3911 get_options(str, ARRAY_SIZE(ints), ints); 3372 get_options(str, ARRAY_SIZE(ints), ints);
3912 3373
3913 if(setup_count>=ARRAY_SIZE(setup)) { 3374 if(setup_count>=ARRAY_SIZE(setup)) {
@@ -3924,16 +3385,9 @@ static int __init aha152x_setup(char *str)
3924 setup[setup_count].synchronous = ints[0] >= 6 ? ints[6] : 1; 3385 setup[setup_count].synchronous = ints[0] >= 6 ? ints[6] : 1;
3925 setup[setup_count].delay = ints[0] >= 7 ? ints[7] : DELAY_DEFAULT; 3386 setup[setup_count].delay = ints[0] >= 7 ? ints[7] : DELAY_DEFAULT;
3926 setup[setup_count].ext_trans = ints[0] >= 8 ? ints[8] : 0; 3387 setup[setup_count].ext_trans = ints[0] >= 8 ? ints[8] : 0;
3927#if defined(AHA152X_DEBUG)
3928 setup[setup_count].debug = ints[0] >= 9 ? ints[9] : DEBUG_DEFAULT;
3929 if (ints[0] > 9) {
3930 printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
3931 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>[,<DEBUG>]]]]]]]]\n");
3932#else
3933 if (ints[0] > 8) { /*}*/ 3388 if (ints[0] > 8) { /*}*/
3934 printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>" 3389 printk(KERN_NOTICE "aha152x: usage: aha152x=<IOBASE>[,<IRQ>[,<SCSI ID>"
3935 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n"); 3390 "[,<RECONNECT>[,<PARITY>[,<SYNCHRONOUS>[,<DELAY>[,<EXT_TRANS>]]]]]]]\n");
3936#endif
3937 } else { 3391 } else {
3938 setup_count++; 3392 setup_count++;
3939 return 0; 3393 return 0;
diff --git a/drivers/scsi/aha1740.c b/drivers/scsi/aha1740.c
index 5f3101797c93..31ace4bef8fe 100644
--- a/drivers/scsi/aha1740.c
+++ b/drivers/scsi/aha1740.c
@@ -531,7 +531,7 @@ static int aha1740_eh_abort_handler (Scsi_Cmnd *dummy)
531 * quiet as possible... 531 * quiet as possible...
532 */ 532 */
533 533
534 return 0; 534 return SUCCESS;
535} 535}
536 536
537static struct scsi_host_template aha1740_template = { 537static struct scsi_host_template aha1740_template = {
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index ed333669a7dc..d5c7b193d8d3 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -925,6 +925,7 @@ struct scsi_host_template aic79xx_driver_template = {
925 .slave_configure = ahd_linux_slave_configure, 925 .slave_configure = ahd_linux_slave_configure,
926 .target_alloc = ahd_linux_target_alloc, 926 .target_alloc = ahd_linux_target_alloc,
927 .target_destroy = ahd_linux_target_destroy, 927 .target_destroy = ahd_linux_target_destroy,
928 .use_blk_tags = 1,
928}; 929};
929 930
930/******************************** Bus DMA *************************************/ 931/******************************** Bus DMA *************************************/
@@ -1468,12 +1469,9 @@ ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
1468 1469
1469 switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) { 1470 switch ((dev->flags & (AHD_DEV_Q_BASIC|AHD_DEV_Q_TAGGED))) {
1470 case AHD_DEV_Q_BASIC: 1471 case AHD_DEV_Q_BASIC:
1471 scsi_set_tag_type(sdev, MSG_SIMPLE_TASK);
1472 scsi_activate_tcq(sdev, dev->openings + dev->active);
1473 break;
1474 case AHD_DEV_Q_TAGGED: 1472 case AHD_DEV_Q_TAGGED:
1475 scsi_set_tag_type(sdev, MSG_ORDERED_TASK); 1473 scsi_change_queue_depth(sdev,
1476 scsi_activate_tcq(sdev, dev->openings + dev->active); 1474 dev->openings + dev->active);
1477 break; 1475 break;
1478 default: 1476 default:
1479 /* 1477 /*
@@ -1482,7 +1480,7 @@ ahd_platform_set_tags(struct ahd_softc *ahd, struct scsi_device *sdev,
1482 * serially on the controller/device. This should 1480 * serially on the controller/device. This should
1483 * remove some latency. 1481 * remove some latency.
1484 */ 1482 */
1485 scsi_deactivate_tcq(sdev, 1); 1483 scsi_change_queue_depth(sdev, 1);
1486 break; 1484 break;
1487 } 1485 }
1488} 1486}
@@ -1619,15 +1617,6 @@ ahd_linux_run_command(struct ahd_softc *ahd, struct ahd_linux_device *dev,
1619 } 1617 }
1620 1618
1621 if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) { 1619 if ((dev->flags & (AHD_DEV_Q_TAGGED|AHD_DEV_Q_BASIC)) != 0) {
1622 int msg_bytes;
1623 uint8_t tag_msgs[2];
1624
1625 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
1626 if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
1627 hscb->control |= tag_msgs[0];
1628 if (tag_msgs[0] == MSG_ORDERED_TASK)
1629 dev->commands_since_idle_or_otag = 0;
1630 } else
1631 if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH 1620 if (dev->commands_since_idle_or_otag == AHD_OTAG_THRESH
1632 && (dev->flags & AHD_DEV_Q_TAGGED) != 0) { 1621 && (dev->flags & AHD_DEV_Q_TAGGED) != 0) {
1633 hscb->control |= MSG_ORDERED_TASK; 1622 hscb->control |= MSG_ORDERED_TASK;
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.c b/drivers/scsi/aic7xxx/aic7xxx_osm.c
index d2c9bf39033d..88360116dbcb 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.c
@@ -812,6 +812,7 @@ struct scsi_host_template aic7xxx_driver_template = {
812 .slave_configure = ahc_linux_slave_configure, 812 .slave_configure = ahc_linux_slave_configure,
813 .target_alloc = ahc_linux_target_alloc, 813 .target_alloc = ahc_linux_target_alloc,
814 .target_destroy = ahc_linux_target_destroy, 814 .target_destroy = ahc_linux_target_destroy,
815 .use_blk_tags = 1,
815}; 816};
816 817
817/**************************** Tasklet Handler *********************************/ 818/**************************** Tasklet Handler *********************************/
@@ -1334,13 +1335,9 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
1334 } 1335 }
1335 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) { 1336 switch ((dev->flags & (AHC_DEV_Q_BASIC|AHC_DEV_Q_TAGGED))) {
1336 case AHC_DEV_Q_BASIC: 1337 case AHC_DEV_Q_BASIC:
1337 scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
1338 scsi_activate_tcq(sdev, dev->openings + dev->active);
1339 break;
1340 case AHC_DEV_Q_TAGGED: 1338 case AHC_DEV_Q_TAGGED:
1341 scsi_set_tag_type(sdev, MSG_ORDERED_TAG); 1339 scsi_change_queue_depth(sdev,
1342 scsi_activate_tcq(sdev, dev->openings + dev->active); 1340 dev->openings + dev->active);
1343 break;
1344 default: 1341 default:
1345 /* 1342 /*
1346 * We allow the OS to queue 2 untagged transactions to 1343 * We allow the OS to queue 2 untagged transactions to
@@ -1348,7 +1345,7 @@ ahc_platform_set_tags(struct ahc_softc *ahc, struct scsi_device *sdev,
1348 * serially on the controller/device. This should 1345 * serially on the controller/device. This should
1349 * remove some latency. 1346 * remove some latency.
1350 */ 1347 */
1351 scsi_deactivate_tcq(sdev, 2); 1348 scsi_change_queue_depth(sdev, 2);
1352 break; 1349 break;
1353 } 1350 }
1354} 1351}
@@ -1447,7 +1444,7 @@ ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
1447 * we are storing a full busy target *lun* 1444 * we are storing a full busy target *lun*
1448 * table in SCB space. 1445 * table in SCB space.
1449 */ 1446 */
1450 if (!blk_rq_tagged(cmd->request) 1447 if (!(cmd->flags & SCMD_TAGGED)
1451 && (ahc->features & AHC_SCB_BTT) == 0) { 1448 && (ahc->features & AHC_SCB_BTT) == 0) {
1452 int target_offset; 1449 int target_offset;
1453 1450
@@ -1501,15 +1498,7 @@ ahc_linux_run_command(struct ahc_softc *ahc, struct ahc_linux_device *dev,
1501 } 1498 }
1502 1499
1503 if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) { 1500 if ((dev->flags & (AHC_DEV_Q_TAGGED|AHC_DEV_Q_BASIC)) != 0) {
1504 int msg_bytes; 1501 if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
1505 uint8_t tag_msgs[2];
1506
1507 msg_bytes = scsi_populate_tag_msg(cmd, tag_msgs);
1508 if (msg_bytes && tag_msgs[0] != MSG_SIMPLE_TASK) {
1509 hscb->control |= tag_msgs[0];
1510 if (tag_msgs[0] == MSG_ORDERED_TASK)
1511 dev->commands_since_idle_or_otag = 0;
1512 } else if (dev->commands_since_idle_or_otag == AHC_OTAG_THRESH
1513 && (dev->flags & AHC_DEV_Q_TAGGED) != 0) { 1502 && (dev->flags & AHC_DEV_Q_TAGGED) != 0) {
1514 hscb->control |= MSG_ORDERED_TASK; 1503 hscb->control |= MSG_ORDERED_TASK;
1515 dev->commands_since_idle_or_otag = 0; 1504 dev->commands_since_idle_or_otag = 0;
diff --git a/drivers/scsi/aic94xx/aic94xx.h b/drivers/scsi/aic94xx/aic94xx.h
index 66cda669b417..26d4ad9ede2e 100644
--- a/drivers/scsi/aic94xx/aic94xx.h
+++ b/drivers/scsi/aic94xx/aic94xx.h
@@ -78,7 +78,7 @@ void asd_dev_gone(struct domain_device *dev);
78 78
79void asd_invalidate_edb(struct asd_ascb *ascb, int edb_id); 79void asd_invalidate_edb(struct asd_ascb *ascb, int edb_id);
80 80
81int asd_execute_task(struct sas_task *, int num, gfp_t gfp_flags); 81int asd_execute_task(struct sas_task *task, gfp_t gfp_flags);
82 82
83void asd_set_dmamode(struct domain_device *dev); 83void asd_set_dmamode(struct domain_device *dev);
84 84
diff --git a/drivers/scsi/aic94xx/aic94xx_hwi.c b/drivers/scsi/aic94xx/aic94xx_hwi.c
index 4df867e07b20..9f636a34d595 100644
--- a/drivers/scsi/aic94xx/aic94xx_hwi.c
+++ b/drivers/scsi/aic94xx/aic94xx_hwi.c
@@ -1200,8 +1200,7 @@ static void asd_start_scb_timers(struct list_head *list)
1200 * Case A: we can send the whole batch at once. Increment "pending" 1200 * Case A: we can send the whole batch at once. Increment "pending"
1201 * in the beginning of this function, when it is checked, in order to 1201 * in the beginning of this function, when it is checked, in order to
1202 * eliminate races when this function is called by multiple processes. 1202 * eliminate races when this function is called by multiple processes.
1203 * Case B: should never happen if the managing layer considers 1203 * Case B: should never happen.
1204 * lldd_queue_size.
1205 */ 1204 */
1206int asd_post_ascb_list(struct asd_ha_struct *asd_ha, struct asd_ascb *ascb, 1205int asd_post_ascb_list(struct asd_ha_struct *asd_ha, struct asd_ascb *ascb,
1207 int num) 1206 int num)
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
index c56741fc4b99..14fc018436c2 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -49,14 +49,6 @@ MODULE_PARM_DESC(use_msi, "\n"
49 "\tEnable(1) or disable(0) using PCI MSI.\n" 49 "\tEnable(1) or disable(0) using PCI MSI.\n"
50 "\tDefault: 0"); 50 "\tDefault: 0");
51 51
52static int lldd_max_execute_num = 0;
53module_param_named(collector, lldd_max_execute_num, int, S_IRUGO);
54MODULE_PARM_DESC(collector, "\n"
55 "\tIf greater than one, tells the SAS Layer to run in Task Collector\n"
56 "\tMode. If 1 or 0, tells the SAS Layer to run in Direct Mode.\n"
57 "\tThe aic94xx SAS LLDD supports both modes.\n"
58 "\tDefault: 0 (Direct Mode).\n");
59
60static struct scsi_transport_template *aic94xx_transport_template; 52static struct scsi_transport_template *aic94xx_transport_template;
61static int asd_scan_finished(struct Scsi_Host *, unsigned long); 53static int asd_scan_finished(struct Scsi_Host *, unsigned long);
62static void asd_scan_start(struct Scsi_Host *); 54static void asd_scan_start(struct Scsi_Host *);
@@ -83,6 +75,8 @@ static struct scsi_host_template aic94xx_sht = {
83 .eh_bus_reset_handler = sas_eh_bus_reset_handler, 75 .eh_bus_reset_handler = sas_eh_bus_reset_handler,
84 .target_destroy = sas_target_destroy, 76 .target_destroy = sas_target_destroy,
85 .ioctl = sas_ioctl, 77 .ioctl = sas_ioctl,
78 .use_blk_tags = 1,
79 .track_queue_depth = 1,
86}; 80};
87 81
88static int asd_map_memio(struct asd_ha_struct *asd_ha) 82static int asd_map_memio(struct asd_ha_struct *asd_ha)
@@ -709,9 +703,6 @@ static int asd_register_sas_ha(struct asd_ha_struct *asd_ha)
709 asd_ha->sas_ha.sas_port= sas_ports; 703 asd_ha->sas_ha.sas_port= sas_ports;
710 asd_ha->sas_ha.num_phys= ASD_MAX_PHYS; 704 asd_ha->sas_ha.num_phys= ASD_MAX_PHYS;
711 705
712 asd_ha->sas_ha.lldd_queue_size = asd_ha->seq.can_queue;
713 asd_ha->sas_ha.lldd_max_execute_num = lldd_max_execute_num;
714
715 return sas_register_ha(&asd_ha->sas_ha); 706 return sas_register_ha(&asd_ha->sas_ha);
716} 707}
717 708
diff --git a/drivers/scsi/aic94xx/aic94xx_task.c b/drivers/scsi/aic94xx/aic94xx_task.c
index 59b86e260ce9..5ff1ce7ba1f4 100644
--- a/drivers/scsi/aic94xx/aic94xx_task.c
+++ b/drivers/scsi/aic94xx/aic94xx_task.c
@@ -543,8 +543,7 @@ static int asd_can_queue(struct asd_ha_struct *asd_ha, int num)
543 return res; 543 return res;
544} 544}
545 545
546int asd_execute_task(struct sas_task *task, const int num, 546int asd_execute_task(struct sas_task *task, gfp_t gfp_flags)
547 gfp_t gfp_flags)
548{ 547{
549 int res = 0; 548 int res = 0;
550 LIST_HEAD(alist); 549 LIST_HEAD(alist);
@@ -553,11 +552,11 @@ int asd_execute_task(struct sas_task *task, const int num,
553 struct asd_ha_struct *asd_ha = task->dev->port->ha->lldd_ha; 552 struct asd_ha_struct *asd_ha = task->dev->port->ha->lldd_ha;
554 unsigned long flags; 553 unsigned long flags;
555 554
556 res = asd_can_queue(asd_ha, num); 555 res = asd_can_queue(asd_ha, 1);
557 if (res) 556 if (res)
558 return res; 557 return res;
559 558
560 res = num; 559 res = 1;
561 ascb = asd_ascb_alloc_list(asd_ha, &res, gfp_flags); 560 ascb = asd_ascb_alloc_list(asd_ha, &res, gfp_flags);
562 if (res) { 561 if (res) {
563 res = -ENOMEM; 562 res = -ENOMEM;
@@ -568,7 +567,7 @@ int asd_execute_task(struct sas_task *task, const int num,
568 list_for_each_entry(a, &alist, list) { 567 list_for_each_entry(a, &alist, list) {
569 a->uldd_task = t; 568 a->uldd_task = t;
570 t->lldd_task = a; 569 t->lldd_task = a;
571 t = list_entry(t->list.next, struct sas_task, list); 570 break;
572 } 571 }
573 list_for_each_entry(a, &alist, list) { 572 list_for_each_entry(a, &alist, list) {
574 t = a->uldd_task; 573 t = a->uldd_task;
@@ -601,7 +600,7 @@ int asd_execute_task(struct sas_task *task, const int num,
601 } 600 }
602 list_del_init(&alist); 601 list_del_init(&alist);
603 602
604 res = asd_post_ascb_list(asd_ha, ascb, num); 603 res = asd_post_ascb_list(asd_ha, ascb, 1);
605 if (unlikely(res)) { 604 if (unlikely(res)) {
606 a = NULL; 605 a = NULL;
607 __list_add(&alist, ascb->list.prev, &ascb->list); 606 __list_add(&alist, ascb->list.prev, &ascb->list);
@@ -639,6 +638,6 @@ out_err_unmap:
639out_err: 638out_err:
640 if (ascb) 639 if (ascb)
641 asd_ascb_free_list(ascb); 640 asd_ascb_free_list(ascb);
642 asd_can_dequeue(asd_ha, num); 641 asd_can_dequeue(asd_ha, 1);
643 return res; 642 return res;
644} 643}
diff --git a/drivers/scsi/am53c974.c b/drivers/scsi/am53c974.c
new file mode 100644
index 000000000000..aa3e2c7cd83c
--- /dev/null
+++ b/drivers/scsi/am53c974.c
@@ -0,0 +1,586 @@
1/*
2 * AMD am53c974 driver.
3 * Copyright (c) 2014 Hannes Reinecke, SUSE Linux GmbH
4 */
5
6#include <linux/kernel.h>
7#include <linux/module.h>
8#include <linux/init.h>
9#include <linux/delay.h>
10#include <linux/pci.h>
11#include <linux/interrupt.h>
12
13#include <scsi/scsi_host.h>
14
15#include "esp_scsi.h"
16
17#define DRV_MODULE_NAME "am53c974"
18#define DRV_MODULE_VERSION "1.00"
19
20static bool am53c974_debug;
21static bool am53c974_fenab = true;
22
23#define esp_dma_log(f, a...) \
24 do { \
25 if (am53c974_debug) \
26 shost_printk(KERN_DEBUG, esp->host, f, ##a); \
27 } while (0)
28
29#define ESP_DMA_CMD 0x10
30#define ESP_DMA_STC 0x11
31#define ESP_DMA_SPA 0x12
32#define ESP_DMA_WBC 0x13
33#define ESP_DMA_WAC 0x14
34#define ESP_DMA_STATUS 0x15
35#define ESP_DMA_SMDLA 0x16
36#define ESP_DMA_WMAC 0x17
37
38#define ESP_DMA_CMD_IDLE 0x00
39#define ESP_DMA_CMD_BLAST 0x01
40#define ESP_DMA_CMD_ABORT 0x02
41#define ESP_DMA_CMD_START 0x03
42#define ESP_DMA_CMD_MASK 0x03
43#define ESP_DMA_CMD_DIAG 0x04
44#define ESP_DMA_CMD_MDL 0x10
45#define ESP_DMA_CMD_INTE_P 0x20
46#define ESP_DMA_CMD_INTE_D 0x40
47#define ESP_DMA_CMD_DIR 0x80
48
49#define ESP_DMA_STAT_PWDN 0x01
50#define ESP_DMA_STAT_ERROR 0x02
51#define ESP_DMA_STAT_ABORT 0x04
52#define ESP_DMA_STAT_DONE 0x08
53#define ESP_DMA_STAT_SCSIINT 0x10
54#define ESP_DMA_STAT_BCMPLT 0x20
55
56/* EEPROM is accessed with 16-bit values */
57#define DC390_EEPROM_READ 0x80
58#define DC390_EEPROM_LEN 0x40
59
60/*
61 * DC390 EEPROM
62 *
63 * 8 * 4 bytes of per-device options
64 * followed by HBA specific options
65 */
66
67/* Per-device options */
68#define DC390_EE_MODE1 0x00
69#define DC390_EE_SPEED 0x01
70
71/* HBA-specific options */
72#define DC390_EE_ADAPT_SCSI_ID 0x40
73#define DC390_EE_MODE2 0x41
74#define DC390_EE_DELAY 0x42
75#define DC390_EE_TAG_CMD_NUM 0x43
76
77#define DC390_EE_MODE1_PARITY_CHK 0x01
78#define DC390_EE_MODE1_SYNC_NEGO 0x02
79#define DC390_EE_MODE1_EN_DISC 0x04
80#define DC390_EE_MODE1_SEND_START 0x08
81#define DC390_EE_MODE1_TCQ 0x10
82
83#define DC390_EE_MODE2_MORE_2DRV 0x01
84#define DC390_EE_MODE2_GREATER_1G 0x02
85#define DC390_EE_MODE2_RST_SCSI_BUS 0x04
86#define DC390_EE_MODE2_ACTIVE_NEGATION 0x08
87#define DC390_EE_MODE2_NO_SEEK 0x10
88#define DC390_EE_MODE2_LUN_CHECK 0x20
89
90struct pci_esp_priv {
91 struct esp *esp;
92 u8 dma_status;
93};
94
95static void pci_esp_dma_drain(struct esp *esp);
96
97static inline struct pci_esp_priv *pci_esp_get_priv(struct esp *esp)
98{
99 struct pci_dev *pdev = esp->dev;
100
101 return pci_get_drvdata(pdev);
102}
103
104static void pci_esp_write8(struct esp *esp, u8 val, unsigned long reg)
105{
106 iowrite8(val, esp->regs + (reg * 4UL));
107}
108
109static u8 pci_esp_read8(struct esp *esp, unsigned long reg)
110{
111 return ioread8(esp->regs + (reg * 4UL));
112}
113
114static void pci_esp_write32(struct esp *esp, u32 val, unsigned long reg)
115{
116 return iowrite32(val, esp->regs + (reg * 4UL));
117}
118
119static dma_addr_t pci_esp_map_single(struct esp *esp, void *buf,
120 size_t sz, int dir)
121{
122 return pci_map_single(esp->dev, buf, sz, dir);
123}
124
125static int pci_esp_map_sg(struct esp *esp, struct scatterlist *sg,
126 int num_sg, int dir)
127{
128 return pci_map_sg(esp->dev, sg, num_sg, dir);
129}
130
131static void pci_esp_unmap_single(struct esp *esp, dma_addr_t addr,
132 size_t sz, int dir)
133{
134 pci_unmap_single(esp->dev, addr, sz, dir);
135}
136
137static void pci_esp_unmap_sg(struct esp *esp, struct scatterlist *sg,
138 int num_sg, int dir)
139{
140 pci_unmap_sg(esp->dev, sg, num_sg, dir);
141}
142
143static int pci_esp_irq_pending(struct esp *esp)
144{
145 struct pci_esp_priv *pep = pci_esp_get_priv(esp);
146
147 pep->dma_status = pci_esp_read8(esp, ESP_DMA_STATUS);
148 esp_dma_log("dma intr dreg[%02x]\n", pep->dma_status);
149
150 if (pep->dma_status & (ESP_DMA_STAT_ERROR |
151 ESP_DMA_STAT_ABORT |
152 ESP_DMA_STAT_DONE |
153 ESP_DMA_STAT_SCSIINT))
154 return 1;
155
156 return 0;
157}
158
159static void pci_esp_reset_dma(struct esp *esp)
160{
161 /* Nothing to do ? */
162}
163
164static void pci_esp_dma_drain(struct esp *esp)
165{
166 u8 resid;
167 int lim = 1000;
168
169
170 if ((esp->sreg & ESP_STAT_PMASK) == ESP_DOP ||
171 (esp->sreg & ESP_STAT_PMASK) == ESP_DIP)
172 /* Data-In or Data-Out, nothing to be done */
173 return;
174
175 while (--lim > 0) {
176 resid = pci_esp_read8(esp, ESP_FFLAGS) & ESP_FF_FBYTES;
177 if (resid <= 1)
178 break;
179 cpu_relax();
180 }
181 if (resid > 1) {
182 /* FIFO not cleared */
183 shost_printk(KERN_INFO, esp->host,
184 "FIFO not cleared, %d bytes left\n",
185 resid);
186 }
187
188 /*
189 * When there is a residual BCMPLT will never be set
190 * (obviously). But we still have to issue the BLAST
191 * command, otherwise the data will not being transferred.
192 * But we'll never know when the BLAST operation is
193 * finished. So check for some time and give up eventually.
194 */
195 lim = 1000;
196 pci_esp_write8(esp, ESP_DMA_CMD_DIR | ESP_DMA_CMD_BLAST, ESP_DMA_CMD);
197 while (pci_esp_read8(esp, ESP_DMA_STATUS) & ESP_DMA_STAT_BCMPLT) {
198 if (--lim == 0)
199 break;
200 cpu_relax();
201 }
202 pci_esp_write8(esp, ESP_DMA_CMD_DIR | ESP_DMA_CMD_IDLE, ESP_DMA_CMD);
203 esp_dma_log("DMA blast done (%d tries, %d bytes left)\n", lim, resid);
204 /* BLAST residual handling is currently untested */
205 if (WARN_ON_ONCE(resid == 1)) {
206 struct esp_cmd_entry *ent = esp->active_cmd;
207
208 ent->flags |= ESP_CMD_FLAG_RESIDUAL;
209 }
210}
211
212static void pci_esp_dma_invalidate(struct esp *esp)
213{
214 struct pci_esp_priv *pep = pci_esp_get_priv(esp);
215
216 esp_dma_log("invalidate DMA\n");
217
218 pci_esp_write8(esp, ESP_DMA_CMD_IDLE, ESP_DMA_CMD);
219 pep->dma_status = 0;
220}
221
222static int pci_esp_dma_error(struct esp *esp)
223{
224 struct pci_esp_priv *pep = pci_esp_get_priv(esp);
225
226 if (pep->dma_status & ESP_DMA_STAT_ERROR) {
227 u8 dma_cmd = pci_esp_read8(esp, ESP_DMA_CMD);
228
229 if ((dma_cmd & ESP_DMA_CMD_MASK) == ESP_DMA_CMD_START)
230 pci_esp_write8(esp, ESP_DMA_CMD_ABORT, ESP_DMA_CMD);
231
232 return 1;
233 }
234 if (pep->dma_status & ESP_DMA_STAT_ABORT) {
235 pci_esp_write8(esp, ESP_DMA_CMD_IDLE, ESP_DMA_CMD);
236 pep->dma_status = pci_esp_read8(esp, ESP_DMA_CMD);
237 return 1;
238 }
239 return 0;
240}
241
242static void pci_esp_send_dma_cmd(struct esp *esp, u32 addr, u32 esp_count,
243 u32 dma_count, int write, u8 cmd)
244{
245 struct pci_esp_priv *pep = pci_esp_get_priv(esp);
246 u32 val = 0;
247
248 BUG_ON(!(cmd & ESP_CMD_DMA));
249
250 pep->dma_status = 0;
251
252 /* Set DMA engine to IDLE */
253 if (write)
254 /* DMA write direction logic is inverted */
255 val |= ESP_DMA_CMD_DIR;
256 pci_esp_write8(esp, ESP_DMA_CMD_IDLE | val, ESP_DMA_CMD);
257
258 pci_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
259 pci_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
260 if (esp->config2 & ESP_CONFIG2_FENAB)
261 pci_esp_write8(esp, (esp_count >> 16) & 0xff, ESP_TCHI);
262
263 pci_esp_write32(esp, esp_count, ESP_DMA_STC);
264 pci_esp_write32(esp, addr, ESP_DMA_SPA);
265
266 esp_dma_log("start dma addr[%x] count[%d:%d]\n",
267 addr, esp_count, dma_count);
268
269 scsi_esp_cmd(esp, cmd);
270 /* Send DMA Start command */
271 pci_esp_write8(esp, ESP_DMA_CMD_START | val, ESP_DMA_CMD);
272}
273
274static u32 pci_esp_dma_length_limit(struct esp *esp, u32 dma_addr, u32 dma_len)
275{
276 int dma_limit = 16;
277 u32 base, end;
278
279 /*
280 * If CONFIG2_FENAB is set we can
281 * handle up to 24 bit addresses
282 */
283 if (esp->config2 & ESP_CONFIG2_FENAB)
284 dma_limit = 24;
285
286 if (dma_len > (1U << dma_limit))
287 dma_len = (1U << dma_limit);
288
289 /*
290 * Prevent crossing a 24-bit address boundary.
291 */
292 base = dma_addr & ((1U << 24) - 1U);
293 end = base + dma_len;
294 if (end > (1U << 24))
295 end = (1U <<24);
296 dma_len = end - base;
297
298 return dma_len;
299}
300
301static const struct esp_driver_ops pci_esp_ops = {
302 .esp_write8 = pci_esp_write8,
303 .esp_read8 = pci_esp_read8,
304 .map_single = pci_esp_map_single,
305 .map_sg = pci_esp_map_sg,
306 .unmap_single = pci_esp_unmap_single,
307 .unmap_sg = pci_esp_unmap_sg,
308 .irq_pending = pci_esp_irq_pending,
309 .reset_dma = pci_esp_reset_dma,
310 .dma_drain = pci_esp_dma_drain,
311 .dma_invalidate = pci_esp_dma_invalidate,
312 .send_dma_cmd = pci_esp_send_dma_cmd,
313 .dma_error = pci_esp_dma_error,
314 .dma_length_limit = pci_esp_dma_length_limit,
315};
316
317/*
318 * Read DC-390 eeprom
319 */
320static void dc390_eeprom_prepare_read(struct pci_dev *pdev, u8 cmd)
321{
322 u8 carry_flag = 1, j = 0x80, bval;
323 int i;
324
325 for (i = 0; i < 9; i++) {
326 if (carry_flag) {
327 pci_write_config_byte(pdev, 0x80, 0x40);
328 bval = 0xc0;
329 } else
330 bval = 0x80;
331
332 udelay(160);
333 pci_write_config_byte(pdev, 0x80, bval);
334 udelay(160);
335 pci_write_config_byte(pdev, 0x80, 0);
336 udelay(160);
337
338 carry_flag = (cmd & j) ? 1 : 0;
339 j >>= 1;
340 }
341}
342
343static u16 dc390_eeprom_get_data(struct pci_dev *pdev)
344{
345 int i;
346 u16 wval = 0;
347 u8 bval;
348
349 for (i = 0; i < 16; i++) {
350 wval <<= 1;
351
352 pci_write_config_byte(pdev, 0x80, 0x80);
353 udelay(160);
354 pci_write_config_byte(pdev, 0x80, 0x40);
355 udelay(160);
356 pci_read_config_byte(pdev, 0x00, &bval);
357
358 if (bval == 0x22)
359 wval |= 1;
360 }
361
362 return wval;
363}
364
365static void dc390_read_eeprom(struct pci_dev *pdev, u16 *ptr)
366{
367 u8 cmd = DC390_EEPROM_READ, i;
368
369 for (i = 0; i < DC390_EEPROM_LEN; i++) {
370 pci_write_config_byte(pdev, 0xc0, 0);
371 udelay(160);
372
373 dc390_eeprom_prepare_read(pdev, cmd++);
374 *ptr++ = dc390_eeprom_get_data(pdev);
375
376 pci_write_config_byte(pdev, 0x80, 0);
377 pci_write_config_byte(pdev, 0x80, 0);
378 udelay(160);
379 }
380}
381
382static void dc390_check_eeprom(struct esp *esp)
383{
384 u8 EEbuf[128];
385 u16 *ptr = (u16 *)EEbuf, wval = 0;
386 int i;
387
388 dc390_read_eeprom((struct pci_dev *)esp->dev, ptr);
389
390 for (i = 0; i < DC390_EEPROM_LEN; i++, ptr++)
391 wval += *ptr;
392
393 /* no Tekram EEprom found */
394 if (wval != 0x1234) {
395 struct pci_dev *pdev = esp->dev;
396 dev_printk(KERN_INFO, &pdev->dev,
397 "No valid Tekram EEprom found\n");
398 return;
399 }
400 esp->scsi_id = EEbuf[DC390_EE_ADAPT_SCSI_ID];
401 esp->num_tags = 2 << EEbuf[DC390_EE_TAG_CMD_NUM];
402 if (EEbuf[DC390_EE_MODE2] & DC390_EE_MODE2_ACTIVE_NEGATION)
403 esp->config4 |= ESP_CONFIG4_RADE | ESP_CONFIG4_RAE;
404}
405
406static int pci_esp_probe_one(struct pci_dev *pdev,
407 const struct pci_device_id *id)
408{
409 struct scsi_host_template *hostt = &scsi_esp_template;
410 int err = -ENODEV;
411 struct Scsi_Host *shost;
412 struct esp *esp;
413 struct pci_esp_priv *pep;
414
415 if (pci_enable_device(pdev)) {
416 dev_printk(KERN_INFO, &pdev->dev, "cannot enable device\n");
417 return -ENODEV;
418 }
419
420 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
421 dev_printk(KERN_INFO, &pdev->dev,
422 "failed to set 32bit DMA mask\n");
423 goto fail_disable_device;
424 }
425
426 shost = scsi_host_alloc(hostt, sizeof(struct esp));
427 if (!shost) {
428 dev_printk(KERN_INFO, &pdev->dev,
429 "failed to allocate scsi host\n");
430 err = -ENOMEM;
431 goto fail_disable_device;
432 }
433
434 pep = kzalloc(sizeof(struct pci_esp_priv), GFP_KERNEL);
435 if (!pep) {
436 dev_printk(KERN_INFO, &pdev->dev,
437 "failed to allocate esp_priv\n");
438 err = -ENOMEM;
439 goto fail_host_alloc;
440 }
441
442 esp = shost_priv(shost);
443 esp->host = shost;
444 esp->dev = pdev;
445 esp->ops = &pci_esp_ops;
446 /*
447 * The am53c974 HBA has a design flaw of generating
448 * spurious DMA completion interrupts when using
449 * DMA for command submission.
450 */
451 esp->flags |= ESP_FLAG_USE_FIFO;
452 /*
453 * Enable CONFIG2_FENAB to allow for large DMA transfers
454 */
455 if (am53c974_fenab)
456 esp->config2 |= ESP_CONFIG2_FENAB;
457
458 pep->esp = esp;
459
460 if (pci_request_regions(pdev, DRV_MODULE_NAME)) {
461 dev_printk(KERN_ERR, &pdev->dev,
462 "pci memory selection failed\n");
463 goto fail_priv_alloc;
464 }
465
466 esp->regs = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
467 if (!esp->regs) {
468 dev_printk(KERN_ERR, &pdev->dev, "pci I/O map failed\n");
469 err = -EINVAL;
470 goto fail_release_regions;
471 }
472 esp->dma_regs = esp->regs;
473
474 pci_set_master(pdev);
475
476 esp->command_block = pci_alloc_consistent(pdev, 16,
477 &esp->command_block_dma);
478 if (!esp->command_block) {
479 dev_printk(KERN_ERR, &pdev->dev,
480 "failed to allocate command block\n");
481 err = -ENOMEM;
482 goto fail_unmap_regs;
483 }
484
485 err = request_irq(pdev->irq, scsi_esp_intr, IRQF_SHARED,
486 DRV_MODULE_NAME, esp);
487 if (err < 0) {
488 dev_printk(KERN_ERR, &pdev->dev, "failed to register IRQ\n");
489 goto fail_unmap_command_block;
490 }
491
492 esp->scsi_id = 7;
493 dc390_check_eeprom(esp);
494
495 shost->this_id = esp->scsi_id;
496 shost->max_id = 8;
497 shost->irq = pdev->irq;
498 shost->io_port = pci_resource_start(pdev, 0);
499 shost->n_io_port = pci_resource_len(pdev, 0);
500 shost->unique_id = shost->io_port;
501 esp->scsi_id_mask = (1 << esp->scsi_id);
502 /* Assume 40MHz clock */
503 esp->cfreq = 40000000;
504
505 pci_set_drvdata(pdev, pep);
506
507 err = scsi_esp_register(esp, &pdev->dev);
508 if (err)
509 goto fail_free_irq;
510
511 return 0;
512
513fail_free_irq:
514 free_irq(pdev->irq, esp);
515fail_unmap_command_block:
516 pci_free_consistent(pdev, 16, esp->command_block,
517 esp->command_block_dma);
518fail_unmap_regs:
519 pci_iounmap(pdev, esp->regs);
520fail_release_regions:
521 pci_release_regions(pdev);
522fail_priv_alloc:
523 kfree(pep);
524fail_host_alloc:
525 scsi_host_put(shost);
526fail_disable_device:
527 pci_disable_device(pdev);
528
529 return err;
530}
531
532static void pci_esp_remove_one(struct pci_dev *pdev)
533{
534 struct pci_esp_priv *pep = pci_get_drvdata(pdev);
535 struct esp *esp = pep->esp;
536
537 scsi_esp_unregister(esp);
538 free_irq(pdev->irq, esp);
539 pci_free_consistent(pdev, 16, esp->command_block,
540 esp->command_block_dma);
541 pci_iounmap(pdev, esp->regs);
542 pci_release_regions(pdev);
543 pci_disable_device(pdev);
544 kfree(pep);
545
546 scsi_host_put(esp->host);
547}
548
549static struct pci_device_id am53c974_pci_tbl[] = {
550 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_SCSI,
551 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
552 { }
553};
554MODULE_DEVICE_TABLE(pci, am53c974_pci_tbl);
555
556static struct pci_driver am53c974_driver = {
557 .name = DRV_MODULE_NAME,
558 .id_table = am53c974_pci_tbl,
559 .probe = pci_esp_probe_one,
560 .remove = pci_esp_remove_one,
561};
562
563static int __init am53c974_module_init(void)
564{
565 return pci_register_driver(&am53c974_driver);
566}
567
568static void __exit am53c974_module_exit(void)
569{
570 pci_unregister_driver(&am53c974_driver);
571}
572
573MODULE_DESCRIPTION("AM53C974 SCSI driver");
574MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>");
575MODULE_LICENSE("GPL");
576MODULE_VERSION(DRV_MODULE_VERSION);
577MODULE_ALIAS("tmscsim");
578
579module_param(am53c974_debug, bool, 0644);
580MODULE_PARM_DESC(am53c974_debug, "Enable debugging");
581
582module_param(am53c974_fenab, bool, 0444);
583MODULE_PARM_DESC(am53c974_fenab, "Enable 24-bit DMA transfer sizes");
584
585module_init(am53c974_module_init);
586module_exit(am53c974_module_exit);
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 0b44fb5ee485..914c39f9f388 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -114,16 +114,11 @@ static void arcmsr_hardware_reset(struct AdapterControlBlock *acb);
114static const char *arcmsr_info(struct Scsi_Host *); 114static const char *arcmsr_info(struct Scsi_Host *);
115static irqreturn_t arcmsr_interrupt(struct AdapterControlBlock *acb); 115static irqreturn_t arcmsr_interrupt(struct AdapterControlBlock *acb);
116static void arcmsr_free_irq(struct pci_dev *, struct AdapterControlBlock *); 116static void arcmsr_free_irq(struct pci_dev *, struct AdapterControlBlock *);
117static int arcmsr_adjust_disk_queue_depth(struct scsi_device *sdev, 117static int arcmsr_adjust_disk_queue_depth(struct scsi_device *sdev, int queue_depth)
118 int queue_depth, int reason)
119{ 118{
120 if (reason != SCSI_QDEPTH_DEFAULT)
121 return -EOPNOTSUPP;
122
123 if (queue_depth > ARCMSR_MAX_CMD_PERLUN) 119 if (queue_depth > ARCMSR_MAX_CMD_PERLUN)
124 queue_depth = ARCMSR_MAX_CMD_PERLUN; 120 queue_depth = ARCMSR_MAX_CMD_PERLUN;
125 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth); 121 return scsi_change_queue_depth(sdev, queue_depth);
126 return queue_depth;
127} 122}
128 123
129static struct scsi_host_template arcmsr_scsi_host_template = { 124static struct scsi_host_template arcmsr_scsi_host_template = {
diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index d89b9b4deb3c..deaaf84989cd 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -850,13 +850,13 @@ static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
850 break; 850 break;
851 851
852 default: 852 default:
853 printk(KERN_ERR "scsi%d.H: incomplete data transfer detected: result=%08X command=", 853 scmd_printk(KERN_ERR, SCpnt,
854 host->host->host_no, SCpnt->result); 854 "incomplete data transfer detected: "
855 __scsi_print_command(SCpnt->cmnd); 855 "result=%08X", SCpnt->result);
856 scsi_print_command(SCpnt);
856 acornscsi_dumpdma(host, "done"); 857 acornscsi_dumpdma(host, "done");
857 acornscsi_dumplog(host, SCpnt->device->id); 858 acornscsi_dumplog(host, SCpnt->device->id);
858 SCpnt->result &= 0xffff; 859 set_host_byte(SCpnt, DID_ERROR);
859 SCpnt->result |= DID_ERROR << 16;
860 } 860 }
861 } 861 }
862 } 862 }
diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index 8ef810a4476e..d28d6c0f18c0 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -13,16 +13,12 @@
13#include <asm/ecard.h> 13#include <asm/ecard.h>
14#include <asm/io.h> 14#include <asm/io.h>
15 15
16#include "../scsi.h"
17#include <scsi/scsi_host.h> 16#include <scsi/scsi_host.h>
18 17
19#include <scsi/scsicam.h> 18#include <scsi/scsicam.h>
20 19
21#define AUTOSENSE
22#define PSEUDO_DMA 20#define PSEUDO_DMA
23 21
24#define CUMANASCSI_PUBLIC_RELEASE 1
25
26#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata) 22#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
27#define NCR5380_local_declare() struct Scsi_Host *_instance 23#define NCR5380_local_declare() struct Scsi_Host *_instance
28#define NCR5380_setup(instance) _instance = instance 24#define NCR5380_setup(instance) _instance = instance
@@ -30,6 +26,7 @@
30#define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value) 26#define NCR5380_write(reg, value) cumanascsi_write(_instance, reg, value)
31#define NCR5380_intr cumanascsi_intr 27#define NCR5380_intr cumanascsi_intr
32#define NCR5380_queue_command cumanascsi_queue_command 28#define NCR5380_queue_command cumanascsi_queue_command
29#define NCR5380_info cumanascsi_info
33 30
34#define NCR5380_implementation_fields \ 31#define NCR5380_implementation_fields \
35 unsigned ctrl; \ 32 unsigned ctrl; \
@@ -42,11 +39,6 @@ void cumanascsi_setup(char *str, int *ints)
42{ 39{
43} 40}
44 41
45const char *cumanascsi_info(struct Scsi_Host *spnt)
46{
47 return "";
48}
49
50#define CTRL 0x16fc 42#define CTRL 0x16fc
51#define STAT 0x2004 43#define STAT 0x2004
52#define L(v) (((v)<<16)|((v) & 0x0000ffff)) 44#define L(v) (((v)<<16)|((v) & 0x0000ffff))
@@ -267,14 +259,6 @@ static int cumanascsi1_probe(struct expansion_card *ec,
267 goto out_unmap; 259 goto out_unmap;
268 } 260 }
269 261
270 printk("scsi%d: at port 0x%08lx irq %d",
271 host->host_no, host->io_port, host->irq);
272 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
273 host->can_queue, host->cmd_per_lun, CUMANASCSI_PUBLIC_RELEASE);
274 printk("\nscsi%d:", host->host_no);
275 NCR5380_print_options(host);
276 printk("\n");
277
278 ret = scsi_add_host(host, &ec->dev); 262 ret = scsi_add_host(host, &ec->dev);
279 if (ret) 263 if (ret)
280 goto out_free_irq; 264 goto out_free_irq;
diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 71cfb1e504c4..e64c3af7c1a0 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -308,8 +308,7 @@ static void fas216_log_command(FAS216_Info *info, int level,
308 fas216_do_log(info, '0' + SCpnt->device->id, fmt, args); 308 fas216_do_log(info, '0' + SCpnt->device->id, fmt, args);
309 va_end(args); 309 va_end(args);
310 310
311 printk(" CDB: "); 311 scsi_print_command(SCpnt);
312 __scsi_print_command(SCpnt->cmnd);
313} 312}
314 313
315static void 314static void
@@ -2079,14 +2078,12 @@ fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result)
2079 break; 2078 break;
2080 2079
2081 default: 2080 default:
2082 printk(KERN_ERR "scsi%d.%c: incomplete data transfer " 2081 scmd_printk(KERN_ERR, SCpnt,
2083 "detected: res=%08X ptr=%p len=%X CDB: ", 2082 "incomplete data transfer detected: res=%08X ptr=%p len=%X\n",
2084 info->host->host_no, '0' + SCpnt->device->id, 2083 SCpnt->result, info->scsi.SCp.ptr,
2085 SCpnt->result, info->scsi.SCp.ptr, 2084 info->scsi.SCp.this_residual);
2086 info->scsi.SCp.this_residual); 2085 scsi_print_command(SCpnt);
2087 __scsi_print_command(SCpnt->cmnd); 2086 set_host_byte(SCpnt, DID_ERROR);
2088 SCpnt->result &= ~(255 << 16);
2089 SCpnt->result |= DID_BAD_TARGET << 16;
2090 goto request_sense; 2087 goto request_sense;
2091 } 2088 }
2092 } 2089 }
@@ -2158,12 +2155,11 @@ static void fas216_done(FAS216_Info *info, unsigned int result)
2158 * to transfer, we should not have a valid pointer. 2155 * to transfer, we should not have a valid pointer.
2159 */ 2156 */
2160 if (info->scsi.SCp.ptr && info->scsi.SCp.this_residual == 0) { 2157 if (info->scsi.SCp.ptr && info->scsi.SCp.this_residual == 0) {
2161 printk("scsi%d.%c: zero bytes left to transfer, but " 2158 scmd_printk(KERN_INFO, SCpnt,
2162 "buffer pointer still valid: ptr=%p len=%08x CDB: ", 2159 "zero bytes left to transfer, but buffer pointer still valid: ptr=%p len=%08x\n",
2163 info->host->host_no, '0' + SCpnt->device->id, 2160 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
2164 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
2165 info->scsi.SCp.ptr = NULL; 2161 info->scsi.SCp.ptr = NULL;
2166 __scsi_print_command(SCpnt->cmnd); 2162 scsi_print_command(SCpnt);
2167 } 2163 }
2168 2164
2169 /* 2165 /*
@@ -2427,14 +2423,11 @@ int fas216_eh_abort(struct scsi_cmnd *SCpnt)
2427 2423
2428 info->stats.aborts += 1; 2424 info->stats.aborts += 1;
2429 2425
2430 printk(KERN_WARNING "scsi%d: abort command ", info->host->host_no); 2426 scmd_printk(KERN_WARNING, SCpnt, "abort command\n");
2431 __scsi_print_command(SCpnt->cmnd);
2432 2427
2433 print_debug_list(); 2428 print_debug_list();
2434 fas216_dumpstate(info); 2429 fas216_dumpstate(info);
2435 2430
2436 printk(KERN_WARNING "scsi%d: abort %p ", info->host->host_no, SCpnt);
2437
2438 switch (fas216_find_command(info, SCpnt)) { 2431 switch (fas216_find_command(info, SCpnt)) {
2439 /* 2432 /*
2440 * We found the command, and cleared it out. Either 2433 * We found the command, and cleared it out. Either
@@ -2442,7 +2435,7 @@ int fas216_eh_abort(struct scsi_cmnd *SCpnt)
2442 * target, or the busylun bit is not set. 2435 * target, or the busylun bit is not set.
2443 */ 2436 */
2444 case res_success: 2437 case res_success:
2445 printk("success\n"); 2438 scmd_printk(KERN_WARNING, SCpnt, "abort %p success\n", SCpnt);
2446 result = SUCCESS; 2439 result = SUCCESS;
2447 break; 2440 break;
2448 2441
@@ -2452,14 +2445,13 @@ int fas216_eh_abort(struct scsi_cmnd *SCpnt)
2452 * if the bus is free. 2445 * if the bus is free.
2453 */ 2446 */
2454 case res_hw_abort: 2447 case res_hw_abort:
2455
2456 2448
2457 /* 2449 /*
2458 * We are unable to abort the command for some reason. 2450 * We are unable to abort the command for some reason.
2459 */ 2451 */
2460 default: 2452 default:
2461 case res_failed: 2453 case res_failed:
2462 printk("failed\n"); 2454 scmd_printk(KERN_WARNING, SCpnt, "abort %p failed\n", SCpnt);
2463 break; 2455 break;
2464 } 2456 }
2465 2457
@@ -2664,8 +2656,7 @@ int fas216_eh_host_reset(struct scsi_cmnd *SCpnt)
2664 2656
2665 fas216_checkmagic(info); 2657 fas216_checkmagic(info);
2666 2658
2667 printk("scsi%d.%c: %s: resetting host\n", 2659 fas216_log(info, LOG_ERROR, "resetting host");
2668 info->host->host_no, '0' + SCpnt->device->id, __func__);
2669 2660
2670 /* 2661 /*
2671 * Reset the SCSI chip. 2662 * Reset the SCSI chip.
diff --git a/drivers/scsi/arm/oak.c b/drivers/scsi/arm/oak.c
index 188e734c7ff0..7c6fa1479c9c 100644
--- a/drivers/scsi/arm/oak.c
+++ b/drivers/scsi/arm/oak.c
@@ -14,13 +14,9 @@
14#include <asm/ecard.h> 14#include <asm/ecard.h>
15#include <asm/io.h> 15#include <asm/io.h>
16 16
17#include "../scsi.h"
18#include <scsi/scsi_host.h> 17#include <scsi/scsi_host.h>
19 18
20#define AUTOSENSE
21/*#define PSEUDO_DMA*/ 19/*#define PSEUDO_DMA*/
22
23#define OAKSCSI_PUBLIC_RELEASE 1
24#define DONT_USE_INTR 20#define DONT_USE_INTR
25 21
26#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata) 22#define priv(host) ((struct NCR5380_hostdata *)(host)->hostdata)
@@ -29,10 +25,9 @@
29 25
30#define NCR5380_read(reg) readb(_base + ((reg) << 2)) 26#define NCR5380_read(reg) readb(_base + ((reg) << 2))
31#define NCR5380_write(reg, value) writeb(value, _base + ((reg) << 2)) 27#define NCR5380_write(reg, value) writeb(value, _base + ((reg) << 2))
32#define NCR5380_intr oakscsi_intr
33#define NCR5380_queue_command oakscsi_queue_command 28#define NCR5380_queue_command oakscsi_queue_command
29#define NCR5380_info oakscsi_info
34#define NCR5380_show_info oakscsi_show_info 30#define NCR5380_show_info oakscsi_show_info
35#define NCR5380_write_info oakscsi_write_info
36 31
37#define NCR5380_implementation_fields \ 32#define NCR5380_implementation_fields \
38 void __iomem *base 33 void __iomem *base
@@ -42,11 +37,6 @@
42#undef START_DMA_INITIATOR_RECEIVE_REG 37#undef START_DMA_INITIATOR_RECEIVE_REG
43#define START_DMA_INITIATOR_RECEIVE_REG (128 + 7) 38#define START_DMA_INITIATOR_RECEIVE_REG (128 + 7)
44 39
45const char * oakscsi_info (struct Scsi_Host *spnt)
46{
47 return "";
48}
49
50#define STAT ((128 + 16) << 2) 40#define STAT ((128 + 16) << 2)
51#define DATA ((128 + 8) << 2) 41#define DATA ((128 + 8) << 2)
52 42
@@ -114,7 +104,6 @@ printk("reading %p len %d\n", addr, len);
114static struct scsi_host_template oakscsi_template = { 104static struct scsi_host_template oakscsi_template = {
115 .module = THIS_MODULE, 105 .module = THIS_MODULE,
116 .show_info = oakscsi_show_info, 106 .show_info = oakscsi_show_info,
117 .write_info = oakscsi_write_info,
118 .name = "Oak 16-bit SCSI", 107 .name = "Oak 16-bit SCSI",
119 .info = oakscsi_info, 108 .info = oakscsi_info,
120 .queuecommand = oakscsi_queue_command, 109 .queuecommand = oakscsi_queue_command,
@@ -150,19 +139,11 @@ static int oakscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
150 goto unreg; 139 goto unreg;
151 } 140 }
152 141
153 host->irq = IRQ_NONE; 142 host->irq = NO_IRQ;
154 host->n_io_port = 255; 143 host->n_io_port = 255;
155 144
156 NCR5380_init(host, 0); 145 NCR5380_init(host, 0);
157 146
158 printk("scsi%d: at port 0x%08lx irqs disabled",
159 host->host_no, host->io_port);
160 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
161 host->can_queue, host->cmd_per_lun, OAKSCSI_PUBLIC_RELEASE);
162 printk("\nscsi%d:", host->host_no);
163 NCR5380_print_options(host);
164 printk("\n");
165
166 ret = scsi_add_host(host, &ec->dev); 147 ret = scsi_add_host(host, &ec->dev);
167 if (ret) 148 if (ret)
168 goto out_unmap; 149 goto out_unmap;
diff --git a/drivers/scsi/atari_NCR5380.c b/drivers/scsi/atari_NCR5380.c
index 79e6f045c2a9..6daed6b386d4 100644
--- a/drivers/scsi/atari_NCR5380.c
+++ b/drivers/scsi/atari_NCR5380.c
@@ -11,8 +11,6 @@
11 * drew@colorado.edu 11 * drew@colorado.edu
12 * +1 (303) 666-5836 12 * +1 (303) 666-5836
13 * 13 *
14 * DISTRIBUTION RELEASE 6.
15 *
16 * For more information, please consult 14 * For more information, please consult
17 * 15 *
18 * NCR 5380 Family 16 * NCR 5380 Family
@@ -73,6 +71,9 @@
73 * 1. Test linked command handling code after Eric is ready with 71 * 1. Test linked command handling code after Eric is ready with
74 * the high level code. 72 * the high level code.
75 */ 73 */
74
75/* Adapted for the sun3 by Sam Creasey. */
76
76#include <scsi/scsi_dbg.h> 77#include <scsi/scsi_dbg.h>
77#include <scsi/scsi_transport_spi.h> 78#include <scsi/scsi_transport_spi.h>
78 79
@@ -103,27 +104,7 @@
103 104
104/* 105/*
105 * Design 106 * Design
106 * Issues :
107 *
108 * The other Linux SCSI drivers were written when Linux was Intel PC-only,
109 * and specifically for each board rather than each chip. This makes their
110 * adaptation to platforms like the Mac (Some of which use NCR5380's)
111 * more difficult than it has to be.
112 * 107 *
113 * Also, many of the SCSI drivers were written before the command queuing
114 * routines were implemented, meaning their implementations of queued
115 * commands were hacked on rather than designed in from the start.
116 *
117 * When I designed the Linux SCSI drivers I figured that
118 * while having two different SCSI boards in a system might be useful
119 * for debugging things, two of the same type wouldn't be used.
120 * Well, I was wrong and a number of users have mailed me about running
121 * multiple high-performance SCSI boards in a server.
122 *
123 * Finally, when I get questions from users, I have no idea what
124 * revision of my driver they are running.
125 *
126 * This driver attempts to address these problems :
127 * This is a generic 5380 driver. To use it on a different platform, 108 * This is a generic 5380 driver. To use it on a different platform,
128 * one simply writes appropriate system specific macros (ie, data 109 * one simply writes appropriate system specific macros (ie, data
129 * transfer - some PC's will use the I/O bus, 68K's must use 110 * transfer - some PC's will use the I/O bus, 68K's must use
@@ -138,17 +119,6 @@
138 * allowing multiple commands to propagate all the way to a SCSI-II device 119 * allowing multiple commands to propagate all the way to a SCSI-II device
139 * while a command is already executing. 120 * while a command is already executing.
140 * 121 *
141 * To solve the multiple-boards-in-the-same-system problem,
142 * there is a separate instance structure for each instance
143 * of a 5380 in the system. So, multiple NCR5380 drivers will
144 * be able to coexist with appropriate changes to the high level
145 * SCSI code.
146 *
147 * A NCR5380_PUBLIC_REVISION macro is provided, with the release
148 * number (updated for each public release) printed by the
149 * NCR5380_print_options command, which should be called from the
150 * wrapper detect function, so that I know what release of the driver
151 * users are using.
152 * 122 *
153 * Issues specific to the NCR5380 : 123 * Issues specific to the NCR5380 :
154 * 124 *
@@ -173,19 +143,17 @@
173 * Architecture : 143 * Architecture :
174 * 144 *
175 * At the heart of the design is a coroutine, NCR5380_main, 145 * At the heart of the design is a coroutine, NCR5380_main,
176 * which is started when not running by the interrupt handler, 146 * which is started from a workqueue for each NCR5380 host in the
177 * timer, and queue command function. It attempts to establish 147 * system. It attempts to establish I_T_L or I_T_L_Q nexuses by
178 * I_T_L or I_T_L_Q nexuses by removing the commands from the 148 * removing the commands from the issue queue and calling
179 * issue queue and calling NCR5380_select() if a nexus 149 * NCR5380_select() if a nexus is not established.
180 * is not established.
181 * 150 *
182 * Once a nexus is established, the NCR5380_information_transfer() 151 * Once a nexus is established, the NCR5380_information_transfer()
183 * phase goes through the various phases as instructed by the target. 152 * phase goes through the various phases as instructed by the target.
184 * if the target goes into MSG IN and sends a DISCONNECT message, 153 * if the target goes into MSG IN and sends a DISCONNECT message,
185 * the command structure is placed into the per instance disconnected 154 * the command structure is placed into the per instance disconnected
186 * queue, and NCR5380_main tries to find more work. If USLEEP 155 * queue, and NCR5380_main tries to find more work. If the target is
187 * was defined, and the target is idle for too long, the system 156 * idle for too long, the system will try to sleep.
188 * will try to sleep.
189 * 157 *
190 * If a command has disconnected, eventually an interrupt will trigger, 158 * If a command has disconnected, eventually an interrupt will trigger,
191 * calling NCR5380_intr() which will in turn call NCR5380_reselect 159 * calling NCR5380_intr() which will in turn call NCR5380_reselect
@@ -211,6 +179,9 @@
211 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically 179 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
212 * for commands that return with a CHECK CONDITION status. 180 * for commands that return with a CHECK CONDITION status.
213 * 181 *
182 * DIFFERENTIAL - if defined, NCR53c81 chips will use external differential
183 * transceivers.
184 *
214 * LINKED - if defined, linked commands are supported. 185 * LINKED - if defined, linked commands are supported.
215 * 186 *
216 * REAL_DMA - if defined, REAL DMA is used during the data transfer phases. 187 * REAL_DMA - if defined, REAL DMA is used during the data transfer phases.
@@ -223,6 +194,9 @@
223 * 194 *
224 * NCR5380_write(register, value) - write to the specific register 195 * NCR5380_write(register, value) - write to the specific register
225 * 196 *
197 * NCR5380_implementation_fields - additional fields needed for this
198 * specific implementation of the NCR5380
199 *
226 * Either real DMA *or* pseudo DMA may be implemented 200 * Either real DMA *or* pseudo DMA may be implemented
227 * REAL functions : 201 * REAL functions :
228 * NCR5380_REAL_DMA should be defined if real DMA is to be used. 202 * NCR5380_REAL_DMA should be defined if real DMA is to be used.
@@ -241,40 +215,21 @@
241 * NCR5380_pwrite(instance, src, count) 215 * NCR5380_pwrite(instance, src, count)
242 * NCR5380_pread(instance, dst, count); 216 * NCR5380_pread(instance, dst, count);
243 * 217 *
244 * If nothing specific to this implementation needs doing (ie, with external
245 * hardware), you must also define
246 *
247 * NCR5380_queue_command
248 * NCR5380_reset
249 * NCR5380_abort
250 * NCR5380_proc_info
251 *
252 * to be the global entry points into the specific driver, ie
253 * #define NCR5380_queue_command t128_queue_command.
254 *
255 * If this is not done, the routines will be defined as static functions
256 * with the NCR5380* names and the user must provide a globally
257 * accessible wrapper function.
258 *
259 * The generic driver is initialized by calling NCR5380_init(instance), 218 * The generic driver is initialized by calling NCR5380_init(instance),
260 * after setting the appropriate host specific fields and ID. If the 219 * after setting the appropriate host specific fields and ID. If the
261 * driver wishes to autoprobe for an IRQ line, the NCR5380_probe_irq(instance, 220 * driver wishes to autoprobe for an IRQ line, the NCR5380_probe_irq(instance,
262 * possible) function may be used. Before the specific driver initialization 221 * possible) function may be used.
263 * code finishes, NCR5380_print_options should be called.
264 */ 222 */
265 223
266static struct Scsi_Host *first_instance = NULL;
267static struct scsi_host_template *the_template = NULL;
268
269/* Macros ease life... :-) */ 224/* Macros ease life... :-) */
270#define SETUP_HOSTDATA(in) \ 225#define SETUP_HOSTDATA(in) \
271 struct NCR5380_hostdata *hostdata = \ 226 struct NCR5380_hostdata *hostdata = \
272 (struct NCR5380_hostdata *)(in)->hostdata 227 (struct NCR5380_hostdata *)(in)->hostdata
273#define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata) 228#define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata)
274 229
275#define NEXT(cmd) ((Scsi_Cmnd *)(cmd)->host_scribble) 230#define NEXT(cmd) ((struct scsi_cmnd *)(cmd)->host_scribble)
276#define SET_NEXT(cmd,next) ((cmd)->host_scribble = (void *)(next)) 231#define SET_NEXT(cmd,next) ((cmd)->host_scribble = (void *)(next))
277#define NEXTADDR(cmd) ((Scsi_Cmnd **)&(cmd)->host_scribble) 232#define NEXTADDR(cmd) ((struct scsi_cmnd **)&(cmd)->host_scribble)
278 233
279#define HOSTNO instance->host_no 234#define HOSTNO instance->host_no
280#define H_NO(cmd) (cmd)->device->host->host_no 235#define H_NO(cmd) (cmd)->device->host->host_no
@@ -316,30 +271,17 @@ static struct scsi_host_template *the_template = NULL;
316 * important: the tag bit must be cleared before 'nr_allocated' is decreased. 271 * important: the tag bit must be cleared before 'nr_allocated' is decreased.
317 */ 272 */
318 273
319/* -1 for TAG_NONE is not possible with unsigned char cmd->tag */ 274static void __init init_tags(struct NCR5380_hostdata *hostdata)
320#undef TAG_NONE
321#define TAG_NONE 0xff
322
323typedef struct {
324 DECLARE_BITMAP(allocated, MAX_TAGS);
325 int nr_allocated;
326 int queue_size;
327} TAG_ALLOC;
328
329static TAG_ALLOC TagAlloc[8][8]; /* 8 targets and 8 LUNs */
330
331
332static void __init init_tags(void)
333{ 275{
334 int target, lun; 276 int target, lun;
335 TAG_ALLOC *ta; 277 struct tag_alloc *ta;
336 278
337 if (!setup_use_tagged_queuing) 279 if (!(hostdata->flags & FLAG_TAGGED_QUEUING))
338 return; 280 return;
339 281
340 for (target = 0; target < 8; ++target) { 282 for (target = 0; target < 8; ++target) {
341 for (lun = 0; lun < 8; ++lun) { 283 for (lun = 0; lun < 8; ++lun) {
342 ta = &TagAlloc[target][lun]; 284 ta = &hostdata->TagAlloc[target][lun];
343 bitmap_zero(ta->allocated, MAX_TAGS); 285 bitmap_zero(ta->allocated, MAX_TAGS);
344 ta->nr_allocated = 0; 286 ta->nr_allocated = 0;
345 /* At the beginning, assume the maximum queue size we could 287 /* At the beginning, assume the maximum queue size we could
@@ -359,7 +301,7 @@ static void __init init_tags(void)
359 * conditions. 301 * conditions.
360 */ 302 */
361 303
362static int is_lun_busy(Scsi_Cmnd *cmd, int should_be_tagged) 304static int is_lun_busy(struct scsi_cmnd *cmd, int should_be_tagged)
363{ 305{
364 u8 lun = cmd->device->lun; 306 u8 lun = cmd->device->lun;
365 SETUP_HOSTDATA(cmd->device->host); 307 SETUP_HOSTDATA(cmd->device->host);
@@ -367,10 +309,11 @@ static int is_lun_busy(Scsi_Cmnd *cmd, int should_be_tagged)
367 if (hostdata->busy[cmd->device->id] & (1 << lun)) 309 if (hostdata->busy[cmd->device->id] & (1 << lun))
368 return 1; 310 return 1;
369 if (!should_be_tagged || 311 if (!should_be_tagged ||
370 !setup_use_tagged_queuing || !cmd->device->tagged_supported) 312 !(hostdata->flags & FLAG_TAGGED_QUEUING) ||
313 !cmd->device->tagged_supported)
371 return 0; 314 return 0;
372 if (TagAlloc[cmd->device->id][lun].nr_allocated >= 315 if (hostdata->TagAlloc[scmd_id(cmd)][lun].nr_allocated >=
373 TagAlloc[cmd->device->id][lun].queue_size) { 316 hostdata->TagAlloc[scmd_id(cmd)][lun].queue_size) {
374 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d: no free tags\n", 317 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d: no free tags\n",
375 H_NO(cmd), cmd->device->id, lun); 318 H_NO(cmd), cmd->device->id, lun);
376 return 1; 319 return 1;
@@ -384,7 +327,7 @@ static int is_lun_busy(Scsi_Cmnd *cmd, int should_be_tagged)
384 * untagged. 327 * untagged.
385 */ 328 */
386 329
387static void cmd_get_tag(Scsi_Cmnd *cmd, int should_be_tagged) 330static void cmd_get_tag(struct scsi_cmnd *cmd, int should_be_tagged)
388{ 331{
389 u8 lun = cmd->device->lun; 332 u8 lun = cmd->device->lun;
390 SETUP_HOSTDATA(cmd->device->host); 333 SETUP_HOSTDATA(cmd->device->host);
@@ -393,13 +336,14 @@ static void cmd_get_tag(Scsi_Cmnd *cmd, int should_be_tagged)
393 * an untagged command. 336 * an untagged command.
394 */ 337 */
395 if (!should_be_tagged || 338 if (!should_be_tagged ||
396 !setup_use_tagged_queuing || !cmd->device->tagged_supported) { 339 !(hostdata->flags & FLAG_TAGGED_QUEUING) ||
340 !cmd->device->tagged_supported) {
397 cmd->tag = TAG_NONE; 341 cmd->tag = TAG_NONE;
398 hostdata->busy[cmd->device->id] |= (1 << lun); 342 hostdata->busy[cmd->device->id] |= (1 << lun);
399 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d now allocated by untagged " 343 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d now allocated by untagged "
400 "command\n", H_NO(cmd), cmd->device->id, lun); 344 "command\n", H_NO(cmd), cmd->device->id, lun);
401 } else { 345 } else {
402 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][lun]; 346 struct tag_alloc *ta = &hostdata->TagAlloc[scmd_id(cmd)][lun];
403 347
404 cmd->tag = find_first_zero_bit(ta->allocated, MAX_TAGS); 348 cmd->tag = find_first_zero_bit(ta->allocated, MAX_TAGS);
405 set_bit(cmd->tag, ta->allocated); 349 set_bit(cmd->tag, ta->allocated);
@@ -416,7 +360,7 @@ static void cmd_get_tag(Scsi_Cmnd *cmd, int should_be_tagged)
416 * unlock the LUN. 360 * unlock the LUN.
417 */ 361 */
418 362
419static void cmd_free_tag(Scsi_Cmnd *cmd) 363static void cmd_free_tag(struct scsi_cmnd *cmd)
420{ 364{
421 u8 lun = cmd->device->lun; 365 u8 lun = cmd->device->lun;
422 SETUP_HOSTDATA(cmd->device->host); 366 SETUP_HOSTDATA(cmd->device->host);
@@ -429,7 +373,7 @@ static void cmd_free_tag(Scsi_Cmnd *cmd)
429 printk(KERN_NOTICE "scsi%d: trying to free bad tag %d!\n", 373 printk(KERN_NOTICE "scsi%d: trying to free bad tag %d!\n",
430 H_NO(cmd), cmd->tag); 374 H_NO(cmd), cmd->tag);
431 } else { 375 } else {
432 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][lun]; 376 struct tag_alloc *ta = &hostdata->TagAlloc[scmd_id(cmd)][lun];
433 clear_bit(cmd->tag, ta->allocated); 377 clear_bit(cmd->tag, ta->allocated);
434 ta->nr_allocated--; 378 ta->nr_allocated--;
435 dprintk(NDEBUG_TAGS, "scsi%d: freed tag %d for target %d lun %d\n", 379 dprintk(NDEBUG_TAGS, "scsi%d: freed tag %d for target %d lun %d\n",
@@ -438,17 +382,17 @@ static void cmd_free_tag(Scsi_Cmnd *cmd)
438} 382}
439 383
440 384
441static void free_all_tags(void) 385static void free_all_tags(struct NCR5380_hostdata *hostdata)
442{ 386{
443 int target, lun; 387 int target, lun;
444 TAG_ALLOC *ta; 388 struct tag_alloc *ta;
445 389
446 if (!setup_use_tagged_queuing) 390 if (!(hostdata->flags & FLAG_TAGGED_QUEUING))
447 return; 391 return;
448 392
449 for (target = 0; target < 8; ++target) { 393 for (target = 0; target < 8; ++target) {
450 for (lun = 0; lun < 8; ++lun) { 394 for (lun = 0; lun < 8; ++lun) {
451 ta = &TagAlloc[target][lun]; 395 ta = &hostdata->TagAlloc[target][lun];
452 bitmap_zero(ta->allocated, MAX_TAGS); 396 bitmap_zero(ta->allocated, MAX_TAGS);
453 ta->nr_allocated = 0; 397 ta->nr_allocated = 0;
454 } 398 }
@@ -459,19 +403,20 @@ static void free_all_tags(void)
459 403
460 404
461/* 405/*
462 * Function: void merge_contiguous_buffers( Scsi_Cmnd *cmd ) 406 * Function: void merge_contiguous_buffers( struct scsi_cmnd *cmd )
463 * 407 *
464 * Purpose: Try to merge several scatter-gather requests into one DMA 408 * Purpose: Try to merge several scatter-gather requests into one DMA
465 * transfer. This is possible if the scatter buffers lie on 409 * transfer. This is possible if the scatter buffers lie on
466 * physical contiguous addresses. 410 * physical contiguous addresses.
467 * 411 *
468 * Parameters: Scsi_Cmnd *cmd 412 * Parameters: struct scsi_cmnd *cmd
469 * The command to work on. The first scatter buffer's data are 413 * The command to work on. The first scatter buffer's data are
470 * assumed to be already transferred into ptr/this_residual. 414 * assumed to be already transferred into ptr/this_residual.
471 */ 415 */
472 416
473static void merge_contiguous_buffers(Scsi_Cmnd *cmd) 417static void merge_contiguous_buffers(struct scsi_cmnd *cmd)
474{ 418{
419#if !defined(CONFIG_SUN3)
475 unsigned long endaddr; 420 unsigned long endaddr;
476#if (NDEBUG & NDEBUG_MERGING) 421#if (NDEBUG & NDEBUG_MERGING)
477 unsigned long oldlen = cmd->SCp.this_residual; 422 unsigned long oldlen = cmd->SCp.this_residual;
@@ -496,18 +441,17 @@ static void merge_contiguous_buffers(Scsi_Cmnd *cmd)
496 dprintk(NDEBUG_MERGING, "merged %d buffers from %p, new length %08x\n", 441 dprintk(NDEBUG_MERGING, "merged %d buffers from %p, new length %08x\n",
497 cnt, cmd->SCp.ptr, cmd->SCp.this_residual); 442 cnt, cmd->SCp.ptr, cmd->SCp.this_residual);
498#endif 443#endif
444#endif /* !defined(CONFIG_SUN3) */
499} 445}
500 446
501/* 447/**
502 * Function : void initialize_SCp(Scsi_Cmnd *cmd) 448 * initialize_SCp - init the scsi pointer field
449 * @cmd: command block to set up
503 * 450 *
504 * Purpose : initialize the saved data pointers for cmd to point to the 451 * Set up the internal fields in the SCSI command.
505 * start of the buffer.
506 *
507 * Inputs : cmd - Scsi_Cmnd structure to have pointers reset.
508 */ 452 */
509 453
510static inline void initialize_SCp(Scsi_Cmnd *cmd) 454static inline void initialize_SCp(struct scsi_cmnd *cmd)
511{ 455{
512 /* 456 /*
513 * Initialize the Scsi Pointer field so that all of the commands in the 457 * Initialize the Scsi Pointer field so that all of the commands in the
@@ -557,12 +501,11 @@ static struct {
557 {0, NULL} 501 {0, NULL}
558}; 502};
559 503
560/* 504/**
561 * Function : void NCR5380_print(struct Scsi_Host *instance) 505 * NCR5380_print - print scsi bus signals
506 * @instance: adapter state to dump
562 * 507 *
563 * Purpose : print the SCSI bus signals for debugging purposes 508 * Print the SCSI bus signals for debugging purposes
564 *
565 * Input : instance - which NCR5380
566 */ 509 */
567 510
568static void NCR5380_print(struct Scsi_Host *instance) 511static void NCR5380_print(struct Scsi_Host *instance)
@@ -605,12 +548,13 @@ static struct {
605 {PHASE_UNKNOWN, "UNKNOWN"} 548 {PHASE_UNKNOWN, "UNKNOWN"}
606}; 549};
607 550
608/* 551/**
609 * Function : void NCR5380_print_phase(struct Scsi_Host *instance) 552 * NCR5380_print_phase - show SCSI phase
553 * @instance: adapter to dump
610 * 554 *
611 * Purpose : print the current SCSI phase for debugging purposes 555 * Print the current SCSI phase for debugging purposes
612 * 556 *
613 * Input : instance - which NCR5380 557 * Locks: none
614 */ 558 */
615 559
616static void NCR5380_print_phase(struct Scsi_Host *instance) 560static void NCR5380_print_phase(struct Scsi_Host *instance)
@@ -648,71 +592,75 @@ static void NCR5380_print_phase(struct Scsi_Host *instance)
648#include <linux/workqueue.h> 592#include <linux/workqueue.h>
649#include <linux/interrupt.h> 593#include <linux/interrupt.h>
650 594
651static volatile int main_running; 595static inline void queue_main(struct NCR5380_hostdata *hostdata)
652static DECLARE_WORK(NCR5380_tqueue, NCR5380_main);
653
654static inline void queue_main(void)
655{ 596{
656 if (!main_running) { 597 if (!hostdata->main_running) {
657 /* If in interrupt and NCR5380_main() not already running, 598 /* If in interrupt and NCR5380_main() not already running,
658 queue it on the 'immediate' task queue, to be processed 599 queue it on the 'immediate' task queue, to be processed
659 immediately after the current interrupt processing has 600 immediately after the current interrupt processing has
660 finished. */ 601 finished. */
661 schedule_work(&NCR5380_tqueue); 602 schedule_work(&hostdata->main_task);
662 } 603 }
663 /* else: nothing to do: the running NCR5380_main() will pick up 604 /* else: nothing to do: the running NCR5380_main() will pick up
664 any newly queued command. */ 605 any newly queued command. */
665} 606}
666 607
667 608/**
668static inline void NCR5380_all_init(void) 609 * NCR58380_info - report driver and host information
669{ 610 * @instance: relevant scsi host instance
670 static int done = 0;
671 if (!done) {
672 dprintk(NDEBUG_INIT, "scsi : NCR5380_all_init()\n");
673 done = 1;
674 }
675}
676
677
678/*
679 * Function : void NCR58380_print_options (struct Scsi_Host *instance)
680 * 611 *
681 * Purpose : called by probe code indicating the NCR5380 driver 612 * For use as the host template info() handler.
682 * options that were selected.
683 * 613 *
684 * Inputs : instance, pointer to this instance. Unused. 614 * Locks: none
685 */ 615 */
686 616
687static void __init NCR5380_print_options(struct Scsi_Host *instance) 617static const char *NCR5380_info(struct Scsi_Host *instance)
618{
619 struct NCR5380_hostdata *hostdata = shost_priv(instance);
620
621 return hostdata->info;
622}
623
624static void prepare_info(struct Scsi_Host *instance)
688{ 625{
689 printk(" generic options" 626 struct NCR5380_hostdata *hostdata = shost_priv(instance);
690#ifdef AUTOSENSE 627
691 " AUTOSENSE" 628 snprintf(hostdata->info, sizeof(hostdata->info),
629 "%s, io_port 0x%lx, n_io_port %d, "
630 "base 0x%lx, irq %d, "
631 "can_queue %d, cmd_per_lun %d, "
632 "sg_tablesize %d, this_id %d, "
633 "flags { %s}, "
634 "options { %s} ",
635 instance->hostt->name, instance->io_port, instance->n_io_port,
636 instance->base, instance->irq,
637 instance->can_queue, instance->cmd_per_lun,
638 instance->sg_tablesize, instance->this_id,
639 hostdata->flags & FLAG_TAGGED_QUEUING ? "TAGGED_QUEUING " : "",
640#ifdef DIFFERENTIAL
641 "DIFFERENTIAL "
692#endif 642#endif
693#ifdef REAL_DMA 643#ifdef REAL_DMA
694 " REAL DMA" 644 "REAL_DMA "
695#endif 645#endif
696#ifdef PARITY 646#ifdef PARITY
697 " PARITY" 647 "PARITY "
698#endif 648#endif
699#ifdef SUPPORT_TAGS 649#ifdef SUPPORT_TAGS
700 " SCSI-2 TAGGED QUEUING" 650 "SUPPORT_TAGS "
701#endif 651#endif
702 ); 652 "");
703 printk(" generic release=%d", NCR5380_PUBLIC_RELEASE);
704} 653}
705 654
706/* 655/**
707 * Function : void NCR5380_print_status (struct Scsi_Host *instance) 656 * NCR5380_print_status - dump controller info
657 * @instance: controller to dump
708 * 658 *
709 * Purpose : print commands in the various queues, called from 659 * Print commands in the various queues, called from NCR5380_abort
710 * NCR5380_abort and NCR5380_debug to aid debugging. 660 * to aid debugging.
711 *
712 * Inputs : instance, pointer to this instance.
713 */ 661 */
714 662
715static void lprint_Scsi_Cmnd(Scsi_Cmnd *cmd) 663static void lprint_Scsi_Cmnd(struct scsi_cmnd *cmd)
716{ 664{
717 int i, s; 665 int i, s;
718 unsigned char *command; 666 unsigned char *command;
@@ -729,7 +677,7 @@ static void lprint_Scsi_Cmnd(Scsi_Cmnd *cmd)
729static void NCR5380_print_status(struct Scsi_Host *instance) 677static void NCR5380_print_status(struct Scsi_Host *instance)
730{ 678{
731 struct NCR5380_hostdata *hostdata; 679 struct NCR5380_hostdata *hostdata;
732 Scsi_Cmnd *ptr; 680 struct scsi_cmnd *ptr;
733 unsigned long flags; 681 unsigned long flags;
734 682
735 NCR5380_dprint(NDEBUG_ANY, instance); 683 NCR5380_dprint(NDEBUG_ANY, instance);
@@ -737,20 +685,19 @@ static void NCR5380_print_status(struct Scsi_Host *instance)
737 685
738 hostdata = (struct NCR5380_hostdata *)instance->hostdata; 686 hostdata = (struct NCR5380_hostdata *)instance->hostdata;
739 687
740 printk("\nNCR5380 core release=%d.\n", NCR5380_PUBLIC_RELEASE);
741 local_irq_save(flags); 688 local_irq_save(flags);
742 printk("NCR5380: coroutine is%s running.\n", 689 printk("NCR5380: coroutine is%s running.\n",
743 main_running ? "" : "n't"); 690 hostdata->main_running ? "" : "n't");
744 if (!hostdata->connected) 691 if (!hostdata->connected)
745 printk("scsi%d: no currently connected command\n", HOSTNO); 692 printk("scsi%d: no currently connected command\n", HOSTNO);
746 else 693 else
747 lprint_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected); 694 lprint_Scsi_Cmnd((struct scsi_cmnd *) hostdata->connected);
748 printk("scsi%d: issue_queue\n", HOSTNO); 695 printk("scsi%d: issue_queue\n", HOSTNO);
749 for (ptr = (Scsi_Cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr)) 696 for (ptr = (struct scsi_cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr))
750 lprint_Scsi_Cmnd(ptr); 697 lprint_Scsi_Cmnd(ptr);
751 698
752 printk("scsi%d: disconnected_queue\n", HOSTNO); 699 printk("scsi%d: disconnected_queue\n", HOSTNO);
753 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr; 700 for (ptr = (struct scsi_cmnd *) hostdata->disconnected_queue; ptr;
754 ptr = NEXT(ptr)) 701 ptr = NEXT(ptr))
755 lprint_Scsi_Cmnd(ptr); 702 lprint_Scsi_Cmnd(ptr);
756 703
@@ -758,7 +705,7 @@ static void NCR5380_print_status(struct Scsi_Host *instance)
758 printk("\n"); 705 printk("\n");
759} 706}
760 707
761static void show_Scsi_Cmnd(Scsi_Cmnd *cmd, struct seq_file *m) 708static void show_Scsi_Cmnd(struct scsi_cmnd *cmd, struct seq_file *m)
762{ 709{
763 int i, s; 710 int i, s;
764 unsigned char *command; 711 unsigned char *command;
@@ -772,28 +719,28 @@ static void show_Scsi_Cmnd(Scsi_Cmnd *cmd, struct seq_file *m)
772 seq_printf(m, "\n"); 719 seq_printf(m, "\n");
773} 720}
774 721
775static int NCR5380_show_info(struct seq_file *m, struct Scsi_Host *instance) 722static int __maybe_unused NCR5380_show_info(struct seq_file *m,
723 struct Scsi_Host *instance)
776{ 724{
777 struct NCR5380_hostdata *hostdata; 725 struct NCR5380_hostdata *hostdata;
778 Scsi_Cmnd *ptr; 726 struct scsi_cmnd *ptr;
779 unsigned long flags; 727 unsigned long flags;
780 728
781 hostdata = (struct NCR5380_hostdata *)instance->hostdata; 729 hostdata = (struct NCR5380_hostdata *)instance->hostdata;
782 730
783 seq_printf(m, "NCR5380 core release=%d.\n", NCR5380_PUBLIC_RELEASE);
784 local_irq_save(flags); 731 local_irq_save(flags);
785 seq_printf(m, "NCR5380: coroutine is%s running.\n", 732 seq_printf(m, "NCR5380: coroutine is%s running.\n",
786 main_running ? "" : "n't"); 733 hostdata->main_running ? "" : "n't");
787 if (!hostdata->connected) 734 if (!hostdata->connected)
788 seq_printf(m, "scsi%d: no currently connected command\n", HOSTNO); 735 seq_printf(m, "scsi%d: no currently connected command\n", HOSTNO);
789 else 736 else
790 show_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected, m); 737 show_Scsi_Cmnd((struct scsi_cmnd *) hostdata->connected, m);
791 seq_printf(m, "scsi%d: issue_queue\n", HOSTNO); 738 seq_printf(m, "scsi%d: issue_queue\n", HOSTNO);
792 for (ptr = (Scsi_Cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr)) 739 for (ptr = (struct scsi_cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr))
793 show_Scsi_Cmnd(ptr, m); 740 show_Scsi_Cmnd(ptr, m);
794 741
795 seq_printf(m, "scsi%d: disconnected_queue\n", HOSTNO); 742 seq_printf(m, "scsi%d: disconnected_queue\n", HOSTNO);
796 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr; 743 for (ptr = (struct scsi_cmnd *) hostdata->disconnected_queue; ptr;
797 ptr = NEXT(ptr)) 744 ptr = NEXT(ptr))
798 show_Scsi_Cmnd(ptr, m); 745 show_Scsi_Cmnd(ptr, m);
799 746
@@ -801,16 +748,18 @@ static int NCR5380_show_info(struct seq_file *m, struct Scsi_Host *instance)
801 return 0; 748 return 0;
802} 749}
803 750
804/* 751/**
805 * Function : void NCR5380_init (struct Scsi_Host *instance) 752 * NCR5380_init - initialise an NCR5380
753 * @instance: adapter to configure
754 * @flags: control flags
806 * 755 *
807 * Purpose : initializes *instance and corresponding 5380 chip. 756 * Initializes *instance and corresponding 5380 chip,
808 * 757 * with flags OR'd into the initial flags value.
809 * Inputs : instance - instantiation of the 5380 driver.
810 * 758 *
811 * Notes : I assume that the host, hostno, and id bits have been 759 * Notes : I assume that the host, hostno, and id bits have been
812 * set correctly. I don't care about the irq and other fields. 760 * set correctly. I don't care about the irq and other fields.
813 * 761 *
762 * Returns 0 for success
814 */ 763 */
815 764
816static int __init NCR5380_init(struct Scsi_Host *instance, int flags) 765static int __init NCR5380_init(struct Scsi_Host *instance, int flags)
@@ -818,8 +767,7 @@ static int __init NCR5380_init(struct Scsi_Host *instance, int flags)
818 int i; 767 int i;
819 SETUP_HOSTDATA(instance); 768 SETUP_HOSTDATA(instance);
820 769
821 NCR5380_all_init(); 770 hostdata->host = instance;
822
823 hostdata->aborted = 0; 771 hostdata->aborted = 0;
824 hostdata->id_mask = 1 << instance->this_id; 772 hostdata->id_mask = 1 << instance->this_id;
825 hostdata->id_higher_mask = 0; 773 hostdata->id_higher_mask = 0;
@@ -829,7 +777,7 @@ static int __init NCR5380_init(struct Scsi_Host *instance, int flags)
829 for (i = 0; i < 8; ++i) 777 for (i = 0; i < 8; ++i)
830 hostdata->busy[i] = 0; 778 hostdata->busy[i] = 0;
831#ifdef SUPPORT_TAGS 779#ifdef SUPPORT_TAGS
832 init_tags(); 780 init_tags(hostdata);
833#endif 781#endif
834#if defined (REAL_DMA) 782#if defined (REAL_DMA)
835 hostdata->dma_len = 0; 783 hostdata->dma_len = 0;
@@ -838,19 +786,11 @@ static int __init NCR5380_init(struct Scsi_Host *instance, int flags)
838 hostdata->connected = NULL; 786 hostdata->connected = NULL;
839 hostdata->issue_queue = NULL; 787 hostdata->issue_queue = NULL;
840 hostdata->disconnected_queue = NULL; 788 hostdata->disconnected_queue = NULL;
841 hostdata->flags = FLAG_CHECK_LAST_BYTE_SENT; 789 hostdata->flags = flags;
842 790
843 if (!the_template) { 791 INIT_WORK(&hostdata->main_task, NCR5380_main);
844 the_template = instance->hostt;
845 first_instance = instance;
846 }
847 792
848#ifndef AUTOSENSE 793 prepare_info(instance);
849 if ((instance->cmd_per_lun > 1) || (instance->can_queue > 1))
850 printk("scsi%d: WARNING : support for multiple outstanding commands enabled\n"
851 " without AUTOSENSE option, contingent allegiance conditions may\n"
852 " be incorrectly cleared.\n", HOSTNO);
853#endif /* def AUTOSENSE */
854 794
855 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 795 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
856 NCR5380_write(MODE_REG, MR_BASE); 796 NCR5380_write(MODE_REG, MR_BASE);
@@ -860,33 +800,35 @@ static int __init NCR5380_init(struct Scsi_Host *instance, int flags)
860 return 0; 800 return 0;
861} 801}
862 802
803/**
804 * NCR5380_exit - remove an NCR5380
805 * @instance: adapter to remove
806 *
807 * Assumes that no more work can be queued (e.g. by NCR5380_intr).
808 */
809
863static void NCR5380_exit(struct Scsi_Host *instance) 810static void NCR5380_exit(struct Scsi_Host *instance)
864{ 811{
865 /* Empty, as we didn't schedule any delayed work */ 812 struct NCR5380_hostdata *hostdata = shost_priv(instance);
813
814 cancel_work_sync(&hostdata->main_task);
866} 815}
867 816
868/* 817/**
869 * Function : int NCR5380_queue_command (Scsi_Cmnd *cmd, 818 * NCR5380_queue_command - queue a command
870 * void (*done)(Scsi_Cmnd *)) 819 * @instance: the relevant SCSI adapter
871 * 820 * @cmd: SCSI command
872 * Purpose : enqueues a SCSI command
873 *
874 * Inputs : cmd - SCSI command, done - function called on completion, with
875 * a pointer to the command descriptor.
876 *
877 * Returns : 0
878 *
879 * Side effects :
880 * cmd is added to the per instance issue_queue, with minor
881 * twiddling done to the host specific fields of cmd. If the
882 * main coroutine is not running, it is restarted.
883 * 821 *
822 * cmd is added to the per instance issue_queue, with minor
823 * twiddling done to the host specific fields of cmd. If the
824 * main coroutine is not running, it is restarted.
884 */ 825 */
885 826
886static int NCR5380_queue_command_lck(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *)) 827static int NCR5380_queue_command(struct Scsi_Host *instance,
828 struct scsi_cmnd *cmd)
887{ 829{
888 SETUP_HOSTDATA(cmd->device->host); 830 struct NCR5380_hostdata *hostdata = shost_priv(instance);
889 Scsi_Cmnd *tmp; 831 struct scsi_cmnd *tmp;
890 unsigned long flags; 832 unsigned long flags;
891 833
892#if (NDEBUG & NDEBUG_NO_WRITE) 834#if (NDEBUG & NDEBUG_NO_WRITE)
@@ -896,47 +838,17 @@ static int NCR5380_queue_command_lck(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
896 printk(KERN_NOTICE "scsi%d: WRITE attempted with NO_WRITE debugging flag set\n", 838 printk(KERN_NOTICE "scsi%d: WRITE attempted with NO_WRITE debugging flag set\n",
897 H_NO(cmd)); 839 H_NO(cmd));
898 cmd->result = (DID_ERROR << 16); 840 cmd->result = (DID_ERROR << 16);
899 done(cmd); 841 cmd->scsi_done(cmd);
900 return 0; 842 return 0;
901 } 843 }
902#endif /* (NDEBUG & NDEBUG_NO_WRITE) */ 844#endif /* (NDEBUG & NDEBUG_NO_WRITE) */
903 845
904#ifdef NCR5380_STATS
905# if 0
906 if (!hostdata->connected && !hostdata->issue_queue &&
907 !hostdata->disconnected_queue) {
908 hostdata->timebase = jiffies;
909 }
910# endif
911# ifdef NCR5380_STAT_LIMIT
912 if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
913# endif
914 switch (cmd->cmnd[0]) {
915 case WRITE:
916 case WRITE_6:
917 case WRITE_10:
918 hostdata->time_write[cmd->device->id] -= (jiffies - hostdata->timebase);
919 hostdata->bytes_write[cmd->device->id] += scsi_bufflen(cmd);
920 hostdata->pendingw++;
921 break;
922 case READ:
923 case READ_6:
924 case READ_10:
925 hostdata->time_read[cmd->device->id] -= (jiffies - hostdata->timebase);
926 hostdata->bytes_read[cmd->device->id] += scsi_bufflen(cmd);
927 hostdata->pendingr++;
928 break;
929 }
930#endif
931
932 /* 846 /*
933 * We use the host_scribble field as a pointer to the next command 847 * We use the host_scribble field as a pointer to the next command
934 * in a queue 848 * in a queue
935 */ 849 */
936 850
937 SET_NEXT(cmd, NULL); 851 SET_NEXT(cmd, NULL);
938 cmd->scsi_done = done;
939
940 cmd->result = 0; 852 cmd->result = 0;
941 853
942 /* 854 /*
@@ -946,7 +858,6 @@ static int NCR5380_queue_command_lck(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
946 * sense data is only guaranteed to be valid while the condition exists. 858 * sense data is only guaranteed to be valid while the condition exists.
947 */ 859 */
948 860
949 local_irq_save(flags);
950 /* ++guenther: now that the issue queue is being set up, we can lock ST-DMA. 861 /* ++guenther: now that the issue queue is being set up, we can lock ST-DMA.
951 * Otherwise a running NCR5380_main may steal the lock. 862 * Otherwise a running NCR5380_main may steal the lock.
952 * Lock before actually inserting due to fairness reasons explained in 863 * Lock before actually inserting due to fairness reasons explained in
@@ -959,17 +870,24 @@ static int NCR5380_queue_command_lck(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
959 * because also a timer int can trigger an abort or reset, which would 870 * because also a timer int can trigger an abort or reset, which would
960 * alter queues and touch the lock. 871 * alter queues and touch the lock.
961 */ 872 */
962 if (!IS_A_TT()) { 873 if (!NCR5380_acquire_dma_irq(instance))
963 /* perhaps stop command timer here */ 874 return SCSI_MLQUEUE_HOST_BUSY;
964 falcon_get_lock(); 875
965 /* perhaps restart command timer here */ 876 local_irq_save(flags);
966 } 877
878 /*
879 * Insert the cmd into the issue queue. Note that REQUEST SENSE
880 * commands are added to the head of the queue since any command will
881 * clear the contingent allegiance condition that exists and the
882 * sense data is only guaranteed to be valid while the condition exists.
883 */
884
967 if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) { 885 if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) {
968 LIST(cmd, hostdata->issue_queue); 886 LIST(cmd, hostdata->issue_queue);
969 SET_NEXT(cmd, hostdata->issue_queue); 887 SET_NEXT(cmd, hostdata->issue_queue);
970 hostdata->issue_queue = cmd; 888 hostdata->issue_queue = cmd;
971 } else { 889 } else {
972 for (tmp = (Scsi_Cmnd *)hostdata->issue_queue; 890 for (tmp = (struct scsi_cmnd *)hostdata->issue_queue;
973 NEXT(tmp); tmp = NEXT(tmp)) 891 NEXT(tmp); tmp = NEXT(tmp))
974 ; 892 ;
975 LIST(cmd, tmp); 893 LIST(cmd, tmp);
@@ -987,32 +905,42 @@ static int NCR5380_queue_command_lck(Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
987 * If we're not in an interrupt, we can call NCR5380_main() 905 * If we're not in an interrupt, we can call NCR5380_main()
988 * unconditionally, because it cannot be already running. 906 * unconditionally, because it cannot be already running.
989 */ 907 */
990 if (in_interrupt() || ((flags >> 8) & 7) >= 6) 908 if (in_interrupt() || irqs_disabled())
991 queue_main(); 909 queue_main(hostdata);
992 else 910 else
993 NCR5380_main(NULL); 911 NCR5380_main(&hostdata->main_task);
994 return 0; 912 return 0;
995} 913}
996 914
997static DEF_SCSI_QCMD(NCR5380_queue_command) 915static inline void maybe_release_dma_irq(struct Scsi_Host *instance)
916{
917 struct NCR5380_hostdata *hostdata = shost_priv(instance);
918
919 /* Caller does the locking needed to set & test these data atomically */
920 if (!hostdata->disconnected_queue &&
921 !hostdata->issue_queue &&
922 !hostdata->connected &&
923 !hostdata->retain_dma_intr)
924 NCR5380_release_dma_irq(instance);
925}
998 926
999/* 927/**
1000 * Function : NCR5380_main (void) 928 * NCR5380_main - NCR state machines
1001 * 929 *
1002 * Purpose : NCR5380_main is a coroutine that runs as long as more work can 930 * NCR5380_main is a coroutine that runs as long as more work can
1003 * be done on the NCR5380 host adapters in a system. Both 931 * be done on the NCR5380 host adapters in a system. Both
1004 * NCR5380_queue_command() and NCR5380_intr() will try to start it 932 * NCR5380_queue_command() and NCR5380_intr() will try to start it
1005 * in case it is not running. 933 * in case it is not running.
1006 * 934 *
1007 * NOTE : NCR5380_main exits with interrupts *disabled*, the caller should 935 * Locks: called as its own thread with no locks held.
1008 * reenable them. This prevents reentrancy and kernel stack overflow.
1009 */ 936 */
1010 937
1011static void NCR5380_main(struct work_struct *work) 938static void NCR5380_main(struct work_struct *work)
1012{ 939{
1013 Scsi_Cmnd *tmp, *prev; 940 struct NCR5380_hostdata *hostdata =
1014 struct Scsi_Host *instance = first_instance; 941 container_of(work, struct NCR5380_hostdata, main_task);
1015 struct NCR5380_hostdata *hostdata = HOSTDATA(instance); 942 struct Scsi_Host *instance = hostdata->host;
943 struct scsi_cmnd *tmp, *prev;
1016 int done; 944 int done;
1017 unsigned long flags; 945 unsigned long flags;
1018 946
@@ -1037,9 +965,9 @@ static void NCR5380_main(struct work_struct *work)
1037 'main_running' is set here, and queues/executes main via the 965 'main_running' is set here, and queues/executes main via the
1038 task queue, it doesn't do any harm, just this instance of main 966 task queue, it doesn't do any harm, just this instance of main
1039 won't find any work left to do. */ 967 won't find any work left to do. */
1040 if (main_running) 968 if (hostdata->main_running)
1041 return; 969 return;
1042 main_running = 1; 970 hostdata->main_running = 1;
1043 971
1044 local_save_flags(flags); 972 local_save_flags(flags);
1045 do { 973 do {
@@ -1053,7 +981,7 @@ static void NCR5380_main(struct work_struct *work)
1053 * for a target that's not busy. 981 * for a target that's not busy.
1054 */ 982 */
1055#if (NDEBUG & NDEBUG_LISTS) 983#if (NDEBUG & NDEBUG_LISTS)
1056 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue, prev = NULL; 984 for (tmp = (struct scsi_cmnd *) hostdata->issue_queue, prev = NULL;
1057 tmp && (tmp != prev); prev = tmp, tmp = NEXT(tmp)) 985 tmp && (tmp != prev); prev = tmp, tmp = NEXT(tmp))
1058 ; 986 ;
1059 /*printk("%p ", tmp);*/ 987 /*printk("%p ", tmp);*/
@@ -1061,16 +989,14 @@ static void NCR5380_main(struct work_struct *work)
1061 printk(" LOOP\n"); 989 printk(" LOOP\n");
1062 /* else printk("\n"); */ 990 /* else printk("\n"); */
1063#endif 991#endif
1064 for (tmp = (Scsi_Cmnd *) hostdata->issue_queue, 992 for (tmp = (struct scsi_cmnd *) hostdata->issue_queue,
1065 prev = NULL; tmp; prev = tmp, tmp = NEXT(tmp)) { 993 prev = NULL; tmp; prev = tmp, tmp = NEXT(tmp)) {
1066 u8 lun = tmp->device->lun; 994 u8 lun = tmp->device->lun;
1067 995
1068#if (NDEBUG & NDEBUG_LISTS) 996 dprintk(NDEBUG_LISTS,
1069 if (prev != tmp) 997 "MAIN tmp=%p target=%d busy=%d lun=%d\n",
1070 printk("MAIN tmp=%p target=%d busy=%d lun=%llu\n", 998 tmp, scmd_id(tmp), hostdata->busy[scmd_id(tmp)],
1071 tmp, tmp->device->id, hostdata->busy[tmp->device->id], 999 lun);
1072 lun);
1073#endif
1074 /* When we find one, remove it from the issue queue. */ 1000 /* When we find one, remove it from the issue queue. */
1075 /* ++guenther: possible race with Falcon locking */ 1001 /* ++guenther: possible race with Falcon locking */
1076 if ( 1002 if (
@@ -1090,7 +1016,7 @@ static void NCR5380_main(struct work_struct *work)
1090 hostdata->issue_queue = NEXT(tmp); 1016 hostdata->issue_queue = NEXT(tmp);
1091 } 1017 }
1092 SET_NEXT(tmp, NULL); 1018 SET_NEXT(tmp, NULL);
1093 falcon_dont_release++; 1019 hostdata->retain_dma_intr++;
1094 1020
1095 /* reenable interrupts after finding one */ 1021 /* reenable interrupts after finding one */
1096 local_irq_restore(flags); 1022 local_irq_restore(flags);
@@ -1117,12 +1043,12 @@ static void NCR5380_main(struct work_struct *work)
1117#ifdef SUPPORT_TAGS 1043#ifdef SUPPORT_TAGS
1118 cmd_get_tag(tmp, tmp->cmnd[0] != REQUEST_SENSE); 1044 cmd_get_tag(tmp, tmp->cmnd[0] != REQUEST_SENSE);
1119#endif 1045#endif
1120 if (!NCR5380_select(instance, tmp, 1046 if (!NCR5380_select(instance, tmp)) {
1121 (tmp->cmnd[0] == REQUEST_SENSE) ? TAG_NONE : 1047 local_irq_disable();
1122 TAG_NEXT)) { 1048 hostdata->retain_dma_intr--;
1123 falcon_dont_release--;
1124 /* release if target did not response! */ 1049 /* release if target did not response! */
1125 falcon_release_lock_if_possible(hostdata); 1050 maybe_release_dma_irq(instance);
1051 local_irq_restore(flags);
1126 break; 1052 break;
1127 } else { 1053 } else {
1128 local_irq_disable(); 1054 local_irq_disable();
@@ -1132,7 +1058,7 @@ static void NCR5380_main(struct work_struct *work)
1132#ifdef SUPPORT_TAGS 1058#ifdef SUPPORT_TAGS
1133 cmd_free_tag(tmp); 1059 cmd_free_tag(tmp);
1134#endif 1060#endif
1135 falcon_dont_release--; 1061 hostdata->retain_dma_intr--;
1136 local_irq_restore(flags); 1062 local_irq_restore(flags);
1137 dprintk(NDEBUG_MAIN, "scsi%d: main(): select() failed, " 1063 dprintk(NDEBUG_MAIN, "scsi%d: main(): select() failed, "
1138 "returned to issue_queue\n", HOSTNO); 1064 "returned to issue_queue\n", HOSTNO);
@@ -1160,7 +1086,7 @@ static void NCR5380_main(struct work_struct *work)
1160 /* Better allow ints _after_ 'main_running' has been cleared, else 1086 /* Better allow ints _after_ 'main_running' has been cleared, else
1161 an interrupt could believe we'll pick up the work it left for 1087 an interrupt could believe we'll pick up the work it left for
1162 us, but we won't see it anymore here... */ 1088 us, but we won't see it anymore here... */
1163 main_running = 0; 1089 hostdata->main_running = 0;
1164 local_irq_restore(flags); 1090 local_irq_restore(flags);
1165} 1091}
1166 1092
@@ -1179,9 +1105,11 @@ static void NCR5380_main(struct work_struct *work)
1179static void NCR5380_dma_complete(struct Scsi_Host *instance) 1105static void NCR5380_dma_complete(struct Scsi_Host *instance)
1180{ 1106{
1181 SETUP_HOSTDATA(instance); 1107 SETUP_HOSTDATA(instance);
1182 int transfered, saved_data = 0, overrun = 0, cnt, toPIO; 1108 int transferred;
1183 unsigned char **data, p; 1109 unsigned char **data;
1184 volatile int *count; 1110 volatile int *count;
1111 int saved_data = 0, overrun = 0;
1112 unsigned char p;
1185 1113
1186 if (!hostdata->connected) { 1114 if (!hostdata->connected) {
1187 printk(KERN_WARNING "scsi%d: received end of DMA interrupt with " 1115 printk(KERN_WARNING "scsi%d: received end of DMA interrupt with "
@@ -1189,7 +1117,7 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance)
1189 return; 1117 return;
1190 } 1118 }
1191 1119
1192 if (atari_read_overruns) { 1120 if (hostdata->read_overruns) {
1193 p = hostdata->connected->SCp.phase; 1121 p = hostdata->connected->SCp.phase;
1194 if (p & SR_IO) { 1122 if (p & SR_IO) {
1195 udelay(10); 1123 udelay(10);
@@ -1207,21 +1135,41 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance)
1207 HOSTNO, NCR5380_read(BUS_AND_STATUS_REG), 1135 HOSTNO, NCR5380_read(BUS_AND_STATUS_REG),
1208 NCR5380_read(STATUS_REG)); 1136 NCR5380_read(STATUS_REG));
1209 1137
1138#if defined(CONFIG_SUN3)
1139 if ((sun3scsi_dma_finish(rq_data_dir(hostdata->connected->request)))) {
1140 pr_err("scsi%d: overrun in UDC counter -- not prepared to deal with this!\n",
1141 instance->host_no);
1142 BUG();
1143 }
1144
1145 /* make sure we're not stuck in a data phase */
1146 if ((NCR5380_read(BUS_AND_STATUS_REG) & (BASR_PHASE_MATCH | BASR_ACK)) ==
1147 (BASR_PHASE_MATCH | BASR_ACK)) {
1148 pr_err("scsi%d: BASR %02x\n", instance->host_no,
1149 NCR5380_read(BUS_AND_STATUS_REG));
1150 pr_err("scsi%d: bus stuck in data phase -- probably a single byte overrun!\n",
1151 instance->host_no);
1152 BUG();
1153 }
1154#endif
1155
1210 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1156 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1211 NCR5380_write(MODE_REG, MR_BASE); 1157 NCR5380_write(MODE_REG, MR_BASE);
1212 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 1158 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1213 1159
1214 transfered = hostdata->dma_len - NCR5380_dma_residual(instance); 1160 transferred = hostdata->dma_len - NCR5380_dma_residual(instance);
1215 hostdata->dma_len = 0; 1161 hostdata->dma_len = 0;
1216 1162
1217 data = (unsigned char **)&hostdata->connected->SCp.ptr; 1163 data = (unsigned char **)&hostdata->connected->SCp.ptr;
1218 count = &hostdata->connected->SCp.this_residual; 1164 count = &hostdata->connected->SCp.this_residual;
1219 *data += transfered; 1165 *data += transferred;
1220 *count -= transfered; 1166 *count -= transferred;
1167
1168 if (hostdata->read_overruns) {
1169 int cnt, toPIO;
1221 1170
1222 if (atari_read_overruns) {
1223 if ((NCR5380_read(STATUS_REG) & PHASE_MASK) == p && (p & SR_IO)) { 1171 if ((NCR5380_read(STATUS_REG) & PHASE_MASK) == p && (p & SR_IO)) {
1224 cnt = toPIO = atari_read_overruns; 1172 cnt = toPIO = hostdata->read_overruns;
1225 if (overrun) { 1173 if (overrun) {
1226 dprintk(NDEBUG_DMA, "Got an input overrun, using saved byte\n"); 1174 dprintk(NDEBUG_DMA, "Got an input overrun, using saved byte\n");
1227 *(*data)++ = saved_data; 1175 *(*data)++ = saved_data;
@@ -1238,20 +1186,19 @@ static void NCR5380_dma_complete(struct Scsi_Host *instance)
1238#endif /* REAL_DMA */ 1186#endif /* REAL_DMA */
1239 1187
1240 1188
1241/* 1189/**
1242 * Function : void NCR5380_intr (int irq) 1190 * NCR5380_intr - generic NCR5380 irq handler
1243 * 1191 * @irq: interrupt number
1244 * Purpose : handle interrupts, reestablishing I_T_L or I_T_L_Q nexuses 1192 * @dev_id: device info
1245 * from the disconnected queue, and restarting NCR5380_main()
1246 * as required.
1247 *
1248 * Inputs : int irq, irq that caused this interrupt.
1249 * 1193 *
1194 * Handle interrupts, reestablishing I_T_L or I_T_L_Q nexuses
1195 * from the disconnected queue, and restarting NCR5380_main()
1196 * as required.
1250 */ 1197 */
1251 1198
1252static irqreturn_t NCR5380_intr(int irq, void *dev_id) 1199static irqreturn_t NCR5380_intr(int irq, void *dev_id)
1253{ 1200{
1254 struct Scsi_Host *instance = first_instance; 1201 struct Scsi_Host *instance = dev_id;
1255 int done = 1, handled = 0; 1202 int done = 1, handled = 0;
1256 unsigned char basr; 1203 unsigned char basr;
1257 1204
@@ -1265,7 +1212,6 @@ static irqreturn_t NCR5380_intr(int irq, void *dev_id)
1265 NCR5380_dprint(NDEBUG_INTR, instance); 1212 NCR5380_dprint(NDEBUG_INTR, instance);
1266 if ((NCR5380_read(STATUS_REG) & (SR_SEL|SR_IO)) == (SR_SEL|SR_IO)) { 1213 if ((NCR5380_read(STATUS_REG) & (SR_SEL|SR_IO)) == (SR_SEL|SR_IO)) {
1267 done = 0; 1214 done = 0;
1268 ENABLE_IRQ();
1269 dprintk(NDEBUG_INTR, "scsi%d: SEL interrupt\n", HOSTNO); 1215 dprintk(NDEBUG_INTR, "scsi%d: SEL interrupt\n", HOSTNO);
1270 NCR5380_reselect(instance); 1216 NCR5380_reselect(instance);
1271 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1217 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
@@ -1295,17 +1241,19 @@ static irqreturn_t NCR5380_intr(int irq, void *dev_id)
1295 dprintk(NDEBUG_INTR, "scsi%d: PHASE MISM or EOP interrupt\n", HOSTNO); 1241 dprintk(NDEBUG_INTR, "scsi%d: PHASE MISM or EOP interrupt\n", HOSTNO);
1296 NCR5380_dma_complete( instance ); 1242 NCR5380_dma_complete( instance );
1297 done = 0; 1243 done = 0;
1298 ENABLE_IRQ();
1299 } else 1244 } else
1300#endif /* REAL_DMA */ 1245#endif /* REAL_DMA */
1301 { 1246 {
1302/* MS: Ignore unknown phase mismatch interrupts (caused by EOP interrupt) */ 1247/* MS: Ignore unknown phase mismatch interrupts (caused by EOP interrupt) */
1303 if (basr & BASR_PHASE_MATCH) 1248 if (basr & BASR_PHASE_MATCH)
1304 printk(KERN_NOTICE "scsi%d: unknown interrupt, " 1249 dprintk(NDEBUG_INTR, "scsi%d: unknown interrupt, "
1305 "BASR 0x%x, MR 0x%x, SR 0x%x\n", 1250 "BASR 0x%x, MR 0x%x, SR 0x%x\n",
1306 HOSTNO, basr, NCR5380_read(MODE_REG), 1251 HOSTNO, basr, NCR5380_read(MODE_REG),
1307 NCR5380_read(STATUS_REG)); 1252 NCR5380_read(STATUS_REG));
1308 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1253 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1254#ifdef SUN3_SCSI_VME
1255 dregs->csr |= CSR_DMA_ENABLE;
1256#endif
1309 } 1257 }
1310 } /* if !(SELECTION || PARITY) */ 1258 } /* if !(SELECTION || PARITY) */
1311 handled = 1; 1259 handled = 1;
@@ -1314,53 +1262,29 @@ static irqreturn_t NCR5380_intr(int irq, void *dev_id)
1314 "BASR 0x%X, MR 0x%X, SR 0x%x\n", HOSTNO, basr, 1262 "BASR 0x%X, MR 0x%X, SR 0x%x\n", HOSTNO, basr,
1315 NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG)); 1263 NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG));
1316 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG); 1264 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1265#ifdef SUN3_SCSI_VME
1266 dregs->csr |= CSR_DMA_ENABLE;
1267#endif
1317 } 1268 }
1318 1269
1319 if (!done) { 1270 if (!done) {
1320 dprintk(NDEBUG_INTR, "scsi%d: in int routine, calling main\n", HOSTNO); 1271 dprintk(NDEBUG_INTR, "scsi%d: in int routine, calling main\n", HOSTNO);
1321 /* Put a call to NCR5380_main() on the queue... */ 1272 /* Put a call to NCR5380_main() on the queue... */
1322 queue_main(); 1273 queue_main(shost_priv(instance));
1323 } 1274 }
1324 return IRQ_RETVAL(handled); 1275 return IRQ_RETVAL(handled);
1325} 1276}
1326 1277
1327#ifdef NCR5380_STATS
1328static void collect_stats(struct NCR5380_hostdata* hostdata, Scsi_Cmnd *cmd)
1329{
1330# ifdef NCR5380_STAT_LIMIT
1331 if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
1332# endif
1333 switch (cmd->cmnd[0]) {
1334 case WRITE:
1335 case WRITE_6:
1336 case WRITE_10:
1337 hostdata->time_write[cmd->device->id] += (jiffies - hostdata->timebase);
1338 /*hostdata->bytes_write[cmd->device->id] += scsi_bufflen(cmd);*/
1339 hostdata->pendingw--;
1340 break;
1341 case READ:
1342 case READ_6:
1343 case READ_10:
1344 hostdata->time_read[cmd->device->id] += (jiffies - hostdata->timebase);
1345 /*hostdata->bytes_read[cmd->device->id] += scsi_bufflen(cmd);*/
1346 hostdata->pendingr--;
1347 break;
1348 }
1349}
1350#endif
1351
1352/* 1278/*
1353 * Function : int NCR5380_select (struct Scsi_Host *instance, Scsi_Cmnd *cmd, 1279 * Function : int NCR5380_select(struct Scsi_Host *instance,
1354 * int tag); 1280 * struct scsi_cmnd *cmd)
1355 * 1281 *
1356 * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command, 1282 * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command,
1357 * including ARBITRATION, SELECTION, and initial message out for 1283 * including ARBITRATION, SELECTION, and initial message out for
1358 * IDENTIFY and queue messages. 1284 * IDENTIFY and queue messages.
1359 * 1285 *
1360 * Inputs : instance - instantiation of the 5380 driver on which this 1286 * Inputs : instance - instantiation of the 5380 driver on which this
1361 * target lives, cmd - SCSI command to execute, tag - set to TAG_NEXT for 1287 * target lives, cmd - SCSI command to execute.
1362 * new tag, TAG_NONE for untagged queueing, otherwise set to the tag for
1363 * the command that is presently connected.
1364 * 1288 *
1365 * Returns : -1 if selection could not execute for some reason, 1289 * Returns : -1 if selection could not execute for some reason,
1366 * 0 if selection succeeded or failed because the target 1290 * 0 if selection succeeded or failed because the target
@@ -1380,7 +1304,7 @@ static void collect_stats(struct NCR5380_hostdata* hostdata, Scsi_Cmnd *cmd)
1380 * cmd->result host byte set to DID_BAD_TARGET. 1304 * cmd->result host byte set to DID_BAD_TARGET.
1381 */ 1305 */
1382 1306
1383static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag) 1307static int NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd)
1384{ 1308{
1385 SETUP_HOSTDATA(instance); 1309 SETUP_HOSTDATA(instance);
1386 unsigned char tmp[3], phase; 1310 unsigned char tmp[3], phase;
@@ -1562,7 +1486,7 @@ static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
1562 * selection. 1486 * selection.
1563 */ 1487 */
1564 1488
1565 timeout = jiffies + 25; 1489 timeout = jiffies + (250 * HZ / 1000);
1566 1490
1567 /* 1491 /*
1568 * XXX very interesting - we're seeing a bounce where the BSY we 1492 * XXX very interesting - we're seeing a bounce where the BSY we
@@ -1616,9 +1540,6 @@ static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
1616 return -1; 1540 return -1;
1617 } 1541 }
1618 cmd->result = DID_BAD_TARGET << 16; 1542 cmd->result = DID_BAD_TARGET << 16;
1619#ifdef NCR5380_STATS
1620 collect_stats(hostdata, cmd);
1621#endif
1622#ifdef SUPPORT_TAGS 1543#ifdef SUPPORT_TAGS
1623 cmd_free_tag(cmd); 1544 cmd_free_tag(cmd);
1624#endif 1545#endif
@@ -1676,6 +1597,9 @@ static int NCR5380_select(struct Scsi_Host *instance, Scsi_Cmnd *cmd, int tag)
1676#ifndef SUPPORT_TAGS 1597#ifndef SUPPORT_TAGS
1677 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun); 1598 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
1678#endif 1599#endif
1600#ifdef SUN3_SCSI_VME
1601 dregs->csr |= CSR_INTR;
1602#endif
1679 1603
1680 initialize_SCp(cmd); 1604 initialize_SCp(cmd);
1681 1605
@@ -1826,7 +1750,7 @@ static int NCR5380_transfer_pio(struct Scsi_Host *instance,
1826 * Returns : 0 on success, -1 on failure. 1750 * Returns : 0 on success, -1 on failure.
1827 */ 1751 */
1828 1752
1829static int do_abort(struct Scsi_Host *host) 1753static int do_abort(struct Scsi_Host *instance)
1830{ 1754{
1831 unsigned char tmp, *msgptr, phase; 1755 unsigned char tmp, *msgptr, phase;
1832 int len; 1756 int len;
@@ -1861,7 +1785,7 @@ static int do_abort(struct Scsi_Host *host)
1861 msgptr = &tmp; 1785 msgptr = &tmp;
1862 len = 1; 1786 len = 1;
1863 phase = PHASE_MSGOUT; 1787 phase = PHASE_MSGOUT;
1864 NCR5380_transfer_pio(host, &phase, &len, &msgptr); 1788 NCR5380_transfer_pio(instance, &phase, &len, &msgptr);
1865 1789
1866 /* 1790 /*
1867 * If we got here, and the command completed successfully, 1791 * If we got here, and the command completed successfully,
@@ -1899,17 +1823,62 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
1899 SETUP_HOSTDATA(instance); 1823 SETUP_HOSTDATA(instance);
1900 register int c = *count; 1824 register int c = *count;
1901 register unsigned char p = *phase; 1825 register unsigned char p = *phase;
1826 unsigned long flags;
1827
1828#if defined(CONFIG_SUN3)
1829 /* sanity check */
1830 if (!sun3_dma_setup_done) {
1831 pr_err("scsi%d: transfer_dma without setup!\n",
1832 instance->host_no);
1833 BUG();
1834 }
1835 hostdata->dma_len = c;
1836
1837 dprintk(NDEBUG_DMA, "scsi%d: initializing DMA for %s, %d bytes %s %p\n",
1838 instance->host_no, (p & SR_IO) ? "reading" : "writing",
1839 c, (p & SR_IO) ? "to" : "from", *data);
1840
1841 /* netbsd turns off ints here, why not be safe and do it too */
1842 local_irq_save(flags);
1843
1844 /* send start chain */
1845 sun3scsi_dma_start(c, *data);
1846
1847 if (p & SR_IO) {
1848 NCR5380_write(TARGET_COMMAND_REG, 1);
1849 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1850 NCR5380_write(INITIATOR_COMMAND_REG, 0);
1851 NCR5380_write(MODE_REG,
1852 (NCR5380_read(MODE_REG) | MR_DMA_MODE | MR_ENABLE_EOP_INTR));
1853 NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0);
1854 } else {
1855 NCR5380_write(TARGET_COMMAND_REG, 0);
1856 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1857 NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_DATA);
1858 NCR5380_write(MODE_REG,
1859 (NCR5380_read(MODE_REG) | MR_DMA_MODE | MR_ENABLE_EOP_INTR));
1860 NCR5380_write(START_DMA_SEND_REG, 0);
1861 }
1862
1863#ifdef SUN3_SCSI_VME
1864 dregs->csr |= CSR_DMA_ENABLE;
1865#endif
1866
1867 local_irq_restore(flags);
1868
1869 sun3_dma_active = 1;
1870
1871#else /* !defined(CONFIG_SUN3) */
1902 register unsigned char *d = *data; 1872 register unsigned char *d = *data;
1903 unsigned char tmp; 1873 unsigned char tmp;
1904 unsigned long flags;
1905 1874
1906 if ((tmp = (NCR5380_read(STATUS_REG) & PHASE_MASK)) != p) { 1875 if ((tmp = (NCR5380_read(STATUS_REG) & PHASE_MASK)) != p) {
1907 *phase = tmp; 1876 *phase = tmp;
1908 return -1; 1877 return -1;
1909 } 1878 }
1910 1879
1911 if (atari_read_overruns && (p & SR_IO)) 1880 if (hostdata->read_overruns && (p & SR_IO))
1912 c -= atari_read_overruns; 1881 c -= hostdata->read_overruns;
1913 1882
1914 dprintk(NDEBUG_DMA, "scsi%d: initializing DMA for %s, %d bytes %s %p\n", 1883 dprintk(NDEBUG_DMA, "scsi%d: initializing DMA for %s, %d bytes %s %p\n",
1915 HOSTNO, (p & SR_IO) ? "reading" : "writing", 1884 HOSTNO, (p & SR_IO) ? "reading" : "writing",
@@ -1921,7 +1890,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
1921 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_ENABLE_EOP_INTR | MR_MONITOR_BSY); 1890 NCR5380_write(MODE_REG, MR_BASE | MR_DMA_MODE | MR_ENABLE_EOP_INTR | MR_MONITOR_BSY);
1922#endif /* def REAL_DMA */ 1891#endif /* def REAL_DMA */
1923 1892
1924 if (IS_A_TT()) { 1893 if (!(hostdata->flags & FLAG_LATE_DMA_SETUP)) {
1925 /* On the Medusa, it is a must to initialize the DMA before 1894 /* On the Medusa, it is a must to initialize the DMA before
1926 * starting the NCR. This is also the cleaner way for the TT. 1895 * starting the NCR. This is also the cleaner way for the TT.
1927 */ 1896 */
@@ -1939,7 +1908,7 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
1939 NCR5380_write(START_DMA_SEND_REG, 0); 1908 NCR5380_write(START_DMA_SEND_REG, 0);
1940 } 1909 }
1941 1910
1942 if (!IS_A_TT()) { 1911 if (hostdata->flags & FLAG_LATE_DMA_SETUP) {
1943 /* On the Falcon, the DMA setup must be done after the last */ 1912 /* On the Falcon, the DMA setup must be done after the last */
1944 /* NCR access, else the DMA setup gets trashed! 1913 /* NCR access, else the DMA setup gets trashed!
1945 */ 1914 */
@@ -1949,6 +1918,8 @@ static int NCR5380_transfer_dma(struct Scsi_Host *instance,
1949 NCR5380_dma_write_setup(instance, d, c); 1918 NCR5380_dma_write_setup(instance, d, c);
1950 local_irq_restore(flags); 1919 local_irq_restore(flags);
1951 } 1920 }
1921#endif /* !defined(CONFIG_SUN3) */
1922
1952 return 0; 1923 return 0;
1953} 1924}
1954#endif /* defined(REAL_DMA) */ 1925#endif /* defined(REAL_DMA) */
@@ -1982,7 +1953,11 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
1982#endif 1953#endif
1983 unsigned char *data; 1954 unsigned char *data;
1984 unsigned char phase, tmp, extended_msg[10], old_phase = 0xff; 1955 unsigned char phase, tmp, extended_msg[10], old_phase = 0xff;
1985 Scsi_Cmnd *cmd = (Scsi_Cmnd *) hostdata->connected; 1956 struct scsi_cmnd *cmd = (struct scsi_cmnd *) hostdata->connected;
1957
1958#ifdef SUN3_SCSI_VME
1959 dregs->csr |= CSR_INTR;
1960#endif
1986 1961
1987 while (1) { 1962 while (1) {
1988 tmp = NCR5380_read(STATUS_REG); 1963 tmp = NCR5380_read(STATUS_REG);
@@ -1993,6 +1968,33 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
1993 old_phase = phase; 1968 old_phase = phase;
1994 NCR5380_dprint_phase(NDEBUG_INFORMATION, instance); 1969 NCR5380_dprint_phase(NDEBUG_INFORMATION, instance);
1995 } 1970 }
1971#if defined(CONFIG_SUN3)
1972 if (phase == PHASE_CMDOUT) {
1973#if defined(REAL_DMA)
1974 void *d;
1975 unsigned long count;
1976
1977 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1978 count = cmd->SCp.buffer->length;
1979 d = sg_virt(cmd->SCp.buffer);
1980 } else {
1981 count = cmd->SCp.this_residual;
1982 d = cmd->SCp.ptr;
1983 }
1984 /* this command setup for dma yet? */
1985 if ((count >= DMA_MIN_SIZE) && (sun3_dma_setup_done != cmd)) {
1986 if (cmd->request->cmd_type == REQ_TYPE_FS) {
1987 sun3scsi_dma_setup(d, count,
1988 rq_data_dir(cmd->request));
1989 sun3_dma_setup_done = cmd;
1990 }
1991 }
1992#endif
1993#ifdef SUN3_SCSI_VME
1994 dregs->csr |= CSR_INTR;
1995#endif
1996 }
1997#endif /* CONFIG_SUN3 */
1996 1998
1997 if (sink && (phase != PHASE_MSGOUT)) { 1999 if (sink && (phase != PHASE_MSGOUT)) {
1998 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp)); 2000 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
@@ -2054,8 +2056,11 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2054 */ 2056 */
2055 2057
2056#if defined(REAL_DMA) 2058#if defined(REAL_DMA)
2057 if (!cmd->device->borken && 2059 if (
2058 (transfersize = NCR5380_dma_xfer_len(instance,cmd,phase)) > 31) { 2060#if !defined(CONFIG_SUN3)
2061 !cmd->device->borken &&
2062#endif
2063 (transfersize = NCR5380_dma_xfer_len(instance, cmd, phase)) >= DMA_MIN_SIZE) {
2059 len = transfersize; 2064 len = transfersize;
2060 cmd->SCp.phase = phase; 2065 cmd->SCp.phase = phase;
2061 if (NCR5380_transfer_dma(instance, &phase, 2066 if (NCR5380_transfer_dma(instance, &phase,
@@ -2064,9 +2069,8 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2064 * If the watchdog timer fires, all future 2069 * If the watchdog timer fires, all future
2065 * accesses to this device will use the 2070 * accesses to this device will use the
2066 * polled-IO. */ 2071 * polled-IO. */
2067 printk(KERN_NOTICE "scsi%d: switching target %d " 2072 scmd_printk(KERN_INFO, cmd,
2068 "lun %llu to slow handshake\n", HOSTNO, 2073 "switching to slow handshake\n");
2069 cmd->device->id, cmd->device->lun);
2070 cmd->device->borken = 1; 2074 cmd->device->borken = 1;
2071 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | 2075 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2072 ICR_ASSERT_ATN); 2076 ICR_ASSERT_ATN);
@@ -2092,6 +2096,11 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2092 NCR5380_transfer_pio(instance, &phase, 2096 NCR5380_transfer_pio(instance, &phase,
2093 (int *)&cmd->SCp.this_residual, 2097 (int *)&cmd->SCp.this_residual,
2094 (unsigned char **)&cmd->SCp.ptr); 2098 (unsigned char **)&cmd->SCp.ptr);
2099#if defined(CONFIG_SUN3) && defined(REAL_DMA)
2100 /* if we had intended to dma that command clear it */
2101 if (sun3_dma_setup_done == cmd)
2102 sun3_dma_setup_done = NULL;
2103#endif
2095 break; 2104 break;
2096 case PHASE_MSGIN: 2105 case PHASE_MSGIN:
2097 len = 1; 2106 len = 1;
@@ -2145,9 +2154,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2145 dprintk(NDEBUG_LINKED, "scsi%d: target %d lun %llu linked request " 2154 dprintk(NDEBUG_LINKED, "scsi%d: target %d lun %llu linked request "
2146 "done, calling scsi_done().\n", 2155 "done, calling scsi_done().\n",
2147 HOSTNO, cmd->device->id, cmd->device->lun); 2156 HOSTNO, cmd->device->id, cmd->device->lun);
2148#ifdef NCR5380_STATS
2149 collect_stats(hostdata, cmd);
2150#endif
2151 cmd->scsi_done(cmd); 2157 cmd->scsi_done(cmd);
2152 cmd = hostdata->connected; 2158 cmd = hostdata->connected;
2153 break; 2159 break;
@@ -2156,11 +2162,12 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2156 case COMMAND_COMPLETE: 2162 case COMMAND_COMPLETE:
2157 /* Accept message by clearing ACK */ 2163 /* Accept message by clearing ACK */
2158 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2164 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2159 /* ++guenther: possible race with Falcon locking */
2160 falcon_dont_release++;
2161 hostdata->connected = NULL;
2162 dprintk(NDEBUG_QUEUES, "scsi%d: command for target %d, lun %llu " 2165 dprintk(NDEBUG_QUEUES, "scsi%d: command for target %d, lun %llu "
2163 "completed\n", HOSTNO, cmd->device->id, cmd->device->lun); 2166 "completed\n", HOSTNO, cmd->device->id, cmd->device->lun);
2167
2168 local_irq_save(flags);
2169 hostdata->retain_dma_intr++;
2170 hostdata->connected = NULL;
2164#ifdef SUPPORT_TAGS 2171#ifdef SUPPORT_TAGS
2165 cmd_free_tag(cmd); 2172 cmd_free_tag(cmd);
2166 if (status_byte(cmd->SCp.Status) == QUEUE_FULL) { 2173 if (status_byte(cmd->SCp.Status) == QUEUE_FULL) {
@@ -2172,7 +2179,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2172 */ 2179 */
2173 /* ++Andreas: the mid level code knows about 2180 /* ++Andreas: the mid level code knows about
2174 QUEUE_FULL now. */ 2181 QUEUE_FULL now. */
2175 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun]; 2182 struct tag_alloc *ta = &hostdata->TagAlloc[scmd_id(cmd)][cmd->device->lun];
2176 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %llu returned " 2183 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %llu returned "
2177 "QUEUE_FULL after %d commands\n", 2184 "QUEUE_FULL after %d commands\n",
2178 HOSTNO, cmd->device->id, cmd->device->lun, 2185 HOSTNO, cmd->device->id, cmd->device->lun,
@@ -2207,7 +2214,6 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2207 else if (status_byte(cmd->SCp.Status) != GOOD) 2214 else if (status_byte(cmd->SCp.Status) != GOOD)
2208 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16); 2215 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
2209 2216
2210#ifdef AUTOSENSE
2211 if ((cmd->cmnd[0] == REQUEST_SENSE) && 2217 if ((cmd->cmnd[0] == REQUEST_SENSE) &&
2212 hostdata->ses.cmd_len) { 2218 hostdata->ses.cmd_len) {
2213 scsi_eh_restore_cmnd(cmd, &hostdata->ses); 2219 scsi_eh_restore_cmnd(cmd, &hostdata->ses);
@@ -2220,22 +2226,17 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2220 2226
2221 dprintk(NDEBUG_AUTOSENSE, "scsi%d: performing request sense\n", HOSTNO); 2227 dprintk(NDEBUG_AUTOSENSE, "scsi%d: performing request sense\n", HOSTNO);
2222 2228
2223 local_irq_save(flags);
2224 LIST(cmd,hostdata->issue_queue); 2229 LIST(cmd,hostdata->issue_queue);
2225 SET_NEXT(cmd, hostdata->issue_queue); 2230 SET_NEXT(cmd, hostdata->issue_queue);
2226 hostdata->issue_queue = (Scsi_Cmnd *) cmd; 2231 hostdata->issue_queue = (struct scsi_cmnd *) cmd;
2227 local_irq_restore(flags);
2228 dprintk(NDEBUG_QUEUES, "scsi%d: REQUEST SENSE added to head of " 2232 dprintk(NDEBUG_QUEUES, "scsi%d: REQUEST SENSE added to head of "
2229 "issue queue\n", H_NO(cmd)); 2233 "issue queue\n", H_NO(cmd));
2230 } else 2234 } else {
2231#endif /* def AUTOSENSE */
2232 {
2233#ifdef NCR5380_STATS
2234 collect_stats(hostdata, cmd);
2235#endif
2236 cmd->scsi_done(cmd); 2235 cmd->scsi_done(cmd);
2237 } 2236 }
2238 2237
2238 local_irq_restore(flags);
2239
2239 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 2240 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2240 /* 2241 /*
2241 * Restore phase bits to 0 so an interrupted selection, 2242 * Restore phase bits to 0 so an interrupted selection,
@@ -2246,12 +2247,14 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2246 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected) 2247 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
2247 barrier(); 2248 barrier();
2248 2249
2249 falcon_dont_release--; 2250 local_irq_save(flags);
2251 hostdata->retain_dma_intr--;
2250 /* ++roman: For Falcon SCSI, release the lock on the 2252 /* ++roman: For Falcon SCSI, release the lock on the
2251 * ST-DMA here if no other commands are waiting on the 2253 * ST-DMA here if no other commands are waiting on the
2252 * disconnected queue. 2254 * disconnected queue.
2253 */ 2255 */
2254 falcon_release_lock_if_possible(hostdata); 2256 maybe_release_dma_irq(instance);
2257 local_irq_restore(flags);
2255 return; 2258 return;
2256 case MESSAGE_REJECT: 2259 case MESSAGE_REJECT:
2257 /* Accept message by clearing ACK */ 2260 /* Accept message by clearing ACK */
@@ -2303,6 +2306,9 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2303 /* Wait for bus free to avoid nasty timeouts */ 2306 /* Wait for bus free to avoid nasty timeouts */
2304 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected) 2307 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
2305 barrier(); 2308 barrier();
2309#ifdef SUN3_SCSI_VME
2310 dregs->csr |= CSR_DMA_ENABLE;
2311#endif
2306 return; 2312 return;
2307 /* 2313 /*
2308 * The SCSI data pointer is *IMPLICITLY* saved on a disconnect 2314 * The SCSI data pointer is *IMPLICITLY* saved on a disconnect
@@ -2384,20 +2390,18 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2384 */ 2390 */
2385 default: 2391 default:
2386 if (!tmp) { 2392 if (!tmp) {
2387 printk(KERN_DEBUG "scsi%d: rejecting message ", HOSTNO); 2393 printk(KERN_INFO "scsi%d: rejecting message ",
2394 instance->host_no);
2388 spi_print_msg(extended_msg); 2395 spi_print_msg(extended_msg);
2389 printk("\n"); 2396 printk("\n");
2390 } else if (tmp != EXTENDED_MESSAGE) 2397 } else if (tmp != EXTENDED_MESSAGE)
2391 printk(KERN_DEBUG "scsi%d: rejecting unknown " 2398 scmd_printk(KERN_INFO, cmd,
2392 "message %02x from target %d, lun %llu\n", 2399 "rejecting unknown message %02x\n",
2393 HOSTNO, tmp, cmd->device->id, cmd->device->lun); 2400 tmp);
2394 else 2401 else
2395 printk(KERN_DEBUG "scsi%d: rejecting unknown " 2402 scmd_printk(KERN_INFO, cmd,
2396 "extended message " 2403 "rejecting unknown extended message code %02x, length %d\n",
2397 "code %02x, length %d from target %d, lun %llu\n", 2404 extended_msg[1], extended_msg[0]);
2398 HOSTNO, extended_msg[1], extended_msg[0],
2399 cmd->device->id, cmd->device->lun);
2400
2401 2405
2402 msgout = MESSAGE_REJECT; 2406 msgout = MESSAGE_REJECT;
2403 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN); 2407 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
@@ -2410,6 +2414,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2410 hostdata->last_message = msgout; 2414 hostdata->last_message = msgout;
2411 NCR5380_transfer_pio(instance, &phase, &len, &data); 2415 NCR5380_transfer_pio(instance, &phase, &len, &data);
2412 if (msgout == ABORT) { 2416 if (msgout == ABORT) {
2417 local_irq_save(flags);
2413#ifdef SUPPORT_TAGS 2418#ifdef SUPPORT_TAGS
2414 cmd_free_tag(cmd); 2419 cmd_free_tag(cmd);
2415#else 2420#else
@@ -2417,12 +2422,10 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2417#endif 2422#endif
2418 hostdata->connected = NULL; 2423 hostdata->connected = NULL;
2419 cmd->result = DID_ERROR << 16; 2424 cmd->result = DID_ERROR << 16;
2420#ifdef NCR5380_STATS
2421 collect_stats(hostdata, cmd);
2422#endif
2423 cmd->scsi_done(cmd);
2424 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask); 2425 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2425 falcon_release_lock_if_possible(hostdata); 2426 maybe_release_dma_irq(instance);
2427 local_irq_restore(flags);
2428 cmd->scsi_done(cmd);
2426 return; 2429 return;
2427 } 2430 }
2428 msgout = NOP; 2431 msgout = NOP;
@@ -2455,7 +2458,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2455 * Function : void NCR5380_reselect (struct Scsi_Host *instance) 2458 * Function : void NCR5380_reselect (struct Scsi_Host *instance)
2456 * 2459 *
2457 * Purpose : does reselection, initializing the instance->connected 2460 * Purpose : does reselection, initializing the instance->connected
2458 * field to point to the Scsi_Cmnd for which the I_T_L or I_T_L_Q 2461 * field to point to the scsi_cmnd for which the I_T_L or I_T_L_Q
2459 * nexus has been reestablished, 2462 * nexus has been reestablished,
2460 * 2463 *
2461 * Inputs : instance - this instance of the NCR5380. 2464 * Inputs : instance - this instance of the NCR5380.
@@ -2463,19 +2466,21 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance)
2463 */ 2466 */
2464 2467
2465 2468
2469/* it might eventually prove necessary to do a dma setup on
2470 reselection, but it doesn't seem to be needed now -- sam */
2471
2466static void NCR5380_reselect(struct Scsi_Host *instance) 2472static void NCR5380_reselect(struct Scsi_Host *instance)
2467{ 2473{
2468 SETUP_HOSTDATA(instance); 2474 SETUP_HOSTDATA(instance);
2469 unsigned char target_mask; 2475 unsigned char target_mask;
2470 unsigned char lun, phase; 2476 unsigned char lun;
2471 int len;
2472#ifdef SUPPORT_TAGS 2477#ifdef SUPPORT_TAGS
2473 unsigned char tag; 2478 unsigned char tag;
2474#endif 2479#endif
2475 unsigned char msg[3]; 2480 unsigned char msg[3];
2476 unsigned char *data; 2481 int __maybe_unused len;
2477 Scsi_Cmnd *tmp = NULL, *prev; 2482 unsigned char __maybe_unused *data, __maybe_unused phase;
2478/* unsigned long flags; */ 2483 struct scsi_cmnd *tmp = NULL, *prev;
2479 2484
2480 /* 2485 /*
2481 * Disable arbitration, etc. since the host adapter obviously 2486 * Disable arbitration, etc. since the host adapter obviously
@@ -2511,10 +2516,18 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
2511 while (!(NCR5380_read(STATUS_REG) & SR_REQ)) 2516 while (!(NCR5380_read(STATUS_REG) & SR_REQ))
2512 ; 2517 ;
2513 2518
2519#if defined(CONFIG_SUN3) && defined(REAL_DMA)
2520 /* acknowledge toggle to MSGIN */
2521 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(PHASE_MSGIN));
2522
2523 /* peek at the byte without really hitting the bus */
2524 msg[0] = NCR5380_read(CURRENT_SCSI_DATA_REG);
2525#else
2514 len = 1; 2526 len = 1;
2515 data = msg; 2527 data = msg;
2516 phase = PHASE_MSGIN; 2528 phase = PHASE_MSGIN;
2517 NCR5380_transfer_pio(instance, &phase, &len, &data); 2529 NCR5380_transfer_pio(instance, &phase, &len, &data);
2530#endif
2518 2531
2519 if (!(msg[0] & 0x80)) { 2532 if (!(msg[0] & 0x80)) {
2520 printk(KERN_DEBUG "scsi%d: expecting IDENTIFY message, got ", HOSTNO); 2533 printk(KERN_DEBUG "scsi%d: expecting IDENTIFY message, got ", HOSTNO);
@@ -2524,13 +2537,13 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
2524 } 2537 }
2525 lun = (msg[0] & 0x07); 2538 lun = (msg[0] & 0x07);
2526 2539
2527#ifdef SUPPORT_TAGS 2540#if defined(SUPPORT_TAGS) && !defined(CONFIG_SUN3)
2528 /* If the phase is still MSGIN, the target wants to send some more 2541 /* If the phase is still MSGIN, the target wants to send some more
2529 * messages. In case it supports tagged queuing, this is probably a 2542 * messages. In case it supports tagged queuing, this is probably a
2530 * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus. 2543 * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus.
2531 */ 2544 */
2532 tag = TAG_NONE; 2545 tag = TAG_NONE;
2533 if (phase == PHASE_MSGIN && setup_use_tagged_queuing) { 2546 if (phase == PHASE_MSGIN && (hostdata->flags & FLAG_TAGGED_QUEUING)) {
2534 /* Accept previous IDENTIFY message by clearing ACK */ 2547 /* Accept previous IDENTIFY message by clearing ACK */
2535 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2548 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2536 len = 2; 2549 len = 2;
@@ -2548,15 +2561,13 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
2548 * just reestablished, and remove it from the disconnected queue. 2561 * just reestablished, and remove it from the disconnected queue.
2549 */ 2562 */
2550 2563
2551 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue, prev = NULL; 2564 for (tmp = (struct scsi_cmnd *) hostdata->disconnected_queue, prev = NULL;
2552 tmp; prev = tmp, tmp = NEXT(tmp)) { 2565 tmp; prev = tmp, tmp = NEXT(tmp)) {
2553 if ((target_mask == (1 << tmp->device->id)) && (lun == tmp->device->lun) 2566 if ((target_mask == (1 << tmp->device->id)) && (lun == tmp->device->lun)
2554#ifdef SUPPORT_TAGS 2567#ifdef SUPPORT_TAGS
2555 && (tag == tmp->tag) 2568 && (tag == tmp->tag)
2556#endif 2569#endif
2557 ) { 2570 ) {
2558 /* ++guenther: prevent race with falcon_release_lock */
2559 falcon_dont_release++;
2560 if (prev) { 2571 if (prev) {
2561 REMOVE(prev, NEXT(prev), tmp, NEXT(tmp)); 2572 REMOVE(prev, NEXT(prev), tmp, NEXT(tmp));
2562 SET_NEXT(prev, NEXT(tmp)); 2573 SET_NEXT(prev, NEXT(tmp));
@@ -2588,26 +2599,67 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
2588 return; 2599 return;
2589 } 2600 }
2590 2601
2602#if defined(CONFIG_SUN3) && defined(REAL_DMA)
2603 /* engage dma setup for the command we just saw */
2604 {
2605 void *d;
2606 unsigned long count;
2607
2608 if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) {
2609 count = tmp->SCp.buffer->length;
2610 d = sg_virt(tmp->SCp.buffer);
2611 } else {
2612 count = tmp->SCp.this_residual;
2613 d = tmp->SCp.ptr;
2614 }
2615 /* setup this command for dma if not already */
2616 if ((count >= DMA_MIN_SIZE) && (sun3_dma_setup_done != tmp)) {
2617 sun3scsi_dma_setup(d, count, rq_data_dir(tmp->request));
2618 sun3_dma_setup_done = tmp;
2619 }
2620 }
2621
2622 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
2623#endif
2624
2591 /* Accept message by clearing ACK */ 2625 /* Accept message by clearing ACK */
2592 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE); 2626 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2593 2627
2628#if defined(SUPPORT_TAGS) && defined(CONFIG_SUN3)
2629 /* If the phase is still MSGIN, the target wants to send some more
2630 * messages. In case it supports tagged queuing, this is probably a
2631 * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus.
2632 */
2633 tag = TAG_NONE;
2634 if (phase == PHASE_MSGIN && setup_use_tagged_queuing) {
2635 /* Accept previous IDENTIFY message by clearing ACK */
2636 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2637 len = 2;
2638 data = msg + 1;
2639 if (!NCR5380_transfer_pio(instance, &phase, &len, &data) &&
2640 msg[1] == SIMPLE_QUEUE_TAG)
2641 tag = msg[2];
2642 dprintk(NDEBUG_TAGS, "scsi%d: target mask %02x, lun %d sent tag %d at reselection\n"
2643 HOSTNO, target_mask, lun, tag);
2644 }
2645#endif
2646
2594 hostdata->connected = tmp; 2647 hostdata->connected = tmp;
2595 dprintk(NDEBUG_RESELECTION, "scsi%d: nexus established, target = %d, lun = %llu, tag = %d\n", 2648 dprintk(NDEBUG_RESELECTION, "scsi%d: nexus established, target = %d, lun = %llu, tag = %d\n",
2596 HOSTNO, tmp->device->id, tmp->device->lun, tmp->tag); 2649 HOSTNO, tmp->device->id, tmp->device->lun, tmp->tag);
2597 falcon_dont_release--;
2598} 2650}
2599 2651
2600 2652
2601/* 2653/*
2602 * Function : int NCR5380_abort (Scsi_Cmnd *cmd) 2654 * Function : int NCR5380_abort (struct scsi_cmnd *cmd)
2603 * 2655 *
2604 * Purpose : abort a command 2656 * Purpose : abort a command
2605 * 2657 *
2606 * Inputs : cmd - the Scsi_Cmnd to abort, code - code to set the 2658 * Inputs : cmd - the scsi_cmnd to abort, code - code to set the
2607 * host byte of the result field to, if zero DID_ABORTED is 2659 * host byte of the result field to, if zero DID_ABORTED is
2608 * used. 2660 * used.
2609 * 2661 *
2610 * Returns : 0 - success, -1 on failure. 2662 * Returns : SUCCESS - success, FAILED on failure.
2611 * 2663 *
2612 * XXX - there is no way to abort the command that is currently 2664 * XXX - there is no way to abort the command that is currently
2613 * connected, you have to wait for it to complete. If this is 2665 * connected, you have to wait for it to complete. If this is
@@ -2616,24 +2668,19 @@ static void NCR5380_reselect(struct Scsi_Host *instance)
2616 */ 2668 */
2617 2669
2618static 2670static
2619int NCR5380_abort(Scsi_Cmnd *cmd) 2671int NCR5380_abort(struct scsi_cmnd *cmd)
2620{ 2672{
2621 struct Scsi_Host *instance = cmd->device->host; 2673 struct Scsi_Host *instance = cmd->device->host;
2622 SETUP_HOSTDATA(instance); 2674 SETUP_HOSTDATA(instance);
2623 Scsi_Cmnd *tmp, **prev; 2675 struct scsi_cmnd *tmp, **prev;
2624 unsigned long flags; 2676 unsigned long flags;
2625 2677
2626 printk(KERN_NOTICE "scsi%d: aborting command\n", HOSTNO); 2678 scmd_printk(KERN_NOTICE, cmd, "aborting command\n");
2627 scsi_print_command(cmd);
2628 2679
2629 NCR5380_print_status(instance); 2680 NCR5380_print_status(instance);
2630 2681
2631 local_irq_save(flags); 2682 local_irq_save(flags);
2632 2683
2633 if (!IS_A_TT() && !falcon_got_lock)
2634 printk(KERN_ERR "scsi%d: !!BINGO!! Falcon has no lock in NCR5380_abort\n",
2635 HOSTNO);
2636
2637 dprintk(NDEBUG_ABORT, "scsi%d: abort called basr 0x%02x, sr 0x%02x\n", HOSTNO, 2684 dprintk(NDEBUG_ABORT, "scsi%d: abort called basr 0x%02x, sr 0x%02x\n", HOSTNO,
2638 NCR5380_read(BUS_AND_STATUS_REG), 2685 NCR5380_read(BUS_AND_STATUS_REG),
2639 NCR5380_read(STATUS_REG)); 2686 NCR5380_read(STATUS_REG));
@@ -2674,12 +2721,12 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
2674#else 2721#else
2675 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); 2722 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2676#endif 2723#endif
2724 maybe_release_dma_irq(instance);
2677 local_irq_restore(flags); 2725 local_irq_restore(flags);
2678 cmd->scsi_done(cmd); 2726 cmd->scsi_done(cmd);
2679 falcon_release_lock_if_possible(hostdata);
2680 return SUCCESS; 2727 return SUCCESS;
2681 } else { 2728 } else {
2682/* local_irq_restore(flags); */ 2729 local_irq_restore(flags);
2683 printk("scsi%d: abort of connected command failed!\n", HOSTNO); 2730 printk("scsi%d: abort of connected command failed!\n", HOSTNO);
2684 return FAILED; 2731 return FAILED;
2685 } 2732 }
@@ -2690,21 +2737,21 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
2690 * Case 2 : If the command hasn't been issued yet, we simply remove it 2737 * Case 2 : If the command hasn't been issued yet, we simply remove it
2691 * from the issue queue. 2738 * from the issue queue.
2692 */ 2739 */
2693 for (prev = (Scsi_Cmnd **)&(hostdata->issue_queue), 2740 for (prev = (struct scsi_cmnd **)&(hostdata->issue_queue),
2694 tmp = (Scsi_Cmnd *)hostdata->issue_queue; 2741 tmp = (struct scsi_cmnd *)hostdata->issue_queue;
2695 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp)) { 2742 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp)) {
2696 if (cmd == tmp) { 2743 if (cmd == tmp) {
2697 REMOVE(5, *prev, tmp, NEXT(tmp)); 2744 REMOVE(5, *prev, tmp, NEXT(tmp));
2698 (*prev) = NEXT(tmp); 2745 (*prev) = NEXT(tmp);
2699 SET_NEXT(tmp, NULL); 2746 SET_NEXT(tmp, NULL);
2700 tmp->result = DID_ABORT << 16; 2747 tmp->result = DID_ABORT << 16;
2748 maybe_release_dma_irq(instance);
2701 local_irq_restore(flags); 2749 local_irq_restore(flags);
2702 dprintk(NDEBUG_ABORT, "scsi%d: abort removed command from issue queue.\n", 2750 dprintk(NDEBUG_ABORT, "scsi%d: abort removed command from issue queue.\n",
2703 HOSTNO); 2751 HOSTNO);
2704 /* Tagged queuing note: no tag to free here, hasn't been assigned 2752 /* Tagged queuing note: no tag to free here, hasn't been assigned
2705 * yet... */ 2753 * yet... */
2706 tmp->scsi_done(tmp); 2754 tmp->scsi_done(tmp);
2707 falcon_release_lock_if_possible(hostdata);
2708 return SUCCESS; 2755 return SUCCESS;
2709 } 2756 }
2710 } 2757 }
@@ -2751,13 +2798,13 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
2751 * it from the disconnected queue. 2798 * it from the disconnected queue.
2752 */ 2799 */
2753 2800
2754 for (tmp = (Scsi_Cmnd *) hostdata->disconnected_queue; tmp; 2801 for (tmp = (struct scsi_cmnd *) hostdata->disconnected_queue; tmp;
2755 tmp = NEXT(tmp)) { 2802 tmp = NEXT(tmp)) {
2756 if (cmd == tmp) { 2803 if (cmd == tmp) {
2757 local_irq_restore(flags); 2804 local_irq_restore(flags);
2758 dprintk(NDEBUG_ABORT, "scsi%d: aborting disconnected command.\n", HOSTNO); 2805 dprintk(NDEBUG_ABORT, "scsi%d: aborting disconnected command.\n", HOSTNO);
2759 2806
2760 if (NCR5380_select(instance, cmd, (int)cmd->tag)) 2807 if (NCR5380_select(instance, cmd))
2761 return FAILED; 2808 return FAILED;
2762 2809
2763 dprintk(NDEBUG_ABORT, "scsi%d: nexus reestablished.\n", HOSTNO); 2810 dprintk(NDEBUG_ABORT, "scsi%d: nexus reestablished.\n", HOSTNO);
@@ -2765,8 +2812,8 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
2765 do_abort(instance); 2812 do_abort(instance);
2766 2813
2767 local_irq_save(flags); 2814 local_irq_save(flags);
2768 for (prev = (Scsi_Cmnd **)&(hostdata->disconnected_queue), 2815 for (prev = (struct scsi_cmnd **)&(hostdata->disconnected_queue),
2769 tmp = (Scsi_Cmnd *)hostdata->disconnected_queue; 2816 tmp = (struct scsi_cmnd *)hostdata->disconnected_queue;
2770 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp)) { 2817 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp)) {
2771 if (cmd == tmp) { 2818 if (cmd == tmp) {
2772 REMOVE(5, *prev, tmp, NEXT(tmp)); 2819 REMOVE(5, *prev, tmp, NEXT(tmp));
@@ -2782,15 +2829,22 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
2782#else 2829#else
2783 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun); 2830 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2784#endif 2831#endif
2832 maybe_release_dma_irq(instance);
2785 local_irq_restore(flags); 2833 local_irq_restore(flags);
2786 tmp->scsi_done(tmp); 2834 tmp->scsi_done(tmp);
2787 falcon_release_lock_if_possible(hostdata);
2788 return SUCCESS; 2835 return SUCCESS;
2789 } 2836 }
2790 } 2837 }
2791 } 2838 }
2792 } 2839 }
2793 2840
2841 /* Maybe it is sufficient just to release the ST-DMA lock... (if
2842 * possible at all) At least, we should check if the lock could be
2843 * released after the abort, in case it is kept due to some bug.
2844 */
2845 maybe_release_dma_irq(instance);
2846 local_irq_restore(flags);
2847
2794 /* 2848 /*
2795 * Case 5 : If we reached this point, the command was not found in any of 2849 * Case 5 : If we reached this point, the command was not found in any of
2796 * the queues. 2850 * the queues.
@@ -2801,21 +2855,14 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
2801 * broke. 2855 * broke.
2802 */ 2856 */
2803 2857
2804 local_irq_restore(flags);
2805 printk(KERN_INFO "scsi%d: warning : SCSI command probably completed successfully before abortion\n", HOSTNO); 2858 printk(KERN_INFO "scsi%d: warning : SCSI command probably completed successfully before abortion\n", HOSTNO);
2806 2859
2807 /* Maybe it is sufficient just to release the ST-DMA lock... (if
2808 * possible at all) At least, we should check if the lock could be
2809 * released after the abort, in case it is kept due to some bug.
2810 */
2811 falcon_release_lock_if_possible(hostdata);
2812
2813 return FAILED; 2860 return FAILED;
2814} 2861}
2815 2862
2816 2863
2817/* 2864/*
2818 * Function : int NCR5380_reset (Scsi_Cmnd *cmd) 2865 * Function : int NCR5380_reset (struct scsi_cmnd *cmd)
2819 * 2866 *
2820 * Purpose : reset the SCSI bus. 2867 * Purpose : reset the SCSI bus.
2821 * 2868 *
@@ -2823,20 +2870,14 @@ int NCR5380_abort(Scsi_Cmnd *cmd)
2823 * 2870 *
2824 */ 2871 */
2825 2872
2826static int NCR5380_bus_reset(Scsi_Cmnd *cmd) 2873static int NCR5380_bus_reset(struct scsi_cmnd *cmd)
2827{ 2874{
2828 SETUP_HOSTDATA(cmd->device->host); 2875 struct Scsi_Host *instance = cmd->device->host;
2876 struct NCR5380_hostdata *hostdata = shost_priv(instance);
2829 int i; 2877 int i;
2830 unsigned long flags; 2878 unsigned long flags;
2831#if defined(RESET_RUN_DONE)
2832 Scsi_Cmnd *connected, *disconnected_queue;
2833#endif
2834
2835 if (!IS_A_TT() && !falcon_got_lock)
2836 printk(KERN_ERR "scsi%d: !!BINGO!! Falcon has no lock in NCR5380_reset\n",
2837 H_NO(cmd));
2838 2879
2839 NCR5380_print_status(cmd->device->host); 2880 NCR5380_print_status(instance);
2840 2881
2841 /* get in phase */ 2882 /* get in phase */
2842 NCR5380_write(TARGET_COMMAND_REG, 2883 NCR5380_write(TARGET_COMMAND_REG,
@@ -2853,89 +2894,6 @@ static int NCR5380_bus_reset(Scsi_Cmnd *cmd)
2853 * through anymore ... */ 2894 * through anymore ... */
2854 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG); 2895 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
2855 2896
2856 /* MSch 20140115 - looking at the generic NCR5380 driver, all of this
2857 * should go.
2858 * Catch-22: if we don't clear all queues, the SCSI driver lock will
2859 * not be reset by atari_scsi_reset()!
2860 */
2861
2862#if defined(RESET_RUN_DONE)
2863 /* XXX Should now be done by midlevel code, but it's broken XXX */
2864 /* XXX see below XXX */
2865
2866 /* MSch: old-style reset: actually abort all command processing here */
2867
2868 /* After the reset, there are no more connected or disconnected commands
2869 * and no busy units; to avoid problems with re-inserting the commands
2870 * into the issue_queue (via scsi_done()), the aborted commands are
2871 * remembered in local variables first.
2872 */
2873 local_irq_save(flags);
2874 connected = (Scsi_Cmnd *)hostdata->connected;
2875 hostdata->connected = NULL;
2876 disconnected_queue = (Scsi_Cmnd *)hostdata->disconnected_queue;
2877 hostdata->disconnected_queue = NULL;
2878#ifdef SUPPORT_TAGS
2879 free_all_tags();
2880#endif
2881 for (i = 0; i < 8; ++i)
2882 hostdata->busy[i] = 0;
2883#ifdef REAL_DMA
2884 hostdata->dma_len = 0;
2885#endif
2886 local_irq_restore(flags);
2887
2888 /* In order to tell the mid-level code which commands were aborted,
2889 * set the command status to DID_RESET and call scsi_done() !!!
2890 * This ultimately aborts processing of these commands in the mid-level.
2891 */
2892
2893 if ((cmd = connected)) {
2894 dprintk(NDEBUG_ABORT, "scsi%d: reset aborted a connected command\n", H_NO(cmd));
2895 cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
2896 cmd->scsi_done(cmd);
2897 }
2898
2899 for (i = 0; (cmd = disconnected_queue); ++i) {
2900 disconnected_queue = NEXT(cmd);
2901 SET_NEXT(cmd, NULL);
2902 cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
2903 cmd->scsi_done(cmd);
2904 }
2905 if (i > 0)
2906 dprintk(NDEBUG_ABORT, "scsi: reset aborted %d disconnected command(s)\n", i);
2907
2908 /* The Falcon lock should be released after a reset...
2909 */
2910 /* ++guenther: moved to atari_scsi_reset(), to prevent a race between
2911 * unlocking and enabling dma interrupt.
2912 */
2913/* falcon_release_lock_if_possible( hostdata );*/
2914
2915 /* since all commands have been explicitly terminated, we need to tell
2916 * the midlevel code that the reset was SUCCESSFUL, and there is no
2917 * need to 'wake up' the commands by a request_sense
2918 */
2919 return SUCCESS;
2920#else /* 1 */
2921
2922 /* MSch: new-style reset handling: let the mid-level do what it can */
2923
2924 /* ++guenther: MID-LEVEL IS STILL BROKEN.
2925 * Mid-level is supposed to requeue all commands that were active on the
2926 * various low-level queues. In fact it does this, but that's not enough
2927 * because all these commands are subject to timeout. And if a timeout
2928 * happens for any removed command, *_abort() is called but all queues
2929 * are now empty. Abort then gives up the falcon lock, which is fatal,
2930 * since the mid-level will queue more commands and must have the lock
2931 * (it's all happening inside timer interrupt handler!!).
2932 * Even worse, abort will return NOT_RUNNING for all those commands not
2933 * on any queue, so they won't be retried ...
2934 *
2935 * Conclusion: either scsi.c disables timeout for all resetted commands
2936 * immediately, or we lose! As of linux-2.0.20 it doesn't.
2937 */
2938
2939 /* After the reset, there are no more connected or disconnected commands 2897 /* After the reset, there are no more connected or disconnected commands
2940 * and no busy units; so clear the low-level status here to avoid 2898 * and no busy units; so clear the low-level status here to avoid
2941 * conflicts when the mid-level code tries to wake up the affected 2899 * conflicts when the mid-level code tries to wake up the affected
@@ -2954,16 +2912,16 @@ static int NCR5380_bus_reset(Scsi_Cmnd *cmd)
2954 hostdata->connected = NULL; 2912 hostdata->connected = NULL;
2955 hostdata->disconnected_queue = NULL; 2913 hostdata->disconnected_queue = NULL;
2956#ifdef SUPPORT_TAGS 2914#ifdef SUPPORT_TAGS
2957 free_all_tags(); 2915 free_all_tags(hostdata);
2958#endif 2916#endif
2959 for (i = 0; i < 8; ++i) 2917 for (i = 0; i < 8; ++i)
2960 hostdata->busy[i] = 0; 2918 hostdata->busy[i] = 0;
2961#ifdef REAL_DMA 2919#ifdef REAL_DMA
2962 hostdata->dma_len = 0; 2920 hostdata->dma_len = 0;
2963#endif 2921#endif
2922
2923 maybe_release_dma_irq(instance);
2964 local_irq_restore(flags); 2924 local_irq_restore(flags);
2965 2925
2966 /* we did no complete reset of all commands, so a wakeup is required */
2967 return SUCCESS; 2926 return SUCCESS;
2968#endif /* 1 */
2969} 2927}
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index b522134528d6..d1c37a386947 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -64,45 +64,57 @@
64/**************************************************************************/ 64/**************************************************************************/
65 65
66 66
67
68#include <linux/module.h> 67#include <linux/module.h>
69
70#define AUTOSENSE
71/* For the Atari version, use only polled IO or REAL_DMA */
72#define REAL_DMA
73/* Support tagged queuing? (on devices that are able to... :-) */
74#define SUPPORT_TAGS
75#define MAX_TAGS 32
76
77#include <linux/types.h> 68#include <linux/types.h>
78#include <linux/stddef.h>
79#include <linux/ctype.h>
80#include <linux/delay.h> 69#include <linux/delay.h>
81#include <linux/mm.h>
82#include <linux/blkdev.h> 70#include <linux/blkdev.h>
83#include <linux/interrupt.h> 71#include <linux/interrupt.h>
84#include <linux/init.h> 72#include <linux/init.h>
85#include <linux/nvram.h> 73#include <linux/nvram.h>
86#include <linux/bitops.h> 74#include <linux/bitops.h>
87#include <linux/wait.h> 75#include <linux/wait.h>
76#include <linux/platform_device.h>
88 77
89#include <asm/setup.h> 78#include <asm/setup.h>
90#include <asm/atarihw.h> 79#include <asm/atarihw.h>
91#include <asm/atariints.h> 80#include <asm/atariints.h>
92#include <asm/page.h>
93#include <asm/pgtable.h>
94#include <asm/irq.h>
95#include <asm/traps.h>
96
97#include "scsi.h"
98#include <scsi/scsi_host.h>
99#include "atari_scsi.h"
100#include "NCR5380.h"
101#include <asm/atari_stdma.h> 81#include <asm/atari_stdma.h>
102#include <asm/atari_stram.h> 82#include <asm/atari_stram.h>
103#include <asm/io.h> 83#include <asm/io.h>
104 84
105#include <linux/stat.h> 85#include <scsi/scsi_host.h>
86
87/* Definitions for the core NCR5380 driver. */
88
89#define REAL_DMA
90#define SUPPORT_TAGS
91#define MAX_TAGS 32
92#define DMA_MIN_SIZE 32
93
94#define NCR5380_implementation_fields /* none */
95
96#define NCR5380_read(reg) atari_scsi_reg_read(reg)
97#define NCR5380_write(reg, value) atari_scsi_reg_write(reg, value)
98
99#define NCR5380_queue_command atari_scsi_queue_command
100#define NCR5380_abort atari_scsi_abort
101#define NCR5380_show_info atari_scsi_show_info
102#define NCR5380_info atari_scsi_info
103
104#define NCR5380_dma_read_setup(instance, data, count) \
105 atari_scsi_dma_setup(instance, data, count, 0)
106#define NCR5380_dma_write_setup(instance, data, count) \
107 atari_scsi_dma_setup(instance, data, count, 1)
108#define NCR5380_dma_residual(instance) \
109 atari_scsi_dma_residual(instance)
110#define NCR5380_dma_xfer_len(instance, cmd, phase) \
111 atari_dma_xfer_len(cmd->SCp.this_residual, cmd, !((phase) & SR_IO))
112
113#define NCR5380_acquire_dma_irq(instance) falcon_get_lock(instance)
114#define NCR5380_release_dma_irq(instance) falcon_release_lock()
115
116#include "NCR5380.h"
117
106 118
107#define IS_A_TT() ATARIHW_PRESENT(TT_SCSI) 119#define IS_A_TT() ATARIHW_PRESENT(TT_SCSI)
108 120
@@ -149,23 +161,6 @@ static inline unsigned long SCSI_DMA_GETADR(void)
149 return adr; 161 return adr;
150} 162}
151 163
152static inline void ENABLE_IRQ(void)
153{
154 if (IS_A_TT())
155 atari_enable_irq(IRQ_TT_MFP_SCSI);
156 else
157 atari_enable_irq(IRQ_MFP_FSCSI);
158}
159
160static inline void DISABLE_IRQ(void)
161{
162 if (IS_A_TT())
163 atari_disable_irq(IRQ_TT_MFP_SCSI);
164 else
165 atari_disable_irq(IRQ_MFP_FSCSI);
166}
167
168
169#define HOSTDATA_DMALEN (((struct NCR5380_hostdata *) \ 164#define HOSTDATA_DMALEN (((struct NCR5380_hostdata *) \
170 (atari_scsi_host->hostdata))->dma_len) 165 (atari_scsi_host->hostdata))->dma_len)
171 166
@@ -178,30 +173,9 @@ static inline void DISABLE_IRQ(void)
178#define AFTER_RESET_DELAY (5*HZ/2) 173#define AFTER_RESET_DELAY (5*HZ/2)
179#endif 174#endif
180 175
181/***************************** Prototypes *****************************/
182
183#ifdef REAL_DMA 176#ifdef REAL_DMA
184static int scsi_dma_is_ignored_buserr(unsigned char dma_stat);
185static void atari_scsi_fetch_restbytes(void); 177static void atari_scsi_fetch_restbytes(void);
186static long atari_scsi_dma_residual(struct Scsi_Host *instance);
187static int falcon_classify_cmd(Scsi_Cmnd *cmd);
188static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
189 Scsi_Cmnd *cmd, int write_flag);
190#endif
191static irqreturn_t scsi_tt_intr(int irq, void *dummy);
192static irqreturn_t scsi_falcon_intr(int irq, void *dummy);
193static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata);
194static void falcon_get_lock(void);
195#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
196static void atari_scsi_reset_boot(void);
197#endif 178#endif
198static unsigned char atari_scsi_tt_reg_read(unsigned char reg);
199static void atari_scsi_tt_reg_write(unsigned char reg, unsigned char value);
200static unsigned char atari_scsi_falcon_reg_read(unsigned char reg);
201static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value);
202
203/************************* End of Prototypes **************************/
204
205 179
206static struct Scsi_Host *atari_scsi_host; 180static struct Scsi_Host *atari_scsi_host;
207static unsigned char (*atari_scsi_reg_read)(unsigned char reg); 181static unsigned char (*atari_scsi_reg_read)(unsigned char reg);
@@ -226,8 +200,6 @@ static char *atari_dma_orig_addr;
226/* mask for address bits that can't be used with the ST-DMA */ 200/* mask for address bits that can't be used with the ST-DMA */
227static unsigned long atari_dma_stram_mask; 201static unsigned long atari_dma_stram_mask;
228#define STRAM_ADDR(a) (((a) & atari_dma_stram_mask) == 0) 202#define STRAM_ADDR(a) (((a) & atari_dma_stram_mask) == 0)
229/* number of bytes to cut from a transfer to handle NCR overruns */
230static int atari_read_overruns;
231#endif 203#endif
232 204
233static int setup_can_queue = -1; 205static int setup_can_queue = -1;
@@ -386,10 +358,6 @@ static irqreturn_t scsi_tt_intr(int irq, void *dummy)
386 358
387 NCR5380_intr(irq, dummy); 359 NCR5380_intr(irq, dummy);
388 360
389#if 0
390 /* To be sure the int is not masked */
391 atari_enable_irq(IRQ_TT_MFP_SCSI);
392#endif
393 return IRQ_HANDLED; 361 return IRQ_HANDLED;
394} 362}
395 363
@@ -480,257 +448,35 @@ static void atari_scsi_fetch_restbytes(void)
480#endif /* REAL_DMA */ 448#endif /* REAL_DMA */
481 449
482 450
483static int falcon_got_lock = 0;
484static DECLARE_WAIT_QUEUE_HEAD(falcon_fairness_wait);
485static int falcon_trying_lock = 0;
486static DECLARE_WAIT_QUEUE_HEAD(falcon_try_wait);
487static int falcon_dont_release = 0;
488
489/* This function releases the lock on the DMA chip if there is no 451/* This function releases the lock on the DMA chip if there is no
490 * connected command and the disconnected queue is empty. On 452 * connected command and the disconnected queue is empty.
491 * releasing, instances of falcon_get_lock are awoken, that put
492 * themselves to sleep for fairness. They can now try to get the lock
493 * again (but others waiting longer more probably will win).
494 */ 453 */
495 454
496static void falcon_release_lock_if_possible(struct NCR5380_hostdata *hostdata) 455static void falcon_release_lock(void)
497{ 456{
498 unsigned long flags;
499
500 if (IS_A_TT()) 457 if (IS_A_TT())
501 return; 458 return;
502 459
503 local_irq_save(flags); 460 if (stdma_is_locked_by(scsi_falcon_intr))
504
505 if (falcon_got_lock && !hostdata->disconnected_queue &&
506 !hostdata->issue_queue && !hostdata->connected) {
507
508 if (falcon_dont_release) {
509#if 0
510 printk("WARNING: Lock release not allowed. Ignored\n");
511#endif
512 local_irq_restore(flags);
513 return;
514 }
515 falcon_got_lock = 0;
516 stdma_release(); 461 stdma_release();
517 wake_up(&falcon_fairness_wait);
518 }
519
520 local_irq_restore(flags);
521} 462}
522 463
523/* This function manages the locking of the ST-DMA. 464/* This function manages the locking of the ST-DMA.
524 * If the DMA isn't locked already for SCSI, it tries to lock it by 465 * If the DMA isn't locked already for SCSI, it tries to lock it by
525 * calling stdma_lock(). But if the DMA is locked by the SCSI code and 466 * calling stdma_lock(). But if the DMA is locked by the SCSI code and
526 * there are other drivers waiting for the chip, we do not issue the 467 * there are other drivers waiting for the chip, we do not issue the
527 * command immediately but wait on 'falcon_fairness_queue'. We will be 468 * command immediately but tell the SCSI mid-layer to defer.
528 * waked up when the DMA is unlocked by some SCSI interrupt. After that
529 * we try to get the lock again.
530 * But we must be prepared that more than one instance of
531 * falcon_get_lock() is waiting on the fairness queue. They should not
532 * try all at once to call stdma_lock(), one is enough! For that, the
533 * first one sets 'falcon_trying_lock', others that see that variable
534 * set wait on the queue 'falcon_try_wait'.
535 * Complicated, complicated.... Sigh...
536 */ 469 */
537 470
538static void falcon_get_lock(void) 471static int falcon_get_lock(struct Scsi_Host *instance)
539{ 472{
540 unsigned long flags;
541
542 if (IS_A_TT()) 473 if (IS_A_TT())
543 return; 474 return 1;
544
545 local_irq_save(flags);
546
547 wait_event_cmd(falcon_fairness_wait,
548 in_interrupt() || !falcon_got_lock || !stdma_others_waiting(),
549 local_irq_restore(flags),
550 local_irq_save(flags));
551
552 while (!falcon_got_lock) {
553 if (in_irq())
554 panic("Falcon SCSI hasn't ST-DMA lock in interrupt");
555 if (!falcon_trying_lock) {
556 falcon_trying_lock = 1;
557 stdma_lock(scsi_falcon_intr, NULL);
558 falcon_got_lock = 1;
559 falcon_trying_lock = 0;
560 wake_up(&falcon_try_wait);
561 } else {
562 wait_event_cmd(falcon_try_wait,
563 falcon_got_lock && !falcon_trying_lock,
564 local_irq_restore(flags),
565 local_irq_save(flags));
566 }
567 }
568
569 local_irq_restore(flags);
570 if (!falcon_got_lock)
571 panic("Falcon SCSI: someone stole the lock :-(\n");
572}
573
574
575static int __init atari_scsi_detect(struct scsi_host_template *host)
576{
577 static int called = 0;
578 struct Scsi_Host *instance;
579
580 if (!MACH_IS_ATARI ||
581 (!ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(TT_SCSI)) ||
582 called)
583 return 0;
584
585 host->proc_name = "Atari";
586
587 atari_scsi_reg_read = IS_A_TT() ? atari_scsi_tt_reg_read :
588 atari_scsi_falcon_reg_read;
589 atari_scsi_reg_write = IS_A_TT() ? atari_scsi_tt_reg_write :
590 atari_scsi_falcon_reg_write;
591
592 /* setup variables */
593 host->can_queue =
594 (setup_can_queue > 0) ? setup_can_queue :
595 IS_A_TT() ? ATARI_TT_CAN_QUEUE : ATARI_FALCON_CAN_QUEUE;
596 host->cmd_per_lun =
597 (setup_cmd_per_lun > 0) ? setup_cmd_per_lun :
598 IS_A_TT() ? ATARI_TT_CMD_PER_LUN : ATARI_FALCON_CMD_PER_LUN;
599 /* Force sg_tablesize to 0 on a Falcon! */
600 host->sg_tablesize =
601 !IS_A_TT() ? ATARI_FALCON_SG_TABLESIZE :
602 (setup_sg_tablesize >= 0) ? setup_sg_tablesize : ATARI_TT_SG_TABLESIZE;
603
604 if (setup_hostid >= 0)
605 host->this_id = setup_hostid;
606 else {
607 /* use 7 as default */
608 host->this_id = 7;
609 /* Test if a host id is set in the NVRam */
610 if (ATARIHW_PRESENT(TT_CLK) && nvram_check_checksum()) {
611 unsigned char b = nvram_read_byte( 14 );
612 /* Arbitration enabled? (for TOS) If yes, use configured host ID */
613 if (b & 0x80)
614 host->this_id = b & 7;
615 }
616 }
617 475
618#ifdef SUPPORT_TAGS 476 if (in_interrupt())
619 if (setup_use_tagged_queuing < 0) 477 return stdma_try_lock(scsi_falcon_intr, instance);
620 setup_use_tagged_queuing = DEFAULT_USE_TAGGED_QUEUING;
621#endif
622#ifdef REAL_DMA
623 /* If running on a Falcon and if there's TT-Ram (i.e., more than one
624 * memory block, since there's always ST-Ram in a Falcon), then allocate a
625 * STRAM_BUFFER_SIZE byte dribble buffer for transfers from/to alternative
626 * Ram.
627 */
628 if (MACH_IS_ATARI && ATARIHW_PRESENT(ST_SCSI) &&
629 !ATARIHW_PRESENT(EXTD_DMA) && m68k_num_memory > 1) {
630 atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI");
631 if (!atari_dma_buffer) {
632 printk(KERN_ERR "atari_scsi_detect: can't allocate ST-RAM "
633 "double buffer\n");
634 return 0;
635 }
636 atari_dma_phys_buffer = atari_stram_to_phys(atari_dma_buffer);
637 atari_dma_orig_addr = 0;
638 }
639#endif
640 instance = scsi_register(host, sizeof(struct NCR5380_hostdata));
641 if (instance == NULL) {
642 atari_stram_free(atari_dma_buffer);
643 atari_dma_buffer = 0;
644 return 0;
645 }
646 atari_scsi_host = instance;
647 /*
648 * Set irq to 0, to avoid that the mid-level code disables our interrupt
649 * during queue_command calls. This is completely unnecessary, and even
650 * worse causes bad problems on the Falcon, where the int is shared with
651 * IDE and floppy!
652 */
653 instance->irq = 0;
654
655#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
656 atari_scsi_reset_boot();
657#endif
658 NCR5380_init(instance, 0);
659
660 if (IS_A_TT()) {
661
662 /* This int is actually "pseudo-slow", i.e. it acts like a slow
663 * interrupt after having cleared the pending flag for the DMA
664 * interrupt. */
665 if (request_irq(IRQ_TT_MFP_SCSI, scsi_tt_intr, IRQ_TYPE_SLOW,
666 "SCSI NCR5380", instance)) {
667 printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting",IRQ_TT_MFP_SCSI);
668 scsi_unregister(atari_scsi_host);
669 atari_stram_free(atari_dma_buffer);
670 atari_dma_buffer = 0;
671 return 0;
672 }
673 tt_mfp.active_edge |= 0x80; /* SCSI int on L->H */
674#ifdef REAL_DMA
675 tt_scsi_dma.dma_ctrl = 0;
676 atari_dma_residual = 0;
677
678 if (MACH_IS_MEDUSA) {
679 /* While the read overruns (described by Drew Eckhardt in
680 * NCR5380.c) never happened on TTs, they do in fact on the Medusa
681 * (This was the cause why SCSI didn't work right for so long
682 * there.) Since handling the overruns slows down a bit, I turned
683 * the #ifdef's into a runtime condition.
684 *
685 * In principle it should be sufficient to do max. 1 byte with
686 * PIO, but there is another problem on the Medusa with the DMA
687 * rest data register. So 'atari_read_overruns' is currently set
688 * to 4 to avoid having transfers that aren't a multiple of 4. If
689 * the rest data bug is fixed, this can be lowered to 1.
690 */
691 atari_read_overruns = 4;
692 }
693#endif /*REAL_DMA*/
694 } else { /* ! IS_A_TT */
695
696 /* Nothing to do for the interrupt: the ST-DMA is initialized
697 * already by atari_init_INTS()
698 */
699
700#ifdef REAL_DMA
701 atari_dma_residual = 0;
702 atari_dma_active = 0;
703 atari_dma_stram_mask = (ATARIHW_PRESENT(EXTD_DMA) ? 0x00000000
704 : 0xff000000);
705#endif
706 }
707 478
708 printk(KERN_INFO "scsi%d: options CAN_QUEUE=%d CMD_PER_LUN=%d SCAT-GAT=%d " 479 stdma_lock(scsi_falcon_intr, instance);
709#ifdef SUPPORT_TAGS
710 "TAGGED-QUEUING=%s "
711#endif
712 "HOSTID=%d",
713 instance->host_no, instance->hostt->can_queue,
714 instance->hostt->cmd_per_lun,
715 instance->hostt->sg_tablesize,
716#ifdef SUPPORT_TAGS
717 setup_use_tagged_queuing ? "yes" : "no",
718#endif
719 instance->hostt->this_id );
720 NCR5380_print_options(instance);
721 printk("\n");
722
723 called = 1;
724 return 1;
725}
726
727static int atari_scsi_release(struct Scsi_Host *sh)
728{
729 if (IS_A_TT())
730 free_irq(IRQ_TT_MFP_SCSI, sh);
731 if (atari_dma_buffer)
732 atari_stram_free(atari_dma_buffer);
733 NCR5380_exit(sh);
734 return 1; 480 return 1;
735} 481}
736 482
@@ -739,7 +485,7 @@ static int __init atari_scsi_setup(char *str)
739{ 485{
740 /* Format of atascsi parameter is: 486 /* Format of atascsi parameter is:
741 * atascsi=<can_queue>,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags> 487 * atascsi=<can_queue>,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>
742 * Defaults depend on TT or Falcon, hostid determined at run time. 488 * Defaults depend on TT or Falcon, determined at run time.
743 * Negative values mean don't change. 489 * Negative values mean don't change.
744 */ 490 */
745 int ints[6]; 491 int ints[6];
@@ -750,36 +496,17 @@ static int __init atari_scsi_setup(char *str)
750 printk("atari_scsi_setup: no arguments!\n"); 496 printk("atari_scsi_setup: no arguments!\n");
751 return 0; 497 return 0;
752 } 498 }
753 499 if (ints[0] >= 1)
754 if (ints[0] >= 1) { 500 setup_can_queue = ints[1];
755 if (ints[1] > 0) 501 if (ints[0] >= 2)
756 /* no limits on this, just > 0 */ 502 setup_cmd_per_lun = ints[2];
757 setup_can_queue = ints[1]; 503 if (ints[0] >= 3)
758 } 504 setup_sg_tablesize = ints[3];
759 if (ints[0] >= 2) { 505 if (ints[0] >= 4)
760 if (ints[2] > 0) 506 setup_hostid = ints[4];
761 setup_cmd_per_lun = ints[2];
762 }
763 if (ints[0] >= 3) {
764 if (ints[3] >= 0) {
765 setup_sg_tablesize = ints[3];
766 /* Must be <= SG_ALL (255) */
767 if (setup_sg_tablesize > SG_ALL)
768 setup_sg_tablesize = SG_ALL;
769 }
770 }
771 if (ints[0] >= 4) {
772 /* Must be between 0 and 7 */
773 if (ints[4] >= 0 && ints[4] <= 7)
774 setup_hostid = ints[4];
775 else if (ints[4] > 7)
776 printk("atari_scsi_setup: invalid host ID %d !\n", ints[4]);
777 }
778#ifdef SUPPORT_TAGS 507#ifdef SUPPORT_TAGS
779 if (ints[0] >= 5) { 508 if (ints[0] >= 5)
780 if (ints[5] >= 0) 509 setup_use_tagged_queuing = ints[5];
781 setup_use_tagged_queuing = !!ints[5];
782 }
783#endif 510#endif
784 511
785 return 1; 512 return 1;
@@ -788,45 +515,6 @@ static int __init atari_scsi_setup(char *str)
788__setup("atascsi=", atari_scsi_setup); 515__setup("atascsi=", atari_scsi_setup);
789#endif /* !MODULE */ 516#endif /* !MODULE */
790 517
791static int atari_scsi_bus_reset(Scsi_Cmnd *cmd)
792{
793 int rv;
794 struct NCR5380_hostdata *hostdata =
795 (struct NCR5380_hostdata *)cmd->device->host->hostdata;
796
797 /* For doing the reset, SCSI interrupts must be disabled first,
798 * since the 5380 raises its IRQ line while _RST is active and we
799 * can't disable interrupts completely, since we need the timer.
800 */
801 /* And abort a maybe active DMA transfer */
802 if (IS_A_TT()) {
803 atari_turnoff_irq(IRQ_TT_MFP_SCSI);
804#ifdef REAL_DMA
805 tt_scsi_dma.dma_ctrl = 0;
806#endif /* REAL_DMA */
807 } else {
808 atari_turnoff_irq(IRQ_MFP_FSCSI);
809#ifdef REAL_DMA
810 st_dma.dma_mode_status = 0x90;
811 atari_dma_active = 0;
812 atari_dma_orig_addr = NULL;
813#endif /* REAL_DMA */
814 }
815
816 rv = NCR5380_bus_reset(cmd);
817
818 /* Re-enable ints */
819 if (IS_A_TT()) {
820 atari_turnon_irq(IRQ_TT_MFP_SCSI);
821 } else {
822 atari_turnon_irq(IRQ_MFP_FSCSI);
823 }
824 if (rv == SUCCESS)
825 falcon_release_lock_if_possible(hostdata);
826
827 return rv;
828}
829
830 518
831#ifdef CONFIG_ATARI_SCSI_RESET_BOOT 519#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
832static void __init atari_scsi_reset_boot(void) 520static void __init atari_scsi_reset_boot(void)
@@ -860,15 +548,6 @@ static void __init atari_scsi_reset_boot(void)
860} 548}
861#endif 549#endif
862 550
863
864static const char *atari_scsi_info(struct Scsi_Host *host)
865{
866 /* atari_scsi_detect() is verbose enough... */
867 static const char string[] = "Atari native SCSI";
868 return string;
869}
870
871
872#if defined(REAL_DMA) 551#if defined(REAL_DMA)
873 552
874static unsigned long atari_scsi_dma_setup(struct Scsi_Host *instance, 553static unsigned long atari_scsi_dma_setup(struct Scsi_Host *instance,
@@ -949,7 +628,7 @@ static long atari_scsi_dma_residual(struct Scsi_Host *instance)
949#define CMD_SURELY_BYTE_MODE 1 628#define CMD_SURELY_BYTE_MODE 1
950#define CMD_MODE_UNKNOWN 2 629#define CMD_MODE_UNKNOWN 2
951 630
952static int falcon_classify_cmd(Scsi_Cmnd *cmd) 631static int falcon_classify_cmd(struct scsi_cmnd *cmd)
953{ 632{
954 unsigned char opcode = cmd->cmnd[0]; 633 unsigned char opcode = cmd->cmnd[0];
955 634
@@ -981,7 +660,7 @@ static int falcon_classify_cmd(Scsi_Cmnd *cmd)
981 */ 660 */
982 661
983static unsigned long atari_dma_xfer_len(unsigned long wanted_len, 662static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
984 Scsi_Cmnd *cmd, int write_flag) 663 struct scsi_cmnd *cmd, int write_flag)
985{ 664{
986 unsigned long possible_len, limit; 665 unsigned long possible_len, limit;
987 666
@@ -1099,23 +778,247 @@ static void atari_scsi_falcon_reg_write(unsigned char reg, unsigned char value)
1099 778
1100#include "atari_NCR5380.c" 779#include "atari_NCR5380.c"
1101 780
1102static struct scsi_host_template driver_template = { 781static int atari_scsi_bus_reset(struct scsi_cmnd *cmd)
782{
783 int rv;
784 unsigned long flags;
785
786 local_irq_save(flags);
787
788#ifdef REAL_DMA
789 /* Abort a maybe active DMA transfer */
790 if (IS_A_TT()) {
791 tt_scsi_dma.dma_ctrl = 0;
792 } else {
793 st_dma.dma_mode_status = 0x90;
794 atari_dma_active = 0;
795 atari_dma_orig_addr = NULL;
796 }
797#endif
798
799 rv = NCR5380_bus_reset(cmd);
800
801 /* The 5380 raises its IRQ line while _RST is active but the ST DMA
802 * "lock" has been released so this interrupt may end up handled by
803 * floppy or IDE driver (if one of them holds the lock). The NCR5380
804 * interrupt flag has been cleared already.
805 */
806
807 local_irq_restore(flags);
808
809 return rv;
810}
811
812#define DRV_MODULE_NAME "atari_scsi"
813#define PFX DRV_MODULE_NAME ": "
814
815static struct scsi_host_template atari_scsi_template = {
816 .module = THIS_MODULE,
817 .proc_name = DRV_MODULE_NAME,
1103 .show_info = atari_scsi_show_info, 818 .show_info = atari_scsi_show_info,
1104 .name = "Atari native SCSI", 819 .name = "Atari native SCSI",
1105 .detect = atari_scsi_detect,
1106 .release = atari_scsi_release,
1107 .info = atari_scsi_info, 820 .info = atari_scsi_info,
1108 .queuecommand = atari_scsi_queue_command, 821 .queuecommand = atari_scsi_queue_command,
1109 .eh_abort_handler = atari_scsi_abort, 822 .eh_abort_handler = atari_scsi_abort,
1110 .eh_bus_reset_handler = atari_scsi_bus_reset, 823 .eh_bus_reset_handler = atari_scsi_bus_reset,
1111 .can_queue = 0, /* initialized at run-time */ 824 .this_id = 7,
1112 .this_id = 0, /* initialized at run-time */
1113 .sg_tablesize = 0, /* initialized at run-time */
1114 .cmd_per_lun = 0, /* initialized at run-time */
1115 .use_clustering = DISABLE_CLUSTERING 825 .use_clustering = DISABLE_CLUSTERING
1116}; 826};
1117 827
828static int __init atari_scsi_probe(struct platform_device *pdev)
829{
830 struct Scsi_Host *instance;
831 int error;
832 struct resource *irq;
833 int host_flags = 0;
834
835 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
836 if (!irq)
837 return -ENODEV;
838
839 if (ATARIHW_PRESENT(TT_SCSI)) {
840 atari_scsi_reg_read = atari_scsi_tt_reg_read;
841 atari_scsi_reg_write = atari_scsi_tt_reg_write;
842 } else {
843 atari_scsi_reg_read = atari_scsi_falcon_reg_read;
844 atari_scsi_reg_write = atari_scsi_falcon_reg_write;
845 }
846
847 /* The values for CMD_PER_LUN and CAN_QUEUE are somehow arbitrary.
848 * Higher values should work, too; try it!
849 * (But cmd_per_lun costs memory!)
850 *
851 * But there seems to be a bug somewhere that requires CAN_QUEUE to be
852 * 2*CMD_PER_LUN. At least on a TT, no spurious timeouts seen since
853 * changed CMD_PER_LUN...
854 *
855 * Note: The Falcon currently uses 8/1 setting due to unsolved problems
856 * with cmd_per_lun != 1
857 */
858 if (ATARIHW_PRESENT(TT_SCSI)) {
859 atari_scsi_template.can_queue = 16;
860 atari_scsi_template.cmd_per_lun = 8;
861 atari_scsi_template.sg_tablesize = SG_ALL;
862 } else {
863 atari_scsi_template.can_queue = 8;
864 atari_scsi_template.cmd_per_lun = 1;
865 atari_scsi_template.sg_tablesize = SG_NONE;
866 }
867
868 if (setup_can_queue > 0)
869 atari_scsi_template.can_queue = setup_can_queue;
870
871 if (setup_cmd_per_lun > 0)
872 atari_scsi_template.cmd_per_lun = setup_cmd_per_lun;
873
874 /* Leave sg_tablesize at 0 on a Falcon! */
875 if (ATARIHW_PRESENT(TT_SCSI) && setup_sg_tablesize >= 0)
876 atari_scsi_template.sg_tablesize = setup_sg_tablesize;
877
878 if (setup_hostid >= 0) {
879 atari_scsi_template.this_id = setup_hostid & 7;
880 } else {
881 /* Test if a host id is set in the NVRam */
882 if (ATARIHW_PRESENT(TT_CLK) && nvram_check_checksum()) {
883 unsigned char b = nvram_read_byte(14);
884
885 /* Arbitration enabled? (for TOS)
886 * If yes, use configured host ID
887 */
888 if (b & 0x80)
889 atari_scsi_template.this_id = b & 7;
890 }
891 }
892
893
894#ifdef REAL_DMA
895 /* If running on a Falcon and if there's TT-Ram (i.e., more than one
896 * memory block, since there's always ST-Ram in a Falcon), then
897 * allocate a STRAM_BUFFER_SIZE byte dribble buffer for transfers
898 * from/to alternative Ram.
899 */
900 if (ATARIHW_PRESENT(ST_SCSI) && !ATARIHW_PRESENT(EXTD_DMA) &&
901 m68k_num_memory > 1) {
902 atari_dma_buffer = atari_stram_alloc(STRAM_BUFFER_SIZE, "SCSI");
903 if (!atari_dma_buffer) {
904 pr_err(PFX "can't allocate ST-RAM double buffer\n");
905 return -ENOMEM;
906 }
907 atari_dma_phys_buffer = atari_stram_to_phys(atari_dma_buffer);
908 atari_dma_orig_addr = 0;
909 }
910#endif
911
912 instance = scsi_host_alloc(&atari_scsi_template,
913 sizeof(struct NCR5380_hostdata));
914 if (!instance) {
915 error = -ENOMEM;
916 goto fail_alloc;
917 }
918 atari_scsi_host = instance;
919
920#ifdef CONFIG_ATARI_SCSI_RESET_BOOT
921 atari_scsi_reset_boot();
922#endif
923
924 instance->irq = irq->start;
925
926 host_flags |= IS_A_TT() ? 0 : FLAG_LATE_DMA_SETUP;
927
928#ifdef SUPPORT_TAGS
929 host_flags |= setup_use_tagged_queuing > 0 ? FLAG_TAGGED_QUEUING : 0;
930#endif
931
932 NCR5380_init(instance, host_flags);
933
934 if (IS_A_TT()) {
935 error = request_irq(instance->irq, scsi_tt_intr, 0,
936 "NCR5380", instance);
937 if (error) {
938 pr_err(PFX "request irq %d failed, aborting\n",
939 instance->irq);
940 goto fail_irq;
941 }
942 tt_mfp.active_edge |= 0x80; /* SCSI int on L->H */
943#ifdef REAL_DMA
944 tt_scsi_dma.dma_ctrl = 0;
945 atari_dma_residual = 0;
946
947 /* While the read overruns (described by Drew Eckhardt in
948 * NCR5380.c) never happened on TTs, they do in fact on the
949 * Medusa (This was the cause why SCSI didn't work right for
950 * so long there.) Since handling the overruns slows down
951 * a bit, I turned the #ifdef's into a runtime condition.
952 *
953 * In principle it should be sufficient to do max. 1 byte with
954 * PIO, but there is another problem on the Medusa with the DMA
955 * rest data register. So read_overruns is currently set
956 * to 4 to avoid having transfers that aren't a multiple of 4.
957 * If the rest data bug is fixed, this can be lowered to 1.
958 */
959 if (MACH_IS_MEDUSA) {
960 struct NCR5380_hostdata *hostdata =
961 shost_priv(instance);
962
963 hostdata->read_overruns = 4;
964 }
965#endif
966 } else {
967 /* Nothing to do for the interrupt: the ST-DMA is initialized
968 * already.
969 */
970#ifdef REAL_DMA
971 atari_dma_residual = 0;
972 atari_dma_active = 0;
973 atari_dma_stram_mask = (ATARIHW_PRESENT(EXTD_DMA) ? 0x00000000
974 : 0xff000000);
975#endif
976 }
977
978 error = scsi_add_host(instance, NULL);
979 if (error)
980 goto fail_host;
981
982 platform_set_drvdata(pdev, instance);
983
984 scsi_scan_host(instance);
985 return 0;
986
987fail_host:
988 if (IS_A_TT())
989 free_irq(instance->irq, instance);
990fail_irq:
991 NCR5380_exit(instance);
992 scsi_host_put(instance);
993fail_alloc:
994 if (atari_dma_buffer)
995 atari_stram_free(atari_dma_buffer);
996 return error;
997}
998
999static int __exit atari_scsi_remove(struct platform_device *pdev)
1000{
1001 struct Scsi_Host *instance = platform_get_drvdata(pdev);
1002
1003 scsi_remove_host(instance);
1004 if (IS_A_TT())
1005 free_irq(instance->irq, instance);
1006 NCR5380_exit(instance);
1007 scsi_host_put(instance);
1008 if (atari_dma_buffer)
1009 atari_stram_free(atari_dma_buffer);
1010 return 0;
1011}
1012
1013static struct platform_driver atari_scsi_driver = {
1014 .remove = __exit_p(atari_scsi_remove),
1015 .driver = {
1016 .name = DRV_MODULE_NAME,
1017 .owner = THIS_MODULE,
1018 },
1019};
1118 1020
1119#include "scsi_module.c" 1021module_platform_driver_probe(atari_scsi_driver, atari_scsi_probe);
1120 1022
1023MODULE_ALIAS("platform:" DRV_MODULE_NAME);
1121MODULE_LICENSE("GPL"); 1024MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/atari_scsi.h b/drivers/scsi/atari_scsi.h
deleted file mode 100644
index 3299d91d7336..000000000000
--- a/drivers/scsi/atari_scsi.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * atari_scsi.h -- Header file for the Atari native SCSI driver
3 *
4 * Copyright 1994 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
5 *
6 * (Loosely based on the work of Robert De Vries' team)
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
10 * for more details.
11 *
12 */
13
14
15#ifndef ATARI_SCSI_H
16#define ATARI_SCSI_H
17
18/* (I_HAVE_OVERRUNS stuff removed) */
19
20#ifndef ASM
21/* The values for CMD_PER_LUN and CAN_QUEUE are somehow arbitrary. Higher
22 * values should work, too; try it! (but cmd_per_lun costs memory!) */
23
24/* But there seems to be a bug somewhere that requires CAN_QUEUE to be
25 * 2*CMD_PER_LUN. At least on a TT, no spurious timeouts seen since
26 * changed CMD_PER_LUN... */
27
28/* Note: The Falcon currently uses 8/1 setting due to unsolved problems with
29 * cmd_per_lun != 1 */
30
31#define ATARI_TT_CAN_QUEUE 16
32#define ATARI_TT_CMD_PER_LUN 8
33#define ATARI_TT_SG_TABLESIZE SG_ALL
34
35#define ATARI_FALCON_CAN_QUEUE 8
36#define ATARI_FALCON_CMD_PER_LUN 1
37#define ATARI_FALCON_SG_TABLESIZE SG_NONE
38
39#define DEFAULT_USE_TAGGED_QUEUING 0
40
41
42#define NCR5380_implementation_fields /* none */
43
44#define NCR5380_read(reg) atari_scsi_reg_read( reg )
45#define NCR5380_write(reg, value) atari_scsi_reg_write( reg, value )
46
47#define NCR5380_intr atari_scsi_intr
48#define NCR5380_queue_command atari_scsi_queue_command
49#define NCR5380_abort atari_scsi_abort
50#define NCR5380_show_info atari_scsi_show_info
51#define NCR5380_dma_read_setup(inst,d,c) atari_scsi_dma_setup (inst, d, c, 0)
52#define NCR5380_dma_write_setup(inst,d,c) atari_scsi_dma_setup (inst, d, c, 1)
53#define NCR5380_dma_residual(inst) atari_scsi_dma_residual( inst )
54#define NCR5380_dma_xfer_len(i,cmd,phase) \
55 atari_dma_xfer_len(cmd->SCp.this_residual,cmd,((phase) & SR_IO) ? 0 : 1)
56
57#endif /* ndef ASM */
58#endif /* ATARI_SCSI_H */
59
60
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 30d74a06b993..f3193406776c 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -556,7 +556,7 @@ static struct scsi_host_template beiscsi_sht = {
556 .name = "Emulex 10Gbe open-iscsi Initiator Driver", 556 .name = "Emulex 10Gbe open-iscsi Initiator Driver",
557 .proc_name = DRV_NAME, 557 .proc_name = DRV_NAME,
558 .queuecommand = iscsi_queuecommand, 558 .queuecommand = iscsi_queuecommand,
559 .change_queue_depth = iscsi_change_queue_depth, 559 .change_queue_depth = scsi_change_queue_depth,
560 .slave_configure = beiscsi_slave_configure, 560 .slave_configure = beiscsi_slave_configure,
561 .target_alloc = iscsi_target_alloc, 561 .target_alloc = iscsi_target_alloc,
562 .eh_abort_handler = beiscsi_eh_abort, 562 .eh_abort_handler = beiscsi_eh_abort,
@@ -570,7 +570,7 @@ static struct scsi_host_template beiscsi_sht = {
570 .cmd_per_lun = BEISCSI_CMD_PER_LUN, 570 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
571 .use_clustering = ENABLE_CLUSTERING, 571 .use_clustering = ENABLE_CLUSTERING,
572 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, 572 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
573 573 .track_queue_depth = 1,
574}; 574};
575 575
576static struct scsi_transport_template *beiscsi_scsi_transport; 576static struct scsi_transport_template *beiscsi_scsi_transport;
diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c
index 8e83d0474fe7..74a307c0a240 100644
--- a/drivers/scsi/bfa/bfad_debugfs.c
+++ b/drivers/scsi/bfa/bfad_debugfs.c
@@ -260,18 +260,9 @@ bfad_debugfs_write_regrd(struct file *file, const char __user *buf,
260 unsigned long flags; 260 unsigned long flags;
261 void *kern_buf; 261 void *kern_buf;
262 262
263 kern_buf = kzalloc(nbytes, GFP_KERNEL); 263 kern_buf = memdup_user(buf, nbytes);
264 264 if (IS_ERR(kern_buf))
265 if (!kern_buf) { 265 return PTR_ERR(kern_buf);
266 printk(KERN_INFO "bfad[%d]: Failed to allocate buffer\n",
267 bfad->inst_no);
268 return -ENOMEM;
269 }
270
271 if (copy_from_user(kern_buf, (void __user *)buf, nbytes)) {
272 kfree(kern_buf);
273 return -ENOMEM;
274 }
275 266
276 rc = sscanf(kern_buf, "%x:%x", &addr, &len); 267 rc = sscanf(kern_buf, "%x:%x", &addr, &len);
277 if (rc < 2) { 268 if (rc < 2) {
@@ -336,18 +327,9 @@ bfad_debugfs_write_regwr(struct file *file, const char __user *buf,
336 unsigned long flags; 327 unsigned long flags;
337 void *kern_buf; 328 void *kern_buf;
338 329
339 kern_buf = kzalloc(nbytes, GFP_KERNEL); 330 kern_buf = memdup_user(buf, nbytes);
340 331 if (IS_ERR(kern_buf))
341 if (!kern_buf) { 332 return PTR_ERR(kern_buf);
342 printk(KERN_INFO "bfad[%d]: Failed to allocate buffer\n",
343 bfad->inst_no);
344 return -ENOMEM;
345 }
346
347 if (copy_from_user(kern_buf, (void __user *)buf, nbytes)) {
348 kfree(kern_buf);
349 return -ENOMEM;
350 }
351 333
352 rc = sscanf(kern_buf, "%x:%x", &addr, &val); 334 rc = sscanf(kern_buf, "%x:%x", &addr, &val);
353 if (rc < 2) { 335 if (rc < 2) {
diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index f067332bf763..7223b0006740 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -776,11 +776,7 @@ bfad_thread_workq(struct bfad_s *bfad)
776static int 776static int
777bfad_im_slave_configure(struct scsi_device *sdev) 777bfad_im_slave_configure(struct scsi_device *sdev)
778{ 778{
779 if (sdev->tagged_supported) 779 scsi_change_queue_depth(sdev, bfa_lun_queue_depth);
780 scsi_activate_tcq(sdev, bfa_lun_queue_depth);
781 else
782 scsi_deactivate_tcq(sdev, bfa_lun_queue_depth);
783
784 return 0; 780 return 0;
785} 781}
786 782
@@ -804,6 +800,7 @@ struct scsi_host_template bfad_im_scsi_host_template = {
804 .shost_attrs = bfad_im_host_attrs, 800 .shost_attrs = bfad_im_host_attrs,
805 .max_sectors = BFAD_MAX_SECTORS, 801 .max_sectors = BFAD_MAX_SECTORS,
806 .vendor_id = BFA_PCI_VENDOR_ID_BROCADE, 802 .vendor_id = BFA_PCI_VENDOR_ID_BROCADE,
803 .use_blk_tags = 1,
807}; 804};
808 805
809struct scsi_host_template bfad_im_vport_template = { 806struct scsi_host_template bfad_im_vport_template = {
@@ -825,6 +822,7 @@ struct scsi_host_template bfad_im_vport_template = {
825 .use_clustering = ENABLE_CLUSTERING, 822 .use_clustering = ENABLE_CLUSTERING,
826 .shost_attrs = bfad_im_vport_attrs, 823 .shost_attrs = bfad_im_vport_attrs,
827 .max_sectors = BFAD_MAX_SECTORS, 824 .max_sectors = BFAD_MAX_SECTORS,
825 .use_blk_tags = 1,
828}; 826};
829 827
830bfa_status_t 828bfa_status_t
@@ -868,14 +866,8 @@ bfad_ramp_up_qdepth(struct bfad_itnim_s *itnim, struct scsi_device *sdev)
868 if (bfa_lun_queue_depth > tmp_sdev->queue_depth) { 866 if (bfa_lun_queue_depth > tmp_sdev->queue_depth) {
869 if (tmp_sdev->id != sdev->id) 867 if (tmp_sdev->id != sdev->id)
870 continue; 868 continue;
871 if (tmp_sdev->ordered_tags) 869 scsi_change_queue_depth(tmp_sdev,
872 scsi_adjust_queue_depth(tmp_sdev, 870 tmp_sdev->queue_depth + 1);
873 MSG_ORDERED_TAG,
874 tmp_sdev->queue_depth + 1);
875 else
876 scsi_adjust_queue_depth(tmp_sdev,
877 MSG_SIMPLE_TAG,
878 tmp_sdev->queue_depth + 1);
879 871
880 itnim->last_ramp_up_time = jiffies; 872 itnim->last_ramp_up_time = jiffies;
881 } 873 }
diff --git a/drivers/scsi/bnx2fc/bnx2fc_els.c b/drivers/scsi/bnx2fc/bnx2fc_els.c
index ca75c7ca2559..ef355c13ccc4 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_els.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_els.c
@@ -480,9 +480,7 @@ void bnx2fc_rec_compl(struct bnx2fc_els_cb_arg *cb_arg)
480 bnx2fc_initiate_cleanup(orig_io_req); 480 bnx2fc_initiate_cleanup(orig_io_req);
481 /* Post a new IO req with the same sc_cmd */ 481 /* Post a new IO req with the same sc_cmd */
482 BNX2FC_IO_DBG(rec_req, "Post IO request again\n"); 482 BNX2FC_IO_DBG(rec_req, "Post IO request again\n");
483 spin_unlock_bh(&tgt->tgt_lock);
484 rc = bnx2fc_post_io_req(tgt, new_io_req); 483 rc = bnx2fc_post_io_req(tgt, new_io_req);
485 spin_lock_bh(&tgt->tgt_lock);
486 if (!rc) 484 if (!rc)
487 goto free_frame; 485 goto free_frame;
488 BNX2FC_IO_DBG(rec_req, "REC: io post err\n"); 486 BNX2FC_IO_DBG(rec_req, "REC: io post err\n");
diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
index 79e5c94107a9..e861f286b42e 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -412,6 +412,7 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
412 struct fc_frame_header *fh; 412 struct fc_frame_header *fh;
413 struct fcoe_rcv_info *fr; 413 struct fcoe_rcv_info *fr;
414 struct fcoe_percpu_s *bg; 414 struct fcoe_percpu_s *bg;
415 struct sk_buff *tmp_skb;
415 unsigned short oxid; 416 unsigned short oxid;
416 417
417 interface = container_of(ptype, struct bnx2fc_interface, 418 interface = container_of(ptype, struct bnx2fc_interface,
@@ -424,6 +425,12 @@ static int bnx2fc_rcv(struct sk_buff *skb, struct net_device *dev,
424 goto err; 425 goto err;
425 } 426 }
426 427
428 tmp_skb = skb_share_check(skb, GFP_ATOMIC);
429 if (!tmp_skb)
430 goto err;
431
432 skb = tmp_skb;
433
427 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) { 434 if (unlikely(eth_hdr(skb)->h_proto != htons(ETH_P_FCOE))) {
428 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n"); 435 printk(KERN_ERR PFX "bnx2fc_rcv: Wrong FC type frame\n");
429 goto err; 436 goto err;
@@ -1081,7 +1088,7 @@ static int bnx2fc_vport_create(struct fc_vport *vport, bool disabled)
1081 mutex_unlock(&bnx2fc_dev_lock); 1088 mutex_unlock(&bnx2fc_dev_lock);
1082 rtnl_unlock(); 1089 rtnl_unlock();
1083 1090
1084 if (IS_ERR(vn_port)) { 1091 if (!vn_port) {
1085 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n", 1092 printk(KERN_ERR PFX "bnx2fc_vport_create (%s) failed\n",
1086 netdev->name); 1093 netdev->name);
1087 return -EIO; 1094 return -EIO;
@@ -2195,6 +2202,7 @@ static int _bnx2fc_create(struct net_device *netdev,
2195 interface = bnx2fc_interface_create(hba, netdev, fip_mode); 2202 interface = bnx2fc_interface_create(hba, netdev, fip_mode);
2196 if (!interface) { 2203 if (!interface) {
2197 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n"); 2204 printk(KERN_ERR PFX "bnx2fc_interface_create failed\n");
2205 rc = -ENOMEM;
2198 goto ifput_err; 2206 goto ifput_err;
2199 } 2207 }
2200 2208
@@ -2783,13 +2791,15 @@ static struct scsi_host_template bnx2fc_shost_template = {
2783 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */ 2791 .eh_target_reset_handler = bnx2fc_eh_target_reset, /* tgt reset */
2784 .eh_host_reset_handler = fc_eh_host_reset, 2792 .eh_host_reset_handler = fc_eh_host_reset,
2785 .slave_alloc = fc_slave_alloc, 2793 .slave_alloc = fc_slave_alloc,
2786 .change_queue_depth = fc_change_queue_depth, 2794 .change_queue_depth = scsi_change_queue_depth,
2787 .change_queue_type = fc_change_queue_type, 2795 .change_queue_type = scsi_change_queue_type,
2788 .this_id = -1, 2796 .this_id = -1,
2789 .cmd_per_lun = 3, 2797 .cmd_per_lun = 3,
2790 .use_clustering = ENABLE_CLUSTERING, 2798 .use_clustering = ENABLE_CLUSTERING,
2791 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD, 2799 .sg_tablesize = BNX2FC_MAX_BDS_PER_CMD,
2792 .max_sectors = 1024, 2800 .max_sectors = 1024,
2801 .use_blk_tags = 1,
2802 .track_queue_depth = 1,
2793}; 2803};
2794 2804
2795static struct libfc_function_template bnx2fc_libfc_fcn_templ = { 2805static struct libfc_function_template bnx2fc_libfc_fcn_templ = {
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 0679782d9d15..4b56858c1df2 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -1725,7 +1725,6 @@ void bnx2fc_build_fcp_cmnd(struct bnx2fc_cmd *io_req,
1725 struct fcp_cmnd *fcp_cmnd) 1725 struct fcp_cmnd *fcp_cmnd)
1726{ 1726{
1727 struct scsi_cmnd *sc_cmd = io_req->sc_cmd; 1727 struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
1728 char tag[2];
1729 1728
1730 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd)); 1729 memset(fcp_cmnd, 0, sizeof(struct fcp_cmnd));
1731 1730
@@ -1739,21 +1738,10 @@ void bnx2fc_build_fcp_cmnd(struct bnx2fc_cmd *io_req,
1739 fcp_cmnd->fc_tm_flags = io_req->mp_req.tm_flags; 1738 fcp_cmnd->fc_tm_flags = io_req->mp_req.tm_flags;
1740 fcp_cmnd->fc_flags = io_req->io_req_flags; 1739 fcp_cmnd->fc_flags = io_req->io_req_flags;
1741 1740
1742 if (scsi_populate_tag_msg(sc_cmd, tag)) { 1741 if (sc_cmd->flags & SCMD_TAGGED)
1743 switch (tag[0]) { 1742 fcp_cmnd->fc_pri_ta = FCP_PTA_SIMPLE;
1744 case HEAD_OF_QUEUE_TAG: 1743 else
1745 fcp_cmnd->fc_pri_ta = FCP_PTA_HEADQ;
1746 break;
1747 case ORDERED_QUEUE_TAG:
1748 fcp_cmnd->fc_pri_ta = FCP_PTA_ORDERED;
1749 break;
1750 default:
1751 fcp_cmnd->fc_pri_ta = FCP_PTA_SIMPLE;
1752 break;
1753 }
1754 } else {
1755 fcp_cmnd->fc_pri_ta = 0; 1744 fcp_cmnd->fc_pri_ta = 0;
1756 }
1757} 1745}
1758 1746
1759static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req, 1747static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
@@ -1894,18 +1882,24 @@ int bnx2fc_queuecommand(struct Scsi_Host *host,
1894 goto exit_qcmd; 1882 goto exit_qcmd;
1895 } 1883 }
1896 } 1884 }
1885
1886 spin_lock_bh(&tgt->tgt_lock);
1887
1897 io_req = bnx2fc_cmd_alloc(tgt); 1888 io_req = bnx2fc_cmd_alloc(tgt);
1898 if (!io_req) { 1889 if (!io_req) {
1899 rc = SCSI_MLQUEUE_HOST_BUSY; 1890 rc = SCSI_MLQUEUE_HOST_BUSY;
1900 goto exit_qcmd; 1891 goto exit_qcmd_tgtlock;
1901 } 1892 }
1902 io_req->sc_cmd = sc_cmd; 1893 io_req->sc_cmd = sc_cmd;
1903 1894
1904 if (bnx2fc_post_io_req(tgt, io_req)) { 1895 if (bnx2fc_post_io_req(tgt, io_req)) {
1905 printk(KERN_ERR PFX "Unable to post io_req\n"); 1896 printk(KERN_ERR PFX "Unable to post io_req\n");
1906 rc = SCSI_MLQUEUE_HOST_BUSY; 1897 rc = SCSI_MLQUEUE_HOST_BUSY;
1907 goto exit_qcmd; 1898 goto exit_qcmd_tgtlock;
1908 } 1899 }
1900
1901exit_qcmd_tgtlock:
1902 spin_unlock_bh(&tgt->tgt_lock);
1909exit_qcmd: 1903exit_qcmd:
1910 return rc; 1904 return rc;
1911} 1905}
@@ -2020,6 +2014,8 @@ int bnx2fc_post_io_req(struct bnx2fc_rport *tgt,
2020 int task_idx, index; 2014 int task_idx, index;
2021 u16 xid; 2015 u16 xid;
2022 2016
2017 /* bnx2fc_post_io_req() is called with the tgt_lock held */
2018
2023 /* Initialize rest of io_req fields */ 2019 /* Initialize rest of io_req fields */
2024 io_req->cmd_type = BNX2FC_SCSI_CMD; 2020 io_req->cmd_type = BNX2FC_SCSI_CMD;
2025 io_req->port = port; 2021 io_req->port = port;
@@ -2047,9 +2043,7 @@ int bnx2fc_post_io_req(struct bnx2fc_rport *tgt,
2047 /* Build buffer descriptor list for firmware from sg list */ 2043 /* Build buffer descriptor list for firmware from sg list */
2048 if (bnx2fc_build_bd_list_from_sg(io_req)) { 2044 if (bnx2fc_build_bd_list_from_sg(io_req)) {
2049 printk(KERN_ERR PFX "BD list creation failed\n"); 2045 printk(KERN_ERR PFX "BD list creation failed\n");
2050 spin_lock_bh(&tgt->tgt_lock);
2051 kref_put(&io_req->refcount, bnx2fc_cmd_release); 2046 kref_put(&io_req->refcount, bnx2fc_cmd_release);
2052 spin_unlock_bh(&tgt->tgt_lock);
2053 return -EAGAIN; 2047 return -EAGAIN;
2054 } 2048 }
2055 2049
@@ -2061,19 +2055,15 @@ int bnx2fc_post_io_req(struct bnx2fc_rport *tgt,
2061 task = &(task_page[index]); 2055 task = &(task_page[index]);
2062 bnx2fc_init_task(io_req, task); 2056 bnx2fc_init_task(io_req, task);
2063 2057
2064 spin_lock_bh(&tgt->tgt_lock);
2065
2066 if (tgt->flush_in_prog) { 2058 if (tgt->flush_in_prog) {
2067 printk(KERN_ERR PFX "Flush in progress..Host Busy\n"); 2059 printk(KERN_ERR PFX "Flush in progress..Host Busy\n");
2068 kref_put(&io_req->refcount, bnx2fc_cmd_release); 2060 kref_put(&io_req->refcount, bnx2fc_cmd_release);
2069 spin_unlock_bh(&tgt->tgt_lock);
2070 return -EAGAIN; 2061 return -EAGAIN;
2071 } 2062 }
2072 2063
2073 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) { 2064 if (!test_bit(BNX2FC_FLAG_SESSION_READY, &tgt->flags)) {
2074 printk(KERN_ERR PFX "Session not ready...post_io\n"); 2065 printk(KERN_ERR PFX "Session not ready...post_io\n");
2075 kref_put(&io_req->refcount, bnx2fc_cmd_release); 2066 kref_put(&io_req->refcount, bnx2fc_cmd_release);
2076 spin_unlock_bh(&tgt->tgt_lock);
2077 return -EAGAIN; 2067 return -EAGAIN;
2078 } 2068 }
2079 2069
@@ -2091,6 +2081,5 @@ int bnx2fc_post_io_req(struct bnx2fc_rport *tgt,
2091 2081
2092 /* Ring doorbell */ 2082 /* Ring doorbell */
2093 bnx2fc_ring_doorbell(tgt); 2083 bnx2fc_ring_doorbell(tgt);
2094 spin_unlock_bh(&tgt->tgt_lock);
2095 return 0; 2084 return 0;
2096} 2085}
diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index 7a36388822aa..e53078d03309 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -2259,7 +2259,7 @@ static struct scsi_host_template bnx2i_host_template = {
2259 .eh_abort_handler = iscsi_eh_abort, 2259 .eh_abort_handler = iscsi_eh_abort,
2260 .eh_device_reset_handler = iscsi_eh_device_reset, 2260 .eh_device_reset_handler = iscsi_eh_device_reset,
2261 .eh_target_reset_handler = iscsi_eh_recover_target, 2261 .eh_target_reset_handler = iscsi_eh_recover_target,
2262 .change_queue_depth = iscsi_change_queue_depth, 2262 .change_queue_depth = scsi_change_queue_depth,
2263 .target_alloc = iscsi_target_alloc, 2263 .target_alloc = iscsi_target_alloc,
2264 .can_queue = 2048, 2264 .can_queue = 2048,
2265 .max_sectors = 127, 2265 .max_sectors = 127,
@@ -2268,6 +2268,7 @@ static struct scsi_host_template bnx2i_host_template = {
2268 .use_clustering = ENABLE_CLUSTERING, 2268 .use_clustering = ENABLE_CLUSTERING,
2269 .sg_tablesize = ISCSI_MAX_BDS_PER_CMD, 2269 .sg_tablesize = ISCSI_MAX_BDS_PER_CMD,
2270 .shost_attrs = bnx2i_dev_attributes, 2270 .shost_attrs = bnx2i_dev_attributes,
2271 .track_queue_depth = 1,
2271}; 2272};
2272 2273
2273struct iscsi_transport bnx2i_iscsi_transport = { 2274struct iscsi_transport bnx2i_iscsi_transport = {
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index ef5ae0d03616..6bac8a746ee2 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -85,8 +85,7 @@ static const char * vendor_labels[CH_TYPES-4] = {
85// module_param_string_array(vendor_labels, NULL, 0444); 85// module_param_string_array(vendor_labels, NULL, 0444);
86 86
87#define ch_printk(prefix, ch, fmt, a...) \ 87#define ch_printk(prefix, ch, fmt, a...) \
88 sdev_printk(prefix, (ch)->device, "[%s] " fmt, \ 88 sdev_prefix_printk(prefix, (ch)->device, (ch)->name, fmt, ##a)
89 (ch)->name, ##a)
90 89
91#define DPRINTK(fmt, arg...) \ 90#define DPRINTK(fmt, arg...) \
92do { \ 91do { \
@@ -183,7 +182,7 @@ static int ch_find_errno(struct scsi_sense_hdr *sshdr)
183} 182}
184 183
185static int 184static int
186ch_do_scsi(scsi_changer *ch, unsigned char *cmd, 185ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
187 void *buffer, unsigned buflength, 186 void *buffer, unsigned buflength,
188 enum dma_data_direction direction) 187 enum dma_data_direction direction)
189{ 188{
@@ -197,7 +196,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
197 errno = 0; 196 errno = 0;
198 if (debug) { 197 if (debug) {
199 DPRINTK("command: "); 198 DPRINTK("command: ");
200 __scsi_print_command(cmd); 199 __scsi_print_command(cmd, cmd_len);
201 } 200 }
202 201
203 result = scsi_execute_req(ch->device, cmd, direction, buffer, 202 result = scsi_execute_req(ch->device, cmd, direction, buffer,
@@ -207,7 +206,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
207 DPRINTK("result: 0x%x\n",result); 206 DPRINTK("result: 0x%x\n",result);
208 if (driver_byte(result) & DRIVER_SENSE) { 207 if (driver_byte(result) & DRIVER_SENSE) {
209 if (debug) 208 if (debug)
210 scsi_print_sense_hdr(ch->name, &sshdr); 209 scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
211 errno = ch_find_errno(&sshdr); 210 errno = ch_find_errno(&sshdr);
212 211
213 switch(sshdr.sense_key) { 212 switch(sshdr.sense_key) {
@@ -258,7 +257,8 @@ ch_read_element_status(scsi_changer *ch, u_int elem, char *data)
258 cmd[3] = elem & 0xff; 257 cmd[3] = elem & 0xff;
259 cmd[5] = 1; 258 cmd[5] = 1;
260 cmd[9] = 255; 259 cmd[9] = 255;
261 if (0 == (result = ch_do_scsi(ch, cmd, buffer, 256, DMA_FROM_DEVICE))) { 260 if (0 == (result = ch_do_scsi(ch, cmd, 12,
261 buffer, 256, DMA_FROM_DEVICE))) {
262 if (((buffer[16] << 8) | buffer[17]) != elem) { 262 if (((buffer[16] << 8) | buffer[17]) != elem) {
263 DPRINTK("asked for element 0x%02x, got 0x%02x\n", 263 DPRINTK("asked for element 0x%02x, got 0x%02x\n",
264 elem,(buffer[16] << 8) | buffer[17]); 264 elem,(buffer[16] << 8) | buffer[17]);
@@ -288,7 +288,7 @@ ch_init_elem(scsi_changer *ch)
288 memset(cmd,0,sizeof(cmd)); 288 memset(cmd,0,sizeof(cmd));
289 cmd[0] = INITIALIZE_ELEMENT_STATUS; 289 cmd[0] = INITIALIZE_ELEMENT_STATUS;
290 cmd[1] = (ch->device->lun & 0x7) << 5; 290 cmd[1] = (ch->device->lun & 0x7) << 5;
291 err = ch_do_scsi(ch, cmd, NULL, 0, DMA_NONE); 291 err = ch_do_scsi(ch, cmd, 6, NULL, 0, DMA_NONE);
292 VPRINTK(KERN_INFO, "... finished\n"); 292 VPRINTK(KERN_INFO, "... finished\n");
293 return err; 293 return err;
294} 294}
@@ -310,10 +310,10 @@ ch_readconfig(scsi_changer *ch)
310 cmd[1] = (ch->device->lun & 0x7) << 5; 310 cmd[1] = (ch->device->lun & 0x7) << 5;
311 cmd[2] = 0x1d; 311 cmd[2] = 0x1d;
312 cmd[4] = 255; 312 cmd[4] = 255;
313 result = ch_do_scsi(ch, cmd, buffer, 255, DMA_FROM_DEVICE); 313 result = ch_do_scsi(ch, cmd, 10, buffer, 255, DMA_FROM_DEVICE);
314 if (0 != result) { 314 if (0 != result) {
315 cmd[1] |= (1<<3); 315 cmd[1] |= (1<<3);
316 result = ch_do_scsi(ch, cmd, buffer, 255, DMA_FROM_DEVICE); 316 result = ch_do_scsi(ch, cmd, 10, buffer, 255, DMA_FROM_DEVICE);
317 } 317 }
318 if (0 == result) { 318 if (0 == result) {
319 ch->firsts[CHET_MT] = 319 ch->firsts[CHET_MT] =
@@ -438,7 +438,7 @@ ch_position(scsi_changer *ch, u_int trans, u_int elem, int rotate)
438 cmd[4] = (elem >> 8) & 0xff; 438 cmd[4] = (elem >> 8) & 0xff;
439 cmd[5] = elem & 0xff; 439 cmd[5] = elem & 0xff;
440 cmd[8] = rotate ? 1 : 0; 440 cmd[8] = rotate ? 1 : 0;
441 return ch_do_scsi(ch, cmd, NULL, 0, DMA_NONE); 441 return ch_do_scsi(ch, cmd, 10, NULL, 0, DMA_NONE);
442} 442}
443 443
444static int 444static int
@@ -459,7 +459,7 @@ ch_move(scsi_changer *ch, u_int trans, u_int src, u_int dest, int rotate)
459 cmd[6] = (dest >> 8) & 0xff; 459 cmd[6] = (dest >> 8) & 0xff;
460 cmd[7] = dest & 0xff; 460 cmd[7] = dest & 0xff;
461 cmd[10] = rotate ? 1 : 0; 461 cmd[10] = rotate ? 1 : 0;
462 return ch_do_scsi(ch, cmd, NULL,0, DMA_NONE); 462 return ch_do_scsi(ch, cmd, 12, NULL,0, DMA_NONE);
463} 463}
464 464
465static int 465static int
@@ -485,7 +485,7 @@ ch_exchange(scsi_changer *ch, u_int trans, u_int src,
485 cmd[9] = dest2 & 0xff; 485 cmd[9] = dest2 & 0xff;
486 cmd[10] = (rotate1 ? 1 : 0) | (rotate2 ? 2 : 0); 486 cmd[10] = (rotate1 ? 1 : 0) | (rotate2 ? 2 : 0);
487 487
488 return ch_do_scsi(ch, cmd, NULL,0, DMA_NONE); 488 return ch_do_scsi(ch, cmd, 12, NULL, 0, DMA_NONE);
489} 489}
490 490
491static void 491static void
@@ -535,7 +535,7 @@ ch_set_voltag(scsi_changer *ch, u_int elem,
535 memcpy(buffer,tag,32); 535 memcpy(buffer,tag,32);
536 ch_check_voltag(buffer); 536 ch_check_voltag(buffer);
537 537
538 result = ch_do_scsi(ch, cmd, buffer, 256, DMA_TO_DEVICE); 538 result = ch_do_scsi(ch, cmd, 12, buffer, 256, DMA_TO_DEVICE);
539 kfree(buffer); 539 kfree(buffer);
540 return result; 540 return result;
541} 541}
@@ -616,6 +616,11 @@ static long ch_ioctl(struct file *file,
616 int retval; 616 int retval;
617 void __user *argp = (void __user *)arg; 617 void __user *argp = (void __user *)arg;
618 618
619 retval = scsi_ioctl_block_when_processing_errors(ch->device, cmd,
620 file->f_flags & O_NDELAY);
621 if (retval)
622 return retval;
623
619 switch (cmd) { 624 switch (cmd) {
620 case CHIOGPARAMS: 625 case CHIOGPARAMS:
621 { 626 {
@@ -766,7 +771,8 @@ static long ch_ioctl(struct file *file,
766 ch_cmd[5] = 1; 771 ch_cmd[5] = 1;
767 ch_cmd[9] = 255; 772 ch_cmd[9] = 255;
768 773
769 result = ch_do_scsi(ch, ch_cmd, buffer, 256, DMA_FROM_DEVICE); 774 result = ch_do_scsi(ch, ch_cmd, 12,
775 buffer, 256, DMA_FROM_DEVICE);
770 if (!result) { 776 if (!result) {
771 cge.cge_status = buffer[18]; 777 cge.cge_status = buffer[18];
772 cge.cge_flags = 0; 778 cge.cge_flags = 0;
@@ -966,9 +972,9 @@ static int ch_remove(struct device *dev)
966} 972}
967 973
968static struct scsi_driver ch_template = { 974static struct scsi_driver ch_template = {
969 .owner = THIS_MODULE,
970 .gendrv = { 975 .gendrv = {
971 .name = "ch", 976 .name = "ch",
977 .owner = THIS_MODULE,
972 .probe = ch_probe, 978 .probe = ch_probe,
973 .remove = ch_remove, 979 .remove = ch_remove,
974 }, 980 },
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index d35a5d6c8d7c..e2068a2621c4 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -21,15 +21,21 @@
21 21
22 22
23/* Commands with service actions that change the command name */ 23/* Commands with service actions that change the command name */
24#define SERVICE_ACTION_IN_12 0xab
25#define SERVICE_ACTION_OUT_12 0xa9
26#define SERVICE_ACTION_BIDIRECTIONAL 0x9d
27#define SERVICE_ACTION_IN_16 0x9e
28#define SERVICE_ACTION_OUT_16 0x9f
29#define THIRD_PARTY_COPY_OUT 0x83 24#define THIRD_PARTY_COPY_OUT 0x83
30#define THIRD_PARTY_COPY_IN 0x84 25#define THIRD_PARTY_COPY_IN 0x84
31 26
27#define VENDOR_SPECIFIC_CDB 0xc0
32 28
29struct sa_name_list {
30 int opcode;
31 const struct value_name_pair *arr;
32 int arr_sz;
33};
34
35struct value_name_pair {
36 int value;
37 const char * name;
38};
33 39
34#ifdef CONFIG_SCSI_CONSTANTS 40#ifdef CONFIG_SCSI_CONSTANTS
35static const char * cdb_byte0_names[] = { 41static const char * cdb_byte0_names[] = {
@@ -102,11 +108,6 @@ static const char * cdb_byte0_names[] = {
102 "Volume set (out), Send DVD structure", 108 "Volume set (out), Send DVD structure",
103}; 109};
104 110
105struct value_name_pair {
106 int value;
107 const char * name;
108};
109
110static const struct value_name_pair maint_in_arr[] = { 111static const struct value_name_pair maint_in_arr[] = {
111 {0x5, "Report identifying information"}, 112 {0x5, "Report identifying information"},
112 {0xa, "Report target port groups"}, 113 {0xa, "Report target port groups"},
@@ -244,170 +245,119 @@ static const struct value_name_pair variable_length_arr[] = {
244}; 245};
245#define VARIABLE_LENGTH_SZ ARRAY_SIZE(variable_length_arr) 246#define VARIABLE_LENGTH_SZ ARRAY_SIZE(variable_length_arr)
246 247
247static const char * get_sa_name(const struct value_name_pair * arr, 248static struct sa_name_list sa_names_arr[] = {
248 int arr_sz, int service_action) 249 {VARIABLE_LENGTH_CMD, variable_length_arr, VARIABLE_LENGTH_SZ},
249{ 250 {MAINTENANCE_IN, maint_in_arr, MAINT_IN_SZ},
250 int k; 251 {MAINTENANCE_OUT, maint_out_arr, MAINT_OUT_SZ},
252 {PERSISTENT_RESERVE_IN, pr_in_arr, PR_IN_SZ},
253 {PERSISTENT_RESERVE_OUT, pr_out_arr, PR_OUT_SZ},
254 {SERVICE_ACTION_IN_12, serv_in12_arr, SERV_IN12_SZ},
255 {SERVICE_ACTION_OUT_12, serv_out12_arr, SERV_OUT12_SZ},
256 {SERVICE_ACTION_BIDIRECTIONAL, serv_bidi_arr, SERV_BIDI_SZ},
257 {SERVICE_ACTION_IN_16, serv_in16_arr, SERV_IN16_SZ},
258 {SERVICE_ACTION_OUT_16, serv_out16_arr, SERV_OUT16_SZ},
259 {THIRD_PARTY_COPY_IN, tpc_in_arr, TPC_IN_SZ},
260 {THIRD_PARTY_COPY_OUT, tpc_out_arr, TPC_OUT_SZ},
261 {0, NULL, 0},
262};
251 263
252 for (k = 0; k < arr_sz; ++k, ++arr) { 264#else /* ifndef CONFIG_SCSI_CONSTANTS */
253 if (service_action == arr->value) 265static const char *cdb_byte0_names[0];
254 break; 266
255 } 267static struct sa_name_list sa_names_arr[] = {
256 return (k < arr_sz) ? arr->name : NULL; 268 {VARIABLE_LENGTH_CMD, NULL, 0},
257} 269 {MAINTENANCE_IN, NULL, 0},
270 {MAINTENANCE_OUT, NULL, 0},
271 {PERSISTENT_RESERVE_IN, NULL, 0},
272 {PERSISTENT_RESERVE_OUT, NULL, 0},
273 {SERVICE_ACTION_IN_12, NULL, 0},
274 {SERVICE_ACTION_OUT_12, NULL, 0},
275 {SERVICE_ACTION_BIDIRECTIONAL, NULL, 0},
276 {SERVICE_ACTION_IN_16, NULL, 0},
277 {SERVICE_ACTION_OUT_16, NULL, 0},
278 {THIRD_PARTY_COPY_IN, NULL, 0},
279 {THIRD_PARTY_COPY_OUT, NULL, 0},
280 {0, NULL, 0},
281};
282#endif /* CONFIG_SCSI_CONSTANTS */
258 283
259/* attempt to guess cdb length if cdb_len==0 . No trailing linefeed. */ 284static bool scsi_opcode_sa_name(int opcode, int service_action,
260static void print_opcode_name(unsigned char * cdbp, int cdb_len) 285 const char **cdb_name, const char **sa_name)
261{ 286{
262 int sa, len, cdb0; 287 struct sa_name_list *sa_name_ptr;
263 int fin_name = 0; 288 const struct value_name_pair *arr = NULL;
264 const char * name; 289 int arr_sz, k;
265 290
266 cdb0 = cdbp[0]; 291 *cdb_name = NULL;
267 switch(cdb0) { 292 if (opcode >= VENDOR_SPECIFIC_CDB)
268 case VARIABLE_LENGTH_CMD: 293 return false;
269 len = scsi_varlen_cdb_length(cdbp);
270 if (len < 10) {
271 printk("short variable length command, "
272 "len=%d ext_len=%d", len, cdb_len);
273 break;
274 }
275 sa = (cdbp[8] << 8) + cdbp[9];
276 name = get_sa_name(variable_length_arr, VARIABLE_LENGTH_SZ,
277 sa);
278 if (name)
279 printk("%s", name);
280 else
281 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
282 294
283 if ((cdb_len > 0) && (len != cdb_len)) 295 if (opcode < ARRAY_SIZE(cdb_byte0_names))
284 printk(", in_cdb_len=%d, ext_len=%d", len, cdb_len); 296 *cdb_name = cdb_byte0_names[opcode];
285 297
286 break; 298 for (sa_name_ptr = sa_names_arr; sa_name_ptr->arr; ++sa_name_ptr) {
287 case MAINTENANCE_IN: 299 if (sa_name_ptr->opcode == opcode) {
288 sa = cdbp[1] & 0x1f; 300 arr = sa_name_ptr->arr;
289 name = get_sa_name(maint_in_arr, MAINT_IN_SZ, sa); 301 arr_sz = sa_name_ptr->arr_sz;
290 fin_name = 1; 302 break;
291 break; 303 }
292 case MAINTENANCE_OUT:
293 sa = cdbp[1] & 0x1f;
294 name = get_sa_name(maint_out_arr, MAINT_OUT_SZ, sa);
295 fin_name = 1;
296 break;
297 case PERSISTENT_RESERVE_IN:
298 sa = cdbp[1] & 0x1f;
299 name = get_sa_name(pr_in_arr, PR_IN_SZ, sa);
300 fin_name = 1;
301 break;
302 case PERSISTENT_RESERVE_OUT:
303 sa = cdbp[1] & 0x1f;
304 name = get_sa_name(pr_out_arr, PR_OUT_SZ, sa);
305 fin_name = 1;
306 break;
307 case SERVICE_ACTION_IN_12:
308 sa = cdbp[1] & 0x1f;
309 name = get_sa_name(serv_in12_arr, SERV_IN12_SZ, sa);
310 fin_name = 1;
311 break;
312 case SERVICE_ACTION_OUT_12:
313 sa = cdbp[1] & 0x1f;
314 name = get_sa_name(serv_out12_arr, SERV_OUT12_SZ, sa);
315 fin_name = 1;
316 break;
317 case SERVICE_ACTION_BIDIRECTIONAL:
318 sa = cdbp[1] & 0x1f;
319 name = get_sa_name(serv_bidi_arr, SERV_BIDI_SZ, sa);
320 fin_name = 1;
321 break;
322 case SERVICE_ACTION_IN_16:
323 sa = cdbp[1] & 0x1f;
324 name = get_sa_name(serv_in16_arr, SERV_IN16_SZ, sa);
325 fin_name = 1;
326 break;
327 case SERVICE_ACTION_OUT_16:
328 sa = cdbp[1] & 0x1f;
329 name = get_sa_name(serv_out16_arr, SERV_OUT16_SZ, sa);
330 fin_name = 1;
331 break;
332 case THIRD_PARTY_COPY_IN:
333 sa = cdbp[1] & 0x1f;
334 name = get_sa_name(tpc_in_arr, TPC_IN_SZ, sa);
335 fin_name = 1;
336 break;
337 case THIRD_PARTY_COPY_OUT:
338 sa = cdbp[1] & 0x1f;
339 name = get_sa_name(tpc_out_arr, TPC_OUT_SZ, sa);
340 fin_name = 1;
341 break;
342 default:
343 if (cdb0 < 0xc0) {
344 name = cdb_byte0_names[cdb0];
345 if (name)
346 printk("%s", name);
347 else
348 printk("cdb[0]=0x%x (reserved)", cdb0);
349 } else
350 printk("cdb[0]=0x%x (vendor)", cdb0);
351 break;
352 } 304 }
353 if (fin_name) { 305 if (!arr)
354 if (name) 306 return false;
355 printk("%s", name); 307
356 else 308 for (k = 0; k < arr_sz; ++k, ++arr) {
357 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa); 309 if (service_action == arr->value)
310 break;
358 } 311 }
359} 312 if (k < arr_sz)
313 *sa_name = arr->name;
360 314
361#else /* ifndef CONFIG_SCSI_CONSTANTS */ 315 return true;
316}
362 317
363static void print_opcode_name(unsigned char * cdbp, int cdb_len) 318static void print_opcode_name(const unsigned char *cdbp, size_t cdb_len)
364{ 319{
365 int sa, len, cdb0; 320 int sa, cdb0;
321 const char *cdb_name = NULL, *sa_name = NULL;
366 322
367 cdb0 = cdbp[0]; 323 cdb0 = cdbp[0];
368 switch(cdb0) { 324 if (cdb0 == VARIABLE_LENGTH_CMD) {
369 case VARIABLE_LENGTH_CMD: 325 if (cdb_len < 10) {
370 len = scsi_varlen_cdb_length(cdbp); 326 printk("short variable length command, len=%zu",
371 if (len < 10) { 327 cdb_len);
372 printk("short opcode=0x%x command, len=%d " 328 return;
373 "ext_len=%d", cdb0, len, cdb_len);
374 break;
375 } 329 }
376 sa = (cdbp[8] << 8) + cdbp[9]; 330 sa = (cdbp[8] << 8) + cdbp[9];
377 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa); 331 } else
378 if (len != cdb_len)
379 printk(", in_cdb_len=%d, ext_len=%d", len, cdb_len);
380 break;
381 case MAINTENANCE_IN:
382 case MAINTENANCE_OUT:
383 case PERSISTENT_RESERVE_IN:
384 case PERSISTENT_RESERVE_OUT:
385 case SERVICE_ACTION_IN_12:
386 case SERVICE_ACTION_OUT_12:
387 case SERVICE_ACTION_BIDIRECTIONAL:
388 case SERVICE_ACTION_IN_16:
389 case SERVICE_ACTION_OUT_16:
390 case THIRD_PARTY_COPY_IN:
391 case THIRD_PARTY_COPY_OUT:
392 sa = cdbp[1] & 0x1f; 332 sa = cdbp[1] & 0x1f;
393 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa); 333
394 break; 334 if (!scsi_opcode_sa_name(cdb0, sa, &cdb_name, &sa_name)) {
395 default: 335 if (cdb_name)
396 if (cdb0 < 0xc0) 336 printk("%s", cdb_name);
337 else if (cdb0 >= VENDOR_SPECIFIC_CDB)
338 printk("cdb[0]=0x%x (vendor)", cdb0);
339 else if (cdb0 >= 0x60 && cdb0 < 0x7e)
340 printk("cdb[0]=0x%x (reserved)", cdb0);
341 else
397 printk("cdb[0]=0x%x", cdb0); 342 printk("cdb[0]=0x%x", cdb0);
343 } else {
344 if (sa_name)
345 printk("%s", sa_name);
346 else if (cdb_name)
347 printk("%s, sa=0x%x", cdb_name, sa);
398 else 348 else
399 printk("cdb[0]=0x%x (vendor)", cdb0); 349 printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
400 break;
401 } 350 }
402} 351}
403#endif
404 352
405void __scsi_print_command(unsigned char *cdb) 353void __scsi_print_command(const unsigned char *cdb, size_t cdb_len)
406{ 354{
407 int k, len; 355 int k, len;
408 356
409 print_opcode_name(cdb, 0); 357 print_opcode_name(cdb, cdb_len);
410 len = scsi_command_size(cdb); 358 len = scsi_command_size(cdb);
359 if (cdb_len < len)
360 len = cdb_len;
411 /* print out all bytes in cdb */ 361 /* print out all bytes in cdb */
412 for (k = 0; k < len; ++k) 362 for (k = 0; k < len; ++k)
413 printk(" %02x", cdb[k]); 363 printk(" %02x", cdb[k]);
@@ -433,41 +383,6 @@ void scsi_print_command(struct scsi_cmnd *cmd)
433} 383}
434EXPORT_SYMBOL(scsi_print_command); 384EXPORT_SYMBOL(scsi_print_command);
435 385
436/**
437 * scsi_print_status - print scsi status description
438 * @scsi_status: scsi status value
439 *
440 * If the status is recognized, the description is printed.
441 * Otherwise "Unknown status" is output. No trailing space.
442 * If CONFIG_SCSI_CONSTANTS is not set, then print status in hex
443 * (e.g. "0x2" for Check Condition).
444 **/
445void
446scsi_print_status(unsigned char scsi_status) {
447#ifdef CONFIG_SCSI_CONSTANTS
448 const char * ccp;
449
450 switch (scsi_status) {
451 case 0: ccp = "Good"; break;
452 case 0x2: ccp = "Check Condition"; break;
453 case 0x4: ccp = "Condition Met"; break;
454 case 0x8: ccp = "Busy"; break;
455 case 0x10: ccp = "Intermediate"; break;
456 case 0x14: ccp = "Intermediate-Condition Met"; break;
457 case 0x18: ccp = "Reservation Conflict"; break;
458 case 0x22: ccp = "Command Terminated"; break; /* obsolete */
459 case 0x28: ccp = "Task set Full"; break; /* was: Queue Full */
460 case 0x30: ccp = "ACA Active"; break;
461 case 0x40: ccp = "Task Aborted"; break;
462 default: ccp = "Unknown status";
463 }
464 printk(KERN_INFO "%s", ccp);
465#else
466 printk(KERN_INFO "0x%0x", scsi_status);
467#endif
468}
469EXPORT_SYMBOL(scsi_print_status);
470
471#ifdef CONFIG_SCSI_CONSTANTS 386#ifdef CONFIG_SCSI_CONSTANTS
472 387
473struct error_info { 388struct error_info {
@@ -1292,18 +1207,19 @@ static const struct error_info additional[] =
1292 1207
1293struct error_info2 { 1208struct error_info2 {
1294 unsigned char code1, code2_min, code2_max; 1209 unsigned char code1, code2_min, code2_max;
1210 const char * str;
1295 const char * fmt; 1211 const char * fmt;
1296}; 1212};
1297 1213
1298static const struct error_info2 additional2[] = 1214static const struct error_info2 additional2[] =
1299{ 1215{
1300 {0x40, 0x00, 0x7f, "Ram failure (%x)"}, 1216 {0x40, 0x00, 0x7f, "Ram failure", ""},
1301 {0x40, 0x80, 0xff, "Diagnostic failure on component (%x)"}, 1217 {0x40, 0x80, 0xff, "Diagnostic failure on component", ""},
1302 {0x41, 0x00, 0xff, "Data path failure (%x)"}, 1218 {0x41, 0x00, 0xff, "Data path failure", ""},
1303 {0x42, 0x00, 0xff, "Power-on or self-test failure (%x)"}, 1219 {0x42, 0x00, 0xff, "Power-on or self-test failure", ""},
1304 {0x4D, 0x00, 0xff, "Tagged overlapped commands (task tag %x)"}, 1220 {0x4D, 0x00, 0xff, "Tagged overlapped commands", "task tag "},
1305 {0x70, 0x00, 0xff, "Decompression exception short algorithm id of %x"}, 1221 {0x70, 0x00, 0xff, "Decompression exception", "short algorithm id of "},
1306 {0, 0, 0, NULL} 1222 {0, 0, 0, NULL, NULL}
1307}; 1223};
1308 1224
1309/* description of the sense key values */ 1225/* description of the sense key values */
@@ -1349,69 +1265,79 @@ EXPORT_SYMBOL(scsi_sense_key_string);
1349 * This string may contain a "%x" and should be printed with ascq as arg. 1265 * This string may contain a "%x" and should be printed with ascq as arg.
1350 */ 1266 */
1351const char * 1267const char *
1352scsi_extd_sense_format(unsigned char asc, unsigned char ascq) { 1268scsi_extd_sense_format(unsigned char asc, unsigned char ascq, const char **fmt)
1269{
1353#ifdef CONFIG_SCSI_CONSTANTS 1270#ifdef CONFIG_SCSI_CONSTANTS
1354 int i; 1271 int i;
1355 unsigned short code = ((asc << 8) | ascq); 1272 unsigned short code = ((asc << 8) | ascq);
1356 1273
1274 *fmt = NULL;
1357 for (i = 0; additional[i].text; i++) 1275 for (i = 0; additional[i].text; i++)
1358 if (additional[i].code12 == code) 1276 if (additional[i].code12 == code)
1359 return additional[i].text; 1277 return additional[i].text;
1360 for (i = 0; additional2[i].fmt; i++) { 1278 for (i = 0; additional2[i].fmt; i++) {
1361 if (additional2[i].code1 == asc && 1279 if (additional2[i].code1 == asc &&
1362 ascq >= additional2[i].code2_min && 1280 ascq >= additional2[i].code2_min &&
1363 ascq <= additional2[i].code2_max) 1281 ascq <= additional2[i].code2_max) {
1364 return additional2[i].fmt; 1282 *fmt = additional2[i].fmt;
1283 return additional2[i].str;
1284 }
1365 } 1285 }
1286#else
1287 *fmt = NULL;
1366#endif 1288#endif
1367 return NULL; 1289 return NULL;
1368} 1290}
1369EXPORT_SYMBOL(scsi_extd_sense_format); 1291EXPORT_SYMBOL(scsi_extd_sense_format);
1370 1292
1371void 1293void
1372scsi_show_extd_sense(unsigned char asc, unsigned char ascq) 1294scsi_show_extd_sense(const struct scsi_device *sdev, const char *name,
1295 unsigned char asc, unsigned char ascq)
1373{ 1296{
1374 const char *extd_sense_fmt = scsi_extd_sense_format(asc, ascq); 1297 const char *extd_sense_fmt = NULL;
1375 1298 const char *extd_sense_str = scsi_extd_sense_format(asc, ascq,
1376 if (extd_sense_fmt) { 1299 &extd_sense_fmt);
1377 if (strstr(extd_sense_fmt, "%x")) { 1300
1378 printk("Add. Sense: "); 1301 if (extd_sense_str) {
1379 printk(extd_sense_fmt, ascq); 1302 if (extd_sense_fmt)
1380 } else 1303 sdev_prefix_printk(KERN_INFO, sdev, name,
1381 printk("Add. Sense: %s", extd_sense_fmt); 1304 "Add. Sense: %s (%s%x)",
1382 } else { 1305 extd_sense_str, extd_sense_fmt,
1383 if (asc >= 0x80) 1306 ascq);
1384 printk("<<vendor>> ASC=0x%x ASCQ=0x%x", asc,
1385 ascq);
1386 if (ascq >= 0x80)
1387 printk("ASC=0x%x <<vendor>> ASCQ=0x%x", asc,
1388 ascq);
1389 else 1307 else
1390 printk("ASC=0x%x ASCQ=0x%x", asc, ascq); 1308 sdev_prefix_printk(KERN_INFO, sdev, name,
1391 } 1309 "Add. Sense: %s", extd_sense_str);
1392 1310
1393 printk("\n"); 1311 } else {
1312 sdev_prefix_printk(KERN_INFO, sdev, name,
1313 "%sASC=0x%x %sASCQ=0x%x\n",
1314 asc >= 0x80 ? "<<vendor>> " : "", asc,
1315 ascq >= 0x80 ? "<<vendor>> " : "", ascq);
1316 }
1394} 1317}
1395EXPORT_SYMBOL(scsi_show_extd_sense); 1318EXPORT_SYMBOL(scsi_show_extd_sense);
1396 1319
1397void 1320void
1398scsi_show_sense_hdr(struct scsi_sense_hdr *sshdr) 1321scsi_show_sense_hdr(const struct scsi_device *sdev, const char *name,
1322 const struct scsi_sense_hdr *sshdr)
1399{ 1323{
1400 const char *sense_txt; 1324 const char *sense_txt;
1401 1325
1402 sense_txt = scsi_sense_key_string(sshdr->sense_key); 1326 sense_txt = scsi_sense_key_string(sshdr->sense_key);
1403 if (sense_txt) 1327 if (sense_txt)
1404 printk("Sense Key : %s ", sense_txt); 1328 sdev_prefix_printk(KERN_INFO, sdev, name,
1329 "Sense Key : %s [%s]%s\n", sense_txt,
1330 scsi_sense_is_deferred(sshdr) ?
1331 "deferred" : "current",
1332 sshdr->response_code >= 0x72 ?
1333 " [descriptor]" : "");
1405 else 1334 else
1406 printk("Sense Key : 0x%x ", sshdr->sense_key); 1335 sdev_prefix_printk(KERN_INFO, sdev, name,
1407 1336 "Sense Key : 0x%x [%s]%s", sshdr->sense_key,
1408 printk("%s", scsi_sense_is_deferred(sshdr) ? "[deferred] " : 1337 scsi_sense_is_deferred(sshdr) ?
1409 "[current] "); 1338 "deferred" : "current",
1410 1339 sshdr->response_code >= 0x72 ?
1411 if (sshdr->response_code >= 0x72) 1340 " [descriptor]" : "");
1412 printk("[descriptor]");
1413
1414 printk("\n");
1415} 1341}
1416EXPORT_SYMBOL(scsi_show_sense_hdr); 1342EXPORT_SYMBOL(scsi_show_sense_hdr);
1417 1343
@@ -1419,141 +1345,55 @@ EXPORT_SYMBOL(scsi_show_sense_hdr);
1419 * Print normalized SCSI sense header with a prefix. 1345 * Print normalized SCSI sense header with a prefix.
1420 */ 1346 */
1421void 1347void
1422scsi_print_sense_hdr(const char *name, struct scsi_sense_hdr *sshdr) 1348scsi_print_sense_hdr(const struct scsi_device *sdev, const char *name,
1349 const struct scsi_sense_hdr *sshdr)
1423{ 1350{
1424 printk(KERN_INFO "%s: ", name); 1351 scsi_show_sense_hdr(sdev, name, sshdr);
1425 scsi_show_sense_hdr(sshdr); 1352 scsi_show_extd_sense(sdev, name, sshdr->asc, sshdr->ascq);
1426 printk(KERN_INFO "%s: ", name);
1427 scsi_show_extd_sense(sshdr->asc, sshdr->ascq);
1428} 1353}
1429EXPORT_SYMBOL(scsi_print_sense_hdr); 1354EXPORT_SYMBOL(scsi_print_sense_hdr);
1430 1355
1431/*
1432 * Print normalized SCSI sense header with device information and a prefix.
1433 */
1434void
1435scsi_cmd_print_sense_hdr(struct scsi_cmnd *scmd, const char *desc,
1436 struct scsi_sense_hdr *sshdr)
1437{
1438 scmd_printk(KERN_INFO, scmd, "%s: ", desc);
1439 scsi_show_sense_hdr(sshdr);
1440 scmd_printk(KERN_INFO, scmd, "%s: ", desc);
1441 scsi_show_extd_sense(sshdr->asc, sshdr->ascq);
1442}
1443EXPORT_SYMBOL(scsi_cmd_print_sense_hdr);
1444
1445static void 1356static void
1446scsi_decode_sense_buffer(const unsigned char *sense_buffer, int sense_len, 1357scsi_dump_sense_buffer(const unsigned char *sense_buffer, int sense_len)
1447 struct scsi_sense_hdr *sshdr)
1448{ 1358{
1449 int k, num, res; 1359 int k, num;
1450 1360
1451 res = scsi_normalize_sense(sense_buffer, sense_len, sshdr); 1361 num = (sense_len < 32) ? sense_len : 32;
1452 if (0 == res) { 1362 printk("Unrecognized sense data (in hex):");
1453 /* this may be SCSI-1 sense data */ 1363 for (k = 0; k < num; ++k) {
1454 num = (sense_len < 32) ? sense_len : 32; 1364 if (0 == (k % 16)) {
1455 printk("Unrecognized sense data (in hex):"); 1365 printk("\n");
1456 for (k = 0; k < num; ++k) { 1366 printk(KERN_INFO " ");
1457 if (0 == (k % 16)) {
1458 printk("\n");
1459 printk(KERN_INFO " ");
1460 }
1461 printk("%02x ", sense_buffer[k]);
1462 } 1367 }
1463 printk("\n"); 1368 printk("%02x ", sense_buffer[k]);
1464 return;
1465 } 1369 }
1466} 1370 printk("\n");
1467 1371 return;
1468static void
1469scsi_decode_sense_extras(const unsigned char *sense_buffer, int sense_len,
1470 struct scsi_sense_hdr *sshdr)
1471{
1472 int k, num, res;
1473
1474 if (sshdr->response_code < 0x72)
1475 {
1476 /* only decode extras for "fixed" format now */
1477 char buff[80];
1478 int blen, fixed_valid;
1479 unsigned int info;
1480
1481 fixed_valid = sense_buffer[0] & 0x80;
1482 info = ((sense_buffer[3] << 24) | (sense_buffer[4] << 16) |
1483 (sense_buffer[5] << 8) | sense_buffer[6]);
1484 res = 0;
1485 memset(buff, 0, sizeof(buff));
1486 blen = sizeof(buff) - 1;
1487 if (fixed_valid)
1488 res += snprintf(buff + res, blen - res,
1489 "Info fld=0x%x", info);
1490 if (sense_buffer[2] & 0x80) {
1491 /* current command has read a filemark */
1492 if (res > 0)
1493 res += snprintf(buff + res, blen - res, ", ");
1494 res += snprintf(buff + res, blen - res, "FMK");
1495 }
1496 if (sense_buffer[2] & 0x40) {
1497 /* end-of-medium condition exists */
1498 if (res > 0)
1499 res += snprintf(buff + res, blen - res, ", ");
1500 res += snprintf(buff + res, blen - res, "EOM");
1501 }
1502 if (sense_buffer[2] & 0x20) {
1503 /* incorrect block length requested */
1504 if (res > 0)
1505 res += snprintf(buff + res, blen - res, ", ");
1506 res += snprintf(buff + res, blen - res, "ILI");
1507 }
1508 if (res > 0)
1509 printk("%s\n", buff);
1510 } else if (sshdr->additional_length > 0) {
1511 /* descriptor format with sense descriptors */
1512 num = 8 + sshdr->additional_length;
1513 num = (sense_len < num) ? sense_len : num;
1514 printk("Descriptor sense data with sense descriptors "
1515 "(in hex):");
1516 for (k = 0; k < num; ++k) {
1517 if (0 == (k % 16)) {
1518 printk("\n");
1519 printk(KERN_INFO " ");
1520 }
1521 printk("%02x ", sense_buffer[k]);
1522 }
1523
1524 printk("\n");
1525 }
1526
1527} 1372}
1528 1373
1529/* Normalize and print sense buffer with name prefix */ 1374/* Normalize and print sense buffer with name prefix */
1530void __scsi_print_sense(const char *name, const unsigned char *sense_buffer, 1375void __scsi_print_sense(const struct scsi_device *sdev, const char *name,
1531 int sense_len) 1376 const unsigned char *sense_buffer, int sense_len)
1532{ 1377{
1533 struct scsi_sense_hdr sshdr; 1378 struct scsi_sense_hdr sshdr;
1534 1379
1535 printk(KERN_INFO "%s: ", name); 1380 if (!scsi_normalize_sense(sense_buffer, sense_len, &sshdr)) {
1536 scsi_decode_sense_buffer(sense_buffer, sense_len, &sshdr); 1381 scsi_dump_sense_buffer(sense_buffer, sense_len);
1537 scsi_show_sense_hdr(&sshdr); 1382 return;
1538 scsi_decode_sense_extras(sense_buffer, sense_len, &sshdr); 1383 }
1539 printk(KERN_INFO "%s: ", name); 1384 scsi_show_sense_hdr(sdev, name, &sshdr);
1540 scsi_show_extd_sense(sshdr.asc, sshdr.ascq); 1385 scsi_show_extd_sense(sdev, name, sshdr.asc, sshdr.ascq);
1541} 1386}
1542EXPORT_SYMBOL(__scsi_print_sense); 1387EXPORT_SYMBOL(__scsi_print_sense);
1543 1388
1544/* Normalize and print sense buffer in SCSI command */ 1389/* Normalize and print sense buffer in SCSI command */
1545void scsi_print_sense(char *name, struct scsi_cmnd *cmd) 1390void scsi_print_sense(const struct scsi_cmnd *cmd)
1546{ 1391{
1547 struct scsi_sense_hdr sshdr; 1392 struct gendisk *disk = cmd->request->rq_disk;
1393 const char *disk_name = disk ? disk->disk_name : NULL;
1548 1394
1549 scmd_printk(KERN_INFO, cmd, " "); 1395 __scsi_print_sense(cmd->device, disk_name, cmd->sense_buffer,
1550 scsi_decode_sense_buffer(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE, 1396 SCSI_SENSE_BUFFERSIZE);
1551 &sshdr);
1552 scsi_show_sense_hdr(&sshdr);
1553 scsi_decode_sense_extras(cmd->sense_buffer, SCSI_SENSE_BUFFERSIZE,
1554 &sshdr);
1555 scmd_printk(KERN_INFO, cmd, " ");
1556 scsi_show_extd_sense(sshdr.asc, sshdr.ascq);
1557} 1397}
1558EXPORT_SYMBOL(scsi_print_sense); 1398EXPORT_SYMBOL(scsi_print_sense);
1559 1399
@@ -1565,38 +1405,87 @@ static const char * const hostbyte_table[]={
1565"DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", "DID_REQUEUE", 1405"DID_PASSTHROUGH", "DID_SOFT_ERROR", "DID_IMM_RETRY", "DID_REQUEUE",
1566"DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE", 1406"DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE",
1567"DID_NEXUS_FAILURE" }; 1407"DID_NEXUS_FAILURE" };
1568#define NUM_HOSTBYTE_STRS ARRAY_SIZE(hostbyte_table)
1569 1408
1570static const char * const driverbyte_table[]={ 1409static const char * const driverbyte_table[]={
1571"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR", 1410"DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR",
1572"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"}; 1411"DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"};
1573#define NUM_DRIVERBYTE_STRS ARRAY_SIZE(driverbyte_table)
1574 1412
1575void scsi_show_result(int result) 1413#endif
1414
1415const char *scsi_hostbyte_string(int result)
1576{ 1416{
1417 const char *hb_string = NULL;
1418#ifdef CONFIG_SCSI_CONSTANTS
1577 int hb = host_byte(result); 1419 int hb = host_byte(result);
1578 int db = driver_byte(result);
1579 1420
1580 printk("Result: hostbyte=%s driverbyte=%s\n", 1421 if (hb < ARRAY_SIZE(hostbyte_table))
1581 (hb < NUM_HOSTBYTE_STRS ? hostbyte_table[hb] : "invalid"), 1422 hb_string = hostbyte_table[hb];
1582 (db < NUM_DRIVERBYTE_STRS ? driverbyte_table[db] : "invalid")); 1423#endif
1424 return hb_string;
1583} 1425}
1426EXPORT_SYMBOL(scsi_hostbyte_string);
1584 1427
1585#else 1428const char *scsi_driverbyte_string(int result)
1586
1587void scsi_show_result(int result)
1588{ 1429{
1589 printk("Result: hostbyte=0x%02x driverbyte=0x%02x\n", 1430 const char *db_string = NULL;
1590 host_byte(result), driver_byte(result)); 1431#ifdef CONFIG_SCSI_CONSTANTS
1432 int db = driver_byte(result);
1433
1434 if (db < ARRAY_SIZE(driverbyte_table))
1435 db_string = driverbyte_table[db];
1436#endif
1437 return db_string;
1591} 1438}
1439EXPORT_SYMBOL(scsi_driverbyte_string);
1592 1440
1441#ifdef CONFIG_SCSI_CONSTANTS
1442#define scsi_mlreturn_name(result) { result, #result }
1443static const struct value_name_pair scsi_mlreturn_arr[] = {
1444 scsi_mlreturn_name(NEEDS_RETRY),
1445 scsi_mlreturn_name(SUCCESS),
1446 scsi_mlreturn_name(FAILED),
1447 scsi_mlreturn_name(QUEUED),
1448 scsi_mlreturn_name(SOFT_ERROR),
1449 scsi_mlreturn_name(ADD_TO_MLQUEUE),
1450 scsi_mlreturn_name(TIMEOUT_ERROR),
1451 scsi_mlreturn_name(SCSI_RETURN_NOT_HANDLED),
1452 scsi_mlreturn_name(FAST_IO_FAIL)
1453};
1593#endif 1454#endif
1594EXPORT_SYMBOL(scsi_show_result);
1595 1455
1456const char *scsi_mlreturn_string(int result)
1457{
1458#ifdef CONFIG_SCSI_CONSTANTS
1459 const struct value_name_pair *arr = scsi_mlreturn_arr;
1460 int k;
1596 1461
1597void scsi_print_result(struct scsi_cmnd *cmd) 1462 for (k = 0; k < ARRAY_SIZE(scsi_mlreturn_arr); ++k, ++arr) {
1463 if (result == arr->value)
1464 return arr->name;
1465 }
1466#endif
1467 return NULL;
1468}
1469EXPORT_SYMBOL(scsi_mlreturn_string);
1470
1471void scsi_print_result(struct scsi_cmnd *cmd, const char *msg, int disposition)
1598{ 1472{
1599 scmd_printk(KERN_INFO, cmd, " "); 1473 const char *mlret_string = scsi_mlreturn_string(disposition);
1600 scsi_show_result(cmd->result); 1474 const char *hb_string = scsi_hostbyte_string(cmd->result);
1475 const char *db_string = scsi_driverbyte_string(cmd->result);
1476
1477 if (hb_string || db_string)
1478 scmd_printk(KERN_INFO, cmd,
1479 "%s%s Result: hostbyte=%s driverbyte=%s",
1480 msg ? msg : "",
1481 mlret_string ? mlret_string : "UNKNOWN",
1482 hb_string ? hb_string : "invalid",
1483 db_string ? db_string : "invalid");
1484 else
1485 scmd_printk(KERN_INFO, cmd,
1486 "%s%s Result: hostbyte=0x%02x driverbyte=0x%02x",
1487 msg ? msg : "",
1488 mlret_string ? mlret_string : "UNKNOWN",
1489 host_byte(cmd->result), driver_byte(cmd->result));
1601} 1490}
1602EXPORT_SYMBOL(scsi_print_result); 1491EXPORT_SYMBOL(scsi_print_result);
diff --git a/drivers/scsi/csiostor/csio_scsi.c b/drivers/scsi/csiostor/csio_scsi.c
index 86103c8475d8..4d0b6ce55f20 100644
--- a/drivers/scsi/csiostor/csio_scsi.c
+++ b/drivers/scsi/csiostor/csio_scsi.c
@@ -152,28 +152,6 @@ csio_scsi_itnexus_loss_error(uint16_t error)
152 return 0; 152 return 0;
153} 153}
154 154
155static inline void
156csio_scsi_tag(struct scsi_cmnd *scmnd, uint8_t *tag, uint8_t hq,
157 uint8_t oq, uint8_t sq)
158{
159 char stag[2];
160
161 if (scsi_populate_tag_msg(scmnd, stag)) {
162 switch (stag[0]) {
163 case HEAD_OF_QUEUE_TAG:
164 *tag = hq;
165 break;
166 case ORDERED_QUEUE_TAG:
167 *tag = oq;
168 break;
169 default:
170 *tag = sq;
171 break;
172 }
173 } else
174 *tag = 0;
175}
176
177/* 155/*
178 * csio_scsi_fcp_cmnd - Frame the SCSI FCP command paylod. 156 * csio_scsi_fcp_cmnd - Frame the SCSI FCP command paylod.
179 * @req: IO req structure. 157 * @req: IO req structure.
@@ -192,11 +170,12 @@ csio_scsi_fcp_cmnd(struct csio_ioreq *req, void *addr)
192 int_to_scsilun(scmnd->device->lun, &fcp_cmnd->fc_lun); 170 int_to_scsilun(scmnd->device->lun, &fcp_cmnd->fc_lun);
193 fcp_cmnd->fc_tm_flags = 0; 171 fcp_cmnd->fc_tm_flags = 0;
194 fcp_cmnd->fc_cmdref = 0; 172 fcp_cmnd->fc_cmdref = 0;
195 fcp_cmnd->fc_pri_ta = 0;
196 173
197 memcpy(fcp_cmnd->fc_cdb, scmnd->cmnd, 16); 174 memcpy(fcp_cmnd->fc_cdb, scmnd->cmnd, 16);
198 csio_scsi_tag(scmnd, &fcp_cmnd->fc_pri_ta, 175 if (scmnd->flags & SCMD_TAGGED)
199 FCP_PTA_HEADQ, FCP_PTA_ORDERED, FCP_PTA_SIMPLE); 176 fcp_cmnd->fc_pri_ta = FCP_PTA_SIMPLE;
177 else
178 fcp_cmnd->fc_pri_ta = 0;
200 fcp_cmnd->fc_dl = cpu_to_be32(scsi_bufflen(scmnd)); 179 fcp_cmnd->fc_dl = cpu_to_be32(scsi_bufflen(scmnd));
201 180
202 if (req->nsge) 181 if (req->nsge)
@@ -2262,11 +2241,7 @@ csio_slave_alloc(struct scsi_device *sdev)
2262static int 2241static int
2263csio_slave_configure(struct scsi_device *sdev) 2242csio_slave_configure(struct scsi_device *sdev)
2264{ 2243{
2265 if (sdev->tagged_supported) 2244 scsi_change_queue_depth(sdev, csio_lun_qdepth);
2266 scsi_activate_tcq(sdev, csio_lun_qdepth);
2267 else
2268 scsi_deactivate_tcq(sdev, csio_lun_qdepth);
2269
2270 return 0; 2245 return 0;
2271} 2246}
2272 2247
@@ -2311,6 +2286,7 @@ struct scsi_host_template csio_fcoe_shost_template = {
2311 .use_clustering = ENABLE_CLUSTERING, 2286 .use_clustering = ENABLE_CLUSTERING,
2312 .shost_attrs = csio_fcoe_lport_attrs, 2287 .shost_attrs = csio_fcoe_lport_attrs,
2313 .max_sectors = CSIO_MAX_SECTOR_SIZE, 2288 .max_sectors = CSIO_MAX_SECTOR_SIZE,
2289 .use_blk_tags = 1,
2314}; 2290};
2315 2291
2316struct scsi_host_template csio_fcoe_shost_vport_template = { 2292struct scsi_host_template csio_fcoe_shost_vport_template = {
@@ -2330,6 +2306,7 @@ struct scsi_host_template csio_fcoe_shost_vport_template = {
2330 .use_clustering = ENABLE_CLUSTERING, 2306 .use_clustering = ENABLE_CLUSTERING,
2331 .shost_attrs = csio_fcoe_vport_attrs, 2307 .shost_attrs = csio_fcoe_vport_attrs,
2332 .max_sectors = CSIO_MAX_SECTOR_SIZE, 2308 .max_sectors = CSIO_MAX_SECTOR_SIZE,
2309 .use_blk_tags = 1,
2333}; 2310};
2334 2311
2335/* 2312/*
diff --git a/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c b/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c
index 49692a1ac44a..3db4c63978c5 100644
--- a/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c
+++ b/drivers/scsi/cxgbi/cxgb3i/cxgb3i.c
@@ -86,7 +86,7 @@ static struct scsi_host_template cxgb3i_host_template = {
86 .proc_name = DRV_MODULE_NAME, 86 .proc_name = DRV_MODULE_NAME,
87 .can_queue = CXGB3I_SCSI_HOST_QDEPTH, 87 .can_queue = CXGB3I_SCSI_HOST_QDEPTH,
88 .queuecommand = iscsi_queuecommand, 88 .queuecommand = iscsi_queuecommand,
89 .change_queue_depth = iscsi_change_queue_depth, 89 .change_queue_depth = scsi_change_queue_depth,
90 .sg_tablesize = SG_ALL, 90 .sg_tablesize = SG_ALL,
91 .max_sectors = 0xFFFF, 91 .max_sectors = 0xFFFF,
92 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN, 92 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
@@ -96,6 +96,7 @@ static struct scsi_host_template cxgb3i_host_template = {
96 .target_alloc = iscsi_target_alloc, 96 .target_alloc = iscsi_target_alloc,
97 .use_clustering = DISABLE_CLUSTERING, 97 .use_clustering = DISABLE_CLUSTERING,
98 .this_id = -1, 98 .this_id = -1,
99 .track_queue_depth = 1,
99}; 100};
100 101
101static struct iscsi_transport cxgb3i_iscsi_transport = { 102static struct iscsi_transport cxgb3i_iscsi_transport = {
diff --git a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
index 3e0a0d315f72..e6c3f55d9d36 100644
--- a/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
+++ b/drivers/scsi/cxgbi/cxgb4i/cxgb4i.c
@@ -89,7 +89,7 @@ static struct scsi_host_template cxgb4i_host_template = {
89 .proc_name = DRV_MODULE_NAME, 89 .proc_name = DRV_MODULE_NAME,
90 .can_queue = CXGB4I_SCSI_HOST_QDEPTH, 90 .can_queue = CXGB4I_SCSI_HOST_QDEPTH,
91 .queuecommand = iscsi_queuecommand, 91 .queuecommand = iscsi_queuecommand,
92 .change_queue_depth = iscsi_change_queue_depth, 92 .change_queue_depth = scsi_change_queue_depth,
93 .sg_tablesize = SG_ALL, 93 .sg_tablesize = SG_ALL,
94 .max_sectors = 0xFFFF, 94 .max_sectors = 0xFFFF,
95 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN, 95 .cmd_per_lun = ISCSI_DEF_CMD_PER_LUN,
@@ -99,6 +99,7 @@ static struct scsi_host_template cxgb4i_host_template = {
99 .target_alloc = iscsi_target_alloc, 99 .target_alloc = iscsi_target_alloc,
100 .use_clustering = DISABLE_CLUSTERING, 100 .use_clustering = DISABLE_CLUSTERING,
101 .this_id = -1, 101 .this_id = -1,
102 .track_queue_depth = 1,
102}; 103};
103 104
104static struct iscsi_transport cxgb4i_iscsi_transport = { 105static struct iscsi_transport cxgb4i_iscsi_transport = {
@@ -828,6 +829,8 @@ static void do_act_open_rpl(struct cxgbi_device *cdev, struct sk_buff *skb)
828 if (status == CPL_ERR_RTX_NEG_ADVICE) 829 if (status == CPL_ERR_RTX_NEG_ADVICE)
829 goto rel_skb; 830 goto rel_skb;
830 831
832 module_put(THIS_MODULE);
833
831 if (status && status != CPL_ERR_TCAM_FULL && 834 if (status && status != CPL_ERR_TCAM_FULL &&
832 status != CPL_ERR_CONN_EXIST && 835 status != CPL_ERR_CONN_EXIST &&
833 status != CPL_ERR_ARP_MISS) 836 status != CPL_ERR_ARP_MISS)
@@ -936,20 +939,23 @@ static void do_abort_req_rss(struct cxgbi_device *cdev, struct sk_buff *skb)
936 cxgbi_sock_get(csk); 939 cxgbi_sock_get(csk);
937 spin_lock_bh(&csk->lock); 940 spin_lock_bh(&csk->lock);
938 941
939 if (!cxgbi_sock_flag(csk, CTPF_ABORT_REQ_RCVD)) { 942 cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD);
940 cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD); 943
941 cxgbi_sock_set_state(csk, CTP_ABORTING); 944 if (!cxgbi_sock_flag(csk, CTPF_TX_DATA_SENT)) {
942 goto done; 945 send_tx_flowc_wr(csk);
946 cxgbi_sock_set_flag(csk, CTPF_TX_DATA_SENT);
943 } 947 }
944 948
945 cxgbi_sock_clear_flag(csk, CTPF_ABORT_REQ_RCVD); 949 cxgbi_sock_set_flag(csk, CTPF_ABORT_REQ_RCVD);
950 cxgbi_sock_set_state(csk, CTP_ABORTING);
951
946 send_abort_rpl(csk, rst_status); 952 send_abort_rpl(csk, rst_status);
947 953
948 if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) { 954 if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
949 csk->err = abort_status_to_errno(csk, req->status, &rst_status); 955 csk->err = abort_status_to_errno(csk, req->status, &rst_status);
950 cxgbi_sock_closed(csk); 956 cxgbi_sock_closed(csk);
951 } 957 }
952done: 958
953 spin_unlock_bh(&csk->lock); 959 spin_unlock_bh(&csk->lock);
954 cxgbi_sock_put(csk); 960 cxgbi_sock_put(csk);
955rel_skb: 961rel_skb:
diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c
index 674d498b46ab..7da59c38a69e 100644
--- a/drivers/scsi/cxgbi/libcxgbi.c
+++ b/drivers/scsi/cxgbi/libcxgbi.c
@@ -816,7 +816,7 @@ static void cxgbi_inform_iscsi_conn_closing(struct cxgbi_sock *csk)
816 read_lock_bh(&csk->callback_lock); 816 read_lock_bh(&csk->callback_lock);
817 if (csk->user_data) 817 if (csk->user_data)
818 iscsi_conn_failure(csk->user_data, 818 iscsi_conn_failure(csk->user_data,
819 ISCSI_ERR_CONN_FAILED); 819 ISCSI_ERR_TCP_CONN_CLOSE);
820 read_unlock_bh(&csk->callback_lock); 820 read_unlock_bh(&csk->callback_lock);
821 } 821 }
822} 822}
@@ -905,18 +905,16 @@ void cxgbi_sock_rcv_abort_rpl(struct cxgbi_sock *csk)
905{ 905{
906 cxgbi_sock_get(csk); 906 cxgbi_sock_get(csk);
907 spin_lock_bh(&csk->lock); 907 spin_lock_bh(&csk->lock);
908
909 cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_RCVD);
908 if (cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) { 910 if (cxgbi_sock_flag(csk, CTPF_ABORT_RPL_PENDING)) {
909 if (!cxgbi_sock_flag(csk, CTPF_ABORT_RPL_RCVD)) 911 cxgbi_sock_clear_flag(csk, CTPF_ABORT_RPL_PENDING);
910 cxgbi_sock_set_flag(csk, CTPF_ABORT_RPL_RCVD); 912 if (cxgbi_sock_flag(csk, CTPF_ABORT_REQ_RCVD))
911 else { 913 pr_err("csk 0x%p,%u,0x%lx,%u,ABT_RPL_RSS.\n",
912 cxgbi_sock_clear_flag(csk, CTPF_ABORT_RPL_RCVD); 914 csk, csk->state, csk->flags, csk->tid);
913 cxgbi_sock_clear_flag(csk, CTPF_ABORT_RPL_PENDING); 915 cxgbi_sock_closed(csk);
914 if (cxgbi_sock_flag(csk, CTPF_ABORT_REQ_RCVD))
915 pr_err("csk 0x%p,%u,0x%lx,%u,ABT_RPL_RSS.\n",
916 csk, csk->state, csk->flags, csk->tid);
917 cxgbi_sock_closed(csk);
918 }
919 } 916 }
917
920 spin_unlock_bh(&csk->lock); 918 spin_unlock_bh(&csk->lock);
921 cxgbi_sock_put(csk); 919 cxgbi_sock_put(csk);
922} 920}
diff --git a/drivers/scsi/device_handler/scsi_dh.c b/drivers/scsi/device_handler/scsi_dh.c
index 33e422e75835..1dba62c5cf6a 100644
--- a/drivers/scsi/device_handler/scsi_dh.c
+++ b/drivers/scsi/device_handler/scsi_dh.c
@@ -98,27 +98,51 @@ device_handler_match(struct scsi_device_handler *scsi_dh,
98static int scsi_dh_handler_attach(struct scsi_device *sdev, 98static int scsi_dh_handler_attach(struct scsi_device *sdev,
99 struct scsi_device_handler *scsi_dh) 99 struct scsi_device_handler *scsi_dh)
100{ 100{
101 int err = 0; 101 struct scsi_dh_data *d;
102 102
103 if (sdev->scsi_dh_data) { 103 if (sdev->scsi_dh_data) {
104 if (sdev->scsi_dh_data->scsi_dh != scsi_dh) 104 if (sdev->scsi_dh_data->scsi_dh != scsi_dh)
105 err = -EBUSY; 105 return -EBUSY;
106 else 106
107 kref_get(&sdev->scsi_dh_data->kref); 107 kref_get(&sdev->scsi_dh_data->kref);
108 } else if (scsi_dh->attach) { 108 return 0;
109 err = scsi_dh->attach(sdev);
110 if (!err) {
111 kref_init(&sdev->scsi_dh_data->kref);
112 sdev->scsi_dh_data->sdev = sdev;
113 }
114 } 109 }
115 return err; 110
111 if (!try_module_get(scsi_dh->module))
112 return -EINVAL;
113
114 d = scsi_dh->attach(sdev);
115 if (IS_ERR(d)) {
116 sdev_printk(KERN_ERR, sdev, "%s: Attach failed (%ld)\n",
117 scsi_dh->name, PTR_ERR(d));
118 module_put(scsi_dh->module);
119 return PTR_ERR(d);
120 }
121
122 d->scsi_dh = scsi_dh;
123 kref_init(&d->kref);
124 d->sdev = sdev;
125
126 spin_lock_irq(sdev->request_queue->queue_lock);
127 sdev->scsi_dh_data = d;
128 spin_unlock_irq(sdev->request_queue->queue_lock);
129 return 0;
116} 130}
117 131
118static void __detach_handler (struct kref *kref) 132static void __detach_handler (struct kref *kref)
119{ 133{
120 struct scsi_dh_data *scsi_dh_data = container_of(kref, struct scsi_dh_data, kref); 134 struct scsi_dh_data *scsi_dh_data =
121 scsi_dh_data->scsi_dh->detach(scsi_dh_data->sdev); 135 container_of(kref, struct scsi_dh_data, kref);
136 struct scsi_device_handler *scsi_dh = scsi_dh_data->scsi_dh;
137 struct scsi_device *sdev = scsi_dh_data->sdev;
138
139 spin_lock_irq(sdev->request_queue->queue_lock);
140 sdev->scsi_dh_data = NULL;
141 spin_unlock_irq(sdev->request_queue->queue_lock);
142
143 scsi_dh->detach(sdev);
144 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", scsi_dh->name);
145 module_put(scsi_dh->module);
122} 146}
123 147
124/* 148/*
@@ -141,7 +165,7 @@ static void scsi_dh_handler_detach(struct scsi_device *sdev,
141 if (!scsi_dh) 165 if (!scsi_dh)
142 scsi_dh = sdev->scsi_dh_data->scsi_dh; 166 scsi_dh = sdev->scsi_dh_data->scsi_dh;
143 167
144 if (scsi_dh && scsi_dh->detach) 168 if (scsi_dh)
145 kref_put(&sdev->scsi_dh_data->kref, __detach_handler); 169 kref_put(&sdev->scsi_dh_data->kref, __detach_handler);
146} 170}
147 171
@@ -330,6 +354,9 @@ int scsi_register_device_handler(struct scsi_device_handler *scsi_dh)
330 if (get_device_handler(scsi_dh->name)) 354 if (get_device_handler(scsi_dh->name))
331 return -EBUSY; 355 return -EBUSY;
332 356
357 if (!scsi_dh->attach || !scsi_dh->detach)
358 return -EINVAL;
359
333 spin_lock(&list_lock); 360 spin_lock(&list_lock);
334 list_add(&scsi_dh->list, &scsi_dh_list); 361 list_add(&scsi_dh->list, &scsi_dh_list);
335 spin_unlock(&list_lock); 362 spin_unlock(&list_lock);
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index e99507ed0e3c..854b568b9931 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -62,6 +62,7 @@
62#define ALUA_OPTIMIZE_STPG 1 62#define ALUA_OPTIMIZE_STPG 1
63 63
64struct alua_dh_data { 64struct alua_dh_data {
65 struct scsi_dh_data dh_data;
65 int group_id; 66 int group_id;
66 int rel_port; 67 int rel_port;
67 int tpgs; 68 int tpgs;
@@ -87,9 +88,7 @@ static int alua_check_sense(struct scsi_device *, struct scsi_sense_hdr *);
87 88
88static inline struct alua_dh_data *get_alua_data(struct scsi_device *sdev) 89static inline struct alua_dh_data *get_alua_data(struct scsi_device *sdev)
89{ 90{
90 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 91 return container_of(sdev->scsi_dh_data, struct alua_dh_data, dh_data);
91 BUG_ON(scsi_dh_data == NULL);
92 return ((struct alua_dh_data *) scsi_dh_data->buf);
93} 92}
94 93
95static int realloc_buffer(struct alua_dh_data *h, unsigned len) 94static int realloc_buffer(struct alua_dh_data *h, unsigned len)
@@ -474,6 +473,13 @@ static int alua_check_sense(struct scsi_device *sdev,
474 * LUN Not Ready -- Offline 473 * LUN Not Ready -- Offline
475 */ 474 */
476 return SUCCESS; 475 return SUCCESS;
476 if (sdev->allow_restart &&
477 sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x02)
478 /*
479 * if the device is not started, we need to wake
480 * the error handler to start the motor
481 */
482 return FAILED;
477 break; 483 break;
478 case UNIT_ATTENTION: 484 case UNIT_ATTENTION:
479 if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00) 485 if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00)
@@ -818,42 +824,18 @@ static bool alua_match(struct scsi_device *sdev)
818 return (scsi_device_tpgs(sdev) != 0); 824 return (scsi_device_tpgs(sdev) != 0);
819} 825}
820 826
821static int alua_bus_attach(struct scsi_device *sdev);
822static void alua_bus_detach(struct scsi_device *sdev);
823
824static struct scsi_device_handler alua_dh = {
825 .name = ALUA_DH_NAME,
826 .module = THIS_MODULE,
827 .attach = alua_bus_attach,
828 .detach = alua_bus_detach,
829 .prep_fn = alua_prep_fn,
830 .check_sense = alua_check_sense,
831 .activate = alua_activate,
832 .set_params = alua_set_params,
833 .match = alua_match,
834};
835
836/* 827/*
837 * alua_bus_attach - Attach device handler 828 * alua_bus_attach - Attach device handler
838 * @sdev: device to be attached to 829 * @sdev: device to be attached to
839 */ 830 */
840static int alua_bus_attach(struct scsi_device *sdev) 831static struct scsi_dh_data *alua_bus_attach(struct scsi_device *sdev)
841{ 832{
842 struct scsi_dh_data *scsi_dh_data;
843 struct alua_dh_data *h; 833 struct alua_dh_data *h;
844 unsigned long flags; 834 int err;
845 int err = SCSI_DH_OK;
846
847 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data)
848 + sizeof(*h) , GFP_KERNEL);
849 if (!scsi_dh_data) {
850 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
851 ALUA_DH_NAME);
852 return -ENOMEM;
853 }
854 835
855 scsi_dh_data->scsi_dh = &alua_dh; 836 h = kzalloc(sizeof(*h) , GFP_KERNEL);
856 h = (struct alua_dh_data *) scsi_dh_data->buf; 837 if (!h)
838 return ERR_PTR(-ENOMEM);
857 h->tpgs = TPGS_MODE_UNINITIALIZED; 839 h->tpgs = TPGS_MODE_UNINITIALIZED;
858 h->state = TPGS_STATE_OPTIMIZED; 840 h->state = TPGS_STATE_OPTIMIZED;
859 h->group_id = -1; 841 h->group_id = -1;
@@ -863,23 +845,14 @@ static int alua_bus_attach(struct scsi_device *sdev)
863 h->sdev = sdev; 845 h->sdev = sdev;
864 846
865 err = alua_initialize(sdev, h); 847 err = alua_initialize(sdev, h);
866 if ((err != SCSI_DH_OK) && (err != SCSI_DH_DEV_OFFLINED)) 848 if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED)
867 goto failed; 849 goto failed;
868 850
869 if (!try_module_get(THIS_MODULE))
870 goto failed;
871
872 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
873 sdev->scsi_dh_data = scsi_dh_data;
874 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
875 sdev_printk(KERN_NOTICE, sdev, "%s: Attached\n", ALUA_DH_NAME); 851 sdev_printk(KERN_NOTICE, sdev, "%s: Attached\n", ALUA_DH_NAME);
876 852 return &h->dh_data;
877 return 0;
878
879failed: 853failed:
880 kfree(scsi_dh_data); 854 kfree(h);
881 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", ALUA_DH_NAME); 855 return ERR_PTR(-EINVAL);
882 return -EINVAL;
883} 856}
884 857
885/* 858/*
@@ -888,23 +861,25 @@ failed:
888 */ 861 */
889static void alua_bus_detach(struct scsi_device *sdev) 862static void alua_bus_detach(struct scsi_device *sdev)
890{ 863{
891 struct scsi_dh_data *scsi_dh_data; 864 struct alua_dh_data *h = get_alua_data(sdev);
892 struct alua_dh_data *h;
893 unsigned long flags;
894
895 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
896 scsi_dh_data = sdev->scsi_dh_data;
897 sdev->scsi_dh_data = NULL;
898 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
899 865
900 h = (struct alua_dh_data *) scsi_dh_data->buf;
901 if (h->buff && h->inq != h->buff) 866 if (h->buff && h->inq != h->buff)
902 kfree(h->buff); 867 kfree(h->buff);
903 kfree(scsi_dh_data); 868 kfree(h);
904 module_put(THIS_MODULE);
905 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", ALUA_DH_NAME);
906} 869}
907 870
871static struct scsi_device_handler alua_dh = {
872 .name = ALUA_DH_NAME,
873 .module = THIS_MODULE,
874 .attach = alua_bus_attach,
875 .detach = alua_bus_detach,
876 .prep_fn = alua_prep_fn,
877 .check_sense = alua_check_sense,
878 .activate = alua_activate,
879 .set_params = alua_set_params,
880 .match = alua_match,
881};
882
908static int __init alua_init(void) 883static int __init alua_init(void)
909{ 884{
910 int r; 885 int r;
diff --git a/drivers/scsi/device_handler/scsi_dh_emc.c b/drivers/scsi/device_handler/scsi_dh_emc.c
index 84765384c47c..6ed1caadbc6a 100644
--- a/drivers/scsi/device_handler/scsi_dh_emc.c
+++ b/drivers/scsi/device_handler/scsi_dh_emc.c
@@ -72,6 +72,7 @@ static const char * lun_state[] =
72}; 72};
73 73
74struct clariion_dh_data { 74struct clariion_dh_data {
75 struct scsi_dh_data dh_data;
75 /* 76 /*
76 * Flags: 77 * Flags:
77 * CLARIION_SHORT_TRESPASS 78 * CLARIION_SHORT_TRESPASS
@@ -116,9 +117,8 @@ struct clariion_dh_data {
116static inline struct clariion_dh_data 117static inline struct clariion_dh_data
117 *get_clariion_data(struct scsi_device *sdev) 118 *get_clariion_data(struct scsi_device *sdev)
118{ 119{
119 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 120 return container_of(sdev->scsi_dh_data, struct clariion_dh_data,
120 BUG_ON(scsi_dh_data == NULL); 121 dh_data);
121 return ((struct clariion_dh_data *) scsi_dh_data->buf);
122} 122}
123 123
124/* 124/*
@@ -622,7 +622,10 @@ done:
622 return result; 622 return result;
623} 623}
624 624
625static const struct scsi_dh_devlist clariion_dev_list[] = { 625static const struct {
626 char *vendor;
627 char *model;
628} clariion_dev_list[] = {
626 {"DGC", "RAID"}, 629 {"DGC", "RAID"},
627 {"DGC", "DISK"}, 630 {"DGC", "DISK"},
628 {"DGC", "VRAID"}, 631 {"DGC", "VRAID"},
@@ -647,39 +650,14 @@ static bool clariion_match(struct scsi_device *sdev)
647 return false; 650 return false;
648} 651}
649 652
650static int clariion_bus_attach(struct scsi_device *sdev); 653static struct scsi_dh_data *clariion_bus_attach(struct scsi_device *sdev)
651static void clariion_bus_detach(struct scsi_device *sdev);
652
653static struct scsi_device_handler clariion_dh = {
654 .name = CLARIION_NAME,
655 .module = THIS_MODULE,
656 .devlist = clariion_dev_list,
657 .attach = clariion_bus_attach,
658 .detach = clariion_bus_detach,
659 .check_sense = clariion_check_sense,
660 .activate = clariion_activate,
661 .prep_fn = clariion_prep_fn,
662 .set_params = clariion_set_params,
663 .match = clariion_match,
664};
665
666static int clariion_bus_attach(struct scsi_device *sdev)
667{ 654{
668 struct scsi_dh_data *scsi_dh_data;
669 struct clariion_dh_data *h; 655 struct clariion_dh_data *h;
670 unsigned long flags;
671 int err; 656 int err;
672 657
673 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) 658 h = kzalloc(sizeof(*h) , GFP_KERNEL);
674 + sizeof(*h) , GFP_KERNEL); 659 if (!h)
675 if (!scsi_dh_data) { 660 return ERR_PTR(-ENOMEM);
676 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
677 CLARIION_NAME);
678 return -ENOMEM;
679 }
680
681 scsi_dh_data->scsi_dh = &clariion_dh;
682 h = (struct clariion_dh_data *) scsi_dh_data->buf;
683 h->lun_state = CLARIION_LUN_UNINITIALIZED; 661 h->lun_state = CLARIION_LUN_UNINITIALIZED;
684 h->default_sp = CLARIION_UNBOUND_LU; 662 h->default_sp = CLARIION_UNBOUND_LU;
685 h->current_sp = CLARIION_UNBOUND_LU; 663 h->current_sp = CLARIION_UNBOUND_LU;
@@ -692,45 +670,37 @@ static int clariion_bus_attach(struct scsi_device *sdev)
692 if (err != SCSI_DH_OK) 670 if (err != SCSI_DH_OK)
693 goto failed; 671 goto failed;
694 672
695 if (!try_module_get(THIS_MODULE))
696 goto failed;
697
698 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
699 sdev->scsi_dh_data = scsi_dh_data;
700 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
701
702 sdev_printk(KERN_INFO, sdev, 673 sdev_printk(KERN_INFO, sdev,
703 "%s: connected to SP %c Port %d (%s, default SP %c)\n", 674 "%s: connected to SP %c Port %d (%s, default SP %c)\n",
704 CLARIION_NAME, h->current_sp + 'A', 675 CLARIION_NAME, h->current_sp + 'A',
705 h->port, lun_state[h->lun_state], 676 h->port, lun_state[h->lun_state],
706 h->default_sp + 'A'); 677 h->default_sp + 'A');
707 678 return &h->dh_data;
708 return 0;
709 679
710failed: 680failed:
711 kfree(scsi_dh_data); 681 kfree(h);
712 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", 682 return ERR_PTR(-EINVAL);
713 CLARIION_NAME);
714 return -EINVAL;
715} 683}
716 684
717static void clariion_bus_detach(struct scsi_device *sdev) 685static void clariion_bus_detach(struct scsi_device *sdev)
718{ 686{
719 struct scsi_dh_data *scsi_dh_data; 687 struct clariion_dh_data *h = get_clariion_data(sdev);
720 unsigned long flags;
721
722 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
723 scsi_dh_data = sdev->scsi_dh_data;
724 sdev->scsi_dh_data = NULL;
725 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
726
727 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n",
728 CLARIION_NAME);
729 688
730 kfree(scsi_dh_data); 689 kfree(h);
731 module_put(THIS_MODULE);
732} 690}
733 691
692static struct scsi_device_handler clariion_dh = {
693 .name = CLARIION_NAME,
694 .module = THIS_MODULE,
695 .attach = clariion_bus_attach,
696 .detach = clariion_bus_detach,
697 .check_sense = clariion_check_sense,
698 .activate = clariion_activate,
699 .prep_fn = clariion_prep_fn,
700 .set_params = clariion_set_params,
701 .match = clariion_match,
702};
703
734static int __init clariion_init(void) 704static int __init clariion_init(void)
735{ 705{
736 int r; 706 int r;
diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
index 4ee2759f5299..485d99544a15 100644
--- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c
+++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
@@ -38,6 +38,7 @@
38#define HP_SW_PATH_PASSIVE 1 38#define HP_SW_PATH_PASSIVE 1
39 39
40struct hp_sw_dh_data { 40struct hp_sw_dh_data {
41 struct scsi_dh_data dh_data;
41 unsigned char sense[SCSI_SENSE_BUFFERSIZE]; 42 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
42 int path_state; 43 int path_state;
43 int retries; 44 int retries;
@@ -51,9 +52,7 @@ static int hp_sw_start_stop(struct hp_sw_dh_data *);
51 52
52static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev) 53static inline struct hp_sw_dh_data *get_hp_sw_data(struct scsi_device *sdev)
53{ 54{
54 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 55 return container_of(sdev->scsi_dh_data, struct hp_sw_dh_data, dh_data);
55 BUG_ON(scsi_dh_data == NULL);
56 return ((struct hp_sw_dh_data *) scsi_dh_data->buf);
57} 56}
58 57
59/* 58/*
@@ -312,7 +311,10 @@ static int hp_sw_activate(struct scsi_device *sdev,
312 return 0; 311 return 0;
313} 312}
314 313
315static const struct scsi_dh_devlist hp_sw_dh_data_list[] = { 314static const struct {
315 char *vendor;
316 char *model;
317} hp_sw_dh_data_list[] = {
316 {"COMPAQ", "MSA1000 VOLUME"}, 318 {"COMPAQ", "MSA1000 VOLUME"},
317 {"COMPAQ", "HSV110"}, 319 {"COMPAQ", "HSV110"},
318 {"HP", "HSV100"}, 320 {"HP", "HSV100"},
@@ -338,37 +340,14 @@ static bool hp_sw_match(struct scsi_device *sdev)
338 return false; 340 return false;
339} 341}
340 342
341static int hp_sw_bus_attach(struct scsi_device *sdev); 343static struct scsi_dh_data *hp_sw_bus_attach(struct scsi_device *sdev)
342static void hp_sw_bus_detach(struct scsi_device *sdev);
343
344static struct scsi_device_handler hp_sw_dh = {
345 .name = HP_SW_NAME,
346 .module = THIS_MODULE,
347 .devlist = hp_sw_dh_data_list,
348 .attach = hp_sw_bus_attach,
349 .detach = hp_sw_bus_detach,
350 .activate = hp_sw_activate,
351 .prep_fn = hp_sw_prep_fn,
352 .match = hp_sw_match,
353};
354
355static int hp_sw_bus_attach(struct scsi_device *sdev)
356{ 344{
357 struct scsi_dh_data *scsi_dh_data;
358 struct hp_sw_dh_data *h; 345 struct hp_sw_dh_data *h;
359 unsigned long flags;
360 int ret; 346 int ret;
361 347
362 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) 348 h = kzalloc(sizeof(*h), GFP_KERNEL);
363 + sizeof(*h) , GFP_KERNEL); 349 if (!h)
364 if (!scsi_dh_data) { 350 return ERR_PTR(-ENOMEM);
365 sdev_printk(KERN_ERR, sdev, "%s: Attach Failed\n",
366 HP_SW_NAME);
367 return 0;
368 }
369
370 scsi_dh_data->scsi_dh = &hp_sw_dh;
371 h = (struct hp_sw_dh_data *) scsi_dh_data->buf;
372 h->path_state = HP_SW_PATH_UNINITIALIZED; 351 h->path_state = HP_SW_PATH_UNINITIALIZED;
373 h->retries = HP_SW_RETRIES; 352 h->retries = HP_SW_RETRIES;
374 h->sdev = sdev; 353 h->sdev = sdev;
@@ -377,42 +356,32 @@ static int hp_sw_bus_attach(struct scsi_device *sdev)
377 if (ret != SCSI_DH_OK || h->path_state == HP_SW_PATH_UNINITIALIZED) 356 if (ret != SCSI_DH_OK || h->path_state == HP_SW_PATH_UNINITIALIZED)
378 goto failed; 357 goto failed;
379 358
380 if (!try_module_get(THIS_MODULE))
381 goto failed;
382
383 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
384 sdev->scsi_dh_data = scsi_dh_data;
385 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
386
387 sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n", 359 sdev_printk(KERN_INFO, sdev, "%s: attached to %s path\n",
388 HP_SW_NAME, h->path_state == HP_SW_PATH_ACTIVE? 360 HP_SW_NAME, h->path_state == HP_SW_PATH_ACTIVE?
389 "active":"passive"); 361 "active":"passive");
390 362 return &h->dh_data;
391 return 0;
392
393failed: 363failed:
394 kfree(scsi_dh_data); 364 kfree(h);
395 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", 365 return ERR_PTR(-EINVAL);
396 HP_SW_NAME);
397 return -EINVAL;
398} 366}
399 367
400static void hp_sw_bus_detach( struct scsi_device *sdev ) 368static void hp_sw_bus_detach( struct scsi_device *sdev )
401{ 369{
402 struct scsi_dh_data *scsi_dh_data; 370 struct hp_sw_dh_data *h = get_hp_sw_data(sdev);
403 unsigned long flags;
404
405 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
406 scsi_dh_data = sdev->scsi_dh_data;
407 sdev->scsi_dh_data = NULL;
408 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
409 module_put(THIS_MODULE);
410
411 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", HP_SW_NAME);
412 371
413 kfree(scsi_dh_data); 372 kfree(h);
414} 373}
415 374
375static struct scsi_device_handler hp_sw_dh = {
376 .name = HP_SW_NAME,
377 .module = THIS_MODULE,
378 .attach = hp_sw_bus_attach,
379 .detach = hp_sw_bus_detach,
380 .activate = hp_sw_activate,
381 .prep_fn = hp_sw_prep_fn,
382 .match = hp_sw_match,
383};
384
416static int __init hp_sw_init(void) 385static int __init hp_sw_init(void)
417{ 386{
418 return scsi_register_device_handler(&hp_sw_dh); 387 return scsi_register_device_handler(&hp_sw_dh);
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c
index 1b5bc9293e37..b46ace3d4bf0 100644
--- a/drivers/scsi/device_handler/scsi_dh_rdac.c
+++ b/drivers/scsi/device_handler/scsi_dh_rdac.c
@@ -181,6 +181,7 @@ struct c2_inquiry {
181}; 181};
182 182
183struct rdac_dh_data { 183struct rdac_dh_data {
184 struct scsi_dh_data dh_data;
184 struct rdac_controller *ctlr; 185 struct rdac_controller *ctlr;
185#define UNINITIALIZED_LUN (1 << 8) 186#define UNINITIALIZED_LUN (1 << 8)
186 unsigned lun; 187 unsigned lun;
@@ -261,9 +262,7 @@ do { \
261 262
262static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev) 263static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev)
263{ 264{
264 struct scsi_dh_data *scsi_dh_data = sdev->scsi_dh_data; 265 return container_of(sdev->scsi_dh_data, struct rdac_dh_data, dh_data);
265 BUG_ON(scsi_dh_data == NULL);
266 return ((struct rdac_dh_data *) scsi_dh_data->buf);
267} 266}
268 267
269static struct request *get_rdac_req(struct scsi_device *sdev, 268static struct request *get_rdac_req(struct scsi_device *sdev,
@@ -779,7 +778,10 @@ static int rdac_check_sense(struct scsi_device *sdev,
779 return SCSI_RETURN_NOT_HANDLED; 778 return SCSI_RETURN_NOT_HANDLED;
780} 779}
781 780
782static const struct scsi_dh_devlist rdac_dev_list[] = { 781static const struct {
782 char *vendor;
783 char *model;
784} rdac_dev_list[] = {
783 {"IBM", "1722"}, 785 {"IBM", "1722"},
784 {"IBM", "1724"}, 786 {"IBM", "1724"},
785 {"IBM", "1726"}, 787 {"IBM", "1726"},
@@ -825,40 +827,16 @@ static bool rdac_match(struct scsi_device *sdev)
825 return false; 827 return false;
826} 828}
827 829
828static int rdac_bus_attach(struct scsi_device *sdev); 830static struct scsi_dh_data *rdac_bus_attach(struct scsi_device *sdev)
829static void rdac_bus_detach(struct scsi_device *sdev);
830
831static struct scsi_device_handler rdac_dh = {
832 .name = RDAC_NAME,
833 .module = THIS_MODULE,
834 .devlist = rdac_dev_list,
835 .prep_fn = rdac_prep_fn,
836 .check_sense = rdac_check_sense,
837 .attach = rdac_bus_attach,
838 .detach = rdac_bus_detach,
839 .activate = rdac_activate,
840 .match = rdac_match,
841};
842
843static int rdac_bus_attach(struct scsi_device *sdev)
844{ 831{
845 struct scsi_dh_data *scsi_dh_data;
846 struct rdac_dh_data *h; 832 struct rdac_dh_data *h;
847 unsigned long flags;
848 int err; 833 int err;
849 char array_name[ARRAY_LABEL_LEN]; 834 char array_name[ARRAY_LABEL_LEN];
850 char array_id[UNIQUE_ID_LEN]; 835 char array_id[UNIQUE_ID_LEN];
851 836
852 scsi_dh_data = kzalloc(sizeof(*scsi_dh_data) 837 h = kzalloc(sizeof(*h) , GFP_KERNEL);
853 + sizeof(*h) , GFP_KERNEL); 838 if (!h)
854 if (!scsi_dh_data) { 839 return ERR_PTR(-ENOMEM);
855 sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
856 RDAC_NAME);
857 return -ENOMEM;
858 }
859
860 scsi_dh_data->scsi_dh = &rdac_dh;
861 h = (struct rdac_dh_data *) scsi_dh_data->buf;
862 h->lun = UNINITIALIZED_LUN; 840 h->lun = UNINITIALIZED_LUN;
863 h->state = RDAC_STATE_ACTIVE; 841 h->state = RDAC_STATE_ACTIVE;
864 842
@@ -878,19 +856,12 @@ static int rdac_bus_attach(struct scsi_device *sdev)
878 if (err != SCSI_DH_OK) 856 if (err != SCSI_DH_OK)
879 goto clean_ctlr; 857 goto clean_ctlr;
880 858
881 if (!try_module_get(THIS_MODULE))
882 goto clean_ctlr;
883
884 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
885 sdev->scsi_dh_data = scsi_dh_data;
886 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
887
888 sdev_printk(KERN_NOTICE, sdev, 859 sdev_printk(KERN_NOTICE, sdev,
889 "%s: LUN %d (%s) (%s)\n", 860 "%s: LUN %d (%s) (%s)\n",
890 RDAC_NAME, h->lun, mode[(int)h->mode], 861 RDAC_NAME, h->lun, mode[(int)h->mode],
891 lun_state[(int)h->lun_state]); 862 lun_state[(int)h->lun_state]);
892 863
893 return 0; 864 return &h->dh_data;
894 865
895clean_ctlr: 866clean_ctlr:
896 spin_lock(&list_lock); 867 spin_lock(&list_lock);
@@ -898,37 +869,34 @@ clean_ctlr:
898 spin_unlock(&list_lock); 869 spin_unlock(&list_lock);
899 870
900failed: 871failed:
901 kfree(scsi_dh_data); 872 kfree(h);
902 sdev_printk(KERN_ERR, sdev, "%s: not attached\n", 873 return ERR_PTR(-EINVAL);
903 RDAC_NAME);
904 return -EINVAL;
905} 874}
906 875
907static void rdac_bus_detach( struct scsi_device *sdev ) 876static void rdac_bus_detach( struct scsi_device *sdev )
908{ 877{
909 struct scsi_dh_data *scsi_dh_data; 878 struct rdac_dh_data *h = get_rdac_data(sdev);
910 struct rdac_dh_data *h;
911 unsigned long flags;
912 879
913 scsi_dh_data = sdev->scsi_dh_data;
914 h = (struct rdac_dh_data *) scsi_dh_data->buf;
915 if (h->ctlr && h->ctlr->ms_queued) 880 if (h->ctlr && h->ctlr->ms_queued)
916 flush_workqueue(kmpath_rdacd); 881 flush_workqueue(kmpath_rdacd);
917 882
918 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
919 sdev->scsi_dh_data = NULL;
920 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
921
922 spin_lock(&list_lock); 883 spin_lock(&list_lock);
923 if (h->ctlr) 884 if (h->ctlr)
924 kref_put(&h->ctlr->kref, release_controller); 885 kref_put(&h->ctlr->kref, release_controller);
925 spin_unlock(&list_lock); 886 spin_unlock(&list_lock);
926 kfree(scsi_dh_data); 887 kfree(h);
927 module_put(THIS_MODULE);
928 sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
929} 888}
930 889
931 890static struct scsi_device_handler rdac_dh = {
891 .name = RDAC_NAME,
892 .module = THIS_MODULE,
893 .prep_fn = rdac_prep_fn,
894 .check_sense = rdac_check_sense,
895 .attach = rdac_bus_attach,
896 .detach = rdac_bus_detach,
897 .activate = rdac_activate,
898 .match = rdac_match,
899};
932 900
933static int __init rdac_init(void) 901static int __init rdac_init(void)
934{ 902{
diff --git a/drivers/scsi/dmx3191d.c b/drivers/scsi/dmx3191d.c
index 4b0dd8c56707..3e088125a8be 100644
--- a/drivers/scsi/dmx3191d.c
+++ b/drivers/scsi/dmx3191d.c
@@ -33,20 +33,20 @@
33/* 33/*
34 * Definitions for the generic 5380 driver. 34 * Definitions for the generic 5380 driver.
35 */ 35 */
36#define AUTOSENSE 36
37#define DONT_USE_INTR
37 38
38#define NCR5380_read(reg) inb(port + reg) 39#define NCR5380_read(reg) inb(port + reg)
39#define NCR5380_write(reg, value) outb(value, port + reg) 40#define NCR5380_write(reg, value) outb(value, port + reg)
40 41
41#define NCR5380_implementation_fields unsigned int port 42#define NCR5380_implementation_fields /* none */
42#define NCR5380_local_declare() NCR5380_implementation_fields 43#define NCR5380_local_declare() unsigned int port
43#define NCR5380_setup(instance) port = instance->io_port 44#define NCR5380_setup(instance) port = instance->io_port
44 45
45/* 46/*
46 * Includes needed for NCR5380.[ch] (XXX: Move them to NCR5380.h) 47 * Includes needed for NCR5380.[ch] (XXX: Move them to NCR5380.h)
47 */ 48 */
48#include <linux/delay.h> 49#include <linux/delay.h>
49#include "scsi.h"
50 50
51#include "NCR5380.h" 51#include "NCR5380.h"
52#include "NCR5380.c" 52#include "NCR5380.c"
@@ -58,6 +58,7 @@
58static struct scsi_host_template dmx3191d_driver_template = { 58static struct scsi_host_template dmx3191d_driver_template = {
59 .proc_name = DMX3191D_DRIVER_NAME, 59 .proc_name = DMX3191D_DRIVER_NAME,
60 .name = "Domex DMX3191D", 60 .name = "Domex DMX3191D",
61 .info = NCR5380_info,
61 .queuecommand = NCR5380_queue_command, 62 .queuecommand = NCR5380_queue_command,
62 .eh_abort_handler = NCR5380_abort, 63 .eh_abort_handler = NCR5380_abort,
63 .eh_bus_reset_handler = NCR5380_bus_reset, 64 .eh_bus_reset_handler = NCR5380_bus_reset,
@@ -90,31 +91,23 @@ static int dmx3191d_probe_one(struct pci_dev *pdev,
90 if (!shost) 91 if (!shost)
91 goto out_release_region; 92 goto out_release_region;
92 shost->io_port = io; 93 shost->io_port = io;
93 shost->irq = pdev->irq;
94 94
95 NCR5380_init(shost, FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E); 95 /* This card does not seem to raise an interrupt on pdev->irq.
96 * Steam-powered SCSI controllers run without an IRQ anyway.
97 */
98 shost->irq = NO_IRQ;
96 99
97 if (request_irq(pdev->irq, NCR5380_intr, IRQF_SHARED, 100 NCR5380_init(shost, FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E);
98 DMX3191D_DRIVER_NAME, shost)) {
99 /*
100 * Steam powered scsi controllers run without an IRQ anyway
101 */
102 printk(KERN_WARNING "dmx3191: IRQ %d not available - "
103 "switching to polled mode.\n", pdev->irq);
104 shost->irq = SCSI_IRQ_NONE;
105 }
106 101
107 pci_set_drvdata(pdev, shost); 102 pci_set_drvdata(pdev, shost);
108 103
109 error = scsi_add_host(shost, &pdev->dev); 104 error = scsi_add_host(shost, &pdev->dev);
110 if (error) 105 if (error)
111 goto out_free_irq; 106 goto out_release_region;
112 107
113 scsi_scan_host(shost); 108 scsi_scan_host(shost);
114 return 0; 109 return 0;
115 110
116 out_free_irq:
117 free_irq(shost->irq, shost);
118 out_release_region: 111 out_release_region:
119 release_region(io, DMX3191D_REGION_LEN); 112 release_region(io, DMX3191D_REGION_LEN);
120 out_disable_device: 113 out_disable_device:
@@ -131,8 +124,6 @@ static void dmx3191d_remove_one(struct pci_dev *pdev)
131 124
132 NCR5380_exit(shost); 125 NCR5380_exit(shost);
133 126
134 if (shost->irq != SCSI_IRQ_NONE)
135 free_irq(shost->irq, shost);
136 release_region(shost->io_port, DMX3191D_REGION_LEN); 127 release_region(shost->io_port, DMX3191D_REGION_LEN);
137 pci_disable_device(pdev); 128 pci_disable_device(pdev);
138 129
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 072f0ec2851e..0bf976936a10 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -415,10 +415,8 @@ static int adpt_slave_configure(struct scsi_device * device)
415 pHba = (adpt_hba *) host->hostdata[0]; 415 pHba = (adpt_hba *) host->hostdata[0];
416 416
417 if (host->can_queue && device->tagged_supported) { 417 if (host->can_queue && device->tagged_supported) {
418 scsi_adjust_queue_depth(device, MSG_SIMPLE_TAG, 418 scsi_change_queue_depth(device,
419 host->can_queue - 1); 419 host->can_queue - 1);
420 } else {
421 scsi_adjust_queue_depth(device, 0, 1);
422 } 420 }
423 return 0; 421 return 0;
424} 422}
diff --git a/drivers/scsi/dtc.c b/drivers/scsi/dtc.c
index 0a667fe05006..4c74c7ba2dff 100644
--- a/drivers/scsi/dtc.c
+++ b/drivers/scsi/dtc.c
@@ -1,5 +1,4 @@
1 1
2#define AUTOSENSE
3#define PSEUDO_DMA 2#define PSEUDO_DMA
4#define DONT_USE_INTR 3#define DONT_USE_INTR
5#define UNSAFE /* Leave interrupts enabled during pseudo-dma I/O */ 4#define UNSAFE /* Leave interrupts enabled during pseudo-dma I/O */
@@ -18,29 +17,9 @@
18 * (Unix and Linux consulting and custom programming) 17 * (Unix and Linux consulting and custom programming)
19 * drew@colorado.edu 18 * drew@colorado.edu
20 * +1 (303) 440-4894 19 * +1 (303) 440-4894
21 * 20 */
22 * DISTRIBUTION RELEASE 1.
23 *
24 * For more information, please consult
25 *
26 * NCR 5380 Family
27 * SCSI Protocol Controller
28 * Databook
29*/
30 21
31/* 22/*
32 * Options :
33 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
34 * for commands that return with a CHECK CONDITION status.
35 *
36 * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
37 * increase compared to polled I/O.
38 *
39 * PARITY - enable parity checking. Not supported.
40 *
41 * UNSAFE - leave interrupts enabled during pseudo-DMA transfers.
42 * You probably want this.
43 *
44 * The card is detected and initialized in one of several ways : 23 * The card is detected and initialized in one of several ways :
45 * 1. Autoprobe (default) - since the board is memory mapped, 24 * 1. Autoprobe (default) - since the board is memory mapped,
46 * a BIOS signature is scanned for to locate the registers. 25 * a BIOS signature is scanned for to locate the registers.
@@ -79,15 +58,11 @@
79#include <linux/init.h> 58#include <linux/init.h>
80#include <linux/interrupt.h> 59#include <linux/interrupt.h>
81#include <linux/io.h> 60#include <linux/io.h>
82#include "scsi.h"
83#include <scsi/scsi_host.h> 61#include <scsi/scsi_host.h>
84#include "dtc.h" 62#include "dtc.h"
85#define AUTOPROBE_IRQ 63#define AUTOPROBE_IRQ
86#include "NCR5380.h" 64#include "NCR5380.h"
87 65
88
89#define DTC_PUBLIC_RELEASE 2
90
91/* 66/*
92 * The DTC3180 & 3280 boards are memory mapped. 67 * The DTC3180 & 3280 boards are memory mapped.
93 * 68 *
@@ -173,10 +148,13 @@ static const struct signature {
173 * 148 *
174 */ 149 */
175 150
176static void __init dtc_setup(char *str, int *ints) 151static int __init dtc_setup(char *str)
177{ 152{
178 static int commandline_current = 0; 153 static int commandline_current = 0;
179 int i; 154 int i;
155 int ints[10];
156
157 get_options(str, ARRAY_SIZE(ints), ints);
180 if (ints[0] != 2) 158 if (ints[0] != 2)
181 printk("dtc_setup: usage dtc=address,irq\n"); 159 printk("dtc_setup: usage dtc=address,irq\n");
182 else if (commandline_current < NO_OVERRIDES) { 160 else if (commandline_current < NO_OVERRIDES) {
@@ -189,7 +167,10 @@ static void __init dtc_setup(char *str, int *ints)
189 } 167 }
190 ++commandline_current; 168 ++commandline_current;
191 } 169 }
170 return 1;
192} 171}
172
173__setup("dtc=", dtc_setup);
193#endif 174#endif
194 175
195/* 176/*
@@ -213,10 +194,6 @@ static int __init dtc_detect(struct scsi_host_template * tpnt)
213 void __iomem *base; 194 void __iomem *base;
214 int sig, count; 195 int sig, count;
215 196
216 tpnt->proc_name = "dtc3x80";
217 tpnt->show_info = dtc_show_info;
218 tpnt->write_info = dtc_write_info;
219
220 for (count = 0; current_override < NO_OVERRIDES; ++current_override) { 197 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
221 addr = 0; 198 addr = 0;
222 base = NULL; 199 base = NULL;
@@ -271,38 +248,33 @@ found:
271 else 248 else
272 instance->irq = NCR5380_probe_irq(instance, DTC_IRQS); 249 instance->irq = NCR5380_probe_irq(instance, DTC_IRQS);
273 250
251 /* Compatibility with documented NCR5380 kernel parameters */
252 if (instance->irq == 255)
253 instance->irq = NO_IRQ;
254
274#ifndef DONT_USE_INTR 255#ifndef DONT_USE_INTR
275 /* With interrupts enabled, it will sometimes hang when doing heavy 256 /* With interrupts enabled, it will sometimes hang when doing heavy
276 * reads. So better not enable them until I finger it out. */ 257 * reads. So better not enable them until I finger it out. */
277 if (instance->irq != SCSI_IRQ_NONE) 258 if (instance->irq != NO_IRQ)
278 if (request_irq(instance->irq, dtc_intr, 0, 259 if (request_irq(instance->irq, dtc_intr, 0,
279 "dtc", instance)) { 260 "dtc", instance)) {
280 printk(KERN_ERR "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq); 261 printk(KERN_ERR "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
281 instance->irq = SCSI_IRQ_NONE; 262 instance->irq = NO_IRQ;
282 } 263 }
283 264
284 if (instance->irq == SCSI_IRQ_NONE) { 265 if (instance->irq == NO_IRQ) {
285 printk(KERN_WARNING "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no); 266 printk(KERN_WARNING "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
286 printk(KERN_WARNING "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no); 267 printk(KERN_WARNING "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
287 } 268 }
288#else 269#else
289 if (instance->irq != SCSI_IRQ_NONE) 270 if (instance->irq != NO_IRQ)
290 printk(KERN_WARNING "scsi%d : interrupts not used. Might as well not jumper it.\n", instance->host_no); 271 printk(KERN_WARNING "scsi%d : interrupts not used. Might as well not jumper it.\n", instance->host_no);
291 instance->irq = SCSI_IRQ_NONE; 272 instance->irq = NO_IRQ;
292#endif 273#endif
293#if defined(DTCDEBUG) && (DTCDEBUG & DTCDEBUG_INIT) 274#if defined(DTCDEBUG) && (DTCDEBUG & DTCDEBUG_INIT)
294 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq); 275 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
295#endif 276#endif
296 277
297 printk(KERN_INFO "scsi%d : at 0x%05X", instance->host_no, (int) instance->base);
298 if (instance->irq == SCSI_IRQ_NONE)
299 printk(" interrupts disabled");
300 else
301 printk(" irq %d", instance->irq);
302 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", CAN_QUEUE, CMD_PER_LUN, DTC_PUBLIC_RELEASE);
303 NCR5380_print_options(instance);
304 printk("\n");
305
306 ++current_override; 278 ++current_override;
307 ++count; 279 ++count;
308 } 280 }
@@ -354,20 +326,18 @@ static int dtc_biosparam(struct scsi_device *sdev, struct block_device *dev,
354 * timeout. 326 * timeout.
355*/ 327*/
356 328
357static int dtc_maxi = 0;
358static int dtc_wmaxi = 0;
359
360static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len) 329static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len)
361{ 330{
362 unsigned char *d = dst; 331 unsigned char *d = dst;
363 int i; /* For counting time spent in the poll-loop */ 332 int i; /* For counting time spent in the poll-loop */
333 struct NCR5380_hostdata *hostdata = shost_priv(instance);
364 NCR5380_local_declare(); 334 NCR5380_local_declare();
365 NCR5380_setup(instance); 335 NCR5380_setup(instance);
366 336
367 i = 0; 337 i = 0;
368 NCR5380_read(RESET_PARITY_INTERRUPT_REG); 338 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
369 NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE); 339 NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE);
370 if (instance->irq == SCSI_IRQ_NONE) 340 if (instance->irq == NO_IRQ)
371 NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ); 341 NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ);
372 else 342 else
373 NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ | CSR_INT_BASE); 343 NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ | CSR_INT_BASE);
@@ -391,8 +361,8 @@ static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst,
391 NCR5380_write(MODE_REG, 0); /* Clear the operating mode */ 361 NCR5380_write(MODE_REG, 0); /* Clear the operating mode */
392 rtrc(0); 362 rtrc(0);
393 NCR5380_read(RESET_PARITY_INTERRUPT_REG); 363 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
394 if (i > dtc_maxi) 364 if (i > hostdata->spin_max_r)
395 dtc_maxi = i; 365 hostdata->spin_max_r = i;
396 return (0); 366 return (0);
397} 367}
398 368
@@ -412,13 +382,14 @@ static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst,
412static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len) 382static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len)
413{ 383{
414 int i; 384 int i;
385 struct NCR5380_hostdata *hostdata = shost_priv(instance);
415 NCR5380_local_declare(); 386 NCR5380_local_declare();
416 NCR5380_setup(instance); 387 NCR5380_setup(instance);
417 388
418 NCR5380_read(RESET_PARITY_INTERRUPT_REG); 389 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
419 NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE); 390 NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE);
420 /* set direction (write) */ 391 /* set direction (write) */
421 if (instance->irq == SCSI_IRQ_NONE) 392 if (instance->irq == NO_IRQ)
422 NCR5380_write(DTC_CONTROL_REG, 0); 393 NCR5380_write(DTC_CONTROL_REG, 0);
423 else 394 else
424 NCR5380_write(DTC_CONTROL_REG, CSR_5380_INTR); 395 NCR5380_write(DTC_CONTROL_REG, CSR_5380_INTR);
@@ -444,8 +415,8 @@ static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src,
444 /* Check for parity error here. fixme. */ 415 /* Check for parity error here. fixme. */
445 NCR5380_write(MODE_REG, 0); /* Clear the operating mode */ 416 NCR5380_write(MODE_REG, 0); /* Clear the operating mode */
446 rtrc(0); 417 rtrc(0);
447 if (i > dtc_wmaxi) 418 if (i > hostdata->spin_max_w)
448 dtc_wmaxi = i; 419 hostdata->spin_max_w = i;
449 return (0); 420 return (0);
450} 421}
451 422
@@ -457,7 +428,7 @@ static int dtc_release(struct Scsi_Host *shost)
457{ 428{
458 NCR5380_local_declare(); 429 NCR5380_local_declare();
459 NCR5380_setup(shost); 430 NCR5380_setup(shost);
460 if (shost->irq) 431 if (shost->irq != NO_IRQ)
461 free_irq(shost->irq, shost); 432 free_irq(shost->irq, shost);
462 NCR5380_exit(shost); 433 NCR5380_exit(shost);
463 if (shost->io_port && shost->n_io_port) 434 if (shost->io_port && shost->n_io_port)
@@ -471,6 +442,10 @@ static struct scsi_host_template driver_template = {
471 .name = "DTC 3180/3280 ", 442 .name = "DTC 3180/3280 ",
472 .detect = dtc_detect, 443 .detect = dtc_detect,
473 .release = dtc_release, 444 .release = dtc_release,
445 .proc_name = "dtc3x80",
446 .show_info = dtc_show_info,
447 .write_info = dtc_write_info,
448 .info = dtc_info,
474 .queuecommand = dtc_queue_command, 449 .queuecommand = dtc_queue_command,
475 .eh_abort_handler = dtc_abort, 450 .eh_abort_handler = dtc_abort,
476 .eh_bus_reset_handler = dtc_bus_reset, 451 .eh_bus_reset_handler = dtc_bus_reset,
diff --git a/drivers/scsi/dtc.h b/drivers/scsi/dtc.h
index 92d7cfc3f4fc..78a2332e9064 100644
--- a/drivers/scsi/dtc.h
+++ b/drivers/scsi/dtc.h
@@ -5,24 +5,6 @@
5 * (Unix and Linux consulting and custom programming) 5 * (Unix and Linux consulting and custom programming)
6 * drew@colorado.edu 6 * drew@colorado.edu
7 * +1 (303) 440-4894 7 * +1 (303) 440-4894
8 *
9 * DISTRIBUTION RELEASE 2.
10 *
11 * For more information, please consult
12 *
13 *
14 *
15 * and
16 *
17 * NCR 5380 Family
18 * SCSI Protocol Controller
19 * Databook
20 *
21 * NCR Microelectronics
22 * 1635 Aeroplaza Drive
23 * Colorado Springs, CO 80916
24 * 1+ (719) 578-3400
25 * 1+ (800) 334-5454
26 */ 8 */
27 9
28#ifndef DTC3280_H 10#ifndef DTC3280_H
@@ -32,13 +14,6 @@
32#define DTCDEBUG_INIT 0x1 14#define DTCDEBUG_INIT 0x1
33#define DTCDEBUG_TRANSFER 0x2 15#define DTCDEBUG_TRANSFER 0x2
34 16
35static int dtc_abort(Scsi_Cmnd *);
36static int dtc_biosparam(struct scsi_device *, struct block_device *,
37 sector_t, int*);
38static int dtc_detect(struct scsi_host_template *);
39static int dtc_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
40static int dtc_bus_reset(Scsi_Cmnd *);
41
42#ifndef CMD_PER_LUN 17#ifndef CMD_PER_LUN
43#define CMD_PER_LUN 2 18#define CMD_PER_LUN 2
44#endif 19#endif
@@ -88,6 +63,7 @@ static int dtc_bus_reset(Scsi_Cmnd *);
88#define NCR5380_queue_command dtc_queue_command 63#define NCR5380_queue_command dtc_queue_command
89#define NCR5380_abort dtc_abort 64#define NCR5380_abort dtc_abort
90#define NCR5380_bus_reset dtc_bus_reset 65#define NCR5380_bus_reset dtc_bus_reset
66#define NCR5380_info dtc_info
91#define NCR5380_show_info dtc_show_info 67#define NCR5380_show_info dtc_show_info
92#define NCR5380_write_info dtc_write_info 68#define NCR5380_write_info dtc_write_info
93 69
diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index 943ad3a19661..227dd2c2ec2f 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -946,20 +946,18 @@ static int eata2x_slave_configure(struct scsi_device *dev)
946 946
947 if (TLDEV(dev->type) && dev->tagged_supported) { 947 if (TLDEV(dev->type) && dev->tagged_supported) {
948 if (tag_mode == TAG_SIMPLE) { 948 if (tag_mode == TAG_SIMPLE) {
949 scsi_adjust_queue_depth(dev, MSG_SIMPLE_TAG, tqd);
950 tag_suffix = ", simple tags"; 949 tag_suffix = ", simple tags";
951 } else if (tag_mode == TAG_ORDERED) { 950 } else if (tag_mode == TAG_ORDERED) {
952 scsi_adjust_queue_depth(dev, MSG_ORDERED_TAG, tqd);
953 tag_suffix = ", ordered tags"; 951 tag_suffix = ", ordered tags";
954 } else { 952 } else {
955 scsi_adjust_queue_depth(dev, 0, tqd);
956 tag_suffix = ", no tags"; 953 tag_suffix = ", no tags";
957 } 954 }
955 scsi_change_queue_depth(dev, tqd);
958 } else if (TLDEV(dev->type) && linked_comm) { 956 } else if (TLDEV(dev->type) && linked_comm) {
959 scsi_adjust_queue_depth(dev, 0, tqd); 957 scsi_change_queue_depth(dev, tqd);
960 tag_suffix = ", untagged"; 958 tag_suffix = ", untagged";
961 } else { 959 } else {
962 scsi_adjust_queue_depth(dev, 0, utqd); 960 scsi_change_queue_depth(dev, utqd);
963 tag_suffix = ""; 961 tag_suffix = "";
964 } 962 }
965 963
diff --git a/drivers/scsi/esas2r/esas2r.h b/drivers/scsi/esas2r/esas2r.h
index 3fd305d6b67d..b6030e3edd01 100644
--- a/drivers/scsi/esas2r/esas2r.h
+++ b/drivers/scsi/esas2r/esas2r.h
@@ -972,11 +972,6 @@ u8 handle_hba_ioctl(struct esas2r_adapter *a,
972 struct atto_ioctl *ioctl_hba); 972 struct atto_ioctl *ioctl_hba);
973int esas2r_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd); 973int esas2r_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd);
974int esas2r_show_info(struct seq_file *m, struct Scsi_Host *sh); 974int esas2r_show_info(struct seq_file *m, struct Scsi_Host *sh);
975int esas2r_slave_alloc(struct scsi_device *dev);
976int esas2r_slave_configure(struct scsi_device *dev);
977void esas2r_slave_destroy(struct scsi_device *dev);
978int esas2r_change_queue_depth(struct scsi_device *dev, int depth, int reason);
979int esas2r_change_queue_type(struct scsi_device *dev, int type);
980long esas2r_proc_ioctl(struct file *fp, unsigned int cmd, unsigned long arg); 975long esas2r_proc_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
981 976
982/* SCSI error handler (eh) functions */ 977/* SCSI error handler (eh) functions */
diff --git a/drivers/scsi/esas2r/esas2r_ioctl.c b/drivers/scsi/esas2r/esas2r_ioctl.c
index d89a0277a8e1..baf913047b48 100644
--- a/drivers/scsi/esas2r/esas2r_ioctl.c
+++ b/drivers/scsi/esas2r/esas2r_ioctl.c
@@ -117,9 +117,8 @@ static void do_fm_api(struct esas2r_adapter *a, struct esas2r_flash_img *fi)
117 117
118 rq = esas2r_alloc_request(a); 118 rq = esas2r_alloc_request(a);
119 if (rq == NULL) { 119 if (rq == NULL) {
120 up(&a->fm_api_semaphore);
121 fi->status = FI_STAT_BUSY; 120 fi->status = FI_STAT_BUSY;
122 return; 121 goto free_sem;
123 } 122 }
124 123
125 if (fi == &a->firmware.header) { 124 if (fi == &a->firmware.header) {
@@ -135,7 +134,7 @@ static void do_fm_api(struct esas2r_adapter *a, struct esas2r_flash_img *fi)
135 if (a->firmware.header_buff == NULL) { 134 if (a->firmware.header_buff == NULL) {
136 esas2r_debug("failed to allocate header buffer!"); 135 esas2r_debug("failed to allocate header buffer!");
137 fi->status = FI_STAT_BUSY; 136 fi->status = FI_STAT_BUSY;
138 return; 137 goto free_req;
139 } 138 }
140 139
141 memcpy(a->firmware.header_buff, fi, 140 memcpy(a->firmware.header_buff, fi,
@@ -171,9 +170,10 @@ all_done:
171 a->firmware.header_buff, 170 a->firmware.header_buff,
172 (dma_addr_t)a->firmware.header_buff_phys); 171 (dma_addr_t)a->firmware.header_buff_phys);
173 } 172 }
174 173free_req:
175 up(&a->fm_api_semaphore);
176 esas2r_free_request(a, (struct esas2r_request *)rq); 174 esas2r_free_request(a, (struct esas2r_request *)rq);
175free_sem:
176 up(&a->fm_api_semaphore);
177 return; 177 return;
178 178
179} 179}
@@ -1420,9 +1420,10 @@ int esas2r_ioctl_handler(void *hostdata, int cmd, void __user *arg)
1420 1420
1421 rq = esas2r_alloc_request(a); 1421 rq = esas2r_alloc_request(a);
1422 if (rq == NULL) { 1422 if (rq == NULL) {
1423 up(&a->nvram_semaphore); 1423 kfree(ioctl);
1424 ioctl->data.prw.code = 0; 1424 esas2r_log(ESAS2R_LOG_WARN,
1425 break; 1425 "could not allocate an internal request");
1426 return -ENOMEM;
1426 } 1427 }
1427 1428
1428 code = esas2r_write_params(a, rq, 1429 code = esas2r_write_params(a, rq,
@@ -1523,9 +1524,12 @@ ioctl_done:
1523 case -EINVAL: 1524 case -EINVAL:
1524 ioctl->header.return_code = IOCTL_INVALID_PARAM; 1525 ioctl->header.return_code = IOCTL_INVALID_PARAM;
1525 break; 1526 break;
1527
1528 default:
1529 ioctl->header.return_code = IOCTL_GENERAL_ERROR;
1530 break;
1526 } 1531 }
1527 1532
1528 ioctl->header.return_code = IOCTL_GENERAL_ERROR;
1529 } 1533 }
1530 1534
1531 /* Always copy the buffer back, if only to pick up the status */ 1535 /* Always copy the buffer back, if only to pick up the status */
diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c
index 6504a195c874..593ff8a63c70 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -254,12 +254,10 @@ static struct scsi_host_template driver_template = {
254 .use_clustering = ENABLE_CLUSTERING, 254 .use_clustering = ENABLE_CLUSTERING,
255 .emulated = 0, 255 .emulated = 0,
256 .proc_name = ESAS2R_DRVR_NAME, 256 .proc_name = ESAS2R_DRVR_NAME,
257 .slave_configure = esas2r_slave_configure, 257 .change_queue_depth = scsi_change_queue_depth,
258 .slave_alloc = esas2r_slave_alloc, 258 .change_queue_type = scsi_change_queue_type,
259 .slave_destroy = esas2r_slave_destroy,
260 .change_queue_depth = esas2r_change_queue_depth,
261 .change_queue_type = esas2r_change_queue_type,
262 .max_sectors = 0xFFFF, 259 .max_sectors = 0xFFFF,
260 .use_blk_tags = 1,
263}; 261};
264 262
265int sgl_page_size = 512; 263int sgl_page_size = 512;
@@ -1057,7 +1055,7 @@ int esas2r_eh_abort(struct scsi_cmnd *cmd)
1057 1055
1058 cmd->scsi_done(cmd); 1056 cmd->scsi_done(cmd);
1059 1057
1060 return 0; 1058 return SUCCESS;
1061 } 1059 }
1062 1060
1063 spin_lock_irqsave(&a->queue_lock, flags); 1061 spin_lock_irqsave(&a->queue_lock, flags);
@@ -1259,60 +1257,6 @@ int esas2r_target_reset(struct scsi_cmnd *cmd)
1259 return esas2r_dev_targ_reset(cmd, true); 1257 return esas2r_dev_targ_reset(cmd, true);
1260} 1258}
1261 1259
1262int esas2r_change_queue_depth(struct scsi_device *dev, int depth, int reason)
1263{
1264 esas2r_log(ESAS2R_LOG_INFO, "change_queue_depth %p, %d", dev, depth);
1265
1266 scsi_adjust_queue_depth(dev, scsi_get_tag_type(dev), depth);
1267
1268 return dev->queue_depth;
1269}
1270
1271int esas2r_change_queue_type(struct scsi_device *dev, int type)
1272{
1273 esas2r_log(ESAS2R_LOG_INFO, "change_queue_type %p, %d", dev, type);
1274
1275 if (dev->tagged_supported) {
1276 scsi_set_tag_type(dev, type);
1277
1278 if (type)
1279 scsi_activate_tcq(dev, dev->queue_depth);
1280 else
1281 scsi_deactivate_tcq(dev, dev->queue_depth);
1282 } else {
1283 type = 0;
1284 }
1285
1286 return type;
1287}
1288
1289int esas2r_slave_alloc(struct scsi_device *dev)
1290{
1291 return 0;
1292}
1293
1294int esas2r_slave_configure(struct scsi_device *dev)
1295{
1296 esas2r_log_dev(ESAS2R_LOG_INFO, &(dev->sdev_gendev),
1297 "esas2r_slave_configure()");
1298
1299 if (dev->tagged_supported) {
1300 scsi_set_tag_type(dev, MSG_SIMPLE_TAG);
1301 scsi_activate_tcq(dev, cmd_per_lun);
1302 } else {
1303 scsi_set_tag_type(dev, 0);
1304 scsi_deactivate_tcq(dev, cmd_per_lun);
1305 }
1306
1307 return 0;
1308}
1309
1310void esas2r_slave_destroy(struct scsi_device *dev)
1311{
1312 esas2r_log_dev(ESAS2R_LOG_INFO, &(dev->sdev_gendev),
1313 "esas2r_slave_destroy()");
1314}
1315
1316void esas2r_log_request_failure(struct esas2r_adapter *a, 1260void esas2r_log_request_failure(struct esas2r_adapter *a,
1317 struct esas2r_request *rq) 1261 struct esas2r_request *rq)
1318{ 1262{
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 55548dc5cec3..ce5bd52fe692 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -49,55 +49,67 @@ static u32 esp_debug;
49#define ESP_DEBUG_DATADONE 0x00000100 49#define ESP_DEBUG_DATADONE 0x00000100
50#define ESP_DEBUG_RECONNECT 0x00000200 50#define ESP_DEBUG_RECONNECT 0x00000200
51#define ESP_DEBUG_AUTOSENSE 0x00000400 51#define ESP_DEBUG_AUTOSENSE 0x00000400
52#define ESP_DEBUG_EVENT 0x00000800
53#define ESP_DEBUG_COMMAND 0x00001000
52 54
53#define esp_log_intr(f, a...) \ 55#define esp_log_intr(f, a...) \
54do { if (esp_debug & ESP_DEBUG_INTR) \ 56do { if (esp_debug & ESP_DEBUG_INTR) \
55 printk(f, ## a); \ 57 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
56} while (0) 58} while (0)
57 59
58#define esp_log_reset(f, a...) \ 60#define esp_log_reset(f, a...) \
59do { if (esp_debug & ESP_DEBUG_RESET) \ 61do { if (esp_debug & ESP_DEBUG_RESET) \
60 printk(f, ## a); \ 62 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
61} while (0) 63} while (0)
62 64
63#define esp_log_msgin(f, a...) \ 65#define esp_log_msgin(f, a...) \
64do { if (esp_debug & ESP_DEBUG_MSGIN) \ 66do { if (esp_debug & ESP_DEBUG_MSGIN) \
65 printk(f, ## a); \ 67 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
66} while (0) 68} while (0)
67 69
68#define esp_log_msgout(f, a...) \ 70#define esp_log_msgout(f, a...) \
69do { if (esp_debug & ESP_DEBUG_MSGOUT) \ 71do { if (esp_debug & ESP_DEBUG_MSGOUT) \
70 printk(f, ## a); \ 72 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
71} while (0) 73} while (0)
72 74
73#define esp_log_cmddone(f, a...) \ 75#define esp_log_cmddone(f, a...) \
74do { if (esp_debug & ESP_DEBUG_CMDDONE) \ 76do { if (esp_debug & ESP_DEBUG_CMDDONE) \
75 printk(f, ## a); \ 77 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
76} while (0) 78} while (0)
77 79
78#define esp_log_disconnect(f, a...) \ 80#define esp_log_disconnect(f, a...) \
79do { if (esp_debug & ESP_DEBUG_DISCONNECT) \ 81do { if (esp_debug & ESP_DEBUG_DISCONNECT) \
80 printk(f, ## a); \ 82 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
81} while (0) 83} while (0)
82 84
83#define esp_log_datastart(f, a...) \ 85#define esp_log_datastart(f, a...) \
84do { if (esp_debug & ESP_DEBUG_DATASTART) \ 86do { if (esp_debug & ESP_DEBUG_DATASTART) \
85 printk(f, ## a); \ 87 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
86} while (0) 88} while (0)
87 89
88#define esp_log_datadone(f, a...) \ 90#define esp_log_datadone(f, a...) \
89do { if (esp_debug & ESP_DEBUG_DATADONE) \ 91do { if (esp_debug & ESP_DEBUG_DATADONE) \
90 printk(f, ## a); \ 92 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
91} while (0) 93} while (0)
92 94
93#define esp_log_reconnect(f, a...) \ 95#define esp_log_reconnect(f, a...) \
94do { if (esp_debug & ESP_DEBUG_RECONNECT) \ 96do { if (esp_debug & ESP_DEBUG_RECONNECT) \
95 printk(f, ## a); \ 97 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
96} while (0) 98} while (0)
97 99
98#define esp_log_autosense(f, a...) \ 100#define esp_log_autosense(f, a...) \
99do { if (esp_debug & ESP_DEBUG_AUTOSENSE) \ 101do { if (esp_debug & ESP_DEBUG_AUTOSENSE) \
100 printk(f, ## a); \ 102 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
103} while (0)
104
105#define esp_log_event(f, a...) \
106do { if (esp_debug & ESP_DEBUG_EVENT) \
107 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
108} while (0)
109
110#define esp_log_command(f, a...) \
111do { if (esp_debug & ESP_DEBUG_COMMAND) \
112 shost_printk(KERN_DEBUG, esp->host, f, ## a); \
101} while (0) 113} while (0)
102 114
103#define esp_read8(REG) esp->ops->esp_read8(esp, REG) 115#define esp_read8(REG) esp->ops->esp_read8(esp, REG)
@@ -126,10 +138,29 @@ void scsi_esp_cmd(struct esp *esp, u8 val)
126 138
127 esp->esp_event_cur = (idx + 1) & (ESP_EVENT_LOG_SZ - 1); 139 esp->esp_event_cur = (idx + 1) & (ESP_EVENT_LOG_SZ - 1);
128 140
141 esp_log_command("cmd[%02x]\n", val);
129 esp_write8(val, ESP_CMD); 142 esp_write8(val, ESP_CMD);
130} 143}
131EXPORT_SYMBOL(scsi_esp_cmd); 144EXPORT_SYMBOL(scsi_esp_cmd);
132 145
146static void esp_send_dma_cmd(struct esp *esp, int len, int max_len, int cmd)
147{
148 if (esp->flags & ESP_FLAG_USE_FIFO) {
149 int i;
150
151 scsi_esp_cmd(esp, ESP_CMD_FLUSH);
152 for (i = 0; i < len; i++)
153 esp_write8(esp->command_block[i], ESP_FDATA);
154 scsi_esp_cmd(esp, cmd);
155 } else {
156 if (esp->rev == FASHME)
157 scsi_esp_cmd(esp, ESP_CMD_FLUSH);
158 cmd |= ESP_CMD_DMA;
159 esp->ops->send_dma_cmd(esp, esp->command_block_dma,
160 len, max_len, 0, cmd);
161 }
162}
163
133static void esp_event(struct esp *esp, u8 val) 164static void esp_event(struct esp *esp, u8 val)
134{ 165{
135 struct esp_event_ent *p; 166 struct esp_event_ent *p;
@@ -150,19 +181,17 @@ static void esp_dump_cmd_log(struct esp *esp)
150 int idx = esp->esp_event_cur; 181 int idx = esp->esp_event_cur;
151 int stop = idx; 182 int stop = idx;
152 183
153 printk(KERN_INFO PFX "esp%d: Dumping command log\n", 184 shost_printk(KERN_INFO, esp->host, "Dumping command log\n");
154 esp->host->unique_id);
155 do { 185 do {
156 struct esp_event_ent *p = &esp->esp_event_log[idx]; 186 struct esp_event_ent *p = &esp->esp_event_log[idx];
157 187
158 printk(KERN_INFO PFX "esp%d: ent[%d] %s ", 188 shost_printk(KERN_INFO, esp->host,
159 esp->host->unique_id, idx, 189 "ent[%d] %s val[%02x] sreg[%02x] seqreg[%02x] "
160 p->type == ESP_EVENT_TYPE_CMD ? "CMD" : "EVENT"); 190 "sreg2[%02x] ireg[%02x] ss[%02x] event[%02x]\n",
161 191 idx,
162 printk("val[%02x] sreg[%02x] seqreg[%02x] " 192 p->type == ESP_EVENT_TYPE_CMD ? "CMD" : "EVENT",
163 "sreg2[%02x] ireg[%02x] ss[%02x] event[%02x]\n", 193 p->val, p->sreg, p->seqreg,
164 p->val, p->sreg, p->seqreg, 194 p->sreg2, p->ireg, p->select_state, p->event);
165 p->sreg2, p->ireg, p->select_state, p->event);
166 195
167 idx = (idx + 1) & (ESP_EVENT_LOG_SZ - 1); 196 idx = (idx + 1) & (ESP_EVENT_LOG_SZ - 1);
168 } while (idx != stop); 197 } while (idx != stop);
@@ -176,9 +205,8 @@ static void esp_flush_fifo(struct esp *esp)
176 205
177 while (esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES) { 206 while (esp_read8(ESP_FFLAGS) & ESP_FF_FBYTES) {
178 if (--lim == 0) { 207 if (--lim == 0) {
179 printk(KERN_ALERT PFX "esp%d: ESP_FF_BYTES " 208 shost_printk(KERN_ALERT, esp->host,
180 "will not clear!\n", 209 "ESP_FF_BYTES will not clear!\n");
181 esp->host->unique_id);
182 break; 210 break;
183 } 211 }
184 udelay(1); 212 udelay(1);
@@ -240,6 +268,19 @@ static void esp_reset_esp(struct esp *esp)
240 } else { 268 } else {
241 esp->min_period = ((5 * esp->ccycle) / 1000); 269 esp->min_period = ((5 * esp->ccycle) / 1000);
242 } 270 }
271 if (esp->rev == FAS236) {
272 /*
273 * The AM53c974 chip returns the same ID as FAS236;
274 * try to configure glitch eater.
275 */
276 u8 config4 = ESP_CONFIG4_GE1;
277 esp_write8(config4, ESP_CFG4);
278 config4 = esp_read8(ESP_CFG4);
279 if (config4 & ESP_CONFIG4_GE1) {
280 esp->rev = PCSCSI;
281 esp_write8(esp->config4, ESP_CFG4);
282 }
283 }
243 esp->max_period = (esp->max_period + 3)>>2; 284 esp->max_period = (esp->max_period + 3)>>2;
244 esp->min_period = (esp->min_period + 3)>>2; 285 esp->min_period = (esp->min_period + 3)>>2;
245 286
@@ -265,7 +306,8 @@ static void esp_reset_esp(struct esp *esp)
265 /* fallthrough... */ 306 /* fallthrough... */
266 307
267 case FAS236: 308 case FAS236:
268 /* Fast 236 or HME */ 309 case PCSCSI:
310 /* Fast 236, AM53c974 or HME */
269 esp_write8(esp->config2, ESP_CFG2); 311 esp_write8(esp->config2, ESP_CFG2);
270 if (esp->rev == FASHME) { 312 if (esp->rev == FASHME) {
271 u8 cfg3 = esp->target[0].esp_config3; 313 u8 cfg3 = esp->target[0].esp_config3;
@@ -383,12 +425,11 @@ static void esp_advance_dma(struct esp *esp, struct esp_cmd_entry *ent,
383 p->cur_residue -= len; 425 p->cur_residue -= len;
384 p->tot_residue -= len; 426 p->tot_residue -= len;
385 if (p->cur_residue < 0 || p->tot_residue < 0) { 427 if (p->cur_residue < 0 || p->tot_residue < 0) {
386 printk(KERN_ERR PFX "esp%d: Data transfer overflow.\n", 428 shost_printk(KERN_ERR, esp->host,
387 esp->host->unique_id); 429 "Data transfer overflow.\n");
388 printk(KERN_ERR PFX "esp%d: cur_residue[%d] tot_residue[%d] " 430 shost_printk(KERN_ERR, esp->host,
389 "len[%u]\n", 431 "cur_residue[%d] tot_residue[%d] len[%u]\n",
390 esp->host->unique_id, 432 p->cur_residue, p->tot_residue, len);
391 p->cur_residue, p->tot_residue, len);
392 p->cur_residue = 0; 433 p->cur_residue = 0;
393 p->tot_residue = 0; 434 p->tot_residue = 0;
394 } 435 }
@@ -604,9 +645,8 @@ static void esp_autosense(struct esp *esp, struct esp_cmd_entry *ent)
604 645
605 646
606 if (!ent->sense_ptr) { 647 if (!ent->sense_ptr) {
607 esp_log_autosense("esp%d: Doing auto-sense for " 648 esp_log_autosense("Doing auto-sense for tgt[%d] lun[%d]\n",
608 "tgt[%d] lun[%d]\n", 649 tgt, lun);
609 esp->host->unique_id, tgt, lun);
610 650
611 ent->sense_ptr = cmd->sense_buffer; 651 ent->sense_ptr = cmd->sense_buffer;
612 ent->sense_dma = esp->ops->map_single(esp, 652 ent->sense_dma = esp->ops->map_single(esp,
@@ -642,10 +682,7 @@ static void esp_autosense(struct esp *esp, struct esp_cmd_entry *ent)
642 682
643 val = (p - esp->command_block); 683 val = (p - esp->command_block);
644 684
645 if (esp->rev == FASHME) 685 esp_send_dma_cmd(esp, val, 16, ESP_CMD_SELA);
646 scsi_esp_cmd(esp, ESP_CMD_FLUSH);
647 esp->ops->send_dma_cmd(esp, esp->command_block_dma,
648 val, 16, 0, ESP_CMD_DMA | ESP_CMD_SELA);
649} 686}
650 687
651static struct esp_cmd_entry *find_and_prep_issuable_command(struct esp *esp) 688static struct esp_cmd_entry *find_and_prep_issuable_command(struct esp *esp)
@@ -663,7 +700,7 @@ static struct esp_cmd_entry *find_and_prep_issuable_command(struct esp *esp)
663 return ent; 700 return ent;
664 } 701 }
665 702
666 if (!scsi_populate_tag_msg(cmd, &ent->tag[0])) { 703 if (!spi_populate_tag_msg(&ent->tag[0], cmd)) {
667 ent->tag[0] = 0; 704 ent->tag[0] = 0;
668 ent->tag[1] = 0; 705 ent->tag[1] = 0;
669 } 706 }
@@ -781,12 +818,12 @@ build_identify:
781 } 818 }
782 819
783 if (!(esp->flags & ESP_FLAG_DOING_SLOWCMD)) { 820 if (!(esp->flags & ESP_FLAG_DOING_SLOWCMD)) {
784 start_cmd = ESP_CMD_DMA | ESP_CMD_SELA; 821 start_cmd = ESP_CMD_SELA;
785 if (ent->tag[0]) { 822 if (ent->tag[0]) {
786 *p++ = ent->tag[0]; 823 *p++ = ent->tag[0];
787 *p++ = ent->tag[1]; 824 *p++ = ent->tag[1];
788 825
789 start_cmd = ESP_CMD_DMA | ESP_CMD_SA3; 826 start_cmd = ESP_CMD_SA3;
790 } 827 }
791 828
792 for (i = 0; i < cmd->cmd_len; i++) 829 for (i = 0; i < cmd->cmd_len; i++)
@@ -806,7 +843,7 @@ build_identify:
806 esp->msg_out_len += 2; 843 esp->msg_out_len += 2;
807 } 844 }
808 845
809 start_cmd = ESP_CMD_DMA | ESP_CMD_SELAS; 846 start_cmd = ESP_CMD_SELAS;
810 esp->select_state = ESP_SELECT_MSGOUT; 847 esp->select_state = ESP_SELECT_MSGOUT;
811 } 848 }
812 val = tgt; 849 val = tgt;
@@ -826,10 +863,7 @@ build_identify:
826 printk("]\n"); 863 printk("]\n");
827 } 864 }
828 865
829 if (esp->rev == FASHME) 866 esp_send_dma_cmd(esp, val, 16, start_cmd);
830 scsi_esp_cmd(esp, ESP_CMD_FLUSH);
831 esp->ops->send_dma_cmd(esp, esp->command_block_dma,
832 val, 16, 0, start_cmd);
833} 867}
834 868
835static struct esp_cmd_entry *esp_get_ent(struct esp *esp) 869static struct esp_cmd_entry *esp_get_ent(struct esp *esp)
@@ -953,8 +987,8 @@ static int esp_check_gross_error(struct esp *esp)
953 * - DMA programmed with wrong direction 987 * - DMA programmed with wrong direction
954 * - improper phase change 988 * - improper phase change
955 */ 989 */
956 printk(KERN_ERR PFX "esp%d: Gross error sreg[%02x]\n", 990 shost_printk(KERN_ERR, esp->host,
957 esp->host->unique_id, esp->sreg); 991 "Gross error sreg[%02x]\n", esp->sreg);
958 /* XXX Reset the chip. XXX */ 992 /* XXX Reset the chip. XXX */
959 return 1; 993 return 1;
960 } 994 }
@@ -974,7 +1008,6 @@ static int esp_check_spur_intr(struct esp *esp)
974 1008
975 default: 1009 default:
976 if (!(esp->sreg & ESP_STAT_INTR)) { 1010 if (!(esp->sreg & ESP_STAT_INTR)) {
977 esp->ireg = esp_read8(ESP_INTRPT);
978 if (esp->ireg & ESP_INTR_SR) 1011 if (esp->ireg & ESP_INTR_SR)
979 return 1; 1012 return 1;
980 1013
@@ -982,14 +1015,13 @@ static int esp_check_spur_intr(struct esp *esp)
982 * ESP is not, the only possibility is a DMA error. 1015 * ESP is not, the only possibility is a DMA error.
983 */ 1016 */
984 if (!esp->ops->dma_error(esp)) { 1017 if (!esp->ops->dma_error(esp)) {
985 printk(KERN_ERR PFX "esp%d: Spurious irq, " 1018 shost_printk(KERN_ERR, esp->host,
986 "sreg=%02x.\n", 1019 "Spurious irq, sreg=%02x.\n",
987 esp->host->unique_id, esp->sreg); 1020 esp->sreg);
988 return -1; 1021 return -1;
989 } 1022 }
990 1023
991 printk(KERN_ERR PFX "esp%d: DMA error\n", 1024 shost_printk(KERN_ERR, esp->host, "DMA error\n");
992 esp->host->unique_id);
993 1025
994 /* XXX Reset the chip. XXX */ 1026 /* XXX Reset the chip. XXX */
995 return -1; 1027 return -1;
@@ -1002,7 +1034,7 @@ static int esp_check_spur_intr(struct esp *esp)
1002 1034
1003static void esp_schedule_reset(struct esp *esp) 1035static void esp_schedule_reset(struct esp *esp)
1004{ 1036{
1005 esp_log_reset("ESP: esp_schedule_reset() from %pf\n", 1037 esp_log_reset("esp_schedule_reset() from %pf\n",
1006 __builtin_return_address(0)); 1038 __builtin_return_address(0));
1007 esp->flags |= ESP_FLAG_RESETTING; 1039 esp->flags |= ESP_FLAG_RESETTING;
1008 esp_event(esp, ESP_EVENT_RESET); 1040 esp_event(esp, ESP_EVENT_RESET);
@@ -1019,20 +1051,20 @@ static struct esp_cmd_entry *esp_reconnect_with_tag(struct esp *esp,
1019 int i; 1051 int i;
1020 1052
1021 if (!lp->num_tagged) { 1053 if (!lp->num_tagged) {
1022 printk(KERN_ERR PFX "esp%d: Reconnect w/num_tagged==0\n", 1054 shost_printk(KERN_ERR, esp->host,
1023 esp->host->unique_id); 1055 "Reconnect w/num_tagged==0\n");
1024 return NULL; 1056 return NULL;
1025 } 1057 }
1026 1058
1027 esp_log_reconnect("ESP: reconnect tag, "); 1059 esp_log_reconnect("reconnect tag, ");
1028 1060
1029 for (i = 0; i < ESP_QUICKIRQ_LIMIT; i++) { 1061 for (i = 0; i < ESP_QUICKIRQ_LIMIT; i++) {
1030 if (esp->ops->irq_pending(esp)) 1062 if (esp->ops->irq_pending(esp))
1031 break; 1063 break;
1032 } 1064 }
1033 if (i == ESP_QUICKIRQ_LIMIT) { 1065 if (i == ESP_QUICKIRQ_LIMIT) {
1034 printk(KERN_ERR PFX "esp%d: Reconnect IRQ1 timeout\n", 1066 shost_printk(KERN_ERR, esp->host,
1035 esp->host->unique_id); 1067 "Reconnect IRQ1 timeout\n");
1036 return NULL; 1068 return NULL;
1037 } 1069 }
1038 1070
@@ -1043,14 +1075,14 @@ static struct esp_cmd_entry *esp_reconnect_with_tag(struct esp *esp,
1043 i, esp->ireg, esp->sreg); 1075 i, esp->ireg, esp->sreg);
1044 1076
1045 if (esp->ireg & ESP_INTR_DC) { 1077 if (esp->ireg & ESP_INTR_DC) {
1046 printk(KERN_ERR PFX "esp%d: Reconnect, got disconnect.\n", 1078 shost_printk(KERN_ERR, esp->host,
1047 esp->host->unique_id); 1079 "Reconnect, got disconnect.\n");
1048 return NULL; 1080 return NULL;
1049 } 1081 }
1050 1082
1051 if ((esp->sreg & ESP_STAT_PMASK) != ESP_MIP) { 1083 if ((esp->sreg & ESP_STAT_PMASK) != ESP_MIP) {
1052 printk(KERN_ERR PFX "esp%d: Reconnect, not MIP sreg[%02x].\n", 1084 shost_printk(KERN_ERR, esp->host,
1053 esp->host->unique_id, esp->sreg); 1085 "Reconnect, not MIP sreg[%02x].\n", esp->sreg);
1054 return NULL; 1086 return NULL;
1055 } 1087 }
1056 1088
@@ -1073,8 +1105,7 @@ static struct esp_cmd_entry *esp_reconnect_with_tag(struct esp *esp,
1073 udelay(1); 1105 udelay(1);
1074 } 1106 }
1075 if (i == ESP_RESELECT_TAG_LIMIT) { 1107 if (i == ESP_RESELECT_TAG_LIMIT) {
1076 printk(KERN_ERR PFX "esp%d: Reconnect IRQ2 timeout\n", 1108 shost_printk(KERN_ERR, esp->host, "Reconnect IRQ2 timeout\n");
1077 esp->host->unique_id);
1078 return NULL; 1109 return NULL;
1079 } 1110 }
1080 esp->ops->dma_drain(esp); 1111 esp->ops->dma_drain(esp);
@@ -1087,17 +1118,17 @@ static struct esp_cmd_entry *esp_reconnect_with_tag(struct esp *esp,
1087 1118
1088 if (esp->command_block[0] < SIMPLE_QUEUE_TAG || 1119 if (esp->command_block[0] < SIMPLE_QUEUE_TAG ||
1089 esp->command_block[0] > ORDERED_QUEUE_TAG) { 1120 esp->command_block[0] > ORDERED_QUEUE_TAG) {
1090 printk(KERN_ERR PFX "esp%d: Reconnect, bad tag " 1121 shost_printk(KERN_ERR, esp->host,
1091 "type %02x.\n", 1122 "Reconnect, bad tag type %02x.\n",
1092 esp->host->unique_id, esp->command_block[0]); 1123 esp->command_block[0]);
1093 return NULL; 1124 return NULL;
1094 } 1125 }
1095 1126
1096 ent = lp->tagged_cmds[esp->command_block[1]]; 1127 ent = lp->tagged_cmds[esp->command_block[1]];
1097 if (!ent) { 1128 if (!ent) {
1098 printk(KERN_ERR PFX "esp%d: Reconnect, no entry for " 1129 shost_printk(KERN_ERR, esp->host,
1099 "tag %02x.\n", 1130 "Reconnect, no entry for tag %02x.\n",
1100 esp->host->unique_id, esp->command_block[1]); 1131 esp->command_block[1]);
1101 return NULL; 1132 return NULL;
1102 } 1133 }
1103 1134
@@ -1163,9 +1194,9 @@ static int esp_reconnect(struct esp *esp)
1163 tp = &esp->target[target]; 1194 tp = &esp->target[target];
1164 dev = __scsi_device_lookup_by_target(tp->starget, lun); 1195 dev = __scsi_device_lookup_by_target(tp->starget, lun);
1165 if (!dev) { 1196 if (!dev) {
1166 printk(KERN_ERR PFX "esp%d: Reconnect, no lp " 1197 shost_printk(KERN_ERR, esp->host,
1167 "tgt[%u] lun[%u]\n", 1198 "Reconnect, no lp tgt[%u] lun[%u]\n",
1168 esp->host->unique_id, target, lun); 1199 target, lun);
1169 goto do_reset; 1200 goto do_reset;
1170 } 1201 }
1171 lp = dev->hostdata; 1202 lp = dev->hostdata;
@@ -1291,8 +1322,8 @@ static int esp_finish_select(struct esp *esp)
1291 return 0; 1322 return 0;
1292 } 1323 }
1293 1324
1294 printk("ESP: Unexpected selection completion ireg[%x].\n", 1325 shost_printk(KERN_INFO, esp->host,
1295 esp->ireg); 1326 "Unexpected selection completion ireg[%x]\n", esp->ireg);
1296 esp_schedule_reset(esp); 1327 esp_schedule_reset(esp);
1297 return 0; 1328 return 0;
1298} 1329}
@@ -1312,11 +1343,42 @@ static int esp_data_bytes_sent(struct esp *esp, struct esp_cmd_entry *ent,
1312 (((unsigned int)esp_read8(ESP_TCMED)) << 8)); 1343 (((unsigned int)esp_read8(ESP_TCMED)) << 8));
1313 if (esp->rev == FASHME) 1344 if (esp->rev == FASHME)
1314 ecount |= ((unsigned int)esp_read8(FAS_RLO)) << 16; 1345 ecount |= ((unsigned int)esp_read8(FAS_RLO)) << 16;
1346 if (esp->rev == PCSCSI && (esp->config2 & ESP_CONFIG2_FENAB))
1347 ecount |= ((unsigned int)esp_read8(ESP_TCHI)) << 16;
1315 } 1348 }
1316 1349
1317 bytes_sent = esp->data_dma_len; 1350 bytes_sent = esp->data_dma_len;
1318 bytes_sent -= ecount; 1351 bytes_sent -= ecount;
1319 1352
1353 /*
1354 * The am53c974 has a DMA 'pecularity'. The doc states:
1355 * In some odd byte conditions, one residual byte will
1356 * be left in the SCSI FIFO, and the FIFO Flags will
1357 * never count to '0 '. When this happens, the residual
1358 * byte should be retrieved via PIO following completion
1359 * of the BLAST operation.
1360 */
1361 if (fifo_cnt == 1 && ent->flags & ESP_CMD_FLAG_RESIDUAL) {
1362 size_t count = 1;
1363 size_t offset = bytes_sent;
1364 u8 bval = esp_read8(ESP_FDATA);
1365
1366 if (ent->flags & ESP_CMD_FLAG_AUTOSENSE)
1367 ent->sense_ptr[bytes_sent] = bval;
1368 else {
1369 struct esp_cmd_priv *p = ESP_CMD_PRIV(cmd);
1370 u8 *ptr;
1371
1372 ptr = scsi_kmap_atomic_sg(p->cur_sg, p->u.num_sg,
1373 &offset, &count);
1374 if (likely(ptr)) {
1375 *(ptr + offset) = bval;
1376 scsi_kunmap_atomic_sg(ptr);
1377 }
1378 }
1379 bytes_sent += fifo_cnt;
1380 ent->flags &= ~ESP_CMD_FLAG_RESIDUAL;
1381 }
1320 if (!(ent->flags & ESP_CMD_FLAG_WRITE)) 1382 if (!(ent->flags & ESP_CMD_FLAG_WRITE))
1321 bytes_sent -= fifo_cnt; 1383 bytes_sent -= fifo_cnt;
1322 1384
@@ -1556,8 +1618,8 @@ static void esp_msgin_extended(struct esp *esp)
1556 return; 1618 return;
1557 } 1619 }
1558 1620
1559 printk("ESP: Unexpected extended msg type %x\n", 1621 shost_printk(KERN_INFO, esp->host,
1560 esp->msg_in[2]); 1622 "Unexpected extended msg type %x\n", esp->msg_in[2]);
1561 1623
1562 esp->msg_out[0] = ABORT_TASK_SET; 1624 esp->msg_out[0] = ABORT_TASK_SET;
1563 esp->msg_out_len = 1; 1625 esp->msg_out_len = 1;
@@ -1574,7 +1636,8 @@ static int esp_msgin_process(struct esp *esp)
1574 1636
1575 if (msg0 & 0x80) { 1637 if (msg0 & 0x80) {
1576 /* Identify */ 1638 /* Identify */
1577 printk("ESP: Unexpected msgin identify\n"); 1639 shost_printk(KERN_INFO, esp->host,
1640 "Unexpected msgin identify\n");
1578 return 0; 1641 return 0;
1579 } 1642 }
1580 1643
@@ -1640,10 +1703,12 @@ static int esp_msgin_process(struct esp *esp)
1640 1703
1641static int esp_process_event(struct esp *esp) 1704static int esp_process_event(struct esp *esp)
1642{ 1705{
1643 int write; 1706 int write, i;
1644 1707
1645again: 1708again:
1646 write = 0; 1709 write = 0;
1710 esp_log_event("process event %d phase %x\n",
1711 esp->event, esp->sreg & ESP_STAT_PMASK);
1647 switch (esp->event) { 1712 switch (esp->event) {
1648 case ESP_EVENT_CHECK_PHASE: 1713 case ESP_EVENT_CHECK_PHASE:
1649 switch (esp->sreg & ESP_STAT_PMASK) { 1714 switch (esp->sreg & ESP_STAT_PMASK) {
@@ -1673,8 +1738,9 @@ again:
1673 break; 1738 break;
1674 1739
1675 default: 1740 default:
1676 printk("ESP: Unexpected phase, sreg=%02x\n", 1741 shost_printk(KERN_INFO, esp->host,
1677 esp->sreg); 1742 "Unexpected phase, sreg=%02x\n",
1743 esp->sreg);
1678 esp_schedule_reset(esp); 1744 esp_schedule_reset(esp);
1679 return 0; 1745 return 0;
1680 } 1746 }
@@ -1708,18 +1774,17 @@ again:
1708 esp->data_dma_len = dma_len; 1774 esp->data_dma_len = dma_len;
1709 1775
1710 if (!dma_len) { 1776 if (!dma_len) {
1711 printk(KERN_ERR PFX "esp%d: DMA length is zero!\n", 1777 shost_printk(KERN_ERR, esp->host,
1712 esp->host->unique_id); 1778 "DMA length is zero!\n");
1713 printk(KERN_ERR PFX "esp%d: cur adr[%08llx] len[%08x]\n", 1779 shost_printk(KERN_ERR, esp->host,
1714 esp->host->unique_id, 1780 "cur adr[%08llx] len[%08x]\n",
1715 (unsigned long long)esp_cur_dma_addr(ent, cmd), 1781 (unsigned long long)esp_cur_dma_addr(ent, cmd),
1716 esp_cur_dma_len(ent, cmd)); 1782 esp_cur_dma_len(ent, cmd));
1717 esp_schedule_reset(esp); 1783 esp_schedule_reset(esp);
1718 return 0; 1784 return 0;
1719 } 1785 }
1720 1786
1721 esp_log_datastart("ESP: start data addr[%08llx] len[%u] " 1787 esp_log_datastart("start data addr[%08llx] len[%u] write(%d)\n",
1722 "write(%d)\n",
1723 (unsigned long long)dma_addr, dma_len, write); 1788 (unsigned long long)dma_addr, dma_len, write);
1724 1789
1725 esp->ops->send_dma_cmd(esp, dma_addr, dma_len, dma_len, 1790 esp->ops->send_dma_cmd(esp, dma_addr, dma_len, dma_len,
@@ -1733,7 +1798,8 @@ again:
1733 int bytes_sent; 1798 int bytes_sent;
1734 1799
1735 if (esp->ops->dma_error(esp)) { 1800 if (esp->ops->dma_error(esp)) {
1736 printk("ESP: data done, DMA error, resetting\n"); 1801 shost_printk(KERN_INFO, esp->host,
1802 "data done, DMA error, resetting\n");
1737 esp_schedule_reset(esp); 1803 esp_schedule_reset(esp);
1738 return 0; 1804 return 0;
1739 } 1805 }
@@ -1749,14 +1815,15 @@ again:
1749 /* We should always see exactly a bus-service 1815 /* We should always see exactly a bus-service
1750 * interrupt at the end of a successful transfer. 1816 * interrupt at the end of a successful transfer.
1751 */ 1817 */
1752 printk("ESP: data done, not BSERV, resetting\n"); 1818 shost_printk(KERN_INFO, esp->host,
1819 "data done, not BSERV, resetting\n");
1753 esp_schedule_reset(esp); 1820 esp_schedule_reset(esp);
1754 return 0; 1821 return 0;
1755 } 1822 }
1756 1823
1757 bytes_sent = esp_data_bytes_sent(esp, ent, cmd); 1824 bytes_sent = esp_data_bytes_sent(esp, ent, cmd);
1758 1825
1759 esp_log_datadone("ESP: data done flgs[%x] sent[%d]\n", 1826 esp_log_datadone("data done flgs[%x] sent[%d]\n",
1760 ent->flags, bytes_sent); 1827 ent->flags, bytes_sent);
1761 1828
1762 if (bytes_sent < 0) { 1829 if (bytes_sent < 0) {
@@ -1785,8 +1852,9 @@ again:
1785 } 1852 }
1786 1853
1787 if (ent->message != COMMAND_COMPLETE) { 1854 if (ent->message != COMMAND_COMPLETE) {
1788 printk("ESP: Unexpected message %x in status\n", 1855 shost_printk(KERN_INFO, esp->host,
1789 ent->message); 1856 "Unexpected message %x in status\n",
1857 ent->message);
1790 esp_schedule_reset(esp); 1858 esp_schedule_reset(esp);
1791 return 0; 1859 return 0;
1792 } 1860 }
@@ -1804,8 +1872,7 @@ again:
1804 scsi_esp_cmd(esp, ESP_CMD_ESEL); 1872 scsi_esp_cmd(esp, ESP_CMD_ESEL);
1805 1873
1806 if (ent->message == COMMAND_COMPLETE) { 1874 if (ent->message == COMMAND_COMPLETE) {
1807 esp_log_cmddone("ESP: Command done status[%x] " 1875 esp_log_cmddone("Command done status[%x] message[%x]\n",
1808 "message[%x]\n",
1809 ent->status, ent->message); 1876 ent->status, ent->message);
1810 if (ent->status == SAM_STAT_TASK_SET_FULL) 1877 if (ent->status == SAM_STAT_TASK_SET_FULL)
1811 esp_event_queue_full(esp, ent); 1878 esp_event_queue_full(esp, ent);
@@ -1821,16 +1888,16 @@ again:
1821 DID_OK)); 1888 DID_OK));
1822 } 1889 }
1823 } else if (ent->message == DISCONNECT) { 1890 } else if (ent->message == DISCONNECT) {
1824 esp_log_disconnect("ESP: Disconnecting tgt[%d] " 1891 esp_log_disconnect("Disconnecting tgt[%d] tag[%x:%x]\n",
1825 "tag[%x:%x]\n",
1826 cmd->device->id, 1892 cmd->device->id,
1827 ent->tag[0], ent->tag[1]); 1893 ent->tag[0], ent->tag[1]);
1828 1894
1829 esp->active_cmd = NULL; 1895 esp->active_cmd = NULL;
1830 esp_maybe_execute_command(esp); 1896 esp_maybe_execute_command(esp);
1831 } else { 1897 } else {
1832 printk("ESP: Unexpected message %x in freebus\n", 1898 shost_printk(KERN_INFO, esp->host,
1833 ent->message); 1899 "Unexpected message %x in freebus\n",
1900 ent->message);
1834 esp_schedule_reset(esp); 1901 esp_schedule_reset(esp);
1835 return 0; 1902 return 0;
1836 } 1903 }
@@ -1862,6 +1929,10 @@ again:
1862 if (esp->msg_out_len == 1) { 1929 if (esp->msg_out_len == 1) {
1863 esp_write8(esp->msg_out[0], ESP_FDATA); 1930 esp_write8(esp->msg_out[0], ESP_FDATA);
1864 scsi_esp_cmd(esp, ESP_CMD_TI); 1931 scsi_esp_cmd(esp, ESP_CMD_TI);
1932 } else if (esp->flags & ESP_FLAG_USE_FIFO) {
1933 for (i = 0; i < esp->msg_out_len; i++)
1934 esp_write8(esp->msg_out[i], ESP_FDATA);
1935 scsi_esp_cmd(esp, ESP_CMD_TI);
1865 } else { 1936 } else {
1866 /* Use DMA. */ 1937 /* Use DMA. */
1867 memcpy(esp->command_block, 1938 memcpy(esp->command_block,
@@ -1917,7 +1988,7 @@ again:
1917 val = esp_read8(ESP_FDATA); 1988 val = esp_read8(ESP_FDATA);
1918 esp->msg_in[esp->msg_in_len++] = val; 1989 esp->msg_in[esp->msg_in_len++] = val;
1919 1990
1920 esp_log_msgin("ESP: Got msgin byte %x\n", val); 1991 esp_log_msgin("Got msgin byte %x\n", val);
1921 1992
1922 if (!esp_msgin_process(esp)) 1993 if (!esp_msgin_process(esp))
1923 esp->msg_in_len = 0; 1994 esp->msg_in_len = 0;
@@ -1930,7 +2001,8 @@ again:
1930 if (esp->event != ESP_EVENT_FREE_BUS) 2001 if (esp->event != ESP_EVENT_FREE_BUS)
1931 esp_event(esp, ESP_EVENT_CHECK_PHASE); 2002 esp_event(esp, ESP_EVENT_CHECK_PHASE);
1932 } else { 2003 } else {
1933 printk("ESP: MSGIN neither BSERV not FDON, resetting"); 2004 shost_printk(KERN_INFO, esp->host,
2005 "MSGIN neither BSERV not FDON, resetting");
1934 esp_schedule_reset(esp); 2006 esp_schedule_reset(esp);
1935 return 0; 2007 return 0;
1936 } 2008 }
@@ -1938,11 +2010,7 @@ again:
1938 case ESP_EVENT_CMD_START: 2010 case ESP_EVENT_CMD_START:
1939 memcpy(esp->command_block, esp->cmd_bytes_ptr, 2011 memcpy(esp->command_block, esp->cmd_bytes_ptr,
1940 esp->cmd_bytes_left); 2012 esp->cmd_bytes_left);
1941 if (esp->rev == FASHME) 2013 esp_send_dma_cmd(esp, esp->cmd_bytes_left, 16, ESP_CMD_TI);
1942 scsi_esp_cmd(esp, ESP_CMD_FLUSH);
1943 esp->ops->send_dma_cmd(esp, esp->command_block_dma,
1944 esp->cmd_bytes_left, 16, 0,
1945 ESP_CMD_DMA | ESP_CMD_TI);
1946 esp_event(esp, ESP_EVENT_CMD_DONE); 2014 esp_event(esp, ESP_EVENT_CMD_DONE);
1947 esp->flags |= ESP_FLAG_QUICKIRQ_CHECK; 2015 esp->flags |= ESP_FLAG_QUICKIRQ_CHECK;
1948 break; 2016 break;
@@ -1961,8 +2029,8 @@ again:
1961 break; 2029 break;
1962 2030
1963 default: 2031 default:
1964 printk("ESP: Unexpected event %x, resetting\n", 2032 shost_printk(KERN_INFO, esp->host,
1965 esp->event); 2033 "Unexpected event %x, resetting\n", esp->event);
1966 esp_schedule_reset(esp); 2034 esp_schedule_reset(esp);
1967 return 0; 2035 return 0;
1968 break; 2036 break;
@@ -2044,7 +2112,12 @@ static void __esp_interrupt(struct esp *esp)
2044 int finish_reset, intr_done; 2112 int finish_reset, intr_done;
2045 u8 phase; 2113 u8 phase;
2046 2114
2115 /*
2116 * Once INTRPT is read STATUS and SSTEP are cleared.
2117 */
2047 esp->sreg = esp_read8(ESP_STATUS); 2118 esp->sreg = esp_read8(ESP_STATUS);
2119 esp->seqreg = esp_read8(ESP_SSTEP);
2120 esp->ireg = esp_read8(ESP_INTRPT);
2048 2121
2049 if (esp->flags & ESP_FLAG_RESETTING) { 2122 if (esp->flags & ESP_FLAG_RESETTING) {
2050 finish_reset = 1; 2123 finish_reset = 1;
@@ -2057,8 +2130,6 @@ static void __esp_interrupt(struct esp *esp)
2057 return; 2130 return;
2058 } 2131 }
2059 2132
2060 esp->ireg = esp_read8(ESP_INTRPT);
2061
2062 if (esp->ireg & ESP_INTR_SR) 2133 if (esp->ireg & ESP_INTR_SR)
2063 finish_reset = 1; 2134 finish_reset = 1;
2064 2135
@@ -2085,14 +2156,15 @@ static void __esp_interrupt(struct esp *esp)
2085 } 2156 }
2086 } 2157 }
2087 2158
2088 esp_log_intr("ESP: intr sreg[%02x] seqreg[%02x] " 2159 esp_log_intr("intr sreg[%02x] seqreg[%02x] "
2089 "sreg2[%02x] ireg[%02x]\n", 2160 "sreg2[%02x] ireg[%02x]\n",
2090 esp->sreg, esp->seqreg, esp->sreg2, esp->ireg); 2161 esp->sreg, esp->seqreg, esp->sreg2, esp->ireg);
2091 2162
2092 intr_done = 0; 2163 intr_done = 0;
2093 2164
2094 if (esp->ireg & (ESP_INTR_S | ESP_INTR_SATN | ESP_INTR_IC)) { 2165 if (esp->ireg & (ESP_INTR_S | ESP_INTR_SATN | ESP_INTR_IC)) {
2095 printk("ESP: unexpected IREG %02x\n", esp->ireg); 2166 shost_printk(KERN_INFO, esp->host,
2167 "unexpected IREG %02x\n", esp->ireg);
2096 if (esp->ireg & ESP_INTR_IC) 2168 if (esp->ireg & ESP_INTR_IC)
2097 esp_dump_cmd_log(esp); 2169 esp_dump_cmd_log(esp);
2098 2170
@@ -2149,46 +2221,50 @@ static void esp_get_revision(struct esp *esp)
2149 u8 val; 2221 u8 val;
2150 2222
2151 esp->config1 = (ESP_CONFIG1_PENABLE | (esp->scsi_id & 7)); 2223 esp->config1 = (ESP_CONFIG1_PENABLE | (esp->scsi_id & 7));
2152 esp->config2 = (ESP_CONFIG2_SCSI2ENAB | ESP_CONFIG2_REGPARITY); 2224 if (esp->config2 == 0) {
2225 esp->config2 = (ESP_CONFIG2_SCSI2ENAB | ESP_CONFIG2_REGPARITY);
2226 esp_write8(esp->config2, ESP_CFG2);
2227
2228 val = esp_read8(ESP_CFG2);
2229 val &= ~ESP_CONFIG2_MAGIC;
2230
2231 esp->config2 = 0;
2232 if (val != (ESP_CONFIG2_SCSI2ENAB | ESP_CONFIG2_REGPARITY)) {
2233 /*
2234 * If what we write to cfg2 does not come back,
2235 * cfg2 is not implemented.
2236 * Therefore this must be a plain esp100.
2237 */
2238 esp->rev = ESP100;
2239 return;
2240 }
2241 }
2242
2243 esp_set_all_config3(esp, 5);
2244 esp->prev_cfg3 = 5;
2153 esp_write8(esp->config2, ESP_CFG2); 2245 esp_write8(esp->config2, ESP_CFG2);
2246 esp_write8(0, ESP_CFG3);
2247 esp_write8(esp->prev_cfg3, ESP_CFG3);
2154 2248
2155 val = esp_read8(ESP_CFG2); 2249 val = esp_read8(ESP_CFG3);
2156 val &= ~ESP_CONFIG2_MAGIC; 2250 if (val != 5) {
2157 if (val != (ESP_CONFIG2_SCSI2ENAB | ESP_CONFIG2_REGPARITY)) { 2251 /* The cfg2 register is implemented, however
2158 /* If what we write to cfg2 does not come back, cfg2 is not 2252 * cfg3 is not, must be esp100a.
2159 * implemented, therefore this must be a plain esp100.
2160 */ 2253 */
2161 esp->rev = ESP100; 2254 esp->rev = ESP100A;
2162 } else { 2255 } else {
2163 esp->config2 = 0; 2256 esp_set_all_config3(esp, 0);
2164 esp_set_all_config3(esp, 5); 2257 esp->prev_cfg3 = 0;
2165 esp->prev_cfg3 = 5;
2166 esp_write8(esp->config2, ESP_CFG2);
2167 esp_write8(0, ESP_CFG3);
2168 esp_write8(esp->prev_cfg3, ESP_CFG3); 2258 esp_write8(esp->prev_cfg3, ESP_CFG3);
2169 2259
2170 val = esp_read8(ESP_CFG3); 2260 /* All of cfg{1,2,3} implemented, must be one of
2171 if (val != 5) { 2261 * the fas variants, figure out which one.
2172 /* The cfg2 register is implemented, however 2262 */
2173 * cfg3 is not, must be esp100a. 2263 if (esp->cfact == 0 || esp->cfact > ESP_CCF_F5) {
2174 */ 2264 esp->rev = FAST;
2175 esp->rev = ESP100A; 2265 esp->sync_defp = SYNC_DEFP_FAST;
2176 } else { 2266 } else {
2177 esp_set_all_config3(esp, 0); 2267 esp->rev = ESP236;
2178 esp->prev_cfg3 = 0;
2179 esp_write8(esp->prev_cfg3, ESP_CFG3);
2180
2181 /* All of cfg{1,2,3} implemented, must be one of
2182 * the fas variants, figure out which one.
2183 */
2184 if (esp->cfact == 0 || esp->cfact > ESP_CCF_F5) {
2185 esp->rev = FAST;
2186 esp->sync_defp = SYNC_DEFP_FAST;
2187 } else {
2188 esp->rev = ESP236;
2189 }
2190 esp->config2 = 0;
2191 esp_write8(esp->config2, ESP_CFG2);
2192 } 2268 }
2193 } 2269 }
2194} 2270}
@@ -2308,6 +2384,7 @@ static const char *esp_chip_names[] = {
2308 "FAS100A", 2384 "FAS100A",
2309 "FAST", 2385 "FAST",
2310 "FASHME", 2386 "FASHME",
2387 "AM53C974",
2311}; 2388};
2312 2389
2313static struct scsi_transport_template *esp_transport_template; 2390static struct scsi_transport_template *esp_transport_template;
@@ -2317,6 +2394,10 @@ int scsi_esp_register(struct esp *esp, struct device *dev)
2317 static int instance; 2394 static int instance;
2318 int err; 2395 int err;
2319 2396
2397 if (!esp->num_tags)
2398 esp->num_tags = ESP_DEFAULT_TAGS;
2399 else if (esp->num_tags >= ESP_MAX_TAG)
2400 esp->num_tags = ESP_MAX_TAG - 1;
2320 esp->host->transportt = esp_transport_template; 2401 esp->host->transportt = esp_transport_template;
2321 esp->host->max_lun = ESP_MAX_LUN; 2402 esp->host->max_lun = ESP_MAX_LUN;
2322 esp->host->cmd_per_lun = 2; 2403 esp->host->cmd_per_lun = 2;
@@ -2330,12 +2411,13 @@ int scsi_esp_register(struct esp *esp, struct device *dev)
2330 2411
2331 esp_bootup_reset(esp); 2412 esp_bootup_reset(esp);
2332 2413
2333 printk(KERN_INFO PFX "esp%u, regs[%1p:%1p] irq[%u]\n", 2414 dev_printk(KERN_INFO, dev, "esp%u: regs[%1p:%1p] irq[%u]\n",
2334 esp->host->unique_id, esp->regs, esp->dma_regs, 2415 esp->host->unique_id, esp->regs, esp->dma_regs,
2335 esp->host->irq); 2416 esp->host->irq);
2336 printk(KERN_INFO PFX "esp%u is a %s, %u MHz (ccf=%u), SCSI ID %u\n", 2417 dev_printk(KERN_INFO, dev,
2337 esp->host->unique_id, esp_chip_names[esp->rev], 2418 "esp%u: is a %s, %u MHz (ccf=%u), SCSI ID %u\n",
2338 esp->cfreq / 1000000, esp->cfact, esp->scsi_id); 2419 esp->host->unique_id, esp_chip_names[esp->rev],
2420 esp->cfreq / 1000000, esp->cfact, esp->scsi_id);
2339 2421
2340 /* Let the SCSI bus reset settle. */ 2422 /* Let the SCSI bus reset settle. */
2341 ssleep(esp_bus_reset_settle); 2423 ssleep(esp_bus_reset_settle);
@@ -2402,28 +2484,10 @@ static int esp_slave_configure(struct scsi_device *dev)
2402{ 2484{
2403 struct esp *esp = shost_priv(dev->host); 2485 struct esp *esp = shost_priv(dev->host);
2404 struct esp_target_data *tp = &esp->target[dev->id]; 2486 struct esp_target_data *tp = &esp->target[dev->id];
2405 int goal_tags, queue_depth;
2406
2407 goal_tags = 0;
2408 2487
2409 if (dev->tagged_supported) { 2488 if (dev->tagged_supported)
2410 /* XXX make this configurable somehow XXX */ 2489 scsi_change_queue_depth(dev, esp->num_tags);
2411 goal_tags = ESP_DEFAULT_TAGS;
2412
2413 if (goal_tags > ESP_MAX_TAG)
2414 goal_tags = ESP_MAX_TAG;
2415 }
2416 2490
2417 queue_depth = goal_tags;
2418 if (queue_depth < dev->host->cmd_per_lun)
2419 queue_depth = dev->host->cmd_per_lun;
2420
2421 if (goal_tags) {
2422 scsi_set_tag_type(dev, MSG_ORDERED_TAG);
2423 scsi_activate_tcq(dev, queue_depth);
2424 } else {
2425 scsi_deactivate_tcq(dev, queue_depth);
2426 }
2427 tp->flags |= ESP_TGT_DISCONNECT; 2491 tp->flags |= ESP_TGT_DISCONNECT;
2428 2492
2429 if (!spi_initial_dv(dev->sdev_target)) 2493 if (!spi_initial_dv(dev->sdev_target))
@@ -2451,19 +2515,20 @@ static int esp_eh_abort_handler(struct scsi_cmnd *cmd)
2451 * XXX much for the final driver. 2515 * XXX much for the final driver.
2452 */ 2516 */
2453 spin_lock_irqsave(esp->host->host_lock, flags); 2517 spin_lock_irqsave(esp->host->host_lock, flags);
2454 printk(KERN_ERR PFX "esp%d: Aborting command [%p:%02x]\n", 2518 shost_printk(KERN_ERR, esp->host, "Aborting command [%p:%02x]\n",
2455 esp->host->unique_id, cmd, cmd->cmnd[0]); 2519 cmd, cmd->cmnd[0]);
2456 ent = esp->active_cmd; 2520 ent = esp->active_cmd;
2457 if (ent) 2521 if (ent)
2458 printk(KERN_ERR PFX "esp%d: Current command [%p:%02x]\n", 2522 shost_printk(KERN_ERR, esp->host,
2459 esp->host->unique_id, ent->cmd, ent->cmd->cmnd[0]); 2523 "Current command [%p:%02x]\n",
2524 ent->cmd, ent->cmd->cmnd[0]);
2460 list_for_each_entry(ent, &esp->queued_cmds, list) { 2525 list_for_each_entry(ent, &esp->queued_cmds, list) {
2461 printk(KERN_ERR PFX "esp%d: Queued command [%p:%02x]\n", 2526 shost_printk(KERN_ERR, esp->host, "Queued command [%p:%02x]\n",
2462 esp->host->unique_id, ent->cmd, ent->cmd->cmnd[0]); 2527 ent->cmd, ent->cmd->cmnd[0]);
2463 } 2528 }
2464 list_for_each_entry(ent, &esp->active_cmds, list) { 2529 list_for_each_entry(ent, &esp->active_cmds, list) {
2465 printk(KERN_ERR PFX "esp%d: Active command [%p:%02x]\n", 2530 shost_printk(KERN_ERR, esp->host, " Active command [%p:%02x]\n",
2466 esp->host->unique_id, ent->cmd, ent->cmd->cmnd[0]); 2531 ent->cmd, ent->cmd->cmnd[0]);
2467 } 2532 }
2468 esp_dump_cmd_log(esp); 2533 esp_dump_cmd_log(esp);
2469 spin_unlock_irqrestore(esp->host->host_lock, flags); 2534 spin_unlock_irqrestore(esp->host->host_lock, flags);
@@ -2631,6 +2696,7 @@ struct scsi_host_template scsi_esp_template = {
2631 .use_clustering = ENABLE_CLUSTERING, 2696 .use_clustering = ENABLE_CLUSTERING,
2632 .max_sectors = 0xffff, 2697 .max_sectors = 0xffff,
2633 .skip_settle_delay = 1, 2698 .skip_settle_delay = 1,
2699 .use_blk_tags = 1,
2634}; 2700};
2635EXPORT_SYMBOL(scsi_esp_template); 2701EXPORT_SYMBOL(scsi_esp_template);
2636 2702
diff --git a/drivers/scsi/esp_scsi.h b/drivers/scsi/esp_scsi.h
index cd68805e8d78..84dcbe4a6268 100644
--- a/drivers/scsi/esp_scsi.h
+++ b/drivers/scsi/esp_scsi.h
@@ -1,4 +1,4 @@
1/* esp_scsi.h: Defines and structures for the ESP drier. 1/* esp_scsi.h: Defines and structures for the ESP driver.
2 * 2 *
3 * Copyright (C) 2007 David S. Miller (davem@davemloft.net) 3 * Copyright (C) 2007 David S. Miller (davem@davemloft.net)
4 */ 4 */
@@ -25,6 +25,7 @@
25#define ESP_CTEST 0x0aUL /* wo Chip test register 0x28 */ 25#define ESP_CTEST 0x0aUL /* wo Chip test register 0x28 */
26#define ESP_CFG2 0x0bUL /* rw Second cfg register 0x2c */ 26#define ESP_CFG2 0x0bUL /* rw Second cfg register 0x2c */
27#define ESP_CFG3 0x0cUL /* rw Third cfg register 0x30 */ 27#define ESP_CFG3 0x0cUL /* rw Third cfg register 0x30 */
28#define ESP_CFG4 0x0dUL /* rw Fourth cfg register 0x34 */
28#define ESP_TCHI 0x0eUL /* rw High bits transf count 0x38 */ 29#define ESP_TCHI 0x0eUL /* rw High bits transf count 0x38 */
29#define ESP_UID ESP_TCHI /* ro Unique ID code 0x38 */ 30#define ESP_UID ESP_TCHI /* ro Unique ID code 0x38 */
30#define FAS_RLO ESP_TCHI /* rw HME extended counter 0x38 */ 31#define FAS_RLO ESP_TCHI /* rw HME extended counter 0x38 */
@@ -76,6 +77,18 @@
76#define ESP_CONFIG3_IMS 0x80 /* ID msg chk'ng (esp/fas236) */ 77#define ESP_CONFIG3_IMS 0x80 /* ID msg chk'ng (esp/fas236) */
77#define ESP_CONFIG3_OBPUSH 0x80 /* Push odd-byte to dma (hme) */ 78#define ESP_CONFIG3_OBPUSH 0x80 /* Push odd-byte to dma (hme) */
78 79
80/* ESP config register 4 read-write, found only on am53c974 chips */
81#define ESP_CONFIG4_RADE 0x04 /* Active negation */
82#define ESP_CONFIG4_RAE 0x08 /* Active negation on REQ and ACK */
83#define ESP_CONFIG4_PWD 0x20 /* Reduced power feature */
84#define ESP_CONFIG4_GE0 0x40 /* Glitch eater bit 0 */
85#define ESP_CONFIG4_GE1 0x80 /* Glitch eater bit 1 */
86
87#define ESP_CONFIG_GE_12NS (0)
88#define ESP_CONFIG_GE_25NS (ESP_CONFIG_GE1)
89#define ESP_CONFIG_GE_35NS (ESP_CONFIG_GE0)
90#define ESP_CONFIG_GE_0NS (ESP_CONFIG_GE0 | ESP_CONFIG_GE1)
91
79/* ESP command register read-write */ 92/* ESP command register read-write */
80/* Group 1 commands: These may be sent at any point in time to the ESP 93/* Group 1 commands: These may be sent at any point in time to the ESP
81 * chip. None of them can generate interrupts 'cept 94 * chip. None of them can generate interrupts 'cept
@@ -254,6 +267,7 @@ enum esp_rev {
254 FAS100A = 0x04, 267 FAS100A = 0x04,
255 FAST = 0x05, 268 FAST = 0x05,
256 FASHME = 0x06, 269 FASHME = 0x06,
270 PCSCSI = 0x07, /* AM53c974 */
257}; 271};
258 272
259struct esp_cmd_entry { 273struct esp_cmd_entry {
@@ -269,6 +283,7 @@ struct esp_cmd_entry {
269#define ESP_CMD_FLAG_WRITE 0x01 /* DMA is a write */ 283#define ESP_CMD_FLAG_WRITE 0x01 /* DMA is a write */
270#define ESP_CMD_FLAG_ABORT 0x02 /* being aborted */ 284#define ESP_CMD_FLAG_ABORT 0x02 /* being aborted */
271#define ESP_CMD_FLAG_AUTOSENSE 0x04 /* Doing automatic REQUEST_SENSE */ 285#define ESP_CMD_FLAG_AUTOSENSE 0x04 /* Doing automatic REQUEST_SENSE */
286#define ESP_CMD_FLAG_RESIDUAL 0x08 /* AM53c974 BLAST residual */
272 287
273 u8 tag[2]; 288 u8 tag[2];
274 u8 orig_tag[2]; 289 u8 orig_tag[2];
@@ -283,7 +298,6 @@ struct esp_cmd_entry {
283 struct completion *eh_done; 298 struct completion *eh_done;
284}; 299};
285 300
286/* XXX make this configurable somehow XXX */
287#define ESP_DEFAULT_TAGS 16 301#define ESP_DEFAULT_TAGS 16
288 302
289#define ESP_MAX_TARGET 16 303#define ESP_MAX_TARGET 16
@@ -445,7 +459,7 @@ struct esp {
445 u8 prev_soff; 459 u8 prev_soff;
446 u8 prev_stp; 460 u8 prev_stp;
447 u8 prev_cfg3; 461 u8 prev_cfg3;
448 u8 __pad; 462 u8 num_tags;
449 463
450 struct list_head esp_cmd_pool; 464 struct list_head esp_cmd_pool;
451 465
@@ -466,6 +480,7 @@ struct esp {
466 u8 bursts; 480 u8 bursts;
467 u8 config1; 481 u8 config1;
468 u8 config2; 482 u8 config2;
483 u8 config4;
469 484
470 u8 scsi_id; 485 u8 scsi_id;
471 u32 scsi_id_mask; 486 u32 scsi_id_mask;
@@ -479,6 +494,7 @@ struct esp {
479#define ESP_FLAG_WIDE_CAPABLE 0x00000008 494#define ESP_FLAG_WIDE_CAPABLE 0x00000008
480#define ESP_FLAG_QUICKIRQ_CHECK 0x00000010 495#define ESP_FLAG_QUICKIRQ_CHECK 0x00000010
481#define ESP_FLAG_DISABLE_SYNC 0x00000020 496#define ESP_FLAG_DISABLE_SYNC 0x00000020
497#define ESP_FLAG_USE_FIFO 0x00000040
482 498
483 u8 select_state; 499 u8 select_state;
484#define ESP_SELECT_NONE 0x00 /* Not selecting */ 500#define ESP_SELECT_NONE 0x00 /* Not selecting */
diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 4a8ac7d8c76b..308a016fdaea 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -280,14 +280,16 @@ static struct scsi_host_template fcoe_shost_template = {
280 .eh_device_reset_handler = fc_eh_device_reset, 280 .eh_device_reset_handler = fc_eh_device_reset,
281 .eh_host_reset_handler = fc_eh_host_reset, 281 .eh_host_reset_handler = fc_eh_host_reset,
282 .slave_alloc = fc_slave_alloc, 282 .slave_alloc = fc_slave_alloc,
283 .change_queue_depth = fc_change_queue_depth, 283 .change_queue_depth = scsi_change_queue_depth,
284 .change_queue_type = fc_change_queue_type, 284 .change_queue_type = scsi_change_queue_type,
285 .this_id = -1, 285 .this_id = -1,
286 .cmd_per_lun = 3, 286 .cmd_per_lun = 3,
287 .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS, 287 .can_queue = FCOE_MAX_OUTSTANDING_COMMANDS,
288 .use_clustering = ENABLE_CLUSTERING, 288 .use_clustering = ENABLE_CLUSTERING,
289 .sg_tablesize = SG_ALL, 289 .sg_tablesize = SG_ALL,
290 .max_sectors = 0xffff, 290 .max_sectors = 0xffff,
291 .use_blk_tags = 1,
292 .track_queue_depth = 1,
291}; 293};
292 294
293/** 295/**
diff --git a/drivers/scsi/fnic/fnic.h b/drivers/scsi/fnic/fnic.h
index bf8d34c26f13..3b73b96619e2 100644
--- a/drivers/scsi/fnic/fnic.h
+++ b/drivers/scsi/fnic/fnic.h
@@ -39,7 +39,7 @@
39 39
40#define DRV_NAME "fnic" 40#define DRV_NAME "fnic"
41#define DRV_DESCRIPTION "Cisco FCoE HBA Driver" 41#define DRV_DESCRIPTION "Cisco FCoE HBA Driver"
42#define DRV_VERSION "1.6.0.11" 42#define DRV_VERSION "1.6.0.16"
43#define PFX DRV_NAME ": " 43#define PFX DRV_NAME ": "
44#define DFX DRV_NAME "%d: " 44#define DFX DRV_NAME "%d: "
45 45
diff --git a/drivers/scsi/fnic/fnic_fcs.c b/drivers/scsi/fnic/fnic_fcs.c
index f3984b48f8e9..bf0bbd42efb5 100644
--- a/drivers/scsi/fnic/fnic_fcs.c
+++ b/drivers/scsi/fnic/fnic_fcs.c
@@ -135,6 +135,11 @@ void fnic_handle_link(struct work_struct *work)
135 fnic->lport->host->host_no, FNIC_FC_LE, 135 fnic->lport->host->host_no, FNIC_FC_LE,
136 "Link Status: UP_DOWN", 136 "Link Status: UP_DOWN",
137 strlen("Link Status: UP_DOWN")); 137 strlen("Link Status: UP_DOWN"));
138 if (fnic->config.flags & VFCF_FIP_CAPABLE) {
139 FNIC_FCS_DBG(KERN_DEBUG, fnic->lport->host,
140 "deleting fip-timer during link-down\n");
141 del_timer_sync(&fnic->fip_timer);
142 }
138 fcoe_ctlr_link_down(&fnic->ctlr); 143 fcoe_ctlr_link_down(&fnic->ctlr);
139 } 144 }
140 145
diff --git a/drivers/scsi/fnic/fnic_main.c b/drivers/scsi/fnic/fnic_main.c
index 8c56fdc3a456..0c1f8177b5b7 100644
--- a/drivers/scsi/fnic/fnic_main.c
+++ b/drivers/scsi/fnic/fnic_main.c
@@ -95,12 +95,10 @@ static int fnic_slave_alloc(struct scsi_device *sdev)
95{ 95{
96 struct fc_rport *rport = starget_to_rport(scsi_target(sdev)); 96 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
97 97
98 sdev->tagged_supported = 1;
99
100 if (!rport || fc_remote_port_chkready(rport)) 98 if (!rport || fc_remote_port_chkready(rport))
101 return -ENXIO; 99 return -ENXIO;
102 100
103 scsi_activate_tcq(sdev, fnic_max_qdepth); 101 scsi_change_queue_depth(sdev, fnic_max_qdepth);
104 return 0; 102 return 0;
105} 103}
106 104
@@ -112,8 +110,8 @@ static struct scsi_host_template fnic_host_template = {
112 .eh_device_reset_handler = fnic_device_reset, 110 .eh_device_reset_handler = fnic_device_reset,
113 .eh_host_reset_handler = fnic_host_reset, 111 .eh_host_reset_handler = fnic_host_reset,
114 .slave_alloc = fnic_slave_alloc, 112 .slave_alloc = fnic_slave_alloc,
115 .change_queue_depth = fc_change_queue_depth, 113 .change_queue_depth = scsi_change_queue_depth,
116 .change_queue_type = fc_change_queue_type, 114 .change_queue_type = scsi_change_queue_type,
117 .this_id = -1, 115 .this_id = -1,
118 .cmd_per_lun = 3, 116 .cmd_per_lun = 3,
119 .can_queue = FNIC_DFLT_IO_REQ, 117 .can_queue = FNIC_DFLT_IO_REQ,
@@ -121,6 +119,8 @@ static struct scsi_host_template fnic_host_template = {
121 .sg_tablesize = FNIC_MAX_SG_DESC_CNT, 119 .sg_tablesize = FNIC_MAX_SG_DESC_CNT,
122 .max_sectors = 0xffff, 120 .max_sectors = 0xffff,
123 .shost_attrs = fnic_attrs, 121 .shost_attrs = fnic_attrs,
122 .use_blk_tags = 1,
123 .track_queue_depth = 1,
124}; 124};
125 125
126static void 126static void
@@ -438,21 +438,30 @@ static int fnic_dev_wait(struct vnic_dev *vdev,
438 unsigned long time; 438 unsigned long time;
439 int done; 439 int done;
440 int err; 440 int err;
441 int count;
442
443 count = 0;
441 444
442 err = start(vdev, arg); 445 err = start(vdev, arg);
443 if (err) 446 if (err)
444 return err; 447 return err;
445 448
446 /* Wait for func to complete...2 seconds max */ 449 /* Wait for func to complete.
450 * Sometime schedule_timeout_uninterruptible take long time
451 * to wake up so we do not retry as we are only waiting for
452 * 2 seconds in while loop. By adding count, we make sure
453 * we try atleast three times before returning -ETIMEDOUT
454 */
447 time = jiffies + (HZ * 2); 455 time = jiffies + (HZ * 2);
448 do { 456 do {
449 err = finished(vdev, &done); 457 err = finished(vdev, &done);
458 count++;
450 if (err) 459 if (err)
451 return err; 460 return err;
452 if (done) 461 if (done)
453 return 0; 462 return 0;
454 schedule_timeout_uninterruptible(HZ / 10); 463 schedule_timeout_uninterruptible(HZ / 10);
455 } while (time_after(time, jiffies)); 464 } while (time_after(time, jiffies) || (count < 3));
456 465
457 return -ETIMEDOUT; 466 return -ETIMEDOUT;
458} 467}
diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
index 961bdf5d31cd..2097de42a147 100644
--- a/drivers/scsi/fnic/fnic_scsi.c
+++ b/drivers/scsi/fnic/fnic_scsi.c
@@ -325,13 +325,11 @@ static inline int fnic_queue_wq_copy_desc(struct fnic *fnic,
325 struct fc_rport_libfc_priv *rp = rport->dd_data; 325 struct fc_rport_libfc_priv *rp = rport->dd_data;
326 struct host_sg_desc *desc; 326 struct host_sg_desc *desc;
327 struct misc_stats *misc_stats = &fnic->fnic_stats.misc_stats; 327 struct misc_stats *misc_stats = &fnic->fnic_stats.misc_stats;
328 u8 pri_tag = 0;
329 unsigned int i; 328 unsigned int i;
330 unsigned long intr_flags; 329 unsigned long intr_flags;
331 int flags; 330 int flags;
332 u8 exch_flags; 331 u8 exch_flags;
333 struct scsi_lun fc_lun; 332 struct scsi_lun fc_lun;
334 char msg[2];
335 333
336 if (sg_count) { 334 if (sg_count) {
337 /* For each SGE, create a device desc entry */ 335 /* For each SGE, create a device desc entry */
@@ -357,12 +355,6 @@ static inline int fnic_queue_wq_copy_desc(struct fnic *fnic,
357 355
358 int_to_scsilun(sc->device->lun, &fc_lun); 356 int_to_scsilun(sc->device->lun, &fc_lun);
359 357
360 pri_tag = FCPIO_ICMND_PTA_SIMPLE;
361 msg[0] = MSG_SIMPLE_TAG;
362 scsi_populate_tag_msg(sc, msg);
363 if (msg[0] == MSG_ORDERED_TAG)
364 pri_tag = FCPIO_ICMND_PTA_ORDERED;
365
366 /* Enqueue the descriptor in the Copy WQ */ 358 /* Enqueue the descriptor in the Copy WQ */
367 spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags); 359 spin_lock_irqsave(&fnic->wq_copy_lock[0], intr_flags);
368 360
@@ -394,7 +386,8 @@ static inline int fnic_queue_wq_copy_desc(struct fnic *fnic,
394 io_req->sgl_list_pa, 386 io_req->sgl_list_pa,
395 io_req->sense_buf_pa, 387 io_req->sense_buf_pa,
396 0, /* scsi cmd ref, always 0 */ 388 0, /* scsi cmd ref, always 0 */
397 pri_tag, /* scsi pri and tag */ 389 FCPIO_ICMND_PTA_SIMPLE,
390 /* scsi pri and tag */
398 flags, /* command flags */ 391 flags, /* command flags */
399 sc->cmnd, sc->cmd_len, 392 sc->cmnd, sc->cmd_len,
400 scsi_bufflen(sc), 393 scsi_bufflen(sc),
@@ -428,8 +421,10 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_
428 int ret; 421 int ret;
429 u64 cmd_trace; 422 u64 cmd_trace;
430 int sg_count = 0; 423 int sg_count = 0;
431 unsigned long flags; 424 unsigned long flags = 0;
432 unsigned long ptr; 425 unsigned long ptr;
426 struct fc_rport_priv *rdata;
427 spinlock_t *io_lock = NULL;
433 428
434 if (unlikely(fnic_chk_state_flags_locked(fnic, FNIC_FLAGS_IO_BLOCKED))) 429 if (unlikely(fnic_chk_state_flags_locked(fnic, FNIC_FLAGS_IO_BLOCKED)))
435 return SCSI_MLQUEUE_HOST_BUSY; 430 return SCSI_MLQUEUE_HOST_BUSY;
@@ -443,6 +438,16 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_
443 return 0; 438 return 0;
444 } 439 }
445 440
441 rdata = lp->tt.rport_lookup(lp, rport->port_id);
442 if (!rdata || (rdata->rp_state == RPORT_ST_DELETE)) {
443 FNIC_SCSI_DBG(KERN_DEBUG, fnic->lport->host,
444 "returning IO as rport is removed\n");
445 atomic64_inc(&fnic_stats->misc_stats.rport_not_ready);
446 sc->result = DID_NO_CONNECT;
447 done(sc);
448 return 0;
449 }
450
446 if (lp->state != LPORT_ST_READY || !(lp->link_up)) 451 if (lp->state != LPORT_ST_READY || !(lp->link_up))
447 return SCSI_MLQUEUE_HOST_BUSY; 452 return SCSI_MLQUEUE_HOST_BUSY;
448 453
@@ -505,6 +510,13 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_
505 } 510 }
506 } 511 }
507 512
513 /*
514 * Will acquire lock defore setting to IO initialized.
515 */
516
517 io_lock = fnic_io_lock_hash(fnic, sc);
518 spin_lock_irqsave(io_lock, flags);
519
508 /* initialize rest of io_req */ 520 /* initialize rest of io_req */
509 io_req->port_id = rport->port_id; 521 io_req->port_id = rport->port_id;
510 io_req->start_time = jiffies; 522 io_req->start_time = jiffies;
@@ -521,11 +533,9 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_
521 * In case another thread cancelled the request, 533 * In case another thread cancelled the request,
522 * refetch the pointer under the lock. 534 * refetch the pointer under the lock.
523 */ 535 */
524 spinlock_t *io_lock = fnic_io_lock_hash(fnic, sc);
525 FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no, 536 FNIC_TRACE(fnic_queuecommand, sc->device->host->host_no,
526 sc->request->tag, sc, 0, 0, 0, 537 sc->request->tag, sc, 0, 0, 0,
527 (((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc))); 538 (((u64)CMD_FLAGS(sc) << 32) | CMD_STATE(sc)));
528 spin_lock_irqsave(io_lock, flags);
529 io_req = (struct fnic_io_req *)CMD_SP(sc); 539 io_req = (struct fnic_io_req *)CMD_SP(sc);
530 CMD_SP(sc) = NULL; 540 CMD_SP(sc) = NULL;
531 CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE; 541 CMD_STATE(sc) = FNIC_IOREQ_CMD_COMPLETE;
@@ -534,6 +544,10 @@ static int fnic_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_
534 fnic_release_ioreq_buf(fnic, io_req, sc); 544 fnic_release_ioreq_buf(fnic, io_req, sc);
535 mempool_free(io_req, fnic->io_req_pool); 545 mempool_free(io_req, fnic->io_req_pool);
536 } 546 }
547 atomic_dec(&fnic->in_flight);
548 /* acquire host lock before returning to SCSI */
549 spin_lock(lp->host->host_lock);
550 return ret;
537 } else { 551 } else {
538 atomic64_inc(&fnic_stats->io_stats.active_ios); 552 atomic64_inc(&fnic_stats->io_stats.active_ios);
539 atomic64_inc(&fnic_stats->io_stats.num_ios); 553 atomic64_inc(&fnic_stats->io_stats.num_ios);
@@ -555,6 +569,11 @@ out:
555 sc->request->tag, sc, io_req, 569 sc->request->tag, sc, io_req,
556 sg_count, cmd_trace, 570 sg_count, cmd_trace,
557 (((u64)CMD_FLAGS(sc) >> 32) | CMD_STATE(sc))); 571 (((u64)CMD_FLAGS(sc) >> 32) | CMD_STATE(sc)));
572
573 /* if only we issued IO, will we have the io lock */
574 if (CMD_FLAGS(sc) & FNIC_IO_INITIALIZED)
575 spin_unlock_irqrestore(io_lock, flags);
576
558 atomic_dec(&fnic->in_flight); 577 atomic_dec(&fnic->in_flight);
559 /* acquire host lock before returning to SCSI */ 578 /* acquire host lock before returning to SCSI */
560 spin_lock(lp->host->host_lock); 579 spin_lock(lp->host->host_lock);
diff --git a/drivers/scsi/fnic/fnic_trace.c b/drivers/scsi/fnic/fnic_trace.c
index acf1f95cb5c5..65a9bde26974 100644
--- a/drivers/scsi/fnic/fnic_trace.c
+++ b/drivers/scsi/fnic/fnic_trace.c
@@ -624,12 +624,12 @@ int fnic_fc_trace_set_data(u32 host_no, u8 frame_type,
624 if (frame_type == FNIC_FC_RECV) { 624 if (frame_type == FNIC_FC_RECV) {
625 eth_fcoe_hdr_len = sizeof(struct ethhdr) + 625 eth_fcoe_hdr_len = sizeof(struct ethhdr) +
626 sizeof(struct fcoe_hdr); 626 sizeof(struct fcoe_hdr);
627 fc_trc_frame_len = fc_trc_frame_len + eth_fcoe_hdr_len;
628 memset((char *)fc_trace, 0xff, eth_fcoe_hdr_len); 627 memset((char *)fc_trace, 0xff, eth_fcoe_hdr_len);
629 /* Copy the rest of data frame */ 628 /* Copy the rest of data frame */
630 memcpy((char *)(fc_trace + eth_fcoe_hdr_len), (void *)frame, 629 memcpy((char *)(fc_trace + eth_fcoe_hdr_len), (void *)frame,
631 min_t(u8, fc_trc_frame_len, 630 min_t(u8, fc_trc_frame_len,
632 (u8)(FC_TRC_SIZE_BYTES - FC_TRC_HEADER_SIZE))); 631 (u8)(FC_TRC_SIZE_BYTES - FC_TRC_HEADER_SIZE
632 - eth_fcoe_hdr_len)));
633 } else { 633 } else {
634 memcpy((char *)fc_trace, (void *)frame, 634 memcpy((char *)fc_trace, (void *)frame,
635 min_t(u8, fc_trc_frame_len, 635 min_t(u8, fc_trc_frame_len,
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index b331272e93bc..f35792f7051c 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -18,20 +18,6 @@
18 * 18 *
19 * Added ISAPNP support for DTC436 adapters, 19 * Added ISAPNP support for DTC436 adapters,
20 * Thomas Sailer, sailer@ife.ee.ethz.ch 20 * Thomas Sailer, sailer@ife.ee.ethz.ch
21 *
22 * ALPHA RELEASE 1.
23 *
24 * For more information, please consult
25 *
26 * NCR 5380 Family
27 * SCSI Protocol Controller
28 * Databook
29 *
30 * NCR Microelectronics
31 * 1635 Aeroplaza Drive
32 * Colorado Springs, CO 80916
33 * 1+ (719) 578-3400
34 * 1+ (800) 334-5454
35 */ 21 */
36 22
37/* 23/*
@@ -40,14 +26,6 @@
40 */ 26 */
41 27
42/* 28/*
43 * Options :
44 *
45 * PARITY - enable parity checking. Not supported.
46 *
47 * SCSI2 - enable support for SCSI-II tagged queueing. Untested.
48 *
49 * USLEEP - enable support for devices that don't disconnect. Untested.
50 *
51 * The card is detected and initialized in one of several ways : 29 * The card is detected and initialized in one of several ways :
52 * 1. With command line overrides - NCR5380=port,irq may be 30 * 1. With command line overrides - NCR5380=port,irq may be
53 * used on the LILO command line to override the defaults. 31 * used on the LILO command line to override the defaults.
@@ -79,27 +57,21 @@
79 */ 57 */
80 58
81/* settings for DTC3181E card with only Mustek scanner attached */ 59/* settings for DTC3181E card with only Mustek scanner attached */
82#define USLEEP
83#define USLEEP_POLL 1 60#define USLEEP_POLL 1
84#define USLEEP_SLEEP 20 61#define USLEEP_SLEEP 20
85#define USLEEP_WAITLONG 500 62#define USLEEP_WAITLONG 500
86 63
87#define AUTOPROBE_IRQ 64#define AUTOPROBE_IRQ
88#define AUTOSENSE
89
90 65
91#ifdef CONFIG_SCSI_GENERIC_NCR53C400 66#ifdef CONFIG_SCSI_GENERIC_NCR53C400
92#define NCR53C400_PSEUDO_DMA 1 67#define NCR53C400_PSEUDO_DMA 1
93#define PSEUDO_DMA 68#define PSEUDO_DMA
94#define NCR53C400 69#define NCR53C400
95#define NCR5380_STATS
96#undef NCR5380_STAT_LIMIT
97#endif 70#endif
98 71
99#include <asm/io.h> 72#include <asm/io.h>
100#include <linux/signal.h> 73#include <linux/signal.h>
101#include <linux/blkdev.h> 74#include <linux/blkdev.h>
102#include "scsi.h"
103#include <scsi/scsi_host.h> 75#include <scsi/scsi_host.h>
104#include "g_NCR5380.h" 76#include "g_NCR5380.h"
105#include "NCR5380.h" 77#include "NCR5380.h"
@@ -277,7 +249,7 @@ static int __init do_DTC3181E_setup(char *str)
277 * Locks: none 249 * Locks: none
278 */ 250 */
279 251
280int __init generic_NCR5380_detect(struct scsi_host_template * tpnt) 252static int __init generic_NCR5380_detect(struct scsi_host_template *tpnt)
281{ 253{
282 static int current_override = 0; 254 static int current_override = 0;
283 int count; 255 int count;
@@ -335,7 +307,7 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
335 if (pnp_irq_valid(dev, 0)) 307 if (pnp_irq_valid(dev, 0))
336 overrides[count].irq = pnp_irq(dev, 0); 308 overrides[count].irq = pnp_irq(dev, 0);
337 else 309 else
338 overrides[count].irq = SCSI_IRQ_NONE; 310 overrides[count].irq = NO_IRQ;
339 if (pnp_dma_valid(dev, 0)) 311 if (pnp_dma_valid(dev, 0))
340 overrides[count].dma = pnp_dma(dev, 0); 312 overrides[count].dma = pnp_dma(dev, 0);
341 else 313 else
@@ -455,27 +427,22 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
455 else 427 else
456 instance->irq = NCR5380_probe_irq(instance, 0xffff); 428 instance->irq = NCR5380_probe_irq(instance, 0xffff);
457 429
458 if (instance->irq != SCSI_IRQ_NONE) 430 /* Compatibility with documented NCR5380 kernel parameters */
431 if (instance->irq == 255)
432 instance->irq = NO_IRQ;
433
434 if (instance->irq != NO_IRQ)
459 if (request_irq(instance->irq, generic_NCR5380_intr, 435 if (request_irq(instance->irq, generic_NCR5380_intr,
460 0, "NCR5380", instance)) { 436 0, "NCR5380", instance)) {
461 printk(KERN_WARNING "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq); 437 printk(KERN_WARNING "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
462 instance->irq = SCSI_IRQ_NONE; 438 instance->irq = NO_IRQ;
463 } 439 }
464 440
465 if (instance->irq == SCSI_IRQ_NONE) { 441 if (instance->irq == NO_IRQ) {
466 printk(KERN_INFO "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no); 442 printk(KERN_INFO "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
467 printk(KERN_INFO "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no); 443 printk(KERN_INFO "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
468 } 444 }
469 445
470 printk(KERN_INFO "scsi%d : at " STRVAL(NCR5380_map_name) " 0x%x", instance->host_no, (unsigned int) instance->NCR5380_instance_name);
471 if (instance->irq == SCSI_IRQ_NONE)
472 printk(" interrupts disabled");
473 else
474 printk(" irq %d", instance->irq);
475 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", CAN_QUEUE, CMD_PER_LUN, GENERIC_NCR5380_PUBLIC_RELEASE);
476 NCR5380_print_options(instance);
477 printk("\n");
478
479 ++current_override; 446 ++current_override;
480 ++count; 447 ++count;
481 } 448 }
@@ -483,19 +450,6 @@ int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
483} 450}
484 451
485/** 452/**
486 * generic_NCR5380_info - reporting string
487 * @host: NCR5380 to report on
488 *
489 * Report driver information for the NCR5380
490 */
491
492const char *generic_NCR5380_info(struct Scsi_Host *host)
493{
494 static const char string[] = "Generic NCR5380/53C400 Driver";
495 return string;
496}
497
498/**
499 * generic_NCR5380_release_resources - free resources 453 * generic_NCR5380_release_resources - free resources
500 * @instance: host adapter to clean up 454 * @instance: host adapter to clean up
501 * 455 *
@@ -504,12 +458,12 @@ const char *generic_NCR5380_info(struct Scsi_Host *host)
504 * Locks: none 458 * Locks: none
505 */ 459 */
506 460
507int generic_NCR5380_release_resources(struct Scsi_Host *instance) 461static int generic_NCR5380_release_resources(struct Scsi_Host *instance)
508{ 462{
509 NCR5380_local_declare(); 463 NCR5380_local_declare();
510 NCR5380_setup(instance); 464 NCR5380_setup(instance);
511 465
512 if (instance->irq != SCSI_IRQ_NONE) 466 if (instance->irq != NO_IRQ)
513 free_irq(instance->irq, instance); 467 free_irq(instance->irq, instance);
514 NCR5380_exit(instance); 468 NCR5380_exit(instance);
515 469
@@ -741,163 +695,9 @@ static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src,
741 695
742#include "NCR5380.c" 696#include "NCR5380.c"
743 697
744#define PRINTP(x) seq_printf(m, x)
745#define ANDP ,
746
747static void sprint_opcode(struct seq_file *m, int opcode)
748{
749 PRINTP("0x%02x " ANDP opcode);
750}
751
752static void sprint_command(struct seq_file *m, unsigned char *command)
753{
754 int i, s;
755 sprint_opcode(m, command[0]);
756 for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i)
757 PRINTP("%02x " ANDP command[i]);
758 PRINTP("\n");
759}
760
761/**
762 * sprintf_Scsi_Cmnd - print a scsi command
763 * @m: seq_fil to print into
764 * @cmd: SCSI command block
765 *
766 * Print out the target and command data in hex
767 */
768
769static void sprint_Scsi_Cmnd(struct seq_file *m, Scsi_Cmnd * cmd)
770{
771 PRINTP("host number %d destination target %d, lun %llu\n" ANDP cmd->device->host->host_no ANDP cmd->device->id ANDP cmd->device->lun);
772 PRINTP(" command = ");
773 sprint_command(m, cmd->cmnd);
774}
775
776/**
777 * generic_NCR5380_proc_info - /proc for NCR5380 driver
778 * @buffer: buffer to print into
779 * @start: start position
780 * @offset: offset into buffer
781 * @len: length
782 * @hostno: instance to affect
783 * @inout: read/write
784 *
785 * Provide the procfs information for the 5380 controller. We fill
786 * this with useful debugging information including the commands
787 * being executed, disconnected command queue and the statistical
788 * data
789 *
790 * Locks: global cli/lock for queue walk
791 */
792
793static int generic_NCR5380_show_info(struct seq_file *m, struct Scsi_Host *scsi_ptr)
794{
795 NCR5380_local_declare();
796 unsigned long flags;
797 unsigned char status;
798 int i;
799 Scsi_Cmnd *ptr;
800 struct NCR5380_hostdata *hostdata;
801#ifdef NCR5380_STATS
802 struct scsi_device *dev;
803#endif
804
805 NCR5380_setup(scsi_ptr);
806 hostdata = (struct NCR5380_hostdata *) scsi_ptr->hostdata;
807
808 spin_lock_irqsave(scsi_ptr->host_lock, flags);
809 PRINTP("SCSI host number %d : %s\n" ANDP scsi_ptr->host_no ANDP scsi_ptr->hostt->name);
810 PRINTP("Generic NCR5380 driver version %d\n" ANDP GENERIC_NCR5380_PUBLIC_RELEASE);
811 PRINTP("NCR5380 core version %d\n" ANDP NCR5380_PUBLIC_RELEASE);
812#ifdef NCR53C400
813 PRINTP("NCR53C400 extension version %d\n" ANDP NCR53C400_PUBLIC_RELEASE);
814 PRINTP("NCR53C400 card%s detected\n" ANDP(((struct NCR5380_hostdata *) scsi_ptr->hostdata)->flags & FLAG_NCR53C400) ? "" : " not");
815# if NCR53C400_PSEUDO_DMA
816 PRINTP("NCR53C400 pseudo DMA used\n");
817# endif
818#else
819 PRINTP("NO NCR53C400 driver extensions\n");
820#endif
821 PRINTP("Using %s mapping at %s 0x%lx, " ANDP STRVAL(NCR5380_map_config) ANDP STRVAL(NCR5380_map_name) ANDP scsi_ptr->NCR5380_instance_name);
822 if (scsi_ptr->irq == SCSI_IRQ_NONE)
823 PRINTP("no interrupt\n");
824 else
825 PRINTP("on interrupt %d\n" ANDP scsi_ptr->irq);
826
827#ifdef NCR5380_STATS
828 if (hostdata->connected || hostdata->issue_queue || hostdata->disconnected_queue)
829 PRINTP("There are commands pending, transfer rates may be crud\n");
830 if (hostdata->pendingr)
831 PRINTP(" %d pending reads" ANDP hostdata->pendingr);
832 if (hostdata->pendingw)
833 PRINTP(" %d pending writes" ANDP hostdata->pendingw);
834 if (hostdata->pendingr || hostdata->pendingw)
835 PRINTP("\n");
836 shost_for_each_device(dev, scsi_ptr) {
837 unsigned long br = hostdata->bytes_read[dev->id];
838 unsigned long bw = hostdata->bytes_write[dev->id];
839 long tr = hostdata->time_read[dev->id] / HZ;
840 long tw = hostdata->time_write[dev->id] / HZ;
841
842 PRINTP(" T:%d %s " ANDP dev->id ANDP scsi_device_type(dev->type));
843 for (i = 0; i < 8; i++)
844 if (dev->vendor[i] >= 0x20)
845 seq_putc(m, dev->vendor[i]);
846 seq_putc(m, ' ');
847 for (i = 0; i < 16; i++)
848 if (dev->model[i] >= 0x20)
849 seq_putc(m, dev->model[i]);
850 seq_putc(m, ' ');
851 for (i = 0; i < 4; i++)
852 if (dev->rev[i] >= 0x20)
853 seq_putc(m, dev->rev[i]);
854 seq_putc(m, ' ');
855
856 PRINTP("\n%10ld kb read in %5ld secs" ANDP br / 1024 ANDP tr);
857 if (tr)
858 PRINTP(" @ %5ld bps" ANDP br / tr);
859
860 PRINTP("\n%10ld kb written in %5ld secs" ANDP bw / 1024 ANDP tw);
861 if (tw)
862 PRINTP(" @ %5ld bps" ANDP bw / tw);
863 PRINTP("\n");
864 }
865#endif
866
867 status = NCR5380_read(STATUS_REG);
868 if (!(status & SR_REQ))
869 PRINTP("REQ not asserted, phase unknown.\n");
870 else {
871 for (i = 0; (phases[i].value != PHASE_UNKNOWN) && (phases[i].value != (status & PHASE_MASK)); ++i);
872 PRINTP("Phase %s\n" ANDP phases[i].name);
873 }
874
875 if (!hostdata->connected) {
876 PRINTP("No currently connected command\n");
877 } else {
878 sprint_Scsi_Cmnd(m, (Scsi_Cmnd *) hostdata->connected);
879 }
880
881 PRINTP("issue_queue\n");
882
883 for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
884 sprint_Scsi_Cmnd(m, ptr);
885
886 PRINTP("disconnected_queue\n");
887
888 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
889 sprint_Scsi_Cmnd(m, ptr);
890
891 spin_unlock_irqrestore(scsi_ptr->host_lock, flags);
892 return 0;
893}
894
895#undef PRINTP
896#undef ANDP
897
898static struct scsi_host_template driver_template = { 698static struct scsi_host_template driver_template = {
899 .show_info = generic_NCR5380_show_info, 699 .show_info = generic_NCR5380_show_info,
900 .name = "Generic NCR5380/NCR53C400 Scsi Driver", 700 .name = "Generic NCR5380/NCR53C400 SCSI",
901 .detect = generic_NCR5380_detect, 701 .detect = generic_NCR5380_detect,
902 .release = generic_NCR5380_release_resources, 702 .release = generic_NCR5380_release_resources,
903 .info = generic_NCR5380_info, 703 .info = generic_NCR5380_info,
diff --git a/drivers/scsi/g_NCR5380.h b/drivers/scsi/g_NCR5380.h
index 703adf78e0b2..bea1a3b9b862 100644
--- a/drivers/scsi/g_NCR5380.h
+++ b/drivers/scsi/g_NCR5380.h
@@ -9,28 +9,11 @@
9 * 9 *
10 * NCR53C400 extensions (c) 1994,1995,1996, Kevin Lentin 10 * NCR53C400 extensions (c) 1994,1995,1996, Kevin Lentin
11 * K.Lentin@cs.monash.edu.au 11 * K.Lentin@cs.monash.edu.au
12 *
13 * ALPHA RELEASE 1.
14 *
15 * For more information, please consult
16 *
17 * NCR 5380 Family
18 * SCSI Protocol Controller
19 * Databook
20 *
21 * NCR Microelectronics
22 * 1635 Aeroplaza Drive
23 * Colorado Springs, CO 80916
24 * 1+ (719) 578-3400
25 * 1+ (800) 334-5454
26 */ 12 */
27 13
28#ifndef GENERIC_NCR5380_H 14#ifndef GENERIC_NCR5380_H
29#define GENERIC_NCR5380_H 15#define GENERIC_NCR5380_H
30 16
31
32#define GENERIC_NCR5380_PUBLIC_RELEASE 1
33
34#ifdef NCR53C400 17#ifdef NCR53C400
35#define BIOSPARAM 18#define BIOSPARAM
36#define NCR5380_BIOSPARAM generic_NCR5380_biosparam 19#define NCR5380_BIOSPARAM generic_NCR5380_biosparam
@@ -39,12 +22,6 @@
39#endif 22#endif
40 23
41#ifndef ASM 24#ifndef ASM
42static int generic_NCR5380_abort(Scsi_Cmnd *);
43static int generic_NCR5380_detect(struct scsi_host_template *);
44static int generic_NCR5380_release_resources(struct Scsi_Host *);
45static int generic_NCR5380_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
46static int generic_NCR5380_bus_reset(Scsi_Cmnd *);
47static const char* generic_NCR5380_info(struct Scsi_Host *);
48 25
49#ifndef CMD_PER_LUN 26#ifndef CMD_PER_LUN
50#define CMD_PER_LUN 2 27#define CMD_PER_LUN 2
@@ -118,7 +95,8 @@ static const char* generic_NCR5380_info(struct Scsi_Host *);
118#define NCR5380_bus_reset generic_NCR5380_bus_reset 95#define NCR5380_bus_reset generic_NCR5380_bus_reset
119#define NCR5380_pread generic_NCR5380_pread 96#define NCR5380_pread generic_NCR5380_pread
120#define NCR5380_pwrite generic_NCR5380_pwrite 97#define NCR5380_pwrite generic_NCR5380_pwrite
121#define NCR5380_proc_info notyet_generic_proc_info 98#define NCR5380_info generic_NCR5380_info
99#define NCR5380_show_info generic_NCR5380_show_info
122 100
123#define BOARD_NCR5380 0 101#define BOARD_NCR5380 0
124#define BOARD_NCR53C400 1 102#define BOARD_NCR53C400 1
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 0f1ae13ce7c7..71e138044379 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -2159,7 +2159,7 @@ static void gdth_next(gdth_ha_str *ha)
2159 case VERIFY: 2159 case VERIFY:
2160 case START_STOP: 2160 case START_STOP:
2161 case MODE_SENSE: 2161 case MODE_SENSE:
2162 case SERVICE_ACTION_IN: 2162 case SERVICE_ACTION_IN_16:
2163 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0], 2163 TRACE(("cache cmd %x/%x/%x/%x/%x/%x\n",nscp->cmnd[0],
2164 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3], 2164 nscp->cmnd[1],nscp->cmnd[2],nscp->cmnd[3],
2165 nscp->cmnd[4],nscp->cmnd[5])); 2165 nscp->cmnd[4],nscp->cmnd[5]));
@@ -2391,7 +2391,7 @@ static int gdth_internal_cache_cmd(gdth_ha_str *ha, Scsi_Cmnd *scp)
2391 gdth_copy_internal_data(ha, scp, (char*)&rdc, sizeof(gdth_rdcap_data)); 2391 gdth_copy_internal_data(ha, scp, (char*)&rdc, sizeof(gdth_rdcap_data));
2392 break; 2392 break;
2393 2393
2394 case SERVICE_ACTION_IN: 2394 case SERVICE_ACTION_IN_16:
2395 if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 && 2395 if ((scp->cmnd[1] & 0x1f) == SAI_READ_CAPACITY_16 &&
2396 (ha->cache_feat & GDT_64BIT)) { 2396 (ha->cache_feat & GDT_64BIT)) {
2397 gdth_rdcap16_data rdc16; 2397 gdth_rdcap16_data rdc16;
@@ -4661,7 +4661,6 @@ static void gdth_flush(gdth_ha_str *ha)
4661/* configure lun */ 4661/* configure lun */
4662static int gdth_slave_configure(struct scsi_device *sdev) 4662static int gdth_slave_configure(struct scsi_device *sdev)
4663{ 4663{
4664 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
4665 sdev->skip_ms_page_3f = 1; 4664 sdev->skip_ms_page_3f = 1;
4666 sdev->skip_ms_page_8 = 1; 4665 sdev->skip_ms_page_8 = 1;
4667 return 0; 4666 return 0;
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 6de80e352871..8bb173e01084 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -418,7 +418,6 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
418 shost->cmd_per_lun = sht->cmd_per_lun; 418 shost->cmd_per_lun = sht->cmd_per_lun;
419 shost->unchecked_isa_dma = sht->unchecked_isa_dma; 419 shost->unchecked_isa_dma = sht->unchecked_isa_dma;
420 shost->use_clustering = sht->use_clustering; 420 shost->use_clustering = sht->use_clustering;
421 shost->ordered_tag = sht->ordered_tag;
422 shost->no_write_same = sht->no_write_same; 421 shost->no_write_same = sht->no_write_same;
423 422
424 if (shost_eh_deadline == -1 || !sht->eh_host_reset_handler) 423 if (shost_eh_deadline == -1 || !sht->eh_host_reset_handler)
@@ -485,8 +484,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
485 WQ_UNBOUND | WQ_MEM_RECLAIM, 484 WQ_UNBOUND | WQ_MEM_RECLAIM,
486 1, shost->host_no); 485 1, shost->host_no);
487 if (!shost->tmf_work_q) { 486 if (!shost->tmf_work_q) {
488 printk(KERN_WARNING "scsi%d: failed to create tmf workq\n", 487 shost_printk(KERN_WARNING, shost,
489 shost->host_no); 488 "failed to create tmf workq\n");
490 goto fail_kthread; 489 goto fail_kthread;
491 } 490 }
492 scsi_proc_hostdir_add(shost->hostt); 491 scsi_proc_hostdir_add(shost->hostt);
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index cef5d49b59cd..6bb4611b238a 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -48,6 +48,7 @@
48#include <linux/bitmap.h> 48#include <linux/bitmap.h>
49#include <linux/atomic.h> 49#include <linux/atomic.h>
50#include <linux/jiffies.h> 50#include <linux/jiffies.h>
51#include <linux/percpu-defs.h>
51#include <linux/percpu.h> 52#include <linux/percpu.h>
52#include <asm/div64.h> 53#include <asm/div64.h>
53#include "hpsa_cmd.h" 54#include "hpsa_cmd.h"
@@ -103,7 +104,6 @@ static const struct pci_device_id hpsa_pci_device_id[] = {
103 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1922}, 104 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1922},
104 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1923}, 105 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1923},
105 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1924}, 106 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1924},
106 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1925},
107 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1926}, 107 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1926},
108 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1928}, 108 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1928},
109 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1929}, 109 {PCI_VENDOR_ID_HP, PCI_DEVICE_ID_HP_CISSH, 0x103C, 0x1929},
@@ -149,6 +149,7 @@ static struct board_type products[] = {
149 {0x3249103C, "Smart Array P812", &SA5_access}, 149 {0x3249103C, "Smart Array P812", &SA5_access},
150 {0x324A103C, "Smart Array P712m", &SA5_access}, 150 {0x324A103C, "Smart Array P712m", &SA5_access},
151 {0x324B103C, "Smart Array P711m", &SA5_access}, 151 {0x324B103C, "Smart Array P711m", &SA5_access},
152 {0x3233103C, "HP StorageWorks 1210m", &SA5_access}, /* alias of 333f */
152 {0x3350103C, "Smart Array P222", &SA5_access}, 153 {0x3350103C, "Smart Array P222", &SA5_access},
153 {0x3351103C, "Smart Array P420", &SA5_access}, 154 {0x3351103C, "Smart Array P420", &SA5_access},
154 {0x3352103C, "Smart Array P421", &SA5_access}, 155 {0x3352103C, "Smart Array P421", &SA5_access},
@@ -193,12 +194,13 @@ static int number_of_controllers;
193 194
194static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id); 195static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id);
195static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id); 196static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id);
196static int hpsa_ioctl(struct scsi_device *dev, int cmd, void *arg); 197static int hpsa_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
197static void lock_and_start_io(struct ctlr_info *h); 198static void lock_and_start_io(struct ctlr_info *h);
198static void start_io(struct ctlr_info *h, unsigned long *flags); 199static void start_io(struct ctlr_info *h, unsigned long *flags);
199 200
200#ifdef CONFIG_COMPAT 201#ifdef CONFIG_COMPAT
201static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void *arg); 202static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd,
203 void __user *arg);
202#endif 204#endif
203 205
204static void cmd_free(struct ctlr_info *h, struct CommandList *c); 206static void cmd_free(struct ctlr_info *h, struct CommandList *c);
@@ -214,8 +216,6 @@ static int hpsa_scsi_queue_command(struct Scsi_Host *h, struct scsi_cmnd *cmd);
214static void hpsa_scan_start(struct Scsi_Host *); 216static void hpsa_scan_start(struct Scsi_Host *);
215static int hpsa_scan_finished(struct Scsi_Host *sh, 217static int hpsa_scan_finished(struct Scsi_Host *sh,
216 unsigned long elapsed_time); 218 unsigned long elapsed_time);
217static int hpsa_change_queue_depth(struct scsi_device *sdev,
218 int qdepth, int reason);
219 219
220static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd); 220static int hpsa_eh_device_reset_handler(struct scsi_cmnd *scsicmd);
221static int hpsa_eh_abort_handler(struct scsi_cmnd *scsicmd); 221static int hpsa_eh_abort_handler(struct scsi_cmnd *scsicmd);
@@ -274,12 +274,12 @@ static int check_for_unit_attention(struct ctlr_info *h,
274 "detected, command retried\n", h->ctlr); 274 "detected, command retried\n", h->ctlr);
275 break; 275 break;
276 case LUN_FAILED: 276 case LUN_FAILED:
277 dev_warn(&h->pdev->dev, HPSA "%d: LUN failure " 277 dev_warn(&h->pdev->dev,
278 "detected, action required\n", h->ctlr); 278 HPSA "%d: LUN failure detected\n", h->ctlr);
279 break; 279 break;
280 case REPORT_LUNS_CHANGED: 280 case REPORT_LUNS_CHANGED:
281 dev_warn(&h->pdev->dev, HPSA "%d: report LUN data " 281 dev_warn(&h->pdev->dev,
282 "changed, action required\n", h->ctlr); 282 HPSA "%d: report LUN data changed\n", h->ctlr);
283 /* 283 /*
284 * Note: this REPORT_LUNS_CHANGED condition only occurs on the external 284 * Note: this REPORT_LUNS_CHANGED condition only occurs on the external
285 * target (array) devices. 285 * target (array) devices.
@@ -392,7 +392,8 @@ static ssize_t host_show_commands_outstanding(struct device *dev,
392 struct Scsi_Host *shost = class_to_shost(dev); 392 struct Scsi_Host *shost = class_to_shost(dev);
393 struct ctlr_info *h = shost_to_hba(shost); 393 struct ctlr_info *h = shost_to_hba(shost);
394 394
395 return snprintf(buf, 20, "%d\n", h->commands_outstanding); 395 return snprintf(buf, 20, "%d\n",
396 atomic_read(&h->commands_outstanding));
396} 397}
397 398
398static ssize_t host_show_transport_mode(struct device *dev, 399static ssize_t host_show_transport_mode(struct device *dev,
@@ -670,7 +671,7 @@ static struct scsi_host_template hpsa_driver_template = {
670 .queuecommand = hpsa_scsi_queue_command, 671 .queuecommand = hpsa_scsi_queue_command,
671 .scan_start = hpsa_scan_start, 672 .scan_start = hpsa_scan_start,
672 .scan_finished = hpsa_scan_finished, 673 .scan_finished = hpsa_scan_finished,
673 .change_queue_depth = hpsa_change_queue_depth, 674 .change_queue_depth = scsi_change_queue_depth,
674 .this_id = -1, 675 .this_id = -1,
675 .use_clustering = ENABLE_CLUSTERING, 676 .use_clustering = ENABLE_CLUSTERING,
676 .eh_abort_handler = hpsa_eh_abort_handler, 677 .eh_abort_handler = hpsa_eh_abort_handler,
@@ -698,7 +699,6 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
698{ 699{
699 u32 a; 700 u32 a;
700 struct reply_queue_buffer *rq = &h->reply_queue[q]; 701 struct reply_queue_buffer *rq = &h->reply_queue[q];
701 unsigned long flags;
702 702
703 if (h->transMethod & CFGTBL_Trans_io_accel1) 703 if (h->transMethod & CFGTBL_Trans_io_accel1)
704 return h->access.command_completed(h, q); 704 return h->access.command_completed(h, q);
@@ -709,9 +709,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
709 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) { 709 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
710 a = rq->head[rq->current_entry]; 710 a = rq->head[rq->current_entry];
711 rq->current_entry++; 711 rq->current_entry++;
712 spin_lock_irqsave(&h->lock, flags); 712 atomic_dec(&h->commands_outstanding);
713 h->commands_outstanding--;
714 spin_unlock_irqrestore(&h->lock, flags);
715 } else { 713 } else {
716 a = FIFO_EMPTY; 714 a = FIFO_EMPTY;
717 } 715 }
@@ -1500,22 +1498,22 @@ static int hpsa_map_sg_chain_block(struct ctlr_info *h,
1500{ 1498{
1501 struct SGDescriptor *chain_sg, *chain_block; 1499 struct SGDescriptor *chain_sg, *chain_block;
1502 u64 temp64; 1500 u64 temp64;
1501 u32 chain_len;
1503 1502
1504 chain_sg = &c->SG[h->max_cmd_sg_entries - 1]; 1503 chain_sg = &c->SG[h->max_cmd_sg_entries - 1];
1505 chain_block = h->cmd_sg_list[c->cmdindex]; 1504 chain_block = h->cmd_sg_list[c->cmdindex];
1506 chain_sg->Ext = HPSA_SG_CHAIN; 1505 chain_sg->Ext = cpu_to_le32(HPSA_SG_CHAIN);
1507 chain_sg->Len = sizeof(*chain_sg) * 1506 chain_len = sizeof(*chain_sg) *
1508 (c->Header.SGTotal - h->max_cmd_sg_entries); 1507 (c->Header.SGTotal - h->max_cmd_sg_entries);
1509 temp64 = pci_map_single(h->pdev, chain_block, chain_sg->Len, 1508 chain_sg->Len = cpu_to_le32(chain_len);
1509 temp64 = pci_map_single(h->pdev, chain_block, chain_len,
1510 PCI_DMA_TODEVICE); 1510 PCI_DMA_TODEVICE);
1511 if (dma_mapping_error(&h->pdev->dev, temp64)) { 1511 if (dma_mapping_error(&h->pdev->dev, temp64)) {
1512 /* prevent subsequent unmapping */ 1512 /* prevent subsequent unmapping */
1513 chain_sg->Addr.lower = 0; 1513 chain_sg->Addr = cpu_to_le64(0);
1514 chain_sg->Addr.upper = 0;
1515 return -1; 1514 return -1;
1516 } 1515 }
1517 chain_sg->Addr.lower = (u32) (temp64 & 0x0FFFFFFFFULL); 1516 chain_sg->Addr = cpu_to_le64(temp64);
1518 chain_sg->Addr.upper = (u32) ((temp64 >> 32) & 0x0FFFFFFFFULL);
1519 return 0; 1517 return 0;
1520} 1518}
1521 1519
@@ -1523,15 +1521,13 @@ static void hpsa_unmap_sg_chain_block(struct ctlr_info *h,
1523 struct CommandList *c) 1521 struct CommandList *c)
1524{ 1522{
1525 struct SGDescriptor *chain_sg; 1523 struct SGDescriptor *chain_sg;
1526 union u64bit temp64;
1527 1524
1528 if (c->Header.SGTotal <= h->max_cmd_sg_entries) 1525 if (le16_to_cpu(c->Header.SGTotal) <= h->max_cmd_sg_entries)
1529 return; 1526 return;
1530 1527
1531 chain_sg = &c->SG[h->max_cmd_sg_entries - 1]; 1528 chain_sg = &c->SG[h->max_cmd_sg_entries - 1];
1532 temp64.val32.lower = chain_sg->Addr.lower; 1529 pci_unmap_single(h->pdev, le64_to_cpu(chain_sg->Addr),
1533 temp64.val32.upper = chain_sg->Addr.upper; 1530 le32_to_cpu(chain_sg->Len), PCI_DMA_TODEVICE);
1534 pci_unmap_single(h->pdev, temp64.val, chain_sg->Len, PCI_DMA_TODEVICE);
1535} 1531}
1536 1532
1537 1533
@@ -1732,8 +1728,7 @@ static void complete_scsi_command(struct CommandList *cp)
1732 struct io_accel1_cmd *c = &h->ioaccel_cmd_pool[cp->cmdindex]; 1728 struct io_accel1_cmd *c = &h->ioaccel_cmd_pool[cp->cmdindex];
1733 cp->Header.SGList = cp->Header.SGTotal = scsi_sg_count(cmd); 1729 cp->Header.SGList = cp->Header.SGTotal = scsi_sg_count(cmd);
1734 cp->Request.CDBLen = c->io_flags & IOACCEL1_IOFLAGS_CDBLEN_MASK; 1730 cp->Request.CDBLen = c->io_flags & IOACCEL1_IOFLAGS_CDBLEN_MASK;
1735 cp->Header.Tag.lower = c->Tag.lower; 1731 cp->Header.tag = c->tag;
1736 cp->Header.Tag.upper = c->Tag.upper;
1737 memcpy(cp->Header.LUN.LunAddrBytes, c->CISS_LUN, 8); 1732 memcpy(cp->Header.LUN.LunAddrBytes, c->CISS_LUN, 8);
1738 memcpy(cp->Request.CDB, c->CDB, cp->Request.CDBLen); 1733 memcpy(cp->Request.CDB, c->CDB, cp->Request.CDBLen);
1739 1734
@@ -1763,72 +1758,13 @@ static void complete_scsi_command(struct CommandList *cp)
1763 /* Get addition sense code qualifier */ 1758 /* Get addition sense code qualifier */
1764 ascq = ei->SenseInfo[13]; 1759 ascq = ei->SenseInfo[13];
1765 } 1760 }
1766
1767 if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) { 1761 if (ei->ScsiStatus == SAM_STAT_CHECK_CONDITION) {
1768 if (check_for_unit_attention(h, cp))
1769 break;
1770 if (sense_key == ILLEGAL_REQUEST) {
1771 /*
1772 * SCSI REPORT_LUNS is commonly unsupported on
1773 * Smart Array. Suppress noisy complaint.
1774 */
1775 if (cp->Request.CDB[0] == REPORT_LUNS)
1776 break;
1777
1778 /* If ASC/ASCQ indicate Logical Unit
1779 * Not Supported condition,
1780 */
1781 if ((asc == 0x25) && (ascq == 0x0)) {
1782 dev_warn(&h->pdev->dev, "cp %p "
1783 "has check condition\n", cp);
1784 break;
1785 }
1786 }
1787
1788 if (sense_key == NOT_READY) {
1789 /* If Sense is Not Ready, Logical Unit
1790 * Not ready, Manual Intervention
1791 * required
1792 */
1793 if ((asc == 0x04) && (ascq == 0x03)) {
1794 dev_warn(&h->pdev->dev, "cp %p "
1795 "has check condition: unit "
1796 "not ready, manual "
1797 "intervention required\n", cp);
1798 break;
1799 }
1800 }
1801 if (sense_key == ABORTED_COMMAND) { 1762 if (sense_key == ABORTED_COMMAND) {
1802 /* Aborted command is retryable */
1803 dev_warn(&h->pdev->dev, "cp %p "
1804 "has check condition: aborted command: "
1805 "ASC: 0x%x, ASCQ: 0x%x\n",
1806 cp, asc, ascq);
1807 cmd->result |= DID_SOFT_ERROR << 16; 1763 cmd->result |= DID_SOFT_ERROR << 16;
1808 break; 1764 break;
1809 } 1765 }
1810 /* Must be some other type of check condition */
1811 dev_dbg(&h->pdev->dev, "cp %p has check condition: "
1812 "unknown type: "
1813 "Sense: 0x%x, ASC: 0x%x, ASCQ: 0x%x, "
1814 "Returning result: 0x%x, "
1815 "cmd=[%02x %02x %02x %02x %02x "
1816 "%02x %02x %02x %02x %02x %02x "
1817 "%02x %02x %02x %02x %02x]\n",
1818 cp, sense_key, asc, ascq,
1819 cmd->result,
1820 cmd->cmnd[0], cmd->cmnd[1],
1821 cmd->cmnd[2], cmd->cmnd[3],
1822 cmd->cmnd[4], cmd->cmnd[5],
1823 cmd->cmnd[6], cmd->cmnd[7],
1824 cmd->cmnd[8], cmd->cmnd[9],
1825 cmd->cmnd[10], cmd->cmnd[11],
1826 cmd->cmnd[12], cmd->cmnd[13],
1827 cmd->cmnd[14], cmd->cmnd[15]);
1828 break; 1766 break;
1829 } 1767 }
1830
1831
1832 /* Problem was not a check condition 1768 /* Problem was not a check condition
1833 * Pass it up to the upper layers... 1769 * Pass it up to the upper layers...
1834 */ 1770 */
@@ -1934,14 +1870,11 @@ static void hpsa_pci_unmap(struct pci_dev *pdev,
1934 struct CommandList *c, int sg_used, int data_direction) 1870 struct CommandList *c, int sg_used, int data_direction)
1935{ 1871{
1936 int i; 1872 int i;
1937 union u64bit addr64;
1938 1873
1939 for (i = 0; i < sg_used; i++) { 1874 for (i = 0; i < sg_used; i++)
1940 addr64.val32.lower = c->SG[i].Addr.lower; 1875 pci_unmap_single(pdev, (dma_addr_t) le64_to_cpu(c->SG[i].Addr),
1941 addr64.val32.upper = c->SG[i].Addr.upper; 1876 le32_to_cpu(c->SG[i].Len),
1942 pci_unmap_single(pdev, (dma_addr_t) addr64.val, c->SG[i].Len, 1877 data_direction);
1943 data_direction);
1944 }
1945} 1878}
1946 1879
1947static int hpsa_map_one(struct pci_dev *pdev, 1880static int hpsa_map_one(struct pci_dev *pdev,
@@ -1954,25 +1887,22 @@ static int hpsa_map_one(struct pci_dev *pdev,
1954 1887
1955 if (buflen == 0 || data_direction == PCI_DMA_NONE) { 1888 if (buflen == 0 || data_direction == PCI_DMA_NONE) {
1956 cp->Header.SGList = 0; 1889 cp->Header.SGList = 0;
1957 cp->Header.SGTotal = 0; 1890 cp->Header.SGTotal = cpu_to_le16(0);
1958 return 0; 1891 return 0;
1959 } 1892 }
1960 1893
1961 addr64 = (u64) pci_map_single(pdev, buf, buflen, data_direction); 1894 addr64 = pci_map_single(pdev, buf, buflen, data_direction);
1962 if (dma_mapping_error(&pdev->dev, addr64)) { 1895 if (dma_mapping_error(&pdev->dev, addr64)) {
1963 /* Prevent subsequent unmap of something never mapped */ 1896 /* Prevent subsequent unmap of something never mapped */
1964 cp->Header.SGList = 0; 1897 cp->Header.SGList = 0;
1965 cp->Header.SGTotal = 0; 1898 cp->Header.SGTotal = cpu_to_le16(0);
1966 return -1; 1899 return -1;
1967 } 1900 }
1968 cp->SG[0].Addr.lower = 1901 cp->SG[0].Addr = cpu_to_le64(addr64);
1969 (u32) (addr64 & (u64) 0x00000000FFFFFFFF); 1902 cp->SG[0].Len = cpu_to_le32(buflen);
1970 cp->SG[0].Addr.upper = 1903 cp->SG[0].Ext = cpu_to_le32(HPSA_SG_LAST); /* we are not chaining */
1971 (u32) ((addr64 >> 32) & (u64) 0x00000000FFFFFFFF); 1904 cp->Header.SGList = 1; /* no. SGs contig in this cmd */
1972 cp->SG[0].Len = buflen; 1905 cp->Header.SGTotal = cpu_to_le16(1); /* total sgs in cmd list */
1973 cp->SG[0].Ext = HPSA_SG_LAST; /* we are not chaining */
1974 cp->Header.SGList = (u8) 1; /* no. SGs contig in this cmd */
1975 cp->Header.SGTotal = (u16) 1; /* total sgs in this cmd list */
1976 return 0; 1906 return 0;
1977} 1907}
1978 1908
@@ -2830,8 +2760,8 @@ static int hpsa_get_pdisk_of_ioaccel2(struct ctlr_info *h,
2830 if (d == NULL) 2760 if (d == NULL)
2831 return 0; /* no match */ 2761 return 0; /* no match */
2832 2762
2833 it_nexus = cpu_to_le32((u32) d->ioaccel_handle); 2763 it_nexus = cpu_to_le32(d->ioaccel_handle);
2834 scsi_nexus = cpu_to_le32((u32) c2a->scsi_nexus); 2764 scsi_nexus = cpu_to_le32(c2a->scsi_nexus);
2835 find = c2a->scsi_nexus; 2765 find = c2a->scsi_nexus;
2836 2766
2837 if (h->raid_offload_debug > 0) 2767 if (h->raid_offload_debug > 0)
@@ -2891,7 +2821,7 @@ static int hpsa_get_pdisk_of_ioaccel2(struct ctlr_info *h,
2891 * Returns 0 on success, -1 otherwise. 2821 * Returns 0 on success, -1 otherwise.
2892 */ 2822 */
2893static int hpsa_gather_lun_info(struct ctlr_info *h, 2823static int hpsa_gather_lun_info(struct ctlr_info *h,
2894 int reportlunsize, 2824 int reportphyslunsize, int reportloglunsize,
2895 struct ReportLUNdata *physdev, u32 *nphysicals, int *physical_mode, 2825 struct ReportLUNdata *physdev, u32 *nphysicals, int *physical_mode,
2896 struct ReportLUNdata *logdev, u32 *nlogicals) 2826 struct ReportLUNdata *logdev, u32 *nlogicals)
2897{ 2827{
@@ -2905,7 +2835,7 @@ static int hpsa_gather_lun_info(struct ctlr_info *h,
2905 *physical_mode = HPSA_REPORT_PHYS_EXTENDED; 2835 *physical_mode = HPSA_REPORT_PHYS_EXTENDED;
2906 physical_entry_size = 24; 2836 physical_entry_size = 24;
2907 } 2837 }
2908 if (hpsa_scsi_do_report_phys_luns(h, physdev, reportlunsize, 2838 if (hpsa_scsi_do_report_phys_luns(h, physdev, reportphyslunsize,
2909 *physical_mode)) { 2839 *physical_mode)) {
2910 dev_err(&h->pdev->dev, "report physical LUNs failed.\n"); 2840 dev_err(&h->pdev->dev, "report physical LUNs failed.\n");
2911 return -1; 2841 return -1;
@@ -2918,7 +2848,7 @@ static int hpsa_gather_lun_info(struct ctlr_info *h,
2918 *nphysicals - HPSA_MAX_PHYS_LUN); 2848 *nphysicals - HPSA_MAX_PHYS_LUN);
2919 *nphysicals = HPSA_MAX_PHYS_LUN; 2849 *nphysicals = HPSA_MAX_PHYS_LUN;
2920 } 2850 }
2921 if (hpsa_scsi_do_report_log_luns(h, logdev, reportlunsize)) { 2851 if (hpsa_scsi_do_report_log_luns(h, logdev, reportloglunsize)) {
2922 dev_err(&h->pdev->dev, "report logical LUNs failed.\n"); 2852 dev_err(&h->pdev->dev, "report logical LUNs failed.\n");
2923 return -1; 2853 return -1;
2924 } 2854 }
@@ -2941,8 +2871,8 @@ static int hpsa_gather_lun_info(struct ctlr_info *h,
2941 return 0; 2871 return 0;
2942} 2872}
2943 2873
2944u8 *figure_lunaddrbytes(struct ctlr_info *h, int raid_ctlr_position, int i, 2874static u8 *figure_lunaddrbytes(struct ctlr_info *h, int raid_ctlr_position,
2945 int nphysicals, int nlogicals, 2875 int i, int nphysicals, int nlogicals,
2946 struct ReportExtendedLUNdata *physdev_list, 2876 struct ReportExtendedLUNdata *physdev_list,
2947 struct ReportLUNdata *logdev_list) 2877 struct ReportLUNdata *logdev_list)
2948{ 2878{
@@ -3011,15 +2941,14 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
3011 u32 ndev_allocated = 0; 2941 u32 ndev_allocated = 0;
3012 struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice; 2942 struct hpsa_scsi_dev_t **currentsd, *this_device, *tmpdevice;
3013 int ncurrent = 0; 2943 int ncurrent = 0;
3014 int reportlunsize = sizeof(*physdev_list) + HPSA_MAX_PHYS_LUN * 24;
3015 int i, n_ext_target_devs, ndevs_to_allocate; 2944 int i, n_ext_target_devs, ndevs_to_allocate;
3016 int raid_ctlr_position; 2945 int raid_ctlr_position;
3017 int rescan_hba_mode; 2946 int rescan_hba_mode;
3018 DECLARE_BITMAP(lunzerobits, MAX_EXT_TARGETS); 2947 DECLARE_BITMAP(lunzerobits, MAX_EXT_TARGETS);
3019 2948
3020 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL); 2949 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL);
3021 physdev_list = kzalloc(reportlunsize, GFP_KERNEL); 2950 physdev_list = kzalloc(sizeof(*physdev_list), GFP_KERNEL);
3022 logdev_list = kzalloc(reportlunsize, GFP_KERNEL); 2951 logdev_list = kzalloc(sizeof(*logdev_list), GFP_KERNEL);
3023 tmpdevice = kzalloc(sizeof(*tmpdevice), GFP_KERNEL); 2952 tmpdevice = kzalloc(sizeof(*tmpdevice), GFP_KERNEL);
3024 2953
3025 if (!currentsd || !physdev_list || !logdev_list || !tmpdevice) { 2954 if (!currentsd || !physdev_list || !logdev_list || !tmpdevice) {
@@ -3039,7 +2968,8 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
3039 2968
3040 h->hba_mode_enabled = rescan_hba_mode; 2969 h->hba_mode_enabled = rescan_hba_mode;
3041 2970
3042 if (hpsa_gather_lun_info(h, reportlunsize, 2971 if (hpsa_gather_lun_info(h,
2972 sizeof(*physdev_list), sizeof(*logdev_list),
3043 (struct ReportLUNdata *) physdev_list, &nphysicals, 2973 (struct ReportLUNdata *) physdev_list, &nphysicals,
3044 &physical_mode, logdev_list, &nlogicals)) 2974 &physical_mode, logdev_list, &nlogicals))
3045 goto out; 2975 goto out;
@@ -3210,19 +3140,19 @@ static int hpsa_scatter_gather(struct ctlr_info *h,
3210 } 3140 }
3211 addr64 = (u64) sg_dma_address(sg); 3141 addr64 = (u64) sg_dma_address(sg);
3212 len = sg_dma_len(sg); 3142 len = sg_dma_len(sg);
3213 curr_sg->Addr.lower = (u32) (addr64 & 0x0FFFFFFFFULL); 3143 curr_sg->Addr = cpu_to_le64(addr64);
3214 curr_sg->Addr.upper = (u32) ((addr64 >> 32) & 0x0FFFFFFFFULL); 3144 curr_sg->Len = cpu_to_le32(len);
3215 curr_sg->Len = len; 3145 curr_sg->Ext = cpu_to_le32(0);
3216 curr_sg->Ext = (i < scsi_sg_count(cmd) - 1) ? 0 : HPSA_SG_LAST;
3217 curr_sg++; 3146 curr_sg++;
3218 } 3147 }
3148 (--curr_sg)->Ext = cpu_to_le32(HPSA_SG_LAST);
3219 3149
3220 if (use_sg + chained > h->maxSG) 3150 if (use_sg + chained > h->maxSG)
3221 h->maxSG = use_sg + chained; 3151 h->maxSG = use_sg + chained;
3222 3152
3223 if (chained) { 3153 if (chained) {
3224 cp->Header.SGList = h->max_cmd_sg_entries; 3154 cp->Header.SGList = h->max_cmd_sg_entries;
3225 cp->Header.SGTotal = (u16) (use_sg + 1); 3155 cp->Header.SGTotal = cpu_to_le16(use_sg + 1);
3226 if (hpsa_map_sg_chain_block(h, cp)) { 3156 if (hpsa_map_sg_chain_block(h, cp)) {
3227 scsi_dma_unmap(cmd); 3157 scsi_dma_unmap(cmd);
3228 return -1; 3158 return -1;
@@ -3233,7 +3163,7 @@ static int hpsa_scatter_gather(struct ctlr_info *h,
3233sglist_finished: 3163sglist_finished:
3234 3164
3235 cp->Header.SGList = (u8) use_sg; /* no. SGs contig in this cmd */ 3165 cp->Header.SGList = (u8) use_sg; /* no. SGs contig in this cmd */
3236 cp->Header.SGTotal = (u16) use_sg; /* total sgs in this cmd list */ 3166 cp->Header.SGTotal = cpu_to_le16(use_sg); /* total sgs in this cmd list */
3237 return 0; 3167 return 0;
3238} 3168}
3239 3169
@@ -3325,17 +3255,12 @@ static int hpsa_scsi_ioaccel1_queue_command(struct ctlr_info *h,
3325 addr64 = (u64) sg_dma_address(sg); 3255 addr64 = (u64) sg_dma_address(sg);
3326 len = sg_dma_len(sg); 3256 len = sg_dma_len(sg);
3327 total_len += len; 3257 total_len += len;
3328 curr_sg->Addr.lower = (u32) (addr64 & 0x0FFFFFFFFULL); 3258 curr_sg->Addr = cpu_to_le64(addr64);
3329 curr_sg->Addr.upper = 3259 curr_sg->Len = cpu_to_le32(len);
3330 (u32) ((addr64 >> 32) & 0x0FFFFFFFFULL); 3260 curr_sg->Ext = cpu_to_le32(0);
3331 curr_sg->Len = len;
3332
3333 if (i == (scsi_sg_count(cmd) - 1))
3334 curr_sg->Ext = HPSA_SG_LAST;
3335 else
3336 curr_sg->Ext = 0; /* we are not chaining */
3337 curr_sg++; 3261 curr_sg++;
3338 } 3262 }
3263 (--curr_sg)->Ext = cpu_to_le32(HPSA_SG_LAST);
3339 3264
3340 switch (cmd->sc_data_direction) { 3265 switch (cmd->sc_data_direction) {
3341 case DMA_TO_DEVICE: 3266 case DMA_TO_DEVICE:
@@ -3592,7 +3517,7 @@ static int hpsa_scsi_ioaccel2_queue_command(struct ctlr_info *h,
3592 cp->data_len = cpu_to_le32(total_len); 3517 cp->data_len = cpu_to_le32(total_len);
3593 cp->err_ptr = cpu_to_le64(c->busaddr + 3518 cp->err_ptr = cpu_to_le64(c->busaddr +
3594 offsetof(struct io_accel2_cmd, error_data)); 3519 offsetof(struct io_accel2_cmd, error_data));
3595 cp->err_len = cpu_to_le32((u32) sizeof(cp->error_data)); 3520 cp->err_len = cpu_to_le32(sizeof(cp->error_data));
3596 3521
3597 enqueue_cmd_and_start_io(h, c); 3522 enqueue_cmd_and_start_io(h, c);
3598 return 0; 3523 return 0;
@@ -3809,11 +3734,6 @@ static int hpsa_scsi_ioaccel_raid_map(struct ctlr_info *h,
3809 offload_to_mirror = 3734 offload_to_mirror =
3810 (offload_to_mirror >= map->layout_map_count - 1) 3735 (offload_to_mirror >= map->layout_map_count - 1)
3811 ? 0 : offload_to_mirror + 1; 3736 ? 0 : offload_to_mirror + 1;
3812 /* FIXME: remove after debug/dev */
3813 BUG_ON(offload_to_mirror >= map->layout_map_count);
3814 dev_warn(&h->pdev->dev,
3815 "DEBUG: Using physical disk map index %d from mirror group %d\n",
3816 map_index, offload_to_mirror);
3817 dev->offload_to_mirror = offload_to_mirror; 3737 dev->offload_to_mirror = offload_to_mirror;
3818 /* Avoid direct use of dev->offload_to_mirror within this 3738 /* Avoid direct use of dev->offload_to_mirror within this
3819 * function since multiple threads might simultaneously 3739 * function since multiple threads might simultaneously
@@ -3959,8 +3879,11 @@ static int hpsa_scsi_ioaccel_raid_map(struct ctlr_info *h,
3959 dev->scsi3addr); 3879 dev->scsi3addr);
3960} 3880}
3961 3881
3962static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd, 3882/*
3963 void (*done)(struct scsi_cmnd *)) 3883 * Running in struct Scsi_Host->host_lock less mode using LLD internal
3884 * struct ctlr_info *h->lock w/ spin_lock_irqsave() protection.
3885 */
3886static int hpsa_scsi_queue_command(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
3964{ 3887{
3965 struct ctlr_info *h; 3888 struct ctlr_info *h;
3966 struct hpsa_scsi_dev_t *dev; 3889 struct hpsa_scsi_dev_t *dev;
@@ -3973,14 +3896,14 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
3973 dev = cmd->device->hostdata; 3896 dev = cmd->device->hostdata;
3974 if (!dev) { 3897 if (!dev) {
3975 cmd->result = DID_NO_CONNECT << 16; 3898 cmd->result = DID_NO_CONNECT << 16;
3976 done(cmd); 3899 cmd->scsi_done(cmd);
3977 return 0; 3900 return 0;
3978 } 3901 }
3979 memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr)); 3902 memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr));
3980 3903
3981 if (unlikely(lockup_detected(h))) { 3904 if (unlikely(lockup_detected(h))) {
3982 cmd->result = DID_ERROR << 16; 3905 cmd->result = DID_ERROR << 16;
3983 done(cmd); 3906 cmd->scsi_done(cmd);
3984 return 0; 3907 return 0;
3985 } 3908 }
3986 c = cmd_alloc(h); 3909 c = cmd_alloc(h);
@@ -3990,9 +3913,6 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
3990 } 3913 }
3991 3914
3992 /* Fill in the command list header */ 3915 /* Fill in the command list header */
3993
3994 cmd->scsi_done = done; /* save this for use by completion code */
3995
3996 /* save c in case we have to abort it */ 3916 /* save c in case we have to abort it */
3997 cmd->host_scribble = (unsigned char *) c; 3917 cmd->host_scribble = (unsigned char *) c;
3998 3918
@@ -4026,8 +3946,8 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
4026 3946
4027 c->Header.ReplyQueue = 0; /* unused in simple mode */ 3947 c->Header.ReplyQueue = 0; /* unused in simple mode */
4028 memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8); 3948 memcpy(&c->Header.LUN.LunAddrBytes[0], &scsi3addr[0], 8);
4029 c->Header.Tag.lower = (c->cmdindex << DIRECT_LOOKUP_SHIFT); 3949 c->Header.tag = cpu_to_le64((c->cmdindex << DIRECT_LOOKUP_SHIFT) |
4030 c->Header.Tag.lower |= DIRECT_LOOKUP_BIT; 3950 DIRECT_LOOKUP_BIT);
4031 3951
4032 /* Fill in the request block... */ 3952 /* Fill in the request block... */
4033 3953
@@ -4036,17 +3956,18 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
4036 BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB)); 3956 BUG_ON(cmd->cmd_len > sizeof(c->Request.CDB));
4037 c->Request.CDBLen = cmd->cmd_len; 3957 c->Request.CDBLen = cmd->cmd_len;
4038 memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len); 3958 memcpy(c->Request.CDB, cmd->cmnd, cmd->cmd_len);
4039 c->Request.Type.Type = TYPE_CMD;
4040 c->Request.Type.Attribute = ATTR_SIMPLE;
4041 switch (cmd->sc_data_direction) { 3959 switch (cmd->sc_data_direction) {
4042 case DMA_TO_DEVICE: 3960 case DMA_TO_DEVICE:
4043 c->Request.Type.Direction = XFER_WRITE; 3961 c->Request.type_attr_dir =
3962 TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_WRITE);
4044 break; 3963 break;
4045 case DMA_FROM_DEVICE: 3964 case DMA_FROM_DEVICE:
4046 c->Request.Type.Direction = XFER_READ; 3965 c->Request.type_attr_dir =
3966 TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_READ);
4047 break; 3967 break;
4048 case DMA_NONE: 3968 case DMA_NONE:
4049 c->Request.Type.Direction = XFER_NONE; 3969 c->Request.type_attr_dir =
3970 TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_NONE);
4050 break; 3971 break;
4051 case DMA_BIDIRECTIONAL: 3972 case DMA_BIDIRECTIONAL:
4052 /* This can happen if a buggy application does a scsi passthru 3973 /* This can happen if a buggy application does a scsi passthru
@@ -4054,7 +3975,8 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
4054 * ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() ) 3975 * ../scsi/scsi_ioctl.c:scsi_ioctl_send_command() )
4055 */ 3976 */
4056 3977
4057 c->Request.Type.Direction = XFER_RSVD; 3978 c->Request.type_attr_dir =
3979 TYPE_ATTR_DIR(TYPE_CMD, ATTR_SIMPLE, XFER_RSVD);
4058 /* This is technically wrong, and hpsa controllers should 3980 /* This is technically wrong, and hpsa controllers should
4059 * reject it with CMD_INVALID, which is the most correct 3981 * reject it with CMD_INVALID, which is the most correct
4060 * response, but non-fibre backends appear to let it 3982 * response, but non-fibre backends appear to let it
@@ -4081,8 +4003,6 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
4081 return 0; 4003 return 0;
4082} 4004}
4083 4005
4084static DEF_SCSI_QCMD(hpsa_scsi_queue_command)
4085
4086static int do_not_scan_if_controller_locked_up(struct ctlr_info *h) 4006static int do_not_scan_if_controller_locked_up(struct ctlr_info *h)
4087{ 4007{
4088 unsigned long flags; 4008 unsigned long flags;
@@ -4152,23 +4072,6 @@ static int hpsa_scan_finished(struct Scsi_Host *sh,
4152 return finished; 4072 return finished;
4153} 4073}
4154 4074
4155static int hpsa_change_queue_depth(struct scsi_device *sdev,
4156 int qdepth, int reason)
4157{
4158 struct ctlr_info *h = sdev_to_hba(sdev);
4159
4160 if (reason != SCSI_QDEPTH_DEFAULT)
4161 return -ENOTSUPP;
4162
4163 if (qdepth < 1)
4164 qdepth = 1;
4165 else
4166 if (qdepth > h->nr_cmds)
4167 qdepth = h->nr_cmds;
4168 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
4169 return sdev->queue_depth;
4170}
4171
4172static void hpsa_unregister_scsi(struct ctlr_info *h) 4075static void hpsa_unregister_scsi(struct ctlr_info *h)
4173{ 4076{
4174 /* we are being forcibly unloaded, and may not refuse. */ 4077 /* we are being forcibly unloaded, and may not refuse. */
@@ -4329,8 +4232,8 @@ static void hpsa_get_tag(struct ctlr_info *h,
4329 if (c->cmd_type == CMD_IOACCEL1) { 4232 if (c->cmd_type == CMD_IOACCEL1) {
4330 struct io_accel1_cmd *cm1 = (struct io_accel1_cmd *) 4233 struct io_accel1_cmd *cm1 = (struct io_accel1_cmd *)
4331 &h->ioaccel_cmd_pool[c->cmdindex]; 4234 &h->ioaccel_cmd_pool[c->cmdindex];
4332 *tagupper = cm1->Tag.upper; 4235 *tagupper = (u32) (cm1->tag >> 32);
4333 *taglower = cm1->Tag.lower; 4236 *taglower = (u32) (cm1->tag & 0x0ffffffffULL);
4334 return; 4237 return;
4335 } 4238 }
4336 if (c->cmd_type == CMD_IOACCEL2) { 4239 if (c->cmd_type == CMD_IOACCEL2) {
@@ -4341,11 +4244,10 @@ static void hpsa_get_tag(struct ctlr_info *h,
4341 *taglower = cm2->Tag; 4244 *taglower = cm2->Tag;
4342 return; 4245 return;
4343 } 4246 }
4344 *tagupper = c->Header.Tag.upper; 4247 *tagupper = (u32) (c->Header.tag >> 32);
4345 *taglower = c->Header.Tag.lower; 4248 *taglower = (u32) (c->Header.tag & 0x0ffffffffULL);
4346} 4249}
4347 4250
4348
4349static int hpsa_send_abort(struct ctlr_info *h, unsigned char *scsi3addr, 4251static int hpsa_send_abort(struct ctlr_info *h, unsigned char *scsi3addr,
4350 struct CommandList *abort, int swizzle) 4252 struct CommandList *abort, int swizzle)
4351{ 4253{
@@ -4410,7 +4312,7 @@ static struct CommandList *hpsa_find_cmd_in_queue(struct ctlr_info *h,
4410 struct CommandList *c = NULL; /* ptr into cmpQ */ 4312 struct CommandList *c = NULL; /* ptr into cmpQ */
4411 4313
4412 if (!find) 4314 if (!find)
4413 return 0; 4315 return NULL;
4414 spin_lock_irqsave(&h->lock, flags); 4316 spin_lock_irqsave(&h->lock, flags);
4415 list_for_each_entry(c, queue_head, list) { 4317 list_for_each_entry(c, queue_head, list) {
4416 if (c->scsi_cmd == NULL) /* e.g.: passthru ioctl */ 4318 if (c->scsi_cmd == NULL) /* e.g.: passthru ioctl */
@@ -4432,7 +4334,7 @@ static struct CommandList *hpsa_find_cmd_in_queue_by_tag(struct ctlr_info *h,
4432 4334
4433 spin_lock_irqsave(&h->lock, flags); 4335 spin_lock_irqsave(&h->lock, flags);
4434 list_for_each_entry(c, queue_head, list) { 4336 list_for_each_entry(c, queue_head, list) {
4435 if (memcmp(&c->Header.Tag, tag, 8) != 0) 4337 if (memcmp(&c->Header.tag, tag, 8) != 0)
4436 continue; 4338 continue;
4437 spin_unlock_irqrestore(&h->lock, flags); 4339 spin_unlock_irqrestore(&h->lock, flags);
4438 return c; 4340 return c;
@@ -4686,19 +4588,32 @@ static struct CommandList *cmd_alloc(struct ctlr_info *h)
4686 int i; 4588 int i;
4687 union u64bit temp64; 4589 union u64bit temp64;
4688 dma_addr_t cmd_dma_handle, err_dma_handle; 4590 dma_addr_t cmd_dma_handle, err_dma_handle;
4689 unsigned long flags; 4591 int loopcount;
4592
4593 /* There is some *extremely* small but non-zero chance that that
4594 * multiple threads could get in here, and one thread could
4595 * be scanning through the list of bits looking for a free
4596 * one, but the free ones are always behind him, and other
4597 * threads sneak in behind him and eat them before he can
4598 * get to them, so that while there is always a free one, a
4599 * very unlucky thread might be starved anyway, never able to
4600 * beat the other threads. In reality, this happens so
4601 * infrequently as to be indistinguishable from never.
4602 */
4690 4603
4691 spin_lock_irqsave(&h->lock, flags); 4604 loopcount = 0;
4692 do { 4605 do {
4693 i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds); 4606 i = find_first_zero_bit(h->cmd_pool_bits, h->nr_cmds);
4694 if (i == h->nr_cmds) { 4607 if (i == h->nr_cmds)
4695 spin_unlock_irqrestore(&h->lock, flags); 4608 i = 0;
4696 return NULL; 4609 loopcount++;
4697 } 4610 } while (test_and_set_bit(i & (BITS_PER_LONG - 1),
4698 } while (test_and_set_bit 4611 h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0 &&
4699 (i & (BITS_PER_LONG - 1), 4612 loopcount < 10);
4700 h->cmd_pool_bits + (i / BITS_PER_LONG)) != 0); 4613
4701 spin_unlock_irqrestore(&h->lock, flags); 4614 /* Thread got starved? We do not expect this to ever happen. */
4615 if (loopcount >= 10)
4616 return NULL;
4702 4617
4703 c = h->cmd_pool + i; 4618 c = h->cmd_pool + i;
4704 memset(c, 0, sizeof(*c)); 4619 memset(c, 0, sizeof(*c));
@@ -4714,9 +4629,8 @@ static struct CommandList *cmd_alloc(struct ctlr_info *h)
4714 INIT_LIST_HEAD(&c->list); 4629 INIT_LIST_HEAD(&c->list);
4715 c->busaddr = (u32) cmd_dma_handle; 4630 c->busaddr = (u32) cmd_dma_handle;
4716 temp64.val = (u64) err_dma_handle; 4631 temp64.val = (u64) err_dma_handle;
4717 c->ErrDesc.Addr.lower = temp64.val32.lower; 4632 c->ErrDesc.Addr = cpu_to_le64(err_dma_handle);
4718 c->ErrDesc.Addr.upper = temp64.val32.upper; 4633 c->ErrDesc.Len = cpu_to_le32(sizeof(*c->err_info));
4719 c->ErrDesc.Len = sizeof(*c->err_info);
4720 4634
4721 c->h = h; 4635 c->h = h;
4722 return c; 4636 return c;
@@ -4729,7 +4643,6 @@ static struct CommandList *cmd_alloc(struct ctlr_info *h)
4729static struct CommandList *cmd_special_alloc(struct ctlr_info *h) 4643static struct CommandList *cmd_special_alloc(struct ctlr_info *h)
4730{ 4644{
4731 struct CommandList *c; 4645 struct CommandList *c;
4732 union u64bit temp64;
4733 dma_addr_t cmd_dma_handle, err_dma_handle; 4646 dma_addr_t cmd_dma_handle, err_dma_handle;
4734 4647
4735 c = pci_zalloc_consistent(h->pdev, sizeof(*c), &cmd_dma_handle); 4648 c = pci_zalloc_consistent(h->pdev, sizeof(*c), &cmd_dma_handle);
@@ -4750,10 +4663,8 @@ static struct CommandList *cmd_special_alloc(struct ctlr_info *h)
4750 4663
4751 INIT_LIST_HEAD(&c->list); 4664 INIT_LIST_HEAD(&c->list);
4752 c->busaddr = (u32) cmd_dma_handle; 4665 c->busaddr = (u32) cmd_dma_handle;
4753 temp64.val = (u64) err_dma_handle; 4666 c->ErrDesc.Addr = cpu_to_le64(err_dma_handle);
4754 c->ErrDesc.Addr.lower = temp64.val32.lower; 4667 c->ErrDesc.Len = cpu_to_le32(sizeof(*c->err_info));
4755 c->ErrDesc.Addr.upper = temp64.val32.upper;
4756 c->ErrDesc.Len = sizeof(*c->err_info);
4757 4668
4758 c->h = h; 4669 c->h = h;
4759 return c; 4670 return c;
@@ -4762,30 +4673,25 @@ static struct CommandList *cmd_special_alloc(struct ctlr_info *h)
4762static void cmd_free(struct ctlr_info *h, struct CommandList *c) 4673static void cmd_free(struct ctlr_info *h, struct CommandList *c)
4763{ 4674{
4764 int i; 4675 int i;
4765 unsigned long flags;
4766 4676
4767 i = c - h->cmd_pool; 4677 i = c - h->cmd_pool;
4768 spin_lock_irqsave(&h->lock, flags);
4769 clear_bit(i & (BITS_PER_LONG - 1), 4678 clear_bit(i & (BITS_PER_LONG - 1),
4770 h->cmd_pool_bits + (i / BITS_PER_LONG)); 4679 h->cmd_pool_bits + (i / BITS_PER_LONG));
4771 spin_unlock_irqrestore(&h->lock, flags);
4772} 4680}
4773 4681
4774static void cmd_special_free(struct ctlr_info *h, struct CommandList *c) 4682static void cmd_special_free(struct ctlr_info *h, struct CommandList *c)
4775{ 4683{
4776 union u64bit temp64;
4777
4778 temp64.val32.lower = c->ErrDesc.Addr.lower;
4779 temp64.val32.upper = c->ErrDesc.Addr.upper;
4780 pci_free_consistent(h->pdev, sizeof(*c->err_info), 4684 pci_free_consistent(h->pdev, sizeof(*c->err_info),
4781 c->err_info, (dma_addr_t) temp64.val); 4685 c->err_info,
4686 (dma_addr_t) le64_to_cpu(c->ErrDesc.Addr));
4782 pci_free_consistent(h->pdev, sizeof(*c), 4687 pci_free_consistent(h->pdev, sizeof(*c),
4783 c, (dma_addr_t) (c->busaddr & DIRECT_LOOKUP_MASK)); 4688 c, (dma_addr_t) (c->busaddr & DIRECT_LOOKUP_MASK));
4784} 4689}
4785 4690
4786#ifdef CONFIG_COMPAT 4691#ifdef CONFIG_COMPAT
4787 4692
4788static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, void *arg) 4693static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd,
4694 void __user *arg)
4789{ 4695{
4790 IOCTL32_Command_struct __user *arg32 = 4696 IOCTL32_Command_struct __user *arg32 =
4791 (IOCTL32_Command_struct __user *) arg; 4697 (IOCTL32_Command_struct __user *) arg;
@@ -4810,7 +4716,7 @@ static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, void *arg)
4810 if (err) 4716 if (err)
4811 return -EFAULT; 4717 return -EFAULT;
4812 4718
4813 err = hpsa_ioctl(dev, CCISS_PASSTHRU, (void *)p); 4719 err = hpsa_ioctl(dev, CCISS_PASSTHRU, p);
4814 if (err) 4720 if (err)
4815 return err; 4721 return err;
4816 err |= copy_in_user(&arg32->error_info, &p->error_info, 4722 err |= copy_in_user(&arg32->error_info, &p->error_info,
@@ -4821,7 +4727,7 @@ static int hpsa_ioctl32_passthru(struct scsi_device *dev, int cmd, void *arg)
4821} 4727}
4822 4728
4823static int hpsa_ioctl32_big_passthru(struct scsi_device *dev, 4729static int hpsa_ioctl32_big_passthru(struct scsi_device *dev,
4824 int cmd, void *arg) 4730 int cmd, void __user *arg)
4825{ 4731{
4826 BIG_IOCTL32_Command_struct __user *arg32 = 4732 BIG_IOCTL32_Command_struct __user *arg32 =
4827 (BIG_IOCTL32_Command_struct __user *) arg; 4733 (BIG_IOCTL32_Command_struct __user *) arg;
@@ -4848,7 +4754,7 @@ static int hpsa_ioctl32_big_passthru(struct scsi_device *dev,
4848 if (err) 4754 if (err)
4849 return -EFAULT; 4755 return -EFAULT;
4850 4756
4851 err = hpsa_ioctl(dev, CCISS_BIG_PASSTHRU, (void *)p); 4757 err = hpsa_ioctl(dev, CCISS_BIG_PASSTHRU, p);
4852 if (err) 4758 if (err)
4853 return err; 4759 return err;
4854 err |= copy_in_user(&arg32->error_info, &p->error_info, 4760 err |= copy_in_user(&arg32->error_info, &p->error_info,
@@ -4858,7 +4764,7 @@ static int hpsa_ioctl32_big_passthru(struct scsi_device *dev,
4858 return err; 4764 return err;
4859} 4765}
4860 4766
4861static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void *arg) 4767static int hpsa_compat_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
4862{ 4768{
4863 switch (cmd) { 4769 switch (cmd) {
4864 case CCISS_GETPCIINFO: 4770 case CCISS_GETPCIINFO:
@@ -4932,7 +4838,7 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
4932 IOCTL_Command_struct iocommand; 4838 IOCTL_Command_struct iocommand;
4933 struct CommandList *c; 4839 struct CommandList *c;
4934 char *buff = NULL; 4840 char *buff = NULL;
4935 union u64bit temp64; 4841 u64 temp64;
4936 int rc = 0; 4842 int rc = 0;
4937 4843
4938 if (!argp) 4844 if (!argp)
@@ -4971,14 +4877,14 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
4971 c->Header.ReplyQueue = 0; /* unused in simple mode */ 4877 c->Header.ReplyQueue = 0; /* unused in simple mode */
4972 if (iocommand.buf_size > 0) { /* buffer to fill */ 4878 if (iocommand.buf_size > 0) { /* buffer to fill */
4973 c->Header.SGList = 1; 4879 c->Header.SGList = 1;
4974 c->Header.SGTotal = 1; 4880 c->Header.SGTotal = cpu_to_le16(1);
4975 } else { /* no buffers to fill */ 4881 } else { /* no buffers to fill */
4976 c->Header.SGList = 0; 4882 c->Header.SGList = 0;
4977 c->Header.SGTotal = 0; 4883 c->Header.SGTotal = cpu_to_le16(0);
4978 } 4884 }
4979 memcpy(&c->Header.LUN, &iocommand.LUN_info, sizeof(c->Header.LUN)); 4885 memcpy(&c->Header.LUN, &iocommand.LUN_info, sizeof(c->Header.LUN));
4980 /* use the kernel address the cmd block for tag */ 4886 /* use the kernel address the cmd block for tag */
4981 c->Header.Tag.lower = c->busaddr; 4887 c->Header.tag = c->busaddr;
4982 4888
4983 /* Fill in Request block */ 4889 /* Fill in Request block */
4984 memcpy(&c->Request, &iocommand.Request, 4890 memcpy(&c->Request, &iocommand.Request,
@@ -4986,19 +4892,17 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
4986 4892
4987 /* Fill in the scatter gather information */ 4893 /* Fill in the scatter gather information */
4988 if (iocommand.buf_size > 0) { 4894 if (iocommand.buf_size > 0) {
4989 temp64.val = pci_map_single(h->pdev, buff, 4895 temp64 = pci_map_single(h->pdev, buff,
4990 iocommand.buf_size, PCI_DMA_BIDIRECTIONAL); 4896 iocommand.buf_size, PCI_DMA_BIDIRECTIONAL);
4991 if (dma_mapping_error(&h->pdev->dev, temp64.val)) { 4897 if (dma_mapping_error(&h->pdev->dev, (dma_addr_t) temp64)) {
4992 c->SG[0].Addr.lower = 0; 4898 c->SG[0].Addr = cpu_to_le64(0);
4993 c->SG[0].Addr.upper = 0; 4899 c->SG[0].Len = cpu_to_le32(0);
4994 c->SG[0].Len = 0;
4995 rc = -ENOMEM; 4900 rc = -ENOMEM;
4996 goto out; 4901 goto out;
4997 } 4902 }
4998 c->SG[0].Addr.lower = temp64.val32.lower; 4903 c->SG[0].Addr = cpu_to_le64(temp64);
4999 c->SG[0].Addr.upper = temp64.val32.upper; 4904 c->SG[0].Len = cpu_to_le32(iocommand.buf_size);
5000 c->SG[0].Len = iocommand.buf_size; 4905 c->SG[0].Ext = cpu_to_le32(HPSA_SG_LAST); /* not chaining */
5001 c->SG[0].Ext = HPSA_SG_LAST; /* we are not chaining*/
5002 } 4906 }
5003 hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c); 4907 hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c);
5004 if (iocommand.buf_size > 0) 4908 if (iocommand.buf_size > 0)
@@ -5033,7 +4937,7 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
5033 struct CommandList *c; 4937 struct CommandList *c;
5034 unsigned char **buff = NULL; 4938 unsigned char **buff = NULL;
5035 int *buff_size = NULL; 4939 int *buff_size = NULL;
5036 union u64bit temp64; 4940 u64 temp64;
5037 BYTE sg_used = 0; 4941 BYTE sg_used = 0;
5038 int status = 0; 4942 int status = 0;
5039 int i; 4943 int i;
@@ -5107,29 +5011,30 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
5107 } 5011 }
5108 c->cmd_type = CMD_IOCTL_PEND; 5012 c->cmd_type = CMD_IOCTL_PEND;
5109 c->Header.ReplyQueue = 0; 5013 c->Header.ReplyQueue = 0;
5110 c->Header.SGList = c->Header.SGTotal = sg_used; 5014 c->Header.SGList = (u8) sg_used;
5015 c->Header.SGTotal = cpu_to_le16(sg_used);
5111 memcpy(&c->Header.LUN, &ioc->LUN_info, sizeof(c->Header.LUN)); 5016 memcpy(&c->Header.LUN, &ioc->LUN_info, sizeof(c->Header.LUN));
5112 c->Header.Tag.lower = c->busaddr; 5017 c->Header.tag = c->busaddr;
5113 memcpy(&c->Request, &ioc->Request, sizeof(c->Request)); 5018 memcpy(&c->Request, &ioc->Request, sizeof(c->Request));
5114 if (ioc->buf_size > 0) { 5019 if (ioc->buf_size > 0) {
5115 int i; 5020 int i;
5116 for (i = 0; i < sg_used; i++) { 5021 for (i = 0; i < sg_used; i++) {
5117 temp64.val = pci_map_single(h->pdev, buff[i], 5022 temp64 = pci_map_single(h->pdev, buff[i],
5118 buff_size[i], PCI_DMA_BIDIRECTIONAL); 5023 buff_size[i], PCI_DMA_BIDIRECTIONAL);
5119 if (dma_mapping_error(&h->pdev->dev, temp64.val)) { 5024 if (dma_mapping_error(&h->pdev->dev,
5120 c->SG[i].Addr.lower = 0; 5025 (dma_addr_t) temp64)) {
5121 c->SG[i].Addr.upper = 0; 5026 c->SG[i].Addr = cpu_to_le64(0);
5122 c->SG[i].Len = 0; 5027 c->SG[i].Len = cpu_to_le32(0);
5123 hpsa_pci_unmap(h->pdev, c, i, 5028 hpsa_pci_unmap(h->pdev, c, i,
5124 PCI_DMA_BIDIRECTIONAL); 5029 PCI_DMA_BIDIRECTIONAL);
5125 status = -ENOMEM; 5030 status = -ENOMEM;
5126 goto cleanup0; 5031 goto cleanup0;
5127 } 5032 }
5128 c->SG[i].Addr.lower = temp64.val32.lower; 5033 c->SG[i].Addr = cpu_to_le64(temp64);
5129 c->SG[i].Addr.upper = temp64.val32.upper; 5034 c->SG[i].Len = cpu_to_le32(buff_size[i]);
5130 c->SG[i].Len = buff_size[i]; 5035 c->SG[i].Ext = cpu_to_le32(0);
5131 c->SG[i].Ext = i < sg_used - 1 ? 0 : HPSA_SG_LAST;
5132 } 5036 }
5037 c->SG[--i].Ext = cpu_to_le32(HPSA_SG_LAST);
5133 } 5038 }
5134 hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c); 5039 hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c);
5135 if (sg_used) 5040 if (sg_used)
@@ -5206,7 +5111,7 @@ static void decrement_passthru_count(struct ctlr_info *h)
5206/* 5111/*
5207 * ioctl 5112 * ioctl
5208 */ 5113 */
5209static int hpsa_ioctl(struct scsi_device *dev, int cmd, void *arg) 5114static int hpsa_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
5210{ 5115{
5211 struct ctlr_info *h; 5116 struct ctlr_info *h;
5212 void __user *argp = (void __user *)arg; 5117 void __user *argp = (void __user *)arg;
@@ -5268,20 +5173,20 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
5268{ 5173{
5269 int pci_dir = XFER_NONE; 5174 int pci_dir = XFER_NONE;
5270 struct CommandList *a; /* for commands to be aborted */ 5175 struct CommandList *a; /* for commands to be aborted */
5176 u32 tupper, tlower;
5271 5177
5272 c->cmd_type = CMD_IOCTL_PEND; 5178 c->cmd_type = CMD_IOCTL_PEND;
5273 c->Header.ReplyQueue = 0; 5179 c->Header.ReplyQueue = 0;
5274 if (buff != NULL && size > 0) { 5180 if (buff != NULL && size > 0) {
5275 c->Header.SGList = 1; 5181 c->Header.SGList = 1;
5276 c->Header.SGTotal = 1; 5182 c->Header.SGTotal = cpu_to_le16(1);
5277 } else { 5183 } else {
5278 c->Header.SGList = 0; 5184 c->Header.SGList = 0;
5279 c->Header.SGTotal = 0; 5185 c->Header.SGTotal = cpu_to_le16(0);
5280 } 5186 }
5281 c->Header.Tag.lower = c->busaddr; 5187 c->Header.tag = c->busaddr;
5282 memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8); 5188 memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8);
5283 5189
5284 c->Request.Type.Type = cmd_type;
5285 if (cmd_type == TYPE_CMD) { 5190 if (cmd_type == TYPE_CMD) {
5286 switch (cmd) { 5191 switch (cmd) {
5287 case HPSA_INQUIRY: 5192 case HPSA_INQUIRY:
@@ -5291,8 +5196,8 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
5291 c->Request.CDB[2] = (page_code & 0xff); 5196 c->Request.CDB[2] = (page_code & 0xff);
5292 } 5197 }
5293 c->Request.CDBLen = 6; 5198 c->Request.CDBLen = 6;
5294 c->Request.Type.Attribute = ATTR_SIMPLE; 5199 c->Request.type_attr_dir =
5295 c->Request.Type.Direction = XFER_READ; 5200 TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ);
5296 c->Request.Timeout = 0; 5201 c->Request.Timeout = 0;
5297 c->Request.CDB[0] = HPSA_INQUIRY; 5202 c->Request.CDB[0] = HPSA_INQUIRY;
5298 c->Request.CDB[4] = size & 0xFF; 5203 c->Request.CDB[4] = size & 0xFF;
@@ -5303,8 +5208,8 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
5303 mode = 00 target = 0. Nothing to write. 5208 mode = 00 target = 0. Nothing to write.
5304 */ 5209 */
5305 c->Request.CDBLen = 12; 5210 c->Request.CDBLen = 12;
5306 c->Request.Type.Attribute = ATTR_SIMPLE; 5211 c->Request.type_attr_dir =
5307 c->Request.Type.Direction = XFER_READ; 5212 TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ);
5308 c->Request.Timeout = 0; 5213 c->Request.Timeout = 0;
5309 c->Request.CDB[0] = cmd; 5214 c->Request.CDB[0] = cmd;
5310 c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */ 5215 c->Request.CDB[6] = (size >> 24) & 0xFF; /* MSB */
@@ -5314,8 +5219,9 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
5314 break; 5219 break;
5315 case HPSA_CACHE_FLUSH: 5220 case HPSA_CACHE_FLUSH:
5316 c->Request.CDBLen = 12; 5221 c->Request.CDBLen = 12;
5317 c->Request.Type.Attribute = ATTR_SIMPLE; 5222 c->Request.type_attr_dir =
5318 c->Request.Type.Direction = XFER_WRITE; 5223 TYPE_ATTR_DIR(cmd_type,
5224 ATTR_SIMPLE, XFER_WRITE);
5319 c->Request.Timeout = 0; 5225 c->Request.Timeout = 0;
5320 c->Request.CDB[0] = BMIC_WRITE; 5226 c->Request.CDB[0] = BMIC_WRITE;
5321 c->Request.CDB[6] = BMIC_CACHE_FLUSH; 5227 c->Request.CDB[6] = BMIC_CACHE_FLUSH;
@@ -5324,14 +5230,14 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
5324 break; 5230 break;
5325 case TEST_UNIT_READY: 5231 case TEST_UNIT_READY:
5326 c->Request.CDBLen = 6; 5232 c->Request.CDBLen = 6;
5327 c->Request.Type.Attribute = ATTR_SIMPLE; 5233 c->Request.type_attr_dir =
5328 c->Request.Type.Direction = XFER_NONE; 5234 TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE);
5329 c->Request.Timeout = 0; 5235 c->Request.Timeout = 0;
5330 break; 5236 break;
5331 case HPSA_GET_RAID_MAP: 5237 case HPSA_GET_RAID_MAP:
5332 c->Request.CDBLen = 12; 5238 c->Request.CDBLen = 12;
5333 c->Request.Type.Attribute = ATTR_SIMPLE; 5239 c->Request.type_attr_dir =
5334 c->Request.Type.Direction = XFER_READ; 5240 TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ);
5335 c->Request.Timeout = 0; 5241 c->Request.Timeout = 0;
5336 c->Request.CDB[0] = HPSA_CISS_READ; 5242 c->Request.CDB[0] = HPSA_CISS_READ;
5337 c->Request.CDB[1] = cmd; 5243 c->Request.CDB[1] = cmd;
@@ -5342,8 +5248,8 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
5342 break; 5248 break;
5343 case BMIC_SENSE_CONTROLLER_PARAMETERS: 5249 case BMIC_SENSE_CONTROLLER_PARAMETERS:
5344 c->Request.CDBLen = 10; 5250 c->Request.CDBLen = 10;
5345 c->Request.Type.Attribute = ATTR_SIMPLE; 5251 c->Request.type_attr_dir =
5346 c->Request.Type.Direction = XFER_READ; 5252 TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_READ);
5347 c->Request.Timeout = 0; 5253 c->Request.Timeout = 0;
5348 c->Request.CDB[0] = BMIC_READ; 5254 c->Request.CDB[0] = BMIC_READ;
5349 c->Request.CDB[6] = BMIC_SENSE_CONTROLLER_PARAMETERS; 5255 c->Request.CDB[6] = BMIC_SENSE_CONTROLLER_PARAMETERS;
@@ -5360,9 +5266,8 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
5360 5266
5361 case HPSA_DEVICE_RESET_MSG: 5267 case HPSA_DEVICE_RESET_MSG:
5362 c->Request.CDBLen = 16; 5268 c->Request.CDBLen = 16;
5363 c->Request.Type.Type = 1; /* It is a MSG not a CMD */ 5269 c->Request.type_attr_dir =
5364 c->Request.Type.Attribute = ATTR_SIMPLE; 5270 TYPE_ATTR_DIR(cmd_type, ATTR_SIMPLE, XFER_NONE);
5365 c->Request.Type.Direction = XFER_NONE;
5366 c->Request.Timeout = 0; /* Don't time out */ 5271 c->Request.Timeout = 0; /* Don't time out */
5367 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); 5272 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB));
5368 c->Request.CDB[0] = cmd; 5273 c->Request.CDB[0] = cmd;
@@ -5376,27 +5281,28 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
5376 break; 5281 break;
5377 case HPSA_ABORT_MSG: 5282 case HPSA_ABORT_MSG:
5378 a = buff; /* point to command to be aborted */ 5283 a = buff; /* point to command to be aborted */
5379 dev_dbg(&h->pdev->dev, "Abort Tag:0x%08x:%08x using request Tag:0x%08x:%08x\n", 5284 dev_dbg(&h->pdev->dev, "Abort Tag:0x%016llx using request Tag:0x%016llx",
5380 a->Header.Tag.upper, a->Header.Tag.lower, 5285 a->Header.tag, c->Header.tag);
5381 c->Header.Tag.upper, c->Header.Tag.lower); 5286 tlower = (u32) (a->Header.tag >> 32);
5287 tupper = (u32) (a->Header.tag & 0x0ffffffffULL);
5382 c->Request.CDBLen = 16; 5288 c->Request.CDBLen = 16;
5383 c->Request.Type.Type = TYPE_MSG; 5289 c->Request.type_attr_dir =
5384 c->Request.Type.Attribute = ATTR_SIMPLE; 5290 TYPE_ATTR_DIR(cmd_type,
5385 c->Request.Type.Direction = XFER_WRITE; 5291 ATTR_SIMPLE, XFER_WRITE);
5386 c->Request.Timeout = 0; /* Don't time out */ 5292 c->Request.Timeout = 0; /* Don't time out */
5387 c->Request.CDB[0] = HPSA_TASK_MANAGEMENT; 5293 c->Request.CDB[0] = HPSA_TASK_MANAGEMENT;
5388 c->Request.CDB[1] = HPSA_TMF_ABORT_TASK; 5294 c->Request.CDB[1] = HPSA_TMF_ABORT_TASK;
5389 c->Request.CDB[2] = 0x00; /* reserved */ 5295 c->Request.CDB[2] = 0x00; /* reserved */
5390 c->Request.CDB[3] = 0x00; /* reserved */ 5296 c->Request.CDB[3] = 0x00; /* reserved */
5391 /* Tag to abort goes in CDB[4]-CDB[11] */ 5297 /* Tag to abort goes in CDB[4]-CDB[11] */
5392 c->Request.CDB[4] = a->Header.Tag.lower & 0xFF; 5298 c->Request.CDB[4] = tlower & 0xFF;
5393 c->Request.CDB[5] = (a->Header.Tag.lower >> 8) & 0xFF; 5299 c->Request.CDB[5] = (tlower >> 8) & 0xFF;
5394 c->Request.CDB[6] = (a->Header.Tag.lower >> 16) & 0xFF; 5300 c->Request.CDB[6] = (tlower >> 16) & 0xFF;
5395 c->Request.CDB[7] = (a->Header.Tag.lower >> 24) & 0xFF; 5301 c->Request.CDB[7] = (tlower >> 24) & 0xFF;
5396 c->Request.CDB[8] = a->Header.Tag.upper & 0xFF; 5302 c->Request.CDB[8] = tupper & 0xFF;
5397 c->Request.CDB[9] = (a->Header.Tag.upper >> 8) & 0xFF; 5303 c->Request.CDB[9] = (tupper >> 8) & 0xFF;
5398 c->Request.CDB[10] = (a->Header.Tag.upper >> 16) & 0xFF; 5304 c->Request.CDB[10] = (tupper >> 16) & 0xFF;
5399 c->Request.CDB[11] = (a->Header.Tag.upper >> 24) & 0xFF; 5305 c->Request.CDB[11] = (tupper >> 24) & 0xFF;
5400 c->Request.CDB[12] = 0x00; /* reserved */ 5306 c->Request.CDB[12] = 0x00; /* reserved */
5401 c->Request.CDB[13] = 0x00; /* reserved */ 5307 c->Request.CDB[13] = 0x00; /* reserved */
5402 c->Request.CDB[14] = 0x00; /* reserved */ 5308 c->Request.CDB[14] = 0x00; /* reserved */
@@ -5412,7 +5318,7 @@ static int fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
5412 BUG(); 5318 BUG();
5413 } 5319 }
5414 5320
5415 switch (c->Request.Type.Direction) { 5321 switch (GET_DIR(c->Request.type_attr_dir)) {
5416 case XFER_READ: 5322 case XFER_READ:
5417 pci_dir = PCI_DMA_FROMDEVICE; 5323 pci_dir = PCI_DMA_FROMDEVICE;
5418 break; 5324 break;
@@ -5467,15 +5373,9 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
5467 5373
5468 /* Put job onto the completed Q */ 5374 /* Put job onto the completed Q */
5469 addQ(&h->cmpQ, c); 5375 addQ(&h->cmpQ, c);
5470 5376 atomic_inc(&h->commands_outstanding);
5471 /* Must increment commands_outstanding before unlocking
5472 * and submitting to avoid race checking for fifo full
5473 * condition.
5474 */
5475 h->commands_outstanding++;
5476
5477 /* Tell the controller execute command */
5478 spin_unlock_irqrestore(&h->lock, *flags); 5377 spin_unlock_irqrestore(&h->lock, *flags);
5378 /* Tell the controller execute command */
5479 h->access.submit_command(h, c); 5379 h->access.submit_command(h, c);
5480 spin_lock_irqsave(&h->lock, *flags); 5380 spin_lock_irqsave(&h->lock, *flags);
5481 } 5381 }
@@ -5521,6 +5421,7 @@ static inline void finish_cmd(struct CommandList *c)
5521 unsigned long flags; 5421 unsigned long flags;
5522 int io_may_be_stalled = 0; 5422 int io_may_be_stalled = 0;
5523 struct ctlr_info *h = c->h; 5423 struct ctlr_info *h = c->h;
5424 int count;
5524 5425
5525 spin_lock_irqsave(&h->lock, flags); 5426 spin_lock_irqsave(&h->lock, flags);
5526 removeQ(c); 5427 removeQ(c);
@@ -5541,11 +5442,10 @@ static inline void finish_cmd(struct CommandList *c)
5541 * want to get in a cycle where we call start_io every time 5442 * want to get in a cycle where we call start_io every time
5542 * through here. 5443 * through here.
5543 */ 5444 */
5544 if (unlikely(h->fifo_recently_full) && 5445 count = atomic_read(&h->commands_outstanding);
5545 h->commands_outstanding < 5)
5546 io_may_be_stalled = 1;
5547
5548 spin_unlock_irqrestore(&h->lock, flags); 5446 spin_unlock_irqrestore(&h->lock, flags);
5447 if (unlikely(h->fifo_recently_full) && count < 5)
5448 io_may_be_stalled = 1;
5549 5449
5550 dial_up_lockup_detection_on_fw_flash_complete(c->h, c); 5450 dial_up_lockup_detection_on_fw_flash_complete(c->h, c);
5551 if (likely(c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_SCSI 5451 if (likely(c->cmd_type == CMD_IOACCEL1 || c->cmd_type == CMD_SCSI
@@ -5765,22 +5665,20 @@ static int hpsa_message(struct pci_dev *pdev, unsigned char opcode,
5765 5665
5766 cmd->CommandHeader.ReplyQueue = 0; 5666 cmd->CommandHeader.ReplyQueue = 0;
5767 cmd->CommandHeader.SGList = 0; 5667 cmd->CommandHeader.SGList = 0;
5768 cmd->CommandHeader.SGTotal = 0; 5668 cmd->CommandHeader.SGTotal = cpu_to_le16(0);
5769 cmd->CommandHeader.Tag.lower = paddr32; 5669 cmd->CommandHeader.tag = paddr32;
5770 cmd->CommandHeader.Tag.upper = 0;
5771 memset(&cmd->CommandHeader.LUN.LunAddrBytes, 0, 8); 5670 memset(&cmd->CommandHeader.LUN.LunAddrBytes, 0, 8);
5772 5671
5773 cmd->Request.CDBLen = 16; 5672 cmd->Request.CDBLen = 16;
5774 cmd->Request.Type.Type = TYPE_MSG; 5673 cmd->Request.type_attr_dir =
5775 cmd->Request.Type.Attribute = ATTR_HEADOFQUEUE; 5674 TYPE_ATTR_DIR(TYPE_MSG, ATTR_HEADOFQUEUE, XFER_NONE);
5776 cmd->Request.Type.Direction = XFER_NONE;
5777 cmd->Request.Timeout = 0; /* Don't time out */ 5675 cmd->Request.Timeout = 0; /* Don't time out */
5778 cmd->Request.CDB[0] = opcode; 5676 cmd->Request.CDB[0] = opcode;
5779 cmd->Request.CDB[1] = type; 5677 cmd->Request.CDB[1] = type;
5780 memset(&cmd->Request.CDB[2], 0, 14); /* rest of the CDB is reserved */ 5678 memset(&cmd->Request.CDB[2], 0, 14); /* rest of the CDB is reserved */
5781 cmd->ErrorDescriptor.Addr.lower = paddr32 + sizeof(*cmd); 5679 cmd->ErrorDescriptor.Addr =
5782 cmd->ErrorDescriptor.Addr.upper = 0; 5680 cpu_to_le64((paddr32 + sizeof(*cmd)));
5783 cmd->ErrorDescriptor.Len = sizeof(struct ErrorInfo); 5681 cmd->ErrorDescriptor.Len = cpu_to_le32(sizeof(struct ErrorInfo));
5784 5682
5785 writel(paddr32, vaddr + SA5_REQUEST_PORT_OFFSET); 5683 writel(paddr32, vaddr + SA5_REQUEST_PORT_OFFSET);
5786 5684
@@ -5818,7 +5716,7 @@ static int hpsa_message(struct pci_dev *pdev, unsigned char opcode,
5818#define hpsa_noop(p) hpsa_message(p, 3, 0) 5716#define hpsa_noop(p) hpsa_message(p, 3, 0)
5819 5717
5820static int hpsa_controller_hard_reset(struct pci_dev *pdev, 5718static int hpsa_controller_hard_reset(struct pci_dev *pdev,
5821 void * __iomem vaddr, u32 use_doorbell) 5719 void __iomem *vaddr, u32 use_doorbell)
5822{ 5720{
5823 u16 pmcsr; 5721 u16 pmcsr;
5824 int pos; 5722 int pos;
@@ -6056,7 +5954,7 @@ unmap_vaddr:
6056 * the io functions. 5954 * the io functions.
6057 * This is for debug only. 5955 * This is for debug only.
6058 */ 5956 */
6059static void print_cfg_table(struct device *dev, struct CfgTable *tb) 5957static void print_cfg_table(struct device *dev, struct CfgTable __iomem *tb)
6060{ 5958{
6061#ifdef HPSA_DEBUG 5959#ifdef HPSA_DEBUG
6062 int i; 5960 int i;
@@ -6323,11 +6221,11 @@ static void hpsa_find_board_params(struct ctlr_info *h)
6323 h->max_cmd_sg_entries = 31; 6221 h->max_cmd_sg_entries = 31;
6324 if (h->maxsgentries > 512) { 6222 if (h->maxsgentries > 512) {
6325 h->max_cmd_sg_entries = 32; 6223 h->max_cmd_sg_entries = 32;
6326 h->chainsize = h->maxsgentries - h->max_cmd_sg_entries + 1; 6224 h->chainsize = h->maxsgentries - h->max_cmd_sg_entries;
6327 h->maxsgentries--; /* save one for chain pointer */ 6225 h->maxsgentries--; /* save one for chain pointer */
6328 } else { 6226 } else {
6329 h->maxsgentries = 31; /* default to traditional values */
6330 h->chainsize = 0; 6227 h->chainsize = 0;
6228 h->maxsgentries = 31; /* default to traditional values */
6331 } 6229 }
6332 6230
6333 /* Find out what task management functions are supported and cache */ 6231 /* Find out what task management functions are supported and cache */
@@ -6456,15 +6354,15 @@ static int hpsa_pci_init(struct ctlr_info *h)
6456 return err; 6354 return err;
6457 } 6355 }
6458 6356
6459 /* Enable bus mastering (pci_disable_device may disable this) */
6460 pci_set_master(h->pdev);
6461
6462 err = pci_request_regions(h->pdev, HPSA); 6357 err = pci_request_regions(h->pdev, HPSA);
6463 if (err) { 6358 if (err) {
6464 dev_err(&h->pdev->dev, 6359 dev_err(&h->pdev->dev,
6465 "cannot obtain PCI resources, aborting\n"); 6360 "cannot obtain PCI resources, aborting\n");
6466 return err; 6361 return err;
6467 } 6362 }
6363
6364 pci_set_master(h->pdev);
6365
6468 hpsa_interrupt_mode(h); 6366 hpsa_interrupt_mode(h);
6469 err = hpsa_pci_find_memory_BAR(h->pdev, &h->paddr); 6367 err = hpsa_pci_find_memory_BAR(h->pdev, &h->paddr);
6470 if (err) 6368 if (err)
@@ -6544,7 +6442,9 @@ static int hpsa_init_reset_devices(struct pci_dev *pdev)
6544 dev_warn(&pdev->dev, "failed to enable device.\n"); 6442 dev_warn(&pdev->dev, "failed to enable device.\n");
6545 return -ENODEV; 6443 return -ENODEV;
6546 } 6444 }
6445
6547 pci_set_master(pdev); 6446 pci_set_master(pdev);
6447
6548 /* Reset the controller with a PCI power-cycle or via doorbell */ 6448 /* Reset the controller with a PCI power-cycle or via doorbell */
6549 rc = hpsa_kdump_hard_reset_controller(pdev); 6449 rc = hpsa_kdump_hard_reset_controller(pdev);
6550 6450
@@ -7431,13 +7331,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
7431 cp->host_context_flags = IOACCEL1_HCFLAGS_CISS_FORMAT; 7331 cp->host_context_flags = IOACCEL1_HCFLAGS_CISS_FORMAT;
7432 cp->timeout_sec = 0; 7332 cp->timeout_sec = 0;
7433 cp->ReplyQueue = 0; 7333 cp->ReplyQueue = 0;
7434 cp->Tag.lower = (i << DIRECT_LOOKUP_SHIFT) | 7334 cp->tag =
7435 DIRECT_LOOKUP_BIT; 7335 cpu_to_le64((i << DIRECT_LOOKUP_SHIFT) |
7436 cp->Tag.upper = 0; 7336 DIRECT_LOOKUP_BIT);
7437 cp->host_addr.lower = 7337 cp->host_addr =
7438 (u32) (h->ioaccel_cmd_pool_dhandle + 7338 cpu_to_le64(h->ioaccel_cmd_pool_dhandle +
7439 (i * sizeof(struct io_accel1_cmd))); 7339 (i * sizeof(struct io_accel1_cmd)));
7440 cp->host_addr.upper = 0;
7441 } 7340 }
7442 } else if (trans_support & CFGTBL_Trans_io_accel2) { 7341 } else if (trans_support & CFGTBL_Trans_io_accel2) {
7443 u64 cfg_offset, cfg_base_addr_index; 7342 u64 cfg_offset, cfg_base_addr_index;
@@ -7711,7 +7610,7 @@ static void __attribute__((unused)) verify_offsets(void)
7711 VERIFY_OFFSET(timeout_sec, 0x62); 7610 VERIFY_OFFSET(timeout_sec, 0x62);
7712 VERIFY_OFFSET(ReplyQueue, 0x64); 7611 VERIFY_OFFSET(ReplyQueue, 0x64);
7713 VERIFY_OFFSET(reserved9, 0x65); 7612 VERIFY_OFFSET(reserved9, 0x65);
7714 VERIFY_OFFSET(Tag, 0x68); 7613 VERIFY_OFFSET(tag, 0x68);
7715 VERIFY_OFFSET(host_addr, 0x70); 7614 VERIFY_OFFSET(host_addr, 0x70);
7716 VERIFY_OFFSET(CISS_LUN, 0x78); 7615 VERIFY_OFFSET(CISS_LUN, 0x78);
7717 VERIFY_OFFSET(SG, 0x78 + 8); 7616 VERIFY_OFFSET(SG, 0x78 + 8);
diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
index 24472cec7de3..8e06d9e280ec 100644
--- a/drivers/scsi/hpsa.h
+++ b/drivers/scsi/hpsa.h
@@ -118,7 +118,7 @@ struct ctlr_info {
118 struct CfgTable __iomem *cfgtable; 118 struct CfgTable __iomem *cfgtable;
119 int interrupts_enabled; 119 int interrupts_enabled;
120 int max_commands; 120 int max_commands;
121 int commands_outstanding; 121 atomic_t commands_outstanding;
122# define PERF_MODE_INT 0 122# define PERF_MODE_INT 0
123# define DOORBELL_INT 1 123# define DOORBELL_INT 1
124# define SIMPLE_MODE_INT 2 124# define SIMPLE_MODE_INT 2
@@ -164,7 +164,7 @@ struct ctlr_info {
164 */ 164 */
165 u32 trans_support; 165 u32 trans_support;
166 u32 trans_offset; 166 u32 trans_offset;
167 struct TransTable_struct *transtable; 167 struct TransTable_struct __iomem *transtable;
168 unsigned long transMethod; 168 unsigned long transMethod;
169 169
170 /* cap concurrent passthrus at some reasonable maximum */ 170 /* cap concurrent passthrus at some reasonable maximum */
@@ -181,7 +181,7 @@ struct ctlr_info {
181 u32 *blockFetchTable; 181 u32 *blockFetchTable;
182 u32 *ioaccel1_blockFetchTable; 182 u32 *ioaccel1_blockFetchTable;
183 u32 *ioaccel2_blockFetchTable; 183 u32 *ioaccel2_blockFetchTable;
184 u32 *ioaccel2_bft2_regs; 184 u32 __iomem *ioaccel2_bft2_regs;
185 unsigned char *hba_inquiry_data; 185 unsigned char *hba_inquiry_data;
186 u32 driver_support; 186 u32 driver_support;
187 u32 fw_support; 187 u32 fw_support;
@@ -192,7 +192,7 @@ struct ctlr_info {
192 u64 last_heartbeat_timestamp; 192 u64 last_heartbeat_timestamp;
193 u32 heartbeat_sample_interval; 193 u32 heartbeat_sample_interval;
194 atomic_t firmware_flash_in_progress; 194 atomic_t firmware_flash_in_progress;
195 u32 *lockup_detected; 195 u32 __percpu *lockup_detected;
196 struct delayed_work monitor_ctlr_work; 196 struct delayed_work monitor_ctlr_work;
197 int remove_in_progress; 197 int remove_in_progress;
198 u32 fifo_recently_full; 198 u32 fifo_recently_full;
@@ -395,7 +395,7 @@ static void SA5_performant_intr_mask(struct ctlr_info *h, unsigned long val)
395static unsigned long SA5_performant_completed(struct ctlr_info *h, u8 q) 395static unsigned long SA5_performant_completed(struct ctlr_info *h, u8 q)
396{ 396{
397 struct reply_queue_buffer *rq = &h->reply_queue[q]; 397 struct reply_queue_buffer *rq = &h->reply_queue[q];
398 unsigned long flags, register_value = FIFO_EMPTY; 398 unsigned long register_value = FIFO_EMPTY;
399 399
400 /* msi auto clears the interrupt pending bit. */ 400 /* msi auto clears the interrupt pending bit. */
401 if (!(h->msi_vector || h->msix_vector)) { 401 if (!(h->msi_vector || h->msix_vector)) {
@@ -413,9 +413,7 @@ static unsigned long SA5_performant_completed(struct ctlr_info *h, u8 q)
413 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) { 413 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
414 register_value = rq->head[rq->current_entry]; 414 register_value = rq->head[rq->current_entry];
415 rq->current_entry++; 415 rq->current_entry++;
416 spin_lock_irqsave(&h->lock, flags); 416 atomic_dec(&h->commands_outstanding);
417 h->commands_outstanding--;
418 spin_unlock_irqrestore(&h->lock, flags);
419 } else { 417 } else {
420 register_value = FIFO_EMPTY; 418 register_value = FIFO_EMPTY;
421 } 419 }
@@ -433,11 +431,7 @@ static unsigned long SA5_performant_completed(struct ctlr_info *h, u8 q)
433 */ 431 */
434static unsigned long SA5_fifo_full(struct ctlr_info *h) 432static unsigned long SA5_fifo_full(struct ctlr_info *h)
435{ 433{
436 if (h->commands_outstanding >= h->max_commands) 434 return atomic_read(&h->commands_outstanding) >= h->max_commands;
437 return 1;
438 else
439 return 0;
440
441} 435}
442/* 436/*
443 * returns value read from hardware. 437 * returns value read from hardware.
@@ -448,13 +442,9 @@ static unsigned long SA5_completed(struct ctlr_info *h,
448{ 442{
449 unsigned long register_value 443 unsigned long register_value
450 = readl(h->vaddr + SA5_REPLY_PORT_OFFSET); 444 = readl(h->vaddr + SA5_REPLY_PORT_OFFSET);
451 unsigned long flags;
452 445
453 if (register_value != FIFO_EMPTY) { 446 if (register_value != FIFO_EMPTY)
454 spin_lock_irqsave(&h->lock, flags); 447 atomic_dec(&h->commands_outstanding);
455 h->commands_outstanding--;
456 spin_unlock_irqrestore(&h->lock, flags);
457 }
458 448
459#ifdef HPSA_DEBUG 449#ifdef HPSA_DEBUG
460 if (register_value != FIFO_EMPTY) 450 if (register_value != FIFO_EMPTY)
@@ -510,7 +500,6 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
510{ 500{
511 u64 register_value; 501 u64 register_value;
512 struct reply_queue_buffer *rq = &h->reply_queue[q]; 502 struct reply_queue_buffer *rq = &h->reply_queue[q];
513 unsigned long flags;
514 503
515 BUG_ON(q >= h->nreply_queues); 504 BUG_ON(q >= h->nreply_queues);
516 505
@@ -528,9 +517,7 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
528 wmb(); 517 wmb();
529 writel((q << 24) | rq->current_entry, h->vaddr + 518 writel((q << 24) | rq->current_entry, h->vaddr +
530 IOACCEL_MODE1_CONSUMER_INDEX); 519 IOACCEL_MODE1_CONSUMER_INDEX);
531 spin_lock_irqsave(&h->lock, flags); 520 atomic_dec(&h->commands_outstanding);
532 h->commands_outstanding--;
533 spin_unlock_irqrestore(&h->lock, flags);
534 } 521 }
535 return (unsigned long) register_value; 522 return (unsigned long) register_value;
536} 523}
diff --git a/drivers/scsi/hpsa_cmd.h b/drivers/scsi/hpsa_cmd.h
index b5125dc31439..cb988c41cad9 100644
--- a/drivers/scsi/hpsa_cmd.h
+++ b/drivers/scsi/hpsa_cmd.h
@@ -252,7 +252,7 @@ struct ReportExtendedLUNdata {
252 u8 LUNListLength[4]; 252 u8 LUNListLength[4];
253 u8 extended_response_flag; 253 u8 extended_response_flag;
254 u8 reserved[3]; 254 u8 reserved[3];
255 struct ext_report_lun_entry LUN[HPSA_MAX_LUN]; 255 struct ext_report_lun_entry LUN[HPSA_MAX_PHYS_LUN];
256}; 256};
257 257
258struct SenseSubsystem_info { 258struct SenseSubsystem_info {
@@ -314,28 +314,36 @@ struct CommandListHeader {
314 u8 ReplyQueue; 314 u8 ReplyQueue;
315 u8 SGList; 315 u8 SGList;
316 u16 SGTotal; 316 u16 SGTotal;
317 struct vals32 Tag; 317 u64 tag;
318 union LUNAddr LUN; 318 union LUNAddr LUN;
319}; 319};
320 320
321struct RequestBlock { 321struct RequestBlock {
322 u8 CDBLen; 322 u8 CDBLen;
323 struct { 323 /*
324 u8 Type:3; 324 * type_attr_dir:
325 u8 Attribute:3; 325 * type: low 3 bits
326 u8 Direction:2; 326 * attr: middle 3 bits
327 } Type; 327 * dir: high 2 bits
328 */
329 u8 type_attr_dir;
330#define TYPE_ATTR_DIR(t, a, d) ((((d) & 0x03) << 6) |\
331 (((a) & 0x07) << 3) |\
332 ((t) & 0x07))
333#define GET_TYPE(tad) ((tad) & 0x07)
334#define GET_ATTR(tad) (((tad) >> 3) & 0x07)
335#define GET_DIR(tad) (((tad) >> 6) & 0x03)
328 u16 Timeout; 336 u16 Timeout;
329 u8 CDB[16]; 337 u8 CDB[16];
330}; 338};
331 339
332struct ErrDescriptor { 340struct ErrDescriptor {
333 struct vals32 Addr; 341 u64 Addr;
334 u32 Len; 342 u32 Len;
335}; 343};
336 344
337struct SGDescriptor { 345struct SGDescriptor {
338 struct vals32 Addr; 346 u64 Addr;
339 u32 Len; 347 u32 Len;
340 u32 Ext; 348 u32 Ext;
341}; 349};
@@ -434,8 +442,8 @@ struct io_accel1_cmd {
434 u16 timeout_sec; /* 0x62 - 0x63 */ 442 u16 timeout_sec; /* 0x62 - 0x63 */
435 u8 ReplyQueue; /* 0x64 */ 443 u8 ReplyQueue; /* 0x64 */
436 u8 reserved9[3]; /* 0x65 - 0x67 */ 444 u8 reserved9[3]; /* 0x65 - 0x67 */
437 struct vals32 Tag; /* 0x68 - 0x6F */ 445 u64 tag; /* 0x68 - 0x6F */
438 struct vals32 host_addr; /* 0x70 - 0x77 */ 446 u64 host_addr; /* 0x70 - 0x77 */
439 u8 CISS_LUN[8]; /* 0x78 - 0x7F */ 447 u8 CISS_LUN[8]; /* 0x78 - 0x7F */
440 struct SGDescriptor SG[IOACCEL1_MAXSGENTRIES]; 448 struct SGDescriptor SG[IOACCEL1_MAXSGENTRIES];
441} __aligned(IOACCEL1_COMMANDLIST_ALIGNMENT); 449} __aligned(IOACCEL1_COMMANDLIST_ALIGNMENT);
@@ -555,8 +563,8 @@ struct hpsa_tmf_struct {
555 u8 reserved1; /* byte 3 Reserved */ 563 u8 reserved1; /* byte 3 Reserved */
556 u32 it_nexus; /* SCSI I-T Nexus */ 564 u32 it_nexus; /* SCSI I-T Nexus */
557 u8 lun_id[8]; /* LUN ID for TMF request */ 565 u8 lun_id[8]; /* LUN ID for TMF request */
558 struct vals32 Tag; /* cciss tag associated w/ request */ 566 u64 tag; /* cciss tag associated w/ request */
559 struct vals32 abort_tag;/* cciss tag of SCSI cmd or task to abort */ 567 u64 abort_tag; /* cciss tag of SCSI cmd or task to abort */
560 u64 error_ptr; /* Error Pointer */ 568 u64 error_ptr; /* Error Pointer */
561 u32 error_len; /* Error Length */ 569 u32 error_len; /* Error Length */
562}; 570};
diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index dedb62c21b29..e995218476ed 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -1118,17 +1118,13 @@ static int hptiop_reset(struct scsi_cmnd *scp)
1118} 1118}
1119 1119
1120static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev, 1120static int hptiop_adjust_disk_queue_depth(struct scsi_device *sdev,
1121 int queue_depth, int reason) 1121 int queue_depth)
1122{ 1122{
1123 struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata; 1123 struct hptiop_hba *hba = (struct hptiop_hba *)sdev->host->hostdata;
1124 1124
1125 if (reason != SCSI_QDEPTH_DEFAULT)
1126 return -EOPNOTSUPP;
1127
1128 if (queue_depth > hba->max_requests) 1125 if (queue_depth > hba->max_requests)
1129 queue_depth = hba->max_requests; 1126 queue_depth = hba->max_requests;
1130 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, queue_depth); 1127 return scsi_change_queue_depth(sdev, queue_depth);
1131 return queue_depth;
1132} 1128}
1133 1129
1134static ssize_t hptiop_show_version(struct device *dev, 1130static ssize_t hptiop_show_version(struct device *dev,
diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 598c42cba5a8..f58c6d8e0264 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1643,19 +1643,9 @@ static int ibmvfc_queuecommand_lck(struct scsi_cmnd *cmnd,
1643 int_to_scsilun(cmnd->device->lun, &vfc_cmd->iu.lun); 1643 int_to_scsilun(cmnd->device->lun, &vfc_cmd->iu.lun);
1644 memcpy(vfc_cmd->iu.cdb, cmnd->cmnd, cmnd->cmd_len); 1644 memcpy(vfc_cmd->iu.cdb, cmnd->cmnd, cmnd->cmd_len);
1645 1645
1646 if (scsi_populate_tag_msg(cmnd, tag)) { 1646 if (cmnd->flags & SCMD_TAGGED) {
1647 vfc_cmd->task_tag = cpu_to_be64(tag[1]); 1647 vfc_cmd->task_tag = cpu_to_be64(cmnd->tag);
1648 switch (tag[0]) { 1648 vfc_cmd->iu.pri_task_attr = IBMVFC_SIMPLE_TASK;
1649 case MSG_SIMPLE_TAG:
1650 vfc_cmd->iu.pri_task_attr = IBMVFC_SIMPLE_TASK;
1651 break;
1652 case MSG_HEAD_TAG:
1653 vfc_cmd->iu.pri_task_attr = IBMVFC_HEAD_OF_QUEUE;
1654 break;
1655 case MSG_ORDERED_TAG:
1656 vfc_cmd->iu.pri_task_attr = IBMVFC_ORDERED_TASK;
1657 break;
1658 };
1659 } 1649 }
1660 1650
1661 if (likely(!(rc = ibmvfc_map_sg_data(cmnd, evt, vfc_cmd, vhost->dev)))) 1651 if (likely(!(rc = ibmvfc_map_sg_data(cmnd, evt, vfc_cmd, vhost->dev))))
@@ -2897,12 +2887,6 @@ static int ibmvfc_slave_configure(struct scsi_device *sdev)
2897 spin_lock_irqsave(shost->host_lock, flags); 2887 spin_lock_irqsave(shost->host_lock, flags);
2898 if (sdev->type == TYPE_DISK) 2888 if (sdev->type == TYPE_DISK)
2899 sdev->allow_restart = 1; 2889 sdev->allow_restart = 1;
2900
2901 if (sdev->tagged_supported) {
2902 scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
2903 scsi_activate_tcq(sdev, sdev->queue_depth);
2904 } else
2905 scsi_deactivate_tcq(sdev, sdev->queue_depth);
2906 spin_unlock_irqrestore(shost->host_lock, flags); 2890 spin_unlock_irqrestore(shost->host_lock, flags);
2907 return 0; 2891 return 0;
2908} 2892}
@@ -2916,40 +2900,12 @@ static int ibmvfc_slave_configure(struct scsi_device *sdev)
2916 * Return value: 2900 * Return value:
2917 * actual depth set 2901 * actual depth set
2918 **/ 2902 **/
2919static int ibmvfc_change_queue_depth(struct scsi_device *sdev, int qdepth, 2903static int ibmvfc_change_queue_depth(struct scsi_device *sdev, int qdepth)
2920 int reason)
2921{ 2904{
2922 if (reason != SCSI_QDEPTH_DEFAULT)
2923 return -EOPNOTSUPP;
2924
2925 if (qdepth > IBMVFC_MAX_CMDS_PER_LUN) 2905 if (qdepth > IBMVFC_MAX_CMDS_PER_LUN)
2926 qdepth = IBMVFC_MAX_CMDS_PER_LUN; 2906 qdepth = IBMVFC_MAX_CMDS_PER_LUN;
2927 2907
2928 scsi_adjust_queue_depth(sdev, 0, qdepth); 2908 return scsi_change_queue_depth(sdev, qdepth);
2929 return sdev->queue_depth;
2930}
2931
2932/**
2933 * ibmvfc_change_queue_type - Change the device's queue type
2934 * @sdev: scsi device struct
2935 * @tag_type: type of tags to use
2936 *
2937 * Return value:
2938 * actual queue type set
2939 **/
2940static int ibmvfc_change_queue_type(struct scsi_device *sdev, int tag_type)
2941{
2942 if (sdev->tagged_supported) {
2943 scsi_set_tag_type(sdev, tag_type);
2944
2945 if (tag_type)
2946 scsi_activate_tcq(sdev, sdev->queue_depth);
2947 else
2948 scsi_deactivate_tcq(sdev, sdev->queue_depth);
2949 } else
2950 tag_type = 0;
2951
2952 return tag_type;
2953} 2909}
2954 2910
2955static ssize_t ibmvfc_show_host_partition_name(struct device *dev, 2911static ssize_t ibmvfc_show_host_partition_name(struct device *dev,
@@ -3133,7 +3089,7 @@ static struct scsi_host_template driver_template = {
3133 .target_alloc = ibmvfc_target_alloc, 3089 .target_alloc = ibmvfc_target_alloc,
3134 .scan_finished = ibmvfc_scan_finished, 3090 .scan_finished = ibmvfc_scan_finished,
3135 .change_queue_depth = ibmvfc_change_queue_depth, 3091 .change_queue_depth = ibmvfc_change_queue_depth,
3136 .change_queue_type = ibmvfc_change_queue_type, 3092 .change_queue_type = scsi_change_queue_type,
3137 .cmd_per_lun = 16, 3093 .cmd_per_lun = 16,
3138 .can_queue = IBMVFC_MAX_REQUESTS_DEFAULT, 3094 .can_queue = IBMVFC_MAX_REQUESTS_DEFAULT,
3139 .this_id = -1, 3095 .this_id = -1,
@@ -3141,6 +3097,8 @@ static struct scsi_host_template driver_template = {
3141 .max_sectors = IBMVFC_MAX_SECTORS, 3097 .max_sectors = IBMVFC_MAX_SECTORS,
3142 .use_clustering = ENABLE_CLUSTERING, 3098 .use_clustering = ENABLE_CLUSTERING,
3143 .shost_attrs = ibmvfc_attrs, 3099 .shost_attrs = ibmvfc_attrs,
3100 .use_blk_tags = 1,
3101 .track_queue_depth = 1,
3144}; 3102};
3145 3103
3146/** 3104/**
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 7b23f21f22f1..acea5d6eebd0 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -1929,7 +1929,6 @@ static int ibmvscsi_slave_configure(struct scsi_device *sdev)
1929 blk_queue_rq_timeout(sdev->request_queue, 120 * HZ); 1929 blk_queue_rq_timeout(sdev->request_queue, 120 * HZ);
1930 } 1930 }
1931 spin_unlock_irqrestore(shost->host_lock, lock_flags); 1931 spin_unlock_irqrestore(shost->host_lock, lock_flags);
1932 scsi_adjust_queue_depth(sdev, 0, shost->cmd_per_lun);
1933 return 0; 1932 return 0;
1934} 1933}
1935 1934
@@ -1942,17 +1941,11 @@ static int ibmvscsi_slave_configure(struct scsi_device *sdev)
1942 * Return value: 1941 * Return value:
1943 * actual depth set 1942 * actual depth set
1944 **/ 1943 **/
1945static int ibmvscsi_change_queue_depth(struct scsi_device *sdev, int qdepth, 1944static int ibmvscsi_change_queue_depth(struct scsi_device *sdev, int qdepth)
1946 int reason)
1947{ 1945{
1948 if (reason != SCSI_QDEPTH_DEFAULT)
1949 return -EOPNOTSUPP;
1950
1951 if (qdepth > IBMVSCSI_MAX_CMDS_PER_LUN) 1946 if (qdepth > IBMVSCSI_MAX_CMDS_PER_LUN)
1952 qdepth = IBMVSCSI_MAX_CMDS_PER_LUN; 1947 qdepth = IBMVSCSI_MAX_CMDS_PER_LUN;
1953 1948 return scsi_change_queue_depth(sdev, qdepth);
1954 scsi_adjust_queue_depth(sdev, 0, qdepth);
1955 return sdev->queue_depth;
1956} 1949}
1957 1950
1958/* ------------------------------------------------------------ 1951/* ------------------------------------------------------------
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 2a9578c116b7..540294389355 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -3942,8 +3942,9 @@ static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
3942 return -EIO; 3942 return -EIO;
3943 } 3943 }
3944 3944
3945 sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist, 3945 sglist->num_dma_sg = dma_map_sg(&ioa_cfg->pdev->dev,
3946 sglist->num_sg, DMA_TO_DEVICE); 3946 sglist->scatterlist, sglist->num_sg,
3947 DMA_TO_DEVICE);
3947 3948
3948 if (!sglist->num_dma_sg) { 3949 if (!sglist->num_dma_sg) {
3949 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3950 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
@@ -4327,16 +4328,12 @@ static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
4327 * Return value: 4328 * Return value:
4328 * actual depth set 4329 * actual depth set
4329 **/ 4330 **/
4330static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth, 4331static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
4331 int reason)
4332{ 4332{
4333 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata; 4333 struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
4334 struct ipr_resource_entry *res; 4334 struct ipr_resource_entry *res;
4335 unsigned long lock_flags = 0; 4335 unsigned long lock_flags = 0;
4336 4336
4337 if (reason != SCSI_QDEPTH_DEFAULT)
4338 return -EOPNOTSUPP;
4339
4340 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 4337 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4341 res = (struct ipr_resource_entry *)sdev->hostdata; 4338 res = (struct ipr_resource_entry *)sdev->hostdata;
4342 4339
@@ -4344,7 +4341,7 @@ static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth,
4344 qdepth = IPR_MAX_CMD_PER_ATA_LUN; 4341 qdepth = IPR_MAX_CMD_PER_ATA_LUN;
4345 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 4342 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4346 4343
4347 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 4344 scsi_change_queue_depth(sdev, qdepth);
4348 return sdev->queue_depth; 4345 return sdev->queue_depth;
4349} 4346}
4350 4347
@@ -4364,24 +4361,10 @@ static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
4364 4361
4365 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 4362 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
4366 res = (struct ipr_resource_entry *)sdev->hostdata; 4363 res = (struct ipr_resource_entry *)sdev->hostdata;
4367 4364 if (res && ipr_is_gscsi(res))
4368 if (res) { 4365 tag_type = scsi_change_queue_type(sdev, tag_type);
4369 if (ipr_is_gscsi(res) && sdev->tagged_supported) { 4366 else
4370 /*
4371 * We don't bother quiescing the device here since the
4372 * adapter firmware does it for us.
4373 */
4374 scsi_set_tag_type(sdev, tag_type);
4375
4376 if (tag_type)
4377 scsi_activate_tcq(sdev, sdev->queue_depth);
4378 else
4379 scsi_deactivate_tcq(sdev, sdev->queue_depth);
4380 } else
4381 tag_type = 0;
4382 } else
4383 tag_type = 0; 4367 tag_type = 0;
4384
4385 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 4368 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4386 return tag_type; 4369 return tag_type;
4387} 4370}
@@ -4765,10 +4748,10 @@ static int ipr_slave_configure(struct scsi_device *sdev)
4765 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 4748 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
4766 4749
4767 if (ap) { 4750 if (ap) {
4768 scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN); 4751 scsi_change_queue_depth(sdev, IPR_MAX_CMD_PER_ATA_LUN);
4769 ata_sas_slave_configure(sdev, ap); 4752 ata_sas_slave_configure(sdev, ap);
4770 } else 4753 }
4771 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); 4754
4772 if (ioa_cfg->sis64) 4755 if (ioa_cfg->sis64)
4773 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n", 4756 sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
4774 ipr_format_res_path(ioa_cfg, 4757 ipr_format_res_path(ioa_cfg,
@@ -5585,7 +5568,7 @@ static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
5585 nseg = scsi_dma_map(scsi_cmd); 5568 nseg = scsi_dma_map(scsi_cmd);
5586 if (nseg < 0) { 5569 if (nseg < 0) {
5587 if (printk_ratelimit()) 5570 if (printk_ratelimit())
5588 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n"); 5571 dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
5589 return -1; 5572 return -1;
5590 } 5573 }
5591 5574
@@ -5636,7 +5619,7 @@ static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5636 5619
5637 nseg = scsi_dma_map(scsi_cmd); 5620 nseg = scsi_dma_map(scsi_cmd);
5638 if (nseg < 0) { 5621 if (nseg < 0) {
5639 dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n"); 5622 dev_err(&ioa_cfg->pdev->dev, "scsi_dma_map failed!\n");
5640 return -1; 5623 return -1;
5641 } 5624 }
5642 5625
@@ -5673,35 +5656,6 @@ static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
5673} 5656}
5674 5657
5675/** 5658/**
5676 * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
5677 * @scsi_cmd: scsi command struct
5678 *
5679 * Return value:
5680 * task attributes
5681 **/
5682static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
5683{
5684 u8 tag[2];
5685 u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
5686
5687 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
5688 switch (tag[0]) {
5689 case MSG_SIMPLE_TAG:
5690 rc = IPR_FLAGS_LO_SIMPLE_TASK;
5691 break;
5692 case MSG_HEAD_TAG:
5693 rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
5694 break;
5695 case MSG_ORDERED_TAG:
5696 rc = IPR_FLAGS_LO_ORDERED_TASK;
5697 break;
5698 };
5699 }
5700
5701 return rc;
5702}
5703
5704/**
5705 * ipr_erp_done - Process completion of ERP for a device 5659 * ipr_erp_done - Process completion of ERP for a device
5706 * @ipr_cmd: ipr command struct 5660 * @ipr_cmd: ipr command struct
5707 * 5661 *
@@ -6236,7 +6190,10 @@ static int ipr_queuecommand(struct Scsi_Host *shost,
6236 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST; 6190 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
6237 } 6191 }
6238 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR; 6192 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
6239 ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd); 6193 if (scsi_cmd->flags & SCMD_TAGGED)
6194 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_SIMPLE_TASK;
6195 else
6196 ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_UNTAGGED_TASK;
6240 } 6197 }
6241 6198
6242 if (scsi_cmd->cmnd[0] >= 0xC0 && 6199 if (scsi_cmd->cmnd[0] >= 0xC0 &&
@@ -6357,6 +6314,7 @@ static struct scsi_host_template driver_template = {
6357 .sdev_attrs = ipr_dev_attrs, 6314 .sdev_attrs = ipr_dev_attrs,
6358 .proc_name = IPR_NAME, 6315 .proc_name = IPR_NAME,
6359 .no_write_same = 1, 6316 .no_write_same = 1,
6317 .use_blk_tags = 1,
6360}; 6318};
6361 6319
6362/** 6320/**
@@ -8431,7 +8389,7 @@ static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
8431 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; 8389 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
8432 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist; 8390 struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
8433 8391
8434 pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist, 8392 dma_unmap_sg(&ioa_cfg->pdev->dev, sglist->scatterlist,
8435 sglist->num_sg, DMA_TO_DEVICE); 8393 sglist->num_sg, DMA_TO_DEVICE);
8436 8394
8437 ipr_cmd->job_step = ipr_reset_alert; 8395 ipr_cmd->job_step = ipr_reset_alert;
@@ -8871,7 +8829,7 @@ static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8871 8829
8872 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) { 8830 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
8873 if (ioa_cfg->ipr_cmnd_list[i]) 8831 if (ioa_cfg->ipr_cmnd_list[i])
8874 pci_pool_free(ioa_cfg->ipr_cmd_pool, 8832 dma_pool_free(ioa_cfg->ipr_cmd_pool,
8875 ioa_cfg->ipr_cmnd_list[i], 8833 ioa_cfg->ipr_cmnd_list[i],
8876 ioa_cfg->ipr_cmnd_list_dma[i]); 8834 ioa_cfg->ipr_cmnd_list_dma[i]);
8877 8835
@@ -8879,7 +8837,7 @@ static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8879 } 8837 }
8880 8838
8881 if (ioa_cfg->ipr_cmd_pool) 8839 if (ioa_cfg->ipr_cmd_pool)
8882 pci_pool_destroy(ioa_cfg->ipr_cmd_pool); 8840 dma_pool_destroy(ioa_cfg->ipr_cmd_pool);
8883 8841
8884 kfree(ioa_cfg->ipr_cmnd_list); 8842 kfree(ioa_cfg->ipr_cmnd_list);
8885 kfree(ioa_cfg->ipr_cmnd_list_dma); 8843 kfree(ioa_cfg->ipr_cmnd_list_dma);
@@ -8900,25 +8858,24 @@ static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
8900 int i; 8858 int i;
8901 8859
8902 kfree(ioa_cfg->res_entries); 8860 kfree(ioa_cfg->res_entries);
8903 pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs), 8861 dma_free_coherent(&ioa_cfg->pdev->dev, sizeof(struct ipr_misc_cbs),
8904 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma); 8862 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
8905 ipr_free_cmd_blks(ioa_cfg); 8863 ipr_free_cmd_blks(ioa_cfg);
8906 8864
8907 for (i = 0; i < ioa_cfg->hrrq_num; i++) 8865 for (i = 0; i < ioa_cfg->hrrq_num; i++)
8908 pci_free_consistent(ioa_cfg->pdev, 8866 dma_free_coherent(&ioa_cfg->pdev->dev,
8909 sizeof(u32) * ioa_cfg->hrrq[i].size, 8867 sizeof(u32) * ioa_cfg->hrrq[i].size,
8910 ioa_cfg->hrrq[i].host_rrq, 8868 ioa_cfg->hrrq[i].host_rrq,
8911 ioa_cfg->hrrq[i].host_rrq_dma); 8869 ioa_cfg->hrrq[i].host_rrq_dma);
8912 8870
8913 pci_free_consistent(ioa_cfg->pdev, ioa_cfg->cfg_table_size, 8871 dma_free_coherent(&ioa_cfg->pdev->dev, ioa_cfg->cfg_table_size,
8914 ioa_cfg->u.cfg_table, 8872 ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
8915 ioa_cfg->cfg_table_dma);
8916 8873
8917 for (i = 0; i < IPR_NUM_HCAMS; i++) { 8874 for (i = 0; i < IPR_NUM_HCAMS; i++) {
8918 pci_free_consistent(ioa_cfg->pdev, 8875 dma_free_coherent(&ioa_cfg->pdev->dev,
8919 sizeof(struct ipr_hostrcb), 8876 sizeof(struct ipr_hostrcb),
8920 ioa_cfg->hostrcb[i], 8877 ioa_cfg->hostrcb[i],
8921 ioa_cfg->hostrcb_dma[i]); 8878 ioa_cfg->hostrcb_dma[i]);
8922 } 8879 }
8923 8880
8924 ipr_free_dump(ioa_cfg); 8881 ipr_free_dump(ioa_cfg);
@@ -8979,7 +8936,7 @@ static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
8979 dma_addr_t dma_addr; 8936 dma_addr_t dma_addr;
8980 int i, entries_each_hrrq, hrrq_id = 0; 8937 int i, entries_each_hrrq, hrrq_id = 0;
8981 8938
8982 ioa_cfg->ipr_cmd_pool = pci_pool_create(IPR_NAME, ioa_cfg->pdev, 8939 ioa_cfg->ipr_cmd_pool = dma_pool_create(IPR_NAME, &ioa_cfg->pdev->dev,
8983 sizeof(struct ipr_cmnd), 512, 0); 8940 sizeof(struct ipr_cmnd), 512, 0);
8984 8941
8985 if (!ioa_cfg->ipr_cmd_pool) 8942 if (!ioa_cfg->ipr_cmd_pool)
@@ -9029,7 +8986,7 @@ static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
9029 } 8986 }
9030 8987
9031 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) { 8988 for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
9032 ipr_cmd = pci_pool_alloc(ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr); 8989 ipr_cmd = dma_pool_alloc(ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
9033 8990
9034 if (!ipr_cmd) { 8991 if (!ipr_cmd) {
9035 ipr_free_cmd_blks(ioa_cfg); 8992 ipr_free_cmd_blks(ioa_cfg);
@@ -9100,9 +9057,10 @@ static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
9100 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg; 9057 ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
9101 } 9058 }
9102 9059
9103 ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev, 9060 ioa_cfg->vpd_cbs = dma_alloc_coherent(&pdev->dev,
9104 sizeof(struct ipr_misc_cbs), 9061 sizeof(struct ipr_misc_cbs),
9105 &ioa_cfg->vpd_cbs_dma); 9062 &ioa_cfg->vpd_cbs_dma,
9063 GFP_KERNEL);
9106 9064
9107 if (!ioa_cfg->vpd_cbs) 9065 if (!ioa_cfg->vpd_cbs)
9108 goto out_free_res_entries; 9066 goto out_free_res_entries;
@@ -9111,13 +9069,14 @@ static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
9111 goto out_free_vpd_cbs; 9069 goto out_free_vpd_cbs;
9112 9070
9113 for (i = 0; i < ioa_cfg->hrrq_num; i++) { 9071 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9114 ioa_cfg->hrrq[i].host_rrq = pci_alloc_consistent(ioa_cfg->pdev, 9072 ioa_cfg->hrrq[i].host_rrq = dma_alloc_coherent(&pdev->dev,
9115 sizeof(u32) * ioa_cfg->hrrq[i].size, 9073 sizeof(u32) * ioa_cfg->hrrq[i].size,
9116 &ioa_cfg->hrrq[i].host_rrq_dma); 9074 &ioa_cfg->hrrq[i].host_rrq_dma,
9075 GFP_KERNEL);
9117 9076
9118 if (!ioa_cfg->hrrq[i].host_rrq) { 9077 if (!ioa_cfg->hrrq[i].host_rrq) {
9119 while (--i > 0) 9078 while (--i > 0)
9120 pci_free_consistent(pdev, 9079 dma_free_coherent(&pdev->dev,
9121 sizeof(u32) * ioa_cfg->hrrq[i].size, 9080 sizeof(u32) * ioa_cfg->hrrq[i].size,
9122 ioa_cfg->hrrq[i].host_rrq, 9081 ioa_cfg->hrrq[i].host_rrq,
9123 ioa_cfg->hrrq[i].host_rrq_dma); 9082 ioa_cfg->hrrq[i].host_rrq_dma);
@@ -9126,17 +9085,19 @@ static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
9126 ioa_cfg->hrrq[i].ioa_cfg = ioa_cfg; 9085 ioa_cfg->hrrq[i].ioa_cfg = ioa_cfg;
9127 } 9086 }
9128 9087
9129 ioa_cfg->u.cfg_table = pci_alloc_consistent(ioa_cfg->pdev, 9088 ioa_cfg->u.cfg_table = dma_alloc_coherent(&pdev->dev,
9130 ioa_cfg->cfg_table_size, 9089 ioa_cfg->cfg_table_size,
9131 &ioa_cfg->cfg_table_dma); 9090 &ioa_cfg->cfg_table_dma,
9091 GFP_KERNEL);
9132 9092
9133 if (!ioa_cfg->u.cfg_table) 9093 if (!ioa_cfg->u.cfg_table)
9134 goto out_free_host_rrq; 9094 goto out_free_host_rrq;
9135 9095
9136 for (i = 0; i < IPR_NUM_HCAMS; i++) { 9096 for (i = 0; i < IPR_NUM_HCAMS; i++) {
9137 ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev, 9097 ioa_cfg->hostrcb[i] = dma_alloc_coherent(&pdev->dev,
9138 sizeof(struct ipr_hostrcb), 9098 sizeof(struct ipr_hostrcb),
9139 &ioa_cfg->hostrcb_dma[i]); 9099 &ioa_cfg->hostrcb_dma[i],
9100 GFP_KERNEL);
9140 9101
9141 if (!ioa_cfg->hostrcb[i]) 9102 if (!ioa_cfg->hostrcb[i])
9142 goto out_free_hostrcb_dma; 9103 goto out_free_hostrcb_dma;
@@ -9160,25 +9121,24 @@ out:
9160 9121
9161out_free_hostrcb_dma: 9122out_free_hostrcb_dma:
9162 while (i-- > 0) { 9123 while (i-- > 0) {
9163 pci_free_consistent(pdev, sizeof(struct ipr_hostrcb), 9124 dma_free_coherent(&pdev->dev, sizeof(struct ipr_hostrcb),
9164 ioa_cfg->hostrcb[i], 9125 ioa_cfg->hostrcb[i],
9165 ioa_cfg->hostrcb_dma[i]); 9126 ioa_cfg->hostrcb_dma[i]);
9166 } 9127 }
9167 pci_free_consistent(pdev, ioa_cfg->cfg_table_size, 9128 dma_free_coherent(&pdev->dev, ioa_cfg->cfg_table_size,
9168 ioa_cfg->u.cfg_table, 9129 ioa_cfg->u.cfg_table, ioa_cfg->cfg_table_dma);
9169 ioa_cfg->cfg_table_dma);
9170out_free_host_rrq: 9130out_free_host_rrq:
9171 for (i = 0; i < ioa_cfg->hrrq_num; i++) { 9131 for (i = 0; i < ioa_cfg->hrrq_num; i++) {
9172 pci_free_consistent(pdev, 9132 dma_free_coherent(&pdev->dev,
9173 sizeof(u32) * ioa_cfg->hrrq[i].size, 9133 sizeof(u32) * ioa_cfg->hrrq[i].size,
9174 ioa_cfg->hrrq[i].host_rrq, 9134 ioa_cfg->hrrq[i].host_rrq,
9175 ioa_cfg->hrrq[i].host_rrq_dma); 9135 ioa_cfg->hrrq[i].host_rrq_dma);
9176 } 9136 }
9177out_ipr_free_cmd_blocks: 9137out_ipr_free_cmd_blocks:
9178 ipr_free_cmd_blks(ioa_cfg); 9138 ipr_free_cmd_blks(ioa_cfg);
9179out_free_vpd_cbs: 9139out_free_vpd_cbs:
9180 pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs), 9140 dma_free_coherent(&pdev->dev, sizeof(struct ipr_misc_cbs),
9181 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma); 9141 ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
9182out_free_res_entries: 9142out_free_res_entries:
9183 kfree(ioa_cfg->res_entries); 9143 kfree(ioa_cfg->res_entries);
9184 goto out; 9144 goto out;
@@ -9618,16 +9578,17 @@ static int ipr_probe_ioa(struct pci_dev *pdev,
9618 ipr_init_regs(ioa_cfg); 9578 ipr_init_regs(ioa_cfg);
9619 9579
9620 if (ioa_cfg->sis64) { 9580 if (ioa_cfg->sis64) {
9621 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64)); 9581 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
9622 if (rc < 0) { 9582 if (rc < 0) {
9623 dev_dbg(&pdev->dev, "Failed to set 64 bit PCI DMA mask\n"); 9583 dev_dbg(&pdev->dev, "Failed to set 64 bit DMA mask\n");
9624 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 9584 rc = dma_set_mask_and_coherent(&pdev->dev,
9585 DMA_BIT_MASK(32));
9625 } 9586 }
9626 } else 9587 } else
9627 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); 9588 rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
9628 9589
9629 if (rc < 0) { 9590 if (rc < 0) {
9630 dev_err(&pdev->dev, "Failed to set PCI DMA mask\n"); 9591 dev_err(&pdev->dev, "Failed to set DMA mask\n");
9631 goto cleanup_nomem; 9592 goto cleanup_nomem;
9632 } 9593 }
9633 9594
diff --git a/drivers/scsi/ipr.h b/drivers/scsi/ipr.h
index d0201ceb4aac..9ebdebd944e7 100644
--- a/drivers/scsi/ipr.h
+++ b/drivers/scsi/ipr.h
@@ -1549,7 +1549,7 @@ struct ipr_ioa_cfg {
1549 struct ipr_misc_cbs *vpd_cbs; 1549 struct ipr_misc_cbs *vpd_cbs;
1550 dma_addr_t vpd_cbs_dma; 1550 dma_addr_t vpd_cbs_dma;
1551 1551
1552 struct pci_pool *ipr_cmd_pool; 1552 struct dma_pool *ipr_cmd_pool;
1553 1553
1554 struct ipr_cmnd *reset_cmd; 1554 struct ipr_cmnd *reset_cmd;
1555 int (*reset) (struct ipr_cmnd *); 1555 int (*reset) (struct ipr_cmnd *);
diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index e5afc3884d74..e5c28435d768 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -1210,7 +1210,7 @@ ips_slave_configure(struct scsi_device * SDptr)
1210 min = ha->max_cmds / 2; 1210 min = ha->max_cmds / 2;
1211 if (ha->enq->ucLogDriveCount <= 2) 1211 if (ha->enq->ucLogDriveCount <= 2)
1212 min = ha->max_cmds - 1; 1212 min = ha->max_cmds - 1;
1213 scsi_adjust_queue_depth(SDptr, MSG_ORDERED_TAG, min); 1213 scsi_change_queue_depth(SDptr, min);
1214 } 1214 }
1215 1215
1216 SDptr->skip_ms_page_8 = 1; 1216 SDptr->skip_ms_page_8 = 1;
diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
index 2e890b1e2526..724c6265b667 100644
--- a/drivers/scsi/isci/init.c
+++ b/drivers/scsi/isci/init.c
@@ -172,6 +172,8 @@ static struct scsi_host_template isci_sht = {
172 .target_destroy = sas_target_destroy, 172 .target_destroy = sas_target_destroy,
173 .ioctl = sas_ioctl, 173 .ioctl = sas_ioctl,
174 .shost_attrs = isci_host_attrs, 174 .shost_attrs = isci_host_attrs,
175 .use_blk_tags = 1,
176 .track_queue_depth = 1,
175}; 177};
176 178
177static struct sas_domain_function_template isci_transport_ops = { 179static struct sas_domain_function_template isci_transport_ops = {
@@ -258,8 +260,6 @@ static int isci_register_sas_ha(struct isci_host *isci_host)
258 sas_ha->sas_port = sas_ports; 260 sas_ha->sas_port = sas_ports;
259 sas_ha->num_phys = SCI_MAX_PHYS; 261 sas_ha->num_phys = SCI_MAX_PHYS;
260 262
261 sas_ha->lldd_queue_size = ISCI_CAN_QUEUE_VAL;
262 sas_ha->lldd_max_execute_num = 1;
263 sas_ha->strict_wide_ports = 1; 263 sas_ha->strict_wide_ports = 1;
264 264
265 sas_register_ha(sas_ha); 265 sas_register_ha(sas_ha);
diff --git a/drivers/scsi/isci/task.c b/drivers/scsi/isci/task.c
index 5d6fda72d659..3f63c6318b0d 100644
--- a/drivers/scsi/isci/task.c
+++ b/drivers/scsi/isci/task.c
@@ -117,104 +117,97 @@ static inline int isci_device_io_ready(struct isci_remote_device *idev,
117 * functions. This function is called by libsas to send a task down to 117 * functions. This function is called by libsas to send a task down to
118 * hardware. 118 * hardware.
119 * @task: This parameter specifies the SAS task to send. 119 * @task: This parameter specifies the SAS task to send.
120 * @num: This parameter specifies the number of tasks to queue.
121 * @gfp_flags: This parameter specifies the context of this call. 120 * @gfp_flags: This parameter specifies the context of this call.
122 * 121 *
123 * status, zero indicates success. 122 * status, zero indicates success.
124 */ 123 */
125int isci_task_execute_task(struct sas_task *task, int num, gfp_t gfp_flags) 124int isci_task_execute_task(struct sas_task *task, gfp_t gfp_flags)
126{ 125{
127 struct isci_host *ihost = dev_to_ihost(task->dev); 126 struct isci_host *ihost = dev_to_ihost(task->dev);
128 struct isci_remote_device *idev; 127 struct isci_remote_device *idev;
129 unsigned long flags; 128 unsigned long flags;
129 enum sci_status status = SCI_FAILURE;
130 bool io_ready; 130 bool io_ready;
131 u16 tag; 131 u16 tag;
132 132
133 dev_dbg(&ihost->pdev->dev, "%s: num=%d\n", __func__, num); 133 spin_lock_irqsave(&ihost->scic_lock, flags);
134 idev = isci_lookup_device(task->dev);
135 io_ready = isci_device_io_ready(idev, task);
136 tag = isci_alloc_tag(ihost);
137 spin_unlock_irqrestore(&ihost->scic_lock, flags);
134 138
135 for_each_sas_task(num, task) { 139 dev_dbg(&ihost->pdev->dev,
136 enum sci_status status = SCI_FAILURE; 140 "task: %p, dev: %p idev: %p:%#lx cmd = %p\n",
141 task, task->dev, idev, idev ? idev->flags : 0,
142 task->uldd_task);
137 143
138 spin_lock_irqsave(&ihost->scic_lock, flags); 144 if (!idev) {
139 idev = isci_lookup_device(task->dev); 145 isci_task_refuse(ihost, task, SAS_TASK_UNDELIVERED,
140 io_ready = isci_device_io_ready(idev, task); 146 SAS_DEVICE_UNKNOWN);
141 tag = isci_alloc_tag(ihost); 147 } else if (!io_ready || tag == SCI_CONTROLLER_INVALID_IO_TAG) {
142 spin_unlock_irqrestore(&ihost->scic_lock, flags); 148 /* Indicate QUEUE_FULL so that the scsi midlayer
149 * retries.
150 */
151 isci_task_refuse(ihost, task, SAS_TASK_COMPLETE,
152 SAS_QUEUE_FULL);
153 } else {
154 /* There is a device and it's ready for I/O. */
155 spin_lock_irqsave(&task->task_state_lock, flags);
143 156
144 dev_dbg(&ihost->pdev->dev, 157 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) {
145 "task: %p, num: %d dev: %p idev: %p:%#lx cmd = %p\n", 158 /* The I/O was aborted. */
146 task, num, task->dev, idev, idev ? idev->flags : 0, 159 spin_unlock_irqrestore(&task->task_state_lock, flags);
147 task->uldd_task); 160
148 161 isci_task_refuse(ihost, task,
149 if (!idev) { 162 SAS_TASK_UNDELIVERED,
150 isci_task_refuse(ihost, task, SAS_TASK_UNDELIVERED, 163 SAM_STAT_TASK_ABORTED);
151 SAS_DEVICE_UNKNOWN);
152 } else if (!io_ready || tag == SCI_CONTROLLER_INVALID_IO_TAG) {
153 /* Indicate QUEUE_FULL so that the scsi midlayer
154 * retries.
155 */
156 isci_task_refuse(ihost, task, SAS_TASK_COMPLETE,
157 SAS_QUEUE_FULL);
158 } else { 164 } else {
159 /* There is a device and it's ready for I/O. */ 165 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
160 spin_lock_irqsave(&task->task_state_lock, flags); 166 spin_unlock_irqrestore(&task->task_state_lock, flags);
161 167
162 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) { 168 /* build and send the request. */
163 /* The I/O was aborted. */ 169 status = isci_request_execute(ihost, idev, task, tag);
164 spin_unlock_irqrestore(&task->task_state_lock, 170
165 flags); 171 if (status != SCI_SUCCESS) {
166 172 spin_lock_irqsave(&task->task_state_lock, flags);
167 isci_task_refuse(ihost, task, 173 /* Did not really start this command. */
168 SAS_TASK_UNDELIVERED, 174 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
169 SAM_STAT_TASK_ABORTED);
170 } else {
171 task->task_state_flags |= SAS_TASK_AT_INITIATOR;
172 spin_unlock_irqrestore(&task->task_state_lock, flags); 175 spin_unlock_irqrestore(&task->task_state_lock, flags);
173 176
174 /* build and send the request. */ 177 if (test_bit(IDEV_GONE, &idev->flags)) {
175 status = isci_request_execute(ihost, idev, task, tag); 178 /* Indicate that the device
176 179 * is gone.
177 if (status != SCI_SUCCESS) { 180 */
178 181 isci_task_refuse(ihost, task,
179 spin_lock_irqsave(&task->task_state_lock, flags); 182 SAS_TASK_UNDELIVERED,
180 /* Did not really start this command. */ 183 SAS_DEVICE_UNKNOWN);
181 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR; 184 } else {
182 spin_unlock_irqrestore(&task->task_state_lock, flags); 185 /* Indicate QUEUE_FULL so that
183 186 * the scsi midlayer retries.
184 if (test_bit(IDEV_GONE, &idev->flags)) { 187 * If the request failed for
185 188 * remote device reasons, it
186 /* Indicate that the device 189 * gets returned as
187 * is gone. 190 * SAS_TASK_UNDELIVERED next
188 */ 191 * time through.
189 isci_task_refuse(ihost, task, 192 */
190 SAS_TASK_UNDELIVERED, 193 isci_task_refuse(ihost, task,
191 SAS_DEVICE_UNKNOWN); 194 SAS_TASK_COMPLETE,
192 } else { 195 SAS_QUEUE_FULL);
193 /* Indicate QUEUE_FULL so that
194 * the scsi midlayer retries.
195 * If the request failed for
196 * remote device reasons, it
197 * gets returned as
198 * SAS_TASK_UNDELIVERED next
199 * time through.
200 */
201 isci_task_refuse(ihost, task,
202 SAS_TASK_COMPLETE,
203 SAS_QUEUE_FULL);
204 }
205 } 196 }
206 } 197 }
207 } 198 }
208 if (status != SCI_SUCCESS && tag != SCI_CONTROLLER_INVALID_IO_TAG) {
209 spin_lock_irqsave(&ihost->scic_lock, flags);
210 /* command never hit the device, so just free
211 * the tci and skip the sequence increment
212 */
213 isci_tci_free(ihost, ISCI_TAG_TCI(tag));
214 spin_unlock_irqrestore(&ihost->scic_lock, flags);
215 }
216 isci_put_device(idev);
217 } 199 }
200
201 if (status != SCI_SUCCESS && tag != SCI_CONTROLLER_INVALID_IO_TAG) {
202 spin_lock_irqsave(&ihost->scic_lock, flags);
203 /* command never hit the device, so just free
204 * the tci and skip the sequence increment
205 */
206 isci_tci_free(ihost, ISCI_TAG_TCI(tag));
207 spin_unlock_irqrestore(&ihost->scic_lock, flags);
208 }
209
210 isci_put_device(idev);
218 return 0; 211 return 0;
219} 212}
220 213
diff --git a/drivers/scsi/isci/task.h b/drivers/scsi/isci/task.h
index 9c06cbad1d26..8f4531f22ac2 100644
--- a/drivers/scsi/isci/task.h
+++ b/drivers/scsi/isci/task.h
@@ -131,7 +131,6 @@ static inline void isci_print_tmf(struct isci_host *ihost, struct isci_tmf *tmf)
131 131
132int isci_task_execute_task( 132int isci_task_execute_task(
133 struct sas_task *task, 133 struct sas_task *task,
134 int num,
135 gfp_t gfp_flags); 134 gfp_t gfp_flags);
136 135
137int isci_task_abort_task( 136int isci_task_abort_task(
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 427af0f24b0f..0b8af186e707 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -952,7 +952,7 @@ static struct scsi_host_template iscsi_sw_tcp_sht = {
952 .module = THIS_MODULE, 952 .module = THIS_MODULE,
953 .name = "iSCSI Initiator over TCP/IP", 953 .name = "iSCSI Initiator over TCP/IP",
954 .queuecommand = iscsi_queuecommand, 954 .queuecommand = iscsi_queuecommand,
955 .change_queue_depth = iscsi_change_queue_depth, 955 .change_queue_depth = scsi_change_queue_depth,
956 .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1, 956 .can_queue = ISCSI_DEF_XMIT_CMDS_MAX - 1,
957 .sg_tablesize = 4096, 957 .sg_tablesize = 4096,
958 .max_sectors = 0xFFFF, 958 .max_sectors = 0xFFFF,
@@ -966,6 +966,7 @@ static struct scsi_host_template iscsi_sw_tcp_sht = {
966 .target_alloc = iscsi_target_alloc, 966 .target_alloc = iscsi_target_alloc,
967 .proc_name = "iscsi_tcp", 967 .proc_name = "iscsi_tcp",
968 .this_id = -1, 968 .this_id = -1,
969 .track_queue_depth = 1,
969}; 970};
970 971
971static struct iscsi_transport iscsi_sw_tcp_transport = { 972static struct iscsi_transport iscsi_sw_tcp_transport = {
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 1d7e76e8b447..c6795941b45d 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -2160,62 +2160,12 @@ int fc_slave_alloc(struct scsi_device *sdev)
2160 if (!rport || fc_remote_port_chkready(rport)) 2160 if (!rport || fc_remote_port_chkready(rport))
2161 return -ENXIO; 2161 return -ENXIO;
2162 2162
2163 if (sdev->tagged_supported) 2163 scsi_change_queue_depth(sdev, FC_FCP_DFLT_QUEUE_DEPTH);
2164 scsi_activate_tcq(sdev, FC_FCP_DFLT_QUEUE_DEPTH);
2165 else
2166 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev),
2167 FC_FCP_DFLT_QUEUE_DEPTH);
2168
2169 return 0; 2164 return 0;
2170} 2165}
2171EXPORT_SYMBOL(fc_slave_alloc); 2166EXPORT_SYMBOL(fc_slave_alloc);
2172 2167
2173/** 2168/**
2174 * fc_change_queue_depth() - Change a device's queue depth
2175 * @sdev: The SCSI device whose queue depth is to change
2176 * @qdepth: The new queue depth
2177 * @reason: The resason for the change
2178 */
2179int fc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
2180{
2181 switch (reason) {
2182 case SCSI_QDEPTH_DEFAULT:
2183 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
2184 break;
2185 case SCSI_QDEPTH_QFULL:
2186 scsi_track_queue_full(sdev, qdepth);
2187 break;
2188 case SCSI_QDEPTH_RAMP_UP:
2189 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
2190 break;
2191 default:
2192 return -EOPNOTSUPP;
2193 }
2194 return sdev->queue_depth;
2195}
2196EXPORT_SYMBOL(fc_change_queue_depth);
2197
2198/**
2199 * fc_change_queue_type() - Change a device's queue type
2200 * @sdev: The SCSI device whose queue depth is to change
2201 * @tag_type: Identifier for queue type
2202 */
2203int fc_change_queue_type(struct scsi_device *sdev, int tag_type)
2204{
2205 if (sdev->tagged_supported) {
2206 scsi_set_tag_type(sdev, tag_type);
2207 if (tag_type)
2208 scsi_activate_tcq(sdev, sdev->queue_depth);
2209 else
2210 scsi_deactivate_tcq(sdev, sdev->queue_depth);
2211 } else
2212 tag_type = 0;
2213
2214 return tag_type;
2215}
2216EXPORT_SYMBOL(fc_change_queue_type);
2217
2218/**
2219 * fc_fcp_destory() - Tear down the FCP layer for a given local port 2169 * fc_fcp_destory() - Tear down the FCP layer for a given local port
2220 * @lport: The local port that no longer needs the FCP layer 2170 * @lport: The local port that no longer needs the FCP layer
2221 */ 2171 */
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 0d8bc6c66650..8053f24f0349 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -1771,25 +1771,6 @@ fault:
1771} 1771}
1772EXPORT_SYMBOL_GPL(iscsi_queuecommand); 1772EXPORT_SYMBOL_GPL(iscsi_queuecommand);
1773 1773
1774int iscsi_change_queue_depth(struct scsi_device *sdev, int depth, int reason)
1775{
1776 switch (reason) {
1777 case SCSI_QDEPTH_DEFAULT:
1778 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
1779 break;
1780 case SCSI_QDEPTH_QFULL:
1781 scsi_track_queue_full(sdev, depth);
1782 break;
1783 case SCSI_QDEPTH_RAMP_UP:
1784 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
1785 break;
1786 default:
1787 return -EOPNOTSUPP;
1788 }
1789 return sdev->queue_depth;
1790}
1791EXPORT_SYMBOL_GPL(iscsi_change_queue_depth);
1792
1793int iscsi_target_alloc(struct scsi_target *starget) 1774int iscsi_target_alloc(struct scsi_target *starget)
1794{ 1775{
1795 struct iscsi_cls_session *cls_session = starget_to_session(starget); 1776 struct iscsi_cls_session *cls_session = starget_to_session(starget);
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 766098af4eb7..577770fdee86 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -171,7 +171,6 @@ static void sas_ata_task_done(struct sas_task *task)
171 spin_unlock_irqrestore(ap->lock, flags); 171 spin_unlock_irqrestore(ap->lock, flags);
172 172
173qc_already_gone: 173qc_already_gone:
174 list_del_init(&task->list);
175 sas_free_task(task); 174 sas_free_task(task);
176} 175}
177 176
@@ -244,12 +243,7 @@ static unsigned int sas_ata_qc_issue(struct ata_queued_cmd *qc)
244 if (qc->scsicmd) 243 if (qc->scsicmd)
245 ASSIGN_SAS_TASK(qc->scsicmd, task); 244 ASSIGN_SAS_TASK(qc->scsicmd, task);
246 245
247 if (sas_ha->lldd_max_execute_num < 2) 246 ret = i->dft->lldd_execute_task(task, GFP_ATOMIC);
248 ret = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC);
249 else
250 ret = sas_queue_up(task);
251
252 /* Examine */
253 if (ret) { 247 if (ret) {
254 SAS_DPRINTK("lldd_execute_task returned: %d\n", ret); 248 SAS_DPRINTK("lldd_execute_task returned: %d\n", ret);
255 249
@@ -485,7 +479,6 @@ static void sas_ata_internal_abort(struct sas_task *task)
485 479
486 return; 480 return;
487 out: 481 out:
488 list_del_init(&task->list);
489 sas_free_task(task); 482 sas_free_task(task);
490} 483}
491 484
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 0cac7d8fd0f7..022bb6e10d98 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -96,7 +96,7 @@ static int smp_execute_task(struct domain_device *dev, void *req, int req_size,
96 task->slow_task->timer.expires = jiffies + SMP_TIMEOUT*HZ; 96 task->slow_task->timer.expires = jiffies + SMP_TIMEOUT*HZ;
97 add_timer(&task->slow_task->timer); 97 add_timer(&task->slow_task->timer);
98 98
99 res = i->dft->lldd_execute_task(task, 1, GFP_KERNEL); 99 res = i->dft->lldd_execute_task(task, GFP_KERNEL);
100 100
101 if (res) { 101 if (res) {
102 del_timer(&task->slow_task->timer); 102 del_timer(&task->slow_task->timer);
diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c
index dbc8a793fd86..362da44f2948 100644
--- a/drivers/scsi/libsas/sas_init.c
+++ b/drivers/scsi/libsas/sas_init.c
@@ -45,7 +45,6 @@ struct sas_task *sas_alloc_task(gfp_t flags)
45 struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags); 45 struct sas_task *task = kmem_cache_zalloc(sas_task_cache, flags);
46 46
47 if (task) { 47 if (task) {
48 INIT_LIST_HEAD(&task->list);
49 spin_lock_init(&task->task_state_lock); 48 spin_lock_init(&task->task_state_lock);
50 task->task_state_flags = SAS_TASK_STATE_PENDING; 49 task->task_state_flags = SAS_TASK_STATE_PENDING;
51 } 50 }
@@ -77,7 +76,6 @@ EXPORT_SYMBOL_GPL(sas_alloc_slow_task);
77void sas_free_task(struct sas_task *task) 76void sas_free_task(struct sas_task *task)
78{ 77{
79 if (task) { 78 if (task) {
80 BUG_ON(!list_empty(&task->list));
81 kfree(task->slow_task); 79 kfree(task->slow_task);
82 kmem_cache_free(sas_task_cache, task); 80 kmem_cache_free(sas_task_cache, task);
83 } 81 }
@@ -127,11 +125,6 @@ int sas_register_ha(struct sas_ha_struct *sas_ha)
127 spin_lock_init(&sas_ha->phy_port_lock); 125 spin_lock_init(&sas_ha->phy_port_lock);
128 sas_hash_addr(sas_ha->hashed_sas_addr, sas_ha->sas_addr); 126 sas_hash_addr(sas_ha->hashed_sas_addr, sas_ha->sas_addr);
129 127
130 if (sas_ha->lldd_queue_size == 0)
131 sas_ha->lldd_queue_size = 1;
132 else if (sas_ha->lldd_queue_size == -1)
133 sas_ha->lldd_queue_size = 128; /* Sanity */
134
135 set_bit(SAS_HA_REGISTERED, &sas_ha->state); 128 set_bit(SAS_HA_REGISTERED, &sas_ha->state);
136 spin_lock_init(&sas_ha->lock); 129 spin_lock_init(&sas_ha->lock);
137 mutex_init(&sas_ha->drain_mutex); 130 mutex_init(&sas_ha->drain_mutex);
@@ -157,15 +150,6 @@ int sas_register_ha(struct sas_ha_struct *sas_ha)
157 goto Undo_ports; 150 goto Undo_ports;
158 } 151 }
159 152
160 if (sas_ha->lldd_max_execute_num > 1) {
161 error = sas_init_queue(sas_ha);
162 if (error) {
163 printk(KERN_NOTICE "couldn't start queue thread:%d, "
164 "running in direct mode\n", error);
165 sas_ha->lldd_max_execute_num = 1;
166 }
167 }
168
169 INIT_LIST_HEAD(&sas_ha->eh_done_q); 153 INIT_LIST_HEAD(&sas_ha->eh_done_q);
170 INIT_LIST_HEAD(&sas_ha->eh_ata_q); 154 INIT_LIST_HEAD(&sas_ha->eh_ata_q);
171 155
@@ -201,11 +185,6 @@ int sas_unregister_ha(struct sas_ha_struct *sas_ha)
201 __sas_drain_work(sas_ha); 185 __sas_drain_work(sas_ha);
202 mutex_unlock(&sas_ha->drain_mutex); 186 mutex_unlock(&sas_ha->drain_mutex);
203 187
204 if (sas_ha->lldd_max_execute_num > 1) {
205 sas_shutdown_queue(sas_ha);
206 sas_ha->lldd_max_execute_num = 1;
207 }
208
209 return 0; 188 return 0;
210} 189}
211 190
diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h
index 7e7ba83f0a21..9cf0bc260b0e 100644
--- a/drivers/scsi/libsas/sas_internal.h
+++ b/drivers/scsi/libsas/sas_internal.h
@@ -66,9 +66,7 @@ void sas_unregister_ports(struct sas_ha_struct *sas_ha);
66 66
67enum blk_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *); 67enum blk_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *);
68 68
69int sas_init_queue(struct sas_ha_struct *sas_ha);
70int sas_init_events(struct sas_ha_struct *sas_ha); 69int sas_init_events(struct sas_ha_struct *sas_ha);
71void sas_shutdown_queue(struct sas_ha_struct *sas_ha);
72void sas_disable_revalidation(struct sas_ha_struct *ha); 70void sas_disable_revalidation(struct sas_ha_struct *ha);
73void sas_enable_revalidation(struct sas_ha_struct *ha); 71void sas_enable_revalidation(struct sas_ha_struct *ha);
74void __sas_drain_work(struct sas_ha_struct *ha); 72void __sas_drain_work(struct sas_ha_struct *ha);
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 24e477d2ea70..72918d227ead 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -112,7 +112,6 @@ static void sas_end_task(struct scsi_cmnd *sc, struct sas_task *task)
112 112
113 sc->result = (hs << 16) | stat; 113 sc->result = (hs << 16) | stat;
114 ASSIGN_SAS_TASK(sc, NULL); 114 ASSIGN_SAS_TASK(sc, NULL);
115 list_del_init(&task->list);
116 sas_free_task(task); 115 sas_free_task(task);
117} 116}
118 117
@@ -138,7 +137,6 @@ static void sas_scsi_task_done(struct sas_task *task)
138 137
139 if (unlikely(!sc)) { 138 if (unlikely(!sc)) {
140 SAS_DPRINTK("task_done called with non existing SCSI cmnd!\n"); 139 SAS_DPRINTK("task_done called with non existing SCSI cmnd!\n");
141 list_del_init(&task->list);
142 sas_free_task(task); 140 sas_free_task(task);
143 return; 141 return;
144 } 142 }
@@ -179,31 +177,10 @@ static struct sas_task *sas_create_task(struct scsi_cmnd *cmd,
179 return task; 177 return task;
180} 178}
181 179
182int sas_queue_up(struct sas_task *task)
183{
184 struct sas_ha_struct *sas_ha = task->dev->port->ha;
185 struct scsi_core *core = &sas_ha->core;
186 unsigned long flags;
187 LIST_HEAD(list);
188
189 spin_lock_irqsave(&core->task_queue_lock, flags);
190 if (sas_ha->lldd_queue_size < core->task_queue_size + 1) {
191 spin_unlock_irqrestore(&core->task_queue_lock, flags);
192 return -SAS_QUEUE_FULL;
193 }
194 list_add_tail(&task->list, &core->task_queue);
195 core->task_queue_size += 1;
196 spin_unlock_irqrestore(&core->task_queue_lock, flags);
197 wake_up_process(core->queue_thread);
198
199 return 0;
200}
201
202int sas_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd) 180int sas_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
203{ 181{
204 struct sas_internal *i = to_sas_internal(host->transportt); 182 struct sas_internal *i = to_sas_internal(host->transportt);
205 struct domain_device *dev = cmd_to_domain_dev(cmd); 183 struct domain_device *dev = cmd_to_domain_dev(cmd);
206 struct sas_ha_struct *sas_ha = dev->port->ha;
207 struct sas_task *task; 184 struct sas_task *task;
208 int res = 0; 185 int res = 0;
209 186
@@ -224,12 +201,7 @@ int sas_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
224 if (!task) 201 if (!task)
225 return SCSI_MLQUEUE_HOST_BUSY; 202 return SCSI_MLQUEUE_HOST_BUSY;
226 203
227 /* Queue up, Direct Mode or Task Collector Mode. */ 204 res = i->dft->lldd_execute_task(task, GFP_ATOMIC);
228 if (sas_ha->lldd_max_execute_num < 2)
229 res = i->dft->lldd_execute_task(task, 1, GFP_ATOMIC);
230 else
231 res = sas_queue_up(task);
232
233 if (res) 205 if (res)
234 goto out_free_task; 206 goto out_free_task;
235 return 0; 207 return 0;
@@ -323,37 +295,17 @@ enum task_disposition {
323 TASK_IS_DONE, 295 TASK_IS_DONE,
324 TASK_IS_ABORTED, 296 TASK_IS_ABORTED,
325 TASK_IS_AT_LU, 297 TASK_IS_AT_LU,
326 TASK_IS_NOT_AT_HA,
327 TASK_IS_NOT_AT_LU, 298 TASK_IS_NOT_AT_LU,
328 TASK_ABORT_FAILED, 299 TASK_ABORT_FAILED,
329}; 300};
330 301
331static enum task_disposition sas_scsi_find_task(struct sas_task *task) 302static enum task_disposition sas_scsi_find_task(struct sas_task *task)
332{ 303{
333 struct sas_ha_struct *ha = task->dev->port->ha;
334 unsigned long flags; 304 unsigned long flags;
335 int i, res; 305 int i, res;
336 struct sas_internal *si = 306 struct sas_internal *si =
337 to_sas_internal(task->dev->port->ha->core.shost->transportt); 307 to_sas_internal(task->dev->port->ha->core.shost->transportt);
338 308
339 if (ha->lldd_max_execute_num > 1) {
340 struct scsi_core *core = &ha->core;
341 struct sas_task *t, *n;
342
343 mutex_lock(&core->task_queue_flush);
344 spin_lock_irqsave(&core->task_queue_lock, flags);
345 list_for_each_entry_safe(t, n, &core->task_queue, list)
346 if (task == t) {
347 list_del_init(&t->list);
348 break;
349 }
350 spin_unlock_irqrestore(&core->task_queue_lock, flags);
351 mutex_unlock(&core->task_queue_flush);
352
353 if (task == t)
354 return TASK_IS_NOT_AT_HA;
355 }
356
357 for (i = 0; i < 5; i++) { 309 for (i = 0; i < 5; i++) {
358 SAS_DPRINTK("%s: aborting task 0x%p\n", __func__, task); 310 SAS_DPRINTK("%s: aborting task 0x%p\n", __func__, task);
359 res = si->dft->lldd_abort_task(task); 311 res = si->dft->lldd_abort_task(task);
@@ -667,14 +619,6 @@ static void sas_eh_handle_sas_errors(struct Scsi_Host *shost, struct list_head *
667 cmd->eh_eflags = 0; 619 cmd->eh_eflags = 0;
668 620
669 switch (res) { 621 switch (res) {
670 case TASK_IS_NOT_AT_HA:
671 SAS_DPRINTK("%s: task 0x%p is not at ha: %s\n",
672 __func__, task,
673 cmd->retries ? "retry" : "aborted");
674 if (cmd->retries)
675 cmd->retries--;
676 sas_eh_finish_cmd(cmd);
677 continue;
678 case TASK_IS_DONE: 622 case TASK_IS_DONE:
679 SAS_DPRINTK("%s: task 0x%p is done\n", __func__, 623 SAS_DPRINTK("%s: task 0x%p is done\n", __func__,
680 task); 624 task);
@@ -836,9 +780,6 @@ retry:
836 scsi_eh_ready_devs(shost, &eh_work_q, &ha->eh_done_q); 780 scsi_eh_ready_devs(shost, &eh_work_q, &ha->eh_done_q);
837 781
838out: 782out:
839 if (ha->lldd_max_execute_num > 1)
840 wake_up_process(ha->core.queue_thread);
841
842 sas_eh_handle_resets(shost); 783 sas_eh_handle_resets(shost);
843 784
844 /* now link into libata eh --- if we have any ata devices */ 785 /* now link into libata eh --- if we have any ata devices */
@@ -940,15 +881,12 @@ int sas_slave_configure(struct scsi_device *scsi_dev)
940 sas_read_port_mode_page(scsi_dev); 881 sas_read_port_mode_page(scsi_dev);
941 882
942 if (scsi_dev->tagged_supported) { 883 if (scsi_dev->tagged_supported) {
943 scsi_set_tag_type(scsi_dev, MSG_SIMPLE_TAG); 884 scsi_change_queue_depth(scsi_dev, SAS_DEF_QD);
944 scsi_activate_tcq(scsi_dev, SAS_DEF_QD);
945 } else { 885 } else {
946 SAS_DPRINTK("device %llx, LUN %llx doesn't support " 886 SAS_DPRINTK("device %llx, LUN %llx doesn't support "
947 "TCQ\n", SAS_ADDR(dev->sas_addr), 887 "TCQ\n", SAS_ADDR(dev->sas_addr),
948 scsi_dev->lun); 888 scsi_dev->lun);
949 scsi_dev->tagged_supported = 0; 889 scsi_change_queue_depth(scsi_dev, 1);
950 scsi_set_tag_type(scsi_dev, 0);
951 scsi_deactivate_tcq(scsi_dev, 1);
952 } 890 }
953 891
954 scsi_dev->allow_restart = 1; 892 scsi_dev->allow_restart = 1;
@@ -956,47 +894,23 @@ int sas_slave_configure(struct scsi_device *scsi_dev)
956 return 0; 894 return 0;
957} 895}
958 896
959int sas_change_queue_depth(struct scsi_device *sdev, int depth, int reason) 897int sas_change_queue_depth(struct scsi_device *sdev, int depth)
960{ 898{
961 struct domain_device *dev = sdev_to_domain_dev(sdev); 899 struct domain_device *dev = sdev_to_domain_dev(sdev);
962 900
963 if (dev_is_sata(dev)) 901 if (dev_is_sata(dev))
964 return __ata_change_queue_depth(dev->sata_dev.ap, sdev, depth, 902 return __ata_change_queue_depth(dev->sata_dev.ap, sdev, depth);
965 reason);
966
967 switch (reason) {
968 case SCSI_QDEPTH_DEFAULT:
969 case SCSI_QDEPTH_RAMP_UP:
970 if (!sdev->tagged_supported)
971 depth = 1;
972 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
973 break;
974 case SCSI_QDEPTH_QFULL:
975 scsi_track_queue_full(sdev, depth);
976 break;
977 default:
978 return -EOPNOTSUPP;
979 }
980 903
981 return depth; 904 if (!sdev->tagged_supported)
905 depth = 1;
906 return scsi_change_queue_depth(sdev, depth);
982} 907}
983 908
984int sas_change_queue_type(struct scsi_device *scsi_dev, int qt) 909int sas_change_queue_type(struct scsi_device *scsi_dev, int type)
985{ 910{
986 struct domain_device *dev = sdev_to_domain_dev(scsi_dev); 911 if (dev_is_sata(sdev_to_domain_dev(scsi_dev)))
987
988 if (dev_is_sata(dev))
989 return -EINVAL; 912 return -EINVAL;
990 913 return scsi_change_queue_type(scsi_dev, type);
991 if (!scsi_dev->tagged_supported)
992 return 0;
993
994 scsi_deactivate_tcq(scsi_dev, 1);
995
996 scsi_set_tag_type(scsi_dev, qt);
997 scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth);
998
999 return qt;
1000} 914}
1001 915
1002int sas_bios_param(struct scsi_device *scsi_dev, 916int sas_bios_param(struct scsi_device *scsi_dev,
@@ -1011,121 +925,6 @@ int sas_bios_param(struct scsi_device *scsi_dev,
1011 return 0; 925 return 0;
1012} 926}
1013 927
1014/* ---------- Task Collector Thread implementation ---------- */
1015
1016static void sas_queue(struct sas_ha_struct *sas_ha)
1017{
1018 struct scsi_core *core = &sas_ha->core;
1019 unsigned long flags;
1020 LIST_HEAD(q);
1021 int can_queue;
1022 int res;
1023 struct sas_internal *i = to_sas_internal(core->shost->transportt);
1024
1025 mutex_lock(&core->task_queue_flush);
1026 spin_lock_irqsave(&core->task_queue_lock, flags);
1027 while (!kthread_should_stop() &&
1028 !list_empty(&core->task_queue) &&
1029 !test_bit(SAS_HA_FROZEN, &sas_ha->state)) {
1030
1031 can_queue = sas_ha->lldd_queue_size - core->task_queue_size;
1032 if (can_queue >= 0) {
1033 can_queue = core->task_queue_size;
1034 list_splice_init(&core->task_queue, &q);
1035 } else {
1036 struct list_head *a, *n;
1037
1038 can_queue = sas_ha->lldd_queue_size;
1039 list_for_each_safe(a, n, &core->task_queue) {
1040 list_move_tail(a, &q);
1041 if (--can_queue == 0)
1042 break;
1043 }
1044 can_queue = sas_ha->lldd_queue_size;
1045 }
1046 core->task_queue_size -= can_queue;
1047 spin_unlock_irqrestore(&core->task_queue_lock, flags);
1048 {
1049 struct sas_task *task = list_entry(q.next,
1050 struct sas_task,
1051 list);
1052 list_del_init(&q);
1053 res = i->dft->lldd_execute_task(task, can_queue,
1054 GFP_KERNEL);
1055 if (unlikely(res))
1056 __list_add(&q, task->list.prev, &task->list);
1057 }
1058 spin_lock_irqsave(&core->task_queue_lock, flags);
1059 if (res) {
1060 list_splice_init(&q, &core->task_queue); /*at head*/
1061 core->task_queue_size += can_queue;
1062 }
1063 }
1064 spin_unlock_irqrestore(&core->task_queue_lock, flags);
1065 mutex_unlock(&core->task_queue_flush);
1066}
1067
1068/**
1069 * sas_queue_thread -- The Task Collector thread
1070 * @_sas_ha: pointer to struct sas_ha
1071 */
1072static int sas_queue_thread(void *_sas_ha)
1073{
1074 struct sas_ha_struct *sas_ha = _sas_ha;
1075
1076 while (1) {
1077 set_current_state(TASK_INTERRUPTIBLE);
1078 schedule();
1079 sas_queue(sas_ha);
1080 if (kthread_should_stop())
1081 break;
1082 }
1083
1084 return 0;
1085}
1086
1087int sas_init_queue(struct sas_ha_struct *sas_ha)
1088{
1089 struct scsi_core *core = &sas_ha->core;
1090
1091 spin_lock_init(&core->task_queue_lock);
1092 mutex_init(&core->task_queue_flush);
1093 core->task_queue_size = 0;
1094 INIT_LIST_HEAD(&core->task_queue);
1095
1096 core->queue_thread = kthread_run(sas_queue_thread, sas_ha,
1097 "sas_queue_%d", core->shost->host_no);
1098 if (IS_ERR(core->queue_thread))
1099 return PTR_ERR(core->queue_thread);
1100 return 0;
1101}
1102
1103void sas_shutdown_queue(struct sas_ha_struct *sas_ha)
1104{
1105 unsigned long flags;
1106 struct scsi_core *core = &sas_ha->core;
1107 struct sas_task *task, *n;
1108
1109 kthread_stop(core->queue_thread);
1110
1111 if (!list_empty(&core->task_queue))
1112 SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n",
1113 SAS_ADDR(sas_ha->sas_addr));
1114
1115 spin_lock_irqsave(&core->task_queue_lock, flags);
1116 list_for_each_entry_safe(task, n, &core->task_queue, list) {
1117 struct scsi_cmnd *cmd = task->uldd_task;
1118
1119 list_del_init(&task->list);
1120
1121 ASSIGN_SAS_TASK(cmd, NULL);
1122 sas_free_task(task);
1123 cmd->result = DID_ABORT << 16;
1124 cmd->scsi_done(cmd);
1125 }
1126 spin_unlock_irqrestore(&core->task_queue_lock, flags);
1127}
1128
1129/* 928/*
1130 * Tell an upper layer that it needs to initiate an abort for a given task. 929 * Tell an upper layer that it needs to initiate an abort for a given task.
1131 * This should only ever be called by an LLDD. 930 * This should only ever be called by an LLDD.
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index b99399fe2548..fd85952b621d 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -243,128 +243,6 @@ lpfc_update_stats(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
243} 243}
244 244
245/** 245/**
246 * lpfc_send_sdev_queuedepth_change_event - Posts a queuedepth change event
247 * @phba: Pointer to HBA context object.
248 * @vport: Pointer to vport object.
249 * @ndlp: Pointer to FC node associated with the target.
250 * @lun: Lun number of the scsi device.
251 * @old_val: Old value of the queue depth.
252 * @new_val: New value of the queue depth.
253 *
254 * This function sends an event to the mgmt application indicating
255 * there is a change in the scsi device queue depth.
256 **/
257static void
258lpfc_send_sdev_queuedepth_change_event(struct lpfc_hba *phba,
259 struct lpfc_vport *vport,
260 struct lpfc_nodelist *ndlp,
261 uint64_t lun,
262 uint32_t old_val,
263 uint32_t new_val)
264{
265 struct lpfc_fast_path_event *fast_path_evt;
266 unsigned long flags;
267
268 fast_path_evt = lpfc_alloc_fast_evt(phba);
269 if (!fast_path_evt)
270 return;
271
272 fast_path_evt->un.queue_depth_evt.scsi_event.event_type =
273 FC_REG_SCSI_EVENT;
274 fast_path_evt->un.queue_depth_evt.scsi_event.subcategory =
275 LPFC_EVENT_VARQUEDEPTH;
276
277 /* Report all luns with change in queue depth */
278 fast_path_evt->un.queue_depth_evt.scsi_event.lun = lun;
279 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
280 memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwpn,
281 &ndlp->nlp_portname, sizeof(struct lpfc_name));
282 memcpy(&fast_path_evt->un.queue_depth_evt.scsi_event.wwnn,
283 &ndlp->nlp_nodename, sizeof(struct lpfc_name));
284 }
285
286 fast_path_evt->un.queue_depth_evt.oldval = old_val;
287 fast_path_evt->un.queue_depth_evt.newval = new_val;
288 fast_path_evt->vport = vport;
289
290 fast_path_evt->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
291 spin_lock_irqsave(&phba->hbalock, flags);
292 list_add_tail(&fast_path_evt->work_evt.evt_listp, &phba->work_list);
293 spin_unlock_irqrestore(&phba->hbalock, flags);
294 lpfc_worker_wake_up(phba);
295
296 return;
297}
298
299/**
300 * lpfc_change_queue_depth - Alter scsi device queue depth
301 * @sdev: Pointer the scsi device on which to change the queue depth.
302 * @qdepth: New queue depth to set the sdev to.
303 * @reason: The reason for the queue depth change.
304 *
305 * This function is called by the midlayer and the LLD to alter the queue
306 * depth for a scsi device. This function sets the queue depth to the new
307 * value and sends an event out to log the queue depth change.
308 **/
309static int
310lpfc_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
311{
312 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
313 struct lpfc_hba *phba = vport->phba;
314 struct lpfc_rport_data *rdata;
315 unsigned long new_queue_depth, old_queue_depth;
316
317 old_queue_depth = sdev->queue_depth;
318
319 switch (reason) {
320 case SCSI_QDEPTH_DEFAULT:
321 /* change request from sysfs, fall through */
322 case SCSI_QDEPTH_RAMP_UP:
323 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
324 break;
325 case SCSI_QDEPTH_QFULL:
326 if (scsi_track_queue_full(sdev, qdepth) == 0)
327 return sdev->queue_depth;
328
329 lpfc_printf_vlog(vport, KERN_WARNING, LOG_FCP,
330 "0711 detected queue full - lun queue "
331 "depth adjusted to %d.\n", sdev->queue_depth);
332 break;
333 default:
334 return -EOPNOTSUPP;
335 }
336
337 new_queue_depth = sdev->queue_depth;
338 rdata = lpfc_rport_data_from_scsi_device(sdev);
339 if (rdata)
340 lpfc_send_sdev_queuedepth_change_event(phba, vport,
341 rdata->pnode, sdev->lun,
342 old_queue_depth,
343 new_queue_depth);
344 return sdev->queue_depth;
345}
346
347/**
348 * lpfc_change_queue_type() - Change a device's scsi tag queuing type
349 * @sdev: Pointer the scsi device whose queue depth is to change
350 * @tag_type: Identifier for queue tag type
351 */
352static int
353lpfc_change_queue_type(struct scsi_device *sdev, int tag_type)
354{
355 if (sdev->tagged_supported) {
356 scsi_set_tag_type(sdev, tag_type);
357 if (tag_type)
358 scsi_activate_tcq(sdev, sdev->queue_depth);
359 else
360 scsi_deactivate_tcq(sdev, sdev->queue_depth);
361 } else
362 tag_type = 0;
363
364 return tag_type;
365}
366
367/**
368 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread 246 * lpfc_rampdown_queue_depth - Post RAMP_DOWN_QUEUE event to worker thread
369 * @phba: The Hba for which this call is being executed. 247 * @phba: The Hba for which this call is being executed.
370 * 248 *
@@ -449,8 +327,7 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
449 else 327 else
450 new_queue_depth = sdev->queue_depth - 328 new_queue_depth = sdev->queue_depth -
451 new_queue_depth; 329 new_queue_depth;
452 lpfc_change_queue_depth(sdev, new_queue_depth, 330 scsi_change_queue_depth(sdev, new_queue_depth);
453 SCSI_QDEPTH_DEFAULT);
454 } 331 }
455 } 332 }
456 lpfc_destroy_vport_work_array(phba, vports); 333 lpfc_destroy_vport_work_array(phba, vports);
@@ -4286,7 +4163,6 @@ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
4286 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb; 4163 IOCB_t *iocb_cmd = &lpfc_cmd->cur_iocbq.iocb;
4287 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq); 4164 struct lpfc_iocbq *piocbq = &(lpfc_cmd->cur_iocbq);
4288 int datadir = scsi_cmnd->sc_data_direction; 4165 int datadir = scsi_cmnd->sc_data_direction;
4289 char tag[2];
4290 uint8_t *ptr; 4166 uint8_t *ptr;
4291 bool sli4; 4167 bool sli4;
4292 uint32_t fcpdl; 4168 uint32_t fcpdl;
@@ -4308,20 +4184,7 @@ lpfc_scsi_prep_cmnd(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
4308 memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len)); 4184 memset(ptr, 0, (LPFC_FCP_CDB_LEN - scsi_cmnd->cmd_len));
4309 } 4185 }
4310 4186
4311 if (scsi_populate_tag_msg(scsi_cmnd, tag)) { 4187 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
4312 switch (tag[0]) {
4313 case HEAD_OF_QUEUE_TAG:
4314 fcp_cmnd->fcpCntl1 = HEAD_OF_Q;
4315 break;
4316 case ORDERED_QUEUE_TAG:
4317 fcp_cmnd->fcpCntl1 = ORDERED_Q;
4318 break;
4319 default:
4320 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
4321 break;
4322 }
4323 } else
4324 fcp_cmnd->fcpCntl1 = SIMPLE_Q;
4325 4188
4326 sli4 = (phba->sli_rev == LPFC_SLI_REV4); 4189 sli4 = (phba->sli_rev == LPFC_SLI_REV4);
4327 piocbq->iocb.un.fcpi.fcpi_XRdy = 0; 4190 piocbq->iocb.un.fcpi.fcpi_XRdy = 0;
@@ -5632,10 +5495,7 @@ lpfc_slave_configure(struct scsi_device *sdev)
5632 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata; 5495 struct lpfc_vport *vport = (struct lpfc_vport *) sdev->host->hostdata;
5633 struct lpfc_hba *phba = vport->phba; 5496 struct lpfc_hba *phba = vport->phba;
5634 5497
5635 if (sdev->tagged_supported) 5498 scsi_change_queue_depth(sdev, vport->cfg_lun_queue_depth);
5636 scsi_activate_tcq(sdev, vport->cfg_lun_queue_depth);
5637 else
5638 scsi_deactivate_tcq(sdev, vport->cfg_lun_queue_depth);
5639 5499
5640 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { 5500 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
5641 lpfc_sli_handle_fast_ring_event(phba, 5501 lpfc_sli_handle_fast_ring_event(phba,
@@ -6018,8 +5878,10 @@ struct scsi_host_template lpfc_template = {
6018 .shost_attrs = lpfc_hba_attrs, 5878 .shost_attrs = lpfc_hba_attrs,
6019 .max_sectors = 0xFFFF, 5879 .max_sectors = 0xFFFF,
6020 .vendor_id = LPFC_NL_VENDOR_ID, 5880 .vendor_id = LPFC_NL_VENDOR_ID,
6021 .change_queue_depth = lpfc_change_queue_depth, 5881 .change_queue_depth = scsi_change_queue_depth,
6022 .change_queue_type = lpfc_change_queue_type, 5882 .change_queue_type = scsi_change_queue_type,
5883 .use_blk_tags = 1,
5884 .track_queue_depth = 1,
6023}; 5885};
6024 5886
6025struct scsi_host_template lpfc_vport_template = { 5887struct scsi_host_template lpfc_vport_template = {
@@ -6041,6 +5903,8 @@ struct scsi_host_template lpfc_vport_template = {
6041 .use_clustering = ENABLE_CLUSTERING, 5903 .use_clustering = ENABLE_CLUSTERING,
6042 .shost_attrs = lpfc_vport_attrs, 5904 .shost_attrs = lpfc_vport_attrs,
6043 .max_sectors = 0xFFFF, 5905 .max_sectors = 0xFFFF,
6044 .change_queue_depth = lpfc_change_queue_depth, 5906 .change_queue_depth = scsi_change_queue_depth,
6045 .change_queue_type = lpfc_change_queue_type, 5907 .change_queue_type = scsi_change_queue_type,
5908 .use_blk_tags = 1,
5909 .track_queue_depth = 1,
6046}; 5910};
diff --git a/drivers/scsi/mac_scsi.c b/drivers/scsi/mac_scsi.c
index 6a039eb1cbce..953fd9b953c7 100644
--- a/drivers/scsi/mac_scsi.c
+++ b/drivers/scsi/mac_scsi.c
@@ -9,69 +9,62 @@
9 * Generic Generic NCR5380 driver 9 * Generic Generic NCR5380 driver
10 * 10 *
11 * Copyright 1995, Russell King 11 * Copyright 1995, Russell King
12 *
13 * ALPHA RELEASE 1.
14 *
15 * For more information, please consult
16 *
17 * NCR 5380 Family
18 * SCSI Protocol Controller
19 * Databook
20 *
21 * NCR Microelectronics
22 * 1635 Aeroplaza Drive
23 * Colorado Springs, CO 80916
24 * 1+ (719) 578-3400
25 * 1+ (800) 334-5454
26 */ 12 */
27 13
28#include <linux/types.h> 14#include <linux/types.h>
29#include <linux/stddef.h>
30#include <linux/ctype.h>
31#include <linux/delay.h> 15#include <linux/delay.h>
32
33#include <linux/module.h> 16#include <linux/module.h>
34#include <linux/signal.h>
35#include <linux/ioport.h> 17#include <linux/ioport.h>
36#include <linux/init.h> 18#include <linux/init.h>
37#include <linux/blkdev.h> 19#include <linux/blkdev.h>
38#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/platform_device.h>
39 22
23#include <asm/hwtest.h>
40#include <asm/io.h> 24#include <asm/io.h>
41#include <asm/irq.h>
42
43#include <asm/macintosh.h>
44#include <asm/macints.h> 25#include <asm/macints.h>
45#include <asm/mac_via.h> 26#include <asm/setup.h>
46 27
47#include "scsi.h"
48#include <scsi/scsi_host.h> 28#include <scsi/scsi_host.h>
49#include "mac_scsi.h"
50 29
51/* These control the behaviour of the generic 5380 core */ 30/* Definitions for the core NCR5380 driver. */
52#define AUTOSENSE 31
53#define PSEUDO_DMA 32#define PSEUDO_DMA
54 33
55#include "NCR5380.h" 34#define NCR5380_implementation_fields unsigned char *pdma_base
35#define NCR5380_local_declare() struct Scsi_Host *_instance
36#define NCR5380_setup(instance) _instance = instance
56 37
57#define RESET_BOOT 38#define NCR5380_read(reg) macscsi_read(_instance, reg)
58#define DRIVER_SETUP 39#define NCR5380_write(reg, value) macscsi_write(_instance, reg, value)
59 40
60extern void via_scsi_clear(void); 41#define NCR5380_pread macscsi_pread
42#define NCR5380_pwrite macscsi_pwrite
61 43
62#ifdef RESET_BOOT 44#define NCR5380_intr macscsi_intr
63static void mac_scsi_reset_boot(struct Scsi_Host *instance); 45#define NCR5380_queue_command macscsi_queue_command
64#endif 46#define NCR5380_abort macscsi_abort
47#define NCR5380_bus_reset macscsi_bus_reset
48#define NCR5380_info macscsi_info
49#define NCR5380_show_info macscsi_show_info
50#define NCR5380_write_info macscsi_write_info
51
52#include "NCR5380.h"
53
54#define RESET_BOOT
65 55
66static int setup_called = 0;
67static int setup_can_queue = -1; 56static int setup_can_queue = -1;
57module_param(setup_can_queue, int, 0);
68static int setup_cmd_per_lun = -1; 58static int setup_cmd_per_lun = -1;
59module_param(setup_cmd_per_lun, int, 0);
69static int setup_sg_tablesize = -1; 60static int setup_sg_tablesize = -1;
61module_param(setup_sg_tablesize, int, 0);
70static int setup_use_pdma = -1; 62static int setup_use_pdma = -1;
71#ifdef SUPPORT_TAGS 63module_param(setup_use_pdma, int, 0);
72static int setup_use_tagged_queuing = -1; 64static int setup_use_tagged_queuing = -1;
73#endif 65module_param(setup_use_tagged_queuing, int, 0);
74static int setup_hostid = -1; 66static int setup_hostid = -1;
67module_param(setup_hostid, int, 0);
75 68
76/* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms, 69/* Time (in jiffies) to wait after a reset; the SCSI standard calls for 250ms,
77 * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more 70 * we usually do 0.5s to be on the safe side. But Toshiba CD-ROMs once more
@@ -84,232 +77,48 @@ static int setup_hostid = -1;
84#define AFTER_RESET_DELAY (HZ/2) 77#define AFTER_RESET_DELAY (HZ/2)
85#endif 78#endif
86 79
87static volatile unsigned char *mac_scsi_regp = NULL;
88static volatile unsigned char *mac_scsi_drq = NULL;
89static volatile unsigned char *mac_scsi_nodrq = NULL;
90
91
92/* 80/*
93 * NCR 5380 register access functions 81 * NCR 5380 register access functions
94 */ 82 */
95 83
96#if 0 84static inline char macscsi_read(struct Scsi_Host *instance, int reg)
97/* Debug versions */
98#define CTRL(p,v) (*ctrl = (v))
99
100static char macscsi_read(struct Scsi_Host *instance, int reg)
101{ 85{
102 int iobase = instance->io_port; 86 return in_8(instance->base + (reg << 4));
103 int i;
104 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
105
106 CTRL(iobase, 0);
107 i = in_8(iobase + (reg<<4));
108 CTRL(iobase, 0x40);
109
110 return i;
111} 87}
112 88
113static void macscsi_write(struct Scsi_Host *instance, int reg, int value) 89static inline void macscsi_write(struct Scsi_Host *instance, int reg, int value)
114{
115 int iobase = instance->io_port;
116 int *ctrl = &((struct NCR5380_hostdata *)instance->hostdata)->ctrl;
117
118 CTRL(iobase, 0);
119 out_8(iobase + (reg<<4), value);
120 CTRL(iobase, 0x40);
121}
122#else
123
124/* Fast versions */
125static __inline__ char macscsi_read(struct Scsi_Host *instance, int reg)
126{ 90{
127 return in_8(instance->io_port + (reg<<4)); 91 out_8(instance->base + (reg << 4), value);
128} 92}
129 93
130static __inline__ void macscsi_write(struct Scsi_Host *instance, int reg, int value) 94#ifndef MODULE
95static int __init mac_scsi_setup(char *str)
131{ 96{
132 out_8(instance->io_port + (reg<<4), value); 97 int ints[7];
133}
134#endif
135
136 98
137/* 99 (void)get_options(str, ARRAY_SIZE(ints), ints);
138 * Function : mac_scsi_setup(char *str)
139 *
140 * Purpose : booter command line initialization of the overrides array,
141 *
142 * Inputs : str - comma delimited list of options
143 *
144 */
145 100
146static int __init mac_scsi_setup(char *str) { 101 if (ints[0] < 1 || ints[0] > 6) {
147#ifdef DRIVER_SETUP 102 pr_err("Usage: mac5380=<can_queue>[,<cmd_per_lun>[,<sg_tablesize>[,<hostid>[,<use_tags>[,<use_pdma>]]]]]\n");
148 int ints[7]; 103 return 0;
149
150 (void)get_options( str, ARRAY_SIZE(ints), ints);
151
152 if (setup_called++ || ints[0] < 1 || ints[0] > 6) {
153 printk(KERN_WARNING "scsi: <mac5380>"
154 " Usage: mac5380=<can_queue>[,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>,<use_pdma>]\n");
155 printk(KERN_ALERT "scsi: <mac5380> Bad Penguin parameters?\n");
156 return 0;
157 }
158
159 if (ints[0] >= 1) {
160 if (ints[1] > 0)
161 /* no limits on this, just > 0 */
162 setup_can_queue = ints[1];
163 }
164 if (ints[0] >= 2) {
165 if (ints[2] > 0)
166 setup_cmd_per_lun = ints[2];
167 }
168 if (ints[0] >= 3) {
169 if (ints[3] >= 0) {
170 setup_sg_tablesize = ints[3];
171 /* Must be <= SG_ALL (255) */
172 if (setup_sg_tablesize > SG_ALL)
173 setup_sg_tablesize = SG_ALL;
174 }
175 }
176 if (ints[0] >= 4) {
177 /* Must be between 0 and 7 */
178 if (ints[4] >= 0 && ints[4] <= 7)
179 setup_hostid = ints[4];
180 else if (ints[4] > 7)
181 printk(KERN_WARNING "mac_scsi_setup: invalid host ID %d !\n", ints[4] );
182 }
183#ifdef SUPPORT_TAGS
184 if (ints[0] >= 5) {
185 if (ints[5] >= 0)
186 setup_use_tagged_queuing = !!ints[5];
187 } 104 }
188 105 if (ints[0] >= 1)
189 if (ints[0] == 6) { 106 setup_can_queue = ints[1];
190 if (ints[6] >= 0) 107 if (ints[0] >= 2)
108 setup_cmd_per_lun = ints[2];
109 if (ints[0] >= 3)
110 setup_sg_tablesize = ints[3];
111 if (ints[0] >= 4)
112 setup_hostid = ints[4];
113 if (ints[0] >= 5)
114 setup_use_tagged_queuing = ints[5];
115 if (ints[0] >= 6)
191 setup_use_pdma = ints[6]; 116 setup_use_pdma = ints[6];
192 }
193#else
194 if (ints[0] == 5) {
195 if (ints[5] >= 0)
196 setup_use_pdma = ints[5];
197 }
198#endif /* SUPPORT_TAGS */
199
200#endif /* DRIVER_SETUP */
201 return 1; 117 return 1;
202} 118}
203 119
204__setup("mac5380=", mac_scsi_setup); 120__setup("mac5380=", mac_scsi_setup);
205 121#endif /* !MODULE */
206/*
207 * Function : int macscsi_detect(struct scsi_host_template * tpnt)
208 *
209 * Purpose : initializes mac NCR5380 driver based on the
210 * command line / compile time port and irq definitions.
211 *
212 * Inputs : tpnt - template for this SCSI adapter.
213 *
214 * Returns : 1 if a host adapter was found, 0 if not.
215 *
216 */
217
218int __init macscsi_detect(struct scsi_host_template * tpnt)
219{
220 static int called = 0;
221 int flags = 0;
222 struct Scsi_Host *instance;
223
224 if (!MACH_IS_MAC || called)
225 return( 0 );
226
227 if (macintosh_config->scsi_type != MAC_SCSI_OLD)
228 return( 0 );
229
230 /* setup variables */
231 tpnt->can_queue =
232 (setup_can_queue > 0) ? setup_can_queue : CAN_QUEUE;
233 tpnt->cmd_per_lun =
234 (setup_cmd_per_lun > 0) ? setup_cmd_per_lun : CMD_PER_LUN;
235 tpnt->sg_tablesize =
236 (setup_sg_tablesize >= 0) ? setup_sg_tablesize : SG_TABLESIZE;
237
238 if (setup_hostid >= 0)
239 tpnt->this_id = setup_hostid;
240 else {
241 /* use 7 as default */
242 tpnt->this_id = 7;
243 }
244
245#ifdef SUPPORT_TAGS
246 if (setup_use_tagged_queuing < 0)
247 setup_use_tagged_queuing = USE_TAGGED_QUEUING;
248#endif
249
250 /* Once we support multiple 5380s (e.g. DuoDock) we'll do
251 something different here */
252 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
253 if (instance == NULL)
254 return 0;
255
256 if (macintosh_config->ident == MAC_MODEL_IIFX) {
257 mac_scsi_regp = via1+0x8000;
258 mac_scsi_drq = via1+0xE000;
259 mac_scsi_nodrq = via1+0xC000;
260 /* The IIFX should be able to do true DMA, but pseudo-dma doesn't work */
261 flags = FLAG_NO_PSEUDO_DMA;
262 } else {
263 mac_scsi_regp = via1+0x10000;
264 mac_scsi_drq = via1+0x6000;
265 mac_scsi_nodrq = via1+0x12000;
266 }
267
268 if (! setup_use_pdma)
269 flags = FLAG_NO_PSEUDO_DMA;
270
271 instance->io_port = (unsigned long) mac_scsi_regp;
272 instance->irq = IRQ_MAC_SCSI;
273
274#ifdef RESET_BOOT
275 mac_scsi_reset_boot(instance);
276#endif
277
278 NCR5380_init(instance, flags);
279
280 instance->n_io_port = 255;
281
282 ((struct NCR5380_hostdata *)instance->hostdata)->ctrl = 0;
283
284 if (instance->irq != SCSI_IRQ_NONE)
285 if (request_irq(instance->irq, NCR5380_intr, 0, "ncr5380", instance)) {
286 printk(KERN_WARNING "scsi%d: IRQ%d not free, interrupts disabled\n",
287 instance->host_no, instance->irq);
288 instance->irq = SCSI_IRQ_NONE;
289 }
290
291 printk(KERN_INFO "scsi%d: generic 5380 at port %lX irq", instance->host_no, instance->io_port);
292 if (instance->irq == SCSI_IRQ_NONE)
293 printk (KERN_INFO "s disabled");
294 else
295 printk (KERN_INFO " %d", instance->irq);
296 printk(KERN_INFO " options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
297 instance->can_queue, instance->cmd_per_lun, MACSCSI_PUBLIC_RELEASE);
298 printk(KERN_INFO "\nscsi%d:", instance->host_no);
299 NCR5380_print_options(instance);
300 printk("\n");
301 called = 1;
302 return 1;
303}
304
305int macscsi_release (struct Scsi_Host *shpnt)
306{
307 if (shpnt->irq != SCSI_IRQ_NONE)
308 free_irq(shpnt->irq, shpnt);
309 NCR5380_exit(shpnt);
310
311 return 0;
312}
313 122
314#ifdef RESET_BOOT 123#ifdef RESET_BOOT
315/* 124/*
@@ -349,10 +158,7 @@ static void mac_scsi_reset_boot(struct Scsi_Host *instance)
349} 158}
350#endif 159#endif
351 160
352const char * macscsi_info (struct Scsi_Host *spnt) { 161#ifdef PSEUDO_DMA
353 return "";
354}
355
356/* 162/*
357 Pseudo-DMA: (Ove Edlund) 163 Pseudo-DMA: (Ove Edlund)
358 The code attempts to catch bus errors that occur if one for example 164 The code attempts to catch bus errors that occur if one for example
@@ -422,38 +228,39 @@ __asm__ __volatile__ \
422 : "0"(s), "1"(d), "2"(len) \ 228 : "0"(s), "1"(d), "2"(len) \
423 : "d0") 229 : "d0")
424 230
425 231static int macscsi_pread(struct Scsi_Host *instance,
426static int macscsi_pread (struct Scsi_Host *instance, 232 unsigned char *dst, int len)
427 unsigned char *dst, int len)
428{ 233{
429 unsigned char *d; 234 struct NCR5380_hostdata *hostdata = shost_priv(instance);
430 volatile unsigned char *s; 235 unsigned char *d;
431 236 unsigned char *s;
432 NCR5380_local_declare(); 237
433 NCR5380_setup(instance); 238 NCR5380_local_declare();
434 239 NCR5380_setup(instance);
435 s = mac_scsi_drq+0x60; 240
436 d = dst; 241 s = hostdata->pdma_base + (INPUT_DATA_REG << 4);
437 242 d = dst;
438/* These conditions are derived from MacOS */ 243
439 244 /* These conditions are derived from MacOS */
440 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) 245
441 && !(NCR5380_read(STATUS_REG) & SR_REQ)) 246 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) &&
442 ; 247 !(NCR5380_read(STATUS_REG) & SR_REQ))
443 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) 248 ;
444 && (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) { 249
445 printk(KERN_ERR "Error in macscsi_pread\n"); 250 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) &&
446 return -1; 251 (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)) {
447 } 252 pr_err("Error in macscsi_pread\n");
448 253 return -1;
449 CP_IO_TO_MEM(s, d, len); 254 }
450 255
451 if (len != 0) { 256 CP_IO_TO_MEM(s, d, len);
452 printk(KERN_NOTICE "Bus error in macscsi_pread\n"); 257
453 return -1; 258 if (len != 0) {
454 } 259 pr_notice("Bus error in macscsi_pread\n");
455 260 return -1;
456 return 0; 261 }
262
263 return 0;
457} 264}
458 265
459 266
@@ -515,59 +322,172 @@ __asm__ __volatile__ \
515 : "0"(s), "1"(d), "2"(len) \ 322 : "0"(s), "1"(d), "2"(len) \
516 : "d0") 323 : "d0")
517 324
518static int macscsi_pwrite (struct Scsi_Host *instance, 325static int macscsi_pwrite(struct Scsi_Host *instance,
519 unsigned char *src, int len) 326 unsigned char *src, int len)
520{ 327{
521 unsigned char *s; 328 struct NCR5380_hostdata *hostdata = shost_priv(instance);
522 volatile unsigned char *d; 329 unsigned char *s;
523 330 unsigned char *d;
524 NCR5380_local_declare(); 331
525 NCR5380_setup(instance); 332 NCR5380_local_declare();
526 333 NCR5380_setup(instance);
527 s = src; 334
528 d = mac_scsi_drq; 335 s = src;
529 336 d = hostdata->pdma_base + (OUTPUT_DATA_REG << 4);
530/* These conditions are derived from MacOS */ 337
531 338 /* These conditions are derived from MacOS */
532 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) 339
533 && (!(NCR5380_read(STATUS_REG) & SR_REQ) 340 while (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ) &&
534 || (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH))) 341 (!(NCR5380_read(STATUS_REG) & SR_REQ) ||
535 ; 342 (NCR5380_read(BUS_AND_STATUS_REG) & BASR_PHASE_MATCH)))
536 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)) { 343 ;
537 printk(KERN_ERR "Error in macscsi_pwrite\n"); 344
538 return -1; 345 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_DRQ)) {
539 } 346 pr_err("Error in macscsi_pwrite\n");
540 347 return -1;
541 CP_MEM_TO_IO(s, d, len); 348 }
542 349
543 if (len != 0) { 350 CP_MEM_TO_IO(s, d, len);
544 printk(KERN_NOTICE "Bus error in macscsi_pwrite\n"); 351
545 return -1; 352 if (len != 0) {
546 } 353 pr_notice("Bus error in macscsi_pwrite\n");
547 354 return -1;
548 return 0; 355 }
549}
550 356
357 return 0;
358}
359#endif
551 360
552#include "NCR5380.c" 361#include "NCR5380.c"
553 362
554static struct scsi_host_template driver_template = { 363#define DRV_MODULE_NAME "mac_scsi"
555 .proc_name = "Mac5380", 364#define PFX DRV_MODULE_NAME ": "
365
366static struct scsi_host_template mac_scsi_template = {
367 .module = THIS_MODULE,
368 .proc_name = DRV_MODULE_NAME,
556 .show_info = macscsi_show_info, 369 .show_info = macscsi_show_info,
557 .write_info = macscsi_write_info, 370 .write_info = macscsi_write_info,
558 .name = "Macintosh NCR5380 SCSI", 371 .name = "Macintosh NCR5380 SCSI",
559 .detect = macscsi_detect,
560 .release = macscsi_release,
561 .info = macscsi_info, 372 .info = macscsi_info,
562 .queuecommand = macscsi_queue_command, 373 .queuecommand = macscsi_queue_command,
563 .eh_abort_handler = macscsi_abort, 374 .eh_abort_handler = macscsi_abort,
564 .eh_bus_reset_handler = macscsi_bus_reset, 375 .eh_bus_reset_handler = macscsi_bus_reset,
565 .can_queue = CAN_QUEUE, 376 .can_queue = 16,
566 .this_id = 7, 377 .this_id = 7,
567 .sg_tablesize = SG_ALL, 378 .sg_tablesize = SG_ALL,
568 .cmd_per_lun = CMD_PER_LUN, 379 .cmd_per_lun = 2,
569 .use_clustering = DISABLE_CLUSTERING 380 .use_clustering = DISABLE_CLUSTERING
570}; 381};
571 382
383static int __init mac_scsi_probe(struct platform_device *pdev)
384{
385 struct Scsi_Host *instance;
386 int error;
387 int host_flags = 0;
388 struct resource *irq, *pio_mem, *pdma_mem = NULL;
389
390 pio_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
391 if (!pio_mem)
392 return -ENODEV;
393
394#ifdef PSEUDO_DMA
395 pdma_mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
396#endif
397
398 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
399
400 if (!hwreg_present((unsigned char *)pio_mem->start +
401 (STATUS_REG << 4))) {
402 pr_info(PFX "no device detected at %pap\n", &pio_mem->start);
403 return -ENODEV;
404 }
405
406 if (setup_can_queue > 0)
407 mac_scsi_template.can_queue = setup_can_queue;
408 if (setup_cmd_per_lun > 0)
409 mac_scsi_template.cmd_per_lun = setup_cmd_per_lun;
410 if (setup_sg_tablesize >= 0)
411 mac_scsi_template.sg_tablesize = setup_sg_tablesize;
412 if (setup_hostid >= 0)
413 mac_scsi_template.this_id = setup_hostid & 7;
414 if (setup_use_pdma < 0)
415 setup_use_pdma = 0;
416
417 instance = scsi_host_alloc(&mac_scsi_template,
418 sizeof(struct NCR5380_hostdata));
419 if (!instance)
420 return -ENOMEM;
421
422 instance->base = pio_mem->start;
423 if (irq)
424 instance->irq = irq->start;
425 else
426 instance->irq = NO_IRQ;
427
428 if (pdma_mem && setup_use_pdma) {
429 struct NCR5380_hostdata *hostdata = shost_priv(instance);
430
431 hostdata->pdma_base = (unsigned char *)pdma_mem->start;
432 } else
433 host_flags |= FLAG_NO_PSEUDO_DMA;
434
435#ifdef RESET_BOOT
436 mac_scsi_reset_boot(instance);
437#endif
438
439#ifdef SUPPORT_TAGS
440 host_flags |= setup_use_tagged_queuing > 0 ? FLAG_TAGGED_QUEUING : 0;
441#endif
442
443 NCR5380_init(instance, host_flags);
444
445 if (instance->irq != NO_IRQ) {
446 error = request_irq(instance->irq, macscsi_intr, IRQF_SHARED,
447 "NCR5380", instance);
448 if (error)
449 goto fail_irq;
450 }
451
452 error = scsi_add_host(instance, NULL);
453 if (error)
454 goto fail_host;
455
456 platform_set_drvdata(pdev, instance);
457
458 scsi_scan_host(instance);
459 return 0;
460
461fail_host:
462 if (instance->irq != NO_IRQ)
463 free_irq(instance->irq, instance);
464fail_irq:
465 NCR5380_exit(instance);
466 scsi_host_put(instance);
467 return error;
468}
469
470static int __exit mac_scsi_remove(struct platform_device *pdev)
471{
472 struct Scsi_Host *instance = platform_get_drvdata(pdev);
473
474 scsi_remove_host(instance);
475 if (instance->irq != NO_IRQ)
476 free_irq(instance->irq, instance);
477 NCR5380_exit(instance);
478 scsi_host_put(instance);
479 return 0;
480}
481
482static struct platform_driver mac_scsi_driver = {
483 .remove = __exit_p(mac_scsi_remove),
484 .driver = {
485 .name = DRV_MODULE_NAME,
486 .owner = THIS_MODULE,
487 },
488};
489
490module_platform_driver_probe(mac_scsi_driver, mac_scsi_probe);
572 491
573#include "scsi_module.c" 492MODULE_ALIAS("platform:" DRV_MODULE_NAME);
493MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/mac_scsi.h b/drivers/scsi/mac_scsi.h
deleted file mode 100644
index 06969b06e54b..000000000000
--- a/drivers/scsi/mac_scsi.h
+++ /dev/null
@@ -1,74 +0,0 @@
1/*
2 * Cumana Generic NCR5380 driver defines
3 *
4 * Copyright 1993, Drew Eckhardt
5 * Visionary Computing
6 * (Unix and Linux consulting and custom programming)
7 * drew@colorado.edu
8 * +1 (303) 440-4894
9 *
10 * ALPHA RELEASE 1.
11 *
12 * For more information, please consult
13 *
14 * NCR 5380 Family
15 * SCSI Protocol Controller
16 * Databook
17 *
18 * NCR Microelectronics
19 * 1635 Aeroplaza Drive
20 * Colorado Springs, CO 80916
21 * 1+ (719) 578-3400
22 * 1+ (800) 334-5454
23 */
24
25#ifndef MAC_NCR5380_H
26#define MAC_NCR5380_H
27
28#define MACSCSI_PUBLIC_RELEASE 2
29
30#ifndef ASM
31
32#ifndef CMD_PER_LUN
33#define CMD_PER_LUN 2
34#endif
35
36#ifndef CAN_QUEUE
37#define CAN_QUEUE 16
38#endif
39
40#ifndef SG_TABLESIZE
41#define SG_TABLESIZE SG_NONE
42#endif
43
44#ifndef USE_TAGGED_QUEUING
45#define USE_TAGGED_QUEUING 0
46#endif
47
48#include <scsi/scsicam.h>
49
50#define NCR5380_implementation_fields \
51 int port, ctrl
52
53#define NCR5380_local_declare() \
54 struct Scsi_Host *_instance
55
56#define NCR5380_setup(instance) \
57 _instance = instance
58
59#define NCR5380_read(reg) macscsi_read(_instance, reg)
60#define NCR5380_write(reg, value) macscsi_write(_instance, reg, value)
61
62#define NCR5380_pread macscsi_pread
63#define NCR5380_pwrite macscsi_pwrite
64
65#define NCR5380_intr macscsi_intr
66#define NCR5380_queue_command macscsi_queue_command
67#define NCR5380_abort macscsi_abort
68#define NCR5380_bus_reset macscsi_bus_reset
69#define NCR5380_show_info macscsi_show_info
70#define NCR5380_write_info macscsi_write_info
71
72#endif /* ndef ASM */
73#endif /* MAC_NCR5380_H */
74
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index ac5d94cfd52f..2485255f3414 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -1945,7 +1945,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)
1945 cmd->device->id, (u32)cmd->device->lun); 1945 cmd->device->id, (u32)cmd->device->lun);
1946 1946
1947 if(list_empty(&adapter->pending_list)) 1947 if(list_empty(&adapter->pending_list))
1948 return FALSE; 1948 return FAILED;
1949 1949
1950 list_for_each_safe(pos, next, &adapter->pending_list) { 1950 list_for_each_safe(pos, next, &adapter->pending_list) {
1951 1951
@@ -1968,7 +1968,7 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)
1968 (aor==SCB_ABORT) ? "ABORTING":"RESET", 1968 (aor==SCB_ABORT) ? "ABORTING":"RESET",
1969 scb->idx); 1969 scb->idx);
1970 1970
1971 return FALSE; 1971 return FAILED;
1972 } 1972 }
1973 else { 1973 else {
1974 1974
@@ -1993,12 +1993,12 @@ megaraid_abort_and_reset(adapter_t *adapter, Scsi_Cmnd *cmd, int aor)
1993 list_add_tail(SCSI_LIST(cmd), 1993 list_add_tail(SCSI_LIST(cmd),
1994 &adapter->completed_list); 1994 &adapter->completed_list);
1995 1995
1996 return TRUE; 1996 return SUCCESS;
1997 } 1997 }
1998 } 1998 }
1999 } 1999 }
2000 2000
2001 return FALSE; 2001 return FAILED;
2002} 2002}
2003 2003
2004static inline int 2004static inline int
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index 531dce419c18..f0987f22ea70 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -332,27 +332,6 @@ static struct device_attribute *megaraid_sdev_attrs[] = {
332 NULL, 332 NULL,
333}; 333};
334 334
335/**
336 * megaraid_change_queue_depth - Change the device's queue depth
337 * @sdev: scsi device struct
338 * @qdepth: depth to set
339 * @reason: calling context
340 *
341 * Return value:
342 * actual depth set
343 */
344static int megaraid_change_queue_depth(struct scsi_device *sdev, int qdepth,
345 int reason)
346{
347 if (reason != SCSI_QDEPTH_DEFAULT)
348 return -EOPNOTSUPP;
349
350 if (qdepth > MBOX_MAX_SCSI_CMDS)
351 qdepth = MBOX_MAX_SCSI_CMDS;
352 scsi_adjust_queue_depth(sdev, 0, qdepth);
353 return sdev->queue_depth;
354}
355
356/* 335/*
357 * Scsi host template for megaraid unified driver 336 * Scsi host template for megaraid unified driver
358 */ 337 */
@@ -365,7 +344,7 @@ static struct scsi_host_template megaraid_template_g = {
365 .eh_device_reset_handler = megaraid_reset_handler, 344 .eh_device_reset_handler = megaraid_reset_handler,
366 .eh_bus_reset_handler = megaraid_reset_handler, 345 .eh_bus_reset_handler = megaraid_reset_handler,
367 .eh_host_reset_handler = megaraid_reset_handler, 346 .eh_host_reset_handler = megaraid_reset_handler,
368 .change_queue_depth = megaraid_change_queue_depth, 347 .change_queue_depth = scsi_change_queue_depth,
369 .use_clustering = ENABLE_CLUSTERING, 348 .use_clustering = ENABLE_CLUSTERING,
370 .no_write_same = 1, 349 .no_write_same = 1,
371 .sdev_attrs = megaraid_sdev_attrs, 350 .sdev_attrs = megaraid_sdev_attrs,
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index a49914de4b95..0d44d91c2fce 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -1,7 +1,8 @@
1/* 1/*
2 * Linux MegaRAID driver for SAS based RAID controllers 2 * Linux MegaRAID driver for SAS based RAID controllers
3 * 3 *
4 * Copyright (c) 2003-2012 LSI Corporation. 4 * Copyright (c) 2003-2013 LSI Corporation
5 * Copyright (c) 2013-2014 Avago Technologies
5 * 6 *
6 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 8 * modify it under the terms of the GNU General Public License
@@ -14,17 +15,18 @@
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
16 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 * FILE: megaraid_sas.h 20 * FILE: megaraid_sas.h
21 * 21 *
22 * Authors: LSI Corporation 22 * Authors: Avago Technologies
23 * Kashyap Desai <kashyap.desai@avagotech.com>
24 * Sumit Saxena <sumit.saxena@avagotech.com>
23 * 25 *
24 * Send feedback to: <megaraidlinux@lsi.com> 26 * Send feedback to: megaraidlinux.pdl@avagotech.com
25 * 27 *
26 * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 28 * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
27 * ATTN: Linuxraid 29 * San Jose, California 95131
28 */ 30 */
29 31
30#ifndef LSI_MEGARAID_SAS_H 32#ifndef LSI_MEGARAID_SAS_H
@@ -33,9 +35,7 @@
33/* 35/*
34 * MegaRAID SAS Driver meta data 36 * MegaRAID SAS Driver meta data
35 */ 37 */
36#define MEGASAS_VERSION "06.805.06.00-rc1" 38#define MEGASAS_VERSION "06.805.06.01-rc1"
37#define MEGASAS_RELDATE "Sep. 4, 2014"
38#define MEGASAS_EXT_VERSION "Thu. Sep. 4 17:00:00 PDT 2014"
39 39
40/* 40/*
41 * Device IDs 41 * Device IDs
@@ -1931,8 +1931,7 @@ u16 get_updated_dev_handle(struct megasas_instance *instance,
1931 struct LD_LOAD_BALANCE_INFO *lbInfo, struct IO_REQUEST_INFO *in_info); 1931 struct LD_LOAD_BALANCE_INFO *lbInfo, struct IO_REQUEST_INFO *in_info);
1932void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *map, 1932void mr_update_load_balance_params(struct MR_DRV_RAID_MAP_ALL *map,
1933 struct LD_LOAD_BALANCE_INFO *lbInfo); 1933 struct LD_LOAD_BALANCE_INFO *lbInfo);
1934int megasas_get_ctrl_info(struct megasas_instance *instance, 1934int megasas_get_ctrl_info(struct megasas_instance *instance);
1935 struct megasas_ctrl_info *ctrl_info);
1936int megasas_set_crash_dump_params(struct megasas_instance *instance, 1935int megasas_set_crash_dump_params(struct megasas_instance *instance,
1937 u8 crash_buf_state); 1936 u8 crash_buf_state);
1938void megasas_free_host_crash_buffer(struct megasas_instance *instance); 1937void megasas_free_host_crash_buffer(struct megasas_instance *instance);
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index f6a69a3b1b3f..f05580e693d0 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * Linux MegaRAID driver for SAS based RAID controllers 2 * Linux MegaRAID driver for SAS based RAID controllers
3 * 3 *
4 * Copyright (c) 2003-2012 LSI Corporation. 4 * Copyright (c) 2003-2013 LSI Corporation
5 * Copyright (c) 2013-2014 Avago Technologies
5 * 6 *
6 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 8 * modify it under the terms of the GNU General Public License
@@ -14,22 +15,20 @@
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
16 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 * FILE: megaraid_sas_base.c 20 * Authors: Avago Technologies
21 * Version : 06.805.06.00-rc1
22 *
23 * Authors: LSI Corporation
24 * Sreenivas Bagalkote 21 * Sreenivas Bagalkote
25 * Sumant Patro 22 * Sumant Patro
26 * Bo Yang 23 * Bo Yang
27 * Adam Radford <linuxraid@lsi.com> 24 * Adam Radford
25 * Kashyap Desai <kashyap.desai@avagotech.com>
26 * Sumit Saxena <sumit.saxena@avagotech.com>
28 * 27 *
29 * Send feedback to: <megaraidlinux@lsi.com> 28 * Send feedback to: megaraidlinux.pdl@avagotech.com
30 * 29 *
31 * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 30 * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
32 * ATTN: Linuxraid 31 * San Jose, California 95131
33 */ 32 */
34 33
35#include <linux/kernel.h> 34#include <linux/kernel.h>
@@ -1008,7 +1007,7 @@ megasas_issue_blocked_abort_cmd(struct megasas_instance *instance,
1008 cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr)); 1007 cpu_to_le32(upper_32_bits(cmd_to_abort->frame_phys_addr));
1009 1008
1010 cmd->sync_cmd = 1; 1009 cmd->sync_cmd = 1;
1011 cmd->cmd_status = 0xFF; 1010 cmd->cmd_status = ENODATA;
1012 1011
1013 instance->instancet->issue_dcmd(instance, cmd); 1012 instance->instancet->issue_dcmd(instance, cmd);
1014 1013
@@ -1572,6 +1571,12 @@ megasas_queue_command(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
1572 instance = (struct megasas_instance *) 1571 instance = (struct megasas_instance *)
1573 scmd->device->host->hostdata; 1572 scmd->device->host->hostdata;
1574 1573
1574 if (instance->unload == 1) {
1575 scmd->result = DID_NO_CONNECT << 16;
1576 scmd->scsi_done(scmd);
1577 return 0;
1578 }
1579
1575 if (instance->issuepend_done == 0) 1580 if (instance->issuepend_done == 0)
1576 return SCSI_MLQUEUE_HOST_BUSY; 1581 return SCSI_MLQUEUE_HOST_BUSY;
1577 1582
@@ -2586,20 +2591,6 @@ megasas_service_aen(struct megasas_instance *instance, struct megasas_cmd *cmd)
2586 } 2591 }
2587} 2592}
2588 2593
2589static int megasas_change_queue_depth(struct scsi_device *sdev,
2590 int queue_depth, int reason)
2591{
2592 if (reason != SCSI_QDEPTH_DEFAULT)
2593 return -EOPNOTSUPP;
2594
2595 if (queue_depth > sdev->host->can_queue)
2596 queue_depth = sdev->host->can_queue;
2597 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev),
2598 queue_depth);
2599
2600 return queue_depth;
2601}
2602
2603static ssize_t 2594static ssize_t
2604megasas_fw_crash_buffer_store(struct device *cdev, 2595megasas_fw_crash_buffer_store(struct device *cdev,
2605 struct device_attribute *attr, const char *buf, size_t count) 2596 struct device_attribute *attr, const char *buf, size_t count)
@@ -2764,7 +2755,7 @@ static struct scsi_host_template megasas_template = {
2764 .shost_attrs = megaraid_host_attrs, 2755 .shost_attrs = megaraid_host_attrs,
2765 .bios_param = megasas_bios_param, 2756 .bios_param = megasas_bios_param,
2766 .use_clustering = ENABLE_CLUSTERING, 2757 .use_clustering = ENABLE_CLUSTERING,
2767 .change_queue_depth = megasas_change_queue_depth, 2758 .change_queue_depth = scsi_change_queue_depth,
2768 .no_write_same = 1, 2759 .no_write_same = 1,
2769}; 2760};
2770 2761
@@ -4028,25 +4019,83 @@ megasas_ld_list_query(struct megasas_instance *instance, u8 query_type)
4028 return ret; 4019 return ret;
4029} 4020}
4030 4021
4022/*
4023 * megasas_update_ext_vd_details : Update details w.r.t Extended VD
4024 * instance : Controller's instance
4025*/
4026static void megasas_update_ext_vd_details(struct megasas_instance *instance)
4027{
4028 struct fusion_context *fusion;
4029 u32 old_map_sz;
4030 u32 new_map_sz;
4031
4032 fusion = instance->ctrl_context;
4033 /* For MFI based controllers return dummy success */
4034 if (!fusion)
4035 return;
4036
4037 instance->supportmax256vd =
4038 instance->ctrl_info->adapterOperations3.supportMaxExtLDs;
4039 /* Below is additional check to address future FW enhancement */
4040 if (instance->ctrl_info->max_lds > 64)
4041 instance->supportmax256vd = 1;
4042
4043 instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS
4044 * MEGASAS_MAX_DEV_PER_CHANNEL;
4045 instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS
4046 * MEGASAS_MAX_DEV_PER_CHANNEL;
4047 if (instance->supportmax256vd) {
4048 instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT;
4049 instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES;
4050 } else {
4051 instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES;
4052 instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES;
4053 }
4054 dev_info(&instance->pdev->dev, "Firmware supports %d VD %d PD\n",
4055 instance->fw_supported_vd_count,
4056 instance->fw_supported_pd_count);
4057 dev_info(&instance->pdev->dev, "Driver supports %d VD %d PD\n",
4058 instance->drv_supported_vd_count,
4059 instance->drv_supported_pd_count);
4060
4061 old_map_sz = sizeof(struct MR_FW_RAID_MAP) +
4062 (sizeof(struct MR_LD_SPAN_MAP) *
4063 (instance->fw_supported_vd_count - 1));
4064 new_map_sz = sizeof(struct MR_FW_RAID_MAP_EXT);
4065 fusion->drv_map_sz = sizeof(struct MR_DRV_RAID_MAP) +
4066 (sizeof(struct MR_LD_SPAN_MAP) *
4067 (instance->drv_supported_vd_count - 1));
4068
4069 fusion->max_map_sz = max(old_map_sz, new_map_sz);
4070
4071
4072 if (instance->supportmax256vd)
4073 fusion->current_map_sz = new_map_sz;
4074 else
4075 fusion->current_map_sz = old_map_sz;
4076
4077}
4078
4031/** 4079/**
4032 * megasas_get_controller_info - Returns FW's controller structure 4080 * megasas_get_controller_info - Returns FW's controller structure
4033 * @instance: Adapter soft state 4081 * @instance: Adapter soft state
4034 * @ctrl_info: Controller information structure
4035 * 4082 *
4036 * Issues an internal command (DCMD) to get the FW's controller structure. 4083 * Issues an internal command (DCMD) to get the FW's controller structure.
4037 * This information is mainly used to find out the maximum IO transfer per 4084 * This information is mainly used to find out the maximum IO transfer per
4038 * command supported by the FW. 4085 * command supported by the FW.
4039 */ 4086 */
4040int 4087int
4041megasas_get_ctrl_info(struct megasas_instance *instance, 4088megasas_get_ctrl_info(struct megasas_instance *instance)
4042 struct megasas_ctrl_info *ctrl_info)
4043{ 4089{
4044 int ret = 0; 4090 int ret = 0;
4045 struct megasas_cmd *cmd; 4091 struct megasas_cmd *cmd;
4046 struct megasas_dcmd_frame *dcmd; 4092 struct megasas_dcmd_frame *dcmd;
4047 struct megasas_ctrl_info *ci; 4093 struct megasas_ctrl_info *ci;
4094 struct megasas_ctrl_info *ctrl_info;
4048 dma_addr_t ci_h = 0; 4095 dma_addr_t ci_h = 0;
4049 4096
4097 ctrl_info = instance->ctrl_info;
4098
4050 cmd = megasas_get_cmd(instance); 4099 cmd = megasas_get_cmd(instance);
4051 4100
4052 if (!cmd) { 4101 if (!cmd) {
@@ -4086,8 +4135,13 @@ megasas_get_ctrl_info(struct megasas_instance *instance,
4086 else 4135 else
4087 ret = megasas_issue_polled(instance, cmd); 4136 ret = megasas_issue_polled(instance, cmd);
4088 4137
4089 if (!ret) 4138 if (!ret) {
4090 memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info)); 4139 memcpy(ctrl_info, ci, sizeof(struct megasas_ctrl_info));
4140 le32_to_cpus((u32 *)&ctrl_info->properties.OnOffProperties);
4141 le32_to_cpus((u32 *)&ctrl_info->adapterOperations2);
4142 le32_to_cpus((u32 *)&ctrl_info->adapterOperations3);
4143 megasas_update_ext_vd_details(instance);
4144 }
4091 4145
4092 pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info), 4146 pci_free_consistent(instance->pdev, sizeof(struct megasas_ctrl_info),
4093 ci, ci_h); 4147 ci, ci_h);
@@ -4289,7 +4343,7 @@ megasas_init_adapter_mfi(struct megasas_instance *instance)
4289 if (megasas_issue_init_mfi(instance)) 4343 if (megasas_issue_init_mfi(instance))
4290 goto fail_fw_init; 4344 goto fail_fw_init;
4291 4345
4292 if (megasas_get_ctrl_info(instance, instance->ctrl_info)) { 4346 if (megasas_get_ctrl_info(instance)) {
4293 dev_err(&instance->pdev->dev, "(%d): Could get controller info " 4347 dev_err(&instance->pdev->dev, "(%d): Could get controller info "
4294 "Fail from %s %d\n", instance->unique_id, 4348 "Fail from %s %d\n", instance->unique_id,
4295 __func__, __LINE__); 4349 __func__, __LINE__);
@@ -4453,7 +4507,7 @@ static int megasas_init_fw(struct megasas_instance *instance)
4453 instance->msixentry[i].entry = i; 4507 instance->msixentry[i].entry = i;
4454 i = pci_enable_msix_range(instance->pdev, instance->msixentry, 4508 i = pci_enable_msix_range(instance->pdev, instance->msixentry,
4455 1, instance->msix_vectors); 4509 1, instance->msix_vectors);
4456 if (i) 4510 if (i > 0)
4457 instance->msix_vectors = i; 4511 instance->msix_vectors = i;
4458 else 4512 else
4459 instance->msix_vectors = 0; 4513 instance->msix_vectors = 0;
@@ -4527,12 +4581,8 @@ static int megasas_init_fw(struct megasas_instance *instance)
4527 dev_info(&instance->pdev->dev, 4581 dev_info(&instance->pdev->dev,
4528 "Controller type: iMR\n"); 4582 "Controller type: iMR\n");
4529 } 4583 }
4530 /* OnOffProperties are converted into CPU arch*/
4531 le32_to_cpus((u32 *)&ctrl_info->properties.OnOffProperties);
4532 instance->disableOnlineCtrlReset = 4584 instance->disableOnlineCtrlReset =
4533 ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset; 4585 ctrl_info->properties.OnOffProperties.disableOnlineCtrlReset;
4534 /* adapterOperations2 are converted into CPU arch*/
4535 le32_to_cpus((u32 *)&ctrl_info->adapterOperations2);
4536 instance->mpio = ctrl_info->adapterOperations2.mpio; 4586 instance->mpio = ctrl_info->adapterOperations2.mpio;
4537 instance->UnevenSpanSupport = 4587 instance->UnevenSpanSupport =
4538 ctrl_info->adapterOperations2.supportUnevenSpans; 4588 ctrl_info->adapterOperations2.supportUnevenSpans;
@@ -4562,7 +4612,6 @@ static int megasas_init_fw(struct megasas_instance *instance)
4562 "requestorId %d\n", instance->requestorId); 4612 "requestorId %d\n", instance->requestorId);
4563 } 4613 }
4564 4614
4565 le32_to_cpus((u32 *)&ctrl_info->adapterOperations3);
4566 instance->crash_dump_fw_support = 4615 instance->crash_dump_fw_support =
4567 ctrl_info->adapterOperations3.supportCrashDump; 4616 ctrl_info->adapterOperations3.supportCrashDump;
4568 instance->crash_dump_drv_support = 4617 instance->crash_dump_drv_support =
@@ -4587,8 +4636,6 @@ static int megasas_init_fw(struct megasas_instance *instance)
4587 if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors)) 4636 if (tmp_sectors && (instance->max_sectors_per_req > tmp_sectors))
4588 instance->max_sectors_per_req = tmp_sectors; 4637 instance->max_sectors_per_req = tmp_sectors;
4589 4638
4590 kfree(ctrl_info);
4591
4592 /* Check for valid throttlequeuedepth module parameter */ 4639 /* Check for valid throttlequeuedepth module parameter */
4593 if (instance->is_imr) { 4640 if (instance->is_imr) {
4594 if (throttlequeuedepth > (instance->max_fw_cmds - 4641 if (throttlequeuedepth > (instance->max_fw_cmds -
@@ -4957,10 +5004,6 @@ static int megasas_io_attach(struct megasas_instance *instance)
4957 return -ENODEV; 5004 return -ENODEV;
4958 } 5005 }
4959 5006
4960 /*
4961 * Trigger SCSI to scan our drives
4962 */
4963 scsi_scan_host(host);
4964 return 0; 5007 return 0;
4965} 5008}
4966 5009
@@ -5083,6 +5126,8 @@ static int megasas_probe_one(struct pci_dev *pdev,
5083 goto fail_alloc_dma_buf; 5126 goto fail_alloc_dma_buf;
5084 } 5127 }
5085 fusion = instance->ctrl_context; 5128 fusion = instance->ctrl_context;
5129 memset(fusion, 0,
5130 ((1 << PAGE_SHIFT) << instance->ctrl_context_pages));
5086 INIT_LIST_HEAD(&fusion->cmd_pool); 5131 INIT_LIST_HEAD(&fusion->cmd_pool);
5087 spin_lock_init(&fusion->mpt_pool_lock); 5132 spin_lock_init(&fusion->mpt_pool_lock);
5088 memset(fusion->load_balance_info, 0, 5133 memset(fusion->load_balance_info, 0,
@@ -5288,6 +5333,10 @@ retry_irq_register:
5288 goto fail_io_attach; 5333 goto fail_io_attach;
5289 5334
5290 instance->unload = 0; 5335 instance->unload = 0;
5336 /*
5337 * Trigger SCSI to scan our drives
5338 */
5339 scsi_scan_host(host);
5291 5340
5292 /* 5341 /*
5293 * Initiate AEN (Asynchronous Event Notification) 5342 * Initiate AEN (Asynchronous Event Notification)
@@ -6051,6 +6100,11 @@ megasas_mgmt_fw_ioctl(struct megasas_instance *instance,
6051 megasas_issue_blocked_cmd(instance, cmd, 0); 6100 megasas_issue_blocked_cmd(instance, cmd, 0);
6052 cmd->sync_cmd = 0; 6101 cmd->sync_cmd = 0;
6053 6102
6103 if (instance->unload == 1) {
6104 dev_info(&instance->pdev->dev, "Driver unload is in progress "
6105 "don't submit data to application\n");
6106 goto out;
6107 }
6054 /* 6108 /*
6055 * copy out the kernel buffers to user buffers 6109 * copy out the kernel buffers to user buffers
6056 */ 6110 */
@@ -6400,16 +6454,6 @@ static ssize_t megasas_sysfs_show_version(struct device_driver *dd, char *buf)
6400static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL); 6454static DRIVER_ATTR(version, S_IRUGO, megasas_sysfs_show_version, NULL);
6401 6455
6402static ssize_t 6456static ssize_t
6403megasas_sysfs_show_release_date(struct device_driver *dd, char *buf)
6404{
6405 return snprintf(buf, strlen(MEGASAS_RELDATE) + 2, "%s\n",
6406 MEGASAS_RELDATE);
6407}
6408
6409static DRIVER_ATTR(release_date, S_IRUGO, megasas_sysfs_show_release_date,
6410 NULL);
6411
6412static ssize_t
6413megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf) 6457megasas_sysfs_show_support_poll_for_event(struct device_driver *dd, char *buf)
6414{ 6458{
6415 return sprintf(buf, "%u\n", support_poll_for_event); 6459 return sprintf(buf, "%u\n", support_poll_for_event);
@@ -6712,8 +6756,7 @@ static int __init megasas_init(void)
6712 /* 6756 /*
6713 * Announce driver version and other information 6757 * Announce driver version and other information
6714 */ 6758 */
6715 printk(KERN_INFO "megasas: %s %s\n", MEGASAS_VERSION, 6759 pr_info("megasas: %s\n", MEGASAS_VERSION);
6716 MEGASAS_EXT_VERSION);
6717 6760
6718 spin_lock_init(&poll_aen_lock); 6761 spin_lock_init(&poll_aen_lock);
6719 6762
@@ -6748,10 +6791,6 @@ static int __init megasas_init(void)
6748 &driver_attr_version); 6791 &driver_attr_version);
6749 if (rval) 6792 if (rval)
6750 goto err_dcf_attr_ver; 6793 goto err_dcf_attr_ver;
6751 rval = driver_create_file(&megasas_pci_driver.driver,
6752 &driver_attr_release_date);
6753 if (rval)
6754 goto err_dcf_rel_date;
6755 6794
6756 rval = driver_create_file(&megasas_pci_driver.driver, 6795 rval = driver_create_file(&megasas_pci_driver.driver,
6757 &driver_attr_support_poll_for_event); 6796 &driver_attr_support_poll_for_event);
@@ -6775,12 +6814,7 @@ err_dcf_support_device_change:
6775err_dcf_dbg_lvl: 6814err_dcf_dbg_lvl:
6776 driver_remove_file(&megasas_pci_driver.driver, 6815 driver_remove_file(&megasas_pci_driver.driver,
6777 &driver_attr_support_poll_for_event); 6816 &driver_attr_support_poll_for_event);
6778
6779err_dcf_support_poll_for_event: 6817err_dcf_support_poll_for_event:
6780 driver_remove_file(&megasas_pci_driver.driver,
6781 &driver_attr_release_date);
6782
6783err_dcf_rel_date:
6784 driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); 6818 driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version);
6785err_dcf_attr_ver: 6819err_dcf_attr_ver:
6786 pci_unregister_driver(&megasas_pci_driver); 6820 pci_unregister_driver(&megasas_pci_driver);
@@ -6800,8 +6834,6 @@ static void __exit megasas_exit(void)
6800 &driver_attr_support_poll_for_event); 6834 &driver_attr_support_poll_for_event);
6801 driver_remove_file(&megasas_pci_driver.driver, 6835 driver_remove_file(&megasas_pci_driver.driver,
6802 &driver_attr_support_device_change); 6836 &driver_attr_support_device_change);
6803 driver_remove_file(&megasas_pci_driver.driver,
6804 &driver_attr_release_date);
6805 driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version); 6837 driver_remove_file(&megasas_pci_driver.driver, &driver_attr_version);
6806 6838
6807 pci_unregister_driver(&megasas_pci_driver); 6839 pci_unregister_driver(&megasas_pci_driver);
diff --git a/drivers/scsi/megaraid/megaraid_sas_fp.c b/drivers/scsi/megaraid/megaraid_sas_fp.c
index 685e6f391fe4..460c6a3d4ade 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fp.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fp.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * Linux MegaRAID driver for SAS based RAID controllers 2 * Linux MegaRAID driver for SAS based RAID controllers
3 * 3 *
4 * Copyright (c) 2009-2012 LSI Corporation. 4 * Copyright (c) 2009-2013 LSI Corporation
5 * Copyright (c) 2013-2014 Avago Technologies
5 * 6 *
6 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 8 * modify it under the terms of the GNU General Public License
@@ -14,20 +15,21 @@
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
16 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 * FILE: megaraid_sas_fp.c 20 * FILE: megaraid_sas_fp.c
21 * 21 *
22 * Authors: LSI Corporation 22 * Authors: Avago Technologies
23 * Sumant Patro 23 * Sumant Patro
24 * Varad Talamacki 24 * Varad Talamacki
25 * Manoj Jose 25 * Manoj Jose
26 * Kashyap Desai <kashyap.desai@avagotech.com>
27 * Sumit Saxena <sumit.saxena@avagotech.com>
26 * 28 *
27 * Send feedback to: <megaraidlinux@lsi.com> 29 * Send feedback to: megaraidlinux.pdl@avagotech.com
28 * 30 *
29 * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 31 * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
30 * ATTN: Linuxraid 32 * San Jose, California 95131
31 */ 33 */
32 34
33#include <linux/kernel.h> 35#include <linux/kernel.h>
@@ -183,14 +185,15 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
183 /* New Raid map will not set totalSize, so keep expected value 185 /* New Raid map will not set totalSize, so keep expected value
184 * for legacy code in ValidateMapInfo 186 * for legacy code in ValidateMapInfo
185 */ 187 */
186 pDrvRaidMap->totalSize = sizeof(struct MR_FW_RAID_MAP_EXT); 188 pDrvRaidMap->totalSize =
189 cpu_to_le32(sizeof(struct MR_FW_RAID_MAP_EXT));
187 } else { 190 } else {
188 fw_map_old = (struct MR_FW_RAID_MAP_ALL *) 191 fw_map_old = (struct MR_FW_RAID_MAP_ALL *)
189 fusion->ld_map[(instance->map_id & 1)]; 192 fusion->ld_map[(instance->map_id & 1)];
190 pFwRaidMap = &fw_map_old->raidMap; 193 pFwRaidMap = &fw_map_old->raidMap;
191 194
192#if VD_EXT_DEBUG 195#if VD_EXT_DEBUG
193 for (i = 0; i < pFwRaidMap->ldCount; i++) { 196 for (i = 0; i < le16_to_cpu(pFwRaidMap->ldCount); i++) {
194 dev_dbg(&instance->pdev->dev, "(%d) :Index 0x%x " 197 dev_dbg(&instance->pdev->dev, "(%d) :Index 0x%x "
195 "Target Id 0x%x Seq Num 0x%x Size 0/%llx\n", 198 "Target Id 0x%x Seq Num 0x%x Size 0/%llx\n",
196 instance->unique_id, i, 199 instance->unique_id, i,
@@ -202,12 +205,12 @@ void MR_PopulateDrvRaidMap(struct megasas_instance *instance)
202 205
203 memset(drv_map, 0, fusion->drv_map_sz); 206 memset(drv_map, 0, fusion->drv_map_sz);
204 pDrvRaidMap->totalSize = pFwRaidMap->totalSize; 207 pDrvRaidMap->totalSize = pFwRaidMap->totalSize;
205 pDrvRaidMap->ldCount = pFwRaidMap->ldCount; 208 pDrvRaidMap->ldCount = (__le16)pFwRaidMap->ldCount;
206 pDrvRaidMap->fpPdIoTimeoutSec = pFwRaidMap->fpPdIoTimeoutSec; 209 pDrvRaidMap->fpPdIoTimeoutSec = pFwRaidMap->fpPdIoTimeoutSec;
207 for (i = 0; i < MAX_RAIDMAP_LOGICAL_DRIVES + MAX_RAIDMAP_VIEWS; i++) 210 for (i = 0; i < MAX_RAIDMAP_LOGICAL_DRIVES + MAX_RAIDMAP_VIEWS; i++)
208 pDrvRaidMap->ldTgtIdToLd[i] = 211 pDrvRaidMap->ldTgtIdToLd[i] =
209 (u8)pFwRaidMap->ldTgtIdToLd[i]; 212 (u8)pFwRaidMap->ldTgtIdToLd[i];
210 for (i = 0; i < pDrvRaidMap->ldCount; i++) { 213 for (i = 0; i < le16_to_cpu(pDrvRaidMap->ldCount); i++) {
211 pDrvRaidMap->ldSpanMap[i] = pFwRaidMap->ldSpanMap[i]; 214 pDrvRaidMap->ldSpanMap[i] = pFwRaidMap->ldSpanMap[i];
212#if VD_EXT_DEBUG 215#if VD_EXT_DEBUG
213 dev_dbg(&instance->pdev->dev, 216 dev_dbg(&instance->pdev->dev,
@@ -268,7 +271,7 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance)
268 else 271 else
269 expected_size = 272 expected_size =
270 (sizeof(struct MR_FW_RAID_MAP) - sizeof(struct MR_LD_SPAN_MAP) + 273 (sizeof(struct MR_FW_RAID_MAP) - sizeof(struct MR_LD_SPAN_MAP) +
271 (sizeof(struct MR_LD_SPAN_MAP) * le32_to_cpu(pDrvRaidMap->ldCount))); 274 (sizeof(struct MR_LD_SPAN_MAP) * le16_to_cpu(pDrvRaidMap->ldCount)));
272 275
273 if (le32_to_cpu(pDrvRaidMap->totalSize) != expected_size) { 276 if (le32_to_cpu(pDrvRaidMap->totalSize) != expected_size) {
274 dev_err(&instance->pdev->dev, "map info structure size 0x%x is not matching with ld count\n", 277 dev_err(&instance->pdev->dev, "map info structure size 0x%x is not matching with ld count\n",
@@ -284,7 +287,7 @@ u8 MR_ValidateMapInfo(struct megasas_instance *instance)
284 287
285 mr_update_load_balance_params(drv_map, lbInfo); 288 mr_update_load_balance_params(drv_map, lbInfo);
286 289
287 num_lds = le32_to_cpu(drv_map->raidMap.ldCount); 290 num_lds = le16_to_cpu(drv_map->raidMap.ldCount);
288 291
289 /*Convert Raid capability values to CPU arch */ 292 /*Convert Raid capability values to CPU arch */
290 for (ldCount = 0; ldCount < num_lds; ldCount++) { 293 for (ldCount = 0; ldCount < num_lds; ldCount++) {
@@ -457,7 +460,7 @@ u32 mr_spanset_get_span_block(struct megasas_instance *instance,
457 quad = &map->raidMap.ldSpanMap[ld]. 460 quad = &map->raidMap.ldSpanMap[ld].
458 spanBlock[span]. 461 spanBlock[span].
459 block_span_info.quad[info]; 462 block_span_info.quad[info];
460 if (le32_to_cpu(quad->diff == 0)) 463 if (le32_to_cpu(quad->diff) == 0)
461 return SPAN_INVALID; 464 return SPAN_INVALID;
462 if (le64_to_cpu(quad->logStart) <= row && 465 if (le64_to_cpu(quad->logStart) <= row &&
463 row <= le64_to_cpu(quad->logEnd) && 466 row <= le64_to_cpu(quad->logEnd) &&
@@ -520,7 +523,7 @@ static u64 get_row_from_strip(struct megasas_instance *instance,
520 span_set->span_row_data_width) * span_set->diff; 523 span_set->span_row_data_width) * span_set->diff;
521 for (span = 0, span_offset = 0; span < raid->spanDepth; span++) 524 for (span = 0, span_offset = 0; span < raid->spanDepth; span++)
522 if (le32_to_cpu(map->raidMap.ldSpanMap[ld].spanBlock[span]. 525 if (le32_to_cpu(map->raidMap.ldSpanMap[ld].spanBlock[span].
523 block_span_info.noElements >= info+1)) { 526 block_span_info.noElements) >= info+1) {
524 if (strip_offset >= 527 if (strip_offset >=
525 span_set->strip_offset[span]) 528 span_set->strip_offset[span])
526 span_offset++; 529 span_offset++;
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index f37eed682c75..71557f64bb5e 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * Linux MegaRAID driver for SAS based RAID controllers 2 * Linux MegaRAID driver for SAS based RAID controllers
3 * 3 *
4 * Copyright (c) 2009-2012 LSI Corporation. 4 * Copyright (c) 2009-2013 LSI Corporation
5 * Copyright (c) 2013-2014 Avago Technologies
5 * 6 *
6 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 8 * modify it under the terms of the GNU General Public License
@@ -14,19 +15,20 @@
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
16 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 * FILE: megaraid_sas_fusion.c 20 * FILE: megaraid_sas_fusion.c
21 * 21 *
22 * Authors: LSI Corporation 22 * Authors: Avago Technologies
23 * Sumant Patro 23 * Sumant Patro
24 * Adam Radford <linuxraid@lsi.com> 24 * Adam Radford
25 * Kashyap Desai <kashyap.desai@avagotech.com>
26 * Sumit Saxena <sumit.saxena@avagotech.com>
25 * 27 *
26 * Send feedback to: <megaraidlinux@lsi.com> 28 * Send feedback to: megaraidlinux.pdl@avagotech.com
27 * 29 *
28 * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 30 * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
29 * ATTN: Linuxraid 31 * San Jose, California 95131
30 */ 32 */
31 33
32#include <linux/kernel.h> 34#include <linux/kernel.h>
@@ -880,7 +882,7 @@ megasas_sync_map_info(struct megasas_instance *instance)
880 882
881 map = fusion->ld_drv_map[instance->map_id & 1]; 883 map = fusion->ld_drv_map[instance->map_id & 1];
882 884
883 num_lds = le32_to_cpu(map->raidMap.ldCount); 885 num_lds = le16_to_cpu(map->raidMap.ldCount);
884 886
885 dcmd = &cmd->frame->dcmd; 887 dcmd = &cmd->frame->dcmd;
886 888
@@ -1065,48 +1067,16 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
1065 goto fail_ioc_init; 1067 goto fail_ioc_init;
1066 1068
1067 megasas_display_intel_branding(instance); 1069 megasas_display_intel_branding(instance);
1068 if (megasas_get_ctrl_info(instance, instance->ctrl_info)) { 1070 if (megasas_get_ctrl_info(instance)) {
1069 dev_err(&instance->pdev->dev, 1071 dev_err(&instance->pdev->dev,
1070 "Could not get controller info. Fail from %s %d\n", 1072 "Could not get controller info. Fail from %s %d\n",
1071 __func__, __LINE__); 1073 __func__, __LINE__);
1072 goto fail_ioc_init; 1074 goto fail_ioc_init;
1073 } 1075 }
1074 1076
1075 instance->supportmax256vd =
1076 instance->ctrl_info->adapterOperations3.supportMaxExtLDs;
1077 /* Below is additional check to address future FW enhancement */
1078 if (instance->ctrl_info->max_lds > 64)
1079 instance->supportmax256vd = 1;
1080 instance->drv_supported_vd_count = MEGASAS_MAX_LD_CHANNELS
1081 * MEGASAS_MAX_DEV_PER_CHANNEL;
1082 instance->drv_supported_pd_count = MEGASAS_MAX_PD_CHANNELS
1083 * MEGASAS_MAX_DEV_PER_CHANNEL;
1084 if (instance->supportmax256vd) {
1085 instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES_EXT;
1086 instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES;
1087 } else {
1088 instance->fw_supported_vd_count = MAX_LOGICAL_DRIVES;
1089 instance->fw_supported_pd_count = MAX_PHYSICAL_DEVICES;
1090 }
1091 dev_info(&instance->pdev->dev, "Firmware supports %d VDs %d PDs\n"
1092 "Driver supports %d VDs %d PDs\n",
1093 instance->fw_supported_vd_count,
1094 instance->fw_supported_pd_count,
1095 instance->drv_supported_vd_count,
1096 instance->drv_supported_pd_count);
1097
1098 instance->flag_ieee = 1; 1077 instance->flag_ieee = 1;
1099 fusion->fast_path_io = 0; 1078 fusion->fast_path_io = 0;
1100 1079
1101 fusion->old_map_sz =
1102 sizeof(struct MR_FW_RAID_MAP) + (sizeof(struct MR_LD_SPAN_MAP) *
1103 (instance->fw_supported_vd_count - 1));
1104 fusion->new_map_sz =
1105 sizeof(struct MR_FW_RAID_MAP_EXT);
1106 fusion->drv_map_sz =
1107 sizeof(struct MR_DRV_RAID_MAP) + (sizeof(struct MR_LD_SPAN_MAP) *
1108 (instance->drv_supported_vd_count - 1));
1109
1110 fusion->drv_map_pages = get_order(fusion->drv_map_sz); 1080 fusion->drv_map_pages = get_order(fusion->drv_map_sz);
1111 for (i = 0; i < 2; i++) { 1081 for (i = 0; i < 2; i++) {
1112 fusion->ld_map[i] = NULL; 1082 fusion->ld_map[i] = NULL;
@@ -1121,16 +1091,10 @@ megasas_init_adapter_fusion(struct megasas_instance *instance)
1121 fusion->drv_map_pages); 1091 fusion->drv_map_pages);
1122 goto fail_ioc_init; 1092 goto fail_ioc_init;
1123 } 1093 }
1094 memset(fusion->ld_drv_map[i], 0,
1095 ((1 << PAGE_SHIFT) << fusion->drv_map_pages));
1124 } 1096 }
1125 1097
1126 fusion->max_map_sz = max(fusion->old_map_sz, fusion->new_map_sz);
1127
1128 if (instance->supportmax256vd)
1129 fusion->current_map_sz = fusion->new_map_sz;
1130 else
1131 fusion->current_map_sz = fusion->old_map_sz;
1132
1133
1134 for (i = 0; i < 2; i++) { 1098 for (i = 0; i < 2; i++) {
1135 fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev, 1099 fusion->ld_map[i] = dma_alloc_coherent(&instance->pdev->dev,
1136 fusion->max_map_sz, 1100 fusion->max_map_sz,
@@ -1173,9 +1137,10 @@ megasas_fire_cmd_fusion(struct megasas_instance *instance,
1173 struct megasas_register_set __iomem *regs) 1137 struct megasas_register_set __iomem *regs)
1174{ 1138{
1175#if defined(writeq) && defined(CONFIG_64BIT) 1139#if defined(writeq) && defined(CONFIG_64BIT)
1176 u64 req_data = (((u64)req_desc_hi << 32) | (u32)req_desc_lo); 1140 u64 req_data = (((u64)le32_to_cpu(req_desc_hi) << 32) |
1141 le32_to_cpu(req_desc_lo));
1177 1142
1178 writeq(le64_to_cpu(req_data), &(regs)->inbound_low_queue_port); 1143 writeq(req_data, &(regs)->inbound_low_queue_port);
1179#else 1144#else
1180 unsigned long flags; 1145 unsigned long flags;
1181 1146
@@ -1373,7 +1338,7 @@ megasas_set_pd_lba(struct MPI2_RAID_SCSI_IO_REQUEST *io_request, u8 cdb_len,
1373 /* Logical block reference tag */ 1338 /* Logical block reference tag */
1374 io_request->CDB.EEDP32.PrimaryReferenceTag = 1339 io_request->CDB.EEDP32.PrimaryReferenceTag =
1375 cpu_to_be32(ref_tag); 1340 cpu_to_be32(ref_tag);
1376 io_request->CDB.EEDP32.PrimaryApplicationTagMask = 0xffff; 1341 io_request->CDB.EEDP32.PrimaryApplicationTagMask = cpu_to_be16(0xffff);
1377 io_request->IoFlags = cpu_to_le16(32); /* Specify 32-byte cdb */ 1342 io_request->IoFlags = cpu_to_le16(32); /* Specify 32-byte cdb */
1378 1343
1379 /* Transfer length */ 1344 /* Transfer length */
@@ -1769,7 +1734,7 @@ megasas_build_dcdb_fusion(struct megasas_instance *instance,
1769 1734
1770 /* set RAID context values */ 1735 /* set RAID context values */
1771 pRAID_Context->regLockFlags = REGION_TYPE_SHARED_READ; 1736 pRAID_Context->regLockFlags = REGION_TYPE_SHARED_READ;
1772 pRAID_Context->timeoutValue = raid->fpIoTimeoutForLd; 1737 pRAID_Context->timeoutValue = cpu_to_le16(raid->fpIoTimeoutForLd);
1773 pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id); 1738 pRAID_Context->VirtualDiskTgtId = cpu_to_le16(device_id);
1774 pRAID_Context->regLockRowLBA = 0; 1739 pRAID_Context->regLockRowLBA = 0;
1775 pRAID_Context->regLockLength = 0; 1740 pRAID_Context->regLockLength = 0;
@@ -2254,7 +2219,7 @@ build_mpt_mfi_pass_thru(struct megasas_instance *instance,
2254 * megasas_complete_cmd 2219 * megasas_complete_cmd
2255 */ 2220 */
2256 2221
2257 if (frame_hdr->flags & MFI_FRAME_DONT_POST_IN_REPLY_QUEUE) 2222 if (frame_hdr->flags & cpu_to_le16(MFI_FRAME_DONT_POST_IN_REPLY_QUEUE))
2258 cmd->flags = MFI_FRAME_DONT_POST_IN_REPLY_QUEUE; 2223 cmd->flags = MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
2259 2224
2260 fusion = instance->ctrl_context; 2225 fusion = instance->ctrl_context;
@@ -2385,6 +2350,8 @@ megasas_alloc_host_crash_buffer(struct megasas_instance *instance)
2385 "memory allocation failed at index %d\n", i); 2350 "memory allocation failed at index %d\n", i);
2386 break; 2351 break;
2387 } 2352 }
2353 memset(instance->crash_buf[i], 0,
2354 ((1 << PAGE_SHIFT) << instance->crash_buf_pages));
2388 } 2355 }
2389 instance->drv_buf_alloc = i; 2356 instance->drv_buf_alloc = i;
2390} 2357}
@@ -2837,11 +2804,15 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout)
2837 } 2804 }
2838 } 2805 }
2839 2806
2840 clear_bit(MEGASAS_FUSION_IN_RESET, 2807 if (megasas_get_ctrl_info(instance)) {
2841 &instance->reset_flags); 2808 dev_info(&instance->pdev->dev,
2842 instance->instancet->enable_intr(instance); 2809 "Failed from %s %d\n",
2843 instance->adprecovery = MEGASAS_HBA_OPERATIONAL; 2810 __func__, __LINE__);
2844 2811 instance->adprecovery =
2812 MEGASAS_HW_CRITICAL_ERROR;
2813 megaraid_sas_kill_hba(instance);
2814 retval = FAILED;
2815 }
2845 /* Reset load balance info */ 2816 /* Reset load balance info */
2846 memset(fusion->load_balance_info, 0, 2817 memset(fusion->load_balance_info, 0,
2847 sizeof(struct LD_LOAD_BALANCE_INFO) 2818 sizeof(struct LD_LOAD_BALANCE_INFO)
@@ -2850,6 +2821,11 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout)
2850 if (!megasas_get_map_info(instance)) 2821 if (!megasas_get_map_info(instance))
2851 megasas_sync_map_info(instance); 2822 megasas_sync_map_info(instance);
2852 2823
2824 clear_bit(MEGASAS_FUSION_IN_RESET,
2825 &instance->reset_flags);
2826 instance->instancet->enable_intr(instance);
2827 instance->adprecovery = MEGASAS_HBA_OPERATIONAL;
2828
2853 /* Restart SR-IOV heartbeat */ 2829 /* Restart SR-IOV heartbeat */
2854 if (instance->requestorId) { 2830 if (instance->requestorId) {
2855 if (!megasas_sriov_start_heartbeat(instance, 0)) 2831 if (!megasas_sriov_start_heartbeat(instance, 0))
@@ -2866,14 +2842,14 @@ int megasas_reset_fusion(struct Scsi_Host *shost, int iotimeout)
2866 "successful for scsi%d.\n", 2842 "successful for scsi%d.\n",
2867 instance->host->host_no); 2843 instance->host->host_no);
2868 2844
2869 if (instance->crash_dump_drv_support) { 2845 if (instance->crash_dump_drv_support &&
2870 if (instance->crash_dump_app_support) 2846 instance->crash_dump_app_support)
2871 megasas_set_crash_dump_params(instance, 2847 megasas_set_crash_dump_params(instance,
2872 MR_CRASH_BUF_TURN_ON); 2848 MR_CRASH_BUF_TURN_ON);
2873 else 2849 else
2874 megasas_set_crash_dump_params(instance, 2850 megasas_set_crash_dump_params(instance,
2875 MR_CRASH_BUF_TURN_OFF); 2851 MR_CRASH_BUF_TURN_OFF);
2876 } 2852
2877 retval = SUCCESS; 2853 retval = SUCCESS;
2878 goto out; 2854 goto out;
2879 } 2855 }
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.h b/drivers/scsi/megaraid/megaraid_sas_fusion.h
index 0d183d521bdd..5ab7daee11be 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.h
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.h
@@ -1,7 +1,8 @@
1/* 1/*
2 * Linux MegaRAID driver for SAS based RAID controllers 2 * Linux MegaRAID driver for SAS based RAID controllers
3 * 3 *
4 * Copyright (c) 2009-2012 LSI Corporation. 4 * Copyright (c) 2009-2013 LSI Corporation
5 * Copyright (c) 2013-2014 Avago Technologies
5 * 6 *
6 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 8 * modify it under the terms of the GNU General Public License
@@ -14,19 +15,20 @@
14 * GNU General Public License for more details. 15 * GNU General Public License for more details.
15 * 16 *
16 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 19 *
20 * FILE: megaraid_sas_fusion.h 20 * FILE: megaraid_sas_fusion.h
21 * 21 *
22 * Authors: LSI Corporation 22 * Authors: Avago Technologies
23 * Manoj Jose 23 * Manoj Jose
24 * Sumant Patro 24 * Sumant Patro
25 * Kashyap Desai <kashyap.desai@avagotech.com>
26 * Sumit Saxena <sumit.saxena@avagotech.com>
25 * 27 *
26 * Send feedback to: <megaraidlinux@lsi.com> 28 * Send feedback to: megaraidlinux.pdl@avagotech.com
27 * 29 *
28 * Mail to: LSI Corporation, 1621 Barber Lane, Milpitas, CA 95035 30 * Mail to: Avago Technologies, 350 West Trimble Road, Building 90,
29 * ATTN: Linuxraid 31 * San Jose, California 95131
30 */ 32 */
31 33
32#ifndef _MEGARAID_SAS_FUSION_H_ 34#ifndef _MEGARAID_SAS_FUSION_H_
@@ -834,8 +836,6 @@ struct fusion_context {
834 836
835 u32 max_map_sz; 837 u32 max_map_sz;
836 u32 current_map_sz; 838 u32 current_map_sz;
837 u32 old_map_sz;
838 u32 new_map_sz;
839 u32 drv_map_sz; 839 u32 drv_map_sz;
840 u32 drv_map_pages; 840 u32 drv_map_pages;
841 u8 fast_path_io; 841 u8 fast_path_io;
diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
index c80ed0482649..8431eb10bbb1 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
@@ -1179,15 +1179,14 @@ _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
1179} 1179}
1180 1180
1181/** 1181/**
1182 * _scsih_adjust_queue_depth - setting device queue depth 1182 * _scsih_change_queue_depth - setting device queue depth
1183 * @sdev: scsi device struct 1183 * @sdev: scsi device struct
1184 * @qdepth: requested queue depth 1184 * @qdepth: requested queue depth
1185 * 1185 *
1186 * 1186 * Returns queue depth.
1187 * Returns nothing
1188 */ 1187 */
1189static void 1188static int
1190_scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth) 1189_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1191{ 1190{
1192 struct Scsi_Host *shost = sdev->host; 1191 struct Scsi_Host *shost = sdev->host;
1193 int max_depth; 1192 int max_depth;
@@ -1217,63 +1216,11 @@ _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1217 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 1216 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1218 1217
1219 not_sata: 1218 not_sata:
1220
1221 if (!sdev->tagged_supported) 1219 if (!sdev->tagged_supported)
1222 max_depth = 1; 1220 max_depth = 1;
1223 if (qdepth > max_depth) 1221 if (qdepth > max_depth)
1224 qdepth = max_depth; 1222 qdepth = max_depth;
1225 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 1223 return scsi_change_queue_depth(sdev, qdepth);
1226}
1227
1228/**
1229 * _scsih_change_queue_depth - setting device queue depth
1230 * @sdev: scsi device struct
1231 * @qdepth: requested queue depth
1232 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1233 * (see include/scsi/scsi_host.h for definition)
1234 *
1235 * Returns queue depth.
1236 */
1237static int
1238_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1239{
1240 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1241 _scsih_adjust_queue_depth(sdev, qdepth);
1242 else if (reason == SCSI_QDEPTH_QFULL)
1243 scsi_track_queue_full(sdev, qdepth);
1244 else
1245 return -EOPNOTSUPP;
1246
1247 if (sdev->inquiry_len > 7)
1248 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
1249 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1250 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1251 sdev->ordered_tags, sdev->scsi_level,
1252 (sdev->inquiry[7] & 2) >> 1);
1253
1254 return sdev->queue_depth;
1255}
1256
1257/**
1258 * _scsih_change_queue_type - changing device queue tag type
1259 * @sdev: scsi device struct
1260 * @tag_type: requested tag type
1261 *
1262 * Returns queue tag type.
1263 */
1264static int
1265_scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1266{
1267 if (sdev->tagged_supported) {
1268 scsi_set_tag_type(sdev, tag_type);
1269 if (tag_type)
1270 scsi_activate_tcq(sdev, sdev->queue_depth);
1271 else
1272 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1273 } else
1274 tag_type = 0;
1275
1276 return tag_type;
1277} 1224}
1278 1225
1279/** 1226/**
@@ -2104,7 +2051,7 @@ _scsih_slave_configure(struct scsi_device *sdev)
2104 r_level, raid_device->handle, 2051 r_level, raid_device->handle,
2105 (unsigned long long)raid_device->wwid, 2052 (unsigned long long)raid_device->wwid,
2106 raid_device->num_pds, ds); 2053 raid_device->num_pds, ds);
2107 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); 2054 _scsih_change_queue_depth(sdev, qdepth);
2108 /* raid transport support */ 2055 /* raid transport support */
2109 if (!ioc->is_warpdrive) 2056 if (!ioc->is_warpdrive)
2110 _scsih_set_level(sdev, raid_device->volume_type); 2057 _scsih_set_level(sdev, raid_device->volume_type);
@@ -2169,7 +2116,7 @@ _scsih_slave_configure(struct scsi_device *sdev)
2169 _scsih_display_sata_capabilities(ioc, handle, sdev); 2116 _scsih_display_sata_capabilities(ioc, handle, sdev);
2170 2117
2171 2118
2172 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); 2119 _scsih_change_queue_depth(sdev, qdepth);
2173 2120
2174 if (ssp_target) { 2121 if (ssp_target) {
2175 sas_read_port_mode_page(sdev); 2122 sas_read_port_mode_page(sdev);
@@ -3966,16 +3913,8 @@ _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3966 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; 3913 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3967 3914
3968 /* set tags */ 3915 /* set tags */
3969 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { 3916 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3970 if (scmd->device->tagged_supported) { 3917
3971 if (scmd->device->ordered_tags)
3972 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3973 else
3974 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3975 } else
3976 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3977 } else
3978 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3979 /* Make sure Device is not raid volume. 3918 /* Make sure Device is not raid volume.
3980 * We do not expose raid functionality to upper layer for warpdrive. 3919 * We do not expose raid functionality to upper layer for warpdrive.
3981 */ 3920 */
@@ -7653,7 +7592,7 @@ static struct scsi_host_template scsih_driver_template = {
7653 .scan_finished = _scsih_scan_finished, 7592 .scan_finished = _scsih_scan_finished,
7654 .scan_start = _scsih_scan_start, 7593 .scan_start = _scsih_scan_start,
7655 .change_queue_depth = _scsih_change_queue_depth, 7594 .change_queue_depth = _scsih_change_queue_depth,
7656 .change_queue_type = _scsih_change_queue_type, 7595 .change_queue_type = scsi_change_queue_type,
7657 .eh_abort_handler = _scsih_abort, 7596 .eh_abort_handler = _scsih_abort,
7658 .eh_device_reset_handler = _scsih_dev_reset, 7597 .eh_device_reset_handler = _scsih_dev_reset,
7659 .eh_target_reset_handler = _scsih_target_reset, 7598 .eh_target_reset_handler = _scsih_target_reset,
@@ -7667,6 +7606,7 @@ static struct scsi_host_template scsih_driver_template = {
7667 .use_clustering = ENABLE_CLUSTERING, 7606 .use_clustering = ENABLE_CLUSTERING,
7668 .shost_attrs = mpt2sas_host_attrs, 7607 .shost_attrs = mpt2sas_host_attrs,
7669 .sdev_attrs = mpt2sas_dev_attrs, 7608 .sdev_attrs = mpt2sas_dev_attrs,
7609 .track_queue_depth = 1,
7670}; 7610};
7671 7611
7672/** 7612/**
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 857276b8880f..a2b60991efd4 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -1053,9 +1053,15 @@ _scsih_scsi_lookup_find_by_lun(struct MPT3SAS_ADAPTER *ioc, int id,
1053 return found; 1053 return found;
1054} 1054}
1055 1055
1056 1056/**
1057static void 1057 * _scsih_change_queue_depth - setting device queue depth
1058_scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth) 1058 * @sdev: scsi device struct
1059 * @qdepth: requested queue depth
1060 *
1061 * Returns queue depth.
1062 */
1063static int
1064_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
1059{ 1065{
1060 struct Scsi_Host *shost = sdev->host; 1066 struct Scsi_Host *shost = sdev->host;
1061 int max_depth; 1067 int max_depth;
@@ -1090,62 +1096,10 @@ _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
1090 max_depth = 1; 1096 max_depth = 1;
1091 if (qdepth > max_depth) 1097 if (qdepth > max_depth)
1092 qdepth = max_depth; 1098 qdepth = max_depth;
1093 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 1099 return scsi_change_queue_depth(sdev, qdepth);
1094} 1100}
1095 1101
1096/** 1102/**
1097 * _scsih_change_queue_depth - setting device queue depth
1098 * @sdev: scsi device struct
1099 * @qdepth: requested queue depth
1100 * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
1101 * (see include/scsi/scsi_host.h for definition)
1102 *
1103 * Returns queue depth.
1104 */
1105static int
1106_scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1107{
1108 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
1109 _scsih_adjust_queue_depth(sdev, qdepth);
1110 else if (reason == SCSI_QDEPTH_QFULL)
1111 scsi_track_queue_full(sdev, qdepth);
1112 else
1113 return -EOPNOTSUPP;
1114
1115 if (sdev->inquiry_len > 7)
1116 sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), " \
1117 "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
1118 sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
1119 sdev->ordered_tags, sdev->scsi_level,
1120 (sdev->inquiry[7] & 2) >> 1);
1121
1122 return sdev->queue_depth;
1123}
1124
1125/**
1126 * _scsih_change_queue_type - changing device queue tag type
1127 * @sdev: scsi device struct
1128 * @tag_type: requested tag type
1129 *
1130 * Returns queue tag type.
1131 */
1132static int
1133_scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
1134{
1135 if (sdev->tagged_supported) {
1136 scsi_set_tag_type(sdev, tag_type);
1137 if (tag_type)
1138 scsi_activate_tcq(sdev, sdev->queue_depth);
1139 else
1140 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1141 } else
1142 tag_type = 0;
1143
1144 return tag_type;
1145}
1146
1147
1148/**
1149 * _scsih_target_alloc - target add routine 1103 * _scsih_target_alloc - target add routine
1150 * @starget: scsi target struct 1104 * @starget: scsi target struct
1151 * 1105 *
@@ -1762,7 +1716,7 @@ _scsih_slave_configure(struct scsi_device *sdev)
1762 raid_device->num_pds, ds); 1716 raid_device->num_pds, ds);
1763 1717
1764 1718
1765 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); 1719 _scsih_change_queue_depth(sdev, qdepth);
1766 1720
1767/* raid transport support */ 1721/* raid transport support */
1768 _scsih_set_level(sdev, raid_device->volume_type); 1722 _scsih_set_level(sdev, raid_device->volume_type);
@@ -1828,7 +1782,7 @@ _scsih_slave_configure(struct scsi_device *sdev)
1828 _scsih_display_sata_capabilities(ioc, handle, sdev); 1782 _scsih_display_sata_capabilities(ioc, handle, sdev);
1829 1783
1830 1784
1831 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); 1785 _scsih_change_queue_depth(sdev, qdepth);
1832 1786
1833 if (ssp_target) { 1787 if (ssp_target) {
1834 sas_read_port_mode_page(sdev); 1788 sas_read_port_mode_page(sdev);
@@ -3586,16 +3540,7 @@ _scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
3586 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER; 3540 mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
3587 3541
3588 /* set tags */ 3542 /* set tags */
3589 if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) { 3543 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3590 if (scmd->device->tagged_supported) {
3591 if (scmd->device->ordered_tags)
3592 mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
3593 else
3594 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3595 } else
3596 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3597 } else
3598 mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
3599 3544
3600 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) && 3545 if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
3601 scmd->cmd_len != 32) 3546 scmd->cmd_len != 32)
@@ -7284,7 +7229,7 @@ static struct scsi_host_template scsih_driver_template = {
7284 .scan_finished = _scsih_scan_finished, 7229 .scan_finished = _scsih_scan_finished,
7285 .scan_start = _scsih_scan_start, 7230 .scan_start = _scsih_scan_start,
7286 .change_queue_depth = _scsih_change_queue_depth, 7231 .change_queue_depth = _scsih_change_queue_depth,
7287 .change_queue_type = _scsih_change_queue_type, 7232 .change_queue_type = scsi_change_queue_type,
7288 .eh_abort_handler = _scsih_abort, 7233 .eh_abort_handler = _scsih_abort,
7289 .eh_device_reset_handler = _scsih_dev_reset, 7234 .eh_device_reset_handler = _scsih_dev_reset,
7290 .eh_target_reset_handler = _scsih_target_reset, 7235 .eh_target_reset_handler = _scsih_target_reset,
@@ -7298,6 +7243,7 @@ static struct scsi_host_template scsih_driver_template = {
7298 .use_clustering = ENABLE_CLUSTERING, 7243 .use_clustering = ENABLE_CLUSTERING,
7299 .shost_attrs = mpt3sas_host_attrs, 7244 .shost_attrs = mpt3sas_host_attrs,
7300 .sdev_attrs = mpt3sas_dev_attrs, 7245 .sdev_attrs = mpt3sas_dev_attrs,
7246 .track_queue_depth = 1,
7301}; 7247};
7302 7248
7303/** 7249/**
diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index eacee48a955c..f15df3de6790 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -26,18 +26,9 @@
26 26
27#include "mv_sas.h" 27#include "mv_sas.h"
28 28
29static int lldd_max_execute_num = 1;
30module_param_named(collector, lldd_max_execute_num, int, S_IRUGO);
31MODULE_PARM_DESC(collector, "\n"
32 "\tIf greater than one, tells the SAS Layer to run in Task Collector\n"
33 "\tMode. If 1 or 0, tells the SAS Layer to run in Direct Mode.\n"
34 "\tThe mvsas SAS LLDD supports both modes.\n"
35 "\tDefault: 1 (Direct Mode).\n");
36
37int interrupt_coalescing = 0x80; 29int interrupt_coalescing = 0x80;
38 30
39static struct scsi_transport_template *mvs_stt; 31static struct scsi_transport_template *mvs_stt;
40struct kmem_cache *mvs_task_list_cache;
41static const struct mvs_chip_info mvs_chips[] = { 32static const struct mvs_chip_info mvs_chips[] = {
42 [chip_6320] = { 1, 2, 0x400, 17, 16, 6, 9, &mvs_64xx_dispatch, }, 33 [chip_6320] = { 1, 2, 0x400, 17, 16, 6, 9, &mvs_64xx_dispatch, },
43 [chip_6440] = { 1, 4, 0x400, 17, 16, 6, 9, &mvs_64xx_dispatch, }, 34 [chip_6440] = { 1, 4, 0x400, 17, 16, 6, 9, &mvs_64xx_dispatch, },
@@ -76,6 +67,8 @@ static struct scsi_host_template mvs_sht = {
76 .target_destroy = sas_target_destroy, 67 .target_destroy = sas_target_destroy,
77 .ioctl = sas_ioctl, 68 .ioctl = sas_ioctl,
78 .shost_attrs = mvst_host_attrs, 69 .shost_attrs = mvst_host_attrs,
70 .use_blk_tags = 1,
71 .track_queue_depth = 1,
79}; 72};
80 73
81static struct sas_domain_function_template mvs_transport_ops = { 74static struct sas_domain_function_template mvs_transport_ops = {
@@ -511,14 +504,11 @@ static void mvs_post_sas_ha_init(struct Scsi_Host *shost,
511 504
512 sha->num_phys = nr_core * chip_info->n_phy; 505 sha->num_phys = nr_core * chip_info->n_phy;
513 506
514 sha->lldd_max_execute_num = lldd_max_execute_num;
515
516 if (mvi->flags & MVF_FLAG_SOC) 507 if (mvi->flags & MVF_FLAG_SOC)
517 can_queue = MVS_SOC_CAN_QUEUE; 508 can_queue = MVS_SOC_CAN_QUEUE;
518 else 509 else
519 can_queue = MVS_CHIP_SLOT_SZ; 510 can_queue = MVS_CHIP_SLOT_SZ;
520 511
521 sha->lldd_queue_size = can_queue;
522 shost->sg_tablesize = min_t(u16, SG_ALL, MVS_MAX_SG); 512 shost->sg_tablesize = min_t(u16, SG_ALL, MVS_MAX_SG);
523 shost->can_queue = can_queue; 513 shost->can_queue = can_queue;
524 mvi->shost->cmd_per_lun = MVS_QUEUE_SIZE; 514 mvi->shost->cmd_per_lun = MVS_QUEUE_SIZE;
@@ -831,16 +821,7 @@ static int __init mvs_init(void)
831 if (!mvs_stt) 821 if (!mvs_stt)
832 return -ENOMEM; 822 return -ENOMEM;
833 823
834 mvs_task_list_cache = kmem_cache_create("mvs_task_list", sizeof(struct mvs_task_list),
835 0, SLAB_HWCACHE_ALIGN, NULL);
836 if (!mvs_task_list_cache) {
837 rc = -ENOMEM;
838 mv_printk("%s: mvs_task_list_cache alloc failed! \n", __func__);
839 goto err_out;
840 }
841
842 rc = pci_register_driver(&mvs_pci_driver); 824 rc = pci_register_driver(&mvs_pci_driver);
843
844 if (rc) 825 if (rc)
845 goto err_out; 826 goto err_out;
846 827
@@ -855,7 +836,6 @@ static void __exit mvs_exit(void)
855{ 836{
856 pci_unregister_driver(&mvs_pci_driver); 837 pci_unregister_driver(&mvs_pci_driver);
857 sas_release_transport(mvs_stt); 838 sas_release_transport(mvs_stt);
858 kmem_cache_destroy(mvs_task_list_cache);
859} 839}
860 840
861struct device_attribute *mvst_host_attrs[] = { 841struct device_attribute *mvst_host_attrs[] = {
diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c
index ac52f7c99513..85d86a5cdb60 100644
--- a/drivers/scsi/mvsas/mv_sas.c
+++ b/drivers/scsi/mvsas/mv_sas.c
@@ -852,43 +852,7 @@ prep_out:
852 return rc; 852 return rc;
853} 853}
854 854
855static struct mvs_task_list *mvs_task_alloc_list(int *num, gfp_t gfp_flags) 855static int mvs_task_exec(struct sas_task *task, gfp_t gfp_flags,
856{
857 struct mvs_task_list *first = NULL;
858
859 for (; *num > 0; --*num) {
860 struct mvs_task_list *mvs_list = kmem_cache_zalloc(mvs_task_list_cache, gfp_flags);
861
862 if (!mvs_list)
863 break;
864
865 INIT_LIST_HEAD(&mvs_list->list);
866 if (!first)
867 first = mvs_list;
868 else
869 list_add_tail(&mvs_list->list, &first->list);
870
871 }
872
873 return first;
874}
875
876static inline void mvs_task_free_list(struct mvs_task_list *mvs_list)
877{
878 LIST_HEAD(list);
879 struct list_head *pos, *a;
880 struct mvs_task_list *mlist = NULL;
881
882 __list_add(&list, mvs_list->list.prev, &mvs_list->list);
883
884 list_for_each_safe(pos, a, &list) {
885 list_del_init(pos);
886 mlist = list_entry(pos, struct mvs_task_list, list);
887 kmem_cache_free(mvs_task_list_cache, mlist);
888 }
889}
890
891static int mvs_task_exec(struct sas_task *task, const int num, gfp_t gfp_flags,
892 struct completion *completion, int is_tmf, 856 struct completion *completion, int is_tmf,
893 struct mvs_tmf_task *tmf) 857 struct mvs_tmf_task *tmf)
894{ 858{
@@ -912,74 +876,9 @@ static int mvs_task_exec(struct sas_task *task, const int num, gfp_t gfp_flags,
912 return rc; 876 return rc;
913} 877}
914 878
915static int mvs_collector_task_exec(struct sas_task *task, const int num, gfp_t gfp_flags, 879int mvs_queue_command(struct sas_task *task, gfp_t gfp_flags)
916 struct completion *completion, int is_tmf,
917 struct mvs_tmf_task *tmf)
918{ 880{
919 struct domain_device *dev = task->dev; 881 return mvs_task_exec(task, gfp_flags, NULL, 0, NULL);
920 struct mvs_prv_info *mpi = dev->port->ha->lldd_ha;
921 struct mvs_info *mvi = NULL;
922 struct sas_task *t = task;
923 struct mvs_task_list *mvs_list = NULL, *a;
924 LIST_HEAD(q);
925 int pass[2] = {0};
926 u32 rc = 0;
927 u32 n = num;
928 unsigned long flags = 0;
929
930 mvs_list = mvs_task_alloc_list(&n, gfp_flags);
931 if (n) {
932 printk(KERN_ERR "%s: mvs alloc list failed.\n", __func__);
933 rc = -ENOMEM;
934 goto free_list;
935 }
936
937 __list_add(&q, mvs_list->list.prev, &mvs_list->list);
938
939 list_for_each_entry(a, &q, list) {
940 a->task = t;
941 t = list_entry(t->list.next, struct sas_task, list);
942 }
943
944 list_for_each_entry(a, &q , list) {
945
946 t = a->task;
947 mvi = ((struct mvs_device *)t->dev->lldd_dev)->mvi_info;
948
949 spin_lock_irqsave(&mvi->lock, flags);
950 rc = mvs_task_prep(t, mvi, is_tmf, tmf, &pass[mvi->id]);
951 if (rc)
952 dev_printk(KERN_ERR, mvi->dev, "mvsas exec failed[%d]!\n", rc);
953 spin_unlock_irqrestore(&mvi->lock, flags);
954 }
955
956 if (likely(pass[0]))
957 MVS_CHIP_DISP->start_delivery(mpi->mvi[0],
958 (mpi->mvi[0]->tx_prod - 1) & (MVS_CHIP_SLOT_SZ - 1));
959
960 if (likely(pass[1]))
961 MVS_CHIP_DISP->start_delivery(mpi->mvi[1],
962 (mpi->mvi[1]->tx_prod - 1) & (MVS_CHIP_SLOT_SZ - 1));
963
964 list_del_init(&q);
965
966free_list:
967 if (mvs_list)
968 mvs_task_free_list(mvs_list);
969
970 return rc;
971}
972
973int mvs_queue_command(struct sas_task *task, const int num,
974 gfp_t gfp_flags)
975{
976 struct mvs_device *mvi_dev = task->dev->lldd_dev;
977 struct sas_ha_struct *sas = mvi_dev->mvi_info->sas;
978
979 if (sas->lldd_max_execute_num < 2)
980 return mvs_task_exec(task, num, gfp_flags, NULL, 0, NULL);
981 else
982 return mvs_collector_task_exec(task, num, gfp_flags, NULL, 0, NULL);
983} 882}
984 883
985static void mvs_slot_free(struct mvs_info *mvi, u32 rx_desc) 884static void mvs_slot_free(struct mvs_info *mvi, u32 rx_desc)
@@ -1411,7 +1310,7 @@ static int mvs_exec_internal_tmf_task(struct domain_device *dev,
1411 task->slow_task->timer.expires = jiffies + MVS_TASK_TIMEOUT*HZ; 1310 task->slow_task->timer.expires = jiffies + MVS_TASK_TIMEOUT*HZ;
1412 add_timer(&task->slow_task->timer); 1311 add_timer(&task->slow_task->timer);
1413 1312
1414 res = mvs_task_exec(task, 1, GFP_KERNEL, NULL, 1, tmf); 1313 res = mvs_task_exec(task, GFP_KERNEL, NULL, 1, tmf);
1415 1314
1416 if (res) { 1315 if (res) {
1417 del_timer(&task->slow_task->timer); 1316 del_timer(&task->slow_task->timer);
diff --git a/drivers/scsi/mvsas/mv_sas.h b/drivers/scsi/mvsas/mv_sas.h
index d6b19dc80bee..dc409c04747a 100644
--- a/drivers/scsi/mvsas/mv_sas.h
+++ b/drivers/scsi/mvsas/mv_sas.h
@@ -65,7 +65,6 @@ extern struct mvs_tgt_initiator mvs_tgt;
65extern struct mvs_info *tgt_mvi; 65extern struct mvs_info *tgt_mvi;
66extern const struct mvs_dispatch mvs_64xx_dispatch; 66extern const struct mvs_dispatch mvs_64xx_dispatch;
67extern const struct mvs_dispatch mvs_94xx_dispatch; 67extern const struct mvs_dispatch mvs_94xx_dispatch;
68extern struct kmem_cache *mvs_task_list_cache;
69 68
70#define DEV_IS_EXPANDER(type) \ 69#define DEV_IS_EXPANDER(type) \
71 ((type == SAS_EDGE_EXPANDER_DEVICE) || (type == SAS_FANOUT_EXPANDER_DEVICE)) 70 ((type == SAS_EDGE_EXPANDER_DEVICE) || (type == SAS_FANOUT_EXPANDER_DEVICE))
@@ -440,12 +439,6 @@ struct mvs_task_exec_info {
440 int n_elem; 439 int n_elem;
441}; 440};
442 441
443struct mvs_task_list {
444 struct sas_task *task;
445 struct list_head list;
446};
447
448
449/******************** function prototype *********************/ 442/******************** function prototype *********************/
450void mvs_get_sas_addr(void *buf, u32 buflen); 443void mvs_get_sas_addr(void *buf, u32 buflen);
451void mvs_tag_clear(struct mvs_info *mvi, u32 tag); 444void mvs_tag_clear(struct mvs_info *mvi, u32 tag);
@@ -462,8 +455,7 @@ void mvs_set_sas_addr(struct mvs_info *mvi, int port_id, u32 off_lo,
462 u32 off_hi, u64 sas_addr); 455 u32 off_hi, u64 sas_addr);
463void mvs_scan_start(struct Scsi_Host *shost); 456void mvs_scan_start(struct Scsi_Host *shost);
464int mvs_scan_finished(struct Scsi_Host *shost, unsigned long time); 457int mvs_scan_finished(struct Scsi_Host *shost, unsigned long time);
465int mvs_queue_command(struct sas_task *task, const int num, 458int mvs_queue_command(struct sas_task *task, gfp_t gfp_flags);
466 gfp_t gfp_flags);
467int mvs_abort_task(struct sas_task *task); 459int mvs_abort_task(struct sas_task *task);
468int mvs_abort_task_set(struct domain_device *dev, u8 *lun); 460int mvs_abort_task_set(struct domain_device *dev, u8 *lun);
469int mvs_clear_aca(struct domain_device *dev, u8 *lun); 461int mvs_clear_aca(struct domain_device *dev, u8 *lun);
diff --git a/drivers/scsi/ncr53c8xx.c b/drivers/scsi/ncr53c8xx.c
index a7305ffc359d..5b93ed810f6e 100644
--- a/drivers/scsi/ncr53c8xx.c
+++ b/drivers/scsi/ncr53c8xx.c
@@ -7997,10 +7997,7 @@ static int ncr53c8xx_slave_configure(struct scsi_device *device)
7997 if (depth_to_use > MAX_TAGS) 7997 if (depth_to_use > MAX_TAGS)
7998 depth_to_use = MAX_TAGS; 7998 depth_to_use = MAX_TAGS;
7999 7999
8000 scsi_adjust_queue_depth(device, 8000 scsi_change_queue_depth(device, depth_to_use);
8001 (device->tagged_supported ?
8002 MSG_SIMPLE_TAG : 0),
8003 depth_to_use);
8004 8001
8005 /* 8002 /*
8006 ** Since the queue depth is not tunable under Linux, 8003 ** Since the queue depth is not tunable under Linux,
diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c
index 92cdd4b06526..243eab3d10d0 100644
--- a/drivers/scsi/osd/osd_uld.c
+++ b/drivers/scsi/osd/osd_uld.c
@@ -540,9 +540,9 @@ static int osd_remove(struct device *dev)
540 */ 540 */
541 541
542static struct scsi_driver osd_driver = { 542static struct scsi_driver osd_driver = {
543 .owner = THIS_MODULE,
544 .gendrv = { 543 .gendrv = {
545 .name = osd_name, 544 .name = osd_name,
545 .owner = THIS_MODULE,
546 .probe = osd_probe, 546 .probe = osd_probe,
547 .remove = osd_remove, 547 .remove = osd_remove,
548 } 548 }
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index dff37a250d79..5033223f6287 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -172,9 +172,9 @@ static int osst_probe(struct device *);
172static int osst_remove(struct device *); 172static int osst_remove(struct device *);
173 173
174static struct scsi_driver osst_template = { 174static struct scsi_driver osst_template = {
175 .owner = THIS_MODULE,
176 .gendrv = { 175 .gendrv = {
177 .name = "osst", 176 .name = "osst",
177 .owner = THIS_MODULE,
178 .probe = osst_probe, 178 .probe = osst_probe,
179 .remove = osst_remove, 179 .remove = osst_remove,
180 } 180 }
@@ -259,9 +259,10 @@ static int osst_chk_result(struct osst_tape * STp, struct osst_request * SRpnt)
259 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2], 259 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2],
260 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]); 260 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]);
261 if (scode) printk(OSST_DEB_MSG "%s:D: Sense: %02x, ASC: %02x, ASCQ: %02x\n", 261 if (scode) printk(OSST_DEB_MSG "%s:D: Sense: %02x, ASC: %02x, ASCQ: %02x\n",
262 name, scode, sense[12], sense[13]); 262 name, scode, sense[12], sense[13]);
263 if (cmdstatp->have_sense) 263 if (cmdstatp->have_sense)
264 __scsi_print_sense("osst ", SRpnt->sense, SCSI_SENSE_BUFFERSIZE); 264 __scsi_print_sense(STp->device, name,
265 SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
265 } 266 }
266 else 267 else
267#endif 268#endif
@@ -275,7 +276,8 @@ static int osst_chk_result(struct osst_tape * STp, struct osst_request * SRpnt)
275 SRpnt->cmd[0] != TEST_UNIT_READY)) { /* Abnormal conditions for tape */ 276 SRpnt->cmd[0] != TEST_UNIT_READY)) { /* Abnormal conditions for tape */
276 if (cmdstatp->have_sense) { 277 if (cmdstatp->have_sense) {
277 printk(KERN_WARNING "%s:W: Command with sense data:\n", name); 278 printk(KERN_WARNING "%s:W: Command with sense data:\n", name);
278 __scsi_print_sense("osst ", SRpnt->sense, SCSI_SENSE_BUFFERSIZE); 279 __scsi_print_sense(STp->device, name,
280 SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
279 } 281 }
280 else { 282 else {
281 static int notyetprinted = 1; 283 static int notyetprinted = 1;
@@ -3325,19 +3327,18 @@ static int osst_write_frame(struct osst_tape * STp, struct osst_request ** aSRpn
3325/* Lock or unlock the drive door. Don't use when struct osst_request allocated. */ 3327/* Lock or unlock the drive door. Don't use when struct osst_request allocated. */
3326static int do_door_lock(struct osst_tape * STp, int do_lock) 3328static int do_door_lock(struct osst_tape * STp, int do_lock)
3327{ 3329{
3328 int retval, cmd; 3330 int retval;
3329 3331
3330 cmd = do_lock ? SCSI_IOCTL_DOORLOCK : SCSI_IOCTL_DOORUNLOCK;
3331#if DEBUG 3332#if DEBUG
3332 printk(OSST_DEB_MSG "%s:D: %socking drive door.\n", tape_name(STp), do_lock ? "L" : "Unl"); 3333 printk(OSST_DEB_MSG "%s:D: %socking drive door.\n", tape_name(STp), do_lock ? "L" : "Unl");
3333#endif 3334#endif
3334 retval = scsi_ioctl(STp->device, cmd, NULL); 3335
3335 if (!retval) { 3336 retval = scsi_set_medium_removal(STp->device,
3337 do_lock ? SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
3338 if (!retval)
3336 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; 3339 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED;
3337 } 3340 else
3338 else {
3339 STp->door_locked = ST_LOCK_FAILS; 3341 STp->door_locked = ST_LOCK_FAILS;
3340 }
3341 return retval; 3342 return retval;
3342} 3343}
3343 3344
@@ -4967,10 +4968,10 @@ static long osst_ioctl(struct file * file,
4967 * may try and take the device offline, in which case all further 4968 * may try and take the device offline, in which case all further
4968 * access to the device is prohibited. 4969 * access to the device is prohibited.
4969 */ 4970 */
4970 if( !scsi_block_when_processing_errors(STp->device) ) { 4971 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in,
4971 retval = (-ENXIO); 4972 file->f_flags & O_NDELAY);
4973 if (retval)
4972 goto out; 4974 goto out;
4973 }
4974 4975
4975 cmd_type = _IOC_TYPE(cmd_in); 4976 cmd_type = _IOC_TYPE(cmd_in);
4976 cmd_nr = _IOC_NR(cmd_in); 4977 cmd_nr = _IOC_NR(cmd_in);
diff --git a/drivers/scsi/pas16.c b/drivers/scsi/pas16.c
index 80bacb5dc1d4..e81eadd08afc 100644
--- a/drivers/scsi/pas16.c
+++ b/drivers/scsi/pas16.c
@@ -1,6 +1,4 @@
1#define AUTOSENSE
2#define PSEUDO_DMA 1#define PSEUDO_DMA
3#define FOO
4#define UNSAFE /* Not unsafe for PAS16 -- use it */ 2#define UNSAFE /* Not unsafe for PAS16 -- use it */
5#define PDEBUG 0 3#define PDEBUG 0
6 4
@@ -24,47 +22,9 @@
24 * Media Vision 22 * Media Vision
25 * (510) 770-8600 23 * (510) 770-8600
26 * (800) 348-7116 24 * (800) 348-7116
27 *
28 * and
29 *
30 * NCR 5380 Family
31 * SCSI Protocol Controller
32 * Databook
33 *
34 * NCR Microelectronics
35 * 1635 Aeroplaza Drive
36 * Colorado Springs, CO 80916
37 * 1+ (719) 578-3400
38 * 1+ (800) 334-5454
39 */ 25 */
40 26
41/* 27/*
42 * Options :
43 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
44 * for commands that return with a CHECK CONDITION status.
45 *
46 * LIMIT_TRANSFERSIZE - if defined, limit the pseudo-dma transfers to 512
47 * bytes at a time. Since interrupts are disabled by default during
48 * these transfers, we might need this to give reasonable interrupt
49 * service time if the transfer size gets too large.
50 *
51 * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
52 * increase compared to polled I/O.
53 *
54 * PARITY - enable parity checking. Not supported.
55 *
56 * SCSI2 - enable support for SCSI-II tagged queueing. Untested.
57 *
58 * UNSAFE - leave interrupts enabled during pseudo-DMA transfers. This
59 * parameter comes from the NCR5380 code. It is NOT unsafe with
60 * the PAS16 and you should use it. If you don't you will have
61 * a problem with dropped characters during high speed
62 * communications during SCSI transfers. If you really don't
63 * want to use UNSAFE you can try defining LIMIT_TRANSFERSIZE or
64 * twiddle with the transfer size in the high level code.
65 *
66 * USLEEP - enable support for devices that don't disconnect. Untested.
67 *
68 * The card is detected and initialized in one of several ways : 28 * The card is detected and initialized in one of several ways :
69 * 1. Autoprobe (default) - There are many different models of 29 * 1. Autoprobe (default) - There are many different models of
70 * the Pro Audio Spectrum/Studio 16, and I only have one of 30 * the Pro Audio Spectrum/Studio 16, and I only have one of
@@ -102,13 +62,11 @@
102 * If you have problems with your card not being recognized, use 62 * If you have problems with your card not being recognized, use
103 * the LILO command line override. Try to get it recognized without 63 * the LILO command line override. Try to get it recognized without
104 * interrupts. Ie, for a board at the default 0x388 base port, 64 * interrupts. Ie, for a board at the default 0x388 base port,
105 * boot: linux pas16=0x388,255 65 * boot: linux pas16=0x388,0
106 * 66 *
107 * SCSI_IRQ_NONE (255) should be specified for no interrupt, 67 * NO_IRQ (0) should be specified for no interrupt,
108 * IRQ_AUTO (254) to autoprobe for an IRQ line if overridden 68 * IRQ_AUTO (254) to autoprobe for an IRQ line if overridden
109 * on the command line. 69 * on the command line.
110 *
111 * (IRQ_AUTO == 254, SCSI_IRQ_NONE == 255 in NCR5380.h)
112 */ 70 */
113 71
114#include <linux/module.h> 72#include <linux/module.h>
@@ -123,15 +81,12 @@
123#include <linux/stat.h> 81#include <linux/stat.h>
124#include <linux/init.h> 82#include <linux/init.h>
125 83
126#include "scsi.h"
127#include <scsi/scsi_host.h> 84#include <scsi/scsi_host.h>
128#include "pas16.h" 85#include "pas16.h"
129#define AUTOPROBE_IRQ 86#define AUTOPROBE_IRQ
130#include "NCR5380.h" 87#include "NCR5380.h"
131 88
132 89
133static int pas_maxi = 0;
134static int pas_wmaxi = 0;
135static unsigned short pas16_addr = 0; 90static unsigned short pas16_addr = 0;
136static int pas16_irq = 0; 91static int pas16_irq = 0;
137 92
@@ -337,6 +292,7 @@ static int __init
337} 292}
338 293
339 294
295#ifndef MODULE
340/* 296/*
341 * Function : pas16_setup(char *str, int *ints) 297 * Function : pas16_setup(char *str, int *ints)
342 * 298 *
@@ -347,10 +303,13 @@ static int __init
347 * 303 *
348 */ 304 */
349 305
350void __init pas16_setup(char *str, int *ints) 306static int __init pas16_setup(char *str)
351{ 307{
352 static int commandline_current = 0; 308 static int commandline_current = 0;
353 int i; 309 int i;
310 int ints[10];
311
312 get_options(str, ARRAY_SIZE(ints), ints);
354 if (ints[0] != 2) 313 if (ints[0] != 2)
355 printk("pas16_setup : usage pas16=io_port,irq\n"); 314 printk("pas16_setup : usage pas16=io_port,irq\n");
356 else 315 else
@@ -364,8 +323,12 @@ void __init pas16_setup(char *str, int *ints)
364 } 323 }
365 ++commandline_current; 324 ++commandline_current;
366 } 325 }
326 return 1;
367} 327}
368 328
329__setup("pas16=", pas16_setup);
330#endif
331
369/* 332/*
370 * Function : int pas16_detect(struct scsi_host_template * tpnt) 333 * Function : int pas16_detect(struct scsi_host_template * tpnt)
371 * 334 *
@@ -379,7 +342,7 @@ void __init pas16_setup(char *str, int *ints)
379 * 342 *
380 */ 343 */
381 344
382int __init pas16_detect(struct scsi_host_template * tpnt) 345static int __init pas16_detect(struct scsi_host_template *tpnt)
383{ 346{
384 static int current_override = 0; 347 static int current_override = 0;
385 static unsigned short current_base = 0; 348 static unsigned short current_base = 0;
@@ -387,10 +350,6 @@ int __init pas16_detect(struct scsi_host_template * tpnt)
387 unsigned short io_port; 350 unsigned short io_port;
388 int count; 351 int count;
389 352
390 tpnt->proc_name = "pas16";
391 tpnt->show_info = pas16_show_info;
392 tpnt->write_info = pas16_write_info;
393
394 if (pas16_addr != 0) { 353 if (pas16_addr != 0) {
395 overrides[0].io_port = pas16_addr; 354 overrides[0].io_port = pas16_addr;
396 /* 355 /*
@@ -452,15 +411,19 @@ int __init pas16_detect(struct scsi_host_template * tpnt)
452 else 411 else
453 instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS); 412 instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS);
454 413
455 if (instance->irq != SCSI_IRQ_NONE) 414 /* Compatibility with documented NCR5380 kernel parameters */
415 if (instance->irq == 255)
416 instance->irq = NO_IRQ;
417
418 if (instance->irq != NO_IRQ)
456 if (request_irq(instance->irq, pas16_intr, 0, 419 if (request_irq(instance->irq, pas16_intr, 0,
457 "pas16", instance)) { 420 "pas16", instance)) {
458 printk("scsi%d : IRQ%d not free, interrupts disabled\n", 421 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
459 instance->host_no, instance->irq); 422 instance->host_no, instance->irq);
460 instance->irq = SCSI_IRQ_NONE; 423 instance->irq = NO_IRQ;
461 } 424 }
462 425
463 if (instance->irq == SCSI_IRQ_NONE) { 426 if (instance->irq == NO_IRQ) {
464 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no); 427 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
465 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no); 428 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
466 /* Disable 5380 interrupts, leave drive params the same */ 429 /* Disable 5380 interrupts, leave drive params the same */
@@ -472,17 +435,6 @@ int __init pas16_detect(struct scsi_host_template * tpnt)
472 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq); 435 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
473#endif 436#endif
474 437
475 printk("scsi%d : at 0x%04x", instance->host_no, (int)
476 instance->io_port);
477 if (instance->irq == SCSI_IRQ_NONE)
478 printk (" interrupts disabled");
479 else
480 printk (" irq %d", instance->irq);
481 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
482 CAN_QUEUE, CMD_PER_LUN, PAS16_PUBLIC_RELEASE);
483 NCR5380_print_options(instance);
484 printk("\n");
485
486 ++current_override; 438 ++current_override;
487 ++count; 439 ++count;
488 } 440 }
@@ -509,8 +461,8 @@ int __init pas16_detect(struct scsi_host_template * tpnt)
509 * and matching the H_C_S coordinates to what DOS uses. 461 * and matching the H_C_S coordinates to what DOS uses.
510 */ 462 */
511 463
512int pas16_biosparam(struct scsi_device *sdev, struct block_device *dev, 464static int pas16_biosparam(struct scsi_device *sdev, struct block_device *dev,
513 sector_t capacity, int * ip) 465 sector_t capacity, int *ip)
514{ 466{
515 int size = capacity; 467 int size = capacity;
516 ip[0] = 64; 468 ip[0] = 64;
@@ -547,6 +499,7 @@ static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
547 P_DATA_REG_OFFSET); 499 P_DATA_REG_OFFSET);
548 register int i = len; 500 register int i = len;
549 int ii = 0; 501 int ii = 0;
502 struct NCR5380_hostdata *hostdata = shost_priv(instance);
550 503
551 while ( !(inb(instance->io_port + P_STATUS_REG_OFFSET) & P_ST_RDY) ) 504 while ( !(inb(instance->io_port + P_STATUS_REG_OFFSET) & P_ST_RDY) )
552 ++ii; 505 ++ii;
@@ -559,8 +512,8 @@ static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
559 instance->host_no); 512 instance->host_no);
560 return -1; 513 return -1;
561 } 514 }
562 if (ii > pas_maxi) 515 if (ii > hostdata->spin_max_r)
563 pas_maxi = ii; 516 hostdata->spin_max_r = ii;
564 return 0; 517 return 0;
565} 518}
566 519
@@ -583,6 +536,7 @@ static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src
583 register unsigned short reg = (instance->io_port + P_DATA_REG_OFFSET); 536 register unsigned short reg = (instance->io_port + P_DATA_REG_OFFSET);
584 register int i = len; 537 register int i = len;
585 int ii = 0; 538 int ii = 0;
539 struct NCR5380_hostdata *hostdata = shost_priv(instance);
586 540
587 while ( !((inb(instance->io_port + P_STATUS_REG_OFFSET)) & P_ST_RDY) ) 541 while ( !((inb(instance->io_port + P_STATUS_REG_OFFSET)) & P_ST_RDY) )
588 ++ii; 542 ++ii;
@@ -595,8 +549,8 @@ static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src
595 instance->host_no); 549 instance->host_no);
596 return -1; 550 return -1;
597 } 551 }
598 if (ii > pas_maxi) 552 if (ii > hostdata->spin_max_w)
599 pas_wmaxi = ii; 553 hostdata->spin_max_w = ii;
600 return 0; 554 return 0;
601} 555}
602 556
@@ -604,7 +558,7 @@ static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src
604 558
605static int pas16_release(struct Scsi_Host *shost) 559static int pas16_release(struct Scsi_Host *shost)
606{ 560{
607 if (shost->irq) 561 if (shost->irq != NO_IRQ)
608 free_irq(shost->irq, shost); 562 free_irq(shost->irq, shost);
609 NCR5380_exit(shost); 563 NCR5380_exit(shost);
610 if (shost->io_port && shost->n_io_port) 564 if (shost->io_port && shost->n_io_port)
@@ -617,6 +571,10 @@ static struct scsi_host_template driver_template = {
617 .name = "Pro Audio Spectrum-16 SCSI", 571 .name = "Pro Audio Spectrum-16 SCSI",
618 .detect = pas16_detect, 572 .detect = pas16_detect,
619 .release = pas16_release, 573 .release = pas16_release,
574 .proc_name = "pas16",
575 .show_info = pas16_show_info,
576 .write_info = pas16_write_info,
577 .info = pas16_info,
620 .queuecommand = pas16_queue_command, 578 .queuecommand = pas16_queue_command,
621 .eh_abort_handler = pas16_abort, 579 .eh_abort_handler = pas16_abort,
622 .eh_bus_reset_handler = pas16_bus_reset, 580 .eh_bus_reset_handler = pas16_bus_reset,
diff --git a/drivers/scsi/pas16.h b/drivers/scsi/pas16.h
index aa528f53c533..c6109c80050b 100644
--- a/drivers/scsi/pas16.h
+++ b/drivers/scsi/pas16.h
@@ -18,26 +18,12 @@
18 * Media Vision 18 * Media Vision
19 * (510) 770-8600 19 * (510) 770-8600
20 * (800) 348-7116 20 * (800) 348-7116
21 *
22 * and
23 *
24 * NCR 5380 Family
25 * SCSI Protocol Controller
26 * Databook
27 *
28 * NCR Microelectronics
29 * 1635 Aeroplaza Drive
30 * Colorado Springs, CO 80916
31 * 1+ (719) 578-3400
32 * 1+ (800) 334-5454
33 */ 21 */
34 22
35 23
36#ifndef PAS16_H 24#ifndef PAS16_H
37#define PAS16_H 25#define PAS16_H
38 26
39#define PAS16_PUBLIC_RELEASE 3
40
41#define PDEBUG_INIT 0x1 27#define PDEBUG_INIT 0x1
42#define PDEBUG_TRANSFER 0x2 28#define PDEBUG_TRANSFER 0x2
43 29
@@ -114,12 +100,6 @@
114 100
115 101
116#ifndef ASM 102#ifndef ASM
117static int pas16_abort(Scsi_Cmnd *);
118static int pas16_biosparam(struct scsi_device *, struct block_device *,
119 sector_t, int*);
120static int pas16_detect(struct scsi_host_template *);
121static int pas16_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
122static int pas16_bus_reset(Scsi_Cmnd *);
123 103
124#ifndef CMD_PER_LUN 104#ifndef CMD_PER_LUN
125#define CMD_PER_LUN 2 105#define CMD_PER_LUN 2
@@ -161,6 +141,7 @@ static int pas16_bus_reset(Scsi_Cmnd *);
161#define NCR5380_queue_command pas16_queue_command 141#define NCR5380_queue_command pas16_queue_command
162#define NCR5380_abort pas16_abort 142#define NCR5380_abort pas16_abort
163#define NCR5380_bus_reset pas16_bus_reset 143#define NCR5380_bus_reset pas16_bus_reset
144#define NCR5380_info pas16_info
164#define NCR5380_show_info pas16_show_info 145#define NCR5380_show_info pas16_show_info
165#define NCR5380_write_info pas16_write_info 146#define NCR5380_write_info pas16_write_info
166 147
diff --git a/drivers/scsi/pm8001/pm8001_init.c b/drivers/scsi/pm8001/pm8001_init.c
index 666bf5af06e2..329aba0083ab 100644
--- a/drivers/scsi/pm8001/pm8001_init.c
+++ b/drivers/scsi/pm8001/pm8001_init.c
@@ -89,6 +89,8 @@ static struct scsi_host_template pm8001_sht = {
89 .target_destroy = sas_target_destroy, 89 .target_destroy = sas_target_destroy,
90 .ioctl = sas_ioctl, 90 .ioctl = sas_ioctl,
91 .shost_attrs = pm8001_host_attrs, 91 .shost_attrs = pm8001_host_attrs,
92 .use_blk_tags = 1,
93 .track_queue_depth = 1,
92}; 94};
93 95
94/** 96/**
@@ -599,8 +601,6 @@ static void pm8001_post_sas_ha_init(struct Scsi_Host *shost,
599 sha->lldd_module = THIS_MODULE; 601 sha->lldd_module = THIS_MODULE;
600 sha->sas_addr = &pm8001_ha->sas_addr[0]; 602 sha->sas_addr = &pm8001_ha->sas_addr[0];
601 sha->num_phys = chip_info->n_phy; 603 sha->num_phys = chip_info->n_phy;
602 sha->lldd_max_execute_num = 1;
603 sha->lldd_queue_size = PM8001_CAN_QUEUE;
604 sha->core.shost = shost; 604 sha->core.shost = shost;
605} 605}
606 606
diff --git a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c
index 76570e6a547d..b93f289b42b3 100644
--- a/drivers/scsi/pm8001/pm8001_sas.c
+++ b/drivers/scsi/pm8001/pm8001_sas.c
@@ -350,7 +350,7 @@ static int sas_find_local_port_id(struct domain_device *dev)
350 */ 350 */
351#define DEV_IS_GONE(pm8001_dev) \ 351#define DEV_IS_GONE(pm8001_dev) \
352 ((!pm8001_dev || (pm8001_dev->dev_type == SAS_PHY_UNUSED))) 352 ((!pm8001_dev || (pm8001_dev->dev_type == SAS_PHY_UNUSED)))
353static int pm8001_task_exec(struct sas_task *task, const int num, 353static int pm8001_task_exec(struct sas_task *task,
354 gfp_t gfp_flags, int is_tmf, struct pm8001_tmf_task *tmf) 354 gfp_t gfp_flags, int is_tmf, struct pm8001_tmf_task *tmf)
355{ 355{
356 struct domain_device *dev = task->dev; 356 struct domain_device *dev = task->dev;
@@ -360,7 +360,6 @@ static int pm8001_task_exec(struct sas_task *task, const int num,
360 struct sas_task *t = task; 360 struct sas_task *t = task;
361 struct pm8001_ccb_info *ccb; 361 struct pm8001_ccb_info *ccb;
362 u32 tag = 0xdeadbeef, rc, n_elem = 0; 362 u32 tag = 0xdeadbeef, rc, n_elem = 0;
363 u32 n = num;
364 unsigned long flags = 0; 363 unsigned long flags = 0;
365 364
366 if (!dev->port) { 365 if (!dev->port) {
@@ -387,18 +386,12 @@ static int pm8001_task_exec(struct sas_task *task, const int num,
387 spin_unlock_irqrestore(&pm8001_ha->lock, flags); 386 spin_unlock_irqrestore(&pm8001_ha->lock, flags);
388 t->task_done(t); 387 t->task_done(t);
389 spin_lock_irqsave(&pm8001_ha->lock, flags); 388 spin_lock_irqsave(&pm8001_ha->lock, flags);
390 if (n > 1)
391 t = list_entry(t->list.next,
392 struct sas_task, list);
393 continue; 389 continue;
394 } else { 390 } else {
395 struct task_status_struct *ts = &t->task_status; 391 struct task_status_struct *ts = &t->task_status;
396 ts->resp = SAS_TASK_UNDELIVERED; 392 ts->resp = SAS_TASK_UNDELIVERED;
397 ts->stat = SAS_PHY_DOWN; 393 ts->stat = SAS_PHY_DOWN;
398 t->task_done(t); 394 t->task_done(t);
399 if (n > 1)
400 t = list_entry(t->list.next,
401 struct sas_task, list);
402 continue; 395 continue;
403 } 396 }
404 } 397 }
@@ -460,9 +453,7 @@ static int pm8001_task_exec(struct sas_task *task, const int num,
460 t->task_state_flags |= SAS_TASK_AT_INITIATOR; 453 t->task_state_flags |= SAS_TASK_AT_INITIATOR;
461 spin_unlock(&t->task_state_lock); 454 spin_unlock(&t->task_state_lock);
462 pm8001_dev->running_req++; 455 pm8001_dev->running_req++;
463 if (n > 1) 456 } while (0);
464 t = list_entry(t->list.next, struct sas_task, list);
465 } while (--n);
466 rc = 0; 457 rc = 0;
467 goto out_done; 458 goto out_done;
468 459
@@ -483,14 +474,11 @@ out_done:
483 * pm8001_queue_command - register for upper layer used, all IO commands sent 474 * pm8001_queue_command - register for upper layer used, all IO commands sent
484 * to HBA are from this interface. 475 * to HBA are from this interface.
485 * @task: the task to be execute. 476 * @task: the task to be execute.
486 * @num: if can_queue great than 1, the task can be queued up. for SMP task,
487 * we always execute one one time
488 * @gfp_flags: gfp_flags 477 * @gfp_flags: gfp_flags
489 */ 478 */
490int pm8001_queue_command(struct sas_task *task, const int num, 479int pm8001_queue_command(struct sas_task *task, gfp_t gfp_flags)
491 gfp_t gfp_flags)
492{ 480{
493 return pm8001_task_exec(task, num, gfp_flags, 0, NULL); 481 return pm8001_task_exec(task, gfp_flags, 0, NULL);
494} 482}
495 483
496/** 484/**
@@ -708,7 +696,7 @@ static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
708 task->slow_task->timer.expires = jiffies + PM8001_TASK_TIMEOUT*HZ; 696 task->slow_task->timer.expires = jiffies + PM8001_TASK_TIMEOUT*HZ;
709 add_timer(&task->slow_task->timer); 697 add_timer(&task->slow_task->timer);
710 698
711 res = pm8001_task_exec(task, 1, GFP_KERNEL, 1, tmf); 699 res = pm8001_task_exec(task, GFP_KERNEL, 1, tmf);
712 700
713 if (res) { 701 if (res) {
714 del_timer(&task->slow_task->timer); 702 del_timer(&task->slow_task->timer);
diff --git a/drivers/scsi/pm8001/pm8001_sas.h b/drivers/scsi/pm8001/pm8001_sas.h
index f6b2ac59dae4..8dd8b7840f04 100644
--- a/drivers/scsi/pm8001/pm8001_sas.h
+++ b/drivers/scsi/pm8001/pm8001_sas.h
@@ -623,8 +623,7 @@ int pm8001_phy_control(struct asd_sas_phy *sas_phy, enum phy_func func,
623 void *funcdata); 623 void *funcdata);
624void pm8001_scan_start(struct Scsi_Host *shost); 624void pm8001_scan_start(struct Scsi_Host *shost);
625int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time); 625int pm8001_scan_finished(struct Scsi_Host *shost, unsigned long time);
626int pm8001_queue_command(struct sas_task *task, const int num, 626int pm8001_queue_command(struct sas_task *task, gfp_t gfp_flags);
627 gfp_t gfp_flags);
628int pm8001_abort_task(struct sas_task *task); 627int pm8001_abort_task(struct sas_task *task);
629int pm8001_abort_task_set(struct domain_device *dev, u8 *lun); 628int pm8001_abort_task_set(struct domain_device *dev, u8 *lun);
630int pm8001_clear_aca(struct domain_device *dev, u8 *lun); 629int pm8001_clear_aca(struct domain_device *dev, u8 *lun);
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index bcb64eb1387f..b1b1f66b1ab7 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -249,15 +249,11 @@ static int pmcraid_slave_configure(struct scsi_device *scsi_dev)
249 PMCRAID_VSET_MAX_SECTORS); 249 PMCRAID_VSET_MAX_SECTORS);
250 } 250 }
251 251
252 if (scsi_dev->tagged_supported && 252 /*
253 (RES_IS_GSCSI(res->cfg_entry) || RES_IS_VSET(res->cfg_entry))) { 253 * We never want to report TCQ support for these types of devices.
254 scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth); 254 */
255 scsi_adjust_queue_depth(scsi_dev, MSG_SIMPLE_TAG, 255 if (!RES_IS_GSCSI(res->cfg_entry) && !RES_IS_VSET(res->cfg_entry))
256 scsi_dev->host->cmd_per_lun); 256 scsi_dev->tagged_supported = 0;
257 } else {
258 scsi_adjust_queue_depth(scsi_dev, 0,
259 scsi_dev->host->cmd_per_lun);
260 }
261 257
262 return 0; 258 return 0;
263} 259}
@@ -289,55 +285,18 @@ static void pmcraid_slave_destroy(struct scsi_device *scsi_dev)
289 * pmcraid_change_queue_depth - Change the device's queue depth 285 * pmcraid_change_queue_depth - Change the device's queue depth
290 * @scsi_dev: scsi device struct 286 * @scsi_dev: scsi device struct
291 * @depth: depth to set 287 * @depth: depth to set
292 * @reason: calling context
293 * 288 *
294 * Return value 289 * Return value
295 * actual depth set 290 * actual depth set
296 */ 291 */
297static int pmcraid_change_queue_depth(struct scsi_device *scsi_dev, int depth, 292static int pmcraid_change_queue_depth(struct scsi_device *scsi_dev, int depth)
298 int reason)
299{ 293{
300 if (reason != SCSI_QDEPTH_DEFAULT)
301 return -EOPNOTSUPP;
302
303 if (depth > PMCRAID_MAX_CMD_PER_LUN) 294 if (depth > PMCRAID_MAX_CMD_PER_LUN)
304 depth = PMCRAID_MAX_CMD_PER_LUN; 295 depth = PMCRAID_MAX_CMD_PER_LUN;
305 296 return scsi_change_queue_depth(scsi_dev, depth);
306 scsi_adjust_queue_depth(scsi_dev, scsi_get_tag_type(scsi_dev), depth);
307
308 return scsi_dev->queue_depth;
309} 297}
310 298
311/** 299/**
312 * pmcraid_change_queue_type - Change the device's queue type
313 * @scsi_dev: scsi device struct
314 * @tag: type of tags to use
315 *
316 * Return value:
317 * actual queue type set
318 */
319static int pmcraid_change_queue_type(struct scsi_device *scsi_dev, int tag)
320{
321 struct pmcraid_resource_entry *res;
322
323 res = (struct pmcraid_resource_entry *)scsi_dev->hostdata;
324
325 if ((res) && scsi_dev->tagged_supported &&
326 (RES_IS_GSCSI(res->cfg_entry) || RES_IS_VSET(res->cfg_entry))) {
327 scsi_set_tag_type(scsi_dev, tag);
328
329 if (tag)
330 scsi_activate_tcq(scsi_dev, scsi_dev->queue_depth);
331 else
332 scsi_deactivate_tcq(scsi_dev, scsi_dev->queue_depth);
333 } else
334 tag = 0;
335
336 return tag;
337}
338
339
340/**
341 * pmcraid_init_cmdblk - initializes a command block 300 * pmcraid_init_cmdblk - initializes a command block
342 * 301 *
343 * @cmd: pointer to struct pmcraid_cmd to be initialized 302 * @cmd: pointer to struct pmcraid_cmd to be initialized
@@ -3175,36 +3134,6 @@ static int pmcraid_eh_host_reset_handler(struct scsi_cmnd *scmd)
3175} 3134}
3176 3135
3177/** 3136/**
3178 * pmcraid_task_attributes - Translate SPI Q-Tags to task attributes
3179 * @scsi_cmd: scsi command struct
3180 *
3181 * Return value
3182 * number of tags or 0 if the task is not tagged
3183 */
3184static u8 pmcraid_task_attributes(struct scsi_cmnd *scsi_cmd)
3185{
3186 char tag[2];
3187 u8 rc = 0;
3188
3189 if (scsi_populate_tag_msg(scsi_cmd, tag)) {
3190 switch (tag[0]) {
3191 case MSG_SIMPLE_TAG:
3192 rc = TASK_TAG_SIMPLE;
3193 break;
3194 case MSG_HEAD_TAG:
3195 rc = TASK_TAG_QUEUE_HEAD;
3196 break;
3197 case MSG_ORDERED_TAG:
3198 rc = TASK_TAG_ORDERED;
3199 break;
3200 };
3201 }
3202
3203 return rc;
3204}
3205
3206
3207/**
3208 * pmcraid_init_ioadls - initializes IOADL related fields in IOARCB 3137 * pmcraid_init_ioadls - initializes IOADL related fields in IOARCB
3209 * @cmd: pmcraid command struct 3138 * @cmd: pmcraid command struct
3210 * @sgcount: count of scatter-gather elements 3139 * @sgcount: count of scatter-gather elements
@@ -3559,7 +3488,9 @@ static int pmcraid_queuecommand_lck(
3559 } 3488 }
3560 3489
3561 ioarcb->request_flags0 |= NO_LINK_DESCS; 3490 ioarcb->request_flags0 |= NO_LINK_DESCS;
3562 ioarcb->request_flags1 |= pmcraid_task_attributes(scsi_cmd); 3491
3492 if (scsi_cmd->flags & SCMD_TAGGED)
3493 ioarcb->request_flags1 |= TASK_TAG_SIMPLE;
3563 3494
3564 if (RES_IS_GSCSI(res->cfg_entry)) 3495 if (RES_IS_GSCSI(res->cfg_entry))
3565 ioarcb->request_flags1 |= DELAY_AFTER_RESET; 3496 ioarcb->request_flags1 |= DELAY_AFTER_RESET;
@@ -4320,7 +4251,7 @@ static struct scsi_host_template pmcraid_host_template = {
4320 .slave_configure = pmcraid_slave_configure, 4251 .slave_configure = pmcraid_slave_configure,
4321 .slave_destroy = pmcraid_slave_destroy, 4252 .slave_destroy = pmcraid_slave_destroy,
4322 .change_queue_depth = pmcraid_change_queue_depth, 4253 .change_queue_depth = pmcraid_change_queue_depth,
4323 .change_queue_type = pmcraid_change_queue_type, 4254 .change_queue_type = scsi_change_queue_type,
4324 .can_queue = PMCRAID_MAX_IO_CMD, 4255 .can_queue = PMCRAID_MAX_IO_CMD,
4325 .this_id = -1, 4256 .this_id = -1,
4326 .sg_tablesize = PMCRAID_MAX_IOADLS, 4257 .sg_tablesize = PMCRAID_MAX_IOADLS,
@@ -4329,7 +4260,8 @@ static struct scsi_host_template pmcraid_host_template = {
4329 .cmd_per_lun = PMCRAID_MAX_CMD_PER_LUN, 4260 .cmd_per_lun = PMCRAID_MAX_CMD_PER_LUN,
4330 .use_clustering = ENABLE_CLUSTERING, 4261 .use_clustering = ENABLE_CLUSTERING,
4331 .shost_attrs = pmcraid_host_attrs, 4262 .shost_attrs = pmcraid_host_attrs,
4332 .proc_name = PMCRAID_DRIVER_NAME 4263 .proc_name = PMCRAID_DRIVER_NAME,
4264 .use_blk_tags = 1,
4333}; 4265};
4334 4266
4335/* 4267/*
diff --git a/drivers/scsi/ps3rom.c b/drivers/scsi/ps3rom.c
index ef23fabe3924..b3b48b5a984c 100644
--- a/drivers/scsi/ps3rom.c
+++ b/drivers/scsi/ps3rom.c
@@ -220,10 +220,6 @@ static int ps3rom_queuecommand_lck(struct scsi_cmnd *cmd,
220 unsigned char opcode; 220 unsigned char opcode;
221 int res; 221 int res;
222 222
223#ifdef DEBUG
224 scsi_print_command(cmd);
225#endif
226
227 priv->curr_cmd = cmd; 223 priv->curr_cmd = cmd;
228 cmd->scsi_done = done; 224 cmd->scsi_done = done;
229 225
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 158020522dfb..c68a66e8cfc1 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -1224,10 +1224,9 @@ qla1280_slave_configure(struct scsi_device *device)
1224 1224
1225 if (device->tagged_supported && 1225 if (device->tagged_supported &&
1226 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) { 1226 (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
1227 scsi_adjust_queue_depth(device, MSG_ORDERED_TAG, 1227 scsi_change_queue_depth(device, ha->bus_settings[bus].hiwat);
1228 ha->bus_settings[bus].hiwat);
1229 } else { 1228 } else {
1230 scsi_adjust_queue_depth(device, 0, default_depth); 1229 scsi_change_queue_depth(device, default_depth);
1231 } 1230 }
1232 1231
1233 nv->bus[bus].target[target].parameter.enable_sync = device->sdtr; 1232 nv->bus[bus].target[target].parameter.enable_sync = device->sdtr;
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index b1865a72ce59..7686bfe9a4a9 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -752,8 +752,6 @@ extern void qla8044_set_idc_dontreset(struct scsi_qla_host *ha);
752extern int qla8044_rd_direct(struct scsi_qla_host *vha, const uint32_t crb_reg); 752extern int qla8044_rd_direct(struct scsi_qla_host *vha, const uint32_t crb_reg);
753extern void qla8044_wr_direct(struct scsi_qla_host *vha, 753extern void qla8044_wr_direct(struct scsi_qla_host *vha,
754 const uint32_t crb_reg, const uint32_t value); 754 const uint32_t crb_reg, const uint32_t value);
755extern inline void qla8044_set_qsnt_ready(struct scsi_qla_host *vha);
756extern inline void qla8044_need_reset_handler(struct scsi_qla_host *vha);
757extern int qla8044_device_state_handler(struct scsi_qla_host *vha); 755extern int qla8044_device_state_handler(struct scsi_qla_host *vha);
758extern void qla8044_clear_qsnt_ready(struct scsi_qla_host *vha); 756extern void qla8044_clear_qsnt_ready(struct scsi_qla_host *vha);
759extern void qla8044_clear_drv_active(struct qla_hw_data *); 757extern void qla8044_clear_drv_active(struct qla_hw_data *);
diff --git a/drivers/scsi/qla2xxx/qla_iocb.c b/drivers/scsi/qla2xxx/qla_iocb.c
index f0edb07f3198..a1ab25fca874 100644
--- a/drivers/scsi/qla2xxx/qla_iocb.c
+++ b/drivers/scsi/qla2xxx/qla_iocb.c
@@ -325,7 +325,6 @@ qla2x00_start_scsi(srb_t *sp)
325 struct qla_hw_data *ha; 325 struct qla_hw_data *ha;
326 struct req_que *req; 326 struct req_que *req;
327 struct rsp_que *rsp; 327 struct rsp_que *rsp;
328 char tag[2];
329 328
330 /* Setup device pointers. */ 329 /* Setup device pointers. */
331 ret = 0; 330 ret = 0;
@@ -404,26 +403,7 @@ qla2x00_start_scsi(srb_t *sp)
404 /* Set target ID and LUN number*/ 403 /* Set target ID and LUN number*/
405 SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id); 404 SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id);
406 cmd_pkt->lun = cpu_to_le16(cmd->device->lun); 405 cmd_pkt->lun = cpu_to_le16(cmd->device->lun);
407 406 cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG);
408 /* Update tagged queuing modifier */
409 if (scsi_populate_tag_msg(cmd, tag)) {
410 switch (tag[0]) {
411 case HEAD_OF_QUEUE_TAG:
412 cmd_pkt->control_flags =
413 __constant_cpu_to_le16(CF_HEAD_TAG);
414 break;
415 case ORDERED_QUEUE_TAG:
416 cmd_pkt->control_flags =
417 __constant_cpu_to_le16(CF_ORDERED_TAG);
418 break;
419 default:
420 cmd_pkt->control_flags =
421 __constant_cpu_to_le16(CF_SIMPLE_TAG);
422 break;
423 }
424 } else {
425 cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG);
426 }
427 407
428 /* Load SCSI command packet. */ 408 /* Load SCSI command packet. */
429 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len); 409 memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len);
@@ -1264,7 +1244,6 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
1264 uint16_t fcp_cmnd_len; 1244 uint16_t fcp_cmnd_len;
1265 struct fcp_cmnd *fcp_cmnd; 1245 struct fcp_cmnd *fcp_cmnd;
1266 dma_addr_t crc_ctx_dma; 1246 dma_addr_t crc_ctx_dma;
1267 char tag[2];
1268 1247
1269 cmd = GET_CMD_SP(sp); 1248 cmd = GET_CMD_SP(sp);
1270 1249
@@ -1356,25 +1335,7 @@ qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
1356 cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32( 1335 cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32(
1357 MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); 1336 MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF));
1358 fcp_cmnd->task_management = 0; 1337 fcp_cmnd->task_management = 0;
1359 1338 fcp_cmnd->task_attribute = TSK_SIMPLE;
1360 /*
1361 * Update tagged queuing modifier if using command tag queuing
1362 */
1363 if (scsi_populate_tag_msg(cmd, tag)) {
1364 switch (tag[0]) {
1365 case HEAD_OF_QUEUE_TAG:
1366 fcp_cmnd->task_attribute = TSK_HEAD_OF_QUEUE;
1367 break;
1368 case ORDERED_QUEUE_TAG:
1369 fcp_cmnd->task_attribute = TSK_ORDERED;
1370 break;
1371 default:
1372 fcp_cmnd->task_attribute = TSK_SIMPLE;
1373 break;
1374 }
1375 } else {
1376 fcp_cmnd->task_attribute = TSK_SIMPLE;
1377 }
1378 1339
1379 cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */ 1340 cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */
1380 1341
@@ -1495,7 +1456,6 @@ qla24xx_start_scsi(srb_t *sp)
1495 struct scsi_cmnd *cmd = GET_CMD_SP(sp); 1456 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
1496 struct scsi_qla_host *vha = sp->fcport->vha; 1457 struct scsi_qla_host *vha = sp->fcport->vha;
1497 struct qla_hw_data *ha = vha->hw; 1458 struct qla_hw_data *ha = vha->hw;
1498 char tag[2];
1499 1459
1500 /* Setup device pointers. */ 1460 /* Setup device pointers. */
1501 ret = 0; 1461 ret = 0;
@@ -1578,22 +1538,7 @@ qla24xx_start_scsi(srb_t *sp)
1578 int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); 1538 int_to_scsilun(cmd->device->lun, &cmd_pkt->lun);
1579 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); 1539 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
1580 1540
1581 /* Update tagged queuing modifier -- default is TSK_SIMPLE (0). */ 1541 cmd_pkt->task = TSK_SIMPLE;
1582 if (scsi_populate_tag_msg(cmd, tag)) {
1583 switch (tag[0]) {
1584 case HEAD_OF_QUEUE_TAG:
1585 cmd_pkt->task = TSK_HEAD_OF_QUEUE;
1586 break;
1587 case ORDERED_QUEUE_TAG:
1588 cmd_pkt->task = TSK_ORDERED;
1589 break;
1590 default:
1591 cmd_pkt->task = TSK_SIMPLE;
1592 break;
1593 }
1594 } else {
1595 cmd_pkt->task = TSK_SIMPLE;
1596 }
1597 1542
1598 /* Load SCSI command packet. */ 1543 /* Load SCSI command packet. */
1599 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); 1544 memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len);
@@ -2310,7 +2255,6 @@ qla82xx_start_scsi(srb_t *sp)
2310 struct qla_hw_data *ha = vha->hw; 2255 struct qla_hw_data *ha = vha->hw;
2311 struct req_que *req = NULL; 2256 struct req_que *req = NULL;
2312 struct rsp_que *rsp = NULL; 2257 struct rsp_que *rsp = NULL;
2313 char tag[2];
2314 2258
2315 /* Setup device pointers. */ 2259 /* Setup device pointers. */
2316 ret = 0; 2260 ret = 0;
@@ -2489,22 +2433,6 @@ sufficient_dsds:
2489 else if (cmd->sc_data_direction == DMA_FROM_DEVICE) 2433 else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
2490 ctx->fcp_cmnd->additional_cdb_len |= 2; 2434 ctx->fcp_cmnd->additional_cdb_len |= 2;
2491 2435
2492 /*
2493 * Update tagged queuing modifier -- default is TSK_SIMPLE (0).
2494 */
2495 if (scsi_populate_tag_msg(cmd, tag)) {
2496 switch (tag[0]) {
2497 case HEAD_OF_QUEUE_TAG:
2498 ctx->fcp_cmnd->task_attribute =
2499 TSK_HEAD_OF_QUEUE;
2500 break;
2501 case ORDERED_QUEUE_TAG:
2502 ctx->fcp_cmnd->task_attribute =
2503 TSK_ORDERED;
2504 break;
2505 }
2506 }
2507
2508 /* Populate the FCP_PRIO. */ 2436 /* Populate the FCP_PRIO. */
2509 if (ha->flags.fcp_prio_enabled) 2437 if (ha->flags.fcp_prio_enabled)
2510 ctx->fcp_cmnd->task_attribute |= 2438 ctx->fcp_cmnd->task_attribute |=
@@ -2565,20 +2493,6 @@ sufficient_dsds:
2565 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, 2493 host_to_fcp_swap((uint8_t *)&cmd_pkt->lun,
2566 sizeof(cmd_pkt->lun)); 2494 sizeof(cmd_pkt->lun));
2567 2495
2568 /*
2569 * Update tagged queuing modifier -- default is TSK_SIMPLE (0).
2570 */
2571 if (scsi_populate_tag_msg(cmd, tag)) {
2572 switch (tag[0]) {
2573 case HEAD_OF_QUEUE_TAG:
2574 cmd_pkt->task = TSK_HEAD_OF_QUEUE;
2575 break;
2576 case ORDERED_QUEUE_TAG:
2577 cmd_pkt->task = TSK_ORDERED;
2578 break;
2579 }
2580 }
2581
2582 /* Populate the FCP_PRIO. */ 2496 /* Populate the FCP_PRIO. */
2583 if (ha->flags.fcp_prio_enabled) 2497 if (ha->flags.fcp_prio_enabled)
2584 cmd_pkt->task |= sp->fcport->fcp_prio << 3; 2498 cmd_pkt->task |= sp->fcport->fcp_prio << 3;
diff --git a/drivers/scsi/qla2xxx/qla_mr.c b/drivers/scsi/qla2xxx/qla_mr.c
index 80867599527d..6d190b4b82a0 100644
--- a/drivers/scsi/qla2xxx/qla_mr.c
+++ b/drivers/scsi/qla2xxx/qla_mr.c
@@ -3086,7 +3086,6 @@ qlafx00_start_scsi(srb_t *sp)
3086 struct cmd_type_7_fx00 *cmd_pkt; 3086 struct cmd_type_7_fx00 *cmd_pkt;
3087 struct cmd_type_7_fx00 lcmd_pkt; 3087 struct cmd_type_7_fx00 lcmd_pkt;
3088 struct scsi_lun llun; 3088 struct scsi_lun llun;
3089 char tag[2];
3090 3089
3091 /* Setup device pointers. */ 3090 /* Setup device pointers. */
3092 ret = 0; 3091 ret = 0;
@@ -3157,18 +3156,6 @@ qlafx00_start_scsi(srb_t *sp)
3157 host_to_adap((uint8_t *)&llun, (uint8_t *)&lcmd_pkt.lun, 3156 host_to_adap((uint8_t *)&llun, (uint8_t *)&lcmd_pkt.lun,
3158 sizeof(lcmd_pkt.lun)); 3157 sizeof(lcmd_pkt.lun));
3159 3158
3160 /* Update tagged queuing modifier -- default is TSK_SIMPLE (0). */
3161 if (scsi_populate_tag_msg(cmd, tag)) {
3162 switch (tag[0]) {
3163 case HEAD_OF_QUEUE_TAG:
3164 lcmd_pkt.task = TSK_HEAD_OF_QUEUE;
3165 break;
3166 case ORDERED_QUEUE_TAG:
3167 lcmd_pkt.task = TSK_ORDERED;
3168 break;
3169 }
3170 }
3171
3172 /* Load SCSI command packet. */ 3159 /* Load SCSI command packet. */
3173 host_to_adap(cmd->cmnd, lcmd_pkt.fcp_cdb, sizeof(lcmd_pkt.fcp_cdb)); 3160 host_to_adap(cmd->cmnd, lcmd_pkt.fcp_cdb, sizeof(lcmd_pkt.fcp_cdb));
3174 lcmd_pkt.byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); 3161 lcmd_pkt.byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
diff --git a/drivers/scsi/qla2xxx/qla_nx2.c b/drivers/scsi/qla2xxx/qla_nx2.c
index 24a852828b5d..ed4d6b6b53e3 100644
--- a/drivers/scsi/qla2xxx/qla_nx2.c
+++ b/drivers/scsi/qla2xxx/qla_nx2.c
@@ -238,7 +238,7 @@ qla8044_rmw_crb_reg(struct scsi_qla_host *vha,
238 return; 238 return;
239} 239}
240 240
241inline void 241static inline void
242qla8044_set_qsnt_ready(struct scsi_qla_host *vha) 242qla8044_set_qsnt_ready(struct scsi_qla_host *vha)
243{ 243{
244 uint32_t qsnt_state; 244 uint32_t qsnt_state;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index db3dbd999cb6..6b4d9235368a 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -236,8 +236,6 @@ static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
236static int qla2xxx_eh_bus_reset(struct scsi_cmnd *); 236static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
237static int qla2xxx_eh_host_reset(struct scsi_cmnd *); 237static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
238 238
239static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
240static int qla2x00_change_queue_type(struct scsi_device *, int);
241static void qla2x00_clear_drv_active(struct qla_hw_data *); 239static void qla2x00_clear_drv_active(struct qla_hw_data *);
242static void qla2x00_free_device(scsi_qla_host_t *); 240static void qla2x00_free_device(scsi_qla_host_t *);
243static void qla83xx_disable_laser(scsi_qla_host_t *vha); 241static void qla83xx_disable_laser(scsi_qla_host_t *vha);
@@ -259,8 +257,8 @@ struct scsi_host_template qla2xxx_driver_template = {
259 .slave_destroy = qla2xxx_slave_destroy, 257 .slave_destroy = qla2xxx_slave_destroy,
260 .scan_finished = qla2xxx_scan_finished, 258 .scan_finished = qla2xxx_scan_finished,
261 .scan_start = qla2xxx_scan_start, 259 .scan_start = qla2xxx_scan_start,
262 .change_queue_depth = qla2x00_change_queue_depth, 260 .change_queue_depth = scsi_change_queue_depth,
263 .change_queue_type = qla2x00_change_queue_type, 261 .change_queue_type = scsi_change_queue_type,
264 .this_id = -1, 262 .this_id = -1,
265 .cmd_per_lun = 3, 263 .cmd_per_lun = 3,
266 .use_clustering = ENABLE_CLUSTERING, 264 .use_clustering = ENABLE_CLUSTERING,
@@ -270,6 +268,8 @@ struct scsi_host_template qla2xxx_driver_template = {
270 .shost_attrs = qla2x00_host_attrs, 268 .shost_attrs = qla2x00_host_attrs,
271 269
272 .supported_mode = MODE_INITIATOR, 270 .supported_mode = MODE_INITIATOR,
271 .use_blk_tags = 1,
272 .track_queue_depth = 1,
273}; 273};
274 274
275static struct scsi_transport_template *qla2xxx_transport_template = NULL; 275static struct scsi_transport_template *qla2xxx_transport_template = NULL;
@@ -1405,10 +1405,7 @@ qla2xxx_slave_configure(struct scsi_device *sdev)
1405 if (IS_T10_PI_CAPABLE(vha->hw)) 1405 if (IS_T10_PI_CAPABLE(vha->hw))
1406 blk_queue_update_dma_alignment(sdev->request_queue, 0x7); 1406 blk_queue_update_dma_alignment(sdev->request_queue, 0x7);
1407 1407
1408 if (sdev->tagged_supported) 1408 scsi_change_queue_depth(sdev, req->max_q_depth);
1409 scsi_activate_tcq(sdev, req->max_q_depth);
1410 else
1411 scsi_deactivate_tcq(sdev, req->max_q_depth);
1412 return 0; 1409 return 0;
1413} 1410}
1414 1411
@@ -1418,76 +1415,6 @@ qla2xxx_slave_destroy(struct scsi_device *sdev)
1418 sdev->hostdata = NULL; 1415 sdev->hostdata = NULL;
1419} 1416}
1420 1417
1421static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1422{
1423 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1424
1425 if (!scsi_track_queue_full(sdev, qdepth))
1426 return;
1427
1428 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
1429 "Queue depth adjusted-down to %d for nexus=%ld:%d:%llu.\n",
1430 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
1431}
1432
1433static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1434{
1435 fc_port_t *fcport = sdev->hostdata;
1436 struct scsi_qla_host *vha = fcport->vha;
1437 struct req_que *req = NULL;
1438
1439 req = vha->req;
1440 if (!req)
1441 return;
1442
1443 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1444 return;
1445
1446 if (sdev->ordered_tags)
1447 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1448 else
1449 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1450
1451 ql_dbg(ql_dbg_io, vha, 0x302a,
1452 "Queue depth adjusted-up to %d for nexus=%ld:%d:%llu.\n",
1453 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
1454}
1455
1456static int
1457qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1458{
1459 switch (reason) {
1460 case SCSI_QDEPTH_DEFAULT:
1461 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1462 break;
1463 case SCSI_QDEPTH_QFULL:
1464 qla2x00_handle_queue_full(sdev, qdepth);
1465 break;
1466 case SCSI_QDEPTH_RAMP_UP:
1467 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1468 break;
1469 default:
1470 return -EOPNOTSUPP;
1471 }
1472
1473 return sdev->queue_depth;
1474}
1475
1476static int
1477qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1478{
1479 if (sdev->tagged_supported) {
1480 scsi_set_tag_type(sdev, tag_type);
1481 if (tag_type)
1482 scsi_activate_tcq(sdev, sdev->queue_depth);
1483 else
1484 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1485 } else
1486 tag_type = 0;
1487
1488 return tag_type;
1489}
1490
1491/** 1418/**
1492 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method. 1419 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1493 * @ha: HA context 1420 * @ha: HA context
diff --git a/drivers/scsi/qla4xxx/ql4_iocb.c b/drivers/scsi/qla4xxx/ql4_iocb.c
index 08ab6dac226d..17222eb49762 100644
--- a/drivers/scsi/qla4xxx/ql4_iocb.c
+++ b/drivers/scsi/qla4xxx/ql4_iocb.c
@@ -280,7 +280,6 @@ int qla4xxx_send_command_to_isp(struct scsi_qla_host *ha, struct srb * srb)
280 uint16_t req_cnt; 280 uint16_t req_cnt;
281 unsigned long flags; 281 unsigned long flags;
282 uint32_t index; 282 uint32_t index;
283 char tag[2];
284 283
285 /* Get real lun and adapter */ 284 /* Get real lun and adapter */
286 ddb_entry = srb->ddb; 285 ddb_entry = srb->ddb;
@@ -352,15 +351,6 @@ int qla4xxx_send_command_to_isp(struct scsi_qla_host *ha, struct srb * srb)
352 351
353 /* Set tagged queueing control flags */ 352 /* Set tagged queueing control flags */
354 cmd_entry->control_flags |= CF_SIMPLE_TAG; 353 cmd_entry->control_flags |= CF_SIMPLE_TAG;
355 if (scsi_populate_tag_msg(cmd, tag))
356 switch (tag[0]) {
357 case MSG_HEAD_TAG:
358 cmd_entry->control_flags |= CF_HEAD_TAG;
359 break;
360 case MSG_ORDERED_TAG:
361 cmd_entry->control_flags |= CF_ORDERED_TAG;
362 break;
363 }
364 354
365 qla4xxx_advance_req_ring_ptr(ha); 355 qla4xxx_advance_req_ring_ptr(ha);
366 qla4xxx_build_scsi_iocbs(srb, cmd_entry, tot_dsds); 356 qla4xxx_build_scsi_iocbs(srb, cmd_entry, tot_dsds);
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 199fcf79a051..6d25879d87c8 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -162,12 +162,8 @@ static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd);
162static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd); 162static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd);
163static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd); 163static int qla4xxx_eh_host_reset(struct scsi_cmnd *cmd);
164static int qla4xxx_slave_alloc(struct scsi_device *device); 164static int qla4xxx_slave_alloc(struct scsi_device *device);
165static int qla4xxx_slave_configure(struct scsi_device *device);
166static void qla4xxx_slave_destroy(struct scsi_device *sdev);
167static umode_t qla4_attr_is_visible(int param_type, int param); 165static umode_t qla4_attr_is_visible(int param_type, int param);
168static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type); 166static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);
169static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
170 int reason);
171 167
172/* 168/*
173 * iSCSI Flash DDB sysfs entry points 169 * iSCSI Flash DDB sysfs entry points
@@ -204,10 +200,8 @@ static struct scsi_host_template qla4xxx_driver_template = {
204 .eh_host_reset_handler = qla4xxx_eh_host_reset, 200 .eh_host_reset_handler = qla4xxx_eh_host_reset,
205 .eh_timed_out = qla4xxx_eh_cmd_timed_out, 201 .eh_timed_out = qla4xxx_eh_cmd_timed_out,
206 202
207 .slave_configure = qla4xxx_slave_configure,
208 .slave_alloc = qla4xxx_slave_alloc, 203 .slave_alloc = qla4xxx_slave_alloc,
209 .slave_destroy = qla4xxx_slave_destroy, 204 .change_queue_depth = scsi_change_queue_depth,
210 .change_queue_depth = qla4xxx_change_queue_depth,
211 205
212 .this_id = -1, 206 .this_id = -1,
213 .cmd_per_lun = 3, 207 .cmd_per_lun = 3,
@@ -218,6 +212,7 @@ static struct scsi_host_template qla4xxx_driver_template = {
218 .shost_attrs = qla4xxx_host_attrs, 212 .shost_attrs = qla4xxx_host_attrs,
219 .host_reset = qla4xxx_host_reset, 213 .host_reset = qla4xxx_host_reset,
220 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC, 214 .vendor_id = SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC,
215 .use_blk_tags = 1,
221}; 216};
222 217
223static struct iscsi_transport qla4xxx_iscsi_transport = { 218static struct iscsi_transport qla4xxx_iscsi_transport = {
@@ -9060,35 +9055,14 @@ static int qla4xxx_slave_alloc(struct scsi_device *sdev)
9060 ddb = sess->dd_data; 9055 ddb = sess->dd_data;
9061 9056
9062 sdev->hostdata = ddb; 9057 sdev->hostdata = ddb;
9063 sdev->tagged_supported = 1;
9064 9058
9065 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU) 9059 if (ql4xmaxqdepth != 0 && ql4xmaxqdepth <= 0xffffU)
9066 queue_depth = ql4xmaxqdepth; 9060 queue_depth = ql4xmaxqdepth;
9067 9061
9068 scsi_activate_tcq(sdev, queue_depth); 9062 scsi_change_queue_depth(sdev, queue_depth);
9069 return 0; 9063 return 0;
9070} 9064}
9071 9065
9072static int qla4xxx_slave_configure(struct scsi_device *sdev)
9073{
9074 sdev->tagged_supported = 1;
9075 return 0;
9076}
9077
9078static void qla4xxx_slave_destroy(struct scsi_device *sdev)
9079{
9080 scsi_deactivate_tcq(sdev, 1);
9081}
9082
9083static int qla4xxx_change_queue_depth(struct scsi_device *sdev, int qdepth,
9084 int reason)
9085{
9086 if (!ql4xqfulltracking)
9087 return -EOPNOTSUPP;
9088
9089 return iscsi_change_queue_depth(sdev, qdepth, reason);
9090}
9091
9092/** 9066/**
9093 * qla4xxx_del_from_active_array - returns an active srb 9067 * qla4xxx_del_from_active_array - returns an active srb
9094 * @ha: Pointer to host adapter structure. 9068 * @ha: Pointer to host adapter structure.
@@ -9888,6 +9862,9 @@ static int __init qla4xxx_module_init(void)
9888{ 9862{
9889 int ret; 9863 int ret;
9890 9864
9865 if (ql4xqfulltracking)
9866 qla4xxx_driver_template.track_queue_depth = 1;
9867
9891 /* Allocate cache for SRBs. */ 9868 /* Allocate cache for SRBs. */
9892 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0, 9869 srb_cachep = kmem_cache_create("qla4xxx_srbs", sizeof(struct srb), 0,
9893 SLAB_HWCACHE_ALIGN, NULL); 9870 SLAB_HWCACHE_ALIGN, NULL);
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 79c77b485a67..1ad0c36375b8 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -527,9 +527,9 @@ void scsi_log_send(struct scsi_cmnd *cmd)
527 * 527 *
528 * 1: nothing (match completion) 528 * 1: nothing (match completion)
529 * 529 *
530 * 2: log opcode + command of all commands 530 * 2: log opcode + command of all commands + cmd address
531 * 531 *
532 * 3: same as 2 plus dump cmd address 532 * 3: same as 2
533 * 533 *
534 * 4: same as 3 plus dump extra junk 534 * 4: same as 3 plus dump extra junk
535 */ 535 */
@@ -537,10 +537,8 @@ void scsi_log_send(struct scsi_cmnd *cmd)
537 level = SCSI_LOG_LEVEL(SCSI_LOG_MLQUEUE_SHIFT, 537 level = SCSI_LOG_LEVEL(SCSI_LOG_MLQUEUE_SHIFT,
538 SCSI_LOG_MLQUEUE_BITS); 538 SCSI_LOG_MLQUEUE_BITS);
539 if (level > 1) { 539 if (level > 1) {
540 scmd_printk(KERN_INFO, cmd, "Send: "); 540 scmd_printk(KERN_INFO, cmd,
541 if (level > 2) 541 "Send: scmd 0x%p\n", cmd);
542 printk("0x%p ", cmd);
543 printk("\n");
544 scsi_print_command(cmd); 542 scsi_print_command(cmd);
545 if (level > 3) { 543 if (level > 3) {
546 printk(KERN_INFO "buffer = 0x%p, bufflen = %d," 544 printk(KERN_INFO "buffer = 0x%p, bufflen = %d,"
@@ -565,7 +563,7 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
565 * 563 *
566 * 2: same as 1 but for all command completions. 564 * 2: same as 1 but for all command completions.
567 * 565 *
568 * 3: same as 2 plus dump cmd address 566 * 3: same as 2
569 * 567 *
570 * 4: same as 3 plus dump extra junk 568 * 4: same as 3 plus dump extra junk
571 */ 569 */
@@ -574,39 +572,10 @@ void scsi_log_completion(struct scsi_cmnd *cmd, int disposition)
574 SCSI_LOG_MLCOMPLETE_BITS); 572 SCSI_LOG_MLCOMPLETE_BITS);
575 if (((level > 0) && (cmd->result || disposition != SUCCESS)) || 573 if (((level > 0) && (cmd->result || disposition != SUCCESS)) ||
576 (level > 1)) { 574 (level > 1)) {
577 scmd_printk(KERN_INFO, cmd, "Done: "); 575 scsi_print_result(cmd, "Done: ", disposition);
578 if (level > 2)
579 printk("0x%p ", cmd);
580 /*
581 * Dump truncated values, so we usually fit within
582 * 80 chars.
583 */
584 switch (disposition) {
585 case SUCCESS:
586 printk("SUCCESS\n");
587 break;
588 case NEEDS_RETRY:
589 printk("RETRY\n");
590 break;
591 case ADD_TO_MLQUEUE:
592 printk("MLQUEUE\n");
593 break;
594 case FAILED:
595 printk("FAILED\n");
596 break;
597 case TIMEOUT_ERROR:
598 /*
599 * If called via scsi_times_out.
600 */
601 printk("TIMEOUT\n");
602 break;
603 default:
604 printk("UNKNOWN\n");
605 }
606 scsi_print_result(cmd);
607 scsi_print_command(cmd); 576 scsi_print_command(cmd);
608 if (status_byte(cmd->result) & CHECK_CONDITION) 577 if (status_byte(cmd->result) & CHECK_CONDITION)
609 scsi_print_sense("", cmd); 578 scsi_print_sense(cmd);
610 if (level > 3) 579 if (level > 3)
611 scmd_printk(KERN_INFO, cmd, 580 scmd_printk(KERN_INFO, cmd,
612 "scsi host busy %d failed %d\n", 581 "scsi host busy %d failed %d\n",
@@ -634,87 +603,6 @@ void scsi_cmd_get_serial(struct Scsi_Host *host, struct scsi_cmnd *cmd)
634EXPORT_SYMBOL(scsi_cmd_get_serial); 603EXPORT_SYMBOL(scsi_cmd_get_serial);
635 604
636/** 605/**
637 * scsi_dispatch_command - Dispatch a command to the low-level driver.
638 * @cmd: command block we are dispatching.
639 *
640 * Return: nonzero return request was rejected and device's queue needs to be
641 * plugged.
642 */
643int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
644{
645 struct Scsi_Host *host = cmd->device->host;
646 int rtn = 0;
647
648 atomic_inc(&cmd->device->iorequest_cnt);
649
650 /* check if the device is still usable */
651 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
652 /* in SDEV_DEL we error all commands. DID_NO_CONNECT
653 * returns an immediate error upwards, and signals
654 * that the device is no longer present */
655 cmd->result = DID_NO_CONNECT << 16;
656 goto done;
657 }
658
659 /* Check to see if the scsi lld made this device blocked. */
660 if (unlikely(scsi_device_blocked(cmd->device))) {
661 /*
662 * in blocked state, the command is just put back on
663 * the device queue. The suspend state has already
664 * blocked the queue so future requests should not
665 * occur until the device transitions out of the
666 * suspend state.
667 */
668 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
669 "queuecommand : device blocked\n"));
670 return SCSI_MLQUEUE_DEVICE_BUSY;
671 }
672
673 /* Store the LUN value in cmnd, if needed. */
674 if (cmd->device->lun_in_cdb)
675 cmd->cmnd[1] = (cmd->cmnd[1] & 0x1f) |
676 (cmd->device->lun << 5 & 0xe0);
677
678 scsi_log_send(cmd);
679
680 /*
681 * Before we queue this command, check if the command
682 * length exceeds what the host adapter can handle.
683 */
684 if (cmd->cmd_len > cmd->device->host->max_cmd_len) {
685 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
686 "queuecommand : command too long. "
687 "cdb_size=%d host->max_cmd_len=%d\n",
688 cmd->cmd_len, cmd->device->host->max_cmd_len));
689 cmd->result = (DID_ABORT << 16);
690 goto done;
691 }
692
693 if (unlikely(host->shost_state == SHOST_DEL)) {
694 cmd->result = (DID_NO_CONNECT << 16);
695 goto done;
696
697 }
698
699 trace_scsi_dispatch_cmd_start(cmd);
700 rtn = host->hostt->queuecommand(host, cmd);
701 if (rtn) {
702 trace_scsi_dispatch_cmd_error(cmd, rtn);
703 if (rtn != SCSI_MLQUEUE_DEVICE_BUSY &&
704 rtn != SCSI_MLQUEUE_TARGET_BUSY)
705 rtn = SCSI_MLQUEUE_HOST_BUSY;
706
707 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
708 "queuecommand : request rejected\n"));
709 }
710
711 return rtn;
712 done:
713 cmd->scsi_done(cmd);
714 return 0;
715}
716
717/**
718 * scsi_finish_command - cleanup and pass command back to upper layer 606 * scsi_finish_command - cleanup and pass command back to upper layer
719 * @cmd: the command 607 * @cmd: the command
720 * 608 *
@@ -773,32 +661,18 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
773} 661}
774 662
775/** 663/**
776 * scsi_adjust_queue_depth - Let low level drivers change a device's queue depth 664 * scsi_change_queue_depth - change a device's queue depth
777 * @sdev: SCSI Device in question 665 * @sdev: SCSI Device in question
778 * @tagged: Do we use tagged queueing (non-0) or do we treat 666 * @depth: number of commands allowed to be queued to the driver
779 * this device as an untagged device (0)
780 * @tags: Number of tags allowed if tagged queueing enabled,
781 * or number of commands the low level driver can
782 * queue up in non-tagged mode (as per cmd_per_lun).
783 *
784 * Returns: Nothing
785 * 667 *
786 * Lock Status: None held on entry 668 * Sets the device queue depth and returns the new value.
787 *
788 * Notes: Low level drivers may call this at any time and we will do
789 * the right thing depending on whether or not the device is
790 * currently active and whether or not it even has the
791 * command blocks built yet.
792 */ 669 */
793void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags) 670int scsi_change_queue_depth(struct scsi_device *sdev, int depth)
794{ 671{
795 unsigned long flags; 672 unsigned long flags;
796 673
797 /* 674 if (depth <= 0)
798 * refuse to set tagged depth to an unworkable size 675 goto out;
799 */
800 if (tags <= 0)
801 return;
802 676
803 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 677 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
804 678
@@ -813,35 +687,17 @@ void scsi_adjust_queue_depth(struct scsi_device *sdev, int tagged, int tags)
813 */ 687 */
814 if (!shost_use_blk_mq(sdev->host) && !sdev->host->bqt) { 688 if (!shost_use_blk_mq(sdev->host) && !sdev->host->bqt) {
815 if (blk_queue_tagged(sdev->request_queue) && 689 if (blk_queue_tagged(sdev->request_queue) &&
816 blk_queue_resize_tags(sdev->request_queue, tags) != 0) 690 blk_queue_resize_tags(sdev->request_queue, depth) != 0)
817 goto out; 691 goto out_unlock;
818 } 692 }
819 693
820 sdev->queue_depth = tags; 694 sdev->queue_depth = depth;
821 switch (tagged) { 695out_unlock:
822 case 0:
823 sdev->ordered_tags = 0;
824 sdev->simple_tags = 0;
825 break;
826 case MSG_ORDERED_TAG:
827 sdev->ordered_tags = 1;
828 sdev->simple_tags = 1;
829 break;
830 case MSG_SIMPLE_TAG:
831 sdev->ordered_tags = 0;
832 sdev->simple_tags = 1;
833 break;
834 default:
835 sdev->ordered_tags = 0;
836 sdev->simple_tags = 0;
837 sdev_printk(KERN_WARNING, sdev,
838 "scsi_adjust_queue_depth, bad queue type, "
839 "disabled\n");
840 }
841 out:
842 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 696 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
697out:
698 return sdev->queue_depth;
843} 699}
844EXPORT_SYMBOL(scsi_adjust_queue_depth); 700EXPORT_SYMBOL(scsi_change_queue_depth);
845 701
846/** 702/**
847 * scsi_track_queue_full - track QUEUE_FULL events to adjust queue depth 703 * scsi_track_queue_full - track QUEUE_FULL events to adjust queue depth
@@ -885,19 +741,32 @@ int scsi_track_queue_full(struct scsi_device *sdev, int depth)
885 return 0; 741 return 0;
886 if (sdev->last_queue_full_depth < 8) { 742 if (sdev->last_queue_full_depth < 8) {
887 /* Drop back to untagged */ 743 /* Drop back to untagged */
888 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); 744 scsi_set_tag_type(sdev, 0);
745 scsi_change_queue_depth(sdev, sdev->host->cmd_per_lun);
889 return -1; 746 return -1;
890 } 747 }
891 748
892 if (sdev->ordered_tags) 749 return scsi_change_queue_depth(sdev, depth);
893 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, depth);
894 else
895 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, depth);
896 return depth;
897} 750}
898EXPORT_SYMBOL(scsi_track_queue_full); 751EXPORT_SYMBOL(scsi_track_queue_full);
899 752
900/** 753/**
754 * scsi_change_queue_type() - Change a device's queue type
755 * @sdev: The SCSI device whose queue depth is to change
756 * @tag_type: Identifier for queue type
757 */
758int scsi_change_queue_type(struct scsi_device *sdev, int tag_type)
759{
760 if (!sdev->tagged_supported)
761 return 0;
762
763 scsi_set_tag_type(sdev, tag_type);
764 return tag_type;
765
766}
767EXPORT_SYMBOL(scsi_change_queue_type);
768
769/**
901 * scsi_vpd_inquiry - Request a device provide us with a VPD page 770 * scsi_vpd_inquiry - Request a device provide us with a VPD page
902 * @sdev: The device to ask 771 * @sdev: The device to ask
903 * @buffer: Where to put the result 772 * @buffer: Where to put the result
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 238e06f13b8a..aa4b6b80aade 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -63,8 +63,8 @@
63#include "sd.h" 63#include "sd.h"
64#include "scsi_logging.h" 64#include "scsi_logging.h"
65 65
66#define SCSI_DEBUG_VERSION "1.84" 66#define SCSI_DEBUG_VERSION "1.85"
67static const char *scsi_debug_version_date = "20140706"; 67static const char *scsi_debug_version_date = "20141022";
68 68
69#define MY_NAME "scsi_debug" 69#define MY_NAME "scsi_debug"
70 70
@@ -75,19 +75,22 @@ static const char *scsi_debug_version_date = "20140706";
75#define UNRECOVERED_READ_ERR 0x11 75#define UNRECOVERED_READ_ERR 0x11
76#define PARAMETER_LIST_LENGTH_ERR 0x1a 76#define PARAMETER_LIST_LENGTH_ERR 0x1a
77#define INVALID_OPCODE 0x20 77#define INVALID_OPCODE 0x20
78#define ADDR_OUT_OF_RANGE 0x21 78#define LBA_OUT_OF_RANGE 0x21
79#define INVALID_COMMAND_OPCODE 0x20
80#define INVALID_FIELD_IN_CDB 0x24 79#define INVALID_FIELD_IN_CDB 0x24
81#define INVALID_FIELD_IN_PARAM_LIST 0x26 80#define INVALID_FIELD_IN_PARAM_LIST 0x26
82#define UA_RESET_ASC 0x29 81#define UA_RESET_ASC 0x29
83#define UA_CHANGED_ASC 0x2a 82#define UA_CHANGED_ASC 0x2a
83#define INSUFF_RES_ASC 0x55
84#define INSUFF_RES_ASCQ 0x3
84#define POWER_ON_RESET_ASCQ 0x0 85#define POWER_ON_RESET_ASCQ 0x0
85#define BUS_RESET_ASCQ 0x2 /* scsi bus reset occurred */ 86#define BUS_RESET_ASCQ 0x2 /* scsi bus reset occurred */
86#define MODE_CHANGED_ASCQ 0x1 /* mode parameters changed */ 87#define MODE_CHANGED_ASCQ 0x1 /* mode parameters changed */
88#define CAPACITY_CHANGED_ASCQ 0x9
87#define SAVING_PARAMS_UNSUP 0x39 89#define SAVING_PARAMS_UNSUP 0x39
88#define TRANSPORT_PROBLEM 0x4b 90#define TRANSPORT_PROBLEM 0x4b
89#define THRESHOLD_EXCEEDED 0x5d 91#define THRESHOLD_EXCEEDED 0x5d
90#define LOW_POWER_COND_ON 0x5e 92#define LOW_POWER_COND_ON 0x5e
93#define MISCOMPARE_VERIFY_ASC 0x1d
91 94
92/* Additional Sense Code Qualifier (ASCQ) */ 95/* Additional Sense Code Qualifier (ASCQ) */
93#define ACK_NAK_TO 0x3 96#define ACK_NAK_TO 0x3
@@ -133,6 +136,7 @@ static const char *scsi_debug_version_date = "20140706";
133#define DEF_VIRTUAL_GB 0 136#define DEF_VIRTUAL_GB 0
134#define DEF_VPD_USE_HOSTNO 1 137#define DEF_VPD_USE_HOSTNO 1
135#define DEF_WRITESAME_LENGTH 0xFFFF 138#define DEF_WRITESAME_LENGTH 0xFFFF
139#define DEF_STRICT 0
136#define DELAY_OVERRIDDEN -9999 140#define DELAY_OVERRIDDEN -9999
137 141
138/* bit mask values for scsi_debug_opts */ 142/* bit mask values for scsi_debug_opts */
@@ -176,11 +180,12 @@ static const char *scsi_debug_version_date = "20140706";
176#define SDEBUG_UA_POR 0 /* Power on, reset, or bus device reset */ 180#define SDEBUG_UA_POR 0 /* Power on, reset, or bus device reset */
177#define SDEBUG_UA_BUS_RESET 1 181#define SDEBUG_UA_BUS_RESET 1
178#define SDEBUG_UA_MODE_CHANGED 2 182#define SDEBUG_UA_MODE_CHANGED 2
179#define SDEBUG_NUM_UAS 3 183#define SDEBUG_UA_CAPACITY_CHANGED 3
184#define SDEBUG_NUM_UAS 4
180 185
181/* for check_readiness() */ 186/* for check_readiness() */
182#define UAS_ONLY 1 187#define UAS_ONLY 1 /* check for UAs only */
183#define UAS_TUR 0 188#define UAS_TUR 0 /* if no UAs then check if media access possible */
184 189
185/* when 1==SCSI_DEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this 190/* when 1==SCSI_DEBUG_OPT_MEDIUM_ERR, a medium error is simulated at this
186 * sector on read commands: */ 191 * sector on read commands: */
@@ -206,6 +211,301 @@ static const char *scsi_debug_version_date = "20140706";
206#warning "Expect DEF_CMD_PER_LUN <= SCSI_DEBUG_CANQUEUE" 211#warning "Expect DEF_CMD_PER_LUN <= SCSI_DEBUG_CANQUEUE"
207#endif 212#endif
208 213
214/* SCSI opcodes (first byte of cdb) mapped onto these indexes */
215enum sdeb_opcode_index {
216 SDEB_I_INVALID_OPCODE = 0,
217 SDEB_I_INQUIRY = 1,
218 SDEB_I_REPORT_LUNS = 2,
219 SDEB_I_REQUEST_SENSE = 3,
220 SDEB_I_TEST_UNIT_READY = 4,
221 SDEB_I_MODE_SENSE = 5, /* 6, 10 */
222 SDEB_I_MODE_SELECT = 6, /* 6, 10 */
223 SDEB_I_LOG_SENSE = 7,
224 SDEB_I_READ_CAPACITY = 8, /* 10; 16 is in SA_IN(16) */
225 SDEB_I_READ = 9, /* 6, 10, 12, 16 */
226 SDEB_I_WRITE = 10, /* 6, 10, 12, 16 */
227 SDEB_I_START_STOP = 11,
228 SDEB_I_SERV_ACT_IN = 12, /* 12, 16 */
229 SDEB_I_SERV_ACT_OUT = 13, /* 12, 16 */
230 SDEB_I_MAINT_IN = 14,
231 SDEB_I_MAINT_OUT = 15,
232 SDEB_I_VERIFY = 16, /* 10 only */
233 SDEB_I_VARIABLE_LEN = 17,
234 SDEB_I_RESERVE = 18, /* 6, 10 */
235 SDEB_I_RELEASE = 19, /* 6, 10 */
236 SDEB_I_ALLOW_REMOVAL = 20, /* PREVENT ALLOW MEDIUM REMOVAL */
237 SDEB_I_REZERO_UNIT = 21, /* REWIND in SSC */
238 SDEB_I_ATA_PT = 22, /* 12, 16 */
239 SDEB_I_SEND_DIAG = 23,
240 SDEB_I_UNMAP = 24,
241 SDEB_I_XDWRITEREAD = 25, /* 10 only */
242 SDEB_I_WRITE_BUFFER = 26,
243 SDEB_I_WRITE_SAME = 27, /* 10, 16 */
244 SDEB_I_SYNC_CACHE = 28, /* 10 only */
245 SDEB_I_COMP_WRITE = 29,
246 SDEB_I_LAST_ELEMENT = 30, /* keep this last */
247};
248
249static const unsigned char opcode_ind_arr[256] = {
250/* 0x0; 0x0->0x1f: 6 byte cdbs */
251 SDEB_I_TEST_UNIT_READY, SDEB_I_REZERO_UNIT, 0, SDEB_I_REQUEST_SENSE,
252 0, 0, 0, 0,
253 SDEB_I_READ, 0, SDEB_I_WRITE, 0, 0, 0, 0, 0,
254 0, 0, SDEB_I_INQUIRY, 0, 0, SDEB_I_MODE_SELECT, SDEB_I_RESERVE,
255 SDEB_I_RELEASE,
256 0, 0, SDEB_I_MODE_SENSE, SDEB_I_START_STOP, 0, SDEB_I_SEND_DIAG,
257 SDEB_I_ALLOW_REMOVAL, 0,
258/* 0x20; 0x20->0x3f: 10 byte cdbs */
259 0, 0, 0, 0, 0, SDEB_I_READ_CAPACITY, 0, 0,
260 SDEB_I_READ, 0, SDEB_I_WRITE, 0, 0, 0, 0, SDEB_I_VERIFY,
261 0, 0, 0, 0, 0, SDEB_I_SYNC_CACHE, 0, 0,
262 0, 0, 0, SDEB_I_WRITE_BUFFER, 0, 0, 0, 0,
263/* 0x40; 0x40->0x5f: 10 byte cdbs */
264 0, SDEB_I_WRITE_SAME, SDEB_I_UNMAP, 0, 0, 0, 0, 0,
265 0, 0, 0, 0, 0, SDEB_I_LOG_SENSE, 0, 0,
266 0, 0, 0, SDEB_I_XDWRITEREAD, 0, SDEB_I_MODE_SELECT, SDEB_I_RESERVE,
267 SDEB_I_RELEASE,
268 0, 0, SDEB_I_MODE_SENSE, 0, 0, 0, 0, 0,
269/* 0x60; 0x60->0x7d are reserved */
270 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
271 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
272 0, SDEB_I_VARIABLE_LEN,
273/* 0x80; 0x80->0x9f: 16 byte cdbs */
274 0, 0, 0, 0, 0, SDEB_I_ATA_PT, 0, 0,
275 SDEB_I_READ, SDEB_I_COMP_WRITE, SDEB_I_WRITE, 0, 0, 0, 0, 0,
276 0, 0, 0, SDEB_I_WRITE_SAME, 0, 0, 0, 0,
277 0, 0, 0, 0, 0, 0, SDEB_I_SERV_ACT_IN, SDEB_I_SERV_ACT_OUT,
278/* 0xa0; 0xa0->0xbf: 12 byte cdbs */
279 SDEB_I_REPORT_LUNS, SDEB_I_ATA_PT, 0, SDEB_I_MAINT_IN,
280 SDEB_I_MAINT_OUT, 0, 0, 0,
281 SDEB_I_READ, SDEB_I_SERV_ACT_OUT, SDEB_I_WRITE, SDEB_I_SERV_ACT_IN,
282 0, 0, 0, 0,
283 0, 0, 0, 0, 0, 0, 0, 0,
284 0, 0, 0, 0, 0, 0, 0, 0,
285/* 0xc0; 0xc0->0xff: vendor specific */
286 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
287 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
288 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
289 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
290};
291
292#define F_D_IN 1
293#define F_D_OUT 2
294#define F_D_OUT_MAYBE 4 /* WRITE SAME, NDOB bit */
295#define F_D_UNKN 8
296#define F_RL_WLUN_OK 0x10
297#define F_SKIP_UA 0x20
298#define F_DELAY_OVERR 0x40
299#define F_SA_LOW 0x80 /* cdb byte 1, bits 4 to 0 */
300#define F_SA_HIGH 0x100 /* as used by variable length cdbs */
301#define F_INV_OP 0x200
302#define F_FAKE_RW 0x400
303#define F_M_ACCESS 0x800 /* media access */
304
305#define FF_RESPOND (F_RL_WLUN_OK | F_SKIP_UA | F_DELAY_OVERR)
306#define FF_DIRECT_IO (F_M_ACCESS | F_FAKE_RW)
307#define FF_SA (F_SA_HIGH | F_SA_LOW)
308
309struct sdebug_dev_info;
310static int resp_inquiry(struct scsi_cmnd *, struct sdebug_dev_info *);
311static int resp_report_luns(struct scsi_cmnd *, struct sdebug_dev_info *);
312static int resp_requests(struct scsi_cmnd *, struct sdebug_dev_info *);
313static int resp_mode_sense(struct scsi_cmnd *, struct sdebug_dev_info *);
314static int resp_mode_select(struct scsi_cmnd *, struct sdebug_dev_info *);
315static int resp_log_sense(struct scsi_cmnd *, struct sdebug_dev_info *);
316static int resp_readcap(struct scsi_cmnd *, struct sdebug_dev_info *);
317static int resp_read_dt0(struct scsi_cmnd *, struct sdebug_dev_info *);
318static int resp_write_dt0(struct scsi_cmnd *, struct sdebug_dev_info *);
319static int resp_start_stop(struct scsi_cmnd *, struct sdebug_dev_info *);
320static int resp_readcap16(struct scsi_cmnd *, struct sdebug_dev_info *);
321static int resp_get_lba_status(struct scsi_cmnd *, struct sdebug_dev_info *);
322static int resp_report_tgtpgs(struct scsi_cmnd *, struct sdebug_dev_info *);
323static int resp_unmap(struct scsi_cmnd *, struct sdebug_dev_info *);
324static int resp_rsup_opcodes(struct scsi_cmnd *, struct sdebug_dev_info *);
325static int resp_rsup_tmfs(struct scsi_cmnd *, struct sdebug_dev_info *);
326static int resp_write_same_10(struct scsi_cmnd *, struct sdebug_dev_info *);
327static int resp_write_same_16(struct scsi_cmnd *, struct sdebug_dev_info *);
328static int resp_xdwriteread_10(struct scsi_cmnd *, struct sdebug_dev_info *);
329static int resp_comp_write(struct scsi_cmnd *, struct sdebug_dev_info *);
330
331struct opcode_info_t {
332 u8 num_attached; /* 0 if this is it (i.e. a leaf); use 0xff
333 * for terminating element */
334 u8 opcode; /* if num_attached > 0, preferred */
335 u16 sa; /* service action */
336 u32 flags; /* OR-ed set of SDEB_F_* */
337 int (*pfp)(struct scsi_cmnd *, struct sdebug_dev_info *);
338 const struct opcode_info_t *arrp; /* num_attached elements or NULL */
339 u8 len_mask[16]; /* len=len_mask[0], then mask for cdb[1]... */
340 /* ignore cdb bytes after position 15 */
341};
342
343static const struct opcode_info_t msense_iarr[1] = {
344 {0, 0x1a, 0, F_D_IN, NULL, NULL,
345 {6, 0xe8, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
346};
347
348static const struct opcode_info_t mselect_iarr[1] = {
349 {0, 0x15, 0, F_D_OUT, NULL, NULL,
350 {6, 0xf1, 0, 0, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
351};
352
353static const struct opcode_info_t read_iarr[3] = {
354 {0, 0x28, 0, F_D_IN | FF_DIRECT_IO, resp_read_dt0, NULL,/* READ(10) */
355 {10, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xc7, 0, 0,
356 0, 0, 0, 0} },
357 {0, 0x8, 0, F_D_IN | FF_DIRECT_IO, resp_read_dt0, NULL, /* READ(6) */
358 {6, 0xff, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
359 {0, 0xa8, 0, F_D_IN | FF_DIRECT_IO, resp_read_dt0, NULL,/* READ(12) */
360 {12, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9f,
361 0xc7, 0, 0, 0, 0} },
362};
363
364static const struct opcode_info_t write_iarr[3] = {
365 {0, 0x2a, 0, F_D_OUT | FF_DIRECT_IO, resp_write_dt0, NULL, /* 10 */
366 {10, 0xfb, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xc7, 0, 0,
367 0, 0, 0, 0} },
368 {0, 0xa, 0, F_D_OUT | FF_DIRECT_IO, resp_write_dt0, NULL, /* 6 */
369 {6, 0xff, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
370 {0, 0xaa, 0, F_D_OUT | FF_DIRECT_IO, resp_write_dt0, NULL, /* 12 */
371 {12, 0xfb, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x9f,
372 0xc7, 0, 0, 0, 0} },
373};
374
375static const struct opcode_info_t sa_in_iarr[1] = {
376 {0, 0x9e, 0x12, F_SA_LOW | F_D_IN, resp_get_lba_status, NULL,
377 {16, 0x12, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
378 0xff, 0xff, 0xff, 0, 0xc7} },
379};
380
381static const struct opcode_info_t vl_iarr[1] = { /* VARIABLE LENGTH */
382 {0, 0x7f, 0xb, F_SA_HIGH | F_D_OUT | FF_DIRECT_IO, resp_write_dt0,
383 NULL, {32, 0xc7, 0, 0, 0, 0, 0x1f, 0x18, 0x0, 0xb, 0xfa,
384 0, 0xff, 0xff, 0xff, 0xff} }, /* WRITE(32) */
385};
386
387static const struct opcode_info_t maint_in_iarr[2] = {
388 {0, 0xa3, 0xc, F_SA_LOW | F_D_IN, resp_rsup_opcodes, NULL,
389 {12, 0xc, 0x87, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0,
390 0xc7, 0, 0, 0, 0} },
391 {0, 0xa3, 0xd, F_SA_LOW | F_D_IN, resp_rsup_tmfs, NULL,
392 {12, 0xd, 0x80, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0, 0xc7, 0, 0,
393 0, 0} },
394};
395
396static const struct opcode_info_t write_same_iarr[1] = {
397 {0, 0x93, 0, F_D_OUT_MAYBE | FF_DIRECT_IO, resp_write_same_16, NULL,
398 {16, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
399 0xff, 0xff, 0xff, 0x1f, 0xc7} },
400};
401
402static const struct opcode_info_t reserve_iarr[1] = {
403 {0, 0x16, 0, F_D_OUT, NULL, NULL, /* RESERVE(6) */
404 {6, 0x1f, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
405};
406
407static const struct opcode_info_t release_iarr[1] = {
408 {0, 0x17, 0, F_D_OUT, NULL, NULL, /* RELEASE(6) */
409 {6, 0x1f, 0xff, 0, 0, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
410};
411
412
413/* This array is accessed via SDEB_I_* values. Make sure all are mapped,
414 * plus the terminating elements for logic that scans this table such as
415 * REPORT SUPPORTED OPERATION CODES. */
416static const struct opcode_info_t opcode_info_arr[SDEB_I_LAST_ELEMENT + 1] = {
417/* 0 */
418 {0, 0, 0, F_INV_OP | FF_RESPOND, NULL, NULL,
419 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
420 {0, 0x12, 0, FF_RESPOND | F_D_IN, resp_inquiry, NULL,
421 {6, 0xe3, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
422 {0, 0xa0, 0, FF_RESPOND | F_D_IN, resp_report_luns, NULL,
423 {12, 0xe3, 0xff, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0, 0xc7, 0, 0,
424 0, 0} },
425 {0, 0x3, 0, FF_RESPOND | F_D_IN, resp_requests, NULL,
426 {6, 0xe1, 0, 0, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
427 {0, 0x0, 0, F_M_ACCESS | F_RL_WLUN_OK, NULL, NULL,/* TEST UNIT READY */
428 {6, 0, 0, 0, 0, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
429 {1, 0x5a, 0, F_D_IN, resp_mode_sense, msense_iarr,
430 {10, 0xf8, 0xff, 0xff, 0, 0, 0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0,
431 0} },
432 {1, 0x55, 0, F_D_OUT, resp_mode_select, mselect_iarr,
433 {10, 0xf1, 0, 0, 0, 0, 0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0} },
434 {0, 0x4d, 0, F_D_IN, resp_log_sense, NULL,
435 {10, 0xe3, 0xff, 0xff, 0, 0xff, 0xff, 0xff, 0xff, 0xc7, 0, 0, 0,
436 0, 0, 0} },
437 {0, 0x25, 0, F_D_IN, resp_readcap, NULL,
438 {10, 0xe1, 0xff, 0xff, 0xff, 0xff, 0, 0, 0x1, 0xc7, 0, 0, 0, 0,
439 0, 0} },
440 {3, 0x88, 0, F_D_IN | FF_DIRECT_IO, resp_read_dt0, read_iarr,
441 {16, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
442 0xff, 0xff, 0xff, 0x9f, 0xc7} }, /* READ(16) */
443/* 10 */
444 {3, 0x8a, 0, F_D_OUT | FF_DIRECT_IO, resp_write_dt0, write_iarr,
445 {16, 0xfa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
446 0xff, 0xff, 0xff, 0x9f, 0xc7} }, /* WRITE(16) */
447 {0, 0x1b, 0, 0, resp_start_stop, NULL, /* START STOP UNIT */
448 {6, 0x1, 0, 0xf, 0xf7, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
449 {1, 0x9e, 0x10, F_SA_LOW | F_D_IN, resp_readcap16, sa_in_iarr,
450 {16, 0x10, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
451 0xff, 0xff, 0xff, 0x1, 0xc7} }, /* READ CAPACITY(16) */
452 {0, 0, 0, F_INV_OP | FF_RESPOND, NULL, NULL, /* SA OUT */
453 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
454 {2, 0xa3, 0xa, F_SA_LOW | F_D_IN, resp_report_tgtpgs, maint_in_iarr,
455 {12, 0xea, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0, 0xc7, 0, 0, 0,
456 0} },
457 {0, 0, 0, F_INV_OP | FF_RESPOND, NULL, NULL, /* MAINT OUT */
458 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
459 {0, 0, 0, F_INV_OP | FF_RESPOND, NULL, NULL, /* VERIFY */
460 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
461 {1, 0x7f, 0x9, F_SA_HIGH | F_D_IN | FF_DIRECT_IO, resp_read_dt0,
462 vl_iarr, {32, 0xc7, 0, 0, 0, 0, 0x1f, 0x18, 0x0, 0x9, 0xfe, 0,
463 0xff, 0xff, 0xff, 0xff} },/* VARIABLE LENGTH, READ(32) */
464 {1, 0x56, 0, F_D_OUT, NULL, reserve_iarr, /* RESERVE(10) */
465 {10, 0xff, 0xff, 0xff, 0, 0, 0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0,
466 0} },
467 {1, 0x57, 0, F_D_OUT, NULL, release_iarr, /* RELEASE(10) */
468 {10, 0x13, 0xff, 0xff, 0, 0, 0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0,
469 0} },
470/* 20 */
471 {0, 0, 0, F_INV_OP | FF_RESPOND, NULL, NULL, /* ALLOW REMOVAL */
472 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
473 {0, 0x1, 0, 0, resp_start_stop, NULL, /* REWIND ?? */
474 {6, 0x1, 0, 0, 0, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
475 {0, 0, 0, F_INV_OP | FF_RESPOND, NULL, NULL, /* ATA_PT */
476 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
477 {0, 0x1d, F_D_OUT, 0, NULL, NULL, /* SEND DIAGNOSTIC */
478 {6, 0xf7, 0, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
479 {0, 0x42, 0, F_D_OUT | FF_DIRECT_IO, resp_unmap, NULL, /* UNMAP */
480 {10, 0x1, 0, 0, 0, 0, 0x1f, 0xff, 0xff, 0xc7, 0, 0, 0, 0, 0, 0} },
481 {0, 0x53, 0, F_D_IN | F_D_OUT | FF_DIRECT_IO, resp_xdwriteread_10,
482 NULL, {10, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xc7,
483 0, 0, 0, 0, 0, 0} },
484 {0, 0, 0, F_INV_OP | FF_RESPOND, NULL, NULL, /* WRITE_BUFFER */
485 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
486 {1, 0x41, 0, F_D_OUT_MAYBE | FF_DIRECT_IO, resp_write_same_10,
487 write_same_iarr, {10, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff,
488 0xff, 0xc7, 0, 0, 0, 0, 0, 0} },
489 {0, 0x35, 0, F_DELAY_OVERR | FF_DIRECT_IO, NULL, NULL, /* SYNC_CACHE */
490 {10, 0x7, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, 0xc7, 0, 0,
491 0, 0, 0, 0} },
492 {0, 0x89, 0, F_D_OUT | FF_DIRECT_IO, resp_comp_write, NULL,
493 {16, 0xf8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0,
494 0, 0xff, 0x1f, 0xc7} }, /* COMPARE AND WRITE */
495
496/* 30 */
497 {0xff, 0, 0, 0, NULL, NULL, /* terminating element */
498 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
499};
500
501struct sdebug_scmd_extra_t {
502 bool inj_recovered;
503 bool inj_transport;
504 bool inj_dif;
505 bool inj_dix;
506 bool inj_short;
507};
508
209static int scsi_debug_add_host = DEF_NUM_HOST; 509static int scsi_debug_add_host = DEF_NUM_HOST;
210static int scsi_debug_ato = DEF_ATO; 510static int scsi_debug_ato = DEF_ATO;
211static int scsi_debug_delay = DEF_DELAY; 511static int scsi_debug_delay = DEF_DELAY;
@@ -245,6 +545,8 @@ static unsigned int scsi_debug_write_same_length = DEF_WRITESAME_LENGTH;
245static bool scsi_debug_removable = DEF_REMOVABLE; 545static bool scsi_debug_removable = DEF_REMOVABLE;
246static bool scsi_debug_clustering; 546static bool scsi_debug_clustering;
247static bool scsi_debug_host_lock = DEF_HOST_LOCK; 547static bool scsi_debug_host_lock = DEF_HOST_LOCK;
548static bool scsi_debug_strict = DEF_STRICT;
549static bool sdebug_any_injecting_opt;
248 550
249static atomic_t sdebug_cmnd_count; 551static atomic_t sdebug_cmnd_count;
250static atomic_t sdebug_completions; 552static atomic_t sdebug_completions;
@@ -277,11 +579,10 @@ struct sdebug_dev_info {
277 unsigned int target; 579 unsigned int target;
278 u64 lun; 580 u64 lun;
279 struct sdebug_host_info *sdbg_host; 581 struct sdebug_host_info *sdbg_host;
280 u64 wlun;
281 unsigned long uas_bm[1]; 582 unsigned long uas_bm[1];
282 atomic_t num_in_q; 583 atomic_t num_in_q;
283 char stopped; 584 char stopped; /* TODO: should be atomic */
284 char used; 585 bool used;
285}; 586};
286 587
287struct sdebug_host_info { 588struct sdebug_host_info {
@@ -394,6 +695,50 @@ static void sdebug_max_tgts_luns(void)
394 spin_unlock(&sdebug_host_list_lock); 695 spin_unlock(&sdebug_host_list_lock);
395} 696}
396 697
698enum sdeb_cmd_data {SDEB_IN_DATA = 0, SDEB_IN_CDB = 1};
699
700/* Set in_bit to -1 to indicate no bit position of invalid field */
701static void
702mk_sense_invalid_fld(struct scsi_cmnd *scp, enum sdeb_cmd_data c_d,
703 int in_byte, int in_bit)
704{
705 unsigned char *sbuff;
706 u8 sks[4];
707 int sl, asc;
708
709 sbuff = scp->sense_buffer;
710 if (!sbuff) {
711 sdev_printk(KERN_ERR, scp->device,
712 "%s: sense_buffer is NULL\n", __func__);
713 return;
714 }
715 asc = c_d ? INVALID_FIELD_IN_CDB : INVALID_FIELD_IN_PARAM_LIST;
716 memset(sbuff, 0, SCSI_SENSE_BUFFERSIZE);
717 scsi_build_sense_buffer(scsi_debug_dsense, sbuff, ILLEGAL_REQUEST,
718 asc, 0);
719 memset(sks, 0, sizeof(sks));
720 sks[0] = 0x80;
721 if (c_d)
722 sks[0] |= 0x40;
723 if (in_bit >= 0) {
724 sks[0] |= 0x8;
725 sks[0] |= 0x7 & in_bit;
726 }
727 put_unaligned_be16(in_byte, sks + 1);
728 if (scsi_debug_dsense) {
729 sl = sbuff[7] + 8;
730 sbuff[7] = sl;
731 sbuff[sl] = 0x2;
732 sbuff[sl + 1] = 0x6;
733 memcpy(sbuff + sl + 4, sks, 3);
734 } else
735 memcpy(sbuff + 15, sks, 3);
736 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
737 sdev_printk(KERN_INFO, scp->device, "%s: [sense_key,asc,ascq"
738 "]: [0x5,0x%x,0x0] %c byte=%d, bit=%d\n",
739 my_name, asc, c_d ? 'C' : 'D', in_byte, in_bit);
740}
741
397static void mk_sense_buffer(struct scsi_cmnd *scp, int key, int asc, int asq) 742static void mk_sense_buffer(struct scsi_cmnd *scp, int key, int asc, int asq)
398{ 743{
399 unsigned char *sbuff; 744 unsigned char *sbuff;
@@ -414,63 +759,10 @@ static void mk_sense_buffer(struct scsi_cmnd *scp, int key, int asc, int asq)
414 my_name, key, asc, asq); 759 my_name, key, asc, asq);
415} 760}
416 761
417static void get_data_transfer_info(unsigned char *cmd, 762static void
418 unsigned long long *lba, unsigned int *num, 763mk_sense_invalid_opcode(struct scsi_cmnd *scp)
419 u32 *ei_lba)
420{ 764{
421 *ei_lba = 0; 765 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_OPCODE, 0);
422
423 switch (*cmd) {
424 case VARIABLE_LENGTH_CMD:
425 *lba = (u64)cmd[19] | (u64)cmd[18] << 8 |
426 (u64)cmd[17] << 16 | (u64)cmd[16] << 24 |
427 (u64)cmd[15] << 32 | (u64)cmd[14] << 40 |
428 (u64)cmd[13] << 48 | (u64)cmd[12] << 56;
429
430 *ei_lba = (u32)cmd[23] | (u32)cmd[22] << 8 |
431 (u32)cmd[21] << 16 | (u32)cmd[20] << 24;
432
433 *num = (u32)cmd[31] | (u32)cmd[30] << 8 | (u32)cmd[29] << 16 |
434 (u32)cmd[28] << 24;
435 break;
436
437 case WRITE_SAME_16:
438 case WRITE_16:
439 case READ_16:
440 *lba = (u64)cmd[9] | (u64)cmd[8] << 8 |
441 (u64)cmd[7] << 16 | (u64)cmd[6] << 24 |
442 (u64)cmd[5] << 32 | (u64)cmd[4] << 40 |
443 (u64)cmd[3] << 48 | (u64)cmd[2] << 56;
444
445 *num = (u32)cmd[13] | (u32)cmd[12] << 8 | (u32)cmd[11] << 16 |
446 (u32)cmd[10] << 24;
447 break;
448 case WRITE_12:
449 case READ_12:
450 *lba = (u32)cmd[5] | (u32)cmd[4] << 8 | (u32)cmd[3] << 16 |
451 (u32)cmd[2] << 24;
452
453 *num = (u32)cmd[9] | (u32)cmd[8] << 8 | (u32)cmd[7] << 16 |
454 (u32)cmd[6] << 24;
455 break;
456 case WRITE_SAME:
457 case WRITE_10:
458 case READ_10:
459 case XDWRITEREAD_10:
460 *lba = (u32)cmd[5] | (u32)cmd[4] << 8 | (u32)cmd[3] << 16 |
461 (u32)cmd[2] << 24;
462
463 *num = (u32)cmd[8] | (u32)cmd[7] << 8;
464 break;
465 case WRITE_6:
466 case READ_6:
467 *lba = (u32)cmd[3] | (u32)cmd[2] << 8 |
468 (u32)(cmd[1] & 0x1f) << 16;
469 *num = (0 == cmd[4]) ? 256 : cmd[4];
470 break;
471 default:
472 break;
473 }
474} 766}
475 767
476static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg) 768static int scsi_debug_ioctl(struct scsi_device *dev, int cmd, void __user *arg)
@@ -520,6 +812,11 @@ static int check_readiness(struct scsi_cmnd *SCpnt, int uas_only,
520 if (debug) 812 if (debug)
521 cp = "mode parameters changed"; 813 cp = "mode parameters changed";
522 break; 814 break;
815 case SDEBUG_UA_CAPACITY_CHANGED:
816 mk_sense_buffer(SCpnt, UNIT_ATTENTION,
817 UA_CHANGED_ASC, CAPACITY_CHANGED_ASCQ);
818 if (debug)
819 cp = "capacity data changed";
523 default: 820 default:
524 pr_warn("%s: unexpected unit attention code=%d\n", 821 pr_warn("%s: unexpected unit attention code=%d\n",
525 __func__, k); 822 __func__, k);
@@ -924,19 +1221,20 @@ static int inquiry_evpd_b2(unsigned char *arr)
924#define SDEBUG_LONG_INQ_SZ 96 1221#define SDEBUG_LONG_INQ_SZ 96
925#define SDEBUG_MAX_INQ_ARR_SZ 584 1222#define SDEBUG_MAX_INQ_ARR_SZ 584
926 1223
927static int resp_inquiry(struct scsi_cmnd *scp, int target, 1224static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
928 struct sdebug_dev_info * devip)
929{ 1225{
930 unsigned char pq_pdt; 1226 unsigned char pq_pdt;
931 unsigned char * arr; 1227 unsigned char * arr;
932 unsigned char *cmd = scp->cmnd; 1228 unsigned char *cmd = scp->cmnd;
933 int alloc_len, n, ret; 1229 int alloc_len, n, ret;
1230 bool have_wlun;
934 1231
935 alloc_len = (cmd[3] << 8) + cmd[4]; 1232 alloc_len = (cmd[3] << 8) + cmd[4];
936 arr = kzalloc(SDEBUG_MAX_INQ_ARR_SZ, GFP_ATOMIC); 1233 arr = kzalloc(SDEBUG_MAX_INQ_ARR_SZ, GFP_ATOMIC);
937 if (! arr) 1234 if (! arr)
938 return DID_REQUEUE << 16; 1235 return DID_REQUEUE << 16;
939 if (devip->wlun) 1236 have_wlun = (scp->device->lun == SAM2_WLUN_REPORT_LUNS);
1237 if (have_wlun)
940 pq_pdt = 0x1e; /* present, wlun */ 1238 pq_pdt = 0x1e; /* present, wlun */
941 else if (scsi_debug_no_lun_0 && (0 == devip->lun)) 1239 else if (scsi_debug_no_lun_0 && (0 == devip->lun))
942 pq_pdt = 0x7f; /* not present, no device type */ 1240 pq_pdt = 0x7f; /* not present, no device type */
@@ -944,8 +1242,7 @@ static int resp_inquiry(struct scsi_cmnd *scp, int target,
944 pq_pdt = (scsi_debug_ptype & 0x1f); 1242 pq_pdt = (scsi_debug_ptype & 0x1f);
945 arr[0] = pq_pdt; 1243 arr[0] = pq_pdt;
946 if (0x2 & cmd[1]) { /* CMDDT bit set */ 1244 if (0x2 & cmd[1]) { /* CMDDT bit set */
947 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 1245 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, 1);
948 0);
949 kfree(arr); 1246 kfree(arr);
950 return check_condition_result; 1247 return check_condition_result;
951 } else if (0x1 & cmd[1]) { /* EVPD bit set */ 1248 } else if (0x1 & cmd[1]) { /* EVPD bit set */
@@ -957,7 +1254,7 @@ static int resp_inquiry(struct scsi_cmnd *scp, int target,
957 (devip->channel & 0x7f); 1254 (devip->channel & 0x7f);
958 if (0 == scsi_debug_vpd_use_hostno) 1255 if (0 == scsi_debug_vpd_use_hostno)
959 host_no = 0; 1256 host_no = 0;
960 lu_id_num = devip->wlun ? -1 : (((host_no + 1) * 2000) + 1257 lu_id_num = have_wlun ? -1 : (((host_no + 1) * 2000) +
961 (devip->target * 1000) + devip->lun); 1258 (devip->target * 1000) + devip->lun);
962 target_dev_id = ((host_no + 1) * 2000) + 1259 target_dev_id = ((host_no + 1) * 2000) +
963 (devip->target * 1000) - 3; 1260 (devip->target * 1000) - 3;
@@ -1029,9 +1326,7 @@ static int resp_inquiry(struct scsi_cmnd *scp, int target,
1029 arr[1] = cmd[2]; /*sanity */ 1326 arr[1] = cmd[2]; /*sanity */
1030 arr[3] = inquiry_evpd_b2(&arr[4]); 1327 arr[3] = inquiry_evpd_b2(&arr[4]);
1031 } else { 1328 } else {
1032 /* Illegal request, invalid field in cdb */ 1329 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, -1);
1033 mk_sense_buffer(scp, ILLEGAL_REQUEST,
1034 INVALID_FIELD_IN_CDB, 0);
1035 kfree(arr); 1330 kfree(arr);
1036 return check_condition_result; 1331 return check_condition_result;
1037 } 1332 }
@@ -1077,18 +1372,20 @@ static int resp_requests(struct scsi_cmnd * scp,
1077 unsigned char * sbuff; 1372 unsigned char * sbuff;
1078 unsigned char *cmd = scp->cmnd; 1373 unsigned char *cmd = scp->cmnd;
1079 unsigned char arr[SCSI_SENSE_BUFFERSIZE]; 1374 unsigned char arr[SCSI_SENSE_BUFFERSIZE];
1080 int want_dsense; 1375 bool dsense, want_dsense;
1081 int len = 18; 1376 int len = 18;
1082 1377
1083 memset(arr, 0, sizeof(arr)); 1378 memset(arr, 0, sizeof(arr));
1084 want_dsense = !!(cmd[1] & 1) || scsi_debug_dsense; 1379 dsense = !!(cmd[1] & 1);
1380 want_dsense = dsense || scsi_debug_dsense;
1085 sbuff = scp->sense_buffer; 1381 sbuff = scp->sense_buffer;
1086 if ((iec_m_pg[2] & 0x4) && (6 == (iec_m_pg[3] & 0xf))) { 1382 if ((iec_m_pg[2] & 0x4) && (6 == (iec_m_pg[3] & 0xf))) {
1087 if (want_dsense) { 1383 if (dsense) {
1088 arr[0] = 0x72; 1384 arr[0] = 0x72;
1089 arr[1] = 0x0; /* NO_SENSE in sense_key */ 1385 arr[1] = 0x0; /* NO_SENSE in sense_key */
1090 arr[2] = THRESHOLD_EXCEEDED; 1386 arr[2] = THRESHOLD_EXCEEDED;
1091 arr[3] = 0xff; /* TEST set and MRIE==6 */ 1387 arr[3] = 0xff; /* TEST set and MRIE==6 */
1388 len = 8;
1092 } else { 1389 } else {
1093 arr[0] = 0x70; 1390 arr[0] = 0x70;
1094 arr[2] = 0x0; /* NO_SENSE in sense_key */ 1391 arr[2] = 0x0; /* NO_SENSE in sense_key */
@@ -1098,15 +1395,34 @@ static int resp_requests(struct scsi_cmnd * scp,
1098 } 1395 }
1099 } else { 1396 } else {
1100 memcpy(arr, sbuff, SCSI_SENSE_BUFFERSIZE); 1397 memcpy(arr, sbuff, SCSI_SENSE_BUFFERSIZE);
1101 if ((cmd[1] & 1) && (! scsi_debug_dsense)) { 1398 if (arr[0] >= 0x70 && dsense == scsi_debug_dsense)
1102 /* DESC bit set and sense_buff in fixed format */ 1399 ; /* have sense and formats match */
1103 memset(arr, 0, sizeof(arr)); 1400 else if (arr[0] <= 0x70) {
1401 if (dsense) {
1402 memset(arr, 0, 8);
1403 arr[0] = 0x72;
1404 len = 8;
1405 } else {
1406 memset(arr, 0, 18);
1407 arr[0] = 0x70;
1408 arr[7] = 0xa;
1409 }
1410 } else if (dsense) {
1411 memset(arr, 0, 8);
1104 arr[0] = 0x72; 1412 arr[0] = 0x72;
1105 arr[1] = sbuff[2]; /* sense key */ 1413 arr[1] = sbuff[2]; /* sense key */
1106 arr[2] = sbuff[12]; /* asc */ 1414 arr[2] = sbuff[12]; /* asc */
1107 arr[3] = sbuff[13]; /* ascq */ 1415 arr[3] = sbuff[13]; /* ascq */
1108 len = 8; 1416 len = 8;
1417 } else {
1418 memset(arr, 0, 18);
1419 arr[0] = 0x70;
1420 arr[2] = sbuff[1];
1421 arr[7] = 0xa;
1422 arr[12] = sbuff[1];
1423 arr[13] = sbuff[3];
1109 } 1424 }
1425
1110 } 1426 }
1111 mk_sense_buffer(scp, 0, NO_ADDITIONAL_SENSE, 0); 1427 mk_sense_buffer(scp, 0, NO_ADDITIONAL_SENSE, 0);
1112 return fill_from_dev_buffer(scp, arr, len); 1428 return fill_from_dev_buffer(scp, arr, len);
@@ -1116,15 +1432,11 @@ static int resp_start_stop(struct scsi_cmnd * scp,
1116 struct sdebug_dev_info * devip) 1432 struct sdebug_dev_info * devip)
1117{ 1433{
1118 unsigned char *cmd = scp->cmnd; 1434 unsigned char *cmd = scp->cmnd;
1119 int power_cond, errsts, start; 1435 int power_cond, start;
1120 1436
1121 errsts = check_readiness(scp, UAS_ONLY, devip);
1122 if (errsts)
1123 return errsts;
1124 power_cond = (cmd[4] & 0xf0) >> 4; 1437 power_cond = (cmd[4] & 0xf0) >> 4;
1125 if (power_cond) { 1438 if (power_cond) {
1126 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 1439 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 4, 7);
1127 0);
1128 return check_condition_result; 1440 return check_condition_result;
1129 } 1441 }
1130 start = cmd[4] & 1; 1442 start = cmd[4] & 1;
@@ -1148,11 +1460,7 @@ static int resp_readcap(struct scsi_cmnd * scp,
1148{ 1460{
1149 unsigned char arr[SDEBUG_READCAP_ARR_SZ]; 1461 unsigned char arr[SDEBUG_READCAP_ARR_SZ];
1150 unsigned int capac; 1462 unsigned int capac;
1151 int errsts;
1152 1463
1153 errsts = check_readiness(scp, UAS_ONLY, devip);
1154 if (errsts)
1155 return errsts;
1156 /* following just in case virtual_gb changed */ 1464 /* following just in case virtual_gb changed */
1157 sdebug_capacity = get_sdebug_capacity(); 1465 sdebug_capacity = get_sdebug_capacity();
1158 memset(arr, 0, SDEBUG_READCAP_ARR_SZ); 1466 memset(arr, 0, SDEBUG_READCAP_ARR_SZ);
@@ -1180,11 +1488,8 @@ static int resp_readcap16(struct scsi_cmnd * scp,
1180 unsigned char *cmd = scp->cmnd; 1488 unsigned char *cmd = scp->cmnd;
1181 unsigned char arr[SDEBUG_READCAP16_ARR_SZ]; 1489 unsigned char arr[SDEBUG_READCAP16_ARR_SZ];
1182 unsigned long long capac; 1490 unsigned long long capac;
1183 int errsts, k, alloc_len; 1491 int k, alloc_len;
1184 1492
1185 errsts = check_readiness(scp, UAS_ONLY, devip);
1186 if (errsts)
1187 return errsts;
1188 alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8) 1493 alloc_len = ((cmd[10] << 24) + (cmd[11] << 16) + (cmd[12] << 8)
1189 + cmd[13]); 1494 + cmd[13]);
1190 /* following just in case virtual_gb changed */ 1495 /* following just in case virtual_gb changed */
@@ -1300,6 +1605,184 @@ static int resp_report_tgtpgs(struct scsi_cmnd * scp,
1300 return ret; 1605 return ret;
1301} 1606}
1302 1607
1608static int
1609resp_rsup_opcodes(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1610{
1611 bool rctd;
1612 u8 reporting_opts, req_opcode, sdeb_i, supp;
1613 u16 req_sa, u;
1614 u32 alloc_len, a_len;
1615 int k, offset, len, errsts, count, bump, na;
1616 const struct opcode_info_t *oip;
1617 const struct opcode_info_t *r_oip;
1618 u8 *arr;
1619 u8 *cmd = scp->cmnd;
1620
1621 rctd = !!(cmd[2] & 0x80);
1622 reporting_opts = cmd[2] & 0x7;
1623 req_opcode = cmd[3];
1624 req_sa = get_unaligned_be16(cmd + 4);
1625 alloc_len = get_unaligned_be32(cmd + 6);
1626 if (alloc_len < 4 && alloc_len > 0xffff) {
1627 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1);
1628 return check_condition_result;
1629 }
1630 if (alloc_len > 8192)
1631 a_len = 8192;
1632 else
1633 a_len = alloc_len;
1634 arr = kzalloc((a_len < 256) ? 320 : a_len + 64, GFP_KERNEL);
1635 if (NULL == arr) {
1636 mk_sense_buffer(scp, ILLEGAL_REQUEST, INSUFF_RES_ASC,
1637 INSUFF_RES_ASCQ);
1638 return check_condition_result;
1639 }
1640 switch (reporting_opts) {
1641 case 0: /* all commands */
1642 /* count number of commands */
1643 for (count = 0, oip = opcode_info_arr;
1644 oip->num_attached != 0xff; ++oip) {
1645 if (F_INV_OP & oip->flags)
1646 continue;
1647 count += (oip->num_attached + 1);
1648 }
1649 bump = rctd ? 20 : 8;
1650 put_unaligned_be32(count * bump, arr);
1651 for (offset = 4, oip = opcode_info_arr;
1652 oip->num_attached != 0xff && offset < a_len; ++oip) {
1653 if (F_INV_OP & oip->flags)
1654 continue;
1655 na = oip->num_attached;
1656 arr[offset] = oip->opcode;
1657 put_unaligned_be16(oip->sa, arr + offset + 2);
1658 if (rctd)
1659 arr[offset + 5] |= 0x2;
1660 if (FF_SA & oip->flags)
1661 arr[offset + 5] |= 0x1;
1662 put_unaligned_be16(oip->len_mask[0], arr + offset + 6);
1663 if (rctd)
1664 put_unaligned_be16(0xa, arr + offset + 8);
1665 r_oip = oip;
1666 for (k = 0, oip = oip->arrp; k < na; ++k, ++oip) {
1667 if (F_INV_OP & oip->flags)
1668 continue;
1669 offset += bump;
1670 arr[offset] = oip->opcode;
1671 put_unaligned_be16(oip->sa, arr + offset + 2);
1672 if (rctd)
1673 arr[offset + 5] |= 0x2;
1674 if (FF_SA & oip->flags)
1675 arr[offset + 5] |= 0x1;
1676 put_unaligned_be16(oip->len_mask[0],
1677 arr + offset + 6);
1678 if (rctd)
1679 put_unaligned_be16(0xa,
1680 arr + offset + 8);
1681 }
1682 oip = r_oip;
1683 offset += bump;
1684 }
1685 break;
1686 case 1: /* one command: opcode only */
1687 case 2: /* one command: opcode plus service action */
1688 case 3: /* one command: if sa==0 then opcode only else opcode+sa */
1689 sdeb_i = opcode_ind_arr[req_opcode];
1690 oip = &opcode_info_arr[sdeb_i];
1691 if (F_INV_OP & oip->flags) {
1692 supp = 1;
1693 offset = 4;
1694 } else {
1695 if (1 == reporting_opts) {
1696 if (FF_SA & oip->flags) {
1697 mk_sense_invalid_fld(scp, SDEB_IN_CDB,
1698 2, 2);
1699 kfree(arr);
1700 return check_condition_result;
1701 }
1702 req_sa = 0;
1703 } else if (2 == reporting_opts &&
1704 0 == (FF_SA & oip->flags)) {
1705 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 4, -1);
1706 kfree(arr); /* point at requested sa */
1707 return check_condition_result;
1708 }
1709 if (0 == (FF_SA & oip->flags) &&
1710 req_opcode == oip->opcode)
1711 supp = 3;
1712 else if (0 == (FF_SA & oip->flags)) {
1713 na = oip->num_attached;
1714 for (k = 0, oip = oip->arrp; k < na;
1715 ++k, ++oip) {
1716 if (req_opcode == oip->opcode)
1717 break;
1718 }
1719 supp = (k >= na) ? 1 : 3;
1720 } else if (req_sa != oip->sa) {
1721 na = oip->num_attached;
1722 for (k = 0, oip = oip->arrp; k < na;
1723 ++k, ++oip) {
1724 if (req_sa == oip->sa)
1725 break;
1726 }
1727 supp = (k >= na) ? 1 : 3;
1728 } else
1729 supp = 3;
1730 if (3 == supp) {
1731 u = oip->len_mask[0];
1732 put_unaligned_be16(u, arr + 2);
1733 arr[4] = oip->opcode;
1734 for (k = 1; k < u; ++k)
1735 arr[4 + k] = (k < 16) ?
1736 oip->len_mask[k] : 0xff;
1737 offset = 4 + u;
1738 } else
1739 offset = 4;
1740 }
1741 arr[1] = (rctd ? 0x80 : 0) | supp;
1742 if (rctd) {
1743 put_unaligned_be16(0xa, arr + offset);
1744 offset += 12;
1745 }
1746 break;
1747 default:
1748 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, 2);
1749 kfree(arr);
1750 return check_condition_result;
1751 }
1752 offset = (offset < a_len) ? offset : a_len;
1753 len = (offset < alloc_len) ? offset : alloc_len;
1754 errsts = fill_from_dev_buffer(scp, arr, len);
1755 kfree(arr);
1756 return errsts;
1757}
1758
1759static int
1760resp_rsup_tmfs(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1761{
1762 bool repd;
1763 u32 alloc_len, len;
1764 u8 arr[16];
1765 u8 *cmd = scp->cmnd;
1766
1767 memset(arr, 0, sizeof(arr));
1768 repd = !!(cmd[2] & 0x80);
1769 alloc_len = get_unaligned_be32(cmd + 6);
1770 if (alloc_len < 4) {
1771 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 6, -1);
1772 return check_condition_result;
1773 }
1774 arr[0] = 0xc8; /* ATS | ATSS | LURS */
1775 arr[1] = 0x1; /* ITNRS */
1776 if (repd) {
1777 arr[3] = 0xc;
1778 len = 16;
1779 } else
1780 len = 4;
1781
1782 len = (len < alloc_len) ? len : alloc_len;
1783 return fill_from_dev_buffer(scp, arr, len);
1784}
1785
1303/* <<Following mode page info copied from ST318451LW>> */ 1786/* <<Following mode page info copied from ST318451LW>> */
1304 1787
1305static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target) 1788static int resp_err_recov_pg(unsigned char * p, int pcontrol, int target)
@@ -1459,20 +1942,18 @@ static int resp_sas_sha_m_spg(unsigned char * p, int pcontrol)
1459 1942
1460#define SDEBUG_MAX_MSENSE_SZ 256 1943#define SDEBUG_MAX_MSENSE_SZ 256
1461 1944
1462static int resp_mode_sense(struct scsi_cmnd * scp, int target, 1945static int
1463 struct sdebug_dev_info * devip) 1946resp_mode_sense(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1464{ 1947{
1465 unsigned char dbd, llbaa; 1948 unsigned char dbd, llbaa;
1466 int pcontrol, pcode, subpcode, bd_len; 1949 int pcontrol, pcode, subpcode, bd_len;
1467 unsigned char dev_spec; 1950 unsigned char dev_spec;
1468 int k, alloc_len, msense_6, offset, len, errsts, target_dev_id; 1951 int k, alloc_len, msense_6, offset, len, target_dev_id;
1952 int target = scp->device->id;
1469 unsigned char * ap; 1953 unsigned char * ap;
1470 unsigned char arr[SDEBUG_MAX_MSENSE_SZ]; 1954 unsigned char arr[SDEBUG_MAX_MSENSE_SZ];
1471 unsigned char *cmd = scp->cmnd; 1955 unsigned char *cmd = scp->cmnd;
1472 1956
1473 errsts = check_readiness(scp, UAS_ONLY, devip);
1474 if (errsts)
1475 return errsts;
1476 dbd = !!(cmd[1] & 0x8); 1957 dbd = !!(cmd[1] & 0x8);
1477 pcontrol = (cmd[2] & 0xc0) >> 6; 1958 pcontrol = (cmd[2] & 0xc0) >> 6;
1478 pcode = cmd[2] & 0x3f; 1959 pcode = cmd[2] & 0x3f;
@@ -1542,8 +2023,7 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target,
1542 2023
1543 if ((subpcode > 0x0) && (subpcode < 0xff) && (0x19 != pcode)) { 2024 if ((subpcode > 0x0) && (subpcode < 0xff) && (0x19 != pcode)) {
1544 /* TODO: Control Extension page */ 2025 /* TODO: Control Extension page */
1545 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 2026 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1);
1546 0);
1547 return check_condition_result; 2027 return check_condition_result;
1548 } 2028 }
1549 switch (pcode) { 2029 switch (pcode) {
@@ -1569,8 +2049,7 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target,
1569 break; 2049 break;
1570 case 0x19: /* if spc==1 then sas phy, control+discover */ 2050 case 0x19: /* if spc==1 then sas phy, control+discover */
1571 if ((subpcode > 0x2) && (subpcode < 0xff)) { 2051 if ((subpcode > 0x2) && (subpcode < 0xff)) {
1572 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2052 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1);
1573 INVALID_FIELD_IN_CDB, 0);
1574 return check_condition_result; 2053 return check_condition_result;
1575 } 2054 }
1576 len = 0; 2055 len = 0;
@@ -1602,15 +2081,13 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target,
1602 } 2081 }
1603 len += resp_iec_m_pg(ap + len, pcontrol, target); 2082 len += resp_iec_m_pg(ap + len, pcontrol, target);
1604 } else { 2083 } else {
1605 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2084 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1);
1606 INVALID_FIELD_IN_CDB, 0);
1607 return check_condition_result; 2085 return check_condition_result;
1608 } 2086 }
1609 offset += len; 2087 offset += len;
1610 break; 2088 break;
1611 default: 2089 default:
1612 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 2090 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, 5);
1613 0);
1614 return check_condition_result; 2091 return check_condition_result;
1615 } 2092 }
1616 if (msense_6) 2093 if (msense_6)
@@ -1624,24 +2101,21 @@ static int resp_mode_sense(struct scsi_cmnd * scp, int target,
1624 2101
1625#define SDEBUG_MAX_MSELECT_SZ 512 2102#define SDEBUG_MAX_MSELECT_SZ 512
1626 2103
1627static int resp_mode_select(struct scsi_cmnd * scp, int mselect6, 2104static int
1628 struct sdebug_dev_info * devip) 2105resp_mode_select(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1629{ 2106{
1630 int pf, sp, ps, md_len, bd_len, off, spf, pg_len; 2107 int pf, sp, ps, md_len, bd_len, off, spf, pg_len;
1631 int param_len, res, errsts, mpage; 2108 int param_len, res, mpage;
1632 unsigned char arr[SDEBUG_MAX_MSELECT_SZ]; 2109 unsigned char arr[SDEBUG_MAX_MSELECT_SZ];
1633 unsigned char *cmd = scp->cmnd; 2110 unsigned char *cmd = scp->cmnd;
2111 int mselect6 = (MODE_SELECT == cmd[0]);
1634 2112
1635 errsts = check_readiness(scp, UAS_ONLY, devip);
1636 if (errsts)
1637 return errsts;
1638 memset(arr, 0, sizeof(arr)); 2113 memset(arr, 0, sizeof(arr));
1639 pf = cmd[1] & 0x10; 2114 pf = cmd[1] & 0x10;
1640 sp = cmd[1] & 0x1; 2115 sp = cmd[1] & 0x1;
1641 param_len = mselect6 ? cmd[4] : ((cmd[7] << 8) + cmd[8]); 2116 param_len = mselect6 ? cmd[4] : ((cmd[7] << 8) + cmd[8]);
1642 if ((0 == pf) || sp || (param_len > SDEBUG_MAX_MSELECT_SZ)) { 2117 if ((0 == pf) || sp || (param_len > SDEBUG_MAX_MSELECT_SZ)) {
1643 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2118 mk_sense_invalid_fld(scp, SDEB_IN_CDB, mselect6 ? 4 : 7, -1);
1644 INVALID_FIELD_IN_CDB, 0);
1645 return check_condition_result; 2119 return check_condition_result;
1646 } 2120 }
1647 res = fetch_to_dev_buffer(scp, arr, param_len); 2121 res = fetch_to_dev_buffer(scp, arr, param_len);
@@ -1655,16 +2129,14 @@ static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
1655 md_len = mselect6 ? (arr[0] + 1) : ((arr[0] << 8) + arr[1] + 2); 2129 md_len = mselect6 ? (arr[0] + 1) : ((arr[0] << 8) + arr[1] + 2);
1656 bd_len = mselect6 ? arr[3] : ((arr[6] << 8) + arr[7]); 2130 bd_len = mselect6 ? arr[3] : ((arr[6] << 8) + arr[7]);
1657 if (md_len > 2) { 2131 if (md_len > 2) {
1658 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2132 mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1);
1659 INVALID_FIELD_IN_PARAM_LIST, 0);
1660 return check_condition_result; 2133 return check_condition_result;
1661 } 2134 }
1662 off = bd_len + (mselect6 ? 4 : 8); 2135 off = bd_len + (mselect6 ? 4 : 8);
1663 mpage = arr[off] & 0x3f; 2136 mpage = arr[off] & 0x3f;
1664 ps = !!(arr[off] & 0x80); 2137 ps = !!(arr[off] & 0x80);
1665 if (ps) { 2138 if (ps) {
1666 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2139 mk_sense_invalid_fld(scp, SDEB_IN_DATA, off, 7);
1667 INVALID_FIELD_IN_PARAM_LIST, 0);
1668 return check_condition_result; 2140 return check_condition_result;
1669 } 2141 }
1670 spf = !!(arr[off] & 0x40); 2142 spf = !!(arr[off] & 0x40);
@@ -1701,8 +2173,7 @@ static int resp_mode_select(struct scsi_cmnd * scp, int mselect6,
1701 default: 2173 default:
1702 break; 2174 break;
1703 } 2175 }
1704 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2176 mk_sense_invalid_fld(scp, SDEB_IN_DATA, off, 5);
1705 INVALID_FIELD_IN_PARAM_LIST, 0);
1706 return check_condition_result; 2177 return check_condition_result;
1707set_mode_changed_ua: 2178set_mode_changed_ua:
1708 set_bit(SDEBUG_UA_MODE_CHANGED, devip->uas_bm); 2179 set_bit(SDEBUG_UA_MODE_CHANGED, devip->uas_bm);
@@ -1737,19 +2208,15 @@ static int resp_ie_l_pg(unsigned char * arr)
1737static int resp_log_sense(struct scsi_cmnd * scp, 2208static int resp_log_sense(struct scsi_cmnd * scp,
1738 struct sdebug_dev_info * devip) 2209 struct sdebug_dev_info * devip)
1739{ 2210{
1740 int ppc, sp, pcontrol, pcode, subpcode, alloc_len, errsts, len, n; 2211 int ppc, sp, pcontrol, pcode, subpcode, alloc_len, len, n;
1741 unsigned char arr[SDEBUG_MAX_LSENSE_SZ]; 2212 unsigned char arr[SDEBUG_MAX_LSENSE_SZ];
1742 unsigned char *cmd = scp->cmnd; 2213 unsigned char *cmd = scp->cmnd;
1743 2214
1744 errsts = check_readiness(scp, UAS_ONLY, devip);
1745 if (errsts)
1746 return errsts;
1747 memset(arr, 0, sizeof(arr)); 2215 memset(arr, 0, sizeof(arr));
1748 ppc = cmd[1] & 0x2; 2216 ppc = cmd[1] & 0x2;
1749 sp = cmd[1] & 0x1; 2217 sp = cmd[1] & 0x1;
1750 if (ppc || sp) { 2218 if (ppc || sp) {
1751 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2219 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, ppc ? 1 : 0);
1752 INVALID_FIELD_IN_CDB, 0);
1753 return check_condition_result; 2220 return check_condition_result;
1754 } 2221 }
1755 pcontrol = (cmd[2] & 0xc0) >> 6; 2222 pcontrol = (cmd[2] & 0xc0) >> 6;
@@ -1773,8 +2240,7 @@ static int resp_log_sense(struct scsi_cmnd * scp,
1773 arr[3] = resp_ie_l_pg(arr + 4); 2240 arr[3] = resp_ie_l_pg(arr + 4);
1774 break; 2241 break;
1775 default: 2242 default:
1776 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2243 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, 5);
1777 INVALID_FIELD_IN_CDB, 0);
1778 return check_condition_result; 2244 return check_condition_result;
1779 } 2245 }
1780 } else if (0xff == subpcode) { 2246 } else if (0xff == subpcode) {
@@ -1806,13 +2272,11 @@ static int resp_log_sense(struct scsi_cmnd * scp,
1806 arr[3] = n - 4; 2272 arr[3] = n - 4;
1807 break; 2273 break;
1808 default: 2274 default:
1809 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2275 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 2, 5);
1810 INVALID_FIELD_IN_CDB, 0);
1811 return check_condition_result; 2276 return check_condition_result;
1812 } 2277 }
1813 } else { 2278 } else {
1814 mk_sense_buffer(scp, ILLEGAL_REQUEST, 2279 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 3, -1);
1815 INVALID_FIELD_IN_CDB, 0);
1816 return check_condition_result; 2280 return check_condition_result;
1817 } 2281 }
1818 len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len); 2282 len = min(((arr[2] << 8) + arr[3]) + 4, alloc_len);
@@ -1824,11 +2288,12 @@ static int check_device_access_params(struct scsi_cmnd *scp,
1824 unsigned long long lba, unsigned int num) 2288 unsigned long long lba, unsigned int num)
1825{ 2289{
1826 if (lba + num > sdebug_capacity) { 2290 if (lba + num > sdebug_capacity) {
1827 mk_sense_buffer(scp, ILLEGAL_REQUEST, ADDR_OUT_OF_RANGE, 0); 2291 mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, 0);
1828 return check_condition_result; 2292 return check_condition_result;
1829 } 2293 }
1830 /* transfer length excessive (tie in to block limits VPD page) */ 2294 /* transfer length excessive (tie in to block limits VPD page) */
1831 if (num > sdebug_store_sectors) { 2295 if (num > sdebug_store_sectors) {
2296 /* needs work to find which cdb byte 'num' comes from */
1832 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0); 2297 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0);
1833 return check_condition_result; 2298 return check_condition_result;
1834 } 2299 }
@@ -1836,17 +2301,17 @@ static int check_device_access_params(struct scsi_cmnd *scp,
1836} 2301}
1837 2302
1838/* Returns number of bytes copied or -1 if error. */ 2303/* Returns number of bytes copied or -1 if error. */
1839static int do_device_access(struct scsi_cmnd *scmd, 2304static int
1840 unsigned long long lba, unsigned int num, int write) 2305do_device_access(struct scsi_cmnd *scmd, u64 lba, u32 num, bool do_write)
1841{ 2306{
1842 int ret; 2307 int ret;
1843 unsigned long long block, rest = 0; 2308 u64 block, rest = 0;
1844 struct scsi_data_buffer *sdb; 2309 struct scsi_data_buffer *sdb;
1845 enum dma_data_direction dir; 2310 enum dma_data_direction dir;
1846 size_t (*func)(struct scatterlist *, unsigned int, void *, size_t, 2311 size_t (*func)(struct scatterlist *, unsigned int, void *, size_t,
1847 off_t); 2312 off_t);
1848 2313
1849 if (write) { 2314 if (do_write) {
1850 sdb = scsi_out(scmd); 2315 sdb = scsi_out(scmd);
1851 dir = DMA_TO_DEVICE; 2316 dir = DMA_TO_DEVICE;
1852 func = sg_pcopy_to_buffer; 2317 func = sg_pcopy_to_buffer;
@@ -1880,6 +2345,38 @@ static int do_device_access(struct scsi_cmnd *scmd,
1880 return ret; 2345 return ret;
1881} 2346}
1882 2347
2348/* If fake_store(lba,num) compares equal to arr(num), then copy top half of
2349 * arr into fake_store(lba,num) and return true. If comparison fails then
2350 * return false. */
2351static bool
2352comp_write_worker(u64 lba, u32 num, const u8 *arr)
2353{
2354 bool res;
2355 u64 block, rest = 0;
2356 u32 store_blks = sdebug_store_sectors;
2357 u32 lb_size = scsi_debug_sector_size;
2358
2359 block = do_div(lba, store_blks);
2360 if (block + num > store_blks)
2361 rest = block + num - store_blks;
2362
2363 res = !memcmp(fake_storep + (block * lb_size), arr,
2364 (num - rest) * lb_size);
2365 if (!res)
2366 return res;
2367 if (rest)
2368 res = memcmp(fake_storep, arr + ((num - rest) * lb_size),
2369 rest * lb_size);
2370 if (!res)
2371 return res;
2372 arr += num * lb_size;
2373 memcpy(fake_storep + (block * lb_size), arr, (num - rest) * lb_size);
2374 if (rest)
2375 memcpy(fake_storep, arr + ((num - rest) * lb_size),
2376 rest * lb_size);
2377 return res;
2378}
2379
1883static __be16 dif_compute_csum(const void *buf, int len) 2380static __be16 dif_compute_csum(const void *buf, int len)
1884{ 2381{
1885 __be16 csum; 2382 __be16 csum;
@@ -1992,55 +2489,143 @@ static int prot_verify_read(struct scsi_cmnd *SCpnt, sector_t start_sec,
1992 return 0; 2489 return 0;
1993} 2490}
1994 2491
1995static int resp_read(struct scsi_cmnd *SCpnt, unsigned long long lba, 2492static int
1996 unsigned int num, u32 ei_lba) 2493resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1997{ 2494{
2495 u8 *cmd = scp->cmnd;
2496 u64 lba;
2497 u32 num;
2498 u32 ei_lba;
1998 unsigned long iflags; 2499 unsigned long iflags;
1999 int ret; 2500 int ret;
2501 bool check_prot;
2000 2502
2001 ret = check_device_access_params(SCpnt, lba, num); 2503 switch (cmd[0]) {
2002 if (ret) 2504 case READ_16:
2003 return ret; 2505 ei_lba = 0;
2506 lba = get_unaligned_be64(cmd + 2);
2507 num = get_unaligned_be32(cmd + 10);
2508 check_prot = true;
2509 break;
2510 case READ_10:
2511 ei_lba = 0;
2512 lba = get_unaligned_be32(cmd + 2);
2513 num = get_unaligned_be16(cmd + 7);
2514 check_prot = true;
2515 break;
2516 case READ_6:
2517 ei_lba = 0;
2518 lba = (u32)cmd[3] | (u32)cmd[2] << 8 |
2519 (u32)(cmd[1] & 0x1f) << 16;
2520 num = (0 == cmd[4]) ? 256 : cmd[4];
2521 check_prot = true;
2522 break;
2523 case READ_12:
2524 ei_lba = 0;
2525 lba = get_unaligned_be32(cmd + 2);
2526 num = get_unaligned_be32(cmd + 6);
2527 check_prot = true;
2528 break;
2529 case XDWRITEREAD_10:
2530 ei_lba = 0;
2531 lba = get_unaligned_be32(cmd + 2);
2532 num = get_unaligned_be16(cmd + 7);
2533 check_prot = false;
2534 break;
2535 default: /* assume READ(32) */
2536 lba = get_unaligned_be64(cmd + 12);
2537 ei_lba = get_unaligned_be32(cmd + 20);
2538 num = get_unaligned_be32(cmd + 28);
2539 check_prot = false;
2540 break;
2541 }
2542 if (check_prot) {
2543 if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION &&
2544 (cmd[1] & 0xe0)) {
2545 mk_sense_invalid_opcode(scp);
2546 return check_condition_result;
2547 }
2548 if ((scsi_debug_dif == SD_DIF_TYPE1_PROTECTION ||
2549 scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) &&
2550 (cmd[1] & 0xe0) == 0)
2551 sdev_printk(KERN_ERR, scp->device, "Unprotected RD "
2552 "to DIF device\n");
2553 }
2554 if (sdebug_any_injecting_opt) {
2555 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp);
2556
2557 if (ep->inj_short)
2558 num /= 2;
2559 }
2560
2561 /* inline check_device_access_params() */
2562 if (lba + num > sdebug_capacity) {
2563 mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, 0);
2564 return check_condition_result;
2565 }
2566 /* transfer length excessive (tie in to block limits VPD page) */
2567 if (num > sdebug_store_sectors) {
2568 /* needs work to find which cdb byte 'num' comes from */
2569 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0);
2570 return check_condition_result;
2571 }
2004 2572
2005 if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) && 2573 if ((SCSI_DEBUG_OPT_MEDIUM_ERR & scsi_debug_opts) &&
2006 (lba <= (OPT_MEDIUM_ERR_ADDR + OPT_MEDIUM_ERR_NUM - 1)) && 2574 (lba <= (OPT_MEDIUM_ERR_ADDR + OPT_MEDIUM_ERR_NUM - 1)) &&
2007 ((lba + num) > OPT_MEDIUM_ERR_ADDR)) { 2575 ((lba + num) > OPT_MEDIUM_ERR_ADDR)) {
2008 /* claim unrecoverable read error */ 2576 /* claim unrecoverable read error */
2009 mk_sense_buffer(SCpnt, MEDIUM_ERROR, UNRECOVERED_READ_ERR, 0); 2577 mk_sense_buffer(scp, MEDIUM_ERROR, UNRECOVERED_READ_ERR, 0);
2010 /* set info field and valid bit for fixed descriptor */ 2578 /* set info field and valid bit for fixed descriptor */
2011 if (0x70 == (SCpnt->sense_buffer[0] & 0x7f)) { 2579 if (0x70 == (scp->sense_buffer[0] & 0x7f)) {
2012 SCpnt->sense_buffer[0] |= 0x80; /* Valid bit */ 2580 scp->sense_buffer[0] |= 0x80; /* Valid bit */
2013 ret = (lba < OPT_MEDIUM_ERR_ADDR) 2581 ret = (lba < OPT_MEDIUM_ERR_ADDR)
2014 ? OPT_MEDIUM_ERR_ADDR : (int)lba; 2582 ? OPT_MEDIUM_ERR_ADDR : (int)lba;
2015 SCpnt->sense_buffer[3] = (ret >> 24) & 0xff; 2583 put_unaligned_be32(ret, scp->sense_buffer + 3);
2016 SCpnt->sense_buffer[4] = (ret >> 16) & 0xff;
2017 SCpnt->sense_buffer[5] = (ret >> 8) & 0xff;
2018 SCpnt->sense_buffer[6] = ret & 0xff;
2019 } 2584 }
2020 scsi_set_resid(SCpnt, scsi_bufflen(SCpnt)); 2585 scsi_set_resid(scp, scsi_bufflen(scp));
2021 return check_condition_result; 2586 return check_condition_result;
2022 } 2587 }
2023 2588
2024 read_lock_irqsave(&atomic_rw, iflags); 2589 read_lock_irqsave(&atomic_rw, iflags);
2025 2590
2026 /* DIX + T10 DIF */ 2591 /* DIX + T10 DIF */
2027 if (scsi_debug_dix && scsi_prot_sg_count(SCpnt)) { 2592 if (scsi_debug_dix && scsi_prot_sg_count(scp)) {
2028 int prot_ret = prot_verify_read(SCpnt, lba, num, ei_lba); 2593 int prot_ret = prot_verify_read(scp, lba, num, ei_lba);
2029 2594
2030 if (prot_ret) { 2595 if (prot_ret) {
2031 read_unlock_irqrestore(&atomic_rw, iflags); 2596 read_unlock_irqrestore(&atomic_rw, iflags);
2032 mk_sense_buffer(SCpnt, ABORTED_COMMAND, 0x10, prot_ret); 2597 mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, prot_ret);
2033 return illegal_condition_result; 2598 return illegal_condition_result;
2034 } 2599 }
2035 } 2600 }
2036 2601
2037 ret = do_device_access(SCpnt, lba, num, 0); 2602 ret = do_device_access(scp, lba, num, false);
2038 read_unlock_irqrestore(&atomic_rw, iflags); 2603 read_unlock_irqrestore(&atomic_rw, iflags);
2039 if (ret == -1) 2604 if (ret == -1)
2040 return DID_ERROR << 16; 2605 return DID_ERROR << 16;
2041 2606
2042 scsi_in(SCpnt)->resid = scsi_bufflen(SCpnt) - ret; 2607 scsi_in(scp)->resid = scsi_bufflen(scp) - ret;
2608
2609 if (sdebug_any_injecting_opt) {
2610 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp);
2043 2611
2612 if (ep->inj_recovered) {
2613 mk_sense_buffer(scp, RECOVERED_ERROR,
2614 THRESHOLD_EXCEEDED, 0);
2615 return check_condition_result;
2616 } else if (ep->inj_transport) {
2617 mk_sense_buffer(scp, ABORTED_COMMAND,
2618 TRANSPORT_PROBLEM, ACK_NAK_TO);
2619 return check_condition_result;
2620 } else if (ep->inj_dif) {
2621 /* Logical block guard check failed */
2622 mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1);
2623 return illegal_condition_result;
2624 } else if (ep->inj_dix) {
2625 mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1);
2626 return illegal_condition_result;
2627 }
2628 }
2044 return 0; 2629 return 0;
2045} 2630}
2046 2631
@@ -2223,31 +2808,95 @@ static void unmap_region(sector_t lba, unsigned int len)
2223 } 2808 }
2224} 2809}
2225 2810
2226static int resp_write(struct scsi_cmnd *SCpnt, unsigned long long lba, 2811static int
2227 unsigned int num, u32 ei_lba) 2812resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2228{ 2813{
2814 u8 *cmd = scp->cmnd;
2815 u64 lba;
2816 u32 num;
2817 u32 ei_lba;
2229 unsigned long iflags; 2818 unsigned long iflags;
2230 int ret; 2819 int ret;
2820 bool check_prot;
2231 2821
2232 ret = check_device_access_params(SCpnt, lba, num); 2822 switch (cmd[0]) {
2233 if (ret) 2823 case WRITE_16:
2234 return ret; 2824 ei_lba = 0;
2825 lba = get_unaligned_be64(cmd + 2);
2826 num = get_unaligned_be32(cmd + 10);
2827 check_prot = true;
2828 break;
2829 case WRITE_10:
2830 ei_lba = 0;
2831 lba = get_unaligned_be32(cmd + 2);
2832 num = get_unaligned_be16(cmd + 7);
2833 check_prot = true;
2834 break;
2835 case WRITE_6:
2836 ei_lba = 0;
2837 lba = (u32)cmd[3] | (u32)cmd[2] << 8 |
2838 (u32)(cmd[1] & 0x1f) << 16;
2839 num = (0 == cmd[4]) ? 256 : cmd[4];
2840 check_prot = true;
2841 break;
2842 case WRITE_12:
2843 ei_lba = 0;
2844 lba = get_unaligned_be32(cmd + 2);
2845 num = get_unaligned_be32(cmd + 6);
2846 check_prot = true;
2847 break;
2848 case 0x53: /* XDWRITEREAD(10) */
2849 ei_lba = 0;
2850 lba = get_unaligned_be32(cmd + 2);
2851 num = get_unaligned_be16(cmd + 7);
2852 check_prot = false;
2853 break;
2854 default: /* assume WRITE(32) */
2855 lba = get_unaligned_be64(cmd + 12);
2856 ei_lba = get_unaligned_be32(cmd + 20);
2857 num = get_unaligned_be32(cmd + 28);
2858 check_prot = false;
2859 break;
2860 }
2861 if (check_prot) {
2862 if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION &&
2863 (cmd[1] & 0xe0)) {
2864 mk_sense_invalid_opcode(scp);
2865 return check_condition_result;
2866 }
2867 if ((scsi_debug_dif == SD_DIF_TYPE1_PROTECTION ||
2868 scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) &&
2869 (cmd[1] & 0xe0) == 0)
2870 sdev_printk(KERN_ERR, scp->device, "Unprotected WR "
2871 "to DIF device\n");
2872 }
2873
2874 /* inline check_device_access_params() */
2875 if (lba + num > sdebug_capacity) {
2876 mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, 0);
2877 return check_condition_result;
2878 }
2879 /* transfer length excessive (tie in to block limits VPD page) */
2880 if (num > sdebug_store_sectors) {
2881 /* needs work to find which cdb byte 'num' comes from */
2882 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0);
2883 return check_condition_result;
2884 }
2235 2885
2236 write_lock_irqsave(&atomic_rw, iflags); 2886 write_lock_irqsave(&atomic_rw, iflags);
2237 2887
2238 /* DIX + T10 DIF */ 2888 /* DIX + T10 DIF */
2239 if (scsi_debug_dix && scsi_prot_sg_count(SCpnt)) { 2889 if (scsi_debug_dix && scsi_prot_sg_count(scp)) {
2240 int prot_ret = prot_verify_write(SCpnt, lba, num, ei_lba); 2890 int prot_ret = prot_verify_write(scp, lba, num, ei_lba);
2241 2891
2242 if (prot_ret) { 2892 if (prot_ret) {
2243 write_unlock_irqrestore(&atomic_rw, iflags); 2893 write_unlock_irqrestore(&atomic_rw, iflags);
2244 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST, 0x10, 2894 mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, prot_ret);
2245 prot_ret);
2246 return illegal_condition_result; 2895 return illegal_condition_result;
2247 } 2896 }
2248 } 2897 }
2249 2898
2250 ret = do_device_access(SCpnt, lba, num, 1); 2899 ret = do_device_access(scp, lba, num, true);
2251 if (scsi_debug_lbp()) 2900 if (scsi_debug_lbp())
2252 map_region(lba, num); 2901 map_region(lba, num);
2253 write_unlock_irqrestore(&atomic_rw, iflags); 2902 write_unlock_irqrestore(&atomic_rw, iflags);
@@ -2255,30 +2904,41 @@ static int resp_write(struct scsi_cmnd *SCpnt, unsigned long long lba,
2255 return (DID_ERROR << 16); 2904 return (DID_ERROR << 16);
2256 else if ((ret < (num * scsi_debug_sector_size)) && 2905 else if ((ret < (num * scsi_debug_sector_size)) &&
2257 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) 2906 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts))
2258 sdev_printk(KERN_INFO, SCpnt->device, 2907 sdev_printk(KERN_INFO, scp->device,
2259 "%s: write: cdb indicated=%u, IO sent=%d bytes\n", 2908 "%s: write: cdb indicated=%u, IO sent=%d bytes\n",
2260 my_name, num * scsi_debug_sector_size, ret); 2909 my_name, num * scsi_debug_sector_size, ret);
2261 2910
2911 if (sdebug_any_injecting_opt) {
2912 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp);
2913
2914 if (ep->inj_recovered) {
2915 mk_sense_buffer(scp, RECOVERED_ERROR,
2916 THRESHOLD_EXCEEDED, 0);
2917 return check_condition_result;
2918 } else if (ep->inj_dif) {
2919 /* Logical block guard check failed */
2920 mk_sense_buffer(scp, ABORTED_COMMAND, 0x10, 1);
2921 return illegal_condition_result;
2922 } else if (ep->inj_dix) {
2923 mk_sense_buffer(scp, ILLEGAL_REQUEST, 0x10, 1);
2924 return illegal_condition_result;
2925 }
2926 }
2262 return 0; 2927 return 0;
2263} 2928}
2264 2929
2265static int resp_write_same(struct scsi_cmnd *scmd, unsigned long long lba, 2930static int
2266 unsigned int num, u32 ei_lba, unsigned int unmap) 2931resp_write_same(struct scsi_cmnd *scp, u64 lba, u32 num, u32 ei_lba,
2932 bool unmap, bool ndob)
2267{ 2933{
2268 unsigned long iflags; 2934 unsigned long iflags;
2269 unsigned long long i; 2935 unsigned long long i;
2270 int ret; 2936 int ret;
2271 2937
2272 ret = check_device_access_params(scmd, lba, num); 2938 ret = check_device_access_params(scp, lba, num);
2273 if (ret) 2939 if (ret)
2274 return ret; 2940 return ret;
2275 2941
2276 if (num > scsi_debug_write_same_length) {
2277 mk_sense_buffer(scmd, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB,
2278 0);
2279 return check_condition_result;
2280 }
2281
2282 write_lock_irqsave(&atomic_rw, iflags); 2942 write_lock_irqsave(&atomic_rw, iflags);
2283 2943
2284 if (unmap && scsi_debug_lbp()) { 2944 if (unmap && scsi_debug_lbp()) {
@@ -2286,17 +2946,22 @@ static int resp_write_same(struct scsi_cmnd *scmd, unsigned long long lba,
2286 goto out; 2946 goto out;
2287 } 2947 }
2288 2948
2289 /* Else fetch one logical block */ 2949 /* if ndob then zero 1 logical block, else fetch 1 logical block */
2290 ret = fetch_to_dev_buffer(scmd, 2950 if (ndob) {
2291 fake_storep + (lba * scsi_debug_sector_size), 2951 memset(fake_storep + (lba * scsi_debug_sector_size), 0,
2292 scsi_debug_sector_size); 2952 scsi_debug_sector_size);
2953 ret = 0;
2954 } else
2955 ret = fetch_to_dev_buffer(scp, fake_storep +
2956 (lba * scsi_debug_sector_size),
2957 scsi_debug_sector_size);
2293 2958
2294 if (-1 == ret) { 2959 if (-1 == ret) {
2295 write_unlock_irqrestore(&atomic_rw, iflags); 2960 write_unlock_irqrestore(&atomic_rw, iflags);
2296 return (DID_ERROR << 16); 2961 return (DID_ERROR << 16);
2297 } else if ((ret < (num * scsi_debug_sector_size)) && 2962 } else if ((ret < (num * scsi_debug_sector_size)) &&
2298 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)) 2963 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts))
2299 sdev_printk(KERN_INFO, scmd->device, 2964 sdev_printk(KERN_INFO, scp->device,
2300 "%s: %s: cdb indicated=%u, IO sent=%d bytes\n", 2965 "%s: %s: cdb indicated=%u, IO sent=%d bytes\n",
2301 my_name, "write same", 2966 my_name, "write same",
2302 num * scsi_debug_sector_size, ret); 2967 num * scsi_debug_sector_size, ret);
@@ -2315,13 +2980,143 @@ out:
2315 return 0; 2980 return 0;
2316} 2981}
2317 2982
2983static int
2984resp_write_same_10(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2985{
2986 u8 *cmd = scp->cmnd;
2987 u32 lba;
2988 u16 num;
2989 u32 ei_lba = 0;
2990 bool unmap = false;
2991
2992 if (cmd[1] & 0x8) {
2993 if (scsi_debug_lbpws10 == 0) {
2994 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, 3);
2995 return check_condition_result;
2996 } else
2997 unmap = true;
2998 }
2999 lba = get_unaligned_be32(cmd + 2);
3000 num = get_unaligned_be16(cmd + 7);
3001 if (num > scsi_debug_write_same_length) {
3002 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1);
3003 return check_condition_result;
3004 }
3005 return resp_write_same(scp, lba, num, ei_lba, unmap, false);
3006}
3007
3008static int
3009resp_write_same_16(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3010{
3011 u8 *cmd = scp->cmnd;
3012 u64 lba;
3013 u32 num;
3014 u32 ei_lba = 0;
3015 bool unmap = false;
3016 bool ndob = false;
3017
3018 if (cmd[1] & 0x8) { /* UNMAP */
3019 if (scsi_debug_lbpws == 0) {
3020 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, 3);
3021 return check_condition_result;
3022 } else
3023 unmap = true;
3024 }
3025 if (cmd[1] & 0x1) /* NDOB (no data-out buffer, assumes zeroes) */
3026 ndob = true;
3027 lba = get_unaligned_be64(cmd + 2);
3028 num = get_unaligned_be32(cmd + 10);
3029 if (num > scsi_debug_write_same_length) {
3030 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 10, -1);
3031 return check_condition_result;
3032 }
3033 return resp_write_same(scp, lba, num, ei_lba, unmap, ndob);
3034}
3035
3036static int
3037resp_comp_write(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3038{
3039 u8 *cmd = scp->cmnd;
3040 u8 *arr;
3041 u8 *fake_storep_hold;
3042 u64 lba;
3043 u32 dnum;
3044 u32 lb_size = scsi_debug_sector_size;
3045 u8 num;
3046 unsigned long iflags;
3047 int ret;
3048
3049 lba = get_unaligned_be32(cmd + 2);
3050 num = cmd[13]; /* 1 to a maximum of 255 logical blocks */
3051 if (0 == num)
3052 return 0; /* degenerate case, not an error */
3053 dnum = 2 * num;
3054 arr = kzalloc(dnum * lb_size, GFP_ATOMIC);
3055 if (NULL == arr) {
3056 mk_sense_buffer(scp, ILLEGAL_REQUEST, INSUFF_RES_ASC,
3057 INSUFF_RES_ASCQ);
3058 return check_condition_result;
3059 }
3060 if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION &&
3061 (cmd[1] & 0xe0)) {
3062 mk_sense_invalid_opcode(scp);
3063 return check_condition_result;
3064 }
3065 if ((scsi_debug_dif == SD_DIF_TYPE1_PROTECTION ||
3066 scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) &&
3067 (cmd[1] & 0xe0) == 0)
3068 sdev_printk(KERN_ERR, scp->device, "Unprotected WR "
3069 "to DIF device\n");
3070
3071 /* inline check_device_access_params() */
3072 if (lba + num > sdebug_capacity) {
3073 mk_sense_buffer(scp, ILLEGAL_REQUEST, LBA_OUT_OF_RANGE, 0);
3074 return check_condition_result;
3075 }
3076 /* transfer length excessive (tie in to block limits VPD page) */
3077 if (num > sdebug_store_sectors) {
3078 /* needs work to find which cdb byte 'num' comes from */
3079 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 0);
3080 return check_condition_result;
3081 }
3082
3083 write_lock_irqsave(&atomic_rw, iflags);
3084
3085 /* trick do_device_access() to fetch both compare and write buffers
3086 * from data-in into arr. Safe (atomic) since write_lock held. */
3087 fake_storep_hold = fake_storep;
3088 fake_storep = arr;
3089 ret = do_device_access(scp, 0, dnum, true);
3090 fake_storep = fake_storep_hold;
3091 if (ret == -1) {
3092 write_unlock_irqrestore(&atomic_rw, iflags);
3093 kfree(arr);
3094 return DID_ERROR << 16;
3095 } else if ((ret < (dnum * lb_size)) &&
3096 (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts))
3097 sdev_printk(KERN_INFO, scp->device, "%s: compare_write: cdb "
3098 "indicated=%u, IO sent=%d bytes\n", my_name,
3099 dnum * lb_size, ret);
3100 if (!comp_write_worker(lba, num, arr)) {
3101 write_unlock_irqrestore(&atomic_rw, iflags);
3102 kfree(arr);
3103 mk_sense_buffer(scp, MISCOMPARE, MISCOMPARE_VERIFY_ASC, 0);
3104 return check_condition_result;
3105 }
3106 if (scsi_debug_lbp())
3107 map_region(lba, num);
3108 write_unlock_irqrestore(&atomic_rw, iflags);
3109 return 0;
3110}
3111
2318struct unmap_block_desc { 3112struct unmap_block_desc {
2319 __be64 lba; 3113 __be64 lba;
2320 __be32 blocks; 3114 __be32 blocks;
2321 __be32 __reserved; 3115 __be32 __reserved;
2322}; 3116};
2323 3117
2324static int resp_unmap(struct scsi_cmnd * scmd, struct sdebug_dev_info * devip) 3118static int
3119resp_unmap(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2325{ 3120{
2326 unsigned char *buf; 3121 unsigned char *buf;
2327 struct unmap_block_desc *desc; 3122 struct unmap_block_desc *desc;
@@ -2329,20 +3124,26 @@ static int resp_unmap(struct scsi_cmnd * scmd, struct sdebug_dev_info * devip)
2329 int ret; 3124 int ret;
2330 unsigned long iflags; 3125 unsigned long iflags;
2331 3126
2332 ret = check_readiness(scmd, UAS_ONLY, devip);
2333 if (ret)
2334 return ret;
2335 3127
2336 payload_len = get_unaligned_be16(&scmd->cmnd[7]); 3128 if (!scsi_debug_lbp())
2337 BUG_ON(scsi_bufflen(scmd) != payload_len); 3129 return 0; /* fib and say its done */
3130 payload_len = get_unaligned_be16(scp->cmnd + 7);
3131 BUG_ON(scsi_bufflen(scp) != payload_len);
2338 3132
2339 descriptors = (payload_len - 8) / 16; 3133 descriptors = (payload_len - 8) / 16;
3134 if (descriptors > scsi_debug_unmap_max_desc) {
3135 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 7, -1);
3136 return check_condition_result;
3137 }
2340 3138
2341 buf = kmalloc(scsi_bufflen(scmd), GFP_ATOMIC); 3139 buf = kmalloc(scsi_bufflen(scp), GFP_ATOMIC);
2342 if (!buf) 3140 if (!buf) {
3141 mk_sense_buffer(scp, ILLEGAL_REQUEST, INSUFF_RES_ASC,
3142 INSUFF_RES_ASCQ);
2343 return check_condition_result; 3143 return check_condition_result;
3144 }
2344 3145
2345 scsi_sg_copy_to_buffer(scmd, buf, scsi_bufflen(scmd)); 3146 scsi_sg_copy_to_buffer(scp, buf, scsi_bufflen(scp));
2346 3147
2347 BUG_ON(get_unaligned_be16(&buf[0]) != payload_len - 2); 3148 BUG_ON(get_unaligned_be16(&buf[0]) != payload_len - 2);
2348 BUG_ON(get_unaligned_be16(&buf[2]) != descriptors * 16); 3149 BUG_ON(get_unaligned_be16(&buf[2]) != descriptors * 16);
@@ -2355,7 +3156,7 @@ static int resp_unmap(struct scsi_cmnd * scmd, struct sdebug_dev_info * devip)
2355 unsigned long long lba = get_unaligned_be64(&desc[i].lba); 3156 unsigned long long lba = get_unaligned_be64(&desc[i].lba);
2356 unsigned int num = get_unaligned_be32(&desc[i].blocks); 3157 unsigned int num = get_unaligned_be32(&desc[i].blocks);
2357 3158
2358 ret = check_device_access_params(scmd, lba, num); 3159 ret = check_device_access_params(scp, lba, num);
2359 if (ret) 3160 if (ret)
2360 goto out; 3161 goto out;
2361 3162
@@ -2373,37 +3174,44 @@ out:
2373 3174
2374#define SDEBUG_GET_LBA_STATUS_LEN 32 3175#define SDEBUG_GET_LBA_STATUS_LEN 32
2375 3176
2376static int resp_get_lba_status(struct scsi_cmnd * scmd, 3177static int
2377 struct sdebug_dev_info * devip) 3178resp_get_lba_status(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2378{ 3179{
2379 unsigned long long lba; 3180 u8 *cmd = scp->cmnd;
2380 unsigned int alloc_len, mapped, num; 3181 u64 lba;
2381 unsigned char arr[SDEBUG_GET_LBA_STATUS_LEN]; 3182 u32 alloc_len, mapped, num;
3183 u8 arr[SDEBUG_GET_LBA_STATUS_LEN];
2382 int ret; 3184 int ret;
2383 3185
2384 ret = check_readiness(scmd, UAS_ONLY, devip); 3186 lba = get_unaligned_be64(cmd + 2);
2385 if (ret) 3187 alloc_len = get_unaligned_be32(cmd + 10);
2386 return ret;
2387
2388 lba = get_unaligned_be64(&scmd->cmnd[2]);
2389 alloc_len = get_unaligned_be32(&scmd->cmnd[10]);
2390 3188
2391 if (alloc_len < 24) 3189 if (alloc_len < 24)
2392 return 0; 3190 return 0;
2393 3191
2394 ret = check_device_access_params(scmd, lba, 1); 3192 ret = check_device_access_params(scp, lba, 1);
2395 if (ret) 3193 if (ret)
2396 return ret; 3194 return ret;
2397 3195
2398 mapped = map_state(lba, &num); 3196 if (scsi_debug_lbp())
3197 mapped = map_state(lba, &num);
3198 else {
3199 mapped = 1;
3200 /* following just in case virtual_gb changed */
3201 sdebug_capacity = get_sdebug_capacity();
3202 if (sdebug_capacity - lba <= 0xffffffff)
3203 num = sdebug_capacity - lba;
3204 else
3205 num = 0xffffffff;
3206 }
2399 3207
2400 memset(arr, 0, SDEBUG_GET_LBA_STATUS_LEN); 3208 memset(arr, 0, SDEBUG_GET_LBA_STATUS_LEN);
2401 put_unaligned_be32(20, &arr[0]); /* Parameter Data Length */ 3209 put_unaligned_be32(20, arr); /* Parameter Data Length */
2402 put_unaligned_be64(lba, &arr[8]); /* LBA */ 3210 put_unaligned_be64(lba, arr + 8); /* LBA */
2403 put_unaligned_be32(num, &arr[16]); /* Number of blocks */ 3211 put_unaligned_be32(num, arr + 16); /* Number of blocks */
2404 arr[20] = !mapped; /* mapped = 0, unmapped = 1 */ 3212 arr[20] = !mapped; /* prov_stat=0: mapped; 1: dealloc */
2405 3213
2406 return fill_from_dev_buffer(scmd, arr, SDEBUG_GET_LBA_STATUS_LEN); 3214 return fill_from_dev_buffer(scp, arr, SDEBUG_GET_LBA_STATUS_LEN);
2407} 3215}
2408 3216
2409#define SDEBUG_RLUN_ARR_SZ 256 3217#define SDEBUG_RLUN_ARR_SZ 256
@@ -2412,8 +3220,8 @@ static int resp_report_luns(struct scsi_cmnd * scp,
2412 struct sdebug_dev_info * devip) 3220 struct sdebug_dev_info * devip)
2413{ 3221{
2414 unsigned int alloc_len; 3222 unsigned int alloc_len;
2415 int lun_cnt, i, upper, num, n; 3223 int lun_cnt, i, upper, num, n, want_wlun, shortish;
2416 u64 wlun, lun; 3224 u64 lun;
2417 unsigned char *cmd = scp->cmnd; 3225 unsigned char *cmd = scp->cmnd;
2418 int select_report = (int)cmd[2]; 3226 int select_report = (int)cmd[2];
2419 struct scsi_lun *one_lun; 3227 struct scsi_lun *one_lun;
@@ -2421,9 +3229,9 @@ static int resp_report_luns(struct scsi_cmnd * scp,
2421 unsigned char * max_addr; 3229 unsigned char * max_addr;
2422 3230
2423 alloc_len = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24); 3231 alloc_len = cmd[9] + (cmd[8] << 8) + (cmd[7] << 16) + (cmd[6] << 24);
2424 if ((alloc_len < 4) || (select_report > 2)) { 3232 shortish = (alloc_len < 4);
2425 mk_sense_buffer(scp, ILLEGAL_REQUEST, INVALID_FIELD_IN_CDB, 3233 if (shortish || (select_report > 2)) {
2426 0); 3234 mk_sense_invalid_fld(scp, SDEB_IN_CDB, shortish ? 6 : 2, -1);
2427 return check_condition_result; 3235 return check_condition_result;
2428 } 3236 }
2429 /* can produce response with up to 16k luns (lun 0 to lun 16383) */ 3237 /* can produce response with up to 16k luns (lun 0 to lun 16383) */
@@ -2433,14 +3241,14 @@ static int resp_report_luns(struct scsi_cmnd * scp,
2433 lun_cnt = 0; 3241 lun_cnt = 0;
2434 else if (scsi_debug_no_lun_0 && (lun_cnt > 0)) 3242 else if (scsi_debug_no_lun_0 && (lun_cnt > 0))
2435 --lun_cnt; 3243 --lun_cnt;
2436 wlun = (select_report > 0) ? 1 : 0; 3244 want_wlun = (select_report > 0) ? 1 : 0;
2437 num = lun_cnt + wlun; 3245 num = lun_cnt + want_wlun;
2438 arr[2] = ((sizeof(struct scsi_lun) * num) >> 8) & 0xff; 3246 arr[2] = ((sizeof(struct scsi_lun) * num) >> 8) & 0xff;
2439 arr[3] = (sizeof(struct scsi_lun) * num) & 0xff; 3247 arr[3] = (sizeof(struct scsi_lun) * num) & 0xff;
2440 n = min((int)((SDEBUG_RLUN_ARR_SZ - 8) / 3248 n = min((int)((SDEBUG_RLUN_ARR_SZ - 8) /
2441 sizeof(struct scsi_lun)), num); 3249 sizeof(struct scsi_lun)), num);
2442 if (n < num) { 3250 if (n < num) {
2443 wlun = 0; 3251 want_wlun = 0;
2444 lun_cnt = n; 3252 lun_cnt = n;
2445 } 3253 }
2446 one_lun = (struct scsi_lun *) &arr[8]; 3254 one_lun = (struct scsi_lun *) &arr[8];
@@ -2454,7 +3262,7 @@ static int resp_report_luns(struct scsi_cmnd * scp,
2454 (upper | (SAM2_LUN_ADDRESS_METHOD << 6)); 3262 (upper | (SAM2_LUN_ADDRESS_METHOD << 6));
2455 one_lun[i].scsi_lun[1] = lun & 0xff; 3263 one_lun[i].scsi_lun[1] = lun & 0xff;
2456 } 3264 }
2457 if (wlun) { 3265 if (want_wlun) {
2458 one_lun[i].scsi_lun[0] = (SAM2_WLUN_REPORT_LUNS >> 8) & 0xff; 3266 one_lun[i].scsi_lun[0] = (SAM2_WLUN_REPORT_LUNS >> 8) & 0xff;
2459 one_lun[i].scsi_lun[1] = SAM2_WLUN_REPORT_LUNS & 0xff; 3267 one_lun[i].scsi_lun[1] = SAM2_WLUN_REPORT_LUNS & 0xff;
2460 i++; 3268 i++;
@@ -2476,8 +3284,8 @@ static int resp_xdwriteread(struct scsi_cmnd *scp, unsigned long long lba,
2476 /* better not to use temporary buffer. */ 3284 /* better not to use temporary buffer. */
2477 buf = kmalloc(scsi_bufflen(scp), GFP_ATOMIC); 3285 buf = kmalloc(scsi_bufflen(scp), GFP_ATOMIC);
2478 if (!buf) { 3286 if (!buf) {
2479 mk_sense_buffer(scp, NOT_READY, 3287 mk_sense_buffer(scp, ILLEGAL_REQUEST, INSUFF_RES_ASC,
2480 LOGICAL_UNIT_COMMUNICATION_FAILURE, 0); 3288 INSUFF_RES_ASCQ);
2481 return check_condition_result; 3289 return check_condition_result;
2482 } 3290 }
2483 3291
@@ -2500,6 +3308,32 @@ static int resp_xdwriteread(struct scsi_cmnd *scp, unsigned long long lba,
2500 return 0; 3308 return 0;
2501} 3309}
2502 3310
3311static int
3312resp_xdwriteread_10(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
3313{
3314 u8 *cmd = scp->cmnd;
3315 u64 lba;
3316 u32 num;
3317 int errsts;
3318
3319 if (!scsi_bidi_cmnd(scp)) {
3320 mk_sense_buffer(scp, ILLEGAL_REQUEST, INSUFF_RES_ASC,
3321 INSUFF_RES_ASCQ);
3322 return check_condition_result;
3323 }
3324 errsts = resp_read_dt0(scp, devip);
3325 if (errsts)
3326 return errsts;
3327 if (!(cmd[1] & 0x4)) { /* DISABLE_WRITE is not set */
3328 errsts = resp_write_dt0(scp, devip);
3329 if (errsts)
3330 return errsts;
3331 }
3332 lba = get_unaligned_be32(cmd + 2);
3333 num = get_unaligned_be16(cmd + 7);
3334 return resp_xdwriteread(scp, lba, num, devip);
3335}
3336
2503/* When timer or tasklet goes off this function is called. */ 3337/* When timer or tasklet goes off this function is called. */
2504static void sdebug_q_cmd_complete(unsigned long indx) 3338static void sdebug_q_cmd_complete(unsigned long indx)
2505{ 3339{
@@ -2672,10 +3506,7 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
2672 open_devip->sdbg_host = sdbg_host; 3506 open_devip->sdbg_host = sdbg_host;
2673 atomic_set(&open_devip->num_in_q, 0); 3507 atomic_set(&open_devip->num_in_q, 0);
2674 set_bit(SDEBUG_UA_POR, open_devip->uas_bm); 3508 set_bit(SDEBUG_UA_POR, open_devip->uas_bm);
2675 open_devip->used = 1; 3509 open_devip->used = true;
2676 if (sdev->lun == SAM2_WLUN_REPORT_LUNS)
2677 open_devip->wlun = SAM2_WLUN_REPORT_LUNS & 0xff;
2678
2679 return open_devip; 3510 return open_devip;
2680} 3511}
2681 3512
@@ -2701,10 +3532,6 @@ static int scsi_debug_slave_configure(struct scsi_device *sdp)
2701 if (NULL == devip) 3532 if (NULL == devip)
2702 return 1; /* no resources, will be marked offline */ 3533 return 1; /* no resources, will be marked offline */
2703 sdp->hostdata = devip; 3534 sdp->hostdata = devip;
2704 sdp->tagged_supported = 1;
2705 if (sdp->host->cmd_per_lun)
2706 scsi_adjust_queue_depth(sdp, DEF_TAGGED_QUEUING,
2707 DEF_CMD_PER_LUN);
2708 blk_queue_max_segment_size(sdp->request_queue, -1U); 3535 blk_queue_max_segment_size(sdp->request_queue, -1U);
2709 if (scsi_debug_no_uld) 3536 if (scsi_debug_no_uld)
2710 sdp->no_uld_attach = 1; 3537 sdp->no_uld_attach = 1;
@@ -2721,7 +3548,7 @@ static void scsi_debug_slave_destroy(struct scsi_device *sdp)
2721 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun); 3548 sdp->host->host_no, sdp->channel, sdp->id, sdp->lun);
2722 if (devip) { 3549 if (devip) {
2723 /* make this slot available for re-use */ 3550 /* make this slot available for re-use */
2724 devip->used = 0; 3551 devip->used = false;
2725 sdp->hostdata = NULL; 3552 sdp->hostdata = NULL;
2726 } 3553 }
2727} 3554}
@@ -3166,6 +3993,7 @@ module_param_named(ptype, scsi_debug_ptype, int, S_IRUGO | S_IWUSR);
3166module_param_named(removable, scsi_debug_removable, bool, S_IRUGO | S_IWUSR); 3993module_param_named(removable, scsi_debug_removable, bool, S_IRUGO | S_IWUSR);
3167module_param_named(scsi_level, scsi_debug_scsi_level, int, S_IRUGO); 3994module_param_named(scsi_level, scsi_debug_scsi_level, int, S_IRUGO);
3168module_param_named(sector_size, scsi_debug_sector_size, int, S_IRUGO); 3995module_param_named(sector_size, scsi_debug_sector_size, int, S_IRUGO);
3996module_param_named(strict, scsi_debug_strict, bool, S_IRUGO | S_IWUSR);
3169module_param_named(unmap_alignment, scsi_debug_unmap_alignment, int, S_IRUGO); 3997module_param_named(unmap_alignment, scsi_debug_unmap_alignment, int, S_IRUGO);
3170module_param_named(unmap_granularity, scsi_debug_unmap_granularity, int, S_IRUGO); 3998module_param_named(unmap_granularity, scsi_debug_unmap_granularity, int, S_IRUGO);
3171module_param_named(unmap_max_blocks, scsi_debug_unmap_max_blocks, int, S_IRUGO); 3999module_param_named(unmap_max_blocks, scsi_debug_unmap_max_blocks, int, S_IRUGO);
@@ -3185,7 +4013,7 @@ MODULE_PARM_DESC(add_host, "0..127 hosts allowed(def=1)");
3185MODULE_PARM_DESC(ato, "application tag ownership: 0=disk 1=host (def=1)"); 4013MODULE_PARM_DESC(ato, "application tag ownership: 0=disk 1=host (def=1)");
3186MODULE_PARM_DESC(clustering, "when set enables larger transfers (def=0)"); 4014MODULE_PARM_DESC(clustering, "when set enables larger transfers (def=0)");
3187MODULE_PARM_DESC(delay, "response delay (def=1 jiffy); 0:imm, -1,-2:tiny"); 4015MODULE_PARM_DESC(delay, "response delay (def=1 jiffy); 0:imm, -1,-2:tiny");
3188MODULE_PARM_DESC(dev_size_mb, "size in MB of ram shared by devs(def=8)"); 4016MODULE_PARM_DESC(dev_size_mb, "size in MiB of ram shared by devs(def=8)");
3189MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)"); 4017MODULE_PARM_DESC(dif, "data integrity field type: 0-3 (def=0)");
3190MODULE_PARM_DESC(dix, "data integrity extensions mask (def=0)"); 4018MODULE_PARM_DESC(dix, "data integrity extensions mask (def=0)");
3191MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)"); 4019MODULE_PARM_DESC(dsense, "use descriptor sense format(def=0 -> fixed)");
@@ -3212,11 +4040,12 @@ MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");
3212MODULE_PARM_DESC(removable, "claim to have removable media (def=0)"); 4040MODULE_PARM_DESC(removable, "claim to have removable media (def=0)");
3213MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=6[SPC-4])"); 4041MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=6[SPC-4])");
3214MODULE_PARM_DESC(sector_size, "logical block size in bytes (def=512)"); 4042MODULE_PARM_DESC(sector_size, "logical block size in bytes (def=512)");
4043MODULE_PARM_DESC(strict, "stricter checks: reserved field in cdb (def=0)");
3215MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)"); 4044MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)");
3216MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)"); 4045MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)");
3217MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)"); 4046MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)");
3218MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)"); 4047MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)");
3219MODULE_PARM_DESC(virtual_gb, "virtual gigabyte size (def=0 -> use dev_size_mb)"); 4048MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)");
3220MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)"); 4049MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)");
3221MODULE_PARM_DESC(write_same_length, "Maximum blocks per WRITE SAME cmd (def=0xffff)"); 4050MODULE_PARM_DESC(write_same_length, "Maximum blocks per WRITE SAME cmd (def=0xffff)");
3222 4051
@@ -3382,6 +4211,16 @@ static ssize_t opts_store(struct device_driver *ddp, const char *buf,
3382 return -EINVAL; 4211 return -EINVAL;
3383opts_done: 4212opts_done:
3384 scsi_debug_opts = opts; 4213 scsi_debug_opts = opts;
4214 if (SCSI_DEBUG_OPT_RECOVERED_ERR & opts)
4215 sdebug_any_injecting_opt = true;
4216 else if (SCSI_DEBUG_OPT_TRANSPORT_ERR & opts)
4217 sdebug_any_injecting_opt = true;
4218 else if (SCSI_DEBUG_OPT_DIF_ERR & opts)
4219 sdebug_any_injecting_opt = true;
4220 else if (SCSI_DEBUG_OPT_DIX_ERR & opts)
4221 sdebug_any_injecting_opt = true;
4222 else if (SCSI_DEBUG_OPT_SHORT_TRANSFER & opts)
4223 sdebug_any_injecting_opt = true;
3385 atomic_set(&sdebug_cmnd_count, 0); 4224 atomic_set(&sdebug_cmnd_count, 0);
3386 atomic_set(&sdebug_a_tsf, 0); 4225 atomic_set(&sdebug_a_tsf, 0);
3387 return count; 4226 return count;
@@ -3589,12 +4428,25 @@ static ssize_t virtual_gb_store(struct device_driver *ddp, const char *buf,
3589 size_t count) 4428 size_t count)
3590{ 4429{
3591 int n; 4430 int n;
4431 bool changed;
3592 4432
3593 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) { 4433 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4434 changed = (scsi_debug_virtual_gb != n);
3594 scsi_debug_virtual_gb = n; 4435 scsi_debug_virtual_gb = n;
3595
3596 sdebug_capacity = get_sdebug_capacity(); 4436 sdebug_capacity = get_sdebug_capacity();
3597 4437 if (changed) {
4438 struct sdebug_host_info *sdhp;
4439 struct sdebug_dev_info *dp;
4440
4441 list_for_each_entry(sdhp, &sdebug_host_list,
4442 host_list) {
4443 list_for_each_entry(dp, &sdhp->dev_info_list,
4444 dev_list) {
4445 set_bit(SDEBUG_UA_CAPACITY_CHANGED,
4446 dp->uas_bm);
4447 }
4448 }
4449 }
3598 return count; 4450 return count;
3599 } 4451 }
3600 return -EINVAL; 4452 return -EINVAL;
@@ -3740,6 +4592,23 @@ static ssize_t host_lock_store(struct device_driver *ddp, const char *buf,
3740} 4592}
3741static DRIVER_ATTR_RW(host_lock); 4593static DRIVER_ATTR_RW(host_lock);
3742 4594
4595static ssize_t strict_show(struct device_driver *ddp, char *buf)
4596{
4597 return scnprintf(buf, PAGE_SIZE, "%d\n", !!scsi_debug_strict);
4598}
4599static ssize_t strict_store(struct device_driver *ddp, const char *buf,
4600 size_t count)
4601{
4602 int n;
4603
4604 if ((count > 0) && (1 == sscanf(buf, "%d", &n)) && (n >= 0)) {
4605 scsi_debug_strict = (n > 0);
4606 return count;
4607 }
4608 return -EINVAL;
4609}
4610static DRIVER_ATTR_RW(strict);
4611
3743 4612
3744/* Note: The following array creates attribute files in the 4613/* Note: The following array creates attribute files in the
3745 /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these 4614 /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these
@@ -3775,6 +4644,7 @@ static struct attribute *sdebug_drv_attrs[] = {
3775 &driver_attr_removable.attr, 4644 &driver_attr_removable.attr,
3776 &driver_attr_host_lock.attr, 4645 &driver_attr_host_lock.attr,
3777 &driver_attr_ndelay.attr, 4646 &driver_attr_ndelay.attr,
4647 &driver_attr_strict.attr,
3778 NULL, 4648 NULL,
3779}; 4649};
3780ATTRIBUTE_GROUPS(sdebug_drv); 4650ATTRIBUTE_GROUPS(sdebug_drv);
@@ -4087,396 +4957,9 @@ static void sdebug_remove_adapter(void)
4087} 4957}
4088 4958
4089static int 4959static int
4090scsi_debug_queuecommand(struct scsi_cmnd *SCpnt) 4960sdebug_change_qdepth(struct scsi_device *sdev, int qdepth)
4091{
4092 unsigned char *cmd = SCpnt->cmnd;
4093 int len, k;
4094 unsigned int num;
4095 unsigned long long lba;
4096 u32 ei_lba;
4097 int errsts = 0;
4098 int target = SCpnt->device->id;
4099 struct sdebug_dev_info *devip = NULL;
4100 int inj_recovered = 0;
4101 int inj_transport = 0;
4102 int inj_dif = 0;
4103 int inj_dix = 0;
4104 int inj_short = 0;
4105 int delay_override = 0;
4106 int unmap = 0;
4107
4108 scsi_set_resid(SCpnt, 0);
4109 if ((SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) &&
4110 !(SCSI_DEBUG_OPT_NO_CDB_NOISE & scsi_debug_opts)) {
4111 char b[120];
4112 int n;
4113
4114 len = SCpnt->cmd_len;
4115 if (len > 32)
4116 strcpy(b, "too long, over 32 bytes");
4117 else {
4118 for (k = 0, n = 0; k < len; ++k)
4119 n += scnprintf(b + n, sizeof(b) - n, "%02x ",
4120 (unsigned int)cmd[k]);
4121 }
4122 sdev_printk(KERN_INFO, SCpnt->device, "%s: cmd %s\n", my_name,
4123 b);
4124 }
4125
4126 if ((SCpnt->device->lun >= scsi_debug_max_luns) &&
4127 (SCpnt->device->lun != SAM2_WLUN_REPORT_LUNS))
4128 return schedule_resp(SCpnt, NULL, DID_NO_CONNECT << 16, 0);
4129 devip = devInfoReg(SCpnt->device);
4130 if (NULL == devip)
4131 return schedule_resp(SCpnt, NULL, DID_NO_CONNECT << 16, 0);
4132
4133 if ((scsi_debug_every_nth != 0) &&
4134 (atomic_inc_return(&sdebug_cmnd_count) >=
4135 abs(scsi_debug_every_nth))) {
4136 atomic_set(&sdebug_cmnd_count, 0);
4137 if (scsi_debug_every_nth < -1)
4138 scsi_debug_every_nth = -1;
4139 if (SCSI_DEBUG_OPT_TIMEOUT & scsi_debug_opts)
4140 return 0; /* ignore command causing timeout */
4141 else if (SCSI_DEBUG_OPT_MAC_TIMEOUT & scsi_debug_opts &&
4142 scsi_medium_access_command(SCpnt))
4143 return 0; /* time out reads and writes */
4144 else if (SCSI_DEBUG_OPT_RECOVERED_ERR & scsi_debug_opts)
4145 inj_recovered = 1; /* to reads and writes below */
4146 else if (SCSI_DEBUG_OPT_TRANSPORT_ERR & scsi_debug_opts)
4147 inj_transport = 1; /* to reads and writes below */
4148 else if (SCSI_DEBUG_OPT_DIF_ERR & scsi_debug_opts)
4149 inj_dif = 1; /* to reads and writes below */
4150 else if (SCSI_DEBUG_OPT_DIX_ERR & scsi_debug_opts)
4151 inj_dix = 1; /* to reads and writes below */
4152 else if (SCSI_DEBUG_OPT_SHORT_TRANSFER & scsi_debug_opts)
4153 inj_short = 1;
4154 }
4155
4156 if (devip->wlun) {
4157 switch (*cmd) {
4158 case INQUIRY:
4159 case REQUEST_SENSE:
4160 case TEST_UNIT_READY:
4161 case REPORT_LUNS:
4162 break; /* only allowable wlun commands */
4163 default:
4164 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
4165 printk(KERN_INFO "scsi_debug: Opcode: 0x%x "
4166 "not supported for wlun\n", *cmd);
4167 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4168 INVALID_OPCODE, 0);
4169 errsts = check_condition_result;
4170 return schedule_resp(SCpnt, devip, errsts, 0);
4171 }
4172 }
4173
4174 switch (*cmd) {
4175 case INQUIRY: /* mandatory, ignore unit attention */
4176 delay_override = 1;
4177 errsts = resp_inquiry(SCpnt, target, devip);
4178 break;
4179 case REQUEST_SENSE: /* mandatory, ignore unit attention */
4180 delay_override = 1;
4181 errsts = resp_requests(SCpnt, devip);
4182 break;
4183 case REZERO_UNIT: /* actually this is REWIND for SSC */
4184 case START_STOP:
4185 errsts = resp_start_stop(SCpnt, devip);
4186 break;
4187 case ALLOW_MEDIUM_REMOVAL:
4188 errsts = check_readiness(SCpnt, UAS_ONLY, devip);
4189 if (errsts)
4190 break;
4191 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
4192 printk(KERN_INFO "scsi_debug: Medium removal %s\n",
4193 cmd[4] ? "inhibited" : "enabled");
4194 break;
4195 case SEND_DIAGNOSTIC: /* mandatory */
4196 errsts = check_readiness(SCpnt, UAS_ONLY, devip);
4197 break;
4198 case TEST_UNIT_READY: /* mandatory */
4199 /* delay_override = 1; */
4200 errsts = check_readiness(SCpnt, UAS_TUR, devip);
4201 break;
4202 case RESERVE:
4203 errsts = check_readiness(SCpnt, UAS_ONLY, devip);
4204 break;
4205 case RESERVE_10:
4206 errsts = check_readiness(SCpnt, UAS_ONLY, devip);
4207 break;
4208 case RELEASE:
4209 errsts = check_readiness(SCpnt, UAS_ONLY, devip);
4210 break;
4211 case RELEASE_10:
4212 errsts = check_readiness(SCpnt, UAS_ONLY, devip);
4213 break;
4214 case READ_CAPACITY:
4215 errsts = resp_readcap(SCpnt, devip);
4216 break;
4217 case SERVICE_ACTION_IN:
4218 if (cmd[1] == SAI_READ_CAPACITY_16)
4219 errsts = resp_readcap16(SCpnt, devip);
4220 else if (cmd[1] == SAI_GET_LBA_STATUS) {
4221
4222 if (scsi_debug_lbp() == 0) {
4223 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4224 INVALID_COMMAND_OPCODE, 0);
4225 errsts = check_condition_result;
4226 } else
4227 errsts = resp_get_lba_status(SCpnt, devip);
4228 } else {
4229 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4230 INVALID_OPCODE, 0);
4231 errsts = check_condition_result;
4232 }
4233 break;
4234 case MAINTENANCE_IN:
4235 if (MI_REPORT_TARGET_PGS != cmd[1]) {
4236 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4237 INVALID_OPCODE, 0);
4238 errsts = check_condition_result;
4239 break;
4240 }
4241 errsts = resp_report_tgtpgs(SCpnt, devip);
4242 break;
4243 case READ_16:
4244 case READ_12:
4245 case READ_10:
4246 /* READ{10,12,16} and DIF Type 2 are natural enemies */
4247 if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION &&
4248 cmd[1] & 0xe0) {
4249 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4250 INVALID_COMMAND_OPCODE, 0);
4251 errsts = check_condition_result;
4252 break;
4253 }
4254
4255 if ((scsi_debug_dif == SD_DIF_TYPE1_PROTECTION ||
4256 scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) &&
4257 (cmd[1] & 0xe0) == 0)
4258 printk(KERN_ERR "Unprotected RD/WR to DIF device\n");
4259
4260 /* fall through */
4261 case READ_6:
4262read:
4263 errsts = check_readiness(SCpnt, UAS_TUR, devip);
4264 if (errsts)
4265 break;
4266 if (scsi_debug_fake_rw)
4267 break;
4268 get_data_transfer_info(cmd, &lba, &num, &ei_lba);
4269
4270 if (inj_short)
4271 num /= 2;
4272
4273 errsts = resp_read(SCpnt, lba, num, ei_lba);
4274 if (inj_recovered && (0 == errsts)) {
4275 mk_sense_buffer(SCpnt, RECOVERED_ERROR,
4276 THRESHOLD_EXCEEDED, 0);
4277 errsts = check_condition_result;
4278 } else if (inj_transport && (0 == errsts)) {
4279 mk_sense_buffer(SCpnt, ABORTED_COMMAND,
4280 TRANSPORT_PROBLEM, ACK_NAK_TO);
4281 errsts = check_condition_result;
4282 } else if (inj_dif && (0 == errsts)) {
4283 /* Logical block guard check failed */
4284 mk_sense_buffer(SCpnt, ABORTED_COMMAND, 0x10, 1);
4285 errsts = illegal_condition_result;
4286 } else if (inj_dix && (0 == errsts)) {
4287 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST, 0x10, 1);
4288 errsts = illegal_condition_result;
4289 }
4290 break;
4291 case REPORT_LUNS: /* mandatory, ignore unit attention */
4292 delay_override = 1;
4293 errsts = resp_report_luns(SCpnt, devip);
4294 break;
4295 case VERIFY: /* 10 byte SBC-2 command */
4296 errsts = check_readiness(SCpnt, UAS_TUR, devip);
4297 break;
4298 case WRITE_16:
4299 case WRITE_12:
4300 case WRITE_10:
4301 /* WRITE{10,12,16} and DIF Type 2 are natural enemies */
4302 if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION &&
4303 cmd[1] & 0xe0) {
4304 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4305 INVALID_COMMAND_OPCODE, 0);
4306 errsts = check_condition_result;
4307 break;
4308 }
4309
4310 if ((scsi_debug_dif == SD_DIF_TYPE1_PROTECTION ||
4311 scsi_debug_dif == SD_DIF_TYPE3_PROTECTION) &&
4312 (cmd[1] & 0xe0) == 0)
4313 printk(KERN_ERR "Unprotected RD/WR to DIF device\n");
4314
4315 /* fall through */
4316 case WRITE_6:
4317write:
4318 errsts = check_readiness(SCpnt, UAS_TUR, devip);
4319 if (errsts)
4320 break;
4321 if (scsi_debug_fake_rw)
4322 break;
4323 get_data_transfer_info(cmd, &lba, &num, &ei_lba);
4324 errsts = resp_write(SCpnt, lba, num, ei_lba);
4325 if (inj_recovered && (0 == errsts)) {
4326 mk_sense_buffer(SCpnt, RECOVERED_ERROR,
4327 THRESHOLD_EXCEEDED, 0);
4328 errsts = check_condition_result;
4329 } else if (inj_dif && (0 == errsts)) {
4330 mk_sense_buffer(SCpnt, ABORTED_COMMAND, 0x10, 1);
4331 errsts = illegal_condition_result;
4332 } else if (inj_dix && (0 == errsts)) {
4333 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST, 0x10, 1);
4334 errsts = illegal_condition_result;
4335 }
4336 break;
4337 case WRITE_SAME_16:
4338 case WRITE_SAME:
4339 if (cmd[1] & 0x8) {
4340 if ((*cmd == WRITE_SAME_16 && scsi_debug_lbpws == 0) ||
4341 (*cmd == WRITE_SAME && scsi_debug_lbpws10 == 0)) {
4342 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4343 INVALID_FIELD_IN_CDB, 0);
4344 errsts = check_condition_result;
4345 } else
4346 unmap = 1;
4347 }
4348 if (errsts)
4349 break;
4350 errsts = check_readiness(SCpnt, UAS_TUR, devip);
4351 if (errsts)
4352 break;
4353 if (scsi_debug_fake_rw)
4354 break;
4355 get_data_transfer_info(cmd, &lba, &num, &ei_lba);
4356 errsts = resp_write_same(SCpnt, lba, num, ei_lba, unmap);
4357 break;
4358 case UNMAP:
4359 errsts = check_readiness(SCpnt, UAS_TUR, devip);
4360 if (errsts)
4361 break;
4362 if (scsi_debug_fake_rw)
4363 break;
4364
4365 if (scsi_debug_unmap_max_desc == 0 || scsi_debug_lbpu == 0) {
4366 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4367 INVALID_COMMAND_OPCODE, 0);
4368 errsts = check_condition_result;
4369 } else
4370 errsts = resp_unmap(SCpnt, devip);
4371 break;
4372 case MODE_SENSE:
4373 case MODE_SENSE_10:
4374 errsts = resp_mode_sense(SCpnt, target, devip);
4375 break;
4376 case MODE_SELECT:
4377 errsts = resp_mode_select(SCpnt, 1, devip);
4378 break;
4379 case MODE_SELECT_10:
4380 errsts = resp_mode_select(SCpnt, 0, devip);
4381 break;
4382 case LOG_SENSE:
4383 errsts = resp_log_sense(SCpnt, devip);
4384 break;
4385 case SYNCHRONIZE_CACHE:
4386 delay_override = 1;
4387 errsts = check_readiness(SCpnt, UAS_TUR, devip);
4388 break;
4389 case WRITE_BUFFER:
4390 errsts = check_readiness(SCpnt, UAS_ONLY, devip);
4391 break;
4392 case XDWRITEREAD_10:
4393 if (!scsi_bidi_cmnd(SCpnt)) {
4394 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4395 INVALID_FIELD_IN_CDB, 0);
4396 errsts = check_condition_result;
4397 break;
4398 }
4399
4400 errsts = check_readiness(SCpnt, UAS_TUR, devip);
4401 if (errsts)
4402 break;
4403 if (scsi_debug_fake_rw)
4404 break;
4405 get_data_transfer_info(cmd, &lba, &num, &ei_lba);
4406 errsts = resp_read(SCpnt, lba, num, ei_lba);
4407 if (errsts)
4408 break;
4409 errsts = resp_write(SCpnt, lba, num, ei_lba);
4410 if (errsts)
4411 break;
4412 errsts = resp_xdwriteread(SCpnt, lba, num, devip);
4413 break;
4414 case VARIABLE_LENGTH_CMD:
4415 if (scsi_debug_dif == SD_DIF_TYPE2_PROTECTION) {
4416
4417 if ((cmd[10] & 0xe0) == 0)
4418 printk(KERN_ERR
4419 "Unprotected RD/WR to DIF device\n");
4420
4421 if (cmd[9] == READ_32) {
4422 BUG_ON(SCpnt->cmd_len < 32);
4423 goto read;
4424 }
4425
4426 if (cmd[9] == WRITE_32) {
4427 BUG_ON(SCpnt->cmd_len < 32);
4428 goto write;
4429 }
4430 }
4431
4432 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4433 INVALID_FIELD_IN_CDB, 0);
4434 errsts = check_condition_result;
4435 break;
4436 case 0x85:
4437 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
4438 sdev_printk(KERN_INFO, SCpnt->device,
4439 "%s: ATA PASS-THROUGH(16) not supported\n", my_name);
4440 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST,
4441 INVALID_OPCODE, 0);
4442 errsts = check_condition_result;
4443 break;
4444 default:
4445 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
4446 sdev_printk(KERN_INFO, SCpnt->device,
4447 "%s: Opcode: 0x%x not supported\n",
4448 my_name, *cmd);
4449 errsts = check_readiness(SCpnt, UAS_ONLY, devip);
4450 if (errsts)
4451 break; /* Unit attention takes precedence */
4452 mk_sense_buffer(SCpnt, ILLEGAL_REQUEST, INVALID_OPCODE, 0);
4453 errsts = check_condition_result;
4454 break;
4455 }
4456 return schedule_resp(SCpnt, devip, errsts,
4457 (delay_override ? 0 : scsi_debug_delay));
4458}
4459
4460static int
4461sdebug_queuecommand_lock_or_not(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
4462{
4463 if (scsi_debug_host_lock) {
4464 unsigned long iflags;
4465 int rc;
4466
4467 spin_lock_irqsave(shost->host_lock, iflags);
4468 rc = scsi_debug_queuecommand(cmd);
4469 spin_unlock_irqrestore(shost->host_lock, iflags);
4470 return rc;
4471 } else
4472 return scsi_debug_queuecommand(cmd);
4473}
4474
4475static int
4476sdebug_change_qdepth(struct scsi_device *sdev, int qdepth, int reason)
4477{ 4961{
4478 int num_in_q = 0; 4962 int num_in_q = 0;
4479 int bad = 0;
4480 unsigned long iflags; 4963 unsigned long iflags;
4481 struct sdebug_dev_info *devip; 4964 struct sdebug_dev_info *devip;
4482 4965
@@ -4488,43 +4971,18 @@ sdebug_change_qdepth(struct scsi_device *sdev, int qdepth, int reason)
4488 } 4971 }
4489 num_in_q = atomic_read(&devip->num_in_q); 4972 num_in_q = atomic_read(&devip->num_in_q);
4490 spin_unlock_irqrestore(&queued_arr_lock, iflags); 4973 spin_unlock_irqrestore(&queued_arr_lock, iflags);
4491 if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP) { 4974
4492 if (qdepth < 1) 4975 if (qdepth < 1)
4493 qdepth = 1; 4976 qdepth = 1;
4494 /* allow to exceed max host queued_arr elements for testing */ 4977 /* allow to exceed max host queued_arr elements for testing */
4495 if (qdepth > SCSI_DEBUG_CANQUEUE + 10) 4978 if (qdepth > SCSI_DEBUG_CANQUEUE + 10)
4496 qdepth = SCSI_DEBUG_CANQUEUE + 10; 4979 qdepth = SCSI_DEBUG_CANQUEUE + 10;
4497 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth); 4980 scsi_change_queue_depth(sdev, qdepth);
4498 } else if (reason == SCSI_QDEPTH_QFULL) 4981
4499 scsi_track_queue_full(sdev, qdepth);
4500 else
4501 bad = 1;
4502 if (bad)
4503 sdev_printk(KERN_WARNING, sdev,
4504 "%s: unknown reason=0x%x\n", __func__, reason);
4505 if (SCSI_DEBUG_OPT_Q_NOISE & scsi_debug_opts) { 4982 if (SCSI_DEBUG_OPT_Q_NOISE & scsi_debug_opts) {
4506 if (SCSI_QDEPTH_QFULL == reason) 4983 sdev_printk(KERN_INFO, sdev,
4507 sdev_printk(KERN_INFO, sdev, 4984 "%s: qdepth=%d, num_in_q=%d\n",
4508 "%s: -> %d, num_in_q=%d, reason: queue full\n", 4985 __func__, qdepth, num_in_q);
4509 __func__, qdepth, num_in_q);
4510 else {
4511 const char *cp;
4512
4513 switch (reason) {
4514 case SCSI_QDEPTH_DEFAULT:
4515 cp = "default (sysfs ?)";
4516 break;
4517 case SCSI_QDEPTH_RAMP_UP:
4518 cp = "ramp up";
4519 break;
4520 default:
4521 cp = "unknown";
4522 break;
4523 }
4524 sdev_printk(KERN_INFO, sdev,
4525 "%s: qdepth=%d, num_in_q=%d, reason: %s\n",
4526 __func__, qdepth, num_in_q, cp);
4527 }
4528 } 4986 }
4529 return sdev->queue_depth; 4987 return sdev->queue_depth;
4530} 4988}
@@ -4532,14 +4990,7 @@ sdebug_change_qdepth(struct scsi_device *sdev, int qdepth, int reason)
4532static int 4990static int
4533sdebug_change_qtype(struct scsi_device *sdev, int qtype) 4991sdebug_change_qtype(struct scsi_device *sdev, int qtype)
4534{ 4992{
4535 if (sdev->tagged_supported) { 4993 qtype = scsi_change_queue_type(sdev, qtype);
4536 scsi_set_tag_type(sdev, qtype);
4537 if (qtype)
4538 scsi_activate_tcq(sdev, sdev->queue_depth);
4539 else
4540 scsi_deactivate_tcq(sdev, sdev->queue_depth);
4541 } else
4542 qtype = 0;
4543 if (SCSI_DEBUG_OPT_Q_NOISE & scsi_debug_opts) { 4994 if (SCSI_DEBUG_OPT_Q_NOISE & scsi_debug_opts) {
4544 const char *cp; 4995 const char *cp;
4545 4996
@@ -4562,6 +5013,193 @@ sdebug_change_qtype(struct scsi_device *sdev, int qtype)
4562 return qtype; 5013 return qtype;
4563} 5014}
4564 5015
5016static int
5017check_inject(struct scsi_cmnd *scp)
5018{
5019 struct sdebug_scmd_extra_t *ep = scsi_cmd_priv(scp);
5020
5021 memset(ep, 0, sizeof(struct sdebug_scmd_extra_t));
5022
5023 if (atomic_inc_return(&sdebug_cmnd_count) >=
5024 abs(scsi_debug_every_nth)) {
5025 atomic_set(&sdebug_cmnd_count, 0);
5026 if (scsi_debug_every_nth < -1)
5027 scsi_debug_every_nth = -1;
5028 if (SCSI_DEBUG_OPT_TIMEOUT & scsi_debug_opts)
5029 return 1; /* ignore command causing timeout */
5030 else if (SCSI_DEBUG_OPT_MAC_TIMEOUT & scsi_debug_opts &&
5031 scsi_medium_access_command(scp))
5032 return 1; /* time out reads and writes */
5033 if (sdebug_any_injecting_opt) {
5034 int opts = scsi_debug_opts;
5035
5036 if (SCSI_DEBUG_OPT_RECOVERED_ERR & opts)
5037 ep->inj_recovered = true;
5038 else if (SCSI_DEBUG_OPT_TRANSPORT_ERR & opts)
5039 ep->inj_transport = true;
5040 else if (SCSI_DEBUG_OPT_DIF_ERR & opts)
5041 ep->inj_dif = true;
5042 else if (SCSI_DEBUG_OPT_DIX_ERR & opts)
5043 ep->inj_dix = true;
5044 else if (SCSI_DEBUG_OPT_SHORT_TRANSFER & opts)
5045 ep->inj_short = true;
5046 }
5047 }
5048 return 0;
5049}
5050
5051static int
5052scsi_debug_queuecommand(struct scsi_cmnd *scp)
5053{
5054 u8 sdeb_i;
5055 struct scsi_device *sdp = scp->device;
5056 const struct opcode_info_t *oip;
5057 const struct opcode_info_t *r_oip;
5058 struct sdebug_dev_info *devip;
5059 u8 *cmd = scp->cmnd;
5060 int (*r_pfp)(struct scsi_cmnd *, struct sdebug_dev_info *);
5061 int k, na;
5062 int errsts = 0;
5063 int errsts_no_connect = DID_NO_CONNECT << 16;
5064 u32 flags;
5065 u16 sa;
5066 u8 opcode = cmd[0];
5067 bool has_wlun_rl;
5068 bool debug = !!(SCSI_DEBUG_OPT_NOISE & scsi_debug_opts);
5069
5070 scsi_set_resid(scp, 0);
5071 if (debug && !(SCSI_DEBUG_OPT_NO_CDB_NOISE & scsi_debug_opts)) {
5072 char b[120];
5073 int n, len, sb;
5074
5075 len = scp->cmd_len;
5076 sb = (int)sizeof(b);
5077 if (len > 32)
5078 strcpy(b, "too long, over 32 bytes");
5079 else {
5080 for (k = 0, n = 0; k < len && n < sb; ++k)
5081 n += scnprintf(b + n, sb - n, "%02x ",
5082 (u32)cmd[k]);
5083 }
5084 sdev_printk(KERN_INFO, sdp, "%s: cmd %s\n", my_name, b);
5085 }
5086 has_wlun_rl = (sdp->lun == SAM2_WLUN_REPORT_LUNS);
5087 if ((sdp->lun >= scsi_debug_max_luns) && !has_wlun_rl)
5088 return schedule_resp(scp, NULL, errsts_no_connect, 0);
5089
5090 sdeb_i = opcode_ind_arr[opcode]; /* fully mapped */
5091 oip = &opcode_info_arr[sdeb_i]; /* safe if table consistent */
5092 devip = (struct sdebug_dev_info *)sdp->hostdata;
5093 if (!devip) {
5094 devip = devInfoReg(sdp);
5095 if (NULL == devip)
5096 return schedule_resp(scp, NULL, errsts_no_connect, 0);
5097 }
5098 na = oip->num_attached;
5099 r_pfp = oip->pfp;
5100 if (na) { /* multiple commands with this opcode */
5101 r_oip = oip;
5102 if (FF_SA & r_oip->flags) {
5103 if (F_SA_LOW & oip->flags)
5104 sa = 0x1f & cmd[1];
5105 else
5106 sa = get_unaligned_be16(cmd + 8);
5107 for (k = 0; k <= na; oip = r_oip->arrp + k++) {
5108 if (opcode == oip->opcode && sa == oip->sa)
5109 break;
5110 }
5111 } else { /* since no service action only check opcode */
5112 for (k = 0; k <= na; oip = r_oip->arrp + k++) {
5113 if (opcode == oip->opcode)
5114 break;
5115 }
5116 }
5117 if (k > na) {
5118 if (F_SA_LOW & r_oip->flags)
5119 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 1, 4);
5120 else if (F_SA_HIGH & r_oip->flags)
5121 mk_sense_invalid_fld(scp, SDEB_IN_CDB, 8, 7);
5122 else
5123 mk_sense_invalid_opcode(scp);
5124 goto check_cond;
5125 }
5126 } /* else (when na==0) we assume the oip is a match */
5127 flags = oip->flags;
5128 if (F_INV_OP & flags) {
5129 mk_sense_invalid_opcode(scp);
5130 goto check_cond;
5131 }
5132 if (has_wlun_rl && !(F_RL_WLUN_OK & flags)) {
5133 if (debug)
5134 sdev_printk(KERN_INFO, sdp, "scsi_debug: Opcode: "
5135 "0x%x not supported for wlun\n", opcode);
5136 mk_sense_invalid_opcode(scp);
5137 goto check_cond;
5138 }
5139 if (scsi_debug_strict) { /* check cdb against mask */
5140 u8 rem;
5141 int j;
5142
5143 for (k = 1; k < oip->len_mask[0] && k < 16; ++k) {
5144 rem = ~oip->len_mask[k] & cmd[k];
5145 if (rem) {
5146 for (j = 7; j >= 0; --j, rem <<= 1) {
5147 if (0x80 & rem)
5148 break;
5149 }
5150 mk_sense_invalid_fld(scp, SDEB_IN_CDB, k, j);
5151 goto check_cond;
5152 }
5153 }
5154 }
5155 if (!(F_SKIP_UA & flags) &&
5156 SDEBUG_NUM_UAS != find_first_bit(devip->uas_bm, SDEBUG_NUM_UAS)) {
5157 errsts = check_readiness(scp, UAS_ONLY, devip);
5158 if (errsts)
5159 goto check_cond;
5160 }
5161 if ((F_M_ACCESS & flags) && devip->stopped) {
5162 mk_sense_buffer(scp, NOT_READY, LOGICAL_UNIT_NOT_READY, 0x2);
5163 if (debug)
5164 sdev_printk(KERN_INFO, sdp, "%s reports: Not ready: "
5165 "%s\n", my_name, "initializing command "
5166 "required");
5167 errsts = check_condition_result;
5168 goto fini;
5169 }
5170 if (scsi_debug_fake_rw && (F_FAKE_RW & flags))
5171 goto fini;
5172 if (scsi_debug_every_nth) {
5173 if (check_inject(scp))
5174 return 0; /* ignore command: make trouble */
5175 }
5176 if (oip->pfp) /* if this command has a resp_* function, call it */
5177 errsts = oip->pfp(scp, devip);
5178 else if (r_pfp) /* if leaf function ptr NULL, try the root's */
5179 errsts = r_pfp(scp, devip);
5180
5181fini:
5182 return schedule_resp(scp, devip, errsts,
5183 ((F_DELAY_OVERR & flags) ? 0 : scsi_debug_delay));
5184check_cond:
5185 return schedule_resp(scp, devip, check_condition_result, 0);
5186}
5187
5188static int
5189sdebug_queuecommand_lock_or_not(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
5190{
5191 if (scsi_debug_host_lock) {
5192 unsigned long iflags;
5193 int rc;
5194
5195 spin_lock_irqsave(shost->host_lock, iflags);
5196 rc = scsi_debug_queuecommand(cmd);
5197 spin_unlock_irqrestore(shost->host_lock, iflags);
5198 return rc;
5199 } else
5200 return scsi_debug_queuecommand(cmd);
5201}
5202
4565static struct scsi_host_template sdebug_driver_template = { 5203static struct scsi_host_template sdebug_driver_template = {
4566 .show_info = scsi_debug_show_info, 5204 .show_info = scsi_debug_show_info,
4567 .write_info = scsi_debug_write_info, 5205 .write_info = scsi_debug_write_info,
@@ -4587,13 +5225,16 @@ static struct scsi_host_template sdebug_driver_template = {
4587 .max_sectors = -1U, 5225 .max_sectors = -1U,
4588 .use_clustering = DISABLE_CLUSTERING, 5226 .use_clustering = DISABLE_CLUSTERING,
4589 .module = THIS_MODULE, 5227 .module = THIS_MODULE,
5228 .track_queue_depth = 1,
5229 .cmd_size = sizeof(struct sdebug_scmd_extra_t),
4590}; 5230};
4591 5231
4592static int sdebug_driver_probe(struct device * dev) 5232static int sdebug_driver_probe(struct device * dev)
4593{ 5233{
4594 int error = 0; 5234 int error = 0;
4595 struct sdebug_host_info *sdbg_host; 5235 int opts;
4596 struct Scsi_Host *hpnt; 5236 struct sdebug_host_info *sdbg_host;
5237 struct Scsi_Host *hpnt;
4597 int host_prot; 5238 int host_prot;
4598 5239
4599 sdbg_host = to_sdebug_host(dev); 5240 sdbg_host = to_sdebug_host(dev);
@@ -4603,7 +5244,7 @@ static int sdebug_driver_probe(struct device * dev)
4603 sdebug_driver_template.use_clustering = ENABLE_CLUSTERING; 5244 sdebug_driver_template.use_clustering = ENABLE_CLUSTERING;
4604 hpnt = scsi_host_alloc(&sdebug_driver_template, sizeof(sdbg_host)); 5245 hpnt = scsi_host_alloc(&sdebug_driver_template, sizeof(sdbg_host));
4605 if (NULL == hpnt) { 5246 if (NULL == hpnt) {
4606 printk(KERN_ERR "%s: scsi_register failed\n", __func__); 5247 pr_err("%s: scsi_host_alloc failed\n", __func__);
4607 error = -ENODEV; 5248 error = -ENODEV;
4608 return error; 5249 return error;
4609 } 5250 }
@@ -4660,6 +5301,18 @@ static int sdebug_driver_probe(struct device * dev)
4660 else 5301 else
4661 scsi_host_set_guard(hpnt, SHOST_DIX_GUARD_CRC); 5302 scsi_host_set_guard(hpnt, SHOST_DIX_GUARD_CRC);
4662 5303
5304 opts = scsi_debug_opts;
5305 if (SCSI_DEBUG_OPT_RECOVERED_ERR & opts)
5306 sdebug_any_injecting_opt = true;
5307 else if (SCSI_DEBUG_OPT_TRANSPORT_ERR & opts)
5308 sdebug_any_injecting_opt = true;
5309 else if (SCSI_DEBUG_OPT_DIF_ERR & opts)
5310 sdebug_any_injecting_opt = true;
5311 else if (SCSI_DEBUG_OPT_DIX_ERR & opts)
5312 sdebug_any_injecting_opt = true;
5313 else if (SCSI_DEBUG_OPT_SHORT_TRANSFER & opts)
5314 sdebug_any_injecting_opt = true;
5315
4663 error = scsi_add_host(hpnt, &sdbg_host->dev); 5316 error = scsi_add_host(hpnt, &sdbg_host->dev);
4664 if (error) { 5317 if (error) {
4665 printk(KERN_ERR "%s: scsi_add_host failed\n", __func__); 5318 printk(KERN_ERR "%s: scsi_add_host failed\n", __func__);
diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 49014a143c6a..c1d04d4d3c6c 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -202,6 +202,7 @@ static struct {
202 {"IOMEGA", "Io20S *F", NULL, BLIST_KEY}, 202 {"IOMEGA", "Io20S *F", NULL, BLIST_KEY},
203 {"INSITE", "Floptical F*8I", NULL, BLIST_KEY}, 203 {"INSITE", "Floptical F*8I", NULL, BLIST_KEY},
204 {"INSITE", "I325VM", NULL, BLIST_KEY}, 204 {"INSITE", "I325VM", NULL, BLIST_KEY},
205 {"Intel", "Multi-Flex", NULL, BLIST_NO_RSOC},
205 {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36}, 206 {"iRiver", "iFP Mass Driver", NULL, BLIST_NOT_LOCKABLE | BLIST_INQUIRY_36},
206 {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN}, 207 {"LASOUND", "CDX7405", "3.10", BLIST_MAX5LUN | BLIST_SINGLELUN},
207 {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN}, 208 {"MATSHITA", "PD-1", NULL, BLIST_FORCELUN | BLIST_SINGLELUN},
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 9a6f8468225f..e42fff6e8c10 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -36,6 +36,7 @@
36#include <scsi/scsi_transport.h> 36#include <scsi/scsi_transport.h>
37#include <scsi/scsi_host.h> 37#include <scsi/scsi_host.h>
38#include <scsi/scsi_ioctl.h> 38#include <scsi/scsi_ioctl.h>
39#include <scsi/sg.h>
39 40
40#include "scsi_priv.h" 41#include "scsi_priv.h"
41#include "scsi_logging.h" 42#include "scsi_logging.h"
@@ -157,8 +158,9 @@ scmd_eh_abort_handler(struct work_struct *work)
157 } else { 158 } else {
158 SCSI_LOG_ERROR_RECOVERY(3, 159 SCSI_LOG_ERROR_RECOVERY(3,
159 scmd_printk(KERN_INFO, scmd, 160 scmd_printk(KERN_INFO, scmd,
160 "scmd %p abort failed, rtn %d\n", 161 "scmd %p abort %s\n", scmd,
161 scmd, rtn)); 162 (rtn == FAST_IO_FAIL) ?
163 "not send" : "failed"));
162 } 164 }
163 } 165 }
164 166
@@ -355,7 +357,7 @@ static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
355 357
356 if (cmd_cancel || cmd_failed) { 358 if (cmd_cancel || cmd_failed) {
357 SCSI_LOG_ERROR_RECOVERY(3, 359 SCSI_LOG_ERROR_RECOVERY(3,
358 sdev_printk(KERN_INFO, sdev, 360 shost_printk(KERN_INFO, shost,
359 "%s: cmds failed: %d, cancel: %d\n", 361 "%s: cmds failed: %d, cancel: %d\n",
360 __func__, cmd_failed, 362 __func__, cmd_failed,
361 cmd_cancel)); 363 cmd_cancel));
@@ -459,14 +461,6 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
459 if (! scsi_command_normalize_sense(scmd, &sshdr)) 461 if (! scsi_command_normalize_sense(scmd, &sshdr))
460 return FAILED; /* no valid sense data */ 462 return FAILED; /* no valid sense data */
461 463
462 if (scmd->cmnd[0] == TEST_UNIT_READY && scmd->scsi_done != scsi_eh_done)
463 /*
464 * nasty: for mid-layer issued TURs, we need to return the
465 * actual sense data without any recovery attempt. For eh
466 * issued ones, we need to try to recover and interpret
467 */
468 return SUCCESS;
469
470 scsi_report_sense(sdev, &sshdr); 464 scsi_report_sense(sdev, &sshdr);
471 465
472 if (scsi_sense_is_deferred(&sshdr)) 466 if (scsi_sense_is_deferred(&sshdr))
@@ -482,6 +476,14 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
482 /* handler does not care. Drop down to default handling */ 476 /* handler does not care. Drop down to default handling */
483 } 477 }
484 478
479 if (scmd->cmnd[0] == TEST_UNIT_READY && scmd->scsi_done != scsi_eh_done)
480 /*
481 * nasty: for mid-layer issued TURs, we need to return the
482 * actual sense data without any recovery attempt. For eh
483 * issued ones, we need to try to recover and interpret
484 */
485 return SUCCESS;
486
485 /* 487 /*
486 * Previous logic looked for FILEMARK, EOM or ILI which are 488 * Previous logic looked for FILEMARK, EOM or ILI which are
487 * mainly associated with tapes and returned SUCCESS. 489 * mainly associated with tapes and returned SUCCESS.
@@ -608,7 +610,7 @@ static void scsi_handle_queue_ramp_up(struct scsi_device *sdev)
608 struct scsi_host_template *sht = sdev->host->hostt; 610 struct scsi_host_template *sht = sdev->host->hostt;
609 struct scsi_device *tmp_sdev; 611 struct scsi_device *tmp_sdev;
610 612
611 if (!sht->change_queue_depth || 613 if (!sht->track_queue_depth ||
612 sdev->queue_depth >= sdev->max_queue_depth) 614 sdev->queue_depth >= sdev->max_queue_depth)
613 return; 615 return;
614 616
@@ -629,12 +631,8 @@ static void scsi_handle_queue_ramp_up(struct scsi_device *sdev)
629 tmp_sdev->id != sdev->id || 631 tmp_sdev->id != sdev->id ||
630 tmp_sdev->queue_depth == sdev->max_queue_depth) 632 tmp_sdev->queue_depth == sdev->max_queue_depth)
631 continue; 633 continue;
632 /* 634
633 * call back into LLD to increase queue_depth by one 635 scsi_change_queue_depth(tmp_sdev, tmp_sdev->queue_depth + 1);
634 * with ramp up reason code.
635 */
636 sht->change_queue_depth(tmp_sdev, tmp_sdev->queue_depth + 1,
637 SCSI_QDEPTH_RAMP_UP);
638 sdev->last_queue_ramp_up = jiffies; 636 sdev->last_queue_ramp_up = jiffies;
639 } 637 }
640} 638}
@@ -644,7 +642,7 @@ static void scsi_handle_queue_full(struct scsi_device *sdev)
644 struct scsi_host_template *sht = sdev->host->hostt; 642 struct scsi_host_template *sht = sdev->host->hostt;
645 struct scsi_device *tmp_sdev; 643 struct scsi_device *tmp_sdev;
646 644
647 if (!sht->change_queue_depth) 645 if (!sht->track_queue_depth)
648 return; 646 return;
649 647
650 shost_for_each_device(tmp_sdev, sdev->host) { 648 shost_for_each_device(tmp_sdev, sdev->host) {
@@ -656,8 +654,7 @@ static void scsi_handle_queue_full(struct scsi_device *sdev)
656 * the device when we got the queue full so we start 654 * the device when we got the queue full so we start
657 * from the highest possible value and work our way down. 655 * from the highest possible value and work our way down.
658 */ 656 */
659 sht->change_queue_depth(tmp_sdev, tmp_sdev->queue_depth - 1, 657 scsi_track_queue_full(tmp_sdev, tmp_sdev->queue_depth - 1);
660 SCSI_QDEPTH_QFULL);
661 } 658 }
662} 659}
663 660
@@ -869,7 +866,24 @@ static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
869 return rtn; 866 return rtn;
870} 867}
871 868
872static int scsi_try_to_abort_cmd(struct scsi_host_template *hostt, struct scsi_cmnd *scmd) 869/**
870 * scsi_try_to_abort_cmd - Ask host to abort a SCSI command
871 * @scmd: SCSI cmd used to send a target reset
872 *
873 * Return value:
874 * SUCCESS, FAILED, or FAST_IO_FAIL
875 *
876 * Notes:
877 * SUCCESS does not necessarily indicate that the command
878 * has been aborted; it only indicates that the LLDDs
879 * has cleared all references to that command.
880 * LLDDs should return FAILED only if an abort was required
881 * but could not be executed. LLDDs should return FAST_IO_FAIL
882 * if the device is temporarily unavailable (eg due to a
883 * link down on FibreChannel)
884 */
885static int scsi_try_to_abort_cmd(struct scsi_host_template *hostt,
886 struct scsi_cmnd *scmd)
873{ 887{
874 if (!hostt->eh_abort_handler) 888 if (!hostt->eh_abort_handler)
875 return FAILED; 889 return FAILED;
@@ -1156,9 +1170,9 @@ int scsi_eh_get_sense(struct list_head *work_q,
1156 shost = scmd->device->host; 1170 shost = scmd->device->host;
1157 if (scsi_host_eh_past_deadline(shost)) { 1171 if (scsi_host_eh_past_deadline(shost)) {
1158 SCSI_LOG_ERROR_RECOVERY(3, 1172 SCSI_LOG_ERROR_RECOVERY(3,
1159 shost_printk(KERN_INFO, shost, 1173 scmd_printk(KERN_INFO, scmd,
1160 "skip %s, past eh deadline\n", 1174 "%s: skip request sense, past eh deadline\n",
1161 __func__)); 1175 current->comm));
1162 break; 1176 break;
1163 } 1177 }
1164 if (status_byte(scmd->result) != CHECK_CONDITION) 1178 if (status_byte(scmd->result) != CHECK_CONDITION)
@@ -1180,7 +1194,7 @@ int scsi_eh_get_sense(struct list_head *work_q,
1180 SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd, 1194 SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
1181 "sense requested for %p result %x\n", 1195 "sense requested for %p result %x\n",
1182 scmd, scmd->result)); 1196 scmd, scmd->result));
1183 SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense("bh", scmd)); 1197 SCSI_LOG_ERROR_RECOVERY(3, scsi_print_sense(scmd));
1184 1198
1185 rtn = scsi_decide_disposition(scmd); 1199 rtn = scsi_decide_disposition(scmd);
1186 1200
@@ -1265,9 +1279,9 @@ static int scsi_eh_test_devices(struct list_head *cmd_list,
1265 /* Push items back onto work_q */ 1279 /* Push items back onto work_q */
1266 list_splice_init(cmd_list, work_q); 1280 list_splice_init(cmd_list, work_q);
1267 SCSI_LOG_ERROR_RECOVERY(3, 1281 SCSI_LOG_ERROR_RECOVERY(3,
1268 shost_printk(KERN_INFO, sdev->host, 1282 sdev_printk(KERN_INFO, sdev,
1269 "skip %s, past eh deadline", 1283 "%s: skip test device, past eh deadline",
1270 __func__)); 1284 current->comm));
1271 break; 1285 break;
1272 } 1286 }
1273 } 1287 }
@@ -1318,21 +1332,20 @@ static int scsi_eh_abort_cmds(struct list_head *work_q,
1318 if (scsi_host_eh_past_deadline(shost)) { 1332 if (scsi_host_eh_past_deadline(shost)) {
1319 list_splice_init(&check_list, work_q); 1333 list_splice_init(&check_list, work_q);
1320 SCSI_LOG_ERROR_RECOVERY(3, 1334 SCSI_LOG_ERROR_RECOVERY(3,
1321 shost_printk(KERN_INFO, shost, 1335 scmd_printk(KERN_INFO, scmd,
1322 "skip %s, past eh deadline\n", 1336 "%s: skip aborting cmd, past eh deadline\n",
1323 __func__)); 1337 current->comm));
1324 return list_empty(work_q); 1338 return list_empty(work_q);
1325 } 1339 }
1326 SCSI_LOG_ERROR_RECOVERY(3, 1340 SCSI_LOG_ERROR_RECOVERY(3,
1327 shost_printk(KERN_INFO, shost, 1341 scmd_printk(KERN_INFO, scmd,
1328 "%s: aborting cmd: 0x%p\n", 1342 "%s: aborting cmd\n", current->comm));
1329 current->comm, scmd));
1330 rtn = scsi_try_to_abort_cmd(shost->hostt, scmd); 1343 rtn = scsi_try_to_abort_cmd(shost->hostt, scmd);
1331 if (rtn == FAILED) { 1344 if (rtn == FAILED) {
1332 SCSI_LOG_ERROR_RECOVERY(3, 1345 SCSI_LOG_ERROR_RECOVERY(3,
1333 shost_printk(KERN_INFO, shost, 1346 scmd_printk(KERN_INFO, scmd,
1334 "%s: aborting cmd failed: 0x%p\n", 1347 "%s: aborting cmd failed\n",
1335 current->comm, scmd)); 1348 current->comm));
1336 list_splice_init(&check_list, work_q); 1349 list_splice_init(&check_list, work_q);
1337 return list_empty(work_q); 1350 return list_empty(work_q);
1338 } 1351 }
@@ -1390,9 +1403,9 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
1390 shost_for_each_device(sdev, shost) { 1403 shost_for_each_device(sdev, shost) {
1391 if (scsi_host_eh_past_deadline(shost)) { 1404 if (scsi_host_eh_past_deadline(shost)) {
1392 SCSI_LOG_ERROR_RECOVERY(3, 1405 SCSI_LOG_ERROR_RECOVERY(3,
1393 shost_printk(KERN_INFO, shost, 1406 sdev_printk(KERN_INFO, sdev,
1394 "skip %s, past eh deadline\n", 1407 "%s: skip START_UNIT, past eh deadline\n",
1395 __func__)); 1408 current->comm));
1396 break; 1409 break;
1397 } 1410 }
1398 stu_scmd = NULL; 1411 stu_scmd = NULL;
@@ -1407,9 +1420,9 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
1407 continue; 1420 continue;
1408 1421
1409 SCSI_LOG_ERROR_RECOVERY(3, 1422 SCSI_LOG_ERROR_RECOVERY(3,
1410 shost_printk(KERN_INFO, shost, 1423 sdev_printk(KERN_INFO, sdev,
1411 "%s: Sending START_UNIT to sdev: 0x%p\n", 1424 "%s: Sending START_UNIT\n",
1412 current->comm, sdev)); 1425 current->comm));
1413 1426
1414 if (!scsi_eh_try_stu(stu_scmd)) { 1427 if (!scsi_eh_try_stu(stu_scmd)) {
1415 if (!scsi_device_online(sdev) || 1428 if (!scsi_device_online(sdev) ||
@@ -1423,9 +1436,9 @@ static int scsi_eh_stu(struct Scsi_Host *shost,
1423 } 1436 }
1424 } else { 1437 } else {
1425 SCSI_LOG_ERROR_RECOVERY(3, 1438 SCSI_LOG_ERROR_RECOVERY(3,
1426 shost_printk(KERN_INFO, shost, 1439 sdev_printk(KERN_INFO, sdev,
1427 "%s: START_UNIT failed to sdev:" 1440 "%s: START_UNIT failed\n",
1428 " 0x%p\n", current->comm, sdev)); 1441 current->comm));
1429 } 1442 }
1430 } 1443 }
1431 1444
@@ -1456,9 +1469,9 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
1456 shost_for_each_device(sdev, shost) { 1469 shost_for_each_device(sdev, shost) {
1457 if (scsi_host_eh_past_deadline(shost)) { 1470 if (scsi_host_eh_past_deadline(shost)) {
1458 SCSI_LOG_ERROR_RECOVERY(3, 1471 SCSI_LOG_ERROR_RECOVERY(3,
1459 shost_printk(KERN_INFO, shost, 1472 sdev_printk(KERN_INFO, sdev,
1460 "skip %s, past eh deadline\n", 1473 "%s: skip BDR, past eh deadline\n",
1461 __func__)); 1474 current->comm));
1462 break; 1475 break;
1463 } 1476 }
1464 bdr_scmd = NULL; 1477 bdr_scmd = NULL;
@@ -1472,9 +1485,8 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
1472 continue; 1485 continue;
1473 1486
1474 SCSI_LOG_ERROR_RECOVERY(3, 1487 SCSI_LOG_ERROR_RECOVERY(3,
1475 shost_printk(KERN_INFO, shost, 1488 sdev_printk(KERN_INFO, sdev,
1476 "%s: Sending BDR sdev: 0x%p\n", 1489 "%s: Sending BDR\n", current->comm));
1477 current->comm, sdev));
1478 rtn = scsi_try_bus_device_reset(bdr_scmd); 1490 rtn = scsi_try_bus_device_reset(bdr_scmd);
1479 if (rtn == SUCCESS || rtn == FAST_IO_FAIL) { 1491 if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
1480 if (!scsi_device_online(sdev) || 1492 if (!scsi_device_online(sdev) ||
@@ -1490,9 +1502,8 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
1490 } 1502 }
1491 } else { 1503 } else {
1492 SCSI_LOG_ERROR_RECOVERY(3, 1504 SCSI_LOG_ERROR_RECOVERY(3,
1493 shost_printk(KERN_INFO, shost, 1505 sdev_printk(KERN_INFO, sdev,
1494 "%s: BDR failed sdev: 0x%p\n", 1506 "%s: BDR failed\n", current->comm));
1495 current->comm, sdev));
1496 } 1507 }
1497 } 1508 }
1498 1509
@@ -1528,8 +1539,8 @@ static int scsi_eh_target_reset(struct Scsi_Host *shost,
1528 list_splice_init(&tmp_list, work_q); 1539 list_splice_init(&tmp_list, work_q);
1529 SCSI_LOG_ERROR_RECOVERY(3, 1540 SCSI_LOG_ERROR_RECOVERY(3,
1530 shost_printk(KERN_INFO, shost, 1541 shost_printk(KERN_INFO, shost,
1531 "skip %s, past eh deadline\n", 1542 "%s: Skip target reset, past eh deadline\n",
1532 __func__)); 1543 current->comm));
1533 return list_empty(work_q); 1544 return list_empty(work_q);
1534 } 1545 }
1535 1546
@@ -1591,8 +1602,8 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost,
1591 list_splice_init(&check_list, work_q); 1602 list_splice_init(&check_list, work_q);
1592 SCSI_LOG_ERROR_RECOVERY(3, 1603 SCSI_LOG_ERROR_RECOVERY(3,
1593 shost_printk(KERN_INFO, shost, 1604 shost_printk(KERN_INFO, shost,
1594 "skip %s, past eh deadline\n", 1605 "%s: skip BRST, past eh deadline\n",
1595 __func__)); 1606 current->comm));
1596 return list_empty(work_q); 1607 return list_empty(work_q);
1597 } 1608 }
1598 1609
@@ -2001,8 +2012,10 @@ static void scsi_restart_operations(struct Scsi_Host *shost)
2001 * is no point trying to lock the door of an off-line device. 2012 * is no point trying to lock the door of an off-line device.
2002 */ 2013 */
2003 shost_for_each_device(sdev, shost) { 2014 shost_for_each_device(sdev, shost) {
2004 if (scsi_device_online(sdev) && sdev->locked) 2015 if (scsi_device_online(sdev) && sdev->was_reset && sdev->locked) {
2005 scsi_eh_lock_door(sdev); 2016 scsi_eh_lock_door(sdev);
2017 sdev->was_reset = 0;
2018 }
2006 } 2019 }
2007 2020
2008 /* 2021 /*
@@ -2191,9 +2204,9 @@ int scsi_error_handler(void *data)
2191 */ 2204 */
2192 if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) { 2205 if (!shost->eh_noresume && scsi_autopm_get_host(shost) != 0) {
2193 SCSI_LOG_ERROR_RECOVERY(1, 2206 SCSI_LOG_ERROR_RECOVERY(1,
2194 printk(KERN_ERR "Error handler scsi_eh_%d " 2207 shost_printk(KERN_ERR, shost,
2195 "unable to autoresume\n", 2208 "scsi_eh_%d: unable to autoresume\n",
2196 shost->host_no)); 2209 shost->host_no));
2197 continue; 2210 continue;
2198 } 2211 }
2199 2212
@@ -2294,42 +2307,34 @@ scsi_reset_provider_done_command(struct scsi_cmnd *scmd)
2294{ 2307{
2295} 2308}
2296 2309
2297/* 2310/**
2298 * Function: scsi_reset_provider 2311 * scsi_ioctl_reset: explicitly reset a host/bus/target/device
2299 * 2312 * @dev: scsi_device to operate on
2300 * Purpose: Send requested reset to a bus or device at any phase. 2313 * @arg: reset type (see sg.h)
2301 *
2302 * Arguments: device - device to send reset to
2303 * flag - reset type (see scsi.h)
2304 *
2305 * Returns: SUCCESS/FAILURE.
2306 *
2307 * Notes: This is used by the SCSI Generic driver to provide
2308 * Bus/Device reset capability.
2309 */ 2314 */
2310int 2315int
2311scsi_reset_provider(struct scsi_device *dev, int flag) 2316scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
2312{ 2317{
2313 struct scsi_cmnd *scmd; 2318 struct scsi_cmnd *scmd;
2314 struct Scsi_Host *shost = dev->host; 2319 struct Scsi_Host *shost = dev->host;
2315 struct request req; 2320 struct request req;
2316 unsigned long flags; 2321 unsigned long flags;
2317 int rtn; 2322 int error = 0, rtn, val;
2318 2323
2319 if (scsi_autopm_get_host(shost) < 0) 2324 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
2320 return FAILED; 2325 return -EACCES;
2321 2326
2322 if (!get_device(&dev->sdev_gendev)) { 2327 error = get_user(val, arg);
2323 rtn = FAILED; 2328 if (error)
2324 goto out_put_autopm_host; 2329 return error;
2325 }
2326 2330
2331 if (scsi_autopm_get_host(shost) < 0)
2332 return -EIO;
2333
2334 error = -EIO;
2327 scmd = scsi_get_command(dev, GFP_KERNEL); 2335 scmd = scsi_get_command(dev, GFP_KERNEL);
2328 if (!scmd) { 2336 if (!scmd)
2329 rtn = FAILED;
2330 put_device(&dev->sdev_gendev);
2331 goto out_put_autopm_host; 2337 goto out_put_autopm_host;
2332 }
2333 2338
2334 blk_rq_init(NULL, &req); 2339 blk_rq_init(NULL, &req);
2335 scmd->request = &req; 2340 scmd->request = &req;
@@ -2347,29 +2352,37 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
2347 shost->tmf_in_progress = 1; 2352 shost->tmf_in_progress = 1;
2348 spin_unlock_irqrestore(shost->host_lock, flags); 2353 spin_unlock_irqrestore(shost->host_lock, flags);
2349 2354
2350 switch (flag) { 2355 switch (val & ~SG_SCSI_RESET_NO_ESCALATE) {
2351 case SCSI_TRY_RESET_DEVICE: 2356 case SG_SCSI_RESET_NOTHING:
2357 rtn = SUCCESS;
2358 break;
2359 case SG_SCSI_RESET_DEVICE:
2352 rtn = scsi_try_bus_device_reset(scmd); 2360 rtn = scsi_try_bus_device_reset(scmd);
2353 if (rtn == SUCCESS) 2361 if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
2354 break; 2362 break;
2355 /* FALLTHROUGH */ 2363 /* FALLTHROUGH */
2356 case SCSI_TRY_RESET_TARGET: 2364 case SG_SCSI_RESET_TARGET:
2357 rtn = scsi_try_target_reset(scmd); 2365 rtn = scsi_try_target_reset(scmd);
2358 if (rtn == SUCCESS) 2366 if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
2359 break; 2367 break;
2360 /* FALLTHROUGH */ 2368 /* FALLTHROUGH */
2361 case SCSI_TRY_RESET_BUS: 2369 case SG_SCSI_RESET_BUS:
2362 rtn = scsi_try_bus_reset(scmd); 2370 rtn = scsi_try_bus_reset(scmd);
2363 if (rtn == SUCCESS) 2371 if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
2364 break; 2372 break;
2365 /* FALLTHROUGH */ 2373 /* FALLTHROUGH */
2366 case SCSI_TRY_RESET_HOST: 2374 case SG_SCSI_RESET_HOST:
2367 rtn = scsi_try_host_reset(scmd); 2375 rtn = scsi_try_host_reset(scmd);
2368 break; 2376 if (rtn == SUCCESS)
2377 break;
2369 default: 2378 default:
2379 /* FALLTHROUGH */
2370 rtn = FAILED; 2380 rtn = FAILED;
2381 break;
2371 } 2382 }
2372 2383
2384 error = (rtn == SUCCESS) ? 0 : -EIO;
2385
2373 spin_lock_irqsave(shost->host_lock, flags); 2386 spin_lock_irqsave(shost->host_lock, flags);
2374 shost->tmf_in_progress = 0; 2387 shost->tmf_in_progress = 0;
2375 spin_unlock_irqrestore(shost->host_lock, flags); 2388 spin_unlock_irqrestore(shost->host_lock, flags);
@@ -2383,15 +2396,15 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
2383 "waking up host to restart after TMF\n")); 2396 "waking up host to restart after TMF\n"));
2384 2397
2385 wake_up(&shost->host_wait); 2398 wake_up(&shost->host_wait);
2386
2387 scsi_run_host_queues(shost); 2399 scsi_run_host_queues(shost);
2388 2400
2389 scsi_next_command(scmd); 2401 scsi_put_command(scmd);
2402
2390out_put_autopm_host: 2403out_put_autopm_host:
2391 scsi_autopm_put_host(shost); 2404 scsi_autopm_put_host(shost);
2392 return rtn; 2405 return error;
2393} 2406}
2394EXPORT_SYMBOL(scsi_reset_provider); 2407EXPORT_SYMBOL(scsi_ioctl_reset);
2395 2408
2396/** 2409/**
2397 * scsi_normalize_sense - normalize main elements from either fixed or 2410 * scsi_normalize_sense - normalize main elements from either fixed or
@@ -2410,20 +2423,20 @@ EXPORT_SYMBOL(scsi_reset_provider);
2410 * responded to a SCSI command with the CHECK_CONDITION status. 2423 * responded to a SCSI command with the CHECK_CONDITION status.
2411 * 2424 *
2412 * Return value: 2425 * Return value:
2413 * 1 if valid sense data information found, else 0; 2426 * true if valid sense data information found, else false;
2414 */ 2427 */
2415int scsi_normalize_sense(const u8 *sense_buffer, int sb_len, 2428bool scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
2416 struct scsi_sense_hdr *sshdr) 2429 struct scsi_sense_hdr *sshdr)
2417{ 2430{
2418 if (!sense_buffer || !sb_len) 2431 if (!sense_buffer || !sb_len)
2419 return 0; 2432 return false;
2420 2433
2421 memset(sshdr, 0, sizeof(struct scsi_sense_hdr)); 2434 memset(sshdr, 0, sizeof(struct scsi_sense_hdr));
2422 2435
2423 sshdr->response_code = (sense_buffer[0] & 0x7f); 2436 sshdr->response_code = (sense_buffer[0] & 0x7f);
2424 2437
2425 if (!scsi_sense_valid(sshdr)) 2438 if (!scsi_sense_valid(sshdr))
2426 return 0; 2439 return false;
2427 2440
2428 if (sshdr->response_code >= 0x72) { 2441 if (sshdr->response_code >= 0x72) {
2429 /* 2442 /*
@@ -2453,12 +2466,12 @@ int scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
2453 } 2466 }
2454 } 2467 }
2455 2468
2456 return 1; 2469 return true;
2457} 2470}
2458EXPORT_SYMBOL(scsi_normalize_sense); 2471EXPORT_SYMBOL(scsi_normalize_sense);
2459 2472
2460int scsi_command_normalize_sense(struct scsi_cmnd *cmd, 2473bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd,
2461 struct scsi_sense_hdr *sshdr) 2474 struct scsi_sense_hdr *sshdr)
2462{ 2475{
2463 return scsi_normalize_sense(cmd->sense_buffer, 2476 return scsi_normalize_sense(cmd->sense_buffer,
2464 SCSI_SENSE_BUFFERSIZE, sshdr); 2477 SCSI_SENSE_BUFFERSIZE, sshdr);
diff --git a/drivers/scsi/scsi_ioctl.c b/drivers/scsi/scsi_ioctl.c
index 1aaaf43c6803..c4f7b56fa6f6 100644
--- a/drivers/scsi/scsi_ioctl.c
+++ b/drivers/scsi/scsi_ioctl.c
@@ -126,7 +126,7 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
126 sdev_printk(KERN_INFO, sdev, 126 sdev_printk(KERN_INFO, sdev,
127 "ioctl_internal_command return code = %x\n", 127 "ioctl_internal_command return code = %x\n",
128 result); 128 result);
129 scsi_print_sense_hdr(" ", &sshdr); 129 scsi_print_sense_hdr(sdev, NULL, &sshdr);
130 break; 130 break;
131 } 131 }
132 } 132 }
@@ -200,19 +200,6 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
200{ 200{
201 char scsi_cmd[MAX_COMMAND_SIZE]; 201 char scsi_cmd[MAX_COMMAND_SIZE];
202 202
203 /* No idea how this happens.... */
204 if (!sdev)
205 return -ENXIO;
206
207 /*
208 * If we are in the middle of error recovery, don't let anyone
209 * else try and use this device. Also, if error recovery fails, it
210 * may try and take the device offline, in which case all further
211 * access to the device is prohibited.
212 */
213 if (!scsi_block_when_processing_errors(sdev))
214 return -ENODEV;
215
216 /* Check for deprecated ioctls ... all the ioctls which don't 203 /* Check for deprecated ioctls ... all the ioctls which don't
217 * follow the new unique numbering scheme are deprecated */ 204 * follow the new unique numbering scheme are deprecated */
218 switch (cmd) { 205 switch (cmd) {
@@ -273,6 +260,8 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
273 START_STOP_TIMEOUT, NORMAL_RETRIES); 260 START_STOP_TIMEOUT, NORMAL_RETRIES);
274 case SCSI_IOCTL_GET_PCI: 261 case SCSI_IOCTL_GET_PCI:
275 return scsi_ioctl_get_pci(sdev, arg); 262 return scsi_ioctl_get_pci(sdev, arg);
263 case SG_SCSI_RESET:
264 return scsi_ioctl_reset(sdev, arg);
276 default: 265 default:
277 if (sdev->host->hostt->ioctl) 266 if (sdev->host->hostt->ioctl)
278 return sdev->host->hostt->ioctl(sdev, cmd, arg); 267 return sdev->host->hostt->ioctl(sdev, cmd, arg);
@@ -281,55 +270,20 @@ int scsi_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
281} 270}
282EXPORT_SYMBOL(scsi_ioctl); 271EXPORT_SYMBOL(scsi_ioctl);
283 272
284/** 273/*
285 * scsi_nonblockable_ioctl() - Handle SG_SCSI_RESET 274 * We can process a reset even when a device isn't fully operable.
286 * @sdev: scsi device receiving ioctl
287 * @cmd: Must be SC_SCSI_RESET
288 * @arg: pointer to int containing SG_SCSI_RESET_{DEVICE,BUS,HOST}
289 * @ndelay: file mode O_NDELAY flag
290 */ 275 */
291int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd, 276int scsi_ioctl_block_when_processing_errors(struct scsi_device *sdev, int cmd,
292 void __user *arg, int ndelay) 277 bool ndelay)
293{ 278{
294 int val, result; 279 if (cmd == SG_SCSI_RESET && ndelay) {
295
296 /* The first set of iocts may be executed even if we're doing
297 * error processing, as long as the device was opened
298 * non-blocking */
299 if (ndelay) {
300 if (scsi_host_in_recovery(sdev->host)) 280 if (scsi_host_in_recovery(sdev->host))
281 return -EAGAIN;
282 } else {
283 if (!scsi_block_when_processing_errors(sdev))
301 return -ENODEV; 284 return -ENODEV;
302 } else if (!scsi_block_when_processing_errors(sdev))
303 return -ENODEV;
304
305 switch (cmd) {
306 case SG_SCSI_RESET:
307 result = get_user(val, (int __user *)arg);
308 if (result)
309 return result;
310 if (val == SG_SCSI_RESET_NOTHING)
311 return 0;
312 switch (val) {
313 case SG_SCSI_RESET_DEVICE:
314 val = SCSI_TRY_RESET_DEVICE;
315 break;
316 case SG_SCSI_RESET_TARGET:
317 val = SCSI_TRY_RESET_TARGET;
318 break;
319 case SG_SCSI_RESET_BUS:
320 val = SCSI_TRY_RESET_BUS;
321 break;
322 case SG_SCSI_RESET_HOST:
323 val = SCSI_TRY_RESET_HOST;
324 break;
325 default:
326 return -EINVAL;
327 }
328 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
329 return -EACCES;
330 return (scsi_reset_provider(sdev, val) ==
331 SUCCESS) ? 0 : -EIO;
332 } 285 }
333 return -ENODEV; 286
287 return 0;
334} 288}
335EXPORT_SYMBOL(scsi_nonblockable_ioctl); 289EXPORT_SYMBOL_GPL(scsi_ioctl_block_when_processing_errors);
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 50a6e1ac8d9c..7e3d954c9cac 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -22,6 +22,7 @@
22#include <linux/hardirq.h> 22#include <linux/hardirq.h>
23#include <linux/scatterlist.h> 23#include <linux/scatterlist.h>
24#include <linux/blk-mq.h> 24#include <linux/blk-mq.h>
25#include <linux/ratelimit.h>
25 26
26#include <scsi/scsi.h> 27#include <scsi/scsi.h>
27#include <scsi/scsi_cmnd.h> 28#include <scsi/scsi_cmnd.h>
@@ -47,7 +48,7 @@ struct scsi_host_sg_pool {
47 mempool_t *pool; 48 mempool_t *pool;
48}; 49};
49 50
50#define SP(x) { x, "sgpool-" __stringify(x) } 51#define SP(x) { .size = x, "sgpool-" __stringify(x) }
51#if (SCSI_MAX_SG_SEGMENTS < 32) 52#if (SCSI_MAX_SG_SEGMENTS < 32)
52#error SCSI_MAX_SG_SEGMENTS is too small (must be 32 or greater) 53#error SCSI_MAX_SG_SEGMENTS is too small (must be 32 or greater)
53#endif 54#endif
@@ -542,17 +543,6 @@ static void scsi_requeue_command(struct request_queue *q, struct scsi_cmnd *cmd)
542 put_device(&sdev->sdev_gendev); 543 put_device(&sdev->sdev_gendev);
543} 544}
544 545
545void scsi_next_command(struct scsi_cmnd *cmd)
546{
547 struct scsi_device *sdev = cmd->device;
548 struct request_queue *q = sdev->request_queue;
549
550 scsi_put_command(cmd);
551 scsi_run_queue(q);
552
553 put_device(&sdev->sdev_gendev);
554}
555
556void scsi_run_host_queues(struct Scsi_Host *shost) 546void scsi_run_host_queues(struct Scsi_Host *shost)
557{ 547{
558 struct scsi_device *sdev; 548 struct scsi_device *sdev;
@@ -598,10 +588,10 @@ static void scsi_free_sgtable(struct scsi_data_buffer *sdb, bool mq)
598 __sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, mq, scsi_sg_free); 588 __sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, mq, scsi_sg_free);
599} 589}
600 590
601static int scsi_alloc_sgtable(struct scsi_data_buffer *sdb, int nents, 591static int scsi_alloc_sgtable(struct scsi_data_buffer *sdb, int nents, bool mq)
602 gfp_t gfp_mask, bool mq)
603{ 592{
604 struct scatterlist *first_chunk = NULL; 593 struct scatterlist *first_chunk = NULL;
594 gfp_t gfp_mask = mq ? GFP_NOIO : GFP_ATOMIC;
605 int ret; 595 int ret;
606 596
607 BUG_ON(!nents); 597 BUG_ON(!nents);
@@ -730,8 +720,6 @@ static bool scsi_end_request(struct request *req, int error,
730 kblockd_schedule_work(&sdev->requeue_work); 720 kblockd_schedule_work(&sdev->requeue_work);
731 else 721 else
732 blk_mq_start_stopped_hw_queues(q, true); 722 blk_mq_start_stopped_hw_queues(q, true);
733
734 put_device(&sdev->sdev_gendev);
735 } else { 723 } else {
736 unsigned long flags; 724 unsigned long flags;
737 725
@@ -743,9 +731,12 @@ static bool scsi_end_request(struct request *req, int error,
743 spin_unlock_irqrestore(q->queue_lock, flags); 731 spin_unlock_irqrestore(q->queue_lock, flags);
744 732
745 scsi_release_buffers(cmd); 733 scsi_release_buffers(cmd);
746 scsi_next_command(cmd); 734
735 scsi_put_command(cmd);
736 scsi_run_queue(q);
747 } 737 }
748 738
739 put_device(&sdev->sdev_gendev);
749 return false; 740 return false;
750} 741}
751 742
@@ -831,8 +822,8 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
831 struct request *req = cmd->request; 822 struct request *req = cmd->request;
832 int error = 0; 823 int error = 0;
833 struct scsi_sense_hdr sshdr; 824 struct scsi_sense_hdr sshdr;
834 int sense_valid = 0; 825 bool sense_valid = false;
835 int sense_deferred = 0; 826 int sense_deferred = 0, level = 0;
836 enum {ACTION_FAIL, ACTION_REPREP, ACTION_RETRY, 827 enum {ACTION_FAIL, ACTION_REPREP, ACTION_RETRY,
837 ACTION_DELAYED_RETRY} action; 828 ACTION_DELAYED_RETRY} action;
838 unsigned long wait_for = (cmd->allowed + 1) * req->timeout; 829 unsigned long wait_for = (cmd->allowed + 1) * req->timeout;
@@ -912,7 +903,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
912 if ((sshdr.asc == 0x0) && (sshdr.ascq == 0x1d)) 903 if ((sshdr.asc == 0x0) && (sshdr.ascq == 0x1d))
913 ; 904 ;
914 else if (!(req->cmd_flags & REQ_QUIET)) 905 else if (!(req->cmd_flags & REQ_QUIET))
915 scsi_print_sense("", cmd); 906 scsi_print_sense(cmd);
916 result = 0; 907 result = 0;
917 /* BLOCK_PC may have set error */ 908 /* BLOCK_PC may have set error */
918 error = 0; 909 error = 0;
@@ -1039,10 +1030,24 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
1039 case ACTION_FAIL: 1030 case ACTION_FAIL:
1040 /* Give up and fail the remainder of the request */ 1031 /* Give up and fail the remainder of the request */
1041 if (!(req->cmd_flags & REQ_QUIET)) { 1032 if (!(req->cmd_flags & REQ_QUIET)) {
1042 scsi_print_result(cmd); 1033 static DEFINE_RATELIMIT_STATE(_rs,
1043 if (driver_byte(result) & DRIVER_SENSE) 1034 DEFAULT_RATELIMIT_INTERVAL,
1044 scsi_print_sense("", cmd); 1035 DEFAULT_RATELIMIT_BURST);
1045 scsi_print_command(cmd); 1036
1037 if (unlikely(scsi_logging_level))
1038 level = SCSI_LOG_LEVEL(SCSI_LOG_MLCOMPLETE_SHIFT,
1039 SCSI_LOG_MLCOMPLETE_BITS);
1040
1041 /*
1042 * if logging is enabled the failure will be printed
1043 * in scsi_log_completion(), so avoid duplicate messages
1044 */
1045 if (!level && __ratelimit(&_rs)) {
1046 scsi_print_result(cmd, NULL, FAILED);
1047 if (driver_byte(result) & DRIVER_SENSE)
1048 scsi_print_sense(cmd);
1049 scsi_print_command(cmd);
1050 }
1046 } 1051 }
1047 if (!scsi_end_request(req, error, blk_rq_err_bytes(req), 0)) 1052 if (!scsi_end_request(req, error, blk_rq_err_bytes(req), 0))
1048 return; 1053 return;
@@ -1072,8 +1077,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
1072 } 1077 }
1073} 1078}
1074 1079
1075static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb, 1080static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb)
1076 gfp_t gfp_mask)
1077{ 1081{
1078 int count; 1082 int count;
1079 1083
@@ -1081,7 +1085,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
1081 * If sg table allocation fails, requeue request later. 1085 * If sg table allocation fails, requeue request later.
1082 */ 1086 */
1083 if (unlikely(scsi_alloc_sgtable(sdb, req->nr_phys_segments, 1087 if (unlikely(scsi_alloc_sgtable(sdb, req->nr_phys_segments,
1084 gfp_mask, req->mq_ctx != NULL))) 1088 req->mq_ctx != NULL)))
1085 return BLKPREP_DEFER; 1089 return BLKPREP_DEFER;
1086 1090
1087 /* 1091 /*
@@ -1106,7 +1110,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
1106 * BLKPREP_DEFER if the failure is retryable 1110 * BLKPREP_DEFER if the failure is retryable
1107 * BLKPREP_KILL if the failure is fatal 1111 * BLKPREP_KILL if the failure is fatal
1108 */ 1112 */
1109int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask) 1113int scsi_init_io(struct scsi_cmnd *cmd)
1110{ 1114{
1111 struct scsi_device *sdev = cmd->device; 1115 struct scsi_device *sdev = cmd->device;
1112 struct request *rq = cmd->request; 1116 struct request *rq = cmd->request;
@@ -1115,7 +1119,7 @@ int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
1115 1119
1116 BUG_ON(!rq->nr_phys_segments); 1120 BUG_ON(!rq->nr_phys_segments);
1117 1121
1118 error = scsi_init_sgtable(rq, &cmd->sdb, gfp_mask); 1122 error = scsi_init_sgtable(rq, &cmd->sdb);
1119 if (error) 1123 if (error)
1120 goto err_exit; 1124 goto err_exit;
1121 1125
@@ -1131,8 +1135,7 @@ int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
1131 rq->next_rq->special = bidi_sdb; 1135 rq->next_rq->special = bidi_sdb;
1132 } 1136 }
1133 1137
1134 error = scsi_init_sgtable(rq->next_rq, rq->next_rq->special, 1138 error = scsi_init_sgtable(rq->next_rq, rq->next_rq->special);
1135 GFP_ATOMIC);
1136 if (error) 1139 if (error)
1137 goto err_exit; 1140 goto err_exit;
1138 } 1141 }
@@ -1144,7 +1147,7 @@ int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask)
1144 BUG_ON(prot_sdb == NULL); 1147 BUG_ON(prot_sdb == NULL);
1145 ivecs = blk_rq_count_integrity_sg(rq->q, rq->bio); 1148 ivecs = blk_rq_count_integrity_sg(rq->q, rq->bio);
1146 1149
1147 if (scsi_alloc_sgtable(prot_sdb, ivecs, gfp_mask, is_mq)) { 1150 if (scsi_alloc_sgtable(prot_sdb, ivecs, is_mq)) {
1148 error = BLKPREP_DEFER; 1151 error = BLKPREP_DEFER;
1149 goto err_exit; 1152 goto err_exit;
1150 } 1153 }
@@ -1213,7 +1216,7 @@ static int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
1213 * submit a request without an attached bio. 1216 * submit a request without an attached bio.
1214 */ 1217 */
1215 if (req->bio) { 1218 if (req->bio) {
1216 int ret = scsi_init_io(cmd, GFP_ATOMIC); 1219 int ret = scsi_init_io(cmd);
1217 if (unlikely(ret)) 1220 if (unlikely(ret))
1218 return ret; 1221 return ret;
1219 } else { 1222 } else {
@@ -1638,6 +1641,87 @@ static void scsi_softirq_done(struct request *rq)
1638} 1641}
1639 1642
1640/** 1643/**
1644 * scsi_dispatch_command - Dispatch a command to the low-level driver.
1645 * @cmd: command block we are dispatching.
1646 *
1647 * Return: nonzero return request was rejected and device's queue needs to be
1648 * plugged.
1649 */
1650static int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
1651{
1652 struct Scsi_Host *host = cmd->device->host;
1653 int rtn = 0;
1654
1655 atomic_inc(&cmd->device->iorequest_cnt);
1656
1657 /* check if the device is still usable */
1658 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
1659 /* in SDEV_DEL we error all commands. DID_NO_CONNECT
1660 * returns an immediate error upwards, and signals
1661 * that the device is no longer present */
1662 cmd->result = DID_NO_CONNECT << 16;
1663 goto done;
1664 }
1665
1666 /* Check to see if the scsi lld made this device blocked. */
1667 if (unlikely(scsi_device_blocked(cmd->device))) {
1668 /*
1669 * in blocked state, the command is just put back on
1670 * the device queue. The suspend state has already
1671 * blocked the queue so future requests should not
1672 * occur until the device transitions out of the
1673 * suspend state.
1674 */
1675 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
1676 "queuecommand : device blocked\n"));
1677 return SCSI_MLQUEUE_DEVICE_BUSY;
1678 }
1679
1680 /* Store the LUN value in cmnd, if needed. */
1681 if (cmd->device->lun_in_cdb)
1682 cmd->cmnd[1] = (cmd->cmnd[1] & 0x1f) |
1683 (cmd->device->lun << 5 & 0xe0);
1684
1685 scsi_log_send(cmd);
1686
1687 /*
1688 * Before we queue this command, check if the command
1689 * length exceeds what the host adapter can handle.
1690 */
1691 if (cmd->cmd_len > cmd->device->host->max_cmd_len) {
1692 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
1693 "queuecommand : command too long. "
1694 "cdb_size=%d host->max_cmd_len=%d\n",
1695 cmd->cmd_len, cmd->device->host->max_cmd_len));
1696 cmd->result = (DID_ABORT << 16);
1697 goto done;
1698 }
1699
1700 if (unlikely(host->shost_state == SHOST_DEL)) {
1701 cmd->result = (DID_NO_CONNECT << 16);
1702 goto done;
1703
1704 }
1705
1706 trace_scsi_dispatch_cmd_start(cmd);
1707 rtn = host->hostt->queuecommand(host, cmd);
1708 if (rtn) {
1709 trace_scsi_dispatch_cmd_error(cmd, rtn);
1710 if (rtn != SCSI_MLQUEUE_DEVICE_BUSY &&
1711 rtn != SCSI_MLQUEUE_TARGET_BUSY)
1712 rtn = SCSI_MLQUEUE_HOST_BUSY;
1713
1714 SCSI_LOG_MLQUEUE(3, scmd_printk(KERN_INFO, cmd,
1715 "queuecommand : request rejected\n"));
1716 }
1717
1718 return rtn;
1719 done:
1720 cmd->scsi_done(cmd);
1721 return 0;
1722}
1723
1724/**
1641 * scsi_done - Invoke completion on finished SCSI command. 1725 * scsi_done - Invoke completion on finished SCSI command.
1642 * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives 1726 * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives
1643 * ownership back to SCSI Core -- i.e. the LLDD has finished with it. 1727 * ownership back to SCSI Core -- i.e. the LLDD has finished with it.
@@ -1725,7 +1809,7 @@ static void scsi_request_fn(struct request_queue *q)
1725 * we add the dev to the starved list so it eventually gets 1809 * we add the dev to the starved list so it eventually gets
1726 * a run when a tag is freed. 1810 * a run when a tag is freed.
1727 */ 1811 */
1728 if (blk_queue_tagged(q) && !blk_rq_tagged(req)) { 1812 if (blk_queue_tagged(q) && !(req->cmd_flags & REQ_QUEUED)) {
1729 spin_lock_irq(shost->host_lock); 1813 spin_lock_irq(shost->host_lock);
1730 if (list_empty(&sdev->starved_entry)) 1814 if (list_empty(&sdev->starved_entry))
1731 list_add_tail(&sdev->starved_entry, 1815 list_add_tail(&sdev->starved_entry,
@@ -1739,6 +1823,11 @@ static void scsi_request_fn(struct request_queue *q)
1739 1823
1740 if (!scsi_host_queue_ready(q, shost, sdev)) 1824 if (!scsi_host_queue_ready(q, shost, sdev))
1741 goto host_not_ready; 1825 goto host_not_ready;
1826
1827 if (sdev->simple_tags)
1828 cmd->flags |= SCMD_TAGGED;
1829 else
1830 cmd->flags &= ~SCMD_TAGGED;
1742 1831
1743 /* 1832 /*
1744 * Finally, initialize any error handling parameters, and set up 1833 * Finally, initialize any error handling parameters, and set up
@@ -1893,10 +1982,10 @@ static int scsi_queue_rq(struct blk_mq_hw_ctx *hctx, struct request *req,
1893 blk_mq_start_request(req); 1982 blk_mq_start_request(req);
1894 } 1983 }
1895 1984
1896 if (blk_queue_tagged(q)) 1985 if (sdev->simple_tags)
1897 req->cmd_flags |= REQ_QUEUED; 1986 cmd->flags |= SCMD_TAGGED;
1898 else 1987 else
1899 req->cmd_flags &= ~REQ_QUEUED; 1988 cmd->flags &= ~SCMD_TAGGED;
1900 1989
1901 scsi_init_cmd_errh(cmd); 1990 scsi_init_cmd_errh(cmd);
1902 cmd->scsi_done = scsi_mq_done; 1991 cmd->scsi_done = scsi_mq_done;
@@ -2091,7 +2180,7 @@ int scsi_mq_setup_tags(struct Scsi_Host *shost)
2091 2180
2092 memset(&shost->tag_set, 0, sizeof(shost->tag_set)); 2181 memset(&shost->tag_set, 0, sizeof(shost->tag_set));
2093 shost->tag_set.ops = &scsi_mq_ops; 2182 shost->tag_set.ops = &scsi_mq_ops;
2094 shost->tag_set.nr_hw_queues = 1; 2183 shost->tag_set.nr_hw_queues = shost->nr_hw_queues ? : 1;
2095 shost->tag_set.queue_depth = shost->can_queue; 2184 shost->tag_set.queue_depth = shost->can_queue;
2096 shost->tag_set.cmd_size = cmd_size; 2185 shost->tag_set.cmd_size = cmd_size;
2097 shost->tag_set.numa_node = NUMA_NO_NODE; 2186 shost->tag_set.numa_node = NUMA_NO_NODE;
diff --git a/drivers/scsi/scsi_logging.h b/drivers/scsi/scsi_logging.h
index 1f65139e14f8..7fe64a847143 100644
--- a/drivers/scsi/scsi_logging.h
+++ b/drivers/scsi/scsi_logging.h
@@ -51,6 +51,7 @@ do { \
51 } while (0); \ 51 } while (0); \
52} while (0) 52} while (0)
53#else 53#else
54#define SCSI_LOG_LEVEL(SHIFT, BITS) 0
54#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) 55#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
55#endif /* CONFIG_SCSI_LOGGING */ 56#endif /* CONFIG_SCSI_LOGGING */
56 57
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index 12b8e1bee7f0..2dc4a83fb84c 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -29,7 +29,6 @@ extern int scsi_init_hosts(void);
29extern void scsi_exit_hosts(void); 29extern void scsi_exit_hosts(void);
30 30
31/* scsi.c */ 31/* scsi.c */
32extern int scsi_dispatch_cmd(struct scsi_cmnd *cmd);
33extern int scsi_setup_command_freelist(struct Scsi_Host *shost); 32extern int scsi_setup_command_freelist(struct Scsi_Host *shost);
34extern void scsi_destroy_command_freelist(struct Scsi_Host *shost); 33extern void scsi_destroy_command_freelist(struct Scsi_Host *shost);
35#ifdef CONFIG_SCSI_LOGGING 34#ifdef CONFIG_SCSI_LOGGING
@@ -84,7 +83,6 @@ int scsi_noretry_cmd(struct scsi_cmnd *scmd);
84extern int scsi_maybe_unblock_host(struct scsi_device *sdev); 83extern int scsi_maybe_unblock_host(struct scsi_device *sdev);
85extern void scsi_device_unbusy(struct scsi_device *sdev); 84extern void scsi_device_unbusy(struct scsi_device *sdev);
86extern void scsi_queue_insert(struct scsi_cmnd *cmd, int reason); 85extern void scsi_queue_insert(struct scsi_cmnd *cmd, int reason);
87extern void scsi_next_command(struct scsi_cmnd *cmd);
88extern void scsi_io_completion(struct scsi_cmnd *, unsigned int); 86extern void scsi_io_completion(struct scsi_cmnd *, unsigned int);
89extern void scsi_run_host_queues(struct Scsi_Host *shost); 87extern void scsi_run_host_queues(struct Scsi_Host *shost);
90extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev); 88extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev);
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index ba3f1e8d0d57..983aed10ff2f 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -286,7 +286,13 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget,
286 } 286 }
287 WARN_ON_ONCE(!blk_get_queue(sdev->request_queue)); 287 WARN_ON_ONCE(!blk_get_queue(sdev->request_queue));
288 sdev->request_queue->queuedata = sdev; 288 sdev->request_queue->queuedata = sdev;
289 scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun); 289
290 if (!shost_use_blk_mq(sdev->host) &&
291 (shost->bqt || shost->hostt->use_blk_tags)) {
292 blk_queue_init_tags(sdev->request_queue,
293 sdev->host->cmd_per_lun, shost->bqt);
294 }
295 scsi_change_queue_depth(sdev, sdev->host->cmd_per_lun);
290 296
291 scsi_sysfs_device_initialize(sdev); 297 scsi_sysfs_device_initialize(sdev);
292 298
@@ -874,8 +880,10 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned char *inq_result,
874 (inq_result[3] & 0x0f) == 1 ? " CCS" : ""); 880 (inq_result[3] & 0x0f) == 1 ? " CCS" : "");
875 881
876 if ((sdev->scsi_level >= SCSI_2) && (inq_result[7] & 2) && 882 if ((sdev->scsi_level >= SCSI_2) && (inq_result[7] & 2) &&
877 !(*bflags & BLIST_NOTQ)) 883 !(*bflags & BLIST_NOTQ)) {
878 sdev->tagged_supported = 1; 884 sdev->tagged_supported = 1;
885 sdev->simple_tags = 1;
886 }
879 887
880 /* 888 /*
881 * Some devices (Texel CD ROM drives) have handshaking problems 889 * Some devices (Texel CD ROM drives) have handshaking problems
@@ -1214,9 +1222,9 @@ static void scsi_sequential_lun_scan(struct scsi_target *starget,
1214 sparse_lun = 0; 1222 sparse_lun = 0;
1215 1223
1216 /* 1224 /*
1217 * If less than SCSI_1_CSS, and no special lun scaning, stop 1225 * If less than SCSI_1_CCS, and no special lun scanning, stop
1218 * scanning; this matches 2.4 behaviour, but could just be a bug 1226 * scanning; this matches 2.4 behaviour, but could just be a bug
1219 * (to continue scanning a SCSI_1_CSS device). 1227 * (to continue scanning a SCSI_1_CCS device).
1220 * 1228 *
1221 * This test is broken. We might not have any device on lun0 for 1229 * This test is broken. We might not have any device on lun0 for
1222 * a sparselun device, and if that's the case then how would we 1230 * a sparselun device, and if that's the case then how would we
@@ -1585,16 +1593,15 @@ EXPORT_SYMBOL(scsi_add_device);
1585 1593
1586void scsi_rescan_device(struct device *dev) 1594void scsi_rescan_device(struct device *dev)
1587{ 1595{
1588 struct scsi_driver *drv;
1589
1590 if (!dev->driver) 1596 if (!dev->driver)
1591 return; 1597 return;
1592 1598
1593 drv = to_scsi_driver(dev->driver); 1599 if (try_module_get(dev->driver->owner)) {
1594 if (try_module_get(drv->owner)) { 1600 struct scsi_driver *drv = to_scsi_driver(dev->driver);
1601
1595 if (drv->rescan) 1602 if (drv->rescan)
1596 drv->rescan(dev); 1603 drv->rescan(dev);
1597 module_put(drv->owner); 1604 module_put(dev->driver->owner);
1598 } 1605 }
1599} 1606}
1600EXPORT_SYMBOL(scsi_rescan_device); 1607EXPORT_SYMBOL(scsi_rescan_device);
@@ -1727,7 +1734,7 @@ int scsi_scan_host_selected(struct Scsi_Host *shost, unsigned int channel,
1727 1734
1728 if (((channel != SCAN_WILD_CARD) && (channel > shost->max_channel)) || 1735 if (((channel != SCAN_WILD_CARD) && (channel > shost->max_channel)) ||
1729 ((id != SCAN_WILD_CARD) && (id >= shost->max_id)) || 1736 ((id != SCAN_WILD_CARD) && (id >= shost->max_id)) ||
1730 ((lun != SCAN_WILD_CARD) && (lun > shost->max_lun))) 1737 ((lun != SCAN_WILD_CARD) && (lun >= shost->max_lun)))
1731 return -EINVAL; 1738 return -EINVAL;
1732 1739
1733 mutex_lock(&shost->scan_mutex); 1740 mutex_lock(&shost->scan_mutex);
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index f4cb7b3e9e23..1cb64a8e18c9 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -727,9 +727,7 @@ show_queue_type_field(struct device *dev, struct device_attribute *attr,
727 struct scsi_device *sdev = to_scsi_device(dev); 727 struct scsi_device *sdev = to_scsi_device(dev);
728 const char *name = "none"; 728 const char *name = "none";
729 729
730 if (sdev->ordered_tags) 730 if (sdev->simple_tags)
731 name = "ordered";
732 else if (sdev->simple_tags)
733 name = "simple"; 731 name = "simple";
734 732
735 return snprintf(buf, 20, "%s\n", name); 733 return snprintf(buf, 20, "%s\n", name);
@@ -747,9 +745,12 @@ store_queue_type_field(struct device *dev, struct device_attribute *attr,
747 if (!sdev->tagged_supported || !sht->change_queue_type) 745 if (!sdev->tagged_supported || !sht->change_queue_type)
748 return -EINVAL; 746 return -EINVAL;
749 747
750 if (strncmp(buf, "ordered", 7) == 0) 748 /*
751 tag_type = MSG_ORDERED_TAG; 749 * We're never issueing order tags these days, but allow the value
752 else if (strncmp(buf, "simple", 6) == 0) 750 * for backwards compatibility.
751 */
752 if (strncmp(buf, "ordered", 7) == 0 ||
753 strncmp(buf, "simple", 6) == 0)
753 tag_type = MSG_SIMPLE_TAG; 754 tag_type = MSG_SIMPLE_TAG;
754 else if (strncmp(buf, "none", 4) != 0) 755 else if (strncmp(buf, "none", 4) != 0)
755 return -EINVAL; 756 return -EINVAL;
@@ -876,11 +877,10 @@ sdev_store_queue_depth(struct device *dev, struct device_attribute *attr,
876 877
877 depth = simple_strtoul(buf, NULL, 0); 878 depth = simple_strtoul(buf, NULL, 0);
878 879
879 if (depth < 1) 880 if (depth < 1 || depth > sht->can_queue)
880 return -EINVAL; 881 return -EINVAL;
881 882
882 retval = sht->change_queue_depth(sdev, depth, 883 retval = sht->change_queue_depth(sdev, depth);
883 SCSI_QDEPTH_DEFAULT);
884 if (retval < 0) 884 if (retval < 0)
885 return retval; 885 return retval;
886 886
diff --git a/drivers/scsi/scsi_trace.c b/drivers/scsi/scsi_trace.c
index 503594e5f76d..82af28b90294 100644
--- a/drivers/scsi/scsi_trace.c
+++ b/drivers/scsi/scsi_trace.c
@@ -278,7 +278,7 @@ scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
278 return scsi_trace_rw16(p, cdb, len); 278 return scsi_trace_rw16(p, cdb, len);
279 case UNMAP: 279 case UNMAP:
280 return scsi_trace_unmap(p, cdb, len); 280 return scsi_trace_unmap(p, cdb, len);
281 case SERVICE_ACTION_IN: 281 case SERVICE_ACTION_IN_16:
282 return scsi_trace_service_action_in(p, cdb, len); 282 return scsi_trace_service_action_in(p, cdb, len);
283 case VARIABLE_LENGTH_CMD: 283 case VARIABLE_LENGTH_CMD:
284 return scsi_trace_varlen(p, cdb, len); 284 return scsi_trace_varlen(p, cdb, len);
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index cf08071a9b6e..fa2aece76cc2 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -32,6 +32,7 @@
32#include <scsi/scsi_host.h> 32#include <scsi/scsi_host.h>
33#include <scsi/scsi_cmnd.h> 33#include <scsi/scsi_cmnd.h>
34#include <scsi/scsi_eh.h> 34#include <scsi/scsi_eh.h>
35#include <scsi/scsi_tcq.h>
35#include <scsi/scsi_transport.h> 36#include <scsi/scsi_transport.h>
36#include <scsi/scsi_transport_spi.h> 37#include <scsi/scsi_transport_spi.h>
37 38
@@ -1207,6 +1208,28 @@ int spi_populate_ppr_msg(unsigned char *msg, int period, int offset,
1207} 1208}
1208EXPORT_SYMBOL_GPL(spi_populate_ppr_msg); 1209EXPORT_SYMBOL_GPL(spi_populate_ppr_msg);
1209 1210
1211/**
1212 * spi_populate_tag_msg - place a tag message in a buffer
1213 * @msg: pointer to the area to place the tag
1214 * @cmd: pointer to the scsi command for the tag
1215 *
1216 * Notes:
1217 * designed to create the correct type of tag message for the
1218 * particular request. Returns the size of the tag message.
1219 * May return 0 if TCQ is disabled for this device.
1220 **/
1221int spi_populate_tag_msg(unsigned char *msg, struct scsi_cmnd *cmd)
1222{
1223 if (cmd->flags & SCMD_TAGGED) {
1224 *msg++ = MSG_SIMPLE_TAG;
1225 *msg++ = cmd->request->tag;
1226 return 2;
1227 }
1228
1229 return 0;
1230}
1231EXPORT_SYMBOL_GPL(spi_populate_tag_msg);
1232
1210#ifdef CONFIG_SCSI_CONSTANTS 1233#ifdef CONFIG_SCSI_CONSTANTS
1211static const char * const one_byte_msgs[] = { 1234static const char * const one_byte_msgs[] = {
1212/* 0x00 */ "Task Complete", NULL /* Extended Message */, "Save Pointers", 1235/* 0x00 */ "Task Complete", NULL /* Extended Message */, "Save Pointers",
diff --git a/drivers/scsi/scsicam.c b/drivers/scsi/scsicam.c
index 92d24d6dcb39..910f4a7a3924 100644
--- a/drivers/scsi/scsicam.c
+++ b/drivers/scsi/scsicam.c
@@ -163,8 +163,8 @@ int scsi_partsize(unsigned char *buf, unsigned long capacity,
163 end_head * end_sector + end_sector; 163 end_head * end_sector + end_sector;
164 164
165 /* This is the actual _sector_ number at the end */ 165 /* This is the actual _sector_ number at the end */
166 logical_end = get_unaligned(&largest->start_sect) 166 logical_end = get_unaligned_le32(&largest->start_sect)
167 + get_unaligned(&largest->nr_sects); 167 + get_unaligned_le32(&largest->nr_sects);
168 168
169 /* This is for >1023 cylinders */ 169 /* This is for >1023 cylinders */
170 ext_cyl = (logical_end - (end_head * end_sector + end_sector)) 170 ext_cyl = (logical_end - (end_head * end_sector + end_sector))
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index cfba74cd8e8b..fedab3c21ddf 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -116,7 +116,7 @@ static int sd_eh_action(struct scsi_cmnd *, int);
116static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer); 116static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer);
117static void scsi_disk_release(struct device *cdev); 117static void scsi_disk_release(struct device *cdev);
118static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *); 118static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *);
119static void sd_print_result(struct scsi_disk *, int); 119static void sd_print_result(const struct scsi_disk *, const char *, int);
120 120
121static DEFINE_SPINLOCK(sd_index_lock); 121static DEFINE_SPINLOCK(sd_index_lock);
122static DEFINE_IDA(sd_index_ida); 122static DEFINE_IDA(sd_index_ida);
@@ -510,9 +510,9 @@ static const struct dev_pm_ops sd_pm_ops = {
510}; 510};
511 511
512static struct scsi_driver sd_template = { 512static struct scsi_driver sd_template = {
513 .owner = THIS_MODULE,
514 .gendrv = { 513 .gendrv = {
515 .name = "sd", 514 .name = "sd",
515 .owner = THIS_MODULE,
516 .probe = sd_probe, 516 .probe = sd_probe,
517 .remove = sd_remove, 517 .remove = sd_remove,
518 .shutdown = sd_shutdown, 518 .shutdown = sd_shutdown,
@@ -656,7 +656,7 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
656 unsigned int logical_block_size = sdkp->device->sector_size; 656 unsigned int logical_block_size = sdkp->device->sector_size;
657 unsigned int max_blocks = 0; 657 unsigned int max_blocks = 0;
658 658
659 q->limits.discard_zeroes_data = sdkp->lbprz; 659 q->limits.discard_zeroes_data = 0;
660 q->limits.discard_alignment = sdkp->unmap_alignment * 660 q->limits.discard_alignment = sdkp->unmap_alignment *
661 logical_block_size; 661 logical_block_size;
662 q->limits.discard_granularity = 662 q->limits.discard_granularity =
@@ -680,11 +680,13 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
680 case SD_LBP_WS16: 680 case SD_LBP_WS16:
681 max_blocks = min_not_zero(sdkp->max_ws_blocks, 681 max_blocks = min_not_zero(sdkp->max_ws_blocks,
682 (u32)SD_MAX_WS16_BLOCKS); 682 (u32)SD_MAX_WS16_BLOCKS);
683 q->limits.discard_zeroes_data = sdkp->lbprz;
683 break; 684 break;
684 685
685 case SD_LBP_WS10: 686 case SD_LBP_WS10:
686 max_blocks = min_not_zero(sdkp->max_ws_blocks, 687 max_blocks = min_not_zero(sdkp->max_ws_blocks,
687 (u32)SD_MAX_WS10_BLOCKS); 688 (u32)SD_MAX_WS10_BLOCKS);
689 q->limits.discard_zeroes_data = sdkp->lbprz;
688 break; 690 break;
689 691
690 case SD_LBP_ZERO: 692 case SD_LBP_ZERO:
@@ -784,7 +786,7 @@ static int sd_setup_discard_cmnd(struct scsi_cmnd *cmd)
784 * amount of blocks described by the request. 786 * amount of blocks described by the request.
785 */ 787 */
786 blk_add_request_payload(rq, page, len); 788 blk_add_request_payload(rq, page, len);
787 ret = scsi_init_io(cmd, GFP_ATOMIC); 789 ret = scsi_init_io(cmd);
788 rq->__data_len = nr_bytes; 790 rq->__data_len = nr_bytes;
789 791
790out: 792out:
@@ -878,7 +880,7 @@ static int sd_setup_write_same_cmnd(struct scsi_cmnd *cmd)
878 * knows how much to actually write. 880 * knows how much to actually write.
879 */ 881 */
880 rq->__data_len = sdp->sector_size; 882 rq->__data_len = sdp->sector_size;
881 ret = scsi_init_io(cmd, GFP_ATOMIC); 883 ret = scsi_init_io(cmd);
882 rq->__data_len = nr_bytes; 884 rq->__data_len = nr_bytes;
883 return ret; 885 return ret;
884} 886}
@@ -912,7 +914,7 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt)
912 int ret; 914 int ret;
913 unsigned char protect; 915 unsigned char protect;
914 916
915 ret = scsi_init_io(SCpnt, GFP_ATOMIC); 917 ret = scsi_init_io(SCpnt);
916 if (ret != BLKPREP_OK) 918 if (ret != BLKPREP_OK)
917 goto out; 919 goto out;
918 SCpnt = rq->special; 920 SCpnt = rq->special;
@@ -1334,9 +1336,9 @@ static int sd_ioctl(struct block_device *bdev, fmode_t mode,
1334 * may try and take the device offline, in which case all further 1336 * may try and take the device offline, in which case all further
1335 * access to the device is prohibited. 1337 * access to the device is prohibited.
1336 */ 1338 */
1337 error = scsi_nonblockable_ioctl(sdp, cmd, p, 1339 error = scsi_ioctl_block_when_processing_errors(sdp, cmd,
1338 (mode & FMODE_NDELAY) != 0); 1340 (mode & FMODE_NDELAY) != 0);
1339 if (!scsi_block_when_processing_errors(sdp) || !error) 1341 if (error)
1340 goto out; 1342 goto out;
1341 1343
1342 /* 1344 /*
@@ -1492,7 +1494,7 @@ static int sd_sync_cache(struct scsi_disk *sdkp)
1492 } 1494 }
1493 1495
1494 if (res) { 1496 if (res) {
1495 sd_print_result(sdkp, res); 1497 sd_print_result(sdkp, "Synchronize Cache(10) failed", res);
1496 1498
1497 if (driver_byte(res) & DRIVER_SENSE) 1499 if (driver_byte(res) & DRIVER_SENSE)
1498 sd_print_sense_hdr(sdkp, &sshdr); 1500 sd_print_sense_hdr(sdkp, &sshdr);
@@ -1541,31 +1543,19 @@ static int sd_compat_ioctl(struct block_device *bdev, fmode_t mode,
1541 unsigned int cmd, unsigned long arg) 1543 unsigned int cmd, unsigned long arg)
1542{ 1544{
1543 struct scsi_device *sdev = scsi_disk(bdev->bd_disk)->device; 1545 struct scsi_device *sdev = scsi_disk(bdev->bd_disk)->device;
1544 int ret; 1546 int error;
1545
1546 ret = scsi_verify_blk_ioctl(bdev, cmd);
1547 if (ret < 0)
1548 return ret;
1549 1547
1550 /* 1548 error = scsi_ioctl_block_when_processing_errors(sdev, cmd,
1551 * If we are in the middle of error recovery, don't let anyone 1549 (mode & FMODE_NDELAY) != 0);
1552 * else try and use this device. Also, if error recovery fails, it 1550 if (error)
1553 * may try and take the device offline, in which case all further 1551 return error;
1554 * access to the device is prohibited.
1555 */
1556 if (!scsi_block_when_processing_errors(sdev))
1557 return -ENODEV;
1558 1552
1559 if (sdev->host->hostt->compat_ioctl) {
1560 ret = sdev->host->hostt->compat_ioctl(sdev, cmd, (void __user *)arg);
1561
1562 return ret;
1563 }
1564
1565 /* 1553 /*
1566 * Let the static ioctl translation table take care of it. 1554 * Let the static ioctl translation table take care of it.
1567 */ 1555 */
1568 return -ENOIOCTLCMD; 1556 if (!sdev->host->hostt->compat_ioctl)
1557 return -ENOIOCTLCMD;
1558 return sdev->host->hostt->compat_ioctl(sdev, cmd, (void __user *)arg);
1569} 1559}
1570#endif 1560#endif
1571 1561
@@ -1713,17 +1703,6 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1713 if (sense_valid) 1703 if (sense_valid)
1714 sense_deferred = scsi_sense_is_deferred(&sshdr); 1704 sense_deferred = scsi_sense_is_deferred(&sshdr);
1715 } 1705 }
1716#ifdef CONFIG_SCSI_LOGGING
1717 SCSI_LOG_HLCOMPLETE(1, scsi_print_result(SCpnt));
1718 if (sense_valid) {
1719 SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt,
1720 "sd_done: sb[respc,sk,asc,"
1721 "ascq]=%x,%x,%x,%x\n",
1722 sshdr.response_code,
1723 sshdr.sense_key, sshdr.asc,
1724 sshdr.ascq));
1725 }
1726#endif
1727 sdkp->medium_access_timed_out = 0; 1706 sdkp->medium_access_timed_out = 0;
1728 1707
1729 if (driver_byte(result) != DRIVER_SENSE && 1708 if (driver_byte(result) != DRIVER_SENSE &&
@@ -1743,7 +1722,6 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1743 * unknown amount of data was transferred so treat it as an 1722 * unknown amount of data was transferred so treat it as an
1744 * error. 1723 * error.
1745 */ 1724 */
1746 scsi_print_sense("sd", SCpnt);
1747 SCpnt->result = 0; 1725 SCpnt->result = 0;
1748 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); 1726 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
1749 break; 1727 break;
@@ -1779,6 +1757,10 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1779 break; 1757 break;
1780 } 1758 }
1781 out: 1759 out:
1760 SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt,
1761 "sd_done: completed %d of %d bytes\n",
1762 good_bytes, scsi_bufflen(SCpnt)));
1763
1782 if (rq_data_dir(SCpnt->request) == READ && scsi_prot_sg_count(SCpnt)) 1764 if (rq_data_dir(SCpnt->request) == READ && scsi_prot_sg_count(SCpnt))
1783 sd_dif_complete(SCpnt, good_bytes); 1765 sd_dif_complete(SCpnt, good_bytes);
1784 1766
@@ -1834,12 +1816,12 @@ sd_spinup_disk(struct scsi_disk *sdkp)
1834 /* no sense, TUR either succeeded or failed 1816 /* no sense, TUR either succeeded or failed
1835 * with a status error */ 1817 * with a status error */
1836 if(!spintime && !scsi_status_is_good(the_result)) { 1818 if(!spintime && !scsi_status_is_good(the_result)) {
1837 sd_printk(KERN_NOTICE, sdkp, "Unit Not Ready\n"); 1819 sd_print_result(sdkp, "Test Unit Ready failed",
1838 sd_print_result(sdkp, the_result); 1820 the_result);
1839 } 1821 }
1840 break; 1822 break;
1841 } 1823 }
1842 1824
1843 /* 1825 /*
1844 * The device does not want the automatic start to be issued. 1826 * The device does not want the automatic start to be issued.
1845 */ 1827 */
@@ -1955,7 +1937,6 @@ static void read_capacity_error(struct scsi_disk *sdkp, struct scsi_device *sdp,
1955 struct scsi_sense_hdr *sshdr, int sense_valid, 1937 struct scsi_sense_hdr *sshdr, int sense_valid,
1956 int the_result) 1938 int the_result)
1957{ 1939{
1958 sd_print_result(sdkp, the_result);
1959 if (driver_byte(the_result) & DRIVER_SENSE) 1940 if (driver_byte(the_result) & DRIVER_SENSE)
1960 sd_print_sense_hdr(sdkp, sshdr); 1941 sd_print_sense_hdr(sdkp, sshdr);
1961 else 1942 else
@@ -2001,7 +1982,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
2001 1982
2002 do { 1983 do {
2003 memset(cmd, 0, 16); 1984 memset(cmd, 0, 16);
2004 cmd[0] = SERVICE_ACTION_IN; 1985 cmd[0] = SERVICE_ACTION_IN_16;
2005 cmd[1] = SAI_READ_CAPACITY_16; 1986 cmd[1] = SAI_READ_CAPACITY_16;
2006 cmd[13] = RC16_LEN; 1987 cmd[13] = RC16_LEN;
2007 memset(buffer, 0, RC16_LEN); 1988 memset(buffer, 0, RC16_LEN);
@@ -2036,7 +2017,7 @@ static int read_capacity_16(struct scsi_disk *sdkp, struct scsi_device *sdp,
2036 } while (the_result && retries); 2017 } while (the_result && retries);
2037 2018
2038 if (the_result) { 2019 if (the_result) {
2039 sd_printk(KERN_NOTICE, sdkp, "READ CAPACITY(16) failed\n"); 2020 sd_print_result(sdkp, "Read Capacity(16) failed", the_result);
2040 read_capacity_error(sdkp, sdp, &sshdr, sense_valid, the_result); 2021 read_capacity_error(sdkp, sdp, &sshdr, sense_valid, the_result);
2041 return -EINVAL; 2022 return -EINVAL;
2042 } 2023 }
@@ -2118,7 +2099,7 @@ static int read_capacity_10(struct scsi_disk *sdkp, struct scsi_device *sdp,
2118 } while (the_result && retries); 2099 } while (the_result && retries);
2119 2100
2120 if (the_result) { 2101 if (the_result) {
2121 sd_printk(KERN_NOTICE, sdkp, "READ CAPACITY failed\n"); 2102 sd_print_result(sdkp, "Read Capacity(10) failed", the_result);
2122 read_capacity_error(sdkp, sdp, &sshdr, sense_valid, the_result); 2103 read_capacity_error(sdkp, sdp, &sshdr, sense_valid, the_result);
2123 return -EINVAL; 2104 return -EINVAL;
2124 } 2105 }
@@ -2643,12 +2624,12 @@ static void sd_read_block_limits(struct scsi_disk *sdkp)
2643 2624
2644 } else { /* LBP VPD page tells us what to use */ 2625 } else { /* LBP VPD page tells us what to use */
2645 2626
2646 if (sdkp->lbpu && sdkp->max_unmap_blocks) 2627 if (sdkp->lbpws)
2647 sd_config_discard(sdkp, SD_LBP_UNMAP);
2648 else if (sdkp->lbpws)
2649 sd_config_discard(sdkp, SD_LBP_WS16); 2628 sd_config_discard(sdkp, SD_LBP_WS16);
2650 else if (sdkp->lbpws10) 2629 else if (sdkp->lbpws10)
2651 sd_config_discard(sdkp, SD_LBP_WS10); 2630 sd_config_discard(sdkp, SD_LBP_WS10);
2631 else if (sdkp->lbpu && sdkp->max_unmap_blocks)
2632 sd_config_discard(sdkp, SD_LBP_UNMAP);
2652 else 2633 else
2653 sd_config_discard(sdkp, SD_LBP_DISABLE); 2634 sd_config_discard(sdkp, SD_LBP_DISABLE);
2654 } 2635 }
@@ -3142,8 +3123,7 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
3142 res = scsi_execute_req_flags(sdp, cmd, DMA_NONE, NULL, 0, &sshdr, 3123 res = scsi_execute_req_flags(sdp, cmd, DMA_NONE, NULL, 0, &sshdr,
3143 SD_TIMEOUT, SD_MAX_RETRIES, NULL, REQ_PM); 3124 SD_TIMEOUT, SD_MAX_RETRIES, NULL, REQ_PM);
3144 if (res) { 3125 if (res) {
3145 sd_printk(KERN_WARNING, sdkp, "START_STOP FAILED\n"); 3126 sd_print_result(sdkp, "Start/Stop Unit failed", res);
3146 sd_print_result(sdkp, res);
3147 if (driver_byte(res) & DRIVER_SENSE) 3127 if (driver_byte(res) & DRIVER_SENSE)
3148 sd_print_sense_hdr(sdkp, &sshdr); 3128 sd_print_sense_hdr(sdkp, &sshdr);
3149 if (scsi_sense_valid(&sshdr) && 3129 if (scsi_sense_valid(&sshdr) &&
@@ -3337,15 +3317,27 @@ module_exit(exit_sd);
3337static void sd_print_sense_hdr(struct scsi_disk *sdkp, 3317static void sd_print_sense_hdr(struct scsi_disk *sdkp,
3338 struct scsi_sense_hdr *sshdr) 3318 struct scsi_sense_hdr *sshdr)
3339{ 3319{
3340 sd_printk(KERN_INFO, sdkp, " "); 3320 scsi_show_sense_hdr(sdkp->device,
3341 scsi_show_sense_hdr(sshdr); 3321 sdkp->disk ? sdkp->disk->disk_name : NULL, sshdr);
3342 sd_printk(KERN_INFO, sdkp, " "); 3322 scsi_show_extd_sense(sdkp->device,
3343 scsi_show_extd_sense(sshdr->asc, sshdr->ascq); 3323 sdkp->disk ? sdkp->disk->disk_name : NULL,
3324 sshdr->asc, sshdr->ascq);
3344} 3325}
3345 3326
3346static void sd_print_result(struct scsi_disk *sdkp, int result) 3327static void sd_print_result(const struct scsi_disk *sdkp, const char *msg,
3328 int result)
3347{ 3329{
3348 sd_printk(KERN_INFO, sdkp, " "); 3330 const char *hb_string = scsi_hostbyte_string(result);
3349 scsi_show_result(result); 3331 const char *db_string = scsi_driverbyte_string(result);
3332
3333 if (hb_string || db_string)
3334 sd_printk(KERN_INFO, sdkp,
3335 "%s: Result: hostbyte=%s driverbyte=%s\n", msg,
3336 hb_string ? hb_string : "invalid",
3337 db_string ? db_string : "invalid");
3338 else
3339 sd_printk(KERN_INFO, sdkp,
3340 "%s: Result: hostbyte=0x%02x driverbyte=0x%02x\n",
3341 msg, host_byte(result), driver_byte(result));
3350} 3342}
3351 3343
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index 467377884b63..63ba5ca7f9a1 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -103,9 +103,9 @@ static inline struct scsi_disk *scsi_disk(struct gendisk *disk)
103 103
104#define sd_printk(prefix, sdsk, fmt, a...) \ 104#define sd_printk(prefix, sdsk, fmt, a...) \
105 (sdsk)->disk ? \ 105 (sdsk)->disk ? \
106 sdev_printk(prefix, (sdsk)->device, "[%s] " fmt, \ 106 sdev_prefix_printk(prefix, (sdsk)->device, \
107 (sdsk)->disk->disk_name, ##a) : \ 107 (sdsk)->disk->disk_name, fmt, ##a) : \
108 sdev_printk(prefix, (sdsk)->device, fmt, ##a) 108 sdev_printk(prefix, (sdsk)->device, fmt, ##a)
109 109
110#define sd_first_printk(prefix, sdsk, fmt, a...) \ 110#define sd_first_printk(prefix, sdsk, fmt, a...) \
111 do { \ 111 do { \
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
index 80bfece1a2de..b7e79e7646ad 100644
--- a/drivers/scsi/ses.c
+++ b/drivers/scsi/ses.c
@@ -693,9 +693,9 @@ static struct class_interface ses_interface = {
693}; 693};
694 694
695static struct scsi_driver ses_template = { 695static struct scsi_driver ses_template = {
696 .owner = THIS_MODULE,
697 .gendrv = { 696 .gendrv = {
698 .name = "ses", 697 .name = "ses",
698 .owner = THIS_MODULE,
699 .probe = ses_probe, 699 .probe = ses_probe,
700 .remove = ses_remove, 700 .remove = ses_remove,
701 }, 701 },
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 60354449d9ed..b14f64cb9724 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -219,8 +219,8 @@ static void sg_device_destroy(struct kref *kref);
219#define SZ_SG_REQ_INFO sizeof(sg_req_info_t) 219#define SZ_SG_REQ_INFO sizeof(sg_req_info_t)
220 220
221#define sg_printk(prefix, sdp, fmt, a...) \ 221#define sg_printk(prefix, sdp, fmt, a...) \
222 sdev_printk(prefix, (sdp)->device, "[%s] " fmt, \ 222 sdev_prefix_printk(prefix, (sdp)->device, \
223 (sdp)->disk->disk_name, ##a) 223 (sdp)->disk->disk_name, fmt, ##a)
224 224
225static int sg_allow_access(struct file *filp, unsigned char *cmd) 225static int sg_allow_access(struct file *filp, unsigned char *cmd)
226{ 226{
@@ -1071,39 +1071,6 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
1071 if (atomic_read(&sdp->detaching)) 1071 if (atomic_read(&sdp->detaching))
1072 return -ENODEV; 1072 return -ENODEV;
1073 return put_user(sdp->device->host->hostt->emulated, ip); 1073 return put_user(sdp->device->host->hostt->emulated, ip);
1074 case SG_SCSI_RESET:
1075 if (atomic_read(&sdp->detaching))
1076 return -ENODEV;
1077 if (filp->f_flags & O_NONBLOCK) {
1078 if (scsi_host_in_recovery(sdp->device->host))
1079 return -EBUSY;
1080 } else if (!scsi_block_when_processing_errors(sdp->device))
1081 return -EBUSY;
1082 result = get_user(val, ip);
1083 if (result)
1084 return result;
1085 if (SG_SCSI_RESET_NOTHING == val)
1086 return 0;
1087 switch (val) {
1088 case SG_SCSI_RESET_DEVICE:
1089 val = SCSI_TRY_RESET_DEVICE;
1090 break;
1091 case SG_SCSI_RESET_TARGET:
1092 val = SCSI_TRY_RESET_TARGET;
1093 break;
1094 case SG_SCSI_RESET_BUS:
1095 val = SCSI_TRY_RESET_BUS;
1096 break;
1097 case SG_SCSI_RESET_HOST:
1098 val = SCSI_TRY_RESET_HOST;
1099 break;
1100 default:
1101 return -EINVAL;
1102 }
1103 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1104 return -EACCES;
1105 return (scsi_reset_provider(sdp->device, val) ==
1106 SUCCESS) ? 0 : -EIO;
1107 case SCSI_IOCTL_SEND_COMMAND: 1074 case SCSI_IOCTL_SEND_COMMAND:
1108 if (atomic_read(&sdp->detaching)) 1075 if (atomic_read(&sdp->detaching))
1109 return -ENODEV; 1076 return -ENODEV;
@@ -1123,13 +1090,6 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
1123 return result; 1090 return result;
1124 sdp->sgdebug = (char) val; 1091 sdp->sgdebug = (char) val;
1125 return 0; 1092 return 0;
1126 case SCSI_IOCTL_GET_IDLUN:
1127 case SCSI_IOCTL_GET_BUS_NUMBER:
1128 case SCSI_IOCTL_PROBE_HOST:
1129 case SG_GET_TRANSFORM:
1130 if (atomic_read(&sdp->detaching))
1131 return -ENODEV;
1132 return scsi_ioctl(sdp->device, cmd_in, p);
1133 case BLKSECTGET: 1093 case BLKSECTGET:
1134 return put_user(max_sectors_bytes(sdp->device->request_queue), 1094 return put_user(max_sectors_bytes(sdp->device->request_queue),
1135 ip); 1095 ip);
@@ -1145,11 +1105,25 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
1145 return blk_trace_startstop(sdp->device->request_queue, 0); 1105 return blk_trace_startstop(sdp->device->request_queue, 0);
1146 case BLKTRACETEARDOWN: 1106 case BLKTRACETEARDOWN:
1147 return blk_trace_remove(sdp->device->request_queue); 1107 return blk_trace_remove(sdp->device->request_queue);
1108 case SCSI_IOCTL_GET_IDLUN:
1109 case SCSI_IOCTL_GET_BUS_NUMBER:
1110 case SCSI_IOCTL_PROBE_HOST:
1111 case SG_GET_TRANSFORM:
1112 case SG_SCSI_RESET:
1113 if (atomic_read(&sdp->detaching))
1114 return -ENODEV;
1115 break;
1148 default: 1116 default:
1149 if (read_only) 1117 if (read_only)
1150 return -EPERM; /* don't know so take safe approach */ 1118 return -EPERM; /* don't know so take safe approach */
1151 return scsi_ioctl(sdp->device, cmd_in, p); 1119 break;
1152 } 1120 }
1121
1122 result = scsi_ioctl_block_when_processing_errors(sdp->device,
1123 cmd_in, filp->f_flags & O_NDELAY);
1124 if (result)
1125 return result;
1126 return scsi_ioctl(sdp->device, cmd_in, p);
1153} 1127}
1154 1128
1155#ifdef CONFIG_COMPAT 1129#ifdef CONFIG_COMPAT
@@ -1360,7 +1334,7 @@ sg_rq_end_io(struct request *rq, int uptodate)
1360 if ((sdp->sgdebug > 0) && 1334 if ((sdp->sgdebug > 0) &&
1361 ((CHECK_CONDITION == srp->header.masked_status) || 1335 ((CHECK_CONDITION == srp->header.masked_status) ||
1362 (COMMAND_TERMINATED == srp->header.masked_status))) 1336 (COMMAND_TERMINATED == srp->header.masked_status)))
1363 __scsi_print_sense(__func__, sense, 1337 __scsi_print_sense(sdp->device, __func__, sense,
1364 SCSI_SENSE_BUFFERSIZE); 1338 SCSI_SENSE_BUFFERSIZE);
1365 1339
1366 /* Following if statement is a patch supplied by Eric Youngdale */ 1340 /* Following if statement is a patch supplied by Eric Youngdale */
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 2de44cc58b1a..8bd54a64efd6 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -88,9 +88,9 @@ static struct dev_pm_ops sr_pm_ops = {
88}; 88};
89 89
90static struct scsi_driver sr_template = { 90static struct scsi_driver sr_template = {
91 .owner = THIS_MODULE,
92 .gendrv = { 91 .gendrv = {
93 .name = "sr", 92 .name = "sr",
93 .owner = THIS_MODULE,
94 .probe = sr_probe, 94 .probe = sr_probe,
95 .remove = sr_remove, 95 .remove = sr_remove,
96 .pm = &sr_pm_ops, 96 .pm = &sr_pm_ops,
@@ -387,7 +387,7 @@ static int sr_init_command(struct scsi_cmnd *SCpnt)
387 struct request *rq = SCpnt->request; 387 struct request *rq = SCpnt->request;
388 int ret; 388 int ret;
389 389
390 ret = scsi_init_io(SCpnt, GFP_ATOMIC); 390 ret = scsi_init_io(SCpnt);
391 if (ret != BLKPREP_OK) 391 if (ret != BLKPREP_OK)
392 goto out; 392 goto out;
393 SCpnt = rq->special; 393 SCpnt = rq->special;
@@ -549,6 +549,11 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
549 549
550 mutex_lock(&sr_mutex); 550 mutex_lock(&sr_mutex);
551 551
552 ret = scsi_ioctl_block_when_processing_errors(sdev, cmd,
553 (mode & FMODE_NDELAY) != 0);
554 if (ret)
555 goto out;
556
552 /* 557 /*
553 * Send SCSI addressing ioctls directly to mid level, send other 558 * Send SCSI addressing ioctls directly to mid level, send other
554 * ioctls to cdrom/block level. 559 * ioctls to cdrom/block level.
@@ -564,16 +569,6 @@ static int sr_block_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
564 if (ret != -ENOSYS) 569 if (ret != -ENOSYS)
565 goto out; 570 goto out;
566 571
567 /*
568 * ENODEV means that we didn't recognise the ioctl, or that we
569 * cannot execute it in the current device state. In either
570 * case fall through to scsi_ioctl, which will return ENDOEV again
571 * if it doesn't recognise the ioctl
572 */
573 ret = scsi_nonblockable_ioctl(sdev, cmd, argp,
574 (mode & FMODE_NDELAY) != 0);
575 if (ret != -ENODEV)
576 goto out;
577 ret = scsi_ioctl(sdev, cmd, argp); 572 ret = scsi_ioctl(sdev, cmd, argp);
578 573
579out: 574out:
diff --git a/drivers/scsi/sr.h b/drivers/scsi/sr.h
index 1d1f6f416c59..1de33719ad8e 100644
--- a/drivers/scsi/sr.h
+++ b/drivers/scsi/sr.h
@@ -57,8 +57,7 @@ typedef struct scsi_cd {
57} Scsi_CD; 57} Scsi_CD;
58 58
59#define sr_printk(prefix, cd, fmt, a...) \ 59#define sr_printk(prefix, cd, fmt, a...) \
60 sdev_printk(prefix, (cd)->device, "[%s] " fmt, \ 60 sdev_prefix_printk(prefix, (cd)->device, (cd)->cdi.name, fmt, ##a)
61 (cd)->cdi.name, ##a)
62 61
63int sr_do_ioctl(Scsi_CD *, struct packet_command *); 62int sr_do_ioctl(Scsi_CD *, struct packet_command *);
64 63
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index 6389fcff12ec..fb929fac22ba 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -246,7 +246,7 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
246 "CDROM not ready. Make sure there " 246 "CDROM not ready. Make sure there "
247 "is a disc in the drive.\n"); 247 "is a disc in the drive.\n");
248#ifdef DEBUG 248#ifdef DEBUG
249 scsi_print_sense_hdr("sr", &sshdr); 249 scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
250#endif 250#endif
251 err = -ENOMEDIUM; 251 err = -ENOMEDIUM;
252 break; 252 break;
@@ -257,15 +257,15 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
257 /* sense: Invalid command operation code */ 257 /* sense: Invalid command operation code */
258 err = -EDRIVE_CANT_DO_THIS; 258 err = -EDRIVE_CANT_DO_THIS;
259#ifdef DEBUG 259#ifdef DEBUG
260 __scsi_print_command(cgc->cmd); 260 __scsi_print_command(cgc->cmd, CDROM_PACKET_SIZE);
261 scsi_print_sense_hdr("sr", &sshdr); 261 scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
262#endif 262#endif
263 break; 263 break;
264 default: 264 default:
265 sr_printk(KERN_ERR, cd, 265 sr_printk(KERN_ERR, cd,
266 "CDROM (ioctl) error, command: "); 266 "CDROM (ioctl) error, command: ");
267 __scsi_print_command(cgc->cmd); 267 __scsi_print_command(cgc->cmd, CDROM_PACKET_SIZE);
268 scsi_print_sense_hdr("sr", &sshdr); 268 scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
269 err = -EIO; 269 err = -EIO;
270 } 270 }
271 } 271 }
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 4daa372ed381..128d3b55bdd9 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -56,7 +56,8 @@ static const char *verstr = "20101219";
56 56
57/* The driver prints some debugging information on the console if DEBUG 57/* The driver prints some debugging information on the console if DEBUG
58 is defined and non-zero. */ 58 is defined and non-zero. */
59#define DEBUG 0 59#define DEBUG 1
60#define NO_DEBUG 0
60 61
61#define ST_DEB_MSG KERN_NOTICE 62#define ST_DEB_MSG KERN_NOTICE
62#if DEBUG 63#if DEBUG
@@ -80,6 +81,7 @@ static int max_sg_segs;
80static int try_direct_io = TRY_DIRECT_IO; 81static int try_direct_io = TRY_DIRECT_IO;
81static int try_rdio = 1; 82static int try_rdio = 1;
82static int try_wdio = 1; 83static int try_wdio = 1;
84static int debug_flag;
83 85
84static struct class st_sysfs_class; 86static struct class st_sysfs_class;
85static const struct attribute_group *st_dev_groups[]; 87static const struct attribute_group *st_dev_groups[];
@@ -100,6 +102,9 @@ module_param_named(max_sg_segs, max_sg_segs, int, 0);
100MODULE_PARM_DESC(max_sg_segs, "Maximum number of scatter/gather segments to use (256)"); 102MODULE_PARM_DESC(max_sg_segs, "Maximum number of scatter/gather segments to use (256)");
101module_param_named(try_direct_io, try_direct_io, int, 0); 103module_param_named(try_direct_io, try_direct_io, int, 0);
102MODULE_PARM_DESC(try_direct_io, "Try direct I/O between user buffer and tape drive (1)"); 104MODULE_PARM_DESC(try_direct_io, "Try direct I/O between user buffer and tape drive (1)");
105module_param_named(debug_flag, debug_flag, int, 0);
106MODULE_PARM_DESC(debug_flag, "Enable DEBUG, same as setting debugging=1");
107
103 108
104/* Extra parameters for testing */ 109/* Extra parameters for testing */
105module_param_named(try_rdio, try_rdio, int, 0); 110module_param_named(try_rdio, try_rdio, int, 0);
@@ -124,6 +129,9 @@ static struct st_dev_parm {
124 }, 129 },
125 { 130 {
126 "try_direct_io", &try_direct_io 131 "try_direct_io", &try_direct_io
132 },
133 {
134 "debug_flag", &debug_flag
127 } 135 }
128}; 136};
129#endif 137#endif
@@ -194,9 +202,9 @@ static int do_create_sysfs_files(void);
194static void do_remove_sysfs_files(void); 202static void do_remove_sysfs_files(void);
195 203
196static struct scsi_driver st_template = { 204static struct scsi_driver st_template = {
197 .owner = THIS_MODULE,
198 .gendrv = { 205 .gendrv = {
199 .name = "st", 206 .name = "st",
207 .owner = THIS_MODULE,
200 .probe = st_probe, 208 .probe = st_probe,
201 .remove = st_remove, 209 .remove = st_remove,
202 }, 210 },
@@ -306,8 +314,7 @@ static inline char *tape_name(struct scsi_tape *tape)
306} 314}
307 315
308#define st_printk(prefix, t, fmt, a...) \ 316#define st_printk(prefix, t, fmt, a...) \
309 sdev_printk(prefix, (t)->device, "%s: " fmt, \ 317 sdev_prefix_printk(prefix, (t)->device, tape_name(t), fmt, ##a)
310 tape_name(t), ##a)
311#ifdef DEBUG 318#ifdef DEBUG
312#define DEBC_printk(t, fmt, a...) \ 319#define DEBC_printk(t, fmt, a...) \
313 if (debugging) { st_printk(ST_DEB_MSG, t, fmt, ##a ); } 320 if (debugging) { st_printk(ST_DEB_MSG, t, fmt, ##a ); }
@@ -374,7 +381,8 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
374 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2], 381 SRpnt->cmd[0], SRpnt->cmd[1], SRpnt->cmd[2],
375 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]); 382 SRpnt->cmd[3], SRpnt->cmd[4], SRpnt->cmd[5]);
376 if (cmdstatp->have_sense) 383 if (cmdstatp->have_sense)
377 __scsi_print_sense(name, SRpnt->sense, SCSI_SENSE_BUFFERSIZE); 384 __scsi_print_sense(STp->device, name,
385 SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
378 } ) /* end DEB */ 386 } ) /* end DEB */
379 if (!debugging) { /* Abnormal conditions for tape */ 387 if (!debugging) { /* Abnormal conditions for tape */
380 if (!cmdstatp->have_sense) 388 if (!cmdstatp->have_sense)
@@ -390,7 +398,8 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
390 SRpnt->cmd[0] != MODE_SENSE && 398 SRpnt->cmd[0] != MODE_SENSE &&
391 SRpnt->cmd[0] != TEST_UNIT_READY) { 399 SRpnt->cmd[0] != TEST_UNIT_READY) {
392 400
393 __scsi_print_sense(name, SRpnt->sense, SCSI_SENSE_BUFFERSIZE); 401 __scsi_print_sense(STp->device, name,
402 SRpnt->sense, SCSI_SENSE_BUFFERSIZE);
394 } 403 }
395 } 404 }
396 405
@@ -852,17 +861,16 @@ static int set_mode_densblk(struct scsi_tape * STp, struct st_modedef * STm)
852/* Lock or unlock the drive door. Don't use when st_request allocated. */ 861/* Lock or unlock the drive door. Don't use when st_request allocated. */
853static int do_door_lock(struct scsi_tape * STp, int do_lock) 862static int do_door_lock(struct scsi_tape * STp, int do_lock)
854{ 863{
855 int retval, cmd; 864 int retval;
856 865
857 cmd = do_lock ? SCSI_IOCTL_DOORLOCK : SCSI_IOCTL_DOORUNLOCK;
858 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl"); 866 DEBC_printk(STp, "%socking drive door.\n", do_lock ? "L" : "Unl");
859 retval = scsi_ioctl(STp->device, cmd, NULL); 867
860 if (!retval) { 868 retval = scsi_set_medium_removal(STp->device,
869 do_lock ? SCSI_REMOVAL_PREVENT : SCSI_REMOVAL_ALLOW);
870 if (!retval)
861 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED; 871 STp->door_locked = do_lock ? ST_LOCKED_EXPLICIT : ST_UNLOCKED;
862 } 872 else
863 else {
864 STp->door_locked = ST_LOCK_FAILS; 873 STp->door_locked = ST_LOCK_FAILS;
865 }
866 return retval; 874 return retval;
867} 875}
868 876
@@ -3367,11 +3375,10 @@ static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
3367 * may try and take the device offline, in which case all further 3375 * may try and take the device offline, in which case all further
3368 * access to the device is prohibited. 3376 * access to the device is prohibited.
3369 */ 3377 */
3370 retval = scsi_nonblockable_ioctl(STp->device, cmd_in, p, 3378 retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in,
3371 file->f_flags & O_NDELAY); 3379 file->f_flags & O_NDELAY);
3372 if (!scsi_block_when_processing_errors(STp->device) || retval != -ENODEV) 3380 if (retval)
3373 goto out; 3381 goto out;
3374 retval = 0;
3375 3382
3376 cmd_type = _IOC_TYPE(cmd_in); 3383 cmd_type = _IOC_TYPE(cmd_in);
3377 cmd_nr = _IOC_NR(cmd_in); 3384 cmd_nr = _IOC_NR(cmd_in);
@@ -4309,6 +4316,12 @@ static int __init init_st(void)
4309 printk(KERN_INFO "st: Version %s, fixed bufsize %d, s/g segs %d\n", 4316 printk(KERN_INFO "st: Version %s, fixed bufsize %d, s/g segs %d\n",
4310 verstr, st_fixed_buffer_size, st_max_sg_segs); 4317 verstr, st_fixed_buffer_size, st_max_sg_segs);
4311 4318
4319 debugging = (debug_flag > 0) ? debug_flag : NO_DEBUG;
4320 if (debugging) {
4321 printk(KERN_INFO "st: Debugging enabled debug_flag = %d\n",
4322 debugging);
4323 }
4324
4312 err = class_register(&st_sysfs_class); 4325 err = class_register(&st_sysfs_class);
4313 if (err) { 4326 if (err) {
4314 pr_err("Unable register sysfs class for SCSI tapes\n"); 4327 pr_err("Unable register sysfs class for SCSI tapes\n");
diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 1aa4befcfbd0..98a62bc15069 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -544,33 +544,15 @@ stex_ss_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag)
544} 544}
545 545
546static int 546static int
547stex_slave_alloc(struct scsi_device *sdev)
548{
549 /* Cheat: usually extracted from Inquiry data */
550 sdev->tagged_supported = 1;
551
552 scsi_activate_tcq(sdev, sdev->host->can_queue);
553
554 return 0;
555}
556
557static int
558stex_slave_config(struct scsi_device *sdev) 547stex_slave_config(struct scsi_device *sdev)
559{ 548{
560 sdev->use_10_for_rw = 1; 549 sdev->use_10_for_rw = 1;
561 sdev->use_10_for_ms = 1; 550 sdev->use_10_for_ms = 1;
562 blk_queue_rq_timeout(sdev->request_queue, 60 * HZ); 551 blk_queue_rq_timeout(sdev->request_queue, 60 * HZ);
563 sdev->tagged_supported = 1;
564 552
565 return 0; 553 return 0;
566} 554}
567 555
568static void
569stex_slave_destroy(struct scsi_device *sdev)
570{
571 scsi_deactivate_tcq(sdev, 1);
572}
573
574static int 556static int
575stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) 557stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
576{ 558{
@@ -1162,9 +1144,7 @@ static int stex_abort(struct scsi_cmnd *cmd)
1162 int result = SUCCESS; 1144 int result = SUCCESS;
1163 unsigned long flags; 1145 unsigned long flags;
1164 1146
1165 printk(KERN_INFO DRV_NAME 1147 scmd_printk(KERN_INFO, cmd, "aborting command\n");
1166 "(%s): aborting command\n", pci_name(hba->pdev));
1167 scsi_print_command(cmd);
1168 1148
1169 base = hba->mmio_base; 1149 base = hba->mmio_base;
1170 spin_lock_irqsave(host->host_lock, flags); 1150 spin_lock_irqsave(host->host_lock, flags);
@@ -1352,9 +1332,8 @@ static int stex_reset(struct scsi_cmnd *cmd)
1352 1332
1353 hba = (struct st_hba *) &cmd->device->host->hostdata[0]; 1333 hba = (struct st_hba *) &cmd->device->host->hostdata[0];
1354 1334
1355 printk(KERN_INFO DRV_NAME 1335 shost_printk(KERN_INFO, cmd->device->host,
1356 "(%s): resetting host\n", pci_name(hba->pdev)); 1336 "resetting host\n");
1357 scsi_print_command(cmd);
1358 1337
1359 return stex_do_reset(hba) ? FAILED : SUCCESS; 1338 return stex_do_reset(hba) ? FAILED : SUCCESS;
1360} 1339}
@@ -1391,12 +1370,11 @@ static struct scsi_host_template driver_template = {
1391 .proc_name = DRV_NAME, 1370 .proc_name = DRV_NAME,
1392 .bios_param = stex_biosparam, 1371 .bios_param = stex_biosparam,
1393 .queuecommand = stex_queuecommand, 1372 .queuecommand = stex_queuecommand,
1394 .slave_alloc = stex_slave_alloc,
1395 .slave_configure = stex_slave_config, 1373 .slave_configure = stex_slave_config,
1396 .slave_destroy = stex_slave_destroy,
1397 .eh_abort_handler = stex_abort, 1374 .eh_abort_handler = stex_abort,
1398 .eh_host_reset_handler = stex_reset, 1375 .eh_host_reset_handler = stex_reset,
1399 .this_id = -1, 1376 .this_id = -1,
1377 .use_blk_tags = 1,
1400}; 1378};
1401 1379
1402static struct pci_device_id stex_pci_tbl[] = { 1380static struct pci_device_id stex_pci_tbl[] = {
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 733e5f759518..e3ba251fb6e7 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1097,7 +1097,8 @@ static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request)
1097 if (scmnd->result) { 1097 if (scmnd->result) {
1098 if (scsi_normalize_sense(scmnd->sense_buffer, 1098 if (scsi_normalize_sense(scmnd->sense_buffer,
1099 SCSI_SENSE_BUFFERSIZE, &sense_hdr)) 1099 SCSI_SENSE_BUFFERSIZE, &sense_hdr))
1100 scsi_print_sense_hdr("storvsc", &sense_hdr); 1100 scsi_print_sense_hdr(scmnd->device, "storvsc",
1101 &sense_hdr);
1101 } 1102 }
1102 1103
1103 if (vm_srb->srb_status != SRB_STATUS_SUCCESS) 1104 if (vm_srb->srb_status != SRB_STATUS_SUCCESS)
@@ -1428,8 +1429,7 @@ static void storvsc_device_destroy(struct scsi_device *sdevice)
1428 1429
1429static int storvsc_device_configure(struct scsi_device *sdevice) 1430static int storvsc_device_configure(struct scsi_device *sdevice)
1430{ 1431{
1431 scsi_adjust_queue_depth(sdevice, MSG_SIMPLE_TAG, 1432 scsi_change_queue_depth(sdevice, STORVSC_MAX_IO_REQUESTS);
1432 STORVSC_MAX_IO_REQUESTS);
1433 1433
1434 blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE); 1434 blk_queue_max_segment_size(sdevice->request_queue, PAGE_SIZE);
1435 1435
diff --git a/drivers/scsi/sun3_NCR5380.c b/drivers/scsi/sun3_NCR5380.c
deleted file mode 100644
index 1a2367a1b1f2..000000000000
--- a/drivers/scsi/sun3_NCR5380.c
+++ /dev/null
@@ -1,2933 +0,0 @@
1/* sun3_NCR5380.c -- adapted from atari_NCR5380.c for the sun3 by
2 Sam Creasey. */
3/*
4 * NCR 5380 generic driver routines. These should make it *trivial*
5 * to implement 5380 SCSI drivers under Linux with a non-trantor
6 * architecture.
7 *
8 * Note that these routines also work with NR53c400 family chips.
9 *
10 * Copyright 1993, Drew Eckhardt
11 * Visionary Computing
12 * (Unix and Linux consulting and custom programming)
13 * drew@colorado.edu
14 * +1 (303) 666-5836
15 *
16 * DISTRIBUTION RELEASE 6.
17 *
18 * For more information, please consult
19 *
20 * NCR 5380 Family
21 * SCSI Protocol Controller
22 * Databook
23 *
24 * NCR Microelectronics
25 * 1635 Aeroplaza Drive
26 * Colorado Springs, CO 80916
27 * 1+ (719) 578-3400
28 * 1+ (800) 334-5454
29 */
30
31/*
32 * ++roman: To port the 5380 driver to the Atari, I had to do some changes in
33 * this file, too:
34 *
35 * - Some of the debug statements were incorrect (undefined variables and the
36 * like). I fixed that.
37 *
38 * - In information_transfer(), I think a #ifdef was wrong. Looking at the
39 * possible DMA transfer size should also happen for REAL_DMA. I added this
40 * in the #if statement.
41 *
42 * - When using real DMA, information_transfer() should return in a DATAOUT
43 * phase after starting the DMA. It has nothing more to do.
44 *
45 * - The interrupt service routine should run main after end of DMA, too (not
46 * only after RESELECTION interrupts). Additionally, it should _not_ test
47 * for more interrupts after running main, since a DMA process may have
48 * been started and interrupts are turned on now. The new int could happen
49 * inside the execution of NCR5380_intr(), leading to recursive
50 * calls.
51 *
52 * - I've deleted all the stuff for AUTOPROBE_IRQ, REAL_DMA_POLL, PSEUDO_DMA
53 * and USLEEP, because these were messing up readability and will never be
54 * needed for Atari SCSI.
55 *
56 * - I've revised the NCR5380_main() calling scheme (relax the 'main_running'
57 * stuff), and 'main' is executed in a bottom half if awoken by an
58 * interrupt.
59 *
60 * - The code was quite cluttered up by "#if (NDEBUG & NDEBUG_*) printk..."
61 * constructs. In my eyes, this made the source rather unreadable, so I
62 * finally replaced that by the *_PRINTK() macros.
63 *
64 */
65#include <scsi/scsi_dbg.h>
66#include <scsi/scsi_transport_spi.h>
67
68/*
69 * Further development / testing that should be done :
70 * 1. Test linked command handling code after Eric is ready with
71 * the high level code.
72 */
73
74#if (NDEBUG & NDEBUG_LISTS)
75#define LIST(x,y) \
76 { printk("LINE:%d Adding %p to %p\n", __LINE__, (void*)(x), (void*)(y)); \
77 if ((x)==(y)) udelay(5); }
78#define REMOVE(w,x,y,z) \
79 { printk("LINE:%d Removing: %p->%p %p->%p \n", __LINE__, \
80 (void*)(w), (void*)(x), (void*)(y), (void*)(z)); \
81 if ((x)==(y)) udelay(5); }
82#else
83#define LIST(x,y)
84#define REMOVE(w,x,y,z)
85#endif
86
87#ifndef notyet
88#undef LINKED
89#endif
90
91/*
92 * Design
93 * Issues :
94 *
95 * The other Linux SCSI drivers were written when Linux was Intel PC-only,
96 * and specifically for each board rather than each chip. This makes their
97 * adaptation to platforms like the Mac (Some of which use NCR5380's)
98 * more difficult than it has to be.
99 *
100 * Also, many of the SCSI drivers were written before the command queuing
101 * routines were implemented, meaning their implementations of queued
102 * commands were hacked on rather than designed in from the start.
103 *
104 * When I designed the Linux SCSI drivers I figured that
105 * while having two different SCSI boards in a system might be useful
106 * for debugging things, two of the same type wouldn't be used.
107 * Well, I was wrong and a number of users have mailed me about running
108 * multiple high-performance SCSI boards in a server.
109 *
110 * Finally, when I get questions from users, I have no idea what
111 * revision of my driver they are running.
112 *
113 * This driver attempts to address these problems :
114 * This is a generic 5380 driver. To use it on a different platform,
115 * one simply writes appropriate system specific macros (ie, data
116 * transfer - some PC's will use the I/O bus, 68K's must use
117 * memory mapped) and drops this file in their 'C' wrapper.
118 *
119 * As far as command queueing, two queues are maintained for
120 * each 5380 in the system - commands that haven't been issued yet,
121 * and commands that are currently executing. This means that an
122 * unlimited number of commands may be queued, letting
123 * more commands propagate from the higher driver levels giving higher
124 * throughput. Note that both I_T_L and I_T_L_Q nexuses are supported,
125 * allowing multiple commands to propagate all the way to a SCSI-II device
126 * while a command is already executing.
127 *
128 * To solve the multiple-boards-in-the-same-system problem,
129 * there is a separate instance structure for each instance
130 * of a 5380 in the system. So, multiple NCR5380 drivers will
131 * be able to coexist with appropriate changes to the high level
132 * SCSI code.
133 *
134 * A NCR5380_PUBLIC_REVISION macro is provided, with the release
135 * number (updated for each public release) printed by the
136 * NCR5380_print_options command, which should be called from the
137 * wrapper detect function, so that I know what release of the driver
138 * users are using.
139 *
140 * Issues specific to the NCR5380 :
141 *
142 * When used in a PIO or pseudo-dma mode, the NCR5380 is a braindead
143 * piece of hardware that requires you to sit in a loop polling for
144 * the REQ signal as long as you are connected. Some devices are
145 * brain dead (ie, many TEXEL CD ROM drives) and won't disconnect
146 * while doing long seek operations.
147 *
148 * The workaround for this is to keep track of devices that have
149 * disconnected. If the device hasn't disconnected, for commands that
150 * should disconnect, we do something like
151 *
152 * while (!REQ is asserted) { sleep for N usecs; poll for M usecs }
153 *
154 * Some tweaking of N and M needs to be done. An algorithm based
155 * on "time to data" would give the best results as long as short time
156 * to datas (ie, on the same track) were considered, however these
157 * broken devices are the exception rather than the rule and I'd rather
158 * spend my time optimizing for the normal case.
159 *
160 * Architecture :
161 *
162 * At the heart of the design is a coroutine, NCR5380_main,
163 * which is started when not running by the interrupt handler,
164 * timer, and queue command function. It attempts to establish
165 * I_T_L or I_T_L_Q nexuses by removing the commands from the
166 * issue queue and calling NCR5380_select() if a nexus
167 * is not established.
168 *
169 * Once a nexus is established, the NCR5380_information_transfer()
170 * phase goes through the various phases as instructed by the target.
171 * if the target goes into MSG IN and sends a DISCONNECT message,
172 * the command structure is placed into the per instance disconnected
173 * queue, and NCR5380_main tries to find more work. If USLEEP
174 * was defined, and the target is idle for too long, the system
175 * will try to sleep.
176 *
177 * If a command has disconnected, eventually an interrupt will trigger,
178 * calling NCR5380_intr() which will in turn call NCR5380_reselect
179 * to reestablish a nexus. This will run main if necessary.
180 *
181 * On command termination, the done function will be called as
182 * appropriate.
183 *
184 * SCSI pointers are maintained in the SCp field of SCSI command
185 * structures, being initialized after the command is connected
186 * in NCR5380_select, and set as appropriate in NCR5380_information_transfer.
187 * Note that in violation of the standard, an implicit SAVE POINTERS operation
188 * is done, since some BROKEN disks fail to issue an explicit SAVE POINTERS.
189 */
190
191/*
192 * Using this file :
193 * This file a skeleton Linux SCSI driver for the NCR 5380 series
194 * of chips. To use it, you write an architecture specific functions
195 * and macros and include this file in your driver.
196 *
197 * These macros control options :
198 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
199 * for commands that return with a CHECK CONDITION status.
200 *
201 * LINKED - if defined, linked commands are supported.
202 *
203 * REAL_DMA - if defined, REAL DMA is used during the data transfer phases.
204 *
205 * SUPPORT_TAGS - if defined, SCSI-2 tagged queuing is used where possible
206 *
207 * These macros MUST be defined :
208 *
209 * NCR5380_read(register) - read from the specified register
210 *
211 * NCR5380_write(register, value) - write to the specific register
212 *
213 * Either real DMA *or* pseudo DMA may be implemented
214 * REAL functions :
215 * NCR5380_REAL_DMA should be defined if real DMA is to be used.
216 * Note that the DMA setup functions should return the number of bytes
217 * that they were able to program the controller for.
218 *
219 * Also note that generic i386/PC versions of these macros are
220 * available as NCR5380_i386_dma_write_setup,
221 * NCR5380_i386_dma_read_setup, and NCR5380_i386_dma_residual.
222 *
223 * NCR5380_dma_write_setup(instance, src, count) - initialize
224 * NCR5380_dma_read_setup(instance, dst, count) - initialize
225 * NCR5380_dma_residual(instance); - residual count
226 *
227 * PSEUDO functions :
228 * NCR5380_pwrite(instance, src, count)
229 * NCR5380_pread(instance, dst, count);
230 *
231 * If nothing specific to this implementation needs doing (ie, with external
232 * hardware), you must also define
233 *
234 * NCR5380_queue_command
235 * NCR5380_reset
236 * NCR5380_abort
237 * NCR5380_proc_info
238 *
239 * to be the global entry points into the specific driver, ie
240 * #define NCR5380_queue_command t128_queue_command.
241 *
242 * If this is not done, the routines will be defined as static functions
243 * with the NCR5380* names and the user must provide a globally
244 * accessible wrapper function.
245 *
246 * The generic driver is initialized by calling NCR5380_init(instance),
247 * after setting the appropriate host specific fields and ID. If the
248 * driver wishes to autoprobe for an IRQ line, the NCR5380_probe_irq(instance,
249 * possible) function may be used. Before the specific driver initialization
250 * code finishes, NCR5380_print_options should be called.
251 */
252
253static struct Scsi_Host *first_instance = NULL;
254static struct scsi_host_template *the_template = NULL;
255
256/* Macros ease life... :-) */
257#define SETUP_HOSTDATA(in) \
258 struct NCR5380_hostdata *hostdata = \
259 (struct NCR5380_hostdata *)(in)->hostdata
260#define HOSTDATA(in) ((struct NCR5380_hostdata *)(in)->hostdata)
261
262#define NEXT(cmd) ((struct scsi_cmnd *)(cmd)->host_scribble)
263#define SET_NEXT(cmd, next) ((cmd)->host_scribble = (void *)(next))
264#define NEXTADDR(cmd) ((struct scsi_cmnd **)&((cmd)->host_scribble))
265
266#define HOSTNO instance->host_no
267#define H_NO(cmd) (cmd)->device->host->host_no
268
269#define SGADDR(buffer) (void *)(((unsigned long)sg_virt(((buffer)))))
270
271#ifdef SUPPORT_TAGS
272
273/*
274 * Functions for handling tagged queuing
275 * =====================================
276 *
277 * ++roman (01/96): Now I've implemented SCSI-2 tagged queuing. Some notes:
278 *
279 * Using consecutive numbers for the tags is no good idea in my eyes. There
280 * could be wrong re-usings if the counter (8 bit!) wraps and some early
281 * command has been preempted for a long time. My solution: a bitfield for
282 * remembering used tags.
283 *
284 * There's also the problem that each target has a certain queue size, but we
285 * cannot know it in advance :-( We just see a QUEUE_FULL status being
286 * returned. So, in this case, the driver internal queue size assumption is
287 * reduced to the number of active tags if QUEUE_FULL is returned by the
288 * target. The command is returned to the mid-level, but with status changed
289 * to BUSY, since --as I've seen-- the mid-level can't handle QUEUE_FULL
290 * correctly.
291 *
292 * We're also not allowed running tagged commands as long as an untagged
293 * command is active. And REQUEST SENSE commands after a contingent allegiance
294 * condition _must_ be untagged. To keep track whether an untagged command has
295 * been issued, the host->busy array is still employed, as it is without
296 * support for tagged queuing.
297 *
298 * One could suspect that there are possible race conditions between
299 * is_lun_busy(), cmd_get_tag() and cmd_free_tag(). But I think this isn't the
300 * case: is_lun_busy() and cmd_get_tag() are both called from NCR5380_main(),
301 * which already guaranteed to be running at most once. It is also the only
302 * place where tags/LUNs are allocated. So no other allocation can slip
303 * between that pair, there could only happen a reselection, which can free a
304 * tag, but that doesn't hurt. Only the sequence in cmd_free_tag() becomes
305 * important: the tag bit must be cleared before 'nr_allocated' is decreased.
306 */
307
308/* -1 for TAG_NONE is not possible with unsigned char cmd->tag */
309#undef TAG_NONE
310#define TAG_NONE 0xff
311
312/* For the m68k, the number of bits in 'allocated' must be a multiple of 32! */
313#if (MAX_TAGS % 32) != 0
314#error "MAX_TAGS must be a multiple of 32!"
315#endif
316
317typedef struct {
318 char allocated[MAX_TAGS/8];
319 int nr_allocated;
320 int queue_size;
321} TAG_ALLOC;
322
323static TAG_ALLOC TagAlloc[8][8]; /* 8 targets and 8 LUNs */
324
325
326static void __init init_tags( void )
327{
328 int target, lun;
329 TAG_ALLOC *ta;
330
331 if (!setup_use_tagged_queuing)
332 return;
333
334 for( target = 0; target < 8; ++target ) {
335 for( lun = 0; lun < 8; ++lun ) {
336 ta = &TagAlloc[target][lun];
337 memset( &ta->allocated, 0, MAX_TAGS/8 );
338 ta->nr_allocated = 0;
339 /* At the beginning, assume the maximum queue size we could
340 * support (MAX_TAGS). This value will be decreased if the target
341 * returns QUEUE_FULL status.
342 */
343 ta->queue_size = MAX_TAGS;
344 }
345 }
346}
347
348
349/* Check if we can issue a command to this LUN: First see if the LUN is marked
350 * busy by an untagged command. If the command should use tagged queuing, also
351 * check that there is a free tag and the target's queue won't overflow. This
352 * function should be called with interrupts disabled to avoid race
353 * conditions.
354 */
355
356static int is_lun_busy(struct scsi_cmnd *cmd, int should_be_tagged)
357{
358 u8 lun = cmd->device->lun;
359 SETUP_HOSTDATA(cmd->device->host);
360
361 if (hostdata->busy[cmd->device->id] & (1 << lun))
362 return( 1 );
363 if (!should_be_tagged ||
364 !setup_use_tagged_queuing || !cmd->device->tagged_supported)
365 return( 0 );
366 if (TagAlloc[cmd->device->id][lun].nr_allocated >=
367 TagAlloc[cmd->device->id][lun].queue_size ) {
368 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d: no free tags\n",
369 H_NO(cmd), cmd->device->id, lun );
370 return( 1 );
371 }
372 return( 0 );
373}
374
375
376/* Allocate a tag for a command (there are no checks anymore, check_lun_busy()
377 * must be called before!), or reserve the LUN in 'busy' if the command is
378 * untagged.
379 */
380
381static void cmd_get_tag(struct scsi_cmnd *cmd, int should_be_tagged)
382{
383 u8 lun = cmd->device->lun;
384 SETUP_HOSTDATA(cmd->device->host);
385
386 /* If we or the target don't support tagged queuing, allocate the LUN for
387 * an untagged command.
388 */
389 if (!should_be_tagged ||
390 !setup_use_tagged_queuing || !cmd->device->tagged_supported) {
391 cmd->tag = TAG_NONE;
392 hostdata->busy[cmd->device->id] |= (1 << lun);
393 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d now allocated by untagged "
394 "command\n", H_NO(cmd), cmd->device->id, lun );
395 }
396 else {
397 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][lun];
398
399 cmd->tag = find_first_zero_bit( &ta->allocated, MAX_TAGS );
400 set_bit( cmd->tag, &ta->allocated );
401 ta->nr_allocated++;
402 dprintk(NDEBUG_TAGS, "scsi%d: using tag %d for target %d lun %d "
403 "(now %d tags in use)\n",
404 H_NO(cmd), cmd->tag, cmd->device->id, lun,
405 ta->nr_allocated );
406 }
407}
408
409
410/* Mark the tag of command 'cmd' as free, or in case of an untagged command,
411 * unlock the LUN.
412 */
413
414static void cmd_free_tag(struct scsi_cmnd *cmd)
415{
416 u8 lun = cmd->device->lun;
417 SETUP_HOSTDATA(cmd->device->host);
418
419 if (cmd->tag == TAG_NONE) {
420 hostdata->busy[cmd->device->id] &= ~(1 << lun);
421 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %d untagged cmd finished\n",
422 H_NO(cmd), cmd->device->id, lun );
423 }
424 else if (cmd->tag >= MAX_TAGS) {
425 printk(KERN_NOTICE "scsi%d: trying to free bad tag %d!\n",
426 H_NO(cmd), cmd->tag );
427 }
428 else {
429 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][lun];
430 clear_bit( cmd->tag, &ta->allocated );
431 ta->nr_allocated--;
432 dprintk(NDEBUG_TAGS, "scsi%d: freed tag %d for target %d lun %d\n",
433 H_NO(cmd), cmd->tag, cmd->device->id, lun );
434 }
435}
436
437
438static void free_all_tags( void )
439{
440 int target, lun;
441 TAG_ALLOC *ta;
442
443 if (!setup_use_tagged_queuing)
444 return;
445
446 for( target = 0; target < 8; ++target ) {
447 for( lun = 0; lun < 8; ++lun ) {
448 ta = &TagAlloc[target][lun];
449 memset( &ta->allocated, 0, MAX_TAGS/8 );
450 ta->nr_allocated = 0;
451 }
452 }
453}
454
455#endif /* SUPPORT_TAGS */
456
457
458/*
459 * Function : void initialize_SCp(struct scsi_cmnd *cmd)
460 *
461 * Purpose : initialize the saved data pointers for cmd to point to the
462 * start of the buffer.
463 *
464 * Inputs : cmd - struct scsi_cmnd structure to have pointers reset.
465 */
466
467static __inline__ void initialize_SCp(struct scsi_cmnd *cmd)
468{
469 /*
470 * Initialize the Scsi Pointer field so that all of the commands in the
471 * various queues are valid.
472 */
473
474 if (scsi_bufflen(cmd)) {
475 cmd->SCp.buffer = scsi_sglist(cmd);
476 cmd->SCp.buffers_residual = scsi_sg_count(cmd) - 1;
477 cmd->SCp.ptr = (char *) SGADDR(cmd->SCp.buffer);
478 cmd->SCp.this_residual = cmd->SCp.buffer->length;
479 } else {
480 cmd->SCp.buffer = NULL;
481 cmd->SCp.buffers_residual = 0;
482 cmd->SCp.ptr = NULL;
483 cmd->SCp.this_residual = 0;
484 }
485
486}
487
488#include <linux/delay.h>
489
490#if NDEBUG
491static struct {
492 unsigned char mask;
493 const char * name;}
494signals[] = {{ SR_DBP, "PARITY"}, { SR_RST, "RST" }, { SR_BSY, "BSY" },
495 { SR_REQ, "REQ" }, { SR_MSG, "MSG" }, { SR_CD, "CD" }, { SR_IO, "IO" },
496 { SR_SEL, "SEL" }, {0, NULL}},
497basrs[] = {{BASR_ATN, "ATN"}, {BASR_ACK, "ACK"}, {0, NULL}},
498icrs[] = {{ICR_ASSERT_RST, "ASSERT RST"},{ICR_ASSERT_ACK, "ASSERT ACK"},
499 {ICR_ASSERT_BSY, "ASSERT BSY"}, {ICR_ASSERT_SEL, "ASSERT SEL"},
500 {ICR_ASSERT_ATN, "ASSERT ATN"}, {ICR_ASSERT_DATA, "ASSERT DATA"},
501 {0, NULL}},
502mrs[] = {{MR_BLOCK_DMA_MODE, "MODE BLOCK DMA"}, {MR_TARGET, "MODE TARGET"},
503 {MR_ENABLE_PAR_CHECK, "MODE PARITY CHECK"}, {MR_ENABLE_PAR_INTR,
504 "MODE PARITY INTR"}, {MR_ENABLE_EOP_INTR,"MODE EOP INTR"},
505 {MR_MONITOR_BSY, "MODE MONITOR BSY"},
506 {MR_DMA_MODE, "MODE DMA"}, {MR_ARBITRATE, "MODE ARBITRATION"},
507 {0, NULL}};
508
509/*
510 * Function : void NCR5380_print(struct Scsi_Host *instance)
511 *
512 * Purpose : print the SCSI bus signals for debugging purposes
513 *
514 * Input : instance - which NCR5380
515 */
516
517static void NCR5380_print(struct Scsi_Host *instance) {
518 unsigned char status, data, basr, mr, icr, i;
519 unsigned long flags;
520
521 local_irq_save(flags);
522 data = NCR5380_read(CURRENT_SCSI_DATA_REG);
523 status = NCR5380_read(STATUS_REG);
524 mr = NCR5380_read(MODE_REG);
525 icr = NCR5380_read(INITIATOR_COMMAND_REG);
526 basr = NCR5380_read(BUS_AND_STATUS_REG);
527 local_irq_restore(flags);
528 printk("STATUS_REG: %02x ", status);
529 for (i = 0; signals[i].mask ; ++i)
530 if (status & signals[i].mask)
531 printk(",%s", signals[i].name);
532 printk("\nBASR: %02x ", basr);
533 for (i = 0; basrs[i].mask ; ++i)
534 if (basr & basrs[i].mask)
535 printk(",%s", basrs[i].name);
536 printk("\nICR: %02x ", icr);
537 for (i = 0; icrs[i].mask; ++i)
538 if (icr & icrs[i].mask)
539 printk(",%s", icrs[i].name);
540 printk("\nMODE: %02x ", mr);
541 for (i = 0; mrs[i].mask; ++i)
542 if (mr & mrs[i].mask)
543 printk(",%s", mrs[i].name);
544 printk("\n");
545}
546
547static struct {
548 unsigned char value;
549 const char *name;
550} phases[] = {
551 {PHASE_DATAOUT, "DATAOUT"}, {PHASE_DATAIN, "DATAIN"}, {PHASE_CMDOUT, "CMDOUT"},
552 {PHASE_STATIN, "STATIN"}, {PHASE_MSGOUT, "MSGOUT"}, {PHASE_MSGIN, "MSGIN"},
553 {PHASE_UNKNOWN, "UNKNOWN"}};
554
555/*
556 * Function : void NCR5380_print_phase(struct Scsi_Host *instance)
557 *
558 * Purpose : print the current SCSI phase for debugging purposes
559 *
560 * Input : instance - which NCR5380
561 */
562
563static void NCR5380_print_phase(struct Scsi_Host *instance)
564{
565 unsigned char status;
566 int i;
567
568 status = NCR5380_read(STATUS_REG);
569 if (!(status & SR_REQ))
570 printk(KERN_DEBUG "scsi%d: REQ not asserted, phase unknown.\n", HOSTNO);
571 else {
572 for (i = 0; (phases[i].value != PHASE_UNKNOWN) &&
573 (phases[i].value != (status & PHASE_MASK)); ++i);
574 printk(KERN_DEBUG "scsi%d: phase %s\n", HOSTNO, phases[i].name);
575 }
576}
577
578#endif
579
580/*
581 * ++roman: New scheme of calling NCR5380_main()
582 *
583 * If we're not in an interrupt, we can call our main directly, it cannot be
584 * already running. Else, we queue it on a task queue, if not 'main_running'
585 * tells us that a lower level is already executing it. This way,
586 * 'main_running' needs not be protected in a special way.
587 *
588 * queue_main() is a utility function for putting our main onto the task
589 * queue, if main_running is false. It should be called only from a
590 * interrupt or bottom half.
591 */
592
593#include <linux/gfp.h>
594#include <linux/workqueue.h>
595#include <linux/interrupt.h>
596
597static volatile int main_running = 0;
598static DECLARE_WORK(NCR5380_tqueue, NCR5380_main);
599
600static __inline__ void queue_main(void)
601{
602 if (!main_running) {
603 /* If in interrupt and NCR5380_main() not already running,
604 queue it on the 'immediate' task queue, to be processed
605 immediately after the current interrupt processing has
606 finished. */
607 schedule_work(&NCR5380_tqueue);
608 }
609 /* else: nothing to do: the running NCR5380_main() will pick up
610 any newly queued command. */
611}
612
613
614static inline void NCR5380_all_init (void)
615{
616 static int done = 0;
617 if (!done) {
618 dprintk(NDEBUG_INIT, "scsi : NCR5380_all_init()\n");
619 done = 1;
620 }
621}
622
623
624/*
625 * Function : void NCR58380_print_options (struct Scsi_Host *instance)
626 *
627 * Purpose : called by probe code indicating the NCR5380 driver
628 * options that were selected.
629 *
630 * Inputs : instance, pointer to this instance. Unused.
631 */
632
633static void __init NCR5380_print_options (struct Scsi_Host *instance)
634{
635 printk(" generic options"
636#ifdef AUTOSENSE
637 " AUTOSENSE"
638#endif
639#ifdef REAL_DMA
640 " REAL DMA"
641#endif
642#ifdef PARITY
643 " PARITY"
644#endif
645#ifdef SUPPORT_TAGS
646 " SCSI-2 TAGGED QUEUING"
647#endif
648 );
649 printk(" generic release=%d", NCR5380_PUBLIC_RELEASE);
650}
651
652/*
653 * Function : void NCR5380_print_status (struct Scsi_Host *instance)
654 *
655 * Purpose : print commands in the various queues, called from
656 * NCR5380_abort and NCR5380_debug to aid debugging.
657 *
658 * Inputs : instance, pointer to this instance.
659 */
660
661static void lprint_Scsi_Cmnd(Scsi_Cmnd *cmd)
662{
663 int i, s;
664 unsigned char *command;
665 printk("scsi%d: destination target %d, lun %llu\n",
666 H_NO(cmd), cmd->device->id, cmd->device->lun);
667 printk(KERN_CONT " command = ");
668 command = cmd->cmnd;
669 printk(KERN_CONT "%2d (0x%02x)", command[0], command[0]);
670 for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i)
671 printk(KERN_CONT " %02x", command[i]);
672 printk("\n");
673}
674
675static void NCR5380_print_status(struct Scsi_Host *instance)
676{
677 struct NCR5380_hostdata *hostdata;
678 Scsi_Cmnd *ptr;
679 unsigned long flags;
680
681 NCR5380_dprint(NDEBUG_ANY, instance);
682 NCR5380_dprint_phase(NDEBUG_ANY, instance);
683
684 hostdata = (struct NCR5380_hostdata *)instance->hostdata;
685
686 printk("\nNCR5380 core release=%d.\n", NCR5380_PUBLIC_RELEASE);
687 local_irq_save(flags);
688 printk("NCR5380: coroutine is%s running.\n",
689 main_running ? "" : "n't");
690 if (!hostdata->connected)
691 printk("scsi%d: no currently connected command\n", HOSTNO);
692 else
693 lprint_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected);
694 printk("scsi%d: issue_queue\n", HOSTNO);
695 for (ptr = (Scsi_Cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr))
696 lprint_Scsi_Cmnd(ptr);
697
698 printk("scsi%d: disconnected_queue\n", HOSTNO);
699 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr;
700 ptr = NEXT(ptr))
701 lprint_Scsi_Cmnd(ptr);
702
703 local_irq_restore(flags);
704 printk("\n");
705}
706
707static void show_Scsi_Cmnd(Scsi_Cmnd *cmd, struct seq_file *m)
708{
709 int i, s;
710 unsigned char *command;
711 seq_printf(m, "scsi%d: destination target %d, lun %llu\n",
712 H_NO(cmd), cmd->device->id, cmd->device->lun);
713 seq_printf(m, " command = ");
714 command = cmd->cmnd;
715 seq_printf(m, "%2d (0x%02x)", command[0], command[0]);
716 for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i)
717 seq_printf(m, " %02x", command[i]);
718 seq_printf(m, "\n");
719}
720
721static int NCR5380_show_info(struct seq_file *m, struct Scsi_Host *instance)
722{
723 struct NCR5380_hostdata *hostdata;
724 Scsi_Cmnd *ptr;
725 unsigned long flags;
726
727 hostdata = (struct NCR5380_hostdata *)instance->hostdata;
728
729 seq_printf(m, "NCR5380 core release=%d.\n", NCR5380_PUBLIC_RELEASE);
730 local_irq_save(flags);
731 seq_printf(m, "NCR5380: coroutine is%s running.\n",
732 main_running ? "" : "n't");
733 if (!hostdata->connected)
734 seq_printf(m, "scsi%d: no currently connected command\n", HOSTNO);
735 else
736 show_Scsi_Cmnd((Scsi_Cmnd *) hostdata->connected, m);
737 seq_printf(m, "scsi%d: issue_queue\n", HOSTNO);
738 for (ptr = (Scsi_Cmnd *)hostdata->issue_queue; ptr; ptr = NEXT(ptr))
739 show_Scsi_Cmnd(ptr, m);
740
741 seq_printf(m, "scsi%d: disconnected_queue\n", HOSTNO);
742 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr;
743 ptr = NEXT(ptr))
744 show_Scsi_Cmnd(ptr, m);
745
746 local_irq_restore(flags);
747 return 0;
748}
749
750/*
751 * Function : void NCR5380_init (struct Scsi_Host *instance)
752 *
753 * Purpose : initializes *instance and corresponding 5380 chip.
754 *
755 * Inputs : instance - instantiation of the 5380 driver.
756 *
757 * Notes : I assume that the host, hostno, and id bits have been
758 * set correctly. I don't care about the irq and other fields.
759 *
760 */
761
762static int __init NCR5380_init(struct Scsi_Host *instance, int flags)
763{
764 int i;
765 SETUP_HOSTDATA(instance);
766
767 NCR5380_all_init();
768
769 hostdata->aborted = 0;
770 hostdata->id_mask = 1 << instance->this_id;
771 hostdata->id_higher_mask = 0;
772 for (i = hostdata->id_mask; i <= 0x80; i <<= 1)
773 if (i > hostdata->id_mask)
774 hostdata->id_higher_mask |= i;
775 for (i = 0; i < 8; ++i)
776 hostdata->busy[i] = 0;
777#ifdef SUPPORT_TAGS
778 init_tags();
779#endif
780#if defined (REAL_DMA)
781 hostdata->dma_len = 0;
782#endif
783 hostdata->targets_present = 0;
784 hostdata->connected = NULL;
785 hostdata->issue_queue = NULL;
786 hostdata->disconnected_queue = NULL;
787 hostdata->flags = FLAG_CHECK_LAST_BYTE_SENT;
788
789 if (!the_template) {
790 the_template = instance->hostt;
791 first_instance = instance;
792 }
793
794
795#ifndef AUTOSENSE
796 if ((instance->cmd_per_lun > 1) || (instance->can_queue > 1))
797 printk("scsi%d: WARNING : support for multiple outstanding commands enabled\n"
798 " without AUTOSENSE option, contingent allegiance conditions may\n"
799 " be incorrectly cleared.\n", HOSTNO);
800#endif /* def AUTOSENSE */
801
802 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
803 NCR5380_write(MODE_REG, MR_BASE);
804 NCR5380_write(TARGET_COMMAND_REG, 0);
805 NCR5380_write(SELECT_ENABLE_REG, 0);
806
807 return 0;
808}
809
810static void NCR5380_exit(struct Scsi_Host *instance)
811{
812 /* Empty, as we didn't schedule any delayed work */
813}
814
815/*
816 * Function : int NCR5380_queue_command (struct scsi_cmnd *cmd,
817 * void (*done)(struct scsi_cmnd *))
818 *
819 * Purpose : enqueues a SCSI command
820 *
821 * Inputs : cmd - SCSI command, done - function called on completion, with
822 * a pointer to the command descriptor.
823 *
824 * Returns : 0
825 *
826 * Side effects :
827 * cmd is added to the per instance issue_queue, with minor
828 * twiddling done to the host specific fields of cmd. If the
829 * main coroutine is not running, it is restarted.
830 *
831 */
832
833/* Only make static if a wrapper function is used */
834static int NCR5380_queue_command_lck(struct scsi_cmnd *cmd,
835 void (*done)(struct scsi_cmnd *))
836{
837 SETUP_HOSTDATA(cmd->device->host);
838 struct scsi_cmnd *tmp;
839 unsigned long flags;
840
841#if (NDEBUG & NDEBUG_NO_WRITE)
842 switch (cmd->cmnd[0]) {
843 case WRITE_6:
844 case WRITE_10:
845 printk(KERN_NOTICE "scsi%d: WRITE attempted with NO_WRITE debugging flag set\n",
846 H_NO(cmd));
847 cmd->result = (DID_ERROR << 16);
848 done(cmd);
849 return 0;
850 }
851#endif /* (NDEBUG & NDEBUG_NO_WRITE) */
852
853
854#ifdef NCR5380_STATS
855# if 0
856 if (!hostdata->connected && !hostdata->issue_queue &&
857 !hostdata->disconnected_queue) {
858 hostdata->timebase = jiffies;
859 }
860# endif
861# ifdef NCR5380_STAT_LIMIT
862 if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
863# endif
864 switch (cmd->cmnd[0])
865 {
866 case WRITE:
867 case WRITE_6:
868 case WRITE_10:
869 hostdata->time_write[cmd->device->id] -= (jiffies - hostdata->timebase);
870 hostdata->bytes_write[cmd->device->id] += scsi_bufflen(cmd);
871 hostdata->pendingw++;
872 break;
873 case READ:
874 case READ_6:
875 case READ_10:
876 hostdata->time_read[cmd->device->id] -= (jiffies - hostdata->timebase);
877 hostdata->bytes_read[cmd->device->id] += scsi_bufflen(cmd);
878 hostdata->pendingr++;
879 break;
880 }
881#endif
882
883 /*
884 * We use the host_scribble field as a pointer to the next command
885 * in a queue
886 */
887
888 SET_NEXT(cmd, NULL);
889 cmd->scsi_done = done;
890
891 cmd->result = 0;
892
893
894 /*
895 * Insert the cmd into the issue queue. Note that REQUEST SENSE
896 * commands are added to the head of the queue since any command will
897 * clear the contingent allegiance condition that exists and the
898 * sense data is only guaranteed to be valid while the condition exists.
899 */
900
901 local_irq_save(flags);
902 /* ++guenther: now that the issue queue is being set up, we can lock ST-DMA.
903 * Otherwise a running NCR5380_main may steal the lock.
904 * Lock before actually inserting due to fairness reasons explained in
905 * atari_scsi.c. If we insert first, then it's impossible for this driver
906 * to release the lock.
907 * Stop timer for this command while waiting for the lock, or timeouts
908 * may happen (and they really do), and it's no good if the command doesn't
909 * appear in any of the queues.
910 * ++roman: Just disabling the NCR interrupt isn't sufficient here,
911 * because also a timer int can trigger an abort or reset, which would
912 * alter queues and touch the lock.
913 */
914 if (!(hostdata->issue_queue) || (cmd->cmnd[0] == REQUEST_SENSE)) {
915 LIST(cmd, hostdata->issue_queue);
916 SET_NEXT(cmd, hostdata->issue_queue);
917 hostdata->issue_queue = cmd;
918 } else {
919 for (tmp = (struct scsi_cmnd *)hostdata->issue_queue;
920 NEXT(tmp); tmp = NEXT(tmp))
921 ;
922 LIST(cmd, tmp);
923 SET_NEXT(tmp, cmd);
924 }
925
926 local_irq_restore(flags);
927
928 dprintk(NDEBUG_QUEUES, "scsi%d: command added to %s of queue\n", H_NO(cmd),
929 (cmd->cmnd[0] == REQUEST_SENSE) ? "head" : "tail");
930
931 /* If queue_command() is called from an interrupt (real one or bottom
932 * half), we let queue_main() do the job of taking care about main. If it
933 * is already running, this is a no-op, else main will be queued.
934 *
935 * If we're not in an interrupt, we can call NCR5380_main()
936 * unconditionally, because it cannot be already running.
937 */
938 if (in_interrupt() || ((flags >> 8) & 7) >= 6)
939 queue_main();
940 else
941 NCR5380_main(NULL);
942 return 0;
943}
944
945static DEF_SCSI_QCMD(NCR5380_queue_command)
946
947/*
948 * Function : NCR5380_main (void)
949 *
950 * Purpose : NCR5380_main is a coroutine that runs as long as more work can
951 * be done on the NCR5380 host adapters in a system. Both
952 * NCR5380_queue_command() and NCR5380_intr() will try to start it
953 * in case it is not running.
954 *
955 * NOTE : NCR5380_main exits with interrupts *disabled*, the caller should
956 * reenable them. This prevents reentrancy and kernel stack overflow.
957 */
958
959static void NCR5380_main (struct work_struct *bl)
960{
961 struct scsi_cmnd *tmp, *prev;
962 struct Scsi_Host *instance = first_instance;
963 struct NCR5380_hostdata *hostdata = HOSTDATA(instance);
964 int done;
965 unsigned long flags;
966
967 /*
968 * We run (with interrupts disabled) until we're sure that none of
969 * the host adapters have anything that can be done, at which point
970 * we set main_running to 0 and exit.
971 *
972 * Interrupts are enabled before doing various other internal
973 * instructions, after we've decided that we need to run through
974 * the loop again.
975 *
976 * this should prevent any race conditions.
977 *
978 * ++roman: Just disabling the NCR interrupt isn't sufficient here,
979 * because also a timer int can trigger an abort or reset, which can
980 * alter queues and touch the Falcon lock.
981 */
982
983 /* Tell int handlers main() is now already executing. Note that
984 no races are possible here. If an int comes in before
985 'main_running' is set here, and queues/executes main via the
986 task queue, it doesn't do any harm, just this instance of main
987 won't find any work left to do. */
988 if (main_running)
989 return;
990 main_running = 1;
991
992 local_save_flags(flags);
993 do {
994 local_irq_disable(); /* Freeze request queues */
995 done = 1;
996
997 if (!hostdata->connected) {
998 dprintk(NDEBUG_MAIN, "scsi%d: not connected\n", HOSTNO );
999 /*
1000 * Search through the issue_queue for a command destined
1001 * for a target that's not busy.
1002 */
1003#if (NDEBUG & NDEBUG_LISTS)
1004 for (tmp = (struct scsi_cmnd *) hostdata->issue_queue, prev = NULL;
1005 tmp && (tmp != prev); prev = tmp, tmp = NEXT(tmp))
1006 ;
1007 if ((tmp == prev) && tmp) printk(" LOOP\n");/* else printk("\n");*/
1008#endif
1009 for (tmp = (struct scsi_cmnd *) hostdata->issue_queue,
1010 prev = NULL; tmp; prev = tmp, tmp = NEXT(tmp) ) {
1011
1012 if (prev != tmp)
1013 dprintk(NDEBUG_LISTS, "MAIN tmp=%p target=%d busy=%d lun=%llu\n", tmp, tmp->device->id, hostdata->busy[tmp->device->id], tmp->device->lun);
1014 /* When we find one, remove it from the issue queue. */
1015 /* ++guenther: possible race with Falcon locking */
1016 if (
1017#ifdef SUPPORT_TAGS
1018 !is_lun_busy( tmp, tmp->cmnd[0] != REQUEST_SENSE)
1019#else
1020 !(hostdata->busy[tmp->device->id] & (1 << tmp->device->lun))
1021#endif
1022 ) {
1023 /* ++guenther: just to be sure, this must be atomic */
1024 local_irq_disable();
1025 if (prev) {
1026 REMOVE(prev, NEXT(prev), tmp, NEXT(tmp));
1027 SET_NEXT(prev, NEXT(tmp));
1028 } else {
1029 REMOVE(-1, hostdata->issue_queue, tmp, NEXT(tmp));
1030 hostdata->issue_queue = NEXT(tmp);
1031 }
1032 SET_NEXT(tmp, NULL);
1033
1034 /* reenable interrupts after finding one */
1035 local_irq_restore(flags);
1036
1037 /*
1038 * Attempt to establish an I_T_L nexus here.
1039 * On success, instance->hostdata->connected is set.
1040 * On failure, we must add the command back to the
1041 * issue queue so we can keep trying.
1042 */
1043 dprintk(NDEBUG_MAIN, "scsi%d: main(): command for target %d "
1044 "lun %llu removed from issue_queue\n",
1045 HOSTNO, tmp->device->id, tmp->device->lun);
1046 /*
1047 * REQUEST SENSE commands are issued without tagged
1048 * queueing, even on SCSI-II devices because the
1049 * contingent allegiance condition exists for the
1050 * entire unit.
1051 */
1052 /* ++roman: ...and the standard also requires that
1053 * REQUEST SENSE command are untagged.
1054 */
1055
1056#ifdef SUPPORT_TAGS
1057 cmd_get_tag( tmp, tmp->cmnd[0] != REQUEST_SENSE );
1058#endif
1059 if (!NCR5380_select(instance, tmp,
1060 (tmp->cmnd[0] == REQUEST_SENSE) ? TAG_NONE :
1061 TAG_NEXT)) {
1062 break;
1063 } else {
1064 local_irq_disable();
1065 LIST(tmp, hostdata->issue_queue);
1066 SET_NEXT(tmp, hostdata->issue_queue);
1067 hostdata->issue_queue = tmp;
1068#ifdef SUPPORT_TAGS
1069 cmd_free_tag( tmp );
1070#endif
1071 local_irq_restore(flags);
1072 dprintk(NDEBUG_MAIN, "scsi%d: main(): select() failed, "
1073 "returned to issue_queue\n", HOSTNO);
1074 if (hostdata->connected)
1075 break;
1076 }
1077 } /* if target/lun/target queue is not busy */
1078 } /* for issue_queue */
1079 } /* if (!hostdata->connected) */
1080 if (hostdata->connected
1081#ifdef REAL_DMA
1082 && !hostdata->dma_len
1083#endif
1084 ) {
1085 local_irq_restore(flags);
1086 dprintk(NDEBUG_MAIN, "scsi%d: main: performing information transfer\n",
1087 HOSTNO);
1088 NCR5380_information_transfer(instance);
1089 dprintk(NDEBUG_MAIN, "scsi%d: main: done set false\n", HOSTNO);
1090 done = 0;
1091 }
1092 } while (!done);
1093
1094 /* Better allow ints _after_ 'main_running' has been cleared, else
1095 an interrupt could believe we'll pick up the work it left for
1096 us, but we won't see it anymore here... */
1097 main_running = 0;
1098 local_irq_restore(flags);
1099}
1100
1101
1102#ifdef REAL_DMA
1103/*
1104 * Function : void NCR5380_dma_complete (struct Scsi_Host *instance)
1105 *
1106 * Purpose : Called by interrupt handler when DMA finishes or a phase
1107 * mismatch occurs (which would finish the DMA transfer).
1108 *
1109 * Inputs : instance - this instance of the NCR5380.
1110 *
1111 */
1112
1113static void NCR5380_dma_complete( struct Scsi_Host *instance )
1114{
1115 SETUP_HOSTDATA(instance);
1116 int transfered;
1117 unsigned char **data;
1118 volatile int *count;
1119
1120 if (!hostdata->connected) {
1121 printk(KERN_WARNING "scsi%d: received end of DMA interrupt with "
1122 "no connected cmd\n", HOSTNO);
1123 return;
1124 }
1125
1126 dprintk(NDEBUG_DMA, "scsi%d: real DMA transfer complete, basr 0x%X, sr 0x%X\n",
1127 HOSTNO, NCR5380_read(BUS_AND_STATUS_REG),
1128 NCR5380_read(STATUS_REG));
1129
1130 if((sun3scsi_dma_finish(rq_data_dir(hostdata->connected->request)))) {
1131 printk("scsi%d: overrun in UDC counter -- not prepared to deal with this!\n", HOSTNO);
1132 printk("please e-mail sammy@sammy.net with a description of how this\n");
1133 printk("error was produced.\n");
1134 BUG();
1135 }
1136
1137 /* make sure we're not stuck in a data phase */
1138 if((NCR5380_read(BUS_AND_STATUS_REG) & (BASR_PHASE_MATCH |
1139 BASR_ACK)) ==
1140 (BASR_PHASE_MATCH | BASR_ACK)) {
1141 printk("scsi%d: BASR %02x\n", HOSTNO, NCR5380_read(BUS_AND_STATUS_REG));
1142 printk("scsi%d: bus stuck in data phase -- probably a single byte "
1143 "overrun!\n", HOSTNO);
1144 printk("not prepared for this error!\n");
1145 printk("please e-mail sammy@sammy.net with a description of how this\n");
1146 printk("error was produced.\n");
1147 BUG();
1148 }
1149
1150
1151
1152 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1153 NCR5380_write(MODE_REG, MR_BASE);
1154 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1155
1156 transfered = hostdata->dma_len - NCR5380_dma_residual(instance);
1157 hostdata->dma_len = 0;
1158
1159 data = (unsigned char **) &(hostdata->connected->SCp.ptr);
1160 count = &(hostdata->connected->SCp.this_residual);
1161 *data += transfered;
1162 *count -= transfered;
1163
1164}
1165#endif /* REAL_DMA */
1166
1167
1168/*
1169 * Function : void NCR5380_intr (int irq)
1170 *
1171 * Purpose : handle interrupts, reestablishing I_T_L or I_T_L_Q nexuses
1172 * from the disconnected queue, and restarting NCR5380_main()
1173 * as required.
1174 *
1175 * Inputs : int irq, irq that caused this interrupt.
1176 *
1177 */
1178
1179static irqreturn_t NCR5380_intr (int irq, void *dev_id)
1180{
1181 struct Scsi_Host *instance = first_instance;
1182 int done = 1, handled = 0;
1183 unsigned char basr;
1184
1185 dprintk(NDEBUG_INTR, "scsi%d: NCR5380 irq triggered\n", HOSTNO);
1186
1187 /* Look for pending interrupts */
1188 basr = NCR5380_read(BUS_AND_STATUS_REG);
1189 dprintk(NDEBUG_INTR, "scsi%d: BASR=%02x\n", HOSTNO, basr);
1190 /* dispatch to appropriate routine if found and done=0 */
1191 if (basr & BASR_IRQ) {
1192 NCR5380_dprint(NDEBUG_INTR, instance);
1193 if ((NCR5380_read(STATUS_REG) & (SR_SEL|SR_IO)) == (SR_SEL|SR_IO)) {
1194 done = 0;
1195// ENABLE_IRQ();
1196 dprintk(NDEBUG_INTR, "scsi%d: SEL interrupt\n", HOSTNO);
1197 NCR5380_reselect(instance);
1198 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1199 }
1200 else if (basr & BASR_PARITY_ERROR) {
1201 dprintk(NDEBUG_INTR, "scsi%d: PARITY interrupt\n", HOSTNO);
1202 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1203 }
1204 else if ((NCR5380_read(STATUS_REG) & SR_RST) == SR_RST) {
1205 dprintk(NDEBUG_INTR, "scsi%d: RESET interrupt\n", HOSTNO);
1206 (void)NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1207 }
1208 else {
1209 /*
1210 * The rest of the interrupt conditions can occur only during a
1211 * DMA transfer
1212 */
1213
1214#if defined(REAL_DMA)
1215 /*
1216 * We should only get PHASE MISMATCH and EOP interrupts if we have
1217 * DMA enabled, so do a sanity check based on the current setting
1218 * of the MODE register.
1219 */
1220
1221 if ((NCR5380_read(MODE_REG) & MR_DMA_MODE) &&
1222 ((basr & BASR_END_DMA_TRANSFER) ||
1223 !(basr & BASR_PHASE_MATCH))) {
1224
1225 dprintk(NDEBUG_INTR, "scsi%d: PHASE MISM or EOP interrupt\n", HOSTNO);
1226 NCR5380_dma_complete( instance );
1227 done = 0;
1228// ENABLE_IRQ();
1229 } else
1230#endif /* REAL_DMA */
1231 {
1232/* MS: Ignore unknown phase mismatch interrupts (caused by EOP interrupt) */
1233 if (basr & BASR_PHASE_MATCH)
1234 dprintk(NDEBUG_INTR, "scsi%d: unknown interrupt, "
1235 "BASR 0x%x, MR 0x%x, SR 0x%x\n",
1236 HOSTNO, basr, NCR5380_read(MODE_REG),
1237 NCR5380_read(STATUS_REG));
1238 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1239#ifdef SUN3_SCSI_VME
1240 dregs->csr |= CSR_DMA_ENABLE;
1241#endif
1242 }
1243 } /* if !(SELECTION || PARITY) */
1244 handled = 1;
1245 } /* BASR & IRQ */
1246 else {
1247
1248 printk(KERN_NOTICE "scsi%d: interrupt without IRQ bit set in BASR, "
1249 "BASR 0x%X, MR 0x%X, SR 0x%x\n", HOSTNO, basr,
1250 NCR5380_read(MODE_REG), NCR5380_read(STATUS_REG));
1251 (void) NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1252#ifdef SUN3_SCSI_VME
1253 dregs->csr |= CSR_DMA_ENABLE;
1254#endif
1255 }
1256
1257 if (!done) {
1258 dprintk(NDEBUG_INTR, "scsi%d: in int routine, calling main\n", HOSTNO);
1259 /* Put a call to NCR5380_main() on the queue... */
1260 queue_main();
1261 }
1262 return IRQ_RETVAL(handled);
1263}
1264
1265#ifdef NCR5380_STATS
1266static void collect_stats(struct NCR5380_hostdata *hostdata,
1267 struct scsi_cmnd *cmd)
1268{
1269# ifdef NCR5380_STAT_LIMIT
1270 if (scsi_bufflen(cmd) > NCR5380_STAT_LIMIT)
1271# endif
1272 switch (cmd->cmnd[0])
1273 {
1274 case WRITE:
1275 case WRITE_6:
1276 case WRITE_10:
1277 hostdata->time_write[cmd->device->id] += (jiffies - hostdata->timebase);
1278 /*hostdata->bytes_write[cmd->device->id] += scsi_bufflen(cmd);*/
1279 hostdata->pendingw--;
1280 break;
1281 case READ:
1282 case READ_6:
1283 case READ_10:
1284 hostdata->time_read[cmd->device->id] += (jiffies - hostdata->timebase);
1285 /*hostdata->bytes_read[cmd->device->id] += scsi_bufflen(cmd);*/
1286 hostdata->pendingr--;
1287 break;
1288 }
1289}
1290#endif
1291
1292/*
1293 * Function : int NCR5380_select(struct Scsi_Host *instance,
1294 * struct scsi_cmnd *cmd, int tag);
1295 *
1296 * Purpose : establishes I_T_L or I_T_L_Q nexus for new or existing command,
1297 * including ARBITRATION, SELECTION, and initial message out for
1298 * IDENTIFY and queue messages.
1299 *
1300 * Inputs : instance - instantiation of the 5380 driver on which this
1301 * target lives, cmd - SCSI command to execute, tag - set to TAG_NEXT for
1302 * new tag, TAG_NONE for untagged queueing, otherwise set to the tag for
1303 * the command that is presently connected.
1304 *
1305 * Returns : -1 if selection could not execute for some reason,
1306 * 0 if selection succeeded or failed because the target
1307 * did not respond.
1308 *
1309 * Side effects :
1310 * If bus busy, arbitration failed, etc, NCR5380_select() will exit
1311 * with registers as they should have been on entry - ie
1312 * SELECT_ENABLE will be set appropriately, the NCR5380
1313 * will cease to drive any SCSI bus signals.
1314 *
1315 * If successful : I_T_L or I_T_L_Q nexus will be established,
1316 * instance->connected will be set to cmd.
1317 * SELECT interrupt will be disabled.
1318 *
1319 * If failed (no target) : cmd->scsi_done() will be called, and the
1320 * cmd->result host byte set to DID_BAD_TARGET.
1321 */
1322
1323static int NCR5380_select(struct Scsi_Host *instance, struct scsi_cmnd *cmd,
1324 int tag)
1325{
1326 SETUP_HOSTDATA(instance);
1327 unsigned char tmp[3], phase;
1328 unsigned char *data;
1329 int len;
1330 unsigned long timeout;
1331 unsigned long flags;
1332
1333 hostdata->restart_select = 0;
1334 NCR5380_dprint(NDEBUG_ARBITRATION, instance);
1335 dprintk(NDEBUG_ARBITRATION, "scsi%d: starting arbitration, id = %d\n", HOSTNO,
1336 instance->this_id);
1337
1338 /*
1339 * Set the phase bits to 0, otherwise the NCR5380 won't drive the
1340 * data bus during SELECTION.
1341 */
1342
1343 local_irq_save(flags);
1344 if (hostdata->connected) {
1345 local_irq_restore(flags);
1346 return -1;
1347 }
1348 NCR5380_write(TARGET_COMMAND_REG, 0);
1349
1350
1351 /*
1352 * Start arbitration.
1353 */
1354
1355 NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
1356 NCR5380_write(MODE_REG, MR_ARBITRATE);
1357
1358 local_irq_restore(flags);
1359
1360 /* Wait for arbitration logic to complete */
1361#ifdef NCR_TIMEOUT
1362 {
1363 unsigned long timeout = jiffies + 2*NCR_TIMEOUT;
1364
1365 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS)
1366 && time_before(jiffies, timeout) && !hostdata->connected)
1367 ;
1368 if (time_after_eq(jiffies, timeout))
1369 {
1370 printk("scsi : arbitration timeout at %d\n", __LINE__);
1371 NCR5380_write(MODE_REG, MR_BASE);
1372 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1373 return -1;
1374 }
1375 }
1376#else /* NCR_TIMEOUT */
1377 while (!(NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_PROGRESS)
1378 && !hostdata->connected);
1379#endif
1380
1381 dprintk(NDEBUG_ARBITRATION, "scsi%d: arbitration complete\n", HOSTNO);
1382
1383 if (hostdata->connected) {
1384 NCR5380_write(MODE_REG, MR_BASE);
1385 return -1;
1386 }
1387 /*
1388 * The arbitration delay is 2.2us, but this is a minimum and there is
1389 * no maximum so we can safely sleep for ceil(2.2) usecs to accommodate
1390 * the integral nature of udelay().
1391 *
1392 */
1393
1394 udelay(3);
1395
1396 /* Check for lost arbitration */
1397 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1398 (NCR5380_read(CURRENT_SCSI_DATA_REG) & hostdata->id_higher_mask) ||
1399 (NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1400 hostdata->connected) {
1401 NCR5380_write(MODE_REG, MR_BASE);
1402 dprintk(NDEBUG_ARBITRATION, "scsi%d: lost arbitration, deasserting MR_ARBITRATE\n",
1403 HOSTNO);
1404 return -1;
1405 }
1406
1407 /* after/during arbitration, BSY should be asserted.
1408 IBM DPES-31080 Version S31Q works now */
1409 /* Tnx to Thomas_Roesch@m2.maus.de for finding this! (Roman) */
1410 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_SEL |
1411 ICR_ASSERT_BSY ) ;
1412
1413 if ((NCR5380_read(INITIATOR_COMMAND_REG) & ICR_ARBITRATION_LOST) ||
1414 hostdata->connected) {
1415 NCR5380_write(MODE_REG, MR_BASE);
1416 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1417 dprintk(NDEBUG_ARBITRATION, "scsi%d: lost arbitration, deasserting ICR_ASSERT_SEL\n",
1418 HOSTNO);
1419 return -1;
1420 }
1421
1422 /*
1423 * Again, bus clear + bus settle time is 1.2us, however, this is
1424 * a minimum so we'll udelay ceil(1.2)
1425 */
1426
1427#ifdef CONFIG_ATARI_SCSI_TOSHIBA_DELAY
1428 /* ++roman: But some targets (see above :-) seem to need a bit more... */
1429 udelay(15);
1430#else
1431 udelay(2);
1432#endif
1433
1434 if (hostdata->connected) {
1435 NCR5380_write(MODE_REG, MR_BASE);
1436 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1437 return -1;
1438 }
1439
1440 dprintk(NDEBUG_ARBITRATION, "scsi%d: won arbitration\n", HOSTNO);
1441
1442 /*
1443 * Now that we have won arbitration, start Selection process, asserting
1444 * the host and target ID's on the SCSI bus.
1445 */
1446
1447 NCR5380_write(OUTPUT_DATA_REG, (hostdata->id_mask | (1 << cmd->device->id)));
1448
1449 /*
1450 * Raise ATN while SEL is true before BSY goes false from arbitration,
1451 * since this is the only way to guarantee that we'll get a MESSAGE OUT
1452 * phase immediately after selection.
1453 */
1454
1455 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_BSY |
1456 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_SEL ));
1457 NCR5380_write(MODE_REG, MR_BASE);
1458
1459 /*
1460 * Reselect interrupts must be turned off prior to the dropping of BSY,
1461 * otherwise we will trigger an interrupt.
1462 */
1463
1464 if (hostdata->connected) {
1465 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1466 return -1;
1467 }
1468
1469 NCR5380_write(SELECT_ENABLE_REG, 0);
1470
1471 /*
1472 * The initiator shall then wait at least two deskew delays and release
1473 * the BSY signal.
1474 */
1475 udelay(1); /* wingel -- wait two bus deskew delay >2*45ns */
1476
1477 /* Reset BSY */
1478 NCR5380_write(INITIATOR_COMMAND_REG, (ICR_BASE | ICR_ASSERT_DATA |
1479 ICR_ASSERT_ATN | ICR_ASSERT_SEL));
1480
1481 /*
1482 * Something weird happens when we cease to drive BSY - looks
1483 * like the board/chip is letting us do another read before the
1484 * appropriate propagation delay has expired, and we're confusing
1485 * a BSY signal from ourselves as the target's response to SELECTION.
1486 *
1487 * A small delay (the 'C++' frontend breaks the pipeline with an
1488 * unnecessary jump, making it work on my 386-33/Trantor T128, the
1489 * tighter 'C' code breaks and requires this) solves the problem -
1490 * the 1 us delay is arbitrary, and only used because this delay will
1491 * be the same on other platforms and since it works here, it should
1492 * work there.
1493 *
1494 * wingel suggests that this could be due to failing to wait
1495 * one deskew delay.
1496 */
1497
1498 udelay(1);
1499
1500 dprintk(NDEBUG_SELECTION, "scsi%d: selecting target %d\n", HOSTNO, cmd->device->id);
1501
1502 /*
1503 * The SCSI specification calls for a 250 ms timeout for the actual
1504 * selection.
1505 */
1506
1507 timeout = jiffies + 25;
1508
1509 /*
1510 * XXX very interesting - we're seeing a bounce where the BSY we
1511 * asserted is being reflected / still asserted (propagation delay?)
1512 * and it's detecting as true. Sigh.
1513 */
1514
1515#if 0
1516 /* ++roman: If a target conformed to the SCSI standard, it wouldn't assert
1517 * IO while SEL is true. But again, there are some disks out the in the
1518 * world that do that nevertheless. (Somebody claimed that this announces
1519 * reselection capability of the target.) So we better skip that test and
1520 * only wait for BSY... (Famous german words: Der Klügere gibt nach :-)
1521 */
1522
1523 while (time_before(jiffies, timeout) && !(NCR5380_read(STATUS_REG) &
1524 (SR_BSY | SR_IO)));
1525
1526 if ((NCR5380_read(STATUS_REG) & (SR_SEL | SR_IO)) ==
1527 (SR_SEL | SR_IO)) {
1528 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1529 NCR5380_reselect(instance);
1530 printk (KERN_ERR "scsi%d: reselection after won arbitration?\n",
1531 HOSTNO);
1532 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1533 return -1;
1534 }
1535#else
1536 while (time_before(jiffies, timeout) && !(NCR5380_read(STATUS_REG) & SR_BSY));
1537#endif
1538
1539 /*
1540 * No less than two deskew delays after the initiator detects the
1541 * BSY signal is true, it shall release the SEL signal and may
1542 * change the DATA BUS. -wingel
1543 */
1544
1545 udelay(1);
1546
1547 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1548
1549 if (!(NCR5380_read(STATUS_REG) & SR_BSY)) {
1550 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1551 if (hostdata->targets_present & (1 << cmd->device->id)) {
1552 printk(KERN_ERR "scsi%d: weirdness\n", HOSTNO);
1553 if (hostdata->restart_select)
1554 printk(KERN_NOTICE "\trestart select\n");
1555 NCR5380_dprint(NDEBUG_ANY, instance);
1556 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1557 return -1;
1558 }
1559 cmd->result = DID_BAD_TARGET << 16;
1560#ifdef NCR5380_STATS
1561 collect_stats(hostdata, cmd);
1562#endif
1563#ifdef SUPPORT_TAGS
1564 cmd_free_tag( cmd );
1565#endif
1566 cmd->scsi_done(cmd);
1567 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1568 dprintk(NDEBUG_SELECTION, "scsi%d: target did not respond within 250ms\n", HOSTNO);
1569 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
1570 return 0;
1571 }
1572
1573 hostdata->targets_present |= (1 << cmd->device->id);
1574
1575 /*
1576 * Since we followed the SCSI spec, and raised ATN while SEL
1577 * was true but before BSY was false during selection, the information
1578 * transfer phase should be a MESSAGE OUT phase so that we can send the
1579 * IDENTIFY message.
1580 *
1581 * If SCSI-II tagged queuing is enabled, we also send a SIMPLE_QUEUE_TAG
1582 * message (2 bytes) with a tag ID that we increment with every command
1583 * until it wraps back to 0.
1584 *
1585 * XXX - it turns out that there are some broken SCSI-II devices,
1586 * which claim to support tagged queuing but fail when more than
1587 * some number of commands are issued at once.
1588 */
1589
1590 /* Wait for start of REQ/ACK handshake */
1591 while (!(NCR5380_read(STATUS_REG) & SR_REQ));
1592
1593 dprintk(NDEBUG_SELECTION, "scsi%d: target %d selected, going into MESSAGE OUT phase.\n",
1594 HOSTNO, cmd->device->id);
1595 tmp[0] = IDENTIFY(1, cmd->device->lun);
1596
1597#ifdef SUPPORT_TAGS
1598 if (cmd->tag != TAG_NONE) {
1599 tmp[1] = hostdata->last_message = SIMPLE_QUEUE_TAG;
1600 tmp[2] = cmd->tag;
1601 len = 3;
1602 } else
1603 len = 1;
1604#else
1605 len = 1;
1606 cmd->tag=0;
1607#endif /* SUPPORT_TAGS */
1608
1609 /* Send message(s) */
1610 data = tmp;
1611 phase = PHASE_MSGOUT;
1612 NCR5380_transfer_pio(instance, &phase, &len, &data);
1613 dprintk(NDEBUG_SELECTION, "scsi%d: nexus established.\n", HOSTNO);
1614 /* XXX need to handle errors here */
1615 hostdata->connected = cmd;
1616#ifndef SUPPORT_TAGS
1617 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
1618#endif
1619#ifdef SUN3_SCSI_VME
1620 dregs->csr |= CSR_INTR;
1621#endif
1622 initialize_SCp(cmd);
1623
1624
1625 return 0;
1626}
1627
1628/*
1629 * Function : int NCR5380_transfer_pio (struct Scsi_Host *instance,
1630 * unsigned char *phase, int *count, unsigned char **data)
1631 *
1632 * Purpose : transfers data in given phase using polled I/O
1633 *
1634 * Inputs : instance - instance of driver, *phase - pointer to
1635 * what phase is expected, *count - pointer to number of
1636 * bytes to transfer, **data - pointer to data pointer.
1637 *
1638 * Returns : -1 when different phase is entered without transferring
1639 * maximum number of bytes, 0 if all bytes are transferred or exit
1640 * is in same phase.
1641 *
1642 * Also, *phase, *count, *data are modified in place.
1643 *
1644 * XXX Note : handling for bus free may be useful.
1645 */
1646
1647/*
1648 * Note : this code is not as quick as it could be, however it
1649 * IS 100% reliable, and for the actual data transfer where speed
1650 * counts, we will always do a pseudo DMA or DMA transfer.
1651 */
1652
1653static int NCR5380_transfer_pio( struct Scsi_Host *instance,
1654 unsigned char *phase, int *count,
1655 unsigned char **data)
1656{
1657 register unsigned char p = *phase, tmp;
1658 register int c = *count;
1659 register unsigned char *d = *data;
1660
1661 /*
1662 * The NCR5380 chip will only drive the SCSI bus when the
1663 * phase specified in the appropriate bits of the TARGET COMMAND
1664 * REGISTER match the STATUS REGISTER
1665 */
1666
1667 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(p));
1668
1669 do {
1670 /*
1671 * Wait for assertion of REQ, after which the phase bits will be
1672 * valid
1673 */
1674 while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ));
1675
1676 dprintk(NDEBUG_HANDSHAKE, "scsi%d: REQ detected\n", HOSTNO);
1677
1678 /* Check for phase mismatch */
1679 if ((tmp & PHASE_MASK) != p) {
1680 dprintk(NDEBUG_PIO, "scsi%d: phase mismatch\n", HOSTNO);
1681 NCR5380_dprint_phase(NDEBUG_PIO, instance);
1682 break;
1683 }
1684
1685 /* Do actual transfer from SCSI bus to / from memory */
1686 if (!(p & SR_IO))
1687 NCR5380_write(OUTPUT_DATA_REG, *d);
1688 else
1689 *d = NCR5380_read(CURRENT_SCSI_DATA_REG);
1690
1691 ++d;
1692
1693 /*
1694 * The SCSI standard suggests that in MSGOUT phase, the initiator
1695 * should drop ATN on the last byte of the message phase
1696 * after REQ has been asserted for the handshake but before
1697 * the initiator raises ACK.
1698 */
1699
1700 if (!(p & SR_IO)) {
1701 if (!((p & SR_MSG) && c > 1)) {
1702 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1703 ICR_ASSERT_DATA);
1704 NCR5380_dprint(NDEBUG_PIO, instance);
1705 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1706 ICR_ASSERT_DATA | ICR_ASSERT_ACK);
1707 } else {
1708 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1709 ICR_ASSERT_DATA | ICR_ASSERT_ATN);
1710 NCR5380_dprint(NDEBUG_PIO, instance);
1711 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1712 ICR_ASSERT_DATA | ICR_ASSERT_ATN | ICR_ASSERT_ACK);
1713 }
1714 } else {
1715 NCR5380_dprint(NDEBUG_PIO, instance);
1716 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
1717 }
1718
1719 while (NCR5380_read(STATUS_REG) & SR_REQ);
1720
1721 dprintk(NDEBUG_HANDSHAKE, "scsi%d: req false, handshake complete\n", HOSTNO);
1722
1723/*
1724 * We have several special cases to consider during REQ/ACK handshaking :
1725 * 1. We were in MSGOUT phase, and we are on the last byte of the
1726 * message. ATN must be dropped as ACK is dropped.
1727 *
1728 * 2. We are in a MSGIN phase, and we are on the last byte of the
1729 * message. We must exit with ACK asserted, so that the calling
1730 * code may raise ATN before dropping ACK to reject the message.
1731 *
1732 * 3. ACK and ATN are clear and the target may proceed as normal.
1733 */
1734 if (!(p == PHASE_MSGIN && c == 1)) {
1735 if (p == PHASE_MSGOUT && c > 1)
1736 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1737 else
1738 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
1739 }
1740 } while (--c);
1741
1742 dprintk(NDEBUG_PIO, "scsi%d: residual %d\n", HOSTNO, c);
1743
1744 *count = c;
1745 *data = d;
1746 tmp = NCR5380_read(STATUS_REG);
1747 /* The phase read from the bus is valid if either REQ is (already)
1748 * asserted or if ACK hasn't been released yet. The latter is the case if
1749 * we're in MSGIN and all wanted bytes have been received. */
1750 if ((tmp & SR_REQ) || (p == PHASE_MSGIN && c == 0))
1751 *phase = tmp & PHASE_MASK;
1752 else
1753 *phase = PHASE_UNKNOWN;
1754
1755 if (!c || (*phase == p))
1756 return 0;
1757 else
1758 return -1;
1759}
1760
1761/*
1762 * Function : do_abort (Scsi_Host *host)
1763 *
1764 * Purpose : abort the currently established nexus. Should only be
1765 * called from a routine which can drop into a
1766 *
1767 * Returns : 0 on success, -1 on failure.
1768 */
1769
1770static int do_abort (struct Scsi_Host *host)
1771{
1772 unsigned char tmp, *msgptr, phase;
1773 int len;
1774
1775 /* Request message out phase */
1776 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1777
1778 /*
1779 * Wait for the target to indicate a valid phase by asserting
1780 * REQ. Once this happens, we'll have either a MSGOUT phase
1781 * and can immediately send the ABORT message, or we'll have some
1782 * other phase and will have to source/sink data.
1783 *
1784 * We really don't care what value was on the bus or what value
1785 * the target sees, so we just handshake.
1786 */
1787
1788 while (!((tmp = NCR5380_read(STATUS_REG)) & SR_REQ));
1789
1790 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
1791
1792 if ((tmp & PHASE_MASK) != PHASE_MSGOUT) {
1793 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
1794 ICR_ASSERT_ACK);
1795 while (NCR5380_read(STATUS_REG) & SR_REQ);
1796 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN);
1797 }
1798
1799 tmp = ABORT;
1800 msgptr = &tmp;
1801 len = 1;
1802 phase = PHASE_MSGOUT;
1803 NCR5380_transfer_pio (host, &phase, &len, &msgptr);
1804
1805 /*
1806 * If we got here, and the command completed successfully,
1807 * we're about to go into bus free state.
1808 */
1809
1810 return len ? -1 : 0;
1811}
1812
1813#if defined(REAL_DMA)
1814/*
1815 * Function : int NCR5380_transfer_dma (struct Scsi_Host *instance,
1816 * unsigned char *phase, int *count, unsigned char **data)
1817 *
1818 * Purpose : transfers data in given phase using either real
1819 * or pseudo DMA.
1820 *
1821 * Inputs : instance - instance of driver, *phase - pointer to
1822 * what phase is expected, *count - pointer to number of
1823 * bytes to transfer, **data - pointer to data pointer.
1824 *
1825 * Returns : -1 when different phase is entered without transferring
1826 * maximum number of bytes, 0 if all bytes or transferred or exit
1827 * is in same phase.
1828 *
1829 * Also, *phase, *count, *data are modified in place.
1830 *
1831 */
1832
1833
1834static int NCR5380_transfer_dma( struct Scsi_Host *instance,
1835 unsigned char *phase, int *count,
1836 unsigned char **data)
1837{
1838 SETUP_HOSTDATA(instance);
1839 register int c = *count;
1840 register unsigned char p = *phase;
1841 unsigned long flags;
1842
1843 /* sanity check */
1844 if(!sun3_dma_setup_done) {
1845 printk("scsi%d: transfer_dma without setup!\n", HOSTNO);
1846 BUG();
1847 }
1848 hostdata->dma_len = c;
1849
1850 dprintk(NDEBUG_DMA, "scsi%d: initializing DMA for %s, %d bytes %s %p\n",
1851 HOSTNO, (p & SR_IO) ? "reading" : "writing",
1852 c, (p & SR_IO) ? "to" : "from", *data);
1853
1854 /* netbsd turns off ints here, why not be safe and do it too */
1855 local_irq_save(flags);
1856
1857 /* send start chain */
1858 sun3scsi_dma_start(c, *data);
1859
1860 if (p & SR_IO) {
1861 NCR5380_write(TARGET_COMMAND_REG, 1);
1862 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1863 NCR5380_write(INITIATOR_COMMAND_REG, 0);
1864 NCR5380_write(MODE_REG, (NCR5380_read(MODE_REG) | MR_DMA_MODE | MR_ENABLE_EOP_INTR));
1865 NCR5380_write(START_DMA_INITIATOR_RECEIVE_REG, 0);
1866 } else {
1867 NCR5380_write(TARGET_COMMAND_REG, 0);
1868 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
1869 NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_DATA);
1870 NCR5380_write(MODE_REG, (NCR5380_read(MODE_REG) | MR_DMA_MODE | MR_ENABLE_EOP_INTR));
1871 NCR5380_write(START_DMA_SEND_REG, 0);
1872 }
1873
1874#ifdef SUN3_SCSI_VME
1875 dregs->csr |= CSR_DMA_ENABLE;
1876#endif
1877
1878 local_irq_restore(flags);
1879
1880 sun3_dma_active = 1;
1881 return 0;
1882}
1883#endif /* defined(REAL_DMA) */
1884
1885/*
1886 * Function : NCR5380_information_transfer (struct Scsi_Host *instance)
1887 *
1888 * Purpose : run through the various SCSI phases and do as the target
1889 * directs us to. Operates on the currently connected command,
1890 * instance->connected.
1891 *
1892 * Inputs : instance, instance for which we are doing commands
1893 *
1894 * Side effects : SCSI things happen, the disconnected queue will be
1895 * modified if a command disconnects, *instance->connected will
1896 * change.
1897 *
1898 * XXX Note : we need to watch for bus free or a reset condition here
1899 * to recover from an unexpected bus free condition.
1900 */
1901
1902static void NCR5380_information_transfer (struct Scsi_Host *instance)
1903{
1904 SETUP_HOSTDATA(instance);
1905 unsigned long flags;
1906 unsigned char msgout = NOP;
1907 int sink = 0;
1908 int len;
1909#if defined(REAL_DMA)
1910 int transfersize;
1911#endif
1912 unsigned char *data;
1913 unsigned char phase, tmp, extended_msg[10], old_phase=0xff;
1914 struct scsi_cmnd *cmd = (struct scsi_cmnd *) hostdata->connected;
1915
1916#ifdef SUN3_SCSI_VME
1917 dregs->csr |= CSR_INTR;
1918#endif
1919
1920 while (1) {
1921 tmp = NCR5380_read(STATUS_REG);
1922 /* We only have a valid SCSI phase when REQ is asserted */
1923 if (tmp & SR_REQ) {
1924 phase = (tmp & PHASE_MASK);
1925 if (phase != old_phase) {
1926 old_phase = phase;
1927 NCR5380_dprint_phase(NDEBUG_INFORMATION, instance);
1928 }
1929
1930 if(phase == PHASE_CMDOUT) {
1931 void *d;
1932 unsigned long count;
1933
1934 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1935 count = cmd->SCp.buffer->length;
1936 d = SGADDR(cmd->SCp.buffer);
1937 } else {
1938 count = cmd->SCp.this_residual;
1939 d = cmd->SCp.ptr;
1940 }
1941#ifdef REAL_DMA
1942 /* this command setup for dma yet? */
1943 if((count > SUN3_DMA_MINSIZE) && (sun3_dma_setup_done
1944 != cmd))
1945 {
1946 if (cmd->request->cmd_type == REQ_TYPE_FS) {
1947 sun3scsi_dma_setup(d, count,
1948 rq_data_dir(cmd->request));
1949 sun3_dma_setup_done = cmd;
1950 }
1951 }
1952#endif
1953#ifdef SUN3_SCSI_VME
1954 dregs->csr |= CSR_INTR;
1955#endif
1956 }
1957
1958
1959 if (sink && (phase != PHASE_MSGOUT)) {
1960 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(tmp));
1961
1962 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ATN |
1963 ICR_ASSERT_ACK);
1964 while (NCR5380_read(STATUS_REG) & SR_REQ);
1965 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
1966 ICR_ASSERT_ATN);
1967 sink = 0;
1968 continue;
1969 }
1970
1971 switch (phase) {
1972 case PHASE_DATAOUT:
1973#if (NDEBUG & NDEBUG_NO_DATAOUT)
1974 printk("scsi%d: NDEBUG_NO_DATAOUT set, attempted DATAOUT "
1975 "aborted\n", HOSTNO);
1976 sink = 1;
1977 do_abort(instance);
1978 cmd->result = DID_ERROR << 16;
1979 cmd->scsi_done(cmd);
1980 return;
1981#endif
1982 case PHASE_DATAIN:
1983 /*
1984 * If there is no room left in the current buffer in the
1985 * scatter-gather list, move onto the next one.
1986 */
1987 if (!cmd->SCp.this_residual && cmd->SCp.buffers_residual) {
1988 ++cmd->SCp.buffer;
1989 --cmd->SCp.buffers_residual;
1990 cmd->SCp.this_residual = cmd->SCp.buffer->length;
1991 cmd->SCp.ptr = SGADDR(cmd->SCp.buffer);
1992 dprintk(NDEBUG_INFORMATION, "scsi%d: %d bytes and %d buffers left\n",
1993 HOSTNO, cmd->SCp.this_residual,
1994 cmd->SCp.buffers_residual);
1995 }
1996
1997 /*
1998 * The preferred transfer method is going to be
1999 * PSEUDO-DMA for systems that are strictly PIO,
2000 * since we can let the hardware do the handshaking.
2001 *
2002 * For this to work, we need to know the transfersize
2003 * ahead of time, since the pseudo-DMA code will sit
2004 * in an unconditional loop.
2005 */
2006
2007/* ++roman: I suggest, this should be
2008 * #if def(REAL_DMA)
2009 * instead of leaving REAL_DMA out.
2010 */
2011
2012#if defined(REAL_DMA)
2013// if (!cmd->device->borken &&
2014 if((transfersize =
2015 NCR5380_dma_xfer_len(instance,cmd,phase)) > SUN3_DMA_MINSIZE) {
2016 len = transfersize;
2017 cmd->SCp.phase = phase;
2018
2019 if (NCR5380_transfer_dma(instance, &phase,
2020 &len, (unsigned char **) &cmd->SCp.ptr)) {
2021 /*
2022 * If the watchdog timer fires, all future
2023 * accesses to this device will use the
2024 * polled-IO. */
2025 printk(KERN_NOTICE "scsi%d: switching target %d "
2026 "lun %llu to slow handshake\n", HOSTNO,
2027 cmd->device->id, cmd->device->lun);
2028 cmd->device->borken = 1;
2029 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2030 ICR_ASSERT_ATN);
2031 sink = 1;
2032 do_abort(instance);
2033 cmd->result = DID_ERROR << 16;
2034 cmd->scsi_done(cmd);
2035 /* XXX - need to source or sink data here, as appropriate */
2036 } else {
2037#ifdef REAL_DMA
2038 /* ++roman: When using real DMA,
2039 * information_transfer() should return after
2040 * starting DMA since it has nothing more to
2041 * do.
2042 */
2043 return;
2044#else
2045 cmd->SCp.this_residual -= transfersize - len;
2046#endif
2047 }
2048 } else
2049#endif /* defined(REAL_DMA) */
2050 NCR5380_transfer_pio(instance, &phase,
2051 (int *) &cmd->SCp.this_residual, (unsigned char **)
2052 &cmd->SCp.ptr);
2053#ifdef REAL_DMA
2054 /* if we had intended to dma that command clear it */
2055 if(sun3_dma_setup_done == cmd)
2056 sun3_dma_setup_done = NULL;
2057#endif
2058
2059 break;
2060 case PHASE_MSGIN:
2061 len = 1;
2062 data = &tmp;
2063 NCR5380_write(SELECT_ENABLE_REG, 0); /* disable reselects */
2064 NCR5380_transfer_pio(instance, &phase, &len, &data);
2065 cmd->SCp.Message = tmp;
2066
2067 switch (tmp) {
2068 /*
2069 * Linking lets us reduce the time required to get the
2070 * next command out to the device, hopefully this will
2071 * mean we don't waste another revolution due to the delays
2072 * required by ARBITRATION and another SELECTION.
2073 *
2074 * In the current implementation proposal, low level drivers
2075 * merely have to start the next command, pointed to by
2076 * next_link, done() is called as with unlinked commands.
2077 */
2078#ifdef LINKED
2079 case LINKED_CMD_COMPLETE:
2080 case LINKED_FLG_CMD_COMPLETE:
2081 /* Accept message by clearing ACK */
2082 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2083
2084 dprintk(NDEBUG_LINKED, "scsi%d: target %d lun %llu linked command "
2085 "complete.\n", HOSTNO, cmd->device->id, cmd->device->lun);
2086
2087 /* Enable reselect interrupts */
2088 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2089 /*
2090 * Sanity check : A linked command should only terminate
2091 * with one of these messages if there are more linked
2092 * commands available.
2093 */
2094
2095 if (!cmd->next_link) {
2096 printk(KERN_NOTICE "scsi%d: target %d lun %llu "
2097 "linked command complete, no next_link\n",
2098 HOSTNO, cmd->device->id, cmd->device->lun);
2099 sink = 1;
2100 do_abort (instance);
2101 return;
2102 }
2103
2104 initialize_SCp(cmd->next_link);
2105 /* The next command is still part of this process; copy it
2106 * and don't free it! */
2107 cmd->next_link->tag = cmd->tag;
2108 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2109 dprintk(NDEBUG_LINKED, "scsi%d: target %d lun %llu linked request "
2110 "done, calling scsi_done().\n",
2111 HOSTNO, cmd->device->id, cmd->device->lun);
2112#ifdef NCR5380_STATS
2113 collect_stats(hostdata, cmd);
2114#endif
2115 cmd->scsi_done(cmd);
2116 cmd = hostdata->connected;
2117 break;
2118#endif /* def LINKED */
2119 case ABORT:
2120 case COMMAND_COMPLETE:
2121 /* Accept message by clearing ACK */
2122 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2123 hostdata->connected = NULL;
2124 dprintk(NDEBUG_QUEUES, "scsi%d: command for target %d, lun %llu "
2125 "completed\n", HOSTNO, cmd->device->id, cmd->device->lun);
2126#ifdef SUPPORT_TAGS
2127 cmd_free_tag( cmd );
2128 if (status_byte(cmd->SCp.Status) == QUEUE_FULL) {
2129 /* Turn a QUEUE FULL status into BUSY, I think the
2130 * mid level cannot handle QUEUE FULL :-( (The
2131 * command is retried after BUSY). Also update our
2132 * queue size to the number of currently issued
2133 * commands now.
2134 */
2135 /* ++Andreas: the mid level code knows about
2136 QUEUE_FULL now. */
2137 TAG_ALLOC *ta = &TagAlloc[cmd->device->id][cmd->device->lun];
2138 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %llu returned "
2139 "QUEUE_FULL after %d commands\n",
2140 HOSTNO, cmd->device->id, cmd->device->lun,
2141 ta->nr_allocated);
2142 if (ta->queue_size > ta->nr_allocated)
2143 ta->nr_allocated = ta->queue_size;
2144 }
2145#else
2146 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2147#endif
2148 /* Enable reselect interrupts */
2149 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2150
2151 /*
2152 * I'm not sure what the correct thing to do here is :
2153 *
2154 * If the command that just executed is NOT a request
2155 * sense, the obvious thing to do is to set the result
2156 * code to the values of the stored parameters.
2157 *
2158 * If it was a REQUEST SENSE command, we need some way to
2159 * differentiate between the failure code of the original
2160 * and the failure code of the REQUEST sense - the obvious
2161 * case is success, where we fall through and leave the
2162 * result code unchanged.
2163 *
2164 * The non-obvious place is where the REQUEST SENSE failed
2165 */
2166
2167 if (cmd->cmnd[0] != REQUEST_SENSE)
2168 cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
2169 else if (status_byte(cmd->SCp.Status) != GOOD)
2170 cmd->result = (cmd->result & 0x00ffff) | (DID_ERROR << 16);
2171
2172#ifdef AUTOSENSE
2173 if ((cmd->cmnd[0] == REQUEST_SENSE) &&
2174 hostdata->ses.cmd_len) {
2175 scsi_eh_restore_cmnd(cmd, &hostdata->ses);
2176 hostdata->ses.cmd_len = 0 ;
2177 }
2178
2179 if ((cmd->cmnd[0] != REQUEST_SENSE) &&
2180 (status_byte(cmd->SCp.Status) == CHECK_CONDITION)) {
2181 scsi_eh_prep_cmnd(cmd, &hostdata->ses, NULL, 0, ~0);
2182 dprintk(NDEBUG_AUTOSENSE, "scsi%d: performing request sense\n",
2183 HOSTNO);
2184 /* this is initialized from initialize_SCp
2185 cmd->SCp.buffer = NULL;
2186 cmd->SCp.buffers_residual = 0;
2187 */
2188
2189 local_irq_save(flags);
2190 LIST(cmd,hostdata->issue_queue);
2191 SET_NEXT(cmd, hostdata->issue_queue);
2192 hostdata->issue_queue = (struct scsi_cmnd *) cmd;
2193 local_irq_restore(flags);
2194 dprintk(NDEBUG_QUEUES, "scsi%d: REQUEST SENSE added to head of "
2195 "issue queue\n", H_NO(cmd));
2196 } else
2197#endif /* def AUTOSENSE */
2198 {
2199#ifdef NCR5380_STATS
2200 collect_stats(hostdata, cmd);
2201#endif
2202 cmd->scsi_done(cmd);
2203 }
2204
2205 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2206 /*
2207 * Restore phase bits to 0 so an interrupted selection,
2208 * arbitration can resume.
2209 */
2210 NCR5380_write(TARGET_COMMAND_REG, 0);
2211
2212 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
2213 barrier();
2214
2215 return;
2216 case MESSAGE_REJECT:
2217 /* Accept message by clearing ACK */
2218 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2219 /* Enable reselect interrupts */
2220 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2221 switch (hostdata->last_message) {
2222 case HEAD_OF_QUEUE_TAG:
2223 case ORDERED_QUEUE_TAG:
2224 case SIMPLE_QUEUE_TAG:
2225 /* The target obviously doesn't support tagged
2226 * queuing, even though it announced this ability in
2227 * its INQUIRY data ?!? (maybe only this LUN?) Ok,
2228 * clear 'tagged_supported' and lock the LUN, since
2229 * the command is treated as untagged further on.
2230 */
2231 cmd->device->tagged_supported = 0;
2232 hostdata->busy[cmd->device->id] |= (1 << cmd->device->lun);
2233 cmd->tag = TAG_NONE;
2234 dprintk(NDEBUG_TAGS, "scsi%d: target %d lun %llu rejected "
2235 "QUEUE_TAG message; tagged queuing "
2236 "disabled\n",
2237 HOSTNO, cmd->device->id, cmd->device->lun);
2238 break;
2239 }
2240 break;
2241 case DISCONNECT:
2242 /* Accept message by clearing ACK */
2243 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2244 local_irq_save(flags);
2245 cmd->device->disconnect = 1;
2246 LIST(cmd,hostdata->disconnected_queue);
2247 SET_NEXT(cmd, hostdata->disconnected_queue);
2248 hostdata->connected = NULL;
2249 hostdata->disconnected_queue = cmd;
2250 local_irq_restore(flags);
2251 dprintk(NDEBUG_QUEUES, "scsi%d: command for target %d lun %llu was "
2252 "moved from connected to the "
2253 "disconnected_queue\n", HOSTNO,
2254 cmd->device->id, cmd->device->lun);
2255 /*
2256 * Restore phase bits to 0 so an interrupted selection,
2257 * arbitration can resume.
2258 */
2259 NCR5380_write(TARGET_COMMAND_REG, 0);
2260
2261 /* Enable reselect interrupts */
2262 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2263 /* Wait for bus free to avoid nasty timeouts */
2264 while ((NCR5380_read(STATUS_REG) & SR_BSY) && !hostdata->connected)
2265 barrier();
2266#ifdef SUN3_SCSI_VME
2267 dregs->csr |= CSR_DMA_ENABLE;
2268#endif
2269 return;
2270 /*
2271 * The SCSI data pointer is *IMPLICITLY* saved on a disconnect
2272 * operation, in violation of the SCSI spec so we can safely
2273 * ignore SAVE/RESTORE pointers calls.
2274 *
2275 * Unfortunately, some disks violate the SCSI spec and
2276 * don't issue the required SAVE_POINTERS message before
2277 * disconnecting, and we have to break spec to remain
2278 * compatible.
2279 */
2280 case SAVE_POINTERS:
2281 case RESTORE_POINTERS:
2282 /* Accept message by clearing ACK */
2283 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2284 /* Enable reselect interrupts */
2285 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2286 break;
2287 case EXTENDED_MESSAGE:
2288/*
2289 * Extended messages are sent in the following format :
2290 * Byte
2291 * 0 EXTENDED_MESSAGE == 1
2292 * 1 length (includes one byte for code, doesn't
2293 * include first two bytes)
2294 * 2 code
2295 * 3..length+1 arguments
2296 *
2297 * Start the extended message buffer with the EXTENDED_MESSAGE
2298 * byte, since spi_print_msg() wants the whole thing.
2299 */
2300 extended_msg[0] = EXTENDED_MESSAGE;
2301 /* Accept first byte by clearing ACK */
2302 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2303
2304 dprintk(NDEBUG_EXTENDED, "scsi%d: receiving extended message\n", HOSTNO);
2305
2306 len = 2;
2307 data = extended_msg + 1;
2308 phase = PHASE_MSGIN;
2309 NCR5380_transfer_pio(instance, &phase, &len, &data);
2310 dprintk(NDEBUG_EXTENDED, "scsi%d: length=%d, code=0x%02x\n", HOSTNO,
2311 (int)extended_msg[1], (int)extended_msg[2]);
2312
2313 if (!len && extended_msg[1] <=
2314 (sizeof (extended_msg) - 1)) {
2315 /* Accept third byte by clearing ACK */
2316 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2317 len = extended_msg[1] - 1;
2318 data = extended_msg + 3;
2319 phase = PHASE_MSGIN;
2320
2321 NCR5380_transfer_pio(instance, &phase, &len, &data);
2322 dprintk(NDEBUG_EXTENDED, "scsi%d: message received, residual %d\n",
2323 HOSTNO, len);
2324
2325 switch (extended_msg[2]) {
2326 case EXTENDED_SDTR:
2327 case EXTENDED_WDTR:
2328 case EXTENDED_MODIFY_DATA_POINTER:
2329 case EXTENDED_EXTENDED_IDENTIFY:
2330 tmp = 0;
2331 }
2332 } else if (len) {
2333 printk(KERN_NOTICE "scsi%d: error receiving "
2334 "extended message\n", HOSTNO);
2335 tmp = 0;
2336 } else {
2337 printk(KERN_NOTICE "scsi%d: extended message "
2338 "code %02x length %d is too long\n",
2339 HOSTNO, extended_msg[2], extended_msg[1]);
2340 tmp = 0;
2341 }
2342 /* Fall through to reject message */
2343
2344 /*
2345 * If we get something weird that we aren't expecting,
2346 * reject it.
2347 */
2348 default:
2349 if (!tmp) {
2350 printk(KERN_DEBUG "scsi%d: rejecting message ", HOSTNO);
2351 spi_print_msg(extended_msg);
2352 printk("\n");
2353 } else if (tmp != EXTENDED_MESSAGE)
2354 printk(KERN_DEBUG "scsi%d: rejecting unknown "
2355 "message %02x from target %d, lun %llu\n",
2356 HOSTNO, tmp, cmd->device->id, cmd->device->lun);
2357 else
2358 printk(KERN_DEBUG "scsi%d: rejecting unknown "
2359 "extended message "
2360 "code %02x, length %d from target %d, lun %llu\n",
2361 HOSTNO, extended_msg[1], extended_msg[0],
2362 cmd->device->id, cmd->device->lun);
2363
2364
2365 msgout = MESSAGE_REJECT;
2366 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE |
2367 ICR_ASSERT_ATN);
2368 break;
2369 } /* switch (tmp) */
2370 break;
2371 case PHASE_MSGOUT:
2372 len = 1;
2373 data = &msgout;
2374 hostdata->last_message = msgout;
2375 NCR5380_transfer_pio(instance, &phase, &len, &data);
2376 if (msgout == ABORT) {
2377#ifdef SUPPORT_TAGS
2378 cmd_free_tag( cmd );
2379#else
2380 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2381#endif
2382 hostdata->connected = NULL;
2383 cmd->result = DID_ERROR << 16;
2384#ifdef NCR5380_STATS
2385 collect_stats(hostdata, cmd);
2386#endif
2387 cmd->scsi_done(cmd);
2388 NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
2389 return;
2390 }
2391 msgout = NOP;
2392 break;
2393 case PHASE_CMDOUT:
2394 len = cmd->cmd_len;
2395 data = cmd->cmnd;
2396 /*
2397 * XXX for performance reasons, on machines with a
2398 * PSEUDO-DMA architecture we should probably
2399 * use the dma transfer function.
2400 */
2401 NCR5380_transfer_pio(instance, &phase, &len,
2402 &data);
2403 break;
2404 case PHASE_STATIN:
2405 len = 1;
2406 data = &tmp;
2407 NCR5380_transfer_pio(instance, &phase, &len, &data);
2408 cmd->SCp.Status = tmp;
2409 break;
2410 default:
2411 printk("scsi%d: unknown phase\n", HOSTNO);
2412 NCR5380_dprint(NDEBUG_ANY, instance);
2413 } /* switch(phase) */
2414 } /* if (tmp * SR_REQ) */
2415 } /* while (1) */
2416}
2417
2418/*
2419 * Function : void NCR5380_reselect (struct Scsi_Host *instance)
2420 *
2421 * Purpose : does reselection, initializing the instance->connected
2422 * field to point to the struct scsi_cmnd for which the I_T_L or I_T_L_Q
2423 * nexus has been reestablished,
2424 *
2425 * Inputs : instance - this instance of the NCR5380.
2426 *
2427 */
2428
2429/* it might eventually prove necessary to do a dma setup on
2430 reselection, but it doesn't seem to be needed now -- sam */
2431
2432static void NCR5380_reselect (struct Scsi_Host *instance)
2433{
2434 SETUP_HOSTDATA(instance);
2435 unsigned char target_mask;
2436 unsigned char lun;
2437#ifdef SUPPORT_TAGS
2438 unsigned char tag;
2439#endif
2440 unsigned char msg[3];
2441 struct scsi_cmnd *tmp = NULL, *prev;
2442/* unsigned long flags; */
2443
2444 /*
2445 * Disable arbitration, etc. since the host adapter obviously
2446 * lost, and tell an interrupted NCR5380_select() to restart.
2447 */
2448
2449 NCR5380_write(MODE_REG, MR_BASE);
2450 hostdata->restart_select = 1;
2451
2452 target_mask = NCR5380_read(CURRENT_SCSI_DATA_REG) & ~(hostdata->id_mask);
2453
2454 dprintk(NDEBUG_RESELECTION, "scsi%d: reselect\n", HOSTNO);
2455
2456 /*
2457 * At this point, we have detected that our SCSI ID is on the bus,
2458 * SEL is true and BSY was false for at least one bus settle delay
2459 * (400 ns).
2460 *
2461 * We must assert BSY ourselves, until the target drops the SEL
2462 * signal.
2463 */
2464
2465 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_BSY);
2466
2467 while (NCR5380_read(STATUS_REG) & SR_SEL);
2468 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2469
2470 /*
2471 * Wait for target to go into MSGIN.
2472 */
2473
2474 while (!(NCR5380_read(STATUS_REG) & SR_REQ));
2475
2476#if 1
2477 // acknowledge toggle to MSGIN
2478 NCR5380_write(TARGET_COMMAND_REG, PHASE_SR_TO_TCR(PHASE_MSGIN));
2479
2480 // peek at the byte without really hitting the bus
2481 msg[0] = NCR5380_read(CURRENT_SCSI_DATA_REG);
2482#endif
2483
2484 if (!(msg[0] & 0x80)) {
2485 printk(KERN_DEBUG "scsi%d: expecting IDENTIFY message, got ", HOSTNO);
2486 spi_print_msg(msg);
2487 do_abort(instance);
2488 return;
2489 }
2490 lun = (msg[0] & 0x07);
2491
2492 /*
2493 * Find the command corresponding to the I_T_L or I_T_L_Q nexus we
2494 * just reestablished, and remove it from the disconnected queue.
2495 */
2496
2497 for (tmp = (struct scsi_cmnd *) hostdata->disconnected_queue, prev = NULL;
2498 tmp; prev = tmp, tmp = NEXT(tmp) ) {
2499 if ((target_mask == (1 << tmp->device->id)) && (lun == tmp->device->lun)
2500#ifdef SUPPORT_TAGS
2501 && (tag == tmp->tag)
2502#endif
2503 ) {
2504 if (prev) {
2505 REMOVE(prev, NEXT(prev), tmp, NEXT(tmp));
2506 SET_NEXT(prev, NEXT(tmp));
2507 } else {
2508 REMOVE(-1, hostdata->disconnected_queue, tmp, NEXT(tmp));
2509 hostdata->disconnected_queue = NEXT(tmp);
2510 }
2511 SET_NEXT(tmp, NULL);
2512 break;
2513 }
2514 }
2515
2516 if (!tmp) {
2517 printk(KERN_WARNING "scsi%d: warning: target bitmask %02x lun %d "
2518#ifdef SUPPORT_TAGS
2519 "tag %d "
2520#endif
2521 "not in disconnected_queue.\n",
2522 HOSTNO, target_mask, lun
2523#ifdef SUPPORT_TAGS
2524 , tag
2525#endif
2526 );
2527 /*
2528 * Since we have an established nexus that we can't do anything
2529 * with, we must abort it.
2530 */
2531 do_abort(instance);
2532 return;
2533 }
2534#if 1
2535 /* engage dma setup for the command we just saw */
2536 {
2537 void *d;
2538 unsigned long count;
2539
2540 if (!tmp->SCp.this_residual && tmp->SCp.buffers_residual) {
2541 count = tmp->SCp.buffer->length;
2542 d = SGADDR(tmp->SCp.buffer);
2543 } else {
2544 count = tmp->SCp.this_residual;
2545 d = tmp->SCp.ptr;
2546 }
2547#ifdef REAL_DMA
2548 /* setup this command for dma if not already */
2549 if((count > SUN3_DMA_MINSIZE) && (sun3_dma_setup_done != tmp))
2550 {
2551 sun3scsi_dma_setup(d, count, rq_data_dir(tmp->request));
2552 sun3_dma_setup_done = tmp;
2553 }
2554#endif
2555 }
2556#endif
2557
2558 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_ACK);
2559 /* Accept message by clearing ACK */
2560 NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
2561
2562#ifdef SUPPORT_TAGS
2563 /* If the phase is still MSGIN, the target wants to send some more
2564 * messages. In case it supports tagged queuing, this is probably a
2565 * SIMPLE_QUEUE_TAG for the I_T_L_Q nexus.
2566 */
2567 tag = TAG_NONE;
2568 if (phase == PHASE_MSGIN && setup_use_tagged_queuing) {
2569 /* Accept previous IDENTIFY message by clearing ACK */
2570 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
2571 len = 2;
2572 data = msg+1;
2573 if (!NCR5380_transfer_pio(instance, &phase, &len, &data) &&
2574 msg[1] == SIMPLE_QUEUE_TAG)
2575 tag = msg[2];
2576 dprintk(NDEBUG_TAGS, "scsi%d: target mask %02x, lun %d sent tag %d at "
2577 "reselection\n", HOSTNO, target_mask, lun, tag);
2578 }
2579#endif
2580
2581 hostdata->connected = tmp;
2582 dprintk(NDEBUG_RESELECTION, "scsi%d: nexus established, target = %d, lun = %llu, tag = %d\n",
2583 HOSTNO, tmp->device->id, tmp->device->lun, tmp->tag);
2584}
2585
2586
2587/*
2588 * Function : int NCR5380_abort(struct scsi_cmnd *cmd)
2589 *
2590 * Purpose : abort a command
2591 *
2592 * Inputs : cmd - the struct scsi_cmnd to abort, code - code to set the
2593 * host byte of the result field to, if zero DID_ABORTED is
2594 * used.
2595 *
2596 * Returns : 0 - success, -1 on failure.
2597 *
2598 * XXX - there is no way to abort the command that is currently
2599 * connected, you have to wait for it to complete. If this is
2600 * a problem, we could implement longjmp() / setjmp(), setjmp()
2601 * called where the loop started in NCR5380_main().
2602 */
2603
2604static int NCR5380_abort(struct scsi_cmnd *cmd)
2605{
2606 struct Scsi_Host *instance = cmd->device->host;
2607 SETUP_HOSTDATA(instance);
2608 struct scsi_cmnd *tmp, **prev;
2609 unsigned long flags;
2610
2611 printk(KERN_NOTICE "scsi%d: aborting command\n", HOSTNO);
2612 scsi_print_command(cmd);
2613
2614 NCR5380_print_status (instance);
2615
2616 local_irq_save(flags);
2617
2618 dprintk(NDEBUG_ABORT, "scsi%d: abort called basr 0x%02x, sr 0x%02x\n", HOSTNO,
2619 NCR5380_read(BUS_AND_STATUS_REG),
2620 NCR5380_read(STATUS_REG));
2621
2622#if 1
2623/*
2624 * Case 1 : If the command is the currently executing command,
2625 * we'll set the aborted flag and return control so that
2626 * information transfer routine can exit cleanly.
2627 */
2628
2629 if (hostdata->connected == cmd) {
2630
2631 dprintk(NDEBUG_ABORT, "scsi%d: aborting connected command\n", HOSTNO);
2632/*
2633 * We should perform BSY checking, and make sure we haven't slipped
2634 * into BUS FREE.
2635 */
2636
2637/* NCR5380_write(INITIATOR_COMMAND_REG, ICR_ASSERT_ATN); */
2638/*
2639 * Since we can't change phases until we've completed the current
2640 * handshake, we have to source or sink a byte of data if the current
2641 * phase is not MSGOUT.
2642 */
2643
2644/*
2645 * Return control to the executing NCR drive so we can clear the
2646 * aborted flag and get back into our main loop.
2647 */
2648
2649 if (do_abort(instance) == 0) {
2650 hostdata->aborted = 1;
2651 hostdata->connected = NULL;
2652 cmd->result = DID_ABORT << 16;
2653#ifdef SUPPORT_TAGS
2654 cmd_free_tag( cmd );
2655#else
2656 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2657#endif
2658 local_irq_restore(flags);
2659 cmd->scsi_done(cmd);
2660 return SUCCESS;
2661 } else {
2662/* local_irq_restore(flags); */
2663 printk("scsi%d: abort of connected command failed!\n", HOSTNO);
2664 return FAILED;
2665 }
2666 }
2667#endif
2668
2669/*
2670 * Case 2 : If the command hasn't been issued yet, we simply remove it
2671 * from the issue queue.
2672 */
2673 for (prev = (struct scsi_cmnd **) &(hostdata->issue_queue),
2674 tmp = (struct scsi_cmnd *) hostdata->issue_queue;
2675 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp))
2676 if (cmd == tmp) {
2677 REMOVE(5, *prev, tmp, NEXT(tmp));
2678 (*prev) = NEXT(tmp);
2679 SET_NEXT(tmp, NULL);
2680 tmp->result = DID_ABORT << 16;
2681 local_irq_restore(flags);
2682 dprintk(NDEBUG_ABORT, "scsi%d: abort removed command from issue queue.\n",
2683 HOSTNO);
2684 /* Tagged queuing note: no tag to free here, hasn't been assigned
2685 * yet... */
2686 tmp->scsi_done(tmp);
2687 return SUCCESS;
2688 }
2689
2690/*
2691 * Case 3 : If any commands are connected, we're going to fail the abort
2692 * and let the high level SCSI driver retry at a later time or
2693 * issue a reset.
2694 *
2695 * Timeouts, and therefore aborted commands, will be highly unlikely
2696 * and handling them cleanly in this situation would make the common
2697 * case of noresets less efficient, and would pollute our code. So,
2698 * we fail.
2699 */
2700
2701 if (hostdata->connected) {
2702 local_irq_restore(flags);
2703 dprintk(NDEBUG_ABORT, "scsi%d: abort failed, command connected.\n", HOSTNO);
2704 return FAILED;
2705 }
2706
2707/*
2708 * Case 4: If the command is currently disconnected from the bus, and
2709 * there are no connected commands, we reconnect the I_T_L or
2710 * I_T_L_Q nexus associated with it, go into message out, and send
2711 * an abort message.
2712 *
2713 * This case is especially ugly. In order to reestablish the nexus, we
2714 * need to call NCR5380_select(). The easiest way to implement this
2715 * function was to abort if the bus was busy, and let the interrupt
2716 * handler triggered on the SEL for reselect take care of lost arbitrations
2717 * where necessary, meaning interrupts need to be enabled.
2718 *
2719 * When interrupts are enabled, the queues may change - so we
2720 * can't remove it from the disconnected queue before selecting it
2721 * because that could cause a failure in hashing the nexus if that
2722 * device reselected.
2723 *
2724 * Since the queues may change, we can't use the pointers from when we
2725 * first locate it.
2726 *
2727 * So, we must first locate the command, and if NCR5380_select()
2728 * succeeds, then issue the abort, relocate the command and remove
2729 * it from the disconnected queue.
2730 */
2731
2732 for (tmp = (struct scsi_cmnd *) hostdata->disconnected_queue; tmp;
2733 tmp = NEXT(tmp))
2734 if (cmd == tmp) {
2735 local_irq_restore(flags);
2736 dprintk(NDEBUG_ABORT, "scsi%d: aborting disconnected command.\n", HOSTNO);
2737
2738 if (NCR5380_select (instance, cmd, (int) cmd->tag))
2739 return FAILED;
2740
2741 dprintk(NDEBUG_ABORT, "scsi%d: nexus reestablished.\n", HOSTNO);
2742
2743 do_abort (instance);
2744
2745 local_irq_save(flags);
2746 for (prev = (struct scsi_cmnd **) &(hostdata->disconnected_queue),
2747 tmp = (struct scsi_cmnd *) hostdata->disconnected_queue;
2748 tmp; prev = NEXTADDR(tmp), tmp = NEXT(tmp) )
2749 if (cmd == tmp) {
2750 REMOVE(5, *prev, tmp, NEXT(tmp));
2751 *prev = NEXT(tmp);
2752 SET_NEXT(tmp, NULL);
2753 tmp->result = DID_ABORT << 16;
2754 /* We must unlock the tag/LUN immediately here, since the
2755 * target goes to BUS FREE and doesn't send us another
2756 * message (COMMAND_COMPLETE or the like)
2757 */
2758#ifdef SUPPORT_TAGS
2759 cmd_free_tag( tmp );
2760#else
2761 hostdata->busy[cmd->device->id] &= ~(1 << cmd->device->lun);
2762#endif
2763 local_irq_restore(flags);
2764 tmp->scsi_done(tmp);
2765 return SUCCESS;
2766 }
2767 }
2768
2769/*
2770 * Case 5 : If we reached this point, the command was not found in any of
2771 * the queues.
2772 *
2773 * We probably reached this point because of an unlikely race condition
2774 * between the command completing successfully and the abortion code,
2775 * so we won't panic, but we will notify the user in case something really
2776 * broke.
2777 */
2778
2779 local_irq_restore(flags);
2780 printk(KERN_INFO "scsi%d: warning : SCSI command probably completed successfully before abortion\n", HOSTNO);
2781
2782 return FAILED;
2783}
2784
2785
2786/*
2787 * Function : int NCR5380_bus_reset(struct scsi_cmnd *cmd)
2788 *
2789 * Purpose : reset the SCSI bus.
2790 *
2791 * Returns : SUCCESS or FAILURE
2792 *
2793 */
2794
2795static int NCR5380_bus_reset(struct scsi_cmnd *cmd)
2796{
2797 SETUP_HOSTDATA(cmd->device->host);
2798 int i;
2799 unsigned long flags;
2800#if defined(RESET_RUN_DONE)
2801 struct scsi_cmnd *connected, *disconnected_queue;
2802#endif
2803
2804
2805 NCR5380_print_status (cmd->device->host);
2806
2807 /* get in phase */
2808 NCR5380_write( TARGET_COMMAND_REG,
2809 PHASE_SR_TO_TCR( NCR5380_read(STATUS_REG) ));
2810 /* assert RST */
2811 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_RST );
2812 udelay (40);
2813 /* reset NCR registers */
2814 NCR5380_write( INITIATOR_COMMAND_REG, ICR_BASE );
2815 NCR5380_write( MODE_REG, MR_BASE );
2816 NCR5380_write( TARGET_COMMAND_REG, 0 );
2817 NCR5380_write( SELECT_ENABLE_REG, 0 );
2818 /* ++roman: reset interrupt condition! otherwise no interrupts don't get
2819 * through anymore ... */
2820 (void)NCR5380_read( RESET_PARITY_INTERRUPT_REG );
2821
2822 /* MSch 20140115 - looking at the generic NCR5380 driver, all of this
2823 * should go.
2824 * Catch-22: if we don't clear all queues, the SCSI driver lock will
2825 * not be released by atari_scsi_reset()!
2826 */
2827
2828#if defined(RESET_RUN_DONE)
2829 /* XXX Should now be done by midlevel code, but it's broken XXX */
2830 /* XXX see below XXX */
2831
2832 /* MSch: old-style reset: actually abort all command processing here */
2833
2834 /* After the reset, there are no more connected or disconnected commands
2835 * and no busy units; to avoid problems with re-inserting the commands
2836 * into the issue_queue (via scsi_done()), the aborted commands are
2837 * remembered in local variables first.
2838 */
2839 local_irq_save(flags);
2840 connected = (struct scsi_cmnd *)hostdata->connected;
2841 hostdata->connected = NULL;
2842 disconnected_queue = (struct scsi_cmnd *)hostdata->disconnected_queue;
2843 hostdata->disconnected_queue = NULL;
2844#ifdef SUPPORT_TAGS
2845 free_all_tags();
2846#endif
2847 for( i = 0; i < 8; ++i )
2848 hostdata->busy[i] = 0;
2849#ifdef REAL_DMA
2850 hostdata->dma_len = 0;
2851#endif
2852 local_irq_restore(flags);
2853
2854 /* In order to tell the mid-level code which commands were aborted,
2855 * set the command status to DID_RESET and call scsi_done() !!!
2856 * This ultimately aborts processing of these commands in the mid-level.
2857 */
2858
2859 if ((cmd = connected)) {
2860 dprintk(NDEBUG_ABORT, "scsi%d: reset aborted a connected command\n", H_NO(cmd));
2861 cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
2862 cmd->scsi_done( cmd );
2863 }
2864
2865 for (i = 0; (cmd = disconnected_queue); ++i) {
2866 disconnected_queue = NEXT(cmd);
2867 SET_NEXT(cmd, NULL);
2868 cmd->result = (cmd->result & 0xffff) | (DID_RESET << 16);
2869 cmd->scsi_done( cmd );
2870 }
2871 if (i > 0)
2872 dprintk(NDEBUG_ABORT, "scsi: reset aborted %d disconnected command(s)\n", i);
2873
2874
2875 /* since all commands have been explicitly terminated, we need to tell
2876 * the midlevel code that the reset was SUCCESSFUL, and there is no
2877 * need to 'wake up' the commands by a request_sense
2878 */
2879 return SUCCESS;
2880#else /* 1 */
2881
2882 /* MSch: new-style reset handling: let the mid-level do what it can */
2883
2884 /* ++guenther: MID-LEVEL IS STILL BROKEN.
2885 * Mid-level is supposed to requeue all commands that were active on the
2886 * various low-level queues. In fact it does this, but that's not enough
2887 * because all these commands are subject to timeout. And if a timeout
2888 * happens for any removed command, *_abort() is called but all queues
2889 * are now empty. Abort then gives up the falcon lock, which is fatal,
2890 * since the mid-level will queue more commands and must have the lock
2891 * (it's all happening inside timer interrupt handler!!).
2892 * Even worse, abort will return NOT_RUNNING for all those commands not
2893 * on any queue, so they won't be retried ...
2894 *
2895 * Conclusion: either scsi.c disables timeout for all resetted commands
2896 * immediately, or we lose! As of linux-2.0.20 it doesn't.
2897 */
2898
2899 /* After the reset, there are no more connected or disconnected commands
2900 * and no busy units; so clear the low-level status here to avoid
2901 * conflicts when the mid-level code tries to wake up the affected
2902 * commands!
2903 */
2904
2905 if (hostdata->issue_queue)
2906 dprintk(NDEBUG_ABORT, "scsi%d: reset aborted issued command(s)\n", H_NO(cmd));
2907 if (hostdata->connected)
2908 dprintk(NDEBUG_ABORT, "scsi%d: reset aborted a connected command\n", H_NO(cmd));
2909 if (hostdata->disconnected_queue)
2910 dprintk(NDEBUG_ABORT, "scsi%d: reset aborted disconnected command(s)\n", H_NO(cmd));
2911
2912 local_irq_save(flags);
2913 hostdata->issue_queue = NULL;
2914 hostdata->connected = NULL;
2915 hostdata->disconnected_queue = NULL;
2916#ifdef SUPPORT_TAGS
2917 free_all_tags();
2918#endif
2919 for( i = 0; i < 8; ++i )
2920 hostdata->busy[i] = 0;
2921#ifdef REAL_DMA
2922 hostdata->dma_len = 0;
2923#endif
2924 local_irq_restore(flags);
2925
2926 /* we did no complete reset of all commands, so a wakeup is required */
2927 return SUCCESS;
2928#endif /* 1 */
2929}
2930
2931/* Local Variables: */
2932/* tab-width: 8 */
2933/* End: */
diff --git a/drivers/scsi/sun3_scsi.c b/drivers/scsi/sun3_scsi.c
index 9707b7494a89..2a906d1d34ba 100644
--- a/drivers/scsi/sun3_scsi.c
+++ b/drivers/scsi/sun3_scsi.c
@@ -20,89 +20,58 @@
20 * Generic Generic NCR5380 driver 20 * Generic Generic NCR5380 driver
21 * 21 *
22 * Copyright 1995, Russell King 22 * Copyright 1995, Russell King
23 *
24 * ALPHA RELEASE 1.
25 *
26 * For more information, please consult
27 *
28 * NCR 5380 Family
29 * SCSI Protocol Controller
30 * Databook
31 *
32 * NCR Microelectronics
33 * 1635 Aeroplaza Drive
34 * Colorado Springs, CO 80916
35 * 1+ (719) 578-3400
36 * 1+ (800) 334-5454
37 */ 23 */
38 24
39
40/*
41 * This is from mac_scsi.h, but hey, maybe this is useful for Sun3 too! :)
42 *
43 * Options :
44 *
45 * PARITY - enable parity checking. Not supported.
46 *
47 * SCSI2 - enable support for SCSI-II tagged queueing. Untested.
48 *
49 * USLEEP - enable support for devices that don't disconnect. Untested.
50 */
51
52#define AUTOSENSE
53
54#include <linux/types.h> 25#include <linux/types.h>
55#include <linux/stddef.h>
56#include <linux/ctype.h>
57#include <linux/delay.h> 26#include <linux/delay.h>
58
59#include <linux/module.h> 27#include <linux/module.h>
60#include <linux/signal.h>
61#include <linux/ioport.h> 28#include <linux/ioport.h>
62#include <linux/init.h> 29#include <linux/init.h>
63#include <linux/blkdev.h> 30#include <linux/blkdev.h>
31#include <linux/platform_device.h>
64 32
65#include <asm/io.h> 33#include <asm/io.h>
66
67#include <asm/sun3ints.h>
68#include <asm/dvma.h> 34#include <asm/dvma.h>
69#include <asm/idprom.h>
70#include <asm/machines.h>
71 35
72/* dma on! */
73#define REAL_DMA
74
75#include "scsi.h"
76#include <scsi/scsi_host.h> 36#include <scsi/scsi_host.h>
77#include "sun3_scsi.h" 37#include "sun3_scsi.h"
78#include "NCR5380.h"
79 38
80extern int sun3_map_test(unsigned long, char *); 39/* Definitions for the core NCR5380 driver. */
81 40
82#define USE_WRAPPER 41#define REAL_DMA
83/*#define RESET_BOOT */ 42/* #define SUPPORT_TAGS */
84#define DRIVER_SETUP 43/* minimum number of bytes to do dma on */
44#define DMA_MIN_SIZE 129
85 45
86/* 46/* #define MAX_TAGS 32 */
87 * BUG can be used to trigger a strange code-size related hang on 2.1 kernels
88 */
89#ifdef BUG
90#undef RESET_BOOT
91#undef DRIVER_SETUP
92#endif
93 47
94/* #define SUPPORT_TAGS */ 48#define NCR5380_implementation_fields /* none */
95 49
96#ifdef SUN3_SCSI_VME 50#define NCR5380_read(reg) sun3scsi_read(reg)
97#define ENABLE_IRQ() 51#define NCR5380_write(reg, value) sun3scsi_write(reg, value)
98#else 52
99#define ENABLE_IRQ() enable_irq( IRQ_SUN3_SCSI ); 53#define NCR5380_queue_command sun3scsi_queue_command
100#endif 54#define NCR5380_bus_reset sun3scsi_bus_reset
55#define NCR5380_abort sun3scsi_abort
56#define NCR5380_show_info sun3scsi_show_info
57#define NCR5380_info sun3scsi_info
101 58
59#define NCR5380_dma_read_setup(instance, data, count) \
60 sun3scsi_dma_setup(data, count, 0)
61#define NCR5380_dma_write_setup(instance, data, count) \
62 sun3scsi_dma_setup(data, count, 1)
63#define NCR5380_dma_residual(instance) \
64 sun3scsi_dma_residual(instance)
65#define NCR5380_dma_xfer_len(instance, cmd, phase) \
66 sun3scsi_dma_xfer_len(cmd->SCp.this_residual, cmd, !((phase) & SR_IO))
102 67
103static irqreturn_t scsi_sun3_intr(int irq, void *dummy); 68#define NCR5380_acquire_dma_irq(instance) (1)
104static inline unsigned char sun3scsi_read(int reg); 69#define NCR5380_release_dma_irq(instance)
105static inline void sun3scsi_write(int reg, int value); 70
71#include "NCR5380.h"
72
73
74extern int sun3_map_test(unsigned long, char *);
106 75
107static int setup_can_queue = -1; 76static int setup_can_queue = -1;
108module_param(setup_can_queue, int, 0); 77module_param(setup_can_queue, int, 0);
@@ -117,9 +86,7 @@ module_param(setup_use_tagged_queuing, int, 0);
117static int setup_hostid = -1; 86static int setup_hostid = -1;
118module_param(setup_hostid, int, 0); 87module_param(setup_hostid, int, 0);
119 88
120static struct scsi_cmnd *sun3_dma_setup_done = NULL; 89/* #define RESET_BOOT */
121
122#define RESET_RUN_DONE
123 90
124#define AFTER_RESET_DELAY (HZ/2) 91#define AFTER_RESET_DELAY (HZ/2)
125 92
@@ -129,18 +96,15 @@ static struct scsi_cmnd *sun3_dma_setup_done = NULL;
129/* dvma buffer to allocate -- 32k should hopefully be more than sufficient */ 96/* dvma buffer to allocate -- 32k should hopefully be more than sufficient */
130#define SUN3_DVMA_BUFSIZE 0xe000 97#define SUN3_DVMA_BUFSIZE 0xe000
131 98
132/* minimum number of bytes to do dma on */ 99static struct scsi_cmnd *sun3_dma_setup_done;
133#define SUN3_DMA_MINSIZE 128 100static unsigned char *sun3_scsi_regp;
134
135static volatile unsigned char *sun3_scsi_regp;
136static volatile struct sun3_dma_regs *dregs; 101static volatile struct sun3_dma_regs *dregs;
137#ifndef SUN3_SCSI_VME 102static struct sun3_udc_regs *udc_regs;
138static struct sun3_udc_regs *udc_regs = NULL;
139#endif
140static unsigned char *sun3_dma_orig_addr = NULL; 103static unsigned char *sun3_dma_orig_addr = NULL;
141static unsigned long sun3_dma_orig_count = 0; 104static unsigned long sun3_dma_orig_count = 0;
142static int sun3_dma_active = 0; 105static int sun3_dma_active = 0;
143static unsigned long last_residual = 0; 106static unsigned long last_residual = 0;
107static struct Scsi_Host *default_instance;
144 108
145/* 109/*
146 * NCR 5380 register access functions 110 * NCR 5380 register access functions
@@ -148,12 +112,12 @@ static unsigned long last_residual = 0;
148 112
149static inline unsigned char sun3scsi_read(int reg) 113static inline unsigned char sun3scsi_read(int reg)
150{ 114{
151 return( sun3_scsi_regp[reg] ); 115 return in_8(sun3_scsi_regp + reg);
152} 116}
153 117
154static inline void sun3scsi_write(int reg, int value) 118static inline void sun3scsi_write(int reg, int value)
155{ 119{
156 sun3_scsi_regp[reg] = value; 120 out_8(sun3_scsi_regp + reg, value);
157} 121}
158 122
159#ifndef SUN3_SCSI_VME 123#ifndef SUN3_SCSI_VME
@@ -180,213 +144,10 @@ static inline void sun3_udc_write(unsigned short val, unsigned char reg)
180} 144}
181#endif 145#endif
182 146
183/*
184 * XXX: status debug
185 */
186static struct Scsi_Host *default_instance;
187
188/*
189 * Function : int sun3scsi_detect(struct scsi_host_template * tpnt)
190 *
191 * Purpose : initializes mac NCR5380 driver based on the
192 * command line / compile time port and irq definitions.
193 *
194 * Inputs : tpnt - template for this SCSI adapter.
195 *
196 * Returns : 1 if a host adapter was found, 0 if not.
197 *
198 */
199
200static int __init sun3scsi_detect(struct scsi_host_template *tpnt)
201{
202 unsigned long ioaddr, irq;
203 static int called = 0;
204 struct Scsi_Host *instance;
205#ifdef SUN3_SCSI_VME
206 int i;
207 unsigned long addrs[3] = { IOBASE_SUN3_VMESCSI,
208 IOBASE_SUN3_VMESCSI + 0x4000,
209 0 };
210 unsigned long vecs[3] = { SUN3_VEC_VMESCSI0,
211 SUN3_VEC_VMESCSI1,
212 0 };
213#endif
214
215 /* check that this machine has an onboard 5380 */
216 switch(idprom->id_machtype) {
217#ifdef SUN3_SCSI_VME
218 case SM_SUN3|SM_3_160:
219 case SM_SUN3|SM_3_260:
220 break;
221#else
222 case SM_SUN3|SM_3_50:
223 case SM_SUN3|SM_3_60:
224 break;
225#endif
226
227 default:
228 return 0;
229 }
230
231 if(called)
232 return 0;
233
234#ifdef SUN3_SCSI_VME
235 tpnt->proc_name = "Sun3 5380 VME SCSI";
236#else
237 tpnt->proc_name = "Sun3 5380 SCSI";
238#endif
239
240 /* setup variables */
241 tpnt->can_queue =
242 (setup_can_queue > 0) ? setup_can_queue : CAN_QUEUE;
243 tpnt->cmd_per_lun =
244 (setup_cmd_per_lun > 0) ? setup_cmd_per_lun : CMD_PER_LUN;
245 tpnt->sg_tablesize =
246 (setup_sg_tablesize >= 0) ? setup_sg_tablesize : SG_TABLESIZE;
247
248 if (setup_hostid >= 0)
249 tpnt->this_id = setup_hostid;
250 else {
251 /* use 7 as default */
252 tpnt->this_id = 7;
253 }
254
255#ifdef SUN3_SCSI_VME
256 ioaddr = 0;
257 for (i = 0; addrs[i] != 0; i++) {
258 unsigned char x;
259
260 ioaddr = (unsigned long)sun3_ioremap(addrs[i], PAGE_SIZE,
261 SUN3_PAGE_TYPE_VME16);
262 irq = vecs[i];
263 sun3_scsi_regp = (unsigned char *)ioaddr;
264
265 dregs = (struct sun3_dma_regs *)(((unsigned char *)ioaddr) + 8);
266
267 if (sun3_map_test((unsigned long)dregs, &x)) {
268 unsigned short oldcsr;
269
270 oldcsr = dregs->csr;
271 dregs->csr = 0;
272 udelay(SUN3_DMA_DELAY);
273 if (dregs->csr == 0x1400)
274 break;
275
276 dregs->csr = oldcsr;
277 }
278
279 iounmap((void *)ioaddr);
280 ioaddr = 0;
281 }
282
283 if (!ioaddr)
284 return 0;
285#else
286 irq = IRQ_SUN3_SCSI;
287 ioaddr = (unsigned long)ioremap(IOBASE_SUN3_SCSI, PAGE_SIZE);
288 sun3_scsi_regp = (unsigned char *)ioaddr;
289
290 dregs = (struct sun3_dma_regs *)(((unsigned char *)ioaddr) + 8);
291
292 if((udc_regs = dvma_malloc(sizeof(struct sun3_udc_regs)))
293 == NULL) {
294 printk("SUN3 Scsi couldn't allocate DVMA memory!\n");
295 return 0;
296 }
297#endif
298#ifdef SUPPORT_TAGS
299 if (setup_use_tagged_queuing < 0)
300 setup_use_tagged_queuing = USE_TAGGED_QUEUING;
301#endif
302
303 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
304 if(instance == NULL)
305 return 0;
306
307 default_instance = instance;
308
309 instance->io_port = (unsigned long) ioaddr;
310 instance->irq = irq;
311
312 NCR5380_init(instance, 0);
313
314 instance->n_io_port = 32;
315
316 ((struct NCR5380_hostdata *)instance->hostdata)->ctrl = 0;
317
318 if (request_irq(instance->irq, scsi_sun3_intr,
319 0, "Sun3SCSI-5380", instance)) {
320#ifndef REAL_DMA
321 printk("scsi%d: IRQ%d not free, interrupts disabled\n",
322 instance->host_no, instance->irq);
323 instance->irq = SCSI_IRQ_NONE;
324#else
325 printk("scsi%d: IRQ%d not free, bailing out\n",
326 instance->host_no, instance->irq);
327 return 0;
328#endif
329 }
330
331 pr_info("scsi%d: %s at port %lX irq", instance->host_no,
332 tpnt->proc_name, instance->io_port);
333 if (instance->irq == SCSI_IRQ_NONE)
334 printk ("s disabled");
335 else
336 printk (" %d", instance->irq);
337 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
338 instance->can_queue, instance->cmd_per_lun,
339 SUN3SCSI_PUBLIC_RELEASE);
340 printk("\nscsi%d:", instance->host_no);
341 NCR5380_print_options(instance);
342 printk("\n");
343
344 dregs->csr = 0;
345 udelay(SUN3_DMA_DELAY);
346 dregs->csr = CSR_SCSI | CSR_FIFO | CSR_INTR;
347 udelay(SUN3_DMA_DELAY);
348 dregs->fifo_count = 0;
349#ifdef SUN3_SCSI_VME
350 dregs->fifo_count_hi = 0;
351 dregs->dma_addr_hi = 0;
352 dregs->dma_addr_lo = 0;
353 dregs->dma_count_hi = 0;
354 dregs->dma_count_lo = 0;
355
356 dregs->ivect = VME_DATA24 | (instance->irq & 0xff);
357#endif
358
359 called = 1;
360
361#ifdef RESET_BOOT
362 sun3_scsi_reset_boot(instance);
363#endif
364
365 return 1;
366}
367
368int sun3scsi_release (struct Scsi_Host *shpnt)
369{
370 if (shpnt->irq != SCSI_IRQ_NONE)
371 free_irq(shpnt->irq, shpnt);
372
373 iounmap((void *)sun3_scsi_regp);
374
375 NCR5380_exit(shpnt);
376 return 0;
377}
378
379#ifdef RESET_BOOT 147#ifdef RESET_BOOT
380/*
381 * Our 'bus reset on boot' function
382 */
383
384static void sun3_scsi_reset_boot(struct Scsi_Host *instance) 148static void sun3_scsi_reset_boot(struct Scsi_Host *instance)
385{ 149{
386 unsigned long end; 150 unsigned long end;
387
388 NCR5380_local_declare();
389 NCR5380_setup(instance);
390 151
391 /* 152 /*
392 * Do a SCSI reset to clean up the bus during initialization. No 153 * Do a SCSI reset to clean up the bus during initialization. No
@@ -422,11 +183,6 @@ static void sun3_scsi_reset_boot(struct Scsi_Host *instance)
422} 183}
423#endif 184#endif
424 185
425static const char *sun3scsi_info(struct Scsi_Host *spnt)
426{
427 return "";
428}
429
430// safe bits for the CSR 186// safe bits for the CSR
431#define CSR_GOOD 0x060f 187#define CSR_GOOD 0x060f
432 188
@@ -468,7 +224,6 @@ static irqreturn_t scsi_sun3_intr(int irq, void *dummy)
468void sun3_sun3_debug (void) 224void sun3_sun3_debug (void)
469{ 225{
470 unsigned long flags; 226 unsigned long flags;
471 NCR5380_local_declare();
472 227
473 if (default_instance) { 228 if (default_instance) {
474 local_irq_save(flags); 229 local_irq_save(flags);
@@ -732,25 +487,200 @@ static int sun3scsi_dma_finish(int write_flag)
732 487
733} 488}
734 489
735#include "sun3_NCR5380.c" 490#include "atari_NCR5380.c"
736 491
737static struct scsi_host_template driver_template = { 492#ifdef SUN3_SCSI_VME
493#define SUN3_SCSI_NAME "Sun3 NCR5380 VME SCSI"
494#define DRV_MODULE_NAME "sun3_scsi_vme"
495#else
496#define SUN3_SCSI_NAME "Sun3 NCR5380 SCSI"
497#define DRV_MODULE_NAME "sun3_scsi"
498#endif
499
500#define PFX DRV_MODULE_NAME ": "
501
502static struct scsi_host_template sun3_scsi_template = {
503 .module = THIS_MODULE,
504 .proc_name = DRV_MODULE_NAME,
738 .show_info = sun3scsi_show_info, 505 .show_info = sun3scsi_show_info,
739 .name = SUN3_SCSI_NAME, 506 .name = SUN3_SCSI_NAME,
740 .detect = sun3scsi_detect,
741 .release = sun3scsi_release,
742 .info = sun3scsi_info, 507 .info = sun3scsi_info,
743 .queuecommand = sun3scsi_queue_command, 508 .queuecommand = sun3scsi_queue_command,
744 .eh_abort_handler = sun3scsi_abort, 509 .eh_abort_handler = sun3scsi_abort,
745 .eh_bus_reset_handler = sun3scsi_bus_reset, 510 .eh_bus_reset_handler = sun3scsi_bus_reset,
746 .can_queue = CAN_QUEUE, 511 .can_queue = 16,
747 .this_id = 7, 512 .this_id = 7,
748 .sg_tablesize = SG_TABLESIZE, 513 .sg_tablesize = SG_NONE,
749 .cmd_per_lun = CMD_PER_LUN, 514 .cmd_per_lun = 2,
750 .use_clustering = DISABLE_CLUSTERING 515 .use_clustering = DISABLE_CLUSTERING
751}; 516};
752 517
518static int __init sun3_scsi_probe(struct platform_device *pdev)
519{
520 struct Scsi_Host *instance;
521 int error;
522 struct resource *irq, *mem;
523 unsigned char *ioaddr;
524 int host_flags = 0;
525#ifdef SUN3_SCSI_VME
526 int i;
527#endif
528
529 if (setup_can_queue > 0)
530 sun3_scsi_template.can_queue = setup_can_queue;
531 if (setup_cmd_per_lun > 0)
532 sun3_scsi_template.cmd_per_lun = setup_cmd_per_lun;
533 if (setup_sg_tablesize >= 0)
534 sun3_scsi_template.sg_tablesize = setup_sg_tablesize;
535 if (setup_hostid >= 0)
536 sun3_scsi_template.this_id = setup_hostid & 7;
537
538#ifdef SUN3_SCSI_VME
539 ioaddr = NULL;
540 for (i = 0; i < 2; i++) {
541 unsigned char x;
542
543 irq = platform_get_resource(pdev, IORESOURCE_IRQ, i);
544 mem = platform_get_resource(pdev, IORESOURCE_MEM, i);
545 if (!irq || !mem)
546 break;
547
548 ioaddr = sun3_ioremap(mem->start, resource_size(mem),
549 SUN3_PAGE_TYPE_VME16);
550 dregs = (struct sun3_dma_regs *)(ioaddr + 8);
551
552 if (sun3_map_test((unsigned long)dregs, &x)) {
553 unsigned short oldcsr;
554
555 oldcsr = dregs->csr;
556 dregs->csr = 0;
557 udelay(SUN3_DMA_DELAY);
558 if (dregs->csr == 0x1400)
559 break;
560
561 dregs->csr = oldcsr;
562 }
563
564 iounmap(ioaddr);
565 ioaddr = NULL;
566 }
567 if (!ioaddr)
568 return -ENODEV;
569#else
570 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
571 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
572 if (!irq || !mem)
573 return -ENODEV;
574
575 ioaddr = ioremap(mem->start, resource_size(mem));
576 dregs = (struct sun3_dma_regs *)(ioaddr + 8);
577
578 udc_regs = dvma_malloc(sizeof(struct sun3_udc_regs));
579 if (!udc_regs) {
580 pr_err(PFX "couldn't allocate DVMA memory!\n");
581 iounmap(ioaddr);
582 return -ENOMEM;
583 }
584#endif
585
586 sun3_scsi_regp = ioaddr;
587
588 instance = scsi_host_alloc(&sun3_scsi_template,
589 sizeof(struct NCR5380_hostdata));
590 if (!instance) {
591 error = -ENOMEM;
592 goto fail_alloc;
593 }
594 default_instance = instance;
595
596 instance->io_port = (unsigned long)ioaddr;
597 instance->irq = irq->start;
598
599#ifdef SUPPORT_TAGS
600 host_flags |= setup_use_tagged_queuing > 0 ? FLAG_TAGGED_QUEUING : 0;
601#endif
602
603 NCR5380_init(instance, host_flags);
604
605 error = request_irq(instance->irq, scsi_sun3_intr, 0,
606 "NCR5380", instance);
607 if (error) {
608#ifdef REAL_DMA
609 pr_err(PFX "scsi%d: IRQ %d not free, bailing out\n",
610 instance->host_no, instance->irq);
611 goto fail_irq;
612#else
613 pr_warn(PFX "scsi%d: IRQ %d not free, interrupts disabled\n",
614 instance->host_no, instance->irq);
615 instance->irq = NO_IRQ;
616#endif
617 }
618
619 dregs->csr = 0;
620 udelay(SUN3_DMA_DELAY);
621 dregs->csr = CSR_SCSI | CSR_FIFO | CSR_INTR;
622 udelay(SUN3_DMA_DELAY);
623 dregs->fifo_count = 0;
624#ifdef SUN3_SCSI_VME
625 dregs->fifo_count_hi = 0;
626 dregs->dma_addr_hi = 0;
627 dregs->dma_addr_lo = 0;
628 dregs->dma_count_hi = 0;
629 dregs->dma_count_lo = 0;
630
631 dregs->ivect = VME_DATA24 | (instance->irq & 0xff);
632#endif
633
634#ifdef RESET_BOOT
635 sun3_scsi_reset_boot(instance);
636#endif
637
638 error = scsi_add_host(instance, NULL);
639 if (error)
640 goto fail_host;
641
642 platform_set_drvdata(pdev, instance);
643
644 scsi_scan_host(instance);
645 return 0;
646
647fail_host:
648 if (instance->irq != NO_IRQ)
649 free_irq(instance->irq, instance);
650fail_irq:
651 NCR5380_exit(instance);
652 scsi_host_put(instance);
653fail_alloc:
654 if (udc_regs)
655 dvma_free(udc_regs);
656 iounmap(sun3_scsi_regp);
657 return error;
658}
659
660static int __exit sun3_scsi_remove(struct platform_device *pdev)
661{
662 struct Scsi_Host *instance = platform_get_drvdata(pdev);
663
664 scsi_remove_host(instance);
665 if (instance->irq != NO_IRQ)
666 free_irq(instance->irq, instance);
667 NCR5380_exit(instance);
668 scsi_host_put(instance);
669 if (udc_regs)
670 dvma_free(udc_regs);
671 iounmap(sun3_scsi_regp);
672 return 0;
673}
674
675static struct platform_driver sun3_scsi_driver = {
676 .remove = __exit_p(sun3_scsi_remove),
677 .driver = {
678 .name = DRV_MODULE_NAME,
679 .owner = THIS_MODULE,
680 },
681};
753 682
754#include "scsi_module.c" 683module_platform_driver_probe(sun3_scsi_driver, sun3_scsi_probe);
755 684
685MODULE_ALIAS("platform:" DRV_MODULE_NAME);
756MODULE_LICENSE("GPL"); 686MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/sun3_scsi.h b/drivers/scsi/sun3_scsi.h
index e96a37cf06ac..d22745fae328 100644
--- a/drivers/scsi/sun3_scsi.h
+++ b/drivers/scsi/sun3_scsi.h
@@ -13,95 +13,11 @@
13 * (Unix and Linux consulting and custom programming) 13 * (Unix and Linux consulting and custom programming)
14 * drew@colorado.edu 14 * drew@colorado.edu
15 * +1 (303) 440-4894 15 * +1 (303) 440-4894
16 *
17 * ALPHA RELEASE 1.
18 *
19 * For more information, please consult
20 *
21 * NCR 5380 Family
22 * SCSI Protocol Controller
23 * Databook
24 *
25 * NCR Microelectronics
26 * 1635 Aeroplaza Drive
27 * Colorado Springs, CO 80916
28 * 1+ (719) 578-3400
29 * 1+ (800) 334-5454
30 */ 16 */
31 17
32#ifndef SUN3_SCSI_H 18#ifndef SUN3_SCSI_H
33#define SUN3_SCSI_H 19#define SUN3_SCSI_H
34 20
35#define SUN3SCSI_PUBLIC_RELEASE 1
36
37/*
38 * Int: level 2 autovector
39 * IO: type 1, base 0x00140000, 5 bits phys space: A<4..0>
40 */
41#define IRQ_SUN3_SCSI 2
42#define IOBASE_SUN3_SCSI 0x00140000
43
44#define IOBASE_SUN3_VMESCSI 0xff200000
45
46static int sun3scsi_abort(struct scsi_cmnd *);
47static int sun3scsi_detect (struct scsi_host_template *);
48static const char *sun3scsi_info (struct Scsi_Host *);
49static int sun3scsi_bus_reset(struct scsi_cmnd *);
50static int sun3scsi_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
51static int sun3scsi_release (struct Scsi_Host *);
52
53#ifndef CMD_PER_LUN
54#define CMD_PER_LUN 2
55#endif
56
57#ifndef CAN_QUEUE
58#define CAN_QUEUE 16
59#endif
60
61#ifndef SG_TABLESIZE
62#define SG_TABLESIZE SG_NONE
63#endif
64
65#ifndef MAX_TAGS
66#define MAX_TAGS 32
67#endif
68
69#ifndef USE_TAGGED_QUEUING
70#define USE_TAGGED_QUEUING 1
71#endif
72
73#include <scsi/scsicam.h>
74
75#ifdef SUN3_SCSI_VME
76#define SUN3_SCSI_NAME "Sun3 NCR5380 VME SCSI"
77#else
78#define SUN3_SCSI_NAME "Sun3 NCR5380 SCSI"
79#endif
80
81#define NCR5380_implementation_fields \
82 int port, ctrl
83
84#define NCR5380_local_declare() \
85 struct Scsi_Host *_instance
86
87#define NCR5380_setup(instance) \
88 _instance = instance
89
90#define NCR5380_read(reg) sun3scsi_read(reg)
91#define NCR5380_write(reg, value) sun3scsi_write(reg, value)
92
93#define NCR5380_intr sun3scsi_intr
94#define NCR5380_queue_command sun3scsi_queue_command
95#define NCR5380_bus_reset sun3scsi_bus_reset
96#define NCR5380_abort sun3scsi_abort
97#define NCR5380_show_info sun3scsi_show_info
98#define NCR5380_dma_xfer_len(i, cmd, phase) \
99 sun3scsi_dma_xfer_len(cmd->SCp.this_residual,cmd,((phase) & SR_IO) ? 0 : 1)
100
101#define NCR5380_dma_write_setup(instance, data, count) sun3scsi_dma_setup(data, count, 1)
102#define NCR5380_dma_read_setup(instance, data, count) sun3scsi_dma_setup(data, count, 0)
103#define NCR5380_dma_residual sun3scsi_dma_residual
104
105/* additional registers - mainly DMA control regs */ 21/* additional registers - mainly DMA control regs */
106/* these start at regbase + 8 -- directly after the NCR regs */ 22/* these start at regbase + 8 -- directly after the NCR regs */
107struct sun3_dma_regs { 23struct sun3_dma_regs {
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index e59e6f96b725..5d00e514ff28 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -820,9 +820,7 @@ static int sym53c8xx_slave_configure(struct scsi_device *sdev)
820 if (reqtags > SYM_CONF_MAX_TAG) 820 if (reqtags > SYM_CONF_MAX_TAG)
821 reqtags = SYM_CONF_MAX_TAG; 821 reqtags = SYM_CONF_MAX_TAG;
822 depth_to_use = reqtags ? reqtags : 1; 822 depth_to_use = reqtags ? reqtags : 1;
823 scsi_adjust_queue_depth(sdev, 823 scsi_change_queue_depth(sdev, depth_to_use);
824 sdev->tagged_supported ? MSG_SIMPLE_TAG : 0,
825 depth_to_use);
826 lp->s.scdev_depth = depth_to_use; 824 lp->s.scdev_depth = depth_to_use;
827 sym_tune_dev_queuing(tp, sdev->lun, reqtags); 825 sym_tune_dev_queuing(tp, sdev->lun, reqtags);
828 826
diff --git a/drivers/scsi/t128.c b/drivers/scsi/t128.c
index 8cc80931df14..87828acbf7c6 100644
--- a/drivers/scsi/t128.c
+++ b/drivers/scsi/t128.c
@@ -1,4 +1,3 @@
1#define AUTOSENSE
2#define PSEUDO_DMA 1#define PSEUDO_DMA
3 2
4/* 3/*
@@ -12,8 +11,6 @@
12 * drew@colorado.edu 11 * drew@colorado.edu
13 * +1 (303) 440-4894 12 * +1 (303) 440-4894
14 * 13 *
15 * DISTRIBUTION RELEASE 3.
16 *
17 * For more information, please consult 14 * For more information, please consult
18 * 15 *
19 * Trantor Systems, Ltd. 16 * Trantor Systems, Ltd.
@@ -24,40 +21,9 @@
24 * 5415 Randall Place 21 * 5415 Randall Place
25 * Fremont, CA 94538 22 * Fremont, CA 94538
26 * 1+ (415) 770-1400, FAX 1+ (415) 770-9910 23 * 1+ (415) 770-1400, FAX 1+ (415) 770-9910
27 *
28 * and
29 *
30 * NCR 5380 Family
31 * SCSI Protocol Controller
32 * Databook
33 *
34 * NCR Microelectronics
35 * 1635 Aeroplaza Drive
36 * Colorado Springs, CO 80916
37 * 1+ (719) 578-3400
38 * 1+ (800) 334-5454
39 */ 24 */
40 25
41/* 26/*
42 * Options :
43 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
44 * for commands that return with a CHECK CONDITION status.
45 *
46 * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
47 * increase compared to polled I/O.
48 *
49 * PARITY - enable parity checking. Not supported.
50 *
51 * SCSI2 - enable support for SCSI-II tagged queueing. Untested.
52 *
53 *
54 * UNSAFE - leave interrupts enabled during pseudo-DMA transfers. You
55 * only really want to use this if you're having a problem with
56 * dropped characters during high speed communications, and even
57 * then, you're going to be better off twiddling with transfersize.
58 *
59 * USLEEP - enable support for devices that don't disconnect. Untested.
60 *
61 * The card is detected and initialized in one of several ways : 27 * The card is detected and initialized in one of several ways :
62 * 1. Autoprobe (default) - since the board is memory mapped, 28 * 1. Autoprobe (default) - since the board is memory mapped,
63 * a BIOS signature is scanned for to locate the registers. 29 * a BIOS signature is scanned for to locate the registers.
@@ -111,7 +77,6 @@
111#include <linux/module.h> 77#include <linux/module.h>
112#include <linux/delay.h> 78#include <linux/delay.h>
113 79
114#include "scsi.h"
115#include <scsi/scsi_host.h> 80#include <scsi/scsi_host.h>
116#include "t128.h" 81#include "t128.h"
117#define AUTOPROBE_IRQ 82#define AUTOPROBE_IRQ
@@ -148,6 +113,7 @@ static struct signature {
148 113
149#define NO_SIGNATURES ARRAY_SIZE(signatures) 114#define NO_SIGNATURES ARRAY_SIZE(signatures)
150 115
116#ifndef MODULE
151/* 117/*
152 * Function : t128_setup(char *str, int *ints) 118 * Function : t128_setup(char *str, int *ints)
153 * 119 *
@@ -158,9 +124,13 @@ static struct signature {
158 * 124 *
159 */ 125 */
160 126
161void __init t128_setup(char *str, int *ints){ 127static int __init t128_setup(char *str)
128{
162 static int commandline_current = 0; 129 static int commandline_current = 0;
163 int i; 130 int i;
131 int ints[10];
132
133 get_options(str, ARRAY_SIZE(ints), ints);
164 if (ints[0] != 2) 134 if (ints[0] != 2)
165 printk("t128_setup : usage t128=address,irq\n"); 135 printk("t128_setup : usage t128=address,irq\n");
166 else 136 else
@@ -174,8 +144,12 @@ void __init t128_setup(char *str, int *ints){
174 } 144 }
175 ++commandline_current; 145 ++commandline_current;
176 } 146 }
147 return 1;
177} 148}
178 149
150__setup("t128=", t128_setup);
151#endif
152
179/* 153/*
180 * Function : int t128_detect(struct scsi_host_template * tpnt) 154 * Function : int t128_detect(struct scsi_host_template * tpnt)
181 * 155 *
@@ -189,17 +163,14 @@ void __init t128_setup(char *str, int *ints){
189 * 163 *
190 */ 164 */
191 165
192int __init t128_detect(struct scsi_host_template * tpnt){ 166static int __init t128_detect(struct scsi_host_template *tpnt)
167{
193 static int current_override = 0, current_base = 0; 168 static int current_override = 0, current_base = 0;
194 struct Scsi_Host *instance; 169 struct Scsi_Host *instance;
195 unsigned long base; 170 unsigned long base;
196 void __iomem *p; 171 void __iomem *p;
197 int sig, count; 172 int sig, count;
198 173
199 tpnt->proc_name = "t128";
200 tpnt->show_info = t128_show_info;
201 tpnt->write_info = t128_write_info;
202
203 for (count = 0; current_override < NO_OVERRIDES; ++current_override) { 174 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
204 base = 0; 175 base = 0;
205 p = NULL; 176 p = NULL;
@@ -254,15 +225,19 @@ found:
254 else 225 else
255 instance->irq = NCR5380_probe_irq(instance, T128_IRQS); 226 instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
256 227
257 if (instance->irq != SCSI_IRQ_NONE) 228 /* Compatibility with documented NCR5380 kernel parameters */
229 if (instance->irq == 255)
230 instance->irq = NO_IRQ;
231
232 if (instance->irq != NO_IRQ)
258 if (request_irq(instance->irq, t128_intr, 0, "t128", 233 if (request_irq(instance->irq, t128_intr, 0, "t128",
259 instance)) { 234 instance)) {
260 printk("scsi%d : IRQ%d not free, interrupts disabled\n", 235 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
261 instance->host_no, instance->irq); 236 instance->host_no, instance->irq);
262 instance->irq = SCSI_IRQ_NONE; 237 instance->irq = NO_IRQ;
263 } 238 }
264 239
265 if (instance->irq == SCSI_IRQ_NONE) { 240 if (instance->irq == NO_IRQ) {
266 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no); 241 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
267 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no); 242 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
268 } 243 }
@@ -271,16 +246,6 @@ found:
271 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq); 246 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
272#endif 247#endif
273 248
274 printk("scsi%d : at 0x%08lx", instance->host_no, instance->base);
275 if (instance->irq == SCSI_IRQ_NONE)
276 printk (" interrupts disabled");
277 else
278 printk (" irq %d", instance->irq);
279 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
280 CAN_QUEUE, CMD_PER_LUN, T128_PUBLIC_RELEASE);
281 NCR5380_print_options(instance);
282 printk("\n");
283
284 ++current_override; 249 ++current_override;
285 ++count; 250 ++count;
286 } 251 }
@@ -291,7 +256,7 @@ static int t128_release(struct Scsi_Host *shost)
291{ 256{
292 NCR5380_local_declare(); 257 NCR5380_local_declare();
293 NCR5380_setup(shost); 258 NCR5380_setup(shost);
294 if (shost->irq) 259 if (shost->irq != NO_IRQ)
295 free_irq(shost->irq, shost); 260 free_irq(shost->irq, shost);
296 NCR5380_exit(shost); 261 NCR5380_exit(shost);
297 if (shost->io_port && shost->n_io_port) 262 if (shost->io_port && shost->n_io_port)
@@ -321,8 +286,8 @@ static int t128_release(struct Scsi_Host *shost)
321 * and matching the H_C_S coordinates to what DOS uses. 286 * and matching the H_C_S coordinates to what DOS uses.
322 */ 287 */
323 288
324int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev, 289static int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
325 sector_t capacity, int * ip) 290 sector_t capacity, int *ip)
326{ 291{
327 ip[0] = 64; 292 ip[0] = 64;
328 ip[1] = 32; 293 ip[1] = 32;
@@ -430,6 +395,10 @@ static struct scsi_host_template driver_template = {
430 .name = "Trantor T128/T128F/T228", 395 .name = "Trantor T128/T128F/T228",
431 .detect = t128_detect, 396 .detect = t128_detect,
432 .release = t128_release, 397 .release = t128_release,
398 .proc_name = "t128",
399 .show_info = t128_show_info,
400 .write_info = t128_write_info,
401 .info = t128_info,
433 .queuecommand = t128_queue_command, 402 .queuecommand = t128_queue_command,
434 .eh_abort_handler = t128_abort, 403 .eh_abort_handler = t128_abort,
435 .eh_bus_reset_handler = t128_bus_reset, 404 .eh_bus_reset_handler = t128_bus_reset,
diff --git a/drivers/scsi/t128.h b/drivers/scsi/t128.h
index fd68cecc62af..2c7371454dfd 100644
--- a/drivers/scsi/t128.h
+++ b/drivers/scsi/t128.h
@@ -8,8 +8,6 @@
8 * drew@colorado.edu 8 * drew@colorado.edu
9 * +1 (303) 440-4894 9 * +1 (303) 440-4894
10 * 10 *
11 * DISTRIBUTION RELEASE 3.
12 *
13 * For more information, please consult 11 * For more information, please consult
14 * 12 *
15 * Trantor Systems, Ltd. 13 * Trantor Systems, Ltd.
@@ -20,25 +18,11 @@
20 * 5415 Randall Place 18 * 5415 Randall Place
21 * Fremont, CA 94538 19 * Fremont, CA 94538
22 * 1+ (415) 770-1400, FAX 1+ (415) 770-9910 20 * 1+ (415) 770-1400, FAX 1+ (415) 770-9910
23 *
24 * and
25 *
26 * NCR 5380 Family
27 * SCSI Protocol Controller
28 * Databook
29 *
30 * NCR Microelectronics
31 * 1635 Aeroplaza Drive
32 * Colorado Springs, CO 80916
33 * 1+ (719) 578-3400
34 * 1+ (800) 334-5454
35 */ 21 */
36 22
37#ifndef T128_H 23#ifndef T128_H
38#define T128_H 24#define T128_H
39 25
40#define T128_PUBLIC_RELEASE 3
41
42#define TDEBUG 0 26#define TDEBUG 0
43#define TDEBUG_INIT 0x1 27#define TDEBUG_INIT 0x1
44#define TDEBUG_TRANSFER 0x2 28#define TDEBUG_TRANSFER 0x2
@@ -88,12 +72,6 @@
88#define T_DATA_REG_OFFSET 0x1e00 /* rw 512 bytes long */ 72#define T_DATA_REG_OFFSET 0x1e00 /* rw 512 bytes long */
89 73
90#ifndef ASM 74#ifndef ASM
91static int t128_abort(struct scsi_cmnd *);
92static int t128_biosparam(struct scsi_device *, struct block_device *,
93 sector_t, int*);
94static int t128_detect(struct scsi_host_template *);
95static int t128_queue_command(struct Scsi_Host *, struct scsi_cmnd *);
96static int t128_bus_reset(struct scsi_cmnd *);
97 75
98#ifndef CMD_PER_LUN 76#ifndef CMD_PER_LUN
99#define CMD_PER_LUN 2 77#define CMD_PER_LUN 2
@@ -134,6 +112,7 @@ static int t128_bus_reset(struct scsi_cmnd *);
134#define NCR5380_queue_command t128_queue_command 112#define NCR5380_queue_command t128_queue_command
135#define NCR5380_abort t128_abort 113#define NCR5380_abort t128_abort
136#define NCR5380_bus_reset t128_bus_reset 114#define NCR5380_bus_reset t128_bus_reset
115#define NCR5380_info t128_info
137#define NCR5380_show_info t128_show_info 116#define NCR5380_show_info t128_show_info
138#define NCR5380_write_info t128_write_info 117#define NCR5380_write_info t128_write_info
139 118
diff --git a/drivers/scsi/tmscsim.c b/drivers/scsi/tmscsim.c
deleted file mode 100644
index 764575726c85..000000000000
--- a/drivers/scsi/tmscsim.c
+++ /dev/null
@@ -1,2620 +0,0 @@
1/************************************************************************
2 * FILE NAME : TMSCSIM.C *
3 * BY : C.L. Huang, ching@tekram.com.tw *
4 * Description: Device Driver for Tekram DC-390(T) PCI SCSI *
5 * Bus Master Host Adapter *
6 * (C)Copyright 1995-1996 Tekram Technology Co., Ltd. *
7 ************************************************************************
8 * (C) Copyright: put under GNU GPL in 10/96 *
9 * (see Documentation/scsi/tmscsim.txt) *
10 ************************************************************************
11 * $Id: tmscsim.c,v 2.60.2.30 2000/12/20 01:07:12 garloff Exp $ *
12 * Enhancements and bugfixes by *
13 * Kurt Garloff <kurt@garloff.de> <garloff@suse.de> *
14 ************************************************************************
15 * HISTORY: *
16 * *
17 * REV# DATE NAME DESCRIPTION *
18 * 1.00 96/04/24 CLH First release *
19 * 1.01 96/06/12 CLH Fixed bug of Media Change for Removable *
20 * Device, scan all LUN. Support Pre2.0.10 *
21 * 1.02 96/06/18 CLH Fixed bug of Command timeout ... *
22 * 1.03 96/09/25 KG Added tmscsim_proc_info() *
23 * 1.04 96/10/11 CLH Updating for support KV 2.0.x *
24 * 1.05 96/10/18 KG Fixed bug in DC390_abort(null ptr deref)*
25 * 1.06 96/10/25 KG Fixed module support *
26 * 1.07 96/11/09 KG Fixed tmscsim_proc_info() *
27 * 1.08 96/11/18 KG Fixed null ptr in DC390_Disconnect() *
28 * 1.09 96/11/30 KG Added register the allocated IO space *
29 * 1.10 96/12/05 CLH Modified tmscsim_proc_info(), and reset *
30 * pending interrupt in DC390_detect() *
31 * 1.11 97/02/05 KG/CLH Fixeds problem with partitions greater *
32 * than 1GB *
33 * 1.12 98/02/15 MJ Rewritten PCI probing *
34 * 1.13 98/04/08 KG Support for non DC390, __initfunc decls,*
35 * changed max devs from 10 to 16 *
36 * 1.14a 98/05/05 KG Dynamic DCB allocation, add-single-dev *
37 * for LUNs if LUN_SCAN (BIOS) not set *
38 * runtime config using /proc interface *
39 * 1.14b 98/05/06 KG eliminated cli (); sti (); spinlocks *
40 * 1.14c 98/05/07 KG 2.0.x compatibility *
41 * 1.20a 98/05/07 KG changed names of funcs to be consistent *
42 * DC390_ (entry points), dc390_ (internal)*
43 * reworked locking *
44 * 1.20b 98/05/12 KG bugs: version, kfree, _ctmp *
45 * debug output *
46 * 1.20c 98/05/12 KG bugs: kfree, parsing, EEpromDefaults *
47 * 1.20d 98/05/14 KG bugs: list linkage, clear flag after *
48 * reset on startup, code cleanup *
49 * 1.20e 98/05/15 KG spinlock comments, name space cleanup *
50 * pLastDCB now part of ACB structure *
51 * added stats, timeout for 2.1, TagQ bug *
52 * RESET and INQUIRY interface commands *
53 * 1.20f 98/05/18 KG spinlocks fixes, max_lun fix, free DCBs *
54 * for missing LUNs, pending int *
55 * 1.20g 98/05/19 KG Clean up: Avoid short *
56 * 1.20h 98/05/21 KG Remove AdaptSCSIID, max_lun ... *
57 * 1.20i 98/05/21 KG Aiiie: Bug with TagQMask *
58 * 1.20j 98/05/24 KG Handle STAT_BUSY, handle pACB->pLinkDCB *
59 * == 0 in remove_dev and DoingSRB_Done *
60 * 1.20k 98/05/25 KG DMA_INT (experimental) *
61 * 1.20l 98/05/27 KG remove DMA_INT; DMA_IDLE cmds added; *
62 * 1.20m 98/06/10 KG glitch configurable; made some global *
63 * vars part of ACB; use DC390_readX *
64 * 1.20n 98/06/11 KG startup params *
65 * 1.20o 98/06/15 KG added TagMaxNum to boot/module params *
66 * Device Nr -> Idx, TagMaxNum power of 2 *
67 * 1.20p 98/06/17 KG Docu updates. Reset depends on settings *
68 * pci_set_master added; 2.0.xx: pcibios_* *
69 * used instead of MechNum things ... *
70 * 1.20q 98/06/23 KG Changed defaults. Added debug code for *
71 * removable media and fixed it. TagMaxNum *
72 * fixed for DC390. Locking: ACB, DRV for *
73 * better IRQ sharing. Spelling: Queueing *
74 * Parsing and glitch_cfg changes. Display *
75 * real SyncSpeed value. Made DisConn *
76 * functional (!) *
77 * 1.20r 98/06/30 KG Debug macros, allow disabling DsCn, set *
78 * BIT4 in CtrlR4, EN_PAGE_INT, 2.0 module *
79 * param -1 fixed. *
80 * 1.20s 98/08/20 KG Debug info on abort(), try to check PCI,*
81 * phys_to_bus instead of phys_to_virt, *
82 * fixed sel. process, fixed locking, *
83 * added MODULE_XXX infos, changed IRQ *
84 * request flags, disable DMA_INT *
85 * 1.20t 98/09/07 KG TagQ report fixed; Write Erase DMA Stat;*
86 * initfunc -> __init; better abort; *
87 * Timeout for XFER_DONE & BLAST_COMPLETE; *
88 * Allow up to 33 commands being processed *
89 * 2.0a 98/10/14 KG Max Cmnds back to 17. DMA_Stat clearing *
90 * all flags. Clear within while() loops *
91 * in DataIn_0/Out_0. Null ptr in dumpinfo *
92 * for pSRB==0. Better locking during init.*
93 * bios_param() now respects part. table. *
94 * 2.0b 98/10/24 KG Docu fixes. Timeout Msg in DMA Blast. *
95 * Disallow illegal idx in INQUIRY/REMOVE *
96 * 2.0c 98/11/19 KG Cleaned up detect/init for SMP boxes, *
97 * Write Erase DMA (1.20t) caused problems *
98 * 2.0d 98/12/25 KG Christmas release ;-) Message handling *
99 * completely reworked. Handle target ini- *
100 * tiated SDTR correctly. *
101 * 2.0d1 99/01/25 KG Try to handle RESTORE_PTR *
102 * 2.0d2 99/02/08 KG Check for failure of kmalloc, correct *
103 * inclusion of scsicam.h, DelayReset *
104 * 2.0d3 99/05/31 KG DRIVER_OK -> DID_OK, DID_NO_CONNECT, *
105 * detect Target mode and warn. *
106 * pcmd->result handling cleaned up. *
107 * 2.0d4 99/06/01 KG Cleaned selection process. Found bug *
108 * which prevented more than 16 tags. Now: *
109 * 24. SDTR cleanup. Cleaner multi-LUN *
110 * handling. Don't modify ControlRegs/FIFO *
111 * when connected. *
112 * 2.0d5 99/06/01 KG Clear DevID, Fix INQUIRY after cfg chg. *
113 * 2.0d6 99/06/02 KG Added ADD special command to allow cfg. *
114 * before detection. Reset SYNC_NEGO_DONE *
115 * after a bus reset. *
116 * 2.0d7 99/06/03 KG Fixed bugs wrt add,remove commands *
117 * 2.0d8 99/06/04 KG Removed copying of cmnd into CmdBlock. *
118 * Fixed Oops in _release(). *
119 * 2.0d9 99/06/06 KG Also tag queue INQUIRY, T_U_R, ... *
120 * Allow arb. no. of Tagged Cmnds. Max 32 *
121 * 2.0d1099/06/20 KG TagMaxNo changes now honoured! Queueing *
122 * clearified (renamed ..) TagMask handling*
123 * cleaned. *
124 * 2.0d1199/06/28 KG cmd->result now identical to 2.0d2 *
125 * 2.0d1299/07/04 KG Changed order of processing in IRQ *
126 * 2.0d1399/07/05 KG Don't update DCB fields if removed *
127 * 2.0d1499/07/05 KG remove_dev: Move kfree() to the end *
128 * 2.0d1599/07/12 KG use_new_eh_code: 0, ULONG -> UINT where *
129 * appropriate *
130 * 2.0d1699/07/13 KG Reenable StartSCSI interrupt, Retry msg *
131 * 2.0d1799/07/15 KG Remove debug msg. Disable recfg. when *
132 * there are queued cmnds *
133 * 2.0d1899/07/18 KG Selection timeout: Don't requeue *
134 * 2.0d1999/07/18 KG Abort: Only call scsi_done if dequeued *
135 * 2.0d2099/07/19 KG Rst_Detect: DoingSRB_Done *
136 * 2.0d2199/08/15 KG dev_id for request/free_irq, cmnd[0] for*
137 * RETRY, SRBdone does DID_ABORT for the *
138 * cmd passed by DC390_reset() *
139 * 2.0d2299/08/25 KG dev_id fixed. can_queue: 42 *
140 * 2.0d2399/08/25 KG Removed some debugging code. dev_id *
141 * now is set to pACB. Use u8,u16,u32. *
142 * 2.0d2499/11/14 KG Unreg. I/O if failed IRQ alloc. Call *
143 * done () w/ DID_BAD_TARGET in case of *
144 * missing DCB. We are old EH!! *
145 * 2.0d2500/01/15 KG 2.3.3x compat from Andreas Schultz *
146 * set unique_id. Disable RETRY message. *
147 * 2.0d2600/01/29 KG Go to new EH. *
148 * 2.0d2700/01/31 KG ... but maintain 2.0 compat. *
149 * and fix DCB freeing *
150 * 2.0d2800/02/14 KG Queue statistics fixed, dump special cmd*
151 * Waiting_Timer for failed StartSCSI *
152 * New EH: Don't return cmnds to ML on RST *
153 * Use old EH (don't have new EH fns yet) *
154 * Reset: Unlock, but refuse to queue *
155 * 2.3 __setup function *
156 * 2.0e 00/05/22 KG Return residual for 2.3 *
157 * 2.0e1 00/05/25 KG Compile fixes for 2.3.99 *
158 * 2.0e2 00/05/27 KG Jeff Garzik's pci_enable_device() *
159 * 2.0e3 00/09/29 KG Some 2.4 changes. Don't try Sync Nego *
160 * before INQUIRY has reported ability. *
161 * Recognise INQUIRY as scanning command. *
162 * 2.0e4 00/10/13 KG Allow compilation into 2.4 kernel *
163 * 2.0e5 00/11/17 KG Store Inq.flags in DCB *
164 * 2.0e6 00/11/22 KG 2.4 init function (Thx to O.Schumann) *
165 * 2.4 PCI device table (Thx to A.Richter) *
166 * 2.0e7 00/11/28 KG Allow overriding of BIOS settings *
167 * 2.0f 00/12/20 KG Handle failed INQUIRYs during scan *
168 * 2.1a 03/11/29 GL, KG Initial fixing for 2.6. Convert to *
169 * use the current PCI-mapping API, update *
170 * command-queuing. *
171 * 2.1b 04/04/13 GL Fix for 64-bit platforms *
172 * 2.1b1 04/01/31 GL (applied 05.04) Remove internal *
173 * command-queuing. *
174 * 2.1b2 04/02/01 CH (applied 05.04) Fix error-handling *
175 * 2.1c 04/05/23 GL Update to use the new pci_driver API, *
176 * some scsi EH updates, more cleanup. *
177 * 2.1d 04/05/27 GL Moved setting of scan_devices to *
178 * slave_alloc/_configure/_destroy, as *
179 * suggested by CH. *
180 ***********************************************************************/
181
182/* DEBUG options */
183//#define DC390_DEBUG0
184//#define DC390_DEBUG1
185//#define DC390_DCBDEBUG
186//#define DC390_PARSEDEBUG
187//#define DC390_REMOVABLEDEBUG
188//#define DC390_LOCKDEBUG
189
190//#define NOP do{}while(0)
191#define C_NOP
192
193/* Debug definitions */
194#ifdef DC390_DEBUG0
195# define DEBUG0(x) x
196#else
197# define DEBUG0(x) C_NOP
198#endif
199#ifdef DC390_DEBUG1
200# define DEBUG1(x) x
201#else
202# define DEBUG1(x) C_NOP
203#endif
204#ifdef DC390_DCBDEBUG
205# define DCBDEBUG(x) x
206#else
207# define DCBDEBUG(x) C_NOP
208#endif
209#ifdef DC390_PARSEDEBUG
210# define PARSEDEBUG(x) x
211#else
212# define PARSEDEBUG(x) C_NOP
213#endif
214#ifdef DC390_REMOVABLEDEBUG
215# define REMOVABLEDEBUG(x) x
216#else
217# define REMOVABLEDEBUG(x) C_NOP
218#endif
219#define DCBDEBUG1(x) C_NOP
220
221#include <linux/module.h>
222#include <linux/delay.h>
223#include <linux/signal.h>
224#include <linux/errno.h>
225#include <linux/kernel.h>
226#include <linux/ioport.h>
227#include <linux/pci.h>
228#include <linux/proc_fs.h>
229#include <linux/string.h>
230#include <linux/mm.h>
231#include <linux/blkdev.h>
232#include <linux/timer.h>
233#include <linux/interrupt.h>
234#include <linux/init.h>
235#include <linux/spinlock.h>
236#include <linux/slab.h>
237#include <asm/io.h>
238
239#include <scsi/scsi.h>
240#include <scsi/scsi_cmnd.h>
241#include <scsi/scsi_device.h>
242#include <scsi/scsi_host.h>
243#include <scsi/scsicam.h>
244#include <scsi/scsi_tcq.h>
245
246
247#define DC390_BANNER "Tekram DC390/AM53C974"
248#define DC390_VERSION "2.1d 2004-05-27"
249
250#define PCI_DEVICE_ID_AMD53C974 PCI_DEVICE_ID_AMD_SCSI
251
252#include "tmscsim.h"
253
254
255static void dc390_DataOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
256static void dc390_DataIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
257static void dc390_Command_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
258static void dc390_Status_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
259static void dc390_MsgOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
260static void dc390_MsgIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
261static void dc390_DataOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
262static void dc390_DataInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
263static void dc390_CommandPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
264static void dc390_StatusPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
265static void dc390_MsgOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
266static void dc390_MsgInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
267static void dc390_Nop_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
268static void dc390_Nop_1( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus);
269
270static void dc390_SetXferRate( struct dc390_acb* pACB, struct dc390_dcb* pDCB );
271static void dc390_Disconnect( struct dc390_acb* pACB );
272static void dc390_Reselect( struct dc390_acb* pACB );
273static void dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB );
274static void dc390_ScsiRstDetect( struct dc390_acb* pACB );
275static void dc390_EnableMsgOut_Abort(struct dc390_acb*, struct dc390_srb*);
276static void dc390_dumpinfo(struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB);
277static void dc390_ResetDevParam(struct dc390_acb* pACB);
278
279static u32 dc390_laststatus = 0;
280static u8 dc390_adapterCnt = 0;
281
282static int disable_clustering;
283module_param(disable_clustering, int, S_IRUGO);
284MODULE_PARM_DESC(disable_clustering, "If you experience problems with your devices, try setting to 1");
285
286/* Startup values, to be overriden on the commandline */
287static int tmscsim[] = {-2, -2, -2, -2, -2, -2};
288
289module_param_array(tmscsim, int, NULL, 0);
290MODULE_PARM_DESC(tmscsim, "Host SCSI ID, Speed (0=10MHz), Device Flags, Adapter Flags, Max Tags (log2(tags)-1), DelayReset (s)");
291MODULE_AUTHOR("C.L. Huang / Kurt Garloff");
292MODULE_DESCRIPTION("SCSI host adapter driver for Tekram DC390 and other AMD53C974A based PCI SCSI adapters");
293MODULE_LICENSE("GPL");
294MODULE_SUPPORTED_DEVICE("sd,sr,sg,st");
295
296static void *dc390_phase0[]={
297 dc390_DataOut_0,
298 dc390_DataIn_0,
299 dc390_Command_0,
300 dc390_Status_0,
301 dc390_Nop_0,
302 dc390_Nop_0,
303 dc390_MsgOut_0,
304 dc390_MsgIn_0,
305 dc390_Nop_1
306 };
307
308static void *dc390_phase1[]={
309 dc390_DataOutPhase,
310 dc390_DataInPhase,
311 dc390_CommandPhase,
312 dc390_StatusPhase,
313 dc390_Nop_0,
314 dc390_Nop_0,
315 dc390_MsgOutPhase,
316 dc390_MsgInPhase,
317 dc390_Nop_1
318 };
319
320#ifdef DC390_DEBUG1
321static char* dc390_p0_str[] = {
322 "dc390_DataOut_0",
323 "dc390_DataIn_0",
324 "dc390_Command_0",
325 "dc390_Status_0",
326 "dc390_Nop_0",
327 "dc390_Nop_0",
328 "dc390_MsgOut_0",
329 "dc390_MsgIn_0",
330 "dc390_Nop_1"
331 };
332
333static char* dc390_p1_str[] = {
334 "dc390_DataOutPhase",
335 "dc390_DataInPhase",
336 "dc390_CommandPhase",
337 "dc390_StatusPhase",
338 "dc390_Nop_0",
339 "dc390_Nop_0",
340 "dc390_MsgOutPhase",
341 "dc390_MsgInPhase",
342 "dc390_Nop_1"
343 };
344#endif
345
346static u8 dc390_eepromBuf[MAX_ADAPTER_NUM][EE_LEN];
347static u8 dc390_clock_period1[] = {4, 5, 6, 7, 8, 10, 13, 20};
348static u8 dc390_clock_speed[] = {100,80,67,57,50, 40, 31, 20};
349
350/***********************************************************************
351 * Functions for the management of the internal structures
352 * (DCBs, SRBs, Queueing)
353 *
354 **********************************************************************/
355static void inline dc390_start_segment(struct dc390_srb* pSRB)
356{
357 struct scatterlist *psgl = pSRB->pSegmentList;
358
359 /* start new sg segment */
360 pSRB->SGBusAddr = sg_dma_address(psgl);
361 pSRB->SGToBeXferLen = sg_dma_len(psgl);
362}
363
364static unsigned long inline dc390_advance_segment(struct dc390_srb* pSRB, u32 residue)
365{
366 unsigned long xfer = pSRB->SGToBeXferLen - residue;
367
368 /* xfer more bytes transferred */
369 pSRB->SGBusAddr += xfer;
370 pSRB->TotalXferredLen += xfer;
371 pSRB->SGToBeXferLen = residue;
372
373 return xfer;
374}
375
376static struct dc390_dcb __inline__ *dc390_findDCB ( struct dc390_acb* pACB, u8 id, u8 lun)
377{
378 struct dc390_dcb* pDCB = pACB->pLinkDCB; if (!pDCB) return NULL;
379 while (pDCB->TargetID != id || pDCB->TargetLUN != lun)
380 {
381 pDCB = pDCB->pNextDCB;
382 if (pDCB == pACB->pLinkDCB)
383 return NULL;
384 }
385 DCBDEBUG1( printk (KERN_DEBUG "DCB %p (%02x,%02x) found.\n", \
386 pDCB, pDCB->TargetID, pDCB->TargetLUN));
387 return pDCB;
388}
389
390/* Insert SRB oin top of free list */
391static __inline__ void dc390_Free_insert (struct dc390_acb* pACB, struct dc390_srb* pSRB)
392{
393 DEBUG0(printk ("DC390: Free SRB %p\n", pSRB));
394 pSRB->pNextSRB = pACB->pFreeSRB;
395 pACB->pFreeSRB = pSRB;
396}
397
398static __inline__ void dc390_Going_append (struct dc390_dcb* pDCB, struct dc390_srb* pSRB)
399{
400 pDCB->GoingSRBCnt++;
401 DEBUG0(printk("DC390: Append SRB %p to Going\n", pSRB));
402 /* Append to the list of Going commands */
403 if( pDCB->pGoingSRB )
404 pDCB->pGoingLast->pNextSRB = pSRB;
405 else
406 pDCB->pGoingSRB = pSRB;
407
408 pDCB->pGoingLast = pSRB;
409 /* No next one in sent list */
410 pSRB->pNextSRB = NULL;
411}
412
413static __inline__ void dc390_Going_remove (struct dc390_dcb* pDCB, struct dc390_srb* pSRB)
414{
415 DEBUG0(printk("DC390: Remove SRB %p from Going\n", pSRB));
416 if (pSRB == pDCB->pGoingSRB)
417 pDCB->pGoingSRB = pSRB->pNextSRB;
418 else
419 {
420 struct dc390_srb* psrb = pDCB->pGoingSRB;
421 while (psrb && psrb->pNextSRB != pSRB)
422 psrb = psrb->pNextSRB;
423 if (!psrb)
424 { printk (KERN_ERR "DC390: Remove non-ex. SRB %p from Going!\n", pSRB); return; }
425 psrb->pNextSRB = pSRB->pNextSRB;
426 if (pSRB == pDCB->pGoingLast)
427 pDCB->pGoingLast = psrb;
428 }
429 pDCB->GoingSRBCnt--;
430}
431
432static struct scatterlist* dc390_sg_build_single(struct scatterlist *sg, void *addr, unsigned int length)
433{
434 sg_init_one(sg, addr, length);
435 return sg;
436}
437
438/* Create pci mapping */
439static int dc390_pci_map (struct dc390_srb* pSRB)
440{
441 int error = 0;
442 struct scsi_cmnd *pcmd = pSRB->pcmd;
443 struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev;
444 dc390_cmd_scp_t* cmdp = ((dc390_cmd_scp_t*)(&pcmd->SCp));
445
446 /* Map sense buffer */
447 if (pSRB->SRBFlag & AUTO_REQSENSE) {
448 pSRB->pSegmentList = dc390_sg_build_single(&pSRB->Segmentx, pcmd->sense_buffer, SCSI_SENSE_BUFFERSIZE);
449 pSRB->SGcount = pci_map_sg(pdev, pSRB->pSegmentList, 1,
450 DMA_FROM_DEVICE);
451 cmdp->saved_dma_handle = sg_dma_address(pSRB->pSegmentList);
452
453 /* TODO: error handling */
454 if (pSRB->SGcount != 1)
455 error = 1;
456 DEBUG1(printk("%s(): Mapped sense buffer %p at %x\n", __func__, pcmd->sense_buffer, cmdp->saved_dma_handle));
457 /* Map SG list */
458 } else if (scsi_sg_count(pcmd)) {
459 int nseg;
460
461 nseg = scsi_dma_map(pcmd);
462
463 pSRB->pSegmentList = scsi_sglist(pcmd);
464 pSRB->SGcount = nseg;
465
466 /* TODO: error handling */
467 if (nseg < 0)
468 error = 1;
469 DEBUG1(printk("%s(): Mapped SG %p with %d (%d) elements\n",\
470 __func__, scsi_sglist(pcmd), nseg, scsi_sg_count(pcmd)));
471 /* Map single segment */
472 } else
473 pSRB->SGcount = 0;
474
475 return error;
476}
477
478/* Remove pci mapping */
479static void dc390_pci_unmap (struct dc390_srb* pSRB)
480{
481 struct scsi_cmnd *pcmd = pSRB->pcmd;
482 struct pci_dev *pdev = pSRB->pSRBDCB->pDCBACB->pdev;
483 DEBUG1(dc390_cmd_scp_t* cmdp = ((dc390_cmd_scp_t*)(&pcmd->SCp)));
484
485 if (pSRB->SRBFlag) {
486 pci_unmap_sg(pdev, &pSRB->Segmentx, 1, DMA_FROM_DEVICE);
487 DEBUG1(printk("%s(): Unmapped sense buffer at %x\n", __func__, cmdp->saved_dma_handle));
488 } else {
489 scsi_dma_unmap(pcmd);
490 DEBUG1(printk("%s(): Unmapped SG at %p with %d elements\n",
491 __func__, scsi_sglist(pcmd), scsi_sg_count(pcmd)));
492 }
493}
494
495static void __inline__
496dc390_freetag (struct dc390_dcb* pDCB, struct dc390_srb* pSRB)
497{
498 if (pSRB->TagNumber != SCSI_NO_TAG) {
499 pDCB->TagMask &= ~(1 << pSRB->TagNumber); /* free tag mask */
500 pSRB->TagNumber = SCSI_NO_TAG;
501 }
502}
503
504
505static int
506dc390_StartSCSI( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB )
507{
508 struct scsi_cmnd *scmd = pSRB->pcmd;
509 struct scsi_device *sdev = scmd->device;
510 u8 cmd, disc_allowed, try_sync_nego;
511 char tag[2];
512
513 pSRB->ScsiPhase = SCSI_NOP0;
514
515 if (pACB->Connected)
516 {
517 // Should not happen normally
518 printk (KERN_WARNING "DC390: Can't select when connected! (%08x,%02x)\n",
519 pSRB->SRBState, pSRB->SRBFlag);
520 pSRB->SRBState = SRB_READY;
521 pACB->SelConn++;
522 return 1;
523 }
524 if (time_before (jiffies, pACB->last_reset))
525 {
526 DEBUG0(printk ("DC390: We were just reset and don't accept commands yet!\n"));
527 return 1;
528 }
529 /* KG: Moved pci mapping here */
530 dc390_pci_map(pSRB);
531 /* TODO: error handling */
532 DC390_write8 (Scsi_Dest_ID, pDCB->TargetID);
533 DC390_write8 (Sync_Period, pDCB->SyncPeriod);
534 DC390_write8 (Sync_Offset, pDCB->SyncOffset);
535 DC390_write8 (CtrlReg1, pDCB->CtrlR1);
536 DC390_write8 (CtrlReg3, pDCB->CtrlR3);
537 DC390_write8 (CtrlReg4, pDCB->CtrlR4);
538 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); /* Flush FIFO */
539 DEBUG1(printk (KERN_INFO "DC390: Start SCSI command: %02x (Sync:%02x)\n",\
540 scmd->cmnd[0], pDCB->SyncMode));
541
542 /* Don't disconnect on AUTO_REQSENSE, cause it might be an
543 * Contingent Allegiance Condition (6.6), where no tags should be used.
544 * All other have to be allowed to disconnect to prevent Incorrect
545 * Initiator Connection (6.8.2/6.5.2) */
546 /* Changed KG, 99/06/06 */
547 if (! (pSRB->SRBFlag & AUTO_REQSENSE))
548 disc_allowed = pDCB->DevMode & EN_DISCONNECT_;
549 else
550 disc_allowed = 0;
551
552 if ((pDCB->SyncMode & SYNC_ENABLE) && pDCB->TargetLUN == 0 && sdev->sdtr &&
553 (((scmd->cmnd[0] == REQUEST_SENSE || (pSRB->SRBFlag & AUTO_REQSENSE)) &&
554 !(pDCB->SyncMode & SYNC_NEGO_DONE)) || scmd->cmnd[0] == INQUIRY))
555 try_sync_nego = 1;
556 else
557 try_sync_nego = 0;
558
559 pSRB->MsgCnt = 0;
560 cmd = SEL_W_ATN;
561 DC390_write8 (ScsiFifo, IDENTIFY(disc_allowed, pDCB->TargetLUN));
562 /* Change 99/05/31: Don't use tags when not disconnecting (BUSY) */
563 if ((pDCB->SyncMode & EN_TAG_QUEUEING) && disc_allowed && scsi_populate_tag_msg(scmd, tag)) {
564 DC390_write8(ScsiFifo, tag[0]);
565 pDCB->TagMask |= 1 << tag[1];
566 pSRB->TagNumber = tag[1];
567 DC390_write8(ScsiFifo, tag[1]);
568 DEBUG1(printk(KERN_INFO "DC390: Select w/DisCn for SRB %p, block tag %02x\n", pSRB, tag[1]));
569 cmd = SEL_W_ATN3;
570 } else {
571 /* No TagQ */
572//no_tag:
573 DEBUG1(printk(KERN_INFO "DC390: Select w%s/DisCn for SRB %p, No TagQ\n", disc_allowed ? "" : "o", pSRB));
574 }
575
576 pSRB->SRBState = SRB_START_;
577
578 if (try_sync_nego)
579 {
580 u8 Sync_Off = pDCB->SyncOffset;
581 DEBUG0(printk (KERN_INFO "DC390: NEW Sync Nego code triggered (%i %i)\n", pDCB->TargetID, pDCB->TargetLUN));
582 pSRB->MsgOutBuf[0] = EXTENDED_MESSAGE;
583 pSRB->MsgOutBuf[1] = 3;
584 pSRB->MsgOutBuf[2] = EXTENDED_SDTR;
585 pSRB->MsgOutBuf[3] = pDCB->NegoPeriod;
586 if (!(Sync_Off & 0x0f)) Sync_Off = SYNC_NEGO_OFFSET;
587 pSRB->MsgOutBuf[4] = Sync_Off;
588 pSRB->MsgCnt = 5;
589 //pSRB->SRBState = SRB_MSGOUT_;
590 pSRB->SRBState |= DO_SYNC_NEGO;
591 cmd = SEL_W_ATN_STOP;
592 }
593
594 /* Command is written in CommandPhase, if SEL_W_ATN_STOP ... */
595 if (cmd != SEL_W_ATN_STOP)
596 {
597 if( pSRB->SRBFlag & AUTO_REQSENSE )
598 {
599 DC390_write8 (ScsiFifo, REQUEST_SENSE);
600 DC390_write8 (ScsiFifo, pDCB->TargetLUN << 5);
601 DC390_write8 (ScsiFifo, 0);
602 DC390_write8 (ScsiFifo, 0);
603 DC390_write8 (ScsiFifo, SCSI_SENSE_BUFFERSIZE);
604 DC390_write8 (ScsiFifo, 0);
605 DEBUG1(printk (KERN_DEBUG "DC390: AutoReqSense !\n"));
606 }
607 else /* write cmnd to bus */
608 {
609 u8 *ptr; u8 i;
610 ptr = (u8 *)scmd->cmnd;
611 for (i = 0; i < scmd->cmd_len; i++)
612 DC390_write8 (ScsiFifo, *(ptr++));
613 }
614 }
615 DEBUG0(if (pACB->pActiveDCB) \
616 printk (KERN_WARNING "DC390: ActiveDCB != 0\n"));
617 DEBUG0(if (pDCB->pActiveSRB) \
618 printk (KERN_WARNING "DC390: ActiveSRB != 0\n"));
619 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
620 if (DC390_read8 (Scsi_Status) & INTERRUPT)
621 {
622 dc390_freetag (pDCB, pSRB);
623 DEBUG0(printk ("DC390: Interrupt during Start SCSI (target %02i-%02i)\n",
624 scmd->device->id, (u8)scmd->device->lun));
625 pSRB->SRBState = SRB_READY;
626 //DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
627 pACB->SelLost++;
628 return 1;
629 }
630 DC390_write8 (ScsiCmd, cmd);
631 pACB->pActiveDCB = pDCB;
632 pDCB->pActiveSRB = pSRB;
633 pACB->Connected = 1;
634 pSRB->ScsiPhase = SCSI_NOP1;
635 return 0;
636}
637
638
639static void __inline__
640dc390_InvalidCmd(struct dc390_acb* pACB)
641{
642 if (pACB->pActiveDCB->pActiveSRB->SRBState & (SRB_START_ | SRB_MSGOUT))
643 DC390_write8(ScsiCmd, CLEAR_FIFO_CMD);
644}
645
646
647static irqreturn_t __inline__
648DC390_Interrupt(void *dev_id)
649{
650 struct dc390_acb *pACB = dev_id;
651 struct dc390_dcb *pDCB;
652 struct dc390_srb *pSRB;
653 u8 sstatus=0;
654 u8 phase;
655 void (*stateV)( struct dc390_acb*, struct dc390_srb*, u8 *);
656 u8 istate, istatus;
657
658 sstatus = DC390_read8 (Scsi_Status);
659 if( !(sstatus & INTERRUPT) )
660 return IRQ_NONE;
661
662 DEBUG1(printk (KERN_DEBUG "sstatus=%02x,", sstatus));
663
664 //DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT);
665 //dstatus = DC390_read8 (DMA_Status);
666 //DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT);
667
668 spin_lock_irq(pACB->pScsiHost->host_lock);
669
670 istate = DC390_read8 (Intern_State);
671 istatus = DC390_read8 (INT_Status); /* This clears Scsi_Status, Intern_State and INT_Status ! */
672
673 DEBUG1(printk (KERN_INFO "Istatus(Res,Inv,Dis,Serv,Succ,ReS,SelA,Sel)=%02x,",istatus));
674 dc390_laststatus &= ~0x00ffffff;
675 dc390_laststatus |= /* dstatus<<24 | */ sstatus<<16 | istate<<8 | istatus;
676
677 if (sstatus & ILLEGAL_OP_ERR)
678 {
679 printk ("DC390: Illegal Operation detected (%08x)!\n", dc390_laststatus);
680 dc390_dumpinfo (pACB, pACB->pActiveDCB, pACB->pActiveDCB->pActiveSRB);
681 }
682
683 else if (istatus & INVALID_CMD)
684 {
685 printk ("DC390: Invalid Command detected (%08x)!\n", dc390_laststatus);
686 dc390_InvalidCmd( pACB );
687 goto unlock;
688 }
689
690 if (istatus & SCSI_RESET)
691 {
692 dc390_ScsiRstDetect( pACB );
693 goto unlock;
694 }
695
696 if (istatus & DISCONNECTED)
697 {
698 dc390_Disconnect( pACB );
699 goto unlock;
700 }
701
702 if (istatus & RESELECTED)
703 {
704 dc390_Reselect( pACB );
705 goto unlock;
706 }
707
708 else if (istatus & (SELECTED | SEL_ATTENTION))
709 {
710 printk (KERN_ERR "DC390: Target mode not supported!\n");
711 goto unlock;
712 }
713
714 if (istatus & (SUCCESSFUL_OP|SERVICE_REQUEST) )
715 {
716 pDCB = pACB->pActiveDCB;
717 if (!pDCB)
718 {
719 printk (KERN_ERR "DC390: Suc. op/ Serv. req: pActiveDCB = 0!\n");
720 goto unlock;
721 }
722 pSRB = pDCB->pActiveSRB;
723 if( pDCB->DCBFlag & ABORT_DEV_ )
724 dc390_EnableMsgOut_Abort (pACB, pSRB);
725
726 phase = pSRB->ScsiPhase;
727 DEBUG1(printk (KERN_INFO "DC390: [%i]%s(0) (%02x)\n", phase, dc390_p0_str[phase], sstatus));
728 stateV = (void *) dc390_phase0[phase];
729 ( *stateV )( pACB, pSRB, &sstatus );
730
731 pSRB->ScsiPhase = sstatus & 7;
732 phase = (u8) sstatus & 7;
733 DEBUG1(printk (KERN_INFO "DC390: [%i]%s(1) (%02x)\n", phase, dc390_p1_str[phase], sstatus));
734 stateV = (void *) dc390_phase1[phase];
735 ( *stateV )( pACB, pSRB, &sstatus );
736 }
737
738 unlock:
739 spin_unlock_irq(pACB->pScsiHost->host_lock);
740 return IRQ_HANDLED;
741}
742
743static irqreturn_t do_DC390_Interrupt(int irq, void *dev_id)
744{
745 irqreturn_t ret;
746 DEBUG1(printk (KERN_INFO "DC390: Irq (%i) caught: ", irq));
747 /* Locking is done in DC390_Interrupt */
748 ret = DC390_Interrupt(dev_id);
749 DEBUG1(printk (".. IRQ returned\n"));
750 return ret;
751}
752
753static void
754dc390_DataOut_0(struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
755{
756 u8 sstatus;
757 u32 ResidCnt;
758 u8 dstate = 0;
759
760 sstatus = *psstatus;
761
762 if( !(pSRB->SRBState & SRB_XFERPAD) )
763 {
764 if( sstatus & (PARITY_ERR | ILLEGAL_OP_ERR) )
765 pSRB->SRBStatus |= PARITY_ERROR;
766
767 if( sstatus & COUNT_2_ZERO )
768 {
769 unsigned long timeout = jiffies + HZ;
770
771 /* Function called from the ISR with the host_lock held and interrupts disabled */
772 if (pSRB->SGToBeXferLen)
773 while (time_before(jiffies, timeout) && !((dstate = DC390_read8 (DMA_Status)) & DMA_XFER_DONE)) {
774 spin_unlock_irq(pACB->pScsiHost->host_lock);
775 udelay(50);
776 spin_lock_irq(pACB->pScsiHost->host_lock);
777 }
778 if (!time_before(jiffies, timeout))
779 printk (KERN_CRIT "DC390: Deadlock in DataOut_0: DMA aborted unfinished: %06x bytes remain!!\n",
780 DC390_read32 (DMA_Wk_ByteCntr));
781 dc390_laststatus &= ~0xff000000;
782 dc390_laststatus |= dstate << 24;
783 pSRB->TotalXferredLen += pSRB->SGToBeXferLen;
784 pSRB->SGIndex++;
785 if( pSRB->SGIndex < pSRB->SGcount )
786 {
787 pSRB->pSegmentList++;
788
789 dc390_start_segment(pSRB);
790 }
791 else
792 pSRB->SGToBeXferLen = 0;
793 }
794 else
795 {
796 ResidCnt = ((u32) DC390_read8 (Current_Fifo) & 0x1f) +
797 (((u32) DC390_read8 (CtcReg_High) << 16) |
798 ((u32) DC390_read8 (CtcReg_Mid) << 8) |
799 (u32) DC390_read8 (CtcReg_Low));
800
801 dc390_advance_segment(pSRB, ResidCnt);
802 }
803 }
804 if ((*psstatus & 7) != SCSI_DATA_OUT)
805 {
806 DC390_write8 (DMA_Cmd, WRITE_DIRECTION+DMA_IDLE_CMD);
807 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
808 }
809}
810
811static void
812dc390_DataIn_0(struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
813{
814 u8 sstatus, residual, bval;
815 u32 ResidCnt, i;
816 unsigned long xferCnt;
817
818 sstatus = *psstatus;
819
820 if( !(pSRB->SRBState & SRB_XFERPAD) )
821 {
822 if( sstatus & (PARITY_ERR | ILLEGAL_OP_ERR))
823 pSRB->SRBStatus |= PARITY_ERROR;
824
825 if( sstatus & COUNT_2_ZERO )
826 {
827 int dstate = 0;
828 unsigned long timeout = jiffies + HZ;
829
830 /* Function called from the ISR with the host_lock held and interrupts disabled */
831 if (pSRB->SGToBeXferLen)
832 while (time_before(jiffies, timeout) && !((dstate = DC390_read8 (DMA_Status)) & DMA_XFER_DONE)) {
833 spin_unlock_irq(pACB->pScsiHost->host_lock);
834 udelay(50);
835 spin_lock_irq(pACB->pScsiHost->host_lock);
836 }
837 if (!time_before(jiffies, timeout)) {
838 printk (KERN_CRIT "DC390: Deadlock in DataIn_0: DMA aborted unfinished: %06x bytes remain!!\n",
839 DC390_read32 (DMA_Wk_ByteCntr));
840 printk (KERN_CRIT "DC390: DataIn_0: DMA State: %i\n", dstate);
841 }
842 dc390_laststatus &= ~0xff000000;
843 dc390_laststatus |= dstate << 24;
844 DEBUG1(ResidCnt = ((unsigned long) DC390_read8 (CtcReg_High) << 16) \
845 + ((unsigned long) DC390_read8 (CtcReg_Mid) << 8) \
846 + ((unsigned long) DC390_read8 (CtcReg_Low)));
847 DEBUG1(printk (KERN_DEBUG "Count_2_Zero (ResidCnt=%u,ToBeXfer=%lu),", ResidCnt, pSRB->SGToBeXferLen));
848
849 DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD);
850
851 pSRB->TotalXferredLen += pSRB->SGToBeXferLen;
852 pSRB->SGIndex++;
853 if( pSRB->SGIndex < pSRB->SGcount )
854 {
855 pSRB->pSegmentList++;
856
857 dc390_start_segment(pSRB);
858 }
859 else
860 pSRB->SGToBeXferLen = 0;
861 }
862 else /* phase changed */
863 {
864 residual = 0;
865 bval = DC390_read8 (Current_Fifo);
866 while( bval & 0x1f )
867 {
868 DEBUG1(printk (KERN_DEBUG "Check for residuals,"));
869 if( (bval & 0x1f) == 1 )
870 {
871 for(i=0; i < 0x100; i++)
872 {
873 bval = DC390_read8 (Current_Fifo);
874 if( !(bval & 0x1f) )
875 goto din_1;
876 else if( i == 0x0ff )
877 {
878 residual = 1; /* ;1 residual byte */
879 goto din_1;
880 }
881 }
882 }
883 else
884 bval = DC390_read8 (Current_Fifo);
885 }
886din_1:
887 DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_BLAST_CMD);
888 for (i = 0xa000; i; i--)
889 {
890 bval = DC390_read8 (DMA_Status);
891 if (bval & BLAST_COMPLETE)
892 break;
893 }
894 /* It seems a DMA Blast abort isn't that bad ... */
895 if (!i) printk (KERN_ERR "DC390: DMA Blast aborted unfinished!\n");
896 //DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD);
897 dc390_laststatus &= ~0xff000000;
898 dc390_laststatus |= bval << 24;
899
900 DEBUG1(printk (KERN_DEBUG "Blast: Read %i times DMA_Status %02x", 0xa000-i, bval));
901 ResidCnt = (((u32) DC390_read8 (CtcReg_High) << 16) |
902 ((u32) DC390_read8 (CtcReg_Mid) << 8)) |
903 (u32) DC390_read8 (CtcReg_Low);
904
905 xferCnt = dc390_advance_segment(pSRB, ResidCnt);
906
907 if (residual) {
908 size_t count = 1;
909 size_t offset = pSRB->SGBusAddr - sg_dma_address(pSRB->pSegmentList);
910 unsigned long flags;
911 u8 *ptr;
912
913 bval = DC390_read8 (ScsiFifo); /* get one residual byte */
914
915 local_irq_save(flags);
916 ptr = scsi_kmap_atomic_sg(pSRB->pSegmentList, pSRB->SGcount, &offset, &count);
917 if (likely(ptr)) {
918 *(ptr + offset) = bval;
919 scsi_kunmap_atomic_sg(ptr);
920 }
921 local_irq_restore(flags);
922 WARN_ON(!ptr);
923
924 /* 1 more byte read */
925 xferCnt += dc390_advance_segment(pSRB, pSRB->SGToBeXferLen - 1);
926 }
927 DEBUG1(printk (KERN_DEBUG "Xfered: %lu, Total: %lu, Remaining: %lu\n", xferCnt,\
928 pSRB->TotalXferredLen, pSRB->SGToBeXferLen));
929 }
930 }
931 if ((*psstatus & 7) != SCSI_DATA_IN)
932 {
933 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
934 DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD);
935 }
936}
937
938static void
939dc390_Command_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
940{
941}
942
943static void
944dc390_Status_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
945{
946
947 pSRB->TargetStatus = DC390_read8 (ScsiFifo);
948 //udelay (1);
949 pSRB->EndMessage = DC390_read8 (ScsiFifo); /* get message */
950
951 *psstatus = SCSI_NOP0;
952 pSRB->SRBState = SRB_COMPLETED;
953 DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD);
954}
955
956static void
957dc390_MsgOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
958{
959 if( pSRB->SRBState & (SRB_UNEXPECT_RESEL+SRB_ABORT_SENT) )
960 *psstatus = SCSI_NOP0;
961 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
962}
963
964
965static void __inline__
966dc390_reprog (struct dc390_acb* pACB, struct dc390_dcb* pDCB)
967{
968 DC390_write8 (Sync_Period, pDCB->SyncPeriod);
969 DC390_write8 (Sync_Offset, pDCB->SyncOffset);
970 DC390_write8 (CtrlReg3, pDCB->CtrlR3);
971 DC390_write8 (CtrlReg4, pDCB->CtrlR4);
972 dc390_SetXferRate (pACB, pDCB);
973}
974
975
976#ifdef DC390_DEBUG0
977static void
978dc390_printMsg (u8 *MsgBuf, u8 len)
979{
980 int i;
981 printk (" %02x", MsgBuf[0]);
982 for (i = 1; i < len; i++)
983 printk (" %02x", MsgBuf[i]);
984 printk ("\n");
985}
986#endif
987
988#define DC390_ENABLE_MSGOUT DC390_write8 (ScsiCmd, SET_ATN_CMD)
989
990/* reject_msg */
991static void __inline__
992dc390_MsgIn_reject (struct dc390_acb* pACB, struct dc390_srb* pSRB)
993{
994 pSRB->MsgOutBuf[0] = MESSAGE_REJECT;
995 pSRB->MsgCnt = 1;
996 DC390_ENABLE_MSGOUT;
997 DEBUG0 (printk (KERN_INFO "DC390: Reject message\n"));
998}
999
1000/* abort command */
1001static void
1002dc390_EnableMsgOut_Abort ( struct dc390_acb* pACB, struct dc390_srb* pSRB )
1003{
1004 pSRB->MsgOutBuf[0] = ABORT;
1005 pSRB->MsgCnt = 1; DC390_ENABLE_MSGOUT;
1006 pSRB->pSRBDCB->DCBFlag &= ~ABORT_DEV_;
1007}
1008
1009static struct dc390_srb*
1010dc390_MsgIn_QTag (struct dc390_acb* pACB, struct dc390_dcb* pDCB, s8 tag)
1011{
1012 struct dc390_srb* pSRB = pDCB->pGoingSRB;
1013
1014 if (pSRB)
1015 {
1016 struct scsi_cmnd *scmd = scsi_find_tag(pSRB->pcmd->device, tag);
1017 pSRB = (struct dc390_srb *)scmd->host_scribble;
1018
1019 if (pDCB->DCBFlag & ABORT_DEV_)
1020 {
1021 pSRB->SRBState = SRB_ABORT_SENT;
1022 dc390_EnableMsgOut_Abort( pACB, pSRB );
1023 }
1024
1025 if (!(pSRB->SRBState & SRB_DISCONNECT))
1026 goto mingx0;
1027
1028 pDCB->pActiveSRB = pSRB;
1029 pSRB->SRBState = SRB_DATA_XFER;
1030 }
1031 else
1032 {
1033 mingx0:
1034 pSRB = pACB->pTmpSRB;
1035 pSRB->SRBState = SRB_UNEXPECT_RESEL;
1036 pDCB->pActiveSRB = pSRB;
1037 pSRB->MsgOutBuf[0] = ABORT_TAG;
1038 pSRB->MsgCnt = 1; DC390_ENABLE_MSGOUT;
1039 }
1040 return pSRB;
1041}
1042
1043
1044/* set async transfer mode */
1045static void
1046dc390_MsgIn_set_async (struct dc390_acb* pACB, struct dc390_srb* pSRB)
1047{
1048 struct dc390_dcb* pDCB = pSRB->pSRBDCB;
1049 if (!(pSRB->SRBState & DO_SYNC_NEGO))
1050 printk (KERN_INFO "DC390: Target %i initiates Non-Sync?\n", pDCB->TargetID);
1051 pSRB->SRBState &= ~DO_SYNC_NEGO;
1052 pDCB->SyncMode &= ~(SYNC_ENABLE+SYNC_NEGO_DONE);
1053 pDCB->SyncPeriod = 0;
1054 pDCB->SyncOffset = 0;
1055 //pDCB->NegoPeriod = 50; /* 200ns <=> 5 MHz */
1056 pDCB->CtrlR3 = FAST_CLK; /* fast clock / normal scsi */
1057 pDCB->CtrlR4 &= 0x3f;
1058 pDCB->CtrlR4 |= pACB->glitch_cfg; /* glitch eater */
1059 dc390_reprog (pACB, pDCB);
1060}
1061
1062/* set sync transfer mode */
1063static void
1064dc390_MsgIn_set_sync (struct dc390_acb* pACB, struct dc390_srb* pSRB)
1065{
1066 u8 bval;
1067 u16 wval, wval1;
1068 struct dc390_dcb* pDCB = pSRB->pSRBDCB;
1069 u8 oldsyncperiod = pDCB->SyncPeriod;
1070 u8 oldsyncoffset = pDCB->SyncOffset;
1071
1072 if (!(pSRB->SRBState & DO_SYNC_NEGO))
1073 {
1074 printk (KERN_INFO "DC390: Target %i initiates Sync: %ins %i ... answer ...\n",
1075 pDCB->TargetID, pSRB->MsgInBuf[3]<<2, pSRB->MsgInBuf[4]);
1076
1077 /* reject */
1078 //dc390_MsgIn_reject (pACB, pSRB);
1079 //return dc390_MsgIn_set_async (pACB, pSRB);
1080
1081 /* Reply with corrected SDTR Message */
1082 if (pSRB->MsgInBuf[4] > 15)
1083 {
1084 printk (KERN_INFO "DC390: Lower Sync Offset to 15\n");
1085 pSRB->MsgInBuf[4] = 15;
1086 }
1087 if (pSRB->MsgInBuf[3] < pDCB->NegoPeriod)
1088 {
1089 printk (KERN_INFO "DC390: Set sync nego period to %ins\n", pDCB->NegoPeriod << 2);
1090 pSRB->MsgInBuf[3] = pDCB->NegoPeriod;
1091 }
1092 memcpy (pSRB->MsgOutBuf, pSRB->MsgInBuf, 5);
1093 pSRB->MsgCnt = 5;
1094 DC390_ENABLE_MSGOUT;
1095 }
1096
1097 pSRB->SRBState &= ~DO_SYNC_NEGO;
1098 pDCB->SyncMode |= SYNC_ENABLE+SYNC_NEGO_DONE;
1099 pDCB->SyncOffset &= 0x0f0;
1100 pDCB->SyncOffset |= pSRB->MsgInBuf[4];
1101 pDCB->NegoPeriod = pSRB->MsgInBuf[3];
1102
1103 wval = (u16) pSRB->MsgInBuf[3];
1104 wval = wval << 2; wval -= 3; wval1 = wval / 25; /* compute speed */
1105 if( (wval1 * 25) != wval) wval1++;
1106 bval = FAST_CLK+FAST_SCSI; /* fast clock / fast scsi */
1107
1108 pDCB->CtrlR4 &= 0x3f; /* Glitch eater: 12ns less than normal */
1109 if (pACB->glitch_cfg != NS_TO_GLITCH(0))
1110 pDCB->CtrlR4 |= NS_TO_GLITCH(((GLITCH_TO_NS(pACB->glitch_cfg)) - 1));
1111 else
1112 pDCB->CtrlR4 |= NS_TO_GLITCH(0);
1113 if (wval1 < 4) pDCB->CtrlR4 |= NS_TO_GLITCH(0); /* Ultra */
1114
1115 if (wval1 >= 8)
1116 {
1117 wval1--; /* Timing computation differs by 1 from FAST_SCSI */
1118 bval = FAST_CLK; /* fast clock / normal scsi */
1119 pDCB->CtrlR4 |= pACB->glitch_cfg; /* glitch eater */
1120 }
1121
1122 pDCB->CtrlR3 = bval;
1123 pDCB->SyncPeriod = (u8)wval1;
1124
1125 if ((oldsyncperiod != wval1 || oldsyncoffset != pDCB->SyncOffset) && pDCB->TargetLUN == 0)
1126 {
1127 if (! (bval & FAST_SCSI)) wval1++;
1128 printk (KERN_INFO "DC390: Target %i: Sync transfer %i.%1i MHz, Offset %i\n", pDCB->TargetID,
1129 40/wval1, ((40%wval1)*10+wval1/2)/wval1, pDCB->SyncOffset & 0x0f);
1130 }
1131
1132 dc390_reprog (pACB, pDCB);
1133}
1134
1135
1136/* handle RESTORE_PTR */
1137/* This doesn't look very healthy... to-be-fixed */
1138static void
1139dc390_restore_ptr (struct dc390_acb* pACB, struct dc390_srb* pSRB)
1140{
1141 struct scsi_cmnd *pcmd = pSRB->pcmd;
1142 struct scatterlist *psgl;
1143 pSRB->TotalXferredLen = 0;
1144 pSRB->SGIndex = 0;
1145 if (scsi_sg_count(pcmd)) {
1146 size_t saved;
1147 pSRB->pSegmentList = scsi_sglist(pcmd);
1148 psgl = pSRB->pSegmentList;
1149 //dc390_pci_sync(pSRB);
1150
1151 while (pSRB->TotalXferredLen + (unsigned long) sg_dma_len(psgl) < pSRB->Saved_Ptr)
1152 {
1153 pSRB->TotalXferredLen += (unsigned long) sg_dma_len(psgl);
1154 pSRB->SGIndex++;
1155 if( pSRB->SGIndex < pSRB->SGcount )
1156 {
1157 pSRB->pSegmentList++;
1158
1159 dc390_start_segment(pSRB);
1160 }
1161 else
1162 pSRB->SGToBeXferLen = 0;
1163 }
1164
1165 saved = pSRB->Saved_Ptr - pSRB->TotalXferredLen;
1166 pSRB->SGToBeXferLen -= saved;
1167 pSRB->SGBusAddr += saved;
1168 printk (KERN_INFO "DC390: Pointer restored. Segment %i, Total %li, Bus %08lx\n",
1169 pSRB->SGIndex, pSRB->Saved_Ptr, pSRB->SGBusAddr);
1170
1171 } else {
1172 pSRB->SGcount = 0;
1173 printk (KERN_INFO "DC390: RESTORE_PTR message for Transfer without Scatter-Gather ??\n");
1174 }
1175
1176 pSRB->TotalXferredLen = pSRB->Saved_Ptr;
1177}
1178
1179
1180/* According to the docs, the AM53C974 reads the message and
1181 * generates a Successful Operation IRQ before asserting ACK for
1182 * the last byte (how does it know whether it's the last ?) */
1183/* The old code handled it in another way, indicating, that on
1184 * every message byte an IRQ is generated and every byte has to
1185 * be manually ACKed. Hmmm ? (KG, 98/11/28) */
1186/* The old implementation was correct. Sigh! */
1187
1188/* Check if the message is complete */
1189static u8 __inline__
1190dc390_MsgIn_complete (u8 *msgbuf, u32 len)
1191{
1192 if (*msgbuf == EXTENDED_MESSAGE)
1193 {
1194 if (len < 2) return 0;
1195 if (len < msgbuf[1] + 2) return 0;
1196 }
1197 else if (*msgbuf >= 0x20 && *msgbuf <= 0x2f) // two byte messages
1198 if (len < 2) return 0;
1199 return 1;
1200}
1201
1202
1203
1204/* read and eval received messages */
1205static void
1206dc390_MsgIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1207{
1208 struct dc390_dcb* pDCB = pACB->pActiveDCB;
1209
1210 /* Read the msg */
1211
1212 pSRB->MsgInBuf[pACB->MsgLen++] = DC390_read8 (ScsiFifo);
1213 //pSRB->SRBState = 0;
1214
1215 /* Msg complete ? */
1216 if (dc390_MsgIn_complete (pSRB->MsgInBuf, pACB->MsgLen))
1217 {
1218 DEBUG0 (printk (KERN_INFO "DC390: MsgIn:"); dc390_printMsg (pSRB->MsgInBuf, pACB->MsgLen));
1219 /* Now eval the msg */
1220 switch (pSRB->MsgInBuf[0])
1221 {
1222 case DISCONNECT:
1223 pSRB->SRBState = SRB_DISCONNECT; break;
1224
1225 case SIMPLE_QUEUE_TAG:
1226 case HEAD_OF_QUEUE_TAG:
1227 case ORDERED_QUEUE_TAG:
1228 pSRB = dc390_MsgIn_QTag (pACB, pDCB, pSRB->MsgInBuf[1]);
1229 break;
1230
1231 case MESSAGE_REJECT:
1232 DC390_write8 (ScsiCmd, RESET_ATN_CMD);
1233 pDCB->NegoPeriod = 50; /* 200ns <=> 5 MHz */
1234 if( pSRB->SRBState & DO_SYNC_NEGO)
1235 dc390_MsgIn_set_async (pACB, pSRB);
1236 break;
1237
1238 case EXTENDED_MESSAGE:
1239 /* reject every extended msg but SDTR */
1240 if (pSRB->MsgInBuf[1] != 3 || pSRB->MsgInBuf[2] != EXTENDED_SDTR)
1241 dc390_MsgIn_reject (pACB, pSRB);
1242 else
1243 {
1244 if (pSRB->MsgInBuf[3] == 0 || pSRB->MsgInBuf[4] == 0)
1245 dc390_MsgIn_set_async (pACB, pSRB);
1246 else
1247 dc390_MsgIn_set_sync (pACB, pSRB);
1248 }
1249
1250 // nothing has to be done
1251 case COMMAND_COMPLETE: break;
1252
1253 // SAVE POINTER may be ignored as we have the struct dc390_srb* associated with the
1254 // scsi command. Thanks, Gerard, for pointing it out.
1255 case SAVE_POINTERS:
1256 pSRB->Saved_Ptr = pSRB->TotalXferredLen;
1257 break;
1258 // The device might want to restart transfer with a RESTORE
1259 case RESTORE_POINTERS:
1260 DEBUG0(printk ("DC390: RESTORE POINTER message received ... try to handle\n"));
1261 dc390_restore_ptr (pACB, pSRB);
1262 break;
1263
1264 // reject unknown messages
1265 default: dc390_MsgIn_reject (pACB, pSRB);
1266 }
1267
1268 /* Clear counter and MsgIn state */
1269 pSRB->SRBState &= ~SRB_MSGIN;
1270 pACB->MsgLen = 0;
1271 }
1272
1273 *psstatus = SCSI_NOP0;
1274 DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD);
1275 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
1276}
1277
1278
1279static void
1280dc390_DataIO_Comm( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 ioDir)
1281{
1282 unsigned long lval;
1283 struct dc390_dcb* pDCB = pACB->pActiveDCB;
1284
1285 if (pSRB == pACB->pTmpSRB)
1286 {
1287 if (pDCB)
1288 printk(KERN_ERR "DC390: pSRB == pTmpSRB! (TagQ Error?) (%02i-%i)\n", pDCB->TargetID, pDCB->TargetLUN);
1289 else
1290 printk(KERN_ERR "DC390: pSRB == pTmpSRB! (TagQ Error?) (DCB 0!)\n");
1291
1292 /* Try to recover - some broken disks react badly to tagged INQUIRY */
1293 if (pDCB && pACB->scan_devices && pDCB->GoingSRBCnt == 1) {
1294 pSRB = pDCB->pGoingSRB;
1295 pDCB->pActiveSRB = pSRB;
1296 } else {
1297 pSRB->pSRBDCB = pDCB;
1298 dc390_EnableMsgOut_Abort(pACB, pSRB);
1299 if (pDCB)
1300 pDCB->DCBFlag |= ABORT_DEV;
1301 return;
1302 }
1303 }
1304
1305 if( pSRB->SGIndex < pSRB->SGcount )
1306 {
1307 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir);
1308 if( !pSRB->SGToBeXferLen )
1309 {
1310 dc390_start_segment(pSRB);
1311
1312 DEBUG1(printk (KERN_DEBUG " DC390: Next SG segment."));
1313 }
1314 lval = pSRB->SGToBeXferLen;
1315 DEBUG1(printk (KERN_DEBUG " DC390: Start transfer: %li bytes (address %08lx)\n", lval, pSRB->SGBusAddr));
1316 DC390_write8 (CtcReg_Low, (u8) lval);
1317 lval >>= 8;
1318 DC390_write8 (CtcReg_Mid, (u8) lval);
1319 lval >>= 8;
1320 DC390_write8 (CtcReg_High, (u8) lval);
1321
1322 DC390_write32 (DMA_XferCnt, pSRB->SGToBeXferLen);
1323 DC390_write32 (DMA_XferAddr, pSRB->SGBusAddr);
1324
1325 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir);
1326 pSRB->SRBState = SRB_DATA_XFER;
1327
1328 DC390_write8 (ScsiCmd, DMA_COMMAND+INFO_XFER_CMD);
1329
1330 DC390_write8 (DMA_Cmd, DMA_START_CMD | ioDir);
1331 //DEBUG1(DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT));
1332 //DEBUG1(printk (KERN_DEBUG "DC390: DMA_Status: %02x\n", DC390_read8 (DMA_Status)));
1333 //DEBUG1(DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT));
1334 }
1335 else /* xfer pad */
1336 {
1337 if( pSRB->SGcount )
1338 {
1339 pSRB->AdaptStatus = H_OVER_UNDER_RUN;
1340 pSRB->SRBStatus |= OVER_RUN;
1341 DEBUG0(printk (KERN_WARNING " DC390: Overrun -"));
1342 }
1343 DEBUG0(printk (KERN_WARNING " Clear transfer pad \n"));
1344 DC390_write8 (CtcReg_Low, 0);
1345 DC390_write8 (CtcReg_Mid, 0);
1346 DC390_write8 (CtcReg_High, 0);
1347
1348 pSRB->SRBState |= SRB_XFERPAD;
1349 DC390_write8 (ScsiCmd, DMA_COMMAND+XFER_PAD_BYTE);
1350/*
1351 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir);
1352 DC390_write8 (DMA_Cmd, DMA_START_CMD | ioDir);
1353*/
1354 }
1355}
1356
1357
1358static void
1359dc390_DataOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1360{
1361 dc390_DataIO_Comm (pACB, pSRB, WRITE_DIRECTION);
1362}
1363
1364static void
1365dc390_DataInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1366{
1367 dc390_DataIO_Comm (pACB, pSRB, READ_DIRECTION);
1368}
1369
1370static void
1371dc390_CommandPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1372{
1373 struct dc390_dcb* pDCB;
1374 u8 i, cnt;
1375 u8 *ptr;
1376
1377 DC390_write8 (ScsiCmd, RESET_ATN_CMD);
1378 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1379 if( !(pSRB->SRBFlag & AUTO_REQSENSE) )
1380 {
1381 cnt = (u8) pSRB->pcmd->cmd_len;
1382 ptr = (u8 *) pSRB->pcmd->cmnd;
1383 for(i=0; i < cnt; i++)
1384 DC390_write8 (ScsiFifo, *(ptr++));
1385 }
1386 else
1387 {
1388 DC390_write8 (ScsiFifo, REQUEST_SENSE);
1389 pDCB = pACB->pActiveDCB;
1390 DC390_write8 (ScsiFifo, pDCB->TargetLUN << 5);
1391 DC390_write8 (ScsiFifo, 0);
1392 DC390_write8 (ScsiFifo, 0);
1393 DC390_write8 (ScsiFifo, SCSI_SENSE_BUFFERSIZE);
1394 DC390_write8 (ScsiFifo, 0);
1395 DEBUG0(printk(KERN_DEBUG "DC390: AutoReqSense (CmndPhase)!\n"));
1396 }
1397 pSRB->SRBState = SRB_COMMAND;
1398 DC390_write8 (ScsiCmd, INFO_XFER_CMD);
1399}
1400
1401static void
1402dc390_StatusPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1403{
1404 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1405 pSRB->SRBState = SRB_STATUS;
1406 DC390_write8 (ScsiCmd, INITIATOR_CMD_CMPLTE);
1407 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
1408}
1409
1410static void
1411dc390_MsgOutPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1412{
1413 u8 bval, i, cnt;
1414 u8 *ptr;
1415 struct dc390_dcb* pDCB;
1416
1417 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1418 pDCB = pACB->pActiveDCB;
1419 if( !(pSRB->SRBState & SRB_MSGOUT) )
1420 {
1421 cnt = pSRB->MsgCnt;
1422 if( cnt )
1423 {
1424 ptr = (u8 *) pSRB->MsgOutBuf;
1425 for(i=0; i < cnt; i++)
1426 DC390_write8 (ScsiFifo, *(ptr++));
1427 pSRB->MsgCnt = 0;
1428 if( (pDCB->DCBFlag & ABORT_DEV_) &&
1429 (pSRB->MsgOutBuf[0] == ABORT) )
1430 pSRB->SRBState = SRB_ABORT_SENT;
1431 }
1432 else
1433 {
1434 bval = ABORT; /* ??? MSG_NOP */
1435 if( (pSRB->pcmd->cmnd[0] == INQUIRY ) ||
1436 (pSRB->pcmd->cmnd[0] == REQUEST_SENSE) ||
1437 (pSRB->SRBFlag & AUTO_REQSENSE) )
1438 {
1439 if( pDCB->SyncMode & SYNC_ENABLE )
1440 goto mop1;
1441 }
1442 DC390_write8 (ScsiFifo, bval);
1443 }
1444 DC390_write8 (ScsiCmd, INFO_XFER_CMD);
1445 }
1446 else
1447 {
1448mop1:
1449 printk (KERN_ERR "DC390: OLD Sync Nego code triggered! (%i %i)\n", pDCB->TargetID, pDCB->TargetLUN);
1450 DC390_write8 (ScsiFifo, EXTENDED_MESSAGE);
1451 DC390_write8 (ScsiFifo, 3); /* ;length of extended msg */
1452 DC390_write8 (ScsiFifo, EXTENDED_SDTR); /* ; sync nego */
1453 DC390_write8 (ScsiFifo, pDCB->NegoPeriod);
1454 if (pDCB->SyncOffset & 0x0f)
1455 DC390_write8 (ScsiFifo, pDCB->SyncOffset);
1456 else
1457 DC390_write8 (ScsiFifo, SYNC_NEGO_OFFSET);
1458 pSRB->SRBState |= DO_SYNC_NEGO;
1459 DC390_write8 (ScsiCmd, INFO_XFER_CMD);
1460 }
1461}
1462
1463static void
1464dc390_MsgInPhase( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1465{
1466 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1467 if( !(pSRB->SRBState & SRB_MSGIN) )
1468 {
1469 pSRB->SRBState &= ~SRB_DISCONNECT;
1470 pSRB->SRBState |= SRB_MSGIN;
1471 }
1472 DC390_write8 (ScsiCmd, INFO_XFER_CMD);
1473 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
1474}
1475
1476static void
1477dc390_Nop_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1478{
1479}
1480
1481static void
1482dc390_Nop_1( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1483{
1484}
1485
1486
1487static void
1488dc390_SetXferRate( struct dc390_acb* pACB, struct dc390_dcb* pDCB )
1489{
1490 u8 bval, i, cnt;
1491 struct dc390_dcb* ptr;
1492
1493 if( !(pDCB->TargetLUN) )
1494 {
1495 if( !pACB->scan_devices )
1496 {
1497 ptr = pACB->pLinkDCB;
1498 cnt = pACB->DCBCnt;
1499 bval = pDCB->TargetID;
1500 for(i=0; i<cnt; i++)
1501 {
1502 if( ptr->TargetID == bval )
1503 {
1504 ptr->SyncPeriod = pDCB->SyncPeriod;
1505 ptr->SyncOffset = pDCB->SyncOffset;
1506 ptr->CtrlR3 = pDCB->CtrlR3;
1507 ptr->CtrlR4 = pDCB->CtrlR4;
1508 ptr->SyncMode = pDCB->SyncMode;
1509 }
1510 ptr = ptr->pNextDCB;
1511 }
1512 }
1513 }
1514 return;
1515}
1516
1517
1518static void
1519dc390_Disconnect( struct dc390_acb* pACB )
1520{
1521 struct dc390_dcb *pDCB;
1522 struct dc390_srb *pSRB, *psrb;
1523 u8 i, cnt;
1524
1525 DEBUG0(printk(KERN_INFO "DISC,"));
1526
1527 if (!pACB->Connected) printk(KERN_ERR "DC390: Disconnect not-connected bus?\n");
1528 pACB->Connected = 0;
1529 pDCB = pACB->pActiveDCB;
1530 if (!pDCB)
1531 {
1532 DEBUG0(printk(KERN_ERR "ACB:%p->ActiveDCB:%p IOPort:%04x IRQ:%02x !\n",\
1533 pACB, pDCB, pACB->IOPortBase, pACB->IRQLevel));
1534 mdelay(400);
1535 DC390_read8 (INT_Status); /* Reset Pending INT */
1536 DC390_write8 (ScsiCmd, EN_SEL_RESEL);
1537 return;
1538 }
1539 DC390_write8 (ScsiCmd, EN_SEL_RESEL);
1540 pSRB = pDCB->pActiveSRB;
1541 pACB->pActiveDCB = NULL;
1542 pSRB->ScsiPhase = SCSI_NOP0;
1543 if( pSRB->SRBState & SRB_UNEXPECT_RESEL )
1544 pSRB->SRBState = 0;
1545 else if( pSRB->SRBState & SRB_ABORT_SENT )
1546 {
1547 pDCB->TagMask = 0;
1548 pDCB->DCBFlag = 0;
1549 cnt = pDCB->GoingSRBCnt;
1550 pDCB->GoingSRBCnt = 0;
1551 pSRB = pDCB->pGoingSRB;
1552 for( i=0; i < cnt; i++)
1553 {
1554 psrb = pSRB->pNextSRB;
1555 dc390_Free_insert (pACB, pSRB);
1556 pSRB = psrb;
1557 }
1558 pDCB->pGoingSRB = NULL;
1559 }
1560 else
1561 {
1562 if( (pSRB->SRBState & (SRB_START_+SRB_MSGOUT)) ||
1563 !(pSRB->SRBState & (SRB_DISCONNECT+SRB_COMPLETED)) )
1564 { /* Selection time out */
1565 pSRB->AdaptStatus = H_SEL_TIMEOUT;
1566 pSRB->TargetStatus = 0;
1567 goto disc1;
1568 }
1569 else if (!(pSRB->SRBState & SRB_DISCONNECT) && (pSRB->SRBState & SRB_COMPLETED))
1570 {
1571disc1:
1572 dc390_freetag (pDCB, pSRB);
1573 pDCB->pActiveSRB = NULL;
1574 pSRB->SRBState = SRB_FREE;
1575 dc390_SRBdone( pACB, pDCB, pSRB);
1576 }
1577 }
1578 pACB->MsgLen = 0;
1579}
1580
1581
1582static void
1583dc390_Reselect( struct dc390_acb* pACB )
1584{
1585 struct dc390_dcb* pDCB;
1586 struct dc390_srb* pSRB;
1587 u8 id, lun;
1588
1589 DEBUG0(printk(KERN_INFO "RSEL,"));
1590 pACB->Connected = 1;
1591 pDCB = pACB->pActiveDCB;
1592 if( pDCB )
1593 { /* Arbitration lost but Reselection won */
1594 DEBUG0(printk ("DC390: (ActiveDCB != 0: Arb. lost but resel. won)!\n"));
1595 pSRB = pDCB->pActiveSRB;
1596 if( !( pACB->scan_devices ) )
1597 {
1598 struct scsi_cmnd *pcmd = pSRB->pcmd;
1599 scsi_set_resid(pcmd, scsi_bufflen(pcmd));
1600 SET_RES_DID(pcmd->result, DID_SOFT_ERROR);
1601 dc390_Going_remove(pDCB, pSRB);
1602 dc390_Free_insert(pACB, pSRB);
1603 pcmd->scsi_done (pcmd);
1604 DEBUG0(printk(KERN_DEBUG"DC390: Return SRB %p to free\n", pSRB));
1605 }
1606 }
1607 /* Get ID */
1608 lun = DC390_read8 (ScsiFifo);
1609 DEBUG0(printk ("Dev %02x,", lun));
1610 if (!(lun & (1 << pACB->pScsiHost->this_id)))
1611 printk (KERN_ERR "DC390: Reselection must select host adapter: %02x!\n", lun);
1612 else
1613 lun ^= 1 << pACB->pScsiHost->this_id; /* Mask AdapterID */
1614 id = 0; while (lun >>= 1) id++;
1615 /* Get LUN */
1616 lun = DC390_read8 (ScsiFifo);
1617 if (!(lun & IDENTIFY_BASE)) printk (KERN_ERR "DC390: Resel: Expect identify message!\n");
1618 lun &= 7;
1619 DEBUG0(printk ("(%02i-%i),", id, lun));
1620 pDCB = dc390_findDCB (pACB, id, lun);
1621 if (!pDCB)
1622 {
1623 printk (KERN_ERR "DC390: Reselect from non existing device (%02i-%i)\n",
1624 id, lun);
1625 return;
1626 }
1627 pACB->pActiveDCB = pDCB;
1628 /* TagQ: We expect a message soon, so never mind the exact SRB */
1629 if( pDCB->SyncMode & EN_TAG_QUEUEING )
1630 {
1631 pSRB = pACB->pTmpSRB;
1632 pDCB->pActiveSRB = pSRB;
1633 }
1634 else
1635 {
1636 pSRB = pDCB->pActiveSRB;
1637 if( !pSRB || !(pSRB->SRBState & SRB_DISCONNECT) )
1638 {
1639 pSRB= pACB->pTmpSRB;
1640 pSRB->SRBState = SRB_UNEXPECT_RESEL;
1641 printk (KERN_ERR "DC390: Reselect without outstanding cmnd (%02i-%i)\n",
1642 id, lun);
1643 pDCB->pActiveSRB = pSRB;
1644 dc390_EnableMsgOut_Abort ( pACB, pSRB );
1645 }
1646 else
1647 {
1648 if( pDCB->DCBFlag & ABORT_DEV_ )
1649 {
1650 pSRB->SRBState = SRB_ABORT_SENT;
1651 printk (KERN_INFO "DC390: Reselect: Abort (%02i-%i)\n",
1652 id, lun);
1653 dc390_EnableMsgOut_Abort( pACB, pSRB );
1654 }
1655 else
1656 pSRB->SRBState = SRB_DATA_XFER;
1657 }
1658 }
1659
1660 DEBUG1(printk (KERN_DEBUG "Resel SRB(%p): TagNum (%02x)\n", pSRB, pSRB->TagNumber));
1661 pSRB->ScsiPhase = SCSI_NOP0;
1662 DC390_write8 (Scsi_Dest_ID, pDCB->TargetID);
1663 DC390_write8 (Sync_Period, pDCB->SyncPeriod);
1664 DC390_write8 (Sync_Offset, pDCB->SyncOffset);
1665 DC390_write8 (CtrlReg1, pDCB->CtrlR1);
1666 DC390_write8 (CtrlReg3, pDCB->CtrlR3);
1667 DC390_write8 (CtrlReg4, pDCB->CtrlR4); /* ; Glitch eater */
1668 DC390_write8 (ScsiCmd, MSG_ACCEPTED_CMD); /* ;to release the /ACK signal */
1669}
1670
1671static int __inline__
1672dc390_RequestSense(struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB)
1673{
1674 struct scsi_cmnd *pcmd;
1675
1676 pcmd = pSRB->pcmd;
1677
1678 REMOVABLEDEBUG(printk(KERN_INFO "DC390: RequestSense(Cmd %02x, Id %02x, LUN %02x)\n",\
1679 pcmd->cmnd[0], pDCB->TargetID, pDCB->TargetLUN));
1680
1681 pSRB->SRBFlag |= AUTO_REQSENSE;
1682 pSRB->SavedTotXLen = pSRB->TotalXferredLen;
1683 pSRB->AdaptStatus = 0;
1684 pSRB->TargetStatus = 0; /* CHECK_CONDITION<<1; */
1685
1686 /* We are called from SRBdone, original PCI mapping has been removed
1687 * already, new one is set up from StartSCSI */
1688 pSRB->SGIndex = 0;
1689
1690 pSRB->TotalXferredLen = 0;
1691 pSRB->SGToBeXferLen = 0;
1692 return dc390_StartSCSI(pACB, pDCB, pSRB);
1693}
1694
1695
1696static void
1697dc390_SRBdone( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB )
1698{
1699 u8 status;
1700 struct scsi_cmnd *pcmd;
1701
1702 pcmd = pSRB->pcmd;
1703 /* KG: Moved pci_unmap here */
1704 dc390_pci_unmap(pSRB);
1705
1706 status = pSRB->TargetStatus;
1707
1708 DEBUG0(printk (" SRBdone (%02x,%08x), SRB %p\n", status, pcmd->result, pSRB));
1709 if(pSRB->SRBFlag & AUTO_REQSENSE)
1710 { /* Last command was a Request Sense */
1711 pSRB->SRBFlag &= ~AUTO_REQSENSE;
1712 pSRB->AdaptStatus = 0;
1713 pSRB->TargetStatus = SAM_STAT_CHECK_CONDITION;
1714
1715 //pcmd->result = MK_RES(DRIVER_SENSE,DID_OK,0,status);
1716 if (status == SAM_STAT_CHECK_CONDITION)
1717 pcmd->result = MK_RES_LNX(0, DID_BAD_TARGET, 0, /*CHECK_CONDITION*/0);
1718 else /* Retry */
1719 {
1720 if( pSRB->pcmd->cmnd[0] == TEST_UNIT_READY /* || pSRB->pcmd->cmnd[0] == START_STOP */)
1721 {
1722 /* Don't retry on TEST_UNIT_READY */
1723 pcmd->result = MK_RES_LNX(DRIVER_SENSE, DID_OK, 0, SAM_STAT_CHECK_CONDITION);
1724 REMOVABLEDEBUG(printk(KERN_INFO "Cmd=%02x, Result=%08x, XferL=%08x\n",pSRB->pcmd->cmnd[0],\
1725 (u32) pcmd->result, (u32) pSRB->TotalXferredLen));
1726 } else {
1727 SET_RES_DRV(pcmd->result, DRIVER_SENSE);
1728 //pSRB->ScsiCmdLen = (u8) (pSRB->Segment1[0] >> 8);
1729 DEBUG0 (printk ("DC390: RETRY (%02x), target %02i-%02i\n", pcmd->cmnd[0], pcmd->device->id, (u8)pcmd->device->lun));
1730 pSRB->TotalXferredLen = 0;
1731 SET_RES_DID(pcmd->result, DID_SOFT_ERROR);
1732 }
1733 }
1734 goto cmd_done;
1735 }
1736 if( status )
1737 {
1738 if (status == SAM_STAT_CHECK_CONDITION)
1739 {
1740 if (dc390_RequestSense(pACB, pDCB, pSRB)) {
1741 SET_RES_DID(pcmd->result, DID_ERROR);
1742 goto cmd_done;
1743 }
1744 return;
1745 }
1746 else if (status == SAM_STAT_TASK_SET_FULL)
1747 {
1748 scsi_track_queue_full(pcmd->device, pDCB->GoingSRBCnt - 1);
1749 DEBUG0 (printk ("DC390: RETRY (%02x), target %02i-%02i\n", pcmd->cmnd[0], pcmd->device->id, (u8)pcmd->device->lun));
1750 pSRB->TotalXferredLen = 0;
1751 SET_RES_DID(pcmd->result, DID_SOFT_ERROR);
1752 }
1753 else if (status == SAM_STAT_BUSY &&
1754 (pcmd->cmnd[0] == TEST_UNIT_READY || pcmd->cmnd[0] == INQUIRY) &&
1755 pACB->scan_devices)
1756 {
1757 pSRB->AdaptStatus = 0;
1758 pSRB->TargetStatus = status;
1759 pcmd->result = MK_RES(0,0,pSRB->EndMessage,/*status*/0);
1760 }
1761 else
1762 { /* Another error */
1763 pSRB->TotalXferredLen = 0;
1764 SET_RES_DID(pcmd->result, DID_SOFT_ERROR);
1765 goto cmd_done;
1766 }
1767 }
1768 else
1769 { /* Target status == 0 */
1770 status = pSRB->AdaptStatus;
1771 if (status == H_OVER_UNDER_RUN)
1772 {
1773 pSRB->TargetStatus = 0;
1774 SET_RES_DID(pcmd->result,DID_OK);
1775 SET_RES_MSG(pcmd->result,pSRB->EndMessage);
1776 }
1777 else if (status == H_SEL_TIMEOUT)
1778 {
1779 pcmd->result = MK_RES(0, DID_NO_CONNECT, 0, 0);
1780 /* Devices are removed below ... */
1781 }
1782 else if( pSRB->SRBStatus & PARITY_ERROR)
1783 {
1784 //pcmd->result = MK_RES(0,DID_PARITY,pSRB->EndMessage,0);
1785 SET_RES_DID(pcmd->result,DID_PARITY);
1786 SET_RES_MSG(pcmd->result,pSRB->EndMessage);
1787 }
1788 else /* No error */
1789 {
1790 pSRB->AdaptStatus = 0;
1791 pSRB->TargetStatus = 0;
1792 SET_RES_DID(pcmd->result,DID_OK);
1793 }
1794 }
1795
1796cmd_done:
1797 scsi_set_resid(pcmd, scsi_bufflen(pcmd) - pSRB->TotalXferredLen);
1798
1799 dc390_Going_remove (pDCB, pSRB);
1800 /* Add to free list */
1801 dc390_Free_insert (pACB, pSRB);
1802
1803 DEBUG0(printk (KERN_DEBUG "DC390: SRBdone: done\n"));
1804 pcmd->scsi_done (pcmd);
1805
1806 return;
1807}
1808
1809
1810/* Remove all SRBs from Going list and inform midlevel */
1811static void
1812dc390_DoingSRB_Done(struct dc390_acb* pACB, struct scsi_cmnd *cmd)
1813{
1814 struct dc390_dcb *pDCB, *pdcb;
1815 struct dc390_srb *psrb, *psrb2;
1816 int i;
1817 struct scsi_cmnd *pcmd;
1818
1819 pDCB = pACB->pLinkDCB;
1820 pdcb = pDCB;
1821 if (! pdcb) return;
1822 do
1823 {
1824 psrb = pdcb->pGoingSRB;
1825 for (i = 0; i < pdcb->GoingSRBCnt; i++)
1826 {
1827 psrb2 = psrb->pNextSRB;
1828 pcmd = psrb->pcmd;
1829 dc390_Free_insert (pACB, psrb);
1830 psrb = psrb2;
1831 }
1832 pdcb->GoingSRBCnt = 0;
1833 pdcb->pGoingSRB = NULL;
1834 pdcb->TagMask = 0;
1835 pdcb = pdcb->pNextDCB;
1836 } while( pdcb != pDCB );
1837}
1838
1839
1840static void
1841dc390_ResetSCSIBus( struct dc390_acb* pACB )
1842{
1843 //DC390_write8 (ScsiCmd, RST_DEVICE_CMD);
1844 //udelay (250);
1845 //DC390_write8 (ScsiCmd, NOP_CMD);
1846
1847 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1848 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
1849 DC390_write8 (ScsiCmd, RST_SCSI_BUS_CMD);
1850 pACB->Connected = 0;
1851
1852 return;
1853}
1854
1855static void
1856dc390_ScsiRstDetect( struct dc390_acb* pACB )
1857{
1858 printk ("DC390: Rst_Detect: laststat = %08x\n", dc390_laststatus);
1859 //DEBUG0(printk(KERN_INFO "RST_DETECT,"));
1860
1861 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
1862 /* Unlock before ? */
1863 /* delay half a second */
1864 udelay (1000);
1865 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1866 pACB->last_reset = jiffies + 5*HZ/2
1867 + HZ * dc390_eepromBuf[pACB->AdapterIndex][EE_DELAY];
1868 pACB->Connected = 0;
1869
1870 if( pACB->ACBFlag & RESET_DEV )
1871 pACB->ACBFlag |= RESET_DONE;
1872 else
1873 { /* Reset was issued by sb else */
1874 pACB->ACBFlag |= RESET_DETECT;
1875
1876 dc390_ResetDevParam( pACB );
1877 dc390_DoingSRB_Done( pACB, NULL);
1878 //dc390_RecoverSRB( pACB );
1879 pACB->pActiveDCB = NULL;
1880 pACB->ACBFlag = 0;
1881 }
1882 return;
1883}
1884
1885static int DC390_queuecommand_lck(struct scsi_cmnd *cmd,
1886 void (*done)(struct scsi_cmnd *))
1887{
1888 struct scsi_device *sdev = cmd->device;
1889 struct dc390_acb *acb = (struct dc390_acb *)sdev->host->hostdata;
1890 struct dc390_dcb *dcb = sdev->hostdata;
1891 struct dc390_srb *srb;
1892
1893 if (sdev->queue_depth <= dcb->GoingSRBCnt)
1894 goto device_busy;
1895 if (acb->pActiveDCB)
1896 goto host_busy;
1897 if (acb->ACBFlag & (RESET_DETECT|RESET_DONE|RESET_DEV))
1898 goto host_busy;
1899
1900 srb = acb->pFreeSRB;
1901 if (unlikely(srb == NULL))
1902 goto host_busy;
1903
1904 cmd->scsi_done = done;
1905 cmd->result = 0;
1906 acb->Cmds++;
1907
1908 acb->pFreeSRB = srb->pNextSRB;
1909 srb->pNextSRB = NULL;
1910
1911 srb->pSRBDCB = dcb;
1912 srb->pcmd = cmd;
1913 cmd->host_scribble = (char *)srb;
1914
1915 srb->SGIndex = 0;
1916 srb->AdaptStatus = 0;
1917 srb->TargetStatus = 0;
1918 srb->MsgCnt = 0;
1919
1920 srb->SRBStatus = 0;
1921 srb->SRBFlag = 0;
1922 srb->SRBState = 0;
1923 srb->TotalXferredLen = 0;
1924 srb->SGBusAddr = 0;
1925 srb->SGToBeXferLen = 0;
1926 srb->ScsiPhase = 0;
1927 srb->EndMessage = 0;
1928 srb->TagNumber = SCSI_NO_TAG;
1929
1930 if (dc390_StartSCSI(acb, dcb, srb)) {
1931 dc390_Free_insert(acb, srb);
1932 goto host_busy;
1933 }
1934
1935 dc390_Going_append(dcb, srb);
1936
1937 return 0;
1938
1939 host_busy:
1940 return SCSI_MLQUEUE_HOST_BUSY;
1941
1942 device_busy:
1943 return SCSI_MLQUEUE_DEVICE_BUSY;
1944}
1945
1946static DEF_SCSI_QCMD(DC390_queuecommand)
1947
1948static void dc390_dumpinfo (struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_srb* pSRB)
1949{
1950 struct pci_dev *pdev;
1951 u16 pstat;
1952
1953 if (!pDCB) pDCB = pACB->pActiveDCB;
1954 if (!pSRB && pDCB) pSRB = pDCB->pActiveSRB;
1955
1956 if (pSRB)
1957 {
1958 printk ("DC390: SRB: Xferred %08lx, Remain %08lx, State %08x, Phase %02x\n",
1959 pSRB->TotalXferredLen, pSRB->SGToBeXferLen, pSRB->SRBState,
1960 pSRB->ScsiPhase);
1961 printk ("DC390: AdpaterStatus: %02x, SRB Status %02x\n", pSRB->AdaptStatus, pSRB->SRBStatus);
1962 }
1963 printk ("DC390: Status of last IRQ (DMA/SC/Int/IRQ): %08x\n", dc390_laststatus);
1964 printk ("DC390: Register dump: SCSI block:\n");
1965 printk ("DC390: XferCnt Cmd Stat IntS IRQS FFIS Ctl1 Ctl2 Ctl3 Ctl4\n");
1966 printk ("DC390: %06x %02x %02x %02x",
1967 DC390_read8(CtcReg_Low) + (DC390_read8(CtcReg_Mid) << 8) + (DC390_read8(CtcReg_High) << 16),
1968 DC390_read8(ScsiCmd), DC390_read8(Scsi_Status), DC390_read8(Intern_State));
1969 printk (" %02x %02x %02x %02x %02x %02x\n",
1970 DC390_read8(INT_Status), DC390_read8(Current_Fifo), DC390_read8(CtrlReg1),
1971 DC390_read8(CtrlReg2), DC390_read8(CtrlReg3), DC390_read8(CtrlReg4));
1972 DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT);
1973 if (DC390_read8(Current_Fifo) & 0x1f)
1974 {
1975 printk ("DC390: FIFO:");
1976 while (DC390_read8(Current_Fifo) & 0x1f) printk (" %02x", DC390_read8(ScsiFifo));
1977 printk ("\n");
1978 }
1979 printk ("DC390: Register dump: DMA engine:\n");
1980 printk ("DC390: Cmd STrCnt SBusA WrkBC WrkAC Stat SBusCtrl\n");
1981 printk ("DC390: %02x %08x %08x %08x %08x %02x %08x\n",
1982 DC390_read8(DMA_Cmd), DC390_read32(DMA_XferCnt), DC390_read32(DMA_XferAddr),
1983 DC390_read32(DMA_Wk_ByteCntr), DC390_read32(DMA_Wk_AddrCntr),
1984 DC390_read8(DMA_Status), DC390_read32(DMA_ScsiBusCtrl));
1985 DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT);
1986
1987 pdev = pACB->pdev;
1988 pci_read_config_word(pdev, PCI_STATUS, &pstat);
1989 printk ("DC390: Register dump: PCI Status: %04x\n", pstat);
1990 printk ("DC390: In case of driver trouble read Documentation/scsi/tmscsim.txt\n");
1991}
1992
1993
1994static int DC390_abort(struct scsi_cmnd *cmd)
1995{
1996 struct dc390_acb *pACB = (struct dc390_acb*) cmd->device->host->hostdata;
1997 struct dc390_dcb *pDCB = (struct dc390_dcb*) cmd->device->hostdata;
1998
1999 scmd_printk(KERN_WARNING, cmd, "DC390: Abort command\n");
2000
2001 /* abort() is too stupid for already sent commands at the moment.
2002 * If it's called we are in trouble anyway, so let's dump some info
2003 * into the syslog at least. (KG, 98/08/20,99/06/20) */
2004 dc390_dumpinfo(pACB, pDCB, NULL);
2005
2006 pDCB->DCBFlag |= ABORT_DEV_;
2007 printk(KERN_INFO "DC390: Aborted.\n");
2008
2009 return FAILED;
2010}
2011
2012
2013static void dc390_ResetDevParam( struct dc390_acb* pACB )
2014{
2015 struct dc390_dcb *pDCB, *pdcb;
2016
2017 pDCB = pACB->pLinkDCB;
2018 if (! pDCB) return;
2019 pdcb = pDCB;
2020 do
2021 {
2022 pDCB->SyncMode &= ~SYNC_NEGO_DONE;
2023 pDCB->SyncPeriod = 0;
2024 pDCB->SyncOffset = 0;
2025 pDCB->TagMask = 0;
2026 pDCB->CtrlR3 = FAST_CLK;
2027 pDCB->CtrlR4 &= NEGATE_REQACKDATA | CTRL4_RESERVED | NEGATE_REQACK;
2028 pDCB->CtrlR4 |= pACB->glitch_cfg;
2029 pDCB = pDCB->pNextDCB;
2030 }
2031 while( pdcb != pDCB );
2032 pACB->ACBFlag &= ~(RESET_DEV | RESET_DONE | RESET_DETECT);
2033
2034}
2035
2036static int DC390_bus_reset (struct scsi_cmnd *cmd)
2037{
2038 struct dc390_acb* pACB = (struct dc390_acb*) cmd->device->host->hostdata;
2039 u8 bval;
2040
2041 spin_lock_irq(cmd->device->host->host_lock);
2042
2043 bval = DC390_read8(CtrlReg1) | DIS_INT_ON_SCSI_RST;
2044 DC390_write8(CtrlReg1, bval); /* disable IRQ on bus reset */
2045
2046 pACB->ACBFlag |= RESET_DEV;
2047 dc390_ResetSCSIBus(pACB);
2048
2049 dc390_ResetDevParam(pACB);
2050 mdelay(1);
2051 pACB->last_reset = jiffies + 3*HZ/2
2052 + HZ * dc390_eepromBuf[pACB->AdapterIndex][EE_DELAY];
2053
2054 DC390_write8(ScsiCmd, CLEAR_FIFO_CMD);
2055 DC390_read8(INT_Status); /* Reset Pending INT */
2056
2057 dc390_DoingSRB_Done(pACB, cmd);
2058
2059 pACB->pActiveDCB = NULL;
2060 pACB->ACBFlag = 0;
2061
2062 bval = DC390_read8(CtrlReg1) & ~DIS_INT_ON_SCSI_RST;
2063 DC390_write8(CtrlReg1, bval); /* re-enable interrupt */
2064
2065 spin_unlock_irq(cmd->device->host->host_lock);
2066
2067 return SUCCESS;
2068}
2069
2070/**
2071 * dc390_slave_alloc - Called by the scsi mid layer to tell us about a new
2072 * scsi device that we need to deal with.
2073 *
2074 * @scsi_device: The new scsi device that we need to handle.
2075 */
2076static int dc390_slave_alloc(struct scsi_device *scsi_device)
2077{
2078 struct dc390_acb *pACB = (struct dc390_acb*) scsi_device->host->hostdata;
2079 struct dc390_dcb *pDCB, *pDCB2 = NULL;
2080 uint id = scsi_device->id;
2081 uint lun = scsi_device->lun;
2082
2083 pDCB = kzalloc(sizeof(struct dc390_dcb), GFP_KERNEL);
2084 if (!pDCB)
2085 return -ENOMEM;
2086
2087 if (!pACB->DCBCnt++) {
2088 pACB->pLinkDCB = pDCB;
2089 pACB->pDCBRunRobin = pDCB;
2090 } else {
2091 pACB->pLastDCB->pNextDCB = pDCB;
2092 }
2093
2094 pDCB->pNextDCB = pACB->pLinkDCB;
2095 pACB->pLastDCB = pDCB;
2096
2097 pDCB->pDCBACB = pACB;
2098 pDCB->TargetID = id;
2099 pDCB->TargetLUN = lun;
2100
2101 /*
2102 * Some values are for all LUNs: Copy them
2103 * In a clean way: We would have an own structure for a SCSI-ID
2104 */
2105 if (lun && (pDCB2 = dc390_findDCB(pACB, id, 0))) {
2106 pDCB->DevMode = pDCB2->DevMode;
2107 pDCB->SyncMode = pDCB2->SyncMode & SYNC_NEGO_DONE;
2108 pDCB->SyncPeriod = pDCB2->SyncPeriod;
2109 pDCB->SyncOffset = pDCB2->SyncOffset;
2110 pDCB->NegoPeriod = pDCB2->NegoPeriod;
2111
2112 pDCB->CtrlR3 = pDCB2->CtrlR3;
2113 pDCB->CtrlR4 = pDCB2->CtrlR4;
2114 } else {
2115 u8 index = pACB->AdapterIndex;
2116 PEEprom prom = (PEEprom) &dc390_eepromBuf[index][id << 2];
2117
2118 pDCB->DevMode = prom->EE_MODE1;
2119 pDCB->NegoPeriod =
2120 (dc390_clock_period1[prom->EE_SPEED] * 25) >> 2;
2121 pDCB->CtrlR3 = FAST_CLK;
2122 pDCB->CtrlR4 = pACB->glitch_cfg | CTRL4_RESERVED;
2123 if (dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION)
2124 pDCB->CtrlR4 |= NEGATE_REQACKDATA | NEGATE_REQACK;
2125 }
2126
2127 if (pDCB->DevMode & SYNC_NEGO_)
2128 pDCB->SyncMode |= SYNC_ENABLE;
2129 else {
2130 pDCB->SyncMode = 0;
2131 pDCB->SyncOffset &= ~0x0f;
2132 }
2133
2134 pDCB->CtrlR1 = pACB->pScsiHost->this_id;
2135 if (pDCB->DevMode & PARITY_CHK_)
2136 pDCB->CtrlR1 |= PARITY_ERR_REPO;
2137
2138 pACB->scan_devices = 1;
2139 scsi_device->hostdata = pDCB;
2140 return 0;
2141}
2142
2143/**
2144 * dc390_slave_destroy - Called by the scsi mid layer to tell us about a
2145 * device that is going away.
2146 *
2147 * @scsi_device: The scsi device that we need to remove.
2148 */
2149static void dc390_slave_destroy(struct scsi_device *scsi_device)
2150{
2151 struct dc390_acb* pACB = (struct dc390_acb*) scsi_device->host->hostdata;
2152 struct dc390_dcb* pDCB = (struct dc390_dcb*) scsi_device->hostdata;
2153 struct dc390_dcb* pPrevDCB = pACB->pLinkDCB;
2154
2155 pACB->scan_devices = 0;
2156
2157 BUG_ON(pDCB->GoingSRBCnt > 1);
2158
2159 if (pDCB == pACB->pLinkDCB) {
2160 if (pACB->pLastDCB == pDCB) {
2161 pDCB->pNextDCB = NULL;
2162 pACB->pLastDCB = NULL;
2163 }
2164 pACB->pLinkDCB = pDCB->pNextDCB;
2165 } else {
2166 while (pPrevDCB->pNextDCB != pDCB)
2167 pPrevDCB = pPrevDCB->pNextDCB;
2168 pPrevDCB->pNextDCB = pDCB->pNextDCB;
2169 if (pDCB == pACB->pLastDCB)
2170 pACB->pLastDCB = pPrevDCB;
2171 }
2172
2173 if (pDCB == pACB->pActiveDCB)
2174 pACB->pActiveDCB = NULL;
2175 if (pDCB == pACB->pLinkDCB)
2176 pACB->pLinkDCB = pDCB->pNextDCB;
2177 if (pDCB == pACB->pDCBRunRobin)
2178 pACB->pDCBRunRobin = pDCB->pNextDCB;
2179 kfree(pDCB);
2180
2181 pACB->DCBCnt--;
2182}
2183
2184static int dc390_slave_configure(struct scsi_device *sdev)
2185{
2186 struct dc390_acb *acb = (struct dc390_acb *)sdev->host->hostdata;
2187 struct dc390_dcb *dcb = (struct dc390_dcb *)sdev->hostdata;
2188
2189 acb->scan_devices = 0;
2190 if (sdev->tagged_supported && (dcb->DevMode & TAG_QUEUEING_)) {
2191 dcb->SyncMode |= EN_TAG_QUEUEING;
2192 scsi_activate_tcq(sdev, acb->TagMaxNum);
2193 }
2194
2195 return 0;
2196}
2197
2198static struct scsi_host_template driver_template = {
2199 .module = THIS_MODULE,
2200 .proc_name = "tmscsim",
2201 .name = DC390_BANNER " V" DC390_VERSION,
2202 .slave_alloc = dc390_slave_alloc,
2203 .slave_configure = dc390_slave_configure,
2204 .slave_destroy = dc390_slave_destroy,
2205 .queuecommand = DC390_queuecommand,
2206 .eh_abort_handler = DC390_abort,
2207 .eh_bus_reset_handler = DC390_bus_reset,
2208 .can_queue = 1,
2209 .this_id = 7,
2210 .sg_tablesize = SG_ALL,
2211 .cmd_per_lun = 1,
2212 .use_clustering = ENABLE_CLUSTERING,
2213 .max_sectors = 0x4000, /* 8MiB = 16 * 1024 * 512 */
2214};
2215
2216/***********************************************************************
2217 * Functions for access to DC390 EEPROM
2218 * and some to emulate it
2219 *
2220 **********************************************************************/
2221
2222static void dc390_eeprom_prepare_read(struct pci_dev *pdev, u8 cmd)
2223{
2224 u8 carryFlag = 1, j = 0x80, bval;
2225 int i;
2226
2227 for (i = 0; i < 9; i++) {
2228 if (carryFlag) {
2229 pci_write_config_byte(pdev, 0x80, 0x40);
2230 bval = 0xc0;
2231 } else
2232 bval = 0x80;
2233
2234 udelay(160);
2235 pci_write_config_byte(pdev, 0x80, bval);
2236 udelay(160);
2237 pci_write_config_byte(pdev, 0x80, 0);
2238 udelay(160);
2239
2240 carryFlag = (cmd & j) ? 1 : 0;
2241 j >>= 1;
2242 }
2243}
2244
2245static u16 dc390_eeprom_get_data(struct pci_dev *pdev)
2246{
2247 int i;
2248 u16 wval = 0;
2249 u8 bval;
2250
2251 for (i = 0; i < 16; i++) {
2252 wval <<= 1;
2253
2254 pci_write_config_byte(pdev, 0x80, 0x80);
2255 udelay(160);
2256 pci_write_config_byte(pdev, 0x80, 0x40);
2257 udelay(160);
2258 pci_read_config_byte(pdev, 0x00, &bval);
2259
2260 if (bval == 0x22)
2261 wval |= 1;
2262 }
2263
2264 return wval;
2265}
2266
2267static void dc390_read_eeprom(struct pci_dev *pdev, u16 *ptr)
2268{
2269 u8 cmd = EEPROM_READ, i;
2270
2271 for (i = 0; i < 0x40; i++) {
2272 pci_write_config_byte(pdev, 0xc0, 0);
2273 udelay(160);
2274
2275 dc390_eeprom_prepare_read(pdev, cmd++);
2276 *ptr++ = dc390_eeprom_get_data(pdev);
2277
2278 pci_write_config_byte(pdev, 0x80, 0);
2279 pci_write_config_byte(pdev, 0x80, 0);
2280 udelay(160);
2281 }
2282}
2283
2284/* Override EEprom values with explicitly set values */
2285static void dc390_eeprom_override(u8 index)
2286{
2287 u8 *ptr = (u8 *) dc390_eepromBuf[index], id;
2288
2289 /* Adapter Settings */
2290 if (tmscsim[0] != -2)
2291 ptr[EE_ADAPT_SCSI_ID] = (u8)tmscsim[0]; /* Adapter ID */
2292 if (tmscsim[3] != -2)
2293 ptr[EE_MODE2] = (u8)tmscsim[3];
2294 if (tmscsim[5] != -2)
2295 ptr[EE_DELAY] = tmscsim[5]; /* Reset delay */
2296 if (tmscsim[4] != -2)
2297 ptr[EE_TAG_CMD_NUM] = (u8)tmscsim[4]; /* Tagged Cmds */
2298
2299 /* Device Settings */
2300 for (id = 0; id < MAX_SCSI_ID; id++) {
2301 if (tmscsim[2] != -2)
2302 ptr[id << 2] = (u8)tmscsim[2]; /* EE_MODE1 */
2303 if (tmscsim[1] != -2)
2304 ptr[(id << 2) + 1] = (u8)tmscsim[1]; /* EE_Speed */
2305 }
2306}
2307
2308static int tmscsim_def[] = {
2309 7,
2310 0 /* 10MHz */,
2311 PARITY_CHK_ | SEND_START_ | EN_DISCONNECT_ | SYNC_NEGO_ | TAG_QUEUEING_,
2312 MORE2_DRV | GREATER_1G | RST_SCSI_BUS | ACTIVE_NEGATION | LUN_CHECK,
2313 3 /* 16 Tags per LUN */,
2314 1 /* s delay after Reset */,
2315};
2316
2317/* Copy defaults over set values where missing */
2318static void dc390_fill_with_defaults (void)
2319{
2320 int i;
2321
2322 for (i = 0; i < 6; i++) {
2323 if (tmscsim[i] < 0 || tmscsim[i] > 255)
2324 tmscsim[i] = tmscsim_def[i];
2325 }
2326
2327 /* Sanity checks */
2328 if (tmscsim[0] > 7)
2329 tmscsim[0] = 7;
2330 if (tmscsim[1] > 7)
2331 tmscsim[1] = 4;
2332 if (tmscsim[4] > 5)
2333 tmscsim[4] = 4;
2334 if (tmscsim[5] > 180)
2335 tmscsim[5] = 180;
2336}
2337
2338static void dc390_check_eeprom(struct pci_dev *pdev, u8 index)
2339{
2340 u8 interpd[] = {1, 3, 5, 10, 16, 30, 60, 120};
2341 u8 EEbuf[128];
2342 u16 *ptr = (u16 *)EEbuf, wval = 0;
2343 int i;
2344
2345 dc390_read_eeprom(pdev, ptr);
2346 memcpy(dc390_eepromBuf[index], EEbuf, EE_ADAPT_SCSI_ID);
2347 memcpy(&dc390_eepromBuf[index][EE_ADAPT_SCSI_ID],
2348 &EEbuf[REAL_EE_ADAPT_SCSI_ID], EE_LEN - EE_ADAPT_SCSI_ID);
2349
2350 dc390_eepromBuf[index][EE_DELAY] = interpd[dc390_eepromBuf[index][EE_DELAY]];
2351
2352 for (i = 0; i < 0x40; i++, ptr++)
2353 wval += *ptr;
2354
2355 /* no Tekram EEprom found */
2356 if (wval != 0x1234) {
2357 int speed;
2358
2359 printk(KERN_INFO "DC390_init: No EEPROM found! Trying default settings ...\n");
2360
2361 /*
2362 * XXX(hch): bogus, because we might have tekram and
2363 * non-tekram hbas in a single machine.
2364 */
2365 dc390_fill_with_defaults();
2366
2367 speed = dc390_clock_speed[tmscsim[1]];
2368 printk(KERN_INFO "DC390: Used defaults: AdaptID=%i, SpeedIdx=%i (%i.%i MHz), "
2369 "DevMode=0x%02x, AdaptMode=0x%02x, TaggedCmnds=%i (%i), DelayReset=%is\n",
2370 tmscsim[0], tmscsim[1], speed / 10, speed % 10,
2371 (u8)tmscsim[2], (u8)tmscsim[3], tmscsim[4], 2 << (tmscsim[4]), tmscsim[5]);
2372 }
2373}
2374
2375static void dc390_init_hw(struct dc390_acb *pACB, u8 index)
2376{
2377 struct Scsi_Host *shost = pACB->pScsiHost;
2378 u8 dstate;
2379
2380 /* Disable SCSI bus reset interrupt */
2381 DC390_write8(CtrlReg1, DIS_INT_ON_SCSI_RST | shost->this_id);
2382
2383 if (pACB->Gmode2 & RST_SCSI_BUS) {
2384 dc390_ResetSCSIBus(pACB);
2385 udelay(1000);
2386 pACB->last_reset = jiffies + HZ/2 +
2387 HZ * dc390_eepromBuf[pACB->AdapterIndex][EE_DELAY];
2388 }
2389
2390 pACB->ACBFlag = 0;
2391
2392 /* Reset Pending INT */
2393 DC390_read8(INT_Status);
2394
2395 /* 250ms selection timeout */
2396 DC390_write8(Scsi_TimeOut, SEL_TIMEOUT);
2397
2398 /* Conversion factor = 0 , 40MHz clock */
2399 DC390_write8(Clk_Factor, CLK_FREQ_40MHZ);
2400
2401 /* NOP cmd - clear command register */
2402 DC390_write8(ScsiCmd, NOP_CMD);
2403
2404 /* Enable Feature and SCSI-2 */
2405 DC390_write8(CtrlReg2, EN_FEATURE+EN_SCSI2_CMD);
2406
2407 /* Fast clock */
2408 DC390_write8(CtrlReg3, FAST_CLK);
2409
2410 /* Negation */
2411 DC390_write8(CtrlReg4, pACB->glitch_cfg | /* glitch eater */
2412 (dc390_eepromBuf[index][EE_MODE2] & ACTIVE_NEGATION) ?
2413 NEGATE_REQACKDATA : 0);
2414
2415 /* Clear Transfer Count High: ID */
2416 DC390_write8(CtcReg_High, 0);
2417 DC390_write8(DMA_Cmd, DMA_IDLE_CMD);
2418 DC390_write8(ScsiCmd, CLEAR_FIFO_CMD);
2419 DC390_write32(DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT);
2420
2421 dstate = DC390_read8(DMA_Status);
2422 DC390_write8(DMA_Status, dstate);
2423}
2424
2425static int dc390_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2426{
2427 struct dc390_acb *pACB;
2428 struct Scsi_Host *shost;
2429 unsigned long io_port;
2430 int error = -ENODEV, i;
2431
2432 if (pci_enable_device(pdev))
2433 goto out;
2434
2435 pci_set_master(pdev);
2436
2437 error = -ENOMEM;
2438 if (disable_clustering)
2439 driver_template.use_clustering = DISABLE_CLUSTERING;
2440 shost = scsi_host_alloc(&driver_template, sizeof(struct dc390_acb));
2441 if (!shost)
2442 goto out_disable_device;
2443
2444 pACB = (struct dc390_acb *)shost->hostdata;
2445 memset(pACB, 0, sizeof(struct dc390_acb));
2446
2447 dc390_check_eeprom(pdev, dc390_adapterCnt);
2448 dc390_eeprom_override(dc390_adapterCnt);
2449
2450 io_port = pci_resource_start(pdev, 0);
2451
2452 shost->this_id = dc390_eepromBuf[dc390_adapterCnt][EE_ADAPT_SCSI_ID];
2453 shost->io_port = io_port;
2454 shost->n_io_port = 0x80;
2455 shost->irq = pdev->irq;
2456 shost->base = io_port;
2457 shost->unique_id = io_port;
2458
2459 pACB->last_reset = jiffies;
2460 pACB->pScsiHost = shost;
2461 pACB->IOPortBase = (u16) io_port;
2462 pACB->IRQLevel = pdev->irq;
2463
2464 shost->max_id = 8;
2465
2466 if (shost->max_id - 1 ==
2467 dc390_eepromBuf[dc390_adapterCnt][EE_ADAPT_SCSI_ID])
2468 shost->max_id--;
2469
2470 if (dc390_eepromBuf[dc390_adapterCnt][EE_MODE2] & LUN_CHECK)
2471 shost->max_lun = 8;
2472 else
2473 shost->max_lun = 1;
2474
2475 pACB->pFreeSRB = pACB->SRB_array;
2476 pACB->SRBCount = MAX_SRB_CNT;
2477 pACB->AdapterIndex = dc390_adapterCnt;
2478 pACB->TagMaxNum =
2479 2 << dc390_eepromBuf[dc390_adapterCnt][EE_TAG_CMD_NUM];
2480 pACB->Gmode2 = dc390_eepromBuf[dc390_adapterCnt][EE_MODE2];
2481
2482 for (i = 0; i < pACB->SRBCount-1; i++)
2483 pACB->SRB_array[i].pNextSRB = &pACB->SRB_array[i+1];
2484 pACB->SRB_array[pACB->SRBCount-1].pNextSRB = NULL;
2485 pACB->pTmpSRB = &pACB->TmpSRB;
2486
2487 pACB->sel_timeout = SEL_TIMEOUT;
2488 pACB->glitch_cfg = EATER_25NS;
2489 pACB->pdev = pdev;
2490
2491 if (!request_region(io_port, shost->n_io_port, "tmscsim")) {
2492 printk(KERN_ERR "DC390: register IO ports error!\n");
2493 goto out_host_put;
2494 }
2495
2496 /* Reset Pending INT */
2497 DC390_read8_(INT_Status, io_port);
2498
2499 if (request_irq(pdev->irq, do_DC390_Interrupt, IRQF_SHARED,
2500 "tmscsim", pACB)) {
2501 printk(KERN_ERR "DC390: register IRQ error!\n");
2502 goto out_release_region;
2503 }
2504
2505 dc390_init_hw(pACB, dc390_adapterCnt);
2506
2507 dc390_adapterCnt++;
2508
2509 pci_set_drvdata(pdev, shost);
2510
2511 error = scsi_add_host(shost, &pdev->dev);
2512 if (error)
2513 goto out_free_irq;
2514 scsi_scan_host(shost);
2515 return 0;
2516
2517 out_free_irq:
2518 free_irq(pdev->irq, pACB);
2519 out_release_region:
2520 release_region(io_port, shost->n_io_port);
2521 out_host_put:
2522 scsi_host_put(shost);
2523 out_disable_device:
2524 pci_disable_device(pdev);
2525 out:
2526 return error;
2527}
2528
2529/**
2530 * dc390_remove_one - Called to remove a single instance of the adapter.
2531 *
2532 * @dev: The PCI device to remove.
2533 */
2534static void dc390_remove_one(struct pci_dev *dev)
2535{
2536 struct Scsi_Host *scsi_host = pci_get_drvdata(dev);
2537 unsigned long iflags;
2538 struct dc390_acb* pACB = (struct dc390_acb*) scsi_host->hostdata;
2539 u8 bval;
2540
2541 scsi_remove_host(scsi_host);
2542
2543 spin_lock_irqsave(scsi_host->host_lock, iflags);
2544 pACB->ACBFlag = RESET_DEV;
2545 bval = DC390_read8(CtrlReg1) | DIS_INT_ON_SCSI_RST;
2546 DC390_write8 (CtrlReg1, bval); /* disable interrupt */
2547 if (pACB->Gmode2 & RST_SCSI_BUS)
2548 dc390_ResetSCSIBus(pACB);
2549 spin_unlock_irqrestore(scsi_host->host_lock, iflags);
2550
2551 free_irq(scsi_host->irq, pACB);
2552 release_region(scsi_host->io_port, scsi_host->n_io_port);
2553
2554 pci_disable_device(dev);
2555 scsi_host_put(scsi_host);
2556}
2557
2558static struct pci_device_id tmscsim_pci_tbl[] = {
2559 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD53C974,
2560 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
2561 { }
2562};
2563MODULE_DEVICE_TABLE(pci, tmscsim_pci_tbl);
2564
2565static struct pci_driver dc390_driver = {
2566 .name = "tmscsim",
2567 .id_table = tmscsim_pci_tbl,
2568 .probe = dc390_probe_one,
2569 .remove = dc390_remove_one,
2570};
2571
2572static int __init dc390_module_init(void)
2573{
2574 if (!disable_clustering) {
2575 printk(KERN_INFO "DC390: clustering now enabled by default. If you get problems load\n");
2576 printk(KERN_INFO " with \"disable_clustering=1\" and report to maintainers\n");
2577 }
2578
2579 if (tmscsim[0] == -1 || tmscsim[0] > 15) {
2580 tmscsim[0] = 7;
2581 tmscsim[1] = 4;
2582 tmscsim[2] = PARITY_CHK_ | TAG_QUEUEING_;
2583 tmscsim[3] = MORE2_DRV | GREATER_1G | RST_SCSI_BUS | ACTIVE_NEGATION;
2584 tmscsim[4] = 2;
2585 tmscsim[5] = 10;
2586 printk (KERN_INFO "DC390: Using safe settings.\n");
2587 }
2588
2589 return pci_register_driver(&dc390_driver);
2590}
2591
2592static void __exit dc390_module_exit(void)
2593{
2594 pci_unregister_driver(&dc390_driver);
2595}
2596
2597module_init(dc390_module_init);
2598module_exit(dc390_module_exit);
2599
2600#ifndef MODULE
2601static int __init dc390_setup (char *str)
2602{
2603 int ints[8],i, im;
2604
2605 get_options(str, ARRAY_SIZE(ints), ints);
2606 im = ints[0];
2607
2608 if (im > 6) {
2609 printk (KERN_NOTICE "DC390: ignore extra params!\n");
2610 im = 6;
2611 }
2612
2613 for (i = 0; i < im; i++)
2614 tmscsim[i] = ints[i+1];
2615 /* dc390_checkparams (); */
2616 return 1;
2617}
2618
2619__setup("tmscsim=", dc390_setup);
2620#endif
diff --git a/drivers/scsi/tmscsim.h b/drivers/scsi/tmscsim.h
deleted file mode 100644
index 3d1bb4ad1826..000000000000
--- a/drivers/scsi/tmscsim.h
+++ /dev/null
@@ -1,551 +0,0 @@
1/***********************************************************************
2;* File Name : TMSCSIM.H *
3;* TEKRAM DC-390(T) PCI SCSI Bus Master Host Adapter *
4;* Device Driver *
5;***********************************************************************/
6/* $Id: tmscsim.h,v 2.15.2.3 2000/11/17 20:52:27 garloff Exp $ */
7
8#ifndef _TMSCSIM_H
9#define _TMSCSIM_H
10
11#include <linux/types.h>
12
13#define SCSI_IRQ_NONE 255
14
15#define MAX_ADAPTER_NUM 4
16#define MAX_SG_LIST_BUF 16 /* Not used */
17#define MAX_SCSI_ID 8
18#define MAX_SRB_CNT 50 /* Max number of started commands */
19
20#define SEL_TIMEOUT 153 /* 250 ms selection timeout (@ 40 MHz) */
21
22/*
23;-----------------------------------------------------------------------
24; SCSI Request Block
25;-----------------------------------------------------------------------
26*/
27struct dc390_srb
28{
29//u8 CmdBlock[12];
30
31struct dc390_srb *pNextSRB;
32struct dc390_dcb *pSRBDCB;
33struct scsi_cmnd *pcmd;
34struct scatterlist *pSegmentList;
35
36struct scatterlist Segmentx; /* make a one entry of S/G list table */
37
38unsigned long SGBusAddr; /*;a segment starting address as seen by AM53C974A
39 in CPU endianness. We're only getting 32-bit bus
40 addresses by default */
41unsigned long SGToBeXferLen; /*; to be xfer length */
42unsigned long TotalXferredLen;
43unsigned long SavedTotXLen;
44unsigned long Saved_Ptr;
45u32 SRBState;
46
47u8 SRBStatus;
48u8 SRBFlag; /*; b0-AutoReqSense,b6-Read,b7-write */
49 /*; b4-settimeout,b5-Residual valid */
50u8 AdaptStatus;
51u8 TargetStatus;
52
53u8 ScsiPhase;
54s8 TagNumber;
55u8 SGIndex;
56u8 SGcount;
57
58u8 MsgCnt;
59u8 EndMessage;
60
61u8 MsgInBuf[6];
62u8 MsgOutBuf[6];
63
64//u8 IORBFlag; /*;81h-Reset, 2-retry */
65};
66
67
68/*
69;-----------------------------------------------------------------------
70; Device Control Block
71;-----------------------------------------------------------------------
72*/
73struct dc390_dcb
74{
75struct dc390_dcb *pNextDCB;
76struct dc390_acb *pDCBACB;
77
78/* Queued SRBs */
79struct dc390_srb *pGoingSRB;
80struct dc390_srb *pGoingLast;
81struct dc390_srb *pActiveSRB;
82u8 GoingSRBCnt;
83
84u32 TagMask;
85
86u8 TargetID; /*; SCSI Target ID (SCSI Only) */
87u8 TargetLUN; /*; SCSI Log. Unit (SCSI Only) */
88u8 DevMode;
89u8 DCBFlag;
90
91u8 CtrlR1;
92u8 CtrlR3;
93u8 CtrlR4;
94
95u8 SyncMode; /*; 0:async mode */
96u8 NegoPeriod; /*;for nego. */
97u8 SyncPeriod; /*;for reg. */
98u8 SyncOffset; /*;for reg. and nego.(low nibble) */
99};
100
101
102/*
103;-----------------------------------------------------------------------
104; Adapter Control Block
105;-----------------------------------------------------------------------
106*/
107struct dc390_acb
108{
109struct Scsi_Host *pScsiHost;
110u16 IOPortBase;
111u8 IRQLevel;
112u8 status;
113
114u8 SRBCount;
115u8 AdapterIndex; /*; nth Adapter this driver */
116u8 DCBCnt;
117
118u8 TagMaxNum;
119u8 ACBFlag;
120u8 Gmode2;
121u8 scan_devices;
122
123struct dc390_dcb *pLinkDCB;
124struct dc390_dcb *pLastDCB;
125struct dc390_dcb *pDCBRunRobin;
126
127struct dc390_dcb *pActiveDCB;
128struct dc390_srb *pFreeSRB;
129struct dc390_srb *pTmpSRB;
130
131u8 msgin123[4];
132u8 Connected;
133u8 pad;
134
135#if defined(USE_SPINLOCKS) && USE_SPINLOCKS > 1 && (defined(CONFIG_SMP) || DEBUG_SPINLOCKS > 0)
136spinlock_t lock;
137#endif
138u8 sel_timeout;
139u8 glitch_cfg;
140
141u8 MsgLen;
142u8 Ignore_IRQ; /* Not used */
143
144struct pci_dev *pdev;
145
146unsigned long last_reset;
147unsigned long Cmds;
148u32 SelLost;
149u32 SelConn;
150u32 CmdInQ;
151u32 CmdOutOfSRB;
152
153struct dc390_srb TmpSRB;
154struct dc390_srb SRB_array[MAX_SRB_CNT]; /* 50 SRBs */
155};
156
157
158/*;-----------------------------------------------------------------------*/
159
160
161#define BIT31 0x80000000
162#define BIT30 0x40000000
163#define BIT29 0x20000000
164#define BIT28 0x10000000
165#define BIT27 0x08000000
166#define BIT26 0x04000000
167#define BIT25 0x02000000
168#define BIT24 0x01000000
169#define BIT23 0x00800000
170#define BIT22 0x00400000
171#define BIT21 0x00200000
172#define BIT20 0x00100000
173#define BIT19 0x00080000
174#define BIT18 0x00040000
175#define BIT17 0x00020000
176#define BIT16 0x00010000
177#define BIT15 0x00008000
178#define BIT14 0x00004000
179#define BIT13 0x00002000
180#define BIT12 0x00001000
181#define BIT11 0x00000800
182#define BIT10 0x00000400
183#define BIT9 0x00000200
184#define BIT8 0x00000100
185#define BIT7 0x00000080
186#define BIT6 0x00000040
187#define BIT5 0x00000020
188#define BIT4 0x00000010
189#define BIT3 0x00000008
190#define BIT2 0x00000004
191#define BIT1 0x00000002
192#define BIT0 0x00000001
193
194/*;---UnitCtrlFlag */
195#define UNIT_ALLOCATED BIT0
196#define UNIT_INFO_CHANGED BIT1
197#define FORMATING_MEDIA BIT2
198#define UNIT_RETRY BIT3
199
200/*;---UnitFlags */
201#define DASD_SUPPORT BIT0
202#define SCSI_SUPPORT BIT1
203#define ASPI_SUPPORT BIT2
204
205/*;----SRBState machine definition */
206#define SRB_FREE 0
207#define SRB_WAIT BIT0
208#define SRB_READY BIT1
209#define SRB_MSGOUT BIT2 /*;arbitration+msg_out 1st byte*/
210#define SRB_MSGIN BIT3
211#define SRB_MSGIN_MULTI BIT4
212#define SRB_COMMAND BIT5
213#define SRB_START_ BIT6 /*;arbitration+msg_out+command_out*/
214#define SRB_DISCONNECT BIT7
215#define SRB_DATA_XFER BIT8
216#define SRB_XFERPAD BIT9
217#define SRB_STATUS BIT10
218#define SRB_COMPLETED BIT11
219#define SRB_ABORT_SENT BIT12
220#define DO_SYNC_NEGO BIT13
221#define SRB_UNEXPECT_RESEL BIT14
222
223/*;---SRBstatus */
224#define SRB_OK BIT0
225#define ABORTION BIT1
226#define OVER_RUN BIT2
227#define UNDER_RUN BIT3
228#define PARITY_ERROR BIT4
229#define SRB_ERROR BIT5
230
231/*;---ACBFlag */
232#define RESET_DEV BIT0
233#define RESET_DETECT BIT1
234#define RESET_DONE BIT2
235
236/*;---DCBFlag */
237#define ABORT_DEV_ BIT0
238
239/*;---SRBFlag */
240#define DATAOUT BIT7
241#define DATAIN BIT6
242#define RESIDUAL_VALID BIT5
243#define ENABLE_TIMER BIT4
244#define RESET_DEV0 BIT2
245#define ABORT_DEV BIT1
246#define AUTO_REQSENSE BIT0
247
248/*;---Adapter status */
249#define H_STATUS_GOOD 0
250#define H_SEL_TIMEOUT 0x11
251#define H_OVER_UNDER_RUN 0x12
252#define H_UNEXP_BUS_FREE 0x13
253#define H_TARGET_PHASE_F 0x14
254#define H_INVALID_CCB_OP 0x16
255#define H_LINK_CCB_BAD 0x17
256#define H_BAD_TARGET_DIR 0x18
257#define H_DUPLICATE_CCB 0x19
258#define H_BAD_CCB_OR_SG 0x1A
259#define H_ABORT 0x0FF
260
261/* cmd->result */
262#define RES_TARGET 0x000000FF /* Target State */
263#define RES_TARGET_LNX STATUS_MASK /* Only official ... */
264#define RES_ENDMSG 0x0000FF00 /* End Message */
265#define RES_DID 0x00FF0000 /* DID_ codes */
266#define RES_DRV 0xFF000000 /* DRIVER_ codes */
267
268#define MK_RES(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt))
269#define MK_RES_LNX(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt))
270
271#define SET_RES_TARGET(who, tgt) do { who &= ~RES_TARGET; who |= (int)(tgt); } while (0)
272#define SET_RES_TARGET_LNX(who, tgt) do { who &= ~RES_TARGET_LNX; who |= (int)(tgt) << 1; } while (0)
273#define SET_RES_MSG(who, msg) do { who &= ~RES_ENDMSG; who |= (int)(msg) << 8; } while (0)
274#define SET_RES_DID(who, did) do { who &= ~RES_DID; who |= (int)(did) << 16; } while (0)
275#define SET_RES_DRV(who, drv) do { who &= ~RES_DRV; who |= (int)(drv) << 24; } while (0)
276
277/*;---Sync_Mode */
278#define SYNC_DISABLE 0
279#define SYNC_ENABLE BIT0
280#define SYNC_NEGO_DONE BIT1
281#define WIDE_ENABLE BIT2 /* Not used ;-) */
282#define WIDE_NEGO_DONE BIT3 /* Not used ;-) */
283#define EN_TAG_QUEUEING BIT4
284#define EN_ATN_STOP BIT5
285
286#define SYNC_NEGO_OFFSET 15
287
288/*;---SCSI bus phase*/
289#define SCSI_DATA_OUT 0
290#define SCSI_DATA_IN 1
291#define SCSI_COMMAND 2
292#define SCSI_STATUS_ 3
293#define SCSI_NOP0 4
294#define SCSI_NOP1 5
295#define SCSI_MSG_OUT 6
296#define SCSI_MSG_IN 7
297
298/*;----SCSI MSG BYTE*/ /* see scsi/scsi.h */ /* One is missing ! */
299#define ABORT_TAG 0x0d
300
301/*
302 * SISC query queue
303 */
304typedef struct {
305 dma_addr_t saved_dma_handle;
306} dc390_cmd_scp_t;
307
308/*
309;==========================================================
310; EEPROM byte offset
311;==========================================================
312*/
313typedef struct _EEprom
314{
315u8 EE_MODE1;
316u8 EE_SPEED;
317u8 xx1;
318u8 xx2;
319} EEprom, *PEEprom;
320
321#define REAL_EE_ADAPT_SCSI_ID 64
322#define REAL_EE_MODE2 65
323#define REAL_EE_DELAY 66
324#define REAL_EE_TAG_CMD_NUM 67
325
326#define EE_ADAPT_SCSI_ID 32
327#define EE_MODE2 33
328#define EE_DELAY 34
329#define EE_TAG_CMD_NUM 35
330
331#define EE_LEN 40
332
333/*; EE_MODE1 bits definition*/
334#define PARITY_CHK_ BIT0
335#define SYNC_NEGO_ BIT1
336#define EN_DISCONNECT_ BIT2
337#define SEND_START_ BIT3
338#define TAG_QUEUEING_ BIT4
339
340/*; EE_MODE2 bits definition*/
341#define MORE2_DRV BIT0
342#define GREATER_1G BIT1
343#define RST_SCSI_BUS BIT2
344#define ACTIVE_NEGATION BIT3
345#define NO_SEEK BIT4
346#define LUN_CHECK BIT5
347
348#define ENABLE_CE 1
349#define DISABLE_CE 0
350#define EEPROM_READ 0x80
351
352/*
353;==========================================================
354; AMD 53C974 Registers bit Definition
355;==========================================================
356*/
357/*
358;====================
359; SCSI Register
360;====================
361*/
362
363/*; Command Reg.(+0CH) (rw) */
364#define DMA_COMMAND BIT7
365#define NOP_CMD 0
366#define CLEAR_FIFO_CMD 1
367#define RST_DEVICE_CMD 2
368#define RST_SCSI_BUS_CMD 3
369
370#define INFO_XFER_CMD 0x10
371#define INITIATOR_CMD_CMPLTE 0x11
372#define MSG_ACCEPTED_CMD 0x12
373#define XFER_PAD_BYTE 0x18
374#define SET_ATN_CMD 0x1A
375#define RESET_ATN_CMD 0x1B
376
377#define SEL_WO_ATN 0x41 /* currently not used */
378#define SEL_W_ATN 0x42
379#define SEL_W_ATN_STOP 0x43
380#define SEL_W_ATN3 0x46
381#define EN_SEL_RESEL 0x44
382#define DIS_SEL_RESEL 0x45 /* currently not used */
383#define RESEL 0x40 /* " */
384#define RESEL_ATN3 0x47 /* " */
385
386#define DATA_XFER_CMD INFO_XFER_CMD
387
388
389/*; SCSI Status Reg.(+10H) (r) */
390#define INTERRUPT BIT7
391#define ILLEGAL_OP_ERR BIT6
392#define PARITY_ERR BIT5
393#define COUNT_2_ZERO BIT4
394#define GROUP_CODE_VALID BIT3
395#define SCSI_PHASE_MASK (BIT2+BIT1+BIT0)
396/* BIT2: MSG phase; BIT1: C/D physe; BIT0: I/O phase */
397
398/*; Interrupt Status Reg.(+14H) (r) */
399#define SCSI_RESET BIT7
400#define INVALID_CMD BIT6
401#define DISCONNECTED BIT5
402#define SERVICE_REQUEST BIT4
403#define SUCCESSFUL_OP BIT3
404#define RESELECTED BIT2
405#define SEL_ATTENTION BIT1
406#define SELECTED BIT0
407
408/*; Internal State Reg.(+18H) (r) */
409#define SYNC_OFFSET_FLAG BIT3
410#define INTRN_STATE_MASK (BIT2+BIT1+BIT0)
411/* 0x04: Sel. successful (w/o stop), 0x01: Sel. successful (w/ stop) */
412
413/*; Clock Factor Reg.(+24H) (w) */
414#define CLK_FREQ_40MHZ 0
415#define CLK_FREQ_35MHZ (BIT2+BIT1+BIT0)
416#define CLK_FREQ_30MHZ (BIT2+BIT1)
417#define CLK_FREQ_25MHZ (BIT2+BIT0)
418#define CLK_FREQ_20MHZ BIT2
419#define CLK_FREQ_15MHZ (BIT1+BIT0)
420#define CLK_FREQ_10MHZ BIT1
421
422/*; Control Reg. 1(+20H) (rw) */
423#define EXTENDED_TIMING BIT7
424#define DIS_INT_ON_SCSI_RST BIT6
425#define PARITY_ERR_REPO BIT4
426#define SCSI_ID_ON_BUS (BIT2+BIT1+BIT0) /* host adapter ID */
427
428/*; Control Reg. 2(+2CH) (rw) */
429#define EN_FEATURE BIT6
430#define EN_SCSI2_CMD BIT3
431
432/*; Control Reg. 3(+30H) (rw) */
433#define ID_MSG_CHECK BIT7
434#define EN_QTAG_MSG BIT6
435#define EN_GRP2_CMD BIT5
436#define FAST_SCSI BIT4 /* ;10MB/SEC */
437#define FAST_CLK BIT3 /* ;25 - 40 MHZ */
438
439/*; Control Reg. 4(+34H) (rw) */
440#define EATER_12NS 0
441#define EATER_25NS BIT7
442#define EATER_35NS BIT6
443#define EATER_0NS (BIT7+BIT6)
444#define REDUCED_POWER BIT5
445#define CTRL4_RESERVED BIT4 /* must be 1 acc. to AM53C974.c */
446#define NEGATE_REQACKDATA BIT2
447#define NEGATE_REQACK BIT3
448
449#define GLITCH_TO_NS(x) (((~x>>6 & 2) >> 1) | ((x>>6 & 1) << 1 ^ (x>>6 & 2)))
450#define NS_TO_GLITCH(y) (((~y<<7) | ~((y<<6) ^ ((y<<5 & 1<<6) | ~0x40))) & 0xc0)
451
452/*
453;====================
454; DMA Register
455;====================
456*/
457/*; DMA Command Reg.(+40H) (rw) */
458#define READ_DIRECTION BIT7
459#define WRITE_DIRECTION 0
460#define EN_DMA_INT BIT6
461#define EN_PAGE_INT BIT5 /* page transfer interrupt enable */
462#define MAP_TO_MDL BIT4
463#define DIAGNOSTIC BIT2
464#define DMA_IDLE_CMD 0
465#define DMA_BLAST_CMD BIT0
466#define DMA_ABORT_CMD BIT1
467#define DMA_START_CMD (BIT1+BIT0)
468
469/*; DMA Status Reg.(+54H) (r) */
470#define PCI_MS_ABORT BIT6
471#define BLAST_COMPLETE BIT5
472#define SCSI_INTERRUPT BIT4
473#define DMA_XFER_DONE BIT3
474#define DMA_XFER_ABORT BIT2
475#define DMA_XFER_ERROR BIT1
476#define POWER_DOWN BIT0
477
478/*; DMA SCSI Bus and Ctrl.(+70H) */
479#define EN_INT_ON_PCI_ABORT BIT25
480#define WRT_ERASE_DMA_STAT BIT24
481#define PW_DOWN_CTRL BIT21
482#define SCSI_BUSY BIT20
483#define SCLK BIT19
484#define SCAM BIT18
485#define SCSI_LINES 0x0003ffff
486
487/*
488;==========================================================
489; SCSI Chip register address offset
490;==========================================================
491;Registers are rw unless declared otherwise
492*/
493#define CtcReg_Low 0x00 /* r curr. transfer count */
494#define CtcReg_Mid 0x04 /* r */
495#define CtcReg_High 0x38 /* r */
496#define ScsiFifo 0x08
497#define ScsiCmd 0x0C
498#define Scsi_Status 0x10 /* r */
499#define INT_Status 0x14 /* r */
500#define Sync_Period 0x18 /* w */
501#define Sync_Offset 0x1C /* w */
502#define Clk_Factor 0x24 /* w */
503#define CtrlReg1 0x20
504#define CtrlReg2 0x2C
505#define CtrlReg3 0x30
506#define CtrlReg4 0x34
507#define DMA_Cmd 0x40
508#define DMA_XferCnt 0x44 /* rw starting transfer count (32 bit) */
509#define DMA_XferAddr 0x48 /* rw starting physical address (32 bit) */
510#define DMA_Wk_ByteCntr 0x4C /* r working byte counter */
511#define DMA_Wk_AddrCntr 0x50 /* r working address counter */
512#define DMA_Status 0x54 /* r */
513#define DMA_MDL_Addr 0x58 /* rw starting MDL address */
514#define DMA_Wk_MDL_Cntr 0x5C /* r working MDL counter */
515#define DMA_ScsiBusCtrl 0x70 /* rw SCSI Bus, PCI/DMA Ctrl */
516
517#define StcReg_Low CtcReg_Low /* w start transfer count */
518#define StcReg_Mid CtcReg_Mid /* w */
519#define StcReg_High CtcReg_High /* w */
520#define Scsi_Dest_ID Scsi_Status /* w */
521#define Scsi_TimeOut INT_Status /* w */
522#define Intern_State Sync_Period /* r */
523#define Current_Fifo Sync_Offset /* r Curr. FIFO / int. state */
524
525
526#define DC390_read8(address) \
527 (inb (pACB->IOPortBase + (address)))
528
529#define DC390_read8_(address, base) \
530 (inb ((u16)(base) + (address)))
531
532#define DC390_read16(address) \
533 (inw (pACB->IOPortBase + (address)))
534
535#define DC390_read32(address) \
536 (inl (pACB->IOPortBase + (address)))
537
538#define DC390_write8(address,value) \
539 outb ((value), pACB->IOPortBase + (address))
540
541#define DC390_write8_(address,value,base) \
542 outb ((value), (u16)(base) + (address))
543
544#define DC390_write16(address,value) \
545 outw ((value), pACB->IOPortBase + (address))
546
547#define DC390_write32(address,value) \
548 outl ((value), pACB->IOPortBase + (address))
549
550
551#endif /* _TMSCSIM_H */
diff --git a/drivers/scsi/u14-34f.c b/drivers/scsi/u14-34f.c
index d8dcf36aed11..14eb50b95a1e 100644
--- a/drivers/scsi/u14-34f.c
+++ b/drivers/scsi/u14-34f.c
@@ -696,25 +696,25 @@ static int u14_34f_slave_configure(struct scsi_device *dev) {
696 if (TLDEV(dev->type) && dev->tagged_supported) 696 if (TLDEV(dev->type) && dev->tagged_supported)
697 697
698 if (tag_mode == TAG_SIMPLE) { 698 if (tag_mode == TAG_SIMPLE) {
699 scsi_adjust_queue_depth(dev, MSG_SIMPLE_TAG, tqd); 699 scsi_change_queue_depth(dev, tqd);
700 tag_suffix = ", simple tags"; 700 tag_suffix = ", simple tags";
701 } 701 }
702 else if (tag_mode == TAG_ORDERED) { 702 else if (tag_mode == TAG_ORDERED) {
703 scsi_adjust_queue_depth(dev, MSG_ORDERED_TAG, tqd); 703 scsi_change_queue_depth(dev, tqd);
704 tag_suffix = ", ordered tags"; 704 tag_suffix = ", ordered tags";
705 } 705 }
706 else { 706 else {
707 scsi_adjust_queue_depth(dev, 0, tqd); 707 scsi_change_queue_depth(dev, tqd);
708 tag_suffix = ", no tags"; 708 tag_suffix = ", no tags";
709 } 709 }
710 710
711 else if (TLDEV(dev->type) && linked_comm) { 711 else if (TLDEV(dev->type) && linked_comm) {
712 scsi_adjust_queue_depth(dev, 0, tqd); 712 scsi_change_queue_depth(dev, tqd);
713 tag_suffix = ", untagged"; 713 tag_suffix = ", untagged";
714 } 714 }
715 715
716 else { 716 else {
717 scsi_adjust_queue_depth(dev, 0, utqd); 717 scsi_change_queue_depth(dev, utqd);
718 tag_suffix = ""; 718 tag_suffix = "";
719 } 719 }
720 720
diff --git a/drivers/scsi/ufs/ufshcd-pltfrm.c b/drivers/scsi/ufs/ufshcd-pltfrm.c
index 8adf067ff019..1c3467b82566 100644
--- a/drivers/scsi/ufs/ufshcd-pltfrm.c
+++ b/drivers/scsi/ufs/ufshcd-pltfrm.c
@@ -102,7 +102,6 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
102 clkfreq = devm_kzalloc(dev, sz * sizeof(*clkfreq), 102 clkfreq = devm_kzalloc(dev, sz * sizeof(*clkfreq),
103 GFP_KERNEL); 103 GFP_KERNEL);
104 if (!clkfreq) { 104 if (!clkfreq) {
105 dev_err(dev, "%s: no memory\n", "freq-table-hz");
106 ret = -ENOMEM; 105 ret = -ENOMEM;
107 goto out; 106 goto out;
108 } 107 }
@@ -112,19 +111,19 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
112 if (ret && (ret != -EINVAL)) { 111 if (ret && (ret != -EINVAL)) {
113 dev_err(dev, "%s: error reading array %d\n", 112 dev_err(dev, "%s: error reading array %d\n",
114 "freq-table-hz", ret); 113 "freq-table-hz", ret);
115 goto free_clkfreq; 114 return ret;
116 } 115 }
117 116
118 for (i = 0; i < sz; i += 2) { 117 for (i = 0; i < sz; i += 2) {
119 ret = of_property_read_string_index(np, 118 ret = of_property_read_string_index(np,
120 "clock-names", i/2, (const char **)&name); 119 "clock-names", i/2, (const char **)&name);
121 if (ret) 120 if (ret)
122 goto free_clkfreq; 121 goto out;
123 122
124 clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL); 123 clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL);
125 if (!clki) { 124 if (!clki) {
126 ret = -ENOMEM; 125 ret = -ENOMEM;
127 goto free_clkfreq; 126 goto out;
128 } 127 }
129 128
130 clki->min_freq = clkfreq[i]; 129 clki->min_freq = clkfreq[i];
@@ -134,8 +133,6 @@ static int ufshcd_parse_clock_info(struct ufs_hba *hba)
134 clki->min_freq, clki->max_freq, clki->name); 133 clki->min_freq, clki->max_freq, clki->name);
135 list_add_tail(&clki->list, &hba->clk_list_head); 134 list_add_tail(&clki->list, &hba->clk_list_head);
136 } 135 }
137free_clkfreq:
138 kfree(clkfreq);
139out: 136out:
140 return ret; 137 return ret;
141} 138}
@@ -162,10 +159,8 @@ static int ufshcd_populate_vreg(struct device *dev, const char *name,
162 } 159 }
163 160
164 vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); 161 vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL);
165 if (!vreg) { 162 if (!vreg)
166 dev_err(dev, "No memory for %s regulator\n", name); 163 return -ENOMEM;
167 goto out;
168 }
169 164
170 vreg->name = kstrdup(name, GFP_KERNEL); 165 vreg->name = kstrdup(name, GFP_KERNEL);
171 166
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 497c38a4a866..2e4614b9dddf 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -744,6 +744,8 @@ static void ufshcd_exit_clk_gating(struct ufs_hba *hba)
744 if (!ufshcd_is_clkgating_allowed(hba)) 744 if (!ufshcd_is_clkgating_allowed(hba))
745 return; 745 return;
746 device_remove_file(hba->dev, &hba->clk_gating.delay_attr); 746 device_remove_file(hba->dev, &hba->clk_gating.delay_attr);
747 cancel_work_sync(&hba->clk_gating.ungate_work);
748 cancel_delayed_work_sync(&hba->clk_gating.gate_work);
747} 749}
748 750
749/* Must be called with host lock acquired */ 751/* Must be called with host lock acquired */
@@ -2246,6 +2248,22 @@ static int ufshcd_uic_hibern8_exit(struct ufs_hba *hba)
2246 return ret; 2248 return ret;
2247} 2249}
2248 2250
2251 /**
2252 * ufshcd_init_pwr_info - setting the POR (power on reset)
2253 * values in hba power info
2254 * @hba: per-adapter instance
2255 */
2256static void ufshcd_init_pwr_info(struct ufs_hba *hba)
2257{
2258 hba->pwr_info.gear_rx = UFS_PWM_G1;
2259 hba->pwr_info.gear_tx = UFS_PWM_G1;
2260 hba->pwr_info.lane_rx = 1;
2261 hba->pwr_info.lane_tx = 1;
2262 hba->pwr_info.pwr_rx = SLOWAUTO_MODE;
2263 hba->pwr_info.pwr_tx = SLOWAUTO_MODE;
2264 hba->pwr_info.hs_rate = 0;
2265}
2266
2249/** 2267/**
2250 * ufshcd_get_max_pwr_mode - reads the max power mode negotiated with device 2268 * ufshcd_get_max_pwr_mode - reads the max power mode negotiated with device
2251 * @hba: per-adapter instance 2269 * @hba: per-adapter instance
@@ -2695,7 +2713,7 @@ static void ufshcd_set_queue_depth(struct scsi_device *sdev)
2695 2713
2696 dev_dbg(hba->dev, "%s: activate tcq with queue depth %d\n", 2714 dev_dbg(hba->dev, "%s: activate tcq with queue depth %d\n",
2697 __func__, lun_qdepth); 2715 __func__, lun_qdepth);
2698 scsi_activate_tcq(sdev, lun_qdepth); 2716 scsi_change_queue_depth(sdev, lun_qdepth);
2699} 2717}
2700 2718
2701/* 2719/*
@@ -2765,11 +2783,9 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev)
2765 struct ufs_hba *hba; 2783 struct ufs_hba *hba;
2766 2784
2767 hba = shost_priv(sdev->host); 2785 hba = shost_priv(sdev->host);
2768 sdev->tagged_supported = 1;
2769 2786
2770 /* Mode sense(6) is not supported by UFS, so use Mode sense(10) */ 2787 /* Mode sense(6) is not supported by UFS, so use Mode sense(10) */
2771 sdev->use_10_for_ms = 1; 2788 sdev->use_10_for_ms = 1;
2772 scsi_set_tag_type(sdev, MSG_SIMPLE_TAG);
2773 2789
2774 /* allow SCSI layer to restart the device in case of errors */ 2790 /* allow SCSI layer to restart the device in case of errors */
2775 sdev->allow_restart = 1; 2791 sdev->allow_restart = 1;
@@ -2789,34 +2805,16 @@ static int ufshcd_slave_alloc(struct scsi_device *sdev)
2789 * ufshcd_change_queue_depth - change queue depth 2805 * ufshcd_change_queue_depth - change queue depth
2790 * @sdev: pointer to SCSI device 2806 * @sdev: pointer to SCSI device
2791 * @depth: required depth to set 2807 * @depth: required depth to set
2792 * @reason: reason for changing the depth
2793 * 2808 *
2794 * Change queue depth according to the reason and make sure 2809 * Change queue depth and make sure the max. limits are not crossed.
2795 * the max. limits are not crossed.
2796 */ 2810 */
2797static int ufshcd_change_queue_depth(struct scsi_device *sdev, 2811static int ufshcd_change_queue_depth(struct scsi_device *sdev, int depth)
2798 int depth, int reason)
2799{ 2812{
2800 struct ufs_hba *hba = shost_priv(sdev->host); 2813 struct ufs_hba *hba = shost_priv(sdev->host);
2801 2814
2802 if (depth > hba->nutrs) 2815 if (depth > hba->nutrs)
2803 depth = hba->nutrs; 2816 depth = hba->nutrs;
2804 2817 return scsi_change_queue_depth(sdev, depth);
2805 switch (reason) {
2806 case SCSI_QDEPTH_DEFAULT:
2807 case SCSI_QDEPTH_RAMP_UP:
2808 if (!sdev->tagged_supported)
2809 depth = 1;
2810 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
2811 break;
2812 case SCSI_QDEPTH_QFULL:
2813 scsi_track_queue_full(sdev, depth);
2814 break;
2815 default:
2816 return -EOPNOTSUPP;
2817 }
2818
2819 return depth;
2820} 2818}
2821 2819
2822/** 2820/**
@@ -2842,10 +2840,14 @@ static void ufshcd_slave_destroy(struct scsi_device *sdev)
2842 struct ufs_hba *hba; 2840 struct ufs_hba *hba;
2843 2841
2844 hba = shost_priv(sdev->host); 2842 hba = shost_priv(sdev->host);
2845 scsi_deactivate_tcq(sdev, hba->nutrs);
2846 /* Drop the reference as it won't be needed anymore */ 2843 /* Drop the reference as it won't be needed anymore */
2847 if (ufshcd_scsi_to_upiu_lun(sdev->lun) == UFS_UPIU_UFS_DEVICE_WLUN) 2844 if (ufshcd_scsi_to_upiu_lun(sdev->lun) == UFS_UPIU_UFS_DEVICE_WLUN) {
2845 unsigned long flags;
2846
2847 spin_lock_irqsave(hba->host->host_lock, flags);
2848 hba->sdev_ufs_device = NULL; 2848 hba->sdev_ufs_device = NULL;
2849 spin_unlock_irqrestore(hba->host->host_lock, flags);
2850 }
2849} 2851}
2850 2852
2851/** 2853/**
@@ -4062,6 +4064,8 @@ static void ufshcd_init_icc_levels(struct ufs_hba *hba)
4062static int ufshcd_scsi_add_wlus(struct ufs_hba *hba) 4064static int ufshcd_scsi_add_wlus(struct ufs_hba *hba)
4063{ 4065{
4064 int ret = 0; 4066 int ret = 0;
4067 struct scsi_device *sdev_rpmb;
4068 struct scsi_device *sdev_boot;
4065 4069
4066 hba->sdev_ufs_device = __scsi_add_device(hba->host, 0, 0, 4070 hba->sdev_ufs_device = __scsi_add_device(hba->host, 0, 0,
4067 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_UFS_DEVICE_WLUN), NULL); 4071 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_UFS_DEVICE_WLUN), NULL);
@@ -4070,26 +4074,27 @@ static int ufshcd_scsi_add_wlus(struct ufs_hba *hba)
4070 hba->sdev_ufs_device = NULL; 4074 hba->sdev_ufs_device = NULL;
4071 goto out; 4075 goto out;
4072 } 4076 }
4077 scsi_device_put(hba->sdev_ufs_device);
4073 4078
4074 hba->sdev_boot = __scsi_add_device(hba->host, 0, 0, 4079 sdev_boot = __scsi_add_device(hba->host, 0, 0,
4075 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_BOOT_WLUN), NULL); 4080 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_BOOT_WLUN), NULL);
4076 if (IS_ERR(hba->sdev_boot)) { 4081 if (IS_ERR(sdev_boot)) {
4077 ret = PTR_ERR(hba->sdev_boot); 4082 ret = PTR_ERR(sdev_boot);
4078 hba->sdev_boot = NULL;
4079 goto remove_sdev_ufs_device; 4083 goto remove_sdev_ufs_device;
4080 } 4084 }
4085 scsi_device_put(sdev_boot);
4081 4086
4082 hba->sdev_rpmb = __scsi_add_device(hba->host, 0, 0, 4087 sdev_rpmb = __scsi_add_device(hba->host, 0, 0,
4083 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL); 4088 ufshcd_upiu_wlun_to_scsi_wlun(UFS_UPIU_RPMB_WLUN), NULL);
4084 if (IS_ERR(hba->sdev_rpmb)) { 4089 if (IS_ERR(sdev_rpmb)) {
4085 ret = PTR_ERR(hba->sdev_rpmb); 4090 ret = PTR_ERR(sdev_rpmb);
4086 hba->sdev_rpmb = NULL;
4087 goto remove_sdev_boot; 4091 goto remove_sdev_boot;
4088 } 4092 }
4093 scsi_device_put(sdev_rpmb);
4089 goto out; 4094 goto out;
4090 4095
4091remove_sdev_boot: 4096remove_sdev_boot:
4092 scsi_remove_device(hba->sdev_boot); 4097 scsi_remove_device(sdev_boot);
4093remove_sdev_ufs_device: 4098remove_sdev_ufs_device:
4094 scsi_remove_device(hba->sdev_ufs_device); 4099 scsi_remove_device(hba->sdev_ufs_device);
4095out: 4100out:
@@ -4097,30 +4102,6 @@ out:
4097} 4102}
4098 4103
4099/** 4104/**
4100 * ufshcd_scsi_remove_wlus - Removes the W-LUs which were added by
4101 * ufshcd_scsi_add_wlus()
4102 * @hba: per-adapter instance
4103 *
4104 */
4105static void ufshcd_scsi_remove_wlus(struct ufs_hba *hba)
4106{
4107 if (hba->sdev_ufs_device) {
4108 scsi_remove_device(hba->sdev_ufs_device);
4109 hba->sdev_ufs_device = NULL;
4110 }
4111
4112 if (hba->sdev_boot) {
4113 scsi_remove_device(hba->sdev_boot);
4114 hba->sdev_boot = NULL;
4115 }
4116
4117 if (hba->sdev_rpmb) {
4118 scsi_remove_device(hba->sdev_rpmb);
4119 hba->sdev_rpmb = NULL;
4120 }
4121}
4122
4123/**
4124 * ufshcd_probe_hba - probe hba to detect device and initialize 4105 * ufshcd_probe_hba - probe hba to detect device and initialize
4125 * @hba: per-adapter instance 4106 * @hba: per-adapter instance
4126 * 4107 *
@@ -4134,6 +4115,8 @@ static int ufshcd_probe_hba(struct ufs_hba *hba)
4134 if (ret) 4115 if (ret)
4135 goto out; 4116 goto out;
4136 4117
4118 ufshcd_init_pwr_info(hba);
4119
4137 /* UniPro link is active now */ 4120 /* UniPro link is active now */
4138 ufshcd_set_link_active(hba); 4121 ufshcd_set_link_active(hba);
4139 4122
@@ -4235,6 +4218,8 @@ static struct scsi_host_template ufshcd_driver_template = {
4235 .cmd_per_lun = UFSHCD_CMD_PER_LUN, 4218 .cmd_per_lun = UFSHCD_CMD_PER_LUN,
4236 .can_queue = UFSHCD_CAN_QUEUE, 4219 .can_queue = UFSHCD_CAN_QUEUE,
4237 .max_host_blocked = 1, 4220 .max_host_blocked = 1,
4221 .use_blk_tags = 1,
4222 .track_queue_depth = 1,
4238}; 4223};
4239 4224
4240static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg, 4225static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
@@ -4264,12 +4249,18 @@ static int ufshcd_config_vreg_load(struct device *dev, struct ufs_vreg *vreg,
4264static inline int ufshcd_config_vreg_lpm(struct ufs_hba *hba, 4249static inline int ufshcd_config_vreg_lpm(struct ufs_hba *hba,
4265 struct ufs_vreg *vreg) 4250 struct ufs_vreg *vreg)
4266{ 4251{
4252 if (!vreg)
4253 return 0;
4254
4267 return ufshcd_config_vreg_load(hba->dev, vreg, UFS_VREG_LPM_LOAD_UA); 4255 return ufshcd_config_vreg_load(hba->dev, vreg, UFS_VREG_LPM_LOAD_UA);
4268} 4256}
4269 4257
4270static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba, 4258static inline int ufshcd_config_vreg_hpm(struct ufs_hba *hba,
4271 struct ufs_vreg *vreg) 4259 struct ufs_vreg *vreg)
4272{ 4260{
4261 if (!vreg)
4262 return 0;
4263
4273 return ufshcd_config_vreg_load(hba->dev, vreg, vreg->max_uA); 4264 return ufshcd_config_vreg_load(hba->dev, vreg, vreg->max_uA);
4274} 4265}
4275 4266
@@ -4471,7 +4462,7 @@ out:
4471 if (!IS_ERR_OR_NULL(clki->clk) && clki->enabled) 4462 if (!IS_ERR_OR_NULL(clki->clk) && clki->enabled)
4472 clk_disable_unprepare(clki->clk); 4463 clk_disable_unprepare(clki->clk);
4473 } 4464 }
4474 } else if (!ret && on) { 4465 } else if (on) {
4475 spin_lock_irqsave(hba->host->host_lock, flags); 4466 spin_lock_irqsave(hba->host->host_lock, flags);
4476 hba->clk_gating.state = CLKS_ON; 4467 hba->clk_gating.state = CLKS_ON;
4477 spin_unlock_irqrestore(hba->host->host_lock, flags); 4468 spin_unlock_irqrestore(hba->host->host_lock, flags);
@@ -4675,11 +4666,25 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
4675{ 4666{
4676 unsigned char cmd[6] = { START_STOP }; 4667 unsigned char cmd[6] = { START_STOP };
4677 struct scsi_sense_hdr sshdr; 4668 struct scsi_sense_hdr sshdr;
4678 struct scsi_device *sdp = hba->sdev_ufs_device; 4669 struct scsi_device *sdp;
4670 unsigned long flags;
4679 int ret; 4671 int ret;
4680 4672
4681 if (!sdp || !scsi_device_online(sdp)) 4673 spin_lock_irqsave(hba->host->host_lock, flags);
4682 return -ENODEV; 4674 sdp = hba->sdev_ufs_device;
4675 if (sdp) {
4676 ret = scsi_device_get(sdp);
4677 if (!ret && !scsi_device_online(sdp)) {
4678 ret = -ENODEV;
4679 scsi_device_put(sdp);
4680 }
4681 } else {
4682 ret = -ENODEV;
4683 }
4684 spin_unlock_irqrestore(hba->host->host_lock, flags);
4685
4686 if (ret)
4687 return ret;
4683 4688
4684 /* 4689 /*
4685 * If scsi commands fail, the scsi mid-layer schedules scsi error- 4690 * If scsi commands fail, the scsi mid-layer schedules scsi error-
@@ -4707,17 +4712,18 @@ static int ufshcd_set_dev_pwr_mode(struct ufs_hba *hba,
4707 START_STOP_TIMEOUT, 0, NULL, REQ_PM); 4712 START_STOP_TIMEOUT, 0, NULL, REQ_PM);
4708 if (ret) { 4713 if (ret) {
4709 sdev_printk(KERN_WARNING, sdp, 4714 sdev_printk(KERN_WARNING, sdp,
4710 "START_STOP failed for power mode: %d\n", pwr_mode); 4715 "START_STOP failed for power mode: %d, result %x\n",
4711 scsi_show_result(ret); 4716 pwr_mode, ret);
4712 if (driver_byte(ret) & DRIVER_SENSE) { 4717 if (driver_byte(ret) & DRIVER_SENSE) {
4713 scsi_show_sense_hdr(&sshdr); 4718 scsi_show_sense_hdr(sdp, NULL, &sshdr);
4714 scsi_show_extd_sense(sshdr.asc, sshdr.ascq); 4719 scsi_show_extd_sense(sdp, NULL, sshdr.asc, sshdr.ascq);
4715 } 4720 }
4716 } 4721 }
4717 4722
4718 if (!ret) 4723 if (!ret)
4719 hba->curr_dev_pwr_mode = pwr_mode; 4724 hba->curr_dev_pwr_mode = pwr_mode;
4720out: 4725out:
4726 scsi_device_put(sdp);
4721 hba->host->eh_noresume = 0; 4727 hba->host->eh_noresume = 0;
4722 return ret; 4728 return ret;
4723} 4729}
@@ -5087,7 +5093,7 @@ int ufshcd_system_suspend(struct ufs_hba *hba)
5087 int ret = 0; 5093 int ret = 0;
5088 5094
5089 if (!hba || !hba->is_powered) 5095 if (!hba || !hba->is_powered)
5090 goto out; 5096 return 0;
5091 5097
5092 if (pm_runtime_suspended(hba->dev)) { 5098 if (pm_runtime_suspended(hba->dev)) {
5093 if (hba->rpm_lvl == hba->spm_lvl) 5099 if (hba->rpm_lvl == hba->spm_lvl)
@@ -5231,7 +5237,6 @@ EXPORT_SYMBOL(ufshcd_shutdown);
5231void ufshcd_remove(struct ufs_hba *hba) 5237void ufshcd_remove(struct ufs_hba *hba)
5232{ 5238{
5233 scsi_remove_host(hba->host); 5239 scsi_remove_host(hba->host);
5234 ufshcd_scsi_remove_wlus(hba);
5235 /* disable interrupts */ 5240 /* disable interrupts */
5236 ufshcd_disable_intr(hba, hba->intr_mask); 5241 ufshcd_disable_intr(hba, hba->intr_mask);
5237 ufshcd_hba_stop(hba); 5242 ufshcd_hba_stop(hba);
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 58ecdff5065c..4a574aa45855 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -392,8 +392,6 @@ struct ufs_hba {
392 * "UFS device" W-LU. 392 * "UFS device" W-LU.
393 */ 393 */
394 struct scsi_device *sdev_ufs_device; 394 struct scsi_device *sdev_ufs_device;
395 struct scsi_device *sdev_rpmb;
396 struct scsi_device *sdev_boot;
397 395
398 enum ufs_dev_pwr_mode curr_dev_pwr_mode; 396 enum ufs_dev_pwr_mode curr_dev_pwr_mode;
399 enum uic_link_state uic_link_state; 397 enum uic_link_state uic_link_state;
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index b83846fc7859..22e70126425b 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -561,6 +561,15 @@ static int virtscsi_queuecommand_single(struct Scsi_Host *sh,
561 return virtscsi_queuecommand(vscsi, &vscsi->req_vqs[0], sc); 561 return virtscsi_queuecommand(vscsi, &vscsi->req_vqs[0], sc);
562} 562}
563 563
564static struct virtio_scsi_vq *virtscsi_pick_vq_mq(struct virtio_scsi *vscsi,
565 struct scsi_cmnd *sc)
566{
567 u32 tag = blk_mq_unique_tag(sc->request);
568 u16 hwq = blk_mq_unique_tag_to_hwq(tag);
569
570 return &vscsi->req_vqs[hwq];
571}
572
564static struct virtio_scsi_vq *virtscsi_pick_vq(struct virtio_scsi *vscsi, 573static struct virtio_scsi_vq *virtscsi_pick_vq(struct virtio_scsi *vscsi,
565 struct virtio_scsi_target_state *tgt) 574 struct virtio_scsi_target_state *tgt)
566{ 575{
@@ -604,7 +613,12 @@ static int virtscsi_queuecommand_multi(struct Scsi_Host *sh,
604 struct virtio_scsi *vscsi = shost_priv(sh); 613 struct virtio_scsi *vscsi = shost_priv(sh);
605 struct virtio_scsi_target_state *tgt = 614 struct virtio_scsi_target_state *tgt =
606 scsi_target(sc->device)->hostdata; 615 scsi_target(sc->device)->hostdata;
607 struct virtio_scsi_vq *req_vq = virtscsi_pick_vq(vscsi, tgt); 616 struct virtio_scsi_vq *req_vq;
617
618 if (shost_use_blk_mq(sh))
619 req_vq = virtscsi_pick_vq_mq(vscsi, sc);
620 else
621 req_vq = virtscsi_pick_vq(vscsi, tgt);
608 622
609 return virtscsi_queuecommand(vscsi, req_vq, sc); 623 return virtscsi_queuecommand(vscsi, req_vq, sc);
610} 624}
@@ -668,30 +682,13 @@ static int virtscsi_device_reset(struct scsi_cmnd *sc)
668 * virtscsi_change_queue_depth() - Change a virtscsi target's queue depth 682 * virtscsi_change_queue_depth() - Change a virtscsi target's queue depth
669 * @sdev: Virtscsi target whose queue depth to change 683 * @sdev: Virtscsi target whose queue depth to change
670 * @qdepth: New queue depth 684 * @qdepth: New queue depth
671 * @reason: Reason for the queue depth change.
672 */ 685 */
673static int virtscsi_change_queue_depth(struct scsi_device *sdev, 686static int virtscsi_change_queue_depth(struct scsi_device *sdev, int qdepth)
674 int qdepth,
675 int reason)
676{ 687{
677 struct Scsi_Host *shost = sdev->host; 688 struct Scsi_Host *shost = sdev->host;
678 int max_depth = shost->cmd_per_lun; 689 int max_depth = shost->cmd_per_lun;
679 690
680 switch (reason) { 691 return scsi_change_queue_depth(sdev, min(max_depth, qdepth));
681 case SCSI_QDEPTH_QFULL: /* Drop qdepth in response to BUSY state */
682 scsi_track_queue_full(sdev, qdepth);
683 break;
684 case SCSI_QDEPTH_RAMP_UP: /* Raise qdepth after BUSY state resolved */
685 case SCSI_QDEPTH_DEFAULT: /* Manual change via sysfs */
686 scsi_adjust_queue_depth(sdev,
687 scsi_get_tag_type(sdev),
688 min(max_depth, qdepth));
689 break;
690 default:
691 return -EOPNOTSUPP;
692 }
693
694 return sdev->queue_depth;
695} 692}
696 693
697static int virtscsi_abort(struct scsi_cmnd *sc) 694static int virtscsi_abort(struct scsi_cmnd *sc)
@@ -758,6 +755,7 @@ static struct scsi_host_template virtscsi_host_template_single = {
758 .use_clustering = ENABLE_CLUSTERING, 755 .use_clustering = ENABLE_CLUSTERING,
759 .target_alloc = virtscsi_target_alloc, 756 .target_alloc = virtscsi_target_alloc,
760 .target_destroy = virtscsi_target_destroy, 757 .target_destroy = virtscsi_target_destroy,
758 .track_queue_depth = 1,
761}; 759};
762 760
763static struct scsi_host_template virtscsi_host_template_multi = { 761static struct scsi_host_template virtscsi_host_template_multi = {
@@ -776,6 +774,7 @@ static struct scsi_host_template virtscsi_host_template_multi = {
776 .use_clustering = ENABLE_CLUSTERING, 774 .use_clustering = ENABLE_CLUSTERING,
777 .target_alloc = virtscsi_target_alloc, 775 .target_alloc = virtscsi_target_alloc,
778 .target_destroy = virtscsi_target_destroy, 776 .target_destroy = virtscsi_target_destroy,
777 .track_queue_depth = 1,
779}; 778};
780 779
781#define virtscsi_config_get(vdev, fld) \ 780#define virtscsi_config_get(vdev, fld) \
@@ -983,6 +982,7 @@ static int virtscsi_probe(struct virtio_device *vdev)
983 shost->max_id = num_targets; 982 shost->max_id = num_targets;
984 shost->max_channel = 0; 983 shost->max_channel = 0;
985 shost->max_cmd_len = VIRTIO_SCSI_CDB_SIZE; 984 shost->max_cmd_len = VIRTIO_SCSI_CDB_SIZE;
985 shost->nr_hw_queues = num_queues;
986 986
987 if (virtio_has_feature(vdev, VIRTIO_SCSI_F_T10_PI)) { 987 if (virtio_has_feature(vdev, VIRTIO_SCSI_F_T10_PI)) {
988 host_prot = SHOST_DIF_TYPE1_PROTECTION | SHOST_DIF_TYPE2_PROTECTION | 988 host_prot = SHOST_DIF_TYPE1_PROTECTION | SHOST_DIF_TYPE2_PROTECTION |
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index 598f65efaaec..0f133c1817de 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -504,33 +504,11 @@ static void pvscsi_setup_all_rings(const struct pvscsi_adapter *adapter)
504 } 504 }
505} 505}
506 506
507static int pvscsi_change_queue_depth(struct scsi_device *sdev, 507static int pvscsi_change_queue_depth(struct scsi_device *sdev, int qdepth)
508 int qdepth,
509 int reason)
510{ 508{
511 int max_depth;
512 struct Scsi_Host *shost = sdev->host;
513
514 if (reason != SCSI_QDEPTH_DEFAULT)
515 /*
516 * We support only changing default.
517 */
518 return -EOPNOTSUPP;
519
520 max_depth = shost->can_queue;
521 if (!sdev->tagged_supported) 509 if (!sdev->tagged_supported)
522 max_depth = 1; 510 qdepth = 1;
523 if (qdepth > max_depth) 511 return scsi_change_queue_depth(sdev, qdepth);
524 qdepth = max_depth;
525 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
526
527 if (sdev->inquiry_len > 7)
528 sdev_printk(KERN_INFO, sdev,
529 "qdepth(%d), tagged(%d), simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
530 sdev->queue_depth, sdev->tagged_supported,
531 sdev->simple_tags, sdev->ordered_tags,
532 sdev->scsi_level, (sdev->inquiry[7] & 2) >> 1);
533 return sdev->queue_depth;
534} 512}
535 513
536/* 514/*
@@ -723,10 +701,6 @@ static int pvscsi_queue_ring(struct pvscsi_adapter *adapter,
723 memcpy(e->cdb, cmd->cmnd, e->cdbLen); 701 memcpy(e->cdb, cmd->cmnd, e->cdbLen);
724 702
725 e->tag = SIMPLE_QUEUE_TAG; 703 e->tag = SIMPLE_QUEUE_TAG;
726 if (sdev->tagged_supported &&
727 (cmd->tag == HEAD_OF_QUEUE_TAG ||
728 cmd->tag == ORDERED_QUEUE_TAG))
729 e->tag = cmd->tag;
730 704
731 if (cmd->sc_data_direction == DMA_FROM_DEVICE) 705 if (cmd->sc_data_direction == DMA_FROM_DEVICE)
732 e->flags = PVSCSI_FLAG_CMD_DIR_TOHOST; 706 e->flags = PVSCSI_FLAG_CMD_DIR_TOHOST;
diff --git a/drivers/scsi/wd7000.c b/drivers/scsi/wd7000.c
index 32674236fec7..f94d73611ab4 100644
--- a/drivers/scsi/wd7000.c
+++ b/drivers/scsi/wd7000.c
@@ -1653,7 +1653,6 @@ static struct scsi_host_template driver_template = {
1653 .can_queue = WD7000_Q, 1653 .can_queue = WD7000_Q,
1654 .this_id = 7, 1654 .this_id = 7,
1655 .sg_tablesize = WD7000_SG, 1655 .sg_tablesize = WD7000_SG,
1656 .cmd_per_lun = 1,
1657 .unchecked_isa_dma = 1, 1656 .unchecked_isa_dma = 1,
1658 .use_clustering = ENABLE_CLUSTERING, 1657 .use_clustering = ENABLE_CLUSTERING,
1659}; 1658};
diff --git a/drivers/scsi/wd719x.c b/drivers/scsi/wd719x.c
new file mode 100644
index 000000000000..7702664d7ed3
--- /dev/null
+++ b/drivers/scsi/wd719x.c
@@ -0,0 +1,996 @@
1/*
2 * Driver for Western Digital WD7193, WD7197 and WD7296 SCSI cards
3 * Copyright 2013 Ondrej Zary
4 *
5 * Original driver by
6 * Aaron Dewell <dewell@woods.net>
7 * Gaerti <Juergen.Gaertner@mbox.si.uni-hannover.de>
8 *
9 * HW documentation available in book:
10 *
11 * SPIDER Command Protocol
12 * by Chandru M. Sippy
13 * SCSI Storage Products (MCP)
14 * Western Digital Corporation
15 * 09-15-95
16 *
17 * http://web.archive.org/web/20070717175254/http://sun1.rrzn.uni-hannover.de/gaertner.juergen/wd719x/Linux/Docu/Spider/
18 */
19
20/*
21 * Driver workflow:
22 * 1. SCSI command is transformed to SCB (Spider Control Block) by the
23 * queuecommand function.
24 * 2. The address of the SCB is stored in a list to be able to access it, if
25 * something goes wrong.
26 * 3. The address of the SCB is written to the Controller, which loads the SCB
27 * via BM-DMA and processes it.
28 * 4. After it has finished, it generates an interrupt, and sets registers.
29 *
30 * flaws:
31 * - abort/reset functions
32 *
33 * ToDo:
34 * - tagged queueing
35 */
36
37#include <linux/interrupt.h>
38#include <linux/module.h>
39#include <linux/delay.h>
40#include <linux/pci.h>
41#include <linux/firmware.h>
42#include <linux/eeprom_93cx6.h>
43#include <scsi/scsi_cmnd.h>
44#include <scsi/scsi_device.h>
45#include <scsi/scsi_host.h>
46#include "wd719x.h"
47
48/* low-level register access */
49static inline u8 wd719x_readb(struct wd719x *wd, u8 reg)
50{
51 return ioread8(wd->base + reg);
52}
53
54static inline u32 wd719x_readl(struct wd719x *wd, u8 reg)
55{
56 return ioread32(wd->base + reg);
57}
58
59static inline void wd719x_writeb(struct wd719x *wd, u8 reg, u8 val)
60{
61 iowrite8(val, wd->base + reg);
62}
63
64static inline void wd719x_writew(struct wd719x *wd, u8 reg, u16 val)
65{
66 iowrite16(val, wd->base + reg);
67}
68
69static inline void wd719x_writel(struct wd719x *wd, u8 reg, u32 val)
70{
71 iowrite32(val, wd->base + reg);
72}
73
74/* wait until the command register is ready */
75static inline int wd719x_wait_ready(struct wd719x *wd)
76{
77 int i = 0;
78
79 do {
80 if (wd719x_readb(wd, WD719X_AMR_COMMAND) == WD719X_CMD_READY)
81 return 0;
82 udelay(1);
83 } while (i++ < WD719X_WAIT_FOR_CMD_READY);
84
85 dev_err(&wd->pdev->dev, "command register is not ready: 0x%02x\n",
86 wd719x_readb(wd, WD719X_AMR_COMMAND));
87
88 return -ETIMEDOUT;
89}
90
91/* poll interrupt status register until command finishes */
92static inline int wd719x_wait_done(struct wd719x *wd, int timeout)
93{
94 u8 status;
95
96 while (timeout > 0) {
97 status = wd719x_readb(wd, WD719X_AMR_INT_STATUS);
98 if (status)
99 break;
100 timeout--;
101 udelay(1);
102 }
103
104 if (timeout <= 0) {
105 dev_err(&wd->pdev->dev, "direct command timed out\n");
106 return -ETIMEDOUT;
107 }
108
109 if (status != WD719X_INT_NOERRORS) {
110 dev_err(&wd->pdev->dev, "direct command failed, status 0x%02x, SUE 0x%02x\n",
111 status, wd719x_readb(wd, WD719X_AMR_SCB_ERROR));
112 return -EIO;
113 }
114
115 return 0;
116}
117
118static int wd719x_direct_cmd(struct wd719x *wd, u8 opcode, u8 dev, u8 lun,
119 u8 tag, dma_addr_t data, int timeout)
120{
121 int ret = 0;
122
123 /* clear interrupt status register (allow command register to clear) */
124 wd719x_writeb(wd, WD719X_AMR_INT_STATUS, WD719X_INT_NONE);
125
126 /* Wait for the Command register to become free */
127 if (wd719x_wait_ready(wd))
128 return -ETIMEDOUT;
129
130 /* make sure we get NO interrupts */
131 dev |= WD719X_DISABLE_INT;
132 wd719x_writeb(wd, WD719X_AMR_CMD_PARAM, dev);
133 wd719x_writeb(wd, WD719X_AMR_CMD_PARAM_2, lun);
134 wd719x_writeb(wd, WD719X_AMR_CMD_PARAM_3, tag);
135 if (data)
136 wd719x_writel(wd, WD719X_AMR_SCB_IN, data);
137
138 /* clear interrupt status register again */
139 wd719x_writeb(wd, WD719X_AMR_INT_STATUS, WD719X_INT_NONE);
140
141 /* Now, write the command */
142 wd719x_writeb(wd, WD719X_AMR_COMMAND, opcode);
143
144 if (timeout) /* wait for the command to complete */
145 ret = wd719x_wait_done(wd, timeout);
146
147 /* clear interrupt status register (clean up) */
148 if (opcode != WD719X_CMD_READ_FIRMVER)
149 wd719x_writeb(wd, WD719X_AMR_INT_STATUS, WD719X_INT_NONE);
150
151 return ret;
152}
153
154static void wd719x_destroy(struct wd719x *wd)
155{
156 struct wd719x_scb *scb;
157
158 /* stop the RISC */
159 if (wd719x_direct_cmd(wd, WD719X_CMD_SLEEP, 0, 0, 0, 0,
160 WD719X_WAIT_FOR_RISC))
161 dev_warn(&wd->pdev->dev, "RISC sleep command failed\n");
162 /* disable RISC */
163 wd719x_writeb(wd, WD719X_PCI_MODE_SELECT, 0);
164
165 /* free all SCBs */
166 list_for_each_entry(scb, &wd->active_scbs, list)
167 pci_free_consistent(wd->pdev, sizeof(struct wd719x_scb), scb,
168 scb->phys);
169 list_for_each_entry(scb, &wd->free_scbs, list)
170 pci_free_consistent(wd->pdev, sizeof(struct wd719x_scb), scb,
171 scb->phys);
172 /* free internal buffers */
173 pci_free_consistent(wd->pdev, wd->fw_size, wd->fw_virt, wd->fw_phys);
174 wd->fw_virt = NULL;
175 pci_free_consistent(wd->pdev, WD719X_HASH_TABLE_SIZE, wd->hash_virt,
176 wd->hash_phys);
177 wd->hash_virt = NULL;
178 pci_free_consistent(wd->pdev, sizeof(struct wd719x_host_param),
179 wd->params, wd->params_phys);
180 wd->params = NULL;
181 free_irq(wd->pdev->irq, wd);
182}
183
184/* finish a SCSI command, mark SCB (if any) as free, unmap buffers */
185static void wd719x_finish_cmd(struct scsi_cmnd *cmd, int result)
186{
187 struct wd719x *wd = shost_priv(cmd->device->host);
188 struct wd719x_scb *scb = (struct wd719x_scb *) cmd->host_scribble;
189
190 if (scb) {
191 list_move(&scb->list, &wd->free_scbs);
192 dma_unmap_single(&wd->pdev->dev, cmd->SCp.dma_handle,
193 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
194 scsi_dma_unmap(cmd);
195 }
196 cmd->result = result << 16;
197 cmd->scsi_done(cmd);
198}
199
200/* Build a SCB and send it to the card */
201static int wd719x_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *cmd)
202{
203 int i, count_sg;
204 unsigned long flags;
205 struct wd719x_scb *scb;
206 struct wd719x *wd = shost_priv(sh);
207 dma_addr_t phys;
208
209 cmd->host_scribble = NULL;
210
211 /* get a free SCB - either from existing ones or allocate a new one */
212 spin_lock_irqsave(wd->sh->host_lock, flags);
213 scb = list_first_entry_or_null(&wd->free_scbs, struct wd719x_scb, list);
214 if (scb) {
215 list_del(&scb->list);
216 phys = scb->phys;
217 } else {
218 spin_unlock_irqrestore(wd->sh->host_lock, flags);
219 scb = pci_alloc_consistent(wd->pdev, sizeof(struct wd719x_scb),
220 &phys);
221 spin_lock_irqsave(wd->sh->host_lock, flags);
222 if (!scb) {
223 dev_err(&wd->pdev->dev, "unable to allocate SCB\n");
224 wd719x_finish_cmd(cmd, DID_ERROR);
225 spin_unlock_irqrestore(wd->sh->host_lock, flags);
226 return 0;
227 }
228 }
229 memset(scb, 0, sizeof(struct wd719x_scb));
230 list_add(&scb->list, &wd->active_scbs);
231
232 scb->phys = phys;
233 scb->cmd = cmd;
234 cmd->host_scribble = (char *) scb;
235
236 scb->CDB_tag = 0; /* Tagged queueing not supported yet */
237 scb->devid = cmd->device->id;
238 scb->lun = cmd->device->lun;
239
240 /* copy the command */
241 memcpy(scb->CDB, cmd->cmnd, cmd->cmd_len);
242
243 /* map sense buffer */
244 scb->sense_buf_length = SCSI_SENSE_BUFFERSIZE;
245 cmd->SCp.dma_handle = dma_map_single(&wd->pdev->dev, cmd->sense_buffer,
246 SCSI_SENSE_BUFFERSIZE, DMA_FROM_DEVICE);
247 scb->sense_buf = cpu_to_le32(cmd->SCp.dma_handle);
248
249 /* request autosense */
250 scb->SCB_options |= WD719X_SCB_FLAGS_AUTO_REQUEST_SENSE;
251
252 /* check direction */
253 if (cmd->sc_data_direction == DMA_TO_DEVICE)
254 scb->SCB_options |= WD719X_SCB_FLAGS_CHECK_DIRECTION
255 | WD719X_SCB_FLAGS_PCI_TO_SCSI;
256 else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
257 scb->SCB_options |= WD719X_SCB_FLAGS_CHECK_DIRECTION;
258
259 /* Scather/gather */
260 count_sg = scsi_dma_map(cmd);
261 if (count_sg < 0) {
262 wd719x_finish_cmd(cmd, DID_ERROR);
263 spin_unlock_irqrestore(wd->sh->host_lock, flags);
264 return 0;
265 }
266 BUG_ON(count_sg > WD719X_SG);
267
268 if (count_sg) {
269 struct scatterlist *sg;
270
271 scb->data_length = cpu_to_le32(count_sg *
272 sizeof(struct wd719x_sglist));
273 scb->data_p = cpu_to_le32(scb->phys +
274 offsetof(struct wd719x_scb, sg_list));
275
276 scsi_for_each_sg(cmd, sg, count_sg, i) {
277 scb->sg_list[i].ptr = cpu_to_le32(sg_dma_address(sg));
278 scb->sg_list[i].length = cpu_to_le32(sg_dma_len(sg));
279 }
280 scb->SCB_options |= WD719X_SCB_FLAGS_DO_SCATTER_GATHER;
281 } else { /* zero length */
282 scb->data_length = 0;
283 scb->data_p = 0;
284 }
285
286 /* check if the Command register is free */
287 if (wd719x_readb(wd, WD719X_AMR_COMMAND) != WD719X_CMD_READY) {
288 spin_unlock_irqrestore(wd->sh->host_lock, flags);
289 return SCSI_MLQUEUE_HOST_BUSY;
290 }
291
292 /* write pointer to the AMR */
293 wd719x_writel(wd, WD719X_AMR_SCB_IN, scb->phys);
294 /* send SCB opcode */
295 wd719x_writeb(wd, WD719X_AMR_COMMAND, WD719X_CMD_PROCESS_SCB);
296
297 spin_unlock_irqrestore(wd->sh->host_lock, flags);
298
299 return 0;
300}
301
302static int wd719x_chip_init(struct wd719x *wd)
303{
304 int i, ret;
305 u32 risc_init[3];
306 const struct firmware *fw_wcs, *fw_risc;
307 const char fwname_wcs[] = "wd719x-wcs.bin";
308 const char fwname_risc[] = "wd719x-risc.bin";
309
310 memset(wd->hash_virt, 0, WD719X_HASH_TABLE_SIZE);
311
312 /* WCS (sequencer) firmware */
313 ret = request_firmware(&fw_wcs, fwname_wcs, &wd->pdev->dev);
314 if (ret) {
315 dev_err(&wd->pdev->dev, "Unable to load firmware %s: %d\n",
316 fwname_wcs, ret);
317 return ret;
318 }
319 /* RISC firmware */
320 ret = request_firmware(&fw_risc, fwname_risc, &wd->pdev->dev);
321 if (ret) {
322 dev_err(&wd->pdev->dev, "Unable to load firmware %s: %d\n",
323 fwname_risc, ret);
324 release_firmware(fw_wcs);
325 return ret;
326 }
327 wd->fw_size = ALIGN(fw_wcs->size, 4) + fw_risc->size;
328
329 if (!wd->fw_virt)
330 wd->fw_virt = pci_alloc_consistent(wd->pdev, wd->fw_size,
331 &wd->fw_phys);
332 if (!wd->fw_virt) {
333 ret = -ENOMEM;
334 goto wd719x_init_end;
335 }
336
337 /* make a fresh copy of WCS and RISC code */
338 memcpy(wd->fw_virt, fw_wcs->data, fw_wcs->size);
339 memcpy(wd->fw_virt + ALIGN(fw_wcs->size, 4), fw_risc->data,
340 fw_risc->size);
341
342 /* Reset the Spider Chip and adapter itself */
343 wd719x_writeb(wd, WD719X_PCI_PORT_RESET, WD719X_PCI_RESET);
344 udelay(WD719X_WAIT_FOR_RISC);
345 /* Clear PIO mode bits set by BIOS */
346 wd719x_writeb(wd, WD719X_AMR_CMD_PARAM, 0);
347 /* ensure RISC is not running */
348 wd719x_writeb(wd, WD719X_PCI_MODE_SELECT, 0);
349 /* ensure command port is ready */
350 wd719x_writeb(wd, WD719X_AMR_COMMAND, 0);
351 if (wd719x_wait_ready(wd)) {
352 ret = -ETIMEDOUT;
353 goto wd719x_init_end;
354 }
355
356 /* Transfer the first 2K words of RISC code to kick start the uP */
357 risc_init[0] = wd->fw_phys; /* WCS FW */
358 risc_init[1] = wd->fw_phys + ALIGN(fw_wcs->size, 4); /* RISC FW */
359 risc_init[2] = wd->hash_phys; /* hash table */
360
361 /* clear DMA status */
362 wd719x_writeb(wd, WD719X_PCI_CHANNEL2_3STATUS, 0);
363
364 /* address to read firmware from */
365 wd719x_writel(wd, WD719X_PCI_EXTERNAL_ADDR, risc_init[1]);
366 /* base address to write firmware to (on card) */
367 wd719x_writew(wd, WD719X_PCI_INTERNAL_ADDR, WD719X_PRAM_BASE_ADDR);
368 /* size: first 2K words */
369 wd719x_writew(wd, WD719X_PCI_DMA_TRANSFER_SIZE, 2048 * 2);
370 /* start DMA */
371 wd719x_writeb(wd, WD719X_PCI_CHANNEL2_3CMD, WD719X_START_CHANNEL2_3DMA);
372
373 /* wait for DMA to complete */
374 i = WD719X_WAIT_FOR_RISC;
375 while (i-- > 0) {
376 u8 status = wd719x_readb(wd, WD719X_PCI_CHANNEL2_3STATUS);
377 if (status == WD719X_START_CHANNEL2_3DONE)
378 break;
379 if (status == WD719X_START_CHANNEL2_3ABORT) {
380 dev_warn(&wd->pdev->dev, "RISC bootstrap failed: DMA aborted\n");
381 ret = -EIO;
382 goto wd719x_init_end;
383 }
384 udelay(1);
385 }
386 if (i < 1) {
387 dev_warn(&wd->pdev->dev, "RISC bootstrap failed: DMA timeout\n");
388 ret = -ETIMEDOUT;
389 goto wd719x_init_end;
390 }
391
392 /* firmware is loaded, now initialize and wake up the RISC */
393 /* write RISC initialization long words to Spider */
394 wd719x_writel(wd, WD719X_AMR_SCB_IN, risc_init[0]);
395 wd719x_writel(wd, WD719X_AMR_SCB_IN + 4, risc_init[1]);
396 wd719x_writel(wd, WD719X_AMR_SCB_IN + 8, risc_init[2]);
397
398 /* disable interrupts during initialization of RISC */
399 wd719x_writeb(wd, WD719X_AMR_CMD_PARAM, WD719X_DISABLE_INT);
400
401 /* issue INITIALIZE RISC comand */
402 wd719x_writeb(wd, WD719X_AMR_COMMAND, WD719X_CMD_INIT_RISC);
403 /* enable advanced mode (wake up RISC) */
404 wd719x_writeb(wd, WD719X_PCI_MODE_SELECT, WD719X_ENABLE_ADVANCE_MODE);
405 udelay(WD719X_WAIT_FOR_RISC);
406
407 ret = wd719x_wait_done(wd, WD719X_WAIT_FOR_RISC);
408 /* clear interrupt status register */
409 wd719x_writeb(wd, WD719X_AMR_INT_STATUS, WD719X_INT_NONE);
410 if (ret) {
411 dev_warn(&wd->pdev->dev, "Unable to initialize RISC\n");
412 goto wd719x_init_end;
413 }
414 /* RISC is up and running */
415
416 /* Read FW version from RISC */
417 ret = wd719x_direct_cmd(wd, WD719X_CMD_READ_FIRMVER, 0, 0, 0, 0,
418 WD719X_WAIT_FOR_RISC);
419 if (ret) {
420 dev_warn(&wd->pdev->dev, "Unable to read firmware version\n");
421 goto wd719x_init_end;
422 }
423 dev_info(&wd->pdev->dev, "RISC initialized with firmware version %.2x.%.2x\n",
424 wd719x_readb(wd, WD719X_AMR_SCB_OUT + 1),
425 wd719x_readb(wd, WD719X_AMR_SCB_OUT));
426
427 /* RESET SCSI bus */
428 ret = wd719x_direct_cmd(wd, WD719X_CMD_BUSRESET, 0, 0, 0, 0,
429 WD719X_WAIT_FOR_SCSI_RESET);
430 if (ret) {
431 dev_warn(&wd->pdev->dev, "SCSI bus reset failed\n");
432 goto wd719x_init_end;
433 }
434
435 /* use HostParameter structure to set Spider's Host Parameter Block */
436 ret = wd719x_direct_cmd(wd, WD719X_CMD_SET_PARAM, 0,
437 sizeof(struct wd719x_host_param), 0,
438 wd->params_phys, WD719X_WAIT_FOR_RISC);
439 if (ret) {
440 dev_warn(&wd->pdev->dev, "Failed to set HOST PARAMETERS\n");
441 goto wd719x_init_end;
442 }
443
444 /* initiate SCAM (does nothing if disabled in BIOS) */
445 /* bug?: we should pass a mask of static IDs which we don't have */
446 ret = wd719x_direct_cmd(wd, WD719X_CMD_INIT_SCAM, 0, 0, 0, 0,
447 WD719X_WAIT_FOR_SCSI_RESET);
448 if (ret) {
449 dev_warn(&wd->pdev->dev, "SCAM initialization failed\n");
450 goto wd719x_init_end;
451 }
452
453 /* clear AMR_BIOS_SHARE_INT register */
454 wd719x_writeb(wd, WD719X_AMR_BIOS_SHARE_INT, 0);
455
456wd719x_init_end:
457 release_firmware(fw_wcs);
458 release_firmware(fw_risc);
459
460 return ret;
461}
462
463static int wd719x_abort(struct scsi_cmnd *cmd)
464{
465 int action, result;
466 unsigned long flags;
467 struct wd719x_scb *scb = (struct wd719x_scb *)cmd->host_scribble;
468 struct wd719x *wd = shost_priv(cmd->device->host);
469
470 dev_info(&wd->pdev->dev, "abort command, tag: %x\n", cmd->tag);
471
472 action = /*cmd->tag ? WD719X_CMD_ABORT_TAG : */WD719X_CMD_ABORT;
473
474 spin_lock_irqsave(wd->sh->host_lock, flags);
475 result = wd719x_direct_cmd(wd, action, cmd->device->id,
476 cmd->device->lun, cmd->tag, scb->phys, 0);
477 spin_unlock_irqrestore(wd->sh->host_lock, flags);
478 if (result)
479 return FAILED;
480
481 return SUCCESS;
482}
483
484static int wd719x_reset(struct scsi_cmnd *cmd, u8 opcode, u8 device)
485{
486 int result;
487 unsigned long flags;
488 struct wd719x *wd = shost_priv(cmd->device->host);
489
490 dev_info(&wd->pdev->dev, "%s reset requested\n",
491 (opcode == WD719X_CMD_BUSRESET) ? "bus" : "device");
492
493 spin_lock_irqsave(wd->sh->host_lock, flags);
494 result = wd719x_direct_cmd(wd, opcode, device, 0, 0, 0,
495 WD719X_WAIT_FOR_SCSI_RESET);
496 spin_unlock_irqrestore(wd->sh->host_lock, flags);
497 if (result)
498 return FAILED;
499
500 return SUCCESS;
501}
502
503static int wd719x_dev_reset(struct scsi_cmnd *cmd)
504{
505 return wd719x_reset(cmd, WD719X_CMD_RESET, cmd->device->id);
506}
507
508static int wd719x_bus_reset(struct scsi_cmnd *cmd)
509{
510 return wd719x_reset(cmd, WD719X_CMD_BUSRESET, 0);
511}
512
513static int wd719x_host_reset(struct scsi_cmnd *cmd)
514{
515 struct wd719x *wd = shost_priv(cmd->device->host);
516 struct wd719x_scb *scb, *tmp;
517 unsigned long flags;
518 int result;
519
520 dev_info(&wd->pdev->dev, "host reset requested\n");
521 spin_lock_irqsave(wd->sh->host_lock, flags);
522 /* Try to reinit the RISC */
523 if (wd719x_chip_init(wd) == 0)
524 result = SUCCESS;
525 else
526 result = FAILED;
527
528 /* flush all SCBs */
529 list_for_each_entry_safe(scb, tmp, &wd->active_scbs, list) {
530 struct scsi_cmnd *tmp_cmd = scb->cmd;
531 wd719x_finish_cmd(tmp_cmd, result);
532 }
533 spin_unlock_irqrestore(wd->sh->host_lock, flags);
534
535 return result;
536}
537
538static int wd719x_biosparam(struct scsi_device *sdev, struct block_device *bdev,
539 sector_t capacity, int geom[])
540{
541 if (capacity >= 0x200000) {
542 geom[0] = 255; /* heads */
543 geom[1] = 63; /* sectors */
544 } else {
545 geom[0] = 64; /* heads */
546 geom[1] = 32; /* sectors */
547 }
548 geom[2] = sector_div(capacity, geom[0] * geom[1]); /* cylinders */
549
550 return 0;
551}
552
553/* process a SCB-completion interrupt */
554static inline void wd719x_interrupt_SCB(struct wd719x *wd,
555 union wd719x_regs regs,
556 struct wd719x_scb *scb)
557{
558 struct scsi_cmnd *cmd;
559 int result;
560
561 /* now have to find result from card */
562 switch (regs.bytes.SUE) {
563 case WD719X_SUE_NOERRORS:
564 result = DID_OK;
565 break;
566 case WD719X_SUE_REJECTED:
567 dev_err(&wd->pdev->dev, "command rejected\n");
568 result = DID_ERROR;
569 break;
570 case WD719X_SUE_SCBQFULL:
571 dev_err(&wd->pdev->dev, "SCB queue is full\n");
572 result = DID_ERROR;
573 break;
574 case WD719X_SUE_TERM:
575 dev_dbg(&wd->pdev->dev, "SCB terminated by direct command\n");
576 result = DID_ABORT; /* or DID_RESET? */
577 break;
578 case WD719X_SUE_CHAN1ABORT:
579 case WD719X_SUE_CHAN23ABORT:
580 result = DID_ABORT;
581 dev_err(&wd->pdev->dev, "DMA abort\n");
582 break;
583 case WD719X_SUE_CHAN1PAR:
584 case WD719X_SUE_CHAN23PAR:
585 result = DID_PARITY;
586 dev_err(&wd->pdev->dev, "DMA parity error\n");
587 break;
588 case WD719X_SUE_TIMEOUT:
589 result = DID_TIME_OUT;
590 dev_dbg(&wd->pdev->dev, "selection timeout\n");
591 break;
592 case WD719X_SUE_RESET:
593 dev_dbg(&wd->pdev->dev, "bus reset occured\n");
594 result = DID_RESET;
595 break;
596 case WD719X_SUE_BUSERROR:
597 dev_dbg(&wd->pdev->dev, "SCSI bus error\n");
598 result = DID_ERROR;
599 break;
600 case WD719X_SUE_WRONGWAY:
601 dev_err(&wd->pdev->dev, "wrong data transfer direction\n");
602 result = DID_ERROR;
603 break;
604 case WD719X_SUE_BADPHASE:
605 dev_err(&wd->pdev->dev, "invalid SCSI phase\n");
606 result = DID_ERROR;
607 break;
608 case WD719X_SUE_TOOLONG:
609 dev_err(&wd->pdev->dev, "record too long\n");
610 result = DID_ERROR;
611 break;
612 case WD719X_SUE_BUSFREE:
613 dev_err(&wd->pdev->dev, "unexpected bus free\n");
614 result = DID_NO_CONNECT; /* or DID_ERROR ???*/
615 break;
616 case WD719X_SUE_ARSDONE:
617 dev_dbg(&wd->pdev->dev, "auto request sense\n");
618 if (regs.bytes.SCSI == 0)
619 result = DID_OK;
620 else
621 result = DID_PARITY;
622 break;
623 case WD719X_SUE_IGNORED:
624 dev_err(&wd->pdev->dev, "target id %d ignored command\n",
625 scb->cmd->device->id);
626 result = DID_NO_CONNECT;
627 break;
628 case WD719X_SUE_WRONGTAGS:
629 dev_err(&wd->pdev->dev, "reversed tags\n");
630 result = DID_ERROR;
631 break;
632 case WD719X_SUE_BADTAGS:
633 dev_err(&wd->pdev->dev, "tag type not supported by target\n");
634 result = DID_ERROR;
635 break;
636 case WD719X_SUE_NOSCAMID:
637 dev_err(&wd->pdev->dev, "no SCAM soft ID available\n");
638 result = DID_ERROR;
639 break;
640 default:
641 dev_warn(&wd->pdev->dev, "unknown SUE error code: 0x%x\n",
642 regs.bytes.SUE);
643 result = DID_ERROR;
644 break;
645 }
646 cmd = scb->cmd;
647
648 wd719x_finish_cmd(cmd, result);
649}
650
651static irqreturn_t wd719x_interrupt(int irq, void *dev_id)
652{
653 struct wd719x *wd = dev_id;
654 union wd719x_regs regs;
655 unsigned long flags;
656 u32 SCB_out;
657
658 spin_lock_irqsave(wd->sh->host_lock, flags);
659 /* read SCB pointer back from card */
660 SCB_out = wd719x_readl(wd, WD719X_AMR_SCB_OUT);
661 /* read all status info at once */
662 regs.all = cpu_to_le32(wd719x_readl(wd, WD719X_AMR_OP_CODE));
663
664 switch (regs.bytes.INT) {
665 case WD719X_INT_NONE:
666 spin_unlock_irqrestore(wd->sh->host_lock, flags);
667 return IRQ_NONE;
668 case WD719X_INT_LINKNOSTATUS:
669 dev_err(&wd->pdev->dev, "linked command completed with no status\n");
670 break;
671 case WD719X_INT_BADINT:
672 dev_err(&wd->pdev->dev, "unsolicited interrupt\n");
673 break;
674 case WD719X_INT_NOERRORS:
675 case WD719X_INT_LINKNOERRORS:
676 case WD719X_INT_ERRORSLOGGED:
677 case WD719X_INT_SPIDERFAILED:
678 /* was the cmd completed a direct or SCB command? */
679 if (regs.bytes.OPC == WD719X_CMD_PROCESS_SCB) {
680 struct wd719x_scb *scb;
681 list_for_each_entry(scb, &wd->active_scbs, list)
682 if (SCB_out == scb->phys)
683 break;
684 if (SCB_out == scb->phys)
685 wd719x_interrupt_SCB(wd, regs, scb);
686 else
687 dev_err(&wd->pdev->dev, "card returned invalid SCB pointer\n");
688 } else
689 dev_warn(&wd->pdev->dev, "direct command 0x%x completed\n",
690 regs.bytes.OPC);
691 break;
692 case WD719X_INT_PIOREADY:
693 dev_err(&wd->pdev->dev, "card indicates PIO data ready but we never use PIO\n");
694 /* interrupt will not be cleared until all data is read */
695 break;
696 default:
697 dev_err(&wd->pdev->dev, "unknown interrupt reason: %d\n",
698 regs.bytes.INT);
699
700 }
701 /* clear interrupt so another can happen */
702 wd719x_writeb(wd, WD719X_AMR_INT_STATUS, WD719X_INT_NONE);
703 spin_unlock_irqrestore(wd->sh->host_lock, flags);
704
705 return IRQ_HANDLED;
706}
707
708static void wd719x_eeprom_reg_read(struct eeprom_93cx6 *eeprom)
709{
710 struct wd719x *wd = eeprom->data;
711 u8 reg = wd719x_readb(wd, WD719X_PCI_GPIO_DATA);
712
713 eeprom->reg_data_out = reg & WD719X_EE_DO;
714}
715
716static void wd719x_eeprom_reg_write(struct eeprom_93cx6 *eeprom)
717{
718 struct wd719x *wd = eeprom->data;
719 u8 reg = 0;
720
721 if (eeprom->reg_data_in)
722 reg |= WD719X_EE_DI;
723 if (eeprom->reg_data_clock)
724 reg |= WD719X_EE_CLK;
725 if (eeprom->reg_chip_select)
726 reg |= WD719X_EE_CS;
727
728 wd719x_writeb(wd, WD719X_PCI_GPIO_DATA, reg);
729}
730
731/* read config from EEPROM so it can be downloaded by the RISC on (re-)init */
732static void wd719x_read_eeprom(struct wd719x *wd)
733{
734 struct eeprom_93cx6 eeprom;
735 u8 gpio;
736 struct wd719x_eeprom_header header;
737
738 eeprom.data = wd;
739 eeprom.register_read = wd719x_eeprom_reg_read;
740 eeprom.register_write = wd719x_eeprom_reg_write;
741 eeprom.width = PCI_EEPROM_WIDTH_93C46;
742
743 /* set all outputs to low */
744 wd719x_writeb(wd, WD719X_PCI_GPIO_DATA, 0);
745 /* configure GPIO pins */
746 gpio = wd719x_readb(wd, WD719X_PCI_GPIO_CONTROL);
747 /* GPIO outputs */
748 gpio &= (~(WD719X_EE_CLK | WD719X_EE_DI | WD719X_EE_CS));
749 /* GPIO input */
750 gpio |= WD719X_EE_DO;
751 wd719x_writeb(wd, WD719X_PCI_GPIO_CONTROL, gpio);
752
753 /* read EEPROM header */
754 eeprom_93cx6_multireadb(&eeprom, 0, (u8 *)&header, sizeof(header));
755
756 if (header.sig1 == 'W' && header.sig2 == 'D')
757 eeprom_93cx6_multireadb(&eeprom, header.cfg_offset,
758 (u8 *)wd->params,
759 sizeof(struct wd719x_host_param));
760 else { /* default EEPROM values */
761 dev_warn(&wd->pdev->dev, "EEPROM signature is invalid (0x%02x 0x%02x), using default values\n",
762 header.sig1, header.sig2);
763 wd->params->ch_1_th = 0x10; /* 16 DWs = 64 B */
764 wd->params->scsi_conf = 0x4c; /* 48ma, spue, parity check */
765 wd->params->own_scsi_id = 0x07; /* ID 7, SCAM disabled */
766 wd->params->sel_timeout = 0x4d; /* 250 ms */
767 wd->params->sleep_timer = 0x01;
768 wd->params->cdb_size = cpu_to_le16(0x5555); /* all 6 B */
769 wd->params->scsi_pad = 0x1b;
770 if (wd->type == WD719X_TYPE_7193) /* narrow card - disable */
771 wd->params->wide = cpu_to_le32(0x00000000);
772 else /* initiate & respond to WIDE messages */
773 wd->params->wide = cpu_to_le32(0xffffffff);
774 wd->params->sync = cpu_to_le32(0xffffffff);
775 wd->params->soft_mask = 0x00; /* all disabled */
776 wd->params->unsol_mask = 0x00; /* all disabled */
777 }
778 /* disable TAGGED messages */
779 wd->params->tag_en = cpu_to_le16(0x0000);
780}
781
782/* Read card type from GPIO bits 1 and 3 */
783static enum wd719x_card_type wd719x_detect_type(struct wd719x *wd)
784{
785 u8 card = wd719x_readb(wd, WD719X_PCI_GPIO_CONTROL);
786
787 card |= WD719X_GPIO_ID_BITS;
788 wd719x_writeb(wd, WD719X_PCI_GPIO_CONTROL, card);
789 card = wd719x_readb(wd, WD719X_PCI_GPIO_DATA) & WD719X_GPIO_ID_BITS;
790 switch (card) {
791 case 0x08:
792 return WD719X_TYPE_7193;
793 case 0x02:
794 return WD719X_TYPE_7197;
795 case 0x00:
796 return WD719X_TYPE_7296;
797 default:
798 dev_warn(&wd->pdev->dev, "unknown card type 0x%x\n", card);
799 return WD719X_TYPE_UNKNOWN;
800 }
801}
802
803static int wd719x_board_found(struct Scsi_Host *sh)
804{
805 struct wd719x *wd = shost_priv(sh);
806 char *card_types[] = { "Unknown card", "WD7193", "WD7197", "WD7296" };
807 int ret;
808
809 INIT_LIST_HEAD(&wd->active_scbs);
810 INIT_LIST_HEAD(&wd->free_scbs);
811
812 sh->base = pci_resource_start(wd->pdev, 0);
813
814 wd->type = wd719x_detect_type(wd);
815
816 wd->sh = sh;
817 sh->irq = wd->pdev->irq;
818 wd->fw_virt = NULL;
819
820 /* memory area for host (EEPROM) parameters */
821 wd->params = pci_alloc_consistent(wd->pdev,
822 sizeof(struct wd719x_host_param),
823 &wd->params_phys);
824 if (!wd->params) {
825 dev_warn(&wd->pdev->dev, "unable to allocate parameter buffer\n");
826 return -ENOMEM;
827 }
828
829 /* memory area for the RISC for hash table of outstanding requests */
830 wd->hash_virt = pci_alloc_consistent(wd->pdev, WD719X_HASH_TABLE_SIZE,
831 &wd->hash_phys);
832 if (!wd->hash_virt) {
833 dev_warn(&wd->pdev->dev, "unable to allocate hash buffer\n");
834 ret = -ENOMEM;
835 goto fail_free_params;
836 }
837
838 ret = request_irq(wd->pdev->irq, wd719x_interrupt, IRQF_SHARED,
839 "wd719x", wd);
840 if (ret) {
841 dev_warn(&wd->pdev->dev, "unable to assign IRQ %d\n",
842 wd->pdev->irq);
843 goto fail_free_hash;
844 }
845
846 /* read parameters from EEPROM */
847 wd719x_read_eeprom(wd);
848
849 ret = wd719x_chip_init(wd);
850 if (ret)
851 goto fail_free_irq;
852
853 sh->this_id = wd->params->own_scsi_id & WD719X_EE_SCSI_ID_MASK;
854
855 dev_info(&wd->pdev->dev, "%s at I/O 0x%lx, IRQ %u, SCSI ID %d\n",
856 card_types[wd->type], sh->base, sh->irq, sh->this_id);
857
858 return 0;
859
860fail_free_irq:
861 free_irq(wd->pdev->irq, wd);
862fail_free_hash:
863 pci_free_consistent(wd->pdev, WD719X_HASH_TABLE_SIZE, wd->hash_virt,
864 wd->hash_phys);
865fail_free_params:
866 pci_free_consistent(wd->pdev, sizeof(struct wd719x_host_param),
867 wd->params, wd->params_phys);
868
869 return ret;
870}
871
872static struct scsi_host_template wd719x_template = {
873 .name = "Western Digital 719x",
874 .queuecommand = wd719x_queuecommand,
875 .eh_abort_handler = wd719x_abort,
876 .eh_device_reset_handler = wd719x_dev_reset,
877 .eh_bus_reset_handler = wd719x_bus_reset,
878 .eh_host_reset_handler = wd719x_host_reset,
879 .bios_param = wd719x_biosparam,
880 .proc_name = "wd719x",
881 .can_queue = 255,
882 .this_id = 7,
883 .sg_tablesize = WD719X_SG,
884 .cmd_per_lun = WD719X_CMD_PER_LUN,
885 .use_clustering = ENABLE_CLUSTERING,
886};
887
888static int wd719x_pci_probe(struct pci_dev *pdev, const struct pci_device_id *d)
889{
890 int err;
891 struct Scsi_Host *sh;
892 struct wd719x *wd;
893
894 err = pci_enable_device(pdev);
895 if (err)
896 goto fail;
897
898 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
899 dev_warn(&pdev->dev, "Unable to set 32-bit DMA mask\n");
900 goto disable_device;
901 }
902
903 err = pci_request_regions(pdev, "wd719x");
904 if (err)
905 goto disable_device;
906 pci_set_master(pdev);
907
908 err = -ENODEV;
909 if (pci_resource_len(pdev, 0) == 0)
910 goto release_region;
911
912 err = -ENOMEM;
913 sh = scsi_host_alloc(&wd719x_template, sizeof(struct wd719x));
914 if (!sh)
915 goto release_region;
916
917 wd = shost_priv(sh);
918 wd->base = pci_iomap(pdev, 0, 0);
919 if (!wd->base)
920 goto free_host;
921 wd->pdev = pdev;
922
923 err = wd719x_board_found(sh);
924 if (err)
925 goto unmap;
926
927 err = scsi_add_host(sh, &wd->pdev->dev);
928 if (err)
929 goto destroy;
930
931 scsi_scan_host(sh);
932
933 pci_set_drvdata(pdev, sh);
934 return 0;
935
936destroy:
937 wd719x_destroy(wd);
938unmap:
939 pci_iounmap(pdev, wd->base);
940free_host:
941 scsi_host_put(sh);
942release_region:
943 pci_release_regions(pdev);
944disable_device:
945 pci_disable_device(pdev);
946fail:
947 return err;
948}
949
950
951static void wd719x_pci_remove(struct pci_dev *pdev)
952{
953 struct Scsi_Host *sh = pci_get_drvdata(pdev);
954 struct wd719x *wd = shost_priv(sh);
955
956 scsi_remove_host(sh);
957 wd719x_destroy(wd);
958 pci_iounmap(pdev, wd->base);
959 pci_release_regions(pdev);
960 pci_disable_device(pdev);
961
962 scsi_host_put(sh);
963}
964
965static DEFINE_PCI_DEVICE_TABLE(wd719x_pci_table) = {
966 { PCI_DEVICE(PCI_VENDOR_ID_WD, 0x3296) },
967 {}
968};
969
970MODULE_DEVICE_TABLE(pci, wd719x_pci_table);
971
972static struct pci_driver wd719x_pci_driver = {
973 .name = "wd719x",
974 .id_table = wd719x_pci_table,
975 .probe = wd719x_pci_probe,
976 .remove = wd719x_pci_remove,
977};
978
979static int __init wd719x_init(void)
980{
981 return pci_register_driver(&wd719x_pci_driver);
982}
983
984static void __exit wd719x_exit(void)
985{
986 pci_unregister_driver(&wd719x_pci_driver);
987}
988
989module_init(wd719x_init);
990module_exit(wd719x_exit);
991
992MODULE_DESCRIPTION("Western Digital WD7193/7197/7296 SCSI driver");
993MODULE_AUTHOR("Ondrej Zary, Aaron Dewell, Juergen Gaertner");
994MODULE_LICENSE("GPL");
995MODULE_FIRMWARE("wd719x-wcs.bin");
996MODULE_FIRMWARE("wd719x-risc.bin");
diff --git a/drivers/scsi/wd719x.h b/drivers/scsi/wd719x.h
new file mode 100644
index 000000000000..185e30e4eb93
--- /dev/null
+++ b/drivers/scsi/wd719x.h
@@ -0,0 +1,249 @@
1#ifndef _WD719X_H_
2#define _WD719X_H_
3
4#define WD719X_SG 255 /* Scatter/gather size */
5#define WD719X_CMD_PER_LUN 1 /* We should be able to do linked commands, but
6 * this is 1 for now to be safe. */
7
8struct wd719x_sglist {
9 __le32 ptr;
10 __le32 length;
11} __packed;
12
13enum wd719x_card_type {
14 WD719X_TYPE_UNKNOWN = 0,
15 WD719X_TYPE_7193,
16 WD719X_TYPE_7197,
17 WD719X_TYPE_7296,
18};
19
20union wd719x_regs {
21 __le32 all; /* All Status at once */
22 struct {
23 u8 OPC; /* Opcode register */
24 u8 SCSI; /* SCSI Errors */
25 u8 SUE; /* Spider unique Errors */
26 u8 INT; /* Interrupt Status */
27 } bytes;
28};
29
30/* Spider Command Block (SCB) */
31struct wd719x_scb {
32 __le32 Int_SCB; /* 00-03 Internal SCB link pointer (must be cleared) */
33 u8 SCB_opcode; /* 04 SCB Command opcode */
34 u8 CDB_tag; /* 05 SCSI Tag byte for CDB queues (0 if untagged) */
35 u8 lun; /* 06 SCSI LUN */
36 u8 devid; /* 07 SCSI Device ID */
37 u8 CDB[16]; /* 08-23 SCSI CDB (16 bytes as defined by ANSI spec. */
38 __le32 data_p; /* 24-27 Data transfer address (or SG list address) */
39 __le32 data_length; /* 28-31 Data transfer Length (or SG list length) */
40 __le32 CDB_link; /* 32-35 SCSI CDB Link Ptr */
41 __le32 sense_buf; /* 36-39 Auto request sense buffer address */
42 u8 sense_buf_length;/* 40 Auto request sense transfer length */
43 u8 reserved; /* 41 reserved */
44 u8 SCB_options; /* 42 SCB-options */
45 u8 SCB_tag_msg; /* 43 Tagged messages options */
46 /* Not filled in by host */
47 __le32 req_ptr; /* 44-47 Ptr to Host Request returned on interrupt */
48 u8 host_opcode; /* 48 Host Command Opcode (same as AMR_00) */
49 u8 scsi_stat; /* 49 SCSI Status returned */
50 u8 ret_error; /* 50 SPIDER Unique Error Code returned (SUE) */
51 u8 int_stat; /* 51 Message u8 / Interrupt Status byte returned */
52 __le32 transferred; /* 52-55 Bytes Transferred */
53 u8 last_trans[3]; /* 56-58 Bytes Transferred in last session */
54 u8 length; /* 59 SCSI Messages Length (1-8) */
55 u8 sync_offset; /* 60 Synchronous offset */
56 u8 sync_rate; /* 61 Synchronous rate */
57 u8 flags[2]; /* 62-63 SCB specific flags (local to each thread) */
58 /* everything below is for driver use (not used by card) */
59 dma_addr_t phys; /* bus address of the SCB */
60 struct scsi_cmnd *cmd; /* a copy of the pointer we were passed */
61 struct list_head list;
62 struct wd719x_sglist sg_list[WD719X_SG] __aligned(8); /* SG list */
63} __packed;
64
65struct wd719x {
66 struct Scsi_Host *sh; /* pointer to host structure */
67 struct pci_dev *pdev;
68 void __iomem *base;
69 enum wd719x_card_type type; /* type of card */
70 void *fw_virt; /* firmware buffer CPU address */
71 dma_addr_t fw_phys; /* firmware buffer bus address */
72 size_t fw_size; /* firmware buffer size */
73 struct wd719x_host_param *params; /* host parameters (EEPROM) */
74 dma_addr_t params_phys; /* host parameters bus address */
75 void *hash_virt; /* hash table CPU address */
76 dma_addr_t hash_phys; /* hash table bus address */
77 struct list_head active_scbs;
78 struct list_head free_scbs;
79};
80
81/* timeout delays in microsecs */
82#define WD719X_WAIT_FOR_CMD_READY 500
83#define WD719X_WAIT_FOR_RISC 2000
84#define WD719X_WAIT_FOR_SCSI_RESET 3000000
85
86/* All commands except 0x00 generate an interrupt */
87#define WD719X_CMD_READY 0x00 /* Command register ready (or noop) */
88#define WD719X_CMD_INIT_RISC 0x01 /* Initialize RISC */
89/* 0x02 is reserved */
90#define WD719X_CMD_BUSRESET 0x03 /* Assert SCSI bus reset */
91#define WD719X_CMD_READ_FIRMVER 0x04 /* Read the Firmware Revision */
92#define WD719X_CMD_ECHO_BYTES 0x05 /* Echo command bytes (DW) */
93/* 0x06 is reserved */
94/* 0x07 is reserved */
95#define WD719X_CMD_GET_PARAM 0x08 /* Get programmable parameters */
96#define WD719X_CMD_SET_PARAM 0x09 /* Set programmable parameters */
97#define WD719X_CMD_SLEEP 0x0a /* Put SPIDER to sleep */
98#define WD719X_CMD_READ_INIT 0x0b /* Read initialization parameters */
99#define WD719X_CMD_RESTORE_INIT 0x0c /* Restore initialization parameters */
100/* 0x0d is reserved */
101/* 0x0e is reserved */
102/* 0x0f is reserved */
103#define WD719X_CMD_ABORT_TAG 0x10 /* Send Abort tag message to target */
104#define WD719X_CMD_ABORT 0x11 /* Send Abort message to target */
105#define WD719X_CMD_RESET 0x12 /* Send Reset message to target */
106#define WD719X_CMD_INIT_SCAM 0x13 /* Initiate SCAM */
107#define WD719X_CMD_GET_SYNC 0x14 /* Get synchronous rates */
108#define WD719X_CMD_SET_SYNC 0x15 /* Set synchronous rates */
109#define WD719X_CMD_GET_WIDTH 0x16 /* Get SCSI bus width */
110#define WD719X_CMD_SET_WIDTH 0x17 /* Set SCSI bus width */
111#define WD719X_CMD_GET_TAGS 0x18 /* Get tag flags */
112#define WD719X_CMD_SET_TAGS 0x19 /* Set tag flags */
113#define WD719X_CMD_GET_PARAM2 0x1a /* Get programmable params (format 2) */
114#define WD719X_CMD_SET_PARAM2 0x1b /* Set programmable params (format 2) */
115/* Commands with request pointers (mailbox) */
116#define WD719X_CMD_PROCESS_SCB 0x80 /* Process SCSI Control Block (SCB) */
117/* No interrupt generated on acceptance of SCB pointer */
118
119/* interrupt status defines */
120#define WD719X_INT_NONE 0x00 /* No interrupt pending */
121#define WD719X_INT_NOERRORS 0x01 /* Command completed with no errors */
122#define WD719X_INT_LINKNOERRORS 0x02 /* link cmd completed with no errors */
123#define WD719X_INT_LINKNOSTATUS 0x03 /* link cmd completed with no flag set */
124#define WD719X_INT_ERRORSLOGGED 0x04 /* cmd completed with errors logged */
125#define WD719X_INT_SPIDERFAILED 0x05 /* cmd failed without valid SCSI status */
126#define WD719X_INT_BADINT 0x80 /* unsolicited interrupt */
127#define WD719X_INT_PIOREADY 0xf0 /* data ready for PIO output */
128
129/* Spider Unique Error Codes (SUE) */
130#define WD719X_SUE_NOERRORS 0x00 /* No errors detected by SPIDER */
131#define WD719X_SUE_REJECTED 0x01 /* Command Rejected (bad opcode/param) */
132#define WD719X_SUE_SCBQFULL 0x02 /* SCB queue full */
133/* 0x03 is reserved */
134#define WD719X_SUE_TERM 0x04 /* Host terminated SCB via primative cmd */
135#define WD719X_SUE_CHAN1PAR 0x05 /* PCI Channel 1 parity error occurred */
136#define WD719X_SUE_CHAN1ABORT 0x06 /* PCI Channel 1 system abort occurred */
137#define WD719X_SUE_CHAN23PAR 0x07 /* PCI Channel 2/3 parity error occurred */
138#define WD719X_SUE_CHAN23ABORT 0x08 /* PCI Channel 2/3 system abort occurred */
139#define WD719X_SUE_TIMEOUT 0x10 /* Selection/reselection timeout */
140#define WD719X_SUE_RESET 0x11 /* SCSI bus reset occurred */
141#define WD719X_SUE_BUSERROR 0x12 /* SCSI bus error */
142#define WD719X_SUE_WRONGWAY 0x13 /* Wrong data transfer dir set by target */
143#define WD719X_SUE_BADPHASE 0x14 /* SCSI phase illegal or unexpected */
144#define WD719X_SUE_TOOLONG 0x15 /* target requested too much data */
145#define WD719X_SUE_BUSFREE 0x16 /* Unexpected SCSI bus free */
146#define WD719X_SUE_ARSDONE 0x17 /* Auto request sense executed */
147#define WD719X_SUE_IGNORED 0x18 /* SCSI message was ignored by target */
148#define WD719X_SUE_WRONGTAGS 0x19 /* Tagged SCB & tags off (or vice versa) */
149#define WD719X_SUE_BADTAGS 0x1a /* Wrong tag message type for target */
150#define WD719X_SUE_NOSCAMID 0x1b /* No SCAM soft ID available */
151
152/* code sizes */
153#define WD719X_HASH_TABLE_SIZE 4096
154
155/* Advanced Mode Registers */
156/* Regs 0x00..0x1f are for Advanced Mode of the card (RISC is running). */
157#define WD719X_AMR_COMMAND 0x00
158#define WD719X_AMR_CMD_PARAM 0x01
159#define WD719X_AMR_CMD_PARAM_2 0x02
160#define WD719X_AMR_CMD_PARAM_3 0x03
161#define WD719X_AMR_SCB_IN 0x04
162
163#define WD719X_AMR_BIOS_SHARE_INT 0x0f
164
165#define WD719X_AMR_SCB_OUT 0x18
166#define WD719X_AMR_OP_CODE 0x1c
167#define WD719X_AMR_SCSI_STATUS 0x1d
168#define WD719X_AMR_SCB_ERROR 0x1e
169#define WD719X_AMR_INT_STATUS 0x1f
170
171#define WD719X_DISABLE_INT 0x80
172
173/* SCB flags */
174#define WD719X_SCB_FLAGS_CHECK_DIRECTION 0x01
175#define WD719X_SCB_FLAGS_PCI_TO_SCSI 0x02
176#define WD719X_SCB_FLAGS_AUTO_REQUEST_SENSE 0x10
177#define WD719X_SCB_FLAGS_DO_SCATTER_GATHER 0x20
178#define WD719X_SCB_FLAGS_NO_DISCONNECT 0x40
179
180/* PCI Registers used for reset, initial code download */
181/* Regs 0x20..0x3f are for Normal (DOS) mode (RISC is asleep). */
182#define WD719X_PCI_GPIO_CONTROL 0x3C
183#define WD719X_PCI_GPIO_DATA 0x3D
184#define WD719X_PCI_PORT_RESET 0x3E
185#define WD719X_PCI_MODE_SELECT 0x3F
186
187#define WD719X_PCI_EXTERNAL_ADDR 0x60
188#define WD719X_PCI_INTERNAL_ADDR 0x64
189#define WD719X_PCI_DMA_TRANSFER_SIZE 0x66
190#define WD719X_PCI_CHANNEL2_3CMD 0x68
191#define WD719X_PCI_CHANNEL2_3STATUS 0x69
192
193#define WD719X_GPIO_ID_BITS 0x0a
194#define WD719X_PRAM_BASE_ADDR 0x00
195
196/* codes written to or read from the card */
197#define WD719X_PCI_RESET 0x01
198#define WD719X_ENABLE_ADVANCE_MODE 0x01
199
200#define WD719X_START_CHANNEL2_3DMA 0x17
201#define WD719X_START_CHANNEL2_3DONE 0x01
202#define WD719X_START_CHANNEL2_3ABORT 0x20
203
204/* 33C296 GPIO bits for EEPROM pins */
205#define WD719X_EE_DI (1 << 1)
206#define WD719X_EE_CS (1 << 2)
207#define WD719X_EE_CLK (1 << 3)
208#define WD719X_EE_DO (1 << 4)
209
210/* EEPROM contents */
211struct wd719x_eeprom_header {
212 u8 sig1;
213 u8 sig2;
214 u8 version;
215 u8 checksum;
216 u8 cfg_offset;
217 u8 cfg_size;
218 u8 setup_offset;
219 u8 setup_size;
220} __packed;
221
222#define WD719X_EE_SIG1 0
223#define WD719X_EE_SIG2 1
224#define WD719X_EE_VERSION 2
225#define WD719X_EE_CHECKSUM 3
226#define WD719X_EE_CFG_OFFSET 4
227#define WD719X_EE_CFG_SIZE 5
228#define WD719X_EE_SETUP_OFFSET 6
229#define WD719X_EE_SETUP_SIZE 7
230
231#define WD719X_EE_SCSI_ID_MASK 0xf
232
233/* SPIDER Host Parameters Block (=EEPROM configuration block) */
234struct wd719x_host_param {
235 u8 ch_1_th; /* FIFO threshold */
236 u8 scsi_conf; /* SCSI configuration */
237 u8 own_scsi_id; /* controller SCSI ID */
238 u8 sel_timeout; /* selection timeout*/
239 u8 sleep_timer; /* seep timer */
240 __le16 cdb_size;/* CDB size groups */
241 __le16 tag_en; /* Tag msg enables (ID 0-15) */
242 u8 scsi_pad; /* SCSI pad control */
243 __le32 wide; /* WIDE msg options (ID 0-15) */
244 __le32 sync; /* SYNC msg options (ID 0-15) */
245 u8 soft_mask; /* soft error mask */
246 u8 unsol_mask; /* unsolicited error mask */
247} __packed;
248
249#endif /* _WD719X_H_ */
diff --git a/drivers/soc/versatile/soc-realview.c b/drivers/soc/versatile/soc-realview.c
index cea8ea3491d2..1a07bf540fec 100644
--- a/drivers/soc/versatile/soc-realview.c
+++ b/drivers/soc/versatile/soc-realview.c
@@ -26,6 +26,7 @@ static const struct of_device_id realview_soc_of_match[] = {
26 { .compatible = "arm,realview-pb11mp-soc", }, 26 { .compatible = "arm,realview-pb11mp-soc", },
27 { .compatible = "arm,realview-pba8-soc", }, 27 { .compatible = "arm,realview-pba8-soc", },
28 { .compatible = "arm,realview-pbx-soc", }, 28 { .compatible = "arm,realview-pbx-soc", },
29 { }
29}; 30};
30 31
31static u32 realview_coreid; 32static u32 realview_coreid;
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 72e12bad14b9..d0d5542efc06 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -376,9 +376,6 @@ static void pump_transfers(unsigned long data)
376 chip = dws->cur_chip; 376 chip = dws->cur_chip;
377 spi = message->spi; 377 spi = message->spi;
378 378
379 if (unlikely(!chip->clk_div))
380 chip->clk_div = dws->max_freq / chip->speed_hz;
381
382 if (message->state == ERROR_STATE) { 379 if (message->state == ERROR_STATE) {
383 message->status = -EIO; 380 message->status = -EIO;
384 goto early_exit; 381 goto early_exit;
@@ -419,7 +416,7 @@ static void pump_transfers(unsigned long data)
419 if (transfer->speed_hz) { 416 if (transfer->speed_hz) {
420 speed = chip->speed_hz; 417 speed = chip->speed_hz;
421 418
422 if (transfer->speed_hz != speed) { 419 if ((transfer->speed_hz != speed) || (!chip->clk_div)) {
423 speed = transfer->speed_hz; 420 speed = transfer->speed_hz;
424 421
425 /* clk_div doesn't support odd number */ 422 /* clk_div doesn't support odd number */
@@ -581,7 +578,6 @@ static int dw_spi_setup(struct spi_device *spi)
581 dev_err(&spi->dev, "No max speed HZ parameter\n"); 578 dev_err(&spi->dev, "No max speed HZ parameter\n");
582 return -EINVAL; 579 return -EINVAL;
583 } 580 }
584 chip->speed_hz = spi->max_speed_hz;
585 581
586 chip->tmode = 0; /* Tx & Rx */ 582 chip->tmode = 0; /* Tx & Rx */
587 /* Default SPI mode is SCPOL = 0, SCPH = 0 */ 583 /* Default SPI mode is SCPOL = 0, SCPH = 0 */
diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 448216025ce8..831ceb4a91f6 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -46,7 +46,7 @@
46 46
47#define SPI_TCR 0x08 47#define SPI_TCR 0x08
48 48
49#define SPI_CTAR(x) (0x0c + (x * 4)) 49#define SPI_CTAR(x) (0x0c + (((x) & 0x3) * 4))
50#define SPI_CTAR_FMSZ(x) (((x) & 0x0000000f) << 27) 50#define SPI_CTAR_FMSZ(x) (((x) & 0x0000000f) << 27)
51#define SPI_CTAR_CPOL(x) ((x) << 26) 51#define SPI_CTAR_CPOL(x) ((x) << 26)
52#define SPI_CTAR_CPHA(x) ((x) << 25) 52#define SPI_CTAR_CPHA(x) ((x) << 25)
@@ -70,7 +70,7 @@
70 70
71#define SPI_PUSHR 0x34 71#define SPI_PUSHR 0x34
72#define SPI_PUSHR_CONT (1 << 31) 72#define SPI_PUSHR_CONT (1 << 31)
73#define SPI_PUSHR_CTAS(x) (((x) & 0x00000007) << 28) 73#define SPI_PUSHR_CTAS(x) (((x) & 0x00000003) << 28)
74#define SPI_PUSHR_EOQ (1 << 27) 74#define SPI_PUSHR_EOQ (1 << 27)
75#define SPI_PUSHR_CTCNT (1 << 26) 75#define SPI_PUSHR_CTCNT (1 << 26)
76#define SPI_PUSHR_PCS(x) (((1 << x) & 0x0000003f) << 16) 76#define SPI_PUSHR_PCS(x) (((1 << x) & 0x0000003f) << 16)
diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index d8a105f76837..9e9e0f971e6c 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -1274,7 +1274,9 @@ static int pxa2xx_spi_suspend(struct device *dev)
1274 if (status != 0) 1274 if (status != 0)
1275 return status; 1275 return status;
1276 write_SSCR0(0, drv_data->ioaddr); 1276 write_SSCR0(0, drv_data->ioaddr);
1277 clk_disable_unprepare(ssp->clk); 1277
1278 if (!pm_runtime_suspended(dev))
1279 clk_disable_unprepare(ssp->clk);
1278 1280
1279 return 0; 1281 return 0;
1280} 1282}
@@ -1288,7 +1290,8 @@ static int pxa2xx_spi_resume(struct device *dev)
1288 pxa2xx_spi_dma_resume(drv_data); 1290 pxa2xx_spi_dma_resume(drv_data);
1289 1291
1290 /* Enable the SSP clock */ 1292 /* Enable the SSP clock */
1291 clk_prepare_enable(ssp->clk); 1293 if (!pm_runtime_suspended(dev))
1294 clk_prepare_enable(ssp->clk);
1292 1295
1293 /* Restore LPSS private register bits */ 1296 /* Restore LPSS private register bits */
1294 lpss_ssp_setup(drv_data); 1297 lpss_ssp_setup(drv_data);
diff --git a/drivers/spi/spi-sirf.c b/drivers/spi/spi-sirf.c
index 39e2c0a55a28..f63de781c729 100644
--- a/drivers/spi/spi-sirf.c
+++ b/drivers/spi/spi-sirf.c
@@ -562,9 +562,9 @@ spi_sirfsoc_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
562 562
563 sspi->word_width = DIV_ROUND_UP(bits_per_word, 8); 563 sspi->word_width = DIV_ROUND_UP(bits_per_word, 8);
564 txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) | 564 txfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
565 sspi->word_width; 565 (sspi->word_width >> 1);
566 rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) | 566 rxfifo_ctrl = SIRFSOC_SPI_FIFO_THD(SIRFSOC_SPI_FIFO_SIZE / 2) |
567 sspi->word_width; 567 (sspi->word_width >> 1);
568 568
569 if (!(spi->mode & SPI_CS_HIGH)) 569 if (!(spi->mode & SPI_CS_HIGH))
570 regval |= SIRFSOC_SPI_CS_IDLE_STAT; 570 regval |= SIRFSOC_SPI_CS_IDLE_STAT;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ebcb33df2eb2..50f20f243981 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -615,13 +615,13 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
615 sg_free_table(sgt); 615 sg_free_table(sgt);
616 return -ENOMEM; 616 return -ENOMEM;
617 } 617 }
618 sg_buf = page_address(vm_page) + 618 sg_set_page(&sgt->sgl[i], vm_page,
619 ((size_t)buf & ~PAGE_MASK); 619 min, offset_in_page(buf));
620 } else { 620 } else {
621 sg_buf = buf; 621 sg_buf = buf;
622 sg_set_buf(&sgt->sgl[i], sg_buf, min);
622 } 623 }
623 624
624 sg_set_buf(&sgt->sgl[i], sg_buf, min);
625 625
626 buf += min; 626 buf += min;
627 len -= min; 627 len -= min;
diff --git a/drivers/staging/iio/meter/ade7758.h b/drivers/staging/iio/meter/ade7758.h
index 07318203a836..e8c98cf57070 100644
--- a/drivers/staging/iio/meter/ade7758.h
+++ b/drivers/staging/iio/meter/ade7758.h
@@ -119,7 +119,6 @@ struct ade7758_state {
119 u8 *tx; 119 u8 *tx;
120 u8 *rx; 120 u8 *rx;
121 struct mutex buf_lock; 121 struct mutex buf_lock;
122 const struct iio_chan_spec *ade7758_ring_channels;
123 struct spi_transfer ring_xfer[4]; 122 struct spi_transfer ring_xfer[4];
124 struct spi_message ring_msg; 123 struct spi_message ring_msg;
125 /* 124 /*
diff --git a/drivers/staging/iio/meter/ade7758_core.c b/drivers/staging/iio/meter/ade7758_core.c
index abc60067cd72..fb373b89dcc2 100644
--- a/drivers/staging/iio/meter/ade7758_core.c
+++ b/drivers/staging/iio/meter/ade7758_core.c
@@ -634,9 +634,6 @@ static const struct iio_chan_spec ade7758_channels[] = {
634 .type = IIO_VOLTAGE, 634 .type = IIO_VOLTAGE,
635 .indexed = 1, 635 .indexed = 1,
636 .channel = 0, 636 .channel = 0,
637 .extend_name = "raw",
638 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
639 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
640 .address = AD7758_WT(AD7758_PHASE_A, AD7758_VOLTAGE), 637 .address = AD7758_WT(AD7758_PHASE_A, AD7758_VOLTAGE),
641 .scan_index = 0, 638 .scan_index = 0,
642 .scan_type = { 639 .scan_type = {
@@ -648,9 +645,6 @@ static const struct iio_chan_spec ade7758_channels[] = {
648 .type = IIO_CURRENT, 645 .type = IIO_CURRENT,
649 .indexed = 1, 646 .indexed = 1,
650 .channel = 0, 647 .channel = 0,
651 .extend_name = "raw",
652 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
653 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
654 .address = AD7758_WT(AD7758_PHASE_A, AD7758_CURRENT), 648 .address = AD7758_WT(AD7758_PHASE_A, AD7758_CURRENT),
655 .scan_index = 1, 649 .scan_index = 1,
656 .scan_type = { 650 .scan_type = {
@@ -662,9 +656,7 @@ static const struct iio_chan_spec ade7758_channels[] = {
662 .type = IIO_POWER, 656 .type = IIO_POWER,
663 .indexed = 1, 657 .indexed = 1,
664 .channel = 0, 658 .channel = 0,
665 .extend_name = "apparent_raw", 659 .extend_name = "apparent",
666 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
667 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
668 .address = AD7758_WT(AD7758_PHASE_A, AD7758_APP_PWR), 660 .address = AD7758_WT(AD7758_PHASE_A, AD7758_APP_PWR),
669 .scan_index = 2, 661 .scan_index = 2,
670 .scan_type = { 662 .scan_type = {
@@ -676,9 +668,7 @@ static const struct iio_chan_spec ade7758_channels[] = {
676 .type = IIO_POWER, 668 .type = IIO_POWER,
677 .indexed = 1, 669 .indexed = 1,
678 .channel = 0, 670 .channel = 0,
679 .extend_name = "active_raw", 671 .extend_name = "active",
680 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
681 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
682 .address = AD7758_WT(AD7758_PHASE_A, AD7758_ACT_PWR), 672 .address = AD7758_WT(AD7758_PHASE_A, AD7758_ACT_PWR),
683 .scan_index = 3, 673 .scan_index = 3,
684 .scan_type = { 674 .scan_type = {
@@ -690,9 +680,7 @@ static const struct iio_chan_spec ade7758_channels[] = {
690 .type = IIO_POWER, 680 .type = IIO_POWER,
691 .indexed = 1, 681 .indexed = 1,
692 .channel = 0, 682 .channel = 0,
693 .extend_name = "reactive_raw", 683 .extend_name = "reactive",
694 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
695 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
696 .address = AD7758_WT(AD7758_PHASE_A, AD7758_REACT_PWR), 684 .address = AD7758_WT(AD7758_PHASE_A, AD7758_REACT_PWR),
697 .scan_index = 4, 685 .scan_index = 4,
698 .scan_type = { 686 .scan_type = {
@@ -704,9 +692,6 @@ static const struct iio_chan_spec ade7758_channels[] = {
704 .type = IIO_VOLTAGE, 692 .type = IIO_VOLTAGE,
705 .indexed = 1, 693 .indexed = 1,
706 .channel = 1, 694 .channel = 1,
707 .extend_name = "raw",
708 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
709 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
710 .address = AD7758_WT(AD7758_PHASE_B, AD7758_VOLTAGE), 695 .address = AD7758_WT(AD7758_PHASE_B, AD7758_VOLTAGE),
711 .scan_index = 5, 696 .scan_index = 5,
712 .scan_type = { 697 .scan_type = {
@@ -718,9 +703,6 @@ static const struct iio_chan_spec ade7758_channels[] = {
718 .type = IIO_CURRENT, 703 .type = IIO_CURRENT,
719 .indexed = 1, 704 .indexed = 1,
720 .channel = 1, 705 .channel = 1,
721 .extend_name = "raw",
722 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
723 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
724 .address = AD7758_WT(AD7758_PHASE_B, AD7758_CURRENT), 706 .address = AD7758_WT(AD7758_PHASE_B, AD7758_CURRENT),
725 .scan_index = 6, 707 .scan_index = 6,
726 .scan_type = { 708 .scan_type = {
@@ -732,9 +714,7 @@ static const struct iio_chan_spec ade7758_channels[] = {
732 .type = IIO_POWER, 714 .type = IIO_POWER,
733 .indexed = 1, 715 .indexed = 1,
734 .channel = 1, 716 .channel = 1,
735 .extend_name = "apparent_raw", 717 .extend_name = "apparent",
736 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
737 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
738 .address = AD7758_WT(AD7758_PHASE_B, AD7758_APP_PWR), 718 .address = AD7758_WT(AD7758_PHASE_B, AD7758_APP_PWR),
739 .scan_index = 7, 719 .scan_index = 7,
740 .scan_type = { 720 .scan_type = {
@@ -746,9 +726,7 @@ static const struct iio_chan_spec ade7758_channels[] = {
746 .type = IIO_POWER, 726 .type = IIO_POWER,
747 .indexed = 1, 727 .indexed = 1,
748 .channel = 1, 728 .channel = 1,
749 .extend_name = "active_raw", 729 .extend_name = "active",
750 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
751 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
752 .address = AD7758_WT(AD7758_PHASE_B, AD7758_ACT_PWR), 730 .address = AD7758_WT(AD7758_PHASE_B, AD7758_ACT_PWR),
753 .scan_index = 8, 731 .scan_index = 8,
754 .scan_type = { 732 .scan_type = {
@@ -760,9 +738,7 @@ static const struct iio_chan_spec ade7758_channels[] = {
760 .type = IIO_POWER, 738 .type = IIO_POWER,
761 .indexed = 1, 739 .indexed = 1,
762 .channel = 1, 740 .channel = 1,
763 .extend_name = "reactive_raw", 741 .extend_name = "reactive",
764 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
765 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
766 .address = AD7758_WT(AD7758_PHASE_B, AD7758_REACT_PWR), 742 .address = AD7758_WT(AD7758_PHASE_B, AD7758_REACT_PWR),
767 .scan_index = 9, 743 .scan_index = 9,
768 .scan_type = { 744 .scan_type = {
@@ -774,9 +750,6 @@ static const struct iio_chan_spec ade7758_channels[] = {
774 .type = IIO_VOLTAGE, 750 .type = IIO_VOLTAGE,
775 .indexed = 1, 751 .indexed = 1,
776 .channel = 2, 752 .channel = 2,
777 .extend_name = "raw",
778 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
779 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
780 .address = AD7758_WT(AD7758_PHASE_C, AD7758_VOLTAGE), 753 .address = AD7758_WT(AD7758_PHASE_C, AD7758_VOLTAGE),
781 .scan_index = 10, 754 .scan_index = 10,
782 .scan_type = { 755 .scan_type = {
@@ -788,9 +761,6 @@ static const struct iio_chan_spec ade7758_channels[] = {
788 .type = IIO_CURRENT, 761 .type = IIO_CURRENT,
789 .indexed = 1, 762 .indexed = 1,
790 .channel = 2, 763 .channel = 2,
791 .extend_name = "raw",
792 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
793 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
794 .address = AD7758_WT(AD7758_PHASE_C, AD7758_CURRENT), 764 .address = AD7758_WT(AD7758_PHASE_C, AD7758_CURRENT),
795 .scan_index = 11, 765 .scan_index = 11,
796 .scan_type = { 766 .scan_type = {
@@ -802,9 +772,7 @@ static const struct iio_chan_spec ade7758_channels[] = {
802 .type = IIO_POWER, 772 .type = IIO_POWER,
803 .indexed = 1, 773 .indexed = 1,
804 .channel = 2, 774 .channel = 2,
805 .extend_name = "apparent_raw", 775 .extend_name = "apparent",
806 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
807 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
808 .address = AD7758_WT(AD7758_PHASE_C, AD7758_APP_PWR), 776 .address = AD7758_WT(AD7758_PHASE_C, AD7758_APP_PWR),
809 .scan_index = 12, 777 .scan_index = 12,
810 .scan_type = { 778 .scan_type = {
@@ -816,9 +784,7 @@ static const struct iio_chan_spec ade7758_channels[] = {
816 .type = IIO_POWER, 784 .type = IIO_POWER,
817 .indexed = 1, 785 .indexed = 1,
818 .channel = 2, 786 .channel = 2,
819 .extend_name = "active_raw", 787 .extend_name = "active",
820 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
821 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
822 .address = AD7758_WT(AD7758_PHASE_C, AD7758_ACT_PWR), 788 .address = AD7758_WT(AD7758_PHASE_C, AD7758_ACT_PWR),
823 .scan_index = 13, 789 .scan_index = 13,
824 .scan_type = { 790 .scan_type = {
@@ -830,9 +796,7 @@ static const struct iio_chan_spec ade7758_channels[] = {
830 .type = IIO_POWER, 796 .type = IIO_POWER,
831 .indexed = 1, 797 .indexed = 1,
832 .channel = 2, 798 .channel = 2,
833 .extend_name = "reactive_raw", 799 .extend_name = "reactive",
834 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
835 .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
836 .address = AD7758_WT(AD7758_PHASE_C, AD7758_REACT_PWR), 800 .address = AD7758_WT(AD7758_PHASE_C, AD7758_REACT_PWR),
837 .scan_index = 14, 801 .scan_index = 14,
838 .scan_type = { 802 .scan_type = {
@@ -873,13 +837,14 @@ static int ade7758_probe(struct spi_device *spi)
873 goto error_free_rx; 837 goto error_free_rx;
874 } 838 }
875 st->us = spi; 839 st->us = spi;
876 st->ade7758_ring_channels = &ade7758_channels[0];
877 mutex_init(&st->buf_lock); 840 mutex_init(&st->buf_lock);
878 841
879 indio_dev->name = spi->dev.driver->name; 842 indio_dev->name = spi->dev.driver->name;
880 indio_dev->dev.parent = &spi->dev; 843 indio_dev->dev.parent = &spi->dev;
881 indio_dev->info = &ade7758_info; 844 indio_dev->info = &ade7758_info;
882 indio_dev->modes = INDIO_DIRECT_MODE; 845 indio_dev->modes = INDIO_DIRECT_MODE;
846 indio_dev->channels = ade7758_channels;
847 indio_dev->num_channels = ARRAY_SIZE(ade7758_channels);
883 848
884 ret = ade7758_configure_ring(indio_dev); 849 ret = ade7758_configure_ring(indio_dev);
885 if (ret) 850 if (ret)
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
index c0accf8cce93..6e9006490742 100644
--- a/drivers/staging/iio/meter/ade7758_ring.c
+++ b/drivers/staging/iio/meter/ade7758_ring.c
@@ -85,17 +85,16 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
85 **/ 85 **/
86static int ade7758_ring_preenable(struct iio_dev *indio_dev) 86static int ade7758_ring_preenable(struct iio_dev *indio_dev)
87{ 87{
88 struct ade7758_state *st = iio_priv(indio_dev);
89 unsigned channel; 88 unsigned channel;
90 89
91 if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength)) 90 if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
92 return -EINVAL; 91 return -EINVAL;
93 92
94 channel = find_first_bit(indio_dev->active_scan_mask, 93 channel = find_first_bit(indio_dev->active_scan_mask,
95 indio_dev->masklength); 94 indio_dev->masklength);
96 95
97 ade7758_write_waveform_type(&indio_dev->dev, 96 ade7758_write_waveform_type(&indio_dev->dev,
98 st->ade7758_ring_channels[channel].address); 97 indio_dev->channels[channel].address);
99 98
100 return 0; 99 return 0;
101} 100}
diff --git a/drivers/staging/rtl8188eu/core/rtw_cmd.c b/drivers/staging/rtl8188eu/core/rtw_cmd.c
index 9935e66935af..eddef9cd2e16 100644
--- a/drivers/staging/rtl8188eu/core/rtw_cmd.c
+++ b/drivers/staging/rtl8188eu/core/rtw_cmd.c
@@ -275,11 +275,11 @@ u8 rtw_sitesurvey_cmd(struct adapter *padapter, struct ndis_802_11_ssid *ssid,
275 if (check_fwstate(pmlmepriv, _FW_LINKED) == true) 275 if (check_fwstate(pmlmepriv, _FW_LINKED) == true)
276 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1); 276 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_SCAN, 1);
277 277
278 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 278 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
279 if (ph2c == NULL) 279 if (ph2c == NULL)
280 return _FAIL; 280 return _FAIL;
281 281
282 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_KERNEL); 282 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC);
283 if (psurveyPara == NULL) { 283 if (psurveyPara == NULL) {
284 kfree(ph2c); 284 kfree(ph2c);
285 return _FAIL; 285 return _FAIL;
@@ -405,7 +405,7 @@ u8 rtw_joinbss_cmd(struct adapter *padapter, struct wlan_network *pnetwork)
405 else 405 else
406 RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+Join cmd: SSid =[%s]\n", pmlmepriv->assoc_ssid.Ssid)); 406 RT_TRACE(_module_rtl871x_cmd_c_, _drv_notice_, ("+Join cmd: SSid =[%s]\n", pmlmepriv->assoc_ssid.Ssid));
407 407
408 pcmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 408 pcmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
409 if (pcmd == NULL) { 409 if (pcmd == NULL) {
410 res = _FAIL; 410 res = _FAIL;
411 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("rtw_joinbss_cmd: memory allocate for cmd_obj fail!!!\n")); 411 RT_TRACE(_module_rtl871x_cmd_c_, _drv_err_, ("rtw_joinbss_cmd: memory allocate for cmd_obj fail!!!\n"));
@@ -755,13 +755,13 @@ u8 rtw_dynamic_chk_wk_cmd(struct adapter *padapter)
755 u8 res = _SUCCESS; 755 u8 res = _SUCCESS;
756 756
757 757
758 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 758 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
759 if (ph2c == NULL) { 759 if (ph2c == NULL) {
760 res = _FAIL; 760 res = _FAIL;
761 goto exit; 761 goto exit;
762 } 762 }
763 763
764 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); 764 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
765 if (pdrvextra_cmd_parm == NULL) { 765 if (pdrvextra_cmd_parm == NULL) {
766 kfree(ph2c); 766 kfree(ph2c);
767 res = _FAIL; 767 res = _FAIL;
@@ -967,13 +967,13 @@ u8 rtw_lps_ctrl_wk_cmd(struct adapter *padapter, u8 lps_ctrl_type, u8 enqueue)
967 u8 res = _SUCCESS; 967 u8 res = _SUCCESS;
968 968
969 if (enqueue) { 969 if (enqueue) {
970 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 970 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
971 if (ph2c == NULL) { 971 if (ph2c == NULL) {
972 res = _FAIL; 972 res = _FAIL;
973 goto exit; 973 goto exit;
974 } 974 }
975 975
976 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); 976 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
977 if (pdrvextra_cmd_parm == NULL) { 977 if (pdrvextra_cmd_parm == NULL) {
978 kfree(ph2c); 978 kfree(ph2c);
979 res = _FAIL; 979 res = _FAIL;
@@ -1010,13 +1010,13 @@ u8 rtw_rpt_timer_cfg_cmd(struct adapter *padapter, u16 min_time)
1010 1010
1011 u8 res = _SUCCESS; 1011 u8 res = _SUCCESS;
1012 1012
1013 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 1013 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1014 if (ph2c == NULL) { 1014 if (ph2c == NULL) {
1015 res = _FAIL; 1015 res = _FAIL;
1016 goto exit; 1016 goto exit;
1017 } 1017 }
1018 1018
1019 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); 1019 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
1020 if (pdrvextra_cmd_parm == NULL) { 1020 if (pdrvextra_cmd_parm == NULL) {
1021 kfree(ph2c); 1021 kfree(ph2c);
1022 res = _FAIL; 1022 res = _FAIL;
@@ -1088,13 +1088,13 @@ u8 rtw_ps_cmd(struct adapter *padapter)
1088 1088
1089 u8 res = _SUCCESS; 1089 u8 res = _SUCCESS;
1090 1090
1091 ppscmd = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 1091 ppscmd = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
1092 if (ppscmd == NULL) { 1092 if (ppscmd == NULL) {
1093 res = _FAIL; 1093 res = _FAIL;
1094 goto exit; 1094 goto exit;
1095 } 1095 }
1096 1096
1097 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_KERNEL); 1097 pdrvextra_cmd_parm = kzalloc(sizeof(struct drvextra_cmd_parm), GFP_ATOMIC);
1098 if (pdrvextra_cmd_parm == NULL) { 1098 if (pdrvextra_cmd_parm == NULL) {
1099 kfree(ppscmd); 1099 kfree(ppscmd);
1100 res = _FAIL; 1100 res = _FAIL;
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index 5ba5099ec20d..70b1bc3e0e63 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -4241,12 +4241,12 @@ void report_survey_event(struct adapter *padapter,
4241 pcmdpriv = &padapter->cmdpriv; 4241 pcmdpriv = &padapter->cmdpriv;
4242 4242
4243 4243
4244 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 4244 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
4245 if (pcmd_obj == NULL) 4245 if (pcmd_obj == NULL)
4246 return; 4246 return;
4247 4247
4248 cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header)); 4248 cmdsz = (sizeof(struct survey_event) + sizeof(struct C2HEvent_Header));
4249 pevtcmd = kzalloc(cmdsz, GFP_KERNEL); 4249 pevtcmd = kzalloc(cmdsz, GFP_ATOMIC);
4250 if (pevtcmd == NULL) { 4250 if (pevtcmd == NULL) {
4251 kfree(pcmd_obj); 4251 kfree(pcmd_obj);
4252 return; 4252 return;
@@ -4339,12 +4339,12 @@ void report_join_res(struct adapter *padapter, int res)
4339 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info); 4339 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
4340 struct cmd_priv *pcmdpriv = &padapter->cmdpriv; 4340 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
4341 4341
4342 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 4342 pcmd_obj = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
4343 if (pcmd_obj == NULL) 4343 if (pcmd_obj == NULL)
4344 return; 4344 return;
4345 4345
4346 cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header)); 4346 cmdsz = (sizeof(struct joinbss_event) + sizeof(struct C2HEvent_Header));
4347 pevtcmd = kzalloc(cmdsz, GFP_KERNEL); 4347 pevtcmd = kzalloc(cmdsz, GFP_ATOMIC);
4348 if (pevtcmd == NULL) { 4348 if (pevtcmd == NULL) {
4349 kfree(pcmd_obj); 4349 kfree(pcmd_obj);
4350 return; 4350 return;
@@ -4854,11 +4854,11 @@ void survey_timer_hdl(void *function_context)
4854 pmlmeext->scan_abort = false;/* reset */ 4854 pmlmeext->scan_abort = false;/* reset */
4855 } 4855 }
4856 4856
4857 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_KERNEL); 4857 ph2c = kzalloc(sizeof(struct cmd_obj), GFP_ATOMIC);
4858 if (ph2c == NULL) 4858 if (ph2c == NULL)
4859 goto exit_survey_timer_hdl; 4859 goto exit_survey_timer_hdl;
4860 4860
4861 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_KERNEL); 4861 psurveyPara = kzalloc(sizeof(struct sitesurvey_parm), GFP_ATOMIC);
4862 if (psurveyPara == NULL) { 4862 if (psurveyPara == NULL) {
4863 kfree(ph2c); 4863 kfree(ph2c);
4864 goto exit_survey_timer_hdl; 4864 goto exit_survey_timer_hdl;
diff --git a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
index 33ccbbbd8ed6..d300369977fa 100644
--- a/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
+++ b/drivers/staging/rtl8188eu/core/rtw_wlan_util.c
@@ -935,7 +935,7 @@ int rtw_check_bcn_info(struct adapter *Adapter, u8 *pframe, u32 packet_len)
935 return true; 935 return true;
936 } 936 }
937 937
938 bssid = kzalloc(sizeof(struct wlan_bssid_ex), GFP_KERNEL); 938 bssid = kzalloc(sizeof(struct wlan_bssid_ex), GFP_ATOMIC);
939 939
940 subtype = GetFrameSubType(pframe) >> 4; 940 subtype = GetFrameSubType(pframe) >> 4;
941 941
diff --git a/drivers/staging/rtl8188eu/os_dep/usb_intf.c b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
index 407a318b09db..2f87150a21b7 100644
--- a/drivers/staging/rtl8188eu/os_dep/usb_intf.c
+++ b/drivers/staging/rtl8188eu/os_dep/usb_intf.c
@@ -47,6 +47,7 @@ static struct usb_device_id rtw_usb_id_tbl[] = {
47 {USB_DEVICE(0x07b8, 0x8179)}, /* Abocom - Abocom */ 47 {USB_DEVICE(0x07b8, 0x8179)}, /* Abocom - Abocom */
48 {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */ 48 {USB_DEVICE(0x2001, 0x330F)}, /* DLink DWA-125 REV D1 */
49 {USB_DEVICE(0x2001, 0x3310)}, /* Dlink DWA-123 REV D1 */ 49 {USB_DEVICE(0x2001, 0x3310)}, /* Dlink DWA-123 REV D1 */
50 {USB_DEVICE(0x2001, 0x3311)}, /* DLink GO-USB-N150 REV B1 */
50 {USB_DEVICE(0x0df6, 0x0076)}, /* Sitecom N150 v2 */ 51 {USB_DEVICE(0x0df6, 0x0076)}, /* Sitecom N150 v2 */
51 {} /* Terminating entry */ 52 {} /* Terminating entry */
52}; 53};
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index b19e4329ba00..73e58d22e325 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -3491,7 +3491,7 @@ iscsit_build_sendtargets_response(struct iscsi_cmd *cmd,
3491 len = sprintf(buf, "TargetAddress=" 3491 len = sprintf(buf, "TargetAddress="
3492 "%s:%hu,%hu", 3492 "%s:%hu,%hu",
3493 inaddr_any ? conn->local_ip : np->np_ip, 3493 inaddr_any ? conn->local_ip : np->np_ip,
3494 inaddr_any ? conn->local_port : np->np_port, 3494 np->np_port,
3495 tpg->tpgt); 3495 tpg->tpgt);
3496 len += 1; 3496 len += 1;
3497 3497
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index ab3ab27d49b7..4d1b7224a7f2 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -110,58 +110,6 @@ static struct device_driver tcm_loop_driverfs = {
110 */ 110 */
111struct device *tcm_loop_primary; 111struct device *tcm_loop_primary;
112 112
113/*
114 * Copied from drivers/scsi/libfc/fc_fcp.c:fc_change_queue_depth() and
115 * drivers/scsi/libiscsi.c:iscsi_change_queue_depth()
116 */
117static int tcm_loop_change_queue_depth(
118 struct scsi_device *sdev,
119 int depth,
120 int reason)
121{
122 switch (reason) {
123 case SCSI_QDEPTH_DEFAULT:
124 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
125 break;
126 case SCSI_QDEPTH_QFULL:
127 scsi_track_queue_full(sdev, depth);
128 break;
129 case SCSI_QDEPTH_RAMP_UP:
130 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
131 break;
132 default:
133 return -EOPNOTSUPP;
134 }
135 return sdev->queue_depth;
136}
137
138static int tcm_loop_change_queue_type(struct scsi_device *sdev, int tag)
139{
140 if (sdev->tagged_supported) {
141 scsi_set_tag_type(sdev, tag);
142
143 if (tag)
144 scsi_activate_tcq(sdev, sdev->queue_depth);
145 else
146 scsi_deactivate_tcq(sdev, sdev->queue_depth);
147 } else
148 tag = 0;
149
150 return tag;
151}
152
153/*
154 * Locate the SAM Task Attr from struct scsi_cmnd *
155 */
156static int tcm_loop_sam_attr(struct scsi_cmnd *sc, int tag)
157{
158 if (sc->device->tagged_supported &&
159 sc->device->ordered_tags && tag >= 0)
160 return MSG_ORDERED_TAG;
161
162 return MSG_SIMPLE_TAG;
163}
164
165static void tcm_loop_submission_work(struct work_struct *work) 113static void tcm_loop_submission_work(struct work_struct *work)
166{ 114{
167 struct tcm_loop_cmd *tl_cmd = 115 struct tcm_loop_cmd *tl_cmd =
@@ -220,7 +168,7 @@ static void tcm_loop_submission_work(struct work_struct *work)
220 168
221 rc = target_submit_cmd_map_sgls(se_cmd, tl_nexus->se_sess, sc->cmnd, 169 rc = target_submit_cmd_map_sgls(se_cmd, tl_nexus->se_sess, sc->cmnd,
222 &tl_cmd->tl_sense_buf[0], tl_cmd->sc->device->lun, 170 &tl_cmd->tl_sense_buf[0], tl_cmd->sc->device->lun,
223 transfer_length, tcm_loop_sam_attr(sc, tl_cmd->sc_cmd_tag), 171 transfer_length, MSG_SIMPLE_TAG,
224 sc->sc_data_direction, 0, 172 sc->sc_data_direction, 0,
225 scsi_sglist(sc), scsi_sg_count(sc), 173 scsi_sglist(sc), scsi_sg_count(sc),
226 sgl_bidi, sgl_bidi_count, 174 sgl_bidi, sgl_bidi_count,
@@ -431,27 +379,13 @@ static int tcm_loop_slave_alloc(struct scsi_device *sd)
431 return 0; 379 return 0;
432} 380}
433 381
434static int tcm_loop_slave_configure(struct scsi_device *sd)
435{
436 if (sd->tagged_supported) {
437 scsi_activate_tcq(sd, sd->queue_depth);
438 scsi_adjust_queue_depth(sd, MSG_SIMPLE_TAG,
439 sd->host->cmd_per_lun);
440 } else {
441 scsi_adjust_queue_depth(sd, 0,
442 sd->host->cmd_per_lun);
443 }
444
445 return 0;
446}
447
448static struct scsi_host_template tcm_loop_driver_template = { 382static struct scsi_host_template tcm_loop_driver_template = {
449 .show_info = tcm_loop_show_info, 383 .show_info = tcm_loop_show_info,
450 .proc_name = "tcm_loopback", 384 .proc_name = "tcm_loopback",
451 .name = "TCM_Loopback", 385 .name = "TCM_Loopback",
452 .queuecommand = tcm_loop_queuecommand, 386 .queuecommand = tcm_loop_queuecommand,
453 .change_queue_depth = tcm_loop_change_queue_depth, 387 .change_queue_depth = scsi_change_queue_depth,
454 .change_queue_type = tcm_loop_change_queue_type, 388 .change_queue_type = scsi_change_queue_type,
455 .eh_abort_handler = tcm_loop_abort_task, 389 .eh_abort_handler = tcm_loop_abort_task,
456 .eh_device_reset_handler = tcm_loop_device_reset, 390 .eh_device_reset_handler = tcm_loop_device_reset,
457 .eh_target_reset_handler = tcm_loop_target_reset, 391 .eh_target_reset_handler = tcm_loop_target_reset,
@@ -462,8 +396,9 @@ static struct scsi_host_template tcm_loop_driver_template = {
462 .max_sectors = 0xFFFF, 396 .max_sectors = 0xFFFF,
463 .use_clustering = DISABLE_CLUSTERING, 397 .use_clustering = DISABLE_CLUSTERING,
464 .slave_alloc = tcm_loop_slave_alloc, 398 .slave_alloc = tcm_loop_slave_alloc,
465 .slave_configure = tcm_loop_slave_configure,
466 .module = THIS_MODULE, 399 .module = THIS_MODULE,
400 .use_blk_tags = 1,
401 .track_queue_depth = 1,
467}; 402};
468 403
469static int tcm_loop_driver_probe(struct device *dev) 404static int tcm_loop_driver_probe(struct device *dev)
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index fb87780929d2..75cbde1f7c5b 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -576,7 +576,7 @@ static inline int core_alua_state_standby(
576 case SEND_DIAGNOSTIC: 576 case SEND_DIAGNOSTIC:
577 case READ_CAPACITY: 577 case READ_CAPACITY:
578 return 0; 578 return 0;
579 case SERVICE_ACTION_IN: 579 case SERVICE_ACTION_IN_16:
580 switch (cdb[1] & 0x1f) { 580 switch (cdb[1] & 0x1f) {
581 case SAI_READ_CAPACITY_16: 581 case SAI_READ_CAPACITY_16:
582 return 0; 582 return 0;
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 8c60a1a1ae8d..4c261c33cf55 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -459,7 +459,7 @@ static int core_scsi3_pr_seq_non_holder(
459 case ACCESS_CONTROL_OUT: 459 case ACCESS_CONTROL_OUT:
460 case INQUIRY: 460 case INQUIRY:
461 case LOG_SENSE: 461 case LOG_SENSE:
462 case READ_MEDIA_SERIAL_NUMBER: 462 case SERVICE_ACTION_IN_12:
463 case REPORT_LUNS: 463 case REPORT_LUNS:
464 case REQUEST_SENSE: 464 case REQUEST_SENSE:
465 case PERSISTENT_RESERVE_IN: 465 case PERSISTENT_RESERVE_IN:
@@ -2738,7 +2738,8 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2738 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_reg_n, *pr_res_holder; 2738 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_reg_n, *pr_res_holder;
2739 struct t10_reservation *pr_tmpl = &dev->t10_pr; 2739 struct t10_reservation *pr_tmpl = &dev->t10_pr;
2740 u32 pr_res_mapped_lun = 0; 2740 u32 pr_res_mapped_lun = 0;
2741 int all_reg = 0, calling_it_nexus = 0, released_regs = 0; 2741 int all_reg = 0, calling_it_nexus = 0;
2742 bool sa_res_key_unmatched = sa_res_key != 0;
2742 int prh_type = 0, prh_scope = 0; 2743 int prh_type = 0, prh_scope = 0;
2743 2744
2744 if (!se_sess) 2745 if (!se_sess)
@@ -2813,6 +2814,7 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2813 if (!all_reg) { 2814 if (!all_reg) {
2814 if (pr_reg->pr_res_key != sa_res_key) 2815 if (pr_reg->pr_res_key != sa_res_key)
2815 continue; 2816 continue;
2817 sa_res_key_unmatched = false;
2816 2818
2817 calling_it_nexus = (pr_reg_n == pr_reg) ? 1 : 0; 2819 calling_it_nexus = (pr_reg_n == pr_reg) ? 1 : 0;
2818 pr_reg_nacl = pr_reg->pr_reg_nacl; 2820 pr_reg_nacl = pr_reg->pr_reg_nacl;
@@ -2820,7 +2822,6 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2820 __core_scsi3_free_registration(dev, pr_reg, 2822 __core_scsi3_free_registration(dev, pr_reg,
2821 (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list : 2823 (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list :
2822 NULL, calling_it_nexus); 2824 NULL, calling_it_nexus);
2823 released_regs++;
2824 } else { 2825 } else {
2825 /* 2826 /*
2826 * Case for any existing all registrants type 2827 * Case for any existing all registrants type
@@ -2838,6 +2839,7 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2838 if ((sa_res_key) && 2839 if ((sa_res_key) &&
2839 (pr_reg->pr_res_key != sa_res_key)) 2840 (pr_reg->pr_res_key != sa_res_key))
2840 continue; 2841 continue;
2842 sa_res_key_unmatched = false;
2841 2843
2842 calling_it_nexus = (pr_reg_n == pr_reg) ? 1 : 0; 2844 calling_it_nexus = (pr_reg_n == pr_reg) ? 1 : 0;
2843 if (calling_it_nexus) 2845 if (calling_it_nexus)
@@ -2848,7 +2850,6 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2848 __core_scsi3_free_registration(dev, pr_reg, 2850 __core_scsi3_free_registration(dev, pr_reg,
2849 (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list : 2851 (preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list :
2850 NULL, 0); 2852 NULL, 0);
2851 released_regs++;
2852 } 2853 }
2853 if (!calling_it_nexus) 2854 if (!calling_it_nexus)
2854 core_scsi3_ua_allocate(pr_reg_nacl, 2855 core_scsi3_ua_allocate(pr_reg_nacl,
@@ -2863,7 +2864,7 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
2863 * registered reservation key, then the device server shall 2864 * registered reservation key, then the device server shall
2864 * complete the command with RESERVATION CONFLICT status. 2865 * complete the command with RESERVATION CONFLICT status.
2865 */ 2866 */
2866 if (!released_regs) { 2867 if (sa_res_key_unmatched) {
2867 spin_unlock(&dev->dev_reservation_lock); 2868 spin_unlock(&dev->dev_reservation_lock);
2868 core_scsi3_put_pr_reg(pr_reg_n); 2869 core_scsi3_put_pr_reg(pr_reg_n);
2869 return TCM_RESERVATION_CONFLICT; 2870 return TCM_RESERVATION_CONFLICT;
diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index ebe62afb957d..8d171ff77e75 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -852,7 +852,7 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
852 size = READ_CAP_LEN; 852 size = READ_CAP_LEN;
853 cmd->execute_cmd = sbc_emulate_readcapacity; 853 cmd->execute_cmd = sbc_emulate_readcapacity;
854 break; 854 break;
855 case SERVICE_ACTION_IN: 855 case SERVICE_ACTION_IN_16:
856 switch (cmd->t_task_cdb[1] & 0x1f) { 856 switch (cmd->t_task_cdb[1] & 0x1f) {
857 case SAI_READ_CAPACITY_16: 857 case SAI_READ_CAPACITY_16:
858 cmd->execute_cmd = sbc_emulate_readcapacity_16; 858 cmd->execute_cmd = sbc_emulate_readcapacity_16;
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 9ea0d5f03f7a..be877bf6f730 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -2292,7 +2292,7 @@ transport_generic_new_cmd(struct se_cmd *cmd)
2292 * and let it call back once the write buffers are ready. 2292 * and let it call back once the write buffers are ready.
2293 */ 2293 */
2294 target_add_to_state_list(cmd); 2294 target_add_to_state_list(cmd);
2295 if (cmd->data_direction != DMA_TO_DEVICE) { 2295 if (cmd->data_direction != DMA_TO_DEVICE || cmd->data_length == 0) {
2296 target_execute_cmd(cmd); 2296 target_execute_cmd(cmd);
2297 return 0; 2297 return 0;
2298 } 2298 }
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 1ab0018271c5..ad09e51ffae4 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -50,15 +50,14 @@ struct cpufreq_cooling_device {
50 unsigned int cpufreq_state; 50 unsigned int cpufreq_state;
51 unsigned int cpufreq_val; 51 unsigned int cpufreq_val;
52 struct cpumask allowed_cpus; 52 struct cpumask allowed_cpus;
53 struct list_head node;
53}; 54};
54static DEFINE_IDR(cpufreq_idr); 55static DEFINE_IDR(cpufreq_idr);
55static DEFINE_MUTEX(cooling_cpufreq_lock); 56static DEFINE_MUTEX(cooling_cpufreq_lock);
56 57
57static unsigned int cpufreq_dev_count; 58static unsigned int cpufreq_dev_count;
58 59
59/* notify_table passes value to the CPUFREQ_ADJUST callback function. */ 60static LIST_HEAD(cpufreq_dev_list);
60#define NOTIFY_INVALID NULL
61static struct cpufreq_cooling_device *notify_device;
62 61
63/** 62/**
64 * get_idr - function to get a unique id. 63 * get_idr - function to get a unique id.
@@ -287,15 +286,12 @@ static int cpufreq_apply_cooling(struct cpufreq_cooling_device *cpufreq_device,
287 286
288 cpufreq_device->cpufreq_state = cooling_state; 287 cpufreq_device->cpufreq_state = cooling_state;
289 cpufreq_device->cpufreq_val = clip_freq; 288 cpufreq_device->cpufreq_val = clip_freq;
290 notify_device = cpufreq_device;
291 289
292 for_each_cpu(cpuid, mask) { 290 for_each_cpu(cpuid, mask) {
293 if (is_cpufreq_valid(cpuid)) 291 if (is_cpufreq_valid(cpuid))
294 cpufreq_update_policy(cpuid); 292 cpufreq_update_policy(cpuid);
295 } 293 }
296 294
297 notify_device = NOTIFY_INVALID;
298
299 return 0; 295 return 0;
300} 296}
301 297
@@ -316,21 +312,28 @@ static int cpufreq_thermal_notifier(struct notifier_block *nb,
316{ 312{
317 struct cpufreq_policy *policy = data; 313 struct cpufreq_policy *policy = data;
318 unsigned long max_freq = 0; 314 unsigned long max_freq = 0;
315 struct cpufreq_cooling_device *cpufreq_dev;
319 316
320 if (event != CPUFREQ_ADJUST || notify_device == NOTIFY_INVALID) 317 if (event != CPUFREQ_ADJUST)
321 return 0; 318 return 0;
322 319
323 if (cpumask_test_cpu(policy->cpu, &notify_device->allowed_cpus)) 320 mutex_lock(&cooling_cpufreq_lock);
324 max_freq = notify_device->cpufreq_val; 321 list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) {
325 else 322 if (!cpumask_test_cpu(policy->cpu,
326 return 0; 323 &cpufreq_dev->allowed_cpus))
324 continue;
325
326 if (!cpufreq_dev->cpufreq_val)
327 cpufreq_dev->cpufreq_val = get_cpu_frequency(
328 cpumask_any(&cpufreq_dev->allowed_cpus),
329 cpufreq_dev->cpufreq_state);
327 330
328 /* Never exceed user_policy.max */ 331 max_freq = cpufreq_dev->cpufreq_val;
329 if (max_freq > policy->user_policy.max)
330 max_freq = policy->user_policy.max;
331 332
332 if (policy->max != max_freq) 333 if (policy->max != max_freq)
333 cpufreq_verify_within_limits(policy, 0, max_freq); 334 cpufreq_verify_within_limits(policy, 0, max_freq);
335 }
336 mutex_unlock(&cooling_cpufreq_lock);
334 337
335 return 0; 338 return 0;
336} 339}
@@ -486,6 +489,7 @@ __cpufreq_cooling_register(struct device_node *np,
486 cpufreq_register_notifier(&thermal_cpufreq_notifier_block, 489 cpufreq_register_notifier(&thermal_cpufreq_notifier_block,
487 CPUFREQ_POLICY_NOTIFIER); 490 CPUFREQ_POLICY_NOTIFIER);
488 cpufreq_dev_count++; 491 cpufreq_dev_count++;
492 list_add(&cpufreq_dev->node, &cpufreq_dev_list);
489 493
490 mutex_unlock(&cooling_cpufreq_lock); 494 mutex_unlock(&cooling_cpufreq_lock);
491 495
@@ -549,6 +553,7 @@ void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
549 553
550 cpufreq_dev = cdev->devdata; 554 cpufreq_dev = cdev->devdata;
551 mutex_lock(&cooling_cpufreq_lock); 555 mutex_lock(&cooling_cpufreq_lock);
556 list_del(&cpufreq_dev->node);
552 cpufreq_dev_count--; 557 cpufreq_dev_count--;
553 558
554 /* Unregister the notifier for the last cpufreq cooling device */ 559 /* Unregister the notifier for the last cpufreq cooling device */
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c
index 461bf3d033a0..5a1f1070b702 100644
--- a/drivers/thermal/imx_thermal.c
+++ b/drivers/thermal/imx_thermal.c
@@ -459,6 +459,10 @@ static int imx_thermal_probe(struct platform_device *pdev)
459 int measure_freq; 459 int measure_freq;
460 int ret; 460 int ret;
461 461
462 if (!cpufreq_get_current_driver()) {
463 dev_dbg(&pdev->dev, "no cpufreq driver!");
464 return -EPROBE_DEFER;
465 }
462 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); 466 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
463 if (!data) 467 if (!data)
464 return -ENOMEM; 468 return -ENOMEM;
@@ -521,6 +525,30 @@ static int imx_thermal_probe(struct platform_device *pdev)
521 return ret; 525 return ret;
522 } 526 }
523 527
528 data->thermal_clk = devm_clk_get(&pdev->dev, NULL);
529 if (IS_ERR(data->thermal_clk)) {
530 ret = PTR_ERR(data->thermal_clk);
531 if (ret != -EPROBE_DEFER)
532 dev_err(&pdev->dev,
533 "failed to get thermal clk: %d\n", ret);
534 cpufreq_cooling_unregister(data->cdev);
535 return ret;
536 }
537
538 /*
539 * Thermal sensor needs clk on to get correct value, normally
540 * we should enable its clk before taking measurement and disable
541 * clk after measurement is done, but if alarm function is enabled,
542 * hardware will auto measure the temperature periodically, so we
543 * need to keep the clk always on for alarm function.
544 */
545 ret = clk_prepare_enable(data->thermal_clk);
546 if (ret) {
547 dev_err(&pdev->dev, "failed to enable thermal clk: %d\n", ret);
548 cpufreq_cooling_unregister(data->cdev);
549 return ret;
550 }
551
524 data->tz = thermal_zone_device_register("imx_thermal_zone", 552 data->tz = thermal_zone_device_register("imx_thermal_zone",
525 IMX_TRIP_NUM, 553 IMX_TRIP_NUM,
526 BIT(IMX_TRIP_PASSIVE), data, 554 BIT(IMX_TRIP_PASSIVE), data,
@@ -531,26 +559,11 @@ static int imx_thermal_probe(struct platform_device *pdev)
531 ret = PTR_ERR(data->tz); 559 ret = PTR_ERR(data->tz);
532 dev_err(&pdev->dev, 560 dev_err(&pdev->dev,
533 "failed to register thermal zone device %d\n", ret); 561 "failed to register thermal zone device %d\n", ret);
562 clk_disable_unprepare(data->thermal_clk);
534 cpufreq_cooling_unregister(data->cdev); 563 cpufreq_cooling_unregister(data->cdev);
535 return ret; 564 return ret;
536 } 565 }
537 566
538 data->thermal_clk = devm_clk_get(&pdev->dev, NULL);
539 if (IS_ERR(data->thermal_clk)) {
540 dev_warn(&pdev->dev, "failed to get thermal clk!\n");
541 } else {
542 /*
543 * Thermal sensor needs clk on to get correct value, normally
544 * we should enable its clk before taking measurement and disable
545 * clk after measurement is done, but if alarm function is enabled,
546 * hardware will auto measure the temperature periodically, so we
547 * need to keep the clk always on for alarm function.
548 */
549 ret = clk_prepare_enable(data->thermal_clk);
550 if (ret)
551 dev_warn(&pdev->dev, "failed to enable thermal clk: %d\n", ret);
552 }
553
554 /* Enable measurements at ~ 10 Hz */ 567 /* Enable measurements at ~ 10 Hz */
555 regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ); 568 regmap_write(map, TEMPSENSE1 + REG_CLR, TEMPSENSE1_MEASURE_FREQ);
556 measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */ 569 measure_freq = DIV_ROUND_UP(32768, 10); /* 10 Hz */
diff --git a/drivers/thermal/int340x_thermal/int3403_thermal.c b/drivers/thermal/int340x_thermal/int3403_thermal.c
index d20dba986f0f..6e9fb62eb817 100644
--- a/drivers/thermal/int340x_thermal/int3403_thermal.c
+++ b/drivers/thermal/int340x_thermal/int3403_thermal.c
@@ -92,7 +92,13 @@ static int sys_get_trip_hyst(struct thermal_zone_device *tzone,
92 if (ACPI_FAILURE(status)) 92 if (ACPI_FAILURE(status))
93 return -EIO; 93 return -EIO;
94 94
95 *temp = DECI_KELVIN_TO_MILLI_CELSIUS(hyst, KELVIN_OFFSET); 95 /*
96 * Thermal hysteresis represents a temperature difference.
97 * Kelvin and Celsius have same degree size. So the
98 * conversion here between tenths of degree Kelvin unit
99 * and Milli-Celsius unit is just to multiply 100.
100 */
101 *temp = hyst * 100;
96 102
97 return 0; 103 return 0;
98} 104}
diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index f8eb625b8400..62143ba31001 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -387,15 +387,18 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id,
387 int (*get_trend)(void *, long *)) 387 int (*get_trend)(void *, long *))
388{ 388{
389 struct device_node *np, *child, *sensor_np; 389 struct device_node *np, *child, *sensor_np;
390 struct thermal_zone_device *tzd = ERR_PTR(-ENODEV);
390 391
391 np = of_find_node_by_name(NULL, "thermal-zones"); 392 np = of_find_node_by_name(NULL, "thermal-zones");
392 if (!np) 393 if (!np)
393 return ERR_PTR(-ENODEV); 394 return ERR_PTR(-ENODEV);
394 395
395 if (!dev || !dev->of_node) 396 if (!dev || !dev->of_node) {
397 of_node_put(np);
396 return ERR_PTR(-EINVAL); 398 return ERR_PTR(-EINVAL);
399 }
397 400
398 sensor_np = dev->of_node; 401 sensor_np = of_node_get(dev->of_node);
399 402
400 for_each_child_of_node(np, child) { 403 for_each_child_of_node(np, child) {
401 struct of_phandle_args sensor_specs; 404 struct of_phandle_args sensor_specs;
@@ -422,16 +425,21 @@ thermal_zone_of_sensor_register(struct device *dev, int sensor_id,
422 } 425 }
423 426
424 if (sensor_specs.np == sensor_np && id == sensor_id) { 427 if (sensor_specs.np == sensor_np && id == sensor_id) {
425 of_node_put(np); 428 tzd = thermal_zone_of_add_sensor(child, sensor_np,
426 return thermal_zone_of_add_sensor(child, sensor_np, 429 data,
427 data, 430 get_temp,
428 get_temp, 431 get_trend);
429 get_trend); 432 of_node_put(sensor_specs.np);
433 of_node_put(child);
434 goto exit;
430 } 435 }
436 of_node_put(sensor_specs.np);
431 } 437 }
438exit:
439 of_node_put(sensor_np);
432 of_node_put(np); 440 of_node_put(np);
433 441
434 return ERR_PTR(-ENODEV); 442 return tzd;
435} 443}
436EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_register); 444EXPORT_SYMBOL_GPL(thermal_zone_of_sensor_register);
437 445
@@ -623,6 +631,7 @@ static int thermal_of_populate_trip(struct device_node *np,
623 631
624 /* Required for cooling map matching */ 632 /* Required for cooling map matching */
625 trip->np = np; 633 trip->np = np;
634 of_node_get(np);
626 635
627 return 0; 636 return 0;
628} 637}
@@ -730,9 +739,14 @@ finish:
730 return tz; 739 return tz;
731 740
732free_tbps: 741free_tbps:
742 for (i = 0; i < tz->num_tbps; i++)
743 of_node_put(tz->tbps[i].cooling_device);
733 kfree(tz->tbps); 744 kfree(tz->tbps);
734free_trips: 745free_trips:
746 for (i = 0; i < tz->ntrips; i++)
747 of_node_put(tz->trips[i].np);
735 kfree(tz->trips); 748 kfree(tz->trips);
749 of_node_put(gchild);
736free_tz: 750free_tz:
737 kfree(tz); 751 kfree(tz);
738 of_node_put(child); 752 of_node_put(child);
@@ -742,7 +756,13 @@ free_tz:
742 756
743static inline void of_thermal_free_zone(struct __thermal_zone *tz) 757static inline void of_thermal_free_zone(struct __thermal_zone *tz)
744{ 758{
759 int i;
760
761 for (i = 0; i < tz->num_tbps; i++)
762 of_node_put(tz->tbps[i].cooling_device);
745 kfree(tz->tbps); 763 kfree(tz->tbps);
764 for (i = 0; i < tz->ntrips; i++)
765 of_node_put(tz->trips[i].np);
746 kfree(tz->trips); 766 kfree(tz->trips);
747 kfree(tz); 767 kfree(tz);
748} 768}
@@ -814,10 +834,13 @@ int __init of_parse_thermal_zones(void)
814 /* attempting to build remaining zones still */ 834 /* attempting to build remaining zones still */
815 } 835 }
816 } 836 }
837 of_node_put(np);
817 838
818 return 0; 839 return 0;
819 840
820exit_free: 841exit_free:
842 of_node_put(child);
843 of_node_put(np);
821 of_thermal_free_zone(tz); 844 of_thermal_free_zone(tz);
822 845
823 /* no memory available, so free what we have built */ 846 /* no memory available, so free what we have built */
@@ -859,4 +882,5 @@ void of_thermal_destroy_zones(void)
859 kfree(zone->ops); 882 kfree(zone->ops);
860 of_thermal_free_zone(zone->devdata); 883 of_thermal_free_zone(zone->devdata);
861 } 884 }
885 of_node_put(np);
862} 886}
diff --git a/drivers/thermal/samsung/exynos_thermal_common.c b/drivers/thermal/samsung/exynos_thermal_common.c
index 3f5ad25ddca8..b6be572704a4 100644
--- a/drivers/thermal/samsung/exynos_thermal_common.c
+++ b/drivers/thermal/samsung/exynos_thermal_common.c
@@ -417,13 +417,10 @@ void exynos_unregister_thermal(struct thermal_sensor_conf *sensor_conf)
417 417
418 th_zone = sensor_conf->pzone_data; 418 th_zone = sensor_conf->pzone_data;
419 419
420 if (th_zone->therm_dev) 420 thermal_zone_device_unregister(th_zone->therm_dev);
421 thermal_zone_device_unregister(th_zone->therm_dev);
422 421
423 for (i = 0; i < th_zone->cool_dev_size; i++) { 422 for (i = 0; i < th_zone->cool_dev_size; ++i)
424 if (th_zone->cool_dev[i]) 423 cpufreq_cooling_unregister(th_zone->cool_dev[i]);
425 cpufreq_cooling_unregister(th_zone->cool_dev[i]);
426 }
427 424
428 dev_info(sensor_conf->dev, 425 dev_info(sensor_conf->dev,
429 "Exynos: Kernel Thermal management unregistered\n"); 426 "Exynos: Kernel Thermal management unregistered\n");
diff --git a/drivers/thermal/samsung/exynos_thermal_common.h b/drivers/thermal/samsung/exynos_thermal_common.h
index 3eb2ed9ea3a4..158f5aa8dc5d 100644
--- a/drivers/thermal/samsung/exynos_thermal_common.h
+++ b/drivers/thermal/samsung/exynos_thermal_common.h
@@ -27,7 +27,7 @@
27#define SENSOR_NAME_LEN 16 27#define SENSOR_NAME_LEN 16
28#define MAX_TRIP_COUNT 8 28#define MAX_TRIP_COUNT 8
29#define MAX_COOLING_DEVICE 4 29#define MAX_COOLING_DEVICE 4
30#define MAX_THRESHOLD_LEVS 5 30#define MAX_TRIMINFO_CTRL_REG 2
31 31
32#define ACTIVE_INTERVAL 500 32#define ACTIVE_INTERVAL 500
33#define IDLE_INTERVAL 10000 33#define IDLE_INTERVAL 10000
diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c
index acbff14da3a4..49c09243fd38 100644
--- a/drivers/thermal/samsung/exynos_tmu.c
+++ b/drivers/thermal/samsung/exynos_tmu.c
@@ -77,16 +77,6 @@ static int temp_to_code(struct exynos_tmu_data *data, u8 temp)
77 struct exynos_tmu_platform_data *pdata = data->pdata; 77 struct exynos_tmu_platform_data *pdata = data->pdata;
78 int temp_code; 78 int temp_code;
79 79
80 if (pdata->cal_mode == HW_MODE)
81 return temp;
82
83 if (data->soc == SOC_ARCH_EXYNOS4210)
84 /* temp should range between 25 and 125 */
85 if (temp < 25 || temp > 125) {
86 temp_code = -EINVAL;
87 goto out;
88 }
89
90 switch (pdata->cal_type) { 80 switch (pdata->cal_type) {
91 case TYPE_TWO_POINT_TRIMMING: 81 case TYPE_TWO_POINT_TRIMMING:
92 temp_code = (temp - pdata->first_point_trim) * 82 temp_code = (temp - pdata->first_point_trim) *
@@ -101,7 +91,7 @@ static int temp_to_code(struct exynos_tmu_data *data, u8 temp)
101 temp_code = temp + pdata->default_temp_offset; 91 temp_code = temp + pdata->default_temp_offset;
102 break; 92 break;
103 } 93 }
104out: 94
105 return temp_code; 95 return temp_code;
106} 96}
107 97
@@ -114,16 +104,6 @@ static int code_to_temp(struct exynos_tmu_data *data, u8 temp_code)
114 struct exynos_tmu_platform_data *pdata = data->pdata; 104 struct exynos_tmu_platform_data *pdata = data->pdata;
115 int temp; 105 int temp;
116 106
117 if (pdata->cal_mode == HW_MODE)
118 return temp_code;
119
120 if (data->soc == SOC_ARCH_EXYNOS4210)
121 /* temp_code should range between 75 and 175 */
122 if (temp_code < 75 || temp_code > 175) {
123 temp = -ENODATA;
124 goto out;
125 }
126
127 switch (pdata->cal_type) { 107 switch (pdata->cal_type) {
128 case TYPE_TWO_POINT_TRIMMING: 108 case TYPE_TWO_POINT_TRIMMING:
129 temp = (temp_code - data->temp_error1) * 109 temp = (temp_code - data->temp_error1) *
@@ -138,18 +118,35 @@ static int code_to_temp(struct exynos_tmu_data *data, u8 temp_code)
138 temp = temp_code - pdata->default_temp_offset; 118 temp = temp_code - pdata->default_temp_offset;
139 break; 119 break;
140 } 120 }
141out: 121
142 return temp; 122 return temp;
143} 123}
144 124
125static void exynos_tmu_clear_irqs(struct exynos_tmu_data *data)
126{
127 const struct exynos_tmu_registers *reg = data->pdata->registers;
128 unsigned int val_irq;
129
130 val_irq = readl(data->base + reg->tmu_intstat);
131 /*
132 * Clear the interrupts. Please note that the documentation for
133 * Exynos3250, Exynos4412, Exynos5250 and Exynos5260 incorrectly
134 * states that INTCLEAR register has a different placing of bits
135 * responsible for FALL IRQs than INTSTAT register. Exynos5420
136 * and Exynos5440 documentation is correct (Exynos4210 doesn't
137 * support FALL IRQs at all).
138 */
139 writel(val_irq, data->base + reg->tmu_intclear);
140}
141
145static int exynos_tmu_initialize(struct platform_device *pdev) 142static int exynos_tmu_initialize(struct platform_device *pdev)
146{ 143{
147 struct exynos_tmu_data *data = platform_get_drvdata(pdev); 144 struct exynos_tmu_data *data = platform_get_drvdata(pdev);
148 struct exynos_tmu_platform_data *pdata = data->pdata; 145 struct exynos_tmu_platform_data *pdata = data->pdata;
149 const struct exynos_tmu_registers *reg = pdata->registers; 146 const struct exynos_tmu_registers *reg = pdata->registers;
150 unsigned int status, trim_info = 0, con; 147 unsigned int status, trim_info = 0, con, ctrl;
151 unsigned int rising_threshold = 0, falling_threshold = 0; 148 unsigned int rising_threshold = 0, falling_threshold = 0;
152 int ret = 0, threshold_code, i, trigger_levs = 0; 149 int ret = 0, threshold_code, i;
153 150
154 mutex_lock(&data->lock); 151 mutex_lock(&data->lock);
155 clk_enable(data->clk); 152 clk_enable(data->clk);
@@ -164,11 +161,17 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
164 } 161 }
165 } 162 }
166 163
167 if (TMU_SUPPORTS(pdata, TRIM_RELOAD)) 164 if (TMU_SUPPORTS(pdata, TRIM_RELOAD)) {
168 __raw_writel(1, data->base + reg->triminfo_ctrl); 165 for (i = 0; i < reg->triminfo_ctrl_count; i++) {
169 166 if (pdata->triminfo_reload[i]) {
170 if (pdata->cal_mode == HW_MODE) 167 ctrl = readl(data->base +
171 goto skip_calib_data; 168 reg->triminfo_ctrl[i]);
169 ctrl |= pdata->triminfo_reload[i];
170 writel(ctrl, data->base +
171 reg->triminfo_ctrl[i]);
172 }
173 }
174 }
172 175
173 /* Save trimming info in order to perform calibration */ 176 /* Save trimming info in order to perform calibration */
174 if (data->soc == SOC_ARCH_EXYNOS5440) { 177 if (data->soc == SOC_ARCH_EXYNOS5440) {
@@ -197,7 +200,7 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
197 trim_info = readl(data->base + reg->triminfo_data); 200 trim_info = readl(data->base + reg->triminfo_data);
198 } 201 }
199 data->temp_error1 = trim_info & EXYNOS_TMU_TEMP_MASK; 202 data->temp_error1 = trim_info & EXYNOS_TMU_TEMP_MASK;
200 data->temp_error2 = ((trim_info >> reg->triminfo_85_shift) & 203 data->temp_error2 = ((trim_info >> EXYNOS_TRIMINFO_85_SHIFT) &
201 EXYNOS_TMU_TEMP_MASK); 204 EXYNOS_TMU_TEMP_MASK);
202 205
203 if (!data->temp_error1 || 206 if (!data->temp_error1 ||
@@ -207,67 +210,33 @@ static int exynos_tmu_initialize(struct platform_device *pdev)
207 210
208 if (!data->temp_error2) 211 if (!data->temp_error2)
209 data->temp_error2 = 212 data->temp_error2 =
210 (pdata->efuse_value >> reg->triminfo_85_shift) & 213 (pdata->efuse_value >> EXYNOS_TRIMINFO_85_SHIFT) &
211 EXYNOS_TMU_TEMP_MASK; 214 EXYNOS_TMU_TEMP_MASK;
212 215
213skip_calib_data:
214 if (pdata->max_trigger_level > MAX_THRESHOLD_LEVS) {
215 dev_err(&pdev->dev, "Invalid max trigger level\n");
216 ret = -EINVAL;
217 goto out;
218 }
219
220 for (i = 0; i < pdata->max_trigger_level; i++) {
221 if (!pdata->trigger_levels[i])
222 continue;
223
224 if ((pdata->trigger_type[i] == HW_TRIP) &&
225 (!pdata->trigger_levels[pdata->max_trigger_level - 1])) {
226 dev_err(&pdev->dev, "Invalid hw trigger level\n");
227 ret = -EINVAL;
228 goto out;
229 }
230
231 /* Count trigger levels except the HW trip*/
232 if (!(pdata->trigger_type[i] == HW_TRIP))
233 trigger_levs++;
234 }
235
236 rising_threshold = readl(data->base + reg->threshold_th0); 216 rising_threshold = readl(data->base + reg->threshold_th0);
237 217
238 if (data->soc == SOC_ARCH_EXYNOS4210) { 218 if (data->soc == SOC_ARCH_EXYNOS4210) {
239 /* Write temperature code for threshold */ 219 /* Write temperature code for threshold */
240 threshold_code = temp_to_code(data, pdata->threshold); 220 threshold_code = temp_to_code(data, pdata->threshold);
241 if (threshold_code < 0) {
242 ret = threshold_code;
243 goto out;
244 }
245 writeb(threshold_code, 221 writeb(threshold_code,
246 data->base + reg->threshold_temp); 222 data->base + reg->threshold_temp);
247 for (i = 0; i < trigger_levs; i++) 223 for (i = 0; i < pdata->non_hw_trigger_levels; i++)
248 writeb(pdata->trigger_levels[i], data->base + 224 writeb(pdata->trigger_levels[i], data->base +
249 reg->threshold_th0 + i * sizeof(reg->threshold_th0)); 225 reg->threshold_th0 + i * sizeof(reg->threshold_th0));
250 226
251 writel(reg->intclr_rise_mask, data->base + reg->tmu_intclear); 227 exynos_tmu_clear_irqs(data);
252 } else { 228 } else {
253 /* Write temperature code for rising and falling threshold */ 229 /* Write temperature code for rising and falling threshold */
254 for (i = 0; 230 for (i = 0; i < pdata->non_hw_trigger_levels; i++) {
255 i < trigger_levs && i < EXYNOS_MAX_TRIGGER_PER_REG; i++) {
256 threshold_code = temp_to_code(data, 231 threshold_code = temp_to_code(data,
257 pdata->trigger_levels[i]); 232 pdata->trigger_levels[i]);
258 if (threshold_code < 0) {
259 ret = threshold_code;
260 goto out;
261 }
262 rising_threshold &= ~(0xff << 8 * i); 233 rising_threshold &= ~(0xff << 8 * i);
263 rising_threshold |= threshold_code << 8 * i; 234 rising_threshold |= threshold_code << 8 * i;
264 if (pdata->threshold_falling) { 235 if (pdata->threshold_falling) {
265 threshold_code = temp_to_code(data, 236 threshold_code = temp_to_code(data,
266 pdata->trigger_levels[i] - 237 pdata->trigger_levels[i] -
267 pdata->threshold_falling); 238 pdata->threshold_falling);
268 if (threshold_code > 0) 239 falling_threshold |= threshold_code << 8 * i;
269 falling_threshold |=
270 threshold_code << 8 * i;
271 } 240 }
272 } 241 }
273 242
@@ -276,9 +245,7 @@ skip_calib_data:
276 writel(falling_threshold, 245 writel(falling_threshold,
277 data->base + reg->threshold_th1); 246 data->base + reg->threshold_th1);
278 247
279 writel((reg->intclr_rise_mask << reg->intclr_rise_shift) | 248 exynos_tmu_clear_irqs(data);
280 (reg->intclr_fall_mask << reg->intclr_fall_shift),
281 data->base + reg->tmu_intclear);
282 249
283 /* if last threshold limit is also present */ 250 /* if last threshold limit is also present */
284 i = pdata->max_trigger_level - 1; 251 i = pdata->max_trigger_level - 1;
@@ -286,10 +253,6 @@ skip_calib_data:
286 (pdata->trigger_type[i] == HW_TRIP)) { 253 (pdata->trigger_type[i] == HW_TRIP)) {
287 threshold_code = temp_to_code(data, 254 threshold_code = temp_to_code(data,
288 pdata->trigger_levels[i]); 255 pdata->trigger_levels[i]);
289 if (threshold_code < 0) {
290 ret = threshold_code;
291 goto out;
292 }
293 if (i == EXYNOS_MAX_TRIGGER_PER_REG - 1) { 256 if (i == EXYNOS_MAX_TRIGGER_PER_REG - 1) {
294 /* 1-4 level to be assigned in th0 reg */ 257 /* 1-4 level to be assigned in th0 reg */
295 rising_threshold &= ~(0xff << 8 * i); 258 rising_threshold &= ~(0xff << 8 * i);
@@ -325,7 +288,7 @@ static void exynos_tmu_control(struct platform_device *pdev, bool on)
325 struct exynos_tmu_data *data = platform_get_drvdata(pdev); 288 struct exynos_tmu_data *data = platform_get_drvdata(pdev);
326 struct exynos_tmu_platform_data *pdata = data->pdata; 289 struct exynos_tmu_platform_data *pdata = data->pdata;
327 const struct exynos_tmu_registers *reg = pdata->registers; 290 const struct exynos_tmu_registers *reg = pdata->registers;
328 unsigned int con, interrupt_en, cal_val; 291 unsigned int con, interrupt_en;
329 292
330 mutex_lock(&data->lock); 293 mutex_lock(&data->lock);
331 clk_enable(data->clk); 294 clk_enable(data->clk);
@@ -335,15 +298,11 @@ static void exynos_tmu_control(struct platform_device *pdev, bool on)
335 if (pdata->test_mux) 298 if (pdata->test_mux)
336 con |= (pdata->test_mux << reg->test_mux_addr_shift); 299 con |= (pdata->test_mux << reg->test_mux_addr_shift);
337 300
338 if (pdata->reference_voltage) { 301 con &= ~(EXYNOS_TMU_REF_VOLTAGE_MASK << EXYNOS_TMU_REF_VOLTAGE_SHIFT);
339 con &= ~(reg->buf_vref_sel_mask << reg->buf_vref_sel_shift); 302 con |= pdata->reference_voltage << EXYNOS_TMU_REF_VOLTAGE_SHIFT;
340 con |= pdata->reference_voltage << reg->buf_vref_sel_shift;
341 }
342 303
343 if (pdata->gain) { 304 con &= ~(EXYNOS_TMU_BUF_SLOPE_SEL_MASK << EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT);
344 con &= ~(reg->buf_slope_sel_mask << reg->buf_slope_sel_shift); 305 con |= (pdata->gain << EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT);
345 con |= (pdata->gain << reg->buf_slope_sel_shift);
346 }
347 306
348 if (pdata->noise_cancel_mode) { 307 if (pdata->noise_cancel_mode) {
349 con &= ~(reg->therm_trip_mode_mask << 308 con &= ~(reg->therm_trip_mode_mask <<
@@ -351,29 +310,8 @@ static void exynos_tmu_control(struct platform_device *pdev, bool on)
351 con |= (pdata->noise_cancel_mode << reg->therm_trip_mode_shift); 310 con |= (pdata->noise_cancel_mode << reg->therm_trip_mode_shift);
352 } 311 }
353 312
354 if (pdata->cal_mode == HW_MODE) {
355 con &= ~(reg->calib_mode_mask << reg->calib_mode_shift);
356 cal_val = 0;
357 switch (pdata->cal_type) {
358 case TYPE_TWO_POINT_TRIMMING:
359 cal_val = 3;
360 break;
361 case TYPE_ONE_POINT_TRIMMING_85:
362 cal_val = 2;
363 break;
364 case TYPE_ONE_POINT_TRIMMING_25:
365 cal_val = 1;
366 break;
367 case TYPE_NONE:
368 break;
369 default:
370 dev_err(&pdev->dev, "Invalid calibration type, using none\n");
371 }
372 con |= cal_val << reg->calib_mode_shift;
373 }
374
375 if (on) { 313 if (on) {
376 con |= (1 << reg->core_en_shift); 314 con |= (1 << EXYNOS_TMU_CORE_EN_SHIFT);
377 interrupt_en = 315 interrupt_en =
378 pdata->trigger_enable[3] << reg->inten_rise3_shift | 316 pdata->trigger_enable[3] << reg->inten_rise3_shift |
379 pdata->trigger_enable[2] << reg->inten_rise2_shift | 317 pdata->trigger_enable[2] << reg->inten_rise2_shift |
@@ -383,7 +321,7 @@ static void exynos_tmu_control(struct platform_device *pdev, bool on)
383 interrupt_en |= 321 interrupt_en |=
384 interrupt_en << reg->inten_fall0_shift; 322 interrupt_en << reg->inten_fall0_shift;
385 } else { 323 } else {
386 con &= ~(1 << reg->core_en_shift); 324 con &= ~(1 << EXYNOS_TMU_CORE_EN_SHIFT);
387 interrupt_en = 0; /* Disable all interrupts */ 325 interrupt_en = 0; /* Disable all interrupts */
388 } 326 }
389 writel(interrupt_en, data->base + reg->tmu_inten); 327 writel(interrupt_en, data->base + reg->tmu_inten);
@@ -404,8 +342,16 @@ static int exynos_tmu_read(struct exynos_tmu_data *data)
404 clk_enable(data->clk); 342 clk_enable(data->clk);
405 343
406 temp_code = readb(data->base + reg->tmu_cur_temp); 344 temp_code = readb(data->base + reg->tmu_cur_temp);
407 temp = code_to_temp(data, temp_code);
408 345
346 if (data->soc == SOC_ARCH_EXYNOS4210)
347 /* temp_code should range between 75 and 175 */
348 if (temp_code < 75 || temp_code > 175) {
349 temp = -ENODATA;
350 goto out;
351 }
352
353 temp = code_to_temp(data, temp_code);
354out:
409 clk_disable(data->clk); 355 clk_disable(data->clk);
410 mutex_unlock(&data->lock); 356 mutex_unlock(&data->lock);
411 357
@@ -465,7 +411,7 @@ static void exynos_tmu_work(struct work_struct *work)
465 struct exynos_tmu_data, irq_work); 411 struct exynos_tmu_data, irq_work);
466 struct exynos_tmu_platform_data *pdata = data->pdata; 412 struct exynos_tmu_platform_data *pdata = data->pdata;
467 const struct exynos_tmu_registers *reg = pdata->registers; 413 const struct exynos_tmu_registers *reg = pdata->registers;
468 unsigned int val_irq, val_type; 414 unsigned int val_type;
469 415
470 if (!IS_ERR(data->clk_sec)) 416 if (!IS_ERR(data->clk_sec))
471 clk_enable(data->clk_sec); 417 clk_enable(data->clk_sec);
@@ -483,9 +429,7 @@ static void exynos_tmu_work(struct work_struct *work)
483 clk_enable(data->clk); 429 clk_enable(data->clk);
484 430
485 /* TODO: take action based on particular interrupt */ 431 /* TODO: take action based on particular interrupt */
486 val_irq = readl(data->base + reg->tmu_intstat); 432 exynos_tmu_clear_irqs(data);
487 /* clear the interrupts */
488 writel(val_irq, data->base + reg->tmu_intclear);
489 433
490 clk_disable(data->clk); 434 clk_disable(data->clk);
491 mutex_unlock(&data->lock); 435 mutex_unlock(&data->lock);
diff --git a/drivers/thermal/samsung/exynos_tmu.h b/drivers/thermal/samsung/exynos_tmu.h
index 1b4a6444ea61..c58c7663a3fe 100644
--- a/drivers/thermal/samsung/exynos_tmu.h
+++ b/drivers/thermal/samsung/exynos_tmu.h
@@ -34,11 +34,6 @@ enum calibration_type {
34 TYPE_NONE, 34 TYPE_NONE,
35}; 35};
36 36
37enum calibration_mode {
38 SW_MODE,
39 HW_MODE,
40};
41
42enum soc_type { 37enum soc_type {
43 SOC_ARCH_EXYNOS3250 = 1, 38 SOC_ARCH_EXYNOS3250 = 1,
44 SOC_ARCH_EXYNOS4210, 39 SOC_ARCH_EXYNOS4210,
@@ -82,46 +77,19 @@ enum soc_type {
82 * bitfields. The register validity, offsets and bitfield values may vary 77 * bitfields. The register validity, offsets and bitfield values may vary
83 * slightly across different exynos SOC's. 78 * slightly across different exynos SOC's.
84 * @triminfo_data: register containing 2 pont trimming data 79 * @triminfo_data: register containing 2 pont trimming data
85 * @triminfo_25_shift: shift bit of the 25 C trim value in triminfo_data reg.
86 * @triminfo_85_shift: shift bit of the 85 C trim value in triminfo_data reg.
87 * @triminfo_ctrl: trim info controller register. 80 * @triminfo_ctrl: trim info controller register.
88 * @triminfo_reload_shift: shift of triminfo reload enable bit in triminfo_ctrl 81 * @triminfo_ctrl_count: the number of trim info controller register.
89 reg.
90 * @tmu_ctrl: TMU main controller register. 82 * @tmu_ctrl: TMU main controller register.
91 * @test_mux_addr_shift: shift bits of test mux address. 83 * @test_mux_addr_shift: shift bits of test mux address.
92 * @buf_vref_sel_shift: shift bits of reference voltage in tmu_ctrl register.
93 * @buf_vref_sel_mask: mask bits of reference voltage in tmu_ctrl register.
94 * @therm_trip_mode_shift: shift bits of tripping mode in tmu_ctrl register. 84 * @therm_trip_mode_shift: shift bits of tripping mode in tmu_ctrl register.
95 * @therm_trip_mode_mask: mask bits of tripping mode in tmu_ctrl register. 85 * @therm_trip_mode_mask: mask bits of tripping mode in tmu_ctrl register.
96 * @therm_trip_en_shift: shift bits of tripping enable in tmu_ctrl register. 86 * @therm_trip_en_shift: shift bits of tripping enable in tmu_ctrl register.
97 * @buf_slope_sel_shift: shift bits of amplifier gain value in tmu_ctrl
98 register.
99 * @buf_slope_sel_mask: mask bits of amplifier gain value in tmu_ctrl register.
100 * @calib_mode_shift: shift bits of calibration mode value in tmu_ctrl
101 register.
102 * @calib_mode_mask: mask bits of calibration mode value in tmu_ctrl
103 register.
104 * @therm_trip_tq_en_shift: shift bits of thermal trip enable by TQ pin in
105 tmu_ctrl register.
106 * @core_en_shift: shift bits of TMU core enable bit in tmu_ctrl register.
107 * @tmu_status: register drescribing the TMU status. 87 * @tmu_status: register drescribing the TMU status.
108 * @tmu_cur_temp: register containing the current temperature of the TMU. 88 * @tmu_cur_temp: register containing the current temperature of the TMU.
109 * @tmu_cur_temp_shift: shift bits of current temp value in tmu_cur_temp
110 register.
111 * @threshold_temp: register containing the base threshold level. 89 * @threshold_temp: register containing the base threshold level.
112 * @threshold_th0: Register containing first set of rising levels. 90 * @threshold_th0: Register containing first set of rising levels.
113 * @threshold_th0_l0_shift: shift bits of level0 threshold temperature.
114 * @threshold_th0_l1_shift: shift bits of level1 threshold temperature.
115 * @threshold_th0_l2_shift: shift bits of level2 threshold temperature.
116 * @threshold_th0_l3_shift: shift bits of level3 threshold temperature.
117 * @threshold_th1: Register containing second set of rising levels. 91 * @threshold_th1: Register containing second set of rising levels.
118 * @threshold_th1_l0_shift: shift bits of level0 threshold temperature.
119 * @threshold_th1_l1_shift: shift bits of level1 threshold temperature.
120 * @threshold_th1_l2_shift: shift bits of level2 threshold temperature.
121 * @threshold_th1_l3_shift: shift bits of level3 threshold temperature.
122 * @threshold_th2: Register containing third set of rising levels. 92 * @threshold_th2: Register containing third set of rising levels.
123 * @threshold_th2_l0_shift: shift bits of level0 threshold temperature.
124 * @threshold_th3: Register containing fourth set of rising levels.
125 * @threshold_th3_l0_shift: shift bits of level0 threshold temperature. 93 * @threshold_th3_l0_shift: shift bits of level0 threshold temperature.
126 * @tmu_inten: register containing the different threshold interrupt 94 * @tmu_inten: register containing the different threshold interrupt
127 enable bits. 95 enable bits.
@@ -130,68 +98,35 @@ enum soc_type {
130 * @inten_rise2_shift: shift bits of rising 2 interrupt bits. 98 * @inten_rise2_shift: shift bits of rising 2 interrupt bits.
131 * @inten_rise3_shift: shift bits of rising 3 interrupt bits. 99 * @inten_rise3_shift: shift bits of rising 3 interrupt bits.
132 * @inten_fall0_shift: shift bits of falling 0 interrupt bits. 100 * @inten_fall0_shift: shift bits of falling 0 interrupt bits.
133 * @inten_fall1_shift: shift bits of falling 1 interrupt bits.
134 * @inten_fall2_shift: shift bits of falling 2 interrupt bits.
135 * @inten_fall3_shift: shift bits of falling 3 interrupt bits.
136 * @tmu_intstat: Register containing the interrupt status values. 101 * @tmu_intstat: Register containing the interrupt status values.
137 * @tmu_intclear: Register for clearing the raised interrupt status. 102 * @tmu_intclear: Register for clearing the raised interrupt status.
138 * @intclr_fall_shift: shift bits for interrupt clear fall 0
139 * @intclr_rise_shift: shift bits of all rising interrupt bits.
140 * @intclr_rise_mask: mask bits of all rising interrupt bits.
141 * @intclr_fall_mask: mask bits of all rising interrupt bits.
142 * @emul_con: TMU emulation controller register. 103 * @emul_con: TMU emulation controller register.
143 * @emul_temp_shift: shift bits of emulation temperature. 104 * @emul_temp_shift: shift bits of emulation temperature.
144 * @emul_time_shift: shift bits of emulation time. 105 * @emul_time_shift: shift bits of emulation time.
145 * @emul_time_mask: mask bits of emulation time.
146 * @tmu_irqstatus: register to find which TMU generated interrupts. 106 * @tmu_irqstatus: register to find which TMU generated interrupts.
147 * @tmu_pmin: register to get/set the Pmin value. 107 * @tmu_pmin: register to get/set the Pmin value.
148 */ 108 */
149struct exynos_tmu_registers { 109struct exynos_tmu_registers {
150 u32 triminfo_data; 110 u32 triminfo_data;
151 u32 triminfo_25_shift;
152 u32 triminfo_85_shift;
153 111
154 u32 triminfo_ctrl; 112 u32 triminfo_ctrl[MAX_TRIMINFO_CTRL_REG];
155 u32 triminfo_ctrl1; 113 u32 triminfo_ctrl_count;
156 u32 triminfo_reload_shift;
157 114
158 u32 tmu_ctrl; 115 u32 tmu_ctrl;
159 u32 test_mux_addr_shift; 116 u32 test_mux_addr_shift;
160 u32 buf_vref_sel_shift;
161 u32 buf_vref_sel_mask;
162 u32 therm_trip_mode_shift; 117 u32 therm_trip_mode_shift;
163 u32 therm_trip_mode_mask; 118 u32 therm_trip_mode_mask;
164 u32 therm_trip_en_shift; 119 u32 therm_trip_en_shift;
165 u32 buf_slope_sel_shift;
166 u32 buf_slope_sel_mask;
167 u32 calib_mode_shift;
168 u32 calib_mode_mask;
169 u32 therm_trip_tq_en_shift;
170 u32 core_en_shift;
171 120
172 u32 tmu_status; 121 u32 tmu_status;
173 122
174 u32 tmu_cur_temp; 123 u32 tmu_cur_temp;
175 u32 tmu_cur_temp_shift;
176 124
177 u32 threshold_temp; 125 u32 threshold_temp;
178 126
179 u32 threshold_th0; 127 u32 threshold_th0;
180 u32 threshold_th0_l0_shift;
181 u32 threshold_th0_l1_shift;
182 u32 threshold_th0_l2_shift;
183 u32 threshold_th0_l3_shift;
184
185 u32 threshold_th1; 128 u32 threshold_th1;
186 u32 threshold_th1_l0_shift;
187 u32 threshold_th1_l1_shift;
188 u32 threshold_th1_l2_shift;
189 u32 threshold_th1_l3_shift;
190
191 u32 threshold_th2; 129 u32 threshold_th2;
192 u32 threshold_th2_l0_shift;
193
194 u32 threshold_th3;
195 u32 threshold_th3_l0_shift; 130 u32 threshold_th3_l0_shift;
196 131
197 u32 tmu_inten; 132 u32 tmu_inten;
@@ -200,22 +135,14 @@ struct exynos_tmu_registers {
200 u32 inten_rise2_shift; 135 u32 inten_rise2_shift;
201 u32 inten_rise3_shift; 136 u32 inten_rise3_shift;
202 u32 inten_fall0_shift; 137 u32 inten_fall0_shift;
203 u32 inten_fall1_shift;
204 u32 inten_fall2_shift;
205 u32 inten_fall3_shift;
206 138
207 u32 tmu_intstat; 139 u32 tmu_intstat;
208 140
209 u32 tmu_intclear; 141 u32 tmu_intclear;
210 u32 intclr_fall_shift;
211 u32 intclr_rise_shift;
212 u32 intclr_fall_mask;
213 u32 intclr_rise_mask;
214 142
215 u32 emul_con; 143 u32 emul_con;
216 u32 emul_temp_shift; 144 u32 emul_temp_shift;
217 u32 emul_time_shift; 145 u32 emul_time_shift;
218 u32 emul_time_mask;
219 146
220 u32 tmu_irqstatus; 147 u32 tmu_irqstatus;
221 u32 tmu_pmin; 148 u32 tmu_pmin;
@@ -250,11 +177,12 @@ struct exynos_tmu_registers {
250 * 1 = enable trigger_level[] interrupt, 177 * 1 = enable trigger_level[] interrupt,
251 * 0 = disable trigger_level[] interrupt 178 * 0 = disable trigger_level[] interrupt
252 * @max_trigger_level: max trigger level supported by the TMU 179 * @max_trigger_level: max trigger level supported by the TMU
180 * @non_hw_trigger_levels: number of defined non-hardware trigger levels
253 * @gain: gain of amplifier in the positive-TC generator block 181 * @gain: gain of amplifier in the positive-TC generator block
254 * 0 <= gain <= 15 182 * 0 < gain <= 15
255 * @reference_voltage: reference voltage of amplifier 183 * @reference_voltage: reference voltage of amplifier
256 * in the positive-TC generator block 184 * in the positive-TC generator block
257 * 0 <= reference_voltage <= 31 185 * 0 < reference_voltage <= 31
258 * @noise_cancel_mode: noise cancellation mode 186 * @noise_cancel_mode: noise cancellation mode
259 * 000, 100, 101, 110 and 111 can be different modes 187 * 000, 100, 101, 110 and 111 can be different modes
260 * @type: determines the type of SOC 188 * @type: determines the type of SOC
@@ -265,8 +193,8 @@ struct exynos_tmu_registers {
265 * @second_point_trim: temp value of the second point trimming 193 * @second_point_trim: temp value of the second point trimming
266 * @default_temp_offset: default temperature offset in case of no trimming 194 * @default_temp_offset: default temperature offset in case of no trimming
267 * @test_mux; information if SoC supports test MUX 195 * @test_mux; information if SoC supports test MUX
196 * @triminfo_reload: reload value to read TRIMINFO register
268 * @cal_type: calibration type for temperature 197 * @cal_type: calibration type for temperature
269 * @cal_mode: calibration mode for temperature
270 * @freq_clip_table: Table representing frequency reduction percentage. 198 * @freq_clip_table: Table representing frequency reduction percentage.
271 * @freq_tab_count: Count of the above table as frequency reduction may 199 * @freq_tab_count: Count of the above table as frequency reduction may
272 * applicable to only some of the trigger levels. 200 * applicable to only some of the trigger levels.
@@ -284,6 +212,7 @@ struct exynos_tmu_platform_data {
284 enum trigger_type trigger_type[MAX_TRIP_COUNT]; 212 enum trigger_type trigger_type[MAX_TRIP_COUNT];
285 bool trigger_enable[MAX_TRIP_COUNT]; 213 bool trigger_enable[MAX_TRIP_COUNT];
286 u8 max_trigger_level; 214 u8 max_trigger_level;
215 u8 non_hw_trigger_levels;
287 u8 gain; 216 u8 gain;
288 u8 reference_voltage; 217 u8 reference_voltage;
289 u8 noise_cancel_mode; 218 u8 noise_cancel_mode;
@@ -295,9 +224,9 @@ struct exynos_tmu_platform_data {
295 u8 second_point_trim; 224 u8 second_point_trim;
296 u8 default_temp_offset; 225 u8 default_temp_offset;
297 u8 test_mux; 226 u8 test_mux;
227 u8 triminfo_reload[MAX_TRIMINFO_CTRL_REG];
298 228
299 enum calibration_type cal_type; 229 enum calibration_type cal_type;
300 enum calibration_mode cal_mode;
301 enum soc_type type; 230 enum soc_type type;
302 struct freq_clip_table freq_tab[4]; 231 struct freq_clip_table freq_tab[4];
303 unsigned int freq_tab_count; 232 unsigned int freq_tab_count;
diff --git a/drivers/thermal/samsung/exynos_tmu_data.c b/drivers/thermal/samsung/exynos_tmu_data.c
index aa8e0dee2055..1724f6cdaef8 100644
--- a/drivers/thermal/samsung/exynos_tmu_data.c
+++ b/drivers/thermal/samsung/exynos_tmu_data.c
@@ -27,14 +27,7 @@
27#if defined(CONFIG_CPU_EXYNOS4210) 27#if defined(CONFIG_CPU_EXYNOS4210)
28static const struct exynos_tmu_registers exynos4210_tmu_registers = { 28static const struct exynos_tmu_registers exynos4210_tmu_registers = {
29 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO, 29 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO,
30 .triminfo_25_shift = EXYNOS_TRIMINFO_25_SHIFT,
31 .triminfo_85_shift = EXYNOS_TRIMINFO_85_SHIFT,
32 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL, 30 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL,
33 .buf_vref_sel_shift = EXYNOS_TMU_REF_VOLTAGE_SHIFT,
34 .buf_vref_sel_mask = EXYNOS_TMU_REF_VOLTAGE_MASK,
35 .buf_slope_sel_shift = EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT,
36 .buf_slope_sel_mask = EXYNOS_TMU_BUF_SLOPE_SEL_MASK,
37 .core_en_shift = EXYNOS_TMU_CORE_EN_SHIFT,
38 .tmu_status = EXYNOS_TMU_REG_STATUS, 31 .tmu_status = EXYNOS_TMU_REG_STATUS,
39 .tmu_cur_temp = EXYNOS_TMU_REG_CURRENT_TEMP, 32 .tmu_cur_temp = EXYNOS_TMU_REG_CURRENT_TEMP,
40 .threshold_temp = EXYNOS4210_TMU_REG_THRESHOLD_TEMP, 33 .threshold_temp = EXYNOS4210_TMU_REG_THRESHOLD_TEMP,
@@ -46,7 +39,6 @@ static const struct exynos_tmu_registers exynos4210_tmu_registers = {
46 .inten_rise3_shift = EXYNOS_TMU_INTEN_RISE3_SHIFT, 39 .inten_rise3_shift = EXYNOS_TMU_INTEN_RISE3_SHIFT,
47 .tmu_intstat = EXYNOS_TMU_REG_INTSTAT, 40 .tmu_intstat = EXYNOS_TMU_REG_INTSTAT,
48 .tmu_intclear = EXYNOS_TMU_REG_INTCLEAR, 41 .tmu_intclear = EXYNOS_TMU_REG_INTCLEAR,
49 .intclr_rise_mask = EXYNOS4210_TMU_TRIG_LEVEL_MASK,
50}; 42};
51 43
52struct exynos_tmu_init_data const exynos4210_default_tmu_data = { 44struct exynos_tmu_init_data const exynos4210_default_tmu_data = {
@@ -64,6 +56,7 @@ struct exynos_tmu_init_data const exynos4210_default_tmu_data = {
64 .trigger_type[1] = THROTTLE_ACTIVE, 56 .trigger_type[1] = THROTTLE_ACTIVE,
65 .trigger_type[2] = SW_TRIP, 57 .trigger_type[2] = SW_TRIP,
66 .max_trigger_level = 4, 58 .max_trigger_level = 4,
59 .non_hw_trigger_levels = 3,
67 .gain = 15, 60 .gain = 15,
68 .reference_voltage = 7, 61 .reference_voltage = 7,
69 .cal_type = TYPE_ONE_POINT_TRIMMING, 62 .cal_type = TYPE_ONE_POINT_TRIMMING,
@@ -93,18 +86,14 @@ struct exynos_tmu_init_data const exynos4210_default_tmu_data = {
93#if defined(CONFIG_SOC_EXYNOS3250) 86#if defined(CONFIG_SOC_EXYNOS3250)
94static const struct exynos_tmu_registers exynos3250_tmu_registers = { 87static const struct exynos_tmu_registers exynos3250_tmu_registers = {
95 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO, 88 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO,
96 .triminfo_25_shift = EXYNOS_TRIMINFO_25_SHIFT, 89 .triminfo_ctrl[0] = EXYNOS_TMU_TRIMINFO_CON1,
97 .triminfo_85_shift = EXYNOS_TRIMINFO_85_SHIFT, 90 .triminfo_ctrl[1] = EXYNOS_TMU_TRIMINFO_CON2,
91 .triminfo_ctrl_count = 2,
98 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL, 92 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL,
99 .test_mux_addr_shift = EXYNOS4412_MUX_ADDR_SHIFT, 93 .test_mux_addr_shift = EXYNOS4412_MUX_ADDR_SHIFT,
100 .buf_vref_sel_shift = EXYNOS_TMU_REF_VOLTAGE_SHIFT,
101 .buf_vref_sel_mask = EXYNOS_TMU_REF_VOLTAGE_MASK,
102 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT, 94 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT,
103 .therm_trip_mode_mask = EXYNOS_TMU_TRIP_MODE_MASK, 95 .therm_trip_mode_mask = EXYNOS_TMU_TRIP_MODE_MASK,
104 .therm_trip_en_shift = EXYNOS_TMU_THERM_TRIP_EN_SHIFT, 96 .therm_trip_en_shift = EXYNOS_TMU_THERM_TRIP_EN_SHIFT,
105 .buf_slope_sel_shift = EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT,
106 .buf_slope_sel_mask = EXYNOS_TMU_BUF_SLOPE_SEL_MASK,
107 .core_en_shift = EXYNOS_TMU_CORE_EN_SHIFT,
108 .tmu_status = EXYNOS_TMU_REG_STATUS, 97 .tmu_status = EXYNOS_TMU_REG_STATUS,
109 .tmu_cur_temp = EXYNOS_TMU_REG_CURRENT_TEMP, 98 .tmu_cur_temp = EXYNOS_TMU_REG_CURRENT_TEMP,
110 .threshold_th0 = EXYNOS_THD_TEMP_RISE, 99 .threshold_th0 = EXYNOS_THD_TEMP_RISE,
@@ -116,14 +105,9 @@ static const struct exynos_tmu_registers exynos3250_tmu_registers = {
116 .inten_fall0_shift = EXYNOS_TMU_INTEN_FALL0_SHIFT, 105 .inten_fall0_shift = EXYNOS_TMU_INTEN_FALL0_SHIFT,
117 .tmu_intstat = EXYNOS_TMU_REG_INTSTAT, 106 .tmu_intstat = EXYNOS_TMU_REG_INTSTAT,
118 .tmu_intclear = EXYNOS_TMU_REG_INTCLEAR, 107 .tmu_intclear = EXYNOS_TMU_REG_INTCLEAR,
119 .intclr_fall_shift = EXYNOS_TMU_CLEAR_FALL_INT_SHIFT,
120 .intclr_rise_shift = EXYNOS_TMU_RISE_INT_SHIFT,
121 .intclr_rise_mask = EXYNOS_TMU_RISE_INT_MASK,
122 .intclr_fall_mask = EXYNOS_TMU_FALL_INT_MASK,
123 .emul_con = EXYNOS_EMUL_CON, 108 .emul_con = EXYNOS_EMUL_CON,
124 .emul_temp_shift = EXYNOS_EMUL_DATA_SHIFT, 109 .emul_temp_shift = EXYNOS_EMUL_DATA_SHIFT,
125 .emul_time_shift = EXYNOS_EMUL_TIME_SHIFT, 110 .emul_time_shift = EXYNOS_EMUL_TIME_SHIFT,
126 .emul_time_mask = EXYNOS_EMUL_TIME_MASK,
127}; 111};
128 112
129#define EXYNOS3250_TMU_DATA \ 113#define EXYNOS3250_TMU_DATA \
@@ -141,6 +125,7 @@ static const struct exynos_tmu_registers exynos3250_tmu_registers = {
141 .trigger_type[2] = SW_TRIP, \ 125 .trigger_type[2] = SW_TRIP, \
142 .trigger_type[3] = HW_TRIP, \ 126 .trigger_type[3] = HW_TRIP, \
143 .max_trigger_level = 4, \ 127 .max_trigger_level = 4, \
128 .non_hw_trigger_levels = 3, \
144 .gain = 8, \ 129 .gain = 8, \
145 .reference_voltage = 16, \ 130 .reference_voltage = 16, \
146 .noise_cancel_mode = 4, \ 131 .noise_cancel_mode = 4, \
@@ -160,8 +145,10 @@ static const struct exynos_tmu_registers exynos3250_tmu_registers = {
160 .temp_level = 95, \ 145 .temp_level = 95, \
161 }, \ 146 }, \
162 .freq_tab_count = 2, \ 147 .freq_tab_count = 2, \
148 .triminfo_reload[0] = EXYNOS_TRIMINFO_RELOAD_ENABLE, \
149 .triminfo_reload[1] = EXYNOS_TRIMINFO_RELOAD_ENABLE, \
163 .registers = &exynos3250_tmu_registers, \ 150 .registers = &exynos3250_tmu_registers, \
164 .features = (TMU_SUPPORT_EMULATION | \ 151 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_TRIM_RELOAD | \
165 TMU_SUPPORT_FALLING_TRIP | TMU_SUPPORT_READY_STATUS | \ 152 TMU_SUPPORT_FALLING_TRIP | TMU_SUPPORT_READY_STATUS | \
166 TMU_SUPPORT_EMUL_TIME) 153 TMU_SUPPORT_EMUL_TIME)
167#endif 154#endif
@@ -182,20 +169,13 @@ struct exynos_tmu_init_data const exynos3250_default_tmu_data = {
182#if defined(CONFIG_SOC_EXYNOS4412) || defined(CONFIG_SOC_EXYNOS5250) 169#if defined(CONFIG_SOC_EXYNOS4412) || defined(CONFIG_SOC_EXYNOS5250)
183static const struct exynos_tmu_registers exynos4412_tmu_registers = { 170static const struct exynos_tmu_registers exynos4412_tmu_registers = {
184 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO, 171 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO,
185 .triminfo_25_shift = EXYNOS_TRIMINFO_25_SHIFT, 172 .triminfo_ctrl[0] = EXYNOS_TMU_TRIMINFO_CON2,
186 .triminfo_85_shift = EXYNOS_TRIMINFO_85_SHIFT, 173 .triminfo_ctrl_count = 1,
187 .triminfo_ctrl = EXYNOS_TMU_TRIMINFO_CON,
188 .triminfo_reload_shift = EXYNOS_TRIMINFO_RELOAD_SHIFT,
189 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL, 174 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL,
190 .test_mux_addr_shift = EXYNOS4412_MUX_ADDR_SHIFT, 175 .test_mux_addr_shift = EXYNOS4412_MUX_ADDR_SHIFT,
191 .buf_vref_sel_shift = EXYNOS_TMU_REF_VOLTAGE_SHIFT,
192 .buf_vref_sel_mask = EXYNOS_TMU_REF_VOLTAGE_MASK,
193 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT, 176 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT,
194 .therm_trip_mode_mask = EXYNOS_TMU_TRIP_MODE_MASK, 177 .therm_trip_mode_mask = EXYNOS_TMU_TRIP_MODE_MASK,
195 .therm_trip_en_shift = EXYNOS_TMU_THERM_TRIP_EN_SHIFT, 178 .therm_trip_en_shift = EXYNOS_TMU_THERM_TRIP_EN_SHIFT,
196 .buf_slope_sel_shift = EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT,
197 .buf_slope_sel_mask = EXYNOS_TMU_BUF_SLOPE_SEL_MASK,
198 .core_en_shift = EXYNOS_TMU_CORE_EN_SHIFT,
199 .tmu_status = EXYNOS_TMU_REG_STATUS, 179 .tmu_status = EXYNOS_TMU_REG_STATUS,
200 .tmu_cur_temp = EXYNOS_TMU_REG_CURRENT_TEMP, 180 .tmu_cur_temp = EXYNOS_TMU_REG_CURRENT_TEMP,
201 .threshold_th0 = EXYNOS_THD_TEMP_RISE, 181 .threshold_th0 = EXYNOS_THD_TEMP_RISE,
@@ -208,14 +188,9 @@ static const struct exynos_tmu_registers exynos4412_tmu_registers = {
208 .inten_fall0_shift = EXYNOS_TMU_INTEN_FALL0_SHIFT, 188 .inten_fall0_shift = EXYNOS_TMU_INTEN_FALL0_SHIFT,
209 .tmu_intstat = EXYNOS_TMU_REG_INTSTAT, 189 .tmu_intstat = EXYNOS_TMU_REG_INTSTAT,
210 .tmu_intclear = EXYNOS_TMU_REG_INTCLEAR, 190 .tmu_intclear = EXYNOS_TMU_REG_INTCLEAR,
211 .intclr_fall_shift = EXYNOS_TMU_CLEAR_FALL_INT_SHIFT,
212 .intclr_rise_shift = EXYNOS_TMU_RISE_INT_SHIFT,
213 .intclr_rise_mask = EXYNOS_TMU_RISE_INT_MASK,
214 .intclr_fall_mask = EXYNOS_TMU_FALL_INT_MASK,
215 .emul_con = EXYNOS_EMUL_CON, 191 .emul_con = EXYNOS_EMUL_CON,
216 .emul_temp_shift = EXYNOS_EMUL_DATA_SHIFT, 192 .emul_temp_shift = EXYNOS_EMUL_DATA_SHIFT,
217 .emul_time_shift = EXYNOS_EMUL_TIME_SHIFT, 193 .emul_time_shift = EXYNOS_EMUL_TIME_SHIFT,
218 .emul_time_mask = EXYNOS_EMUL_TIME_MASK,
219}; 194};
220 195
221#define EXYNOS4412_TMU_DATA \ 196#define EXYNOS4412_TMU_DATA \
@@ -233,6 +208,7 @@ static const struct exynos_tmu_registers exynos4412_tmu_registers = {
233 .trigger_type[2] = SW_TRIP, \ 208 .trigger_type[2] = SW_TRIP, \
234 .trigger_type[3] = HW_TRIP, \ 209 .trigger_type[3] = HW_TRIP, \
235 .max_trigger_level = 4, \ 210 .max_trigger_level = 4, \
211 .non_hw_trigger_levels = 3, \
236 .gain = 8, \ 212 .gain = 8, \
237 .reference_voltage = 16, \ 213 .reference_voltage = 16, \
238 .noise_cancel_mode = 4, \ 214 .noise_cancel_mode = 4, \
@@ -252,6 +228,7 @@ static const struct exynos_tmu_registers exynos4412_tmu_registers = {
252 .temp_level = 95, \ 228 .temp_level = 95, \
253 }, \ 229 }, \
254 .freq_tab_count = 2, \ 230 .freq_tab_count = 2, \
231 .triminfo_reload[0] = EXYNOS_TRIMINFO_RELOAD_ENABLE, \
255 .registers = &exynos4412_tmu_registers, \ 232 .registers = &exynos4412_tmu_registers, \
256 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_TRIM_RELOAD | \ 233 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_TRIM_RELOAD | \
257 TMU_SUPPORT_FALLING_TRIP | TMU_SUPPORT_READY_STATUS | \ 234 TMU_SUPPORT_FALLING_TRIP | TMU_SUPPORT_READY_STATUS | \
@@ -286,18 +263,10 @@ struct exynos_tmu_init_data const exynos5250_default_tmu_data = {
286#if defined(CONFIG_SOC_EXYNOS5260) 263#if defined(CONFIG_SOC_EXYNOS5260)
287static const struct exynos_tmu_registers exynos5260_tmu_registers = { 264static const struct exynos_tmu_registers exynos5260_tmu_registers = {
288 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO, 265 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO,
289 .triminfo_25_shift = EXYNOS_TRIMINFO_25_SHIFT,
290 .triminfo_85_shift = EXYNOS_TRIMINFO_85_SHIFT,
291 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL, 266 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL,
292 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL1,
293 .buf_vref_sel_shift = EXYNOS_TMU_REF_VOLTAGE_SHIFT,
294 .buf_vref_sel_mask = EXYNOS_TMU_REF_VOLTAGE_MASK,
295 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT, 267 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT,
296 .therm_trip_mode_mask = EXYNOS_TMU_TRIP_MODE_MASK, 268 .therm_trip_mode_mask = EXYNOS_TMU_TRIP_MODE_MASK,
297 .therm_trip_en_shift = EXYNOS_TMU_THERM_TRIP_EN_SHIFT, 269 .therm_trip_en_shift = EXYNOS_TMU_THERM_TRIP_EN_SHIFT,
298 .buf_slope_sel_shift = EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT,
299 .buf_slope_sel_mask = EXYNOS_TMU_BUF_SLOPE_SEL_MASK,
300 .core_en_shift = EXYNOS_TMU_CORE_EN_SHIFT,
301 .tmu_status = EXYNOS_TMU_REG_STATUS, 270 .tmu_status = EXYNOS_TMU_REG_STATUS,
302 .tmu_cur_temp = EXYNOS_TMU_REG_CURRENT_TEMP, 271 .tmu_cur_temp = EXYNOS_TMU_REG_CURRENT_TEMP,
303 .threshold_th0 = EXYNOS_THD_TEMP_RISE, 272 .threshold_th0 = EXYNOS_THD_TEMP_RISE,
@@ -310,14 +279,9 @@ static const struct exynos_tmu_registers exynos5260_tmu_registers = {
310 .inten_fall0_shift = EXYNOS_TMU_INTEN_FALL0_SHIFT, 279 .inten_fall0_shift = EXYNOS_TMU_INTEN_FALL0_SHIFT,
311 .tmu_intstat = EXYNOS5260_TMU_REG_INTSTAT, 280 .tmu_intstat = EXYNOS5260_TMU_REG_INTSTAT,
312 .tmu_intclear = EXYNOS5260_TMU_REG_INTCLEAR, 281 .tmu_intclear = EXYNOS5260_TMU_REG_INTCLEAR,
313 .intclr_fall_shift = EXYNOS5420_TMU_CLEAR_FALL_INT_SHIFT,
314 .intclr_rise_shift = EXYNOS_TMU_RISE_INT_SHIFT,
315 .intclr_rise_mask = EXYNOS5260_TMU_RISE_INT_MASK,
316 .intclr_fall_mask = EXYNOS5260_TMU_FALL_INT_MASK,
317 .emul_con = EXYNOS5260_EMUL_CON, 282 .emul_con = EXYNOS5260_EMUL_CON,
318 .emul_temp_shift = EXYNOS_EMUL_DATA_SHIFT, 283 .emul_temp_shift = EXYNOS_EMUL_DATA_SHIFT,
319 .emul_time_shift = EXYNOS_EMUL_TIME_SHIFT, 284 .emul_time_shift = EXYNOS_EMUL_TIME_SHIFT,
320 .emul_time_mask = EXYNOS_EMUL_TIME_MASK,
321}; 285};
322 286
323#define __EXYNOS5260_TMU_DATA \ 287#define __EXYNOS5260_TMU_DATA \
@@ -335,6 +299,7 @@ static const struct exynos_tmu_registers exynos5260_tmu_registers = {
335 .trigger_type[2] = SW_TRIP, \ 299 .trigger_type[2] = SW_TRIP, \
336 .trigger_type[3] = HW_TRIP, \ 300 .trigger_type[3] = HW_TRIP, \
337 .max_trigger_level = 4, \ 301 .max_trigger_level = 4, \
302 .non_hw_trigger_levels = 3, \
338 .gain = 8, \ 303 .gain = 8, \
339 .reference_voltage = 16, \ 304 .reference_voltage = 16, \
340 .noise_cancel_mode = 4, \ 305 .noise_cancel_mode = 4, \
@@ -359,9 +324,8 @@ static const struct exynos_tmu_registers exynos5260_tmu_registers = {
359#define EXYNOS5260_TMU_DATA \ 324#define EXYNOS5260_TMU_DATA \
360 __EXYNOS5260_TMU_DATA \ 325 __EXYNOS5260_TMU_DATA \
361 .type = SOC_ARCH_EXYNOS5260, \ 326 .type = SOC_ARCH_EXYNOS5260, \
362 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_TRIM_RELOAD | \ 327 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_FALLING_TRIP | \
363 TMU_SUPPORT_FALLING_TRIP | TMU_SUPPORT_READY_STATUS | \ 328 TMU_SUPPORT_READY_STATUS | TMU_SUPPORT_EMUL_TIME)
364 TMU_SUPPORT_EMUL_TIME)
365 329
366struct exynos_tmu_init_data const exynos5260_default_tmu_data = { 330struct exynos_tmu_init_data const exynos5260_default_tmu_data = {
367 .tmu_data = { 331 .tmu_data = {
@@ -378,17 +342,10 @@ struct exynos_tmu_init_data const exynos5260_default_tmu_data = {
378#if defined(CONFIG_SOC_EXYNOS5420) 342#if defined(CONFIG_SOC_EXYNOS5420)
379static const struct exynos_tmu_registers exynos5420_tmu_registers = { 343static const struct exynos_tmu_registers exynos5420_tmu_registers = {
380 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO, 344 .triminfo_data = EXYNOS_TMU_REG_TRIMINFO,
381 .triminfo_25_shift = EXYNOS_TRIMINFO_25_SHIFT,
382 .triminfo_85_shift = EXYNOS_TRIMINFO_85_SHIFT,
383 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL, 345 .tmu_ctrl = EXYNOS_TMU_REG_CONTROL,
384 .buf_vref_sel_shift = EXYNOS_TMU_REF_VOLTAGE_SHIFT,
385 .buf_vref_sel_mask = EXYNOS_TMU_REF_VOLTAGE_MASK,
386 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT, 346 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT,
387 .therm_trip_mode_mask = EXYNOS_TMU_TRIP_MODE_MASK, 347 .therm_trip_mode_mask = EXYNOS_TMU_TRIP_MODE_MASK,
388 .therm_trip_en_shift = EXYNOS_TMU_THERM_TRIP_EN_SHIFT, 348 .therm_trip_en_shift = EXYNOS_TMU_THERM_TRIP_EN_SHIFT,
389 .buf_slope_sel_shift = EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT,
390 .buf_slope_sel_mask = EXYNOS_TMU_BUF_SLOPE_SEL_MASK,
391 .core_en_shift = EXYNOS_TMU_CORE_EN_SHIFT,
392 .tmu_status = EXYNOS_TMU_REG_STATUS, 349 .tmu_status = EXYNOS_TMU_REG_STATUS,
393 .tmu_cur_temp = EXYNOS_TMU_REG_CURRENT_TEMP, 350 .tmu_cur_temp = EXYNOS_TMU_REG_CURRENT_TEMP,
394 .threshold_th0 = EXYNOS_THD_TEMP_RISE, 351 .threshold_th0 = EXYNOS_THD_TEMP_RISE,
@@ -402,14 +359,9 @@ static const struct exynos_tmu_registers exynos5420_tmu_registers = {
402 .inten_fall0_shift = EXYNOS_TMU_INTEN_FALL0_SHIFT, 359 .inten_fall0_shift = EXYNOS_TMU_INTEN_FALL0_SHIFT,
403 .tmu_intstat = EXYNOS_TMU_REG_INTSTAT, 360 .tmu_intstat = EXYNOS_TMU_REG_INTSTAT,
404 .tmu_intclear = EXYNOS_TMU_REG_INTCLEAR, 361 .tmu_intclear = EXYNOS_TMU_REG_INTCLEAR,
405 .intclr_fall_shift = EXYNOS5420_TMU_CLEAR_FALL_INT_SHIFT,
406 .intclr_rise_shift = EXYNOS_TMU_RISE_INT_SHIFT,
407 .intclr_rise_mask = EXYNOS_TMU_RISE_INT_MASK,
408 .intclr_fall_mask = EXYNOS_TMU_FALL_INT_MASK,
409 .emul_con = EXYNOS_EMUL_CON, 362 .emul_con = EXYNOS_EMUL_CON,
410 .emul_temp_shift = EXYNOS_EMUL_DATA_SHIFT, 363 .emul_temp_shift = EXYNOS_EMUL_DATA_SHIFT,
411 .emul_time_shift = EXYNOS_EMUL_TIME_SHIFT, 364 .emul_time_shift = EXYNOS_EMUL_TIME_SHIFT,
412 .emul_time_mask = EXYNOS_EMUL_TIME_MASK,
413}; 365};
414 366
415#define __EXYNOS5420_TMU_DATA \ 367#define __EXYNOS5420_TMU_DATA \
@@ -427,6 +379,7 @@ static const struct exynos_tmu_registers exynos5420_tmu_registers = {
427 .trigger_type[2] = SW_TRIP, \ 379 .trigger_type[2] = SW_TRIP, \
428 .trigger_type[3] = HW_TRIP, \ 380 .trigger_type[3] = HW_TRIP, \
429 .max_trigger_level = 4, \ 381 .max_trigger_level = 4, \
382 .non_hw_trigger_levels = 3, \
430 .gain = 8, \ 383 .gain = 8, \
431 .reference_voltage = 16, \ 384 .reference_voltage = 16, \
432 .noise_cancel_mode = 4, \ 385 .noise_cancel_mode = 4, \
@@ -451,16 +404,15 @@ static const struct exynos_tmu_registers exynos5420_tmu_registers = {
451#define EXYNOS5420_TMU_DATA \ 404#define EXYNOS5420_TMU_DATA \
452 __EXYNOS5420_TMU_DATA \ 405 __EXYNOS5420_TMU_DATA \
453 .type = SOC_ARCH_EXYNOS5250, \ 406 .type = SOC_ARCH_EXYNOS5250, \
454 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_TRIM_RELOAD | \ 407 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_FALLING_TRIP | \
455 TMU_SUPPORT_FALLING_TRIP | TMU_SUPPORT_READY_STATUS | \ 408 TMU_SUPPORT_READY_STATUS | TMU_SUPPORT_EMUL_TIME)
456 TMU_SUPPORT_EMUL_TIME)
457 409
458#define EXYNOS5420_TMU_DATA_SHARED \ 410#define EXYNOS5420_TMU_DATA_SHARED \
459 __EXYNOS5420_TMU_DATA \ 411 __EXYNOS5420_TMU_DATA \
460 .type = SOC_ARCH_EXYNOS5420_TRIMINFO, \ 412 .type = SOC_ARCH_EXYNOS5420_TRIMINFO, \
461 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_TRIM_RELOAD | \ 413 .features = (TMU_SUPPORT_EMULATION | TMU_SUPPORT_FALLING_TRIP | \
462 TMU_SUPPORT_FALLING_TRIP | TMU_SUPPORT_READY_STATUS | \ 414 TMU_SUPPORT_READY_STATUS | TMU_SUPPORT_EMUL_TIME | \
463 TMU_SUPPORT_EMUL_TIME | TMU_SUPPORT_ADDRESS_MULTIPLE) 415 TMU_SUPPORT_ADDRESS_MULTIPLE)
464 416
465struct exynos_tmu_init_data const exynos5420_default_tmu_data = { 417struct exynos_tmu_init_data const exynos5420_default_tmu_data = {
466 .tmu_data = { 418 .tmu_data = {
@@ -477,19 +429,10 @@ struct exynos_tmu_init_data const exynos5420_default_tmu_data = {
477#if defined(CONFIG_SOC_EXYNOS5440) 429#if defined(CONFIG_SOC_EXYNOS5440)
478static const struct exynos_tmu_registers exynos5440_tmu_registers = { 430static const struct exynos_tmu_registers exynos5440_tmu_registers = {
479 .triminfo_data = EXYNOS5440_TMU_S0_7_TRIM, 431 .triminfo_data = EXYNOS5440_TMU_S0_7_TRIM,
480 .triminfo_25_shift = EXYNOS_TRIMINFO_25_SHIFT,
481 .triminfo_85_shift = EXYNOS_TRIMINFO_85_SHIFT,
482 .tmu_ctrl = EXYNOS5440_TMU_S0_7_CTRL, 432 .tmu_ctrl = EXYNOS5440_TMU_S0_7_CTRL,
483 .buf_vref_sel_shift = EXYNOS_TMU_REF_VOLTAGE_SHIFT,
484 .buf_vref_sel_mask = EXYNOS_TMU_REF_VOLTAGE_MASK,
485 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT, 433 .therm_trip_mode_shift = EXYNOS_TMU_TRIP_MODE_SHIFT,
486 .therm_trip_mode_mask = EXYNOS_TMU_TRIP_MODE_MASK, 434 .therm_trip_mode_mask = EXYNOS_TMU_TRIP_MODE_MASK,
487 .therm_trip_en_shift = EXYNOS_TMU_THERM_TRIP_EN_SHIFT, 435 .therm_trip_en_shift = EXYNOS_TMU_THERM_TRIP_EN_SHIFT,
488 .buf_slope_sel_shift = EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT,
489 .buf_slope_sel_mask = EXYNOS_TMU_BUF_SLOPE_SEL_MASK,
490 .calib_mode_shift = EXYNOS_TMU_CALIB_MODE_SHIFT,
491 .calib_mode_mask = EXYNOS_TMU_CALIB_MODE_MASK,
492 .core_en_shift = EXYNOS_TMU_CORE_EN_SHIFT,
493 .tmu_status = EXYNOS5440_TMU_S0_7_STATUS, 436 .tmu_status = EXYNOS5440_TMU_S0_7_STATUS,
494 .tmu_cur_temp = EXYNOS5440_TMU_S0_7_TEMP, 437 .tmu_cur_temp = EXYNOS5440_TMU_S0_7_TEMP,
495 .threshold_th0 = EXYNOS5440_TMU_S0_7_TH0, 438 .threshold_th0 = EXYNOS5440_TMU_S0_7_TH0,
@@ -504,10 +447,6 @@ static const struct exynos_tmu_registers exynos5440_tmu_registers = {
504 .inten_fall0_shift = EXYNOS5440_TMU_INTEN_FALL0_SHIFT, 447 .inten_fall0_shift = EXYNOS5440_TMU_INTEN_FALL0_SHIFT,
505 .tmu_intstat = EXYNOS5440_TMU_S0_7_IRQ, 448 .tmu_intstat = EXYNOS5440_TMU_S0_7_IRQ,
506 .tmu_intclear = EXYNOS5440_TMU_S0_7_IRQ, 449 .tmu_intclear = EXYNOS5440_TMU_S0_7_IRQ,
507 .intclr_fall_shift = EXYNOS5440_TMU_CLEAR_FALL_INT_SHIFT,
508 .intclr_rise_shift = EXYNOS5440_TMU_RISE_INT_SHIFT,
509 .intclr_rise_mask = EXYNOS5440_TMU_RISE_INT_MASK,
510 .intclr_fall_mask = EXYNOS5440_TMU_FALL_INT_MASK,
511 .tmu_irqstatus = EXYNOS5440_TMU_IRQ_STATUS, 450 .tmu_irqstatus = EXYNOS5440_TMU_IRQ_STATUS,
512 .emul_con = EXYNOS5440_TMU_S0_7_DEBUG, 451 .emul_con = EXYNOS5440_TMU_S0_7_DEBUG,
513 .emul_temp_shift = EXYNOS_EMUL_DATA_SHIFT, 452 .emul_temp_shift = EXYNOS_EMUL_DATA_SHIFT,
@@ -521,11 +460,11 @@ static const struct exynos_tmu_registers exynos5440_tmu_registers = {
521 .trigger_type[0] = SW_TRIP, \ 460 .trigger_type[0] = SW_TRIP, \
522 .trigger_type[4] = HW_TRIP, \ 461 .trigger_type[4] = HW_TRIP, \
523 .max_trigger_level = 5, \ 462 .max_trigger_level = 5, \
463 .non_hw_trigger_levels = 1, \
524 .gain = 5, \ 464 .gain = 5, \
525 .reference_voltage = 16, \ 465 .reference_voltage = 16, \
526 .noise_cancel_mode = 4, \ 466 .noise_cancel_mode = 4, \
527 .cal_type = TYPE_ONE_POINT_TRIMMING, \ 467 .cal_type = TYPE_ONE_POINT_TRIMMING, \
528 .cal_mode = 0, \
529 .efuse_value = 0x5b2d, \ 468 .efuse_value = 0x5b2d, \
530 .min_efuse_value = 16, \ 469 .min_efuse_value = 16, \
531 .max_efuse_value = 76, \ 470 .max_efuse_value = 76, \
diff --git a/drivers/thermal/samsung/exynos_tmu_data.h b/drivers/thermal/samsung/exynos_tmu_data.h
index f0979e598491..63de598c9c2c 100644
--- a/drivers/thermal/samsung/exynos_tmu_data.h
+++ b/drivers/thermal/samsung/exynos_tmu_data.h
@@ -39,55 +39,31 @@
39#define EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT 8 39#define EXYNOS_TMU_BUF_SLOPE_SEL_SHIFT 8
40#define EXYNOS_TMU_CORE_EN_SHIFT 0 40#define EXYNOS_TMU_CORE_EN_SHIFT 0
41 41
42/* Exynos3250 specific registers */
43#define EXYNOS_TMU_TRIMINFO_CON1 0x10
44
42/* Exynos4210 specific registers */ 45/* Exynos4210 specific registers */
43#define EXYNOS4210_TMU_REG_THRESHOLD_TEMP 0x44 46#define EXYNOS4210_TMU_REG_THRESHOLD_TEMP 0x44
44#define EXYNOS4210_TMU_REG_TRIG_LEVEL0 0x50 47#define EXYNOS4210_TMU_REG_TRIG_LEVEL0 0x50
45#define EXYNOS4210_TMU_REG_TRIG_LEVEL1 0x54 48
46#define EXYNOS4210_TMU_REG_TRIG_LEVEL2 0x58 49/* Exynos5250, Exynos4412, Exynos3250 specific registers */
47#define EXYNOS4210_TMU_REG_TRIG_LEVEL3 0x5C 50#define EXYNOS_TMU_TRIMINFO_CON2 0x14
48#define EXYNOS4210_TMU_REG_PAST_TEMP0 0x60
49#define EXYNOS4210_TMU_REG_PAST_TEMP1 0x64
50#define EXYNOS4210_TMU_REG_PAST_TEMP2 0x68
51#define EXYNOS4210_TMU_REG_PAST_TEMP3 0x6C
52
53#define EXYNOS4210_TMU_TRIG_LEVEL0_MASK 0x1
54#define EXYNOS4210_TMU_TRIG_LEVEL1_MASK 0x10
55#define EXYNOS4210_TMU_TRIG_LEVEL2_MASK 0x100
56#define EXYNOS4210_TMU_TRIG_LEVEL3_MASK 0x1000
57#define EXYNOS4210_TMU_TRIG_LEVEL_MASK 0x1111
58#define EXYNOS4210_TMU_INTCLEAR_VAL 0x1111
59
60/* Exynos5250 and Exynos4412 specific registers */
61#define EXYNOS_TMU_TRIMINFO_CON 0x14
62#define EXYNOS_THD_TEMP_RISE 0x50 51#define EXYNOS_THD_TEMP_RISE 0x50
63#define EXYNOS_THD_TEMP_FALL 0x54 52#define EXYNOS_THD_TEMP_FALL 0x54
64#define EXYNOS_EMUL_CON 0x80 53#define EXYNOS_EMUL_CON 0x80
65 54
66#define EXYNOS_TRIMINFO_RELOAD_SHIFT 1 55#define EXYNOS_TRIMINFO_RELOAD_ENABLE 1
67#define EXYNOS_TRIMINFO_25_SHIFT 0 56#define EXYNOS_TRIMINFO_25_SHIFT 0
68#define EXYNOS_TRIMINFO_85_SHIFT 8 57#define EXYNOS_TRIMINFO_85_SHIFT 8
69#define EXYNOS_TMU_RISE_INT_MASK 0x111
70#define EXYNOS_TMU_RISE_INT_SHIFT 0
71#define EXYNOS_TMU_FALL_INT_MASK 0x111
72#define EXYNOS_TMU_CLEAR_RISE_INT 0x111
73#define EXYNOS_TMU_CLEAR_FALL_INT (0x111 << 12)
74#define EXYNOS_TMU_CLEAR_FALL_INT_SHIFT 12
75#define EXYNOS5420_TMU_CLEAR_FALL_INT_SHIFT 16
76#define EXYNOS5440_TMU_CLEAR_FALL_INT_SHIFT 4
77#define EXYNOS_TMU_TRIP_MODE_SHIFT 13 58#define EXYNOS_TMU_TRIP_MODE_SHIFT 13
78#define EXYNOS_TMU_TRIP_MODE_MASK 0x7 59#define EXYNOS_TMU_TRIP_MODE_MASK 0x7
79#define EXYNOS_TMU_THERM_TRIP_EN_SHIFT 12 60#define EXYNOS_TMU_THERM_TRIP_EN_SHIFT 12
80#define EXYNOS_TMU_CALIB_MODE_SHIFT 4
81#define EXYNOS_TMU_CALIB_MODE_MASK 0x3
82 61
83#define EXYNOS_TMU_INTEN_RISE0_SHIFT 0 62#define EXYNOS_TMU_INTEN_RISE0_SHIFT 0
84#define EXYNOS_TMU_INTEN_RISE1_SHIFT 4 63#define EXYNOS_TMU_INTEN_RISE1_SHIFT 4
85#define EXYNOS_TMU_INTEN_RISE2_SHIFT 8 64#define EXYNOS_TMU_INTEN_RISE2_SHIFT 8
86#define EXYNOS_TMU_INTEN_RISE3_SHIFT 12 65#define EXYNOS_TMU_INTEN_RISE3_SHIFT 12
87#define EXYNOS_TMU_INTEN_FALL0_SHIFT 16 66#define EXYNOS_TMU_INTEN_FALL0_SHIFT 16
88#define EXYNOS_TMU_INTEN_FALL1_SHIFT 20
89#define EXYNOS_TMU_INTEN_FALL2_SHIFT 24
90#define EXYNOS_TMU_INTEN_FALL3_SHIFT 28
91 67
92#define EXYNOS_EMUL_TIME 0x57F0 68#define EXYNOS_EMUL_TIME 0x57F0
93#define EXYNOS_EMUL_TIME_MASK 0xffff 69#define EXYNOS_EMUL_TIME_MASK 0xffff
@@ -99,14 +75,9 @@
99#define EXYNOS_MAX_TRIGGER_PER_REG 4 75#define EXYNOS_MAX_TRIGGER_PER_REG 4
100 76
101/* Exynos5260 specific */ 77/* Exynos5260 specific */
102#define EXYNOS_TMU_REG_CONTROL1 0x24
103#define EXYNOS5260_TMU_REG_INTEN 0xC0 78#define EXYNOS5260_TMU_REG_INTEN 0xC0
104#define EXYNOS5260_TMU_REG_INTSTAT 0xC4 79#define EXYNOS5260_TMU_REG_INTSTAT 0xC4
105#define EXYNOS5260_TMU_REG_INTCLEAR 0xC8 80#define EXYNOS5260_TMU_REG_INTCLEAR 0xC8
106#define EXYNOS5260_TMU_CLEAR_RISE_INT 0x1111
107#define EXYNOS5260_TMU_CLEAR_FALL_INT (0x1111 << 16)
108#define EXYNOS5260_TMU_RISE_INT_MASK 0x1111
109#define EXYNOS5260_TMU_FALL_INT_MASK 0x1111
110#define EXYNOS5260_EMUL_CON 0x100 81#define EXYNOS5260_EMUL_CON 0x100
111 82
112/* Exynos4412 specific */ 83/* Exynos4412 specific */
@@ -122,29 +93,17 @@
122#define EXYNOS5440_TMU_S0_7_TH0 0x110 93#define EXYNOS5440_TMU_S0_7_TH0 0x110
123#define EXYNOS5440_TMU_S0_7_TH1 0x130 94#define EXYNOS5440_TMU_S0_7_TH1 0x130
124#define EXYNOS5440_TMU_S0_7_TH2 0x150 95#define EXYNOS5440_TMU_S0_7_TH2 0x150
125#define EXYNOS5440_TMU_S0_7_EVTEN 0x1F0
126#define EXYNOS5440_TMU_S0_7_IRQEN 0x210 96#define EXYNOS5440_TMU_S0_7_IRQEN 0x210
127#define EXYNOS5440_TMU_S0_7_IRQ 0x230 97#define EXYNOS5440_TMU_S0_7_IRQ 0x230
128/* exynos5440 common registers */ 98/* exynos5440 common registers */
129#define EXYNOS5440_TMU_IRQ_STATUS 0x000 99#define EXYNOS5440_TMU_IRQ_STATUS 0x000
130#define EXYNOS5440_TMU_PMIN 0x004 100#define EXYNOS5440_TMU_PMIN 0x004
131#define EXYNOS5440_TMU_TEMP 0x008
132 101
133#define EXYNOS5440_TMU_RISE_INT_MASK 0xf
134#define EXYNOS5440_TMU_RISE_INT_SHIFT 0
135#define EXYNOS5440_TMU_FALL_INT_MASK 0xf
136#define EXYNOS5440_TMU_INTEN_RISE0_SHIFT 0 102#define EXYNOS5440_TMU_INTEN_RISE0_SHIFT 0
137#define EXYNOS5440_TMU_INTEN_RISE1_SHIFT 1 103#define EXYNOS5440_TMU_INTEN_RISE1_SHIFT 1
138#define EXYNOS5440_TMU_INTEN_RISE2_SHIFT 2 104#define EXYNOS5440_TMU_INTEN_RISE2_SHIFT 2
139#define EXYNOS5440_TMU_INTEN_RISE3_SHIFT 3 105#define EXYNOS5440_TMU_INTEN_RISE3_SHIFT 3
140#define EXYNOS5440_TMU_INTEN_FALL0_SHIFT 4 106#define EXYNOS5440_TMU_INTEN_FALL0_SHIFT 4
141#define EXYNOS5440_TMU_INTEN_FALL1_SHIFT 5
142#define EXYNOS5440_TMU_INTEN_FALL2_SHIFT 6
143#define EXYNOS5440_TMU_INTEN_FALL3_SHIFT 7
144#define EXYNOS5440_TMU_TH_RISE0_SHIFT 0
145#define EXYNOS5440_TMU_TH_RISE1_SHIFT 8
146#define EXYNOS5440_TMU_TH_RISE2_SHIFT 16
147#define EXYNOS5440_TMU_TH_RISE3_SHIFT 24
148#define EXYNOS5440_TMU_TH_RISE4_SHIFT 24 107#define EXYNOS5440_TMU_TH_RISE4_SHIFT 24
149#define EXYNOS5440_EFUSE_SWAP_OFFSET 8 108#define EXYNOS5440_EFUSE_SWAP_OFFSET 8
150 109
diff --git a/drivers/thermal/st/st_thermal.c b/drivers/thermal/st/st_thermal.c
index 90163b384660..d1ec5804c0bb 100644
--- a/drivers/thermal/st/st_thermal.c
+++ b/drivers/thermal/st/st_thermal.c
@@ -275,6 +275,7 @@ int st_thermal_unregister(struct platform_device *pdev)
275} 275}
276EXPORT_SYMBOL_GPL(st_thermal_unregister); 276EXPORT_SYMBOL_GPL(st_thermal_unregister);
277 277
278#ifdef CONFIG_PM_SLEEP
278static int st_thermal_suspend(struct device *dev) 279static int st_thermal_suspend(struct device *dev)
279{ 280{
280 struct platform_device *pdev = to_platform_device(dev); 281 struct platform_device *pdev = to_platform_device(dev);
@@ -305,6 +306,8 @@ static int st_thermal_resume(struct device *dev)
305 306
306 return 0; 307 return 0;
307} 308}
309#endif
310
308SIMPLE_DEV_PM_OPS(st_thermal_pm_ops, st_thermal_suspend, st_thermal_resume); 311SIMPLE_DEV_PM_OPS(st_thermal_pm_ops, st_thermal_suspend, st_thermal_resume);
309EXPORT_SYMBOL_GPL(st_thermal_pm_ops); 312EXPORT_SYMBOL_GPL(st_thermal_pm_ops);
310 313
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 9bf10aa6069b..43b90709585f 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1575,8 +1575,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type,
1575 1575
1576 thermal_zone_device_update(tz); 1576 thermal_zone_device_update(tz);
1577 1577
1578 if (!result) 1578 return tz;
1579 return tz;
1580 1579
1581unregister: 1580unregister:
1582 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id); 1581 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 89c4cee253e3..2e900a98c3e3 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2413,12 +2413,17 @@ static unsigned int n_tty_poll(struct tty_struct *tty, struct file *file,
2413 2413
2414 poll_wait(file, &tty->read_wait, wait); 2414 poll_wait(file, &tty->read_wait, wait);
2415 poll_wait(file, &tty->write_wait, wait); 2415 poll_wait(file, &tty->write_wait, wait);
2416 if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
2417 mask |= POLLHUP;
2416 if (input_available_p(tty, 1)) 2418 if (input_available_p(tty, 1))
2417 mask |= POLLIN | POLLRDNORM; 2419 mask |= POLLIN | POLLRDNORM;
2420 else if (mask & POLLHUP) {
2421 tty_flush_to_ldisc(tty);
2422 if (input_available_p(tty, 1))
2423 mask |= POLLIN | POLLRDNORM;
2424 }
2418 if (tty->packet && tty->link->ctrl_status) 2425 if (tty->packet && tty->link->ctrl_status)
2419 mask |= POLLPRI | POLLIN | POLLRDNORM; 2426 mask |= POLLPRI | POLLIN | POLLRDNORM;
2420 if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
2421 mask |= POLLHUP;
2422 if (tty_hung_up_p(file)) 2427 if (tty_hung_up_p(file))
2423 mask |= POLLHUP; 2428 mask |= POLLHUP;
2424 if (!(mask & (POLLHUP | POLLIN | POLLRDNORM))) { 2429 if (!(mask & (POLLHUP | POLLIN | POLLRDNORM))) {
diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c
index 8f37d57165ec..de7aae523b37 100644
--- a/drivers/tty/serial/8250/8250_mtk.c
+++ b/drivers/tty/serial/8250/8250_mtk.c
@@ -81,7 +81,7 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios,
81 /* Set to highest baudrate supported */ 81 /* Set to highest baudrate supported */
82 if (baud >= 1152000) 82 if (baud >= 1152000)
83 baud = 921600; 83 baud = 921600;
84 quot = DIV_ROUND_CLOSEST(port->uartclk, 256 * baud); 84 quot = (port->uartclk / (256 * baud)) + 1;
85 } 85 }
86 86
87 /* 87 /*
diff --git a/drivers/tty/serial/of_serial.c b/drivers/tty/serial/of_serial.c
index 8bc2563335ae..bf355050eab6 100644
--- a/drivers/tty/serial/of_serial.c
+++ b/drivers/tty/serial/of_serial.c
@@ -158,7 +158,7 @@ static int of_platform_serial_probe(struct platform_device *ofdev)
158 if (of_find_property(ofdev->dev.of_node, "used-by-rtas", NULL)) 158 if (of_find_property(ofdev->dev.of_node, "used-by-rtas", NULL))
159 return -EBUSY; 159 return -EBUSY;
160 160
161 info = kmalloc(sizeof(*info), GFP_KERNEL); 161 info = kzalloc(sizeof(*info), GFP_KERNEL);
162 if (info == NULL) 162 if (info == NULL)
163 return -ENOMEM; 163 return -ENOMEM;
164 164
@@ -240,32 +240,6 @@ static int of_platform_serial_remove(struct platform_device *ofdev)
240 return 0; 240 return 0;
241} 241}
242 242
243#ifdef CONFIG_PM_SLEEP
244static int of_serial_suspend(struct device *dev)
245{
246 struct of_serial_info *info = dev_get_drvdata(dev);
247
248 serial8250_suspend_port(info->line);
249 if (info->clk)
250 clk_disable_unprepare(info->clk);
251
252 return 0;
253}
254
255static int of_serial_resume(struct device *dev)
256{
257 struct of_serial_info *info = dev_get_drvdata(dev);
258
259 if (info->clk)
260 clk_prepare_enable(info->clk);
261
262 serial8250_resume_port(info->line);
263
264 return 0;
265}
266#endif
267static SIMPLE_DEV_PM_OPS(of_serial_pm_ops, of_serial_suspend, of_serial_resume);
268
269/* 243/*
270 * A few common types, add more as needed. 244 * A few common types, add more as needed.
271 */ 245 */
@@ -297,7 +271,6 @@ static struct platform_driver of_platform_serial_driver = {
297 .name = "of_serial", 271 .name = "of_serial",
298 .owner = THIS_MODULE, 272 .owner = THIS_MODULE,
299 .of_match_table = of_platform_serial_table, 273 .of_match_table = of_platform_serial_table,
300 .pm = &of_serial_pm_ops,
301 }, 274 },
302 .probe = of_platform_serial_probe, 275 .probe = of_platform_serial_probe,
303 .remove = of_platform_serial_remove, 276 .remove = of_platform_serial_remove,
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index df3a8c74358e..eaeb9a02c7fe 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -363,7 +363,7 @@ uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
363 * The spd_hi, spd_vhi, spd_shi, spd_warp kludge... 363 * The spd_hi, spd_vhi, spd_shi, spd_warp kludge...
364 * Die! Die! Die! 364 * Die! Die! Die!
365 */ 365 */
366 if (baud == 38400) 366 if (try == 0 && baud == 38400)
367 baud = altbaud; 367 baud = altbaud;
368 368
369 /* 369 /*
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 16a2c0237dd6..0508a1d8e4cd 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1709,6 +1709,8 @@ int tty_release(struct inode *inode, struct file *filp)
1709 int pty_master, tty_closing, o_tty_closing, do_sleep; 1709 int pty_master, tty_closing, o_tty_closing, do_sleep;
1710 int idx; 1710 int idx;
1711 char buf[64]; 1711 char buf[64];
1712 long timeout = 0;
1713 int once = 1;
1712 1714
1713 if (tty_paranoia_check(tty, inode, __func__)) 1715 if (tty_paranoia_check(tty, inode, __func__))
1714 return 0; 1716 return 0;
@@ -1789,11 +1791,18 @@ int tty_release(struct inode *inode, struct file *filp)
1789 if (!do_sleep) 1791 if (!do_sleep)
1790 break; 1792 break;
1791 1793
1792 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n", 1794 if (once) {
1793 __func__, tty_name(tty, buf)); 1795 once = 0;
1796 printk(KERN_WARNING "%s: %s: read/write wait queue active!\n",
1797 __func__, tty_name(tty, buf));
1798 }
1794 tty_unlock_pair(tty, o_tty); 1799 tty_unlock_pair(tty, o_tty);
1795 mutex_unlock(&tty_mutex); 1800 mutex_unlock(&tty_mutex);
1796 schedule(); 1801 schedule_timeout_killable(timeout);
1802 if (timeout < 120 * HZ)
1803 timeout = 2 * timeout + 1;
1804 else
1805 timeout = MAX_SCHEDULE_TIMEOUT;
1797 } 1806 }
1798 1807
1799 /* 1808 /*
diff --git a/drivers/tty/vt/consolemap.c b/drivers/tty/vt/consolemap.c
index 610b720d3b91..59b25e039968 100644
--- a/drivers/tty/vt/consolemap.c
+++ b/drivers/tty/vt/consolemap.c
@@ -539,6 +539,12 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
539 539
540 /* Save original vc_unipagdir_loc in case we allocate a new one */ 540 /* Save original vc_unipagdir_loc in case we allocate a new one */
541 p = *vc->vc_uni_pagedir_loc; 541 p = *vc->vc_uni_pagedir_loc;
542
543 if (!p) {
544 err = -EINVAL;
545
546 goto out_unlock;
547 }
542 548
543 if (p->refcount > 1) { 549 if (p->refcount > 1) {
544 int j, k; 550 int j, k;
@@ -623,6 +629,7 @@ int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
623 set_inverse_transl(vc, p, i); /* Update inverse translations */ 629 set_inverse_transl(vc, p, i); /* Update inverse translations */
624 set_inverse_trans_unicode(vc, p); 630 set_inverse_trans_unicode(vc, p);
625 631
632out_unlock:
626 console_unlock(); 633 console_unlock();
627 return err; 634 return err;
628} 635}
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index e934e19f49f5..077d58ac3dcb 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -60,6 +60,9 @@ static struct acm *acm_table[ACM_TTY_MINORS];
60 60
61static DEFINE_MUTEX(acm_table_lock); 61static DEFINE_MUTEX(acm_table_lock);
62 62
63static void acm_tty_set_termios(struct tty_struct *tty,
64 struct ktermios *termios_old);
65
63/* 66/*
64 * acm_table accessors 67 * acm_table accessors
65 */ 68 */
@@ -145,8 +148,15 @@ static int acm_ctrl_msg(struct acm *acm, int request, int value,
145/* devices aren't required to support these requests. 148/* devices aren't required to support these requests.
146 * the cdc acm descriptor tells whether they do... 149 * the cdc acm descriptor tells whether they do...
147 */ 150 */
148#define acm_set_control(acm, control) \ 151static inline int acm_set_control(struct acm *acm, int control)
149 acm_ctrl_msg(acm, USB_CDC_REQ_SET_CONTROL_LINE_STATE, control, NULL, 0) 152{
153 if (acm->quirks & QUIRK_CONTROL_LINE_STATE)
154 return -EOPNOTSUPP;
155
156 return acm_ctrl_msg(acm, USB_CDC_REQ_SET_CONTROL_LINE_STATE,
157 control, NULL, 0);
158}
159
150#define acm_set_line(acm, line) \ 160#define acm_set_line(acm, line) \
151 acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line)) 161 acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line))
152#define acm_send_break(acm, ms) \ 162#define acm_send_break(acm, ms) \
@@ -554,6 +564,8 @@ static int acm_port_activate(struct tty_port *port, struct tty_struct *tty)
554 goto error_submit_urb; 564 goto error_submit_urb;
555 } 565 }
556 566
567 acm_tty_set_termios(tty, NULL);
568
557 /* 569 /*
558 * Unthrottle device in case the TTY was closed while throttled. 570 * Unthrottle device in case the TTY was closed while throttled.
559 */ 571 */
@@ -980,11 +992,12 @@ static void acm_tty_set_termios(struct tty_struct *tty,
980 /* FIXME: Needs to clear unsupported bits in the termios */ 992 /* FIXME: Needs to clear unsupported bits in the termios */
981 acm->clocal = ((termios->c_cflag & CLOCAL) != 0); 993 acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
982 994
983 if (!newline.dwDTERate) { 995 if (C_BAUD(tty) == B0) {
984 newline.dwDTERate = acm->line.dwDTERate; 996 newline.dwDTERate = acm->line.dwDTERate;
985 newctrl &= ~ACM_CTRL_DTR; 997 newctrl &= ~ACM_CTRL_DTR;
986 } else 998 } else if (termios_old && (termios_old->c_cflag & CBAUD) == B0) {
987 newctrl |= ACM_CTRL_DTR; 999 newctrl |= ACM_CTRL_DTR;
1000 }
988 1001
989 if (newctrl != acm->ctrlout) 1002 if (newctrl != acm->ctrlout)
990 acm_set_control(acm, acm->ctrlout = newctrl); 1003 acm_set_control(acm, acm->ctrlout = newctrl);
@@ -1314,6 +1327,7 @@ made_compressed_probe:
1314 tty_port_init(&acm->port); 1327 tty_port_init(&acm->port);
1315 acm->port.ops = &acm_port_ops; 1328 acm->port.ops = &acm_port_ops;
1316 init_usb_anchor(&acm->delayed); 1329 init_usb_anchor(&acm->delayed);
1330 acm->quirks = quirks;
1317 1331
1318 buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); 1332 buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
1319 if (!buf) { 1333 if (!buf) {
@@ -1681,6 +1695,9 @@ static const struct usb_device_id acm_ids[] = {
1681 { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */ 1695 { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */
1682 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ 1696 .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
1683 }, 1697 },
1698 { USB_DEVICE(0x20df, 0x0001), /* Simtec Electronics Entropy Key */
1699 .driver_info = QUIRK_CONTROL_LINE_STATE, },
1700 { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */
1684 { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */ 1701 { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */
1685 }, 1702 },
1686 /* Motorola H24 HSPA module: */ 1703 /* Motorola H24 HSPA module: */
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index fc75651afe1c..d3251ebd09e2 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -121,6 +121,7 @@ struct acm {
121 unsigned int throttle_req:1; /* throttle requested */ 121 unsigned int throttle_req:1; /* throttle requested */
122 u8 bInterval; 122 u8 bInterval;
123 struct usb_anchor delayed; /* writes queued for a device about to be woken */ 123 struct usb_anchor delayed; /* writes queued for a device about to be woken */
124 unsigned long quirks;
124}; 125};
125 126
126#define CDC_DATA_INTERFACE_TYPE 0x0a 127#define CDC_DATA_INTERFACE_TYPE 0x0a
@@ -132,3 +133,4 @@ struct acm {
132#define NOT_A_MODEM BIT(3) 133#define NOT_A_MODEM BIT(3)
133#define NO_DATA_INTERFACE BIT(4) 134#define NO_DATA_INTERFACE BIT(4)
134#define IGNORE_DEVICE BIT(5) 135#define IGNORE_DEVICE BIT(5)
136#define QUIRK_CONTROL_LINE_STATE BIT(6)
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index b84fb141e122..a6efb4184f2b 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2060,6 +2060,8 @@ int usb_alloc_streams(struct usb_interface *interface,
2060 return -EINVAL; 2060 return -EINVAL;
2061 if (dev->speed != USB_SPEED_SUPER) 2061 if (dev->speed != USB_SPEED_SUPER)
2062 return -EINVAL; 2062 return -EINVAL;
2063 if (dev->state < USB_STATE_CONFIGURED)
2064 return -ENODEV;
2063 2065
2064 for (i = 0; i < num_eps; i++) { 2066 for (i = 0; i < num_eps; i++) {
2065 /* Streams only apply to bulk endpoints. */ 2067 /* Streams only apply to bulk endpoints. */
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 11e80ac31324..b649fef2e35d 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -4468,9 +4468,6 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
4468 if (retval) 4468 if (retval)
4469 goto fail; 4469 goto fail;
4470 4470
4471 if (hcd->usb_phy && !hdev->parent)
4472 usb_phy_notify_connect(hcd->usb_phy, udev->speed);
4473
4474 /* 4471 /*
4475 * Some superspeed devices have finished the link training process 4472 * Some superspeed devices have finished the link training process
4476 * and attached to a superspeed hub port, but the device descriptor 4473 * and attached to a superspeed hub port, but the device descriptor
@@ -4627,8 +4624,7 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
4627 4624
4628 /* Disconnect any existing devices under this port */ 4625 /* Disconnect any existing devices under this port */
4629 if (udev) { 4626 if (udev) {
4630 if (hcd->usb_phy && !hdev->parent && 4627 if (hcd->usb_phy && !hdev->parent)
4631 !(portstatus & USB_PORT_STAT_CONNECTION))
4632 usb_phy_notify_disconnect(hcd->usb_phy, udev->speed); 4628 usb_phy_notify_disconnect(hcd->usb_phy, udev->speed);
4633 usb_disconnect(&port_dev->child); 4629 usb_disconnect(&port_dev->child);
4634 } 4630 }
@@ -4783,6 +4779,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
4783 port_dev->child = NULL; 4779 port_dev->child = NULL;
4784 spin_unlock_irq(&device_state_lock); 4780 spin_unlock_irq(&device_state_lock);
4785 mutex_unlock(&usb_port_peer_mutex); 4781 mutex_unlock(&usb_port_peer_mutex);
4782 } else {
4783 if (hcd->usb_phy && !hdev->parent)
4784 usb_phy_notify_connect(hcd->usb_phy,
4785 udev->speed);
4786 } 4786 }
4787 } 4787 }
4788 4788
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 5ae883dc21f5..96fafed92b76 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -44,6 +44,9 @@ static const struct usb_device_id usb_quirk_list[] = {
44 /* Creative SB Audigy 2 NX */ 44 /* Creative SB Audigy 2 NX */
45 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME }, 45 { USB_DEVICE(0x041e, 0x3020), .driver_info = USB_QUIRK_RESET_RESUME },
46 46
47 /* Microsoft Wireless Laser Mouse 6000 Receiver */
48 { USB_DEVICE(0x045e, 0x00e1), .driver_info = USB_QUIRK_RESET_RESUME },
49
47 /* Microsoft LifeCam-VX700 v2.0 */ 50 /* Microsoft LifeCam-VX700 v2.0 */
48 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME }, 51 { USB_DEVICE(0x045e, 0x0770), .driver_info = USB_QUIRK_RESET_RESUME },
49 52
@@ -97,6 +100,12 @@ static const struct usb_device_id usb_quirk_list[] = {
97 { USB_DEVICE(0x04f3, 0x0089), .driver_info = 100 { USB_DEVICE(0x04f3, 0x0089), .driver_info =
98 USB_QUIRK_DEVICE_QUALIFIER }, 101 USB_QUIRK_DEVICE_QUALIFIER },
99 102
103 { USB_DEVICE(0x04f3, 0x009b), .driver_info =
104 USB_QUIRK_DEVICE_QUALIFIER },
105
106 { USB_DEVICE(0x04f3, 0x016f), .driver_info =
107 USB_QUIRK_DEVICE_QUALIFIER },
108
100 /* Roland SC-8820 */ 109 /* Roland SC-8820 */
101 { USB_DEVICE(0x0582, 0x0007), .driver_info = USB_QUIRK_RESET_RESUME }, 110 { USB_DEVICE(0x0582, 0x0007), .driver_info = USB_QUIRK_RESET_RESUME },
102 111
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index eee87098bb8b..8b5c079c7b7d 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2327,7 +2327,7 @@ irq_retry:
2327 2327
2328 u32 usb_status = readl(hsotg->regs + GOTGCTL); 2328 u32 usb_status = readl(hsotg->regs + GOTGCTL);
2329 2329
2330 dev_info(hsotg->dev, "%s: USBRst\n", __func__); 2330 dev_dbg(hsotg->dev, "%s: USBRst\n", __func__);
2331 dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n", 2331 dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n",
2332 readl(hsotg->regs + GNPTXSTS)); 2332 readl(hsotg->regs + GNPTXSTS));
2333 2333
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 711b23019d54..df38e7ef4976 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -791,6 +791,10 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
791 791
792 trb = dwc->ep0_trb; 792 trb = dwc->ep0_trb;
793 793
794 r = next_request(&ep0->request_list);
795 if (!r)
796 return;
797
794 status = DWC3_TRB_SIZE_TRBSTS(trb->size); 798 status = DWC3_TRB_SIZE_TRBSTS(trb->size);
795 if (status == DWC3_TRBSTS_SETUP_PENDING) { 799 if (status == DWC3_TRBSTS_SETUP_PENDING) {
796 dwc3_trace(trace_dwc3_ep0, "Setup Pending received"); 800 dwc3_trace(trace_dwc3_ep0, "Setup Pending received");
@@ -801,10 +805,6 @@ static void dwc3_ep0_complete_data(struct dwc3 *dwc,
801 return; 805 return;
802 } 806 }
803 807
804 r = next_request(&ep0->request_list);
805 if (!r)
806 return;
807
808 ur = &r->request; 808 ur = &r->request;
809 809
810 length = trb->size & DWC3_TRB_SIZE_MASK; 810 length = trb->size & DWC3_TRB_SIZE_MASK;
diff --git a/drivers/usb/gadget/legacy/tcm_usb_gadget.c b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
index 6cdb7a534f23..024f58475a94 100644
--- a/drivers/usb/gadget/legacy/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
@@ -912,7 +912,7 @@ static int get_cmd_dir(const unsigned char *cdb)
912 case INQUIRY: 912 case INQUIRY:
913 case MODE_SENSE: 913 case MODE_SENSE:
914 case MODE_SENSE_10: 914 case MODE_SENSE_10:
915 case SERVICE_ACTION_IN: 915 case SERVICE_ACTION_IN_16:
916 case MAINTENANCE_IN: 916 case MAINTENANCE_IN:
917 case PERSISTENT_RESERVE_IN: 917 case PERSISTENT_RESERVE_IN:
918 case SECURITY_PROTOCOL_IN: 918 case SECURITY_PROTOCOL_IN:
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index a8a30b1d4167..a3ca1375dd52 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -234,7 +234,7 @@ config USB_EHCI_SH
234 234
235config USB_EHCI_EXYNOS 235config USB_EHCI_EXYNOS
236 tristate "EHCI support for Samsung S5P/EXYNOS SoC Series" 236 tristate "EHCI support for Samsung S5P/EXYNOS SoC Series"
237 depends on PLAT_S5P || ARCH_EXYNOS 237 depends on ARCH_S5PV210 || ARCH_EXYNOS
238 help 238 help
239 Enable support for the Samsung Exynos SOC's on-chip EHCI controller. 239 Enable support for the Samsung Exynos SOC's on-chip EHCI controller.
240 240
@@ -550,7 +550,7 @@ config USB_OHCI_SH
550 550
551config USB_OHCI_EXYNOS 551config USB_OHCI_EXYNOS
552 tristate "OHCI support for Samsung S5P/EXYNOS SoC Series" 552 tristate "OHCI support for Samsung S5P/EXYNOS SoC Series"
553 depends on PLAT_S5P || ARCH_EXYNOS 553 depends on ARCH_S5PV210 || ARCH_EXYNOS
554 help 554 help
555 Enable support for the Samsung Exynos SOC's on-chip OHCI controller. 555 Enable support for the Samsung Exynos SOC's on-chip OHCI controller.
556 556
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
index d0d8fadf7066..1db0626c8bf4 100644
--- a/drivers/usb/host/hwa-hc.c
+++ b/drivers/usb/host/hwa-hc.c
@@ -607,7 +607,7 @@ found:
607 wa->wa_descr = wa_descr = (struct usb_wa_descriptor *) hdr; 607 wa->wa_descr = wa_descr = (struct usb_wa_descriptor *) hdr;
608 if (le16_to_cpu(wa_descr->bcdWAVersion) > 0x0100) 608 if (le16_to_cpu(wa_descr->bcdWAVersion) > 0x0100)
609 dev_warn(dev, "Wire Adapter v%d.%d newer than groked v1.0\n", 609 dev_warn(dev, "Wire Adapter v%d.%d newer than groked v1.0\n",
610 le16_to_cpu(wa_descr->bcdWAVersion) & 0xff00 >> 8, 610 (le16_to_cpu(wa_descr->bcdWAVersion) & 0xff00) >> 8,
611 le16_to_cpu(wa_descr->bcdWAVersion) & 0x00ff); 611 le16_to_cpu(wa_descr->bcdWAVersion) & 0x00ff);
612 result = 0; 612 result = 0;
613error: 613error:
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 696160d48ae8..388cfd83b6b6 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -22,7 +22,6 @@
22 22
23 23
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/device.h>
26#include <asm/unaligned.h> 25#include <asm/unaligned.h>
27 26
28#include "xhci.h" 27#include "xhci.h"
@@ -1149,9 +1148,7 @@ int xhci_bus_suspend(struct usb_hcd *hcd)
1149 * including the USB 3.0 roothub, but only if CONFIG_PM_RUNTIME 1148 * including the USB 3.0 roothub, but only if CONFIG_PM_RUNTIME
1150 * is enabled, so also enable remote wake here. 1149 * is enabled, so also enable remote wake here.
1151 */ 1150 */
1152 if (hcd->self.root_hub->do_remote_wakeup 1151 if (hcd->self.root_hub->do_remote_wakeup) {
1153 && device_may_wakeup(hcd->self.controller)) {
1154
1155 if (t1 & PORT_CONNECT) { 1152 if (t1 & PORT_CONNECT) {
1156 t2 |= PORT_WKOC_E | PORT_WKDISC_E; 1153 t2 |= PORT_WKOC_E | PORT_WKDISC_E;
1157 t2 &= ~PORT_WKCONN_E; 1154 t2 &= ~PORT_WKCONN_E;
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 280dde93abe5..142b601f9563 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -128,20 +128,6 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
128 xhci->quirks |= XHCI_AVOID_BEI; 128 xhci->quirks |= XHCI_AVOID_BEI;
129 } 129 }
130 if (pdev->vendor == PCI_VENDOR_ID_INTEL && 130 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
131 (pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_XHCI ||
132 pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI)) {
133 /* Workaround for occasional spurious wakeups from S5 (or
134 * any other sleep) on Haswell machines with LPT and LPT-LP
135 * with the new Intel BIOS
136 */
137 /* Limit the quirk to only known vendors, as this triggers
138 * yet another BIOS bug on some other machines
139 * https://bugzilla.kernel.org/show_bug.cgi?id=66171
140 */
141 if (pdev->subsystem_vendor == PCI_VENDOR_ID_HP)
142 xhci->quirks |= XHCI_SPURIOUS_WAKEUP;
143 }
144 if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
145 pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI) { 131 pdev->device == PCI_DEVICE_ID_INTEL_LYNXPOINT_LP_XHCI) {
146 xhci->quirks |= XHCI_SPURIOUS_REBOOT; 132 xhci->quirks |= XHCI_SPURIOUS_REBOOT;
147 } 133 }
@@ -162,6 +148,10 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)
162 pdev->device == 0x3432) 148 pdev->device == 0x3432)
163 xhci->quirks |= XHCI_BROKEN_STREAMS; 149 xhci->quirks |= XHCI_BROKEN_STREAMS;
164 150
151 if (pdev->vendor == PCI_VENDOR_ID_ASMEDIA &&
152 pdev->device == 0x1042)
153 xhci->quirks |= XHCI_BROKEN_STREAMS;
154
165 if (xhci->quirks & XHCI_RESET_ON_RESUME) 155 if (xhci->quirks & XHCI_RESET_ON_RESUME)
166 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks, 156 xhci_dbg_trace(xhci, trace_xhci_dbg_quirks,
167 "QUIRK: Resetting on resume"); 157 "QUIRK: Resetting on resume");
@@ -291,7 +281,7 @@ static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
291 if (xhci->quirks & XHCI_COMP_MODE_QUIRK) 281 if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
292 pdev->no_d3cold = true; 282 pdev->no_d3cold = true;
293 283
294 return xhci_suspend(xhci); 284 return xhci_suspend(xhci, do_wakeup);
295} 285}
296 286
297static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated) 287static int xhci_pci_resume(struct usb_hcd *hcd, bool hibernated)
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 3d78b0cd674b..646300cbe5f7 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -204,7 +204,15 @@ static int xhci_plat_suspend(struct device *dev)
204 struct usb_hcd *hcd = dev_get_drvdata(dev); 204 struct usb_hcd *hcd = dev_get_drvdata(dev);
205 struct xhci_hcd *xhci = hcd_to_xhci(hcd); 205 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
206 206
207 return xhci_suspend(xhci); 207 /*
208 * xhci_suspend() needs `do_wakeup` to know whether host is allowed
209 * to do wakeup during suspend. Since xhci_plat_suspend is currently
210 * only designed for system suspend, device_may_wakeup() is enough
211 * to dertermine whether host is allowed to do wakeup. Need to
212 * reconsider this when xhci_plat_suspend enlarges its scope, e.g.,
213 * also applies to runtime suspend.
214 */
215 return xhci_suspend(xhci, device_may_wakeup(dev));
208} 216}
209 217
210static int xhci_plat_resume(struct device *dev) 218static int xhci_plat_resume(struct device *dev)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index bc6fcbc16f61..06433aec81d7 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1067,9 +1067,8 @@ static void xhci_handle_cmd_reset_ep(struct xhci_hcd *xhci, int slot_id,
1067 false); 1067 false);
1068 xhci_ring_cmd_db(xhci); 1068 xhci_ring_cmd_db(xhci);
1069 } else { 1069 } else {
1070 /* Clear our internal halted state and restart the ring(s) */ 1070 /* Clear our internal halted state */
1071 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_HALTED; 1071 xhci->devs[slot_id]->eps[ep_index].ep_state &= ~EP_HALTED;
1072 ring_doorbell_for_active_rings(xhci, slot_id, ep_index);
1073 } 1072 }
1074} 1073}
1075 1074
@@ -1823,22 +1822,13 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td,
1823 ep->stopped_td = td; 1822 ep->stopped_td = td;
1824 return 0; 1823 return 0;
1825 } else { 1824 } else {
1826 if (trb_comp_code == COMP_STALL) { 1825 if (trb_comp_code == COMP_STALL ||
1827 /* The transfer is completed from the driver's 1826 xhci_requires_manual_halt_cleanup(xhci, ep_ctx,
1828 * perspective, but we need to issue a set dequeue 1827 trb_comp_code)) {
1829 * command for this stalled endpoint to move the dequeue 1828 /* Issue a reset endpoint command to clear the host side
1830 * pointer past the TD. We can't do that here because 1829 * halt, followed by a set dequeue command to move the
1831 * the halt condition must be cleared first. Let the 1830 * dequeue pointer past the TD.
1832 * USB class driver clear the stall later. 1831 * The class driver clears the device side halt later.
1833 */
1834 ep->stopped_td = td;
1835 ep->stopped_stream = ep_ring->stream_id;
1836 } else if (xhci_requires_manual_halt_cleanup(xhci,
1837 ep_ctx, trb_comp_code)) {
1838 /* Other types of errors halt the endpoint, but the
1839 * class driver doesn't call usb_reset_endpoint() unless
1840 * the error is -EPIPE. Clear the halted status in the
1841 * xHCI hardware manually.
1842 */ 1832 */
1843 xhci_cleanup_halted_endpoint(xhci, 1833 xhci_cleanup_halted_endpoint(xhci,
1844 slot_id, ep_index, ep_ring->stream_id, 1834 slot_id, ep_index, ep_ring->stream_id,
@@ -1958,9 +1948,7 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
1958 else 1948 else
1959 td->urb->actual_length = 0; 1949 td->urb->actual_length = 0;
1960 1950
1961 xhci_cleanup_halted_endpoint(xhci, 1951 return finish_td(xhci, td, event_trb, event, ep, status, false);
1962 slot_id, ep_index, 0, td, event_trb);
1963 return finish_td(xhci, td, event_trb, event, ep, status, true);
1964 } 1952 }
1965 /* 1953 /*
1966 * Did we transfer any data, despite the errors that might have 1954 * Did we transfer any data, despite the errors that might have
@@ -2519,17 +2507,8 @@ cleanup:
2519 if (ret) { 2507 if (ret) {
2520 urb = td->urb; 2508 urb = td->urb;
2521 urb_priv = urb->hcpriv; 2509 urb_priv = urb->hcpriv;
2522 /* Leave the TD around for the reset endpoint function 2510
2523 * to use(but only if it's not a control endpoint, 2511 xhci_urb_free_priv(xhci, urb_priv);
2524 * since we already queued the Set TR dequeue pointer
2525 * command for stalled control endpoints).
2526 */
2527 if (usb_endpoint_xfer_control(&urb->ep->desc) ||
2528 (trb_comp_code != COMP_STALL &&
2529 trb_comp_code != COMP_BABBLE))
2530 xhci_urb_free_priv(xhci, urb_priv);
2531 else
2532 kfree(urb_priv);
2533 2512
2534 usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb); 2513 usb_hcd_unlink_urb_from_ep(bus_to_hcd(urb->dev->bus), urb);
2535 if ((urb->actual_length != urb->transfer_buffer_length && 2514 if ((urb->actual_length != urb->transfer_buffer_length &&
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 2a5d45b4cb15..033b46c470bd 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -35,6 +35,8 @@
35#define DRIVER_AUTHOR "Sarah Sharp" 35#define DRIVER_AUTHOR "Sarah Sharp"
36#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver" 36#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
37 37
38#define PORT_WAKE_BITS (PORT_WKOC_E | PORT_WKDISC_E | PORT_WKCONN_E)
39
38/* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */ 40/* Some 0.95 hardware can't handle the chain bit on a Link TRB being cleared */
39static int link_quirk; 41static int link_quirk;
40module_param(link_quirk, int, S_IRUGO | S_IWUSR); 42module_param(link_quirk, int, S_IRUGO | S_IWUSR);
@@ -851,13 +853,47 @@ static void xhci_clear_command_ring(struct xhci_hcd *xhci)
851 xhci_set_cmd_ring_deq(xhci); 853 xhci_set_cmd_ring_deq(xhci);
852} 854}
853 855
856static void xhci_disable_port_wake_on_bits(struct xhci_hcd *xhci)
857{
858 int port_index;
859 __le32 __iomem **port_array;
860 unsigned long flags;
861 u32 t1, t2;
862
863 spin_lock_irqsave(&xhci->lock, flags);
864
865 /* disble usb3 ports Wake bits*/
866 port_index = xhci->num_usb3_ports;
867 port_array = xhci->usb3_ports;
868 while (port_index--) {
869 t1 = readl(port_array[port_index]);
870 t1 = xhci_port_state_to_neutral(t1);
871 t2 = t1 & ~PORT_WAKE_BITS;
872 if (t1 != t2)
873 writel(t2, port_array[port_index]);
874 }
875
876 /* disble usb2 ports Wake bits*/
877 port_index = xhci->num_usb2_ports;
878 port_array = xhci->usb2_ports;
879 while (port_index--) {
880 t1 = readl(port_array[port_index]);
881 t1 = xhci_port_state_to_neutral(t1);
882 t2 = t1 & ~PORT_WAKE_BITS;
883 if (t1 != t2)
884 writel(t2, port_array[port_index]);
885 }
886
887 spin_unlock_irqrestore(&xhci->lock, flags);
888}
889
854/* 890/*
855 * Stop HC (not bus-specific) 891 * Stop HC (not bus-specific)
856 * 892 *
857 * This is called when the machine transition into S3/S4 mode. 893 * This is called when the machine transition into S3/S4 mode.
858 * 894 *
859 */ 895 */
860int xhci_suspend(struct xhci_hcd *xhci) 896int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup)
861{ 897{
862 int rc = 0; 898 int rc = 0;
863 unsigned int delay = XHCI_MAX_HALT_USEC; 899 unsigned int delay = XHCI_MAX_HALT_USEC;
@@ -868,6 +904,10 @@ int xhci_suspend(struct xhci_hcd *xhci)
868 xhci->shared_hcd->state != HC_STATE_SUSPENDED) 904 xhci->shared_hcd->state != HC_STATE_SUSPENDED)
869 return -EINVAL; 905 return -EINVAL;
870 906
907 /* Clear root port wake on bits if wakeup not allowed. */
908 if (!do_wakeup)
909 xhci_disable_port_wake_on_bits(xhci);
910
871 /* Don't poll the roothubs on bus suspend. */ 911 /* Don't poll the roothubs on bus suspend. */
872 xhci_dbg(xhci, "%s: stopping port polling.\n", __func__); 912 xhci_dbg(xhci, "%s: stopping port polling.\n", __func__);
873 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags); 913 clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
@@ -2912,68 +2952,33 @@ void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
2912 } 2952 }
2913} 2953}
2914 2954
2915/* Deal with stalled endpoints. The core should have sent the control message 2955/* Called when clearing halted device. The core should have sent the control
2916 * to clear the halt condition. However, we need to make the xHCI hardware 2956 * message to clear the device halt condition. The host side of the halt should
2917 * reset its sequence number, since a device will expect a sequence number of 2957 * already be cleared with a reset endpoint command issued when the STALL tx
2918 * zero after the halt condition is cleared. 2958 * event was received.
2959 *
2919 * Context: in_interrupt 2960 * Context: in_interrupt
2920 */ 2961 */
2962
2921void xhci_endpoint_reset(struct usb_hcd *hcd, 2963void xhci_endpoint_reset(struct usb_hcd *hcd,
2922 struct usb_host_endpoint *ep) 2964 struct usb_host_endpoint *ep)
2923{ 2965{
2924 struct xhci_hcd *xhci; 2966 struct xhci_hcd *xhci;
2925 struct usb_device *udev;
2926 unsigned int ep_index;
2927 unsigned long flags;
2928 int ret;
2929 struct xhci_virt_ep *virt_ep;
2930 struct xhci_command *command;
2931 2967
2932 xhci = hcd_to_xhci(hcd); 2968 xhci = hcd_to_xhci(hcd);
2933 udev = (struct usb_device *) ep->hcpriv;
2934 /* Called with a root hub endpoint (or an endpoint that wasn't added
2935 * with xhci_add_endpoint()
2936 */
2937 if (!ep->hcpriv)
2938 return;
2939 ep_index = xhci_get_endpoint_index(&ep->desc);
2940 virt_ep = &xhci->devs[udev->slot_id]->eps[ep_index];
2941 if (!virt_ep->stopped_td) {
2942 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2943 "Endpoint 0x%x not halted, refusing to reset.",
2944 ep->desc.bEndpointAddress);
2945 return;
2946 }
2947 if (usb_endpoint_xfer_control(&ep->desc)) {
2948 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2949 "Control endpoint stall already handled.");
2950 return;
2951 }
2952 2969
2953 command = xhci_alloc_command(xhci, false, false, GFP_ATOMIC);
2954 if (!command)
2955 return;
2956
2957 xhci_dbg_trace(xhci, trace_xhci_dbg_reset_ep,
2958 "Queueing reset endpoint command");
2959 spin_lock_irqsave(&xhci->lock, flags);
2960 ret = xhci_queue_reset_ep(xhci, command, udev->slot_id, ep_index);
2961 /* 2970 /*
2962 * Can't change the ring dequeue pointer until it's transitioned to the 2971 * We might need to implement the config ep cmd in xhci 4.8.1 note:
2963 * stopped state, which is only upon a successful reset endpoint 2972 * The Reset Endpoint Command may only be issued to endpoints in the
2964 * command. Better hope that last command worked! 2973 * Halted state. If software wishes reset the Data Toggle or Sequence
2974 * Number of an endpoint that isn't in the Halted state, then software
2975 * may issue a Configure Endpoint Command with the Drop and Add bits set
2976 * for the target endpoint. that is in the Stopped state.
2965 */ 2977 */
2966 if (!ret) {
2967 xhci_cleanup_stalled_ring(xhci, udev, ep_index);
2968 kfree(virt_ep->stopped_td);
2969 xhci_ring_cmd_db(xhci);
2970 }
2971 virt_ep->stopped_td = NULL;
2972 virt_ep->stopped_stream = 0;
2973 spin_unlock_irqrestore(&xhci->lock, flags);
2974 2978
2975 if (ret) 2979 /* For now just print debug to follow the situation */
2976 xhci_warn(xhci, "FIXME allocate a new ring segment\n"); 2980 xhci_dbg(xhci, "Endpoint 0x%x ep reset callback called\n",
2981 ep->desc.bEndpointAddress);
2977} 2982}
2978 2983
2979static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, 2984static int xhci_check_streams_endpoint(struct xhci_hcd *xhci,
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index df76d642e719..d745715a1e2f 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1746,7 +1746,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
1746void xhci_init_driver(struct hc_driver *drv, int (*setup_fn)(struct usb_hcd *)); 1746void xhci_init_driver(struct hc_driver *drv, int (*setup_fn)(struct usb_hcd *));
1747 1747
1748#ifdef CONFIG_PM 1748#ifdef CONFIG_PM
1749int xhci_suspend(struct xhci_hcd *xhci); 1749int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup);
1750int xhci_resume(struct xhci_hcd *xhci, bool hibernated); 1750int xhci_resume(struct xhci_hcd *xhci, bool hibernated);
1751#else 1751#else
1752#define xhci_suspend NULL 1752#define xhci_suspend NULL
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index cfd009dc4018..6c4eb3cf5efd 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -120,6 +120,7 @@ static const struct usb_device_id id_table[] = {
120 { USB_DEVICE(0x10C4, 0x85F8) }, /* Virtenio Preon32 */ 120 { USB_DEVICE(0x10C4, 0x85F8) }, /* Virtenio Preon32 */
121 { USB_DEVICE(0x10C4, 0x8664) }, /* AC-Services CAN-IF */ 121 { USB_DEVICE(0x10C4, 0x8664) }, /* AC-Services CAN-IF */
122 { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */ 122 { USB_DEVICE(0x10C4, 0x8665) }, /* AC-Services OBD-IF */
123 { USB_DEVICE(0x10C4, 0x8875) }, /* CEL MeshConnect USB Stick */
123 { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */ 124 { USB_DEVICE(0x10C4, 0x88A4) }, /* MMB Networks ZigBee USB Device */
124 { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */ 125 { USB_DEVICE(0x10C4, 0x88A5) }, /* Planet Innovation Ingeni ZigBee USB Device */
125 { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */ 126 { USB_DEVICE(0x10C4, 0x8946) }, /* Ketra N1 Wireless Interface */
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 0dad8ce5a609..1ebb351b9e9a 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -470,6 +470,39 @@ static const struct usb_device_id id_table_combined[] = {
470 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FD_PID) }, 470 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FD_PID) },
471 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FE_PID) }, 471 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FE_PID) },
472 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FF_PID) }, 472 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_01FF_PID) },
473 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_4701_PID) },
474 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9300_PID) },
475 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9301_PID) },
476 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9302_PID) },
477 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9303_PID) },
478 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9304_PID) },
479 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9305_PID) },
480 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9306_PID) },
481 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9307_PID) },
482 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9308_PID) },
483 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9309_PID) },
484 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930A_PID) },
485 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930B_PID) },
486 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930C_PID) },
487 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930D_PID) },
488 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930E_PID) },
489 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_930F_PID) },
490 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9310_PID) },
491 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9311_PID) },
492 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9312_PID) },
493 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9313_PID) },
494 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9314_PID) },
495 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9315_PID) },
496 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9316_PID) },
497 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9317_PID) },
498 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9318_PID) },
499 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_9319_PID) },
500 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931A_PID) },
501 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931B_PID) },
502 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931C_PID) },
503 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931D_PID) },
504 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931E_PID) },
505 { USB_DEVICE(MTXORB_VID, MTXORB_FTDI_RANGE_931F_PID) },
473 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) }, 506 { USB_DEVICE(FTDI_VID, FTDI_PERLE_ULTRAPORT_PID) },
474 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) }, 507 { USB_DEVICE(FTDI_VID, FTDI_PIEGROUP_PID) },
475 { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) }, 508 { USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) },
diff --git a/drivers/usb/serial/ftdi_sio_ids.h b/drivers/usb/serial/ftdi_sio_ids.h
index 6786b705ccf6..e52409c9be99 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -926,8 +926,8 @@
926#define BAYER_CONTOUR_CABLE_PID 0x6001 926#define BAYER_CONTOUR_CABLE_PID 0x6001
927 927
928/* 928/*
929 * The following are the values for the Matrix Orbital FTDI Range 929 * Matrix Orbital Intelligent USB displays.
930 * Anything in this range will use an FT232RL. 930 * http://www.matrixorbital.com
931 */ 931 */
932#define MTXORB_VID 0x1B3D 932#define MTXORB_VID 0x1B3D
933#define MTXORB_FTDI_RANGE_0100_PID 0x0100 933#define MTXORB_FTDI_RANGE_0100_PID 0x0100
@@ -1186,8 +1186,39 @@
1186#define MTXORB_FTDI_RANGE_01FD_PID 0x01FD 1186#define MTXORB_FTDI_RANGE_01FD_PID 0x01FD
1187#define MTXORB_FTDI_RANGE_01FE_PID 0x01FE 1187#define MTXORB_FTDI_RANGE_01FE_PID 0x01FE
1188#define MTXORB_FTDI_RANGE_01FF_PID 0x01FF 1188#define MTXORB_FTDI_RANGE_01FF_PID 0x01FF
1189 1189#define MTXORB_FTDI_RANGE_4701_PID 0x4701
1190 1190#define MTXORB_FTDI_RANGE_9300_PID 0x9300
1191#define MTXORB_FTDI_RANGE_9301_PID 0x9301
1192#define MTXORB_FTDI_RANGE_9302_PID 0x9302
1193#define MTXORB_FTDI_RANGE_9303_PID 0x9303
1194#define MTXORB_FTDI_RANGE_9304_PID 0x9304
1195#define MTXORB_FTDI_RANGE_9305_PID 0x9305
1196#define MTXORB_FTDI_RANGE_9306_PID 0x9306
1197#define MTXORB_FTDI_RANGE_9307_PID 0x9307
1198#define MTXORB_FTDI_RANGE_9308_PID 0x9308
1199#define MTXORB_FTDI_RANGE_9309_PID 0x9309
1200#define MTXORB_FTDI_RANGE_930A_PID 0x930A
1201#define MTXORB_FTDI_RANGE_930B_PID 0x930B
1202#define MTXORB_FTDI_RANGE_930C_PID 0x930C
1203#define MTXORB_FTDI_RANGE_930D_PID 0x930D
1204#define MTXORB_FTDI_RANGE_930E_PID 0x930E
1205#define MTXORB_FTDI_RANGE_930F_PID 0x930F
1206#define MTXORB_FTDI_RANGE_9310_PID 0x9310
1207#define MTXORB_FTDI_RANGE_9311_PID 0x9311
1208#define MTXORB_FTDI_RANGE_9312_PID 0x9312
1209#define MTXORB_FTDI_RANGE_9313_PID 0x9313
1210#define MTXORB_FTDI_RANGE_9314_PID 0x9314
1211#define MTXORB_FTDI_RANGE_9315_PID 0x9315
1212#define MTXORB_FTDI_RANGE_9316_PID 0x9316
1213#define MTXORB_FTDI_RANGE_9317_PID 0x9317
1214#define MTXORB_FTDI_RANGE_9318_PID 0x9318
1215#define MTXORB_FTDI_RANGE_9319_PID 0x9319
1216#define MTXORB_FTDI_RANGE_931A_PID 0x931A
1217#define MTXORB_FTDI_RANGE_931B_PID 0x931B
1218#define MTXORB_FTDI_RANGE_931C_PID 0x931C
1219#define MTXORB_FTDI_RANGE_931D_PID 0x931D
1220#define MTXORB_FTDI_RANGE_931E_PID 0x931E
1221#define MTXORB_FTDI_RANGE_931F_PID 0x931F
1191 1222
1192/* 1223/*
1193 * The Mobility Lab (TML) 1224 * The Mobility Lab (TML)
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 93cb7cebda62..077c714f1285 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -311,24 +311,30 @@ static void usa26_indat_callback(struct urb *urb)
311 if ((data[0] & 0x80) == 0) { 311 if ((data[0] & 0x80) == 0) {
312 /* no errors on individual bytes, only 312 /* no errors on individual bytes, only
313 possible overrun err */ 313 possible overrun err */
314 if (data[0] & RXERROR_OVERRUN) 314 if (data[0] & RXERROR_OVERRUN) {
315 err = TTY_OVERRUN; 315 tty_insert_flip_char(&port->port, 0,
316 else 316 TTY_OVERRUN);
317 err = 0; 317 }
318 for (i = 1; i < urb->actual_length ; ++i) 318 for (i = 1; i < urb->actual_length ; ++i)
319 tty_insert_flip_char(&port->port, data[i], err); 319 tty_insert_flip_char(&port->port, data[i],
320 TTY_NORMAL);
320 } else { 321 } else {
321 /* some bytes had errors, every byte has status */ 322 /* some bytes had errors, every byte has status */
322 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__); 323 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
323 for (i = 0; i + 1 < urb->actual_length; i += 2) { 324 for (i = 0; i + 1 < urb->actual_length; i += 2) {
324 int stat = data[i], flag = 0; 325 int stat = data[i];
325 if (stat & RXERROR_OVERRUN) 326 int flag = TTY_NORMAL;
326 flag |= TTY_OVERRUN; 327
327 if (stat & RXERROR_FRAMING) 328 if (stat & RXERROR_OVERRUN) {
328 flag |= TTY_FRAME; 329 tty_insert_flip_char(&port->port, 0,
329 if (stat & RXERROR_PARITY) 330 TTY_OVERRUN);
330 flag |= TTY_PARITY; 331 }
331 /* XXX should handle break (0x10) */ 332 /* XXX should handle break (0x10) */
333 if (stat & RXERROR_PARITY)
334 flag = TTY_PARITY;
335 else if (stat & RXERROR_FRAMING)
336 flag = TTY_FRAME;
337
332 tty_insert_flip_char(&port->port, data[i+1], 338 tty_insert_flip_char(&port->port, data[i+1],
333 flag); 339 flag);
334 } 340 }
@@ -649,14 +655,19 @@ static void usa49_indat_callback(struct urb *urb)
649 } else { 655 } else {
650 /* some bytes had errors, every byte has status */ 656 /* some bytes had errors, every byte has status */
651 for (i = 0; i + 1 < urb->actual_length; i += 2) { 657 for (i = 0; i + 1 < urb->actual_length; i += 2) {
652 int stat = data[i], flag = 0; 658 int stat = data[i];
653 if (stat & RXERROR_OVERRUN) 659 int flag = TTY_NORMAL;
654 flag |= TTY_OVERRUN; 660
655 if (stat & RXERROR_FRAMING) 661 if (stat & RXERROR_OVERRUN) {
656 flag |= TTY_FRAME; 662 tty_insert_flip_char(&port->port, 0,
657 if (stat & RXERROR_PARITY) 663 TTY_OVERRUN);
658 flag |= TTY_PARITY; 664 }
659 /* XXX should handle break (0x10) */ 665 /* XXX should handle break (0x10) */
666 if (stat & RXERROR_PARITY)
667 flag = TTY_PARITY;
668 else if (stat & RXERROR_FRAMING)
669 flag = TTY_FRAME;
670
660 tty_insert_flip_char(&port->port, data[i+1], 671 tty_insert_flip_char(&port->port, data[i+1],
661 flag); 672 flag);
662 } 673 }
@@ -713,15 +724,19 @@ static void usa49wg_indat_callback(struct urb *urb)
713 */ 724 */
714 for (x = 0; x + 1 < len && 725 for (x = 0; x + 1 < len &&
715 i + 1 < urb->actual_length; x += 2) { 726 i + 1 < urb->actual_length; x += 2) {
716 int stat = data[i], flag = 0; 727 int stat = data[i];
728 int flag = TTY_NORMAL;
717 729
718 if (stat & RXERROR_OVERRUN) 730 if (stat & RXERROR_OVERRUN) {
719 flag |= TTY_OVERRUN; 731 tty_insert_flip_char(&port->port, 0,
720 if (stat & RXERROR_FRAMING) 732 TTY_OVERRUN);
721 flag |= TTY_FRAME; 733 }
722 if (stat & RXERROR_PARITY)
723 flag |= TTY_PARITY;
724 /* XXX should handle break (0x10) */ 734 /* XXX should handle break (0x10) */
735 if (stat & RXERROR_PARITY)
736 flag = TTY_PARITY;
737 else if (stat & RXERROR_FRAMING)
738 flag = TTY_FRAME;
739
725 tty_insert_flip_char(&port->port, data[i+1], 740 tty_insert_flip_char(&port->port, data[i+1],
726 flag); 741 flag);
727 i += 2; 742 i += 2;
@@ -773,25 +788,31 @@ static void usa90_indat_callback(struct urb *urb)
773 if ((data[0] & 0x80) == 0) { 788 if ((data[0] & 0x80) == 0) {
774 /* no errors on individual bytes, only 789 /* no errors on individual bytes, only
775 possible overrun err*/ 790 possible overrun err*/
776 if (data[0] & RXERROR_OVERRUN) 791 if (data[0] & RXERROR_OVERRUN) {
777 err = TTY_OVERRUN; 792 tty_insert_flip_char(&port->port, 0,
778 else 793 TTY_OVERRUN);
779 err = 0; 794 }
780 for (i = 1; i < urb->actual_length ; ++i) 795 for (i = 1; i < urb->actual_length ; ++i)
781 tty_insert_flip_char(&port->port, 796 tty_insert_flip_char(&port->port,
782 data[i], err); 797 data[i], TTY_NORMAL);
783 } else { 798 } else {
784 /* some bytes had errors, every byte has status */ 799 /* some bytes had errors, every byte has status */
785 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__); 800 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
786 for (i = 0; i + 1 < urb->actual_length; i += 2) { 801 for (i = 0; i + 1 < urb->actual_length; i += 2) {
787 int stat = data[i], flag = 0; 802 int stat = data[i];
788 if (stat & RXERROR_OVERRUN) 803 int flag = TTY_NORMAL;
789 flag |= TTY_OVERRUN; 804
790 if (stat & RXERROR_FRAMING) 805 if (stat & RXERROR_OVERRUN) {
791 flag |= TTY_FRAME; 806 tty_insert_flip_char(
792 if (stat & RXERROR_PARITY) 807 &port->port, 0,
793 flag |= TTY_PARITY; 808 TTY_OVERRUN);
809 }
794 /* XXX should handle break (0x10) */ 810 /* XXX should handle break (0x10) */
811 if (stat & RXERROR_PARITY)
812 flag = TTY_PARITY;
813 else if (stat & RXERROR_FRAMING)
814 flag = TTY_FRAME;
815
795 tty_insert_flip_char(&port->port, 816 tty_insert_flip_char(&port->port,
796 data[i+1], flag); 817 data[i+1], flag);
797 } 818 }
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index 3d2bd65df0fc..02c420af251e 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -335,7 +335,8 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
335 port->interrupt_out_urb->transfer_buffer_length = length; 335 port->interrupt_out_urb->transfer_buffer_length = length;
336 336
337 priv->cur_pos = priv->cur_pos + length; 337 priv->cur_pos = priv->cur_pos + length;
338 result = usb_submit_urb(port->interrupt_out_urb, GFP_NOIO); 338 result = usb_submit_urb(port->interrupt_out_urb,
339 GFP_ATOMIC);
339 dev_dbg(&port->dev, "%s - Send write URB returns: %i\n", __func__, result); 340 dev_dbg(&port->dev, "%s - Send write URB returns: %i\n", __func__, result);
340 todo = priv->filled - priv->cur_pos; 341 todo = priv->filled - priv->cur_pos;
341 342
@@ -350,7 +351,7 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
350 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID || 351 if (priv->device_type == KOBIL_ADAPTER_B_PRODUCT_ID ||
351 priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) { 352 priv->device_type == KOBIL_ADAPTER_K_PRODUCT_ID) {
352 result = usb_submit_urb(port->interrupt_in_urb, 353 result = usb_submit_urb(port->interrupt_in_urb,
353 GFP_NOIO); 354 GFP_ATOMIC);
354 dev_dbg(&port->dev, "%s - Send read URB returns: %i\n", __func__, result); 355 dev_dbg(&port->dev, "%s - Send read URB returns: %i\n", __func__, result);
355 } 356 }
356 } 357 }
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index 4856fb7e637e..4b7bfb394a32 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -215,7 +215,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
215 215
216 /* The connected devices do not have a bulk write endpoint, 216 /* The connected devices do not have a bulk write endpoint,
217 * to transmit data to de barcode device the control endpoint is used */ 217 * to transmit data to de barcode device the control endpoint is used */
218 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_NOIO); 218 dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_ATOMIC);
219 if (!dr) { 219 if (!dr) {
220 count = -ENOMEM; 220 count = -ENOMEM;
221 goto error_no_dr; 221 goto error_no_dr;
diff --git a/drivers/usb/serial/ssu100.c b/drivers/usb/serial/ssu100.c
index a7fe664b6b7d..70a098de429f 100644
--- a/drivers/usb/serial/ssu100.c
+++ b/drivers/usb/serial/ssu100.c
@@ -490,10 +490,9 @@ static void ssu100_update_lsr(struct usb_serial_port *port, u8 lsr,
490 if (*tty_flag == TTY_NORMAL) 490 if (*tty_flag == TTY_NORMAL)
491 *tty_flag = TTY_FRAME; 491 *tty_flag = TTY_FRAME;
492 } 492 }
493 if (lsr & UART_LSR_OE){ 493 if (lsr & UART_LSR_OE) {
494 port->icount.overrun++; 494 port->icount.overrun++;
495 if (*tty_flag == TTY_NORMAL) 495 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
496 *tty_flag = TTY_OVERRUN;
497 } 496 }
498 } 497 }
499 498
@@ -511,12 +510,8 @@ static void ssu100_process_read_urb(struct urb *urb)
511 if ((len >= 4) && 510 if ((len >= 4) &&
512 (packet[0] == 0x1b) && (packet[1] == 0x1b) && 511 (packet[0] == 0x1b) && (packet[1] == 0x1b) &&
513 ((packet[2] == 0x00) || (packet[2] == 0x01))) { 512 ((packet[2] == 0x00) || (packet[2] == 0x01))) {
514 if (packet[2] == 0x00) { 513 if (packet[2] == 0x00)
515 ssu100_update_lsr(port, packet[3], &flag); 514 ssu100_update_lsr(port, packet[3], &flag);
516 if (flag == TTY_OVERRUN)
517 tty_insert_flip_char(&port->port, 0,
518 TTY_OVERRUN);
519 }
520 if (packet[2] == 0x01) 515 if (packet[2] == 0x01)
521 ssu100_update_msr(port, packet[3]); 516 ssu100_update_msr(port, packet[3]);
522 517
diff --git a/drivers/usb/storage/debug.c b/drivers/usb/storage/debug.c
index e08f64780e30..66a684a29938 100644
--- a/drivers/usb/storage/debug.c
+++ b/drivers/usb/storage/debug.c
@@ -164,10 +164,10 @@ void usb_stor_show_sense(const struct us_data *us,
164 unsigned char asc, 164 unsigned char asc,
165 unsigned char ascq) 165 unsigned char ascq)
166{ 166{
167 const char *what, *keystr; 167 const char *what, *keystr, *fmt;
168 168
169 keystr = scsi_sense_key_string(key); 169 keystr = scsi_sense_key_string(key);
170 what = scsi_extd_sense_format(asc, ascq); 170 what = scsi_extd_sense_format(asc, ascq, &fmt);
171 171
172 if (keystr == NULL) 172 if (keystr == NULL)
173 keystr = "(Unknown Key)"; 173 keystr = "(Unknown Key)";
@@ -175,8 +175,10 @@ void usb_stor_show_sense(const struct us_data *us,
175 what = "(unknown ASC/ASCQ)"; 175 what = "(unknown ASC/ASCQ)";
176 176
177 usb_stor_dbg(us, "%s: ", keystr); 177 usb_stor_dbg(us, "%s: ", keystr);
178 US_DEBUGPX(what, ascq); 178 if (fmt)
179 US_DEBUGPX("\n"); 179 US_DEBUGPX("%s (%s%x)\n", what, fmt, ascq);
180 else
181 US_DEBUGPX("%s\n", what);
180} 182}
181 183
182int usb_stor_dbg(const struct us_data *us, const char *fmt, ...) 184int usb_stor_dbg(const struct us_data *us, const char *fmt, ...)
diff --git a/drivers/usb/storage/initializers.c b/drivers/usb/storage/initializers.c
index 4bc2fc98636e..73f125e0cb58 100644
--- a/drivers/usb/storage/initializers.c
+++ b/drivers/usb/storage/initializers.c
@@ -52,7 +52,7 @@ int usb_stor_euscsi_init(struct us_data *us)
52 us->iobuf[0] = 0x1; 52 us->iobuf[0] = 0x1;
53 result = usb_stor_control_msg(us, us->send_ctrl_pipe, 53 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
54 0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR, 54 0x0C, USB_RECIP_INTERFACE | USB_TYPE_VENDOR,
55 0x01, 0x0, us->iobuf, 0x1, USB_CTRL_SET_TIMEOUT); 55 0x01, 0x0, us->iobuf, 0x1, 5 * HZ);
56 usb_stor_dbg(us, "-- result is %d\n", result); 56 usb_stor_dbg(us, "-- result is %d\n", result);
57 57
58 return 0; 58 return 0;
@@ -100,7 +100,7 @@ int usb_stor_huawei_e220_init(struct us_data *us)
100 result = usb_stor_control_msg(us, us->send_ctrl_pipe, 100 result = usb_stor_control_msg(us, us->send_ctrl_pipe,
101 USB_REQ_SET_FEATURE, 101 USB_REQ_SET_FEATURE,
102 USB_TYPE_STANDARD | USB_RECIP_DEVICE, 102 USB_TYPE_STANDARD | USB_RECIP_DEVICE,
103 0x01, 0x0, NULL, 0x0, 1000); 103 0x01, 0x0, NULL, 0x0, 1 * HZ);
104 usb_stor_dbg(us, "Huawei mode set result is %d\n", result); 104 usb_stor_dbg(us, "Huawei mode set result is %d\n", result);
105 return 0; 105 return 0;
106} 106}
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
index 8591d89a38e6..27e4a580d2ed 100644
--- a/drivers/usb/storage/realtek_cr.c
+++ b/drivers/usb/storage/realtek_cr.c
@@ -626,6 +626,7 @@ static int config_autodelink_after_power_on(struct us_data *us)
626 return 0; 626 return 0;
627} 627}
628 628
629#ifdef CONFIG_PM
629static int config_autodelink_before_power_down(struct us_data *us) 630static int config_autodelink_before_power_down(struct us_data *us)
630{ 631{
631 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra); 632 struct rts51x_chip *chip = (struct rts51x_chip *)(us->extra);
@@ -716,6 +717,7 @@ static void fw5895_init(struct us_data *us)
716 } 717 }
717 } 718 }
718} 719}
720#endif
719 721
720#ifdef CONFIG_REALTEK_AUTOPM 722#ifdef CONFIG_REALTEK_AUTOPM
721static void fw5895_set_mmc_wp(struct us_data *us) 723static void fw5895_set_mmc_wp(struct us_data *us)
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 22c7d4360fa2..b1d815eb6d0b 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -1118,6 +1118,31 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1118 */ 1118 */
1119 if (result == USB_STOR_XFER_LONG) 1119 if (result == USB_STOR_XFER_LONG)
1120 fake_sense = 1; 1120 fake_sense = 1;
1121
1122 /*
1123 * Sometimes a device will mistakenly skip the data phase
1124 * and go directly to the status phase without sending a
1125 * zero-length packet. If we get a 13-byte response here,
1126 * check whether it really is a CSW.
1127 */
1128 if (result == USB_STOR_XFER_SHORT &&
1129 srb->sc_data_direction == DMA_FROM_DEVICE &&
1130 transfer_length - scsi_get_resid(srb) ==
1131 US_BULK_CS_WRAP_LEN) {
1132 struct scatterlist *sg = NULL;
1133 unsigned int offset = 0;
1134
1135 if (usb_stor_access_xfer_buf((unsigned char *) bcs,
1136 US_BULK_CS_WRAP_LEN, srb, &sg,
1137 &offset, FROM_XFER_BUF) ==
1138 US_BULK_CS_WRAP_LEN &&
1139 bcs->Signature ==
1140 cpu_to_le32(US_BULK_CS_SIGN)) {
1141 usb_stor_dbg(us, "Device skipped data phase\n");
1142 scsi_set_resid(srb, transfer_length);
1143 goto skipped_data_phase;
1144 }
1145 }
1121 } 1146 }
1122 1147
1123 /* See flow chart on pg 15 of the Bulk Only Transport spec for 1148 /* See flow chart on pg 15 of the Bulk Only Transport spec for
@@ -1153,6 +1178,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1153 if (result != USB_STOR_XFER_GOOD) 1178 if (result != USB_STOR_XFER_GOOD)
1154 return USB_STOR_TRANSPORT_ERROR; 1179 return USB_STOR_TRANSPORT_ERROR;
1155 1180
1181 skipped_data_phase:
1156 /* check bulk status */ 1182 /* check bulk status */
1157 residue = le32_to_cpu(bcs->Residue); 1183 residue = le32_to_cpu(bcs->Residue);
1158 usb_stor_dbg(us, "Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n", 1184 usb_stor_dbg(us, "Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n",
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 89b24349269e..4047edfb64e1 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -181,7 +181,7 @@ static int uas_get_tag(struct scsi_cmnd *cmnd)
181{ 181{
182 int tag; 182 int tag;
183 183
184 if (blk_rq_tagged(cmnd->request)) 184 if (cmnd->flags & SCMD_TAGGED)
185 tag = cmnd->request->tag + 2; 185 tag = cmnd->request->tag + 2;
186 else 186 else
187 tag = 1; 187 tag = 1;
@@ -799,8 +799,7 @@ static int uas_slave_configure(struct scsi_device *sdev)
799 if (devinfo->flags & US_FL_NO_REPORT_OPCODES) 799 if (devinfo->flags & US_FL_NO_REPORT_OPCODES)
800 sdev->no_report_opcodes = 1; 800 sdev->no_report_opcodes = 1;
801 801
802 scsi_set_tag_type(sdev, MSG_ORDERED_TAG); 802 scsi_change_queue_depth(sdev, devinfo->qdepth - 2);
803 scsi_activate_tcq(sdev, devinfo->qdepth - 2);
804 return 0; 803 return 0;
805} 804}
806 805
@@ -817,7 +816,6 @@ static struct scsi_host_template uas_host_template = {
817 .sg_tablesize = SG_NONE, 816 .sg_tablesize = SG_NONE,
818 .cmd_per_lun = 1, /* until we override it */ 817 .cmd_per_lun = 1, /* until we override it */
819 .skip_settle_delay = 1, 818 .skip_settle_delay = 1,
820 .ordered_tag = 1,
821 819
822 /* 820 /*
823 * The uas drivers expects tags not to be bigger than the maximum 821 * The uas drivers expects tags not to be bigger than the maximum
@@ -825,6 +823,7 @@ static struct scsi_host_template uas_host_template = {
825 * allocator. 823 * allocator.
826 */ 824 */
827 .disable_blk_mq = true, 825 .disable_blk_mq = true,
826 .use_blk_tags = 1,
828}; 827};
829 828
830#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \ 829#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
diff --git a/drivers/usb/storage/unusual_uas.h b/drivers/usb/storage/unusual_uas.h
index 8511b54a65d9..18a283d6de1c 100644
--- a/drivers/usb/storage/unusual_uas.h
+++ b/drivers/usb/storage/unusual_uas.h
@@ -54,6 +54,20 @@ UNUSUAL_DEV(0x0bc2, 0x3312, 0x0000, 0x9999,
54 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 54 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
55 US_FL_NO_ATA_1X), 55 US_FL_NO_ATA_1X),
56 56
57/* Reported-by: Hans de Goede <hdegoede@redhat.com> */
58UNUSUAL_DEV(0x0bc2, 0x3320, 0x0000, 0x9999,
59 "Seagate",
60 "Expansion Desk",
61 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
62 US_FL_NO_ATA_1X),
63
64/* Reported-by: Bogdan Mihalcea <bogdan.mihalcea@infim.ro> */
65UNUSUAL_DEV(0x0bc2, 0xa003, 0x0000, 0x9999,
66 "Seagate",
67 "Backup Plus",
68 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
69 US_FL_NO_ATA_1X),
70
57/* https://bbs.archlinux.org/viewtopic.php?id=183190 */ 71/* https://bbs.archlinux.org/viewtopic.php?id=183190 */
58UNUSUAL_DEV(0x0bc2, 0xab20, 0x0000, 0x9999, 72UNUSUAL_DEV(0x0bc2, 0xab20, 0x0000, 0x9999,
59 "Seagate", 73 "Seagate",
@@ -61,6 +75,13 @@ UNUSUAL_DEV(0x0bc2, 0xab20, 0x0000, 0x9999,
61 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 75 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
62 US_FL_NO_ATA_1X), 76 US_FL_NO_ATA_1X),
63 77
78/* https://bbs.archlinux.org/viewtopic.php?id=183190 */
79UNUSUAL_DEV(0x0bc2, 0xab21, 0x0000, 0x9999,
80 "Seagate",
81 "Backup+ BK",
82 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
83 US_FL_NO_ATA_1X),
84
64/* Reported-by: Claudio Bizzarri <claudio.bizzarri@gmail.com> */ 85/* Reported-by: Claudio Bizzarri <claudio.bizzarri@gmail.com> */
65UNUSUAL_DEV(0x152d, 0x0567, 0x0000, 0x9999, 86UNUSUAL_DEV(0x152d, 0x0567, 0x0000, 0x9999,
66 "JMicron", 87 "JMicron",
@@ -75,3 +96,17 @@ UNUSUAL_DEV(0x174c, 0x5106, 0x0000, 0x9999,
75 "ASM1051", 96 "ASM1051",
76 USB_SC_DEVICE, USB_PR_DEVICE, NULL, 97 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
77 US_FL_IGNORE_UAS), 98 US_FL_IGNORE_UAS),
99
100/* Reported-by: Hans de Goede <hdegoede@redhat.com> */
101UNUSUAL_DEV(0x2109, 0x0711, 0x0000, 0x9999,
102 "VIA",
103 "VL711",
104 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
105 US_FL_NO_ATA_1X),
106
107/* Reported-by: Hans de Goede <hdegoede@redhat.com> */
108UNUSUAL_DEV(0x4971, 0x1012, 0x0000, 0x9999,
109 "Hitachi",
110 "External HDD",
111 USB_SC_DEVICE, USB_PR_DEVICE, NULL,
112 US_FL_IGNORE_UAS),
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 69906cacd04f..a17f11850669 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1312,6 +1312,7 @@ static int
1312vhost_scsi_set_endpoint(struct vhost_scsi *vs, 1312vhost_scsi_set_endpoint(struct vhost_scsi *vs,
1313 struct vhost_scsi_target *t) 1313 struct vhost_scsi_target *t)
1314{ 1314{
1315 struct se_portal_group *se_tpg;
1315 struct tcm_vhost_tport *tv_tport; 1316 struct tcm_vhost_tport *tv_tport;
1316 struct tcm_vhost_tpg *tpg; 1317 struct tcm_vhost_tpg *tpg;
1317 struct tcm_vhost_tpg **vs_tpg; 1318 struct tcm_vhost_tpg **vs_tpg;
@@ -1359,6 +1360,21 @@ vhost_scsi_set_endpoint(struct vhost_scsi *vs,
1359 ret = -EEXIST; 1360 ret = -EEXIST;
1360 goto out; 1361 goto out;
1361 } 1362 }
1363 /*
1364 * In order to ensure individual vhost-scsi configfs
1365 * groups cannot be removed while in use by vhost ioctl,
1366 * go ahead and take an explicit se_tpg->tpg_group.cg_item
1367 * dependency now.
1368 */
1369 se_tpg = &tpg->se_tpg;
1370 ret = configfs_depend_item(se_tpg->se_tpg_tfo->tf_subsys,
1371 &se_tpg->tpg_group.cg_item);
1372 if (ret) {
1373 pr_warn("configfs_depend_item() failed: %d\n", ret);
1374 kfree(vs_tpg);
1375 mutex_unlock(&tpg->tv_tpg_mutex);
1376 goto out;
1377 }
1362 tpg->tv_tpg_vhost_count++; 1378 tpg->tv_tpg_vhost_count++;
1363 tpg->vhost_scsi = vs; 1379 tpg->vhost_scsi = vs;
1364 vs_tpg[tpg->tport_tpgt] = tpg; 1380 vs_tpg[tpg->tport_tpgt] = tpg;
@@ -1401,6 +1417,7 @@ static int
1401vhost_scsi_clear_endpoint(struct vhost_scsi *vs, 1417vhost_scsi_clear_endpoint(struct vhost_scsi *vs,
1402 struct vhost_scsi_target *t) 1418 struct vhost_scsi_target *t)
1403{ 1419{
1420 struct se_portal_group *se_tpg;
1404 struct tcm_vhost_tport *tv_tport; 1421 struct tcm_vhost_tport *tv_tport;
1405 struct tcm_vhost_tpg *tpg; 1422 struct tcm_vhost_tpg *tpg;
1406 struct vhost_virtqueue *vq; 1423 struct vhost_virtqueue *vq;
@@ -1449,6 +1466,13 @@ vhost_scsi_clear_endpoint(struct vhost_scsi *vs,
1449 vs->vs_tpg[target] = NULL; 1466 vs->vs_tpg[target] = NULL;
1450 match = true; 1467 match = true;
1451 mutex_unlock(&tpg->tv_tpg_mutex); 1468 mutex_unlock(&tpg->tv_tpg_mutex);
1469 /*
1470 * Release se_tpg->tpg_group.cg_item configfs dependency now
1471 * to allow vhost-scsi WWPN se_tpg->tpg_group shutdown to occur.
1472 */
1473 se_tpg = &tpg->se_tpg;
1474 configfs_undepend_item(se_tpg->se_tpg_tfo->tf_subsys,
1475 &se_tpg->tpg_group.cg_item);
1452 } 1476 }
1453 if (match) { 1477 if (match) {
1454 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) { 1478 for (i = 0; i < VHOST_SCSI_MAX_VQ; i++) {
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 8d03924749b8..efb09046a8cf 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -168,7 +168,6 @@ if BACKLIGHT_CLASS_DEVICE
168config BACKLIGHT_ATMEL_LCDC 168config BACKLIGHT_ATMEL_LCDC
169 bool "Atmel LCDC Contrast-as-Backlight control" 169 bool "Atmel LCDC Contrast-as-Backlight control"
170 depends on FB_ATMEL 170 depends on FB_ATMEL
171 default y if MACH_AT91SAM9261EK || MACH_AT91SAM9G10EK || MACH_AT91SAM9263EK
172 help 171 help
173 This provides a backlight control internal to the Atmel LCDC 172 This provides a backlight control internal to the Atmel LCDC
174 driver. If the LCD "contrast control" on your board is wired 173 driver. If the LCD "contrast control" on your board is wired
diff --git a/drivers/video/fbdev/Kconfig b/drivers/video/fbdev/Kconfig
index c7bf606a8706..c78bfd1d1b34 100644
--- a/drivers/video/fbdev/Kconfig
+++ b/drivers/video/fbdev/Kconfig
@@ -999,23 +999,6 @@ config FB_ATMEL
999 help 999 help
1000 This enables support for the AT91/AT32 LCD Controller. 1000 This enables support for the AT91/AT32 LCD Controller.
1001 1001
1002config FB_INTSRAM
1003 bool "Frame Buffer in internal SRAM"
1004 depends on FB_ATMEL && ARCH_AT91SAM9261
1005 help
1006 Say Y if you want to map Frame Buffer in internal SRAM. Say N if you want
1007 to let frame buffer in external SDRAM.
1008
1009config FB_ATMEL_STN
1010 bool "Use a STN display with AT91/AT32 LCD Controller"
1011 depends on FB_ATMEL && (MACH_AT91SAM9261EK || MACH_AT91SAM9G10EK)
1012 default n
1013 help
1014 Say Y if you want to connect a STN LCD display to the AT91/AT32 LCD
1015 Controller. Say N if you want to connect a TFT.
1016
1017 If unsure, say N.
1018
1019config FB_NVIDIA 1002config FB_NVIDIA
1020 tristate "nVidia Framebuffer Support" 1003 tristate "nVidia Framebuffer Support"
1021 depends on FB && PCI 1004 depends on FB && PCI
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index d0107d424ee4..08f41add1461 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -154,14 +154,14 @@ config ARM_SP805_WATCHDOG
154 154
155config AT91RM9200_WATCHDOG 155config AT91RM9200_WATCHDOG
156 tristate "AT91RM9200 watchdog" 156 tristate "AT91RM9200 watchdog"
157 depends on ARCH_AT91RM9200 157 depends on SOC_AT91RM9200
158 help 158 help
159 Watchdog timer embedded into AT91RM9200 chips. This will reboot your 159 Watchdog timer embedded into AT91RM9200 chips. This will reboot your
160 system when the timeout is reached. 160 system when the timeout is reached.
161 161
162config AT91SAM9X_WATCHDOG 162config AT91SAM9X_WATCHDOG
163 tristate "AT91SAM9X / AT91CAP9 watchdog" 163 tristate "AT91SAM9X / AT91CAP9 watchdog"
164 depends on ARCH_AT91 && !ARCH_AT91RM9200 164 depends on ARCH_AT91
165 select WATCHDOG_CORE 165 select WATCHDOG_CORE
166 help 166 help
167 Watchdog timer embedded into AT91SAM9X and AT91CAP9 chips. This will 167 Watchdog timer embedded into AT91SAM9X and AT91CAP9 chips. This will
diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
index 8532c3e2aea7..1626dc66e763 100644
--- a/drivers/watchdog/s3c2410_wdt.c
+++ b/drivers/watchdog/s3c2410_wdt.c
@@ -161,7 +161,7 @@ static const struct s3c2410_wdt_variant drv_data_exynos5420 = {
161static const struct s3c2410_wdt_variant drv_data_exynos7 = { 161static const struct s3c2410_wdt_variant drv_data_exynos7 = {
162 .disable_reg = EXYNOS5_WDT_DISABLE_REG_OFFSET, 162 .disable_reg = EXYNOS5_WDT_DISABLE_REG_OFFSET,
163 .mask_reset_reg = EXYNOS5_WDT_MASK_RESET_REG_OFFSET, 163 .mask_reset_reg = EXYNOS5_WDT_MASK_RESET_REG_OFFSET,
164 .mask_bit = 0, 164 .mask_bit = 23,
165 .rst_stat_reg = EXYNOS5_RST_STAT_REG_OFFSET, 165 .rst_stat_reg = EXYNOS5_RST_STAT_REG_OFFSET,
166 .rst_stat_bit = 23, /* A57 WDTRESET */ 166 .rst_stat_bit = 23, /* A57 WDTRESET */
167 .quirks = QUIRK_HAS_PMU_CONFIG | QUIRK_HAS_RST_STAT, 167 .quirks = QUIRK_HAS_PMU_CONFIG | QUIRK_HAS_RST_STAT,
diff --git a/drivers/xen/efi.c b/drivers/xen/efi.c
index 1f850c97482f..f745db270171 100644
--- a/drivers/xen/efi.c
+++ b/drivers/xen/efi.c
@@ -294,6 +294,7 @@ static const struct efi efi_xen __initconst = {
294 .acpi = EFI_INVALID_TABLE_ADDR, 294 .acpi = EFI_INVALID_TABLE_ADDR,
295 .acpi20 = EFI_INVALID_TABLE_ADDR, 295 .acpi20 = EFI_INVALID_TABLE_ADDR,
296 .smbios = EFI_INVALID_TABLE_ADDR, 296 .smbios = EFI_INVALID_TABLE_ADDR,
297 .smbios3 = EFI_INVALID_TABLE_ADDR,
297 .sal_systab = EFI_INVALID_TABLE_ADDR, 298 .sal_systab = EFI_INVALID_TABLE_ADDR,
298 .boot_info = EFI_INVALID_TABLE_ADDR, 299 .boot_info = EFI_INVALID_TABLE_ADDR,
299 .hcdp = EFI_INVALID_TABLE_ADDR, 300 .hcdp = EFI_INVALID_TABLE_ADDR,
diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 3e32146472a5..50610a6acf3d 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -274,10 +274,6 @@ static void scsiback_print_status(char *sense_buffer, int errors,
274 tpg->tport->tport_name, pending_req->v2p->lun, 274 tpg->tport->tport_name, pending_req->v2p->lun,
275 pending_req->cmnd[0], status_byte(errors), msg_byte(errors), 275 pending_req->cmnd[0], status_byte(errors), msg_byte(errors),
276 host_byte(errors), driver_byte(errors)); 276 host_byte(errors), driver_byte(errors));
277
278 if (CHECK_CONDITION & status_byte(errors))
279 __scsi_print_sense("xen-pvscsi", sense_buffer,
280 SCSI_SENSE_BUFFERSIZE);
281} 277}
282 278
283static void scsiback_fast_flush_area(struct vscsibk_pend *req) 279static void scsiback_fast_flush_area(struct vscsibk_pend *req)
diff --git a/fs/Makefile b/fs/Makefile
index 34a1b9dea6dd..da0bbb456d3f 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -104,7 +104,7 @@ obj-$(CONFIG_QNX6FS_FS) += qnx6/
104obj-$(CONFIG_AUTOFS4_FS) += autofs4/ 104obj-$(CONFIG_AUTOFS4_FS) += autofs4/
105obj-$(CONFIG_ADFS_FS) += adfs/ 105obj-$(CONFIG_ADFS_FS) += adfs/
106obj-$(CONFIG_FUSE_FS) += fuse/ 106obj-$(CONFIG_FUSE_FS) += fuse/
107obj-$(CONFIG_OVERLAYFS_FS) += overlayfs/ 107obj-$(CONFIG_OVERLAY_FS) += overlayfs/
108obj-$(CONFIG_UDF_FS) += udf/ 108obj-$(CONFIG_UDF_FS) += udf/
109obj-$(CONFIG_SUN_OPENPROMFS) += openpromfs/ 109obj-$(CONFIG_SUN_OPENPROMFS) += openpromfs/
110obj-$(CONFIG_OMFS_FS) += omfs/ 110obj-$(CONFIG_OMFS_FS) += omfs/
diff --git a/fs/aio.c b/fs/aio.c
index 84a751005f5b..14b93159ef83 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -165,6 +165,15 @@ static struct vfsmount *aio_mnt;
165static const struct file_operations aio_ring_fops; 165static const struct file_operations aio_ring_fops;
166static const struct address_space_operations aio_ctx_aops; 166static const struct address_space_operations aio_ctx_aops;
167 167
168/* Backing dev info for aio fs.
169 * -no dirty page accounting or writeback happens
170 */
171static struct backing_dev_info aio_fs_backing_dev_info = {
172 .name = "aiofs",
173 .state = 0,
174 .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK | BDI_CAP_MAP_COPY,
175};
176
168static struct file *aio_private_file(struct kioctx *ctx, loff_t nr_pages) 177static struct file *aio_private_file(struct kioctx *ctx, loff_t nr_pages)
169{ 178{
170 struct qstr this = QSTR_INIT("[aio]", 5); 179 struct qstr this = QSTR_INIT("[aio]", 5);
@@ -176,6 +185,7 @@ static struct file *aio_private_file(struct kioctx *ctx, loff_t nr_pages)
176 185
177 inode->i_mapping->a_ops = &aio_ctx_aops; 186 inode->i_mapping->a_ops = &aio_ctx_aops;
178 inode->i_mapping->private_data = ctx; 187 inode->i_mapping->private_data = ctx;
188 inode->i_mapping->backing_dev_info = &aio_fs_backing_dev_info;
179 inode->i_size = PAGE_SIZE * nr_pages; 189 inode->i_size = PAGE_SIZE * nr_pages;
180 190
181 path.dentry = d_alloc_pseudo(aio_mnt->mnt_sb, &this); 191 path.dentry = d_alloc_pseudo(aio_mnt->mnt_sb, &this);
@@ -220,6 +230,9 @@ static int __init aio_setup(void)
220 if (IS_ERR(aio_mnt)) 230 if (IS_ERR(aio_mnt))
221 panic("Failed to create aio fs mount."); 231 panic("Failed to create aio fs mount.");
222 232
233 if (bdi_init(&aio_fs_backing_dev_info))
234 panic("Failed to init aio fs backing dev info.");
235
223 kiocb_cachep = KMEM_CACHE(kiocb, SLAB_HWCACHE_ALIGN|SLAB_PANIC); 236 kiocb_cachep = KMEM_CACHE(kiocb, SLAB_HWCACHE_ALIGN|SLAB_PANIC);
224 kioctx_cachep = KMEM_CACHE(kioctx,SLAB_HWCACHE_ALIGN|SLAB_PANIC); 237 kioctx_cachep = KMEM_CACHE(kioctx,SLAB_HWCACHE_ALIGN|SLAB_PANIC);
225 238
@@ -281,11 +294,6 @@ static const struct file_operations aio_ring_fops = {
281 .mmap = aio_ring_mmap, 294 .mmap = aio_ring_mmap,
282}; 295};
283 296
284static int aio_set_page_dirty(struct page *page)
285{
286 return 0;
287}
288
289#if IS_ENABLED(CONFIG_MIGRATION) 297#if IS_ENABLED(CONFIG_MIGRATION)
290static int aio_migratepage(struct address_space *mapping, struct page *new, 298static int aio_migratepage(struct address_space *mapping, struct page *new,
291 struct page *old, enum migrate_mode mode) 299 struct page *old, enum migrate_mode mode)
@@ -357,7 +365,7 @@ out:
357#endif 365#endif
358 366
359static const struct address_space_operations aio_ctx_aops = { 367static const struct address_space_operations aio_ctx_aops = {
360 .set_page_dirty = aio_set_page_dirty, 368 .set_page_dirty = __set_page_dirty_no_writeback,
361#if IS_ENABLED(CONFIG_MIGRATION) 369#if IS_ENABLED(CONFIG_MIGRATION)
362 .migratepage = aio_migratepage, 370 .migratepage = aio_migratepage,
363#endif 371#endif
@@ -412,7 +420,6 @@ static int aio_setup_ring(struct kioctx *ctx)
412 pr_debug("pid(%d) page[%d]->count=%d\n", 420 pr_debug("pid(%d) page[%d]->count=%d\n",
413 current->pid, i, page_count(page)); 421 current->pid, i, page_count(page));
414 SetPageUptodate(page); 422 SetPageUptodate(page);
415 SetPageDirty(page);
416 unlock_page(page); 423 unlock_page(page);
417 424
418 ctx->ring_pages[i] = page; 425 ctx->ring_pages[i] = page;
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index d3220d31d3cb..dcd9be32ac57 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -1011,8 +1011,6 @@ int btrfs_decompress_buf2page(char *buf, unsigned long buf_start,
1011 bytes = min(bytes, working_bytes); 1011 bytes = min(bytes, working_bytes);
1012 kaddr = kmap_atomic(page_out); 1012 kaddr = kmap_atomic(page_out);
1013 memcpy(kaddr + *pg_offset, buf + buf_offset, bytes); 1013 memcpy(kaddr + *pg_offset, buf + buf_offset, bytes);
1014 if (*pg_index == (vcnt - 1) && *pg_offset == 0)
1015 memset(kaddr + bytes, 0, PAGE_CACHE_SIZE - bytes);
1016 kunmap_atomic(kaddr); 1014 kunmap_atomic(kaddr);
1017 flush_dcache_page(page_out); 1015 flush_dcache_page(page_out);
1018 1016
@@ -1054,3 +1052,34 @@ int btrfs_decompress_buf2page(char *buf, unsigned long buf_start,
1054 1052
1055 return 1; 1053 return 1;
1056} 1054}
1055
1056/*
1057 * When uncompressing data, we need to make sure and zero any parts of
1058 * the biovec that were not filled in by the decompression code. pg_index
1059 * and pg_offset indicate the last page and the last offset of that page
1060 * that have been filled in. This will zero everything remaining in the
1061 * biovec.
1062 */
1063void btrfs_clear_biovec_end(struct bio_vec *bvec, int vcnt,
1064 unsigned long pg_index,
1065 unsigned long pg_offset)
1066{
1067 while (pg_index < vcnt) {
1068 struct page *page = bvec[pg_index].bv_page;
1069 unsigned long off = bvec[pg_index].bv_offset;
1070 unsigned long len = bvec[pg_index].bv_len;
1071
1072 if (pg_offset < off)
1073 pg_offset = off;
1074 if (pg_offset < off + len) {
1075 unsigned long bytes = off + len - pg_offset;
1076 char *kaddr;
1077
1078 kaddr = kmap_atomic(page);
1079 memset(kaddr + pg_offset, 0, bytes);
1080 kunmap_atomic(kaddr);
1081 }
1082 pg_index++;
1083 pg_offset = 0;
1084 }
1085}
diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h
index 0c803b4fbf93..d181f70caae0 100644
--- a/fs/btrfs/compression.h
+++ b/fs/btrfs/compression.h
@@ -45,7 +45,9 @@ int btrfs_submit_compressed_write(struct inode *inode, u64 start,
45 unsigned long nr_pages); 45 unsigned long nr_pages);
46int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, 46int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
47 int mirror_num, unsigned long bio_flags); 47 int mirror_num, unsigned long bio_flags);
48 48void btrfs_clear_biovec_end(struct bio_vec *bvec, int vcnt,
49 unsigned long pg_index,
50 unsigned long pg_offset);
49struct btrfs_compress_op { 51struct btrfs_compress_op {
50 struct list_head *(*alloc_workspace)(void); 52 struct list_head *(*alloc_workspace)(void);
51 53
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 19bc6162fb8e..150822ee0a0b 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -80,13 +80,6 @@ noinline void btrfs_clear_path_blocking(struct btrfs_path *p,
80{ 80{
81 int i; 81 int i;
82 82
83#ifdef CONFIG_DEBUG_LOCK_ALLOC
84 /* lockdep really cares that we take all of these spinlocks
85 * in the right order. If any of the locks in the path are not
86 * currently blocking, it is going to complain. So, make really
87 * really sure by forcing the path to blocking before we clear
88 * the path blocking.
89 */
90 if (held) { 83 if (held) {
91 btrfs_set_lock_blocking_rw(held, held_rw); 84 btrfs_set_lock_blocking_rw(held, held_rw);
92 if (held_rw == BTRFS_WRITE_LOCK) 85 if (held_rw == BTRFS_WRITE_LOCK)
@@ -95,7 +88,6 @@ noinline void btrfs_clear_path_blocking(struct btrfs_path *p,
95 held_rw = BTRFS_READ_LOCK_BLOCKING; 88 held_rw = BTRFS_READ_LOCK_BLOCKING;
96 } 89 }
97 btrfs_set_path_blocking(p); 90 btrfs_set_path_blocking(p);
98#endif
99 91
100 for (i = BTRFS_MAX_LEVEL - 1; i >= 0; i--) { 92 for (i = BTRFS_MAX_LEVEL - 1; i >= 0; i--) {
101 if (p->nodes[i] && p->locks[i]) { 93 if (p->nodes[i] && p->locks[i]) {
@@ -107,10 +99,8 @@ noinline void btrfs_clear_path_blocking(struct btrfs_path *p,
107 } 99 }
108 } 100 }
109 101
110#ifdef CONFIG_DEBUG_LOCK_ALLOC
111 if (held) 102 if (held)
112 btrfs_clear_lock_blocking_rw(held, held_rw); 103 btrfs_clear_lock_blocking_rw(held, held_rw);
113#endif
114} 104}
115 105
116/* this also releases the path */ 106/* this also releases the path */
@@ -2893,7 +2883,7 @@ cow_done:
2893 } 2883 }
2894 p->locks[level] = BTRFS_WRITE_LOCK; 2884 p->locks[level] = BTRFS_WRITE_LOCK;
2895 } else { 2885 } else {
2896 err = btrfs_try_tree_read_lock(b); 2886 err = btrfs_tree_read_lock_atomic(b);
2897 if (!err) { 2887 if (!err) {
2898 btrfs_set_path_blocking(p); 2888 btrfs_set_path_blocking(p);
2899 btrfs_tree_read_lock(b); 2889 btrfs_tree_read_lock(b);
@@ -3025,7 +3015,7 @@ again:
3025 } 3015 }
3026 3016
3027 level = btrfs_header_level(b); 3017 level = btrfs_header_level(b);
3028 err = btrfs_try_tree_read_lock(b); 3018 err = btrfs_tree_read_lock_atomic(b);
3029 if (!err) { 3019 if (!err) {
3030 btrfs_set_path_blocking(p); 3020 btrfs_set_path_blocking(p);
3031 btrfs_tree_read_lock(b); 3021 btrfs_tree_read_lock(b);
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 783a94355efd..84a2d1868271 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -413,7 +413,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
413 ret = 0; 413 ret = 0;
414fail: 414fail:
415 while (ret < 0 && !list_empty(&tmplist)) { 415 while (ret < 0 && !list_empty(&tmplist)) {
416 sums = list_entry(&tmplist, struct btrfs_ordered_sum, list); 416 sums = list_entry(tmplist.next, struct btrfs_ordered_sum, list);
417 list_del(&sums->list); 417 list_del(&sums->list);
418 kfree(sums); 418 kfree(sums);
419 } 419 }
diff --git a/fs/btrfs/locking.c b/fs/btrfs/locking.c
index 5665d2149249..f8229ef1b46d 100644
--- a/fs/btrfs/locking.c
+++ b/fs/btrfs/locking.c
@@ -128,6 +128,26 @@ again:
128} 128}
129 129
130/* 130/*
131 * take a spinning read lock.
132 * returns 1 if we get the read lock and 0 if we don't
133 * this won't wait for blocking writers
134 */
135int btrfs_tree_read_lock_atomic(struct extent_buffer *eb)
136{
137 if (atomic_read(&eb->blocking_writers))
138 return 0;
139
140 read_lock(&eb->lock);
141 if (atomic_read(&eb->blocking_writers)) {
142 read_unlock(&eb->lock);
143 return 0;
144 }
145 atomic_inc(&eb->read_locks);
146 atomic_inc(&eb->spinning_readers);
147 return 1;
148}
149
150/*
131 * returns 1 if we get the read lock and 0 if we don't 151 * returns 1 if we get the read lock and 0 if we don't
132 * this won't wait for blocking writers 152 * this won't wait for blocking writers
133 */ 153 */
@@ -158,9 +178,7 @@ int btrfs_try_tree_write_lock(struct extent_buffer *eb)
158 atomic_read(&eb->blocking_readers)) 178 atomic_read(&eb->blocking_readers))
159 return 0; 179 return 0;
160 180
161 if (!write_trylock(&eb->lock)) 181 write_lock(&eb->lock);
162 return 0;
163
164 if (atomic_read(&eb->blocking_writers) || 182 if (atomic_read(&eb->blocking_writers) ||
165 atomic_read(&eb->blocking_readers)) { 183 atomic_read(&eb->blocking_readers)) {
166 write_unlock(&eb->lock); 184 write_unlock(&eb->lock);
diff --git a/fs/btrfs/locking.h b/fs/btrfs/locking.h
index b81e0e9a4894..c44a9d5f5362 100644
--- a/fs/btrfs/locking.h
+++ b/fs/btrfs/locking.h
@@ -35,6 +35,8 @@ void btrfs_clear_lock_blocking_rw(struct extent_buffer *eb, int rw);
35void btrfs_assert_tree_locked(struct extent_buffer *eb); 35void btrfs_assert_tree_locked(struct extent_buffer *eb);
36int btrfs_try_tree_read_lock(struct extent_buffer *eb); 36int btrfs_try_tree_read_lock(struct extent_buffer *eb);
37int btrfs_try_tree_write_lock(struct extent_buffer *eb); 37int btrfs_try_tree_write_lock(struct extent_buffer *eb);
38int btrfs_tree_read_lock_atomic(struct extent_buffer *eb);
39
38 40
39static inline void btrfs_tree_unlock_rw(struct extent_buffer *eb, int rw) 41static inline void btrfs_tree_unlock_rw(struct extent_buffer *eb, int rw)
40{ 42{
diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index 78285f30909e..617553cdb7d3 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -373,6 +373,8 @@ cont:
373 } 373 }
374done: 374done:
375 kunmap(pages_in[page_in_index]); 375 kunmap(pages_in[page_in_index]);
376 if (!ret)
377 btrfs_clear_biovec_end(bvec, vcnt, page_out_index, pg_offset);
376 return ret; 378 return ret;
377} 379}
378 380
@@ -410,10 +412,23 @@ static int lzo_decompress(struct list_head *ws, unsigned char *data_in,
410 goto out; 412 goto out;
411 } 413 }
412 414
415 /*
416 * the caller is already checking against PAGE_SIZE, but lets
417 * move this check closer to the memcpy/memset
418 */
419 destlen = min_t(unsigned long, destlen, PAGE_SIZE);
413 bytes = min_t(unsigned long, destlen, out_len - start_byte); 420 bytes = min_t(unsigned long, destlen, out_len - start_byte);
414 421
415 kaddr = kmap_atomic(dest_page); 422 kaddr = kmap_atomic(dest_page);
416 memcpy(kaddr, workspace->buf + start_byte, bytes); 423 memcpy(kaddr, workspace->buf + start_byte, bytes);
424
425 /*
426 * btrfs_getblock is doing a zero on the tail of the page too,
427 * but this will cover anything missing from the decompressed
428 * data.
429 */
430 if (bytes < destlen)
431 memset(kaddr+bytes, 0, destlen-bytes);
417 kunmap_atomic(kaddr); 432 kunmap_atomic(kaddr);
418out: 433out:
419 return ret; 434 return ret;
diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
index 759fa4e2de8f..fb22fd8d8fb8 100644
--- a/fs/btrfs/zlib.c
+++ b/fs/btrfs/zlib.c
@@ -299,6 +299,8 @@ done:
299 zlib_inflateEnd(&workspace->strm); 299 zlib_inflateEnd(&workspace->strm);
300 if (data_in) 300 if (data_in)
301 kunmap(pages_in[page_in_index]); 301 kunmap(pages_in[page_in_index]);
302 if (!ret)
303 btrfs_clear_biovec_end(bvec, vcnt, page_out_index, pg_offset);
302 return ret; 304 return ret;
303} 305}
304 306
@@ -310,10 +312,14 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,
310 struct workspace *workspace = list_entry(ws, struct workspace, list); 312 struct workspace *workspace = list_entry(ws, struct workspace, list);
311 int ret = 0; 313 int ret = 0;
312 int wbits = MAX_WBITS; 314 int wbits = MAX_WBITS;
313 unsigned long bytes_left = destlen; 315 unsigned long bytes_left;
314 unsigned long total_out = 0; 316 unsigned long total_out = 0;
317 unsigned long pg_offset = 0;
315 char *kaddr; 318 char *kaddr;
316 319
320 destlen = min_t(unsigned long, destlen, PAGE_SIZE);
321 bytes_left = destlen;
322
317 workspace->strm.next_in = data_in; 323 workspace->strm.next_in = data_in;
318 workspace->strm.avail_in = srclen; 324 workspace->strm.avail_in = srclen;
319 workspace->strm.total_in = 0; 325 workspace->strm.total_in = 0;
@@ -341,7 +347,6 @@ static int zlib_decompress(struct list_head *ws, unsigned char *data_in,
341 unsigned long buf_start; 347 unsigned long buf_start;
342 unsigned long buf_offset; 348 unsigned long buf_offset;
343 unsigned long bytes; 349 unsigned long bytes;
344 unsigned long pg_offset = 0;
345 350
346 ret = zlib_inflate(&workspace->strm, Z_NO_FLUSH); 351 ret = zlib_inflate(&workspace->strm, Z_NO_FLUSH);
347 if (ret != Z_OK && ret != Z_STREAM_END) 352 if (ret != Z_OK && ret != Z_STREAM_END)
@@ -384,6 +389,17 @@ next:
384 ret = 0; 389 ret = 0;
385 390
386 zlib_inflateEnd(&workspace->strm); 391 zlib_inflateEnd(&workspace->strm);
392
393 /*
394 * this should only happen if zlib returned fewer bytes than we
395 * expected. btrfs_get_block is responsible for zeroing from the
396 * end of the inline extent (destlen) to the end of the page
397 */
398 if (pg_offset < destlen) {
399 kaddr = kmap_atomic(dest_page);
400 memset(kaddr + pg_offset, 0, destlen - pg_offset);
401 kunmap_atomic(kaddr);
402 }
387 return ret; 403 return ret;
388} 404}
389 405
diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 659f2ea9e6f7..cefca661464b 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -2638,7 +2638,7 @@ static void handle_cap_flush_ack(struct inode *inode, u64 flush_tid,
2638 2638
2639 for (i = 0; i < CEPH_CAP_BITS; i++) 2639 for (i = 0; i < CEPH_CAP_BITS; i++)
2640 if ((dirty & (1 << i)) && 2640 if ((dirty & (1 << i)) &&
2641 flush_tid == ci->i_cap_flush_tid[i]) 2641 (u16)flush_tid == ci->i_cap_flush_tid[i])
2642 cleaned |= 1 << i; 2642 cleaned |= 1 << i;
2643 2643
2644 dout("handle_cap_flush_ack inode %p mds%d seq %d on %s cleaned %s," 2644 dout("handle_cap_flush_ack inode %p mds%d seq %d on %s cleaned %s,"
diff --git a/fs/dcache.c b/fs/dcache.c
index 3ffef7f4e5cd..5bc72b07fde2 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -778,6 +778,7 @@ restart:
778 struct dentry *parent = lock_parent(dentry); 778 struct dentry *parent = lock_parent(dentry);
779 if (likely(!dentry->d_lockref.count)) { 779 if (likely(!dentry->d_lockref.count)) {
780 __dentry_kill(dentry); 780 __dentry_kill(dentry);
781 dput(parent);
781 goto restart; 782 goto restart;
782 } 783 }
783 if (parent) 784 if (parent)
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index 6df8d3d885e5..b8b92c2f9683 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -736,7 +736,12 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
736 } 736 }
737 737
738 alias = d_find_alias(inode); 738 alias = d_find_alias(inode);
739 if (alias && !vfat_d_anon_disconn(alias)) { 739 /*
740 * Checking "alias->d_parent == dentry->d_parent" to make sure
741 * FS is not corrupted (especially double linked dir).
742 */
743 if (alias && alias->d_parent == dentry->d_parent &&
744 !vfat_d_anon_disconn(alias)) {
740 /* 745 /*
741 * This inode has non anonymous-DCACHE_DISCONNECTED 746 * This inode has non anonymous-DCACHE_DISCONNECTED
742 * dentry. This means, the user did ->lookup() by an 747 * dentry. This means, the user did ->lookup() by an
@@ -755,12 +760,9 @@ static struct dentry *vfat_lookup(struct inode *dir, struct dentry *dentry,
755 760
756out: 761out:
757 mutex_unlock(&MSDOS_SB(sb)->s_lock); 762 mutex_unlock(&MSDOS_SB(sb)->s_lock);
758 dentry->d_time = dentry->d_parent->d_inode->i_version; 763 if (!inode)
759 dentry = d_splice_alias(inode, dentry); 764 dentry->d_time = dir->i_version;
760 if (dentry) 765 return d_splice_alias(inode, dentry);
761 dentry->d_time = dentry->d_parent->d_inode->i_version;
762 return dentry;
763
764error: 766error:
765 mutex_unlock(&MSDOS_SB(sb)->s_lock); 767 mutex_unlock(&MSDOS_SB(sb)->s_lock);
766 return ERR_PTR(err); 768 return ERR_PTR(err);
@@ -793,7 +795,6 @@ static int vfat_create(struct inode *dir, struct dentry *dentry, umode_t mode,
793 inode->i_mtime = inode->i_atime = inode->i_ctime = ts; 795 inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
794 /* timestamp is already written, so mark_inode_dirty() is unneeded. */ 796 /* timestamp is already written, so mark_inode_dirty() is unneeded. */
795 797
796 dentry->d_time = dentry->d_parent->d_inode->i_version;
797 d_instantiate(dentry, inode); 798 d_instantiate(dentry, inode);
798out: 799out:
799 mutex_unlock(&MSDOS_SB(sb)->s_lock); 800 mutex_unlock(&MSDOS_SB(sb)->s_lock);
@@ -824,6 +825,7 @@ static int vfat_rmdir(struct inode *dir, struct dentry *dentry)
824 clear_nlink(inode); 825 clear_nlink(inode);
825 inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC; 826 inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
826 fat_detach(inode); 827 fat_detach(inode);
828 dentry->d_time = dir->i_version;
827out: 829out:
828 mutex_unlock(&MSDOS_SB(sb)->s_lock); 830 mutex_unlock(&MSDOS_SB(sb)->s_lock);
829 831
@@ -849,6 +851,7 @@ static int vfat_unlink(struct inode *dir, struct dentry *dentry)
849 clear_nlink(inode); 851 clear_nlink(inode);
850 inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC; 852 inode->i_mtime = inode->i_atime = CURRENT_TIME_SEC;
851 fat_detach(inode); 853 fat_detach(inode);
854 dentry->d_time = dir->i_version;
852out: 855out:
853 mutex_unlock(&MSDOS_SB(sb)->s_lock); 856 mutex_unlock(&MSDOS_SB(sb)->s_lock);
854 857
@@ -889,7 +892,6 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
889 inode->i_mtime = inode->i_atime = inode->i_ctime = ts; 892 inode->i_mtime = inode->i_atime = inode->i_ctime = ts;
890 /* timestamp is already written, so mark_inode_dirty() is unneeded. */ 893 /* timestamp is already written, so mark_inode_dirty() is unneeded. */
891 894
892 dentry->d_time = dentry->d_parent->d_inode->i_version;
893 d_instantiate(dentry, inode); 895 d_instantiate(dentry, inode);
894 896
895 mutex_unlock(&MSDOS_SB(sb)->s_lock); 897 mutex_unlock(&MSDOS_SB(sb)->s_lock);
diff --git a/fs/isofs/inode.c b/fs/isofs/inode.c
index fe839b915116..d67a16f2a45d 100644
--- a/fs/isofs/inode.c
+++ b/fs/isofs/inode.c
@@ -174,27 +174,6 @@ struct iso9660_options{
174 * Compute the hash for the isofs name corresponding to the dentry. 174 * Compute the hash for the isofs name corresponding to the dentry.
175 */ 175 */
176static int 176static int
177isofs_hash_common(struct qstr *qstr, int ms)
178{
179 const char *name;
180 int len;
181
182 len = qstr->len;
183 name = qstr->name;
184 if (ms) {
185 while (len && name[len-1] == '.')
186 len--;
187 }
188
189 qstr->hash = full_name_hash(name, len);
190
191 return 0;
192}
193
194/*
195 * Compute the hash for the isofs name corresponding to the dentry.
196 */
197static int
198isofs_hashi_common(struct qstr *qstr, int ms) 177isofs_hashi_common(struct qstr *qstr, int ms)
199{ 178{
200 const char *name; 179 const char *name;
@@ -263,6 +242,27 @@ isofs_dentry_cmpi(const struct dentry *parent, const struct dentry *dentry,
263} 242}
264 243
265#ifdef CONFIG_JOLIET 244#ifdef CONFIG_JOLIET
245/*
246 * Compute the hash for the isofs name corresponding to the dentry.
247 */
248static int
249isofs_hash_common(struct qstr *qstr, int ms)
250{
251 const char *name;
252 int len;
253
254 len = qstr->len;
255 name = qstr->name;
256 if (ms) {
257 while (len && name[len-1] == '.')
258 len--;
259 }
260
261 qstr->hash = full_name_hash(name, len);
262
263 return 0;
264}
265
266static int 266static int
267isofs_hash_ms(const struct dentry *dentry, struct qstr *qstr) 267isofs_hash_ms(const struct dentry *dentry, struct qstr *qstr)
268{ 268{
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index e4dc74713a43..1df94fabe4eb 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1853,13 +1853,12 @@ int jbd2_journal_set_features (journal_t *journal, unsigned long compat,
1853 journal->j_chksum_driver = NULL; 1853 journal->j_chksum_driver = NULL;
1854 return 0; 1854 return 0;
1855 } 1855 }
1856 }
1857 1856
1858 /* Precompute checksum seed for all metadata */ 1857 /* Precompute checksum seed for all metadata */
1859 if (jbd2_journal_has_csum_v2or3(journal))
1860 journal->j_csum_seed = jbd2_chksum(journal, ~0, 1858 journal->j_csum_seed = jbd2_chksum(journal, ~0,
1861 sb->s_uuid, 1859 sb->s_uuid,
1862 sizeof(sb->s_uuid)); 1860 sizeof(sb->s_uuid));
1861 }
1863 } 1862 }
1864 1863
1865 /* If enabling v1 checksums, downgrade superblock */ 1864 /* If enabling v1 checksums, downgrade superblock */
diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
index 5228f201d3d5..4f46f7a05289 100644
--- a/fs/nfs/blocklayout/blocklayout.c
+++ b/fs/nfs/blocklayout/blocklayout.c
@@ -378,7 +378,7 @@ bl_write_pagelist(struct nfs_pgio_header *header, int sync)
378 loff_t offset = header->args.offset; 378 loff_t offset = header->args.offset;
379 size_t count = header->args.count; 379 size_t count = header->args.count;
380 struct page **pages = header->args.pages; 380 struct page **pages = header->args.pages;
381 int pg_index = pg_index = header->args.pgbase >> PAGE_CACHE_SHIFT; 381 int pg_index = header->args.pgbase >> PAGE_CACHE_SHIFT;
382 unsigned int pg_len; 382 unsigned int pg_len;
383 struct blk_plug plug; 383 struct blk_plug plug;
384 int i; 384 int i;
diff --git a/fs/nfs/blocklayout/rpc_pipefs.c b/fs/nfs/blocklayout/rpc_pipefs.c
index e966c023b1b7..acbf9ca4018c 100644
--- a/fs/nfs/blocklayout/rpc_pipefs.c
+++ b/fs/nfs/blocklayout/rpc_pipefs.c
@@ -65,17 +65,18 @@ bl_resolve_deviceid(struct nfs_server *server, struct pnfs_block_volume *b,
65 65
66 dprintk("%s CREATING PIPEFS MESSAGE\n", __func__); 66 dprintk("%s CREATING PIPEFS MESSAGE\n", __func__);
67 67
68 mutex_lock(&nn->bl_mutex);
68 bl_pipe_msg.bl_wq = &nn->bl_wq; 69 bl_pipe_msg.bl_wq = &nn->bl_wq;
69 70
70 b->simple.len += 4; /* single volume */ 71 b->simple.len += 4; /* single volume */
71 if (b->simple.len > PAGE_SIZE) 72 if (b->simple.len > PAGE_SIZE)
72 return -EIO; 73 goto out_unlock;
73 74
74 memset(msg, 0, sizeof(*msg)); 75 memset(msg, 0, sizeof(*msg));
75 msg->len = sizeof(*bl_msg) + b->simple.len; 76 msg->len = sizeof(*bl_msg) + b->simple.len;
76 msg->data = kzalloc(msg->len, gfp_mask); 77 msg->data = kzalloc(msg->len, gfp_mask);
77 if (!msg->data) 78 if (!msg->data)
78 goto out; 79 goto out_free_data;
79 80
80 bl_msg = msg->data; 81 bl_msg = msg->data;
81 bl_msg->type = BL_DEVICE_MOUNT, 82 bl_msg->type = BL_DEVICE_MOUNT,
@@ -87,7 +88,7 @@ bl_resolve_deviceid(struct nfs_server *server, struct pnfs_block_volume *b,
87 rc = rpc_queue_upcall(nn->bl_device_pipe, msg); 88 rc = rpc_queue_upcall(nn->bl_device_pipe, msg);
88 if (rc < 0) { 89 if (rc < 0) {
89 remove_wait_queue(&nn->bl_wq, &wq); 90 remove_wait_queue(&nn->bl_wq, &wq);
90 goto out; 91 goto out_free_data;
91 } 92 }
92 93
93 set_current_state(TASK_UNINTERRUPTIBLE); 94 set_current_state(TASK_UNINTERRUPTIBLE);
@@ -97,12 +98,14 @@ bl_resolve_deviceid(struct nfs_server *server, struct pnfs_block_volume *b,
97 if (reply->status != BL_DEVICE_REQUEST_PROC) { 98 if (reply->status != BL_DEVICE_REQUEST_PROC) {
98 printk(KERN_WARNING "%s failed to decode device: %d\n", 99 printk(KERN_WARNING "%s failed to decode device: %d\n",
99 __func__, reply->status); 100 __func__, reply->status);
100 goto out; 101 goto out_free_data;
101 } 102 }
102 103
103 dev = MKDEV(reply->major, reply->minor); 104 dev = MKDEV(reply->major, reply->minor);
104out: 105out_free_data:
105 kfree(msg->data); 106 kfree(msg->data);
107out_unlock:
108 mutex_unlock(&nn->bl_mutex);
106 return dev; 109 return dev;
107} 110}
108 111
@@ -232,6 +235,7 @@ static int nfs4blocklayout_net_init(struct net *net)
232 struct nfs_net *nn = net_generic(net, nfs_net_id); 235 struct nfs_net *nn = net_generic(net, nfs_net_id);
233 struct dentry *dentry; 236 struct dentry *dentry;
234 237
238 mutex_init(&nn->bl_mutex);
235 init_waitqueue_head(&nn->bl_wq); 239 init_waitqueue_head(&nn->bl_wq);
236 nn->bl_device_pipe = rpc_mkpipe_data(&bl_upcall_ops, 0); 240 nn->bl_device_pipe = rpc_mkpipe_data(&bl_upcall_ops, 0);
237 if (IS_ERR(nn->bl_device_pipe)) 241 if (IS_ERR(nn->bl_device_pipe))
diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c
index 5853f53db732..7f3f60641344 100644
--- a/fs/nfs/delegation.c
+++ b/fs/nfs/delegation.c
@@ -125,6 +125,8 @@ again:
125 continue; 125 continue;
126 if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) 126 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
127 continue; 127 continue;
128 if (!nfs4_valid_open_stateid(state))
129 continue;
128 if (!nfs4_stateid_match(&state->stateid, stateid)) 130 if (!nfs4_stateid_match(&state->stateid, stateid))
129 continue; 131 continue;
130 get_nfs_open_context(ctx); 132 get_nfs_open_context(ctx);
@@ -193,7 +195,11 @@ static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *
193{ 195{
194 int res = 0; 196 int res = 0;
195 197
196 res = nfs4_proc_delegreturn(inode, delegation->cred, &delegation->stateid, issync); 198 if (!test_bit(NFS_DELEGATION_REVOKED, &delegation->flags))
199 res = nfs4_proc_delegreturn(inode,
200 delegation->cred,
201 &delegation->stateid,
202 issync);
197 nfs_free_delegation(delegation); 203 nfs_free_delegation(delegation);
198 return res; 204 return res;
199} 205}
@@ -380,11 +386,13 @@ static int nfs_end_delegation_return(struct inode *inode, struct nfs_delegation
380{ 386{
381 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client; 387 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
382 struct nfs_inode *nfsi = NFS_I(inode); 388 struct nfs_inode *nfsi = NFS_I(inode);
383 int err; 389 int err = 0;
384 390
385 if (delegation == NULL) 391 if (delegation == NULL)
386 return 0; 392 return 0;
387 do { 393 do {
394 if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags))
395 break;
388 err = nfs_delegation_claim_opens(inode, &delegation->stateid); 396 err = nfs_delegation_claim_opens(inode, &delegation->stateid);
389 if (!issync || err != -EAGAIN) 397 if (!issync || err != -EAGAIN)
390 break; 398 break;
@@ -605,10 +613,23 @@ static void nfs_client_mark_return_unused_delegation_types(struct nfs_client *cl
605 rcu_read_unlock(); 613 rcu_read_unlock();
606} 614}
607 615
616static void nfs_revoke_delegation(struct inode *inode)
617{
618 struct nfs_delegation *delegation;
619 rcu_read_lock();
620 delegation = rcu_dereference(NFS_I(inode)->delegation);
621 if (delegation != NULL) {
622 set_bit(NFS_DELEGATION_REVOKED, &delegation->flags);
623 nfs_mark_return_delegation(NFS_SERVER(inode), delegation);
624 }
625 rcu_read_unlock();
626}
627
608void nfs_remove_bad_delegation(struct inode *inode) 628void nfs_remove_bad_delegation(struct inode *inode)
609{ 629{
610 struct nfs_delegation *delegation; 630 struct nfs_delegation *delegation;
611 631
632 nfs_revoke_delegation(inode);
612 delegation = nfs_inode_detach_delegation(inode); 633 delegation = nfs_inode_detach_delegation(inode);
613 if (delegation) { 634 if (delegation) {
614 nfs_inode_find_state_and_recover(inode, &delegation->stateid); 635 nfs_inode_find_state_and_recover(inode, &delegation->stateid);
diff --git a/fs/nfs/delegation.h b/fs/nfs/delegation.h
index 5c1cce39297f..e3c20a3ccc93 100644
--- a/fs/nfs/delegation.h
+++ b/fs/nfs/delegation.h
@@ -31,6 +31,7 @@ enum {
31 NFS_DELEGATION_RETURN_IF_CLOSED, 31 NFS_DELEGATION_RETURN_IF_CLOSED,
32 NFS_DELEGATION_REFERENCED, 32 NFS_DELEGATION_REFERENCED,
33 NFS_DELEGATION_RETURNING, 33 NFS_DELEGATION_RETURNING,
34 NFS_DELEGATION_REVOKED,
34}; 35};
35 36
36int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res); 37int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res);
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index 06e8cfcbb670..6e62155abf26 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1527,6 +1527,7 @@ int nfs_atomic_open(struct inode *dir, struct dentry *dentry,
1527 case -ENOENT: 1527 case -ENOENT:
1528 d_drop(dentry); 1528 d_drop(dentry);
1529 d_add(dentry, NULL); 1529 d_add(dentry, NULL);
1530 nfs_set_verifier(dentry, nfs_save_change_attribute(dir));
1530 break; 1531 break;
1531 case -EISDIR: 1532 case -EISDIR:
1532 case -ENOTDIR: 1533 case -ENOTDIR:
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 20cffc830468..10bf07280f4a 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -266,6 +266,7 @@ static void nfs_direct_req_free(struct kref *kref)
266{ 266{
267 struct nfs_direct_req *dreq = container_of(kref, struct nfs_direct_req, kref); 267 struct nfs_direct_req *dreq = container_of(kref, struct nfs_direct_req, kref);
268 268
269 nfs_free_pnfs_ds_cinfo(&dreq->ds_cinfo);
269 if (dreq->l_ctx != NULL) 270 if (dreq->l_ctx != NULL)
270 nfs_put_lock_context(dreq->l_ctx); 271 nfs_put_lock_context(dreq->l_ctx);
271 if (dreq->ctx != NULL) 272 if (dreq->ctx != NULL)
diff --git a/fs/nfs/filelayout/filelayout.c b/fs/nfs/filelayout/filelayout.c
index 46fab1cb455a..7afb52f6a25a 100644
--- a/fs/nfs/filelayout/filelayout.c
+++ b/fs/nfs/filelayout/filelayout.c
@@ -145,9 +145,6 @@ static int filelayout_async_handle_error(struct rpc_task *task,
145 case -NFS4ERR_DELEG_REVOKED: 145 case -NFS4ERR_DELEG_REVOKED:
146 case -NFS4ERR_ADMIN_REVOKED: 146 case -NFS4ERR_ADMIN_REVOKED:
147 case -NFS4ERR_BAD_STATEID: 147 case -NFS4ERR_BAD_STATEID:
148 if (state == NULL)
149 break;
150 nfs_remove_bad_delegation(state->inode);
151 case -NFS4ERR_OPENMODE: 148 case -NFS4ERR_OPENMODE:
152 if (state == NULL) 149 if (state == NULL)
153 break; 150 break;
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 6388a59f2add..00689a8a85e4 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -626,7 +626,7 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
626{ 626{
627 struct inode *inode = dentry->d_inode; 627 struct inode *inode = dentry->d_inode;
628 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME; 628 int need_atime = NFS_I(inode)->cache_validity & NFS_INO_INVALID_ATIME;
629 int err; 629 int err = 0;
630 630
631 trace_nfs_getattr_enter(inode); 631 trace_nfs_getattr_enter(inode);
632 /* Flush out writes to the server in order to update c/mtime. */ 632 /* Flush out writes to the server in order to update c/mtime. */
diff --git a/fs/nfs/netns.h b/fs/nfs/netns.h
index ef221fb8a183..f0e06e4acbef 100644
--- a/fs/nfs/netns.h
+++ b/fs/nfs/netns.h
@@ -19,6 +19,7 @@ struct nfs_net {
19 struct rpc_pipe *bl_device_pipe; 19 struct rpc_pipe *bl_device_pipe;
20 struct bl_dev_msg bl_mount_reply; 20 struct bl_dev_msg bl_mount_reply;
21 wait_queue_head_t bl_wq; 21 wait_queue_head_t bl_wq;
22 struct mutex bl_mutex;
22 struct list_head nfs_client_list; 23 struct list_head nfs_client_list;
23 struct list_head nfs_volume_list; 24 struct list_head nfs_volume_list;
24#if IS_ENABLED(CONFIG_NFS_V4) 25#if IS_ENABLED(CONFIG_NFS_V4)
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 405bd95c1f58..69dc20a743f9 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -370,11 +370,6 @@ static int nfs4_handle_exception(struct nfs_server *server, int errorcode, struc
370 case -NFS4ERR_DELEG_REVOKED: 370 case -NFS4ERR_DELEG_REVOKED:
371 case -NFS4ERR_ADMIN_REVOKED: 371 case -NFS4ERR_ADMIN_REVOKED:
372 case -NFS4ERR_BAD_STATEID: 372 case -NFS4ERR_BAD_STATEID:
373 if (inode != NULL && nfs4_have_delegation(inode, FMODE_READ)) {
374 nfs_remove_bad_delegation(inode);
375 exception->retry = 1;
376 break;
377 }
378 if (state == NULL) 373 if (state == NULL)
379 break; 374 break;
380 ret = nfs4_schedule_stateid_recovery(server, state); 375 ret = nfs4_schedule_stateid_recovery(server, state);
@@ -1654,7 +1649,7 @@ static int nfs4_handle_delegation_recall_error(struct nfs_server *server, struct
1654 nfs_inode_find_state_and_recover(state->inode, 1649 nfs_inode_find_state_and_recover(state->inode,
1655 stateid); 1650 stateid);
1656 nfs4_schedule_stateid_recovery(server, state); 1651 nfs4_schedule_stateid_recovery(server, state);
1657 return 0; 1652 return -EAGAIN;
1658 case -NFS4ERR_DELAY: 1653 case -NFS4ERR_DELAY:
1659 case -NFS4ERR_GRACE: 1654 case -NFS4ERR_GRACE:
1660 set_bit(NFS_DELEGATED_STATE, &state->flags); 1655 set_bit(NFS_DELEGATED_STATE, &state->flags);
@@ -2109,46 +2104,60 @@ static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *sta
2109 return ret; 2104 return ret;
2110} 2105}
2111 2106
2107static void nfs_finish_clear_delegation_stateid(struct nfs4_state *state)
2108{
2109 nfs_remove_bad_delegation(state->inode);
2110 write_seqlock(&state->seqlock);
2111 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
2112 write_sequnlock(&state->seqlock);
2113 clear_bit(NFS_DELEGATED_STATE, &state->flags);
2114}
2115
2116static void nfs40_clear_delegation_stateid(struct nfs4_state *state)
2117{
2118 if (rcu_access_pointer(NFS_I(state->inode)->delegation) != NULL)
2119 nfs_finish_clear_delegation_stateid(state);
2120}
2121
2122static int nfs40_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state)
2123{
2124 /* NFSv4.0 doesn't allow for delegation recovery on open expire */
2125 nfs40_clear_delegation_stateid(state);
2126 return nfs4_open_expired(sp, state);
2127}
2128
2112#if defined(CONFIG_NFS_V4_1) 2129#if defined(CONFIG_NFS_V4_1)
2113static void nfs41_clear_delegation_stateid(struct nfs4_state *state) 2130static void nfs41_check_delegation_stateid(struct nfs4_state *state)
2114{ 2131{
2115 struct nfs_server *server = NFS_SERVER(state->inode); 2132 struct nfs_server *server = NFS_SERVER(state->inode);
2116 nfs4_stateid *stateid = &state->stateid; 2133 nfs4_stateid stateid;
2117 struct nfs_delegation *delegation; 2134 struct nfs_delegation *delegation;
2118 struct rpc_cred *cred = NULL; 2135 struct rpc_cred *cred;
2119 int status = -NFS4ERR_BAD_STATEID; 2136 int status;
2120
2121 /* If a state reset has been done, test_stateid is unneeded */
2122 if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0)
2123 return;
2124 2137
2125 /* Get the delegation credential for use by test/free_stateid */ 2138 /* Get the delegation credential for use by test/free_stateid */
2126 rcu_read_lock(); 2139 rcu_read_lock();
2127 delegation = rcu_dereference(NFS_I(state->inode)->delegation); 2140 delegation = rcu_dereference(NFS_I(state->inode)->delegation);
2128 if (delegation != NULL && 2141 if (delegation == NULL) {
2129 nfs4_stateid_match(&delegation->stateid, stateid)) {
2130 cred = get_rpccred(delegation->cred);
2131 rcu_read_unlock();
2132 status = nfs41_test_stateid(server, stateid, cred);
2133 trace_nfs4_test_delegation_stateid(state, NULL, status);
2134 } else
2135 rcu_read_unlock(); 2142 rcu_read_unlock();
2143 return;
2144 }
2145
2146 nfs4_stateid_copy(&stateid, &delegation->stateid);
2147 cred = get_rpccred(delegation->cred);
2148 rcu_read_unlock();
2149 status = nfs41_test_stateid(server, &stateid, cred);
2150 trace_nfs4_test_delegation_stateid(state, NULL, status);
2136 2151
2137 if (status != NFS_OK) { 2152 if (status != NFS_OK) {
2138 /* Free the stateid unless the server explicitly 2153 /* Free the stateid unless the server explicitly
2139 * informs us the stateid is unrecognized. */ 2154 * informs us the stateid is unrecognized. */
2140 if (status != -NFS4ERR_BAD_STATEID) 2155 if (status != -NFS4ERR_BAD_STATEID)
2141 nfs41_free_stateid(server, stateid, cred); 2156 nfs41_free_stateid(server, &stateid, cred);
2142 nfs_remove_bad_delegation(state->inode); 2157 nfs_finish_clear_delegation_stateid(state);
2143
2144 write_seqlock(&state->seqlock);
2145 nfs4_stateid_copy(&state->stateid, &state->open_stateid);
2146 write_sequnlock(&state->seqlock);
2147 clear_bit(NFS_DELEGATED_STATE, &state->flags);
2148 } 2158 }
2149 2159
2150 if (cred != NULL) 2160 put_rpccred(cred);
2151 put_rpccred(cred);
2152} 2161}
2153 2162
2154/** 2163/**
@@ -2192,7 +2201,7 @@ static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *st
2192{ 2201{
2193 int status; 2202 int status;
2194 2203
2195 nfs41_clear_delegation_stateid(state); 2204 nfs41_check_delegation_stateid(state);
2196 status = nfs41_check_open_stateid(state); 2205 status = nfs41_check_open_stateid(state);
2197 if (status != NFS_OK) 2206 if (status != NFS_OK)
2198 status = nfs4_open_expired(sp, state); 2207 status = nfs4_open_expired(sp, state);
@@ -2231,19 +2240,8 @@ static int _nfs4_open_and_get_state(struct nfs4_opendata *opendata,
2231 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount); 2240 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
2232 2241
2233 ret = _nfs4_proc_open(opendata); 2242 ret = _nfs4_proc_open(opendata);
2234 if (ret != 0) { 2243 if (ret != 0)
2235 if (ret == -ENOENT) {
2236 dentry = opendata->dentry;
2237 if (dentry->d_inode)
2238 d_delete(dentry);
2239 else if (d_unhashed(dentry))
2240 d_add(dentry, NULL);
2241
2242 nfs_set_verifier(dentry,
2243 nfs_save_change_attribute(opendata->dir->d_inode));
2244 }
2245 goto out; 2244 goto out;
2246 }
2247 2245
2248 state = nfs4_opendata_to_nfs4_state(opendata); 2246 state = nfs4_opendata_to_nfs4_state(opendata);
2249 ret = PTR_ERR(state); 2247 ret = PTR_ERR(state);
@@ -4841,9 +4839,6 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server,
4841 case -NFS4ERR_DELEG_REVOKED: 4839 case -NFS4ERR_DELEG_REVOKED:
4842 case -NFS4ERR_ADMIN_REVOKED: 4840 case -NFS4ERR_ADMIN_REVOKED:
4843 case -NFS4ERR_BAD_STATEID: 4841 case -NFS4ERR_BAD_STATEID:
4844 if (state == NULL)
4845 break;
4846 nfs_remove_bad_delegation(state->inode);
4847 case -NFS4ERR_OPENMODE: 4842 case -NFS4ERR_OPENMODE:
4848 if (state == NULL) 4843 if (state == NULL)
4849 break; 4844 break;
@@ -8341,7 +8336,7 @@ static const struct nfs4_state_recovery_ops nfs41_reboot_recovery_ops = {
8341static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = { 8336static const struct nfs4_state_recovery_ops nfs40_nograce_recovery_ops = {
8342 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE, 8337 .owner_flag_bit = NFS_OWNER_RECLAIM_NOGRACE,
8343 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE, 8338 .state_flag_bit = NFS_STATE_RECLAIM_NOGRACE,
8344 .recover_open = nfs4_open_expired, 8339 .recover_open = nfs40_open_expired,
8345 .recover_lock = nfs4_lock_expired, 8340 .recover_lock = nfs4_lock_expired,
8346 .establish_clid = nfs4_init_clientid, 8341 .establish_clid = nfs4_init_clientid,
8347}; 8342};
@@ -8408,8 +8403,7 @@ static const struct nfs4_minor_version_ops nfs_v4_1_minor_ops = {
8408 | NFS_CAP_CHANGE_ATTR 8403 | NFS_CAP_CHANGE_ATTR
8409 | NFS_CAP_POSIX_LOCK 8404 | NFS_CAP_POSIX_LOCK
8410 | NFS_CAP_STATEID_NFSV41 8405 | NFS_CAP_STATEID_NFSV41
8411 | NFS_CAP_ATOMIC_OPEN_V1 8406 | NFS_CAP_ATOMIC_OPEN_V1,
8412 | NFS_CAP_SEEK,
8413 .init_client = nfs41_init_client, 8407 .init_client = nfs41_init_client,
8414 .shutdown_client = nfs41_shutdown_client, 8408 .shutdown_client = nfs41_shutdown_client,
8415 .match_stateid = nfs41_match_stateid, 8409 .match_stateid = nfs41_match_stateid,
@@ -8431,7 +8425,8 @@ static const struct nfs4_minor_version_ops nfs_v4_2_minor_ops = {
8431 | NFS_CAP_CHANGE_ATTR 8425 | NFS_CAP_CHANGE_ATTR
8432 | NFS_CAP_POSIX_LOCK 8426 | NFS_CAP_POSIX_LOCK
8433 | NFS_CAP_STATEID_NFSV41 8427 | NFS_CAP_STATEID_NFSV41
8434 | NFS_CAP_ATOMIC_OPEN_V1, 8428 | NFS_CAP_ATOMIC_OPEN_V1
8429 | NFS_CAP_SEEK,
8435 .init_client = nfs41_init_client, 8430 .init_client = nfs41_init_client,
8436 .shutdown_client = nfs41_shutdown_client, 8431 .shutdown_client = nfs41_shutdown_client,
8437 .match_stateid = nfs41_match_stateid, 8432 .match_stateid = nfs41_match_stateid,
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 12493846a2d3..f83b02dc9166 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -715,8 +715,6 @@ static void nfs_inode_remove_request(struct nfs_page *req)
715 715
716 if (test_and_clear_bit(PG_INODE_REF, &req->wb_flags)) 716 if (test_and_clear_bit(PG_INODE_REF, &req->wb_flags))
717 nfs_release_request(req); 717 nfs_release_request(req);
718 else
719 WARN_ON_ONCE(1);
720} 718}
721 719
722static void 720static void
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index ed2b1151b171..7cbdf1b2e4ab 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -774,8 +774,12 @@ static bool nfsd41_cb_get_slot(struct nfs4_client *clp, struct rpc_task *task)
774{ 774{
775 if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) { 775 if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) {
776 rpc_sleep_on(&clp->cl_cb_waitq, task, NULL); 776 rpc_sleep_on(&clp->cl_cb_waitq, task, NULL);
777 dprintk("%s slot is busy\n", __func__); 777 /* Race breaker */
778 return false; 778 if (test_and_set_bit(0, &clp->cl_cb_slot_busy) != 0) {
779 dprintk("%s slot is busy\n", __func__);
780 return false;
781 }
782 rpc_wake_up_queued_task(&clp->cl_cb_waitq, task);
779 } 783 }
780 return true; 784 return true;
781} 785}
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index 747f3b95bd11..33a46a8dfaf7 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -335,12 +335,15 @@ void nfsd_lockd_shutdown(void);
335 (NFSD4_SUPPORTED_ATTRS_WORD2 | FATTR4_WORD2_SUPPATTR_EXCLCREAT) 335 (NFSD4_SUPPORTED_ATTRS_WORD2 | FATTR4_WORD2_SUPPATTR_EXCLCREAT)
336 336
337#ifdef CONFIG_NFSD_V4_SECURITY_LABEL 337#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
338#define NFSD4_2_SUPPORTED_ATTRS_WORD2 \ 338#define NFSD4_2_SECURITY_ATTRS FATTR4_WORD2_SECURITY_LABEL
339 (NFSD4_1_SUPPORTED_ATTRS_WORD2 | FATTR4_WORD2_SECURITY_LABEL)
340#else 339#else
341#define NFSD4_2_SUPPORTED_ATTRS_WORD2 0 340#define NFSD4_2_SECURITY_ATTRS 0
342#endif 341#endif
343 342
343#define NFSD4_2_SUPPORTED_ATTRS_WORD2 \
344 (NFSD4_1_SUPPORTED_ATTRS_WORD2 | \
345 NFSD4_2_SECURITY_ATTRS)
346
344static inline u32 nfsd_suppattrs0(u32 minorversion) 347static inline u32 nfsd_suppattrs0(u32 minorversion)
345{ 348{
346 return minorversion ? NFSD4_1_SUPPORTED_ATTRS_WORD0 349 return minorversion ? NFSD4_1_SUPPORTED_ATTRS_WORD0
diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 9d3e9c50066a..89326acd4561 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -229,8 +229,16 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
229 &fsnotify_mark_srcu); 229 &fsnotify_mark_srcu);
230 } 230 }
231 231
232 /*
233 * We need to merge inode & vfsmount mark lists so that inode mark
234 * ignore masks are properly reflected for mount mark notifications.
235 * That's why this traversal is so complicated...
236 */
232 while (inode_node || vfsmount_node) { 237 while (inode_node || vfsmount_node) {
233 inode_group = vfsmount_group = NULL; 238 inode_group = NULL;
239 inode_mark = NULL;
240 vfsmount_group = NULL;
241 vfsmount_mark = NULL;
234 242
235 if (inode_node) { 243 if (inode_node) {
236 inode_mark = hlist_entry(srcu_dereference(inode_node, &fsnotify_mark_srcu), 244 inode_mark = hlist_entry(srcu_dereference(inode_node, &fsnotify_mark_srcu),
@@ -244,21 +252,19 @@ int fsnotify(struct inode *to_tell, __u32 mask, void *data, int data_is,
244 vfsmount_group = vfsmount_mark->group; 252 vfsmount_group = vfsmount_mark->group;
245 } 253 }
246 254
247 if (inode_group > vfsmount_group) { 255 if (inode_group && vfsmount_group) {
248 /* handle inode */ 256 int cmp = fsnotify_compare_groups(inode_group,
249 ret = send_to_group(to_tell, inode_mark, NULL, mask, 257 vfsmount_group);
250 data, data_is, cookie, file_name); 258 if (cmp > 0) {
251 /* we didn't use the vfsmount_mark */ 259 inode_group = NULL;
252 vfsmount_group = NULL; 260 inode_mark = NULL;
253 } else if (vfsmount_group > inode_group) { 261 } else if (cmp < 0) {
254 ret = send_to_group(to_tell, NULL, vfsmount_mark, mask, 262 vfsmount_group = NULL;
255 data, data_is, cookie, file_name); 263 vfsmount_mark = NULL;
256 inode_group = NULL; 264 }
257 } else {
258 ret = send_to_group(to_tell, inode_mark, vfsmount_mark,
259 mask, data, data_is, cookie,
260 file_name);
261 } 265 }
266 ret = send_to_group(to_tell, inode_mark, vfsmount_mark, mask,
267 data, data_is, cookie, file_name);
262 268
263 if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS)) 269 if (ret && (mask & ALL_FSNOTIFY_PERM_EVENTS))
264 goto out; 270 goto out;
diff --git a/fs/notify/fsnotify.h b/fs/notify/fsnotify.h
index 9c0898c4cfe1..3b68b0ae0a97 100644
--- a/fs/notify/fsnotify.h
+++ b/fs/notify/fsnotify.h
@@ -12,6 +12,10 @@ extern void fsnotify_flush_notify(struct fsnotify_group *group);
12/* protects reads of inode and vfsmount marks list */ 12/* protects reads of inode and vfsmount marks list */
13extern struct srcu_struct fsnotify_mark_srcu; 13extern struct srcu_struct fsnotify_mark_srcu;
14 14
15/* compare two groups for sorting of marks lists */
16extern int fsnotify_compare_groups(struct fsnotify_group *a,
17 struct fsnotify_group *b);
18
15extern void fsnotify_set_inode_mark_mask_locked(struct fsnotify_mark *fsn_mark, 19extern void fsnotify_set_inode_mark_mask_locked(struct fsnotify_mark *fsn_mark,
16 __u32 mask); 20 __u32 mask);
17/* add a mark to an inode */ 21/* add a mark to an inode */
diff --git a/fs/notify/inode_mark.c b/fs/notify/inode_mark.c
index e8497144b323..dfbf5447eea4 100644
--- a/fs/notify/inode_mark.c
+++ b/fs/notify/inode_mark.c
@@ -194,6 +194,7 @@ int fsnotify_add_inode_mark(struct fsnotify_mark *mark,
194{ 194{
195 struct fsnotify_mark *lmark, *last = NULL; 195 struct fsnotify_mark *lmark, *last = NULL;
196 int ret = 0; 196 int ret = 0;
197 int cmp;
197 198
198 mark->flags |= FSNOTIFY_MARK_FLAG_INODE; 199 mark->flags |= FSNOTIFY_MARK_FLAG_INODE;
199 200
@@ -219,11 +220,8 @@ int fsnotify_add_inode_mark(struct fsnotify_mark *mark,
219 goto out; 220 goto out;
220 } 221 }
221 222
222 if (mark->group->priority < lmark->group->priority) 223 cmp = fsnotify_compare_groups(lmark->group, mark->group);
223 continue; 224 if (cmp < 0)
224
225 if ((mark->group->priority == lmark->group->priority) &&
226 (mark->group < lmark->group))
227 continue; 225 continue;
228 226
229 hlist_add_before_rcu(&mark->i.i_list, &lmark->i.i_list); 227 hlist_add_before_rcu(&mark->i.i_list, &lmark->i.i_list);
diff --git a/fs/notify/mark.c b/fs/notify/mark.c
index d90deaa08e78..34c38fabf514 100644
--- a/fs/notify/mark.c
+++ b/fs/notify/mark.c
@@ -210,6 +210,42 @@ void fsnotify_set_mark_ignored_mask_locked(struct fsnotify_mark *mark, __u32 mas
210} 210}
211 211
212/* 212/*
213 * Sorting function for lists of fsnotify marks.
214 *
215 * Fanotify supports different notification classes (reflected as priority of
216 * notification group). Events shall be passed to notification groups in
217 * decreasing priority order. To achieve this marks in notification lists for
218 * inodes and vfsmounts are sorted so that priorities of corresponding groups
219 * are descending.
220 *
221 * Furthermore correct handling of the ignore mask requires processing inode
222 * and vfsmount marks of each group together. Using the group address as
223 * further sort criterion provides a unique sorting order and thus we can
224 * merge inode and vfsmount lists of marks in linear time and find groups
225 * present in both lists.
226 *
227 * A return value of 1 signifies that b has priority over a.
228 * A return value of 0 signifies that the two marks have to be handled together.
229 * A return value of -1 signifies that a has priority over b.
230 */
231int fsnotify_compare_groups(struct fsnotify_group *a, struct fsnotify_group *b)
232{
233 if (a == b)
234 return 0;
235 if (!a)
236 return 1;
237 if (!b)
238 return -1;
239 if (a->priority < b->priority)
240 return 1;
241 if (a->priority > b->priority)
242 return -1;
243 if (a < b)
244 return 1;
245 return -1;
246}
247
248/*
213 * Attach an initialized mark to a given group and fs object. 249 * Attach an initialized mark to a given group and fs object.
214 * These marks may be used for the fsnotify backend to determine which 250 * These marks may be used for the fsnotify backend to determine which
215 * event types should be delivered to which group. 251 * event types should be delivered to which group.
diff --git a/fs/notify/vfsmount_mark.c b/fs/notify/vfsmount_mark.c
index ac851e8376b1..faefa72a11eb 100644
--- a/fs/notify/vfsmount_mark.c
+++ b/fs/notify/vfsmount_mark.c
@@ -153,6 +153,7 @@ int fsnotify_add_vfsmount_mark(struct fsnotify_mark *mark,
153 struct mount *m = real_mount(mnt); 153 struct mount *m = real_mount(mnt);
154 struct fsnotify_mark *lmark, *last = NULL; 154 struct fsnotify_mark *lmark, *last = NULL;
155 int ret = 0; 155 int ret = 0;
156 int cmp;
156 157
157 mark->flags |= FSNOTIFY_MARK_FLAG_VFSMOUNT; 158 mark->flags |= FSNOTIFY_MARK_FLAG_VFSMOUNT;
158 159
@@ -178,11 +179,8 @@ int fsnotify_add_vfsmount_mark(struct fsnotify_mark *mark,
178 goto out; 179 goto out;
179 } 180 }
180 181
181 if (mark->group->priority < lmark->group->priority) 182 cmp = fsnotify_compare_groups(lmark->group, mark->group);
182 continue; 183 if (cmp < 0)
183
184 if ((mark->group->priority == lmark->group->priority) &&
185 (mark->group < lmark->group))
186 continue; 184 continue;
187 185
188 hlist_add_before_rcu(&mark->m.m_list, &lmark->m.m_list); 186 hlist_add_before_rcu(&mark->m.m_list, &lmark->m.m_list);
diff --git a/fs/ocfs2/cluster/tcp.c b/fs/ocfs2/cluster/tcp.c
index 97de0fbd9f78..a96044004064 100644
--- a/fs/ocfs2/cluster/tcp.c
+++ b/fs/ocfs2/cluster/tcp.c
@@ -925,7 +925,7 @@ static int o2net_send_tcp_msg(struct socket *sock, struct kvec *vec,
925 size_t veclen, size_t total) 925 size_t veclen, size_t total)
926{ 926{
927 int ret; 927 int ret;
928 struct msghdr msg; 928 struct msghdr msg = {.msg_flags = 0,};
929 929
930 if (sock == NULL) { 930 if (sock == NULL) {
931 ret = -EINVAL; 931 ret = -EINVAL;
diff --git a/fs/overlayfs/Kconfig b/fs/overlayfs/Kconfig
index e60125976873..34355818a2e0 100644
--- a/fs/overlayfs/Kconfig
+++ b/fs/overlayfs/Kconfig
@@ -1,4 +1,4 @@
1config OVERLAYFS_FS 1config OVERLAY_FS
2 tristate "Overlay filesystem support" 2 tristate "Overlay filesystem support"
3 help 3 help
4 An overlay filesystem combines two filesystems - an 'upper' filesystem 4 An overlay filesystem combines two filesystems - an 'upper' filesystem
diff --git a/fs/overlayfs/Makefile b/fs/overlayfs/Makefile
index 8f91889480d0..900daed3e91d 100644
--- a/fs/overlayfs/Makefile
+++ b/fs/overlayfs/Makefile
@@ -2,6 +2,6 @@
2# Makefile for the overlay filesystem. 2# Makefile for the overlay filesystem.
3# 3#
4 4
5obj-$(CONFIG_OVERLAYFS_FS) += overlayfs.o 5obj-$(CONFIG_OVERLAY_FS) += overlay.o
6 6
7overlayfs-objs := super.o inode.o dir.o readdir.o copy_up.o 7overlay-objs := super.o inode.o dir.o readdir.o copy_up.o
diff --git a/fs/overlayfs/dir.c b/fs/overlayfs/dir.c
index 15cd91ad9940..8ffc4b980f1b 100644
--- a/fs/overlayfs/dir.c
+++ b/fs/overlayfs/dir.c
@@ -284,8 +284,7 @@ out:
284 return ERR_PTR(err); 284 return ERR_PTR(err);
285} 285}
286 286
287static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry, 287static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry)
288 enum ovl_path_type type)
289{ 288{
290 int err; 289 int err;
291 struct dentry *ret = NULL; 290 struct dentry *ret = NULL;
@@ -294,8 +293,17 @@ static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry,
294 err = ovl_check_empty_dir(dentry, &list); 293 err = ovl_check_empty_dir(dentry, &list);
295 if (err) 294 if (err)
296 ret = ERR_PTR(err); 295 ret = ERR_PTR(err);
297 else if (type == OVL_PATH_MERGE) 296 else {
298 ret = ovl_clear_empty(dentry, &list); 297 /*
298 * If no upperdentry then skip clearing whiteouts.
299 *
300 * Can race with copy-up, since we don't hold the upperdir
301 * mutex. Doesn't matter, since copy-up can't create a
302 * non-empty directory from an empty one.
303 */
304 if (ovl_dentry_upper(dentry))
305 ret = ovl_clear_empty(dentry, &list);
306 }
299 307
300 ovl_cache_free(&list); 308 ovl_cache_free(&list);
301 309
@@ -487,8 +495,7 @@ out:
487 return err; 495 return err;
488} 496}
489 497
490static int ovl_remove_and_whiteout(struct dentry *dentry, 498static int ovl_remove_and_whiteout(struct dentry *dentry, bool is_dir)
491 enum ovl_path_type type, bool is_dir)
492{ 499{
493 struct dentry *workdir = ovl_workdir(dentry); 500 struct dentry *workdir = ovl_workdir(dentry);
494 struct inode *wdir = workdir->d_inode; 501 struct inode *wdir = workdir->d_inode;
@@ -500,7 +507,7 @@ static int ovl_remove_and_whiteout(struct dentry *dentry,
500 int err; 507 int err;
501 508
502 if (is_dir) { 509 if (is_dir) {
503 opaquedir = ovl_check_empty_and_clear(dentry, type); 510 opaquedir = ovl_check_empty_and_clear(dentry);
504 err = PTR_ERR(opaquedir); 511 err = PTR_ERR(opaquedir);
505 if (IS_ERR(opaquedir)) 512 if (IS_ERR(opaquedir))
506 goto out; 513 goto out;
@@ -515,9 +522,10 @@ static int ovl_remove_and_whiteout(struct dentry *dentry,
515 if (IS_ERR(whiteout)) 522 if (IS_ERR(whiteout))
516 goto out_unlock; 523 goto out_unlock;
517 524
518 if (type == OVL_PATH_LOWER) { 525 upper = ovl_dentry_upper(dentry);
526 if (!upper) {
519 upper = lookup_one_len(dentry->d_name.name, upperdir, 527 upper = lookup_one_len(dentry->d_name.name, upperdir,
520 dentry->d_name.len); 528 dentry->d_name.len);
521 err = PTR_ERR(upper); 529 err = PTR_ERR(upper);
522 if (IS_ERR(upper)) 530 if (IS_ERR(upper))
523 goto kill_whiteout; 531 goto kill_whiteout;
@@ -529,7 +537,6 @@ static int ovl_remove_and_whiteout(struct dentry *dentry,
529 } else { 537 } else {
530 int flags = 0; 538 int flags = 0;
531 539
532 upper = ovl_dentry_upper(dentry);
533 if (opaquedir) 540 if (opaquedir)
534 upper = opaquedir; 541 upper = opaquedir;
535 err = -ESTALE; 542 err = -ESTALE;
@@ -648,7 +655,7 @@ static int ovl_do_remove(struct dentry *dentry, bool is_dir)
648 cap_raise(override_cred->cap_effective, CAP_CHOWN); 655 cap_raise(override_cred->cap_effective, CAP_CHOWN);
649 old_cred = override_creds(override_cred); 656 old_cred = override_creds(override_cred);
650 657
651 err = ovl_remove_and_whiteout(dentry, type, is_dir); 658 err = ovl_remove_and_whiteout(dentry, is_dir);
652 659
653 revert_creds(old_cred); 660 revert_creds(old_cred);
654 put_cred(override_cred); 661 put_cred(override_cred);
@@ -781,7 +788,7 @@ static int ovl_rename2(struct inode *olddir, struct dentry *old,
781 } 788 }
782 789
783 if (overwrite && (new_type == OVL_PATH_LOWER || new_type == OVL_PATH_MERGE) && new_is_dir) { 790 if (overwrite && (new_type == OVL_PATH_LOWER || new_type == OVL_PATH_MERGE) && new_is_dir) {
784 opaquedir = ovl_check_empty_and_clear(new, new_type); 791 opaquedir = ovl_check_empty_and_clear(new);
785 err = PTR_ERR(opaquedir); 792 err = PTR_ERR(opaquedir);
786 if (IS_ERR(opaquedir)) { 793 if (IS_ERR(opaquedir)) {
787 opaquedir = NULL; 794 opaquedir = NULL;
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index af2d18c9fcee..07d74b24913b 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -235,26 +235,36 @@ out:
235 return err; 235 return err;
236} 236}
237 237
238static bool ovl_need_xattr_filter(struct dentry *dentry,
239 enum ovl_path_type type)
240{
241 return type == OVL_PATH_UPPER && S_ISDIR(dentry->d_inode->i_mode);
242}
243
238ssize_t ovl_getxattr(struct dentry *dentry, const char *name, 244ssize_t ovl_getxattr(struct dentry *dentry, const char *name,
239 void *value, size_t size) 245 void *value, size_t size)
240{ 246{
241 if (ovl_path_type(dentry->d_parent) == OVL_PATH_MERGE && 247 struct path realpath;
242 ovl_is_private_xattr(name)) 248 enum ovl_path_type type = ovl_path_real(dentry, &realpath);
249
250 if (ovl_need_xattr_filter(dentry, type) && ovl_is_private_xattr(name))
243 return -ENODATA; 251 return -ENODATA;
244 252
245 return vfs_getxattr(ovl_dentry_real(dentry), name, value, size); 253 return vfs_getxattr(realpath.dentry, name, value, size);
246} 254}
247 255
248ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size) 256ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
249{ 257{
258 struct path realpath;
259 enum ovl_path_type type = ovl_path_real(dentry, &realpath);
250 ssize_t res; 260 ssize_t res;
251 int off; 261 int off;
252 262
253 res = vfs_listxattr(ovl_dentry_real(dentry), list, size); 263 res = vfs_listxattr(realpath.dentry, list, size);
254 if (res <= 0 || size == 0) 264 if (res <= 0 || size == 0)
255 return res; 265 return res;
256 266
257 if (ovl_path_type(dentry->d_parent) != OVL_PATH_MERGE) 267 if (!ovl_need_xattr_filter(dentry, type))
258 return res; 268 return res;
259 269
260 /* filter out private xattrs */ 270 /* filter out private xattrs */
@@ -279,17 +289,16 @@ int ovl_removexattr(struct dentry *dentry, const char *name)
279{ 289{
280 int err; 290 int err;
281 struct path realpath; 291 struct path realpath;
282 enum ovl_path_type type; 292 enum ovl_path_type type = ovl_path_real(dentry, &realpath);
283 293
284 err = ovl_want_write(dentry); 294 err = ovl_want_write(dentry);
285 if (err) 295 if (err)
286 goto out; 296 goto out;
287 297
288 if (ovl_path_type(dentry->d_parent) == OVL_PATH_MERGE && 298 err = -ENODATA;
289 ovl_is_private_xattr(name)) 299 if (ovl_need_xattr_filter(dentry, type) && ovl_is_private_xattr(name))
290 goto out_drop_write; 300 goto out_drop_write;
291 301
292 type = ovl_path_real(dentry, &realpath);
293 if (type == OVL_PATH_LOWER) { 302 if (type == OVL_PATH_LOWER) {
294 err = vfs_getxattr(realpath.dentry, name, NULL, 0); 303 err = vfs_getxattr(realpath.dentry, name, NULL, 0);
295 if (err < 0) 304 if (err < 0)
diff --git a/fs/overlayfs/readdir.c b/fs/overlayfs/readdir.c
index 4e9d7c1fea52..ab1e3dcbed95 100644
--- a/fs/overlayfs/readdir.c
+++ b/fs/overlayfs/readdir.c
@@ -168,7 +168,7 @@ static void ovl_cache_put(struct ovl_dir_file *od, struct dentry *dentry)
168{ 168{
169 struct ovl_dir_cache *cache = od->cache; 169 struct ovl_dir_cache *cache = od->cache;
170 170
171 list_del(&od->cursor.l_node); 171 list_del_init(&od->cursor.l_node);
172 WARN_ON(cache->refcount <= 0); 172 WARN_ON(cache->refcount <= 0);
173 cache->refcount--; 173 cache->refcount--;
174 if (!cache->refcount) { 174 if (!cache->refcount) {
@@ -274,11 +274,11 @@ static int ovl_dir_mark_whiteouts(struct dentry *dir,
274 return 0; 274 return 0;
275} 275}
276 276
277static inline int ovl_dir_read_merged(struct path *upperpath, 277static int ovl_dir_read_merged(struct dentry *dentry, struct list_head *list)
278 struct path *lowerpath,
279 struct list_head *list)
280{ 278{
281 int err; 279 int err;
280 struct path lowerpath;
281 struct path upperpath;
282 struct ovl_readdir_data rdd = { 282 struct ovl_readdir_data rdd = {
283 .ctx.actor = ovl_fill_merge, 283 .ctx.actor = ovl_fill_merge,
284 .list = list, 284 .list = list,
@@ -286,25 +286,28 @@ static inline int ovl_dir_read_merged(struct path *upperpath,
286 .is_merge = false, 286 .is_merge = false,
287 }; 287 };
288 288
289 if (upperpath->dentry) { 289 ovl_path_lower(dentry, &lowerpath);
290 err = ovl_dir_read(upperpath, &rdd); 290 ovl_path_upper(dentry, &upperpath);
291
292 if (upperpath.dentry) {
293 err = ovl_dir_read(&upperpath, &rdd);
291 if (err) 294 if (err)
292 goto out; 295 goto out;
293 296
294 if (lowerpath->dentry) { 297 if (lowerpath.dentry) {
295 err = ovl_dir_mark_whiteouts(upperpath->dentry, &rdd); 298 err = ovl_dir_mark_whiteouts(upperpath.dentry, &rdd);
296 if (err) 299 if (err)
297 goto out; 300 goto out;
298 } 301 }
299 } 302 }
300 if (lowerpath->dentry) { 303 if (lowerpath.dentry) {
301 /* 304 /*
302 * Insert lowerpath entries before upperpath ones, this allows 305 * Insert lowerpath entries before upperpath ones, this allows
303 * offsets to be reasonably constant 306 * offsets to be reasonably constant
304 */ 307 */
305 list_add(&rdd.middle, rdd.list); 308 list_add(&rdd.middle, rdd.list);
306 rdd.is_merge = true; 309 rdd.is_merge = true;
307 err = ovl_dir_read(lowerpath, &rdd); 310 err = ovl_dir_read(&lowerpath, &rdd);
308 list_del(&rdd.middle); 311 list_del(&rdd.middle);
309 } 312 }
310out: 313out:
@@ -329,8 +332,6 @@ static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos)
329static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry) 332static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)
330{ 333{
331 int res; 334 int res;
332 struct path lowerpath;
333 struct path upperpath;
334 struct ovl_dir_cache *cache; 335 struct ovl_dir_cache *cache;
335 336
336 cache = ovl_dir_cache(dentry); 337 cache = ovl_dir_cache(dentry);
@@ -347,10 +348,7 @@ static struct ovl_dir_cache *ovl_cache_get(struct dentry *dentry)
347 cache->refcount = 1; 348 cache->refcount = 1;
348 INIT_LIST_HEAD(&cache->entries); 349 INIT_LIST_HEAD(&cache->entries);
349 350
350 ovl_path_lower(dentry, &lowerpath); 351 res = ovl_dir_read_merged(dentry, &cache->entries);
351 ovl_path_upper(dentry, &upperpath);
352
353 res = ovl_dir_read_merged(&upperpath, &lowerpath, &cache->entries);
354 if (res) { 352 if (res) {
355 ovl_cache_free(&cache->entries); 353 ovl_cache_free(&cache->entries);
356 kfree(cache); 354 kfree(cache);
@@ -452,10 +450,10 @@ static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end,
452 /* 450 /*
453 * Need to check if we started out being a lower dir, but got copied up 451 * Need to check if we started out being a lower dir, but got copied up
454 */ 452 */
455 if (!od->is_upper && ovl_path_type(dentry) == OVL_PATH_MERGE) { 453 if (!od->is_upper && ovl_path_type(dentry) != OVL_PATH_LOWER) {
456 struct inode *inode = file_inode(file); 454 struct inode *inode = file_inode(file);
457 455
458 realfile =lockless_dereference(od->upperfile); 456 realfile = lockless_dereference(od->upperfile);
459 if (!realfile) { 457 if (!realfile) {
460 struct path upperpath; 458 struct path upperpath;
461 459
@@ -538,14 +536,9 @@ const struct file_operations ovl_dir_operations = {
538int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list) 536int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)
539{ 537{
540 int err; 538 int err;
541 struct path lowerpath;
542 struct path upperpath;
543 struct ovl_cache_entry *p; 539 struct ovl_cache_entry *p;
544 540
545 ovl_path_upper(dentry, &upperpath); 541 err = ovl_dir_read_merged(dentry, list);
546 ovl_path_lower(dentry, &lowerpath);
547
548 err = ovl_dir_read_merged(&upperpath, &lowerpath, list);
549 if (err) 542 if (err)
550 return err; 543 return err;
551 544
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 08b704cebfc4..f16d318b71f8 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -24,7 +24,7 @@ MODULE_AUTHOR("Miklos Szeredi <miklos@szeredi.hu>");
24MODULE_DESCRIPTION("Overlay filesystem"); 24MODULE_DESCRIPTION("Overlay filesystem");
25MODULE_LICENSE("GPL"); 25MODULE_LICENSE("GPL");
26 26
27#define OVERLAYFS_SUPER_MAGIC 0x794c764f 27#define OVERLAYFS_SUPER_MAGIC 0x794c7630
28 28
29struct ovl_config { 29struct ovl_config {
30 char *lowerdir; 30 char *lowerdir;
@@ -84,12 +84,7 @@ enum ovl_path_type ovl_path_type(struct dentry *dentry)
84 84
85static struct dentry *ovl_upperdentry_dereference(struct ovl_entry *oe) 85static struct dentry *ovl_upperdentry_dereference(struct ovl_entry *oe)
86{ 86{
87 struct dentry *upperdentry = ACCESS_ONCE(oe->__upperdentry); 87 return lockless_dereference(oe->__upperdentry);
88 /*
89 * Make sure to order reads to upperdentry wrt ovl_dentry_update()
90 */
91 smp_read_barrier_depends();
92 return upperdentry;
93} 88}
94 89
95void ovl_path_upper(struct dentry *dentry, struct path *path) 90void ovl_path_upper(struct dentry *dentry, struct path *path)
@@ -462,11 +457,34 @@ static const match_table_t ovl_tokens = {
462 {OPT_ERR, NULL} 457 {OPT_ERR, NULL}
463}; 458};
464 459
460static char *ovl_next_opt(char **s)
461{
462 char *sbegin = *s;
463 char *p;
464
465 if (sbegin == NULL)
466 return NULL;
467
468 for (p = sbegin; *p; p++) {
469 if (*p == '\\') {
470 p++;
471 if (!*p)
472 break;
473 } else if (*p == ',') {
474 *p = '\0';
475 *s = p + 1;
476 return sbegin;
477 }
478 }
479 *s = NULL;
480 return sbegin;
481}
482
465static int ovl_parse_opt(char *opt, struct ovl_config *config) 483static int ovl_parse_opt(char *opt, struct ovl_config *config)
466{ 484{
467 char *p; 485 char *p;
468 486
469 while ((p = strsep(&opt, ",")) != NULL) { 487 while ((p = ovl_next_opt(&opt)) != NULL) {
470 int token; 488 int token;
471 substring_t args[MAX_OPT_ARGS]; 489 substring_t args[MAX_OPT_ARGS];
472 490
@@ -554,15 +572,34 @@ out_dput:
554 goto out_unlock; 572 goto out_unlock;
555} 573}
556 574
575static void ovl_unescape(char *s)
576{
577 char *d = s;
578
579 for (;; s++, d++) {
580 if (*s == '\\')
581 s++;
582 *d = *s;
583 if (!*s)
584 break;
585 }
586}
587
557static int ovl_mount_dir(const char *name, struct path *path) 588static int ovl_mount_dir(const char *name, struct path *path)
558{ 589{
559 int err; 590 int err;
591 char *tmp = kstrdup(name, GFP_KERNEL);
592
593 if (!tmp)
594 return -ENOMEM;
560 595
561 err = kern_path(name, LOOKUP_FOLLOW, path); 596 ovl_unescape(tmp);
597 err = kern_path(tmp, LOOKUP_FOLLOW, path);
562 if (err) { 598 if (err) {
563 pr_err("overlayfs: failed to resolve '%s': %i\n", name, err); 599 pr_err("overlayfs: failed to resolve '%s': %i\n", tmp, err);
564 err = -EINVAL; 600 err = -EINVAL;
565 } 601 }
602 kfree(tmp);
566 return err; 603 return err;
567} 604}
568 605
@@ -776,11 +813,11 @@ static struct dentry *ovl_mount(struct file_system_type *fs_type, int flags,
776 813
777static struct file_system_type ovl_fs_type = { 814static struct file_system_type ovl_fs_type = {
778 .owner = THIS_MODULE, 815 .owner = THIS_MODULE,
779 .name = "overlayfs", 816 .name = "overlay",
780 .mount = ovl_mount, 817 .mount = ovl_mount,
781 .kill_sb = kill_anon_super, 818 .kill_sb = kill_anon_super,
782}; 819};
783MODULE_ALIAS_FS("overlayfs"); 820MODULE_ALIAS_FS("overlay");
784 821
785static int __init ovl_init(void) 822static int __init ovl_init(void)
786{ 823{
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 92e8f99a5857..281002689d64 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -1338,7 +1338,10 @@ xfs_free_file_space(
1338 goto out; 1338 goto out;
1339} 1339}
1340 1340
1341 1341/*
1342 * Preallocate and zero a range of a file. This mechanism has the allocation
1343 * semantics of fallocate and in addition converts data in the range to zeroes.
1344 */
1342int 1345int
1343xfs_zero_file_space( 1346xfs_zero_file_space(
1344 struct xfs_inode *ip, 1347 struct xfs_inode *ip,
@@ -1346,65 +1349,30 @@ xfs_zero_file_space(
1346 xfs_off_t len) 1349 xfs_off_t len)
1347{ 1350{
1348 struct xfs_mount *mp = ip->i_mount; 1351 struct xfs_mount *mp = ip->i_mount;
1349 uint granularity; 1352 uint blksize;
1350 xfs_off_t start_boundary;
1351 xfs_off_t end_boundary;
1352 int error; 1353 int error;
1353 1354
1354 trace_xfs_zero_file_space(ip); 1355 trace_xfs_zero_file_space(ip);
1355 1356
1356 granularity = max_t(uint, 1 << mp->m_sb.sb_blocklog, PAGE_CACHE_SIZE); 1357 blksize = 1 << mp->m_sb.sb_blocklog;
1357 1358
1358 /* 1359 /*
1359 * Round the range of extents we are going to convert inwards. If the 1360 * Punch a hole and prealloc the range. We use hole punch rather than
1360 * offset is aligned, then it doesn't get changed so we zero from the 1361 * unwritten extent conversion for two reasons:
1361 * start of the block offset points to. 1362 *
1363 * 1.) Hole punch handles partial block zeroing for us.
1364 *
1365 * 2.) If prealloc returns ENOSPC, the file range is still zero-valued
1366 * by virtue of the hole punch.
1362 */ 1367 */
1363 start_boundary = round_up(offset, granularity); 1368 error = xfs_free_file_space(ip, offset, len);
1364 end_boundary = round_down(offset + len, granularity); 1369 if (error)
1365 1370 goto out;
1366 ASSERT(start_boundary >= offset);
1367 ASSERT(end_boundary <= offset + len);
1368
1369 if (start_boundary < end_boundary - 1) {
1370 /*
1371 * Writeback the range to ensure any inode size updates due to
1372 * appending writes make it to disk (otherwise we could just
1373 * punch out the delalloc blocks).
1374 */
1375 error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
1376 start_boundary, end_boundary - 1);
1377 if (error)
1378 goto out;
1379 truncate_pagecache_range(VFS_I(ip), start_boundary,
1380 end_boundary - 1);
1381
1382 /* convert the blocks */
1383 error = xfs_alloc_file_space(ip, start_boundary,
1384 end_boundary - start_boundary - 1,
1385 XFS_BMAPI_PREALLOC | XFS_BMAPI_CONVERT);
1386 if (error)
1387 goto out;
1388
1389 /* We've handled the interior of the range, now for the edges */
1390 if (start_boundary != offset) {
1391 error = xfs_iozero(ip, offset, start_boundary - offset);
1392 if (error)
1393 goto out;
1394 }
1395
1396 if (end_boundary != offset + len)
1397 error = xfs_iozero(ip, end_boundary,
1398 offset + len - end_boundary);
1399
1400 } else {
1401 /*
1402 * It's either a sub-granularity range or the range spanned lies
1403 * partially across two adjacent blocks.
1404 */
1405 error = xfs_iozero(ip, offset, len);
1406 }
1407 1371
1372 error = xfs_alloc_file_space(ip, round_down(offset, blksize),
1373 round_up(offset + len, blksize) -
1374 round_down(offset, blksize),
1375 XFS_BMAPI_PREALLOC);
1408out: 1376out:
1409 return error; 1377 return error;
1410 1378
diff --git a/fs/xfs/xfs_itable.c b/fs/xfs/xfs_itable.c
index f1deb961a296..894924a5129b 100644
--- a/fs/xfs/xfs_itable.c
+++ b/fs/xfs/xfs_itable.c
@@ -236,8 +236,10 @@ xfs_bulkstat_grab_ichunk(
236 XFS_WANT_CORRUPTED_RETURN(stat == 1); 236 XFS_WANT_CORRUPTED_RETURN(stat == 1);
237 237
238 /* Check if the record contains the inode in request */ 238 /* Check if the record contains the inode in request */
239 if (irec->ir_startino + XFS_INODES_PER_CHUNK <= agino) 239 if (irec->ir_startino + XFS_INODES_PER_CHUNK <= agino) {
240 return -EINVAL; 240 *icount = 0;
241 return 0;
242 }
241 243
242 idx = agino - irec->ir_startino + 1; 244 idx = agino - irec->ir_startino + 1;
243 if (idx < XFS_INODES_PER_CHUNK && 245 if (idx < XFS_INODES_PER_CHUNK &&
@@ -262,75 +264,76 @@ xfs_bulkstat_grab_ichunk(
262 264
263#define XFS_BULKSTAT_UBLEFT(ubleft) ((ubleft) >= statstruct_size) 265#define XFS_BULKSTAT_UBLEFT(ubleft) ((ubleft) >= statstruct_size)
264 266
267struct xfs_bulkstat_agichunk {
268 char __user **ac_ubuffer;/* pointer into user's buffer */
269 int ac_ubleft; /* bytes left in user's buffer */
270 int ac_ubelem; /* spaces used in user's buffer */
271};
272
265/* 273/*
266 * Process inodes in chunk with a pointer to a formatter function 274 * Process inodes in chunk with a pointer to a formatter function
267 * that will iget the inode and fill in the appropriate structure. 275 * that will iget the inode and fill in the appropriate structure.
268 */ 276 */
269int 277static int
270xfs_bulkstat_ag_ichunk( 278xfs_bulkstat_ag_ichunk(
271 struct xfs_mount *mp, 279 struct xfs_mount *mp,
272 xfs_agnumber_t agno, 280 xfs_agnumber_t agno,
273 struct xfs_inobt_rec_incore *irbp, 281 struct xfs_inobt_rec_incore *irbp,
274 bulkstat_one_pf formatter, 282 bulkstat_one_pf formatter,
275 size_t statstruct_size, 283 size_t statstruct_size,
276 struct xfs_bulkstat_agichunk *acp) 284 struct xfs_bulkstat_agichunk *acp,
285 xfs_agino_t *last_agino)
277{ 286{
278 xfs_ino_t lastino = acp->ac_lastino;
279 char __user **ubufp = acp->ac_ubuffer; 287 char __user **ubufp = acp->ac_ubuffer;
280 int ubleft = acp->ac_ubleft; 288 int chunkidx;
281 int ubelem = acp->ac_ubelem;
282 int chunkidx, clustidx;
283 int error = 0; 289 int error = 0;
284 xfs_agino_t agino; 290 xfs_agino_t agino = irbp->ir_startino;
285 291
286 for (agino = irbp->ir_startino, chunkidx = clustidx = 0; 292 for (chunkidx = 0; chunkidx < XFS_INODES_PER_CHUNK;
287 XFS_BULKSTAT_UBLEFT(ubleft) && 293 chunkidx++, agino++) {
288 irbp->ir_freecount < XFS_INODES_PER_CHUNK; 294 int fmterror;
289 chunkidx++, clustidx++, agino++) {
290 int fmterror; /* bulkstat formatter result */
291 int ubused; 295 int ubused;
292 xfs_ino_t ino = XFS_AGINO_TO_INO(mp, agno, agino);
293 296
294 ASSERT(chunkidx < XFS_INODES_PER_CHUNK); 297 /* inode won't fit in buffer, we are done */
298 if (acp->ac_ubleft < statstruct_size)
299 break;
295 300
296 /* Skip if this inode is free */ 301 /* Skip if this inode is free */
297 if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free) { 302 if (XFS_INOBT_MASK(chunkidx) & irbp->ir_free)
298 lastino = ino;
299 continue; 303 continue;
300 }
301
302 /*
303 * Count used inodes as free so we can tell when the
304 * chunk is used up.
305 */
306 irbp->ir_freecount++;
307 304
308 /* Get the inode and fill in a single buffer */ 305 /* Get the inode and fill in a single buffer */
309 ubused = statstruct_size; 306 ubused = statstruct_size;
310 error = formatter(mp, ino, *ubufp, ubleft, &ubused, &fmterror); 307 error = formatter(mp, XFS_AGINO_TO_INO(mp, agno, agino),
311 if (fmterror == BULKSTAT_RV_NOTHING) { 308 *ubufp, acp->ac_ubleft, &ubused, &fmterror);
312 if (error && error != -ENOENT && error != -EINVAL) { 309
313 ubleft = 0; 310 if (fmterror == BULKSTAT_RV_GIVEUP ||
314 break; 311 (error && error != -ENOENT && error != -EINVAL)) {
315 } 312 acp->ac_ubleft = 0;
316 lastino = ino;
317 continue;
318 }
319 if (fmterror == BULKSTAT_RV_GIVEUP) {
320 ubleft = 0;
321 ASSERT(error); 313 ASSERT(error);
322 break; 314 break;
323 } 315 }
324 if (*ubufp) 316
325 *ubufp += ubused; 317 /* be careful not to leak error if at end of chunk */
326 ubleft -= ubused; 318 if (fmterror == BULKSTAT_RV_NOTHING || error) {
327 ubelem++; 319 error = 0;
328 lastino = ino; 320 continue;
321 }
322
323 *ubufp += ubused;
324 acp->ac_ubleft -= ubused;
325 acp->ac_ubelem++;
329 } 326 }
330 327
331 acp->ac_lastino = lastino; 328 /*
332 acp->ac_ubleft = ubleft; 329 * Post-update *last_agino. At this point, agino will always point one
333 acp->ac_ubelem = ubelem; 330 * inode past the last inode we processed successfully. Hence we
331 * substract that inode when setting the *last_agino cursor so that we
332 * return the correct cookie to userspace. On the next bulkstat call,
333 * the inode under the lastino cookie will be skipped as we have already
334 * processed it here.
335 */
336 *last_agino = agino - 1;
334 337
335 return error; 338 return error;
336} 339}
@@ -353,45 +356,33 @@ xfs_bulkstat(
353 xfs_agino_t agino; /* inode # in allocation group */ 356 xfs_agino_t agino; /* inode # in allocation group */
354 xfs_agnumber_t agno; /* allocation group number */ 357 xfs_agnumber_t agno; /* allocation group number */
355 xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */ 358 xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */
356 int end_of_ag; /* set if we've seen the ag end */
357 int error; /* error code */
358 int fmterror;/* bulkstat formatter result */
359 int i; /* loop index */
360 int icount; /* count of inodes good in irbuf */
361 size_t irbsize; /* size of irec buffer in bytes */ 359 size_t irbsize; /* size of irec buffer in bytes */
362 xfs_ino_t ino; /* inode number (filesystem) */
363 xfs_inobt_rec_incore_t *irbp; /* current irec buffer pointer */
364 xfs_inobt_rec_incore_t *irbuf; /* start of irec buffer */ 360 xfs_inobt_rec_incore_t *irbuf; /* start of irec buffer */
365 xfs_inobt_rec_incore_t *irbufend; /* end of good irec buffer entries */
366 xfs_ino_t lastino; /* last inode number returned */
367 int nirbuf; /* size of irbuf */ 361 int nirbuf; /* size of irbuf */
368 int rval; /* return value error code */
369 int tmp; /* result value from btree calls */
370 int ubcount; /* size of user's buffer */ 362 int ubcount; /* size of user's buffer */
371 int ubleft; /* bytes left in user's buffer */ 363 struct xfs_bulkstat_agichunk ac;
372 char __user *ubufp; /* pointer into user's buffer */ 364 int error = 0;
373 int ubelem; /* spaces used in user's buffer */
374 365
375 /* 366 /*
376 * Get the last inode value, see if there's nothing to do. 367 * Get the last inode value, see if there's nothing to do.
377 */ 368 */
378 ino = (xfs_ino_t)*lastinop; 369 agno = XFS_INO_TO_AGNO(mp, *lastinop);
379 lastino = ino; 370 agino = XFS_INO_TO_AGINO(mp, *lastinop);
380 agno = XFS_INO_TO_AGNO(mp, ino);
381 agino = XFS_INO_TO_AGINO(mp, ino);
382 if (agno >= mp->m_sb.sb_agcount || 371 if (agno >= mp->m_sb.sb_agcount ||
383 ino != XFS_AGINO_TO_INO(mp, agno, agino)) { 372 *lastinop != XFS_AGINO_TO_INO(mp, agno, agino)) {
384 *done = 1; 373 *done = 1;
385 *ubcountp = 0; 374 *ubcountp = 0;
386 return 0; 375 return 0;
387 } 376 }
388 377
389 ubcount = *ubcountp; /* statstruct's */ 378 ubcount = *ubcountp; /* statstruct's */
390 ubleft = ubcount * statstruct_size; /* bytes */ 379 ac.ac_ubuffer = &ubuffer;
391 *ubcountp = ubelem = 0; 380 ac.ac_ubleft = ubcount * statstruct_size; /* bytes */;
381 ac.ac_ubelem = 0;
382
383 *ubcountp = 0;
392 *done = 0; 384 *done = 0;
393 fmterror = 0; 385
394 ubufp = ubuffer;
395 irbuf = kmem_zalloc_greedy(&irbsize, PAGE_SIZE, PAGE_SIZE * 4); 386 irbuf = kmem_zalloc_greedy(&irbsize, PAGE_SIZE, PAGE_SIZE * 4);
396 if (!irbuf) 387 if (!irbuf)
397 return -ENOMEM; 388 return -ENOMEM;
@@ -402,9 +393,13 @@ xfs_bulkstat(
402 * Loop over the allocation groups, starting from the last 393 * Loop over the allocation groups, starting from the last
403 * inode returned; 0 means start of the allocation group. 394 * inode returned; 0 means start of the allocation group.
404 */ 395 */
405 rval = 0; 396 while (agno < mp->m_sb.sb_agcount) {
406 while (XFS_BULKSTAT_UBLEFT(ubleft) && agno < mp->m_sb.sb_agcount) { 397 struct xfs_inobt_rec_incore *irbp = irbuf;
407 cond_resched(); 398 struct xfs_inobt_rec_incore *irbufend = irbuf + nirbuf;
399 bool end_of_ag = false;
400 int icount = 0;
401 int stat;
402
408 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp); 403 error = xfs_ialloc_read_agi(mp, NULL, agno, &agbp);
409 if (error) 404 if (error)
410 break; 405 break;
@@ -414,10 +409,6 @@ xfs_bulkstat(
414 */ 409 */
415 cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno, 410 cur = xfs_inobt_init_cursor(mp, NULL, agbp, agno,
416 XFS_BTNUM_INO); 411 XFS_BTNUM_INO);
417 irbp = irbuf;
418 irbufend = irbuf + nirbuf;
419 end_of_ag = 0;
420 icount = 0;
421 if (agino > 0) { 412 if (agino > 0) {
422 /* 413 /*
423 * In the middle of an allocation group, we need to get 414 * In the middle of an allocation group, we need to get
@@ -427,22 +418,23 @@ xfs_bulkstat(
427 418
428 error = xfs_bulkstat_grab_ichunk(cur, agino, &icount, &r); 419 error = xfs_bulkstat_grab_ichunk(cur, agino, &icount, &r);
429 if (error) 420 if (error)
430 break; 421 goto del_cursor;
431 if (icount) { 422 if (icount) {
432 irbp->ir_startino = r.ir_startino; 423 irbp->ir_startino = r.ir_startino;
433 irbp->ir_freecount = r.ir_freecount; 424 irbp->ir_freecount = r.ir_freecount;
434 irbp->ir_free = r.ir_free; 425 irbp->ir_free = r.ir_free;
435 irbp++; 426 irbp++;
436 agino = r.ir_startino + XFS_INODES_PER_CHUNK;
437 } 427 }
438 /* Increment to the next record */ 428 /* Increment to the next record */
439 error = xfs_btree_increment(cur, 0, &tmp); 429 error = xfs_btree_increment(cur, 0, &stat);
440 } else { 430 } else {
441 /* Start of ag. Lookup the first inode chunk */ 431 /* Start of ag. Lookup the first inode chunk */
442 error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &tmp); 432 error = xfs_inobt_lookup(cur, 0, XFS_LOOKUP_GE, &stat);
433 }
434 if (error || stat == 0) {
435 end_of_ag = true;
436 goto del_cursor;
443 } 437 }
444 if (error)
445 break;
446 438
447 /* 439 /*
448 * Loop through inode btree records in this ag, 440 * Loop through inode btree records in this ag,
@@ -451,10 +443,10 @@ xfs_bulkstat(
451 while (irbp < irbufend && icount < ubcount) { 443 while (irbp < irbufend && icount < ubcount) {
452 struct xfs_inobt_rec_incore r; 444 struct xfs_inobt_rec_incore r;
453 445
454 error = xfs_inobt_get_rec(cur, &r, &i); 446 error = xfs_inobt_get_rec(cur, &r, &stat);
455 if (error || i == 0) { 447 if (error || stat == 0) {
456 end_of_ag = 1; 448 end_of_ag = true;
457 break; 449 goto del_cursor;
458 } 450 }
459 451
460 /* 452 /*
@@ -469,77 +461,79 @@ xfs_bulkstat(
469 irbp++; 461 irbp++;
470 icount += XFS_INODES_PER_CHUNK - r.ir_freecount; 462 icount += XFS_INODES_PER_CHUNK - r.ir_freecount;
471 } 463 }
472 /* 464 error = xfs_btree_increment(cur, 0, &stat);
473 * Set agino to after this chunk and bump the cursor. 465 if (error || stat == 0) {
474 */ 466 end_of_ag = true;
475 agino = r.ir_startino + XFS_INODES_PER_CHUNK; 467 goto del_cursor;
476 error = xfs_btree_increment(cur, 0, &tmp); 468 }
477 cond_resched(); 469 cond_resched();
478 } 470 }
471
479 /* 472 /*
480 * Drop the btree buffers and the agi buffer. 473 * Drop the btree buffers and the agi buffer as we can't hold any
481 * We can't hold any of the locks these represent 474 * of the locks these represent when calling iget. If there is a
482 * when calling iget. 475 * pending error, then we are done.
483 */ 476 */
477del_cursor:
484 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); 478 xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR);
485 xfs_buf_relse(agbp); 479 xfs_buf_relse(agbp);
480 if (error)
481 break;
486 /* 482 /*
487 * Now format all the good inodes into the user's buffer. 483 * Now format all the good inodes into the user's buffer. The
484 * call to xfs_bulkstat_ag_ichunk() sets up the agino pointer
485 * for the next loop iteration.
488 */ 486 */
489 irbufend = irbp; 487 irbufend = irbp;
490 for (irbp = irbuf; 488 for (irbp = irbuf;
491 irbp < irbufend && XFS_BULKSTAT_UBLEFT(ubleft); irbp++) { 489 irbp < irbufend && ac.ac_ubleft >= statstruct_size;
492 struct xfs_bulkstat_agichunk ac; 490 irbp++) {
493
494 ac.ac_lastino = lastino;
495 ac.ac_ubuffer = &ubuffer;
496 ac.ac_ubleft = ubleft;
497 ac.ac_ubelem = ubelem;
498 error = xfs_bulkstat_ag_ichunk(mp, agno, irbp, 491 error = xfs_bulkstat_ag_ichunk(mp, agno, irbp,
499 formatter, statstruct_size, &ac); 492 formatter, statstruct_size, &ac,
493 &agino);
500 if (error) 494 if (error)
501 rval = error; 495 break;
502
503 lastino = ac.ac_lastino;
504 ubleft = ac.ac_ubleft;
505 ubelem = ac.ac_ubelem;
506 496
507 cond_resched(); 497 cond_resched();
508 } 498 }
499
509 /* 500 /*
510 * Set up for the next loop iteration. 501 * If we've run out of space or had a formatting error, we
502 * are now done
511 */ 503 */
512 if (XFS_BULKSTAT_UBLEFT(ubleft)) { 504 if (ac.ac_ubleft < statstruct_size || error)
513 if (end_of_ag) {
514 agno++;
515 agino = 0;
516 } else
517 agino = XFS_INO_TO_AGINO(mp, lastino);
518 } else
519 break; 505 break;
506
507 if (end_of_ag) {
508 agno++;
509 agino = 0;
510 }
520 } 511 }
521 /* 512 /*
522 * Done, we're either out of filesystem or space to put the data. 513 * Done, we're either out of filesystem or space to put the data.
523 */ 514 */
524 kmem_free(irbuf); 515 kmem_free(irbuf);
525 *ubcountp = ubelem; 516 *ubcountp = ac.ac_ubelem;
517
526 /* 518 /*
527 * Found some inodes, return them now and return the error next time. 519 * We found some inodes, so clear the error status and return them.
520 * The lastino pointer will point directly at the inode that triggered
521 * any error that occurred, so on the next call the error will be
522 * triggered again and propagated to userspace as there will be no
523 * formatted inodes in the buffer.
528 */ 524 */
529 if (ubelem) 525 if (ac.ac_ubelem)
530 rval = 0; 526 error = 0;
531 if (agno >= mp->m_sb.sb_agcount) { 527
532 /* 528 /*
533 * If we ran out of filesystem, mark lastino as off 529 * If we ran out of filesystem, lastino will point off the end of
534 * the end of the filesystem, so the next call 530 * the filesystem so the next call will return immediately.
535 * will return immediately. 531 */
536 */ 532 *lastinop = XFS_AGINO_TO_INO(mp, agno, agino);
537 *lastinop = (xfs_ino_t)XFS_AGINO_TO_INO(mp, agno, 0); 533 if (agno >= mp->m_sb.sb_agcount)
538 *done = 1; 534 *done = 1;
539 } else
540 *lastinop = (xfs_ino_t)lastino;
541 535
542 return rval; 536 return error;
543} 537}
544 538
545int 539int
diff --git a/fs/xfs/xfs_itable.h b/fs/xfs/xfs_itable.h
index aaed08022eb9..6ea8b3912fa4 100644
--- a/fs/xfs/xfs_itable.h
+++ b/fs/xfs/xfs_itable.h
@@ -30,22 +30,6 @@ typedef int (*bulkstat_one_pf)(struct xfs_mount *mp,
30 int *ubused, 30 int *ubused,
31 int *stat); 31 int *stat);
32 32
33struct xfs_bulkstat_agichunk {
34 xfs_ino_t ac_lastino; /* last inode returned */
35 char __user **ac_ubuffer;/* pointer into user's buffer */
36 int ac_ubleft; /* bytes left in user's buffer */
37 int ac_ubelem; /* spaces used in user's buffer */
38};
39
40int
41xfs_bulkstat_ag_ichunk(
42 struct xfs_mount *mp,
43 xfs_agnumber_t agno,
44 struct xfs_inobt_rec_incore *irbp,
45 bulkstat_one_pf formatter,
46 size_t statstruct_size,
47 struct xfs_bulkstat_agichunk *acp);
48
49/* 33/*
50 * Values for stat return value. 34 * Values for stat return value.
51 */ 35 */
diff --git a/include/asm-generic/futex.h b/include/asm-generic/futex.h
index 01f227e14254..b59b5a52637e 100644
--- a/include/asm-generic/futex.h
+++ b/include/asm-generic/futex.h
@@ -5,6 +5,119 @@
5#include <linux/uaccess.h> 5#include <linux/uaccess.h>
6#include <asm/errno.h> 6#include <asm/errno.h>
7 7
8#ifndef CONFIG_SMP
9/*
10 * The following implementation only for uniprocessor machines.
11 * For UP, it's relies on the fact that pagefault_disable() also disables
12 * preemption to ensure mutual exclusion.
13 *
14 */
15
16/**
17 * futex_atomic_op_inuser() - Atomic arithmetic operation with constant
18 * argument and comparison of the previous
19 * futex value with another constant.
20 *
21 * @encoded_op: encoded operation to execute
22 * @uaddr: pointer to user space address
23 *
24 * Return:
25 * 0 - On success
26 * <0 - On error
27 */
28static inline int
29futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
30{
31 int op = (encoded_op >> 28) & 7;
32 int cmp = (encoded_op >> 24) & 15;
33 int oparg = (encoded_op << 8) >> 20;
34 int cmparg = (encoded_op << 20) >> 20;
35 int oldval, ret;
36 u32 tmp;
37
38 if (encoded_op & (FUTEX_OP_OPARG_SHIFT << 28))
39 oparg = 1 << oparg;
40
41 pagefault_disable();
42
43 ret = -EFAULT;
44 if (unlikely(get_user(oldval, uaddr) != 0))
45 goto out_pagefault_enable;
46
47 ret = 0;
48 tmp = oldval;
49
50 switch (op) {
51 case FUTEX_OP_SET:
52 tmp = oparg;
53 break;
54 case FUTEX_OP_ADD:
55 tmp += oparg;
56 break;
57 case FUTEX_OP_OR:
58 tmp |= oparg;
59 break;
60 case FUTEX_OP_ANDN:
61 tmp &= ~oparg;
62 break;
63 case FUTEX_OP_XOR:
64 tmp ^= oparg;
65 break;
66 default:
67 ret = -ENOSYS;
68 }
69
70 if (ret == 0 && unlikely(put_user(tmp, uaddr) != 0))
71 ret = -EFAULT;
72
73out_pagefault_enable:
74 pagefault_enable();
75
76 if (ret == 0) {
77 switch (cmp) {
78 case FUTEX_OP_CMP_EQ: ret = (oldval == cmparg); break;
79 case FUTEX_OP_CMP_NE: ret = (oldval != cmparg); break;
80 case FUTEX_OP_CMP_LT: ret = (oldval < cmparg); break;
81 case FUTEX_OP_CMP_GE: ret = (oldval >= cmparg); break;
82 case FUTEX_OP_CMP_LE: ret = (oldval <= cmparg); break;
83 case FUTEX_OP_CMP_GT: ret = (oldval > cmparg); break;
84 default: ret = -ENOSYS;
85 }
86 }
87 return ret;
88}
89
90/**
91 * futex_atomic_cmpxchg_inatomic() - Compare and exchange the content of the
92 * uaddr with newval if the current value is
93 * oldval.
94 * @uval: pointer to store content of @uaddr
95 * @uaddr: pointer to user space address
96 * @oldval: old value
97 * @newval: new value to store to @uaddr
98 *
99 * Return:
100 * 0 - On success
101 * <0 - On error
102 */
103static inline int
104futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
105 u32 oldval, u32 newval)
106{
107 u32 val;
108
109 if (unlikely(get_user(val, uaddr) != 0))
110 return -EFAULT;
111
112 if (val == oldval && unlikely(put_user(newval, uaddr) != 0))
113 return -EFAULT;
114
115 *uval = val;
116
117 return 0;
118}
119
120#else
8static inline int 121static inline int
9futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr) 122futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
10{ 123{
@@ -54,4 +167,5 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
54 return -ENOSYS; 167 return -ENOSYS;
55} 168}
56 169
170#endif /* CONFIG_SMP */
57#endif 171#endif
diff --git a/include/asm-generic/seccomp.h b/include/asm-generic/seccomp.h
new file mode 100644
index 000000000000..9fa1f653ed3b
--- /dev/null
+++ b/include/asm-generic/seccomp.h
@@ -0,0 +1,30 @@
1/*
2 * include/asm-generic/seccomp.h
3 *
4 * Copyright (C) 2014 Linaro Limited
5 * Author: AKASHI Takahiro <takahiro.akashi@linaro.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#ifndef _ASM_GENERIC_SECCOMP_H
12#define _ASM_GENERIC_SECCOMP_H
13
14#include <linux/unistd.h>
15
16#if defined(CONFIG_COMPAT) && !defined(__NR_seccomp_read_32)
17#define __NR_seccomp_read_32 __NR_read
18#define __NR_seccomp_write_32 __NR_write
19#define __NR_seccomp_exit_32 __NR_exit
20#define __NR_seccomp_sigreturn_32 __NR_rt_sigreturn
21#endif /* CONFIG_COMPAT && ! already defined */
22
23#define __NR_seccomp_read __NR_read
24#define __NR_seccomp_write __NR_write
25#define __NR_seccomp_exit __NR_exit
26#ifndef __NR_seccomp_sigreturn
27#define __NR_seccomp_sigreturn __NR_rt_sigreturn
28#endif
29
30#endif /* _ASM_GENERIC_SECCOMP_H */
diff --git a/include/asm-generic/tlb.h b/include/asm-generic/tlb.h
index 5672d7ea1fa0..08848050922e 100644
--- a/include/asm-generic/tlb.h
+++ b/include/asm-generic/tlb.h
@@ -96,10 +96,9 @@ struct mmu_gather {
96#endif 96#endif
97 unsigned long start; 97 unsigned long start;
98 unsigned long end; 98 unsigned long end;
99 unsigned int need_flush : 1, /* Did free PTEs */
100 /* we are in the middle of an operation to clear 99 /* we are in the middle of an operation to clear
101 * a full mm and can make some optimizations */ 100 * a full mm and can make some optimizations */
102 fullmm : 1, 101 unsigned int fullmm : 1,
103 /* we have performed an operation which 102 /* we have performed an operation which
104 * requires a complete flush of the tlb */ 103 * requires a complete flush of the tlb */
105 need_flush_all : 1; 104 need_flush_all : 1;
@@ -128,16 +127,54 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
128 tlb_flush_mmu(tlb); 127 tlb_flush_mmu(tlb);
129} 128}
130 129
130static inline void __tlb_adjust_range(struct mmu_gather *tlb,
131 unsigned long address)
132{
133 tlb->start = min(tlb->start, address);
134 tlb->end = max(tlb->end, address + PAGE_SIZE);
135}
136
137static inline void __tlb_reset_range(struct mmu_gather *tlb)
138{
139 tlb->start = TASK_SIZE;
140 tlb->end = 0;
141}
142
143/*
144 * In the case of tlb vma handling, we can optimise these away in the
145 * case where we're doing a full MM flush. When we're doing a munmap,
146 * the vmas are adjusted to only cover the region to be torn down.
147 */
148#ifndef tlb_start_vma
149#define tlb_start_vma(tlb, vma) do { } while (0)
150#endif
151
152#define __tlb_end_vma(tlb, vma) \
153 do { \
154 if (!tlb->fullmm && tlb->end) { \
155 tlb_flush(tlb); \
156 __tlb_reset_range(tlb); \
157 } \
158 } while (0)
159
160#ifndef tlb_end_vma
161#define tlb_end_vma __tlb_end_vma
162#endif
163
164#ifndef __tlb_remove_tlb_entry
165#define __tlb_remove_tlb_entry(tlb, ptep, address) do { } while (0)
166#endif
167
131/** 168/**
132 * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation. 169 * tlb_remove_tlb_entry - remember a pte unmapping for later tlb invalidation.
133 * 170 *
134 * Record the fact that pte's were really umapped in ->need_flush, so we can 171 * Record the fact that pte's were really unmapped by updating the range,
135 * later optimise away the tlb invalidate. This helps when userspace is 172 * so we can later optimise away the tlb invalidate. This helps when
136 * unmapping already-unmapped pages, which happens quite a lot. 173 * userspace is unmapping already-unmapped pages, which happens quite a lot.
137 */ 174 */
138#define tlb_remove_tlb_entry(tlb, ptep, address) \ 175#define tlb_remove_tlb_entry(tlb, ptep, address) \
139 do { \ 176 do { \
140 tlb->need_flush = 1; \ 177 __tlb_adjust_range(tlb, address); \
141 __tlb_remove_tlb_entry(tlb, ptep, address); \ 178 __tlb_remove_tlb_entry(tlb, ptep, address); \
142 } while (0) 179 } while (0)
143 180
@@ -151,27 +188,27 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
151 188
152#define tlb_remove_pmd_tlb_entry(tlb, pmdp, address) \ 189#define tlb_remove_pmd_tlb_entry(tlb, pmdp, address) \
153 do { \ 190 do { \
154 tlb->need_flush = 1; \ 191 __tlb_adjust_range(tlb, address); \
155 __tlb_remove_pmd_tlb_entry(tlb, pmdp, address); \ 192 __tlb_remove_pmd_tlb_entry(tlb, pmdp, address); \
156 } while (0) 193 } while (0)
157 194
158#define pte_free_tlb(tlb, ptep, address) \ 195#define pte_free_tlb(tlb, ptep, address) \
159 do { \ 196 do { \
160 tlb->need_flush = 1; \ 197 __tlb_adjust_range(tlb, address); \
161 __pte_free_tlb(tlb, ptep, address); \ 198 __pte_free_tlb(tlb, ptep, address); \
162 } while (0) 199 } while (0)
163 200
164#ifndef __ARCH_HAS_4LEVEL_HACK 201#ifndef __ARCH_HAS_4LEVEL_HACK
165#define pud_free_tlb(tlb, pudp, address) \ 202#define pud_free_tlb(tlb, pudp, address) \
166 do { \ 203 do { \
167 tlb->need_flush = 1; \ 204 __tlb_adjust_range(tlb, address); \
168 __pud_free_tlb(tlb, pudp, address); \ 205 __pud_free_tlb(tlb, pudp, address); \
169 } while (0) 206 } while (0)
170#endif 207#endif
171 208
172#define pmd_free_tlb(tlb, pmdp, address) \ 209#define pmd_free_tlb(tlb, pmdp, address) \
173 do { \ 210 do { \
174 tlb->need_flush = 1; \ 211 __tlb_adjust_range(tlb, address); \
175 __pmd_free_tlb(tlb, pmdp, address); \ 212 __pmd_free_tlb(tlb, pmdp, address); \
176 } while (0) 213 } while (0)
177 214
diff --git a/include/dt-bindings/clock/qcom,mmcc-apq8084.h b/include/dt-bindings/clock/qcom,mmcc-apq8084.h
index a929f86d0ddd..d72b5b35f15e 100644
--- a/include/dt-bindings/clock/qcom,mmcc-apq8084.h
+++ b/include/dt-bindings/clock/qcom,mmcc-apq8084.h
@@ -60,7 +60,7 @@
60#define ESC1_CLK_SRC 43 60#define ESC1_CLK_SRC 43
61#define HDMI_CLK_SRC 44 61#define HDMI_CLK_SRC 44
62#define VSYNC_CLK_SRC 45 62#define VSYNC_CLK_SRC 45
63#define RBCPR_CLK_SRC 46 63#define MMSS_RBCPR_CLK_SRC 46
64#define RBBMTIMER_CLK_SRC 47 64#define RBBMTIMER_CLK_SRC 47
65#define MAPLE_CLK_SRC 48 65#define MAPLE_CLK_SRC 48
66#define VDP_CLK_SRC 49 66#define VDP_CLK_SRC 49
diff --git a/include/dt-bindings/pinctrl/dra.h b/include/dt-bindings/pinctrl/dra.h
index 3d33794e4f3e..7448edff4723 100644
--- a/include/dt-bindings/pinctrl/dra.h
+++ b/include/dt-bindings/pinctrl/dra.h
@@ -40,8 +40,8 @@
40 40
41/* Active pin states */ 41/* Active pin states */
42#define PIN_OUTPUT (0 | PULL_DIS) 42#define PIN_OUTPUT (0 | PULL_DIS)
43#define PIN_OUTPUT_PULLUP (PIN_OUTPUT | PULL_ENA | PULL_UP) 43#define PIN_OUTPUT_PULLUP (PULL_UP)
44#define PIN_OUTPUT_PULLDOWN (PIN_OUTPUT | PULL_ENA) 44#define PIN_OUTPUT_PULLDOWN (0)
45#define PIN_INPUT (INPUT_EN | PULL_DIS) 45#define PIN_INPUT (INPUT_EN | PULL_DIS)
46#define PIN_INPUT_SLEW (INPUT_EN | SLEWCONTROL) 46#define PIN_INPUT_SLEW (INPUT_EN | SLEWCONTROL)
47#define PIN_INPUT_PULLUP (PULL_ENA | INPUT_EN | PULL_UP) 47#define PIN_INPUT_PULLUP (PULL_ENA | INPUT_EN | PULL_UP)
diff --git a/include/dt-bindings/regulator/maxim,max77802.h b/include/dt-bindings/regulator/maxim,max77802.h
new file mode 100644
index 000000000000..cf28631d7109
--- /dev/null
+++ b/include/dt-bindings/regulator/maxim,max77802.h
@@ -0,0 +1,18 @@
1/*
2 * Copyright (C) 2014 Google, Inc
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * Device Tree binding constants for the Maxim 77802 PMIC regulators
9 */
10
11#ifndef _DT_BINDINGS_REGULATOR_MAXIM_MAX77802_H
12#define _DT_BINDINGS_REGULATOR_MAXIM_MAX77802_H
13
14/* Regulator operating modes */
15#define MAX77802_OPMODE_LP 1
16#define MAX77802_OPMODE_NORMAL 3
17
18#endif /* _DT_BINDINGS_REGULATOR_MAXIM_MAX77802_H */
diff --git a/include/linux/atmel-mci.h b/include/linux/atmel-mci.h
index 91b77f8d495d..9177947bf032 100644
--- a/include/linux/atmel-mci.h
+++ b/include/linux/atmel-mci.h
@@ -11,6 +11,7 @@
11 * @detect_pin: GPIO pin wired to the card detect switch 11 * @detect_pin: GPIO pin wired to the card detect switch
12 * @wp_pin: GPIO pin wired to the write protect sensor 12 * @wp_pin: GPIO pin wired to the write protect sensor
13 * @detect_is_active_high: The state of the detect pin when it is active 13 * @detect_is_active_high: The state of the detect pin when it is active
14 * @non_removable: The slot is not removable, only detect once
14 * 15 *
15 * If a given slot is not present on the board, @bus_width should be 16 * If a given slot is not present on the board, @bus_width should be
16 * set to 0. The other fields are ignored in this case. 17 * set to 0. The other fields are ignored in this case.
@@ -26,6 +27,7 @@ struct mci_slot_pdata {
26 int detect_pin; 27 int detect_pin;
27 int wp_pin; 28 int wp_pin;
28 bool detect_is_active_high; 29 bool detect_is_active_high;
30 bool non_removable;
29}; 31};
30 32
31/** 33/**
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index be5fd38bd5a0..5d858e02997f 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -18,8 +18,11 @@
18 * position @h. For example 18 * position @h. For example
19 * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. 19 * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
20 */ 20 */
21#define GENMASK(h, l) (((U32_C(1) << ((h) - (l) + 1)) - 1) << (l)) 21#define GENMASK(h, l) \
22#define GENMASK_ULL(h, l) (((U64_C(1) << ((h) - (l) + 1)) - 1) << (l)) 22 (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
23
24#define GENMASK_ULL(h, l) \
25 (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
23 26
24extern unsigned int __sw_hweight8(unsigned int w); 27extern unsigned int __sw_hweight8(unsigned int w);
25extern unsigned int __sw_hweight16(unsigned int w); 28extern unsigned int __sw_hweight16(unsigned int w);
diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
index c9be1589415a..15f7034aa377 100644
--- a/include/linux/blk-mq.h
+++ b/include/linux/blk-mq.h
@@ -167,6 +167,23 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw,
167 gfp_t gfp, bool reserved); 167 gfp_t gfp, bool reserved);
168struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag); 168struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag);
169 169
170enum {
171 BLK_MQ_UNIQUE_TAG_BITS = 16,
172 BLK_MQ_UNIQUE_TAG_MASK = (1 << BLK_MQ_UNIQUE_TAG_BITS) - 1,
173};
174
175u32 blk_mq_unique_tag(struct request *rq);
176
177static inline u16 blk_mq_unique_tag_to_hwq(u32 unique_tag)
178{
179 return unique_tag >> BLK_MQ_UNIQUE_TAG_BITS;
180}
181
182static inline u16 blk_mq_unique_tag_to_tag(u32 unique_tag)
183{
184 return unique_tag & BLK_MQ_UNIQUE_TAG_MASK;
185}
186
170struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index); 187struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *, const int ctx_index);
171struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int); 188struct blk_mq_hw_ctx *blk_mq_alloc_single_hw_queue(struct blk_mq_tag_set *, unsigned int, int);
172 189
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index aac0f9ea952a..6d76b8b4aa2b 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1136,7 +1136,6 @@ static inline bool blk_needs_flush_plug(struct task_struct *tsk)
1136/* 1136/*
1137 * tag stuff 1137 * tag stuff
1138 */ 1138 */
1139#define blk_rq_tagged(rq) ((rq)->cmd_flags & REQ_QUEUED)
1140extern int blk_queue_start_tag(struct request_queue *, struct request *); 1139extern int blk_queue_start_tag(struct request_queue *, struct request *);
1141extern struct request *blk_queue_find_tag(struct request_queue *, int); 1140extern struct request *blk_queue_find_tag(struct request_queue *, int);
1142extern void blk_queue_end_tag(struct request_queue *, struct request *); 1141extern void blk_queue_end_tag(struct request_queue *, struct request *);
diff --git a/include/linux/bootmem.h b/include/linux/bootmem.h
index 4e2bd4c95b66..0995c2de8162 100644
--- a/include/linux/bootmem.h
+++ b/include/linux/bootmem.h
@@ -46,6 +46,7 @@ extern unsigned long init_bootmem_node(pg_data_t *pgdat,
46extern unsigned long init_bootmem(unsigned long addr, unsigned long memend); 46extern unsigned long init_bootmem(unsigned long addr, unsigned long memend);
47 47
48extern unsigned long free_all_bootmem(void); 48extern unsigned long free_all_bootmem(void);
49extern void reset_node_managed_pages(pg_data_t *pgdat);
49extern void reset_all_zones_managed_pages(void); 50extern void reset_all_zones_managed_pages(void);
50 51
51extern void free_bootmem_node(pg_data_t *pgdat, 52extern void free_bootmem_node(pg_data_t *pgdat,
diff --git a/include/linux/can/dev.h b/include/linux/can/dev.h
index 6992afc6ba7f..b37ea95bc348 100644
--- a/include/linux/can/dev.h
+++ b/include/linux/can/dev.h
@@ -99,6 +99,12 @@ inval_skb:
99 return 1; 99 return 1;
100} 100}
101 101
102static inline bool can_is_canfd_skb(const struct sk_buff *skb)
103{
104 /* the CAN specific type of skb is identified by its data length */
105 return skb->len == CANFD_MTU;
106}
107
102/* get data length from can_dlc with sanitized can_dlc */ 108/* get data length from can_dlc with sanitized can_dlc */
103u8 can_dlc2len(u8 can_dlc); 109u8 can_dlc2len(u8 can_dlc);
104 110
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index be21af149f11..2839c639f092 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -352,7 +352,6 @@ struct clk_divider {
352#define CLK_DIVIDER_READ_ONLY BIT(5) 352#define CLK_DIVIDER_READ_ONLY BIT(5)
353 353
354extern const struct clk_ops clk_divider_ops; 354extern const struct clk_ops clk_divider_ops;
355extern const struct clk_ops clk_divider_ro_ops;
356struct clk *clk_register_divider(struct device *dev, const char *name, 355struct clk *clk_register_divider(struct device *dev, const char *name,
357 const char *parent_name, unsigned long flags, 356 const char *parent_name, unsigned long flags,
358 void __iomem *reg, u8 shift, u8 width, 357 void __iomem *reg, u8 shift, u8 width,
diff --git a/include/linux/cma.h b/include/linux/cma.h
index 0430ed05d3b9..a93438beb33c 100644
--- a/include/linux/cma.h
+++ b/include/linux/cma.h
@@ -18,12 +18,12 @@ struct cma;
18extern phys_addr_t cma_get_base(struct cma *cma); 18extern phys_addr_t cma_get_base(struct cma *cma);
19extern unsigned long cma_get_size(struct cma *cma); 19extern unsigned long cma_get_size(struct cma *cma);
20 20
21extern int __init cma_declare_contiguous(phys_addr_t size, 21extern int __init cma_declare_contiguous(phys_addr_t base,
22 phys_addr_t base, phys_addr_t limit, 22 phys_addr_t size, phys_addr_t limit,
23 phys_addr_t alignment, unsigned int order_per_bit, 23 phys_addr_t alignment, unsigned int order_per_bit,
24 bool fixed, struct cma **res_cma); 24 bool fixed, struct cma **res_cma);
25extern int cma_init_reserved_mem(phys_addr_t size, 25extern int cma_init_reserved_mem(phys_addr_t base,
26 phys_addr_t base, int order_per_bit, 26 phys_addr_t size, int order_per_bit,
27 struct cma **res_cma); 27 struct cma **res_cma);
28extern struct page *cma_alloc(struct cma *cma, int count, unsigned int align); 28extern struct page *cma_alloc(struct cma *cma, int count, unsigned int align);
29extern bool cma_release(struct cma *cma, struct page *pages, int count); 29extern bool cma_release(struct cma *cma, struct page *pages, int count);
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index e1707de043ae..ca6d2acc5eb7 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -64,6 +64,7 @@ typedef int (*dm_request_endio_fn) (struct dm_target *ti,
64 union map_info *map_context); 64 union map_info *map_context);
65 65
66typedef void (*dm_presuspend_fn) (struct dm_target *ti); 66typedef void (*dm_presuspend_fn) (struct dm_target *ti);
67typedef void (*dm_presuspend_undo_fn) (struct dm_target *ti);
67typedef void (*dm_postsuspend_fn) (struct dm_target *ti); 68typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
68typedef int (*dm_preresume_fn) (struct dm_target *ti); 69typedef int (*dm_preresume_fn) (struct dm_target *ti);
69typedef void (*dm_resume_fn) (struct dm_target *ti); 70typedef void (*dm_resume_fn) (struct dm_target *ti);
@@ -145,6 +146,7 @@ struct target_type {
145 dm_endio_fn end_io; 146 dm_endio_fn end_io;
146 dm_request_endio_fn rq_end_io; 147 dm_request_endio_fn rq_end_io;
147 dm_presuspend_fn presuspend; 148 dm_presuspend_fn presuspend;
149 dm_presuspend_undo_fn presuspend_undo;
148 dm_postsuspend_fn postsuspend; 150 dm_postsuspend_fn postsuspend;
149 dm_preresume_fn preresume; 151 dm_preresume_fn preresume;
150 dm_resume_fn resume; 152 dm_resume_fn resume;
diff --git a/include/linux/edac.h b/include/linux/edac.h
index e1e68da6f35c..da3b72e95db3 100644
--- a/include/linux/edac.h
+++ b/include/linux/edac.h
@@ -194,7 +194,8 @@ static inline char *mc_event_error_type(const unsigned int err_type)
194 * @MEM_DDR3: DDR3 RAM 194 * @MEM_DDR3: DDR3 RAM
195 * @MEM_RDDR3: Registered DDR3 RAM 195 * @MEM_RDDR3: Registered DDR3 RAM
196 * This is a variant of the DDR3 memories. 196 * This is a variant of the DDR3 memories.
197 * @MEM_DDR4: DDR4 RAM 197 * @MEM_LRDDR3 Load-Reduced DDR3 memory.
198 * @MEM_DDR4: Unbuffered DDR4 RAM
198 * @MEM_RDDR4: Registered DDR4 RAM 199 * @MEM_RDDR4: Registered DDR4 RAM
199 * This is a variant of the DDR4 memories. 200 * This is a variant of the DDR4 memories.
200 */ 201 */
@@ -216,6 +217,7 @@ enum mem_type {
216 MEM_XDR, 217 MEM_XDR,
217 MEM_DDR3, 218 MEM_DDR3,
218 MEM_RDDR3, 219 MEM_RDDR3,
220 MEM_LRDDR3,
219 MEM_DDR4, 221 MEM_DDR4,
220 MEM_RDDR4, 222 MEM_RDDR4,
221}; 223};
diff --git a/include/linux/eeprom_93cx6.h b/include/linux/eeprom_93cx6.h
index e50f98b0297a..eb0b1988050a 100644
--- a/include/linux/eeprom_93cx6.h
+++ b/include/linux/eeprom_93cx6.h
@@ -75,6 +75,10 @@ extern void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom,
75 const u8 word, u16 *data); 75 const u8 word, u16 *data);
76extern void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, 76extern void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom,
77 const u8 word, __le16 *data, const u16 words); 77 const u8 word, __le16 *data, const u16 words);
78extern void eeprom_93cx6_readb(struct eeprom_93cx6 *eeprom,
79 const u8 byte, u8 *data);
80extern void eeprom_93cx6_multireadb(struct eeprom_93cx6 *eeprom,
81 const u8 byte, u8 *data, const u16 bytes);
78 82
79extern void eeprom_93cx6_wren(struct eeprom_93cx6 *eeprom, bool enable); 83extern void eeprom_93cx6_wren(struct eeprom_93cx6 *eeprom, bool enable);
80 84
diff --git a/include/linux/efi.h b/include/linux/efi.h
index 0949f9c7e872..0238d612750e 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -547,6 +547,9 @@ void efi_native_runtime_setup(void);
547#define SMBIOS_TABLE_GUID \ 547#define SMBIOS_TABLE_GUID \
548 EFI_GUID( 0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d ) 548 EFI_GUID( 0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
549 549
550#define SMBIOS3_TABLE_GUID \
551 EFI_GUID( 0xf2fd1544, 0x9794, 0x4a2c, 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 )
552
550#define SAL_SYSTEM_TABLE_GUID \ 553#define SAL_SYSTEM_TABLE_GUID \
551 EFI_GUID( 0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d ) 554 EFI_GUID( 0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d )
552 555
@@ -810,7 +813,8 @@ extern struct efi {
810 unsigned long mps; /* MPS table */ 813 unsigned long mps; /* MPS table */
811 unsigned long acpi; /* ACPI table (IA64 ext 0.71) */ 814 unsigned long acpi; /* ACPI table (IA64 ext 0.71) */
812 unsigned long acpi20; /* ACPI table (ACPI 2.0) */ 815 unsigned long acpi20; /* ACPI table (ACPI 2.0) */
813 unsigned long smbios; /* SM BIOS table */ 816 unsigned long smbios; /* SMBIOS table (32 bit entry point) */
817 unsigned long smbios3; /* SMBIOS table (64 bit entry point) */
814 unsigned long sal_systab; /* SAL system table */ 818 unsigned long sal_systab; /* SAL system table */
815 unsigned long boot_info; /* boot info table */ 819 unsigned long boot_info; /* boot info table */
816 unsigned long hcdp; /* HCDP table */ 820 unsigned long hcdp; /* HCDP table */
diff --git a/include/linux/i2c/pmbus.h b/include/linux/i2c/pmbus.h
index 69280db02c41..ee3c2aba2a8e 100644
--- a/include/linux/i2c/pmbus.h
+++ b/include/linux/i2c/pmbus.h
@@ -40,6 +40,10 @@
40 40
41struct pmbus_platform_data { 41struct pmbus_platform_data {
42 u32 flags; /* Device specific flags */ 42 u32 flags; /* Device specific flags */
43
44 /* regulator support */
45 int num_regulators;
46 struct regulator_init_data *reg_init_data;
43}; 47};
44 48
45#endif /* _PMBUS_H_ */ 49#endif /* _PMBUS_H_ */
diff --git a/include/linux/iio/events.h b/include/linux/iio/events.h
index 8bbd7bc1043d..03fa332ad2a8 100644
--- a/include/linux/iio/events.h
+++ b/include/linux/iio/events.h
@@ -72,7 +72,7 @@ struct iio_event_data {
72 72
73#define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF) 73#define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
74 74
75#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xCF) 75#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0x7F)
76 76
77#define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF) 77#define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
78 78
diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h
index 0068708161ff..0a21fbefdfbe 100644
--- a/include/linux/inetdevice.h
+++ b/include/linux/inetdevice.h
@@ -242,7 +242,7 @@ static inline void in_dev_put(struct in_device *idev)
242static __inline__ __be32 inet_make_mask(int logmask) 242static __inline__ __be32 inet_make_mask(int logmask)
243{ 243{
244 if (logmask) 244 if (logmask)
245 return htonl(~((1<<(32-logmask))-1)); 245 return htonl(~((1U<<(32-logmask))-1));
246 return 0; 246 return 0;
247} 247}
248 248
diff --git a/include/linux/kernel_stat.h b/include/linux/kernel_stat.h
index 8422b4ed6882..b9376cd5a187 100644
--- a/include/linux/kernel_stat.h
+++ b/include/linux/kernel_stat.h
@@ -77,11 +77,6 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
77 return kstat_cpu(cpu).irqs_sum; 77 return kstat_cpu(cpu).irqs_sum;
78} 78}
79 79
80/*
81 * Lock/unlock the current runqueue - to extract task statistics:
82 */
83extern unsigned long long task_delta_exec(struct task_struct *);
84
85extern void account_user_time(struct task_struct *, cputime_t, cputime_t); 80extern void account_user_time(struct task_struct *, cputime_t, cputime_t);
86extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t); 81extern void account_system_time(struct task_struct *, int, cputime_t, cputime_t);
87extern void account_steal_time(cputime_t); 82extern void account_steal_time(cputime_t);
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index ea53b04993f2..a6059bdf7b03 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -703,7 +703,7 @@ void kvm_arch_sync_events(struct kvm *kvm);
703int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu); 703int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu);
704void kvm_vcpu_kick(struct kvm_vcpu *vcpu); 704void kvm_vcpu_kick(struct kvm_vcpu *vcpu);
705 705
706bool kvm_is_mmio_pfn(pfn_t pfn); 706bool kvm_is_reserved_pfn(pfn_t pfn);
707 707
708struct kvm_irq_ack_notifier { 708struct kvm_irq_ack_notifier {
709 struct hlist_node link; 709 struct hlist_node link;
diff --git a/include/linux/libata.h b/include/linux/libata.h
index bd5fefeaf548..bfbc817c34ee 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -1191,9 +1191,9 @@ extern void ata_scsi_unlock_native_capacity(struct scsi_device *sdev);
1191extern int ata_scsi_slave_config(struct scsi_device *sdev); 1191extern int ata_scsi_slave_config(struct scsi_device *sdev);
1192extern void ata_scsi_slave_destroy(struct scsi_device *sdev); 1192extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
1193extern int ata_scsi_change_queue_depth(struct scsi_device *sdev, 1193extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
1194 int queue_depth, int reason); 1194 int queue_depth);
1195extern int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev, 1195extern int __ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1196 int queue_depth, int reason); 1196 int queue_depth);
1197extern struct ata_device *ata_dev_pair(struct ata_device *adev); 1197extern struct ata_device *ata_dev_pair(struct ata_device *adev);
1198extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev); 1198extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
1199extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap); 1199extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);
diff --git a/include/linux/mfd/abx500/ab8500-sysctrl.h b/include/linux/mfd/abx500/ab8500-sysctrl.h
index adba89d9c660..689312745b2f 100644
--- a/include/linux/mfd/abx500/ab8500-sysctrl.h
+++ b/include/linux/mfd/abx500/ab8500-sysctrl.h
@@ -12,7 +12,6 @@
12 12
13int ab8500_sysctrl_read(u16 reg, u8 *value); 13int ab8500_sysctrl_read(u16 reg, u8 *value);
14int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value); 14int ab8500_sysctrl_write(u16 reg, u8 mask, u8 value);
15void ab8500_restart(char mode, const char *cmd);
16 15
17#else 16#else
18 17
diff --git a/include/linux/mfd/arizona/registers.h b/include/linux/mfd/arizona/registers.h
index c0b075f6bc35..aacc10d7789c 100644
--- a/include/linux/mfd/arizona/registers.h
+++ b/include/linux/mfd/arizona/registers.h
@@ -125,6 +125,8 @@
125#define ARIZONA_MIC_BIAS_CTRL_1 0x218 125#define ARIZONA_MIC_BIAS_CTRL_1 0x218
126#define ARIZONA_MIC_BIAS_CTRL_2 0x219 126#define ARIZONA_MIC_BIAS_CTRL_2 0x219
127#define ARIZONA_MIC_BIAS_CTRL_3 0x21A 127#define ARIZONA_MIC_BIAS_CTRL_3 0x21A
128#define ARIZONA_HP_CTRL_1L 0x225
129#define ARIZONA_HP_CTRL_1R 0x226
128#define ARIZONA_ACCESSORY_DETECT_MODE_1 0x293 130#define ARIZONA_ACCESSORY_DETECT_MODE_1 0x293
129#define ARIZONA_HEADPHONE_DETECT_1 0x29B 131#define ARIZONA_HEADPHONE_DETECT_1 0x29B
130#define ARIZONA_HEADPHONE_DETECT_2 0x29C 132#define ARIZONA_HEADPHONE_DETECT_2 0x29C
@@ -279,8 +281,16 @@
279#define ARIZONA_AIF2_FRAME_CTRL_2 0x548 281#define ARIZONA_AIF2_FRAME_CTRL_2 0x548
280#define ARIZONA_AIF2_FRAME_CTRL_3 0x549 282#define ARIZONA_AIF2_FRAME_CTRL_3 0x549
281#define ARIZONA_AIF2_FRAME_CTRL_4 0x54A 283#define ARIZONA_AIF2_FRAME_CTRL_4 0x54A
284#define ARIZONA_AIF2_FRAME_CTRL_5 0x54B
285#define ARIZONA_AIF2_FRAME_CTRL_6 0x54C
286#define ARIZONA_AIF2_FRAME_CTRL_7 0x54D
287#define ARIZONA_AIF2_FRAME_CTRL_8 0x54E
282#define ARIZONA_AIF2_FRAME_CTRL_11 0x551 288#define ARIZONA_AIF2_FRAME_CTRL_11 0x551
283#define ARIZONA_AIF2_FRAME_CTRL_12 0x552 289#define ARIZONA_AIF2_FRAME_CTRL_12 0x552
290#define ARIZONA_AIF2_FRAME_CTRL_13 0x553
291#define ARIZONA_AIF2_FRAME_CTRL_14 0x554
292#define ARIZONA_AIF2_FRAME_CTRL_15 0x555
293#define ARIZONA_AIF2_FRAME_CTRL_16 0x556
284#define ARIZONA_AIF2_TX_ENABLES 0x559 294#define ARIZONA_AIF2_TX_ENABLES 0x559
285#define ARIZONA_AIF2_RX_ENABLES 0x55A 295#define ARIZONA_AIF2_RX_ENABLES 0x55A
286#define ARIZONA_AIF2_FORCE_WRITE 0x55B 296#define ARIZONA_AIF2_FORCE_WRITE 0x55B
@@ -2245,6 +2255,46 @@
2245#define ARIZONA_MICB3_ENA_WIDTH 1 /* MICB3_ENA */ 2255#define ARIZONA_MICB3_ENA_WIDTH 1 /* MICB3_ENA */
2246 2256
2247/* 2257/*
2258 * R549 (0x225) - HP Ctrl 1L
2259 */
2260#define ARIZONA_RMV_SHRT_HP1L 0x4000 /* RMV_SHRT_HP1L */
2261#define ARIZONA_RMV_SHRT_HP1L_MASK 0x4000 /* RMV_SHRT_HP1L */
2262#define ARIZONA_RMV_SHRT_HP1L_SHIFT 14 /* RMV_SHRT_HP1L */
2263#define ARIZONA_RMV_SHRT_HP1L_WIDTH 1 /* RMV_SHRT_HP1L */
2264#define ARIZONA_HP1L_FLWR 0x0004 /* HP1L_FLWR */
2265#define ARIZONA_HP1L_FLWR_MASK 0x0004 /* HP1L_FLWR */
2266#define ARIZONA_HP1L_FLWR_SHIFT 2 /* HP1L_FLWR */
2267#define ARIZONA_HP1L_FLWR_WIDTH 1 /* HP1L_FLWR */
2268#define ARIZONA_HP1L_SHRTI 0x0002 /* HP1L_SHRTI */
2269#define ARIZONA_HP1L_SHRTI_MASK 0x0002 /* HP1L_SHRTI */
2270#define ARIZONA_HP1L_SHRTI_SHIFT 1 /* HP1L_SHRTI */
2271#define ARIZONA_HP1L_SHRTI_WIDTH 1 /* HP1L_SHRTI */
2272#define ARIZONA_HP1L_SHRTO 0x0001 /* HP1L_SHRTO */
2273#define ARIZONA_HP1L_SHRTO_MASK 0x0001 /* HP1L_SHRTO */
2274#define ARIZONA_HP1L_SHRTO_SHIFT 0 /* HP1L_SHRTO */
2275#define ARIZONA_HP1L_SHRTO_WIDTH 1 /* HP1L_SHRTO */
2276
2277/*
2278 * R550 (0x226) - HP Ctrl 1R
2279 */
2280#define ARIZONA_RMV_SHRT_HP1R 0x4000 /* RMV_SHRT_HP1R */
2281#define ARIZONA_RMV_SHRT_HP1R_MASK 0x4000 /* RMV_SHRT_HP1R */
2282#define ARIZONA_RMV_SHRT_HP1R_SHIFT 14 /* RMV_SHRT_HP1R */
2283#define ARIZONA_RMV_SHRT_HP1R_WIDTH 1 /* RMV_SHRT_HP1R */
2284#define ARIZONA_HP1R_FLWR 0x0004 /* HP1R_FLWR */
2285#define ARIZONA_HP1R_FLWR_MASK 0x0004 /* HP1R_FLWR */
2286#define ARIZONA_HP1R_FLWR_SHIFT 2 /* HP1R_FLWR */
2287#define ARIZONA_HP1R_FLWR_WIDTH 1 /* HP1R_FLWR */
2288#define ARIZONA_HP1R_SHRTI 0x0002 /* HP1R_SHRTI */
2289#define ARIZONA_HP1R_SHRTI_MASK 0x0002 /* HP1R_SHRTI */
2290#define ARIZONA_HP1R_SHRTI_SHIFT 1 /* HP1R_SHRTI */
2291#define ARIZONA_HP1R_SHRTI_WIDTH 1 /* HP1R_SHRTI */
2292#define ARIZONA_HP1R_SHRTO 0x0001 /* HP1R_SHRTO */
2293#define ARIZONA_HP1R_SHRTO_MASK 0x0001 /* HP1R_SHRTO */
2294#define ARIZONA_HP1R_SHRTO_SHIFT 0 /* HP1R_SHRTO */
2295#define ARIZONA_HP1R_SHRTO_WIDTH 1 /* HP1R_SHRTO */
2296
2297/*
2248 * R659 (0x293) - Accessory Detect Mode 1 2298 * R659 (0x293) - Accessory Detect Mode 1
2249 */ 2299 */
2250#define ARIZONA_ACCDET_SRC 0x2000 /* ACCDET_SRC */ 2300#define ARIZONA_ACCDET_SRC 0x2000 /* ACCDET_SRC */
diff --git a/include/linux/mfd/atmel-hlcdc.h b/include/linux/mfd/atmel-hlcdc.h
new file mode 100644
index 000000000000..1279ab1644b5
--- /dev/null
+++ b/include/linux/mfd/atmel-hlcdc.h
@@ -0,0 +1,85 @@
1/*
2 * Copyright (C) 2014 Free Electrons
3 * Copyright (C) 2014 Atmel
4 *
5 * Author: Boris BREZILLON <boris.brezillon@free-electrons.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 version 2 as published by
9 * the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef __LINUX_MFD_HLCDC_H
21#define __LINUX_MFD_HLCDC_H
22
23#include <linux/clk.h>
24#include <linux/regmap.h>
25
26#define ATMEL_HLCDC_CFG(i) ((i) * 0x4)
27#define ATMEL_HLCDC_SIG_CFG LCDCFG(5)
28#define ATMEL_HLCDC_HSPOL BIT(0)
29#define ATMEL_HLCDC_VSPOL BIT(1)
30#define ATMEL_HLCDC_VSPDLYS BIT(2)
31#define ATMEL_HLCDC_VSPDLYE BIT(3)
32#define ATMEL_HLCDC_DISPPOL BIT(4)
33#define ATMEL_HLCDC_DITHER BIT(6)
34#define ATMEL_HLCDC_DISPDLY BIT(7)
35#define ATMEL_HLCDC_MODE_MASK GENMASK(9, 8)
36#define ATMEL_HLCDC_PP BIT(10)
37#define ATMEL_HLCDC_VSPSU BIT(12)
38#define ATMEL_HLCDC_VSPHO BIT(13)
39#define ATMEL_HLCDC_GUARDTIME_MASK GENMASK(20, 16)
40
41#define ATMEL_HLCDC_EN 0x20
42#define ATMEL_HLCDC_DIS 0x24
43#define ATMEL_HLCDC_SR 0x28
44#define ATMEL_HLCDC_IER 0x2c
45#define ATMEL_HLCDC_IDR 0x30
46#define ATMEL_HLCDC_IMR 0x34
47#define ATMEL_HLCDC_ISR 0x38
48
49#define ATMEL_HLCDC_CLKPOL BIT(0)
50#define ATMEL_HLCDC_CLKSEL BIT(2)
51#define ATMEL_HLCDC_CLKPWMSEL BIT(3)
52#define ATMEL_HLCDC_CGDIS(i) BIT(8 + (i))
53#define ATMEL_HLCDC_CLKDIV_SHFT 16
54#define ATMEL_HLCDC_CLKDIV_MASK GENMASK(23, 16)
55#define ATMEL_HLCDC_CLKDIV(div) ((div - 2) << ATMEL_HLCDC_CLKDIV_SHFT)
56
57#define ATMEL_HLCDC_PIXEL_CLK BIT(0)
58#define ATMEL_HLCDC_SYNC BIT(1)
59#define ATMEL_HLCDC_DISP BIT(2)
60#define ATMEL_HLCDC_PWM BIT(3)
61#define ATMEL_HLCDC_SIP BIT(4)
62
63#define ATMEL_HLCDC_SOF BIT(0)
64#define ATMEL_HLCDC_SYNCDIS BIT(1)
65#define ATMEL_HLCDC_FIFOERR BIT(4)
66#define ATMEL_HLCDC_LAYER_STATUS(x) BIT((x) + 8)
67
68/**
69 * Structure shared by the MFD device and its subdevices.
70 *
71 * @regmap: register map used to access HLCDC IP registers
72 * @periph_clk: the hlcdc peripheral clock
73 * @sys_clk: the hlcdc system clock
74 * @slow_clk: the system slow clk
75 * @irq: the hlcdc irq
76 */
77struct atmel_hlcdc {
78 struct regmap *regmap;
79 struct clk *periph_clk;
80 struct clk *sys_clk;
81 struct clk *slow_clk;
82 int irq;
83};
84
85#endif /* __LINUX_MFD_HLCDC_H */
diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h
index d0e31a2287ac..81589d176ae8 100644
--- a/include/linux/mfd/axp20x.h
+++ b/include/linux/mfd/axp20x.h
@@ -14,6 +14,8 @@
14enum { 14enum {
15 AXP202_ID = 0, 15 AXP202_ID = 0,
16 AXP209_ID, 16 AXP209_ID,
17 AXP288_ID,
18 NR_AXP20X_VARIANTS,
17}; 19};
18 20
19#define AXP20X_DATACACHE(m) (0x04 + (m)) 21#define AXP20X_DATACACHE(m) (0x04 + (m))
@@ -49,11 +51,13 @@ enum {
49#define AXP20X_IRQ3_EN 0x42 51#define AXP20X_IRQ3_EN 0x42
50#define AXP20X_IRQ4_EN 0x43 52#define AXP20X_IRQ4_EN 0x43
51#define AXP20X_IRQ5_EN 0x44 53#define AXP20X_IRQ5_EN 0x44
54#define AXP20X_IRQ6_EN 0x45
52#define AXP20X_IRQ1_STATE 0x48 55#define AXP20X_IRQ1_STATE 0x48
53#define AXP20X_IRQ2_STATE 0x49 56#define AXP20X_IRQ2_STATE 0x49
54#define AXP20X_IRQ3_STATE 0x4a 57#define AXP20X_IRQ3_STATE 0x4a
55#define AXP20X_IRQ4_STATE 0x4b 58#define AXP20X_IRQ4_STATE 0x4b
56#define AXP20X_IRQ5_STATE 0x4c 59#define AXP20X_IRQ5_STATE 0x4c
60#define AXP20X_IRQ6_STATE 0x4d
57 61
58/* ADC */ 62/* ADC */
59#define AXP20X_ACIN_V_ADC_H 0x56 63#define AXP20X_ACIN_V_ADC_H 0x56
@@ -116,6 +120,15 @@ enum {
116#define AXP20X_CC_CTRL 0xb8 120#define AXP20X_CC_CTRL 0xb8
117#define AXP20X_FG_RES 0xb9 121#define AXP20X_FG_RES 0xb9
118 122
123/* AXP288 specific registers */
124#define AXP288_PMIC_ADC_H 0x56
125#define AXP288_PMIC_ADC_L 0x57
126#define AXP288_ADC_TS_PIN_CTRL 0x84
127
128#define AXP288_PMIC_ADC_EN 0x84
129#define AXP288_FG_TUNE5 0xed
130
131
119/* Regulators IDs */ 132/* Regulators IDs */
120enum { 133enum {
121 AXP20X_LDO1 = 0, 134 AXP20X_LDO1 = 0,
@@ -169,12 +182,58 @@ enum {
169 AXP20X_IRQ_GPIO0_INPUT, 182 AXP20X_IRQ_GPIO0_INPUT,
170}; 183};
171 184
185enum axp288_irqs {
186 AXP288_IRQ_VBUS_FALL = 2,
187 AXP288_IRQ_VBUS_RISE,
188 AXP288_IRQ_OV,
189 AXP288_IRQ_FALLING_ALT,
190 AXP288_IRQ_RISING_ALT,
191 AXP288_IRQ_OV_ALT,
192 AXP288_IRQ_DONE = 10,
193 AXP288_IRQ_CHARGING,
194 AXP288_IRQ_SAFE_QUIT,
195 AXP288_IRQ_SAFE_ENTER,
196 AXP288_IRQ_ABSENT,
197 AXP288_IRQ_APPEND,
198 AXP288_IRQ_QWBTU,
199 AXP288_IRQ_WBTU,
200 AXP288_IRQ_QWBTO,
201 AXP288_IRQ_WBTO,
202 AXP288_IRQ_QCBTU,
203 AXP288_IRQ_CBTU,
204 AXP288_IRQ_QCBTO,
205 AXP288_IRQ_CBTO,
206 AXP288_IRQ_WL2,
207 AXP288_IRQ_WL1,
208 AXP288_IRQ_GPADC,
209 AXP288_IRQ_OT = 31,
210 AXP288_IRQ_GPIO0,
211 AXP288_IRQ_GPIO1,
212 AXP288_IRQ_POKO,
213 AXP288_IRQ_POKL,
214 AXP288_IRQ_POKS,
215 AXP288_IRQ_POKN,
216 AXP288_IRQ_POKP,
217 AXP288_IRQ_TIMER,
218 AXP288_IRQ_MV_CHNG,
219 AXP288_IRQ_BC_USB_CHNG,
220};
221
222#define AXP288_TS_ADC_H 0x58
223#define AXP288_TS_ADC_L 0x59
224#define AXP288_GP_ADC_H 0x5a
225#define AXP288_GP_ADC_L 0x5b
226
172struct axp20x_dev { 227struct axp20x_dev {
173 struct device *dev; 228 struct device *dev;
174 struct i2c_client *i2c_client; 229 struct i2c_client *i2c_client;
175 struct regmap *regmap; 230 struct regmap *regmap;
176 struct regmap_irq_chip_data *regmap_irqc; 231 struct regmap_irq_chip_data *regmap_irqc;
177 long variant; 232 long variant;
233 int nr_cells;
234 struct mfd_cell *cells;
235 const struct regmap_config *regmap_cfg;
236 const struct regmap_irq_chip *regmap_irq_chip;
178}; 237};
179 238
180#endif /* __LINUX_MFD_AXP20X_H */ 239#endif /* __LINUX_MFD_AXP20X_H */
diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h
index 73e1709d4c09..a76bc100bf97 100644
--- a/include/linux/mfd/core.h
+++ b/include/linux/mfd/core.h
@@ -111,6 +111,13 @@ extern int mfd_add_devices(struct device *parent, int id,
111 struct resource *mem_base, 111 struct resource *mem_base,
112 int irq_base, struct irq_domain *irq_domain); 112 int irq_base, struct irq_domain *irq_domain);
113 113
114static inline int mfd_add_hotplug_devices(struct device *parent,
115 const struct mfd_cell *cells, int n_devs)
116{
117 return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
118 NULL, 0, NULL);
119}
120
114extern void mfd_remove_devices(struct device *parent); 121extern void mfd_remove_devices(struct device *parent);
115 122
116#endif 123#endif
diff --git a/include/linux/mfd/dln2.h b/include/linux/mfd/dln2.h
new file mode 100644
index 000000000000..004b24576da8
--- /dev/null
+++ b/include/linux/mfd/dln2.h
@@ -0,0 +1,103 @@
1#ifndef __LINUX_USB_DLN2_H
2#define __LINUX_USB_DLN2_H
3
4#define DLN2_CMD(cmd, id) ((cmd) | ((id) << 8))
5
6struct dln2_platform_data {
7 u16 handle; /* sub-driver handle (internally used only) */
8 u8 port; /* I2C/SPI port */
9};
10
11/**
12 * dln2_event_cb_t - event callback function signature
13 *
14 * @pdev - the sub-device that registered this callback
15 * @echo - the echo header field received in the message
16 * @data - the data payload
17 * @len - the data payload length
18 *
19 * The callback function is called in interrupt context and the data payload is
20 * only valid during the call. If the user needs later access of the data, it
21 * must copy it.
22 */
23
24typedef void (*dln2_event_cb_t)(struct platform_device *pdev, u16 echo,
25 const void *data, int len);
26
27/**
28 * dl2n_register_event_cb - register a callback function for an event
29 *
30 * @pdev - the sub-device that registers the callback
31 * @event - the event for which to register a callback
32 * @event_cb - the callback function
33 *
34 * @return 0 in case of success, negative value in case of error
35 */
36int dln2_register_event_cb(struct platform_device *pdev, u16 event,
37 dln2_event_cb_t event_cb);
38
39/**
40 * dln2_unregister_event_cb - unregister the callback function for an event
41 *
42 * @pdev - the sub-device that registered the callback
43 * @event - the event for which to register a callback
44 */
45void dln2_unregister_event_cb(struct platform_device *pdev, u16 event);
46
47/**
48 * dln2_transfer - issue a DLN2 command and wait for a response and the
49 * associated data
50 *
51 * @pdev - the sub-device which is issuing this transfer
52 * @cmd - the command to be sent to the device
53 * @obuf - the buffer to be sent to the device; it can be NULL if the user
54 * doesn't need to transmit data with this command
55 * @obuf_len - the size of the buffer to be sent to the device
56 * @ibuf - any data associated with the response will be copied here; it can be
57 * NULL if the user doesn't need the response data
58 * @ibuf_len - must be initialized to the input buffer size; it will be modified
59 * to indicate the actual data transferred;
60 *
61 * @return 0 for success, negative value for errors
62 */
63int dln2_transfer(struct platform_device *pdev, u16 cmd,
64 const void *obuf, unsigned obuf_len,
65 void *ibuf, unsigned *ibuf_len);
66
67/**
68 * dln2_transfer_rx - variant of @dln2_transfer() where TX buffer is not needed
69 *
70 * @pdev - the sub-device which is issuing this transfer
71 * @cmd - the command to be sent to the device
72 * @ibuf - any data associated with the response will be copied here; it can be
73 * NULL if the user doesn't need the response data
74 * @ibuf_len - must be initialized to the input buffer size; it will be modified
75 * to indicate the actual data transferred;
76 *
77 * @return 0 for success, negative value for errors
78 */
79
80static inline int dln2_transfer_rx(struct platform_device *pdev, u16 cmd,
81 void *ibuf, unsigned *ibuf_len)
82{
83 return dln2_transfer(pdev, cmd, NULL, 0, ibuf, ibuf_len);
84}
85
86/**
87 * dln2_transfer_tx - variant of @dln2_transfer() where RX buffer is not needed
88 *
89 * @pdev - the sub-device which is issuing this transfer
90 * @cmd - the command to be sent to the device
91 * @obuf - the buffer to be sent to the device; it can be NULL if the
92 * user doesn't need to transmit data with this command
93 * @obuf_len - the size of the buffer to be sent to the device
94 *
95 * @return 0 for success, negative value for errors
96 */
97static inline int dln2_transfer_tx(struct platform_device *pdev, u16 cmd,
98 const void *obuf, unsigned obuf_len)
99{
100 return dln2_transfer(pdev, cmd, obuf, obuf_len, NULL, NULL);
101}
102
103#endif
diff --git a/include/linux/mfd/max77686.h b/include/linux/mfd/max77686.h
index 7e6dc4b2b795..553f7d09258a 100644
--- a/include/linux/mfd/max77686.h
+++ b/include/linux/mfd/max77686.h
@@ -131,13 +131,6 @@ enum max77686_opmode {
131 MAX77686_OPMODE_STANDBY, 131 MAX77686_OPMODE_STANDBY,
132}; 132};
133 133
134enum max77802_opmode {
135 MAX77802_OPMODE_OFF,
136 MAX77802_OPMODE_STANDBY,
137 MAX77802_OPMODE_LP,
138 MAX77802_OPMODE_NORMAL,
139};
140
141struct max77686_opmode_data { 134struct max77686_opmode_data {
142 int id; 135 int id;
143 int mode; 136 int mode;
diff --git a/include/linux/mfd/max77693-private.h b/include/linux/mfd/max77693-private.h
index fc17d56581b2..08dae01258b9 100644
--- a/include/linux/mfd/max77693-private.h
+++ b/include/linux/mfd/max77693-private.h
@@ -26,7 +26,6 @@
26 26
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28 28
29#define MAX77693_NUM_IRQ_MUIC_REGS 3
30#define MAX77693_REG_INVALID (0xff) 29#define MAX77693_REG_INVALID (0xff)
31 30
32/* Slave addr = 0xCC: PMIC, Charger, Flash LED */ 31/* Slave addr = 0xCC: PMIC, Charger, Flash LED */
@@ -330,6 +329,13 @@ enum max77693_irq_source {
330 MAX77693_IRQ_GROUP_NR, 329 MAX77693_IRQ_GROUP_NR,
331}; 330};
332 331
332#define SRC_IRQ_CHARGER BIT(0)
333#define SRC_IRQ_TOP BIT(1)
334#define SRC_IRQ_FLASH BIT(2)
335#define SRC_IRQ_MUIC BIT(3)
336#define SRC_IRQ_ALL (SRC_IRQ_CHARGER | SRC_IRQ_TOP \
337 | SRC_IRQ_FLASH | SRC_IRQ_MUIC)
338
333#define LED_IRQ_FLED2_OPEN BIT(0) 339#define LED_IRQ_FLED2_OPEN BIT(0)
334#define LED_IRQ_FLED2_SHORT BIT(1) 340#define LED_IRQ_FLED2_SHORT BIT(1)
335#define LED_IRQ_FLED1_OPEN BIT(2) 341#define LED_IRQ_FLED1_OPEN BIT(2)
diff --git a/include/linux/mfd/rtsx_pci.h b/include/linux/mfd/rtsx_pci.h
index 74346d5e7899..0c12628e91c6 100644
--- a/include/linux/mfd/rtsx_pci.h
+++ b/include/linux/mfd/rtsx_pci.h
@@ -558,6 +558,7 @@
558#define SD_SAMPLE_POINT_CTL 0xFDA7 558#define SD_SAMPLE_POINT_CTL 0xFDA7
559#define SD_PUSH_POINT_CTL 0xFDA8 559#define SD_PUSH_POINT_CTL 0xFDA8
560#define SD_CMD0 0xFDA9 560#define SD_CMD0 0xFDA9
561#define SD_CMD_START 0x40
561#define SD_CMD1 0xFDAA 562#define SD_CMD1 0xFDAA
562#define SD_CMD2 0xFDAB 563#define SD_CMD2 0xFDAB
563#define SD_CMD3 0xFDAC 564#define SD_CMD3 0xFDAC
@@ -707,6 +708,14 @@
707#define PM_CTRL1 0xFF44 708#define PM_CTRL1 0xFF44
708#define PM_CTRL2 0xFF45 709#define PM_CTRL2 0xFF45
709#define PM_CTRL3 0xFF46 710#define PM_CTRL3 0xFF46
711#define SDIO_SEND_PME_EN 0x80
712#define FORCE_RC_MODE_ON 0x40
713#define FORCE_RX50_LINK_ON 0x20
714#define D3_DELINK_MODE_EN 0x10
715#define USE_PESRTB_CTL_DELINK 0x08
716#define DELAY_PIN_WAKE 0x04
717#define RESET_PIN_WAKE 0x02
718#define PM_WAKE_EN 0x01
710#define PM_CTRL4 0xFF47 719#define PM_CTRL4 0xFF47
711 720
712/* Memory mapping */ 721/* Memory mapping */
@@ -752,6 +761,14 @@
752#define PHY_DUM_REG 0x1F 761#define PHY_DUM_REG 0x1F
753 762
754#define LCTLR 0x80 763#define LCTLR 0x80
764#define LCTLR_EXT_SYNC 0x80
765#define LCTLR_COMMON_CLOCK_CFG 0x40
766#define LCTLR_RETRAIN_LINK 0x20
767#define LCTLR_LINK_DISABLE 0x10
768#define LCTLR_RCB 0x08
769#define LCTLR_RESERVED 0x04
770#define LCTLR_ASPM_CTL_MASK 0x03
771
755#define PCR_SETTING_REG1 0x724 772#define PCR_SETTING_REG1 0x724
756#define PCR_SETTING_REG2 0x814 773#define PCR_SETTING_REG2 0x814
757#define PCR_SETTING_REG3 0x747 774#define PCR_SETTING_REG3 0x747
@@ -967,4 +984,24 @@ static inline u8 *rtsx_pci_get_cmd_data(struct rtsx_pcr *pcr)
967 return (u8 *)(pcr->host_cmds_ptr); 984 return (u8 *)(pcr->host_cmds_ptr);
968} 985}
969 986
987static inline int rtsx_pci_update_cfg_byte(struct rtsx_pcr *pcr, int addr,
988 u8 mask, u8 append)
989{
990 int err;
991 u8 val;
992
993 err = pci_read_config_byte(pcr->pci, addr, &val);
994 if (err < 0)
995 return err;
996 return pci_write_config_byte(pcr->pci, addr, (val & mask) | append);
997}
998
999static inline void rtsx_pci_write_be32(struct rtsx_pcr *pcr, u16 reg, u32 val)
1000{
1001 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg, 0xFF, val >> 24);
1002 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 1, 0xFF, val >> 16);
1003 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 2, 0xFF, val >> 8);
1004 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, reg + 3, 0xFF, val);
1005}
1006
970#endif 1007#endif
diff --git a/include/linux/mfd/samsung/core.h b/include/linux/mfd/samsung/core.h
index 1825edacbda7..3fdb7cfbffb3 100644
--- a/include/linux/mfd/samsung/core.h
+++ b/include/linux/mfd/samsung/core.h
@@ -28,6 +28,7 @@
28#define MIN_800_MV 800000 28#define MIN_800_MV 800000
29#define MIN_750_MV 750000 29#define MIN_750_MV 750000
30#define MIN_600_MV 600000 30#define MIN_600_MV 600000
31#define MIN_500_MV 500000
31 32
32/* Macros to represent steps for LDO/BUCK */ 33/* Macros to represent steps for LDO/BUCK */
33#define STEP_50_MV 50000 34#define STEP_50_MV 50000
@@ -41,6 +42,7 @@ enum sec_device_type {
41 S5M8767X, 42 S5M8767X,
42 S2MPA01, 43 S2MPA01,
43 S2MPS11X, 44 S2MPS11X,
45 S2MPS13X,
44 S2MPS14X, 46 S2MPS14X,
45 S2MPU02, 47 S2MPU02,
46}; 48};
diff --git a/include/linux/mfd/samsung/s2mps13.h b/include/linux/mfd/samsung/s2mps13.h
new file mode 100644
index 000000000000..ce5dda8958fe
--- /dev/null
+++ b/include/linux/mfd/samsung/s2mps13.h
@@ -0,0 +1,186 @@
1/*
2 * s2mps13.h
3 *
4 * Copyright (c) 2014 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 * 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 */
18
19#ifndef __LINUX_MFD_S2MPS13_H
20#define __LINUX_MFD_S2MPS13_H
21
22/* S2MPS13 registers */
23enum s2mps13_reg {
24 S2MPS13_REG_ID,
25 S2MPS13_REG_INT1,
26 S2MPS13_REG_INT2,
27 S2MPS13_REG_INT3,
28 S2MPS13_REG_INT1M,
29 S2MPS13_REG_INT2M,
30 S2MPS13_REG_INT3M,
31 S2MPS13_REG_ST1,
32 S2MPS13_REG_ST2,
33 S2MPS13_REG_PWRONSRC,
34 S2MPS13_REG_OFFSRC,
35 S2MPS13_REG_BU_CHG,
36 S2MPS13_REG_RTCCTRL,
37 S2MPS13_REG_CTRL1,
38 S2MPS13_REG_CTRL2,
39 S2MPS13_REG_RSVD1,
40 S2MPS13_REG_RSVD2,
41 S2MPS13_REG_RSVD3,
42 S2MPS13_REG_RSVD4,
43 S2MPS13_REG_RSVD5,
44 S2MPS13_REG_RSVD6,
45 S2MPS13_REG_CTRL3,
46 S2MPS13_REG_RSVD7,
47 S2MPS13_REG_RSVD8,
48 S2MPS13_REG_WRSTBI,
49 S2MPS13_REG_B1CTRL,
50 S2MPS13_REG_B1OUT,
51 S2MPS13_REG_B2CTRL,
52 S2MPS13_REG_B2OUT,
53 S2MPS13_REG_B3CTRL,
54 S2MPS13_REG_B3OUT,
55 S2MPS13_REG_B4CTRL,
56 S2MPS13_REG_B4OUT,
57 S2MPS13_REG_B5CTRL,
58 S2MPS13_REG_B5OUT,
59 S2MPS13_REG_B6CTRL,
60 S2MPS13_REG_B6OUT,
61 S2MPS13_REG_B7CTRL,
62 S2MPS13_REG_B7OUT,
63 S2MPS13_REG_B8CTRL,
64 S2MPS13_REG_B8OUT,
65 S2MPS13_REG_B9CTRL,
66 S2MPS13_REG_B9OUT,
67 S2MPS13_REG_B10CTRL,
68 S2MPS13_REG_B10OUT,
69 S2MPS13_REG_BB1CTRL,
70 S2MPS13_REG_BB1OUT,
71 S2MPS13_REG_BUCK_RAMP1,
72 S2MPS13_REG_BUCK_RAMP2,
73 S2MPS13_REG_LDO_DVS1,
74 S2MPS13_REG_LDO_DVS2,
75 S2MPS13_REG_LDO_DVS3,
76 S2MPS13_REG_B6OUT2,
77 S2MPS13_REG_L1CTRL,
78 S2MPS13_REG_L2CTRL,
79 S2MPS13_REG_L3CTRL,
80 S2MPS13_REG_L4CTRL,
81 S2MPS13_REG_L5CTRL,
82 S2MPS13_REG_L6CTRL,
83 S2MPS13_REG_L7CTRL,
84 S2MPS13_REG_L8CTRL,
85 S2MPS13_REG_L9CTRL,
86 S2MPS13_REG_L10CTRL,
87 S2MPS13_REG_L11CTRL,
88 S2MPS13_REG_L12CTRL,
89 S2MPS13_REG_L13CTRL,
90 S2MPS13_REG_L14CTRL,
91 S2MPS13_REG_L15CTRL,
92 S2MPS13_REG_L16CTRL,
93 S2MPS13_REG_L17CTRL,
94 S2MPS13_REG_L18CTRL,
95 S2MPS13_REG_L19CTRL,
96 S2MPS13_REG_L20CTRL,
97 S2MPS13_REG_L21CTRL,
98 S2MPS13_REG_L22CTRL,
99 S2MPS13_REG_L23CTRL,
100 S2MPS13_REG_L24CTRL,
101 S2MPS13_REG_L25CTRL,
102 S2MPS13_REG_L26CTRL,
103 S2MPS13_REG_L27CTRL,
104 S2MPS13_REG_L28CTRL,
105 S2MPS13_REG_L30CTRL,
106 S2MPS13_REG_L31CTRL,
107 S2MPS13_REG_L32CTRL,
108 S2MPS13_REG_L33CTRL,
109 S2MPS13_REG_L34CTRL,
110 S2MPS13_REG_L35CTRL,
111 S2MPS13_REG_L36CTRL,
112 S2MPS13_REG_L37CTRL,
113 S2MPS13_REG_L38CTRL,
114 S2MPS13_REG_L39CTRL,
115 S2MPS13_REG_L40CTRL,
116 S2MPS13_REG_LDODSCH1,
117 S2MPS13_REG_LDODSCH2,
118 S2MPS13_REG_LDODSCH3,
119 S2MPS13_REG_LDODSCH4,
120 S2MPS13_REG_LDODSCH5,
121};
122
123/* regulator ids */
124enum s2mps13_regulators {
125 S2MPS13_LDO1,
126 S2MPS13_LDO2,
127 S2MPS13_LDO3,
128 S2MPS13_LDO4,
129 S2MPS13_LDO5,
130 S2MPS13_LDO6,
131 S2MPS13_LDO7,
132 S2MPS13_LDO8,
133 S2MPS13_LDO9,
134 S2MPS13_LDO10,
135 S2MPS13_LDO11,
136 S2MPS13_LDO12,
137 S2MPS13_LDO13,
138 S2MPS13_LDO14,
139 S2MPS13_LDO15,
140 S2MPS13_LDO16,
141 S2MPS13_LDO17,
142 S2MPS13_LDO18,
143 S2MPS13_LDO19,
144 S2MPS13_LDO20,
145 S2MPS13_LDO21,
146 S2MPS13_LDO22,
147 S2MPS13_LDO23,
148 S2MPS13_LDO24,
149 S2MPS13_LDO25,
150 S2MPS13_LDO26,
151 S2MPS13_LDO27,
152 S2MPS13_LDO28,
153 S2MPS13_LDO29,
154 S2MPS13_LDO30,
155 S2MPS13_LDO31,
156 S2MPS13_LDO32,
157 S2MPS13_LDO33,
158 S2MPS13_LDO34,
159 S2MPS13_LDO35,
160 S2MPS13_LDO36,
161 S2MPS13_LDO37,
162 S2MPS13_LDO38,
163 S2MPS13_LDO39,
164 S2MPS13_LDO40,
165 S2MPS13_BUCK1,
166 S2MPS13_BUCK2,
167 S2MPS13_BUCK3,
168 S2MPS13_BUCK4,
169 S2MPS13_BUCK5,
170 S2MPS13_BUCK6,
171 S2MPS13_BUCK7,
172 S2MPS13_BUCK8,
173 S2MPS13_BUCK9,
174 S2MPS13_BUCK10,
175
176 S2MPS13_REGULATOR_MAX,
177};
178
179/*
180 * Default ramp delay in uv/us. Datasheet says that ramp delay can be
181 * controlled however it does not specify which register is used for that.
182 * Let's assume that default value will be set.
183 */
184#define S2MPS13_BUCK_RAMP_DELAY 12500
185
186#endif /* __LINUX_MFD_S2MPS13_H */
diff --git a/include/linux/mfd/tc3589x.h b/include/linux/mfd/tc3589x.h
index e6088c2e2092..e1c12d84c26a 100644
--- a/include/linux/mfd/tc3589x.h
+++ b/include/linux/mfd/tc3589x.h
@@ -164,13 +164,10 @@ struct tc3589x_keypad_platform_data {
164 164
165/** 165/**
166 * struct tc3589x_gpio_platform_data - TC3589x GPIO platform data 166 * struct tc3589x_gpio_platform_data - TC3589x GPIO platform data
167 * @gpio_base: first gpio number assigned to TC3589x. A maximum of
168 * %TC3589x_NR_GPIOS GPIOs will be allocated.
169 * @setup: callback for board-specific initialization 167 * @setup: callback for board-specific initialization
170 * @remove: callback for board-specific teardown 168 * @remove: callback for board-specific teardown
171 */ 169 */
172struct tc3589x_gpio_platform_data { 170struct tc3589x_gpio_platform_data {
173 int gpio_base;
174 void (*setup)(struct tc3589x *tc3589x, unsigned gpio_base); 171 void (*setup)(struct tc3589x *tc3589x, unsigned gpio_base);
175 void (*remove)(struct tc3589x *tc3589x, unsigned gpio_base); 172 void (*remove)(struct tc3589x *tc3589x, unsigned gpio_base);
176}; 173};
@@ -178,18 +175,13 @@ struct tc3589x_gpio_platform_data {
178/** 175/**
179 * struct tc3589x_platform_data - TC3589x platform data 176 * struct tc3589x_platform_data - TC3589x platform data
180 * @block: bitmask of blocks to enable (use TC3589x_BLOCK_*) 177 * @block: bitmask of blocks to enable (use TC3589x_BLOCK_*)
181 * @irq_base: base IRQ number. %TC3589x_NR_IRQS irqs will be used.
182 * @gpio: GPIO-specific platform data 178 * @gpio: GPIO-specific platform data
183 * @keypad: keypad-specific platform data 179 * @keypad: keypad-specific platform data
184 */ 180 */
185struct tc3589x_platform_data { 181struct tc3589x_platform_data {
186 unsigned int block; 182 unsigned int block;
187 int irq_base;
188 struct tc3589x_gpio_platform_data *gpio; 183 struct tc3589x_gpio_platform_data *gpio;
189 const struct tc3589x_keypad_platform_data *keypad; 184 const struct tc3589x_keypad_platform_data *keypad;
190}; 185};
191 186
192#define TC3589x_NR_GPIOS 24
193#define TC3589x_NR_IRQS TC3589x_INT_GPIO(TC3589x_NR_GPIOS)
194
195#endif 187#endif
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index b0692d28f8e6..4d69c00497bd 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -88,6 +88,9 @@ struct mmc_ext_csd {
88 unsigned int data_tag_unit_size; /* DATA TAG UNIT size */ 88 unsigned int data_tag_unit_size; /* DATA TAG UNIT size */
89 unsigned int boot_ro_lock; /* ro lock support */ 89 unsigned int boot_ro_lock; /* ro lock support */
90 bool boot_ro_lockable; 90 bool boot_ro_lockable;
91 bool ffu_capable; /* Firmware upgrade support */
92#define MMC_FIRMWARE_LEN 8
93 u8 fwrev[MMC_FIRMWARE_LEN]; /* FW version */
91 u8 raw_exception_status; /* 54 */ 94 u8 raw_exception_status; /* 54 */
92 u8 raw_partition_support; /* 160 */ 95 u8 raw_partition_support; /* 160 */
93 u8 raw_rpmb_size_mult; /* 168 */ 96 u8 raw_rpmb_size_mult; /* 168 */
@@ -509,24 +512,8 @@ static inline int mmc_card_broken_irq_polling(const struct mmc_card *c)
509 512
510#define mmc_dev_to_card(d) container_of(d, struct mmc_card, dev) 513#define mmc_dev_to_card(d) container_of(d, struct mmc_card, dev)
511 514
512#define mmc_list_to_card(l) container_of(l, struct mmc_card, node) 515extern int mmc_register_driver(struct device_driver *);
513#define mmc_get_drvdata(c) dev_get_drvdata(&(c)->dev) 516extern void mmc_unregister_driver(struct device_driver *);
514#define mmc_set_drvdata(c,d) dev_set_drvdata(&(c)->dev, d)
515
516/*
517 * MMC device driver (e.g., Flash card, I/O card...)
518 */
519struct mmc_driver {
520 struct device_driver drv;
521 int (*probe)(struct mmc_card *);
522 void (*remove)(struct mmc_card *);
523 int (*suspend)(struct mmc_card *);
524 int (*resume)(struct mmc_card *);
525 void (*shutdown)(struct mmc_card *);
526};
527
528extern int mmc_register_driver(struct mmc_driver *);
529extern void mmc_unregister_driver(struct mmc_driver *);
530 517
531extern void mmc_fixup_device(struct mmc_card *card, 518extern void mmc_fixup_device(struct mmc_card *card,
532 const struct mmc_fixup *table); 519 const struct mmc_fixup *table);
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index f206e29f94d7..cb2b0400d284 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -154,7 +154,8 @@ extern void mmc_start_bkops(struct mmc_card *card, bool from_exception);
154extern int __mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int, bool, 154extern int __mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int, bool,
155 bool, bool); 155 bool, bool);
156extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int); 156extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
157extern int mmc_send_ext_csd(struct mmc_card *card, u8 *ext_csd); 157extern int mmc_send_tuning(struct mmc_host *host);
158extern int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd);
158 159
159#define MMC_ERASE_ARG 0x00000000 160#define MMC_ERASE_ARG 0x00000000
160#define MMC_SECURE_ERASE_ARG 0x80000000 161#define MMC_SECURE_ERASE_ARG 0x80000000
diff --git a/include/linux/mmc/dw_mmc.h b/include/linux/mmc/dw_mmc.h
index 001366927cf4..42b724e8d503 100644
--- a/include/linux/mmc/dw_mmc.h
+++ b/include/linux/mmc/dw_mmc.h
@@ -54,6 +54,7 @@ struct mmc_data;
54 * transfer is in progress. 54 * transfer is in progress.
55 * @use_dma: Whether DMA channel is initialized or not. 55 * @use_dma: Whether DMA channel is initialized or not.
56 * @using_dma: Whether DMA is in use for the current transfer. 56 * @using_dma: Whether DMA is in use for the current transfer.
57 * @dma_64bit_address: Whether DMA supports 64-bit address mode or not.
57 * @sg_dma: Bus address of DMA buffer. 58 * @sg_dma: Bus address of DMA buffer.
58 * @sg_cpu: Virtual address of DMA buffer. 59 * @sg_cpu: Virtual address of DMA buffer.
59 * @dma_ops: Pointer to platform-specific DMA callbacks. 60 * @dma_ops: Pointer to platform-specific DMA callbacks.
@@ -96,6 +97,7 @@ struct mmc_data;
96 * @quirks: Set of quirks that apply to specific versions of the IP. 97 * @quirks: Set of quirks that apply to specific versions of the IP.
97 * @irq_flags: The flags to be passed to request_irq. 98 * @irq_flags: The flags to be passed to request_irq.
98 * @irq: The irq value to be passed to request_irq. 99 * @irq: The irq value to be passed to request_irq.
100 * @sdio_id0: Number of slot0 in the SDIO interrupt registers.
99 * 101 *
100 * Locking 102 * Locking
101 * ======= 103 * =======
@@ -135,11 +137,11 @@ struct dw_mci {
135 struct mmc_command stop_abort; 137 struct mmc_command stop_abort;
136 unsigned int prev_blksz; 138 unsigned int prev_blksz;
137 unsigned char timing; 139 unsigned char timing;
138 struct workqueue_struct *card_workqueue;
139 140
140 /* DMA interface members*/ 141 /* DMA interface members*/
141 int use_dma; 142 int use_dma;
142 int using_dma; 143 int using_dma;
144 int dma_64bit_address;
143 145
144 dma_addr_t sg_dma; 146 dma_addr_t sg_dma;
145 void *sg_cpu; 147 void *sg_cpu;
@@ -154,7 +156,6 @@ struct dw_mci {
154 u32 stop_cmdr; 156 u32 stop_cmdr;
155 u32 dir_status; 157 u32 dir_status;
156 struct tasklet_struct tasklet; 158 struct tasklet_struct tasklet;
157 struct work_struct card_work;
158 unsigned long pending_events; 159 unsigned long pending_events;
159 unsigned long completed_events; 160 unsigned long completed_events;
160 enum dw_mci_state state; 161 enum dw_mci_state state;
@@ -193,6 +194,8 @@ struct dw_mci {
193 bool vqmmc_enabled; 194 bool vqmmc_enabled;
194 unsigned long irq_flags; /* IRQ flags */ 195 unsigned long irq_flags; /* IRQ flags */
195 int irq; 196 int irq;
197
198 int sdio_id0;
196}; 199};
197 200
198/* DMA ops for Internal/External DMAC interface */ 201/* DMA ops for Internal/External DMAC interface */
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index df0c15396bbf..9f322706f7cb 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -289,6 +289,7 @@ struct mmc_host {
289#define MMC_CAP2_HS400_1_2V (1 << 16) /* Can support HS400 1.2V */ 289#define MMC_CAP2_HS400_1_2V (1 << 16) /* Can support HS400 1.2V */
290#define MMC_CAP2_HS400 (MMC_CAP2_HS400_1_8V | \ 290#define MMC_CAP2_HS400 (MMC_CAP2_HS400_1_8V | \
291 MMC_CAP2_HS400_1_2V) 291 MMC_CAP2_HS400_1_2V)
292#define MMC_CAP2_HSX00_1_2V (MMC_CAP2_HS200_1_2V_SDR | MMC_CAP2_HS400_1_2V)
292#define MMC_CAP2_SDIO_IRQ_NOTHREAD (1 << 17) 293#define MMC_CAP2_SDIO_IRQ_NOTHREAD (1 << 17)
293 294
294 mmc_pm_flag_t pm_caps; /* supported pm features */ 295 mmc_pm_flag_t pm_caps; /* supported pm features */
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 1cd00b3a75b9..49ad7a943638 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -296,6 +296,7 @@ struct _mmc_csd {
296#define EXT_CSD_SANITIZE_START 165 /* W */ 296#define EXT_CSD_SANITIZE_START 165 /* W */
297#define EXT_CSD_WR_REL_PARAM 166 /* RO */ 297#define EXT_CSD_WR_REL_PARAM 166 /* RO */
298#define EXT_CSD_RPMB_MULT 168 /* RO */ 298#define EXT_CSD_RPMB_MULT 168 /* RO */
299#define EXT_CSD_FW_CONFIG 169 /* R/W */
299#define EXT_CSD_BOOT_WP 173 /* R/W */ 300#define EXT_CSD_BOOT_WP 173 /* R/W */
300#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ 301#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
301#define EXT_CSD_PART_CONFIG 179 /* R/W */ 302#define EXT_CSD_PART_CONFIG 179 /* R/W */
@@ -332,6 +333,8 @@ struct _mmc_csd {
332#define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */ 333#define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */
333#define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */ 334#define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */
334#define EXT_CSD_PWR_CL_DDR_200_360 253 /* RO */ 335#define EXT_CSD_PWR_CL_DDR_200_360 253 /* RO */
336#define EXT_CSD_FIRMWARE_VERSION 254 /* RO, 8 bytes */
337#define EXT_CSD_SUPPORTED_MODE 493 /* RO */
335#define EXT_CSD_TAG_UNIT_SIZE 498 /* RO */ 338#define EXT_CSD_TAG_UNIT_SIZE 498 /* RO */
336#define EXT_CSD_DATA_TAG_SUPPORT 499 /* RO */ 339#define EXT_CSD_DATA_TAG_SUPPORT 499 /* RO */
337#define EXT_CSD_MAX_PACKED_WRITES 500 /* RO */ 340#define EXT_CSD_MAX_PACKED_WRITES 500 /* RO */
diff --git a/include/linux/mmc/sdhci.h b/include/linux/mmc/sdhci.h
index dba793e3a331..375af80bde7d 100644
--- a/include/linux/mmc/sdhci.h
+++ b/include/linux/mmc/sdhci.h
@@ -100,6 +100,12 @@ struct sdhci_host {
100#define SDHCI_QUIRK2_BROKEN_DDR50 (1<<7) 100#define SDHCI_QUIRK2_BROKEN_DDR50 (1<<7)
101/* Stop command (CMD12) can set Transfer Complete when not using MMC_RSP_BUSY */ 101/* Stop command (CMD12) can set Transfer Complete when not using MMC_RSP_BUSY */
102#define SDHCI_QUIRK2_STOP_WITH_TC (1<<8) 102#define SDHCI_QUIRK2_STOP_WITH_TC (1<<8)
103/* Controller does not support 64-bit DMA */
104#define SDHCI_QUIRK2_BROKEN_64_BIT_DMA (1<<9)
105/* need clear transfer mode register before send cmd */
106#define SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD (1<<10)
107/* Capability register bit-63 indicates HS400 support */
108#define SDHCI_QUIRK2_CAPS_BIT63_FOR_HS400 (1<<11)
103 109
104 int irq; /* Device IRQ */ 110 int irq; /* Device IRQ */
105 void __iomem *ioaddr; /* Mapped address */ 111 void __iomem *ioaddr; /* Mapped address */
@@ -130,6 +136,7 @@ struct sdhci_host {
130#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */ 136#define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
131#define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */ 137#define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
132#define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */ 138#define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
139#define SDHCI_USE_64_BIT_DMA (1<<12) /* Use 64-bit DMA */
133 140
134 unsigned int version; /* SDHCI spec. version */ 141 unsigned int version; /* SDHCI spec. version */
135 142
@@ -155,12 +162,19 @@ struct sdhci_host {
155 162
156 int sg_count; /* Mapped sg entries */ 163 int sg_count; /* Mapped sg entries */
157 164
158 u8 *adma_desc; /* ADMA descriptor table */ 165 void *adma_table; /* ADMA descriptor table */
159 u8 *align_buffer; /* Bounce buffer */ 166 void *align_buffer; /* Bounce buffer */
167
168 size_t adma_table_sz; /* ADMA descriptor table size */
169 size_t align_buffer_sz; /* Bounce buffer size */
160 170
161 dma_addr_t adma_addr; /* Mapped ADMA descr. table */ 171 dma_addr_t adma_addr; /* Mapped ADMA descr. table */
162 dma_addr_t align_addr; /* Mapped bounce buffer */ 172 dma_addr_t align_addr; /* Mapped bounce buffer */
163 173
174 unsigned int desc_sz; /* ADMA descriptor size */
175 unsigned int align_sz; /* ADMA alignment */
176 unsigned int align_mask; /* ADMA alignment mask */
177
164 struct tasklet_struct finish_tasklet; /* Tasklet structures */ 178 struct tasklet_struct finish_tasklet; /* Tasklet structures */
165 179
166 struct timer_list timer; /* Timer for timeouts */ 180 struct timer_list timer; /* Timer for timeouts */
diff --git a/include/linux/mmc/sdio_func.h b/include/linux/mmc/sdio_func.h
index 50f0bc952328..aab032a6ae61 100644
--- a/include/linux/mmc/sdio_func.h
+++ b/include/linux/mmc/sdio_func.h
@@ -84,8 +84,6 @@ struct sdio_driver {
84 struct device_driver drv; 84 struct device_driver drv;
85}; 85};
86 86
87#define to_sdio_driver(d) container_of(d, struct sdio_driver, drv)
88
89/** 87/**
90 * SDIO_DEVICE - macro used to describe a specific SDIO device 88 * SDIO_DEVICE - macro used to describe a specific SDIO device
91 * @vend: the 16 bit manufacturer code 89 * @vend: the 16 bit manufacturer code
diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
index 48bf12ef6620..ffe66e381c04 100644
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -431,6 +431,15 @@ struct zone {
431 */ 431 */
432 int nr_migrate_reserve_block; 432 int nr_migrate_reserve_block;
433 433
434#ifdef CONFIG_MEMORY_ISOLATION
435 /*
436 * Number of isolated pageblock. It is used to solve incorrect
437 * freepage counting problem due to racy retrieving migratetype
438 * of pageblock. Protected by zone->lock.
439 */
440 unsigned long nr_isolate_pageblock;
441#endif
442
434#ifdef CONFIG_MEMORY_HOTPLUG 443#ifdef CONFIG_MEMORY_HOTPLUG
435 /* see spanned/present_pages for more description */ 444 /* see spanned/present_pages for more description */
436 seqlock_t span_seqlock; 445 seqlock_t span_seqlock;
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index 983876f24aed..47ebb4fafd87 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -1224,11 +1224,22 @@ struct nfs41_free_stateid_res {
1224 unsigned int status; 1224 unsigned int status;
1225}; 1225};
1226 1226
1227static inline void
1228nfs_free_pnfs_ds_cinfo(struct pnfs_ds_commit_info *cinfo)
1229{
1230 kfree(cinfo->buckets);
1231}
1232
1227#else 1233#else
1228 1234
1229struct pnfs_ds_commit_info { 1235struct pnfs_ds_commit_info {
1230}; 1236};
1231 1237
1238static inline void
1239nfs_free_pnfs_ds_cinfo(struct pnfs_ds_commit_info *cinfo)
1240{
1241}
1242
1232#endif /* CONFIG_NFS_V4_1 */ 1243#endif /* CONFIG_NFS_V4_1 */
1233 1244
1234#ifdef CONFIG_NFS_V4_2 1245#ifdef CONFIG_NFS_V4_2
diff --git a/include/linux/of.h b/include/linux/of.h
index 6545e7aec7bb..c55b50018ac4 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -267,14 +267,12 @@ extern int of_property_read_u64(const struct device_node *np,
267extern int of_property_read_string(struct device_node *np, 267extern int of_property_read_string(struct device_node *np,
268 const char *propname, 268 const char *propname,
269 const char **out_string); 269 const char **out_string);
270extern int of_property_read_string_index(struct device_node *np,
271 const char *propname,
272 int index, const char **output);
273extern int of_property_match_string(struct device_node *np, 270extern int of_property_match_string(struct device_node *np,
274 const char *propname, 271 const char *propname,
275 const char *string); 272 const char *string);
276extern int of_property_count_strings(struct device_node *np, 273extern int of_property_read_string_helper(struct device_node *np,
277 const char *propname); 274 const char *propname,
275 const char **out_strs, size_t sz, int index);
278extern int of_device_is_compatible(const struct device_node *device, 276extern int of_device_is_compatible(const struct device_node *device,
279 const char *); 277 const char *);
280extern int of_device_is_available(const struct device_node *device); 278extern int of_device_is_available(const struct device_node *device);
@@ -486,15 +484,9 @@ static inline int of_property_read_string(struct device_node *np,
486 return -ENOSYS; 484 return -ENOSYS;
487} 485}
488 486
489static inline int of_property_read_string_index(struct device_node *np, 487static inline int of_property_read_string_helper(struct device_node *np,
490 const char *propname, int index, 488 const char *propname,
491 const char **out_string) 489 const char **out_strs, size_t sz, int index)
492{
493 return -ENOSYS;
494}
495
496static inline int of_property_count_strings(struct device_node *np,
497 const char *propname)
498{ 490{
499 return -ENOSYS; 491 return -ENOSYS;
500} 492}
@@ -668,6 +660,70 @@ static inline int of_property_count_u64_elems(const struct device_node *np,
668} 660}
669 661
670/** 662/**
663 * of_property_read_string_array() - Read an array of strings from a multiple
664 * strings property.
665 * @np: device node from which the property value is to be read.
666 * @propname: name of the property to be searched.
667 * @out_strs: output array of string pointers.
668 * @sz: number of array elements to read.
669 *
670 * Search for a property in a device tree node and retrieve a list of
671 * terminated string values (pointer to data, not a copy) in that property.
672 *
673 * If @out_strs is NULL, the number of strings in the property is returned.
674 */
675static inline int of_property_read_string_array(struct device_node *np,
676 const char *propname, const char **out_strs,
677 size_t sz)
678{
679 return of_property_read_string_helper(np, propname, out_strs, sz, 0);
680}
681
682/**
683 * of_property_count_strings() - Find and return the number of strings from a
684 * multiple strings property.
685 * @np: device node from which the property value is to be read.
686 * @propname: name of the property to be searched.
687 *
688 * Search for a property in a device tree node and retrieve the number of null
689 * terminated string contain in it. Returns the number of strings on
690 * success, -EINVAL if the property does not exist, -ENODATA if property
691 * does not have a value, and -EILSEQ if the string is not null-terminated
692 * within the length of the property data.
693 */
694static inline int of_property_count_strings(struct device_node *np,
695 const char *propname)
696{
697 return of_property_read_string_helper(np, propname, NULL, 0, 0);
698}
699
700/**
701 * of_property_read_string_index() - Find and read a string from a multiple
702 * strings property.
703 * @np: device node from which the property value is to be read.
704 * @propname: name of the property to be searched.
705 * @index: index of the string in the list of strings
706 * @out_string: pointer to null terminated return string, modified only if
707 * return value is 0.
708 *
709 * Search for a property in a device tree node and retrieve a null
710 * terminated string value (pointer to data, not a copy) in the list of strings
711 * contained in that property.
712 * Returns 0 on success, -EINVAL if the property does not exist, -ENODATA if
713 * property does not have a value, and -EILSEQ if the string is not
714 * null-terminated within the length of the property data.
715 *
716 * The out_string pointer is modified only if a valid string can be decoded.
717 */
718static inline int of_property_read_string_index(struct device_node *np,
719 const char *propname,
720 int index, const char **output)
721{
722 int rc = of_property_read_string_helper(np, propname, output, 1, index);
723 return rc < 0 ? rc : 0;
724}
725
726/**
671 * of_property_read_bool - Findfrom a property 727 * of_property_read_bool - Findfrom a property
672 * @np: device node from which the property value is to be read. 728 * @np: device node from which the property value is to be read.
673 * @propname: name of the property to be searched. 729 * @propname: name of the property to be searched.
@@ -866,4 +922,15 @@ static inline int of_changeset_update_property(struct of_changeset *ocs,
866/* CONFIG_OF_RESOLVE api */ 922/* CONFIG_OF_RESOLVE api */
867extern int of_resolve_phandles(struct device_node *tree); 923extern int of_resolve_phandles(struct device_node *tree);
868 924
925/**
926 * of_device_is_system_power_controller - Tells if system-power-controller is found for device_node
927 * @np: Pointer to the given device_node
928 *
929 * return true if present false otherwise
930 */
931static inline bool of_device_is_system_power_controller(const struct device_node *np)
932{
933 return of_property_read_bool(np, "system-power-controller");
934}
935
869#endif /* _LINUX_OF_H */ 936#endif /* _LINUX_OF_H */
diff --git a/include/linux/page-isolation.h b/include/linux/page-isolation.h
index 3fff8e774067..2dc1e1697b45 100644
--- a/include/linux/page-isolation.h
+++ b/include/linux/page-isolation.h
@@ -2,6 +2,10 @@
2#define __LINUX_PAGEISOLATION_H 2#define __LINUX_PAGEISOLATION_H
3 3
4#ifdef CONFIG_MEMORY_ISOLATION 4#ifdef CONFIG_MEMORY_ISOLATION
5static inline bool has_isolate_pageblock(struct zone *zone)
6{
7 return zone->nr_isolate_pageblock;
8}
5static inline bool is_migrate_isolate_page(struct page *page) 9static inline bool is_migrate_isolate_page(struct page *page)
6{ 10{
7 return get_pageblock_migratetype(page) == MIGRATE_ISOLATE; 11 return get_pageblock_migratetype(page) == MIGRATE_ISOLATE;
@@ -11,6 +15,10 @@ static inline bool is_migrate_isolate(int migratetype)
11 return migratetype == MIGRATE_ISOLATE; 15 return migratetype == MIGRATE_ISOLATE;
12} 16}
13#else 17#else
18static inline bool has_isolate_pageblock(struct zone *zone)
19{
20 return false;
21}
14static inline bool is_migrate_isolate_page(struct page *page) 22static inline bool is_migrate_isolate_page(struct page *page)
15{ 23{
16 return false; 24 return false;
diff --git a/include/linux/pci-acpi.h b/include/linux/pci-acpi.h
index 64dacb7288a6..24c7728ca681 100644
--- a/include/linux/pci-acpi.h
+++ b/include/linux/pci-acpi.h
@@ -41,8 +41,13 @@ static inline acpi_handle acpi_pci_get_bridge_handle(struct pci_bus *pbus)
41 41
42 if (pci_is_root_bus(pbus)) 42 if (pci_is_root_bus(pbus))
43 dev = pbus->bridge; 43 dev = pbus->bridge;
44 else 44 else {
45 /* If pbus is a virtual bus, there is no bridge to it */
46 if (!pbus->self)
47 return NULL;
48
45 dev = &pbus->self->dev; 49 dev = &pbus->self->dev;
50 }
46 51
47 return ACPI_HANDLE(dev); 52 return ACPI_HANDLE(dev);
48} 53}
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 5be8db45e368..4c8ac5fcc224 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -331,6 +331,7 @@ struct pci_dev {
331 unsigned int is_added:1; 331 unsigned int is_added:1;
332 unsigned int is_busmaster:1; /* device is busmaster */ 332 unsigned int is_busmaster:1; /* device is busmaster */
333 unsigned int no_msi:1; /* device may not use msi */ 333 unsigned int no_msi:1; /* device may not use msi */
334 unsigned int no_64bit_msi:1; /* device may only use 32-bit MSIs */
334 unsigned int block_cfg_access:1; /* config space access is blocked */ 335 unsigned int block_cfg_access:1; /* config space access is blocked */
335 unsigned int broken_parity_status:1; /* Device generates false positive parity */ 336 unsigned int broken_parity_status:1; /* Device generates false positive parity */
336 unsigned int irq_reroute_variant:2; /* device needs IRQ rerouting variant */ 337 unsigned int irq_reroute_variant:2; /* device needs IRQ rerouting variant */
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 1fa99a301817..97fb9f69aaed 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -522,6 +522,8 @@
522#define PCI_DEVICE_ID_AMD_15H_M10H_F3 0x1403 522#define PCI_DEVICE_ID_AMD_15H_M10H_F3 0x1403
523#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F3 0x141d 523#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F3 0x141d
524#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F4 0x141e 524#define PCI_DEVICE_ID_AMD_15H_M30H_NB_F4 0x141e
525#define PCI_DEVICE_ID_AMD_15H_M60H_NB_F3 0x1573
526#define PCI_DEVICE_ID_AMD_15H_M60H_NB_F4 0x1574
525#define PCI_DEVICE_ID_AMD_15H_NB_F0 0x1600 527#define PCI_DEVICE_ID_AMD_15H_NB_F0 0x1600
526#define PCI_DEVICE_ID_AMD_15H_NB_F1 0x1601 528#define PCI_DEVICE_ID_AMD_15H_NB_F1 0x1601
527#define PCI_DEVICE_ID_AMD_15H_NB_F2 0x1602 529#define PCI_DEVICE_ID_AMD_15H_NB_F2 0x1602
diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index d5c89e0dd0e6..51ce60c35f4c 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -133,7 +133,13 @@ static inline bool __ref_is_percpu(struct percpu_ref *ref,
133 /* paired with smp_store_release() in percpu_ref_reinit() */ 133 /* paired with smp_store_release() in percpu_ref_reinit() */
134 smp_read_barrier_depends(); 134 smp_read_barrier_depends();
135 135
136 if (unlikely(percpu_ptr & __PERCPU_REF_ATOMIC)) 136 /*
137 * Theoretically, the following could test just ATOMIC; however,
138 * then we'd have to mask off DEAD separately as DEAD may be
139 * visible without ATOMIC if we race with percpu_ref_kill(). DEAD
140 * implies ATOMIC anyway. Test them together.
141 */
142 if (unlikely(percpu_ptr & __PERCPU_REF_ATOMIC_DEAD))
137 return false; 143 return false;
138 144
139 *percpu_countp = (unsigned long __percpu *)percpu_ptr; 145 *percpu_countp = (unsigned long __percpu *)percpu_ptr;
diff --git a/include/linux/platform_data/hsmmc-omap.h b/include/linux/platform_data/hsmmc-omap.h
new file mode 100644
index 000000000000..67bbcf0785f6
--- /dev/null
+++ b/include/linux/platform_data/hsmmc-omap.h
@@ -0,0 +1,90 @@
1/*
2 * MMC definitions for OMAP2
3 *
4 * Copyright (C) 2006 Nokia Corporation
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/*
12 * struct omap_hsmmc_dev_attr.flags possibilities
13 *
14 * OMAP_HSMMC_SUPPORTS_DUAL_VOLT: Some HSMMC controller instances can
15 * operate with either 1.8Vdc or 3.0Vdc card voltages; this flag
16 * should be set if this is the case. See for example Section 22.5.3
17 * "MMC/SD/SDIO1 Bus Voltage Selection" of the OMAP34xx Multimedia
18 * Device Silicon Revision 3.1.x Revision ZR (July 2011) (SWPU223R).
19 *
20 * OMAP_HSMMC_BROKEN_MULTIBLOCK_READ: Multiple-block read transfers
21 * don't work correctly on some MMC controller instances on some
22 * OMAP3 SoCs; this flag should be set if this is the case. See
23 * for example Advisory 2.1.1.128 "MMC: Multiple Block Read
24 * Operation Issue" in _OMAP3530/3525/3515/3503 Silicon Errata_
25 * Revision F (October 2010) (SPRZ278F).
26 */
27#define OMAP_HSMMC_SUPPORTS_DUAL_VOLT BIT(0)
28#define OMAP_HSMMC_BROKEN_MULTIBLOCK_READ BIT(1)
29#define OMAP_HSMMC_SWAKEUP_MISSING BIT(2)
30
31struct omap_hsmmc_dev_attr {
32 u8 flags;
33};
34
35struct mmc_card;
36
37struct omap_hsmmc_platform_data {
38 /* back-link to device */
39 struct device *dev;
40
41 /* set if your board has components or wiring that limits the
42 * maximum frequency on the MMC bus */
43 unsigned int max_freq;
44
45 /* Integrating attributes from the omap_hwmod layer */
46 u8 controller_flags;
47
48 /* Register offset deviation */
49 u16 reg_offset;
50
51 /*
52 * 4/8 wires and any additional host capabilities
53 * need to OR'd all capabilities (ref. linux/mmc/host.h)
54 */
55 u32 caps; /* Used for the MMC driver on 2430 and later */
56 u32 pm_caps; /* PM capabilities of the mmc */
57
58 /* switch pin can be for card detect (default) or card cover */
59 unsigned cover:1;
60
61 /* use the internal clock */
62 unsigned internal_clock:1;
63
64 /* nonremovable e.g. eMMC */
65 unsigned nonremovable:1;
66
67 /* eMMC does not handle power off when not in sleep state */
68 unsigned no_regulator_off_init:1;
69
70 /* we can put the features above into this variable */
71#define HSMMC_HAS_PBIAS (1 << 0)
72#define HSMMC_HAS_UPDATED_RESET (1 << 1)
73#define HSMMC_HAS_HSPE_SUPPORT (1 << 2)
74 unsigned features;
75
76 int switch_pin; /* gpio (card detect) */
77 int gpio_wp; /* gpio (write protect) */
78
79 int (*set_power)(struct device *dev, int power_on, int vdd);
80 void (*remux)(struct device *dev, int power_on);
81 /* Call back before enabling / disabling regulators */
82 void (*before_set_reg)(struct device *dev, int power_on, int vdd);
83 /* Call back after enabling / disabling regulators */
84 void (*after_set_reg)(struct device *dev, int power_on, int vdd);
85 /* if we have special card, init it using this callback */
86 void (*init_card)(struct mmc_card *card);
87
88 const char *name;
89 u32 ocr_mask;
90};
diff --git a/arch/arm/mach-at91/include/mach/atmel-mci.h b/include/linux/platform_data/mmc-atmel-mci.h
index 3069e4135573..399a2d5a14bd 100644
--- a/arch/arm/mach-at91/include/mach/atmel-mci.h
+++ b/include/linux/platform_data/mmc-atmel-mci.h
@@ -1,17 +1,22 @@
1#ifndef __MACH_ATMEL_MCI_H 1#ifndef __MMC_ATMEL_MCI_H
2#define __MACH_ATMEL_MCI_H 2#define __MMC_ATMEL_MCI_H
3 3
4#include <linux/platform_data/dma-atmel.h> 4#include <linux/platform_data/dma-atmel.h>
5#include <linux/platform_data/dma-dw.h>
5 6
6/** 7/**
7 * struct mci_dma_data - DMA data for MCI interface 8 * struct mci_dma_data - DMA data for MCI interface
8 */ 9 */
9struct mci_dma_data { 10struct mci_dma_data {
10 struct at_dma_slave sdata; 11#ifdef CONFIG_ARM
12 struct at_dma_slave sdata;
13#else
14 struct dw_dma_slave sdata;
15#endif
11}; 16};
12 17
13/* accessor macros */ 18/* accessor macros */
14#define slave_data_ptr(s) (&(s)->sdata) 19#define slave_data_ptr(s) (&(s)->sdata)
15#define find_slave_dev(s) ((s)->sdata.dma_dev) 20#define find_slave_dev(s) ((s)->sdata.dma_dev)
16 21
17#endif /* __MACH_ATMEL_MCI_H */ 22#endif /* __MMC_ATMEL_MCI_H */
diff --git a/include/linux/platform_data/mmc-omap.h b/include/linux/platform_data/mmc-omap.h
index 51e70cf25cbc..5c188f4e9bec 100644
--- a/include/linux/platform_data/mmc-omap.h
+++ b/include/linux/platform_data/mmc-omap.h
@@ -10,32 +10,8 @@
10 10
11#define OMAP_MMC_MAX_SLOTS 2 11#define OMAP_MMC_MAX_SLOTS 2
12 12
13/*
14 * struct omap_mmc_dev_attr.flags possibilities
15 *
16 * OMAP_HSMMC_SUPPORTS_DUAL_VOLT: Some HSMMC controller instances can
17 * operate with either 1.8Vdc or 3.0Vdc card voltages; this flag
18 * should be set if this is the case. See for example Section 22.5.3
19 * "MMC/SD/SDIO1 Bus Voltage Selection" of the OMAP34xx Multimedia
20 * Device Silicon Revision 3.1.x Revision ZR (July 2011) (SWPU223R).
21 *
22 * OMAP_HSMMC_BROKEN_MULTIBLOCK_READ: Multiple-block read transfers
23 * don't work correctly on some MMC controller instances on some
24 * OMAP3 SoCs; this flag should be set if this is the case. See
25 * for example Advisory 2.1.1.128 "MMC: Multiple Block Read
26 * Operation Issue" in _OMAP3530/3525/3515/3503 Silicon Errata_
27 * Revision F (October 2010) (SPRZ278F).
28 */
29#define OMAP_HSMMC_SUPPORTS_DUAL_VOLT BIT(0)
30#define OMAP_HSMMC_BROKEN_MULTIBLOCK_READ BIT(1)
31#define OMAP_HSMMC_SWAKEUP_MISSING BIT(2)
32
33struct mmc_card; 13struct mmc_card;
34 14
35struct omap_mmc_dev_attr {
36 u8 flags;
37};
38
39struct omap_mmc_platform_data { 15struct omap_mmc_platform_data {
40 /* back-link to device */ 16 /* back-link to device */
41 struct device *dev; 17 struct device *dev;
@@ -106,9 +82,6 @@ struct omap_mmc_platform_data {
106 unsigned vcc_aux_disable_is_sleep:1; 82 unsigned vcc_aux_disable_is_sleep:1;
107 83
108 /* we can put the features above into this variable */ 84 /* we can put the features above into this variable */
109#define HSMMC_HAS_PBIAS (1 << 0)
110#define HSMMC_HAS_UPDATED_RESET (1 << 1)
111#define HSMMC_HAS_HSPE_SUPPORT (1 << 2)
112#define MMC_OMAP7XX (1 << 3) 85#define MMC_OMAP7XX (1 << 3)
113#define MMC_OMAP15XX (1 << 4) 86#define MMC_OMAP15XX (1 << 4)
114#define MMC_OMAP16XX (1 << 5) 87#define MMC_OMAP16XX (1 << 5)
diff --git a/include/linux/platform_data/pxa_sdhci.h b/include/linux/platform_data/pxa_sdhci.h
index 27d3156d093a..9e20c2fb4ffd 100644
--- a/include/linux/platform_data/pxa_sdhci.h
+++ b/include/linux/platform_data/pxa_sdhci.h
@@ -55,9 +55,4 @@ struct sdhci_pxa_platdata {
55 unsigned int quirks2; 55 unsigned int quirks2;
56 unsigned int pm_caps; 56 unsigned int pm_caps;
57}; 57};
58
59struct sdhci_pxa {
60 u8 clk_enable;
61 u8 power_mode;
62};
63#endif /* _PXA_SDHCI_H_ */ 58#endif /* _PXA_SDHCI_H_ */
diff --git a/include/linux/platform_data/serial-omap.h b/include/linux/platform_data/serial-omap.h
index c860c1b314c0..d09275f3cde3 100644
--- a/include/linux/platform_data/serial-omap.h
+++ b/include/linux/platform_data/serial-omap.h
@@ -38,9 +38,6 @@ struct omap_uart_port_info {
38 unsigned int dma_rx_timeout; 38 unsigned int dma_rx_timeout;
39 unsigned int autosuspend_timeout; 39 unsigned int autosuspend_timeout;
40 unsigned int dma_rx_poll_rate; 40 unsigned int dma_rx_poll_rate;
41 int DTR_gpio;
42 int DTR_inverted;
43 int DTR_present;
44 41
45 int (*get_context_loss_count)(struct device *); 42 int (*get_context_loss_count)(struct device *);
46 void (*enable_wakeup)(struct device *, bool); 43 void (*enable_wakeup)(struct device *, bool);
diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
index 73e938b7e937..2e0e06daf8c0 100644
--- a/include/linux/pm_domain.h
+++ b/include/linux/pm_domain.h
@@ -72,8 +72,10 @@ struct generic_pm_domain {
72 bool max_off_time_changed; 72 bool max_off_time_changed;
73 bool cached_power_down_ok; 73 bool cached_power_down_ok;
74 struct gpd_cpuidle_data *cpuidle_data; 74 struct gpd_cpuidle_data *cpuidle_data;
75 void (*attach_dev)(struct device *dev); 75 int (*attach_dev)(struct generic_pm_domain *domain,
76 void (*detach_dev)(struct device *dev); 76 struct device *dev);
77 void (*detach_dev)(struct generic_pm_domain *domain,
78 struct device *dev);
77}; 79};
78 80
79static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd) 81static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
@@ -104,7 +106,7 @@ struct generic_pm_domain_data {
104 struct notifier_block nb; 106 struct notifier_block nb;
105 struct mutex lock; 107 struct mutex lock;
106 unsigned int refcount; 108 unsigned int refcount;
107 bool need_restore; 109 int need_restore;
108}; 110};
109 111
110#ifdef CONFIG_PM_GENERIC_DOMAINS 112#ifdef CONFIG_PM_GENERIC_DOMAINS
diff --git a/include/linux/power/charger-manager.h b/include/linux/power/charger-manager.h
index 07e7945a1ff2..e97fc656a058 100644
--- a/include/linux/power/charger-manager.h
+++ b/include/linux/power/charger-manager.h
@@ -253,9 +253,6 @@ struct charger_manager {
253 struct device *dev; 253 struct device *dev;
254 struct charger_desc *desc; 254 struct charger_desc *desc;
255 255
256 struct power_supply *fuel_gauge;
257 struct power_supply **charger_stat;
258
259#ifdef CONFIG_THERMAL 256#ifdef CONFIG_THERMAL
260 struct thermal_zone_device *tzd_batt; 257 struct thermal_zone_device *tzd_batt;
261#endif 258#endif
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 3ed049673022..096dbced02ac 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -200,6 +200,12 @@ struct power_supply {
200 void (*external_power_changed)(struct power_supply *psy); 200 void (*external_power_changed)(struct power_supply *psy);
201 void (*set_charged)(struct power_supply *psy); 201 void (*set_charged)(struct power_supply *psy);
202 202
203 /*
204 * Set if thermal zone should not be created for this power supply.
205 * For example for virtual supplies forwarding calls to actual
206 * sensors or other supplies.
207 */
208 bool no_thermal;
203 /* For APM emulation, think legacy userspace. */ 209 /* For APM emulation, think legacy userspace. */
204 int use_for_apm; 210 int use_for_apm;
205 211
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index c5ed83f49c4e..4419b99d8d6e 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -27,6 +27,7 @@ struct spmi_device;
27struct regmap; 27struct regmap;
28struct regmap_range_cfg; 28struct regmap_range_cfg;
29struct regmap_field; 29struct regmap_field;
30struct snd_ac97;
30 31
31/* An enum of all the supported cache types */ 32/* An enum of all the supported cache types */
32enum regcache_type { 33enum regcache_type {
@@ -340,6 +341,8 @@ struct regmap *regmap_init_spmi_ext(struct spmi_device *dev,
340struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id, 341struct regmap *regmap_init_mmio_clk(struct device *dev, const char *clk_id,
341 void __iomem *regs, 342 void __iomem *regs,
342 const struct regmap_config *config); 343 const struct regmap_config *config);
344struct regmap *regmap_init_ac97(struct snd_ac97 *ac97,
345 const struct regmap_config *config);
343 346
344struct regmap *devm_regmap_init(struct device *dev, 347struct regmap *devm_regmap_init(struct device *dev,
345 const struct regmap_bus *bus, 348 const struct regmap_bus *bus,
@@ -356,6 +359,10 @@ struct regmap *devm_regmap_init_spmi_ext(struct spmi_device *dev,
356struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id, 359struct regmap *devm_regmap_init_mmio_clk(struct device *dev, const char *clk_id,
357 void __iomem *regs, 360 void __iomem *regs,
358 const struct regmap_config *config); 361 const struct regmap_config *config);
362struct regmap *devm_regmap_init_ac97(struct snd_ac97 *ac97,
363 const struct regmap_config *config);
364
365bool regmap_ac97_default_volatile(struct device *dev, unsigned int reg);
359 366
360/** 367/**
361 * regmap_init_mmio(): Initialise register map 368 * regmap_init_mmio(): Initialise register map
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index f540b1496e2f..d17e1ff7ad01 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -101,6 +101,8 @@ struct regmap;
101 * Data passed is "struct pre_voltage_change_data" 101 * Data passed is "struct pre_voltage_change_data"
102 * ABORT_VOLTAGE_CHANGE Regulator voltage change failed for some reason. 102 * ABORT_VOLTAGE_CHANGE Regulator voltage change failed for some reason.
103 * Data passed is old voltage cast to (void *). 103 * Data passed is old voltage cast to (void *).
104 * PRE_DISABLE Regulator is about to be disabled
105 * ABORT_DISABLE Regulator disable failed for some reason
104 * 106 *
105 * NOTE: These events can be OR'ed together when passed into handler. 107 * NOTE: These events can be OR'ed together when passed into handler.
106 */ 108 */
@@ -115,6 +117,8 @@ struct regmap;
115#define REGULATOR_EVENT_DISABLE 0x80 117#define REGULATOR_EVENT_DISABLE 0x80
116#define REGULATOR_EVENT_PRE_VOLTAGE_CHANGE 0x100 118#define REGULATOR_EVENT_PRE_VOLTAGE_CHANGE 0x100
117#define REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE 0x200 119#define REGULATOR_EVENT_ABORT_VOLTAGE_CHANGE 0x200
120#define REGULATOR_EVENT_PRE_DISABLE 0x400
121#define REGULATOR_EVENT_ABORT_DISABLE 0x800
118 122
119/** 123/**
120 * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event 124 * struct pre_voltage_change_data - Data sent with PRE_VOLTAGE_CHANGE event
@@ -284,7 +288,7 @@ devm_regulator_get(struct device *dev, const char *id)
284static inline struct regulator *__must_check 288static inline struct regulator *__must_check
285regulator_get_exclusive(struct device *dev, const char *id) 289regulator_get_exclusive(struct device *dev, const char *id)
286{ 290{
287 return NULL; 291 return ERR_PTR(-ENODEV);
288} 292}
289 293
290static inline struct regulator *__must_check 294static inline struct regulator *__must_check
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h
index fc0ee0ce8325..5f1e9ca47417 100644
--- a/include/linux/regulator/driver.h
+++ b/include/linux/regulator/driver.h
@@ -243,6 +243,8 @@ enum regulator_type {
243 * 243 *
244 * @enable_time: Time taken for initial enable of regulator (in uS). 244 * @enable_time: Time taken for initial enable of regulator (in uS).
245 * @off_on_delay: guard time (in uS), before re-enabling a regulator 245 * @off_on_delay: guard time (in uS), before re-enabling a regulator
246 *
247 * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode
246 */ 248 */
247struct regulator_desc { 249struct regulator_desc {
248 const char *name; 250 const char *name;
@@ -285,6 +287,8 @@ struct regulator_desc {
285 unsigned int enable_time; 287 unsigned int enable_time;
286 288
287 unsigned int off_on_delay; 289 unsigned int off_on_delay;
290
291 unsigned int (*of_map_mode)(unsigned int mode);
288}; 292};
289 293
290/** 294/**
@@ -301,6 +305,9 @@ struct regulator_desc {
301 * NULL). 305 * NULL).
302 * @regmap: regmap to use for core regmap helpers if dev_get_regulator() is 306 * @regmap: regmap to use for core regmap helpers if dev_get_regulator() is
303 * insufficient. 307 * insufficient.
308 * @ena_gpio_initialized: GPIO controlling regulator enable was properly
309 * initialized, meaning that >= 0 is a valid gpio
310 * identifier and < 0 is a non existent gpio.
304 * @ena_gpio: GPIO controlling regulator enable. 311 * @ena_gpio: GPIO controlling regulator enable.
305 * @ena_gpio_invert: Sense for GPIO enable control. 312 * @ena_gpio_invert: Sense for GPIO enable control.
306 * @ena_gpio_flags: Flags to use when calling gpio_request_one() 313 * @ena_gpio_flags: Flags to use when calling gpio_request_one()
@@ -312,6 +319,7 @@ struct regulator_config {
312 struct device_node *of_node; 319 struct device_node *of_node;
313 struct regmap *regmap; 320 struct regmap *regmap;
314 321
322 bool ena_gpio_initialized;
315 int ena_gpio; 323 int ena_gpio;
316 unsigned int ena_gpio_invert:1; 324 unsigned int ena_gpio_invert:1;
317 unsigned int ena_gpio_flags; 325 unsigned int ena_gpio_flags;
diff --git a/include/linux/regulator/of_regulator.h b/include/linux/regulator/of_regulator.h
index f9217965aaa3..763953f7e3b8 100644
--- a/include/linux/regulator/of_regulator.h
+++ b/include/linux/regulator/of_regulator.h
@@ -6,24 +6,29 @@
6#ifndef __LINUX_OF_REG_H 6#ifndef __LINUX_OF_REG_H
7#define __LINUX_OF_REG_H 7#define __LINUX_OF_REG_H
8 8
9struct regulator_desc;
10
9struct of_regulator_match { 11struct of_regulator_match {
10 const char *name; 12 const char *name;
11 void *driver_data; 13 void *driver_data;
12 struct regulator_init_data *init_data; 14 struct regulator_init_data *init_data;
13 struct device_node *of_node; 15 struct device_node *of_node;
16 const struct regulator_desc *desc;
14}; 17};
15 18
16#if defined(CONFIG_OF) 19#if defined(CONFIG_OF)
17extern struct regulator_init_data 20extern struct regulator_init_data
18 *of_get_regulator_init_data(struct device *dev, 21 *of_get_regulator_init_data(struct device *dev,
19 struct device_node *node); 22 struct device_node *node,
23 const struct regulator_desc *desc);
20extern int of_regulator_match(struct device *dev, struct device_node *node, 24extern int of_regulator_match(struct device *dev, struct device_node *node,
21 struct of_regulator_match *matches, 25 struct of_regulator_match *matches,
22 unsigned int num_matches); 26 unsigned int num_matches);
23#else 27#else
24static inline struct regulator_init_data 28static inline struct regulator_init_data
25 *of_get_regulator_init_data(struct device *dev, 29 *of_get_regulator_init_data(struct device *dev,
26 struct device_node *node) 30 struct device_node *node,
31 const struct regulator_desc *desc)
27{ 32{
28 return NULL; 33 return NULL;
29} 34}
diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
index 49a4d6f59108..e2c13cd863bd 100644
--- a/include/linux/ring_buffer.h
+++ b/include/linux/ring_buffer.h
@@ -97,7 +97,7 @@ __ring_buffer_alloc(unsigned long size, unsigned flags, struct lock_class_key *k
97 __ring_buffer_alloc((size), (flags), &__key); \ 97 __ring_buffer_alloc((size), (flags), &__key); \
98}) 98})
99 99
100int ring_buffer_wait(struct ring_buffer *buffer, int cpu); 100int ring_buffer_wait(struct ring_buffer *buffer, int cpu, bool full);
101int ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu, 101int ring_buffer_poll_wait(struct ring_buffer *buffer, int cpu,
102 struct file *filp, poll_table *poll_table); 102 struct file *filp, poll_table *poll_table);
103 103
diff --git a/include/linux/socket.h b/include/linux/socket.h
index ec538fc287a6..bb9b83640070 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -256,7 +256,7 @@ struct ucred {
256#define MSG_EOF MSG_FIN 256#define MSG_EOF MSG_FIN
257 257
258#define MSG_FASTOPEN 0x20000000 /* Send data in TCP SYN */ 258#define MSG_FASTOPEN 0x20000000 /* Send data in TCP SYN */
259#define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exit for file 259#define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exec for file
260 descriptor received through 260 descriptor received through
261 SCM_RIGHTS */ 261 SCM_RIGHTS */
262#if defined(CONFIG_COMPAT) 262#if defined(CONFIG_COMPAT)
diff --git a/include/linux/vexpress.h b/include/linux/vexpress.h
index a4c9547aae64..f8e76e08ebe4 100644
--- a/include/linux/vexpress.h
+++ b/include/linux/vexpress.h
@@ -15,8 +15,6 @@
15#define _LINUX_VEXPRESS_H 15#define _LINUX_VEXPRESS_H
16 16
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/platform_device.h>
19#include <linux/reboot.h>
20#include <linux/regmap.h> 18#include <linux/regmap.h>
21 19
22#define VEXPRESS_SITE_MB 0 20#define VEXPRESS_SITE_MB 0
@@ -24,13 +22,6 @@
24#define VEXPRESS_SITE_DB2 2 22#define VEXPRESS_SITE_DB2 2
25#define VEXPRESS_SITE_MASTER 0xf 23#define VEXPRESS_SITE_MASTER 0xf
26 24
27#define VEXPRESS_RES_FUNC(_site, _func) \
28{ \
29 .start = (_site), \
30 .end = (_func), \
31 .flags = IORESOURCE_BUS, \
32}
33
34/* Config infrastructure */ 25/* Config infrastructure */
35 26
36void vexpress_config_set_master(u32 site); 27void vexpress_config_set_master(u32 site);
@@ -58,16 +49,6 @@ struct regmap *devm_regmap_init_vexpress_config(struct device *dev);
58 49
59/* Platform control */ 50/* Platform control */
60 51
61unsigned int vexpress_get_mci_cardin(struct device *dev);
62u32 vexpress_get_procid(int site);
63void *vexpress_get_24mhz_clock_base(void);
64void vexpress_flags_set(u32 data); 52void vexpress_flags_set(u32 data);
65 53
66void vexpress_sysreg_early_init(void __iomem *base);
67int vexpress_syscfg_device_register(struct platform_device *pdev);
68
69/* Clocks */
70
71void vexpress_clk_init(void __iomem *sp810_base);
72
73#endif 54#endif
diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
index d9fa68f26c41..2a25dec30211 100644
--- a/include/net/9p/transport.h
+++ b/include/net/9p/transport.h
@@ -34,7 +34,6 @@
34 * @list: used to maintain a list of currently available transports 34 * @list: used to maintain a list of currently available transports
35 * @name: the human-readable name of the transport 35 * @name: the human-readable name of the transport
36 * @maxsize: transport provided maximum packet size 36 * @maxsize: transport provided maximum packet size
37 * @pref: Preferences of this transport
38 * @def: set if this transport should be considered the default 37 * @def: set if this transport should be considered the default
39 * @create: member function to create a new connection on this transport 38 * @create: member function to create a new connection on this transport
40 * @close: member function to discard a connection on this transport 39 * @close: member function to discard a connection on this transport
diff --git a/include/net/inet_common.h b/include/net/inet_common.h
index fe7994c48b75..b2828a06a5a6 100644
--- a/include/net/inet_common.h
+++ b/include/net/inet_common.h
@@ -37,6 +37,8 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
37int inet_ctl_sock_create(struct sock **sk, unsigned short family, 37int inet_ctl_sock_create(struct sock **sk, unsigned short family,
38 unsigned short type, unsigned char protocol, 38 unsigned short type, unsigned char protocol,
39 struct net *net); 39 struct net *net);
40int inet_recv_error(struct sock *sk, struct msghdr *msg, int len,
41 int *addr_len);
40 42
41static inline void inet_ctl_sock_destroy(struct sock *sk) 43static inline void inet_ctl_sock_destroy(struct sock *sk)
42{ 44{
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index 845c596bf594..3ae969e3acf0 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -396,14 +396,12 @@ struct nft_rule {
396/** 396/**
397 * struct nft_trans - nf_tables object update in transaction 397 * struct nft_trans - nf_tables object update in transaction
398 * 398 *
399 * @rcu_head: rcu head to defer release of transaction data
400 * @list: used internally 399 * @list: used internally
401 * @msg_type: message type 400 * @msg_type: message type
402 * @ctx: transaction context 401 * @ctx: transaction context
403 * @data: internal information related to the transaction 402 * @data: internal information related to the transaction
404 */ 403 */
405struct nft_trans { 404struct nft_trans {
406 struct rcu_head rcu_head;
407 struct list_head list; 405 struct list_head list;
408 int msg_type; 406 int msg_type;
409 struct nft_ctx ctx; 407 struct nft_ctx ctx;
diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h
index a47790bcaa38..2a50a70ef587 100644
--- a/include/net/udp_tunnel.h
+++ b/include/net/udp_tunnel.h
@@ -100,6 +100,15 @@ static inline struct sk_buff *udp_tunnel_handle_offloads(struct sk_buff *skb,
100 return iptunnel_handle_offloads(skb, udp_csum, type); 100 return iptunnel_handle_offloads(skb, udp_csum, type);
101} 101}
102 102
103static inline void udp_tunnel_gro_complete(struct sk_buff *skb, int nhoff)
104{
105 struct udphdr *uh;
106
107 uh = (struct udphdr *)(skb->data + nhoff - sizeof(struct udphdr));
108 skb_shinfo(skb)->gso_type |= uh->check ?
109 SKB_GSO_UDP_TUNNEL_CSUM : SKB_GSO_UDP_TUNNEL;
110}
111
103static inline void udp_tunnel_encap_enable(struct socket *sock) 112static inline void udp_tunnel_encap_enable(struct socket *sock)
104{ 113{
105#if IS_ENABLED(CONFIG_IPV6) 114#if IS_ENABLED(CONFIG_IPV6)
diff --git a/include/net/vxlan.h b/include/net/vxlan.h
index d5f59f3fc35d..57cccd0052e5 100644
--- a/include/net/vxlan.h
+++ b/include/net/vxlan.h
@@ -8,6 +8,12 @@
8#define VNI_HASH_BITS 10 8#define VNI_HASH_BITS 10
9#define VNI_HASH_SIZE (1<<VNI_HASH_BITS) 9#define VNI_HASH_SIZE (1<<VNI_HASH_BITS)
10 10
11/* VXLAN protocol header */
12struct vxlanhdr {
13 __be32 vx_flags;
14 __be32 vx_vni;
15};
16
11struct vxlan_sock; 17struct vxlan_sock;
12typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb, __be32 key); 18typedef void (vxlan_rcv_t)(struct vxlan_sock *vh, struct sk_buff *skb, __be32 key);
13 19
@@ -45,6 +51,18 @@ int vxlan_xmit_skb(struct vxlan_sock *vs,
45 __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df, 51 __be32 src, __be32 dst, __u8 tos, __u8 ttl, __be16 df,
46 __be16 src_port, __be16 dst_port, __be32 vni, bool xnet); 52 __be16 src_port, __be16 dst_port, __be32 vni, bool xnet);
47 53
54static inline bool vxlan_gso_check(struct sk_buff *skb)
55{
56 if ((skb_shinfo(skb)->gso_type & SKB_GSO_UDP_TUNNEL) &&
57 (skb->inner_protocol_type != ENCAP_TYPE_ETHER ||
58 skb->inner_protocol != htons(ETH_P_TEB) ||
59 (skb_inner_mac_header(skb) - skb_transport_header(skb) !=
60 sizeof(struct udphdr) + sizeof(struct vxlanhdr))))
61 return false;
62
63 return true;
64}
65
48/* IP header + UDP + VXLAN + Ethernet header */ 66/* IP header + UDP + VXLAN + Ethernet header */
49#define VXLAN_HEADROOM (20 + 8 + 8 + 14) 67#define VXLAN_HEADROOM (20 + 8 + 8 + 14)
50/* IPv6 header + UDP + VXLAN + Ethernet header */ 68/* IPv6 header + UDP + VXLAN + Ethernet header */
diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
index 52beadf9a29b..93d14daf0994 100644
--- a/include/scsi/libfc.h
+++ b/include/scsi/libfc.h
@@ -1105,8 +1105,6 @@ int fc_eh_abort(struct scsi_cmnd *);
1105int fc_eh_device_reset(struct scsi_cmnd *); 1105int fc_eh_device_reset(struct scsi_cmnd *);
1106int fc_eh_host_reset(struct scsi_cmnd *); 1106int fc_eh_host_reset(struct scsi_cmnd *);
1107int fc_slave_alloc(struct scsi_device *); 1107int fc_slave_alloc(struct scsi_device *);
1108int fc_change_queue_depth(struct scsi_device *, int qdepth, int reason);
1109int fc_change_queue_type(struct scsi_device *, int tag_type);
1110 1108
1111/* 1109/*
1112 * ELS/CT interface 1110 * ELS/CT interface
diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h
index 728c9ad9feb0..4d1c46aac331 100644
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -378,8 +378,6 @@ struct iscsi_host {
378/* 378/*
379 * scsi host template 379 * scsi host template
380 */ 380 */
381extern int iscsi_change_queue_depth(struct scsi_device *sdev, int depth,
382 int reason);
383extern int iscsi_eh_abort(struct scsi_cmnd *sc); 381extern int iscsi_eh_abort(struct scsi_cmnd *sc);
384extern int iscsi_eh_recover_target(struct scsi_cmnd *sc); 382extern int iscsi_eh_recover_target(struct scsi_cmnd *sc);
385extern int iscsi_eh_session_reset(struct scsi_cmnd *sc); 383extern int iscsi_eh_session_reset(struct scsi_cmnd *sc);
diff --git a/include/scsi/libsas.h b/include/scsi/libsas.h
index ef7872c20da9..832dcc9f86ec 100644
--- a/include/scsi/libsas.h
+++ b/include/scsi/libsas.h
@@ -365,12 +365,6 @@ struct asd_sas_phy {
365struct scsi_core { 365struct scsi_core {
366 struct Scsi_Host *shost; 366 struct Scsi_Host *shost;
367 367
368 struct mutex task_queue_flush;
369 spinlock_t task_queue_lock;
370 struct list_head task_queue;
371 int task_queue_size;
372
373 struct task_struct *queue_thread;
374}; 368};
375 369
376struct sas_ha_event { 370struct sas_ha_event {
@@ -422,9 +416,6 @@ struct sas_ha_struct {
422 struct asd_sas_port **sas_port; /* array of valid pointers, must be set */ 416 struct asd_sas_port **sas_port; /* array of valid pointers, must be set */
423 int num_phys; /* must be set, gt 0, static */ 417 int num_phys; /* must be set, gt 0, static */
424 418
425 /* The class calls this to send a task for execution. */
426 int lldd_max_execute_num;
427 int lldd_queue_size;
428 int strict_wide_ports; /* both sas_addr and attached_sas_addr must match 419 int strict_wide_ports; /* both sas_addr and attached_sas_addr must match
429 * their siblings when forming wide ports */ 420 * their siblings when forming wide ports */
430 421
@@ -612,7 +603,6 @@ struct sas_ssp_task {
612 603
613struct sas_task { 604struct sas_task {
614 struct domain_device *dev; 605 struct domain_device *dev;
615 struct list_head list;
616 606
617 spinlock_t task_state_lock; 607 spinlock_t task_state_lock;
618 unsigned task_state_flags; 608 unsigned task_state_flags;
@@ -665,8 +655,7 @@ struct sas_domain_function_template {
665 int (*lldd_dev_found)(struct domain_device *); 655 int (*lldd_dev_found)(struct domain_device *);
666 void (*lldd_dev_gone)(struct domain_device *); 656 void (*lldd_dev_gone)(struct domain_device *);
667 657
668 int (*lldd_execute_task)(struct sas_task *, int num, 658 int (*lldd_execute_task)(struct sas_task *, gfp_t gfp_flags);
669 gfp_t gfp_flags);
670 659
671 /* Task Management Functions. Must be called from process context. */ 660 /* Task Management Functions. Must be called from process context. */
672 int (*lldd_abort_task)(struct sas_task *); 661 int (*lldd_abort_task)(struct sas_task *);
@@ -700,12 +689,10 @@ extern void sas_suspend_ha(struct sas_ha_struct *sas_ha);
700int sas_set_phy_speed(struct sas_phy *phy, 689int sas_set_phy_speed(struct sas_phy *phy,
701 struct sas_phy_linkrates *rates); 690 struct sas_phy_linkrates *rates);
702int sas_phy_reset(struct sas_phy *phy, int hard_reset); 691int sas_phy_reset(struct sas_phy *phy, int hard_reset);
703int sas_queue_up(struct sas_task *task);
704extern int sas_queuecommand(struct Scsi_Host * ,struct scsi_cmnd *); 692extern int sas_queuecommand(struct Scsi_Host * ,struct scsi_cmnd *);
705extern int sas_target_alloc(struct scsi_target *); 693extern int sas_target_alloc(struct scsi_target *);
706extern int sas_slave_configure(struct scsi_device *); 694extern int sas_slave_configure(struct scsi_device *);
707extern int sas_change_queue_depth(struct scsi_device *, int new_depth, 695extern int sas_change_queue_depth(struct scsi_device *, int new_depth);
708 int reason);
709extern int sas_change_queue_type(struct scsi_device *, int qt); 696extern int sas_change_queue_type(struct scsi_device *, int qt);
710extern int sas_bios_param(struct scsi_device *, 697extern int sas_bios_param(struct scsi_device *,
711 struct block_device *, 698 struct block_device *,
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index d17178e6fcdd..8a7f8ad58aac 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -128,8 +128,10 @@ enum scsi_timeouts {
128#define MOVE_MEDIUM 0xa5 128#define MOVE_MEDIUM 0xa5
129#define EXCHANGE_MEDIUM 0xa6 129#define EXCHANGE_MEDIUM 0xa6
130#define READ_12 0xa8 130#define READ_12 0xa8
131#define SERVICE_ACTION_OUT_12 0xa9
131#define WRITE_12 0xaa 132#define WRITE_12 0xaa
132#define READ_MEDIA_SERIAL_NUMBER 0xab 133#define READ_MEDIA_SERIAL_NUMBER 0xab /* Obsolete with SPC-2 */
134#define SERVICE_ACTION_IN_12 0xab
133#define WRITE_VERIFY_12 0xae 135#define WRITE_VERIFY_12 0xae
134#define VERIFY_12 0xaf 136#define VERIFY_12 0xaf
135#define SEARCH_HIGH_12 0xb0 137#define SEARCH_HIGH_12 0xb0
@@ -151,7 +153,9 @@ enum scsi_timeouts {
151#define VERIFY_16 0x8f 153#define VERIFY_16 0x8f
152#define SYNCHRONIZE_CACHE_16 0x91 154#define SYNCHRONIZE_CACHE_16 0x91
153#define WRITE_SAME_16 0x93 155#define WRITE_SAME_16 0x93
154#define SERVICE_ACTION_IN 0x9e 156#define SERVICE_ACTION_BIDIRECTIONAL 0x9d
157#define SERVICE_ACTION_IN_16 0x9e
158#define SERVICE_ACTION_OUT_16 0x9f
155/* values for service action in */ 159/* values for service action in */
156#define SAI_READ_CAPACITY_16 0x10 160#define SAI_READ_CAPACITY_16 0x10
157#define SAI_GET_LBA_STATUS 0x12 161#define SAI_GET_LBA_STATUS 0x12
@@ -165,8 +169,8 @@ enum scsi_timeouts {
165#define MI_REPORT_ALIASES 0x0b 169#define MI_REPORT_ALIASES 0x0b
166#define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c 170#define MI_REPORT_SUPPORTED_OPERATION_CODES 0x0c
167#define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d 171#define MI_REPORT_SUPPORTED_TASK_MANAGEMENT_FUNCTIONS 0x0d
168#define MI_REPORT_PRIORITY 0x0e 172#define MI_REPORT_PRIORITY 0x0e
169#define MI_REPORT_TIMESTAMP 0x0f 173#define MI_REPORT_TIMESTAMP 0x0f
170#define MI_MANAGEMENT_PROTOCOL_IN 0x10 174#define MI_MANAGEMENT_PROTOCOL_IN 0x10
171/* value for MI_REPORT_TARGET_PGS ext header */ 175/* value for MI_REPORT_TARGET_PGS ext header */
172#define MI_EXT_HDR_PARAM_FMT 0x20 176#define MI_EXT_HDR_PARAM_FMT 0x20
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 522a5f27f553..9fc1aecfc813 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -53,6 +53,9 @@ struct scsi_pointer {
53 volatile int phase; 53 volatile int phase;
54}; 54};
55 55
56/* for scmd->flags */
57#define SCMD_TAGGED (1 << 0)
58
56struct scsi_cmnd { 59struct scsi_cmnd {
57 struct scsi_device *device; 60 struct scsi_device *device;
58 struct list_head list; /* scsi_cmnd participates in queue lists */ 61 struct list_head list; /* scsi_cmnd participates in queue lists */
@@ -132,6 +135,7 @@ struct scsi_cmnd {
132 * to be at an address < 16Mb). */ 135 * to be at an address < 16Mb). */
133 136
134 int result; /* Status code from lower level driver */ 137 int result; /* Status code from lower level driver */
138 int flags; /* Command flags */
135 139
136 unsigned char tag; /* SCSI-II queued command tag */ 140 unsigned char tag; /* SCSI-II queued command tag */
137}; 141};
@@ -159,7 +163,7 @@ extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
159 size_t *offset, size_t *len); 163 size_t *offset, size_t *len);
160extern void scsi_kunmap_atomic_sg(void *virt); 164extern void scsi_kunmap_atomic_sg(void *virt);
161 165
162extern int scsi_init_io(struct scsi_cmnd *cmd, gfp_t gfp_mask); 166extern int scsi_init_io(struct scsi_cmnd *cmd);
163 167
164extern int scsi_dma_map(struct scsi_cmnd *cmd); 168extern int scsi_dma_map(struct scsi_cmnd *cmd);
165extern void scsi_dma_unmap(struct scsi_cmnd *cmd); 169extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
diff --git a/include/scsi/scsi_dbg.h b/include/scsi/scsi_dbg.h
index e89844cc2cd3..7982795df595 100644
--- a/include/scsi/scsi_dbg.h
+++ b/include/scsi/scsi_dbg.h
@@ -2,23 +2,27 @@
2#define _SCSI_SCSI_DBG_H 2#define _SCSI_SCSI_DBG_H
3 3
4struct scsi_cmnd; 4struct scsi_cmnd;
5struct scsi_device;
5struct scsi_sense_hdr; 6struct scsi_sense_hdr;
6 7
7extern void scsi_print_command(struct scsi_cmnd *); 8extern void scsi_print_command(struct scsi_cmnd *);
8extern void __scsi_print_command(unsigned char *); 9extern void __scsi_print_command(const unsigned char *, size_t);
9extern void scsi_show_extd_sense(unsigned char, unsigned char); 10extern void scsi_show_extd_sense(const struct scsi_device *, const char *,
10extern void scsi_show_sense_hdr(struct scsi_sense_hdr *); 11 unsigned char, unsigned char);
11extern void scsi_print_sense_hdr(const char *, struct scsi_sense_hdr *); 12extern void scsi_show_sense_hdr(const struct scsi_device *, const char *,
12extern void scsi_cmd_print_sense_hdr(struct scsi_cmnd *, const char *, 13 const struct scsi_sense_hdr *);
13 struct scsi_sense_hdr *); 14extern void scsi_print_sense_hdr(const struct scsi_device *, const char *,
14extern void scsi_print_sense(char *, struct scsi_cmnd *); 15 const struct scsi_sense_hdr *);
15extern void __scsi_print_sense(const char *name, 16extern void scsi_print_sense(const struct scsi_cmnd *);
17extern void __scsi_print_sense(const struct scsi_device *, const char *name,
16 const unsigned char *sense_buffer, 18 const unsigned char *sense_buffer,
17 int sense_len); 19 int sense_len);
18extern void scsi_show_result(int); 20extern void scsi_print_result(struct scsi_cmnd *, const char *, int);
19extern void scsi_print_result(struct scsi_cmnd *); 21extern const char *scsi_hostbyte_string(int);
20extern void scsi_print_status(unsigned char); 22extern const char *scsi_driverbyte_string(int);
23extern const char *scsi_mlreturn_string(int);
21extern const char *scsi_sense_key_string(unsigned char); 24extern const char *scsi_sense_key_string(unsigned char);
22extern const char *scsi_extd_sense_format(unsigned char, unsigned char); 25extern const char *scsi_extd_sense_format(unsigned char, unsigned char,
26 const char **);
23 27
24#endif /* _SCSI_SCSI_DBG_H */ 28#endif /* _SCSI_SCSI_DBG_H */
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 27ecee73bd72..6364e23454dd 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -141,7 +141,6 @@ struct scsi_device {
141 unsigned ppr:1; /* Device supports PPR messages */ 141 unsigned ppr:1; /* Device supports PPR messages */
142 unsigned tagged_supported:1; /* Supports SCSI-II tagged queuing */ 142 unsigned tagged_supported:1; /* Supports SCSI-II tagged queuing */
143 unsigned simple_tags:1; /* simple queue tag messages are enabled */ 143 unsigned simple_tags:1; /* simple queue tag messages are enabled */
144 unsigned ordered_tags:1;/* ordered queue tag messages are enabled */
145 unsigned was_reset:1; /* There was a bus reset on the bus for 144 unsigned was_reset:1; /* There was a bus reset on the bus for
146 * this device */ 145 * this device */
147 unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN 146 unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN
@@ -201,11 +200,6 @@ struct scsi_device {
201 unsigned long sdev_data[0]; 200 unsigned long sdev_data[0];
202} __attribute__((aligned(sizeof(unsigned long)))); 201} __attribute__((aligned(sizeof(unsigned long))));
203 202
204struct scsi_dh_devlist {
205 char *vendor;
206 char *model;
207};
208
209typedef void (*activate_complete)(void *, int); 203typedef void (*activate_complete)(void *, int);
210struct scsi_device_handler { 204struct scsi_device_handler {
211 /* Used by the infrastructure */ 205 /* Used by the infrastructure */
@@ -214,9 +208,8 @@ struct scsi_device_handler {
214 /* Filled by the hardware handler */ 208 /* Filled by the hardware handler */
215 struct module *module; 209 struct module *module;
216 const char *name; 210 const char *name;
217 const struct scsi_dh_devlist *devlist;
218 int (*check_sense)(struct scsi_device *, struct scsi_sense_hdr *); 211 int (*check_sense)(struct scsi_device *, struct scsi_sense_hdr *);
219 int (*attach)(struct scsi_device *); 212 struct scsi_dh_data *(*attach)(struct scsi_device *);
220 void (*detach)(struct scsi_device *); 213 void (*detach)(struct scsi_device *);
221 int (*activate)(struct scsi_device *, activate_complete, void *); 214 int (*activate)(struct scsi_device *, activate_complete, void *);
222 int (*prep_fn)(struct scsi_device *, struct request *); 215 int (*prep_fn)(struct scsi_device *, struct request *);
@@ -228,7 +221,6 @@ struct scsi_dh_data {
228 struct scsi_device_handler *scsi_dh; 221 struct scsi_device_handler *scsi_dh;
229 struct scsi_device *sdev; 222 struct scsi_device *sdev;
230 struct kref kref; 223 struct kref kref;
231 char buf[0];
232}; 224};
233 225
234#define to_scsi_device(d) \ 226#define to_scsi_device(d) \
@@ -244,6 +236,15 @@ struct scsi_dh_data {
244#define sdev_dbg(sdev, fmt, a...) \ 236#define sdev_dbg(sdev, fmt, a...) \
245 dev_dbg(&(sdev)->sdev_gendev, fmt, ##a) 237 dev_dbg(&(sdev)->sdev_gendev, fmt, ##a)
246 238
239/*
240 * like scmd_printk, but the device name is passed in
241 * as a string pointer
242 */
243#define sdev_prefix_printk(l, sdev, p, fmt, a...) \
244 (p) ? \
245 sdev_printk(l, sdev, "[%s] " fmt, p, ##a) : \
246 sdev_printk(l, sdev, fmt, ##a)
247
247#define scmd_printk(prefix, scmd, fmt, a...) \ 248#define scmd_printk(prefix, scmd, fmt, a...) \
248 (scmd)->request->rq_disk ? \ 249 (scmd)->request->rq_disk ? \
249 sdev_printk(prefix, (scmd)->device, "[%s] " fmt, \ 250 sdev_printk(prefix, (scmd)->device, "[%s] " fmt, \
@@ -379,7 +380,7 @@ extern struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *,
379#define __shost_for_each_device(sdev, shost) \ 380#define __shost_for_each_device(sdev, shost) \
380 list_for_each_entry((sdev), &((shost)->__devices), siblings) 381 list_for_each_entry((sdev), &((shost)->__devices), siblings)
381 382
382extern void scsi_adjust_queue_depth(struct scsi_device *, int, int); 383extern int scsi_change_queue_depth(struct scsi_device *, int);
383extern int scsi_track_queue_full(struct scsi_device *, int); 384extern int scsi_track_queue_full(struct scsi_device *, int);
384 385
385extern int scsi_set_medium_removal(struct scsi_device *, char); 386extern int scsi_set_medium_removal(struct scsi_device *, char);
diff --git a/include/scsi/scsi_driver.h b/include/scsi/scsi_driver.h
index c2b759809d8a..891a658aa867 100644
--- a/include/scsi/scsi_driver.h
+++ b/include/scsi/scsi_driver.h
@@ -9,7 +9,6 @@ struct scsi_cmnd;
9struct scsi_device; 9struct scsi_device;
10 10
11struct scsi_driver { 11struct scsi_driver {
12 struct module *owner;
13 struct device_driver gendrv; 12 struct device_driver gendrv;
14 13
15 void (*rescan)(struct device *); 14 void (*rescan)(struct device *);
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h
index 06a8790893ef..1e1421b06565 100644
--- a/include/scsi/scsi_eh.h
+++ b/include/scsi/scsi_eh.h
@@ -27,10 +27,10 @@ struct scsi_sense_hdr { /* See SPC-3 section 4.5 */
27 u8 additional_length; /* always 0 for fixed sense format */ 27 u8 additional_length; /* always 0 for fixed sense format */
28}; 28};
29 29
30static inline int scsi_sense_valid(struct scsi_sense_hdr *sshdr) 30static inline bool scsi_sense_valid(const struct scsi_sense_hdr *sshdr)
31{ 31{
32 if (!sshdr) 32 if (!sshdr)
33 return 0; 33 return false;
34 34
35 return (sshdr->response_code & 0x70) == 0x70; 35 return (sshdr->response_code & 0x70) == 0x70;
36} 36}
@@ -42,12 +42,12 @@ extern void scsi_eh_flush_done_q(struct list_head *done_q);
42extern void scsi_report_bus_reset(struct Scsi_Host *, int); 42extern void scsi_report_bus_reset(struct Scsi_Host *, int);
43extern void scsi_report_device_reset(struct Scsi_Host *, int, int); 43extern void scsi_report_device_reset(struct Scsi_Host *, int, int);
44extern int scsi_block_when_processing_errors(struct scsi_device *); 44extern int scsi_block_when_processing_errors(struct scsi_device *);
45extern int scsi_normalize_sense(const u8 *sense_buffer, int sb_len, 45extern bool scsi_normalize_sense(const u8 *sense_buffer, int sb_len,
46 struct scsi_sense_hdr *sshdr); 46 struct scsi_sense_hdr *sshdr);
47extern int scsi_command_normalize_sense(struct scsi_cmnd *cmd, 47extern bool scsi_command_normalize_sense(const struct scsi_cmnd *cmd,
48 struct scsi_sense_hdr *sshdr); 48 struct scsi_sense_hdr *sshdr);
49 49
50static inline int scsi_sense_is_deferred(struct scsi_sense_hdr *sshdr) 50static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *sshdr)
51{ 51{
52 return ((sshdr->response_code >= 0x70) && (sshdr->response_code & 1)); 52 return ((sshdr->response_code >= 0x70) && (sshdr->response_code & 1));
53} 53}
@@ -60,15 +60,7 @@ extern int scsi_get_sense_info_fld(const u8 * sense_buffer, int sb_len,
60 60
61extern void scsi_build_sense_buffer(int desc, u8 *buf, u8 key, u8 asc, u8 ascq); 61extern void scsi_build_sense_buffer(int desc, u8 *buf, u8 key, u8 asc, u8 ascq);
62 62
63/* 63extern int scsi_ioctl_reset(struct scsi_device *, int __user *);
64 * Reset request from external source
65 */
66#define SCSI_TRY_RESET_DEVICE 1
67#define SCSI_TRY_RESET_BUS 2
68#define SCSI_TRY_RESET_HOST 3
69#define SCSI_TRY_RESET_TARGET 4
70
71extern int scsi_reset_provider(struct scsi_device *, int);
72 64
73struct scsi_eh_save { 65struct scsi_eh_save {
74 /* saved state */ 66 /* saved state */
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 5e362489ee88..c8a462ef9a4e 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -46,12 +46,6 @@ struct blk_queue_tags;
46#define DISABLE_CLUSTERING 0 46#define DISABLE_CLUSTERING 0
47#define ENABLE_CLUSTERING 1 47#define ENABLE_CLUSTERING 1
48 48
49enum {
50 SCSI_QDEPTH_DEFAULT, /* default requested change, e.g. from sysfs */
51 SCSI_QDEPTH_QFULL, /* scsi-ml requested due to queue full */
52 SCSI_QDEPTH_RAMP_UP, /* scsi-ml requested due to threshold event */
53};
54
55struct scsi_host_template { 49struct scsi_host_template {
56 struct module *module; 50 struct module *module;
57 const char *name; 51 const char *name;
@@ -195,7 +189,7 @@ struct scsi_host_template {
195 * Things currently recommended to be handled at this time include: 189 * Things currently recommended to be handled at this time include:
196 * 190 *
197 * 1. Setting the device queue depth. Proper setting of this is 191 * 1. Setting the device queue depth. Proper setting of this is
198 * described in the comments for scsi_adjust_queue_depth. 192 * described in the comments for scsi_change_queue_depth.
199 * 2. Determining if the device supports the various synchronous 193 * 2. Determining if the device supports the various synchronous
200 * negotiation protocols. The device struct will already have 194 * negotiation protocols. The device struct will already have
201 * responded to INQUIRY and the results of the standard items 195 * responded to INQUIRY and the results of the standard items
@@ -281,7 +275,7 @@ struct scsi_host_template {
281 * 275 *
282 * Status: OPTIONAL 276 * Status: OPTIONAL
283 */ 277 */
284 int (* change_queue_depth)(struct scsi_device *, int, int); 278 int (* change_queue_depth)(struct scsi_device *, int);
285 279
286 /* 280 /*
287 * Fill in this function to allow the changing of tag types 281 * Fill in this function to allow the changing of tag types
@@ -422,6 +416,16 @@ struct scsi_host_template {
422 unsigned char present; 416 unsigned char present;
423 417
424 /* 418 /*
419 * Let the block layer assigns tags to all commands.
420 */
421 unsigned use_blk_tags:1;
422
423 /*
424 * Track QUEUE_FULL events and reduce queue depth on demand.
425 */
426 unsigned track_queue_depth:1;
427
428 /*
425 * This specifies the mode that a LLD supports. 429 * This specifies the mode that a LLD supports.
426 */ 430 */
427 unsigned supported_mode:2; 431 unsigned supported_mode:2;
@@ -451,11 +455,6 @@ struct scsi_host_template {
451 */ 455 */
452 unsigned skip_settle_delay:1; 456 unsigned skip_settle_delay:1;
453 457
454 /*
455 * True if we are using ordered write support.
456 */
457 unsigned ordered_tag:1;
458
459 /* True if the controller does not support WRITE SAME */ 458 /* True if the controller does not support WRITE SAME */
460 unsigned no_write_same:1; 459 unsigned no_write_same:1;
461 460
@@ -638,6 +637,14 @@ struct Scsi_Host {
638 short unsigned int sg_prot_tablesize; 637 short unsigned int sg_prot_tablesize;
639 unsigned int max_sectors; 638 unsigned int max_sectors;
640 unsigned long dma_boundary; 639 unsigned long dma_boundary;
640 /*
641 * In scsi-mq mode, the number of hardware queues supported by the LLD.
642 *
643 * Note: it is assumed that each hardware queue has a queue depth of
644 * can_queue. In other words, the total queue depth per host
645 * is nr_hw_queues * can_queue.
646 */
647 unsigned nr_hw_queues;
641 /* 648 /*
642 * Used to assign serial numbers to the cmds. 649 * Used to assign serial numbers to the cmds.
643 * Protected by the host lock. 650 * Protected by the host lock.
@@ -647,7 +654,6 @@ struct Scsi_Host {
647 unsigned active_mode:2; 654 unsigned active_mode:2;
648 unsigned unchecked_isa_dma:1; 655 unsigned unchecked_isa_dma:1;
649 unsigned use_clustering:1; 656 unsigned use_clustering:1;
650 unsigned use_blk_tcq:1;
651 657
652 /* 658 /*
653 * Host has requested that no further requests come through for the 659 * Host has requested that no further requests come through for the
@@ -662,11 +668,6 @@ struct Scsi_Host {
662 */ 668 */
663 unsigned reverse_ordering:1; 669 unsigned reverse_ordering:1;
664 670
665 /*
666 * Ordered write support
667 */
668 unsigned ordered_tag:1;
669
670 /* Task mgmt function in progress */ 671 /* Task mgmt function in progress */
671 unsigned tmf_in_progress:1; 672 unsigned tmf_in_progress:1;
672 673
diff --git a/include/scsi/scsi_ioctl.h b/include/scsi/scsi_ioctl.h
index b9006848b813..8d19d1d233c3 100644
--- a/include/scsi/scsi_ioctl.h
+++ b/include/scsi/scsi_ioctl.h
@@ -40,9 +40,9 @@ typedef struct scsi_fctargaddress {
40 unsigned char host_wwn[8]; // include NULL term. 40 unsigned char host_wwn[8]; // include NULL term.
41} Scsi_FCTargAddress; 41} Scsi_FCTargAddress;
42 42
43int scsi_ioctl_block_when_processing_errors(struct scsi_device *sdev,
44 int cmd, bool ndelay);
43extern int scsi_ioctl(struct scsi_device *, int, void __user *); 45extern int scsi_ioctl(struct scsi_device *, int, void __user *);
44extern int scsi_nonblockable_ioctl(struct scsi_device *sdev, int cmd,
45 void __user *arg, int ndelay);
46 46
47#endif /* __KERNEL__ */ 47#endif /* __KERNEL__ */
48#endif /* _SCSI_IOCTL_H */ 48#endif /* _SCSI_IOCTL_H */
diff --git a/include/scsi/scsi_tcq.h b/include/scsi/scsi_tcq.h
index 56ed843969ca..fe4a70299419 100644
--- a/include/scsi/scsi_tcq.h
+++ b/include/scsi/scsi_tcq.h
@@ -16,20 +16,16 @@
16 16
17#ifdef CONFIG_BLOCK 17#ifdef CONFIG_BLOCK
18 18
19int scsi_change_queue_type(struct scsi_device *sdev, int tag_type);
20
19/** 21/**
20 * scsi_get_tag_type - get the type of tag the device supports 22 * scsi_get_tag_type - get the type of tag the device supports
21 * @sdev: the scsi device 23 * @sdev: the scsi device
22 *
23 * Notes:
24 * If the drive only supports simple tags, returns MSG_SIMPLE_TAG
25 * if it supports all tag types, returns MSG_ORDERED_TAG.
26 */ 24 */
27static inline int scsi_get_tag_type(struct scsi_device *sdev) 25static inline int scsi_get_tag_type(struct scsi_device *sdev)
28{ 26{
29 if (!sdev->tagged_supported) 27 if (!sdev->tagged_supported)
30 return 0; 28 return 0;
31 if (sdev->ordered_tags)
32 return MSG_ORDERED_TAG;
33 if (sdev->simple_tags) 29 if (sdev->simple_tags)
34 return MSG_SIMPLE_TAG; 30 return MSG_SIMPLE_TAG;
35 return 0; 31 return 0;
@@ -39,90 +35,33 @@ static inline void scsi_set_tag_type(struct scsi_device *sdev, int tag)
39{ 35{
40 switch (tag) { 36 switch (tag) {
41 case MSG_ORDERED_TAG: 37 case MSG_ORDERED_TAG:
42 sdev->ordered_tags = 1;
43 /* fall through */
44 case MSG_SIMPLE_TAG: 38 case MSG_SIMPLE_TAG:
45 sdev->simple_tags = 1; 39 sdev->simple_tags = 1;
46 break; 40 break;
47 case 0: 41 case 0:
48 /* fall through */ 42 /* fall through */
49 default: 43 default:
50 sdev->ordered_tags = 0;
51 sdev->simple_tags = 0; 44 sdev->simple_tags = 0;
52 break; 45 break;
53 } 46 }
54} 47}
55/**
56 * scsi_activate_tcq - turn on tag command queueing
57 * @SDpnt: device to turn on TCQ for
58 * @depth: queue depth
59 *
60 * Notes:
61 * Eventually, I hope depth would be the maximum depth
62 * the device could cope with and the real queue depth
63 * would be adjustable from 0 to depth.
64 **/
65static inline void scsi_activate_tcq(struct scsi_device *sdev, int depth)
66{
67 if (!sdev->tagged_supported)
68 return;
69
70 if (shost_use_blk_mq(sdev->host))
71 queue_flag_set_unlocked(QUEUE_FLAG_QUEUED, sdev->request_queue);
72 else if (!blk_queue_tagged(sdev->request_queue))
73 blk_queue_init_tags(sdev->request_queue, depth,
74 sdev->host->bqt);
75
76 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), depth);
77}
78
79/**
80 * scsi_deactivate_tcq - turn off tag command queueing
81 * @SDpnt: device to turn off TCQ for
82 **/
83static inline void scsi_deactivate_tcq(struct scsi_device *sdev, int depth)
84{
85 if (blk_queue_tagged(sdev->request_queue))
86 blk_queue_free_tags(sdev->request_queue);
87 scsi_adjust_queue_depth(sdev, 0, depth);
88}
89
90/**
91 * scsi_populate_tag_msg - place a tag message in a buffer
92 * @SCpnt: pointer to the Scsi_Cmnd for the tag
93 * @msg: pointer to the area to place the tag
94 *
95 * Notes:
96 * designed to create the correct type of tag message for the
97 * particular request. Returns the size of the tag message.
98 * May return 0 if TCQ is disabled for this device.
99 **/
100static inline int scsi_populate_tag_msg(struct scsi_cmnd *cmd, char *msg)
101{
102 struct request *req = cmd->request;
103
104 if (blk_rq_tagged(req)) {
105 *msg++ = MSG_SIMPLE_TAG;
106 *msg++ = req->tag;
107 return 2;
108 }
109
110 return 0;
111}
112 48
113static inline struct scsi_cmnd *scsi_mq_find_tag(struct Scsi_Host *shost, 49static inline struct scsi_cmnd *scsi_mq_find_tag(struct Scsi_Host *shost,
114 unsigned int hw_ctx, int tag) 50 int unique_tag)
115{ 51{
116 struct request *req; 52 u16 hwq = blk_mq_unique_tag_to_hwq(unique_tag);
53 struct request *req = NULL;
117 54
118 req = blk_mq_tag_to_rq(shost->tag_set.tags[hw_ctx], tag); 55 if (hwq < shost->tag_set.nr_hw_queues)
56 req = blk_mq_tag_to_rq(shost->tag_set.tags[hwq],
57 blk_mq_unique_tag_to_tag(unique_tag));
119 return req ? (struct scsi_cmnd *)req->special : NULL; 58 return req ? (struct scsi_cmnd *)req->special : NULL;
120} 59}
121 60
122/** 61/**
123 * scsi_find_tag - find a tagged command by device 62 * scsi_find_tag - find a tagged command by device
124 * @SDpnt: pointer to the ScSI device 63 * @SDpnt: pointer to the ScSI device
125 * @tag: the tag number 64 * @tag: tag generated by blk_mq_unique_tag()
126 * 65 *
127 * Notes: 66 * Notes:
128 * Only works with tags allocated by the generic blk layer. 67 * Only works with tags allocated by the generic blk layer.
@@ -133,9 +72,9 @@ static inline struct scsi_cmnd *scsi_find_tag(struct scsi_device *sdev, int tag)
133 72
134 if (tag != SCSI_NO_TAG) { 73 if (tag != SCSI_NO_TAG) {
135 if (shost_use_blk_mq(sdev->host)) 74 if (shost_use_blk_mq(sdev->host))
136 return scsi_mq_find_tag(sdev->host, 0, tag); 75 return scsi_mq_find_tag(sdev->host, tag);
137 76
138 req = blk_queue_find_tag(sdev->request_queue, tag); 77 req = blk_queue_find_tag(sdev->request_queue, tag);
139 return req ? (struct scsi_cmnd *)req->special : NULL; 78 return req ? (struct scsi_cmnd *)req->special : NULL;
140 } 79 }
141 80
@@ -174,7 +113,7 @@ static inline int scsi_init_shared_tag_map(struct Scsi_Host *shost, int depth)
174/** 113/**
175 * scsi_host_find_tag - find the tagged command by host 114 * scsi_host_find_tag - find the tagged command by host
176 * @shost: pointer to scsi_host 115 * @shost: pointer to scsi_host
177 * @tag: tag of the scsi_cmnd 116 * @tag: tag generated by blk_mq_unique_tag()
178 * 117 *
179 * Notes: 118 * Notes:
180 * Only works with tags allocated by the generic blk layer. 119 * Only works with tags allocated by the generic blk layer.
@@ -186,7 +125,7 @@ static inline struct scsi_cmnd *scsi_host_find_tag(struct Scsi_Host *shost,
186 125
187 if (tag != SCSI_NO_TAG) { 126 if (tag != SCSI_NO_TAG) {
188 if (shost_use_blk_mq(shost)) 127 if (shost_use_blk_mq(shost))
189 return scsi_mq_find_tag(shost, 0, tag); 128 return scsi_mq_find_tag(shost, tag);
190 req = blk_map_queue_find_tag(shost->bqt, tag); 129 req = blk_map_queue_find_tag(shost->bqt, tag);
191 return req ? (struct scsi_cmnd *)req->special : NULL; 130 return req ? (struct scsi_cmnd *)req->special : NULL;
192 } 131 }
diff --git a/include/scsi/scsi_transport_spi.h b/include/scsi/scsi_transport_spi.h
index 7497a383b1a4..a4fa52b4d5c5 100644
--- a/include/scsi/scsi_transport_spi.h
+++ b/include/scsi/scsi_transport_spi.h
@@ -157,5 +157,6 @@ int spi_populate_width_msg(unsigned char *msg, int width);
157int spi_populate_sync_msg(unsigned char *msg, int period, int offset); 157int spi_populate_sync_msg(unsigned char *msg, int period, int offset);
158int spi_populate_ppr_msg(unsigned char *msg, int period, int offset, int width, 158int spi_populate_ppr_msg(unsigned char *msg, int period, int offset, int width,
159 int options); 159 int options);
160int spi_populate_tag_msg(unsigned char *msg, struct scsi_cmnd *cmd);
160 161
161#endif /* SCSI_TRANSPORT_SPI_H */ 162#endif /* SCSI_TRANSPORT_SPI_H */
diff --git a/include/scsi/sg.h b/include/scsi/sg.h
index 750e5db7c6bf..3afec7032448 100644
--- a/include/scsi/sg.h
+++ b/include/scsi/sg.h
@@ -164,12 +164,15 @@ typedef struct sg_req_info { /* used by SG_GET_REQUEST_TABLE ioctl() */
164 164
165/* Returns -EBUSY if occupied. 3rd argument pointer to int (see next) */ 165/* Returns -EBUSY if occupied. 3rd argument pointer to int (see next) */
166#define SG_SCSI_RESET 0x2284 166#define SG_SCSI_RESET 0x2284
167/* Associated values that can be given to SG_SCSI_RESET follow */ 167/* Associated values that can be given to SG_SCSI_RESET follow.
168 * SG_SCSI_RESET_NO_ESCALATE may be OR-ed to the _DEVICE, _TARGET, _BUS
169 * or _HOST reset value so only that action is attempted. */
168#define SG_SCSI_RESET_NOTHING 0 170#define SG_SCSI_RESET_NOTHING 0
169#define SG_SCSI_RESET_DEVICE 1 171#define SG_SCSI_RESET_DEVICE 1
170#define SG_SCSI_RESET_BUS 2 172#define SG_SCSI_RESET_BUS 2
171#define SG_SCSI_RESET_HOST 3 173#define SG_SCSI_RESET_HOST 3
172#define SG_SCSI_RESET_TARGET 4 174#define SG_SCSI_RESET_TARGET 4
175#define SG_SCSI_RESET_NO_ESCALATE 0x100
173 176
174/* synchronous SCSI command ioctl, (only in version 3 interface) */ 177/* synchronous SCSI command ioctl, (only in version 3 interface) */
175#define SG_IO 0x2285 /* similar effect as write() followed by read() */ 178#define SG_IO 0x2285 /* similar effect as write() followed by read() */
diff --git a/arch/arm/mach-at91/include/mach/at91rm9200_sdramc.h b/include/soc/at91/at91rm9200_sdramc.h
index aa047f458f1b..aa047f458f1b 100644
--- a/arch/arm/mach-at91/include/mach/at91rm9200_sdramc.h
+++ b/include/soc/at91/at91rm9200_sdramc.h
diff --git a/arch/arm/mach-at91/include/mach/at91sam9_ddrsdr.h b/include/soc/at91/at91sam9_ddrsdr.h
index 0210797abf2e..0210797abf2e 100644
--- a/arch/arm/mach-at91/include/mach/at91sam9_ddrsdr.h
+++ b/include/soc/at91/at91sam9_ddrsdr.h
diff --git a/arch/arm/mach-at91/include/mach/at91sam9_sdramc.h b/include/soc/at91/at91sam9_sdramc.h
index 3d085a9a7450..3d085a9a7450 100644
--- a/arch/arm/mach-at91/include/mach/at91sam9_sdramc.h
+++ b/include/soc/at91/at91sam9_sdramc.h
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index e862497f7556..8bb00a27e219 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -184,6 +184,8 @@ struct snd_pcm_ops {
184#define SNDRV_PCM_FMTBIT_DSD_U8 _SNDRV_PCM_FMTBIT(DSD_U8) 184#define SNDRV_PCM_FMTBIT_DSD_U8 _SNDRV_PCM_FMTBIT(DSD_U8)
185#define SNDRV_PCM_FMTBIT_DSD_U16_LE _SNDRV_PCM_FMTBIT(DSD_U16_LE) 185#define SNDRV_PCM_FMTBIT_DSD_U16_LE _SNDRV_PCM_FMTBIT(DSD_U16_LE)
186#define SNDRV_PCM_FMTBIT_DSD_U32_LE _SNDRV_PCM_FMTBIT(DSD_U32_LE) 186#define SNDRV_PCM_FMTBIT_DSD_U32_LE _SNDRV_PCM_FMTBIT(DSD_U32_LE)
187#define SNDRV_PCM_FMTBIT_DSD_U16_BE _SNDRV_PCM_FMTBIT(DSD_U16_BE)
188#define SNDRV_PCM_FMTBIT_DSD_U32_BE _SNDRV_PCM_FMTBIT(DSD_U32_BE)
187 189
188#ifdef SNDRV_LITTLE_ENDIAN 190#ifdef SNDRV_LITTLE_ENDIAN
189#define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_LE 191#define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_LE
diff --git a/include/sound/soc-dpcm.h b/include/sound/soc-dpcm.h
index 2883a7a6f9f3..98f2ade0266e 100644
--- a/include/sound/soc-dpcm.h
+++ b/include/sound/soc-dpcm.h
@@ -102,6 +102,8 @@ struct snd_soc_dpcm_runtime {
102 /* state and update */ 102 /* state and update */
103 enum snd_soc_dpcm_update runtime_update; 103 enum snd_soc_dpcm_update runtime_update;
104 enum snd_soc_dpcm_state state; 104 enum snd_soc_dpcm_state state;
105
106 int trigger_pending; /* trigger cmd + 1 if pending, 0 if not */
105}; 107};
106 108
107/* can this BE stop and free */ 109/* can this BE stop and free */
diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h
index db6c93510f74..079bd10a01b4 100644
--- a/include/trace/events/scsi.h
+++ b/include/trace/events/scsi.h
@@ -94,7 +94,7 @@
94 scsi_opcode_name(WRITE_16), \ 94 scsi_opcode_name(WRITE_16), \
95 scsi_opcode_name(VERIFY_16), \ 95 scsi_opcode_name(VERIFY_16), \
96 scsi_opcode_name(WRITE_SAME_16), \ 96 scsi_opcode_name(WRITE_SAME_16), \
97 scsi_opcode_name(SERVICE_ACTION_IN), \ 97 scsi_opcode_name(SERVICE_ACTION_IN_16), \
98 scsi_opcode_name(SAI_READ_CAPACITY_16), \ 98 scsi_opcode_name(SAI_READ_CAPACITY_16), \
99 scsi_opcode_name(SAI_GET_LBA_STATUS), \ 99 scsi_opcode_name(SAI_GET_LBA_STATUS), \
100 scsi_opcode_name(MI_REPORT_TARGET_PGS), \ 100 scsi_opcode_name(MI_REPORT_TARGET_PGS), \
diff --git a/include/trace/events/target.h b/include/trace/events/target.h
index da9cc0f05c93..45403443dd82 100644
--- a/include/trace/events/target.h
+++ b/include/trace/events/target.h
@@ -96,7 +96,7 @@
96 scsi_opcode_name(WRITE_16), \ 96 scsi_opcode_name(WRITE_16), \
97 scsi_opcode_name(VERIFY_16), \ 97 scsi_opcode_name(VERIFY_16), \
98 scsi_opcode_name(WRITE_SAME_16), \ 98 scsi_opcode_name(WRITE_SAME_16), \
99 scsi_opcode_name(SERVICE_ACTION_IN), \ 99 scsi_opcode_name(SERVICE_ACTION_IN_16), \
100 scsi_opcode_name(SAI_READ_CAPACITY_16), \ 100 scsi_opcode_name(SAI_READ_CAPACITY_16), \
101 scsi_opcode_name(SAI_GET_LBA_STATUS), \ 101 scsi_opcode_name(SAI_GET_LBA_STATUS), \
102 scsi_opcode_name(MI_REPORT_TARGET_PGS), \ 102 scsi_opcode_name(MI_REPORT_TARGET_PGS), \
diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
index b70237e8bc37..8523f9bb72f2 100644
--- a/include/uapi/linux/Kbuild
+++ b/include/uapi/linux/Kbuild
@@ -125,6 +125,7 @@ header-y += filter.h
125header-y += firewire-cdev.h 125header-y += firewire-cdev.h
126header-y += firewire-constants.h 126header-y += firewire-constants.h
127header-y += flat.h 127header-y += flat.h
128header-y += fou.h
128header-y += fs.h 129header-y += fs.h
129header-y += fsl_hypervisor.h 130header-y += fsl_hypervisor.h
130header-y += fuse.h 131header-y += fuse.h
@@ -141,6 +142,7 @@ header-y += hid.h
141header-y += hiddev.h 142header-y += hiddev.h
142header-y += hidraw.h 143header-y += hidraw.h
143header-y += hpet.h 144header-y += hpet.h
145header-y += hsr_netlink.h
144header-y += hyperv.h 146header-y += hyperv.h
145header-y += hysdn_if.h 147header-y += hysdn_if.h
146header-y += i2c-dev.h 148header-y += i2c-dev.h
@@ -251,6 +253,7 @@ header-y += mii.h
251header-y += minix_fs.h 253header-y += minix_fs.h
252header-y += mman.h 254header-y += mman.h
253header-y += mmtimer.h 255header-y += mmtimer.h
256header-y += mpls.h
254header-y += mqueue.h 257header-y += mqueue.h
255header-y += mroute.h 258header-y += mroute.h
256header-y += mroute6.h 259header-y += mroute6.h
@@ -424,6 +427,7 @@ header-y += virtio_net.h
424header-y += virtio_pci.h 427header-y += virtio_pci.h
425header-y += virtio_ring.h 428header-y += virtio_ring.h
426header-y += virtio_rng.h 429header-y += virtio_rng.h
430header-y += vm_sockets.h
427header-y += vt.h 431header-y += vt.h
428header-y += wait.h 432header-y += wait.h
429header-y += wanrouter.h 433header-y += wanrouter.h
diff --git a/include/uapi/linux/dm-ioctl.h b/include/uapi/linux/dm-ioctl.h
index 3315ab21f728..a570d7b5796c 100644
--- a/include/uapi/linux/dm-ioctl.h
+++ b/include/uapi/linux/dm-ioctl.h
@@ -267,9 +267,9 @@ enum {
267#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl) 267#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
268 268
269#define DM_VERSION_MAJOR 4 269#define DM_VERSION_MAJOR 4
270#define DM_VERSION_MINOR 28 270#define DM_VERSION_MINOR 29
271#define DM_VERSION_PATCHLEVEL 0 271#define DM_VERSION_PATCHLEVEL 0
272#define DM_VERSION_EXTRA "-ioctl (2014-09-17)" 272#define DM_VERSION_EXTRA "-ioctl (2014-10-28)"
273 273
274/* Status bits */ 274/* Status bits */
275#define DM_READONLY_FLAG (1 << 0) /* In/Out */ 275#define DM_READONLY_FLAG (1 << 0) /* In/Out */
@@ -352,4 +352,9 @@ enum {
352 */ 352 */
353#define DM_DEFERRED_REMOVE (1 << 17) /* In/Out */ 353#define DM_DEFERRED_REMOVE (1 << 17) /* In/Out */
354 354
355/*
356 * If set, the device is suspended internally.
357 */
358#define DM_INTERNAL_SUSPEND_FLAG (1 << 18) /* Out */
359
355#endif /* _LINUX_DM_IOCTL_H */ 360#endif /* _LINUX_DM_IOCTL_H */
diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h
index aa90bc98b6e2..ae99f7743cf4 100644
--- a/include/uapi/linux/elf-em.h
+++ b/include/uapi/linux/elf-em.h
@@ -34,6 +34,7 @@
34#define EM_MN10300 89 /* Panasonic/MEI MN10300, AM33 */ 34#define EM_MN10300 89 /* Panasonic/MEI MN10300, AM33 */
35#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ 35#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
36#define EM_BLACKFIN 106 /* ADI Blackfin Processor */ 36#define EM_BLACKFIN 106 /* ADI Blackfin Processor */
37#define EM_ALTERA_NIOS2 113 /* Altera Nios II soft-core processor */
37#define EM_TI_C6000 140 /* TI C6X DSPs */ 38#define EM_TI_C6000 140 /* TI C6X DSPs */
38#define EM_AARCH64 183 /* ARM 64 bit */ 39#define EM_AARCH64 183 /* ARM 64 bit */
39#define EM_FRV 0x5441 /* Fujitsu FR-V */ 40#define EM_FRV 0x5441 /* Fujitsu FR-V */
diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
index ea9bf2561b9e..71e1d0ed92f7 100644
--- a/include/uapi/linux/elf.h
+++ b/include/uapi/linux/elf.h
@@ -397,6 +397,7 @@ typedef struct elf64_shdr {
397#define NT_ARM_TLS 0x401 /* ARM TLS register */ 397#define NT_ARM_TLS 0x401 /* ARM TLS register */
398#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */ 398#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
399#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */ 399#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
400#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
400#define NT_METAG_CBUF 0x500 /* Metag catch buffer registers */ 401#define NT_METAG_CBUF 0x500 /* Metag catch buffer registers */
401#define NT_METAG_RPIPE 0x501 /* Metag read pipeline state */ 402#define NT_METAG_RPIPE 0x501 /* Metag read pipeline state */
402#define NT_METAG_TLS 0x502 /* Metag TLS pointer */ 403#define NT_METAG_TLS 0x502 /* Metag TLS pointer */
diff --git a/include/uapi/linux/if_bridge.h b/include/uapi/linux/if_bridge.h
index 39f621a9fe82..da17e456908d 100644
--- a/include/uapi/linux/if_bridge.h
+++ b/include/uapi/linux/if_bridge.h
@@ -15,6 +15,7 @@
15 15
16#include <linux/types.h> 16#include <linux/types.h>
17#include <linux/if_ether.h> 17#include <linux/if_ether.h>
18#include <linux/in6.h>
18 19
19#define SYSFS_BRIDGE_ATTR "bridge" 20#define SYSFS_BRIDGE_ATTR "bridge"
20#define SYSFS_BRIDGE_FDB "brforward" 21#define SYSFS_BRIDGE_FDB "brforward"
diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h
index 6ee586728df9..941d32f007dc 100644
--- a/include/uapi/sound/asound.h
+++ b/include/uapi/sound/asound.h
@@ -220,7 +220,9 @@ typedef int __bitwise snd_pcm_format_t;
220#define SNDRV_PCM_FORMAT_DSD_U8 ((__force snd_pcm_format_t) 48) /* DSD, 1-byte samples DSD (x8) */ 220#define SNDRV_PCM_FORMAT_DSD_U8 ((__force snd_pcm_format_t) 48) /* DSD, 1-byte samples DSD (x8) */
221#define SNDRV_PCM_FORMAT_DSD_U16_LE ((__force snd_pcm_format_t) 49) /* DSD, 2-byte samples DSD (x16), little endian */ 221#define SNDRV_PCM_FORMAT_DSD_U16_LE ((__force snd_pcm_format_t) 49) /* DSD, 2-byte samples DSD (x16), little endian */
222#define SNDRV_PCM_FORMAT_DSD_U32_LE ((__force snd_pcm_format_t) 50) /* DSD, 4-byte samples DSD (x32), little endian */ 222#define SNDRV_PCM_FORMAT_DSD_U32_LE ((__force snd_pcm_format_t) 50) /* DSD, 4-byte samples DSD (x32), little endian */
223#define SNDRV_PCM_FORMAT_LAST SNDRV_PCM_FORMAT_DSD_U32_LE 223#define SNDRV_PCM_FORMAT_DSD_U16_BE ((__force snd_pcm_format_t) 51) /* DSD, 2-byte samples DSD (x16), big endian */
224#define SNDRV_PCM_FORMAT_DSD_U32_BE ((__force snd_pcm_format_t) 52) /* DSD, 4-byte samples DSD (x32), big endian */
225#define SNDRV_PCM_FORMAT_LAST SNDRV_PCM_FORMAT_DSD_U32_BE
224 226
225#ifdef SNDRV_LITTLE_ENDIAN 227#ifdef SNDRV_LITTLE_ENDIAN
226#define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_LE 228#define SNDRV_PCM_FORMAT_S16 SNDRV_PCM_FORMAT_S16_LE
diff --git a/init/main.c b/init/main.c
index 800a0daede7e..321d0ceb26d3 100644
--- a/init/main.c
+++ b/init/main.c
@@ -544,7 +544,7 @@ asmlinkage __visible void __init start_kernel(void)
544 static_command_line, __start___param, 544 static_command_line, __start___param,
545 __stop___param - __start___param, 545 __stop___param - __start___param,
546 -1, -1, &unknown_bootoption); 546 -1, -1, &unknown_bootoption);
547 if (after_dashes) 547 if (!IS_ERR_OR_NULL(after_dashes))
548 parse_args("Setting init args", after_dashes, NULL, 0, -1, -1, 548 parse_args("Setting init args", after_dashes, NULL, 0, -1, -1,
549 set_init_arg); 549 set_init_arg);
550 550
diff --git a/ipc/sem.c b/ipc/sem.c
index 454f6c6020a8..53c3310f41c6 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -507,13 +507,6 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)
507 return retval; 507 return retval;
508 } 508 }
509 509
510 id = ipc_addid(&sem_ids(ns), &sma->sem_perm, ns->sc_semmni);
511 if (id < 0) {
512 ipc_rcu_putref(sma, sem_rcu_free);
513 return id;
514 }
515 ns->used_sems += nsems;
516
517 sma->sem_base = (struct sem *) &sma[1]; 510 sma->sem_base = (struct sem *) &sma[1];
518 511
519 for (i = 0; i < nsems; i++) { 512 for (i = 0; i < nsems; i++) {
@@ -528,6 +521,14 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)
528 INIT_LIST_HEAD(&sma->list_id); 521 INIT_LIST_HEAD(&sma->list_id);
529 sma->sem_nsems = nsems; 522 sma->sem_nsems = nsems;
530 sma->sem_ctime = get_seconds(); 523 sma->sem_ctime = get_seconds();
524
525 id = ipc_addid(&sem_ids(ns), &sma->sem_perm, ns->sc_semmni);
526 if (id < 0) {
527 ipc_rcu_putref(sma, sem_rcu_free);
528 return id;
529 }
530 ns->used_sems += nsems;
531
531 sem_unlock(sma, -1); 532 sem_unlock(sma, -1);
532 rcu_read_unlock(); 533 rcu_read_unlock();
533 534
diff --git a/kernel/audit.c b/kernel/audit.c
index 80983df92cd4..cebb11db4d34 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -739,7 +739,7 @@ static void audit_log_feature_change(int which, u32 old_feature, u32 new_feature
739 739
740 ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_FEATURE_CHANGE); 740 ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_FEATURE_CHANGE);
741 audit_log_task_info(ab, current); 741 audit_log_task_info(ab, current);
742 audit_log_format(ab, "feature=%s old=%u new=%u old_lock=%u new_lock=%u res=%d", 742 audit_log_format(ab, " feature=%s old=%u new=%u old_lock=%u new_lock=%u res=%d",
743 audit_feature_names[which], !!old_feature, !!new_feature, 743 audit_feature_names[which], !!old_feature, !!new_feature,
744 !!old_lock, !!new_lock, res); 744 !!old_lock, !!new_lock, res);
745 audit_log_end(ab); 745 audit_log_end(ab);
diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
index e242e3a9864a..80f29e015570 100644
--- a/kernel/audit_tree.c
+++ b/kernel/audit_tree.c
@@ -154,6 +154,7 @@ static struct audit_chunk *alloc_chunk(int count)
154 chunk->owners[i].index = i; 154 chunk->owners[i].index = i;
155 } 155 }
156 fsnotify_init_mark(&chunk->mark, audit_tree_destroy_watch); 156 fsnotify_init_mark(&chunk->mark, audit_tree_destroy_watch);
157 chunk->mark.mask = FS_IN_IGNORED;
157 return chunk; 158 return chunk;
158} 159}
159 160
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 2b02c9fda790..1cd5eef1fcdd 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -1562,8 +1562,10 @@ static void perf_remove_from_context(struct perf_event *event, bool detach_group
1562 1562
1563 if (!task) { 1563 if (!task) {
1564 /* 1564 /*
1565 * Per cpu events are removed via an smp call and 1565 * Per cpu events are removed via an smp call. The removal can
1566 * the removal is always successful. 1566 * fail if the CPU is currently offline, but in that case we
1567 * already called __perf_remove_from_context from
1568 * perf_event_exit_cpu.
1567 */ 1569 */
1568 cpu_function_call(event->cpu, __perf_remove_from_context, &re); 1570 cpu_function_call(event->cpu, __perf_remove_from_context, &re);
1569 return; 1571 return;
@@ -8117,7 +8119,7 @@ static void perf_pmu_rotate_stop(struct pmu *pmu)
8117 8119
8118static void __perf_event_exit_context(void *__info) 8120static void __perf_event_exit_context(void *__info)
8119{ 8121{
8120 struct remove_event re = { .detach_group = false }; 8122 struct remove_event re = { .detach_group = true };
8121 struct perf_event_context *ctx = __info; 8123 struct perf_event_context *ctx = __info;
8122 8124
8123 perf_pmu_rotate_stop(ctx->pmu); 8125 perf_pmu_rotate_stop(ctx->pmu);
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 1d0af8a2c646..ed8f2cde34c5 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1640,7 +1640,6 @@ bool uprobe_deny_signal(void)
1640 if (__fatal_signal_pending(t) || arch_uprobe_xol_was_trapped(t)) { 1640 if (__fatal_signal_pending(t) || arch_uprobe_xol_was_trapped(t)) {
1641 utask->state = UTASK_SSTEP_TRAPPED; 1641 utask->state = UTASK_SSTEP_TRAPPED;
1642 set_tsk_thread_flag(t, TIF_UPROBE); 1642 set_tsk_thread_flag(t, TIF_UPROBE);
1643 set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
1644 } 1643 }
1645 } 1644 }
1646 1645
diff --git a/kernel/panic.c b/kernel/panic.c
index d09dc5c32c67..cf80672b7924 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -244,6 +244,7 @@ static const struct tnt tnts[] = {
244 * 'I' - Working around severe firmware bug. 244 * 'I' - Working around severe firmware bug.
245 * 'O' - Out-of-tree module has been loaded. 245 * 'O' - Out-of-tree module has been loaded.
246 * 'E' - Unsigned module has been loaded. 246 * 'E' - Unsigned module has been loaded.
247 * 'L' - A soft lockup has previously occurred.
247 * 248 *
248 * The string is overwritten by the next call to print_tainted(). 249 * The string is overwritten by the next call to print_tainted().
249 */ 250 */
diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c
index 4ca9a33ff620..c347e3ce3a55 100644
--- a/kernel/power/suspend.c
+++ b/kernel/power/suspend.c
@@ -146,7 +146,7 @@ static int platform_suspend_prepare(suspend_state_t state)
146 146
147static int platform_suspend_prepare_late(suspend_state_t state) 147static int platform_suspend_prepare_late(suspend_state_t state)
148{ 148{
149 return state == PM_SUSPEND_FREEZE && freeze_ops->prepare ? 149 return state == PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->prepare ?
150 freeze_ops->prepare() : 0; 150 freeze_ops->prepare() : 0;
151} 151}
152 152
@@ -164,7 +164,7 @@ static void platform_resume_noirq(suspend_state_t state)
164 164
165static void platform_resume_early(suspend_state_t state) 165static void platform_resume_early(suspend_state_t state)
166{ 166{
167 if (state == PM_SUSPEND_FREEZE && freeze_ops->restore) 167 if (state == PM_SUSPEND_FREEZE && freeze_ops && freeze_ops->restore)
168 freeze_ops->restore(); 168 freeze_ops->restore();
169} 169}
170 170
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 240157c13ddc..89e7283015a6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2475,44 +2475,6 @@ EXPORT_PER_CPU_SYMBOL(kstat);
2475EXPORT_PER_CPU_SYMBOL(kernel_cpustat); 2475EXPORT_PER_CPU_SYMBOL(kernel_cpustat);
2476 2476
2477/* 2477/*
2478 * Return any ns on the sched_clock that have not yet been accounted in
2479 * @p in case that task is currently running.
2480 *
2481 * Called with task_rq_lock() held on @rq.
2482 */
2483static u64 do_task_delta_exec(struct task_struct *p, struct rq *rq)
2484{
2485 u64 ns = 0;
2486
2487 /*
2488 * Must be ->curr _and_ ->on_rq. If dequeued, we would
2489 * project cycles that may never be accounted to this
2490 * thread, breaking clock_gettime().
2491 */
2492 if (task_current(rq, p) && task_on_rq_queued(p)) {
2493 update_rq_clock(rq);
2494 ns = rq_clock_task(rq) - p->se.exec_start;
2495 if ((s64)ns < 0)
2496 ns = 0;
2497 }
2498
2499 return ns;
2500}
2501
2502unsigned long long task_delta_exec(struct task_struct *p)
2503{
2504 unsigned long flags;
2505 struct rq *rq;
2506 u64 ns = 0;
2507
2508 rq = task_rq_lock(p, &flags);
2509 ns = do_task_delta_exec(p, rq);
2510 task_rq_unlock(rq, p, &flags);
2511
2512 return ns;
2513}
2514
2515/*
2516 * Return accounted runtime for the task. 2478 * Return accounted runtime for the task.
2517 * In case the task is currently running, return the runtime plus current's 2479 * In case the task is currently running, return the runtime plus current's
2518 * pending runtime that have not been accounted yet. 2480 * pending runtime that have not been accounted yet.
@@ -2521,7 +2483,7 @@ unsigned long long task_sched_runtime(struct task_struct *p)
2521{ 2483{
2522 unsigned long flags; 2484 unsigned long flags;
2523 struct rq *rq; 2485 struct rq *rq;
2524 u64 ns = 0; 2486 u64 ns;
2525 2487
2526#if defined(CONFIG_64BIT) && defined(CONFIG_SMP) 2488#if defined(CONFIG_64BIT) && defined(CONFIG_SMP)
2527 /* 2489 /*
@@ -2540,7 +2502,16 @@ unsigned long long task_sched_runtime(struct task_struct *p)
2540#endif 2502#endif
2541 2503
2542 rq = task_rq_lock(p, &flags); 2504 rq = task_rq_lock(p, &flags);
2543 ns = p->se.sum_exec_runtime + do_task_delta_exec(p, rq); 2505 /*
2506 * Must be ->curr _and_ ->on_rq. If dequeued, we would
2507 * project cycles that may never be accounted to this
2508 * thread, breaking clock_gettime().
2509 */
2510 if (task_current(rq, p) && task_on_rq_queued(p)) {
2511 update_rq_clock(rq);
2512 p->sched_class->update_curr(rq);
2513 }
2514 ns = p->se.sum_exec_runtime;
2544 task_rq_unlock(rq, p, &flags); 2515 task_rq_unlock(rq, p, &flags);
2545 2516
2546 return ns; 2517 return ns;
@@ -2903,10 +2874,14 @@ asmlinkage __visible void __sched schedule_user(void)
2903 * or we have been woken up remotely but the IPI has not yet arrived, 2874 * or we have been woken up remotely but the IPI has not yet arrived,
2904 * we haven't yet exited the RCU idle mode. Do it here manually until 2875 * we haven't yet exited the RCU idle mode. Do it here manually until
2905 * we find a better solution. 2876 * we find a better solution.
2877 *
2878 * NB: There are buggy callers of this function. Ideally we
2879 * should warn if prev_state != IN_USER, but that will trigger
2880 * too frequently to make sense yet.
2906 */ 2881 */
2907 user_exit(); 2882 enum ctx_state prev_state = exception_enter();
2908 schedule(); 2883 schedule();
2909 user_enter(); 2884 exception_exit(prev_state);
2910} 2885}
2911#endif 2886#endif
2912 2887
@@ -6368,6 +6343,10 @@ static void sched_init_numa(void)
6368 if (!sched_debug()) 6343 if (!sched_debug())
6369 break; 6344 break;
6370 } 6345 }
6346
6347 if (!level)
6348 return;
6349
6371 /* 6350 /*
6372 * 'level' contains the number of unique distances, excluding the 6351 * 'level' contains the number of unique distances, excluding the
6373 * identity distance node_distance(i,i). 6352 * identity distance node_distance(i,i).
@@ -7444,8 +7423,12 @@ void sched_move_task(struct task_struct *tsk)
7444 if (unlikely(running)) 7423 if (unlikely(running))
7445 put_prev_task(rq, tsk); 7424 put_prev_task(rq, tsk);
7446 7425
7447 tg = container_of(task_css_check(tsk, cpu_cgrp_id, 7426 /*
7448 lockdep_is_held(&tsk->sighand->siglock)), 7427 * All callers are synchronized by task_rq_lock(); we do not use RCU
7428 * which is pointless here. Thus, we pass "true" to task_css_check()
7429 * to prevent lockdep warnings.
7430 */
7431 tg = container_of(task_css_check(tsk, cpu_cgrp_id, true),
7449 struct task_group, css); 7432 struct task_group, css);
7450 tg = autogroup_task_group(tsk, tg); 7433 tg = autogroup_task_group(tsk, tg);
7451 tsk->sched_task_group = tg; 7434 tsk->sched_task_group = tg;
diff --git a/kernel/sched/deadline.c b/kernel/sched/deadline.c
index 5285332392d5..28fa9d9e9201 100644
--- a/kernel/sched/deadline.c
+++ b/kernel/sched/deadline.c
@@ -1701,4 +1701,6 @@ const struct sched_class dl_sched_class = {
1701 .prio_changed = prio_changed_dl, 1701 .prio_changed = prio_changed_dl,
1702 .switched_from = switched_from_dl, 1702 .switched_from = switched_from_dl,
1703 .switched_to = switched_to_dl, 1703 .switched_to = switched_to_dl,
1704
1705 .update_curr = update_curr_dl,
1704}; 1706};
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 34baa60f8a7b..ef2b104b254c 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -726,6 +726,11 @@ static void update_curr(struct cfs_rq *cfs_rq)
726 account_cfs_rq_runtime(cfs_rq, delta_exec); 726 account_cfs_rq_runtime(cfs_rq, delta_exec);
727} 727}
728 728
729static void update_curr_fair(struct rq *rq)
730{
731 update_curr(cfs_rq_of(&rq->curr->se));
732}
733
729static inline void 734static inline void
730update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se) 735update_stats_wait_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
731{ 736{
@@ -1180,6 +1185,13 @@ static void task_numa_compare(struct task_numa_env *env,
1180 raw_spin_unlock_irq(&dst_rq->lock); 1185 raw_spin_unlock_irq(&dst_rq->lock);
1181 1186
1182 /* 1187 /*
1188 * Because we have preemption enabled we can get migrated around and
1189 * end try selecting ourselves (current == env->p) as a swap candidate.
1190 */
1191 if (cur == env->p)
1192 goto unlock;
1193
1194 /*
1183 * "imp" is the fault differential for the source task between the 1195 * "imp" is the fault differential for the source task between the
1184 * source and destination node. Calculate the total differential for 1196 * source and destination node. Calculate the total differential for
1185 * the source task and potential destination task. The more negative 1197 * the source task and potential destination task. The more negative
@@ -7949,6 +7961,8 @@ const struct sched_class fair_sched_class = {
7949 7961
7950 .get_rr_interval = get_rr_interval_fair, 7962 .get_rr_interval = get_rr_interval_fair,
7951 7963
7964 .update_curr = update_curr_fair,
7965
7952#ifdef CONFIG_FAIR_GROUP_SCHED 7966#ifdef CONFIG_FAIR_GROUP_SCHED
7953 .task_move_group = task_move_group_fair, 7967 .task_move_group = task_move_group_fair,
7954#endif 7968#endif
diff --git a/kernel/sched/idle_task.c b/kernel/sched/idle_task.c
index 67ad4e7f506a..c65dac8c97cd 100644
--- a/kernel/sched/idle_task.c
+++ b/kernel/sched/idle_task.c
@@ -75,6 +75,10 @@ static unsigned int get_rr_interval_idle(struct rq *rq, struct task_struct *task
75 return 0; 75 return 0;
76} 76}
77 77
78static void update_curr_idle(struct rq *rq)
79{
80}
81
78/* 82/*
79 * Simple, special scheduling class for the per-CPU idle tasks: 83 * Simple, special scheduling class for the per-CPU idle tasks:
80 */ 84 */
@@ -101,4 +105,5 @@ const struct sched_class idle_sched_class = {
101 105
102 .prio_changed = prio_changed_idle, 106 .prio_changed = prio_changed_idle,
103 .switched_to = switched_to_idle, 107 .switched_to = switched_to_idle,
108 .update_curr = update_curr_idle,
104}; 109};
diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c
index d024e6ce30ba..20bca398084a 100644
--- a/kernel/sched/rt.c
+++ b/kernel/sched/rt.c
@@ -2128,6 +2128,8 @@ const struct sched_class rt_sched_class = {
2128 2128
2129 .prio_changed = prio_changed_rt, 2129 .prio_changed = prio_changed_rt,
2130 .switched_to = switched_to_rt, 2130 .switched_to = switched_to_rt,
2131
2132 .update_curr = update_curr_rt,
2131}; 2133};
2132 2134
2133#ifdef CONFIG_SCHED_DEBUG 2135#ifdef CONFIG_SCHED_DEBUG
diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
index 24156c8434d1..2df8ef067cc5 100644
--- a/kernel/sched/sched.h
+++ b/kernel/sched/sched.h
@@ -1135,6 +1135,8 @@ struct sched_class {
1135 unsigned int (*get_rr_interval) (struct rq *rq, 1135 unsigned int (*get_rr_interval) (struct rq *rq,
1136 struct task_struct *task); 1136 struct task_struct *task);
1137 1137
1138 void (*update_curr) (struct rq *rq);
1139
1138#ifdef CONFIG_FAIR_GROUP_SCHED 1140#ifdef CONFIG_FAIR_GROUP_SCHED
1139 void (*task_move_group) (struct task_struct *p, int on_rq); 1141 void (*task_move_group) (struct task_struct *p, int on_rq);
1140#endif 1142#endif
diff --git a/kernel/sched/stop_task.c b/kernel/sched/stop_task.c
index 67426e529f59..79ffec45a6ac 100644
--- a/kernel/sched/stop_task.c
+++ b/kernel/sched/stop_task.c
@@ -102,6 +102,10 @@ get_rr_interval_stop(struct rq *rq, struct task_struct *task)
102 return 0; 102 return 0;
103} 103}
104 104
105static void update_curr_stop(struct rq *rq)
106{
107}
108
105/* 109/*
106 * Simple, special scheduling class for the per-CPU stop tasks: 110 * Simple, special scheduling class for the per-CPU stop tasks:
107 */ 111 */
@@ -128,4 +132,5 @@ const struct sched_class stop_sched_class = {
128 132
129 .prio_changed = prio_changed_stop, 133 .prio_changed = prio_changed_stop,
130 .switched_to = switched_to_stop, 134 .switched_to = switched_to_stop,
135 .update_curr = update_curr_stop,
131}; 136};
diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
index 492b986195d5..a16b67859e2a 100644
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -553,7 +553,7 @@ static int cpu_timer_sample_group(const clockid_t which_clock,
553 *sample = cputime_to_expires(cputime.utime); 553 *sample = cputime_to_expires(cputime.utime);
554 break; 554 break;
555 case CPUCLOCK_SCHED: 555 case CPUCLOCK_SCHED:
556 *sample = cputime.sum_exec_runtime + task_delta_exec(p); 556 *sample = cputime.sum_exec_runtime;
557 break; 557 break;
558 } 558 }
559 return 0; 559 return 0;
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 2d75c94ae87d..a56e07c8d15b 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -538,16 +538,18 @@ static void rb_wake_up_waiters(struct irq_work *work)
538 * ring_buffer_wait - wait for input to the ring buffer 538 * ring_buffer_wait - wait for input to the ring buffer
539 * @buffer: buffer to wait on 539 * @buffer: buffer to wait on
540 * @cpu: the cpu buffer to wait on 540 * @cpu: the cpu buffer to wait on
541 * @full: wait until a full page is available, if @cpu != RING_BUFFER_ALL_CPUS
541 * 542 *
542 * If @cpu == RING_BUFFER_ALL_CPUS then the task will wake up as soon 543 * If @cpu == RING_BUFFER_ALL_CPUS then the task will wake up as soon
543 * as data is added to any of the @buffer's cpu buffers. Otherwise 544 * as data is added to any of the @buffer's cpu buffers. Otherwise
544 * it will wait for data to be added to a specific cpu buffer. 545 * it will wait for data to be added to a specific cpu buffer.
545 */ 546 */
546int ring_buffer_wait(struct ring_buffer *buffer, int cpu) 547int ring_buffer_wait(struct ring_buffer *buffer, int cpu, bool full)
547{ 548{
548 struct ring_buffer_per_cpu *cpu_buffer; 549 struct ring_buffer_per_cpu *uninitialized_var(cpu_buffer);
549 DEFINE_WAIT(wait); 550 DEFINE_WAIT(wait);
550 struct rb_irq_work *work; 551 struct rb_irq_work *work;
552 int ret = 0;
551 553
552 /* 554 /*
553 * Depending on what the caller is waiting for, either any 555 * Depending on what the caller is waiting for, either any
@@ -564,36 +566,61 @@ int ring_buffer_wait(struct ring_buffer *buffer, int cpu)
564 } 566 }
565 567
566 568
567 prepare_to_wait(&work->waiters, &wait, TASK_INTERRUPTIBLE); 569 while (true) {
570 prepare_to_wait(&work->waiters, &wait, TASK_INTERRUPTIBLE);
568 571
569 /* 572 /*
570 * The events can happen in critical sections where 573 * The events can happen in critical sections where
571 * checking a work queue can cause deadlocks. 574 * checking a work queue can cause deadlocks.
572 * After adding a task to the queue, this flag is set 575 * After adding a task to the queue, this flag is set
573 * only to notify events to try to wake up the queue 576 * only to notify events to try to wake up the queue
574 * using irq_work. 577 * using irq_work.
575 * 578 *
576 * We don't clear it even if the buffer is no longer 579 * We don't clear it even if the buffer is no longer
577 * empty. The flag only causes the next event to run 580 * empty. The flag only causes the next event to run
578 * irq_work to do the work queue wake up. The worse 581 * irq_work to do the work queue wake up. The worse
579 * that can happen if we race with !trace_empty() is that 582 * that can happen if we race with !trace_empty() is that
580 * an event will cause an irq_work to try to wake up 583 * an event will cause an irq_work to try to wake up
581 * an empty queue. 584 * an empty queue.
582 * 585 *
583 * There's no reason to protect this flag either, as 586 * There's no reason to protect this flag either, as
584 * the work queue and irq_work logic will do the necessary 587 * the work queue and irq_work logic will do the necessary
585 * synchronization for the wake ups. The only thing 588 * synchronization for the wake ups. The only thing
586 * that is necessary is that the wake up happens after 589 * that is necessary is that the wake up happens after
587 * a task has been queued. It's OK for spurious wake ups. 590 * a task has been queued. It's OK for spurious wake ups.
588 */ 591 */
589 work->waiters_pending = true; 592 work->waiters_pending = true;
593
594 if (signal_pending(current)) {
595 ret = -EINTR;
596 break;
597 }
598
599 if (cpu == RING_BUFFER_ALL_CPUS && !ring_buffer_empty(buffer))
600 break;
601
602 if (cpu != RING_BUFFER_ALL_CPUS &&
603 !ring_buffer_empty_cpu(buffer, cpu)) {
604 unsigned long flags;
605 bool pagebusy;
606
607 if (!full)
608 break;
609
610 raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
611 pagebusy = cpu_buffer->reader_page == cpu_buffer->commit_page;
612 raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
613
614 if (!pagebusy)
615 break;
616 }
590 617
591 if ((cpu == RING_BUFFER_ALL_CPUS && ring_buffer_empty(buffer)) ||
592 (cpu != RING_BUFFER_ALL_CPUS && ring_buffer_empty_cpu(buffer, cpu)))
593 schedule(); 618 schedule();
619 }
594 620
595 finish_wait(&work->waiters, &wait); 621 finish_wait(&work->waiters, &wait);
596 return 0; 622
623 return ret;
597} 624}
598 625
599/** 626/**
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8a528392b1f4..92f4a6cee172 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1076,13 +1076,14 @@ update_max_tr_single(struct trace_array *tr, struct task_struct *tsk, int cpu)
1076} 1076}
1077#endif /* CONFIG_TRACER_MAX_TRACE */ 1077#endif /* CONFIG_TRACER_MAX_TRACE */
1078 1078
1079static int wait_on_pipe(struct trace_iterator *iter) 1079static int wait_on_pipe(struct trace_iterator *iter, bool full)
1080{ 1080{
1081 /* Iterators are static, they should be filled or empty */ 1081 /* Iterators are static, they should be filled or empty */
1082 if (trace_buffer_iter(iter, iter->cpu_file)) 1082 if (trace_buffer_iter(iter, iter->cpu_file))
1083 return 0; 1083 return 0;
1084 1084
1085 return ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file); 1085 return ring_buffer_wait(iter->trace_buffer->buffer, iter->cpu_file,
1086 full);
1086} 1087}
1087 1088
1088#ifdef CONFIG_FTRACE_STARTUP_TEST 1089#ifdef CONFIG_FTRACE_STARTUP_TEST
@@ -4434,15 +4435,12 @@ static int tracing_wait_pipe(struct file *filp)
4434 4435
4435 mutex_unlock(&iter->mutex); 4436 mutex_unlock(&iter->mutex);
4436 4437
4437 ret = wait_on_pipe(iter); 4438 ret = wait_on_pipe(iter, false);
4438 4439
4439 mutex_lock(&iter->mutex); 4440 mutex_lock(&iter->mutex);
4440 4441
4441 if (ret) 4442 if (ret)
4442 return ret; 4443 return ret;
4443
4444 if (signal_pending(current))
4445 return -EINTR;
4446 } 4444 }
4447 4445
4448 return 1; 4446 return 1;
@@ -5372,16 +5370,12 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,
5372 goto out_unlock; 5370 goto out_unlock;
5373 } 5371 }
5374 mutex_unlock(&trace_types_lock); 5372 mutex_unlock(&trace_types_lock);
5375 ret = wait_on_pipe(iter); 5373 ret = wait_on_pipe(iter, false);
5376 mutex_lock(&trace_types_lock); 5374 mutex_lock(&trace_types_lock);
5377 if (ret) { 5375 if (ret) {
5378 size = ret; 5376 size = ret;
5379 goto out_unlock; 5377 goto out_unlock;
5380 } 5378 }
5381 if (signal_pending(current)) {
5382 size = -EINTR;
5383 goto out_unlock;
5384 }
5385 goto again; 5379 goto again;
5386 } 5380 }
5387 size = 0; 5381 size = 0;
@@ -5500,7 +5494,7 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
5500 }; 5494 };
5501 struct buffer_ref *ref; 5495 struct buffer_ref *ref;
5502 int entries, size, i; 5496 int entries, size, i;
5503 ssize_t ret; 5497 ssize_t ret = 0;
5504 5498
5505 mutex_lock(&trace_types_lock); 5499 mutex_lock(&trace_types_lock);
5506 5500
@@ -5538,13 +5532,16 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
5538 int r; 5532 int r;
5539 5533
5540 ref = kzalloc(sizeof(*ref), GFP_KERNEL); 5534 ref = kzalloc(sizeof(*ref), GFP_KERNEL);
5541 if (!ref) 5535 if (!ref) {
5536 ret = -ENOMEM;
5542 break; 5537 break;
5538 }
5543 5539
5544 ref->ref = 1; 5540 ref->ref = 1;
5545 ref->buffer = iter->trace_buffer->buffer; 5541 ref->buffer = iter->trace_buffer->buffer;
5546 ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file); 5542 ref->page = ring_buffer_alloc_read_page(ref->buffer, iter->cpu_file);
5547 if (!ref->page) { 5543 if (!ref->page) {
5544 ret = -ENOMEM;
5548 kfree(ref); 5545 kfree(ref);
5549 break; 5546 break;
5550 } 5547 }
@@ -5582,19 +5579,19 @@ tracing_buffers_splice_read(struct file *file, loff_t *ppos,
5582 5579
5583 /* did we read anything? */ 5580 /* did we read anything? */
5584 if (!spd.nr_pages) { 5581 if (!spd.nr_pages) {
5582 if (ret)
5583 goto out;
5584
5585 if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) { 5585 if ((file->f_flags & O_NONBLOCK) || (flags & SPLICE_F_NONBLOCK)) {
5586 ret = -EAGAIN; 5586 ret = -EAGAIN;
5587 goto out; 5587 goto out;
5588 } 5588 }
5589 mutex_unlock(&trace_types_lock); 5589 mutex_unlock(&trace_types_lock);
5590 ret = wait_on_pipe(iter); 5590 ret = wait_on_pipe(iter, true);
5591 mutex_lock(&trace_types_lock); 5591 mutex_lock(&trace_types_lock);
5592 if (ret) 5592 if (ret)
5593 goto out; 5593 goto out;
5594 if (signal_pending(current)) { 5594
5595 ret = -EINTR;
5596 goto out;
5597 }
5598 goto again; 5595 goto again;
5599 } 5596 }
5600 5597
diff --git a/lib/Makefile b/lib/Makefile
index 7512dc978f18..0211d2bd5e17 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -10,7 +10,7 @@ endif
10lib-y := ctype.o string.o vsprintf.o cmdline.o \ 10lib-y := ctype.o string.o vsprintf.o cmdline.o \
11 rbtree.o radix-tree.o dump_stack.o timerqueue.o\ 11 rbtree.o radix-tree.o dump_stack.o timerqueue.o\
12 idr.o int_sqrt.o extable.o \ 12 idr.o int_sqrt.o extable.o \
13 sha1.o md5.o irq_regs.o reciprocal_div.o argv_split.o \ 13 sha1.o md5.o irq_regs.o argv_split.o \
14 proportions.o flex_proportions.o ratelimit.o show_mem.o \ 14 proportions.o flex_proportions.o ratelimit.o show_mem.o \
15 is_single_threaded.o plist.o decompress.o kobject_uevent.o \ 15 is_single_threaded.o plist.o decompress.o kobject_uevent.o \
16 earlycpio.o 16 earlycpio.o
@@ -26,7 +26,7 @@ obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
26 bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \ 26 bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \
27 gcd.o lcm.o list_sort.o uuid.o flex_array.o iovec.o clz_ctz.o \ 27 gcd.o lcm.o list_sort.o uuid.o flex_array.o iovec.o clz_ctz.o \
28 bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o kfifo.o \ 28 bsearch.o find_last_bit.o find_next_bit.o llist.o memweight.o kfifo.o \
29 percpu-refcount.o percpu_ida.o hash.o rhashtable.o 29 percpu-refcount.o percpu_ida.o hash.o rhashtable.o reciprocal_div.o
30obj-y += string_helpers.o 30obj-y += string_helpers.o
31obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o 31obj-$(CONFIG_TEST_STRING_HELPERS) += test-string_helpers.o
32obj-y += kstrtox.o 32obj-y += kstrtox.o
diff --git a/lib/genalloc.c b/lib/genalloc.c
index cce4dd68c40d..2e65d206b01c 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -598,6 +598,7 @@ struct gen_pool *devm_gen_pool_create(struct device *dev, int min_alloc_order,
598 598
599 return pool; 599 return pool;
600} 600}
601EXPORT_SYMBOL(devm_gen_pool_create);
601 602
602/** 603/**
603 * dev_get_gen_pool - Obtain the gen_pool (if any) for a device 604 * dev_get_gen_pool - Obtain the gen_pool (if any) for a device
diff --git a/lib/rhashtable.c b/lib/rhashtable.c
index 081be3ba9ea8..624a0b7c05ef 100644
--- a/lib/rhashtable.c
+++ b/lib/rhashtable.c
@@ -230,7 +230,7 @@ int rhashtable_expand(struct rhashtable *ht, gfp_t flags)
230 ht->shift++; 230 ht->shift++;
231 231
232 /* For each new bucket, search the corresponding old bucket 232 /* For each new bucket, search the corresponding old bucket
233 * for the rst entry that hashes to the new bucket, and 233 * for the first entry that hashes to the new bucket, and
234 * link the new bucket to that entry. Since all the entries 234 * link the new bucket to that entry. Since all the entries
235 * which will end up in the new bucket appear in the same 235 * which will end up in the new bucket appear in the same
236 * old bucket, this constructs an entirely valid new hash 236 * old bucket, this constructs an entirely valid new hash
@@ -248,8 +248,8 @@ int rhashtable_expand(struct rhashtable *ht, gfp_t flags)
248 } 248 }
249 249
250 /* Publish the new table pointer. Lookups may now traverse 250 /* Publish the new table pointer. Lookups may now traverse
251 * the new table, but they will not benet from any 251 * the new table, but they will not benefit from any
252 * additional efciency until later steps unzip the buckets. 252 * additional efficiency until later steps unzip the buckets.
253 */ 253 */
254 rcu_assign_pointer(ht->tbl, new_tbl); 254 rcu_assign_pointer(ht->tbl, new_tbl);
255 255
@@ -306,14 +306,14 @@ int rhashtable_shrink(struct rhashtable *ht, gfp_t flags)
306 306
307 ht->shift--; 307 ht->shift--;
308 308
309 /* Link each bucket in the new table to the rst bucket 309 /* Link each bucket in the new table to the first bucket
310 * in the old table that contains entries which will hash 310 * in the old table that contains entries which will hash
311 * to the new bucket. 311 * to the new bucket.
312 */ 312 */
313 for (i = 0; i < ntbl->size; i++) { 313 for (i = 0; i < ntbl->size; i++) {
314 ntbl->buckets[i] = tbl->buckets[i]; 314 ntbl->buckets[i] = tbl->buckets[i];
315 315
316 /* Link each bucket in the new table to the rst bucket 316 /* Link each bucket in the new table to the first bucket
317 * in the old table that contains entries which will hash 317 * in the old table that contains entries which will hash
318 * to the new bucket. 318 * to the new bucket.
319 */ 319 */
diff --git a/lib/show_mem.c b/lib/show_mem.c
index 09225796991a..5e256271b47b 100644
--- a/lib/show_mem.c
+++ b/lib/show_mem.c
@@ -28,7 +28,7 @@ void show_mem(unsigned int filter)
28 continue; 28 continue;
29 29
30 total += zone->present_pages; 30 total += zone->present_pages;
31 reserved = zone->present_pages - zone->managed_pages; 31 reserved += zone->present_pages - zone->managed_pages;
32 32
33 if (is_highmem_idx(zoneid)) 33 if (is_highmem_idx(zoneid))
34 highmem += zone->present_pages; 34 highmem += zone->present_pages;
diff --git a/mm/bootmem.c b/mm/bootmem.c
index 8a000cebb0d7..477be696511d 100644
--- a/mm/bootmem.c
+++ b/mm/bootmem.c
@@ -243,13 +243,10 @@ static unsigned long __init free_all_bootmem_core(bootmem_data_t *bdata)
243 243
244static int reset_managed_pages_done __initdata; 244static int reset_managed_pages_done __initdata;
245 245
246static inline void __init reset_node_managed_pages(pg_data_t *pgdat) 246void reset_node_managed_pages(pg_data_t *pgdat)
247{ 247{
248 struct zone *z; 248 struct zone *z;
249 249
250 if (reset_managed_pages_done)
251 return;
252
253 for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++) 250 for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
254 z->managed_pages = 0; 251 z->managed_pages = 0;
255} 252}
@@ -258,8 +255,12 @@ void __init reset_all_zones_managed_pages(void)
258{ 255{
259 struct pglist_data *pgdat; 256 struct pglist_data *pgdat;
260 257
258 if (reset_managed_pages_done)
259 return;
260
261 for_each_online_pgdat(pgdat) 261 for_each_online_pgdat(pgdat)
262 reset_node_managed_pages(pgdat); 262 reset_node_managed_pages(pgdat);
263
263 reset_managed_pages_done = 1; 264 reset_managed_pages_done = 1;
264} 265}
265 266
diff --git a/mm/cma.c b/mm/cma.c
index 963bc4add9af..fde706e1284f 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -124,6 +124,7 @@ static int __init cma_activate_area(struct cma *cma)
124 124
125err: 125err:
126 kfree(cma->bitmap); 126 kfree(cma->bitmap);
127 cma->count = 0;
127 return -EINVAL; 128 return -EINVAL;
128} 129}
129 130
@@ -217,9 +218,8 @@ int __init cma_declare_contiguous(phys_addr_t base,
217 phys_addr_t highmem_start = __pa(high_memory); 218 phys_addr_t highmem_start = __pa(high_memory);
218 int ret = 0; 219 int ret = 0;
219 220
220 pr_debug("%s(size %lx, base %08lx, limit %08lx alignment %08lx)\n", 221 pr_debug("%s(size %pa, base %pa, limit %pa alignment %pa)\n",
221 __func__, (unsigned long)size, (unsigned long)base, 222 __func__, &size, &base, &limit, &alignment);
222 (unsigned long)limit, (unsigned long)alignment);
223 223
224 if (cma_area_count == ARRAY_SIZE(cma_areas)) { 224 if (cma_area_count == ARRAY_SIZE(cma_areas)) {
225 pr_err("Not enough slots for CMA reserved regions!\n"); 225 pr_err("Not enough slots for CMA reserved regions!\n");
@@ -244,52 +244,72 @@ int __init cma_declare_contiguous(phys_addr_t base,
244 size = ALIGN(size, alignment); 244 size = ALIGN(size, alignment);
245 limit &= ~(alignment - 1); 245 limit &= ~(alignment - 1);
246 246
247 if (!base)
248 fixed = false;
249
247 /* size should be aligned with order_per_bit */ 250 /* size should be aligned with order_per_bit */
248 if (!IS_ALIGNED(size >> PAGE_SHIFT, 1 << order_per_bit)) 251 if (!IS_ALIGNED(size >> PAGE_SHIFT, 1 << order_per_bit))
249 return -EINVAL; 252 return -EINVAL;
250 253
251 /* 254 /*
252 * adjust limit to avoid crossing low/high memory boundary for 255 * If allocating at a fixed base the request region must not cross the
253 * automatically allocated regions 256 * low/high memory boundary.
254 */ 257 */
255 if (((limit == 0 || limit > memblock_end) && 258 if (fixed && base < highmem_start && base + size > highmem_start) {
256 (memblock_end - size < highmem_start &&
257 memblock_end > highmem_start)) ||
258 (!fixed && limit > highmem_start && limit - size < highmem_start)) {
259 limit = highmem_start;
260 }
261
262 if (fixed && base < highmem_start && base+size > highmem_start) {
263 ret = -EINVAL; 259 ret = -EINVAL;
264 pr_err("Region at %08lx defined on low/high memory boundary (%08lx)\n", 260 pr_err("Region at %pa defined on low/high memory boundary (%pa)\n",
265 (unsigned long)base, (unsigned long)highmem_start); 261 &base, &highmem_start);
266 goto err; 262 goto err;
267 } 263 }
268 264
265 /*
266 * If the limit is unspecified or above the memblock end, its effective
267 * value will be the memblock end. Set it explicitly to simplify further
268 * checks.
269 */
270 if (limit == 0 || limit > memblock_end)
271 limit = memblock_end;
272
269 /* Reserve memory */ 273 /* Reserve memory */
270 if (base && fixed) { 274 if (fixed) {
271 if (memblock_is_region_reserved(base, size) || 275 if (memblock_is_region_reserved(base, size) ||
272 memblock_reserve(base, size) < 0) { 276 memblock_reserve(base, size) < 0) {
273 ret = -EBUSY; 277 ret = -EBUSY;
274 goto err; 278 goto err;
275 } 279 }
276 } else { 280 } else {
277 phys_addr_t addr = memblock_alloc_range(size, alignment, base, 281 phys_addr_t addr = 0;
278 limit); 282
283 /*
284 * All pages in the reserved area must come from the same zone.
285 * If the requested region crosses the low/high memory boundary,
286 * try allocating from high memory first and fall back to low
287 * memory in case of failure.
288 */
289 if (base < highmem_start && limit > highmem_start) {
290 addr = memblock_alloc_range(size, alignment,
291 highmem_start, limit);
292 limit = highmem_start;
293 }
294
279 if (!addr) { 295 if (!addr) {
280 ret = -ENOMEM; 296 addr = memblock_alloc_range(size, alignment, base,
281 goto err; 297 limit);
282 } else { 298 if (!addr) {
283 base = addr; 299 ret = -ENOMEM;
300 goto err;
301 }
284 } 302 }
303
304 base = addr;
285 } 305 }
286 306
287 ret = cma_init_reserved_mem(base, size, order_per_bit, res_cma); 307 ret = cma_init_reserved_mem(base, size, order_per_bit, res_cma);
288 if (ret) 308 if (ret)
289 goto err; 309 goto err;
290 310
291 pr_info("Reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M, 311 pr_info("Reserved %ld MiB at %pa\n", (unsigned long)size / SZ_1M,
292 (unsigned long)base); 312 &base);
293 return 0; 313 return 0;
294 314
295err: 315err:
diff --git a/mm/compaction.c b/mm/compaction.c
index ec74cf0123ef..f9792ba3537c 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -479,6 +479,16 @@ isolate_freepages_range(struct compact_control *cc,
479 479
480 block_end_pfn = min(block_end_pfn, end_pfn); 480 block_end_pfn = min(block_end_pfn, end_pfn);
481 481
482 /*
483 * pfn could pass the block_end_pfn if isolated freepage
484 * is more than pageblock order. In this case, we adjust
485 * scanning range to right one.
486 */
487 if (pfn >= block_end_pfn) {
488 block_end_pfn = ALIGN(pfn + 1, pageblock_nr_pages);
489 block_end_pfn = min(block_end_pfn, end_pfn);
490 }
491
482 if (!pageblock_pfn_to_page(pfn, block_end_pfn, cc->zone)) 492 if (!pageblock_pfn_to_page(pfn, block_end_pfn, cc->zone))
483 break; 493 break;
484 494
@@ -1029,8 +1039,12 @@ static isolate_migrate_t isolate_migratepages(struct zone *zone,
1029 } 1039 }
1030 1040
1031 acct_isolated(zone, cc); 1041 acct_isolated(zone, cc);
1032 /* Record where migration scanner will be restarted */ 1042 /*
1033 cc->migrate_pfn = low_pfn; 1043 * Record where migration scanner will be restarted. If we end up in
1044 * the same pageblock as the free scanner, make the scanners fully
1045 * meet so that compact_finished() terminates compaction.
1046 */
1047 cc->migrate_pfn = (end_pfn <= cc->free_pfn) ? low_pfn : cc->free_pfn;
1034 1048
1035 return cc->nr_migratepages ? ISOLATE_SUCCESS : ISOLATE_NONE; 1049 return cc->nr_migratepages ? ISOLATE_SUCCESS : ISOLATE_NONE;
1036} 1050}
diff --git a/mm/frontswap.c b/mm/frontswap.c
index c30eec536f03..f2a3571c6e22 100644
--- a/mm/frontswap.c
+++ b/mm/frontswap.c
@@ -244,8 +244,10 @@ int __frontswap_store(struct page *page)
244 the (older) page from frontswap 244 the (older) page from frontswap
245 */ 245 */
246 inc_frontswap_failed_stores(); 246 inc_frontswap_failed_stores();
247 if (dup) 247 if (dup) {
248 __frontswap_clear(sis, offset); 248 __frontswap_clear(sis, offset);
249 frontswap_ops->invalidate_page(type, offset);
250 }
249 } 251 }
250 if (frontswap_writethrough_enabled) 252 if (frontswap_writethrough_enabled)
251 /* report failure so swap also writes to swap device */ 253 /* report failure so swap also writes to swap device */
diff --git a/mm/internal.h b/mm/internal.h
index 829304090b90..a4f90ba7068e 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -108,6 +108,31 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
108/* 108/*
109 * in mm/page_alloc.c 109 * in mm/page_alloc.c
110 */ 110 */
111
112/*
113 * Locate the struct page for both the matching buddy in our
114 * pair (buddy1) and the combined O(n+1) page they form (page).
115 *
116 * 1) Any buddy B1 will have an order O twin B2 which satisfies
117 * the following equation:
118 * B2 = B1 ^ (1 << O)
119 * For example, if the starting buddy (buddy2) is #8 its order
120 * 1 buddy is #10:
121 * B2 = 8 ^ (1 << 1) = 8 ^ 2 = 10
122 *
123 * 2) Any buddy B will have an order O+1 parent P which
124 * satisfies the following equation:
125 * P = B & ~(1 << O)
126 *
127 * Assumption: *_mem_map is contiguous at least up to MAX_ORDER
128 */
129static inline unsigned long
130__find_buddy_index(unsigned long page_idx, unsigned int order)
131{
132 return page_idx ^ (1 << order);
133}
134
135extern int __isolate_free_page(struct page *page, unsigned int order);
111extern void __free_pages_bootmem(struct page *page, unsigned int order); 136extern void __free_pages_bootmem(struct page *page, unsigned int order);
112extern void prep_compound_page(struct page *page, unsigned long order); 137extern void prep_compound_page(struct page *page, unsigned long order);
113#ifdef CONFIG_MEMORY_FAILURE 138#ifdef CONFIG_MEMORY_FAILURE
diff --git a/mm/iov_iter.c b/mm/iov_iter.c
index eafcf60f6b83..e34a3cb6aad6 100644
--- a/mm/iov_iter.c
+++ b/mm/iov_iter.c
@@ -911,9 +911,9 @@ size_t iov_iter_single_seg_count(const struct iov_iter *i)
911 if (i->nr_segs == 1) 911 if (i->nr_segs == 1)
912 return i->count; 912 return i->count;
913 else if (i->type & ITER_BVEC) 913 else if (i->type & ITER_BVEC)
914 return min(i->count, i->iov->iov_len - i->iov_offset);
915 else
916 return min(i->count, i->bvec->bv_len - i->iov_offset); 914 return min(i->count, i->bvec->bv_len - i->iov_offset);
915 else
916 return min(i->count, i->iov->iov_len - i->iov_offset);
917} 917}
918EXPORT_SYMBOL(iov_iter_single_seg_count); 918EXPORT_SYMBOL(iov_iter_single_seg_count);
919 919
diff --git a/mm/memory.c b/mm/memory.c
index 3e503831e042..0b3f6c71620d 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -220,9 +220,6 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long
220 /* Is it from 0 to ~0? */ 220 /* Is it from 0 to ~0? */
221 tlb->fullmm = !(start | (end+1)); 221 tlb->fullmm = !(start | (end+1));
222 tlb->need_flush_all = 0; 222 tlb->need_flush_all = 0;
223 tlb->start = start;
224 tlb->end = end;
225 tlb->need_flush = 0;
226 tlb->local.next = NULL; 223 tlb->local.next = NULL;
227 tlb->local.nr = 0; 224 tlb->local.nr = 0;
228 tlb->local.max = ARRAY_SIZE(tlb->__pages); 225 tlb->local.max = ARRAY_SIZE(tlb->__pages);
@@ -232,15 +229,20 @@ void tlb_gather_mmu(struct mmu_gather *tlb, struct mm_struct *mm, unsigned long
232#ifdef CONFIG_HAVE_RCU_TABLE_FREE 229#ifdef CONFIG_HAVE_RCU_TABLE_FREE
233 tlb->batch = NULL; 230 tlb->batch = NULL;
234#endif 231#endif
232
233 __tlb_reset_range(tlb);
235} 234}
236 235
237static void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb) 236static void tlb_flush_mmu_tlbonly(struct mmu_gather *tlb)
238{ 237{
239 tlb->need_flush = 0; 238 if (!tlb->end)
239 return;
240
240 tlb_flush(tlb); 241 tlb_flush(tlb);
241#ifdef CONFIG_HAVE_RCU_TABLE_FREE 242#ifdef CONFIG_HAVE_RCU_TABLE_FREE
242 tlb_table_flush(tlb); 243 tlb_table_flush(tlb);
243#endif 244#endif
245 __tlb_reset_range(tlb);
244} 246}
245 247
246static void tlb_flush_mmu_free(struct mmu_gather *tlb) 248static void tlb_flush_mmu_free(struct mmu_gather *tlb)
@@ -256,8 +258,6 @@ static void tlb_flush_mmu_free(struct mmu_gather *tlb)
256 258
257void tlb_flush_mmu(struct mmu_gather *tlb) 259void tlb_flush_mmu(struct mmu_gather *tlb)
258{ 260{
259 if (!tlb->need_flush)
260 return;
261 tlb_flush_mmu_tlbonly(tlb); 261 tlb_flush_mmu_tlbonly(tlb);
262 tlb_flush_mmu_free(tlb); 262 tlb_flush_mmu_free(tlb);
263} 263}
@@ -292,7 +292,7 @@ int __tlb_remove_page(struct mmu_gather *tlb, struct page *page)
292{ 292{
293 struct mmu_gather_batch *batch; 293 struct mmu_gather_batch *batch;
294 294
295 VM_BUG_ON(!tlb->need_flush); 295 VM_BUG_ON(!tlb->end);
296 296
297 batch = tlb->active; 297 batch = tlb->active;
298 batch->pages[batch->nr++] = page; 298 batch->pages[batch->nr++] = page;
@@ -359,8 +359,6 @@ void tlb_remove_table(struct mmu_gather *tlb, void *table)
359{ 359{
360 struct mmu_table_batch **batch = &tlb->batch; 360 struct mmu_table_batch **batch = &tlb->batch;
361 361
362 tlb->need_flush = 1;
363
364 /* 362 /*
365 * When there's less then two users of this mm there cannot be a 363 * When there's less then two users of this mm there cannot be a
366 * concurrent page-table walk. 364 * concurrent page-table walk.
@@ -815,20 +813,20 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
815 if (!pte_file(pte)) { 813 if (!pte_file(pte)) {
816 swp_entry_t entry = pte_to_swp_entry(pte); 814 swp_entry_t entry = pte_to_swp_entry(pte);
817 815
818 if (swap_duplicate(entry) < 0) 816 if (likely(!non_swap_entry(entry))) {
819 return entry.val; 817 if (swap_duplicate(entry) < 0)
820 818 return entry.val;
821 /* make sure dst_mm is on swapoff's mmlist. */ 819
822 if (unlikely(list_empty(&dst_mm->mmlist))) { 820 /* make sure dst_mm is on swapoff's mmlist. */
823 spin_lock(&mmlist_lock); 821 if (unlikely(list_empty(&dst_mm->mmlist))) {
824 if (list_empty(&dst_mm->mmlist)) 822 spin_lock(&mmlist_lock);
825 list_add(&dst_mm->mmlist, 823 if (list_empty(&dst_mm->mmlist))
826 &src_mm->mmlist); 824 list_add(&dst_mm->mmlist,
827 spin_unlock(&mmlist_lock); 825 &src_mm->mmlist);
828 } 826 spin_unlock(&mmlist_lock);
829 if (likely(!non_swap_entry(entry))) 827 }
830 rss[MM_SWAPENTS]++; 828 rss[MM_SWAPENTS]++;
831 else if (is_migration_entry(entry)) { 829 } else if (is_migration_entry(entry)) {
832 page = migration_entry_to_page(entry); 830 page = migration_entry_to_page(entry);
833 831
834 if (PageAnon(page)) 832 if (PageAnon(page))
@@ -1186,20 +1184,8 @@ again:
1186 arch_leave_lazy_mmu_mode(); 1184 arch_leave_lazy_mmu_mode();
1187 1185
1188 /* Do the actual TLB flush before dropping ptl */ 1186 /* Do the actual TLB flush before dropping ptl */
1189 if (force_flush) { 1187 if (force_flush)
1190 unsigned long old_end;
1191
1192 /*
1193 * Flush the TLB just for the previous segment,
1194 * then update the range to be the remaining
1195 * TLB range.
1196 */
1197 old_end = tlb->end;
1198 tlb->end = addr;
1199 tlb_flush_mmu_tlbonly(tlb); 1188 tlb_flush_mmu_tlbonly(tlb);
1200 tlb->start = addr;
1201 tlb->end = old_end;
1202 }
1203 pte_unmap_unlock(start_pte, ptl); 1189 pte_unmap_unlock(start_pte, ptl);
1204 1190
1205 /* 1191 /*
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 252e1dbbed86..1bf4807cb21e 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -31,6 +31,7 @@
31#include <linux/stop_machine.h> 31#include <linux/stop_machine.h>
32#include <linux/hugetlb.h> 32#include <linux/hugetlb.h>
33#include <linux/memblock.h> 33#include <linux/memblock.h>
34#include <linux/bootmem.h>
34 35
35#include <asm/tlbflush.h> 36#include <asm/tlbflush.h>
36 37
@@ -1066,6 +1067,16 @@ out:
1066} 1067}
1067#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ 1068#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
1068 1069
1070static void reset_node_present_pages(pg_data_t *pgdat)
1071{
1072 struct zone *z;
1073
1074 for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
1075 z->present_pages = 0;
1076
1077 pgdat->node_present_pages = 0;
1078}
1079
1069/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ 1080/* we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */
1070static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start) 1081static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
1071{ 1082{
@@ -1096,6 +1107,21 @@ static pg_data_t __ref *hotadd_new_pgdat(int nid, u64 start)
1096 build_all_zonelists(pgdat, NULL); 1107 build_all_zonelists(pgdat, NULL);
1097 mutex_unlock(&zonelists_mutex); 1108 mutex_unlock(&zonelists_mutex);
1098 1109
1110 /*
1111 * zone->managed_pages is set to an approximate value in
1112 * free_area_init_core(), which will cause
1113 * /sys/device/system/node/nodeX/meminfo has wrong data.
1114 * So reset it to 0 before any memory is onlined.
1115 */
1116 reset_node_managed_pages(pgdat);
1117
1118 /*
1119 * When memory is hot-added, all the memory is in offline state. So
1120 * clear all zones' present_pages because they will be updated in
1121 * online_pages() and offline_pages().
1122 */
1123 reset_node_present_pages(pgdat);
1124
1099 return pgdat; 1125 return pgdat;
1100} 1126}
1101 1127
diff --git a/mm/mmap.c b/mm/mmap.c
index 87e82b38453c..ae919891a087 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -776,8 +776,11 @@ again: remove_next = 1 + (end > next->vm_end);
776 * shrinking vma had, to cover any anon pages imported. 776 * shrinking vma had, to cover any anon pages imported.
777 */ 777 */
778 if (exporter && exporter->anon_vma && !importer->anon_vma) { 778 if (exporter && exporter->anon_vma && !importer->anon_vma) {
779 if (anon_vma_clone(importer, exporter)) 779 int error;
780 return -ENOMEM; 780
781 error = anon_vma_clone(importer, exporter);
782 if (error)
783 return error;
781 importer->anon_vma = exporter->anon_vma; 784 importer->anon_vma = exporter->anon_vma;
782 } 785 }
783 } 786 }
@@ -2469,7 +2472,8 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
2469 if (err) 2472 if (err)
2470 goto out_free_vma; 2473 goto out_free_vma;
2471 2474
2472 if (anon_vma_clone(new, vma)) 2475 err = anon_vma_clone(new, vma);
2476 if (err)
2473 goto out_free_mpol; 2477 goto out_free_mpol;
2474 2478
2475 if (new->vm_file) 2479 if (new->vm_file)
diff --git a/mm/nobootmem.c b/mm/nobootmem.c
index 7c7ab32ee503..90b50468333e 100644
--- a/mm/nobootmem.c
+++ b/mm/nobootmem.c
@@ -145,12 +145,10 @@ static unsigned long __init free_low_memory_core_early(void)
145 145
146static int reset_managed_pages_done __initdata; 146static int reset_managed_pages_done __initdata;
147 147
148static inline void __init reset_node_managed_pages(pg_data_t *pgdat) 148void reset_node_managed_pages(pg_data_t *pgdat)
149{ 149{
150 struct zone *z; 150 struct zone *z;
151 151
152 if (reset_managed_pages_done)
153 return;
154 for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++) 152 for (z = pgdat->node_zones; z < pgdat->node_zones + MAX_NR_ZONES; z++)
155 z->managed_pages = 0; 153 z->managed_pages = 0;
156} 154}
@@ -159,8 +157,12 @@ void __init reset_all_zones_managed_pages(void)
159{ 157{
160 struct pglist_data *pgdat; 158 struct pglist_data *pgdat;
161 159
160 if (reset_managed_pages_done)
161 return;
162
162 for_each_online_pgdat(pgdat) 163 for_each_online_pgdat(pgdat)
163 reset_node_managed_pages(pgdat); 164 reset_node_managed_pages(pgdat);
165
164 reset_managed_pages_done = 1; 166 reset_managed_pages_done = 1;
165} 167}
166 168
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 9cd36b822444..616a2c956b4b 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -467,29 +467,6 @@ static inline void rmv_page_order(struct page *page)
467} 467}
468 468
469/* 469/*
470 * Locate the struct page for both the matching buddy in our
471 * pair (buddy1) and the combined O(n+1) page they form (page).
472 *
473 * 1) Any buddy B1 will have an order O twin B2 which satisfies
474 * the following equation:
475 * B2 = B1 ^ (1 << O)
476 * For example, if the starting buddy (buddy2) is #8 its order
477 * 1 buddy is #10:
478 * B2 = 8 ^ (1 << 1) = 8 ^ 2 = 10
479 *
480 * 2) Any buddy B will have an order O+1 parent P which
481 * satisfies the following equation:
482 * P = B & ~(1 << O)
483 *
484 * Assumption: *_mem_map is contiguous at least up to MAX_ORDER
485 */
486static inline unsigned long
487__find_buddy_index(unsigned long page_idx, unsigned int order)
488{
489 return page_idx ^ (1 << order);
490}
491
492/*
493 * This function checks whether a page is free && is the buddy 470 * This function checks whether a page is free && is the buddy
494 * we can do coalesce a page and its buddy if 471 * we can do coalesce a page and its buddy if
495 * (a) the buddy is not in a hole && 472 * (a) the buddy is not in a hole &&
@@ -569,6 +546,7 @@ static inline void __free_one_page(struct page *page,
569 unsigned long combined_idx; 546 unsigned long combined_idx;
570 unsigned long uninitialized_var(buddy_idx); 547 unsigned long uninitialized_var(buddy_idx);
571 struct page *buddy; 548 struct page *buddy;
549 int max_order = MAX_ORDER;
572 550
573 VM_BUG_ON(!zone_is_initialized(zone)); 551 VM_BUG_ON(!zone_is_initialized(zone));
574 552
@@ -577,13 +555,24 @@ static inline void __free_one_page(struct page *page,
577 return; 555 return;
578 556
579 VM_BUG_ON(migratetype == -1); 557 VM_BUG_ON(migratetype == -1);
558 if (is_migrate_isolate(migratetype)) {
559 /*
560 * We restrict max order of merging to prevent merge
561 * between freepages on isolate pageblock and normal
562 * pageblock. Without this, pageblock isolation
563 * could cause incorrect freepage accounting.
564 */
565 max_order = min(MAX_ORDER, pageblock_order + 1);
566 } else {
567 __mod_zone_freepage_state(zone, 1 << order, migratetype);
568 }
580 569
581 page_idx = pfn & ((1 << MAX_ORDER) - 1); 570 page_idx = pfn & ((1 << max_order) - 1);
582 571
583 VM_BUG_ON_PAGE(page_idx & ((1 << order) - 1), page); 572 VM_BUG_ON_PAGE(page_idx & ((1 << order) - 1), page);
584 VM_BUG_ON_PAGE(bad_range(zone, page), page); 573 VM_BUG_ON_PAGE(bad_range(zone, page), page);
585 574
586 while (order < MAX_ORDER-1) { 575 while (order < max_order - 1) {
587 buddy_idx = __find_buddy_index(page_idx, order); 576 buddy_idx = __find_buddy_index(page_idx, order);
588 buddy = page + (buddy_idx - page_idx); 577 buddy = page + (buddy_idx - page_idx);
589 if (!page_is_buddy(page, buddy, order)) 578 if (!page_is_buddy(page, buddy, order))
@@ -594,9 +583,11 @@ static inline void __free_one_page(struct page *page,
594 */ 583 */
595 if (page_is_guard(buddy)) { 584 if (page_is_guard(buddy)) {
596 clear_page_guard_flag(buddy); 585 clear_page_guard_flag(buddy);
597 set_page_private(page, 0); 586 set_page_private(buddy, 0);
598 __mod_zone_freepage_state(zone, 1 << order, 587 if (!is_migrate_isolate(migratetype)) {
599 migratetype); 588 __mod_zone_freepage_state(zone, 1 << order,
589 migratetype);
590 }
600 } else { 591 } else {
601 list_del(&buddy->lru); 592 list_del(&buddy->lru);
602 zone->free_area[order].nr_free--; 593 zone->free_area[order].nr_free--;
@@ -715,14 +706,12 @@ static void free_pcppages_bulk(struct zone *zone, int count,
715 /* must delete as __free_one_page list manipulates */ 706 /* must delete as __free_one_page list manipulates */
716 list_del(&page->lru); 707 list_del(&page->lru);
717 mt = get_freepage_migratetype(page); 708 mt = get_freepage_migratetype(page);
709 if (unlikely(has_isolate_pageblock(zone)))
710 mt = get_pageblock_migratetype(page);
711
718 /* MIGRATE_MOVABLE list may include MIGRATE_RESERVEs */ 712 /* MIGRATE_MOVABLE list may include MIGRATE_RESERVEs */
719 __free_one_page(page, page_to_pfn(page), zone, 0, mt); 713 __free_one_page(page, page_to_pfn(page), zone, 0, mt);
720 trace_mm_page_pcpu_drain(page, 0, mt); 714 trace_mm_page_pcpu_drain(page, 0, mt);
721 if (likely(!is_migrate_isolate_page(page))) {
722 __mod_zone_page_state(zone, NR_FREE_PAGES, 1);
723 if (is_migrate_cma(mt))
724 __mod_zone_page_state(zone, NR_FREE_CMA_PAGES, 1);
725 }
726 } while (--to_free && --batch_free && !list_empty(list)); 715 } while (--to_free && --batch_free && !list_empty(list));
727 } 716 }
728 spin_unlock(&zone->lock); 717 spin_unlock(&zone->lock);
@@ -739,9 +728,11 @@ static void free_one_page(struct zone *zone,
739 if (nr_scanned) 728 if (nr_scanned)
740 __mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned); 729 __mod_zone_page_state(zone, NR_PAGES_SCANNED, -nr_scanned);
741 730
731 if (unlikely(has_isolate_pageblock(zone) ||
732 is_migrate_isolate(migratetype))) {
733 migratetype = get_pfnblock_migratetype(page, pfn);
734 }
742 __free_one_page(page, pfn, zone, order, migratetype); 735 __free_one_page(page, pfn, zone, order, migratetype);
743 if (unlikely(!is_migrate_isolate(migratetype)))
744 __mod_zone_freepage_state(zone, 1 << order, migratetype);
745 spin_unlock(&zone->lock); 736 spin_unlock(&zone->lock);
746} 737}
747 738
@@ -1484,7 +1475,7 @@ void split_page(struct page *page, unsigned int order)
1484} 1475}
1485EXPORT_SYMBOL_GPL(split_page); 1476EXPORT_SYMBOL_GPL(split_page);
1486 1477
1487static int __isolate_free_page(struct page *page, unsigned int order) 1478int __isolate_free_page(struct page *page, unsigned int order)
1488{ 1479{
1489 unsigned long watermark; 1480 unsigned long watermark;
1490 struct zone *zone; 1481 struct zone *zone;
@@ -6408,13 +6399,12 @@ int alloc_contig_range(unsigned long start, unsigned long end,
6408 6399
6409 /* Make sure the range is really isolated. */ 6400 /* Make sure the range is really isolated. */
6410 if (test_pages_isolated(outer_start, end, false)) { 6401 if (test_pages_isolated(outer_start, end, false)) {
6411 pr_warn("alloc_contig_range test_pages_isolated(%lx, %lx) failed\n", 6402 pr_info("%s: [%lx, %lx) PFNs busy\n",
6412 outer_start, end); 6403 __func__, outer_start, end);
6413 ret = -EBUSY; 6404 ret = -EBUSY;
6414 goto done; 6405 goto done;
6415 } 6406 }
6416 6407
6417
6418 /* Grab isolated pages from freelists. */ 6408 /* Grab isolated pages from freelists. */
6419 outer_end = isolate_freepages_range(&cc, outer_start, end); 6409 outer_end = isolate_freepages_range(&cc, outer_start, end);
6420 if (!outer_end) { 6410 if (!outer_end) {
diff --git a/mm/page_isolation.c b/mm/page_isolation.c
index d1473b2e9481..c8778f7e208e 100644
--- a/mm/page_isolation.c
+++ b/mm/page_isolation.c
@@ -60,6 +60,7 @@ out:
60 int migratetype = get_pageblock_migratetype(page); 60 int migratetype = get_pageblock_migratetype(page);
61 61
62 set_pageblock_migratetype(page, MIGRATE_ISOLATE); 62 set_pageblock_migratetype(page, MIGRATE_ISOLATE);
63 zone->nr_isolate_pageblock++;
63 nr_pages = move_freepages_block(zone, page, MIGRATE_ISOLATE); 64 nr_pages = move_freepages_block(zone, page, MIGRATE_ISOLATE);
64 65
65 __mod_zone_freepage_state(zone, -nr_pages, migratetype); 66 __mod_zone_freepage_state(zone, -nr_pages, migratetype);
@@ -75,16 +76,54 @@ void unset_migratetype_isolate(struct page *page, unsigned migratetype)
75{ 76{
76 struct zone *zone; 77 struct zone *zone;
77 unsigned long flags, nr_pages; 78 unsigned long flags, nr_pages;
79 struct page *isolated_page = NULL;
80 unsigned int order;
81 unsigned long page_idx, buddy_idx;
82 struct page *buddy;
78 83
79 zone = page_zone(page); 84 zone = page_zone(page);
80 spin_lock_irqsave(&zone->lock, flags); 85 spin_lock_irqsave(&zone->lock, flags);
81 if (get_pageblock_migratetype(page) != MIGRATE_ISOLATE) 86 if (get_pageblock_migratetype(page) != MIGRATE_ISOLATE)
82 goto out; 87 goto out;
83 nr_pages = move_freepages_block(zone, page, migratetype); 88
84 __mod_zone_freepage_state(zone, nr_pages, migratetype); 89 /*
90 * Because freepage with more than pageblock_order on isolated
91 * pageblock is restricted to merge due to freepage counting problem,
92 * it is possible that there is free buddy page.
93 * move_freepages_block() doesn't care of merge so we need other
94 * approach in order to merge them. Isolation and free will make
95 * these pages to be merged.
96 */
97 if (PageBuddy(page)) {
98 order = page_order(page);
99 if (order >= pageblock_order) {
100 page_idx = page_to_pfn(page) & ((1 << MAX_ORDER) - 1);
101 buddy_idx = __find_buddy_index(page_idx, order);
102 buddy = page + (buddy_idx - page_idx);
103
104 if (!is_migrate_isolate_page(buddy)) {
105 __isolate_free_page(page, order);
106 set_page_refcounted(page);
107 isolated_page = page;
108 }
109 }
110 }
111
112 /*
113 * If we isolate freepage with more than pageblock_order, there
114 * should be no freepage in the range, so we could avoid costly
115 * pageblock scanning for freepage moving.
116 */
117 if (!isolated_page) {
118 nr_pages = move_freepages_block(zone, page, migratetype);
119 __mod_zone_freepage_state(zone, nr_pages, migratetype);
120 }
85 set_pageblock_migratetype(page, migratetype); 121 set_pageblock_migratetype(page, migratetype);
122 zone->nr_isolate_pageblock--;
86out: 123out:
87 spin_unlock_irqrestore(&zone->lock, flags); 124 spin_unlock_irqrestore(&zone->lock, flags);
125 if (isolated_page)
126 __free_pages(isolated_page, order);
88} 127}
89 128
90static inline struct page * 129static inline struct page *
diff --git a/mm/rmap.c b/mm/rmap.c
index 19886fb2f13a..3e4c7213210c 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -274,6 +274,7 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
274{ 274{
275 struct anon_vma_chain *avc; 275 struct anon_vma_chain *avc;
276 struct anon_vma *anon_vma; 276 struct anon_vma *anon_vma;
277 int error;
277 278
278 /* Don't bother if the parent process has no anon_vma here. */ 279 /* Don't bother if the parent process has no anon_vma here. */
279 if (!pvma->anon_vma) 280 if (!pvma->anon_vma)
@@ -283,8 +284,9 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
283 * First, attach the new VMA to the parent VMA's anon_vmas, 284 * First, attach the new VMA to the parent VMA's anon_vmas,
284 * so rmap can find non-COWed pages in child processes. 285 * so rmap can find non-COWed pages in child processes.
285 */ 286 */
286 if (anon_vma_clone(vma, pvma)) 287 error = anon_vma_clone(vma, pvma);
287 return -ENOMEM; 288 if (error)
289 return error;
288 290
289 /* Then add our own anon_vma. */ 291 /* Then add our own anon_vma. */
290 anon_vma = anon_vma_alloc(); 292 anon_vma = anon_vma_alloc();
diff --git a/mm/slab.c b/mm/slab.c
index eb2b2ea30130..f34e053ec46e 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3076,7 +3076,7 @@ static void *____cache_alloc_node(struct kmem_cache *cachep, gfp_t flags,
3076 void *obj; 3076 void *obj;
3077 int x; 3077 int x;
3078 3078
3079 VM_BUG_ON(nodeid > num_online_nodes()); 3079 VM_BUG_ON(nodeid < 0 || nodeid >= MAX_NUMNODES);
3080 n = get_node(cachep, nodeid); 3080 n = get_node(cachep, nodeid);
3081 BUG_ON(!n); 3081 BUG_ON(!n);
3082 3082
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 406944207b61..dcdab81bd240 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -259,6 +259,10 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
259 if (s->size - size >= sizeof(void *)) 259 if (s->size - size >= sizeof(void *))
260 continue; 260 continue;
261 261
262 if (IS_ENABLED(CONFIG_SLAB) && align &&
263 (align > s->align || s->align % align))
264 continue;
265
262 return s; 266 return s;
263 } 267 }
264 return NULL; 268 return NULL;
diff --git a/mm/truncate.c b/mm/truncate.c
index 261eaf6e5a19..f1e4d6052369 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -715,8 +715,9 @@ EXPORT_SYMBOL(truncate_pagecache);
715 * necessary) to @newsize. It will be typically be called from the filesystem's 715 * necessary) to @newsize. It will be typically be called from the filesystem's
716 * setattr function when ATTR_SIZE is passed in. 716 * setattr function when ATTR_SIZE is passed in.
717 * 717 *
718 * Must be called with inode_mutex held and before all filesystem specific 718 * Must be called with a lock serializing truncates and writes (generally
719 * block truncation has been performed. 719 * i_mutex but e.g. xfs uses a different lock) and before all filesystem
720 * specific block truncation has been performed.
720 */ 721 */
721void truncate_setsize(struct inode *inode, loff_t newsize) 722void truncate_setsize(struct inode *inode, loff_t newsize)
722{ 723{
@@ -755,7 +756,6 @@ void pagecache_isize_extended(struct inode *inode, loff_t from, loff_t to)
755 struct page *page; 756 struct page *page;
756 pgoff_t index; 757 pgoff_t index;
757 758
758 WARN_ON(!mutex_is_locked(&inode->i_mutex));
759 WARN_ON(to > inode->i_size); 759 WARN_ON(to > inode->i_size);
760 760
761 if (from >= to || bsize == PAGE_CACHE_SIZE) 761 if (from >= to || bsize == PAGE_CACHE_SIZE)
diff --git a/mm/vmpressure.c b/mm/vmpressure.c
index d4042e75f7c7..c5afd573d7da 100644
--- a/mm/vmpressure.c
+++ b/mm/vmpressure.c
@@ -165,6 +165,7 @@ static void vmpressure_work_fn(struct work_struct *work)
165 unsigned long scanned; 165 unsigned long scanned;
166 unsigned long reclaimed; 166 unsigned long reclaimed;
167 167
168 spin_lock(&vmpr->sr_lock);
168 /* 169 /*
169 * Several contexts might be calling vmpressure(), so it is 170 * Several contexts might be calling vmpressure(), so it is
170 * possible that the work was rescheduled again before the old 171 * possible that the work was rescheduled again before the old
@@ -173,11 +174,12 @@ static void vmpressure_work_fn(struct work_struct *work)
173 * here. No need for any locks here since we don't care if 174 * here. No need for any locks here since we don't care if
174 * vmpr->reclaimed is in sync. 175 * vmpr->reclaimed is in sync.
175 */ 176 */
176 if (!vmpr->scanned) 177 scanned = vmpr->scanned;
178 if (!scanned) {
179 spin_unlock(&vmpr->sr_lock);
177 return; 180 return;
181 }
178 182
179 spin_lock(&vmpr->sr_lock);
180 scanned = vmpr->scanned;
181 reclaimed = vmpr->reclaimed; 183 reclaimed = vmpr->reclaimed;
182 vmpr->scanned = 0; 184 vmpr->scanned = 0;
183 vmpr->reclaimed = 0; 185 vmpr->reclaimed = 0;
diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
index 648d79ccf462..c465876c7861 100644
--- a/net/bridge/br_multicast.c
+++ b/net/bridge/br_multicast.c
@@ -813,10 +813,9 @@ static void __br_multicast_send_query(struct net_bridge *br,
813 return; 813 return;
814 814
815 if (port) { 815 if (port) {
816 __skb_push(skb, sizeof(struct ethhdr));
817 skb->dev = port->dev; 816 skb->dev = port->dev;
818 NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev, 817 NF_HOOK(NFPROTO_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
819 dev_queue_xmit); 818 br_dev_queue_push_xmit);
820 } else { 819 } else {
821 br_multicast_select_own_querier(br, ip, skb); 820 br_multicast_select_own_querier(br, ip, skb);
822 netif_rx(skb); 821 netif_rx(skb);
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index 2ff9706647f2..e5ec470b851f 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -280,6 +280,7 @@ static const struct nla_policy br_port_policy[IFLA_BRPORT_MAX + 1] = {
280 [IFLA_BRPORT_MODE] = { .type = NLA_U8 }, 280 [IFLA_BRPORT_MODE] = { .type = NLA_U8 },
281 [IFLA_BRPORT_GUARD] = { .type = NLA_U8 }, 281 [IFLA_BRPORT_GUARD] = { .type = NLA_U8 },
282 [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 }, 282 [IFLA_BRPORT_PROTECT] = { .type = NLA_U8 },
283 [IFLA_BRPORT_FAST_LEAVE]= { .type = NLA_U8 },
283 [IFLA_BRPORT_LEARNING] = { .type = NLA_U8 }, 284 [IFLA_BRPORT_LEARNING] = { .type = NLA_U8 },
284 [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NLA_U8 }, 285 [IFLA_BRPORT_UNICAST_FLOOD] = { .type = NLA_U8 },
285}; 286};
diff --git a/net/bridge/netfilter/nft_reject_bridge.c b/net/bridge/netfilter/nft_reject_bridge.c
index 654c9018e3e7..48da2c54a69e 100644
--- a/net/bridge/netfilter/nft_reject_bridge.c
+++ b/net/bridge/netfilter/nft_reject_bridge.c
@@ -18,6 +18,7 @@
18#include <net/netfilter/ipv6/nf_reject.h> 18#include <net/netfilter/ipv6/nf_reject.h>
19#include <linux/ip.h> 19#include <linux/ip.h>
20#include <net/ip.h> 20#include <net/ip.h>
21#include <net/ip6_checksum.h>
21#include <linux/netfilter_bridge.h> 22#include <linux/netfilter_bridge.h>
22#include "../br_private.h" 23#include "../br_private.h"
23 24
diff --git a/net/ceph/auth_x.c b/net/ceph/auth_x.c
index de6662b14e1f..7e38b729696a 100644
--- a/net/ceph/auth_x.c
+++ b/net/ceph/auth_x.c
@@ -149,6 +149,7 @@ static int process_one_ticket(struct ceph_auth_client *ac,
149 struct ceph_crypto_key old_key; 149 struct ceph_crypto_key old_key;
150 void *ticket_buf = NULL; 150 void *ticket_buf = NULL;
151 void *tp, *tpend; 151 void *tp, *tpend;
152 void **ptp;
152 struct ceph_timespec new_validity; 153 struct ceph_timespec new_validity;
153 struct ceph_crypto_key new_session_key; 154 struct ceph_crypto_key new_session_key;
154 struct ceph_buffer *new_ticket_blob; 155 struct ceph_buffer *new_ticket_blob;
@@ -208,25 +209,19 @@ static int process_one_ticket(struct ceph_auth_client *ac,
208 goto out; 209 goto out;
209 } 210 }
210 tp = ticket_buf; 211 tp = ticket_buf;
211 dlen = ceph_decode_32(&tp); 212 ptp = &tp;
213 tpend = *ptp + dlen;
212 } else { 214 } else {
213 /* unencrypted */ 215 /* unencrypted */
214 ceph_decode_32_safe(p, end, dlen, bad); 216 ptp = p;
215 ticket_buf = kmalloc(dlen, GFP_NOFS); 217 tpend = end;
216 if (!ticket_buf) {
217 ret = -ENOMEM;
218 goto out;
219 }
220 tp = ticket_buf;
221 ceph_decode_need(p, end, dlen, bad);
222 ceph_decode_copy(p, ticket_buf, dlen);
223 } 218 }
224 tpend = tp + dlen; 219 ceph_decode_32_safe(ptp, tpend, dlen, bad);
225 dout(" ticket blob is %d bytes\n", dlen); 220 dout(" ticket blob is %d bytes\n", dlen);
226 ceph_decode_need(&tp, tpend, 1 + sizeof(u64), bad); 221 ceph_decode_need(ptp, tpend, 1 + sizeof(u64), bad);
227 blob_struct_v = ceph_decode_8(&tp); 222 blob_struct_v = ceph_decode_8(ptp);
228 new_secret_id = ceph_decode_64(&tp); 223 new_secret_id = ceph_decode_64(ptp);
229 ret = ceph_decode_buffer(&new_ticket_blob, &tp, tpend); 224 ret = ceph_decode_buffer(&new_ticket_blob, ptp, tpend);
230 if (ret) 225 if (ret)
231 goto out; 226 goto out;
232 227
diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c
index 62fc5e7a9acf..790fe89d90c0 100644
--- a/net/ceph/crypto.c
+++ b/net/ceph/crypto.c
@@ -90,11 +90,82 @@ static struct crypto_blkcipher *ceph_crypto_alloc_cipher(void)
90 90
91static const u8 *aes_iv = (u8 *)CEPH_AES_IV; 91static const u8 *aes_iv = (u8 *)CEPH_AES_IV;
92 92
93/*
94 * Should be used for buffers allocated with ceph_kvmalloc().
95 * Currently these are encrypt out-buffer (ceph_buffer) and decrypt
96 * in-buffer (msg front).
97 *
98 * Dispose of @sgt with teardown_sgtable().
99 *
100 * @prealloc_sg is to avoid memory allocation inside sg_alloc_table()
101 * in cases where a single sg is sufficient. No attempt to reduce the
102 * number of sgs by squeezing physically contiguous pages together is
103 * made though, for simplicity.
104 */
105static int setup_sgtable(struct sg_table *sgt, struct scatterlist *prealloc_sg,
106 const void *buf, unsigned int buf_len)
107{
108 struct scatterlist *sg;
109 const bool is_vmalloc = is_vmalloc_addr(buf);
110 unsigned int off = offset_in_page(buf);
111 unsigned int chunk_cnt = 1;
112 unsigned int chunk_len = PAGE_ALIGN(off + buf_len);
113 int i;
114 int ret;
115
116 if (buf_len == 0) {
117 memset(sgt, 0, sizeof(*sgt));
118 return -EINVAL;
119 }
120
121 if (is_vmalloc) {
122 chunk_cnt = chunk_len >> PAGE_SHIFT;
123 chunk_len = PAGE_SIZE;
124 }
125
126 if (chunk_cnt > 1) {
127 ret = sg_alloc_table(sgt, chunk_cnt, GFP_NOFS);
128 if (ret)
129 return ret;
130 } else {
131 WARN_ON(chunk_cnt != 1);
132 sg_init_table(prealloc_sg, 1);
133 sgt->sgl = prealloc_sg;
134 sgt->nents = sgt->orig_nents = 1;
135 }
136
137 for_each_sg(sgt->sgl, sg, sgt->orig_nents, i) {
138 struct page *page;
139 unsigned int len = min(chunk_len - off, buf_len);
140
141 if (is_vmalloc)
142 page = vmalloc_to_page(buf);
143 else
144 page = virt_to_page(buf);
145
146 sg_set_page(sg, page, len, off);
147
148 off = 0;
149 buf += len;
150 buf_len -= len;
151 }
152 WARN_ON(buf_len != 0);
153
154 return 0;
155}
156
157static void teardown_sgtable(struct sg_table *sgt)
158{
159 if (sgt->orig_nents > 1)
160 sg_free_table(sgt);
161}
162
93static int ceph_aes_encrypt(const void *key, int key_len, 163static int ceph_aes_encrypt(const void *key, int key_len,
94 void *dst, size_t *dst_len, 164 void *dst, size_t *dst_len,
95 const void *src, size_t src_len) 165 const void *src, size_t src_len)
96{ 166{
97 struct scatterlist sg_in[2], sg_out[1]; 167 struct scatterlist sg_in[2], prealloc_sg;
168 struct sg_table sg_out;
98 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher(); 169 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
99 struct blkcipher_desc desc = { .tfm = tfm, .flags = 0 }; 170 struct blkcipher_desc desc = { .tfm = tfm, .flags = 0 };
100 int ret; 171 int ret;
@@ -110,16 +181,18 @@ static int ceph_aes_encrypt(const void *key, int key_len,
110 181
111 *dst_len = src_len + zero_padding; 182 *dst_len = src_len + zero_padding;
112 183
113 crypto_blkcipher_setkey((void *)tfm, key, key_len);
114 sg_init_table(sg_in, 2); 184 sg_init_table(sg_in, 2);
115 sg_set_buf(&sg_in[0], src, src_len); 185 sg_set_buf(&sg_in[0], src, src_len);
116 sg_set_buf(&sg_in[1], pad, zero_padding); 186 sg_set_buf(&sg_in[1], pad, zero_padding);
117 sg_init_table(sg_out, 1); 187 ret = setup_sgtable(&sg_out, &prealloc_sg, dst, *dst_len);
118 sg_set_buf(sg_out, dst, *dst_len); 188 if (ret)
189 goto out_tfm;
190
191 crypto_blkcipher_setkey((void *)tfm, key, key_len);
119 iv = crypto_blkcipher_crt(tfm)->iv; 192 iv = crypto_blkcipher_crt(tfm)->iv;
120 ivsize = crypto_blkcipher_ivsize(tfm); 193 ivsize = crypto_blkcipher_ivsize(tfm);
121
122 memcpy(iv, aes_iv, ivsize); 194 memcpy(iv, aes_iv, ivsize);
195
123 /* 196 /*
124 print_hex_dump(KERN_ERR, "enc key: ", DUMP_PREFIX_NONE, 16, 1, 197 print_hex_dump(KERN_ERR, "enc key: ", DUMP_PREFIX_NONE, 16, 1,
125 key, key_len, 1); 198 key, key_len, 1);
@@ -128,16 +201,22 @@ static int ceph_aes_encrypt(const void *key, int key_len,
128 print_hex_dump(KERN_ERR, "enc pad: ", DUMP_PREFIX_NONE, 16, 1, 201 print_hex_dump(KERN_ERR, "enc pad: ", DUMP_PREFIX_NONE, 16, 1,
129 pad, zero_padding, 1); 202 pad, zero_padding, 1);
130 */ 203 */
131 ret = crypto_blkcipher_encrypt(&desc, sg_out, sg_in, 204 ret = crypto_blkcipher_encrypt(&desc, sg_out.sgl, sg_in,
132 src_len + zero_padding); 205 src_len + zero_padding);
133 crypto_free_blkcipher(tfm); 206 if (ret < 0) {
134 if (ret < 0)
135 pr_err("ceph_aes_crypt failed %d\n", ret); 207 pr_err("ceph_aes_crypt failed %d\n", ret);
208 goto out_sg;
209 }
136 /* 210 /*
137 print_hex_dump(KERN_ERR, "enc out: ", DUMP_PREFIX_NONE, 16, 1, 211 print_hex_dump(KERN_ERR, "enc out: ", DUMP_PREFIX_NONE, 16, 1,
138 dst, *dst_len, 1); 212 dst, *dst_len, 1);
139 */ 213 */
140 return 0; 214
215out_sg:
216 teardown_sgtable(&sg_out);
217out_tfm:
218 crypto_free_blkcipher(tfm);
219 return ret;
141} 220}
142 221
143static int ceph_aes_encrypt2(const void *key, int key_len, void *dst, 222static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
@@ -145,7 +224,8 @@ static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
145 const void *src1, size_t src1_len, 224 const void *src1, size_t src1_len,
146 const void *src2, size_t src2_len) 225 const void *src2, size_t src2_len)
147{ 226{
148 struct scatterlist sg_in[3], sg_out[1]; 227 struct scatterlist sg_in[3], prealloc_sg;
228 struct sg_table sg_out;
149 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher(); 229 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
150 struct blkcipher_desc desc = { .tfm = tfm, .flags = 0 }; 230 struct blkcipher_desc desc = { .tfm = tfm, .flags = 0 };
151 int ret; 231 int ret;
@@ -161,17 +241,19 @@ static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
161 241
162 *dst_len = src1_len + src2_len + zero_padding; 242 *dst_len = src1_len + src2_len + zero_padding;
163 243
164 crypto_blkcipher_setkey((void *)tfm, key, key_len);
165 sg_init_table(sg_in, 3); 244 sg_init_table(sg_in, 3);
166 sg_set_buf(&sg_in[0], src1, src1_len); 245 sg_set_buf(&sg_in[0], src1, src1_len);
167 sg_set_buf(&sg_in[1], src2, src2_len); 246 sg_set_buf(&sg_in[1], src2, src2_len);
168 sg_set_buf(&sg_in[2], pad, zero_padding); 247 sg_set_buf(&sg_in[2], pad, zero_padding);
169 sg_init_table(sg_out, 1); 248 ret = setup_sgtable(&sg_out, &prealloc_sg, dst, *dst_len);
170 sg_set_buf(sg_out, dst, *dst_len); 249 if (ret)
250 goto out_tfm;
251
252 crypto_blkcipher_setkey((void *)tfm, key, key_len);
171 iv = crypto_blkcipher_crt(tfm)->iv; 253 iv = crypto_blkcipher_crt(tfm)->iv;
172 ivsize = crypto_blkcipher_ivsize(tfm); 254 ivsize = crypto_blkcipher_ivsize(tfm);
173
174 memcpy(iv, aes_iv, ivsize); 255 memcpy(iv, aes_iv, ivsize);
256
175 /* 257 /*
176 print_hex_dump(KERN_ERR, "enc key: ", DUMP_PREFIX_NONE, 16, 1, 258 print_hex_dump(KERN_ERR, "enc key: ", DUMP_PREFIX_NONE, 16, 1,
177 key, key_len, 1); 259 key, key_len, 1);
@@ -182,23 +264,30 @@ static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
182 print_hex_dump(KERN_ERR, "enc pad: ", DUMP_PREFIX_NONE, 16, 1, 264 print_hex_dump(KERN_ERR, "enc pad: ", DUMP_PREFIX_NONE, 16, 1,
183 pad, zero_padding, 1); 265 pad, zero_padding, 1);
184 */ 266 */
185 ret = crypto_blkcipher_encrypt(&desc, sg_out, sg_in, 267 ret = crypto_blkcipher_encrypt(&desc, sg_out.sgl, sg_in,
186 src1_len + src2_len + zero_padding); 268 src1_len + src2_len + zero_padding);
187 crypto_free_blkcipher(tfm); 269 if (ret < 0) {
188 if (ret < 0)
189 pr_err("ceph_aes_crypt2 failed %d\n", ret); 270 pr_err("ceph_aes_crypt2 failed %d\n", ret);
271 goto out_sg;
272 }
190 /* 273 /*
191 print_hex_dump(KERN_ERR, "enc out: ", DUMP_PREFIX_NONE, 16, 1, 274 print_hex_dump(KERN_ERR, "enc out: ", DUMP_PREFIX_NONE, 16, 1,
192 dst, *dst_len, 1); 275 dst, *dst_len, 1);
193 */ 276 */
194 return 0; 277
278out_sg:
279 teardown_sgtable(&sg_out);
280out_tfm:
281 crypto_free_blkcipher(tfm);
282 return ret;
195} 283}
196 284
197static int ceph_aes_decrypt(const void *key, int key_len, 285static int ceph_aes_decrypt(const void *key, int key_len,
198 void *dst, size_t *dst_len, 286 void *dst, size_t *dst_len,
199 const void *src, size_t src_len) 287 const void *src, size_t src_len)
200{ 288{
201 struct scatterlist sg_in[1], sg_out[2]; 289 struct sg_table sg_in;
290 struct scatterlist sg_out[2], prealloc_sg;
202 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher(); 291 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
203 struct blkcipher_desc desc = { .tfm = tfm }; 292 struct blkcipher_desc desc = { .tfm = tfm };
204 char pad[16]; 293 char pad[16];
@@ -210,16 +299,16 @@ static int ceph_aes_decrypt(const void *key, int key_len,
210 if (IS_ERR(tfm)) 299 if (IS_ERR(tfm))
211 return PTR_ERR(tfm); 300 return PTR_ERR(tfm);
212 301
213 crypto_blkcipher_setkey((void *)tfm, key, key_len);
214 sg_init_table(sg_in, 1);
215 sg_init_table(sg_out, 2); 302 sg_init_table(sg_out, 2);
216 sg_set_buf(sg_in, src, src_len);
217 sg_set_buf(&sg_out[0], dst, *dst_len); 303 sg_set_buf(&sg_out[0], dst, *dst_len);
218 sg_set_buf(&sg_out[1], pad, sizeof(pad)); 304 sg_set_buf(&sg_out[1], pad, sizeof(pad));
305 ret = setup_sgtable(&sg_in, &prealloc_sg, src, src_len);
306 if (ret)
307 goto out_tfm;
219 308
309 crypto_blkcipher_setkey((void *)tfm, key, key_len);
220 iv = crypto_blkcipher_crt(tfm)->iv; 310 iv = crypto_blkcipher_crt(tfm)->iv;
221 ivsize = crypto_blkcipher_ivsize(tfm); 311 ivsize = crypto_blkcipher_ivsize(tfm);
222
223 memcpy(iv, aes_iv, ivsize); 312 memcpy(iv, aes_iv, ivsize);
224 313
225 /* 314 /*
@@ -228,12 +317,10 @@ static int ceph_aes_decrypt(const void *key, int key_len,
228 print_hex_dump(KERN_ERR, "dec in: ", DUMP_PREFIX_NONE, 16, 1, 317 print_hex_dump(KERN_ERR, "dec in: ", DUMP_PREFIX_NONE, 16, 1,
229 src, src_len, 1); 318 src, src_len, 1);
230 */ 319 */
231 320 ret = crypto_blkcipher_decrypt(&desc, sg_out, sg_in.sgl, src_len);
232 ret = crypto_blkcipher_decrypt(&desc, sg_out, sg_in, src_len);
233 crypto_free_blkcipher(tfm);
234 if (ret < 0) { 321 if (ret < 0) {
235 pr_err("ceph_aes_decrypt failed %d\n", ret); 322 pr_err("ceph_aes_decrypt failed %d\n", ret);
236 return ret; 323 goto out_sg;
237 } 324 }
238 325
239 if (src_len <= *dst_len) 326 if (src_len <= *dst_len)
@@ -251,7 +338,12 @@ static int ceph_aes_decrypt(const void *key, int key_len,
251 print_hex_dump(KERN_ERR, "dec out: ", DUMP_PREFIX_NONE, 16, 1, 338 print_hex_dump(KERN_ERR, "dec out: ", DUMP_PREFIX_NONE, 16, 1,
252 dst, *dst_len, 1); 339 dst, *dst_len, 1);
253 */ 340 */
254 return 0; 341
342out_sg:
343 teardown_sgtable(&sg_in);
344out_tfm:
345 crypto_free_blkcipher(tfm);
346 return ret;
255} 347}
256 348
257static int ceph_aes_decrypt2(const void *key, int key_len, 349static int ceph_aes_decrypt2(const void *key, int key_len,
@@ -259,7 +351,8 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
259 void *dst2, size_t *dst2_len, 351 void *dst2, size_t *dst2_len,
260 const void *src, size_t src_len) 352 const void *src, size_t src_len)
261{ 353{
262 struct scatterlist sg_in[1], sg_out[3]; 354 struct sg_table sg_in;
355 struct scatterlist sg_out[3], prealloc_sg;
263 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher(); 356 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
264 struct blkcipher_desc desc = { .tfm = tfm }; 357 struct blkcipher_desc desc = { .tfm = tfm };
265 char pad[16]; 358 char pad[16];
@@ -271,17 +364,17 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
271 if (IS_ERR(tfm)) 364 if (IS_ERR(tfm))
272 return PTR_ERR(tfm); 365 return PTR_ERR(tfm);
273 366
274 sg_init_table(sg_in, 1);
275 sg_set_buf(sg_in, src, src_len);
276 sg_init_table(sg_out, 3); 367 sg_init_table(sg_out, 3);
277 sg_set_buf(&sg_out[0], dst1, *dst1_len); 368 sg_set_buf(&sg_out[0], dst1, *dst1_len);
278 sg_set_buf(&sg_out[1], dst2, *dst2_len); 369 sg_set_buf(&sg_out[1], dst2, *dst2_len);
279 sg_set_buf(&sg_out[2], pad, sizeof(pad)); 370 sg_set_buf(&sg_out[2], pad, sizeof(pad));
371 ret = setup_sgtable(&sg_in, &prealloc_sg, src, src_len);
372 if (ret)
373 goto out_tfm;
280 374
281 crypto_blkcipher_setkey((void *)tfm, key, key_len); 375 crypto_blkcipher_setkey((void *)tfm, key, key_len);
282 iv = crypto_blkcipher_crt(tfm)->iv; 376 iv = crypto_blkcipher_crt(tfm)->iv;
283 ivsize = crypto_blkcipher_ivsize(tfm); 377 ivsize = crypto_blkcipher_ivsize(tfm);
284
285 memcpy(iv, aes_iv, ivsize); 378 memcpy(iv, aes_iv, ivsize);
286 379
287 /* 380 /*
@@ -290,12 +383,10 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
290 print_hex_dump(KERN_ERR, "dec in: ", DUMP_PREFIX_NONE, 16, 1, 383 print_hex_dump(KERN_ERR, "dec in: ", DUMP_PREFIX_NONE, 16, 1,
291 src, src_len, 1); 384 src, src_len, 1);
292 */ 385 */
293 386 ret = crypto_blkcipher_decrypt(&desc, sg_out, sg_in.sgl, src_len);
294 ret = crypto_blkcipher_decrypt(&desc, sg_out, sg_in, src_len);
295 crypto_free_blkcipher(tfm);
296 if (ret < 0) { 387 if (ret < 0) {
297 pr_err("ceph_aes_decrypt failed %d\n", ret); 388 pr_err("ceph_aes_decrypt failed %d\n", ret);
298 return ret; 389 goto out_sg;
299 } 390 }
300 391
301 if (src_len <= *dst1_len) 392 if (src_len <= *dst1_len)
@@ -325,7 +416,11 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
325 dst2, *dst2_len, 1); 416 dst2, *dst2_len, 1);
326 */ 417 */
327 418
328 return 0; 419out_sg:
420 teardown_sgtable(&sg_in);
421out_tfm:
422 crypto_free_blkcipher(tfm);
423 return ret;
329} 424}
330 425
331 426
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
index 559c9f619c20..8d1653caffdb 100644
--- a/net/ceph/messenger.c
+++ b/net/ceph/messenger.c
@@ -484,7 +484,7 @@ static int ceph_tcp_connect(struct ceph_connection *con)
484 IPPROTO_TCP, &sock); 484 IPPROTO_TCP, &sock);
485 if (ret) 485 if (ret)
486 return ret; 486 return ret;
487 sock->sk->sk_allocation = GFP_NOFS; 487 sock->sk->sk_allocation = GFP_NOFS | __GFP_MEMALLOC;
488 488
489#ifdef CONFIG_LOCKDEP 489#ifdef CONFIG_LOCKDEP
490 lockdep_set_class(&sock->sk->sk_lock, &socket_class); 490 lockdep_set_class(&sock->sk->sk_lock, &socket_class);
@@ -509,6 +509,9 @@ static int ceph_tcp_connect(struct ceph_connection *con)
509 509
510 return ret; 510 return ret;
511 } 511 }
512
513 sk_set_memalloc(sock->sk);
514
512 con->sock = sock; 515 con->sock = sock;
513 return 0; 516 return 0;
514} 517}
@@ -2769,8 +2772,11 @@ static void con_work(struct work_struct *work)
2769{ 2772{
2770 struct ceph_connection *con = container_of(work, struct ceph_connection, 2773 struct ceph_connection *con = container_of(work, struct ceph_connection,
2771 work.work); 2774 work.work);
2775 unsigned long pflags = current->flags;
2772 bool fault; 2776 bool fault;
2773 2777
2778 current->flags |= PF_MEMALLOC;
2779
2774 mutex_lock(&con->mutex); 2780 mutex_lock(&con->mutex);
2775 while (true) { 2781 while (true) {
2776 int ret; 2782 int ret;
@@ -2824,6 +2830,8 @@ static void con_work(struct work_struct *work)
2824 con_fault_finish(con); 2830 con_fault_finish(con);
2825 2831
2826 con->ops->put(con); 2832 con->ops->put(con);
2833
2834 tsk_restore_flags(current, pflags, PF_MEMALLOC);
2827} 2835}
2828 2836
2829/* 2837/*
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index f3fc54eac09d..6f164289bde8 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -1007,8 +1007,8 @@ static void put_osd(struct ceph_osd *osd)
1007static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd) 1007static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
1008{ 1008{
1009 dout("__remove_osd %p\n", osd); 1009 dout("__remove_osd %p\n", osd);
1010 BUG_ON(!list_empty(&osd->o_requests)); 1010 WARN_ON(!list_empty(&osd->o_requests));
1011 BUG_ON(!list_empty(&osd->o_linger_requests)); 1011 WARN_ON(!list_empty(&osd->o_linger_requests));
1012 1012
1013 rb_erase(&osd->o_node, &osdc->osds); 1013 rb_erase(&osd->o_node, &osdc->osds);
1014 list_del_init(&osd->o_osd_lru); 1014 list_del_init(&osd->o_osd_lru);
@@ -1254,6 +1254,8 @@ static void __unregister_linger_request(struct ceph_osd_client *osdc,
1254 if (list_empty(&req->r_osd_item)) 1254 if (list_empty(&req->r_osd_item))
1255 req->r_osd = NULL; 1255 req->r_osd = NULL;
1256 } 1256 }
1257
1258 list_del_init(&req->r_req_lru_item); /* can be on notarget */
1257 ceph_osdc_put_request(req); 1259 ceph_osdc_put_request(req);
1258} 1260}
1259 1261
@@ -1395,6 +1397,7 @@ static int __map_request(struct ceph_osd_client *osdc,
1395 if (req->r_osd) { 1397 if (req->r_osd) {
1396 __cancel_request(req); 1398 __cancel_request(req);
1397 list_del_init(&req->r_osd_item); 1399 list_del_init(&req->r_osd_item);
1400 list_del_init(&req->r_linger_osd_item);
1398 req->r_osd = NULL; 1401 req->r_osd = NULL;
1399 } 1402 }
1400 1403
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index a6882686ca3a..76321ea442c3 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1498,6 +1498,7 @@ static int do_setlink(const struct sk_buff *skb,
1498 goto errout; 1498 goto errout;
1499 } 1499 }
1500 if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) { 1500 if (!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)) {
1501 put_net(net);
1501 err = -EPERM; 1502 err = -EPERM;
1502 goto errout; 1503 goto errout;
1503 } 1504 }
@@ -2685,13 +2686,20 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb)
2685 int idx = 0; 2686 int idx = 0;
2686 u32 portid = NETLINK_CB(cb->skb).portid; 2687 u32 portid = NETLINK_CB(cb->skb).portid;
2687 u32 seq = cb->nlh->nlmsg_seq; 2688 u32 seq = cb->nlh->nlmsg_seq;
2688 struct nlattr *extfilt;
2689 u32 filter_mask = 0; 2689 u32 filter_mask = 0;
2690 2690
2691 extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct ifinfomsg), 2691 if (nlmsg_len(cb->nlh) > sizeof(struct ifinfomsg)) {
2692 IFLA_EXT_MASK); 2692 struct nlattr *extfilt;
2693 if (extfilt) 2693
2694 filter_mask = nla_get_u32(extfilt); 2694 extfilt = nlmsg_find_attr(cb->nlh, sizeof(struct ifinfomsg),
2695 IFLA_EXT_MASK);
2696 if (extfilt) {
2697 if (nla_len(extfilt) < sizeof(filter_mask))
2698 return -EINVAL;
2699
2700 filter_mask = nla_get_u32(extfilt);
2701 }
2702 }
2695 2703
2696 rcu_read_lock(); 2704 rcu_read_lock();
2697 for_each_netdev_rcu(net, dev) { 2705 for_each_netdev_rcu(net, dev) {
@@ -2798,6 +2806,9 @@ static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh)
2798 if (br_spec) { 2806 if (br_spec) {
2799 nla_for_each_nested(attr, br_spec, rem) { 2807 nla_for_each_nested(attr, br_spec, rem) {
2800 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) { 2808 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
2809 if (nla_len(attr) < sizeof(flags))
2810 return -EINVAL;
2811
2801 have_flags = true; 2812 have_flags = true;
2802 flags = nla_get_u16(attr); 2813 flags = nla_get_u16(attr);
2803 break; 2814 break;
@@ -2868,6 +2879,9 @@ static int rtnl_bridge_dellink(struct sk_buff *skb, struct nlmsghdr *nlh)
2868 if (br_spec) { 2879 if (br_spec) {
2869 nla_for_each_nested(attr, br_spec, rem) { 2880 nla_for_each_nested(attr, br_spec, rem) {
2870 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) { 2881 if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
2882 if (nla_len(attr) < sizeof(flags))
2883 return -EINVAL;
2884
2871 have_flags = true; 2885 have_flags = true;
2872 flags = nla_get_u16(attr); 2886 flags = nla_get_u16(attr);
2873 break; 2887 break;
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index c16615bfb61e..32e31c299631 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -552,20 +552,13 @@ static void kfree_skbmem(struct sk_buff *skb)
552 case SKB_FCLONE_CLONE: 552 case SKB_FCLONE_CLONE:
553 fclones = container_of(skb, struct sk_buff_fclones, skb2); 553 fclones = container_of(skb, struct sk_buff_fclones, skb2);
554 554
555 /* Warning : We must perform the atomic_dec_and_test() before 555 /* The clone portion is available for
556 * setting skb->fclone back to SKB_FCLONE_FREE, otherwise 556 * fast-cloning again.
557 * skb_clone() could set clone_ref to 2 before our decrement.
558 * Anyway, if we are going to free the structure, no need to
559 * rewrite skb->fclone.
560 */ 557 */
561 if (atomic_dec_and_test(&fclones->fclone_ref)) { 558 skb->fclone = SKB_FCLONE_FREE;
559
560 if (atomic_dec_and_test(&fclones->fclone_ref))
562 kmem_cache_free(skbuff_fclone_cache, fclones); 561 kmem_cache_free(skbuff_fclone_cache, fclones);
563 } else {
564 /* The clone portion is available for
565 * fast-cloning again.
566 */
567 skb->fclone = SKB_FCLONE_FREE;
568 }
569 break; 562 break;
570 } 563 }
571} 564}
@@ -887,11 +880,7 @@ struct sk_buff *skb_clone(struct sk_buff *skb, gfp_t gfp_mask)
887 if (skb->fclone == SKB_FCLONE_ORIG && 880 if (skb->fclone == SKB_FCLONE_ORIG &&
888 n->fclone == SKB_FCLONE_FREE) { 881 n->fclone == SKB_FCLONE_FREE) {
889 n->fclone = SKB_FCLONE_CLONE; 882 n->fclone = SKB_FCLONE_CLONE;
890 /* As our fastclone was free, clone_ref must be 1 at this point. 883 atomic_inc(&fclones->fclone_ref);
891 * We could use atomic_inc() here, but it is faster
892 * to set the final value.
893 */
894 atomic_set(&fclones->fclone_ref, 2);
895 } else { 884 } else {
896 if (skb_pfmemalloc(skb)) 885 if (skb_pfmemalloc(skb))
897 gfp_mask |= __GFP_MEMALLOC; 886 gfp_mask |= __GFP_MEMALLOC;
diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
index ca11d283bbeb..93ea80196f0e 100644
--- a/net/dcb/dcbnl.c
+++ b/net/dcb/dcbnl.c
@@ -1080,13 +1080,13 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
1080 if (!app) 1080 if (!app)
1081 return -EMSGSIZE; 1081 return -EMSGSIZE;
1082 1082
1083 spin_lock(&dcb_lock); 1083 spin_lock_bh(&dcb_lock);
1084 list_for_each_entry(itr, &dcb_app_list, list) { 1084 list_for_each_entry(itr, &dcb_app_list, list) {
1085 if (itr->ifindex == netdev->ifindex) { 1085 if (itr->ifindex == netdev->ifindex) {
1086 err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app), 1086 err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app),
1087 &itr->app); 1087 &itr->app);
1088 if (err) { 1088 if (err) {
1089 spin_unlock(&dcb_lock); 1089 spin_unlock_bh(&dcb_lock);
1090 return -EMSGSIZE; 1090 return -EMSGSIZE;
1091 } 1091 }
1092 } 1092 }
@@ -1097,7 +1097,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
1097 else 1097 else
1098 dcbx = -EOPNOTSUPP; 1098 dcbx = -EOPNOTSUPP;
1099 1099
1100 spin_unlock(&dcb_lock); 1100 spin_unlock_bh(&dcb_lock);
1101 nla_nest_end(skb, app); 1101 nla_nest_end(skb, app);
1102 1102
1103 /* get peer info if available */ 1103 /* get peer info if available */
@@ -1234,7 +1234,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
1234 } 1234 }
1235 1235
1236 /* local app */ 1236 /* local app */
1237 spin_lock(&dcb_lock); 1237 spin_lock_bh(&dcb_lock);
1238 app = nla_nest_start(skb, DCB_ATTR_CEE_APP_TABLE); 1238 app = nla_nest_start(skb, DCB_ATTR_CEE_APP_TABLE);
1239 if (!app) 1239 if (!app)
1240 goto dcb_unlock; 1240 goto dcb_unlock;
@@ -1271,7 +1271,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
1271 else 1271 else
1272 dcbx = -EOPNOTSUPP; 1272 dcbx = -EOPNOTSUPP;
1273 1273
1274 spin_unlock(&dcb_lock); 1274 spin_unlock_bh(&dcb_lock);
1275 1275
1276 /* features flags */ 1276 /* features flags */
1277 if (ops->getfeatcfg) { 1277 if (ops->getfeatcfg) {
@@ -1326,7 +1326,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
1326 return 0; 1326 return 0;
1327 1327
1328dcb_unlock: 1328dcb_unlock:
1329 spin_unlock(&dcb_lock); 1329 spin_unlock_bh(&dcb_lock);
1330nla_put_failure: 1330nla_put_failure:
1331 return err; 1331 return err;
1332} 1332}
@@ -1762,10 +1762,10 @@ u8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
1762 struct dcb_app_type *itr; 1762 struct dcb_app_type *itr;
1763 u8 prio = 0; 1763 u8 prio = 0;
1764 1764
1765 spin_lock(&dcb_lock); 1765 spin_lock_bh(&dcb_lock);
1766 if ((itr = dcb_app_lookup(app, dev->ifindex, 0))) 1766 if ((itr = dcb_app_lookup(app, dev->ifindex, 0)))
1767 prio = itr->app.priority; 1767 prio = itr->app.priority;
1768 spin_unlock(&dcb_lock); 1768 spin_unlock_bh(&dcb_lock);
1769 1769
1770 return prio; 1770 return prio;
1771} 1771}
@@ -1789,7 +1789,7 @@ int dcb_setapp(struct net_device *dev, struct dcb_app *new)
1789 if (dev->dcbnl_ops->getdcbx) 1789 if (dev->dcbnl_ops->getdcbx)
1790 event.dcbx = dev->dcbnl_ops->getdcbx(dev); 1790 event.dcbx = dev->dcbnl_ops->getdcbx(dev);
1791 1791
1792 spin_lock(&dcb_lock); 1792 spin_lock_bh(&dcb_lock);
1793 /* Search for existing match and replace */ 1793 /* Search for existing match and replace */
1794 if ((itr = dcb_app_lookup(new, dev->ifindex, 0))) { 1794 if ((itr = dcb_app_lookup(new, dev->ifindex, 0))) {
1795 if (new->priority) 1795 if (new->priority)
@@ -1804,7 +1804,7 @@ int dcb_setapp(struct net_device *dev, struct dcb_app *new)
1804 if (new->priority) 1804 if (new->priority)
1805 err = dcb_app_add(new, dev->ifindex); 1805 err = dcb_app_add(new, dev->ifindex);
1806out: 1806out:
1807 spin_unlock(&dcb_lock); 1807 spin_unlock_bh(&dcb_lock);
1808 if (!err) 1808 if (!err)
1809 call_dcbevent_notifiers(DCB_APP_EVENT, &event); 1809 call_dcbevent_notifiers(DCB_APP_EVENT, &event);
1810 return err; 1810 return err;
@@ -1823,10 +1823,10 @@ u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app)
1823 struct dcb_app_type *itr; 1823 struct dcb_app_type *itr;
1824 u8 prio = 0; 1824 u8 prio = 0;
1825 1825
1826 spin_lock(&dcb_lock); 1826 spin_lock_bh(&dcb_lock);
1827 if ((itr = dcb_app_lookup(app, dev->ifindex, 0))) 1827 if ((itr = dcb_app_lookup(app, dev->ifindex, 0)))
1828 prio |= 1 << itr->app.priority; 1828 prio |= 1 << itr->app.priority;
1829 spin_unlock(&dcb_lock); 1829 spin_unlock_bh(&dcb_lock);
1830 1830
1831 return prio; 1831 return prio;
1832} 1832}
@@ -1850,7 +1850,7 @@ int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new)
1850 if (dev->dcbnl_ops->getdcbx) 1850 if (dev->dcbnl_ops->getdcbx)
1851 event.dcbx = dev->dcbnl_ops->getdcbx(dev); 1851 event.dcbx = dev->dcbnl_ops->getdcbx(dev);
1852 1852
1853 spin_lock(&dcb_lock); 1853 spin_lock_bh(&dcb_lock);
1854 /* Search for existing match and abort if found */ 1854 /* Search for existing match and abort if found */
1855 if (dcb_app_lookup(new, dev->ifindex, new->priority)) { 1855 if (dcb_app_lookup(new, dev->ifindex, new->priority)) {
1856 err = -EEXIST; 1856 err = -EEXIST;
@@ -1859,7 +1859,7 @@ int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new)
1859 1859
1860 err = dcb_app_add(new, dev->ifindex); 1860 err = dcb_app_add(new, dev->ifindex);
1861out: 1861out:
1862 spin_unlock(&dcb_lock); 1862 spin_unlock_bh(&dcb_lock);
1863 if (!err) 1863 if (!err)
1864 call_dcbevent_notifiers(DCB_APP_EVENT, &event); 1864 call_dcbevent_notifiers(DCB_APP_EVENT, &event);
1865 return err; 1865 return err;
@@ -1882,7 +1882,7 @@ int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del)
1882 if (dev->dcbnl_ops->getdcbx) 1882 if (dev->dcbnl_ops->getdcbx)
1883 event.dcbx = dev->dcbnl_ops->getdcbx(dev); 1883 event.dcbx = dev->dcbnl_ops->getdcbx(dev);
1884 1884
1885 spin_lock(&dcb_lock); 1885 spin_lock_bh(&dcb_lock);
1886 /* Search for existing match and remove it. */ 1886 /* Search for existing match and remove it. */
1887 if ((itr = dcb_app_lookup(del, dev->ifindex, del->priority))) { 1887 if ((itr = dcb_app_lookup(del, dev->ifindex, del->priority))) {
1888 list_del(&itr->list); 1888 list_del(&itr->list);
@@ -1890,7 +1890,7 @@ int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del)
1890 err = 0; 1890 err = 0;
1891 } 1891 }
1892 1892
1893 spin_unlock(&dcb_lock); 1893 spin_unlock_bh(&dcb_lock);
1894 if (!err) 1894 if (!err)
1895 call_dcbevent_notifiers(DCB_APP_EVENT, &event); 1895 call_dcbevent_notifiers(DCB_APP_EVENT, &event);
1896 return err; 1896 return err;
@@ -1902,12 +1902,12 @@ static void dcb_flushapp(void)
1902 struct dcb_app_type *app; 1902 struct dcb_app_type *app;
1903 struct dcb_app_type *tmp; 1903 struct dcb_app_type *tmp;
1904 1904
1905 spin_lock(&dcb_lock); 1905 spin_lock_bh(&dcb_lock);
1906 list_for_each_entry_safe(app, tmp, &dcb_app_list, list) { 1906 list_for_each_entry_safe(app, tmp, &dcb_app_list, list) {
1907 list_del(&app->list); 1907 list_del(&app->list);
1908 kfree(app); 1908 kfree(app);
1909 } 1909 }
1910 spin_unlock(&dcb_lock); 1910 spin_unlock_bh(&dcb_lock);
1911} 1911}
1912 1912
1913static int __init dcbnl_init(void) 1913static int __init dcbnl_init(void)
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 6d1817449c36..ab03e00ffe8f 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -489,11 +489,14 @@ static void dsa_slave_phy_setup(struct dsa_slave_priv *p,
489 /* We could not connect to a designated PHY, so use the switch internal 489 /* We could not connect to a designated PHY, so use the switch internal
490 * MDIO bus instead 490 * MDIO bus instead
491 */ 491 */
492 if (!p->phy) 492 if (!p->phy) {
493 p->phy = ds->slave_mii_bus->phy_map[p->port]; 493 p->phy = ds->slave_mii_bus->phy_map[p->port];
494 else 494 phy_connect_direct(slave_dev, p->phy, dsa_slave_adjust_link,
495 p->phy_interface);
496 } else {
495 pr_info("attached PHY at address %d [%s]\n", 497 pr_info("attached PHY at address %d [%s]\n",
496 p->phy->addr, p->phy->drv->name); 498 p->phy->addr, p->phy->drv->name);
499 }
497} 500}
498 501
499int dsa_slave_suspend(struct net_device *slave_dev) 502int dsa_slave_suspend(struct net_device *slave_dev)
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 8b7fe5b03906..e67da4e6c324 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -1386,6 +1386,17 @@ out:
1386 return pp; 1386 return pp;
1387} 1387}
1388 1388
1389int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
1390{
1391 if (sk->sk_family == AF_INET)
1392 return ip_recv_error(sk, msg, len, addr_len);
1393#if IS_ENABLED(CONFIG_IPV6)
1394 if (sk->sk_family == AF_INET6)
1395 return pingv6_ops.ipv6_recv_error(sk, msg, len, addr_len);
1396#endif
1397 return -EINVAL;
1398}
1399
1389static int inet_gro_complete(struct sk_buff *skb, int nhoff) 1400static int inet_gro_complete(struct sk_buff *skb, int nhoff)
1390{ 1401{
1391 __be16 newlen = htons(skb->len - nhoff); 1402 __be16 newlen = htons(skb->len - nhoff);
diff --git a/net/ipv4/fib_rules.c b/net/ipv4/fib_rules.c
index f2e15738534d..8f7bd56955b0 100644
--- a/net/ipv4/fib_rules.c
+++ b/net/ipv4/fib_rules.c
@@ -62,6 +62,10 @@ int __fib_lookup(struct net *net, struct flowi4 *flp, struct fib_result *res)
62 else 62 else
63 res->tclassid = 0; 63 res->tclassid = 0;
64#endif 64#endif
65
66 if (err == -ESRCH)
67 err = -ENETUNREACH;
68
65 return err; 69 return err;
66} 70}
67EXPORT_SYMBOL_GPL(__fib_lookup); 71EXPORT_SYMBOL_GPL(__fib_lookup);
diff --git a/net/ipv4/fou.c b/net/ipv4/fou.c
index 32e78924e246..606c520ffd5a 100644
--- a/net/ipv4/fou.c
+++ b/net/ipv4/fou.c
@@ -133,6 +133,8 @@ static int fou_gro_complete(struct sk_buff *skb, int nhoff)
133 int err = -ENOSYS; 133 int err = -ENOSYS;
134 const struct net_offload **offloads; 134 const struct net_offload **offloads;
135 135
136 udp_tunnel_gro_complete(skb, nhoff);
137
136 rcu_read_lock(); 138 rcu_read_lock();
137 offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads; 139 offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads;
138 ops = rcu_dereference(offloads[proto]); 140 ops = rcu_dereference(offloads[proto]);
diff --git a/net/ipv4/geneve.c b/net/ipv4/geneve.c
index 065cd94c640c..dedb21e99914 100644
--- a/net/ipv4/geneve.c
+++ b/net/ipv4/geneve.c
@@ -144,6 +144,8 @@ int geneve_xmit_skb(struct geneve_sock *gs, struct rtable *rt,
144 gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len); 144 gnvh = (struct genevehdr *)__skb_push(skb, sizeof(*gnvh) + opt_len);
145 geneve_build_header(gnvh, tun_flags, vni, opt_len, opt); 145 geneve_build_header(gnvh, tun_flags, vni, opt_len, opt);
146 146
147 skb_set_inner_protocol(skb, htons(ETH_P_TEB));
148
147 return udp_tunnel_xmit_skb(gs->sock, rt, skb, src, dst, 149 return udp_tunnel_xmit_skb(gs->sock, rt, skb, src, dst,
148 tos, ttl, df, src_port, dst_port, xnet); 150 tos, ttl, df, src_port, dst_port, xnet);
149} 151}
@@ -364,6 +366,7 @@ late_initcall(geneve_init_module);
364static void __exit geneve_cleanup_module(void) 366static void __exit geneve_cleanup_module(void)
365{ 367{
366 destroy_workqueue(geneve_wq); 368 destroy_workqueue(geneve_wq);
369 unregister_pernet_subsys(&geneve_net_ops);
367} 370}
368module_exit(geneve_cleanup_module); 371module_exit(geneve_cleanup_module);
369 372
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index fb70e3ecc3e4..bb15d0e03d4f 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -318,9 +318,7 @@ igmp_scount(struct ip_mc_list *pmc, int type, int gdeleted, int sdeleted)
318 return scount; 318 return scount;
319} 319}
320 320
321#define igmp_skb_size(skb) (*(unsigned int *)((skb)->cb)) 321static struct sk_buff *igmpv3_newpack(struct net_device *dev, unsigned int mtu)
322
323static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
324{ 322{
325 struct sk_buff *skb; 323 struct sk_buff *skb;
326 struct rtable *rt; 324 struct rtable *rt;
@@ -330,6 +328,7 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
330 struct flowi4 fl4; 328 struct flowi4 fl4;
331 int hlen = LL_RESERVED_SPACE(dev); 329 int hlen = LL_RESERVED_SPACE(dev);
332 int tlen = dev->needed_tailroom; 330 int tlen = dev->needed_tailroom;
331 unsigned int size = mtu;
333 332
334 while (1) { 333 while (1) {
335 skb = alloc_skb(size + hlen + tlen, 334 skb = alloc_skb(size + hlen + tlen,
@@ -341,7 +340,6 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
341 return NULL; 340 return NULL;
342 } 341 }
343 skb->priority = TC_PRIO_CONTROL; 342 skb->priority = TC_PRIO_CONTROL;
344 igmp_skb_size(skb) = size;
345 343
346 rt = ip_route_output_ports(net, &fl4, NULL, IGMPV3_ALL_MCR, 0, 344 rt = ip_route_output_ports(net, &fl4, NULL, IGMPV3_ALL_MCR, 0,
347 0, 0, 345 0, 0,
@@ -354,6 +352,8 @@ static struct sk_buff *igmpv3_newpack(struct net_device *dev, int size)
354 skb_dst_set(skb, &rt->dst); 352 skb_dst_set(skb, &rt->dst);
355 skb->dev = dev; 353 skb->dev = dev;
356 354
355 skb->reserved_tailroom = skb_end_offset(skb) -
356 min(mtu, skb_end_offset(skb));
357 skb_reserve(skb, hlen); 357 skb_reserve(skb, hlen);
358 358
359 skb_reset_network_header(skb); 359 skb_reset_network_header(skb);
@@ -423,8 +423,7 @@ static struct sk_buff *add_grhead(struct sk_buff *skb, struct ip_mc_list *pmc,
423 return skb; 423 return skb;
424} 424}
425 425
426#define AVAILABLE(skb) ((skb) ? ((skb)->dev ? igmp_skb_size(skb) - (skb)->len : \ 426#define AVAILABLE(skb) ((skb) ? skb_availroom(skb) : 0)
427 skb_tailroom(skb)) : 0)
428 427
429static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc, 428static struct sk_buff *add_grec(struct sk_buff *skb, struct ip_mc_list *pmc,
430 int type, int gdeleted, int sdeleted) 429 int type, int gdeleted, int sdeleted)
diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
index c373a9ad4555..9daf2177dc00 100644
--- a/net/ipv4/ip_sockglue.c
+++ b/net/ipv4/ip_sockglue.c
@@ -195,7 +195,7 @@ int ip_cmsg_send(struct net *net, struct msghdr *msg, struct ipcm_cookie *ipc,
195 for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) { 195 for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
196 if (!CMSG_OK(msg, cmsg)) 196 if (!CMSG_OK(msg, cmsg))
197 return -EINVAL; 197 return -EINVAL;
198#if defined(CONFIG_IPV6) 198#if IS_ENABLED(CONFIG_IPV6)
199 if (allow_ipv6 && 199 if (allow_ipv6 &&
200 cmsg->cmsg_level == SOL_IPV6 && 200 cmsg->cmsg_level == SOL_IPV6 &&
201 cmsg->cmsg_type == IPV6_PKTINFO) { 201 cmsg->cmsg_type == IPV6_PKTINFO) {
diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
index 3e861011e4a3..1a7e979e80ba 100644
--- a/net/ipv4/ip_vti.c
+++ b/net/ipv4/ip_vti.c
@@ -528,6 +528,7 @@ static struct rtnl_link_ops vti_link_ops __read_mostly = {
528 .validate = vti_tunnel_validate, 528 .validate = vti_tunnel_validate,
529 .newlink = vti_newlink, 529 .newlink = vti_newlink,
530 .changelink = vti_changelink, 530 .changelink = vti_changelink,
531 .dellink = ip_tunnel_dellink,
531 .get_size = vti_get_size, 532 .get_size = vti_get_size,
532 .fill_info = vti_fill_info, 533 .fill_info = vti_fill_info,
533}; 534};
diff --git a/net/ipv4/netfilter/nft_masq_ipv4.c b/net/ipv4/netfilter/nft_masq_ipv4.c
index c1023c445920..665de06561cd 100644
--- a/net/ipv4/netfilter/nft_masq_ipv4.c
+++ b/net/ipv4/netfilter/nft_masq_ipv4.c
@@ -24,6 +24,7 @@ static void nft_masq_ipv4_eval(const struct nft_expr *expr,
24 struct nf_nat_range range; 24 struct nf_nat_range range;
25 unsigned int verdict; 25 unsigned int verdict;
26 26
27 memset(&range, 0, sizeof(range));
27 range.flags = priv->flags; 28 range.flags = priv->flags;
28 29
29 verdict = nf_nat_masquerade_ipv4(pkt->skb, pkt->ops->hooknum, 30 verdict = nf_nat_masquerade_ipv4(pkt->skb, pkt->ops->hooknum,
diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
index 57f7c9804139..5d740cccf69e 100644
--- a/net/ipv4/ping.c
+++ b/net/ipv4/ping.c
@@ -217,6 +217,8 @@ static struct sock *ping_lookup(struct net *net, struct sk_buff *skb, u16 ident)
217 &ipv6_hdr(skb)->daddr)) 217 &ipv6_hdr(skb)->daddr))
218 continue; 218 continue;
219#endif 219#endif
220 } else {
221 continue;
220 } 222 }
221 223
222 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif) 224 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif)
@@ -853,16 +855,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
853 if (flags & MSG_OOB) 855 if (flags & MSG_OOB)
854 goto out; 856 goto out;
855 857
856 if (flags & MSG_ERRQUEUE) { 858 if (flags & MSG_ERRQUEUE)
857 if (family == AF_INET) { 859 return inet_recv_error(sk, msg, len, addr_len);
858 return ip_recv_error(sk, msg, len, addr_len);
859#if IS_ENABLED(CONFIG_IPV6)
860 } else if (family == AF_INET6) {
861 return pingv6_ops.ipv6_recv_error(sk, msg, len,
862 addr_len);
863#endif
864 }
865 }
866 860
867 skb = skb_recv_datagram(sk, flags, noblock, &err); 861 skb = skb_recv_datagram(sk, flags, noblock, &err);
868 if (!skb) 862 if (!skb)
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 39ec0c379545..38c2bcb8dd5d 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1598,7 +1598,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
1598 u32 urg_hole = 0; 1598 u32 urg_hole = 0;
1599 1599
1600 if (unlikely(flags & MSG_ERRQUEUE)) 1600 if (unlikely(flags & MSG_ERRQUEUE))
1601 return ip_recv_error(sk, msg, len, addr_len); 1601 return inet_recv_error(sk, msg, len, addr_len);
1602 1602
1603 if (sk_can_busy_loop(sk) && skb_queue_empty(&sk->sk_receive_queue) && 1603 if (sk_can_busy_loop(sk) && skb_queue_empty(&sk->sk_receive_queue) &&
1604 (sk->sk_state == TCP_ESTABLISHED)) 1604 (sk->sk_state == TCP_ESTABLISHED))
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index a12b455928e5..d107ee246a1d 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -2315,6 +2315,35 @@ static inline bool tcp_packet_delayed(const struct tcp_sock *tp)
2315 2315
2316/* Undo procedures. */ 2316/* Undo procedures. */
2317 2317
2318/* We can clear retrans_stamp when there are no retransmissions in the
2319 * window. It would seem that it is trivially available for us in
2320 * tp->retrans_out, however, that kind of assumptions doesn't consider
2321 * what will happen if errors occur when sending retransmission for the
2322 * second time. ...It could the that such segment has only
2323 * TCPCB_EVER_RETRANS set at the present time. It seems that checking
2324 * the head skb is enough except for some reneging corner cases that
2325 * are not worth the effort.
2326 *
2327 * Main reason for all this complexity is the fact that connection dying
2328 * time now depends on the validity of the retrans_stamp, in particular,
2329 * that successive retransmissions of a segment must not advance
2330 * retrans_stamp under any conditions.
2331 */
2332static bool tcp_any_retrans_done(const struct sock *sk)
2333{
2334 const struct tcp_sock *tp = tcp_sk(sk);
2335 struct sk_buff *skb;
2336
2337 if (tp->retrans_out)
2338 return true;
2339
2340 skb = tcp_write_queue_head(sk);
2341 if (unlikely(skb && TCP_SKB_CB(skb)->sacked & TCPCB_EVER_RETRANS))
2342 return true;
2343
2344 return false;
2345}
2346
2318#if FASTRETRANS_DEBUG > 1 2347#if FASTRETRANS_DEBUG > 1
2319static void DBGUNDO(struct sock *sk, const char *msg) 2348static void DBGUNDO(struct sock *sk, const char *msg)
2320{ 2349{
@@ -2410,6 +2439,8 @@ static bool tcp_try_undo_recovery(struct sock *sk)
2410 * is ACKed. For Reno it is MUST to prevent false 2439 * is ACKed. For Reno it is MUST to prevent false
2411 * fast retransmits (RFC2582). SACK TCP is safe. */ 2440 * fast retransmits (RFC2582). SACK TCP is safe. */
2412 tcp_moderate_cwnd(tp); 2441 tcp_moderate_cwnd(tp);
2442 if (!tcp_any_retrans_done(sk))
2443 tp->retrans_stamp = 0;
2413 return true; 2444 return true;
2414 } 2445 }
2415 tcp_set_ca_state(sk, TCP_CA_Open); 2446 tcp_set_ca_state(sk, TCP_CA_Open);
@@ -2430,35 +2461,6 @@ static bool tcp_try_undo_dsack(struct sock *sk)
2430 return false; 2461 return false;
2431} 2462}
2432 2463
2433/* We can clear retrans_stamp when there are no retransmissions in the
2434 * window. It would seem that it is trivially available for us in
2435 * tp->retrans_out, however, that kind of assumptions doesn't consider
2436 * what will happen if errors occur when sending retransmission for the
2437 * second time. ...It could the that such segment has only
2438 * TCPCB_EVER_RETRANS set at the present time. It seems that checking
2439 * the head skb is enough except for some reneging corner cases that
2440 * are not worth the effort.
2441 *
2442 * Main reason for all this complexity is the fact that connection dying
2443 * time now depends on the validity of the retrans_stamp, in particular,
2444 * that successive retransmissions of a segment must not advance
2445 * retrans_stamp under any conditions.
2446 */
2447static bool tcp_any_retrans_done(const struct sock *sk)
2448{
2449 const struct tcp_sock *tp = tcp_sk(sk);
2450 struct sk_buff *skb;
2451
2452 if (tp->retrans_out)
2453 return true;
2454
2455 skb = tcp_write_queue_head(sk);
2456 if (unlikely(skb && TCP_SKB_CB(skb)->sacked & TCPCB_EVER_RETRANS))
2457 return true;
2458
2459 return false;
2460}
2461
2462/* Undo during loss recovery after partial ACK or using F-RTO. */ 2464/* Undo during loss recovery after partial ACK or using F-RTO. */
2463static bool tcp_try_undo_loss(struct sock *sk, bool frto_undo) 2465static bool tcp_try_undo_loss(struct sock *sk, bool frto_undo)
2464{ 2466{
@@ -5229,7 +5231,7 @@ slow_path:
5229 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb)) 5231 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
5230 goto csum_error; 5232 goto csum_error;
5231 5233
5232 if (!th->ack && !th->rst) 5234 if (!th->ack && !th->rst && !th->syn)
5233 goto discard; 5235 goto discard;
5234 5236
5235 /* 5237 /*
@@ -5648,7 +5650,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
5648 goto discard; 5650 goto discard;
5649 } 5651 }
5650 5652
5651 if (!th->ack && !th->rst) 5653 if (!th->ack && !th->rst && !th->syn)
5652 goto discard; 5654 goto discard;
5653 5655
5654 if (!tcp_validate_incoming(sk, skb, th, 0)) 5656 if (!tcp_validate_incoming(sk, skb, th, 0))
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 9c7d7621466b..147be2024290 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -598,7 +598,10 @@ static void tcp_v4_send_reset(struct sock *sk, struct sk_buff *skb)
598 if (th->rst) 598 if (th->rst)
599 return; 599 return;
600 600
601 if (skb_rtable(skb)->rt_type != RTN_LOCAL) 601 /* If sk not NULL, it means we did a successful lookup and incoming
602 * route had to be correct. prequeue might have dropped our dst.
603 */
604 if (!sk && skb_rtable(skb)->rt_type != RTN_LOCAL)
602 return; 605 return;
603 606
604 /* Swap the send and the receive. */ 607 /* Swap the send and the receive. */
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 12c3c8ef3849..0e32d2e1bdbf 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -502,11 +502,11 @@ static int ip6gre_rcv(struct sk_buff *skb)
502 502
503 skb->protocol = gre_proto; 503 skb->protocol = gre_proto;
504 /* WCCP version 1 and 2 protocol decoding. 504 /* WCCP version 1 and 2 protocol decoding.
505 * - Change protocol to IP 505 * - Change protocol to IPv6
506 * - When dealing with WCCPv2, Skip extra 4 bytes in GRE header 506 * - When dealing with WCCPv2, Skip extra 4 bytes in GRE header
507 */ 507 */
508 if (flags == 0 && gre_proto == htons(ETH_P_WCCP)) { 508 if (flags == 0 && gre_proto == htons(ETH_P_WCCP)) {
509 skb->protocol = htons(ETH_P_IP); 509 skb->protocol = htons(ETH_P_IPV6);
510 if ((*(h + offset) & 0xF0) != 0x40) 510 if ((*(h + offset) & 0xF0) != 0x40)
511 offset += 4; 511 offset += 4;
512 } 512 }
@@ -961,8 +961,6 @@ static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu)
961 else 961 else
962 dev->flags &= ~IFF_POINTOPOINT; 962 dev->flags &= ~IFF_POINTOPOINT;
963 963
964 dev->iflink = p->link;
965
966 /* Precalculate GRE options length */ 964 /* Precalculate GRE options length */
967 if (t->parms.o_flags&(GRE_CSUM|GRE_KEY|GRE_SEQ)) { 965 if (t->parms.o_flags&(GRE_CSUM|GRE_KEY|GRE_SEQ)) {
968 if (t->parms.o_flags&GRE_CSUM) 966 if (t->parms.o_flags&GRE_CSUM)
@@ -1272,6 +1270,7 @@ static int ip6gre_tunnel_init(struct net_device *dev)
1272 u64_stats_init(&ip6gre_tunnel_stats->syncp); 1270 u64_stats_init(&ip6gre_tunnel_stats->syncp);
1273 } 1271 }
1274 1272
1273 dev->iflink = tunnel->parms.link;
1275 1274
1276 return 0; 1275 return 0;
1277} 1276}
@@ -1481,6 +1480,8 @@ static int ip6gre_tap_init(struct net_device *dev)
1481 if (!dev->tstats) 1480 if (!dev->tstats)
1482 return -ENOMEM; 1481 return -ENOMEM;
1483 1482
1483 dev->iflink = tunnel->parms.link;
1484
1484 return 0; 1485 return 0;
1485} 1486}
1486 1487
diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
index a071563a7e6e..01e12d0d8fcc 100644
--- a/net/ipv6/ip6_offload.c
+++ b/net/ipv6/ip6_offload.c
@@ -69,7 +69,8 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
69 int nhoff; 69 int nhoff;
70 70
71 if (unlikely(skb_shinfo(skb)->gso_type & 71 if (unlikely(skb_shinfo(skb)->gso_type &
72 ~(SKB_GSO_UDP | 72 ~(SKB_GSO_TCPV4 |
73 SKB_GSO_UDP |
73 SKB_GSO_DODGY | 74 SKB_GSO_DODGY |
74 SKB_GSO_TCP_ECN | 75 SKB_GSO_TCP_ECN |
75 SKB_GSO_GRE | 76 SKB_GSO_GRE |
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 9409887fb664..9cb94cfa0ae7 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -272,9 +272,6 @@ static int ip6_tnl_create2(struct net_device *dev)
272 int err; 272 int err;
273 273
274 t = netdev_priv(dev); 274 t = netdev_priv(dev);
275 err = ip6_tnl_dev_init(dev);
276 if (err < 0)
277 goto out;
278 275
279 err = register_netdevice(dev); 276 err = register_netdevice(dev);
280 if (err < 0) 277 if (err < 0)
@@ -1462,6 +1459,7 @@ ip6_tnl_change_mtu(struct net_device *dev, int new_mtu)
1462 1459
1463 1460
1464static const struct net_device_ops ip6_tnl_netdev_ops = { 1461static const struct net_device_ops ip6_tnl_netdev_ops = {
1462 .ndo_init = ip6_tnl_dev_init,
1465 .ndo_uninit = ip6_tnl_dev_uninit, 1463 .ndo_uninit = ip6_tnl_dev_uninit,
1466 .ndo_start_xmit = ip6_tnl_xmit, 1464 .ndo_start_xmit = ip6_tnl_xmit,
1467 .ndo_do_ioctl = ip6_tnl_ioctl, 1465 .ndo_do_ioctl = ip6_tnl_ioctl,
@@ -1546,16 +1544,10 @@ static int __net_init ip6_fb_tnl_dev_init(struct net_device *dev)
1546 struct ip6_tnl *t = netdev_priv(dev); 1544 struct ip6_tnl *t = netdev_priv(dev);
1547 struct net *net = dev_net(dev); 1545 struct net *net = dev_net(dev);
1548 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id); 1546 struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
1549 int err = ip6_tnl_dev_init_gen(dev);
1550
1551 if (err)
1552 return err;
1553 1547
1554 t->parms.proto = IPPROTO_IPV6; 1548 t->parms.proto = IPPROTO_IPV6;
1555 dev_hold(dev); 1549 dev_hold(dev);
1556 1550
1557 ip6_tnl_link_config(t);
1558
1559 rcu_assign_pointer(ip6n->tnls_wc[0], t); 1551 rcu_assign_pointer(ip6n->tnls_wc[0], t);
1560 return 0; 1552 return 0;
1561} 1553}
diff --git a/net/ipv6/ip6_udp_tunnel.c b/net/ipv6/ip6_udp_tunnel.c
index b04ed72c4542..8db6c98fe218 100644
--- a/net/ipv6/ip6_udp_tunnel.c
+++ b/net/ipv6/ip6_udp_tunnel.c
@@ -79,15 +79,13 @@ int udp_tunnel6_xmit_skb(struct socket *sock, struct dst_entry *dst,
79 uh->source = src_port; 79 uh->source = src_port;
80 80
81 uh->len = htons(skb->len); 81 uh->len = htons(skb->len);
82 uh->check = 0;
83 82
84 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); 83 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
85 IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED 84 IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED
86 | IPSKB_REROUTED); 85 | IPSKB_REROUTED);
87 skb_dst_set(skb, dst); 86 skb_dst_set(skb, dst);
88 87
89 udp6_set_csum(udp_get_no_check6_tx(sk), skb, &inet6_sk(sk)->saddr, 88 udp6_set_csum(udp_get_no_check6_tx(sk), skb, saddr, daddr, skb->len);
90 &sk->sk_v6_daddr, skb->len);
91 89
92 __skb_push(skb, sizeof(*ip6h)); 90 __skb_push(skb, sizeof(*ip6h));
93 skb_reset_network_header(skb); 91 skb_reset_network_header(skb);
diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
index d440bb585524..bcda14de7f84 100644
--- a/net/ipv6/ip6_vti.c
+++ b/net/ipv6/ip6_vti.c
@@ -172,10 +172,6 @@ static int vti6_tnl_create2(struct net_device *dev)
172 struct vti6_net *ip6n = net_generic(net, vti6_net_id); 172 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
173 int err; 173 int err;
174 174
175 err = vti6_dev_init(dev);
176 if (err < 0)
177 goto out;
178
179 err = register_netdevice(dev); 175 err = register_netdevice(dev);
180 if (err < 0) 176 if (err < 0)
181 goto out; 177 goto out;
@@ -783,6 +779,7 @@ static int vti6_change_mtu(struct net_device *dev, int new_mtu)
783} 779}
784 780
785static const struct net_device_ops vti6_netdev_ops = { 781static const struct net_device_ops vti6_netdev_ops = {
782 .ndo_init = vti6_dev_init,
786 .ndo_uninit = vti6_dev_uninit, 783 .ndo_uninit = vti6_dev_uninit,
787 .ndo_start_xmit = vti6_tnl_xmit, 784 .ndo_start_xmit = vti6_tnl_xmit,
788 .ndo_do_ioctl = vti6_ioctl, 785 .ndo_do_ioctl = vti6_ioctl,
@@ -852,16 +849,10 @@ static int __net_init vti6_fb_tnl_dev_init(struct net_device *dev)
852 struct ip6_tnl *t = netdev_priv(dev); 849 struct ip6_tnl *t = netdev_priv(dev);
853 struct net *net = dev_net(dev); 850 struct net *net = dev_net(dev);
854 struct vti6_net *ip6n = net_generic(net, vti6_net_id); 851 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
855 int err = vti6_dev_init_gen(dev);
856
857 if (err)
858 return err;
859 852
860 t->parms.proto = IPPROTO_IPV6; 853 t->parms.proto = IPPROTO_IPV6;
861 dev_hold(dev); 854 dev_hold(dev);
862 855
863 vti6_link_config(t);
864
865 rcu_assign_pointer(ip6n->tnls_wc[0], t); 856 rcu_assign_pointer(ip6n->tnls_wc[0], t);
866 return 0; 857 return 0;
867} 858}
@@ -914,6 +905,15 @@ static int vti6_newlink(struct net *src_net, struct net_device *dev,
914 return vti6_tnl_create2(dev); 905 return vti6_tnl_create2(dev);
915} 906}
916 907
908static void vti6_dellink(struct net_device *dev, struct list_head *head)
909{
910 struct net *net = dev_net(dev);
911 struct vti6_net *ip6n = net_generic(net, vti6_net_id);
912
913 if (dev != ip6n->fb_tnl_dev)
914 unregister_netdevice_queue(dev, head);
915}
916
917static int vti6_changelink(struct net_device *dev, struct nlattr *tb[], 917static int vti6_changelink(struct net_device *dev, struct nlattr *tb[],
918 struct nlattr *data[]) 918 struct nlattr *data[])
919{ 919{
@@ -989,6 +989,7 @@ static struct rtnl_link_ops vti6_link_ops __read_mostly = {
989 .setup = vti6_dev_setup, 989 .setup = vti6_dev_setup,
990 .validate = vti6_validate, 990 .validate = vti6_validate,
991 .newlink = vti6_newlink, 991 .newlink = vti6_newlink,
992 .dellink = vti6_dellink,
992 .changelink = vti6_changelink, 993 .changelink = vti6_changelink,
993 .get_size = vti6_get_size, 994 .get_size = vti6_get_size,
994 .fill_info = vti6_fill_info, 995 .fill_info = vti6_fill_info,
@@ -1029,6 +1030,7 @@ static int __net_init vti6_init_net(struct net *net)
1029 if (!ip6n->fb_tnl_dev) 1030 if (!ip6n->fb_tnl_dev)
1030 goto err_alloc_dev; 1031 goto err_alloc_dev;
1031 dev_net_set(ip6n->fb_tnl_dev, net); 1032 dev_net_set(ip6n->fb_tnl_dev, net);
1033 ip6n->fb_tnl_dev->rtnl_link_ops = &vti6_link_ops;
1032 1034
1033 err = vti6_fb_tnl_dev_init(ip6n->fb_tnl_dev); 1035 err = vti6_fb_tnl_dev_init(ip6n->fb_tnl_dev);
1034 if (err < 0) 1036 if (err < 0)
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 0171f08325c3..1a01d79b8698 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -1439,6 +1439,10 @@ reg_pernet_fail:
1439 1439
1440void ip6_mr_cleanup(void) 1440void ip6_mr_cleanup(void)
1441{ 1441{
1442 rtnl_unregister(RTNL_FAMILY_IP6MR, RTM_GETROUTE);
1443#ifdef CONFIG_IPV6_PIMSM_V2
1444 inet6_del_protocol(&pim6_protocol, IPPROTO_PIM);
1445#endif
1442 unregister_netdevice_notifier(&ip6_mr_notifier); 1446 unregister_netdevice_notifier(&ip6_mr_notifier);
1443 unregister_pernet_subsys(&ip6mr_net_ops); 1447 unregister_pernet_subsys(&ip6mr_net_ops);
1444 kmem_cache_destroy(mrt_cachep); 1448 kmem_cache_destroy(mrt_cachep);
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c
index 9648de2b6745..ed2c4e400b46 100644
--- a/net/ipv6/mcast.c
+++ b/net/ipv6/mcast.c
@@ -1550,7 +1550,7 @@ static void ip6_mc_hdr(struct sock *sk, struct sk_buff *skb,
1550 hdr->daddr = *daddr; 1550 hdr->daddr = *daddr;
1551} 1551}
1552 1552
1553static struct sk_buff *mld_newpack(struct inet6_dev *idev, int size) 1553static struct sk_buff *mld_newpack(struct inet6_dev *idev, unsigned int mtu)
1554{ 1554{
1555 struct net_device *dev = idev->dev; 1555 struct net_device *dev = idev->dev;
1556 struct net *net = dev_net(dev); 1556 struct net *net = dev_net(dev);
@@ -1561,13 +1561,13 @@ static struct sk_buff *mld_newpack(struct inet6_dev *idev, int size)
1561 const struct in6_addr *saddr; 1561 const struct in6_addr *saddr;
1562 int hlen = LL_RESERVED_SPACE(dev); 1562 int hlen = LL_RESERVED_SPACE(dev);
1563 int tlen = dev->needed_tailroom; 1563 int tlen = dev->needed_tailroom;
1564 unsigned int size = mtu + hlen + tlen;
1564 int err; 1565 int err;
1565 u8 ra[8] = { IPPROTO_ICMPV6, 0, 1566 u8 ra[8] = { IPPROTO_ICMPV6, 0,
1566 IPV6_TLV_ROUTERALERT, 2, 0, 0, 1567 IPV6_TLV_ROUTERALERT, 2, 0, 0,
1567 IPV6_TLV_PADN, 0 }; 1568 IPV6_TLV_PADN, 0 };
1568 1569
1569 /* we assume size > sizeof(ra) here */ 1570 /* we assume size > sizeof(ra) here */
1570 size += hlen + tlen;
1571 /* limit our allocations to order-0 page */ 1571 /* limit our allocations to order-0 page */
1572 size = min_t(int, size, SKB_MAX_ORDER(0, 0)); 1572 size = min_t(int, size, SKB_MAX_ORDER(0, 0));
1573 skb = sock_alloc_send_skb(sk, size, 1, &err); 1573 skb = sock_alloc_send_skb(sk, size, 1, &err);
@@ -1576,6 +1576,8 @@ static struct sk_buff *mld_newpack(struct inet6_dev *idev, int size)
1576 return NULL; 1576 return NULL;
1577 1577
1578 skb->priority = TC_PRIO_CONTROL; 1578 skb->priority = TC_PRIO_CONTROL;
1579 skb->reserved_tailroom = skb_end_offset(skb) -
1580 min(mtu, skb_end_offset(skb));
1579 skb_reserve(skb, hlen); 1581 skb_reserve(skb, hlen);
1580 1582
1581 if (__ipv6_get_lladdr(idev, &addr_buf, IFA_F_TENTATIVE)) { 1583 if (__ipv6_get_lladdr(idev, &addr_buf, IFA_F_TENTATIVE)) {
@@ -1690,8 +1692,7 @@ static struct sk_buff *add_grhead(struct sk_buff *skb, struct ifmcaddr6 *pmc,
1690 return skb; 1692 return skb;
1691} 1693}
1692 1694
1693#define AVAILABLE(skb) ((skb) ? ((skb)->dev ? (skb)->dev->mtu - (skb)->len : \ 1695#define AVAILABLE(skb) ((skb) ? skb_availroom(skb) : 0)
1694 skb_tailroom(skb)) : 0)
1695 1696
1696static struct sk_buff *add_grec(struct sk_buff *skb, struct ifmcaddr6 *pmc, 1697static struct sk_buff *add_grec(struct sk_buff *skb, struct ifmcaddr6 *pmc,
1697 int type, int gdeleted, int sdeleted, int crsend) 1698 int type, int gdeleted, int sdeleted, int crsend)
diff --git a/net/ipv6/netfilter/nft_masq_ipv6.c b/net/ipv6/netfilter/nft_masq_ipv6.c
index 8a7ac685076d..529c119cbb14 100644
--- a/net/ipv6/netfilter/nft_masq_ipv6.c
+++ b/net/ipv6/netfilter/nft_masq_ipv6.c
@@ -25,6 +25,7 @@ static void nft_masq_ipv6_eval(const struct nft_expr *expr,
25 struct nf_nat_range range; 25 struct nf_nat_range range;
26 unsigned int verdict; 26 unsigned int verdict;
27 27
28 memset(&range, 0, sizeof(range));
28 range.flags = priv->flags; 29 range.flags = priv->flags;
29 30
30 verdict = nf_nat_masquerade_ipv6(pkt->skb, &range, pkt->out); 31 verdict = nf_nat_masquerade_ipv6(pkt->skb, &range, pkt->out);
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 58e5b4710127..a24557a1c1d8 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -195,10 +195,8 @@ static int ipip6_tunnel_create(struct net_device *dev)
195 struct sit_net *sitn = net_generic(net, sit_net_id); 195 struct sit_net *sitn = net_generic(net, sit_net_id);
196 int err; 196 int err;
197 197
198 err = ipip6_tunnel_init(dev); 198 memcpy(dev->dev_addr, &t->parms.iph.saddr, 4);
199 if (err < 0) 199 memcpy(dev->broadcast, &t->parms.iph.daddr, 4);
200 goto out;
201 ipip6_tunnel_clone_6rd(dev, sitn);
202 200
203 if ((__force u16)t->parms.i_flags & SIT_ISATAP) 201 if ((__force u16)t->parms.i_flags & SIT_ISATAP)
204 dev->priv_flags |= IFF_ISATAP; 202 dev->priv_flags |= IFF_ISATAP;
@@ -207,7 +205,8 @@ static int ipip6_tunnel_create(struct net_device *dev)
207 if (err < 0) 205 if (err < 0)
208 goto out; 206 goto out;
209 207
210 strcpy(t->parms.name, dev->name); 208 ipip6_tunnel_clone_6rd(dev, sitn);
209
211 dev->rtnl_link_ops = &sit_link_ops; 210 dev->rtnl_link_ops = &sit_link_ops;
212 211
213 dev_hold(dev); 212 dev_hold(dev);
@@ -1330,6 +1329,7 @@ static int ipip6_tunnel_change_mtu(struct net_device *dev, int new_mtu)
1330} 1329}
1331 1330
1332static const struct net_device_ops ipip6_netdev_ops = { 1331static const struct net_device_ops ipip6_netdev_ops = {
1332 .ndo_init = ipip6_tunnel_init,
1333 .ndo_uninit = ipip6_tunnel_uninit, 1333 .ndo_uninit = ipip6_tunnel_uninit,
1334 .ndo_start_xmit = sit_tunnel_xmit, 1334 .ndo_start_xmit = sit_tunnel_xmit,
1335 .ndo_do_ioctl = ipip6_tunnel_ioctl, 1335 .ndo_do_ioctl = ipip6_tunnel_ioctl,
@@ -1378,9 +1378,7 @@ static int ipip6_tunnel_init(struct net_device *dev)
1378 1378
1379 tunnel->dev = dev; 1379 tunnel->dev = dev;
1380 tunnel->net = dev_net(dev); 1380 tunnel->net = dev_net(dev);
1381 1381 strcpy(tunnel->parms.name, dev->name);
1382 memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
1383 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
1384 1382
1385 ipip6_tunnel_bind_dev(dev); 1383 ipip6_tunnel_bind_dev(dev);
1386 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); 1384 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
@@ -1405,7 +1403,6 @@ static int __net_init ipip6_fb_tunnel_init(struct net_device *dev)
1405 1403
1406 tunnel->dev = dev; 1404 tunnel->dev = dev;
1407 tunnel->net = dev_net(dev); 1405 tunnel->net = dev_net(dev);
1408 strcpy(tunnel->parms.name, dev->name);
1409 1406
1410 iph->version = 4; 1407 iph->version = 4;
1411 iph->protocol = IPPROTO_IPV6; 1408 iph->protocol = IPPROTO_IPV6;
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index ace29b60813c..dc495ae2ead0 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -903,7 +903,10 @@ static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb)
903 if (th->rst) 903 if (th->rst)
904 return; 904 return;
905 905
906 if (!ipv6_unicast_destination(skb)) 906 /* If sk not NULL, it means we did a successful lookup and incoming
907 * route had to be correct. prequeue might have dropped our dst.
908 */
909 if (!sk && !ipv6_unicast_destination(skb))
907 return; 910 return;
908 911
909#ifdef CONFIG_TCP_MD5SIG 912#ifdef CONFIG_TCP_MD5SIG
diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c
index 91729b807c7d..1b095ca37aa4 100644
--- a/net/ipx/af_ipx.c
+++ b/net/ipx/af_ipx.c
@@ -1764,6 +1764,7 @@ static int ipx_recvmsg(struct kiocb *iocb, struct socket *sock,
1764 struct ipxhdr *ipx = NULL; 1764 struct ipxhdr *ipx = NULL;
1765 struct sk_buff *skb; 1765 struct sk_buff *skb;
1766 int copied, rc; 1766 int copied, rc;
1767 bool locked = true;
1767 1768
1768 lock_sock(sk); 1769 lock_sock(sk);
1769 /* put the autobinding in */ 1770 /* put the autobinding in */
@@ -1790,6 +1791,8 @@ static int ipx_recvmsg(struct kiocb *iocb, struct socket *sock,
1790 if (sock_flag(sk, SOCK_ZAPPED)) 1791 if (sock_flag(sk, SOCK_ZAPPED))
1791 goto out; 1792 goto out;
1792 1793
1794 release_sock(sk);
1795 locked = false;
1793 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, 1796 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
1794 flags & MSG_DONTWAIT, &rc); 1797 flags & MSG_DONTWAIT, &rc);
1795 if (!skb) { 1798 if (!skb) {
@@ -1826,7 +1829,8 @@ static int ipx_recvmsg(struct kiocb *iocb, struct socket *sock,
1826out_free: 1829out_free:
1827 skb_free_datagram(sk, skb); 1830 skb_free_datagram(sk, skb);
1828out: 1831out:
1829 release_sock(sk); 1832 if (locked)
1833 release_sock(sk);
1830 return rc; 1834 return rc;
1831} 1835}
1832 1836
diff --git a/net/mac80211/aes_ccm.c b/net/mac80211/aes_ccm.c
index ec24378caaaf..09d9caaec591 100644
--- a/net/mac80211/aes_ccm.c
+++ b/net/mac80211/aes_ccm.c
@@ -53,6 +53,9 @@ int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
53 __aligned(__alignof__(struct aead_request)); 53 __aligned(__alignof__(struct aead_request));
54 struct aead_request *aead_req = (void *) aead_req_data; 54 struct aead_request *aead_req = (void *) aead_req_data;
55 55
56 if (data_len == 0)
57 return -EINVAL;
58
56 memset(aead_req, 0, sizeof(aead_req_data)); 59 memset(aead_req, 0, sizeof(aead_req_data));
57 60
58 sg_init_one(&pt, data, data_len); 61 sg_init_one(&pt, data, data_len);
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 56b53571c807..509bc157ce55 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -805,7 +805,7 @@ ieee80211_ibss_process_chanswitch(struct ieee80211_sub_if_data *sdata,
805 805
806 memset(&params, 0, sizeof(params)); 806 memset(&params, 0, sizeof(params));
807 memset(&csa_ie, 0, sizeof(csa_ie)); 807 memset(&csa_ie, 0, sizeof(csa_ie));
808 err = ieee80211_parse_ch_switch_ie(sdata, elems, beacon, 808 err = ieee80211_parse_ch_switch_ie(sdata, elems,
809 ifibss->chandef.chan->band, 809 ifibss->chandef.chan->band,
810 sta_flags, ifibss->bssid, &csa_ie); 810 sta_flags, ifibss->bssid, &csa_ie);
811 /* can't switch to destination channel, fail */ 811 /* can't switch to destination channel, fail */
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index c2aaec4dfcf0..8c68da30595d 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1642,7 +1642,6 @@ void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,
1642 * ieee80211_parse_ch_switch_ie - parses channel switch IEs 1642 * ieee80211_parse_ch_switch_ie - parses channel switch IEs
1643 * @sdata: the sdata of the interface which has received the frame 1643 * @sdata: the sdata of the interface which has received the frame
1644 * @elems: parsed 802.11 elements received with the frame 1644 * @elems: parsed 802.11 elements received with the frame
1645 * @beacon: indicates if the frame was a beacon or probe response
1646 * @current_band: indicates the current band 1645 * @current_band: indicates the current band
1647 * @sta_flags: contains information about own capabilities and restrictions 1646 * @sta_flags: contains information about own capabilities and restrictions
1648 * to decide which channel switch announcements can be accepted. Only the 1647 * to decide which channel switch announcements can be accepted. Only the
@@ -1656,7 +1655,7 @@ void ieee80211_process_measurement_req(struct ieee80211_sub_if_data *sdata,
1656 * Return: 0 on success, <0 on error and >0 if there is nothing to parse. 1655 * Return: 0 on success, <0 on error and >0 if there is nothing to parse.
1657 */ 1656 */
1658int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata, 1657int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata,
1659 struct ieee802_11_elems *elems, bool beacon, 1658 struct ieee802_11_elems *elems,
1660 enum ieee80211_band current_band, 1659 enum ieee80211_band current_band,
1661 u32 sta_flags, u8 *bssid, 1660 u32 sta_flags, u8 *bssid,
1662 struct ieee80211_csa_ie *csa_ie); 1661 struct ieee80211_csa_ie *csa_ie);
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index af237223a8cd..653f5eb07a27 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -766,10 +766,12 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
766 int i, flushed; 766 int i, flushed;
767 struct ps_data *ps; 767 struct ps_data *ps;
768 struct cfg80211_chan_def chandef; 768 struct cfg80211_chan_def chandef;
769 bool cancel_scan;
769 770
770 clear_bit(SDATA_STATE_RUNNING, &sdata->state); 771 clear_bit(SDATA_STATE_RUNNING, &sdata->state);
771 772
772 if (rcu_access_pointer(local->scan_sdata) == sdata) 773 cancel_scan = rcu_access_pointer(local->scan_sdata) == sdata;
774 if (cancel_scan)
773 ieee80211_scan_cancel(local); 775 ieee80211_scan_cancel(local);
774 776
775 /* 777 /*
@@ -898,6 +900,8 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
898 list_del(&sdata->u.vlan.list); 900 list_del(&sdata->u.vlan.list);
899 mutex_unlock(&local->mtx); 901 mutex_unlock(&local->mtx);
900 RCU_INIT_POINTER(sdata->vif.chanctx_conf, NULL); 902 RCU_INIT_POINTER(sdata->vif.chanctx_conf, NULL);
903 /* see comment in the default case below */
904 ieee80211_free_keys(sdata, true);
901 /* no need to tell driver */ 905 /* no need to tell driver */
902 break; 906 break;
903 case NL80211_IFTYPE_MONITOR: 907 case NL80211_IFTYPE_MONITOR:
@@ -923,17 +927,16 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
923 /* 927 /*
924 * When we get here, the interface is marked down. 928 * When we get here, the interface is marked down.
925 * Free the remaining keys, if there are any 929 * Free the remaining keys, if there are any
926 * (shouldn't be, except maybe in WDS mode?) 930 * (which can happen in AP mode if userspace sets
931 * keys before the interface is operating, and maybe
932 * also in WDS mode)
927 * 933 *
928 * Force the key freeing to always synchronize_net() 934 * Force the key freeing to always synchronize_net()
929 * to wait for the RX path in case it is using this 935 * to wait for the RX path in case it is using this
930 * interface enqueuing frames * at this very time on 936 * interface enqueuing frames at this very time on
931 * another CPU. 937 * another CPU.
932 */ 938 */
933 ieee80211_free_keys(sdata, true); 939 ieee80211_free_keys(sdata, true);
934
935 /* fall through */
936 case NL80211_IFTYPE_AP:
937 skb_queue_purge(&sdata->skb_queue); 940 skb_queue_purge(&sdata->skb_queue);
938 } 941 }
939 942
@@ -991,6 +994,9 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
991 994
992 ieee80211_recalc_ps(local, -1); 995 ieee80211_recalc_ps(local, -1);
993 996
997 if (cancel_scan)
998 flush_delayed_work(&local->scan_work);
999
994 if (local->open_count == 0) { 1000 if (local->open_count == 0) {
995 ieee80211_stop_device(local); 1001 ieee80211_stop_device(local);
996 1002
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index e9f99c1e3fad..0c8b2a77d312 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -874,7 +874,7 @@ ieee80211_mesh_process_chnswitch(struct ieee80211_sub_if_data *sdata,
874 874
875 memset(&params, 0, sizeof(params)); 875 memset(&params, 0, sizeof(params));
876 memset(&csa_ie, 0, sizeof(csa_ie)); 876 memset(&csa_ie, 0, sizeof(csa_ie));
877 err = ieee80211_parse_ch_switch_ie(sdata, elems, beacon, band, 877 err = ieee80211_parse_ch_switch_ie(sdata, elems, band,
878 sta_flags, sdata->vif.addr, 878 sta_flags, sdata->vif.addr,
879 &csa_ie); 879 &csa_ie);
880 if (err < 0) 880 if (err < 0)
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 2de88704278b..93af0f1c9d99 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -1072,7 +1072,7 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1072 1072
1073 current_band = cbss->channel->band; 1073 current_band = cbss->channel->band;
1074 memset(&csa_ie, 0, sizeof(csa_ie)); 1074 memset(&csa_ie, 0, sizeof(csa_ie));
1075 res = ieee80211_parse_ch_switch_ie(sdata, elems, beacon, current_band, 1075 res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
1076 ifmgd->flags, 1076 ifmgd->flags,
1077 ifmgd->associated->bssid, &csa_ie); 1077 ifmgd->associated->bssid, &csa_ie);
1078 if (res < 0) 1078 if (res < 0)
@@ -1168,7 +1168,8 @@ ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
1168 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work); 1168 ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
1169 else 1169 else
1170 mod_timer(&ifmgd->chswitch_timer, 1170 mod_timer(&ifmgd->chswitch_timer,
1171 TU_TO_EXP_TIME(csa_ie.count * cbss->beacon_interval)); 1171 TU_TO_EXP_TIME((csa_ie.count - 1) *
1172 cbss->beacon_interval));
1172} 1173}
1173 1174
1174static bool 1175static bool
diff --git a/net/mac80211/rc80211_minstrel_ht.c b/net/mac80211/rc80211_minstrel_ht.c
index df90ce2db00c..408fd8ab4eef 100644
--- a/net/mac80211/rc80211_minstrel_ht.c
+++ b/net/mac80211/rc80211_minstrel_ht.c
@@ -252,19 +252,16 @@ minstrel_ht_sort_best_tp_rates(struct minstrel_ht_sta *mi, u8 index,
252 cur_thr = mi->groups[cur_group].rates[cur_idx].cur_tp; 252 cur_thr = mi->groups[cur_group].rates[cur_idx].cur_tp;
253 cur_prob = mi->groups[cur_group].rates[cur_idx].probability; 253 cur_prob = mi->groups[cur_group].rates[cur_idx].probability;
254 254
255 tmp_group = tp_list[j - 1] / MCS_GROUP_RATES; 255 do {
256 tmp_idx = tp_list[j - 1] % MCS_GROUP_RATES;
257 tmp_thr = mi->groups[tmp_group].rates[tmp_idx].cur_tp;
258 tmp_prob = mi->groups[tmp_group].rates[tmp_idx].probability;
259
260 while (j > 0 && (cur_thr > tmp_thr ||
261 (cur_thr == tmp_thr && cur_prob > tmp_prob))) {
262 j--;
263 tmp_group = tp_list[j - 1] / MCS_GROUP_RATES; 256 tmp_group = tp_list[j - 1] / MCS_GROUP_RATES;
264 tmp_idx = tp_list[j - 1] % MCS_GROUP_RATES; 257 tmp_idx = tp_list[j - 1] % MCS_GROUP_RATES;
265 tmp_thr = mi->groups[tmp_group].rates[tmp_idx].cur_tp; 258 tmp_thr = mi->groups[tmp_group].rates[tmp_idx].cur_tp;
266 tmp_prob = mi->groups[tmp_group].rates[tmp_idx].probability; 259 tmp_prob = mi->groups[tmp_group].rates[tmp_idx].probability;
267 } 260 if (cur_thr < tmp_thr ||
261 (cur_thr == tmp_thr && cur_prob <= tmp_prob))
262 break;
263 j--;
264 } while (j > 0);
268 265
269 if (j < MAX_THR_RATES - 1) { 266 if (j < MAX_THR_RATES - 1) {
270 memmove(&tp_list[j + 1], &tp_list[j], (sizeof(*tp_list) * 267 memmove(&tp_list[j + 1], &tp_list[j], (sizeof(*tp_list) *
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index b04ca4049c95..a37f9af634cb 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -1678,11 +1678,14 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1678 sc = le16_to_cpu(hdr->seq_ctrl); 1678 sc = le16_to_cpu(hdr->seq_ctrl);
1679 frag = sc & IEEE80211_SCTL_FRAG; 1679 frag = sc & IEEE80211_SCTL_FRAG;
1680 1680
1681 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) || 1681 if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
1682 is_multicast_ether_addr(hdr->addr1))) { 1682 goto out;
1683 /* not fragmented */ 1683
1684 if (is_multicast_ether_addr(hdr->addr1)) {
1685 rx->local->dot11MulticastReceivedFrameCount++;
1684 goto out; 1686 goto out;
1685 } 1687 }
1688
1686 I802_DEBUG_INC(rx->local->rx_handlers_fragments); 1689 I802_DEBUG_INC(rx->local->rx_handlers_fragments);
1687 1690
1688 if (skb_linearize(rx->skb)) 1691 if (skb_linearize(rx->skb))
@@ -1775,10 +1778,7 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
1775 out: 1778 out:
1776 if (rx->sta) 1779 if (rx->sta)
1777 rx->sta->rx_packets++; 1780 rx->sta->rx_packets++;
1778 if (is_multicast_ether_addr(hdr->addr1)) 1781 ieee80211_led_rx(rx->local);
1779 rx->local->dot11MulticastReceivedFrameCount++;
1780 else
1781 ieee80211_led_rx(rx->local);
1782 return RX_CONTINUE; 1782 return RX_CONTINUE;
1783} 1783}
1784 1784
diff --git a/net/mac80211/spectmgmt.c b/net/mac80211/spectmgmt.c
index 6ab009070084..efeba56c913b 100644
--- a/net/mac80211/spectmgmt.c
+++ b/net/mac80211/spectmgmt.c
@@ -22,7 +22,7 @@
22#include "wme.h" 22#include "wme.h"
23 23
24int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata, 24int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata,
25 struct ieee802_11_elems *elems, bool beacon, 25 struct ieee802_11_elems *elems,
26 enum ieee80211_band current_band, 26 enum ieee80211_band current_band,
27 u32 sta_flags, u8 *bssid, 27 u32 sta_flags, u8 *bssid,
28 struct ieee80211_csa_ie *csa_ie) 28 struct ieee80211_csa_ie *csa_ie)
@@ -91,19 +91,13 @@ int ieee80211_parse_ch_switch_ie(struct ieee80211_sub_if_data *sdata,
91 return -EINVAL; 91 return -EINVAL;
92 } 92 }
93 93
94 if (!beacon && sec_chan_offs) { 94 if (sec_chan_offs) {
95 secondary_channel_offset = sec_chan_offs->sec_chan_offs; 95 secondary_channel_offset = sec_chan_offs->sec_chan_offs;
96 } else if (beacon && ht_oper) {
97 secondary_channel_offset =
98 ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
99 } else if (!(sta_flags & IEEE80211_STA_DISABLE_HT)) { 96 } else if (!(sta_flags & IEEE80211_STA_DISABLE_HT)) {
100 /* If it's not a beacon, HT is enabled and the IE not present, 97 /* If the secondary channel offset IE is not present,
101 * it's 20 MHz, 802.11-2012 8.5.2.6: 98 * we can't know what's the post-CSA offset, so the
102 * This element [the Secondary Channel Offset Element] is 99 * best we can do is use 20MHz.
103 * present when switching to a 40 MHz channel. It may be 100 */
104 * present when switching to a 20 MHz channel (in which
105 * case the secondary channel offset is set to SCN).
106 */
107 secondary_channel_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE; 101 secondary_channel_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
108 } 102 }
109 103
diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index 86f9d76b1464..d259da3ce67a 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -1863,6 +1863,12 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
1863 if (*op < IP_SET_OP_VERSION) { 1863 if (*op < IP_SET_OP_VERSION) {
1864 /* Check the version at the beginning of operations */ 1864 /* Check the version at the beginning of operations */
1865 struct ip_set_req_version *req_version = data; 1865 struct ip_set_req_version *req_version = data;
1866
1867 if (*len < sizeof(struct ip_set_req_version)) {
1868 ret = -EINVAL;
1869 goto done;
1870 }
1871
1866 if (req_version->version != IPSET_PROTOCOL) { 1872 if (req_version->version != IPSET_PROTOCOL) {
1867 ret = -EPROTO; 1873 ret = -EPROTO;
1868 goto done; 1874 goto done;
diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
index 437a3663ad03..bd90bf8107da 100644
--- a/net/netfilter/ipvs/ip_vs_xmit.c
+++ b/net/netfilter/ipvs/ip_vs_xmit.c
@@ -846,6 +846,8 @@ ip_vs_prepare_tunneled_skb(struct sk_buff *skb, int skb_af,
846 new_skb = skb_realloc_headroom(skb, max_headroom); 846 new_skb = skb_realloc_headroom(skb, max_headroom);
847 if (!new_skb) 847 if (!new_skb)
848 goto error; 848 goto error;
849 if (skb->sk)
850 skb_set_owner_w(new_skb, skb->sk);
849 consume_skb(skb); 851 consume_skb(skb);
850 skb = new_skb; 852 skb = new_skb;
851 } 853 }
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 11ab4b078f3b..66e8425dbfe7 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -3484,13 +3484,8 @@ static void nft_chain_commit_update(struct nft_trans *trans)
3484 } 3484 }
3485} 3485}
3486 3486
3487/* Schedule objects for release via rcu to make sure no packets are accesing 3487static void nf_tables_commit_release(struct nft_trans *trans)
3488 * removed rules.
3489 */
3490static void nf_tables_commit_release_rcu(struct rcu_head *rt)
3491{ 3488{
3492 struct nft_trans *trans = container_of(rt, struct nft_trans, rcu_head);
3493
3494 switch (trans->msg_type) { 3489 switch (trans->msg_type) {
3495 case NFT_MSG_DELTABLE: 3490 case NFT_MSG_DELTABLE:
3496 nf_tables_table_destroy(&trans->ctx); 3491 nf_tables_table_destroy(&trans->ctx);
@@ -3612,10 +3607,11 @@ static int nf_tables_commit(struct sk_buff *skb)
3612 } 3607 }
3613 } 3608 }
3614 3609
3610 synchronize_rcu();
3611
3615 list_for_each_entry_safe(trans, next, &net->nft.commit_list, list) { 3612 list_for_each_entry_safe(trans, next, &net->nft.commit_list, list) {
3616 list_del(&trans->list); 3613 list_del(&trans->list);
3617 trans->ctx.nla = NULL; 3614 nf_tables_commit_release(trans);
3618 call_rcu(&trans->rcu_head, nf_tables_commit_release_rcu);
3619 } 3615 }
3620 3616
3621 nf_tables_gen_notify(net, skb, NFT_MSG_NEWGEN); 3617 nf_tables_gen_notify(net, skb, NFT_MSG_NEWGEN);
@@ -3623,13 +3619,8 @@ static int nf_tables_commit(struct sk_buff *skb)
3623 return 0; 3619 return 0;
3624} 3620}
3625 3621
3626/* Schedule objects for release via rcu to make sure no packets are accesing 3622static void nf_tables_abort_release(struct nft_trans *trans)
3627 * aborted rules.
3628 */
3629static void nf_tables_abort_release_rcu(struct rcu_head *rt)
3630{ 3623{
3631 struct nft_trans *trans = container_of(rt, struct nft_trans, rcu_head);
3632
3633 switch (trans->msg_type) { 3624 switch (trans->msg_type) {
3634 case NFT_MSG_NEWTABLE: 3625 case NFT_MSG_NEWTABLE:
3635 nf_tables_table_destroy(&trans->ctx); 3626 nf_tables_table_destroy(&trans->ctx);
@@ -3725,11 +3716,12 @@ static int nf_tables_abort(struct sk_buff *skb)
3725 } 3716 }
3726 } 3717 }
3727 3718
3719 synchronize_rcu();
3720
3728 list_for_each_entry_safe_reverse(trans, next, 3721 list_for_each_entry_safe_reverse(trans, next,
3729 &net->nft.commit_list, list) { 3722 &net->nft.commit_list, list) {
3730 list_del(&trans->list); 3723 list_del(&trans->list);
3731 trans->ctx.nla = NULL; 3724 nf_tables_abort_release(trans);
3732 call_rcu(&trans->rcu_head, nf_tables_abort_release_rcu);
3733 } 3725 }
3734 3726
3735 return 0; 3727 return 0;
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index 6c5a915cfa75..13c2e17bbe27 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -47,6 +47,8 @@ static const int nfnl_group2type[NFNLGRP_MAX+1] = {
47 [NFNLGRP_CONNTRACK_EXP_NEW] = NFNL_SUBSYS_CTNETLINK_EXP, 47 [NFNLGRP_CONNTRACK_EXP_NEW] = NFNL_SUBSYS_CTNETLINK_EXP,
48 [NFNLGRP_CONNTRACK_EXP_UPDATE] = NFNL_SUBSYS_CTNETLINK_EXP, 48 [NFNLGRP_CONNTRACK_EXP_UPDATE] = NFNL_SUBSYS_CTNETLINK_EXP,
49 [NFNLGRP_CONNTRACK_EXP_DESTROY] = NFNL_SUBSYS_CTNETLINK_EXP, 49 [NFNLGRP_CONNTRACK_EXP_DESTROY] = NFNL_SUBSYS_CTNETLINK_EXP,
50 [NFNLGRP_NFTABLES] = NFNL_SUBSYS_NFTABLES,
51 [NFNLGRP_ACCT_QUOTA] = NFNL_SUBSYS_ACCT,
50}; 52};
51 53
52void nfnl_lock(__u8 subsys_id) 54void nfnl_lock(__u8 subsys_id)
@@ -464,7 +466,12 @@ static void nfnetlink_rcv(struct sk_buff *skb)
464static int nfnetlink_bind(int group) 466static int nfnetlink_bind(int group)
465{ 467{
466 const struct nfnetlink_subsystem *ss; 468 const struct nfnetlink_subsystem *ss;
467 int type = nfnl_group2type[group]; 469 int type;
470
471 if (group <= NFNLGRP_NONE || group > NFNLGRP_MAX)
472 return -EINVAL;
473
474 type = nfnl_group2type[group];
468 475
469 rcu_read_lock(); 476 rcu_read_lock();
470 ss = nfnetlink_get_subsys(type); 477 ss = nfnetlink_get_subsys(type);
@@ -514,6 +521,9 @@ static int __init nfnetlink_init(void)
514{ 521{
515 int i; 522 int i;
516 523
524 for (i = NFNLGRP_NONE + 1; i <= NFNLGRP_MAX; i++)
525 BUG_ON(nfnl_group2type[i] == NFNL_SUBSYS_NONE);
526
517 for (i=0; i<NFNL_SUBSYS_COUNT; i++) 527 for (i=0; i<NFNL_SUBSYS_COUNT; i++)
518 mutex_init(&table[i].mutex); 528 mutex_init(&table[i].mutex);
519 529
diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
index 9d6d6f60a80f..265e190f2218 100644
--- a/net/netfilter/nft_compat.c
+++ b/net/netfilter/nft_compat.c
@@ -21,45 +21,17 @@
21#include <linux/netfilter_ipv6/ip6_tables.h> 21#include <linux/netfilter_ipv6/ip6_tables.h>
22#include <net/netfilter/nf_tables.h> 22#include <net/netfilter/nf_tables.h>
23 23
24static const struct {
25 const char *name;
26 u8 type;
27} table_to_chaintype[] = {
28 { "filter", NFT_CHAIN_T_DEFAULT },
29 { "raw", NFT_CHAIN_T_DEFAULT },
30 { "security", NFT_CHAIN_T_DEFAULT },
31 { "mangle", NFT_CHAIN_T_ROUTE },
32 { "nat", NFT_CHAIN_T_NAT },
33 { },
34};
35
36static int nft_compat_table_to_chaintype(const char *table)
37{
38 int i;
39
40 for (i = 0; table_to_chaintype[i].name != NULL; i++) {
41 if (strcmp(table_to_chaintype[i].name, table) == 0)
42 return table_to_chaintype[i].type;
43 }
44
45 return -1;
46}
47
48static int nft_compat_chain_validate_dependency(const char *tablename, 24static int nft_compat_chain_validate_dependency(const char *tablename,
49 const struct nft_chain *chain) 25 const struct nft_chain *chain)
50{ 26{
51 enum nft_chain_type type;
52 const struct nft_base_chain *basechain; 27 const struct nft_base_chain *basechain;
53 28
54 if (!tablename || !(chain->flags & NFT_BASE_CHAIN)) 29 if (!tablename || !(chain->flags & NFT_BASE_CHAIN))
55 return 0; 30 return 0;
56 31
57 type = nft_compat_table_to_chaintype(tablename);
58 if (type < 0)
59 return -EINVAL;
60
61 basechain = nft_base_chain(chain); 32 basechain = nft_base_chain(chain);
62 if (basechain->type->type != type) 33 if (strcmp(tablename, "nat") == 0 &&
34 basechain->type->type != NFT_CHAIN_T_NAT)
63 return -EINVAL; 35 return -EINVAL;
64 36
65 return 0; 37 return 0;
@@ -117,7 +89,7 @@ nft_target_set_tgchk_param(struct xt_tgchk_param *par,
117 struct xt_target *target, void *info, 89 struct xt_target *target, void *info,
118 union nft_entry *entry, u8 proto, bool inv) 90 union nft_entry *entry, u8 proto, bool inv)
119{ 91{
120 par->net = &init_net; 92 par->net = ctx->net;
121 par->table = ctx->table->name; 93 par->table = ctx->table->name;
122 switch (ctx->afi->family) { 94 switch (ctx->afi->family) {
123 case AF_INET: 95 case AF_INET:
@@ -324,7 +296,7 @@ nft_match_set_mtchk_param(struct xt_mtchk_param *par, const struct nft_ctx *ctx,
324 struct xt_match *match, void *info, 296 struct xt_match *match, void *info,
325 union nft_entry *entry, u8 proto, bool inv) 297 union nft_entry *entry, u8 proto, bool inv)
326{ 298{
327 par->net = &init_net; 299 par->net = ctx->net;
328 par->table = ctx->table->name; 300 par->table = ctx->table->name;
329 switch (ctx->afi->family) { 301 switch (ctx->afi->family) {
330 case AF_INET: 302 case AF_INET:
@@ -374,7 +346,7 @@ nft_match_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
374 union nft_entry e = {}; 346 union nft_entry e = {};
375 int ret; 347 int ret;
376 348
377 ret = nft_compat_chain_validate_dependency(match->name, ctx->chain); 349 ret = nft_compat_chain_validate_dependency(match->table, ctx->chain);
378 if (ret < 0) 350 if (ret < 0)
379 goto err; 351 goto err;
380 352
@@ -448,7 +420,7 @@ static int nft_match_validate(const struct nft_ctx *ctx,
448 if (!(hook_mask & match->hooks)) 420 if (!(hook_mask & match->hooks))
449 return -EINVAL; 421 return -EINVAL;
450 422
451 ret = nft_compat_chain_validate_dependency(match->name, 423 ret = nft_compat_chain_validate_dependency(match->table,
452 ctx->chain); 424 ctx->chain);
453 if (ret < 0) 425 if (ret < 0)
454 return ret; 426 return ret;
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
index f1de72de273e..0007b8180397 100644
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -1440,7 +1440,7 @@ static void netlink_unbind(int group, long unsigned int groups,
1440 return; 1440 return;
1441 1441
1442 for (undo = 0; undo < group; undo++) 1442 for (undo = 0; undo < group; undo++)
1443 if (test_bit(group, &groups)) 1443 if (test_bit(undo, &groups))
1444 nlk->netlink_unbind(undo); 1444 nlk->netlink_unbind(undo);
1445} 1445}
1446 1446
@@ -1492,7 +1492,7 @@ static int netlink_bind(struct socket *sock, struct sockaddr *addr,
1492 netlink_insert(sk, net, nladdr->nl_pid) : 1492 netlink_insert(sk, net, nladdr->nl_pid) :
1493 netlink_autobind(sock); 1493 netlink_autobind(sock);
1494 if (err) { 1494 if (err) {
1495 netlink_unbind(nlk->ngroups - 1, groups, nlk); 1495 netlink_unbind(nlk->ngroups, groups, nlk);
1496 return err; 1496 return err;
1497 } 1497 }
1498 } 1498 }
@@ -2509,6 +2509,7 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module,
2509 nl_table[unit].module = module; 2509 nl_table[unit].module = module;
2510 if (cfg) { 2510 if (cfg) {
2511 nl_table[unit].bind = cfg->bind; 2511 nl_table[unit].bind = cfg->bind;
2512 nl_table[unit].unbind = cfg->unbind;
2512 nl_table[unit].flags = cfg->flags; 2513 nl_table[unit].flags = cfg->flags;
2513 if (cfg->compare) 2514 if (cfg->compare)
2514 nl_table[unit].compare = cfg->compare; 2515 nl_table[unit].compare = cfg->compare;
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 006886dbee36..8c4229b11c34 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -246,11 +246,11 @@ static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
246{ 246{
247 int transport_len = skb->len - skb_transport_offset(skb); 247 int transport_len = skb->len - skb_transport_offset(skb);
248 248
249 if (l4_proto == IPPROTO_TCP) { 249 if (l4_proto == NEXTHDR_TCP) {
250 if (likely(transport_len >= sizeof(struct tcphdr))) 250 if (likely(transport_len >= sizeof(struct tcphdr)))
251 inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb, 251 inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb,
252 addr, new_addr, 1); 252 addr, new_addr, 1);
253 } else if (l4_proto == IPPROTO_UDP) { 253 } else if (l4_proto == NEXTHDR_UDP) {
254 if (likely(transport_len >= sizeof(struct udphdr))) { 254 if (likely(transport_len >= sizeof(struct udphdr))) {
255 struct udphdr *uh = udp_hdr(skb); 255 struct udphdr *uh = udp_hdr(skb);
256 256
@@ -261,6 +261,10 @@ static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
261 uh->check = CSUM_MANGLED_0; 261 uh->check = CSUM_MANGLED_0;
262 } 262 }
263 } 263 }
264 } else if (l4_proto == NEXTHDR_ICMP) {
265 if (likely(transport_len >= sizeof(struct icmp6hdr)))
266 inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum,
267 skb, addr, new_addr, 1);
264 } 268 }
265} 269}
266 270
@@ -722,8 +726,6 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
722 726
723 case OVS_ACTION_ATTR_SAMPLE: 727 case OVS_ACTION_ATTR_SAMPLE:
724 err = sample(dp, skb, key, a); 728 err = sample(dp, skb, key, a);
725 if (unlikely(err)) /* skb already freed. */
726 return err;
727 break; 729 break;
728 } 730 }
729 731
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index e6d7255183eb..f9e556b56086 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -1265,7 +1265,7 @@ static size_t ovs_dp_cmd_msg_size(void)
1265 return msgsize; 1265 return msgsize;
1266} 1266}
1267 1267
1268/* Called with ovs_mutex or RCU read lock. */ 1268/* Called with ovs_mutex. */
1269static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb, 1269static int ovs_dp_cmd_fill_info(struct datapath *dp, struct sk_buff *skb,
1270 u32 portid, u32 seq, u32 flags, u8 cmd) 1270 u32 portid, u32 seq, u32 flags, u8 cmd)
1271{ 1271{
@@ -1555,7 +1555,7 @@ static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info)
1555 if (!reply) 1555 if (!reply)
1556 return -ENOMEM; 1556 return -ENOMEM;
1557 1557
1558 rcu_read_lock(); 1558 ovs_lock();
1559 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs); 1559 dp = lookup_datapath(sock_net(skb->sk), info->userhdr, info->attrs);
1560 if (IS_ERR(dp)) { 1560 if (IS_ERR(dp)) {
1561 err = PTR_ERR(dp); 1561 err = PTR_ERR(dp);
@@ -1564,12 +1564,12 @@ static int ovs_dp_cmd_get(struct sk_buff *skb, struct genl_info *info)
1564 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid, 1564 err = ovs_dp_cmd_fill_info(dp, reply, info->snd_portid,
1565 info->snd_seq, 0, OVS_DP_CMD_NEW); 1565 info->snd_seq, 0, OVS_DP_CMD_NEW);
1566 BUG_ON(err < 0); 1566 BUG_ON(err < 0);
1567 rcu_read_unlock(); 1567 ovs_unlock();
1568 1568
1569 return genlmsg_reply(reply, info); 1569 return genlmsg_reply(reply, info);
1570 1570
1571err_unlock_free: 1571err_unlock_free:
1572 rcu_read_unlock(); 1572 ovs_unlock();
1573 kfree_skb(reply); 1573 kfree_skb(reply);
1574 return err; 1574 return err;
1575} 1575}
@@ -1581,8 +1581,8 @@ static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
1581 int skip = cb->args[0]; 1581 int skip = cb->args[0];
1582 int i = 0; 1582 int i = 0;
1583 1583
1584 rcu_read_lock(); 1584 ovs_lock();
1585 list_for_each_entry_rcu(dp, &ovs_net->dps, list_node) { 1585 list_for_each_entry(dp, &ovs_net->dps, list_node) {
1586 if (i >= skip && 1586 if (i >= skip &&
1587 ovs_dp_cmd_fill_info(dp, skb, NETLINK_CB(cb->skb).portid, 1587 ovs_dp_cmd_fill_info(dp, skb, NETLINK_CB(cb->skb).portid,
1588 cb->nlh->nlmsg_seq, NLM_F_MULTI, 1588 cb->nlh->nlmsg_seq, NLM_F_MULTI,
@@ -1590,7 +1590,7 @@ static int ovs_dp_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
1590 break; 1590 break;
1591 i++; 1591 i++;
1592 } 1592 }
1593 rcu_read_unlock(); 1593 ovs_unlock();
1594 1594
1595 cb->args[0] = i; 1595 cb->args[0] = i;
1596 1596
diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c
index 939bcb32100f..089b195c064a 100644
--- a/net/openvswitch/flow_netlink.c
+++ b/net/openvswitch/flow_netlink.c
@@ -145,7 +145,7 @@ static bool match_validate(const struct sw_flow_match *match,
145 if (match->key->eth.type == htons(ETH_P_ARP) 145 if (match->key->eth.type == htons(ETH_P_ARP)
146 || match->key->eth.type == htons(ETH_P_RARP)) { 146 || match->key->eth.type == htons(ETH_P_RARP)) {
147 key_expected |= 1 << OVS_KEY_ATTR_ARP; 147 key_expected |= 1 << OVS_KEY_ATTR_ARP;
148 if (match->mask && (match->mask->key.eth.type == htons(0xffff))) 148 if (match->mask && (match->mask->key.tp.src == htons(0xff)))
149 mask_allowed |= 1 << OVS_KEY_ATTR_ARP; 149 mask_allowed |= 1 << OVS_KEY_ATTR_ARP;
150 } 150 }
151 151
@@ -689,6 +689,13 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
689 ipv6_key->ipv6_frag, OVS_FRAG_TYPE_MAX); 689 ipv6_key->ipv6_frag, OVS_FRAG_TYPE_MAX);
690 return -EINVAL; 690 return -EINVAL;
691 } 691 }
692
693 if (!is_mask && ipv6_key->ipv6_label & htonl(0xFFF00000)) {
694 OVS_NLERR("IPv6 flow label %x is out of range (max=%x).\n",
695 ntohl(ipv6_key->ipv6_label), (1 << 20) - 1);
696 return -EINVAL;
697 }
698
692 SW_FLOW_KEY_PUT(match, ipv6.label, 699 SW_FLOW_KEY_PUT(match, ipv6.label,
693 ipv6_key->ipv6_label, is_mask); 700 ipv6_key->ipv6_label, is_mask);
694 SW_FLOW_KEY_PUT(match, ip.proto, 701 SW_FLOW_KEY_PUT(match, ip.proto,
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 87d20f48ff06..07c04a841ba0 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -378,7 +378,7 @@ static void unregister_prot_hook(struct sock *sk, bool sync)
378 __unregister_prot_hook(sk, sync); 378 __unregister_prot_hook(sk, sync);
379} 379}
380 380
381static inline __pure struct page *pgv_to_page(void *addr) 381static inline struct page * __pure pgv_to_page(void *addr)
382{ 382{
383 if (is_vmalloc_addr(addr)) 383 if (is_vmalloc_addr(addr))
384 return vmalloc_to_page(addr); 384 return vmalloc_to_page(addr);
diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index 0e8529113dc5..fb7976aee61c 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -862,8 +862,6 @@ int sctp_auth_set_key(struct sctp_endpoint *ep,
862 list_add(&cur_key->key_list, sh_keys); 862 list_add(&cur_key->key_list, sh_keys);
863 863
864 cur_key->key = key; 864 cur_key->key = key;
865 sctp_auth_key_hold(key);
866
867 return 0; 865 return 0;
868nomem: 866nomem:
869 if (!replace) 867 if (!replace)
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index ab734be8cb20..9f32741abb1c 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -2609,6 +2609,9 @@ do_addr_param:
2609 addr_param = param.v + sizeof(sctp_addip_param_t); 2609 addr_param = param.v + sizeof(sctp_addip_param_t);
2610 2610
2611 af = sctp_get_af_specific(param_type2af(param.p->type)); 2611 af = sctp_get_af_specific(param_type2af(param.p->type));
2612 if (af == NULL)
2613 break;
2614
2612 af->from_addr_param(&addr, addr_param, 2615 af->from_addr_param(&addr, addr_param,
2613 htons(asoc->peer.port), 0); 2616 htons(asoc->peer.port), 0);
2614 2617
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index afb292cd797d..53ed8d3f8897 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -1353,6 +1353,7 @@ gss_stringify_acceptor(struct rpc_cred *cred)
1353 char *string = NULL; 1353 char *string = NULL;
1354 struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base); 1354 struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base);
1355 struct gss_cl_ctx *ctx; 1355 struct gss_cl_ctx *ctx;
1356 unsigned int len;
1356 struct xdr_netobj *acceptor; 1357 struct xdr_netobj *acceptor;
1357 1358
1358 rcu_read_lock(); 1359 rcu_read_lock();
@@ -1360,15 +1361,39 @@ gss_stringify_acceptor(struct rpc_cred *cred)
1360 if (!ctx) 1361 if (!ctx)
1361 goto out; 1362 goto out;
1362 1363
1363 acceptor = &ctx->gc_acceptor; 1364 len = ctx->gc_acceptor.len;
1365 rcu_read_unlock();
1364 1366
1365 /* no point if there's no string */ 1367 /* no point if there's no string */
1366 if (!acceptor->len) 1368 if (!len)
1367 goto out; 1369 return NULL;
1368 1370realloc:
1369 string = kmalloc(acceptor->len + 1, GFP_KERNEL); 1371 string = kmalloc(len + 1, GFP_KERNEL);
1370 if (!string) 1372 if (!string)
1373 return NULL;
1374
1375 rcu_read_lock();
1376 ctx = rcu_dereference(gss_cred->gc_ctx);
1377
1378 /* did the ctx disappear or was it replaced by one with no acceptor? */
1379 if (!ctx || !ctx->gc_acceptor.len) {
1380 kfree(string);
1381 string = NULL;
1371 goto out; 1382 goto out;
1383 }
1384
1385 acceptor = &ctx->gc_acceptor;
1386
1387 /*
1388 * Did we find a new acceptor that's longer than the original? Allocate
1389 * a longer buffer and try again.
1390 */
1391 if (len < acceptor->len) {
1392 len = acceptor->len;
1393 rcu_read_unlock();
1394 kfree(string);
1395 goto realloc;
1396 }
1372 1397
1373 memcpy(string, acceptor->data, acceptor->len); 1398 memcpy(string, acceptor->data, acceptor->len);
1374 string[acceptor->len] = '\0'; 1399 string[acceptor->len] = '\0';
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 3f959c681885..f9c052d508f0 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -1019,17 +1019,12 @@ static int receive_cb_reply(struct svc_sock *svsk, struct svc_rqst *rqstp)
1019 xid = *p++; 1019 xid = *p++;
1020 calldir = *p; 1020 calldir = *p;
1021 1021
1022 if (bc_xprt) 1022 if (!bc_xprt)
1023 req = xprt_lookup_rqst(bc_xprt, xid);
1024
1025 if (!req) {
1026 printk(KERN_NOTICE
1027 "%s: Got unrecognized reply: "
1028 "calldir 0x%x xpt_bc_xprt %p xid %08x\n",
1029 __func__, ntohl(calldir),
1030 bc_xprt, ntohl(xid));
1031 return -EAGAIN; 1023 return -EAGAIN;
1032 } 1024 spin_lock_bh(&bc_xprt->transport_lock);
1025 req = xprt_lookup_rqst(bc_xprt, xid);
1026 if (!req)
1027 goto unlock_notfound;
1033 1028
1034 memcpy(&req->rq_private_buf, &req->rq_rcv_buf, sizeof(struct xdr_buf)); 1029 memcpy(&req->rq_private_buf, &req->rq_rcv_buf, sizeof(struct xdr_buf));
1035 /* 1030 /*
@@ -1040,11 +1035,21 @@ static int receive_cb_reply(struct svc_sock *svsk, struct svc_rqst *rqstp)
1040 dst = &req->rq_private_buf.head[0]; 1035 dst = &req->rq_private_buf.head[0];
1041 src = &rqstp->rq_arg.head[0]; 1036 src = &rqstp->rq_arg.head[0];
1042 if (dst->iov_len < src->iov_len) 1037 if (dst->iov_len < src->iov_len)
1043 return -EAGAIN; /* whatever; just giving up. */ 1038 goto unlock_eagain; /* whatever; just giving up. */
1044 memcpy(dst->iov_base, src->iov_base, src->iov_len); 1039 memcpy(dst->iov_base, src->iov_base, src->iov_len);
1045 xprt_complete_rqst(req->rq_task, rqstp->rq_arg.len); 1040 xprt_complete_rqst(req->rq_task, rqstp->rq_arg.len);
1046 rqstp->rq_arg.len = 0; 1041 rqstp->rq_arg.len = 0;
1042 spin_unlock_bh(&bc_xprt->transport_lock);
1047 return 0; 1043 return 0;
1044unlock_notfound:
1045 printk(KERN_NOTICE
1046 "%s: Got unrecognized reply: "
1047 "calldir 0x%x xpt_bc_xprt %p xid %08x\n",
1048 __func__, ntohl(calldir),
1049 bc_xprt, ntohl(xid));
1050unlock_eagain:
1051 spin_unlock_bh(&bc_xprt->transport_lock);
1052 return -EAGAIN;
1048} 1053}
1049 1054
1050static int copy_pages_to_kvecs(struct kvec *vec, struct page **pages, int len) 1055static int copy_pages_to_kvecs(struct kvec *vec, struct page **pages, int len)
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index 65e7b08bb2cc..5374b1bdf02f 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -179,6 +179,12 @@ build := -f $(srctree)/scripts/Makefile.build obj
179# $(Q)$(MAKE) $(modbuiltin)=dir 179# $(Q)$(MAKE) $(modbuiltin)=dir
180modbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj 180modbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj
181 181
182###
183# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
184# Usage:
185# $(Q)$(MAKE) $(dtbinst)=dir
186dtbinst := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.dtbinst obj
187
182# Prefix -I with $(srctree) if it is not an absolute path. 188# Prefix -I with $(srctree) if it is not an absolute path.
183# skip if -I has no parameter 189# skip if -I has no parameter
184addtree = $(if $(patsubst -I%,%,$(1)), \ 190addtree = $(if $(patsubst -I%,%,$(1)), \
diff --git a/scripts/Makefile.dtbinst b/scripts/Makefile.dtbinst
new file mode 100644
index 000000000000..909ed7a2ac61
--- /dev/null
+++ b/scripts/Makefile.dtbinst
@@ -0,0 +1,51 @@
1# ==========================================================================
2# Installing dtb files
3#
4# Installs all dtb files listed in $(dtb-y) either in the
5# INSTALL_DTBS_PATH directory or the default location:
6#
7# $INSTALL_PATH/dtbs/$KERNELRELEASE
8#
9# Traverse through subdirectories listed in $(dts-dirs).
10# ==========================================================================
11
12src := $(obj)
13
14PHONY := __dtbs_install
15__dtbs_install:
16
17export dtbinst-root ?= $(obj)
18
19include include/config/auto.conf
20include scripts/Kbuild.include
21include $(srctree)/$(obj)/Makefile
22
23PHONY += __dtbs_install_prep
24__dtbs_install_prep:
25ifeq ("$(dtbinst-root)", "$(obj)")
26 $(Q)if [ -d $(INSTALL_DTBS_PATH).old ]; then rm -rf $(INSTALL_DTBS_PATH).old; fi
27 $(Q)if [ -d $(INSTALL_DTBS_PATH) ]; then mv $(INSTALL_DTBS_PATH) $(INSTALL_DTBS_PATH).old; fi
28 $(Q)mkdir -p $(INSTALL_DTBS_PATH)
29endif
30
31dtbinst-files := $(dtb-y)
32dtbinst-dirs := $(dts-dirs)
33
34# Helper targets for Installing DTBs into the boot directory
35quiet_cmd_dtb_install = INSTALL $<
36 cmd_dtb_install = mkdir -p $(2); cp $< $(2)
37
38install-dir = $(patsubst $(dtbinst-root)%,$(INSTALL_DTBS_PATH)%,$(obj))
39
40$(dtbinst-files) $(dtbinst-dirs): | __dtbs_install_prep
41
42$(dtbinst-files): %.dtb: $(obj)/%.dtb
43 $(call cmd,dtb_install,$(install-dir))
44
45$(dtbinst-dirs):
46 $(Q)$(MAKE) $(dtbinst)=$(obj)/$@
47
48PHONY += $(dtbinst-files) $(dtbinst-dirs)
49__dtbs_install: $(dtbinst-files) $(dtbinst-dirs)
50
51.PHONY: $(PHONY)
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 54be19a0fa51..511755200634 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -283,18 +283,6 @@ $(obj)/%.dtb: $(src)/%.dts FORCE
283 283
284dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp) 284dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
285 285
286# Helper targets for Installing DTBs into the boot directory
287quiet_cmd_dtb_install = INSTALL $<
288 cmd_dtb_install = cp $< $(2)
289
290_dtbinst_pre_:
291 $(Q)if [ -d $(INSTALL_DTBS_PATH).old ]; then rm -rf $(INSTALL_DTBS_PATH).old; fi
292 $(Q)if [ -d $(INSTALL_DTBS_PATH) ]; then mv $(INSTALL_DTBS_PATH) $(INSTALL_DTBS_PATH).old; fi
293 $(Q)mkdir -p $(INSTALL_DTBS_PATH)
294
295%.dtb_dtbinst_: $(obj)/%.dtb _dtbinst_pre_
296 $(call cmd,dtb_install,$(INSTALL_DTBS_PATH))
297
298# Bzip2 286# Bzip2
299# --------------------------------------------------------------------------- 287# ---------------------------------------------------------------------------
300 288
diff --git a/security/keys/internal.h b/security/keys/internal.h
index b8960c4959a5..200e37867336 100644
--- a/security/keys/internal.h
+++ b/security/keys/internal.h
@@ -117,6 +117,7 @@ struct keyring_search_context {
117#define KEYRING_SEARCH_NO_UPDATE_TIME 0x0004 /* Don't update times */ 117#define KEYRING_SEARCH_NO_UPDATE_TIME 0x0004 /* Don't update times */
118#define KEYRING_SEARCH_NO_CHECK_PERM 0x0008 /* Don't check permissions */ 118#define KEYRING_SEARCH_NO_CHECK_PERM 0x0008 /* Don't check permissions */
119#define KEYRING_SEARCH_DETECT_TOO_DEEP 0x0010 /* Give an error on excessive depth */ 119#define KEYRING_SEARCH_DETECT_TOO_DEEP 0x0010 /* Give an error on excessive depth */
120#define KEYRING_SEARCH_SKIP_EXPIRED 0x0020 /* Ignore expired keys (intention to replace) */
120 121
121 int (*iterator)(const void *object, void *iterator_data); 122 int (*iterator)(const void *object, void *iterator_data);
122 123
diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
index eff88a5f5d40..4743d71e4aa6 100644
--- a/security/keys/keyctl.c
+++ b/security/keys/keyctl.c
@@ -26,6 +26,8 @@
26#include <asm/uaccess.h> 26#include <asm/uaccess.h>
27#include "internal.h" 27#include "internal.h"
28 28
29#define KEY_MAX_DESC_SIZE 4096
30
29static int key_get_type_from_user(char *type, 31static int key_get_type_from_user(char *type,
30 const char __user *_type, 32 const char __user *_type,
31 unsigned len) 33 unsigned len)
@@ -78,7 +80,7 @@ SYSCALL_DEFINE5(add_key, const char __user *, _type,
78 80
79 description = NULL; 81 description = NULL;
80 if (_description) { 82 if (_description) {
81 description = strndup_user(_description, PAGE_SIZE); 83 description = strndup_user(_description, KEY_MAX_DESC_SIZE);
82 if (IS_ERR(description)) { 84 if (IS_ERR(description)) {
83 ret = PTR_ERR(description); 85 ret = PTR_ERR(description);
84 goto error; 86 goto error;
@@ -177,7 +179,7 @@ SYSCALL_DEFINE4(request_key, const char __user *, _type,
177 goto error; 179 goto error;
178 180
179 /* pull the description into kernel space */ 181 /* pull the description into kernel space */
180 description = strndup_user(_description, PAGE_SIZE); 182 description = strndup_user(_description, KEY_MAX_DESC_SIZE);
181 if (IS_ERR(description)) { 183 if (IS_ERR(description)) {
182 ret = PTR_ERR(description); 184 ret = PTR_ERR(description);
183 goto error; 185 goto error;
@@ -287,7 +289,7 @@ long keyctl_join_session_keyring(const char __user *_name)
287 /* fetch the name from userspace */ 289 /* fetch the name from userspace */
288 name = NULL; 290 name = NULL;
289 if (_name) { 291 if (_name) {
290 name = strndup_user(_name, PAGE_SIZE); 292 name = strndup_user(_name, KEY_MAX_DESC_SIZE);
291 if (IS_ERR(name)) { 293 if (IS_ERR(name)) {
292 ret = PTR_ERR(name); 294 ret = PTR_ERR(name);
293 goto error; 295 goto error;
@@ -562,8 +564,9 @@ long keyctl_describe_key(key_serial_t keyid,
562{ 564{
563 struct key *key, *instkey; 565 struct key *key, *instkey;
564 key_ref_t key_ref; 566 key_ref_t key_ref;
565 char *tmpbuf; 567 char *infobuf;
566 long ret; 568 long ret;
569 int desclen, infolen;
567 570
568 key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_NEED_VIEW); 571 key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_NEED_VIEW);
569 if (IS_ERR(key_ref)) { 572 if (IS_ERR(key_ref)) {
@@ -586,38 +589,31 @@ long keyctl_describe_key(key_serial_t keyid,
586 } 589 }
587 590
588okay: 591okay:
589 /* calculate how much description we're going to return */
590 ret = -ENOMEM;
591 tmpbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
592 if (!tmpbuf)
593 goto error2;
594
595 key = key_ref_to_ptr(key_ref); 592 key = key_ref_to_ptr(key_ref);
593 desclen = strlen(key->description);
596 594
597 ret = snprintf(tmpbuf, PAGE_SIZE - 1, 595 /* calculate how much information we're going to return */
598 "%s;%d;%d;%08x;%s", 596 ret = -ENOMEM;
599 key->type->name, 597 infobuf = kasprintf(GFP_KERNEL,
600 from_kuid_munged(current_user_ns(), key->uid), 598 "%s;%d;%d;%08x;",
601 from_kgid_munged(current_user_ns(), key->gid), 599 key->type->name,
602 key->perm, 600 from_kuid_munged(current_user_ns(), key->uid),
603 key->description ?: ""); 601 from_kgid_munged(current_user_ns(), key->gid),
604 602 key->perm);
605 /* include a NUL char at the end of the data */ 603 if (!infobuf)
606 if (ret > PAGE_SIZE - 1) 604 goto error2;
607 ret = PAGE_SIZE - 1; 605 infolen = strlen(infobuf);
608 tmpbuf[ret] = 0; 606 ret = infolen + desclen + 1;
609 ret++;
610 607
611 /* consider returning the data */ 608 /* consider returning the data */
612 if (buffer && buflen > 0) { 609 if (buffer && buflen >= ret) {
613 if (buflen > ret) 610 if (copy_to_user(buffer, infobuf, infolen) != 0 ||
614 buflen = ret; 611 copy_to_user(buffer + infolen, key->description,
615 612 desclen + 1) != 0)
616 if (copy_to_user(buffer, tmpbuf, buflen) != 0)
617 ret = -EFAULT; 613 ret = -EFAULT;
618 } 614 }
619 615
620 kfree(tmpbuf); 616 kfree(infobuf);
621error2: 617error2:
622 key_ref_put(key_ref); 618 key_ref_put(key_ref);
623error: 619error:
@@ -649,7 +645,7 @@ long keyctl_keyring_search(key_serial_t ringid,
649 if (ret < 0) 645 if (ret < 0)
650 goto error; 646 goto error;
651 647
652 description = strndup_user(_description, PAGE_SIZE); 648 description = strndup_user(_description, KEY_MAX_DESC_SIZE);
653 if (IS_ERR(description)) { 649 if (IS_ERR(description)) {
654 ret = PTR_ERR(description); 650 ret = PTR_ERR(description);
655 goto error; 651 goto error;
diff --git a/security/keys/keyring.c b/security/keys/keyring.c
index 8177010174f7..e72548b5897e 100644
--- a/security/keys/keyring.c
+++ b/security/keys/keyring.c
@@ -546,7 +546,8 @@ static int keyring_search_iterator(const void *object, void *iterator_data)
546 } 546 }
547 547
548 if (key->expiry && ctx->now.tv_sec >= key->expiry) { 548 if (key->expiry && ctx->now.tv_sec >= key->expiry) {
549 ctx->result = ERR_PTR(-EKEYEXPIRED); 549 if (!(ctx->flags & KEYRING_SEARCH_SKIP_EXPIRED))
550 ctx->result = ERR_PTR(-EKEYEXPIRED);
550 kleave(" = %d [expire]", ctx->skipped_ret); 551 kleave(" = %d [expire]", ctx->skipped_ret);
551 goto skipped; 552 goto skipped;
552 } 553 }
@@ -628,6 +629,10 @@ static bool search_nested_keyrings(struct key *keyring,
628 ctx->index_key.type->name, 629 ctx->index_key.type->name,
629 ctx->index_key.description); 630 ctx->index_key.description);
630 631
632#define STATE_CHECKS (KEYRING_SEARCH_NO_STATE_CHECK | KEYRING_SEARCH_DO_STATE_CHECK)
633 BUG_ON((ctx->flags & STATE_CHECKS) == 0 ||
634 (ctx->flags & STATE_CHECKS) == STATE_CHECKS);
635
631 if (ctx->index_key.description) 636 if (ctx->index_key.description)
632 ctx->index_key.desc_len = strlen(ctx->index_key.description); 637 ctx->index_key.desc_len = strlen(ctx->index_key.description);
633 638
@@ -637,7 +642,6 @@ static bool search_nested_keyrings(struct key *keyring,
637 if (ctx->match_data.lookup_type == KEYRING_SEARCH_LOOKUP_ITERATE || 642 if (ctx->match_data.lookup_type == KEYRING_SEARCH_LOOKUP_ITERATE ||
638 keyring_compare_object(keyring, &ctx->index_key)) { 643 keyring_compare_object(keyring, &ctx->index_key)) {
639 ctx->skipped_ret = 2; 644 ctx->skipped_ret = 2;
640 ctx->flags |= KEYRING_SEARCH_DO_STATE_CHECK;
641 switch (ctx->iterator(keyring_key_to_ptr(keyring), ctx)) { 645 switch (ctx->iterator(keyring_key_to_ptr(keyring), ctx)) {
642 case 1: 646 case 1:
643 goto found; 647 goto found;
@@ -649,8 +653,6 @@ static bool search_nested_keyrings(struct key *keyring,
649 } 653 }
650 654
651 ctx->skipped_ret = 0; 655 ctx->skipped_ret = 0;
652 if (ctx->flags & KEYRING_SEARCH_NO_STATE_CHECK)
653 ctx->flags &= ~KEYRING_SEARCH_DO_STATE_CHECK;
654 656
655 /* Start processing a new keyring */ 657 /* Start processing a new keyring */
656descend_to_keyring: 658descend_to_keyring:
diff --git a/security/keys/request_key.c b/security/keys/request_key.c
index bb4337c7ae1b..0c7aea4dea54 100644
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -516,6 +516,8 @@ struct key *request_key_and_link(struct key_type *type,
516 .match_data.cmp = key_default_cmp, 516 .match_data.cmp = key_default_cmp,
517 .match_data.raw_data = description, 517 .match_data.raw_data = description,
518 .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, 518 .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT,
519 .flags = (KEYRING_SEARCH_DO_STATE_CHECK |
520 KEYRING_SEARCH_SKIP_EXPIRED),
519 }; 521 };
520 struct key *key; 522 struct key *key;
521 key_ref_t key_ref; 523 key_ref_t key_ref;
diff --git a/security/keys/request_key_auth.c b/security/keys/request_key_auth.c
index 6639e2cb8853..5d672f7580dd 100644
--- a/security/keys/request_key_auth.c
+++ b/security/keys/request_key_auth.c
@@ -249,6 +249,7 @@ struct key *key_get_instantiation_authkey(key_serial_t target_id)
249 .match_data.cmp = key_default_cmp, 249 .match_data.cmp = key_default_cmp,
250 .match_data.raw_data = description, 250 .match_data.raw_data = description,
251 .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT, 251 .match_data.lookup_type = KEYRING_SEARCH_LOOKUP_DIRECT,
252 .flags = KEYRING_SEARCH_DO_STATE_CHECK,
252 }; 253 };
253 struct key *authkey; 254 struct key *authkey;
254 key_ref_t authkey_ref; 255 key_ref_t authkey_ref;
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index e66314138b38..c603b20356ad 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -4725,9 +4725,10 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
4725 err = selinux_nlmsg_lookup(sksec->sclass, nlh->nlmsg_type, &perm); 4725 err = selinux_nlmsg_lookup(sksec->sclass, nlh->nlmsg_type, &perm);
4726 if (err) { 4726 if (err) {
4727 if (err == -EINVAL) { 4727 if (err == -EINVAL) {
4728 WARN_ONCE(1, "selinux_nlmsg_perm: unrecognized netlink message:" 4728 printk(KERN_WARNING
4729 " protocol=%hu nlmsg_type=%hu sclass=%hu\n", 4729 "SELinux: unrecognized netlink message:"
4730 sk->sk_protocol, nlh->nlmsg_type, sksec->sclass); 4730 " protocol=%hu nlmsg_type=%hu sclass=%hu\n",
4731 sk->sk_protocol, nlh->nlmsg_type, sksec->sclass);
4731 if (!selinux_enforcing || security_get_allow_unknown()) 4732 if (!selinux_enforcing || security_get_allow_unknown())
4732 err = 0; 4733 err = 0;
4733 } 4734 }
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 42ded997b223..c6ff94ab1ad6 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -216,6 +216,8 @@ static char *snd_pcm_format_names[] = {
216 FORMAT(DSD_U8), 216 FORMAT(DSD_U8),
217 FORMAT(DSD_U16_LE), 217 FORMAT(DSD_U16_LE),
218 FORMAT(DSD_U32_LE), 218 FORMAT(DSD_U32_LE),
219 FORMAT(DSD_U16_BE),
220 FORMAT(DSD_U32_BE),
219}; 221};
220 222
221const char *snd_pcm_format_name(snd_pcm_format_t format) 223const char *snd_pcm_format_name(snd_pcm_format_t format)
diff --git a/sound/core/pcm_misc.c b/sound/core/pcm_misc.c
index ae7a0feb3b76..ebe8444de6c6 100644
--- a/sound/core/pcm_misc.c
+++ b/sound/core/pcm_misc.c
@@ -152,6 +152,14 @@ static struct pcm_format_data pcm_formats[(INT)SNDRV_PCM_FORMAT_LAST+1] = {
152 .width = 32, .phys = 32, .le = 1, .signd = 0, 152 .width = 32, .phys = 32, .le = 1, .signd = 0,
153 .silence = { 0x69, 0x69, 0x69, 0x69 }, 153 .silence = { 0x69, 0x69, 0x69, 0x69 },
154 }, 154 },
155 [SNDRV_PCM_FORMAT_DSD_U16_BE] = {
156 .width = 16, .phys = 16, .le = 0, .signd = 0,
157 .silence = { 0x69, 0x69 },
158 },
159 [SNDRV_PCM_FORMAT_DSD_U32_BE] = {
160 .width = 32, .phys = 32, .le = 0, .signd = 0,
161 .silence = { 0x69, 0x69, 0x69, 0x69 },
162 },
155 /* FIXME: the following three formats are not defined properly yet */ 163 /* FIXME: the following three formats are not defined properly yet */
156 [SNDRV_PCM_FORMAT_MPEG] = { 164 [SNDRV_PCM_FORMAT_MPEG] = {
157 .le = -1, .signd = -1, 165 .le = -1, .signd = -1,
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 9ab1e631cb32..48b6c5a3884f 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -219,6 +219,7 @@ MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
219 "{Intel, LPT_LP}," 219 "{Intel, LPT_LP},"
220 "{Intel, WPT_LP}," 220 "{Intel, WPT_LP},"
221 "{Intel, SPT}," 221 "{Intel, SPT},"
222 "{Intel, SPT_LP},"
222 "{Intel, HPT}," 223 "{Intel, HPT},"
223 "{Intel, PBG}," 224 "{Intel, PBG},"
224 "{Intel, SCH}," 225 "{Intel, SCH},"
@@ -297,7 +298,8 @@ enum {
297 298
298/* quirks for ATI/AMD HDMI */ 299/* quirks for ATI/AMD HDMI */
299#define AZX_DCAPS_PRESET_ATI_HDMI \ 300#define AZX_DCAPS_PRESET_ATI_HDMI \
300 (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB) 301 (AZX_DCAPS_NO_TCSEL | AZX_DCAPS_SYNC_WRITE | AZX_DCAPS_POSFIX_LPIB|\
302 AZX_DCAPS_NO_MSI64)
301 303
302/* quirks for Nvidia */ 304/* quirks for Nvidia */
303#define AZX_DCAPS_PRESET_NVIDIA \ 305#define AZX_DCAPS_PRESET_NVIDIA \
@@ -1485,6 +1487,7 @@ static int azx_first_init(struct azx *chip)
1485 struct snd_card *card = chip->card; 1487 struct snd_card *card = chip->card;
1486 int err; 1488 int err;
1487 unsigned short gcap; 1489 unsigned short gcap;
1490 unsigned int dma_bits = 64;
1488 1491
1489#if BITS_PER_LONG != 64 1492#if BITS_PER_LONG != 64
1490 /* Fix up base address on ULI M5461 */ 1493 /* Fix up base address on ULI M5461 */
@@ -1508,9 +1511,14 @@ static int azx_first_init(struct azx *chip)
1508 return -ENXIO; 1511 return -ENXIO;
1509 } 1512 }
1510 1513
1511 if (chip->msi) 1514 if (chip->msi) {
1515 if (chip->driver_caps & AZX_DCAPS_NO_MSI64) {
1516 dev_dbg(card->dev, "Disabling 64bit MSI\n");
1517 pci->no_64bit_msi = true;
1518 }
1512 if (pci_enable_msi(pci) < 0) 1519 if (pci_enable_msi(pci) < 0)
1513 chip->msi = 0; 1520 chip->msi = 0;
1521 }
1514 1522
1515 if (azx_acquire_irq(chip, 0) < 0) 1523 if (azx_acquire_irq(chip, 0) < 0)
1516 return -EBUSY; 1524 return -EBUSY;
@@ -1521,9 +1529,14 @@ static int azx_first_init(struct azx *chip)
1521 gcap = azx_readw(chip, GCAP); 1529 gcap = azx_readw(chip, GCAP);
1522 dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap); 1530 dev_dbg(card->dev, "chipset global capabilities = 0x%x\n", gcap);
1523 1531
1532 /* AMD devices support 40 or 48bit DMA, take the safe one */
1533 if (chip->pci->vendor == PCI_VENDOR_ID_AMD)
1534 dma_bits = 40;
1535
1524 /* disable SB600 64bit support for safety */ 1536 /* disable SB600 64bit support for safety */
1525 if (chip->pci->vendor == PCI_VENDOR_ID_ATI) { 1537 if (chip->pci->vendor == PCI_VENDOR_ID_ATI) {
1526 struct pci_dev *p_smbus; 1538 struct pci_dev *p_smbus;
1539 dma_bits = 40;
1527 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI, 1540 p_smbus = pci_get_device(PCI_VENDOR_ID_ATI,
1528 PCI_DEVICE_ID_ATI_SBX00_SMBUS, 1541 PCI_DEVICE_ID_ATI_SBX00_SMBUS,
1529 NULL); 1542 NULL);
@@ -1553,9 +1566,11 @@ static int azx_first_init(struct azx *chip)
1553 } 1566 }
1554 1567
1555 /* allow 64bit DMA address if supported by H/W */ 1568 /* allow 64bit DMA address if supported by H/W */
1556 if ((gcap & AZX_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64))) 1569 if (!(gcap & AZX_GCAP_64OK))
1557 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64)); 1570 dma_bits = 32;
1558 else { 1571 if (!pci_set_dma_mask(pci, DMA_BIT_MASK(dma_bits))) {
1572 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(dma_bits));
1573 } else {
1559 pci_set_dma_mask(pci, DMA_BIT_MASK(32)); 1574 pci_set_dma_mask(pci, DMA_BIT_MASK(32));
1560 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)); 1575 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32));
1561 } 1576 }
@@ -2004,6 +2019,9 @@ static const struct pci_device_id azx_ids[] = {
2004 /* Sunrise Point */ 2019 /* Sunrise Point */
2005 { PCI_DEVICE(0x8086, 0xa170), 2020 { PCI_DEVICE(0x8086, 0xa170),
2006 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH }, 2021 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2022 /* Sunrise Point-LP */
2023 { PCI_DEVICE(0x8086, 0x9d70),
2024 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_INTEL_PCH },
2007 /* Haswell */ 2025 /* Haswell */
2008 { PCI_DEVICE(0x8086, 0x0a0c), 2026 { PCI_DEVICE(0x8086, 0x0a0c),
2009 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL }, 2027 .driver_data = AZX_DRIVER_HDMI | AZX_DCAPS_INTEL_HASWELL },
diff --git a/sound/pci/hda/hda_priv.h b/sound/pci/hda/hda_priv.h
index 949cd437eeb2..5016014e57f2 100644
--- a/sound/pci/hda/hda_priv.h
+++ b/sound/pci/hda/hda_priv.h
@@ -171,6 +171,7 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
171#define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */ 171#define AZX_DCAPS_PM_RUNTIME (1 << 26) /* runtime PM support */
172#define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */ 172#define AZX_DCAPS_I915_POWERWELL (1 << 27) /* HSW i915 powerwell support */
173#define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */ 173#define AZX_DCAPS_CORBRP_SELF_CLEAR (1 << 28) /* CORBRP clears itself after reset */
174#define AZX_DCAPS_NO_MSI64 (1 << 29) /* Stick to 32-bit MSIs */
174 175
175/* HD Audio class code */ 176/* HD Audio class code */
176#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403 177#define PCI_CLASS_MULTIMEDIA_HD_AUDIO 0x0403
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 71e4bad06345..e9ebc7bd752c 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -43,6 +43,7 @@ struct conexant_spec {
43 unsigned int num_eapds; 43 unsigned int num_eapds;
44 hda_nid_t eapds[4]; 44 hda_nid_t eapds[4];
45 bool dynamic_eapd; 45 bool dynamic_eapd;
46 hda_nid_t mute_led_eapd;
46 47
47 unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */ 48 unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
48 49
@@ -163,6 +164,17 @@ static void cx_auto_vmaster_hook(void *private_data, int enabled)
163 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled); 164 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
164} 165}
165 166
167/* turn on/off EAPD according to Master switch (inversely!) for mute LED */
168static void cx_auto_vmaster_hook_mute_led(void *private_data, int enabled)
169{
170 struct hda_codec *codec = private_data;
171 struct conexant_spec *spec = codec->spec;
172
173 snd_hda_codec_write(codec, spec->mute_led_eapd, 0,
174 AC_VERB_SET_EAPD_BTLENABLE,
175 enabled ? 0x00 : 0x02);
176}
177
166static int cx_auto_build_controls(struct hda_codec *codec) 178static int cx_auto_build_controls(struct hda_codec *codec)
167{ 179{
168 int err; 180 int err;
@@ -223,6 +235,7 @@ enum {
223 CXT_FIXUP_TOSHIBA_P105, 235 CXT_FIXUP_TOSHIBA_P105,
224 CXT_FIXUP_HP_530, 236 CXT_FIXUP_HP_530,
225 CXT_FIXUP_CAP_MIX_AMP_5047, 237 CXT_FIXUP_CAP_MIX_AMP_5047,
238 CXT_FIXUP_MUTE_LED_EAPD,
226}; 239};
227 240
228/* for hda_fixup_thinkpad_acpi() */ 241/* for hda_fixup_thinkpad_acpi() */
@@ -557,6 +570,18 @@ static void cxt_fixup_olpc_xo(struct hda_codec *codec,
557 } 570 }
558} 571}
559 572
573static void cxt_fixup_mute_led_eapd(struct hda_codec *codec,
574 const struct hda_fixup *fix, int action)
575{
576 struct conexant_spec *spec = codec->spec;
577
578 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
579 spec->mute_led_eapd = 0x1b;
580 spec->dynamic_eapd = 1;
581 spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook_mute_led;
582 }
583}
584
560/* 585/*
561 * Fix max input level on mixer widget to 0dB 586 * Fix max input level on mixer widget to 0dB
562 * (originally it has 0x2b steps with 0dB offset 0x14) 587 * (originally it has 0x2b steps with 0dB offset 0x14)
@@ -705,6 +730,10 @@ static const struct hda_fixup cxt_fixups[] = {
705 .type = HDA_FIXUP_FUNC, 730 .type = HDA_FIXUP_FUNC,
706 .v.func = cxt_fixup_cap_mix_amp_5047, 731 .v.func = cxt_fixup_cap_mix_amp_5047,
707 }, 732 },
733 [CXT_FIXUP_MUTE_LED_EAPD] = {
734 .type = HDA_FIXUP_FUNC,
735 .v.func = cxt_fixup_mute_led_eapd,
736 },
708}; 737};
709 738
710static const struct snd_pci_quirk cxt5045_fixups[] = { 739static const struct snd_pci_quirk cxt5045_fixups[] = {
@@ -762,6 +791,7 @@ static const struct snd_pci_quirk cxt5066_fixups[] = {
762 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410), 791 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
763 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410), 792 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
764 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410), 793 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
794 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo IdeaPad Z560", CXT_FIXUP_MUTE_LED_EAPD),
765 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC), 795 SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
766 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC), 796 SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
767 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC), 797 SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
@@ -780,6 +810,7 @@ static const struct hda_model_fixup cxt5066_fixup_models[] = {
780 { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" }, 810 { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
781 { .id = CXT_PINCFG_LEMOTE_A1205, .name = "lemote-a1205" }, 811 { .id = CXT_PINCFG_LEMOTE_A1205, .name = "lemote-a1205" },
782 { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" }, 812 { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
813 { .id = CXT_FIXUP_MUTE_LED_EAPD, .name = "mute-led-eapd" },
783 {} 814 {}
784}; 815};
785 816
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index c9cf248ce8ec..b118a5be18df 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -288,21 +288,91 @@ static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
288 snd_hda_jack_unsol_event(codec, res >> 2); 288 snd_hda_jack_unsol_event(codec, res >> 2);
289} 289}
290 290
291/* additional initialization for ALC888 variants */ 291/* Change EAPD to verb control */
292static void alc888_coef_init(struct hda_codec *codec) 292static void alc_fill_eapd_coef(struct hda_codec *codec)
293{ 293{
294 if (alc_get_coef0(codec) == 0x20) 294 int coef;
295 /* alc888S-VC */ 295
296 alc_write_coef_idx(codec, 7, 0x830); 296 coef = alc_get_coef0(codec);
297 else 297
298 /* alc888-VB */ 298 switch (codec->vendor_id) {
299 alc_write_coef_idx(codec, 7, 0x3030); 299 case 0x10ec0262:
300 alc_update_coef_idx(codec, 0x7, 0, 1<<5);
301 break;
302 case 0x10ec0267:
303 case 0x10ec0268:
304 alc_update_coef_idx(codec, 0x7, 0, 1<<13);
305 break;
306 case 0x10ec0269:
307 if ((coef & 0x00f0) == 0x0010)
308 alc_update_coef_idx(codec, 0xd, 0, 1<<14);
309 if ((coef & 0x00f0) == 0x0020)
310 alc_update_coef_idx(codec, 0x4, 1<<15, 0);
311 if ((coef & 0x00f0) == 0x0030)
312 alc_update_coef_idx(codec, 0x10, 1<<9, 0);
313 break;
314 case 0x10ec0280:
315 case 0x10ec0284:
316 case 0x10ec0290:
317 case 0x10ec0292:
318 alc_update_coef_idx(codec, 0x4, 1<<15, 0);
319 break;
320 case 0x10ec0233:
321 case 0x10ec0255:
322 case 0x10ec0282:
323 case 0x10ec0283:
324 case 0x10ec0286:
325 case 0x10ec0288:
326 alc_update_coef_idx(codec, 0x10, 1<<9, 0);
327 break;
328 case 0x10ec0285:
329 case 0x10ec0293:
330 alc_update_coef_idx(codec, 0xa, 1<<13, 0);
331 break;
332 case 0x10ec0662:
333 if ((coef & 0x00f0) == 0x0030)
334 alc_update_coef_idx(codec, 0x4, 1<<10, 0); /* EAPD Ctrl */
335 break;
336 case 0x10ec0272:
337 case 0x10ec0273:
338 case 0x10ec0663:
339 case 0x10ec0665:
340 case 0x10ec0670:
341 case 0x10ec0671:
342 case 0x10ec0672:
343 alc_update_coef_idx(codec, 0xd, 0, 1<<14); /* EAPD Ctrl */
344 break;
345 case 0x10ec0668:
346 alc_update_coef_idx(codec, 0x7, 3<<13, 0);
347 break;
348 case 0x10ec0867:
349 alc_update_coef_idx(codec, 0x4, 1<<10, 0);
350 break;
351 case 0x10ec0888:
352 if ((coef & 0x00f0) == 0x0020 || (coef & 0x00f0) == 0x0030)
353 alc_update_coef_idx(codec, 0x7, 1<<5, 0);
354 break;
355 case 0x10ec0892:
356 alc_update_coef_idx(codec, 0x7, 1<<5, 0);
357 break;
358 case 0x10ec0899:
359 case 0x10ec0900:
360 alc_update_coef_idx(codec, 0x7, 1<<1, 0);
361 break;
362 }
300} 363}
301 364
302/* additional initialization for ALC889 variants */ 365/* additional initialization for ALC888 variants */
303static void alc889_coef_init(struct hda_codec *codec) 366static void alc888_coef_init(struct hda_codec *codec)
304{ 367{
305 alc_update_coef_idx(codec, 7, 0, 0x2010); 368 switch (alc_get_coef0(codec) & 0x00f0) {
369 /* alc888-VA */
370 case 0x00:
371 /* alc888-VB */
372 case 0x10:
373 alc_update_coef_idx(codec, 7, 0, 0x2030); /* Turn EAPD to High */
374 break;
375 }
306} 376}
307 377
308/* turn on/off EAPD control (only if available) */ 378/* turn on/off EAPD control (only if available) */
@@ -343,6 +413,7 @@ static void alc_eapd_shutup(struct hda_codec *codec)
343/* generic EAPD initialization */ 413/* generic EAPD initialization */
344static void alc_auto_init_amp(struct hda_codec *codec, int type) 414static void alc_auto_init_amp(struct hda_codec *codec, int type)
345{ 415{
416 alc_fill_eapd_coef(codec);
346 alc_auto_setup_eapd(codec, true); 417 alc_auto_setup_eapd(codec, true);
347 switch (type) { 418 switch (type) {
348 case ALC_INIT_GPIO1: 419 case ALC_INIT_GPIO1:
@@ -359,25 +430,15 @@ static void alc_auto_init_amp(struct hda_codec *codec, int type)
359 case 0x10ec0260: 430 case 0x10ec0260:
360 alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x2010); 431 alc_update_coefex_idx(codec, 0x1a, 7, 0, 0x2010);
361 break; 432 break;
362 case 0x10ec0262:
363 case 0x10ec0880: 433 case 0x10ec0880:
364 case 0x10ec0882: 434 case 0x10ec0882:
365 case 0x10ec0883: 435 case 0x10ec0883:
366 case 0x10ec0885: 436 case 0x10ec0885:
367 case 0x10ec0887: 437 alc_update_coef_idx(codec, 7, 0, 0x2030);
368 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
369 case 0x10ec0900:
370 alc889_coef_init(codec);
371 break; 438 break;
372 case 0x10ec0888: 439 case 0x10ec0888:
373 alc888_coef_init(codec); 440 alc888_coef_init(codec);
374 break; 441 break;
375#if 0 /* XXX: This may cause the silent output on speaker on some machines */
376 case 0x10ec0267:
377 case 0x10ec0268:
378 alc_update_coef_idx(codec, 7, 0, 0x3000);
379 break;
380#endif /* XXX */
381 } 442 }
382 break; 443 break;
383 } 444 }
@@ -1710,7 +1771,7 @@ static void alc889_fixup_coef(struct hda_codec *codec,
1710{ 1771{
1711 if (action != HDA_FIXUP_ACT_INIT) 1772 if (action != HDA_FIXUP_ACT_INIT)
1712 return; 1773 return;
1713 alc889_coef_init(codec); 1774 alc_update_coef_idx(codec, 7, 0, 0x2030);
1714} 1775}
1715 1776
1716/* toggle speaker-output according to the hp-jack state */ 1777/* toggle speaker-output according to the hp-jack state */
@@ -3350,6 +3411,27 @@ static void alc269_fixup_hp_gpio_mic1_led(struct hda_codec *codec,
3350 } 3411 }
3351} 3412}
3352 3413
3414static void alc280_fixup_hp_gpio4(struct hda_codec *codec,
3415 const struct hda_fixup *fix, int action)
3416{
3417 /* Like hp_gpio_mic1_led, but also needs GPIO4 low to enable headphone amp */
3418 struct alc_spec *spec = codec->spec;
3419 static const struct hda_verb gpio_init[] = {
3420 { 0x01, AC_VERB_SET_GPIO_MASK, 0x18 },
3421 { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x18 },
3422 {}
3423 };
3424
3425 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
3426 spec->gen.vmaster_mute.hook = alc269_fixup_hp_gpio_mute_hook;
3427 spec->gen.cap_sync_hook = alc269_fixup_hp_cap_mic_mute_hook;
3428 spec->gpio_led = 0;
3429 spec->cap_mute_led_nid = 0x18;
3430 snd_hda_add_verbs(codec, gpio_init);
3431 codec->power_filter = led_power_filter;
3432 }
3433}
3434
3353static void alc269_fixup_hp_line1_mic1_led(struct hda_codec *codec, 3435static void alc269_fixup_hp_line1_mic1_led(struct hda_codec *codec,
3354 const struct hda_fixup *fix, int action) 3436 const struct hda_fixup *fix, int action)
3355{ 3437{
@@ -4217,6 +4299,7 @@ enum {
4217 ALC283_FIXUP_BXBT2807_MIC, 4299 ALC283_FIXUP_BXBT2807_MIC,
4218 ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED, 4300 ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED,
4219 ALC282_FIXUP_ASPIRE_V5_PINS, 4301 ALC282_FIXUP_ASPIRE_V5_PINS,
4302 ALC280_FIXUP_HP_GPIO4,
4220}; 4303};
4221 4304
4222static const struct hda_fixup alc269_fixups[] = { 4305static const struct hda_fixup alc269_fixups[] = {
@@ -4437,6 +4520,8 @@ static const struct hda_fixup alc269_fixups[] = {
4437 [ALC269_FIXUP_HEADSET_MODE] = { 4520 [ALC269_FIXUP_HEADSET_MODE] = {
4438 .type = HDA_FIXUP_FUNC, 4521 .type = HDA_FIXUP_FUNC,
4439 .v.func = alc_fixup_headset_mode, 4522 .v.func = alc_fixup_headset_mode,
4523 .chained = true,
4524 .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED
4440 }, 4525 },
4441 [ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC] = { 4526 [ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
4442 .type = HDA_FIXUP_FUNC, 4527 .type = HDA_FIXUP_FUNC,
@@ -4626,6 +4711,8 @@ static const struct hda_fixup alc269_fixups[] = {
4626 [ALC255_FIXUP_HEADSET_MODE] = { 4711 [ALC255_FIXUP_HEADSET_MODE] = {
4627 .type = HDA_FIXUP_FUNC, 4712 .type = HDA_FIXUP_FUNC,
4628 .v.func = alc_fixup_headset_mode_alc255, 4713 .v.func = alc_fixup_headset_mode_alc255,
4714 .chained = true,
4715 .chain_id = ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED
4629 }, 4716 },
4630 [ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC] = { 4717 [ALC255_FIXUP_HEADSET_MODE_NO_HP_MIC] = {
4631 .type = HDA_FIXUP_FUNC, 4718 .type = HDA_FIXUP_FUNC,
@@ -4661,8 +4748,6 @@ static const struct hda_fixup alc269_fixups[] = {
4661 [ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED] = { 4748 [ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED] = {
4662 .type = HDA_FIXUP_FUNC, 4749 .type = HDA_FIXUP_FUNC,
4663 .v.func = alc_fixup_dell_wmi, 4750 .v.func = alc_fixup_dell_wmi,
4664 .chained_before = true,
4665 .chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE
4666 }, 4751 },
4667 [ALC282_FIXUP_ASPIRE_V5_PINS] = { 4752 [ALC282_FIXUP_ASPIRE_V5_PINS] = {
4668 .type = HDA_FIXUP_PINS, 4753 .type = HDA_FIXUP_PINS,
@@ -4680,7 +4765,10 @@ static const struct hda_fixup alc269_fixups[] = {
4680 { }, 4765 { },
4681 }, 4766 },
4682 }, 4767 },
4683 4768 [ALC280_FIXUP_HP_GPIO4] = {
4769 .type = HDA_FIXUP_FUNC,
4770 .v.func = alc280_fixup_hp_gpio4,
4771 },
4684}; 4772};
4685 4773
4686static const struct snd_pci_quirk alc269_fixup_tbl[] = { 4774static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -4697,13 +4785,13 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4697 SND_PCI_QUIRK(0x1028, 0x05f4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE), 4785 SND_PCI_QUIRK(0x1028, 0x05f4, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4698 SND_PCI_QUIRK(0x1028, 0x05f5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE), 4786 SND_PCI_QUIRK(0x1028, 0x05f5, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4699 SND_PCI_QUIRK(0x1028, 0x05f6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE), 4787 SND_PCI_QUIRK(0x1028, 0x05f6, "Dell", ALC269_FIXUP_DELL1_MIC_NO_PRESENCE),
4700 SND_PCI_QUIRK(0x1028, 0x0610, "Dell", ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED),
4701 SND_PCI_QUIRK(0x1028, 0x0615, "Dell Vostro 5470", ALC290_FIXUP_SUBWOOFER_HSJACK), 4788 SND_PCI_QUIRK(0x1028, 0x0615, "Dell Vostro 5470", ALC290_FIXUP_SUBWOOFER_HSJACK),
4702 SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_SUBWOOFER_HSJACK), 4789 SND_PCI_QUIRK(0x1028, 0x0616, "Dell Vostro 5470", ALC290_FIXUP_SUBWOOFER_HSJACK),
4703 SND_PCI_QUIRK(0x1028, 0x061f, "Dell", ALC255_FIXUP_DELL_WMI_MIC_MUTE_LED),
4704 SND_PCI_QUIRK(0x1028, 0x0638, "Dell Inspiron 5439", ALC290_FIXUP_MONO_SPEAKERS_HSJACK), 4790 SND_PCI_QUIRK(0x1028, 0x0638, "Dell Inspiron 5439", ALC290_FIXUP_MONO_SPEAKERS_HSJACK),
4705 SND_PCI_QUIRK(0x1028, 0x064a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 4791 SND_PCI_QUIRK(0x1028, 0x064a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4706 SND_PCI_QUIRK(0x1028, 0x064b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 4792 SND_PCI_QUIRK(0x1028, 0x064b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4793 SND_PCI_QUIRK(0x1028, 0x06d9, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4794 SND_PCI_QUIRK(0x1028, 0x06da, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4707 SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 4795 SND_PCI_QUIRK(0x1028, 0x164a, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4708 SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE), 4796 SND_PCI_QUIRK(0x1028, 0x164b, "Dell", ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),
4709 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2), 4797 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC2),
@@ -4728,21 +4816,15 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4728 SND_PCI_QUIRK(0x103c, 0x22cf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4816 SND_PCI_QUIRK(0x103c, 0x22cf, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4729 SND_PCI_QUIRK(0x103c, 0x22dc, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4817 SND_PCI_QUIRK(0x103c, 0x22dc, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4730 SND_PCI_QUIRK(0x103c, 0x22fb, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4818 SND_PCI_QUIRK(0x103c, 0x22fb, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4731 SND_PCI_QUIRK(0x103c, 0x8004, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4732 /* ALC290 */ 4819 /* ALC290 */
4733 SND_PCI_QUIRK(0x103c, 0x221b, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4820 SND_PCI_QUIRK(0x103c, 0x221b, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4734 SND_PCI_QUIRK(0x103c, 0x2221, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4821 SND_PCI_QUIRK(0x103c, 0x2221, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4735 SND_PCI_QUIRK(0x103c, 0x2225, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4822 SND_PCI_QUIRK(0x103c, 0x2225, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4736 SND_PCI_QUIRK(0x103c, 0x2246, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4737 SND_PCI_QUIRK(0x103c, 0x2247, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4738 SND_PCI_QUIRK(0x103c, 0x2248, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4739 SND_PCI_QUIRK(0x103c, 0x2249, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4740 SND_PCI_QUIRK(0x103c, 0x2253, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4823 SND_PCI_QUIRK(0x103c, 0x2253, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4741 SND_PCI_QUIRK(0x103c, 0x2254, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4824 SND_PCI_QUIRK(0x103c, 0x2254, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4742 SND_PCI_QUIRK(0x103c, 0x2255, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4825 SND_PCI_QUIRK(0x103c, 0x2255, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4743 SND_PCI_QUIRK(0x103c, 0x2256, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4826 SND_PCI_QUIRK(0x103c, 0x2256, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4744 SND_PCI_QUIRK(0x103c, 0x2257, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4827 SND_PCI_QUIRK(0x103c, 0x2257, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4745 SND_PCI_QUIRK(0x103c, 0x2258, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4746 SND_PCI_QUIRK(0x103c, 0x2259, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4828 SND_PCI_QUIRK(0x103c, 0x2259, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4747 SND_PCI_QUIRK(0x103c, 0x225a, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4829 SND_PCI_QUIRK(0x103c, 0x225a, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4748 SND_PCI_QUIRK(0x103c, 0x2260, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4830 SND_PCI_QUIRK(0x103c, 0x2260, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
@@ -4751,7 +4833,6 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4751 SND_PCI_QUIRK(0x103c, 0x2265, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4833 SND_PCI_QUIRK(0x103c, 0x2265, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4752 SND_PCI_QUIRK(0x103c, 0x2272, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4834 SND_PCI_QUIRK(0x103c, 0x2272, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4753 SND_PCI_QUIRK(0x103c, 0x2273, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4835 SND_PCI_QUIRK(0x103c, 0x2273, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4754 SND_PCI_QUIRK(0x103c, 0x2277, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4755 SND_PCI_QUIRK(0x103c, 0x2278, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED), 4836 SND_PCI_QUIRK(0x103c, 0x2278, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED),
4756 SND_PCI_QUIRK(0x103c, 0x227f, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4837 SND_PCI_QUIRK(0x103c, 0x227f, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
4757 SND_PCI_QUIRK(0x103c, 0x2282, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1), 4838 SND_PCI_QUIRK(0x103c, 0x2282, "HP", ALC269_FIXUP_HP_MUTE_LED_MIC1),
@@ -4804,7 +4885,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4804 SND_PCI_QUIRK(0x17aa, 0x220e, "Thinkpad T440p", ALC292_FIXUP_TPT440_DOCK), 4885 SND_PCI_QUIRK(0x17aa, 0x220e, "Thinkpad T440p", ALC292_FIXUP_TPT440_DOCK),
4805 SND_PCI_QUIRK(0x17aa, 0x2210, "Thinkpad T540p", ALC292_FIXUP_TPT440_DOCK), 4886 SND_PCI_QUIRK(0x17aa, 0x2210, "Thinkpad T540p", ALC292_FIXUP_TPT440_DOCK),
4806 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK), 4887 SND_PCI_QUIRK(0x17aa, 0x2212, "Thinkpad T440", ALC292_FIXUP_TPT440_DOCK),
4807 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4888 SND_PCI_QUIRK(0x17aa, 0x2214, "Thinkpad X240", ALC292_FIXUP_TPT440_DOCK),
4808 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4889 SND_PCI_QUIRK(0x17aa, 0x2215, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
4809 SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP), 4890 SND_PCI_QUIRK(0x17aa, 0x3978, "IdeaPad Y410P", ALC269_FIXUP_NO_SHUTUP),
4810 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST), 4891 SND_PCI_QUIRK(0x17aa, 0x5013, "Thinkpad", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
@@ -4984,6 +5065,19 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
4984 {0x17, 0x40000000}, 5065 {0x17, 0x40000000},
4985 {0x1d, 0x40700001}, 5066 {0x1d, 0x40700001},
4986 {0x21, 0x02211040}), 5067 {0x21, 0x02211040}),
5068 SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC280_FIXUP_HP_GPIO4,
5069 {0x12, 0x90a60130},
5070 {0x13, 0x40000000},
5071 {0x14, 0x90170110},
5072 {0x15, 0x0421101f},
5073 {0x16, 0x411111f0},
5074 {0x17, 0x411111f0},
5075 {0x18, 0x411111f0},
5076 {0x19, 0x411111f0},
5077 {0x1a, 0x04a11020},
5078 {0x1b, 0x411111f0},
5079 {0x1d, 0x40748605},
5080 {0x1e, 0x411111f0}),
4987 SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED, 5081 SND_HDA_PIN_QUIRK(0x10ec0280, 0x103c, "HP", ALC269_FIXUP_HP_GPIO_MIC1_LED,
4988 {0x12, 0x90a60140}, 5082 {0x12, 0x90a60140},
4989 {0x13, 0x40000000}, 5083 {0x13, 0x40000000},
@@ -5194,9 +5288,6 @@ static void alc269_fill_coef(struct hda_codec *codec)
5194 } 5288 }
5195 } 5289 }
5196 5290
5197 /* Class D */
5198 alc_update_coef_idx(codec, 0xd, 0, 1<<14);
5199
5200 /* HP */ 5291 /* HP */
5201 alc_update_coef_idx(codec, 0x4, 0, 1<<11); 5292 alc_update_coef_idx(codec, 0x4, 0, 1<<11);
5202} 5293}
@@ -5651,6 +5742,35 @@ static void alc662_fixup_led_gpio1(struct hda_codec *codec,
5651 } 5742 }
5652} 5743}
5653 5744
5745static struct coef_fw alc668_coefs[] = {
5746 WRITE_COEF(0x01, 0xbebe), WRITE_COEF(0x02, 0xaaaa), WRITE_COEF(0x03, 0x0),
5747 WRITE_COEF(0x04, 0x0180), WRITE_COEF(0x06, 0x0), WRITE_COEF(0x07, 0x0f80),
5748 WRITE_COEF(0x08, 0x0031), WRITE_COEF(0x0a, 0x0060), WRITE_COEF(0x0b, 0x0),
5749 WRITE_COEF(0x0c, 0x7cf7), WRITE_COEF(0x0d, 0x1080), WRITE_COEF(0x0e, 0x7f7f),
5750 WRITE_COEF(0x0f, 0xcccc), WRITE_COEF(0x10, 0xddcc), WRITE_COEF(0x11, 0x0001),
5751 WRITE_COEF(0x13, 0x0), WRITE_COEF(0x14, 0x2aa0), WRITE_COEF(0x17, 0xa940),
5752 WRITE_COEF(0x19, 0x0), WRITE_COEF(0x1a, 0x0), WRITE_COEF(0x1b, 0x0),
5753 WRITE_COEF(0x1c, 0x0), WRITE_COEF(0x1d, 0x0), WRITE_COEF(0x1e, 0x7418),
5754 WRITE_COEF(0x1f, 0x0804), WRITE_COEF(0x20, 0x4200), WRITE_COEF(0x21, 0x0468),
5755 WRITE_COEF(0x22, 0x8ccc), WRITE_COEF(0x23, 0x0250), WRITE_COEF(0x24, 0x7418),
5756 WRITE_COEF(0x27, 0x0), WRITE_COEF(0x28, 0x8ccc), WRITE_COEF(0x2a, 0xff00),
5757 WRITE_COEF(0x2b, 0x8000), WRITE_COEF(0xa7, 0xff00), WRITE_COEF(0xa8, 0x8000),
5758 WRITE_COEF(0xaa, 0x2e17), WRITE_COEF(0xab, 0xa0c0), WRITE_COEF(0xac, 0x0),
5759 WRITE_COEF(0xad, 0x0), WRITE_COEF(0xae, 0x2ac6), WRITE_COEF(0xaf, 0xa480),
5760 WRITE_COEF(0xb0, 0x0), WRITE_COEF(0xb1, 0x0), WRITE_COEF(0xb2, 0x0),
5761 WRITE_COEF(0xb3, 0x0), WRITE_COEF(0xb4, 0x0), WRITE_COEF(0xb5, 0x1040),
5762 WRITE_COEF(0xb6, 0xd697), WRITE_COEF(0xb7, 0x902b), WRITE_COEF(0xb8, 0xd697),
5763 WRITE_COEF(0xb9, 0x902b), WRITE_COEF(0xba, 0xb8ba), WRITE_COEF(0xbb, 0xaaab),
5764 WRITE_COEF(0xbc, 0xaaaf), WRITE_COEF(0xbd, 0x6aaa), WRITE_COEF(0xbe, 0x1c02),
5765 WRITE_COEF(0xc0, 0x00ff), WRITE_COEF(0xc1, 0x0fa6),
5766 {}
5767};
5768
5769static void alc668_restore_default_value(struct hda_codec *codec)
5770{
5771 alc_process_coef_fw(codec, alc668_coefs);
5772}
5773
5654enum { 5774enum {
5655 ALC662_FIXUP_ASPIRE, 5775 ALC662_FIXUP_ASPIRE,
5656 ALC662_FIXUP_LED_GPIO1, 5776 ALC662_FIXUP_LED_GPIO1,
@@ -6077,29 +6197,6 @@ static const struct snd_hda_pin_quirk alc662_pin_fixup_tbl[] = {
6077 {} 6197 {}
6078}; 6198};
6079 6199
6080static void alc662_fill_coef(struct hda_codec *codec)
6081{
6082 int coef;
6083
6084 coef = alc_get_coef0(codec);
6085
6086 switch (codec->vendor_id) {
6087 case 0x10ec0662:
6088 if ((coef & 0x00f0) == 0x0030)
6089 alc_update_coef_idx(codec, 0x4, 1<<10, 0); /* EAPD Ctrl */
6090 break;
6091 case 0x10ec0272:
6092 case 0x10ec0273:
6093 case 0x10ec0663:
6094 case 0x10ec0665:
6095 case 0x10ec0670:
6096 case 0x10ec0671:
6097 case 0x10ec0672:
6098 alc_update_coef_idx(codec, 0xd, 0, 1<<14); /* EAPD Ctrl */
6099 break;
6100 }
6101}
6102
6103/* 6200/*
6104 */ 6201 */
6105static int patch_alc662(struct hda_codec *codec) 6202static int patch_alc662(struct hda_codec *codec)
@@ -6118,8 +6215,11 @@ static int patch_alc662(struct hda_codec *codec)
6118 6215
6119 alc_fix_pll_init(codec, 0x20, 0x04, 15); 6216 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6120 6217
6121 spec->init_hook = alc662_fill_coef; 6218 switch (codec->vendor_id) {
6122 alc662_fill_coef(codec); 6219 case 0x10ec0668:
6220 spec->init_hook = alc668_restore_default_value;
6221 break;
6222 }
6123 6223
6124 snd_hda_pick_fixup(codec, alc662_fixup_models, 6224 snd_hda_pick_fixup(codec, alc662_fixup_models,
6125 alc662_fixup_tbl, alc662_fixups); 6225 alc662_fixup_tbl, alc662_fixups);
diff --git a/sound/soc/codecs/cs42l51-i2c.c b/sound/soc/codecs/cs42l51-i2c.c
index cee51ae177c1..c40428f25ba5 100644
--- a/sound/soc/codecs/cs42l51-i2c.c
+++ b/sound/soc/codecs/cs42l51-i2c.c
@@ -46,6 +46,7 @@ static struct i2c_driver cs42l51_i2c_driver = {
46 .driver = { 46 .driver = {
47 .name = "cs42l51", 47 .name = "cs42l51",
48 .owner = THIS_MODULE, 48 .owner = THIS_MODULE,
49 .of_match_table = cs42l51_of_match,
49 }, 50 },
50 .probe = cs42l51_i2c_probe, 51 .probe = cs42l51_i2c_probe,
51 .remove = cs42l51_i2c_remove, 52 .remove = cs42l51_i2c_remove,
diff --git a/sound/soc/codecs/cs42l51.c b/sound/soc/codecs/cs42l51.c
index 09488d97de60..669c38fc3034 100644
--- a/sound/soc/codecs/cs42l51.c
+++ b/sound/soc/codecs/cs42l51.c
@@ -558,11 +558,13 @@ error:
558} 558}
559EXPORT_SYMBOL_GPL(cs42l51_probe); 559EXPORT_SYMBOL_GPL(cs42l51_probe);
560 560
561static const struct of_device_id cs42l51_of_match[] = { 561const struct of_device_id cs42l51_of_match[] = {
562 { .compatible = "cirrus,cs42l51", }, 562 { .compatible = "cirrus,cs42l51", },
563 { } 563 { }
564}; 564};
565MODULE_DEVICE_TABLE(of, cs42l51_of_match); 565MODULE_DEVICE_TABLE(of, cs42l51_of_match);
566EXPORT_SYMBOL_GPL(cs42l51_of_match);
567
566MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>"); 568MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
567MODULE_DESCRIPTION("Cirrus Logic CS42L51 ALSA SoC Codec Driver"); 569MODULE_DESCRIPTION("Cirrus Logic CS42L51 ALSA SoC Codec Driver");
568MODULE_LICENSE("GPL"); 570MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs42l51.h b/sound/soc/codecs/cs42l51.h
index 8c55bf384bc6..0ca805492ac4 100644
--- a/sound/soc/codecs/cs42l51.h
+++ b/sound/soc/codecs/cs42l51.h
@@ -22,6 +22,7 @@ struct device;
22 22
23extern const struct regmap_config cs42l51_regmap; 23extern const struct regmap_config cs42l51_regmap;
24int cs42l51_probe(struct device *dev, struct regmap *regmap); 24int cs42l51_probe(struct device *dev, struct regmap *regmap);
25extern const struct of_device_id cs42l51_of_match[];
25 26
26#define CS42L51_CHIP_ID 0x1B 27#define CS42L51_CHIP_ID 0x1B
27#define CS42L51_CHIP_REV_A 0x00 28#define CS42L51_CHIP_REV_A 0x00
diff --git a/sound/soc/codecs/es8328-i2c.c b/sound/soc/codecs/es8328-i2c.c
index aae410d122ee..2d05b5d3a6ce 100644
--- a/sound/soc/codecs/es8328-i2c.c
+++ b/sound/soc/codecs/es8328-i2c.c
@@ -19,7 +19,7 @@
19#include "es8328.h" 19#include "es8328.h"
20 20
21static const struct i2c_device_id es8328_id[] = { 21static const struct i2c_device_id es8328_id[] = {
22 { "everest,es8328", 0 }, 22 { "es8328", 0 },
23 { } 23 { }
24}; 24};
25MODULE_DEVICE_TABLE(i2c, es8328_id); 25MODULE_DEVICE_TABLE(i2c, es8328_id);
diff --git a/sound/soc/codecs/max98090.c b/sound/soc/codecs/max98090.c
index d519294f57c7..1229554f1464 100644
--- a/sound/soc/codecs/max98090.c
+++ b/sound/soc/codecs/max98090.c
@@ -1941,13 +1941,13 @@ static int max98090_dai_set_sysclk(struct snd_soc_dai *dai,
1941 * 0x02 (when master clk is 20MHz to 40MHz).. 1941 * 0x02 (when master clk is 20MHz to 40MHz)..
1942 * 0x03 (when master clk is 40MHz to 60MHz).. 1942 * 0x03 (when master clk is 40MHz to 60MHz)..
1943 */ 1943 */
1944 if ((freq >= 10000000) && (freq < 20000000)) { 1944 if ((freq >= 10000000) && (freq <= 20000000)) {
1945 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK, 1945 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK,
1946 M98090_PSCLK_DIV1); 1946 M98090_PSCLK_DIV1);
1947 } else if ((freq >= 20000000) && (freq < 40000000)) { 1947 } else if ((freq > 20000000) && (freq <= 40000000)) {
1948 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK, 1948 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK,
1949 M98090_PSCLK_DIV2); 1949 M98090_PSCLK_DIV2);
1950 } else if ((freq >= 40000000) && (freq < 60000000)) { 1950 } else if ((freq > 40000000) && (freq <= 60000000)) {
1951 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK, 1951 snd_soc_write(codec, M98090_REG_SYSTEM_CLOCK,
1952 M98090_PSCLK_DIV4); 1952 M98090_PSCLK_DIV4);
1953 } else { 1953 } else {
diff --git a/sound/soc/codecs/rt5645.c b/sound/soc/codecs/rt5645.c
index 3fb83bf09768..d16331e0b64d 100644
--- a/sound/soc/codecs/rt5645.c
+++ b/sound/soc/codecs/rt5645.c
@@ -139,6 +139,7 @@ static const struct reg_default rt5645_reg[] = {
139 { 0x76, 0x000a }, 139 { 0x76, 0x000a },
140 { 0x77, 0x0c00 }, 140 { 0x77, 0x0c00 },
141 { 0x78, 0x0000 }, 141 { 0x78, 0x0000 },
142 { 0x79, 0x0123 },
142 { 0x80, 0x0000 }, 143 { 0x80, 0x0000 },
143 { 0x81, 0x0000 }, 144 { 0x81, 0x0000 },
144 { 0x82, 0x0000 }, 145 { 0x82, 0x0000 },
@@ -334,6 +335,7 @@ static bool rt5645_readable_register(struct device *dev, unsigned int reg)
334 case RT5645_DMIC_CTRL2: 335 case RT5645_DMIC_CTRL2:
335 case RT5645_TDM_CTRL_1: 336 case RT5645_TDM_CTRL_1:
336 case RT5645_TDM_CTRL_2: 337 case RT5645_TDM_CTRL_2:
338 case RT5645_TDM_CTRL_3:
337 case RT5645_GLB_CLK: 339 case RT5645_GLB_CLK:
338 case RT5645_PLL_CTRL1: 340 case RT5645_PLL_CTRL1:
339 case RT5645_PLL_CTRL2: 341 case RT5645_PLL_CTRL2:
diff --git a/sound/soc/codecs/rt5670.c b/sound/soc/codecs/rt5670.c
index ba9d9b4d4857..9bd8b4f63303 100644
--- a/sound/soc/codecs/rt5670.c
+++ b/sound/soc/codecs/rt5670.c
@@ -100,18 +100,18 @@ static const struct reg_default rt5670_reg[] = {
100 { 0x4c, 0x5380 }, 100 { 0x4c, 0x5380 },
101 { 0x4f, 0x0073 }, 101 { 0x4f, 0x0073 },
102 { 0x52, 0x00d3 }, 102 { 0x52, 0x00d3 },
103 { 0x53, 0xf0f0 }, 103 { 0x53, 0xf000 },
104 { 0x61, 0x0000 }, 104 { 0x61, 0x0000 },
105 { 0x62, 0x0001 }, 105 { 0x62, 0x0001 },
106 { 0x63, 0x00c3 }, 106 { 0x63, 0x00c3 },
107 { 0x64, 0x0000 }, 107 { 0x64, 0x0000 },
108 { 0x65, 0x0000 }, 108 { 0x65, 0x0001 },
109 { 0x66, 0x0000 }, 109 { 0x66, 0x0000 },
110 { 0x6f, 0x8000 }, 110 { 0x6f, 0x8000 },
111 { 0x70, 0x8000 }, 111 { 0x70, 0x8000 },
112 { 0x71, 0x8000 }, 112 { 0x71, 0x8000 },
113 { 0x72, 0x8000 }, 113 { 0x72, 0x8000 },
114 { 0x73, 0x1110 }, 114 { 0x73, 0x7770 },
115 { 0x74, 0x0e00 }, 115 { 0x74, 0x0e00 },
116 { 0x75, 0x1505 }, 116 { 0x75, 0x1505 },
117 { 0x76, 0x0015 }, 117 { 0x76, 0x0015 },
@@ -125,21 +125,21 @@ static const struct reg_default rt5670_reg[] = {
125 { 0x83, 0x0000 }, 125 { 0x83, 0x0000 },
126 { 0x84, 0x0000 }, 126 { 0x84, 0x0000 },
127 { 0x85, 0x0000 }, 127 { 0x85, 0x0000 },
128 { 0x86, 0x0008 }, 128 { 0x86, 0x0004 },
129 { 0x87, 0x0000 }, 129 { 0x87, 0x0000 },
130 { 0x88, 0x0000 }, 130 { 0x88, 0x0000 },
131 { 0x89, 0x0000 }, 131 { 0x89, 0x0000 },
132 { 0x8a, 0x0000 }, 132 { 0x8a, 0x0000 },
133 { 0x8b, 0x0000 }, 133 { 0x8b, 0x0000 },
134 { 0x8c, 0x0007 }, 134 { 0x8c, 0x0003 },
135 { 0x8d, 0x0000 }, 135 { 0x8d, 0x0000 },
136 { 0x8e, 0x0004 }, 136 { 0x8e, 0x0004 },
137 { 0x8f, 0x1100 }, 137 { 0x8f, 0x1100 },
138 { 0x90, 0x0646 }, 138 { 0x90, 0x0646 },
139 { 0x91, 0x0c06 }, 139 { 0x91, 0x0c06 },
140 { 0x93, 0x0000 }, 140 { 0x93, 0x0000 },
141 { 0x94, 0x0000 }, 141 { 0x94, 0x1270 },
142 { 0x95, 0x0000 }, 142 { 0x95, 0x1000 },
143 { 0x97, 0x0000 }, 143 { 0x97, 0x0000 },
144 { 0x98, 0x0000 }, 144 { 0x98, 0x0000 },
145 { 0x99, 0x0000 }, 145 { 0x99, 0x0000 },
@@ -150,11 +150,11 @@ static const struct reg_default rt5670_reg[] = {
150 { 0x9e, 0x0400 }, 150 { 0x9e, 0x0400 },
151 { 0xae, 0x7000 }, 151 { 0xae, 0x7000 },
152 { 0xaf, 0x0000 }, 152 { 0xaf, 0x0000 },
153 { 0xb0, 0x6000 }, 153 { 0xb0, 0x7000 },
154 { 0xb1, 0x0000 }, 154 { 0xb1, 0x0000 },
155 { 0xb2, 0x0000 }, 155 { 0xb2, 0x0000 },
156 { 0xb3, 0x001f }, 156 { 0xb3, 0x001f },
157 { 0xb4, 0x2206 }, 157 { 0xb4, 0x220c },
158 { 0xb5, 0x1f00 }, 158 { 0xb5, 0x1f00 },
159 { 0xb6, 0x0000 }, 159 { 0xb6, 0x0000 },
160 { 0xb7, 0x0000 }, 160 { 0xb7, 0x0000 },
@@ -171,25 +171,25 @@ static const struct reg_default rt5670_reg[] = {
171 { 0xcf, 0x1813 }, 171 { 0xcf, 0x1813 },
172 { 0xd0, 0x0690 }, 172 { 0xd0, 0x0690 },
173 { 0xd1, 0x1c17 }, 173 { 0xd1, 0x1c17 },
174 { 0xd3, 0xb320 }, 174 { 0xd3, 0xa220 },
175 { 0xd4, 0x0000 }, 175 { 0xd4, 0x0000 },
176 { 0xd6, 0x0400 }, 176 { 0xd6, 0x0400 },
177 { 0xd9, 0x0809 }, 177 { 0xd9, 0x0809 },
178 { 0xda, 0x0000 }, 178 { 0xda, 0x0000 },
179 { 0xdb, 0x0001 }, 179 { 0xdb, 0x0001 },
180 { 0xdc, 0x0049 }, 180 { 0xdc, 0x0049 },
181 { 0xdd, 0x0009 }, 181 { 0xdd, 0x0024 },
182 { 0xe6, 0x8000 }, 182 { 0xe6, 0x8000 },
183 { 0xe7, 0x0000 }, 183 { 0xe7, 0x0000 },
184 { 0xec, 0xb300 }, 184 { 0xec, 0xa200 },
185 { 0xed, 0x0000 }, 185 { 0xed, 0x0000 },
186 { 0xee, 0xb300 }, 186 { 0xee, 0xa200 },
187 { 0xef, 0x0000 }, 187 { 0xef, 0x0000 },
188 { 0xf8, 0x0000 }, 188 { 0xf8, 0x0000 },
189 { 0xf9, 0x0000 }, 189 { 0xf9, 0x0000 },
190 { 0xfa, 0x8010 }, 190 { 0xfa, 0x8010 },
191 { 0xfb, 0x0033 }, 191 { 0xfb, 0x0033 },
192 { 0xfc, 0x0080 }, 192 { 0xfc, 0x0100 },
193}; 193};
194 194
195static bool rt5670_volatile_register(struct device *dev, unsigned int reg) 195static bool rt5670_volatile_register(struct device *dev, unsigned int reg)
@@ -1877,6 +1877,10 @@ static const struct snd_soc_dapm_route rt5670_dapm_routes[] = {
1877 { "DAC1 MIXR", "DAC1 Switch", "DAC1 R Mux" }, 1877 { "DAC1 MIXR", "DAC1 Switch", "DAC1 R Mux" },
1878 { "DAC1 MIXR", NULL, "DAC Stereo1 Filter" }, 1878 { "DAC1 MIXR", NULL, "DAC Stereo1 Filter" },
1879 1879
1880 { "DAC Stereo1 Filter", NULL, "PLL1", is_sys_clk_from_pll },
1881 { "DAC Mono Left Filter", NULL, "PLL1", is_sys_clk_from_pll },
1882 { "DAC Mono Right Filter", NULL, "PLL1", is_sys_clk_from_pll },
1883
1880 { "DAC MIX", NULL, "DAC1 MIXL" }, 1884 { "DAC MIX", NULL, "DAC1 MIXL" },
1881 { "DAC MIX", NULL, "DAC1 MIXR" }, 1885 { "DAC MIX", NULL, "DAC1 MIXR" },
1882 1886
@@ -1926,14 +1930,10 @@ static const struct snd_soc_dapm_route rt5670_dapm_routes[] = {
1926 1930
1927 { "DAC L1", NULL, "DAC L1 Power" }, 1931 { "DAC L1", NULL, "DAC L1 Power" },
1928 { "DAC L1", NULL, "Stereo DAC MIXL" }, 1932 { "DAC L1", NULL, "Stereo DAC MIXL" },
1929 { "DAC L1", NULL, "PLL1", is_sys_clk_from_pll },
1930 { "DAC R1", NULL, "DAC R1 Power" }, 1933 { "DAC R1", NULL, "DAC R1 Power" },
1931 { "DAC R1", NULL, "Stereo DAC MIXR" }, 1934 { "DAC R1", NULL, "Stereo DAC MIXR" },
1932 { "DAC R1", NULL, "PLL1", is_sys_clk_from_pll },
1933 { "DAC L2", NULL, "Mono DAC MIXL" }, 1935 { "DAC L2", NULL, "Mono DAC MIXL" },
1934 { "DAC L2", NULL, "PLL1", is_sys_clk_from_pll },
1935 { "DAC R2", NULL, "Mono DAC MIXR" }, 1936 { "DAC R2", NULL, "Mono DAC MIXR" },
1936 { "DAC R2", NULL, "PLL1", is_sys_clk_from_pll },
1937 1937
1938 { "OUT MIXL", "BST1 Switch", "BST1" }, 1938 { "OUT MIXL", "BST1 Switch", "BST1" },
1939 { "OUT MIXL", "INL Switch", "INL VOL" }, 1939 { "OUT MIXL", "INL Switch", "INL VOL" },
diff --git a/sound/soc/codecs/sgtl5000.c b/sound/soc/codecs/sgtl5000.c
index 6bb77d76561b..dab9b15304af 100644
--- a/sound/soc/codecs/sgtl5000.c
+++ b/sound/soc/codecs/sgtl5000.c
@@ -1299,8 +1299,7 @@ static int sgtl5000_probe(struct snd_soc_codec *codec)
1299 1299
1300 /* enable small pop, introduce 400ms delay in turning off */ 1300 /* enable small pop, introduce 400ms delay in turning off */
1301 snd_soc_update_bits(codec, SGTL5000_CHIP_REF_CTRL, 1301 snd_soc_update_bits(codec, SGTL5000_CHIP_REF_CTRL,
1302 SGTL5000_SMALL_POP, 1302 SGTL5000_SMALL_POP, 1);
1303 SGTL5000_SMALL_POP);
1304 1303
1305 /* disable short cut detector */ 1304 /* disable short cut detector */
1306 snd_soc_write(codec, SGTL5000_CHIP_SHORT_CTRL, 0); 1305 snd_soc_write(codec, SGTL5000_CHIP_SHORT_CTRL, 0);
diff --git a/sound/soc/codecs/sgtl5000.h b/sound/soc/codecs/sgtl5000.h
index 2f8c88931f69..bd7a344bf8c5 100644
--- a/sound/soc/codecs/sgtl5000.h
+++ b/sound/soc/codecs/sgtl5000.h
@@ -275,7 +275,7 @@
275#define SGTL5000_BIAS_CTRL_MASK 0x000e 275#define SGTL5000_BIAS_CTRL_MASK 0x000e
276#define SGTL5000_BIAS_CTRL_SHIFT 1 276#define SGTL5000_BIAS_CTRL_SHIFT 1
277#define SGTL5000_BIAS_CTRL_WIDTH 3 277#define SGTL5000_BIAS_CTRL_WIDTH 3
278#define SGTL5000_SMALL_POP 0x0001 278#define SGTL5000_SMALL_POP 0
279 279
280/* 280/*
281 * SGTL5000_CHIP_MIC_CTRL 281 * SGTL5000_CHIP_MIC_CTRL
diff --git a/sound/soc/codecs/wm_adsp.c b/sound/soc/codecs/wm_adsp.c
index f412a9911a75..67124783558a 100644
--- a/sound/soc/codecs/wm_adsp.c
+++ b/sound/soc/codecs/wm_adsp.c
@@ -1355,6 +1355,7 @@ static int wm_adsp_load_coeff(struct wm_adsp *dsp)
1355 file, blocks, pos - firmware->size); 1355 file, blocks, pos - firmware->size);
1356 1356
1357out_fw: 1357out_fw:
1358 regmap_async_complete(regmap);
1358 release_firmware(firmware); 1359 release_firmware(firmware);
1359 wm_adsp_buf_free(&buf_list); 1360 wm_adsp_buf_free(&buf_list);
1360out: 1361out:
diff --git a/sound/soc/fsl/fsl_asrc.c b/sound/soc/fsl/fsl_asrc.c
index ed866e9a2928..9deabdd2b1a2 100644
--- a/sound/soc/fsl/fsl_asrc.c
+++ b/sound/soc/fsl/fsl_asrc.c
@@ -684,12 +684,38 @@ static bool fsl_asrc_writeable_reg(struct device *dev, unsigned int reg)
684 } 684 }
685} 685}
686 686
687static struct reg_default fsl_asrc_reg[] = {
688 { REG_ASRCTR, 0x0000 }, { REG_ASRIER, 0x0000 },
689 { REG_ASRCNCR, 0x0000 }, { REG_ASRCFG, 0x0000 },
690 { REG_ASRCSR, 0x0000 }, { REG_ASRCDR1, 0x0000 },
691 { REG_ASRCDR2, 0x0000 }, { REG_ASRSTR, 0x0000 },
692 { REG_ASRRA, 0x0000 }, { REG_ASRRB, 0x0000 },
693 { REG_ASRRC, 0x0000 }, { REG_ASRPM1, 0x0000 },
694 { REG_ASRPM2, 0x0000 }, { REG_ASRPM3, 0x0000 },
695 { REG_ASRPM4, 0x0000 }, { REG_ASRPM5, 0x0000 },
696 { REG_ASRTFR1, 0x0000 }, { REG_ASRCCR, 0x0000 },
697 { REG_ASRDIA, 0x0000 }, { REG_ASRDOA, 0x0000 },
698 { REG_ASRDIB, 0x0000 }, { REG_ASRDOB, 0x0000 },
699 { REG_ASRDIC, 0x0000 }, { REG_ASRDOC, 0x0000 },
700 { REG_ASRIDRHA, 0x0000 }, { REG_ASRIDRLA, 0x0000 },
701 { REG_ASRIDRHB, 0x0000 }, { REG_ASRIDRLB, 0x0000 },
702 { REG_ASRIDRHC, 0x0000 }, { REG_ASRIDRLC, 0x0000 },
703 { REG_ASR76K, 0x0A47 }, { REG_ASR56K, 0x0DF3 },
704 { REG_ASRMCRA, 0x0000 }, { REG_ASRFSTA, 0x0000 },
705 { REG_ASRMCRB, 0x0000 }, { REG_ASRFSTB, 0x0000 },
706 { REG_ASRMCRC, 0x0000 }, { REG_ASRFSTC, 0x0000 },
707 { REG_ASRMCR1A, 0x0000 }, { REG_ASRMCR1B, 0x0000 },
708 { REG_ASRMCR1C, 0x0000 },
709};
710
687static const struct regmap_config fsl_asrc_regmap_config = { 711static const struct regmap_config fsl_asrc_regmap_config = {
688 .reg_bits = 32, 712 .reg_bits = 32,
689 .reg_stride = 4, 713 .reg_stride = 4,
690 .val_bits = 32, 714 .val_bits = 32,
691 715
692 .max_register = REG_ASRMCR1C, 716 .max_register = REG_ASRMCR1C,
717 .reg_defaults = fsl_asrc_reg,
718 .num_reg_defaults = ARRAY_SIZE(fsl_asrc_reg),
693 .readable_reg = fsl_asrc_readable_reg, 719 .readable_reg = fsl_asrc_readable_reg,
694 .volatile_reg = fsl_asrc_volatile_reg, 720 .volatile_reg = fsl_asrc_volatile_reg,
695 .writeable_reg = fsl_asrc_writeable_reg, 721 .writeable_reg = fsl_asrc_writeable_reg,
diff --git a/sound/soc/rockchip/rockchip_i2s.c b/sound/soc/rockchip/rockchip_i2s.c
index f373e37f8305..c74ba37f862c 100644
--- a/sound/soc/rockchip/rockchip_i2s.c
+++ b/sound/soc/rockchip/rockchip_i2s.c
@@ -154,8 +154,10 @@ static void rockchip_snd_rxctrl(struct rk_i2s_dev *i2s, int on)
154 while (val) { 154 while (val) {
155 regmap_read(i2s->regmap, I2S_CLR, &val); 155 regmap_read(i2s->regmap, I2S_CLR, &val);
156 retry--; 156 retry--;
157 if (!retry) 157 if (!retry) {
158 dev_warn(i2s->dev, "fail to clear\n"); 158 dev_warn(i2s->dev, "fail to clear\n");
159 break;
160 }
159 } 161 }
160 } 162 }
161 } 163 }
diff --git a/sound/soc/samsung/snow.c b/sound/soc/samsung/snow.c
index 0acf5d0eed53..72118a77dd5b 100644
--- a/sound/soc/samsung/snow.c
+++ b/sound/soc/samsung/snow.c
@@ -110,6 +110,7 @@ static const struct of_device_id snow_of_match[] = {
110 { .compatible = "google,snow-audio-max98095", }, 110 { .compatible = "google,snow-audio-max98095", },
111 {}, 111 {},
112}; 112};
113MODULE_DEVICE_TABLE(of, snow_of_match);
113 114
114static struct platform_driver snow_driver = { 115static struct platform_driver snow_driver = {
115 .driver = { 116 .driver = {
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 66fddec9543d..88e5df474ccf 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -1711,8 +1711,7 @@ static const struct snd_soc_dai_ops fsi_dai_ops = {
1711static struct snd_pcm_hardware fsi_pcm_hardware = { 1711static struct snd_pcm_hardware fsi_pcm_hardware = {
1712 .info = SNDRV_PCM_INFO_INTERLEAVED | 1712 .info = SNDRV_PCM_INFO_INTERLEAVED |
1713 SNDRV_PCM_INFO_MMAP | 1713 SNDRV_PCM_INFO_MMAP |
1714 SNDRV_PCM_INFO_MMAP_VALID | 1714 SNDRV_PCM_INFO_MMAP_VALID,
1715 SNDRV_PCM_INFO_PAUSE,
1716 .buffer_bytes_max = 64 * 1024, 1715 .buffer_bytes_max = 64 * 1024,
1717 .period_bytes_min = 32, 1716 .period_bytes_min = 32,
1718 .period_bytes_max = 8192, 1717 .period_bytes_max = 8192,
diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index 1922ec57d10a..70042197f9e2 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -886,8 +886,7 @@ static int rsnd_dai_probe(struct platform_device *pdev,
886static struct snd_pcm_hardware rsnd_pcm_hardware = { 886static struct snd_pcm_hardware rsnd_pcm_hardware = {
887 .info = SNDRV_PCM_INFO_INTERLEAVED | 887 .info = SNDRV_PCM_INFO_INTERLEAVED |
888 SNDRV_PCM_INFO_MMAP | 888 SNDRV_PCM_INFO_MMAP |
889 SNDRV_PCM_INFO_MMAP_VALID | 889 SNDRV_PCM_INFO_MMAP_VALID,
890 SNDRV_PCM_INFO_PAUSE,
891 .buffer_bytes_max = 64 * 1024, 890 .buffer_bytes_max = 64 * 1024,
892 .period_bytes_min = 32, 891 .period_bytes_min = 32,
893 .period_bytes_max = 8192, 892 .period_bytes_max = 8192,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 4c8f8a23a0e9..b60ff56ebc0f 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -884,7 +884,7 @@ static struct snd_soc_dai *snd_soc_find_dai(
884 list_for_each_entry(component, &component_list, list) { 884 list_for_each_entry(component, &component_list, list) {
885 if (dlc->of_node && component->dev->of_node != dlc->of_node) 885 if (dlc->of_node && component->dev->of_node != dlc->of_node)
886 continue; 886 continue;
887 if (dlc->name && strcmp(dev_name(component->dev), dlc->name)) 887 if (dlc->name && strcmp(component->name, dlc->name))
888 continue; 888 continue;
889 list_for_each_entry(dai, &component->dai_list, list) { 889 list_for_each_entry(dai, &component->dai_list, list) {
890 if (dlc->dai_name && strcmp(dai->name, dlc->dai_name)) 890 if (dlc->dai_name && strcmp(dai->name, dlc->dai_name))
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 002311afdeaa..57277dd79e11 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1522,13 +1522,36 @@ static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
1522 dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture); 1522 dpcm_init_runtime_hw(runtime, &cpu_dai_drv->capture);
1523} 1523}
1524 1524
1525static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd);
1526
1527/* Set FE's runtime_update state; the state is protected via PCM stream lock
1528 * for avoiding the race with trigger callback.
1529 * If the state is unset and a trigger is pending while the previous operation,
1530 * process the pending trigger action here.
1531 */
1532static void dpcm_set_fe_update_state(struct snd_soc_pcm_runtime *fe,
1533 int stream, enum snd_soc_dpcm_update state)
1534{
1535 struct snd_pcm_substream *substream =
1536 snd_soc_dpcm_get_substream(fe, stream);
1537
1538 snd_pcm_stream_lock_irq(substream);
1539 if (state == SND_SOC_DPCM_UPDATE_NO && fe->dpcm[stream].trigger_pending) {
1540 dpcm_fe_dai_do_trigger(substream,
1541 fe->dpcm[stream].trigger_pending - 1);
1542 fe->dpcm[stream].trigger_pending = 0;
1543 }
1544 fe->dpcm[stream].runtime_update = state;
1545 snd_pcm_stream_unlock_irq(substream);
1546}
1547
1525static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream) 1548static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
1526{ 1549{
1527 struct snd_soc_pcm_runtime *fe = fe_substream->private_data; 1550 struct snd_soc_pcm_runtime *fe = fe_substream->private_data;
1528 struct snd_pcm_runtime *runtime = fe_substream->runtime; 1551 struct snd_pcm_runtime *runtime = fe_substream->runtime;
1529 int stream = fe_substream->stream, ret = 0; 1552 int stream = fe_substream->stream, ret = 0;
1530 1553
1531 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; 1554 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1532 1555
1533 ret = dpcm_be_dai_startup(fe, fe_substream->stream); 1556 ret = dpcm_be_dai_startup(fe, fe_substream->stream);
1534 if (ret < 0) { 1557 if (ret < 0) {
@@ -1550,13 +1573,13 @@ static int dpcm_fe_dai_startup(struct snd_pcm_substream *fe_substream)
1550 dpcm_set_fe_runtime(fe_substream); 1573 dpcm_set_fe_runtime(fe_substream);
1551 snd_pcm_limit_hw_rates(runtime); 1574 snd_pcm_limit_hw_rates(runtime);
1552 1575
1553 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 1576 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1554 return 0; 1577 return 0;
1555 1578
1556unwind: 1579unwind:
1557 dpcm_be_dai_startup_unwind(fe, fe_substream->stream); 1580 dpcm_be_dai_startup_unwind(fe, fe_substream->stream);
1558be_err: 1581be_err:
1559 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 1582 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1560 return ret; 1583 return ret;
1561} 1584}
1562 1585
@@ -1603,7 +1626,7 @@ static int dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream)
1603 struct snd_soc_pcm_runtime *fe = substream->private_data; 1626 struct snd_soc_pcm_runtime *fe = substream->private_data;
1604 int stream = substream->stream; 1627 int stream = substream->stream;
1605 1628
1606 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; 1629 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1607 1630
1608 /* shutdown the BEs */ 1631 /* shutdown the BEs */
1609 dpcm_be_dai_shutdown(fe, substream->stream); 1632 dpcm_be_dai_shutdown(fe, substream->stream);
@@ -1617,7 +1640,7 @@ static int dpcm_fe_dai_shutdown(struct snd_pcm_substream *substream)
1617 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP); 1640 dpcm_dapm_stream_event(fe, stream, SND_SOC_DAPM_STREAM_STOP);
1618 1641
1619 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE; 1642 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_CLOSE;
1620 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 1643 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1621 return 0; 1644 return 0;
1622} 1645}
1623 1646
@@ -1665,7 +1688,7 @@ static int dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream)
1665 int err, stream = substream->stream; 1688 int err, stream = substream->stream;
1666 1689
1667 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); 1690 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1668 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; 1691 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1669 1692
1670 dev_dbg(fe->dev, "ASoC: hw_free FE %s\n", fe->dai_link->name); 1693 dev_dbg(fe->dev, "ASoC: hw_free FE %s\n", fe->dai_link->name);
1671 1694
@@ -1680,7 +1703,7 @@ static int dpcm_fe_dai_hw_free(struct snd_pcm_substream *substream)
1680 err = dpcm_be_dai_hw_free(fe, stream); 1703 err = dpcm_be_dai_hw_free(fe, stream);
1681 1704
1682 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE; 1705 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
1683 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 1706 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1684 1707
1685 mutex_unlock(&fe->card->mutex); 1708 mutex_unlock(&fe->card->mutex);
1686 return 0; 1709 return 0;
@@ -1773,7 +1796,7 @@ static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
1773 int ret, stream = substream->stream; 1796 int ret, stream = substream->stream;
1774 1797
1775 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME); 1798 mutex_lock_nested(&fe->card->mutex, SND_SOC_CARD_CLASS_RUNTIME);
1776 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; 1799 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
1777 1800
1778 memcpy(&fe->dpcm[substream->stream].hw_params, params, 1801 memcpy(&fe->dpcm[substream->stream].hw_params, params,
1779 sizeof(struct snd_pcm_hw_params)); 1802 sizeof(struct snd_pcm_hw_params));
@@ -1796,7 +1819,7 @@ static int dpcm_fe_dai_hw_params(struct snd_pcm_substream *substream,
1796 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS; 1819 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_PARAMS;
1797 1820
1798out: 1821out:
1799 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 1822 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
1800 mutex_unlock(&fe->card->mutex); 1823 mutex_unlock(&fe->card->mutex);
1801 return ret; 1824 return ret;
1802} 1825}
@@ -1910,7 +1933,7 @@ int dpcm_be_dai_trigger(struct snd_soc_pcm_runtime *fe, int stream,
1910} 1933}
1911EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger); 1934EXPORT_SYMBOL_GPL(dpcm_be_dai_trigger);
1912 1935
1913static int dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd) 1936static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd)
1914{ 1937{
1915 struct snd_soc_pcm_runtime *fe = substream->private_data; 1938 struct snd_soc_pcm_runtime *fe = substream->private_data;
1916 int stream = substream->stream, ret; 1939 int stream = substream->stream, ret;
@@ -1984,6 +2007,23 @@ out:
1984 return ret; 2007 return ret;
1985} 2008}
1986 2009
2010static int dpcm_fe_dai_trigger(struct snd_pcm_substream *substream, int cmd)
2011{
2012 struct snd_soc_pcm_runtime *fe = substream->private_data;
2013 int stream = substream->stream;
2014
2015 /* if FE's runtime_update is already set, we're in race;
2016 * process this trigger later at exit
2017 */
2018 if (fe->dpcm[stream].runtime_update != SND_SOC_DPCM_UPDATE_NO) {
2019 fe->dpcm[stream].trigger_pending = cmd + 1;
2020 return 0; /* delayed, assuming it's successful */
2021 }
2022
2023 /* we're alone, let's trigger */
2024 return dpcm_fe_dai_do_trigger(substream, cmd);
2025}
2026
1987int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream) 2027int dpcm_be_dai_prepare(struct snd_soc_pcm_runtime *fe, int stream)
1988{ 2028{
1989 struct snd_soc_dpcm *dpcm; 2029 struct snd_soc_dpcm *dpcm;
@@ -2027,7 +2067,7 @@ static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
2027 2067
2028 dev_dbg(fe->dev, "ASoC: prepare FE %s\n", fe->dai_link->name); 2068 dev_dbg(fe->dev, "ASoC: prepare FE %s\n", fe->dai_link->name);
2029 2069
2030 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_FE; 2070 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_FE);
2031 2071
2032 /* there is no point preparing this FE if there are no BEs */ 2072 /* there is no point preparing this FE if there are no BEs */
2033 if (list_empty(&fe->dpcm[stream].be_clients)) { 2073 if (list_empty(&fe->dpcm[stream].be_clients)) {
@@ -2054,7 +2094,7 @@ static int dpcm_fe_dai_prepare(struct snd_pcm_substream *substream)
2054 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE; 2094 fe->dpcm[stream].state = SND_SOC_DPCM_STATE_PREPARE;
2055 2095
2056out: 2096out:
2057 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 2097 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2058 mutex_unlock(&fe->card->mutex); 2098 mutex_unlock(&fe->card->mutex);
2059 2099
2060 return ret; 2100 return ret;
@@ -2201,11 +2241,11 @@ static int dpcm_run_new_update(struct snd_soc_pcm_runtime *fe, int stream)
2201{ 2241{
2202 int ret; 2242 int ret;
2203 2243
2204 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE; 2244 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE);
2205 ret = dpcm_run_update_startup(fe, stream); 2245 ret = dpcm_run_update_startup(fe, stream);
2206 if (ret < 0) 2246 if (ret < 0)
2207 dev_err(fe->dev, "ASoC: failed to startup some BEs\n"); 2247 dev_err(fe->dev, "ASoC: failed to startup some BEs\n");
2208 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 2248 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2209 2249
2210 return ret; 2250 return ret;
2211} 2251}
@@ -2214,11 +2254,11 @@ static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream)
2214{ 2254{
2215 int ret; 2255 int ret;
2216 2256
2217 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_BE; 2257 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_BE);
2218 ret = dpcm_run_update_shutdown(fe, stream); 2258 ret = dpcm_run_update_shutdown(fe, stream);
2219 if (ret < 0) 2259 if (ret < 0)
2220 dev_err(fe->dev, "ASoC: failed to shutdown some BEs\n"); 2260 dev_err(fe->dev, "ASoC: failed to shutdown some BEs\n");
2221 fe->dpcm[stream].runtime_update = SND_SOC_DPCM_UPDATE_NO; 2261 dpcm_set_fe_update_state(fe, stream, SND_SOC_DPCM_UPDATE_NO);
2222 2262
2223 return ret; 2263 return ret;
2224} 2264}
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 7ecd0e8a5c51..f61ebb17cc64 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -591,18 +591,19 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
591{ 591{
592 struct snd_card *card; 592 struct snd_card *card;
593 struct list_head *p; 593 struct list_head *p;
594 bool was_shutdown;
594 595
595 if (chip == (void *)-1L) 596 if (chip == (void *)-1L)
596 return; 597 return;
597 598
598 card = chip->card; 599 card = chip->card;
599 down_write(&chip->shutdown_rwsem); 600 down_write(&chip->shutdown_rwsem);
601 was_shutdown = chip->shutdown;
600 chip->shutdown = 1; 602 chip->shutdown = 1;
601 up_write(&chip->shutdown_rwsem); 603 up_write(&chip->shutdown_rwsem);
602 604
603 mutex_lock(&register_mutex); 605 mutex_lock(&register_mutex);
604 chip->num_interfaces--; 606 if (!was_shutdown) {
605 if (chip->num_interfaces <= 0) {
606 struct snd_usb_endpoint *ep; 607 struct snd_usb_endpoint *ep;
607 608
608 snd_card_disconnect(card); 609 snd_card_disconnect(card);
@@ -622,6 +623,10 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
622 list_for_each(p, &chip->mixer_list) { 623 list_for_each(p, &chip->mixer_list) {
623 snd_usb_mixer_disconnect(p); 624 snd_usb_mixer_disconnect(p);
624 } 625 }
626 }
627
628 chip->num_interfaces--;
629 if (chip->num_interfaces <= 0) {
625 usb_chip[chip->index] = NULL; 630 usb_chip[chip->index] = NULL;
626 mutex_unlock(&register_mutex); 631 mutex_unlock(&register_mutex);
627 snd_card_free_when_closed(card); 632 snd_card_free_when_closed(card);
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 2e4a9dbc51fa..6e354d326858 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -2033,10 +2033,11 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid,
2033 cval->res = 1; 2033 cval->res = 1;
2034 cval->initialized = 1; 2034 cval->initialized = 1;
2035 2035
2036 if (desc->bDescriptorSubtype == UAC2_CLOCK_SELECTOR) 2036 if (state->mixer->protocol == UAC_VERSION_1)
2037 cval->control = UAC2_CX_CLOCK_SELECTOR;
2038 else
2039 cval->control = 0; 2037 cval->control = 0;
2038 else /* UAC_VERSION_2 */
2039 cval->control = (desc->bDescriptorSubtype == UAC2_CLOCK_SELECTOR) ?
2040 UAC2_CX_CLOCK_SELECTOR : UAC2_SU_SELECTOR;
2040 2041
2041 namelist = kmalloc(sizeof(char *) * desc->bNrInPins, GFP_KERNEL); 2042 namelist = kmalloc(sizeof(char *) * desc->bNrInPins, GFP_KERNEL);
2042 if (!namelist) { 2043 if (!namelist) {
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index f119a41ed9a9..8c9bf4b7aaf0 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -593,10 +593,10 @@ static int snd_nativeinstruments_control_get(struct snd_kcontrol *kcontrol,
593 if (mixer->chip->shutdown) 593 if (mixer->chip->shutdown)
594 ret = -ENODEV; 594 ret = -ENODEV;
595 else 595 else
596 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest, 596 ret = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), bRequest,
597 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN, 597 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
598 0, wIndex, 598 0, wIndex,
599 &tmp, sizeof(tmp), 1000); 599 &tmp, sizeof(tmp));
600 up_read(&mixer->chip->shutdown_rwsem); 600 up_read(&mixer->chip->shutdown_rwsem);
601 601
602 if (ret < 0) { 602 if (ret < 0) {
@@ -885,6 +885,11 @@ static int snd_ftu_eff_switch_put(struct snd_kcontrol *kctl,
885 return changed; 885 return changed;
886} 886}
887 887
888static void kctl_private_value_free(struct snd_kcontrol *kctl)
889{
890 kfree((void *)kctl->private_value);
891}
892
888static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer, 893static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
889 int validx, int bUnitID) 894 int validx, int bUnitID)
890{ 895{
@@ -919,6 +924,7 @@ static int snd_ftu_create_effect_switch(struct usb_mixer_interface *mixer,
919 return -ENOMEM; 924 return -ENOMEM;
920 } 925 }
921 926
927 kctl->private_free = kctl_private_value_free;
922 err = snd_ctl_add(mixer->chip->card, kctl); 928 err = snd_ctl_add(mixer->chip->card, kctl);
923 if (err < 0) 929 if (err < 0)
924 return err; 930 return err;
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index d2aa45a8d895..60dfe0d28771 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -1146,6 +1146,20 @@ void snd_usb_ctl_msg_quirk(struct usb_device *dev, unsigned int pipe,
1146 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x23ba) && 1146 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x23ba) &&
1147 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) 1147 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS)
1148 mdelay(20); 1148 mdelay(20);
1149
1150 /* Marantz/Denon devices with USB DAC functionality need a delay
1151 * after each class compliant request
1152 */
1153 if ((le16_to_cpu(dev->descriptor.idVendor) == 0x154e) &&
1154 (requesttype & USB_TYPE_MASK) == USB_TYPE_CLASS) {
1155
1156 switch (le16_to_cpu(dev->descriptor.idProduct)) {
1157 case 0x3005: /* Marantz HD-DAC1 */
1158 case 0x3006: /* Marantz SA-14S1 */
1159 mdelay(20);
1160 break;
1161 }
1162 }
1149} 1163}
1150 1164
1151/* 1165/*
@@ -1179,12 +1193,12 @@ u64 snd_usb_interface_dsd_format_quirks(struct snd_usb_audio *chip,
1179 /* iFi Audio micro/nano iDSD */ 1193 /* iFi Audio micro/nano iDSD */
1180 case USB_ID(0x20b1, 0x3008): 1194 case USB_ID(0x20b1, 0x3008):
1181 if (fp->altsetting == 2) 1195 if (fp->altsetting == 2)
1182 return SNDRV_PCM_FMTBIT_DSD_U32_LE; 1196 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1183 break; 1197 break;
1184 /* DIYINHK DSD DXD 384kHz USB to I2S/DSD */ 1198 /* DIYINHK DSD DXD 384kHz USB to I2S/DSD */
1185 case USB_ID(0x20b1, 0x2009): 1199 case USB_ID(0x20b1, 0x2009):
1186 if (fp->altsetting == 3) 1200 if (fp->altsetting == 3)
1187 return SNDRV_PCM_FMTBIT_DSD_U32_LE; 1201 return SNDRV_PCM_FMTBIT_DSD_U32_BE;
1188 break; 1202 break;
1189 default: 1203 default:
1190 break; 1204 break;
diff --git a/tools/lib/traceevent/plugin_scsi.c b/tools/lib/traceevent/plugin_scsi.c
index eda326fc8620..3727de48c8d5 100644
--- a/tools/lib/traceevent/plugin_scsi.c
+++ b/tools/lib/traceevent/plugin_scsi.c
@@ -85,8 +85,9 @@ typedef unsigned int u32;
85#define MOVE_MEDIUM 0xa5 85#define MOVE_MEDIUM 0xa5
86#define EXCHANGE_MEDIUM 0xa6 86#define EXCHANGE_MEDIUM 0xa6
87#define READ_12 0xa8 87#define READ_12 0xa8
88#define SERVICE_ACTION_OUT_12 0xa9
88#define WRITE_12 0xaa 89#define WRITE_12 0xaa
89#define READ_MEDIA_SERIAL_NUMBER 0xab 90#define SERVICE_ACTION_IN_12 0xab
90#define WRITE_VERIFY_12 0xae 91#define WRITE_VERIFY_12 0xae
91#define VERIFY_12 0xaf 92#define VERIFY_12 0xaf
92#define SEARCH_HIGH_12 0xb0 93#define SEARCH_HIGH_12 0xb0
@@ -107,7 +108,9 @@ typedef unsigned int u32;
107#define VERIFY_16 0x8f 108#define VERIFY_16 0x8f
108#define SYNCHRONIZE_CACHE_16 0x91 109#define SYNCHRONIZE_CACHE_16 0x91
109#define WRITE_SAME_16 0x93 110#define WRITE_SAME_16 0x93
110#define SERVICE_ACTION_IN 0x9e 111#define SERVICE_ACTION_BIDIRECTIONAL 0x9d
112#define SERVICE_ACTION_IN_16 0x9e
113#define SERVICE_ACTION_OUT_16 0x9f
111/* values for service action in */ 114/* values for service action in */
112#define SAI_READ_CAPACITY_16 0x10 115#define SAI_READ_CAPACITY_16 0x10
113#define SAI_GET_LBA_STATUS 0x12 116#define SAI_GET_LBA_STATUS 0x12
@@ -393,7 +396,7 @@ scsi_trace_parse_cdb(struct trace_seq *p, unsigned char *cdb, int len)
393 return scsi_trace_rw16(p, cdb, len); 396 return scsi_trace_rw16(p, cdb, len);
394 case UNMAP: 397 case UNMAP:
395 return scsi_trace_unmap(p, cdb, len); 398 return scsi_trace_unmap(p, cdb, len);
396 case SERVICE_ACTION_IN: 399 case SERVICE_ACTION_IN_16:
397 return scsi_trace_service_action_in(p, cdb, len); 400 return scsi_trace_service_action_in(p, cdb, len);
398 case VARIABLE_LENGTH_CMD: 401 case VARIABLE_LENGTH_CMD:
399 return scsi_trace_varlen(p, cdb, len); 402 return scsi_trace_varlen(p, cdb, len);
diff --git a/tools/testing/selftests/ftrace/ftracetest b/tools/testing/selftests/ftrace/ftracetest
index a8f81c782856..515247601df4 100755
--- a/tools/testing/selftests/ftrace/ftracetest
+++ b/tools/testing/selftests/ftrace/ftracetest
@@ -82,7 +82,7 @@ parse_opts() { # opts
82} 82}
83 83
84# Parameters 84# Parameters
85DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' '` 85DEBUGFS_DIR=`grep debugfs /proc/mounts | cut -f2 -d' ' | head -1`
86TRACING_DIR=$DEBUGFS_DIR/tracing 86TRACING_DIR=$DEBUGFS_DIR/tracing
87TOP_DIR=`absdir $0` 87TOP_DIR=`absdir $0`
88TEST_DIR=$TOP_DIR/test.d 88TEST_DIR=$TOP_DIR/test.d
diff --git a/tools/testing/selftests/net/psock_fanout.c b/tools/testing/selftests/net/psock_fanout.c
index 57b9c2b7c4ff..6f6733331d95 100644
--- a/tools/testing/selftests/net/psock_fanout.c
+++ b/tools/testing/selftests/net/psock_fanout.c
@@ -128,7 +128,7 @@ static int sock_fanout_read_ring(int fd, void *ring)
128 struct tpacket2_hdr *header = ring; 128 struct tpacket2_hdr *header = ring;
129 int count = 0; 129 int count = 0;
130 130
131 while (header->tp_status & TP_STATUS_USER && count < RING_NUM_FRAMES) { 131 while (count < RING_NUM_FRAMES && header->tp_status & TP_STATUS_USER) {
132 count++; 132 count++;
133 header = ring + (count * getpagesize()); 133 header = ring + (count * getpagesize());
134 } 134 }
diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 3aaca49de325..aacdb59f30de 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -1933,7 +1933,7 @@ out:
1933 1933
1934int kvm_vgic_create(struct kvm *kvm) 1934int kvm_vgic_create(struct kvm *kvm)
1935{ 1935{
1936 int i, vcpu_lock_idx = -1, ret = 0; 1936 int i, vcpu_lock_idx = -1, ret;
1937 struct kvm_vcpu *vcpu; 1937 struct kvm_vcpu *vcpu;
1938 1938
1939 mutex_lock(&kvm->lock); 1939 mutex_lock(&kvm->lock);
@@ -1948,6 +1948,7 @@ int kvm_vgic_create(struct kvm *kvm)
1948 * vcpu->mutex. By grabbing the vcpu->mutex of all VCPUs we ensure 1948 * vcpu->mutex. By grabbing the vcpu->mutex of all VCPUs we ensure
1949 * that no other VCPUs are run while we create the vgic. 1949 * that no other VCPUs are run while we create the vgic.
1950 */ 1950 */
1951 ret = -EBUSY;
1951 kvm_for_each_vcpu(i, vcpu, kvm) { 1952 kvm_for_each_vcpu(i, vcpu, kvm) {
1952 if (!mutex_trylock(&vcpu->mutex)) 1953 if (!mutex_trylock(&vcpu->mutex))
1953 goto out_unlock; 1954 goto out_unlock;
@@ -1955,11 +1956,10 @@ int kvm_vgic_create(struct kvm *kvm)
1955 } 1956 }
1956 1957
1957 kvm_for_each_vcpu(i, vcpu, kvm) { 1958 kvm_for_each_vcpu(i, vcpu, kvm) {
1958 if (vcpu->arch.has_run_once) { 1959 if (vcpu->arch.has_run_once)
1959 ret = -EBUSY;
1960 goto out_unlock; 1960 goto out_unlock;
1961 }
1962 } 1961 }
1962 ret = 0;
1963 1963
1964 spin_lock_init(&kvm->arch.vgic.lock); 1964 spin_lock_init(&kvm->arch.vgic.lock);
1965 kvm->arch.vgic.in_kernel = true; 1965 kvm->arch.vgic.in_kernel = true;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 25ffac9e947d..3cee7b167052 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -107,10 +107,10 @@ EXPORT_SYMBOL_GPL(kvm_rebooting);
107 107
108static bool largepages_enabled = true; 108static bool largepages_enabled = true;
109 109
110bool kvm_is_mmio_pfn(pfn_t pfn) 110bool kvm_is_reserved_pfn(pfn_t pfn)
111{ 111{
112 if (pfn_valid(pfn)) 112 if (pfn_valid(pfn))
113 return !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn)); 113 return PageReserved(pfn_to_page(pfn));
114 114
115 return true; 115 return true;
116} 116}
@@ -1321,7 +1321,7 @@ static pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async,
1321 else if ((vma->vm_flags & VM_PFNMAP)) { 1321 else if ((vma->vm_flags & VM_PFNMAP)) {
1322 pfn = ((addr - vma->vm_start) >> PAGE_SHIFT) + 1322 pfn = ((addr - vma->vm_start) >> PAGE_SHIFT) +
1323 vma->vm_pgoff; 1323 vma->vm_pgoff;
1324 BUG_ON(!kvm_is_mmio_pfn(pfn)); 1324 BUG_ON(!kvm_is_reserved_pfn(pfn));
1325 } else { 1325 } else {
1326 if (async && vma_is_valid(vma, write_fault)) 1326 if (async && vma_is_valid(vma, write_fault))
1327 *async = true; 1327 *async = true;
@@ -1427,7 +1427,7 @@ static struct page *kvm_pfn_to_page(pfn_t pfn)
1427 if (is_error_noslot_pfn(pfn)) 1427 if (is_error_noslot_pfn(pfn))
1428 return KVM_ERR_PTR_BAD_PAGE; 1428 return KVM_ERR_PTR_BAD_PAGE;
1429 1429
1430 if (kvm_is_mmio_pfn(pfn)) { 1430 if (kvm_is_reserved_pfn(pfn)) {
1431 WARN_ON(1); 1431 WARN_ON(1);
1432 return KVM_ERR_PTR_BAD_PAGE; 1432 return KVM_ERR_PTR_BAD_PAGE;
1433 } 1433 }
@@ -1456,7 +1456,7 @@ EXPORT_SYMBOL_GPL(kvm_release_page_clean);
1456 1456
1457void kvm_release_pfn_clean(pfn_t pfn) 1457void kvm_release_pfn_clean(pfn_t pfn)
1458{ 1458{
1459 if (!is_error_noslot_pfn(pfn) && !kvm_is_mmio_pfn(pfn)) 1459 if (!is_error_noslot_pfn(pfn) && !kvm_is_reserved_pfn(pfn))
1460 put_page(pfn_to_page(pfn)); 1460 put_page(pfn_to_page(pfn));
1461} 1461}
1462EXPORT_SYMBOL_GPL(kvm_release_pfn_clean); 1462EXPORT_SYMBOL_GPL(kvm_release_pfn_clean);
@@ -1477,7 +1477,7 @@ static void kvm_release_pfn_dirty(pfn_t pfn)
1477 1477
1478void kvm_set_pfn_dirty(pfn_t pfn) 1478void kvm_set_pfn_dirty(pfn_t pfn)
1479{ 1479{
1480 if (!kvm_is_mmio_pfn(pfn)) { 1480 if (!kvm_is_reserved_pfn(pfn)) {
1481 struct page *page = pfn_to_page(pfn); 1481 struct page *page = pfn_to_page(pfn);
1482 if (!PageReserved(page)) 1482 if (!PageReserved(page))
1483 SetPageDirty(page); 1483 SetPageDirty(page);
@@ -1487,14 +1487,14 @@ EXPORT_SYMBOL_GPL(kvm_set_pfn_dirty);
1487 1487
1488void kvm_set_pfn_accessed(pfn_t pfn) 1488void kvm_set_pfn_accessed(pfn_t pfn)
1489{ 1489{
1490 if (!kvm_is_mmio_pfn(pfn)) 1490 if (!kvm_is_reserved_pfn(pfn))
1491 mark_page_accessed(pfn_to_page(pfn)); 1491 mark_page_accessed(pfn_to_page(pfn));
1492} 1492}
1493EXPORT_SYMBOL_GPL(kvm_set_pfn_accessed); 1493EXPORT_SYMBOL_GPL(kvm_set_pfn_accessed);
1494 1494
1495void kvm_get_pfn(pfn_t pfn) 1495void kvm_get_pfn(pfn_t pfn)
1496{ 1496{
1497 if (!kvm_is_mmio_pfn(pfn)) 1497 if (!kvm_is_reserved_pfn(pfn))
1498 get_page(pfn_to_page(pfn)); 1498 get_page(pfn_to_page(pfn));
1499} 1499}
1500EXPORT_SYMBOL_GPL(kvm_get_pfn); 1500EXPORT_SYMBOL_GPL(kvm_get_pfn);